diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index 04b0bc350..530349ced 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -20,7 +20,7 @@ def repository = ['https://github.com/86Box/86Box.git', scm.userRemoteConfigs[0] def commitBrowser = ['https://github.com/86Box/86Box/commit/%s', null] def branch = ['master', scm.branches[0].name] def buildType = ['beta', 'alpha'] -def tarballFlags = ['', '-s'] +def tarballFlags = ['', '-t'] def buildBranch = env.JOB_BASE_NAME.contains('-') ? 1 : 0 def osArchs = [ diff --git a/.ci/build.sh b/.ci/build.sh index 326952186..0af94132a 100755 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -542,11 +542,12 @@ then sudo sed -i -e 's/configure.env-append MAKE=/configure.env-append VULKAN_SDK=${prefix} MAKE=/g' "$qt5_portfile" fi - # Patch openal-soft to use 1.23.1 on all targets instead of 1.24.1 on >=10.15 only, + # Patch openal-soft to use 1.23.1 on all targets instead of 1.24.2 on >=10.13 only, # to prevent a symlink mismatch from having different versions on x86_64 and arm64. # See: https://github.com/macports/macports-ports/commit/9b4903fc9c76769d476079e404c9a3b8a225f8aa + # https://github.com/macports/macports-ports/commit/788deb64dc0695e8d04afb32ed904947f2a7591b openal_portfile="$macports/var/macports/sources/rsync.macports.org/macports/release/tarballs/ports/audio/openal-soft/Portfile" - sudo sed -i -e 's/if {${os.platform} ne "darwin" || ${os.major} >= 19}/if {0}/g' "$openal_portfile" + sudo sed -i -e 's/if {${os.platform} ne "darwin" ||/if {0 \&\&/g' "$openal_portfile" # Patch wget to remove libproxy support, as it depends on shared-mime-info which # fails to build for a 10.13 target, which we have to do despite wget only being diff --git a/.github/workflows/cmake_macos.yml b/.github/workflows/cmake_macos.yml index 5a0454385..2ae417e13 100644 --- a/.github/workflows/cmake_macos.yml +++ b/.github/workflows/cmake_macos.yml @@ -56,22 +56,13 @@ jobs: - name: SDL GUI qt: off static: on - src-packages: >- - libsndfile - name: Qt GUI qt: on slug: -Qt packages: >- qt@5 - src-packages: >- - libsndfile steps: - - name: Install source dependencies - run: >- - brew reinstall -s - ${{ matrix.ui.src-packages }} - - name: Install dependencies run: >- brew install @@ -158,22 +149,13 @@ jobs: - name: SDL GUI qt: off static: on - src-packages: >- - libsndfile - name: Qt GUI qt: on slug: -Qt packages: >- qt@5 - src-packages: >- - libsndfile steps: - - name: Install source dependencies - run: >- - brew reinstall -s - ${{ matrix.ui.src-packages }} - - name: Install dependencies run: >- brew install diff --git a/.github/workflows/cmake_windows_msys2.yml b/.github/workflows/cmake_windows_msys2.yml index abe25b949..ca48599a0 100644 --- a/.github/workflows/cmake_windows_msys2.yml +++ b/.github/workflows/cmake_windows_msys2.yml @@ -18,7 +18,6 @@ on: - cmake/** - "**/CMakeLists.txt" - "CMakePresets.json" - - .github/workflows/** - .github/workflows/cmake_windows_msys2.yml - vcpkg.json - "!**/Makefile*" @@ -26,9 +25,9 @@ on: jobs: msys2: - name: "${{ matrix.ui.name }}, ${{ matrix.build.name }}, ${{ matrix.dynarec.name }}, ${{ matrix.environment.msystem }}" + name: "${{ matrix.build.name }}, ${{ matrix.dynarec.name }}, ${{ matrix.environment.msystem }}" - runs-on: windows-2022 + runs-on: ${{ matrix.environment.runner }} env: BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed @@ -41,47 +40,38 @@ jobs: fail-fast: true matrix: build: -# - name: Regular -# preset: regular - - name: Debug + - name: Dev Debug preset: dev_debug - slug: -Debug + slug: -Dev-Debug - name: Dev preset: development slug: -Dev dynarec: - name: ODR new: off - slug: -ODR - name: NDR new: on slug: -NDR - ui: - - name: Qt GUI - qt: on - static: on - slug: -Qt - packages: >- - qt5-static:p - vulkan-headers:p environment: -# - msystem: MSYS -# toolchain: ./cmake/flags-gcc-x86_64.cmake - msystem: MINGW64 - prefix: mingw-w64-x86_64 toolchain: ./cmake/flags-gcc-x86_64.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 + slug: "-64" + runner: windows-2022 + - msystem: CLANGARM64 + toolchain: ./cmake/flags-gcc-aarch64.cmake + slug: -arm64 + runner: windows-11-arm + exclude: + - dynarec: + new: off + environment: + msystem: CLANGARM64 steps: - name: Prepare MSYS2 environment uses: msys2/setup-msys2@v2 with: - release: false + release: true update: true msystem: ${{ matrix.environment.msystem }} pacboy: >- @@ -98,15 +88,17 @@ jobs: libslirp:p fluidsynth:p libserialport:p - ${{ matrix.ui.packages }} + qt5-static:p + vulkan-headers:p + openmp:p - name: Checkout repository uses: actions/checkout@v4 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@v3 + # - name: Install sonar-scanner and build-wrapper + # uses: SonarSource/sonarcloud-github-c-cpp@v3 - name: Configure CMake run: >- @@ -114,20 +106,20 @@ jobs: --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: | + # .sonar/build-wrapper-win-x86/build-wrapper-win-x86-64.exe --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build - name: Build - run: | - .sonar/build-wrapper-win-x86/build-wrapper-win-x86-64.exe --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} 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/sonar-scanner-5.0.1.3006-windows/bin/sonar-scanner.bat --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" + # - name: Run sonar-scanner + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + # run: | + # .sonar/sonar-scanner-5.0.1.3006-windows/bin/sonar-scanner.bat --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" - name: Generate package run: cmake --install build @@ -135,5 +127,5 @@ jobs: - name: Upload artifact uses: actions/upload-artifact@v4 with: - name: '86Box${{ matrix.ui.slug }}${{ matrix.dynarec.slug }}${{ matrix.build.slug }}-Windows-${{ matrix.environment.msystem }}-gha${{ github.run_number }}' + name: '86Box${{ matrix.dynarec.slug }}${{ matrix.build.slug }}-Windows${{ matrix.environment.slug }}-gha${{ github.run_number }}' path: build/artifacts/** diff --git a/CMakeLists.txt b/CMakeLists.txt index f9f39a8d5..4dd83523f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ # Authors: David Hrdlička, # # Copyright 2020-2021 David Hrdlička. -# Copyright 2021-2024 Jasmine Iwanek. +# Copyright 2021-2025 Jasmine Iwanek. # cmake_minimum_required(VERSION 3.16) @@ -36,7 +36,7 @@ if(MUNT_EXTERNAL) endif() project(86Box - VERSION 4.3 + VERSION 5.0 DESCRIPTION "Emulator of x86-based systems" HOMEPAGE_URL "https://86box.net" LANGUAGES C CXX) @@ -132,7 +132,6 @@ option(RTMIDI "RtMidi" option(FLUIDSYNTH "FluidSynth" ON) option(MUNT "MUNT" ON) option(VNC "VNC renderer" OFF) -option(NEW_DYNAREC "Use the PCem v15 (\"new\") dynamic recompiler" OFF) option(MINITRACE "Enable Chrome tracing using the modified minitrace library" OFF) option(GDBSTUB "Enable GDB stub server for debugging" OFF) option(DEV_BRANCH "Development branch" OFF) @@ -140,6 +139,24 @@ option(DISCORD "Discord Rich Presence support" option(DEBUGREGS486 "Enable debug register opeartion on 486+ CPUs" OFF) option(LIBASAN "Enable compilation with the addresss sanitizer" OFF) +if((ARCH STREQUAL "arm64") OR (ARCH STREQUAL "arm")) + set(NEW_DYNAREC ON) +else() + option(NEW_DYNAREC "Use the PCem v15 (\"new\") dynamic recompiler" OFF) +endif() + +if(CMAKE_SYSTEM_NAME STREQUAL "NetBSD") + option(AUDIO4 "Use audio(4) as sound backend" ON) +else() + set(AUDIO4 OFF) +endif() + +if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") + option(SNDIO "Use sndio as sound backend" ON) +else() + set(SNDIO OFF) +endif() + if(WIN32) set(QT ON) option(CPPTHREADS "C++11 threads" OFF) @@ -157,17 +174,11 @@ endif() # Option Description Def. Condition Otherwise # ------ ----------- ---- ------------ --------- cmake_dependent_option(AMD_K5 "AMD K5" ON "DEV_BRANCH" OFF) -cmake_dependent_option(AN430TX "Intel AN430TX" ON "DEV_BRANCH" OFF) cmake_dependent_option(CDROM_MITSUMI "Mitsumi CDROM" ON "DEV_BRANCH" OFF) -cmake_dependent_option(CYRIX_6X86 "Cyrix 6x86" ON "DEV_BRANCH" OFF) cmake_dependent_option(G100 "Matrox Productiva G100" ON "DEV_BRANCH" OFF) -cmake_dependent_option(GUSMAX "Gravis UltraSound MAX" ON "DEV_BRANCH" OFF) cmake_dependent_option(ISAMEM_RAMPAGE "AST Rampage" ON "DEV_BRANCH" OFF) cmake_dependent_option(ISAMEM_IAB "Intel Above Board" ON "DEV_BRANCH" OFF) cmake_dependent_option(ISAMEM_BRAT "BocaRAM/AT" ON "DEV_BRANCH" OFF) -cmake_dependent_option(LASERXT "VTech Laser XT" ON "DEV_BRANCH" OFF) -cmake_dependent_option(OLIVETTI "Olivetti M290" ON "DEV_BRANCH" OFF) -cmake_dependent_option(OPEN_AT "OpenAT" ON "DEV_BRANCH" OFF) cmake_dependent_option(OPL4ML "OPL4-ML daughterboard" ON "DEV_BRANCH" OFF) cmake_dependent_option(PCL "Generic PCL5e Printer" ON "DEV_BRANCH" OFF) cmake_dependent_option(SIO_DETECT "Super I/O Detection Helper" ON "DEV_BRANCH" OFF) diff --git a/CMakePresets.json b/CMakePresets.json index d4af8e6cb..be6615088 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -55,6 +55,14 @@ }, "inherits": "base" }, + { + "name": "ultra_debug", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "UltraDebug", + "DEV_BRANCH": "ON" + }, + "inherits": "base" + }, { "name": "llvm-macos-aarch64.cmake", "displayName": "MacOS clang regular", diff --git a/README.md b/README.md index ce38632e6..506eba794 100644 --- a/README.md +++ b/README.md @@ -26,17 +26,18 @@ Minimum system requirements and recommendations * 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. +Performance may vary depending on host and guest configuration. Most emulation logic is executed in a single thread. Therefore, systems with greater IPC (instructions per clock) capacity 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. +For easier handling of multiple virtual machines, use a manager application: +* [Avalonia 86](https://github.com/notBald/Avalonia86) by [notBald](https://github.com/notBald) (Windows and Linux) * [86Box Manager](https://github.com/86Box/86BoxManager) by [Overdoze](https://github.com/daviunic) (Windows only) * [86Box Manager X](https://github.com/RetBox/86BoxManagerX) by [xafero](https://github.com/xafero) (Cross platform Port of 86Box Manager using Avalonia) * [sl86](https://github.com/DDXofficial/sl86) by [DDX](https://github.com/DDXofficial) (Command-line 86Box machine manager written in Python) * [Linbox-qt5](https://github.com/Dungeonseeker/linbox-qt5) by [Dungeonseeker](https://github.com/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. +To use 86Box on its own, use the `--vmpath`/`-P` command line option. Getting started --------------- @@ -46,7 +47,7 @@ See [our documentation](https://86box.readthedocs.io/en/latest/index.html) for a 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! +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) diff --git a/cmake/flags-gcc.cmake b/cmake/flags-gcc.cmake index 885353b87..90eb52cd1 100644 --- a/cmake/flags-gcc.cmake +++ b/cmake/flags-gcc.cmake @@ -20,6 +20,8 @@ string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " -g0 -O3") string(APPEND CMAKE_CXX_FLAGS_RELEASE_INIT " -g0 -O3") string(APPEND CMAKE_C_FLAGS_DEBUG_INIT " -ggdb -Og") string(APPEND CMAKE_CXX_FLAGS_DEBUG_INIT " -ggdb -Og") +string(APPEND CMAKE_C_FLAGS_ULTRADEBUG_INIT " -O0 -ggdb -g3") +string(APPEND CMAKE_CXX_FLAGS_ULTRADEBUG_INIT " -O0 -ggdb -g3") string(APPEND CMAKE_C_FLAGS_OPTIMIZED_INIT " -march=native -mtune=native -O3 -ffp-contract=fast -flto") string(APPEND CMAKE_CXX_FLAGS_OPTIMIZED_INIT " -march=native -mtune=native -O3 -ffp-contract=fast -flto") @@ -28,7 +30,7 @@ foreach(LANG C;CXX) set(CMAKE_${LANG}_FLAGS "$ENV{${LANG}FLAGS} ${CMAKE_${LANG}_FLAGS_INIT}" CACHE STRING "Flags used by the ${LANG} compiler during all build types.") mark_as_advanced(CMAKE_${LANG}_FLAGS) - foreach(CONFIG RELEASE;DEBUG;OPTIMIZED) + foreach(CONFIG RELEASE;DEBUG;ULTRADEBUG;OPTIMIZED) set(CMAKE_${LANG}_FLAGS_${CONFIG} "${CMAKE_${LANG}_FLAGS_${CONFIG}_INIT}" CACHE STRING "Flags used by the ${LANG} compiler during ${CONFIG} builds.") mark_as_advanced(CMAKE_${LANG}_FLAGS_${CONFIG}) endforeach() diff --git a/cmake/intel-linux-x86_64.cmake b/cmake/intel-linux-x86_64.cmake new file mode 100644 index 000000000..a0c3e5d0b --- /dev/null +++ b/cmake/intel-linux-x86_64.cmake @@ -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. +# +# CMake toolchain file defining GCC compiler flags +# for 64-bit x86 targets. +# +# Authors: David Hrdlička, +# +# Copyright 2021 David Hrdlička. +# + +include(${CMAKE_CURRENT_LIST_DIR}/flags-gcc-x86_64.cmake) + +set(CMAKE_C_COMPILER icx) +set(CMAKE_CXX_COMPILER icpx) diff --git a/cmake/llvm-linux-x86_64.cmake b/cmake/llvm-linux-x86_64.cmake new file mode 100644 index 000000000..ccdd7b18e --- /dev/null +++ b/cmake/llvm-linux-x86_64.cmake @@ -0,0 +1,23 @@ +# +# 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 toolchain file defining Clang compiler flags +# for 64-bit x86 targets. +# +# Authors: David Hrdlička, +# dob205 +# +# Copyright 2021 David Hrdlička. +# Copyright 2022 dob205. +# + +include(${CMAKE_CURRENT_LIST_DIR}/flags-gcc-x86_64.cmake) + +# Use the GCC-compatible Clang executables in order to use our flags +set(CMAKE_C_COMPILER clang) +set(CMAKE_CXX_COMPILER clang++) diff --git a/debian/changelog b/debian/changelog index 5665ff968..079fba5dd 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,5 @@ -86box (4.3) UNRELEASED; urgency=medium +86box (5.0) UNRELEASED; urgency=medium * Bump release. - -- Jasmine Iwanek Wed, 13 Nov 2024 06:31:46 +0100 + -- Jasmine Iwanek Wed, 16 Apr 2025 22:08:04 +0200 diff --git a/src/86box.c b/src/86box.c index 8fa74fd4b..1c11d9bee 100644 --- a/src/86box.c +++ b/src/86box.c @@ -11,6 +11,7 @@ * Authors: Sarah Walker, * Miran Grca, * Fred N. van Kempen, + * Jasmine Iwanek, * * Copyright 2008-2020 Sarah Walker. * Copyright 2016-2020 Miran Grca. @@ -18,7 +19,7 @@ * Copyright 2021 Laci bá' * Copyright 2021 dob205 * Copyright 2021 Andreas J. Reichel. - * Copyright 2021-2022 Jasmine Iwanek. + * Copyright 2021-2025 Jasmine Iwanek. */ #include #include @@ -31,6 +32,7 @@ #include #include #include +#include #ifndef _WIN32 # include @@ -68,6 +70,7 @@ #include <86box/unittester.h> #include <86box/novell_cardkey.h> #include <86box/isamem.h> +#include <86box/isarom.h> #include <86box/isartc.h> #include <86box/lpt.h> #include <86box/serial.h> @@ -103,6 +106,7 @@ #include <86box/machine_status.h> #include <86box/apm.h> #include <86box/acpi.h> +#include <86box/nv/vid_nv_rivatimer.h> // Disable c99-designator to avoid the warnings about int ng #ifdef __clang__ @@ -157,6 +161,7 @@ int window_remember; int vid_resize; /* (C) allow resizing */ int invert_display = 0; /* (C) invert the display */ int suppress_overscan = 0; /* (C) suppress overscans */ +int lang_id = 0; /* (C) language id */ int scale = 0; /* (C) screen scale factor */ int dpi_scale = 0; /* (C) DPI scaling of the emulated screen */ @@ -164,20 +169,20 @@ int vid_api = 0; /* (C) video r int vid_cga_contrast = 0; /* (C) video */ int video_fullscreen = 0; /* (C) video */ int video_fullscreen_scale = 0; /* (C) video */ -int video_fullscreen_first = 0; /* (C) video */ int enable_overscan = 0; /* (C) video */ int force_43 = 0; /* (C) video */ int video_filter_method = 1; /* (C) video */ int video_vsync = 0; /* (C) video */ int video_framerate = -1; /* (C) video */ -char video_shader[512] = { '\0' }; /* (C) video */ -bool serial_passthrough_enabled[SERIAL_MAX] = { 0, 0, 0, 0, 0, 0, 0 }; /* (C) activation and kind of +bool serial_passthrough_enabled[SERIAL_MAX - 1] = { 0, 0, 0, 0, 0, 0, 0 }; /* (C) activation and kind of pass-through for serial ports */ int bugger_enabled = 0; /* (C) enable ISAbugger */ int novell_keycard_enabled = 0; /* (C) enable Novell NetWare 2.x key card emulation. */ int postcard_enabled = 0; /* (C) enable POST card */ int unittester_enabled = 0; /* (C) enable unit tester device */ +int gameport_type[GAMEPORT_MAX] = { 0, 0 }; /* (C) enable gameports */ int isamem_type[ISAMEM_MAX] = { 0, 0, 0, 0 }; /* (C) enable ISA mem cards */ +int isarom_type[ISAROM_MAX] = { 0, 0, 0, 0 }; /* (C) enable ISA ROM cards */ int isartc_type = 0; /* (C) enable ISA RTC card */ int gfxcard[GFXCARD_MAX] = { 0, 0 }; /* (C) graphics/video card */ int show_second_monitors = 1; /* (C) show non-primary monitors */ @@ -186,6 +191,7 @@ int voodoo_enabled = 0; /* (C) video o int lba_enhancer_enabled = 0; /* (C) enable Vision Systems LBA Enhancer */ int ibm8514_standalone_enabled = 0; /* (C) video option */ int xga_standalone_enabled = 0; /* (C) video option */ +int da2_standalone_enabled = 0; /* (C) video option */ uint32_t mem_size = 0; /* (C) memory size (Installed on system board)*/ uint32_t isa_mem_size = 0; /* (C) memory size (ISA Memory Cards) */ @@ -207,13 +213,49 @@ int video_fullscreen_scale_maximized = 0; /* (C) Whether int do_auto_pause = 0; /* (C) Auto-pause the emulator on focus loss */ int hook_enabled = 1; /* (C) Keyboard hook is enabled */ +int test_mode = 0; /* (C) Test mode */ char uuid[MAX_UUID_LEN] = { '\0' }; /* (C) UUID or machine identifier */ +int sound_muted = 0; /* (C) Is sound muted? */ +int inhibit_multimedia_keys; /* (C) Inhibit multimedia keys on Windows. */ int other_ide_present = 0; /* IDE controllers from non-IDE cards are present */ int other_scsi_present = 0; /* SCSI controllers from non-SCSI cards are present */ +// Accelerator key array +struct accelKey acc_keys[NUM_ACCELS]; + +// Default accelerator key values +struct accelKey def_acc_keys[NUM_ACCELS] = { + { .name="send_ctrl_alt_del", .desc="Send Control+Alt+Del", + .seq="Ctrl+F12" }, + + { .name="send_ctrl_alt_esc", .desc="Send Control+Alt+Escape", + .seq="Ctrl+F10" }, + + { .name="fullscreen", .desc="Toggle fullscreen", + .seq="Ctrl+Alt+PgUp" }, + + { .name="screenshot", .desc="Screenshot", + .seq="Ctrl+F11" }, + + { .name="release_mouse", .desc="Release mouse pointer", + .seq="Ctrl+End" }, + + { .name="hard_reset", .desc="Hard reset", + .seq="Ctrl+Alt+F12" }, + + { .name="pause", .desc="Toggle pause", + .seq="Ctrl+Alt+F1" }, + + { .name="mute", .desc="Toggle mute", + .seq="Ctrl+Alt+M" } +}; + +char vmm_path[1024] = { '\0'}; /* TEMPORARY - VM manager path to scan for VMs */ +int vmm_enabled = 0; + /* Statistics. */ extern int mmuflush; extern int readlnum; @@ -227,6 +269,8 @@ extern int CPUID; extern int output; int atfullspeed; +extern double exp_pow_table[0x800]; + 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 */ @@ -246,18 +290,44 @@ int unscaled_size_y = SCREEN_RES_Y; /* current unscaled size Y */ int efscrnsz_y = SCREEN_RES_Y; #endif +__thread int is_cpu_thread = 0; + static wchar_t mouse_msg[3][200]; static volatile atomic_int do_pause_ack = 0; static volatile atomic_int pause_ack = 0; #ifndef RELEASE_BUILD -static char buff[1024]; -static int seen = 0; + +#define LOG_SIZE_BUFFER 1024 /* Log size buffer */ + +static char buff[LOG_SIZE_BUFFER]; + +static int seen = 0; static int suppr_seen = 1; + +// Functions only used in this translation unit +void pclog_ensure_stdlog_open(void); #endif +/* + Ensures STDLOG is open for pclog_ex and pclog_ex_cyclic +*/ +void pclog_ensure_stdlog_open(void) +{ +#ifndef RELEASE_BUILD + if (stdlog == NULL) { + if (log_path[0] != '\0') { + stdlog = plat_fopen(log_path, "w"); + if (stdlog == NULL) + stdlog = stdout; + } else + stdlog = stdout; + } +#endif +} + /* * Log something to the logfile or stdout. * @@ -266,22 +336,15 @@ static int suppr_seen = 1; * being logged, and catch repeating entries. */ void -pclog_ex(const char *fmt, va_list ap) +pclog_ex(UNUSED(const char *fmt), UNUSED(va_list ap)) { #ifndef RELEASE_BUILD - char temp[1024]; + char temp[LOG_SIZE_BUFFER]; if (strcmp(fmt, "") == 0) return; - if (stdlog == NULL) { - if (log_path[0] != '\0') { - stdlog = plat_fopen(log_path, "w"); - if (stdlog == NULL) - stdlog = stdout; - } else - stdlog = stdout; - } + pclog_ensure_stdlog_open(); vsprintf(temp, fmt, ap); if (suppr_seen && !strcmp(buff, temp)) @@ -298,6 +361,8 @@ pclog_ex(const char *fmt, va_list ap) #endif } + + void pclog_toggle_suppr(void) { @@ -308,7 +373,7 @@ pclog_toggle_suppr(void) /* Log something. We only do this in non-release builds. */ void -pclog(const char *fmt, ...) +pclog(UNUSED(const char *fmt), ...) { #ifndef RELEASE_BUILD va_list ap; @@ -410,6 +475,75 @@ fatal_ex(const char *fmt, va_list ap) fflush(stdlog); } +/* Log a warning error, and display a UI message without exiting. */ +void +warning(const char *fmt, ...) +{ + char temp[1024]; + va_list ap; + char *sp; + + va_start(ap, fmt); + + if (stdlog == NULL) { + if (log_path[0] != '\0') { + stdlog = plat_fopen(log_path, "w"); + if (stdlog == NULL) + stdlog = stdout; + } else + stdlog = stdout; + } + + vsprintf(temp, fmt, ap); + fprintf(stdlog, "%s", temp); + fflush(stdlog); + va_end(ap); + + /* Make sure the message does not have a trailing newline. */ + if ((sp = strchr(temp, '\n')) != NULL) + *sp = '\0'; + + do_pause(2); + + ui_msgbox(MBX_ERROR | MBX_ANSI, temp); + + fflush(stdlog); + + do_pause(0); +} + +void +warning_ex(const char *fmt, va_list ap) +{ + char temp[1024]; + char *sp; + + if (stdlog == NULL) { + if (log_path[0] != '\0') { + stdlog = plat_fopen(log_path, "w"); + if (stdlog == NULL) + stdlog = stdout; + } else + stdlog = stdout; + } + + vsprintf(temp, fmt, ap); + fprintf(stdlog, "%s", temp); + fflush(stdlog); + + /* Make sure the message does not have a trailing newline. */ + if ((sp = strchr(temp, '\n')) != NULL) + *sp = '\0'; + + do_pause(2); + + ui_msgbox(MBX_ERROR | MBX_ANSI, temp); + + fflush(stdlog); + + do_pause(0); +} + #ifdef ENABLE_PC_LOG int pc_do_log = ENABLE_PC_LOG; @@ -435,7 +569,7 @@ delete_nvr_file(uint8_t flash) int c; /* Set up the NVR file's name. */ - c = strlen(machine_get_internal_name()) + 5; + c = strlen(machine_get_nvr_name()) + 5; fn = (char *) malloc(c + 1); if (fn == NULL) @@ -443,9 +577,9 @@ delete_nvr_file(uint8_t flash) flash ? "BIOS flash" : "CMOS"); if (flash) - sprintf(fn, "%s.bin", machine_get_internal_name()); + sprintf(fn, "%s.bin", machine_get_nvr_name()); else - sprintf(fn, "%s.nvr", machine_get_internal_name()); + sprintf(fn, "%s.nvr", machine_get_nvr_name()); remove(nvr_path(fn)); @@ -455,6 +589,62 @@ delete_nvr_file(uint8_t flash) extern void device_find_all_descs(void); +static void +pc_show_usage(char *s) +{ + char p[4096] = { 0 }; + + sprintf(p, + "\n%sUsage: 86box [options] [cfg-file]\n\n" + "Valid options are:\n\n" + "-? or --help\t\t\t- show this information\n" + "-C or --config path\t\t- set 'path' to be config file\n" +#ifdef _WIN32 + "-D or --debug\t\t\t- force debug output logging\n" +#endif +#if 1 + "-E or --vmmpath\t\t- vm manager path\n" +#endif + "-F or --fullscreen\t\t- start in fullscreen mode\n" + "-G or --lang langid\t\t- start with specified language\n" + "\t\t\t\t (e.g. en-US, or system)\n" +#ifdef _WIN32 + "-H or --hwnd id,hwnd\t\t- sends back the main dialog's hwnd\n" +#endif + "-I or --image d:path\t\t- load 'path' as floppy image on drive d\n" +#ifdef USE_INSTRUMENT + "-J or --instrument name\t- set 'name' to be the profiling instrument\n" +#endif + "-L or --logfile pat\t\t- set 'path' to be the logfile\n" + "-M or --missing\t\t- dump missing machines and video cards\n" + "-N or --noconfirm\t\t- do not ask for confirmation on quit\n" + "-P or --vmpath path\t\t- set 'path' to be root for vm\n" + "-R or --rompath path\t\t- set 'path' to be ROM path\n" +#ifndef USE_SDL_UI + "-S or --settings\t\t\t- show only the settings dialog\n" +#endif + "-T or --testmode\t\t- test mode: execute the test mode entry\n" + "\t\t\t\t point on init/hard reset\n" + "-V or --vmname name\t\t- overrides the name of the running VM\n" + "-W or --nohook\t\t- disables keyboard hook\n" + "\t\t\t\t (compatibility-only outside Windows)\n" + "-X or --clear what\t\t- clears the 'what' (cmos/flash/both)\n" + "-Y or --donothing\t\t- do not show any UI or run the emulation\n" + "-Z or --lastvmpath\t\t- the last parameter is VM path rather\n" + "\t\t\t\t than config\n" + "\nA config file can be specified. If none is, the default file will be used.\n", + (s == NULL) ? "" : s); + +#ifdef _WIN32 + ui_msgbox(MBX_ANSI | ((s == NULL) ? MBX_INFO : MBX_WARNING), p); +#else + if (s == NULL) + pclog("%s", p); + else + ui_msgbox(MBX_ANSI | MBX_WARNING, p); +#endif +} + /* * Perform initial startup of the PC. * @@ -478,6 +668,9 @@ pc_init(int argc, char *argv[]) time_t now; int c; int lvmp = 0; +#ifdef DEPRECATE_USAGE + int deprecated = 1; +#endif #ifdef ENABLE_NG int ng = 0; #endif @@ -485,7 +678,7 @@ pc_init(int argc, char *argv[]) uint32_t *uid; uint32_t *shwnd; #endif - uint32_t lang_init = 0; + int lang_init = 0; /* Grab the executable's full path. */ plat_get_exe_name(exe_path, sizeof(exe_path) - 1); @@ -535,40 +728,7 @@ usage: } } - printf("\nUsage: 86box [options] [cfg-file]\n\n"); - printf("Valid options are:\n\n"); - printf("-? or --help - show this information\n"); - printf("-C or --config path - set 'path' to be config file\n"); -#ifdef _WIN32 - printf("-D or --debug - force debug output logging\n"); -#endif -#if 0 - printf("-E or --nographic - forces the old behavior\n"); -#endif - printf("-F or --fullscreen - start in fullscreen mode\n"); - printf("-G or --lang langid - start with specified language (e.g. en-US, or system)\n"); -#ifdef _WIN32 - printf("-H or --hwnd id,hwnd - sends back the main dialog's hwnd\n"); -#endif - printf("-I or --image d:path - load 'path' as floppy image on drive d\n"); -#ifdef USE_INSTRUMENT - printf("-J or --instrument name - set 'name' to be the profiling instrument\n"); -#endif - printf("-K or --keycodes codes - set 'codes' to be the uncapture combination\n"); - printf("-L or --logfile path - set 'path' to be the logfile\n"); - printf("-M or --missing - dump missing machines and video cards\n"); - printf("-N or --noconfirm - do not ask for confirmation on quit\n"); - printf("-P or --vmpath path - set 'path' to be root for vm\n"); - printf("-R or --rompath path - set 'path' to be ROM path\n"); -#ifndef USE_SDL_UI - printf("-S or --settings - show only the settings dialog\n"); -#endif - printf("-V or --vmname name - overrides the name of the running VM\n"); - printf("-W or --nohook - disables keyboard hook (compatibility-only outside Windows)\n"); - printf("-X or --clear what - clears the 'what' (cmos/flash/both)\n"); - printf("-Y or --donothing - do not show any UI or run the emulation\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"); + pc_show_usage(NULL); return 0; } else if (!strcasecmp(argv[c], "--lastvmpath") || !strcasecmp(argv[c], "-Z")) { lvmp = 1; @@ -576,13 +736,18 @@ usage: } else if (!strcasecmp(argv[c], "--debug") || !strcasecmp(argv[c], "-D")) { force_debug = 1; #endif -#ifdef ENABLE_NG - } else if (!strcasecmp(argv[c], "--nographic") || !strcasecmp(argv[c], "-E")) { - /* Currently does nothing, but if/when we implement a built-in manager, - it's going to force the manager not to run, allowing the old usage - without parameter. */ - ng = 1; -#endif +//#ifdef ENABLE_NG + } else if (!strcasecmp(argv[c], "--vmmpath") || + !strcasecmp(argv[c], "-E")) { + /* Using this variable for vm manager path + Temporary solution!*/ + if ((c+1) == argc) goto usage; + char *vp = argv[++c]; + if ((strlen(vp) + 1) >= sizeof(vmm_path)) + memcpy(vmm_path, vp, sizeof(vmm_path)); + else + memcpy(vmm_path, vp, strlen(vp) + 1); + //#endif } else if (!strcasecmp(argv[c], "--fullscreen") || !strcasecmp(argv[c], "-F")) { start_in_fullscreen = 1; } else if (!strcasecmp(argv[c], "--logfile") || !strcasecmp(argv[c], "-L")) { @@ -595,6 +760,9 @@ usage: goto usage; ppath = argv[++c]; +#ifdef DEPRECATE_USAGE + deprecated = 0; +#endif } else if (!strcasecmp(argv[c], "--rompath") || !strcasecmp(argv[c], "-R")) { if ((c + 1) == argc) goto usage; @@ -606,6 +774,9 @@ usage: goto usage; cfg = argv[++c]; +#ifdef DEPRECATE_USAGE + deprecated = 0; +#endif } else if (!strcasecmp(argv[c], "--image") || !strcasecmp(argv[c], "-I")) { if ((c + 1) == argc) goto usage; @@ -634,6 +805,8 @@ usage: } else if (!strcasecmp(argv[c], "--settings") || !strcasecmp(argv[c], "-S")) { settings_only = 1; #endif + } else if (!strcasecmp(argv[c], "--testmode") || !strcasecmp(argv[c], "-T")) { + test_mode = 1; } else if (!strcasecmp(argv[c], "--noconfirm") || !strcasecmp(argv[c], "-N")) { confirm_exit_cmdl = 0; } else if (!strcasecmp(argv[c], "--missing") || !strcasecmp(argv[c], "-M")) { @@ -642,13 +815,6 @@ usage: do_nothing = 1; } else if (!strcasecmp(argv[c], "--nohook") || !strcasecmp(argv[c], "-W")) { hook_enabled = 0; - } else if (!strcasecmp(argv[c], "--keycodes") || !strcasecmp(argv[c], "-K")) { - if ((c + 1) == argc) - goto usage; - - sscanf(argv[++c], "%03hX,%03hX,%03hX,%03hX,%03hX,%03hX", - &key_prefix_1_1, &key_prefix_1_2, &key_prefix_2_1, &key_prefix_2_2, - &key_uncapture_1, &key_uncapture_2); } else if (!strcasecmp(argv[c], "--clearboth") || !strcasecmp(argv[c], "-X")) { if ((c + 1) == argc) goto usage; @@ -709,11 +875,22 @@ usage: ppath = argv[c++]; else cfg = argv[c++]; + +#ifdef DEPRECATE_USAGE + deprecated = 0; +#endif } if (c != argc) goto usage; +#ifdef DEPRECATE_USAGE + if (deprecated) + pc_show_usage("Running 86Box without a specified VM path and/or configuration\n" + "file has been deprected. Please specify one or use a manager\n" + "(Avalonia 86 is recommended).\n\n"); +#endif + path_slash(usr_path); path_slash(rom_path); @@ -857,6 +1034,10 @@ usage: } pclog("# Configuration file: %s\n#\n\n", cfg_path); + if (strlen(vmm_path) != 0) { + vmm_enabled = 1; + pclog("# VM Manager enabled. Path: %s\n", vmm_path); + } /* * We are about to read the configuration file, which MAY * put data into global variables (the hard- and floppy @@ -870,6 +1051,13 @@ usage: zip_global_init(); mo_global_init(); + /* Initialize the keyboard accelerator list with default values */ + for (int x = 0; x < NUM_ACCELS; x++) { + strcpy(acc_keys[x].name, def_acc_keys[x].name); + strcpy(acc_keys[x].desc, def_acc_keys[x].desc); + strcpy(acc_keys[x].seq, def_acc_keys[x].seq); + } + /* Load the configuration file. */ config_load(); @@ -1056,6 +1244,11 @@ pc_init_modules(void) machine_status_init(); + for (c = 0; c <= 0x7ff; c++) { + int64_t exp = c - 1023; /* 1023 = BIAS64 */ + exp_pow_table[c] = pow(2.0, (double) exp); + } + if (do_nothing) { do_nothing = 0; exit(-1); @@ -1067,13 +1260,52 @@ pc_init_modules(void) void pc_send_ca(uint16_t sc) { - keyboard_input(1, 0x1D); /* Ctrl key pressed */ - keyboard_input(1, 0x38); /* Alt key pressed */ - keyboard_input(1, sc); - usleep(50000); - keyboard_input(0, sc); - keyboard_input(0, 0x38); /* Alt key released */ - keyboard_input(0, 0x1D); /* Ctrl key released */ + if (keyboard_mode >= 0x81) { + /* Use R-Alt because PS/55 DOS and OS/2 assign L-Alt Kanji */ + keyboard_input(1, 0x1D); /* Ctrl key pressed */ + if (keyboard_get_in_reset()) + return; + keyboard_input(1, 0x138); /* R-Alt key pressed */ + if (keyboard_get_in_reset()) + return; + keyboard_input(1, sc); + if (keyboard_get_in_reset()) + return; + usleep(50000); + if (keyboard_get_in_reset()) + return; + keyboard_input(0, sc); + if (keyboard_get_in_reset()) + return; + keyboard_input(0, 0x138); /* R-Alt key released */ + if (keyboard_get_in_reset()) + return; + keyboard_input(0, 0x1D); /* Ctrl key released */ + if (keyboard_get_in_reset()) + return; + } else { + keyboard_input(1, 0x1D); /* Ctrl key pressed */ + if (keyboard_get_in_reset()) + return; + keyboard_input(1, 0x38); /* Alt key pressed */ + if (keyboard_get_in_reset()) + return; + keyboard_input(1, sc); + if (keyboard_get_in_reset()) + return; + usleep(50000); + if (keyboard_get_in_reset()) + return; + keyboard_input(0, sc); + if (keyboard_get_in_reset()) + return; + keyboard_input(0, 0x38); /* Alt key released */ + if (keyboard_get_in_reset()) + return; + keyboard_input(0, 0x1D); /* Ctrl key released */ + if (keyboard_get_in_reset()) + return; + } } /* Send the machine a Control-Alt-DEL sequence. */ @@ -1090,6 +1322,27 @@ pc_send_cae(void) pc_send_ca(1); } +/* + Currently available API: + + extern void resetx86(void); + extern void softresetx86(void); + extern void hardresetx86(void); + + extern void prefetch_queue_set_pos(int pos); + extern void prefetch_queue_set_ip(uint16_t ip); + extern void prefetch_queue_set_prefetching(int p); + extern int prefetch_queue_get_pos(void); + extern uint16_t prefetch_queue_get_ip(void); + extern int prefetch_queue_get_prefetching(void); + extern int prefetch_queue_get_size(void); + */ +static void +pc_test_mode_entry_point(void) +{ + pclog("Test mode entry point\n=====================\n"); +} + void pc_reset_hard_close(void) { @@ -1154,6 +1407,8 @@ pc_reset_hard_init(void) * modules that are. */ + keyboard_init(); + /* Reset the IDE and SCSI presences */ other_ide_present = other_scsi_present = 0; @@ -1230,6 +1485,10 @@ pc_reset_hard_init(void) zip_hard_reset(); + + /* Reset any ISA ROM cards. */ + isarom_reset(); + /* Reset any ISA RTC cards. */ isartc_reset(); @@ -1291,6 +1550,9 @@ pc_reset_hard_init(void) update_mouse_msg(); + if (test_mode) + pc_test_mode_entry_point(); + ui_hard_reset_completed(); } @@ -1394,6 +1656,10 @@ pc_close(UNUSED(thread_t *ptr)) scsi_disk_close(); gdbstub_close(); + +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) + mem_free(); +#endif } #ifdef __APPLE__ @@ -1427,6 +1693,9 @@ pc_run(void) pc_reset_hard_init(); } + /* Update the guest-CPU independent timer for devices with independent clock speed */ + rivatimer_update_all(); + /* Run a block of code. */ startblit(); cpu_exec((int32_t) cpu_s->rspeed / 100); @@ -1477,6 +1746,8 @@ 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; + int is_svga = (video_get_type_monitor(monitor_index) == VIDEO_FLAG_TYPE_SPECIAL) || + (video_get_type_monitor(monitor_index) == VIDEO_FLAG_TYPE_8514); double dx; double dy; double dtx; @@ -1510,19 +1781,19 @@ set_screen_size_monitor(int x, int y, int monitor_index) dty = (double) temp_overscan_y; /* Account for possible overscan. */ - if (video_get_type_monitor(monitor_index) != VIDEO_FLAG_TYPE_SPECIAL && (temp_overscan_y == 16)) { + if (!is_svga && (temp_overscan_y == 16)) { /* CGA */ dy = (((dx - dtx) / 4.0) * 3.0) + dty; - } else if (video_get_type_monitor(monitor_index) != VIDEO_FLAG_TYPE_SPECIAL && (temp_overscan_y < 16)) { + } else if (!is_svga && (temp_overscan_y < 16)) { /* MDA/Hercules */ - dy = (x / 4.0) * 3.0; + dy = (dx / 4.0) * 3.0; } else { if (enable_overscan) { /* EGA/(S)VGA with overscan */ dy = (((dx - dtx) / 4.0) * 3.0) + dty; } else { /* EGA/(S)VGA without overscan */ - dy = (x / 4.0) * 3.0; + dy = (dx / 4.0) * 3.0; } } monitors[monitor_index].mon_unscaled_size_y = (int) dy; @@ -1639,3 +1910,16 @@ do_pause(int p) } atomic_store(&pause_ack, 0); } + +// Helper to find an accelerator key and return it's index in acc_keys +int FindAccelerator(const char *name) { + for(int x=0;x COMMENT "Disable PaX MPROTECT") +endif() diff --git a/src/acpi.c b/src/acpi.c index 339ea7dcf..e7a0de53d 100644 --- a/src/acpi.c +++ b/src/acpi.c @@ -36,6 +36,7 @@ #include <86box/pit.h> #include <86box/apm.h> #include <86box/acpi.h> +#include <86box/dma.h> #include <86box/machine.h> #include <86box/i2c.h> #include <86box/video.h> @@ -89,7 +90,7 @@ acpi_timer_get(acpi_t *dev) } static uint8_t -acpi_gp_timer_get(acpi_t *dev) +acpi_gp_timer_get(UNUSED(acpi_t *dev)) { uint64_t clock = acpi_clock_get(); clock -= acpi_last_clock; @@ -211,7 +212,10 @@ acpi_update_irq(acpi_t *dev) if ((dev->regs.pmcntrl & 0x01) && sci_level) switch (dev->irq_mode) { default: - picintlevel(1 << dev->irq_line, &dev->irq_state); + if (dev->irq_line != 0) + picintlevel(1 << dev->irq_line, &dev->irq_state); + else + dev->irq_state = 1; break; case 1: pci_set_irq(dev->slot, dev->irq_pin, &dev->irq_state); @@ -223,7 +227,10 @@ acpi_update_irq(acpi_t *dev) break; } else switch (dev->irq_mode) { default: - picintclevel(1 << dev->irq_line, &dev->irq_state); + if (dev->irq_line != 0) + picintclevel(1 << dev->irq_line, &dev->irq_state); + else + dev->irq_state = 0; break; case 1: pci_clear_irq(dev->slot, dev->irq_pin, &dev->irq_state); @@ -1019,8 +1026,13 @@ acpi_reg_write_common_regs(UNUSED(int size), uint16_t addr, uint8_t val, void *p nvr_reg_write(0x000f, 0xff, dev->nvr); } - if (sus_typ & SUS_RESET_PCI) + if (sus_typ & SUS_RESET_PCI) { + /* DMA is part of the southbridge so it responds to PCI reset. */ + dma_reset(); + dma_set_at(1); + device_reset_all(DEVICE_PCI); + } if (sus_typ & SUS_RESET_CPU) cpu_alt_reset = 0; @@ -2381,6 +2393,14 @@ acpi_reset(void *priv) dev->regs.gpi_val = 0xfff57fc1; if (!strcmp(machine_get_internal_name(), "ficva503a") || !strcmp(machine_get_internal_name(), "6via90ap")) dev->regs.gpi_val |= 0x00000004; + /* + TriGem Delhi-III second GPI word: + - Bit 7 = Save CMOS (must be set); + - Bit 6 = Password jumper (must be set); + - Bit 5 = Enable Setup (must be set). + */ + else if (!strcmp(machine_get_internal_name(), "delhi3")) + dev->regs.gpi_val |= 0x00008000; } if (acpi_power_on) { @@ -2473,10 +2493,9 @@ acpi_init(const device_t *info) { acpi_t *dev; - dev = (acpi_t *) malloc(sizeof(acpi_t)); + dev = (acpi_t *) calloc(1, sizeof(acpi_t)); if (dev == NULL) return NULL; - memset(dev, 0x00, sizeof(acpi_t)); cpu_to_acpi = ACPI_TIMER_FREQ / cpuclock; dev->vendor = info->local; @@ -2576,7 +2595,7 @@ const device_t acpi_ali_device = { .init = acpi_init, .close = acpi_close, .reset = acpi_reset, - { .available = NULL }, + .available = NULL, .speed_changed = acpi_speed_changed, .force_redraw = NULL, .config = NULL @@ -2590,7 +2609,7 @@ const device_t acpi_intel_device = { .init = acpi_init, .close = acpi_close, .reset = acpi_reset, - { .available = NULL }, + .available = NULL, .speed_changed = acpi_speed_changed, .force_redraw = NULL, .config = NULL @@ -2604,7 +2623,7 @@ const device_t acpi_via_device = { .init = acpi_init, .close = acpi_close, .reset = acpi_reset, - { .available = NULL }, + .available = NULL, .speed_changed = acpi_speed_changed, .force_redraw = NULL, .config = NULL @@ -2618,7 +2637,7 @@ const device_t acpi_via_596b_device = { .init = acpi_init, .close = acpi_close, .reset = acpi_reset, - { .available = NULL }, + .available = NULL, .speed_changed = acpi_speed_changed, .force_redraw = NULL, .config = NULL @@ -2632,7 +2651,7 @@ const device_t acpi_smc_device = { .init = acpi_init, .close = acpi_close, .reset = acpi_reset, - { .available = NULL }, + .available = NULL, .speed_changed = acpi_speed_changed, .force_redraw = NULL, .config = NULL @@ -2646,7 +2665,7 @@ const device_t acpi_sis_5582_device = { .init = acpi_init, .close = acpi_close, .reset = acpi_reset, - { .available = NULL }, + .available = NULL, .speed_changed = acpi_speed_changed, .force_redraw = NULL, .config = NULL @@ -2660,7 +2679,7 @@ const device_t acpi_sis_5595_1997_device = { .init = acpi_init, .close = acpi_close, .reset = acpi_reset, - { .available = NULL }, + .available = NULL, .speed_changed = acpi_speed_changed, .force_redraw = NULL, .config = NULL @@ -2674,7 +2693,7 @@ const device_t acpi_sis_5595_device = { .init = acpi_init, .close = acpi_close, .reset = acpi_reset, - { .available = NULL }, + .available = NULL, .speed_changed = acpi_speed_changed, .force_redraw = NULL, .config = NULL diff --git a/src/apm.c b/src/apm.c index d7ce262a3..3973f2b23 100644 --- a/src/apm.c +++ b/src/apm.c @@ -122,7 +122,7 @@ const device_t apm_device = { .init = apm_init, .close = apm_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -136,7 +136,7 @@ const device_t apm_pci_device = { .init = apm_init, .close = apm_close, .reset = apm_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -150,7 +150,7 @@ const device_t apm_pci_acpi_device = { .init = apm_init, .close = apm_close, .reset = apm_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/cdrom/CMakeLists.txt b/src/cdrom/CMakeLists.txt index 2f0f1cd23..621b069b0 100644 --- a/src/cdrom/CMakeLists.txt +++ b/src/cdrom/CMakeLists.txt @@ -21,10 +21,8 @@ pkg_check_modules(SNDFILE REQUIRED IMPORTED_TARGET sndfile) add_library(cdrom OBJECT cdrom.c - cdrom_image_backend.c - cdrom_image_viso.c cdrom_image.c - cdrom_ioctl.c + cdrom_image_viso.c ) target_link_libraries(86Box PkgConfig::SNDFILE) diff --git a/src/cdrom/cdrom.c b/src/cdrom/cdrom.c index 6d993f24a..e0fa8b0b6 100644 --- a/src/cdrom/cdrom.c +++ b/src/cdrom/cdrom.c @@ -15,105 +15,92 @@ * Copyright 2018-2021 Miran Grca. */ #include +#ifdef ENABLE_CDROM_LOG #include +#endif #include #include #include #include #include -#define HAVE_STDARG_H #include <86box/86box.h> #include <86box/device.h> #include <86box/config.h> #include <86box/cdrom.h> #include <86box/cdrom_image.h> #include <86box/cdrom_interface.h> +#ifdef USE_CDROM_MITSUMI #include <86box/cdrom_mitsumi.h> +#endif +#include <86box/log.h> #include <86box/plat.h> +#include <86box/plat_cdrom_ioctl.h> #include <86box/scsi.h> #include <86box/scsi_device.h> +#include <86box/scsi_cdrom.h> #include <86box/sound.h> - -/* 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. */ -#undef MSFtoLBA -#define MSFtoLBA(m, s, f) ((((m * 60) + s) * 75) + f) +#include <86box/ui.h> #define RAW_SECTOR_SIZE 2352 -#define COOKED_SECTOR_SIZE 2048 #define MIN_SEEK 2000 #define MAX_SEEK 333333 -#pragma pack(push, 1) -typedef struct { - uint8_t user_data[2048], - ecc[288]; -} m1_data_t; - -typedef struct { - uint8_t sub_header[8], - user_data[2328]; -} m2_data_t; - -typedef union { - m1_data_t m1_data; - m2_data_t m2_data; - uint8_t raw_data[2336]; -} sector_data_t; - -typedef struct { - uint8_t sync[12]; - uint8_t header[4]; - sector_data_t data; -} sector_raw_data_t; - -typedef union { - sector_raw_data_t sector_data; - uint8_t raw_data[2352]; -} sector_t; - -typedef struct { - sector_t sector; - uint8_t c2[296]; - uint8_t subchannel_raw[96]; - uint8_t subchannel_q[16]; - uint8_t subchannel_rw[96]; -} cdrom_sector_t; - -typedef union { - cdrom_sector_t cdrom_sector; - uint8_t buffer[2856]; -} sector_buffer_t; -#pragma pack(pop) - -static int cdrom_sector_size; -static uint8_t raw_buffer[2856]; /* Needs to be the same size as sector_buffer_t in the structs. */ -static uint8_t extra_buffer[296]; - -cdrom_t cdrom[CDROM_NUM]; +cdrom_t cdrom[CDROM_NUM] = { 0 }; int cdrom_interface_current; +int cdrom_assigned_letters = 0; #ifdef ENABLE_CDROM_LOG int cdrom_do_log = ENABLE_CDROM_LOG; -void -cdrom_log(const char *fmt, ...) +static void +cdrom_log(void *priv, const char *fmt, ...) { - va_list ap; - if (cdrom_do_log) { + va_list ap; va_start(ap, fmt); - pclog_ex(fmt, ap); + log_out(priv, fmt, ap); va_end(ap); } } #else -# define cdrom_log(fmt, ...) +# define cdrom_log(priv, fmt, ...) #endif +static void process_mode1(cdrom_t *dev, const int cdrom_sector_flags, + uint8_t *b); +static void process_mode2_non_xa(cdrom_t *dev, const int cdrom_sector_flags, + uint8_t *b); +static void process_mode2_xa_form1(cdrom_t *dev, const int cdrom_sector_flags, + uint8_t *b); +static void process_mode2_xa_form2(cdrom_t *dev, const int cdrom_sector_flags, + uint8_t *b); + +typedef void (*cdrom_process_data_t)(cdrom_t *dev, const int cdrom_sector_flags, + uint8_t *b); + +static cdrom_process_data_t cdrom_process_data[4] = { process_mode1, process_mode2_non_xa, + process_mode2_xa_form1, process_mode2_xa_form2 }; +#ifdef ENABLE_CDROM_LOG +static char * cdrom_req_modes[14] = { "Any", "Audio", "Mode 1", "Mode 2", + "CD-I/XA Mode 2 Form 1", "CD-I/XA Mode 2 Form 2", "Unk", "Unk", + "Any Data", "Any Data - 4", + "CD-I/XA Mode 2 Form 1", "CD-I/XA Mode 2 Form 1 - 4", + "Any CD-I/XA Data", "Any CD-I/XA Data - 4" }; +static char * cdrom_modes[4] = { "Mode 1", "Mode 2", "CD-I/XA Mode 2 Form 1", "CD-I/XA Mode 2 Form 2" }; +#endif +static uint8_t cdrom_mode_masks[14] = { 0x0f, 0x00, 0x01, 0x02, 0x04, 0x08, 0x00, 0x00, + 0x05, 0x05, 0x04, 0x04, 0x0c, 0x0c }; + +static uint8_t status_codes[2][16] = { { 0x13, 0x15, 0x15, 0x15, 0x12, 0x11, 0x13, 0x13, + 0x12, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15 }, + { 0x00, 0x00, 0x00, 0x00, 0x15, 0x11, 0x00, 0x00, + 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }; +static int mult = 1; +static int part = 0; +static int ecc_diff = 288; + static const device_t cdrom_interface_none_device = { .name = "None", .internal_name = "none", @@ -122,7 +109,7 @@ static const device_t cdrom_interface_none_device = { .init = NULL, .close = NULL, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -133,150 +120,64 @@ static const struct { } controllers[] = { // clang-format off { &cdrom_interface_none_device }, +#ifdef USE_CDROM_MITSUMI + { &mitsumi_cdrom_device }, +#endif { NULL } // clang-format on }; -/* Reset the CD-ROM Interface, whichever one that is. */ -void -cdrom_interface_reset(void) +/* Private functions. */ +static void +cdrom_generate_name(const int type, char *name, const int internal) { - cdrom_log("CD-ROM Interface: reset(current=%d)\n", - cdrom_interface_current); + char elements[3][512] = { 0 }; - /* If we have a valid controller, add its device. */ - if ((cdrom_interface_current > 0) && controllers[cdrom_interface_current].device) - device_add(controllers[cdrom_interface_current].device); -} + memcpy(elements[0], cdrom_drive_types[type].vendor, + strlen(cdrom_drive_types[type].vendor) + 1); + if (internal) for (int i = 0; i < strlen(elements[0]); i++) + if (elements[0][i] == ' ') + elements[0][i] = '_'; -const char * -cdrom_interface_get_internal_name(int cdinterface) -{ - return device_get_internal_name(controllers[cdinterface].device); -} + if (internal) { + int j = 0; + for (int i = 0; i <= strlen(cdrom_drive_types[type].model); i++) + if (cdrom_drive_types[type].model[i] != ':') + elements[1][j++] = cdrom_drive_types[type].model[i]; + } else + memcpy(elements[1], cdrom_drive_types[type].model, + strlen(cdrom_drive_types[type].model) + 1); + char *s = strstr(elements[1], " "); + if (s != NULL) + s[0] = 0x00; + if (internal) for (int i = 0; i < strlen(elements[1]); i++) + if (elements[1][i] == ' ') + elements[1][i] = '_'; -int -cdrom_interface_get_from_internal_name(char *s) -{ - int c = 0; + memcpy(elements[2], cdrom_drive_types[type].revision, + strlen(cdrom_drive_types[type].revision) + 1); + s = strstr(elements[2], " "); + if (s != NULL) + s[0] = 0x00; + if (internal) for (int i = 0; i < strlen(elements[2]); i++) + if (elements[2][i] == ' ') + elements[2][i] = '_'; - while (controllers[c].device != NULL) { - if (!strcmp(controllers[c].device->internal_name, s)) - return c; - c++; - } - - return 0; -} - -const device_t * -cdrom_interface_get_device(int cdinterface) -{ - return (controllers[cdinterface].device); -} - -int -cdrom_interface_has_config(int cdinterface) -{ - const device_t *dev = cdrom_interface_get_device(cdinterface); - - if (dev == NULL) - return 0; - - if (!device_has_config(dev)) - return 0; - - return 1; -} - -int -cdrom_interface_get_flags(int cdinterface) -{ - return (controllers[cdinterface].device->flags); -} - -int -cdrom_interface_available(int cdinterface) -{ - return (device_available(controllers[cdinterface].device)); -} - -char * -cdrom_getname(int type) -{ - return (char *) cdrom_drive_types[type].name; -} - -char * -cdrom_get_internal_name(int type) -{ - return (char *) cdrom_drive_types[type].internal_name; -} - -int -cdrom_get_from_internal_name(char *s) -{ - int c = 0; - - while (strlen(cdrom_drive_types[c].internal_name)) { - if (!strcmp((char *) cdrom_drive_types[c].internal_name, s)) - return c; - c++; - } - - return 0; -} - -void -cdrom_set_type(int model, int type) -{ - cdrom[model].type = type; -} - -int -cdrom_get_type(int model) -{ - return cdrom[model].type; -} - -static __inline int -bin2bcd(int x) -{ - return (x % 10) | ((x / 10) << 4); -} - -static __inline int -bcd2bin(int x) -{ - return (x >> 4) * 10 + (x & 0x0f); -} - -int -cdrom_lba_to_msf_accurate(int lba) -{ - int pos; - int m; - int s; - int f; - - pos = lba + 150; - f = pos % 75; - pos -= f; - pos /= 75; - s = pos % 60; - pos -= s; - pos /= 60; - m = pos; - - return ((m << 16) | (s << 8) | f); + if (internal) + sprintf(name, "%s_%s_%s", elements[0], elements[1], elements[2]); + else if (cdrom_drive_types[type].speed == -1) + sprintf(name, "%s %s %s", elements[0], elements[1], elements[2]); + else + sprintf(name, "%s %s %s (%ix)", elements[0], elements[1], + elements[2], cdrom_drive_types[type].speed); } static double -cdrom_get_short_seek(cdrom_t *dev) +cdrom_get_short_seek(const cdrom_t *dev) { switch (dev->cur_speed) { case 0: - fatal("CD-ROM %i: 0x speed\n", dev->id); + log_fatal(dev->log, "0x speed\n"); return 0.0; case 1: return 240.0; @@ -324,11 +225,11 @@ cdrom_get_short_seek(cdrom_t *dev) } static double -cdrom_get_long_seek(cdrom_t *dev) +cdrom_get_long_seek(const cdrom_t *dev) { switch (dev->cur_speed) { case 0: - fatal("CD-ROM %i: 0x speed\n", dev->id); + log_fatal(dev->log, "0x speed\n"); return 0.0; case 1: return 1446.0; @@ -375,113 +276,6 @@ cdrom_get_long_seek(cdrom_t *dev) } } -double -cdrom_seek_time(cdrom_t *dev) -{ - uint32_t diff = dev->seek_diff; - double sd = (double) (MAX_SEEK - MIN_SEEK); - - if (diff < MIN_SEEK) - return 0.0; - if (diff > MAX_SEEK) - diff = MAX_SEEK; - - diff -= MIN_SEEK; - - return cdrom_get_short_seek(dev) + ((cdrom_get_long_seek(dev) * ((double) diff)) / sd); -} - -void -cdrom_stop(cdrom_t *dev) -{ - if (dev->cd_status > CD_STATUS_DATA_ONLY) - dev->cd_status = CD_STATUS_STOPPED; -} - -void -cdrom_seek(cdrom_t *dev, uint32_t pos, uint8_t vendor_type) -{ - int m; - int s; - int f; - - if (!dev) - return; - - cdrom_log("CD-ROM %i: Seek to LBA %08X, vendor type = %02x.\n", dev->id, pos, vendor_type); - - switch (vendor_type) { - case 0x40: - m = bcd2bin((pos >> 24) & 0xff); - s = bcd2bin((pos >> 16) & 0xff); - f = bcd2bin((pos >> 8) & 0xff); - pos = MSFtoLBA(m, s, f) - 150; - break; - case 0x80: - pos = bcd2bin((pos >> 24) & 0xff); - break; - default: - break; - } - - dev->seek_pos = pos; - cdrom_stop(dev); -} - -int -cdrom_is_pre(cdrom_t *dev, uint32_t lba) -{ - if (dev->ops && dev->ops->is_track_pre) - return dev->ops->is_track_pre(dev, lba); - - return 0; -} - -int -cdrom_audio_callback(cdrom_t *dev, int16_t *output, int len) -{ - int ret = 1; - - if (!dev->sound_on || (dev->cd_status != CD_STATUS_PLAYING) || dev->audio_muted_soft) { - // cdrom_log("CD-ROM %i: Audio callback while not playing\n", dev->id); - if (dev->cd_status == CD_STATUS_PLAYING) - dev->seek_pos += (len >> 11); - memset(output, 0, len * 2); - return 0; - } - - while (dev->cd_buflen < len) { - if (dev->seek_pos < dev->cd_end) { - if (dev->ops->read_sector(dev, (uint8_t *) &(dev->cd_buffer[dev->cd_buflen]), dev->seek_pos)) { - cdrom_log("CD-ROM %i: Read LBA %08X successful\n", dev->id, dev->seek_pos); - memcpy(dev->subch_buffer, ((uint8_t *) &(dev->cd_buffer[dev->cd_buflen])) + 2352, 96); - dev->seek_pos++; - dev->cd_buflen += (RAW_SECTOR_SIZE / 2); - ret = 1; - } else { - cdrom_log("CD-ROM %i: Read LBA %08X failed\n", dev->id, dev->seek_pos); - memset(&(dev->cd_buffer[dev->cd_buflen]), 0x00, (BUF_SIZE - dev->cd_buflen) * 2); - dev->cd_status = CD_STATUS_STOPPED; - dev->cd_buflen = len; - ret = 0; - } - } else { - cdrom_log("CD-ROM %i: Playing completed\n", dev->id); - memset(&dev->cd_buffer[dev->cd_buflen], 0x00, (BUF_SIZE - dev->cd_buflen) * 2); - dev->cd_status = CD_STATUS_PLAYING_COMPLETED; - dev->cd_buflen = len; - ret = 0; - } - } - - memcpy(output, dev->cd_buffer, len * 2); - memmove(dev->cd_buffer, &dev->cd_buffer[len], (BUF_SIZE - len) * 2); - dev->cd_buflen -= len; - - cdrom_log("CD-ROM %i: Audio callback returning %i\n", dev->id, ret); - return ret; -} - static void msf_from_bcd(int *m, int *s, int *f) { @@ -498,595 +292,66 @@ msf_to_bcd(int *m, int *s, int *f) *f = bin2bcd(*f); } -uint8_t -cdrom_audio_play(cdrom_t *dev, uint32_t pos, uint32_t len, int ismsf) +static int +read_data(cdrom_t *dev, const uint32_t lba) { - track_info_t ti; - int m = 0; - int s = 0; - int f = 0; + int ret = 1; - if (dev->cd_status == CD_STATUS_DATA_ONLY) - return 0; + if (dev->cached_sector != lba) { + dev->cached_sector = lba; - cdrom_log("CD-ROM %i: Play audio - %08X %08X %i\n", dev->id, pos, len, ismsf); - if (ismsf & 0x100) { - /* Track-relative audio play. */ - dev->ops->get_track_info(dev, ismsf & 0xff, 0, &ti); - pos += MSFtoLBA(ti.m, ti.s, ti.f) - 150; - } else if ((ismsf == 2) || (ismsf == 3)) { - dev->ops->get_track_info(dev, pos, 0, &ti); - pos = MSFtoLBA(ti.m, ti.s, ti.f) - 150; - if (ismsf == 2) { - /* We have to end at the *end* of the specified track, - not at the beginning. */ - dev->ops->get_track_info(dev, len, 1, &ti); - len = MSFtoLBA(ti.m, ti.s, ti.f) - 150; - } - } else if (ismsf == 1) { - m = (pos >> 16) & 0xff; - s = (pos >> 8) & 0xff; - f = pos & 0xff; + ret = dev->ops->read_sector(dev->local, + dev->raw_buffer[dev->cur_buf ^ 1], lba); - /* NEC CDR-260 speaks BCD. */ - if ((dev->type == CDROM_TYPE_NEC_260_100) || (dev->type == CDROM_TYPE_NEC_260_101)) /*NEC*/ - msf_from_bcd(&m, &s, &f); - - if (pos == 0xffffff) { - cdrom_log("CD-ROM %i: Playing from current position (MSF)\n", dev->id); - pos = dev->seek_pos; - } else - pos = MSFtoLBA(m, s, f) - 150; - - m = (len >> 16) & 0xff; - s = (len >> 8) & 0xff; - f = len & 0xff; - - /* NEC CDR-260 speaks BCD. */ - if ((dev->type == CDROM_TYPE_NEC_260_100) || (dev->type == CDROM_TYPE_NEC_260_101)) /*NEC*/ - msf_from_bcd(&m, &s, &f); - - len = MSFtoLBA(m, s, f) - 150; - - cdrom_log("CD-ROM %i: MSF - pos = %08X len = %08X\n", dev->id, pos, len); - } else if (ismsf == 0) { - if (pos == 0xffffffff) { - cdrom_log("CD-ROM %i: Playing from current position\n", dev->id); - pos = dev->seek_pos; - } - len += pos; - } - - dev->audio_muted_soft = 0; - /* Do this at this point, since it's at this point that we know the - actual LBA position to start playing from. */ - if (!(dev->ops->track_type(dev, pos) & CD_TRACK_AUDIO)) { - cdrom_log("CD-ROM %i: LBA %08X not on an audio track\n", dev->id, pos); - cdrom_stop(dev); - return 0; - } - - dev->seek_pos = pos; - dev->cd_end = len; - dev->cd_status = CD_STATUS_PLAYING; - dev->cd_buflen = 0; - return 1; -} - -uint8_t -cdrom_audio_track_search(cdrom_t *dev, uint32_t pos, int type, uint8_t playbit) -{ - int m = 0; - int s = 0; - int f = 0; - uint32_t pos2 = 0; - - if (dev->cd_status == CD_STATUS_DATA_ONLY) - return 0; - - cdrom_log("Audio Track Search: MSF = %06x, type = %02x, playbit = %02x\n", pos, type, playbit); - switch (type) { - case 0x00: - if (pos == 0xffffffff) { - cdrom_log("CD-ROM %i: (type 0) Search from current position\n", dev->id); - pos = dev->seek_pos; - } - dev->seek_pos = pos; - break; - case 0x40: - m = bcd2bin((pos >> 24) & 0xff); - s = bcd2bin((pos >> 16) & 0xff); - f = bcd2bin((pos >> 8) & 0xff); - if (pos == 0xffffffff) { - cdrom_log("CD-ROM %i: (type 1) Search from current position\n", dev->id); - pos = dev->seek_pos; - } else - pos = MSFtoLBA(m, s, f) - 150; - - dev->seek_pos = pos; - break; - case 0x80: - if (pos == 0xffffffff) { - cdrom_log("CD-ROM %i: (type 2) Search from current position\n", dev->id); - pos = dev->seek_pos; - } - dev->seek_pos = (pos >> 24) & 0xff; - break; - default: - break; - } - - pos2 = pos - 1; - if (pos2 == 0xffffffff) - pos2 = pos + 1; - - /* Do this at this point, since it's at this point that we know the - actual LBA position to start playing from. */ - if (!(dev->ops->track_type(dev, pos2) & CD_TRACK_AUDIO)) { - cdrom_log("CD-ROM %i: Track Search: LBA %08X not on an audio track\n", dev->id, pos); - dev->audio_muted_soft = 1; - if (dev->ops->track_type(dev, pos) & CD_TRACK_AUDIO) - dev->audio_muted_soft = 0; - } else - dev->audio_muted_soft = 0; - - cdrom_log("Track Search Toshiba: Muted?=%d, LBA=%08X.\n", dev->audio_muted_soft, pos); - dev->cd_buflen = 0; - dev->cd_status = playbit ? CD_STATUS_PLAYING : CD_STATUS_PAUSED; - return 1; -} - -uint8_t -cdrom_audio_track_search_pioneer(cdrom_t *dev, uint32_t pos, uint8_t playbit) -{ - int m = 0; - int s = 0; - int f = 0; - - if (dev->cd_status == CD_STATUS_DATA_ONLY) - return 0; - - f = bcd2bin((pos >> 24) & 0xff); - s = bcd2bin((pos >> 16) & 0xff); - m = bcd2bin((pos >> 8) & 0xff); - if (pos == 0xffffffff) { - pos = dev->seek_pos; - } else - pos = MSFtoLBA(m, s, f) - 150; - - dev->seek_pos = pos; - - dev->audio_muted_soft = 0; - /* Do this at this point, since it's at this point that we know the - actual LBA position to start playing from. */ - if (!(dev->ops->track_type(dev, pos) & CD_TRACK_AUDIO)) { - cdrom_log("CD-ROM %i: LBA %08X not on an audio track\n", dev->id, pos); - cdrom_stop(dev); - return 0; - } - - dev->cd_buflen = 0; - dev->cd_status = playbit ? CD_STATUS_PLAYING : CD_STATUS_PAUSED; - return 1; -} - -uint8_t -cdrom_audio_play_pioneer(cdrom_t *dev, uint32_t pos) -{ - int m = 0; - int s = 0; - int f = 0; - - if (dev->cd_status == CD_STATUS_DATA_ONLY) - return 0; - - f = bcd2bin((pos >> 24) & 0xff); - s = bcd2bin((pos >> 16) & 0xff); - m = bcd2bin((pos >> 8) & 0xff); - pos = MSFtoLBA(m, s, f) - 150; - dev->cd_end = pos; - - dev->audio_muted_soft = 0; - dev->cd_buflen = 0; - dev->cd_status = CD_STATUS_PLAYING; - return 1; -} - -uint8_t -cdrom_audio_play_toshiba(cdrom_t *dev, uint32_t pos, int type) -{ - int m = 0; - int s = 0; - int f = 0; - - if (dev->cd_status == CD_STATUS_DATA_ONLY) - return 0; - - /*Preliminary support, revert if too incomplete*/ - switch (type) { - case 0x00: - dev->cd_end = pos; - break; - case 0x40: - m = bcd2bin((pos >> 24) & 0xff); - s = bcd2bin((pos >> 16) & 0xff); - f = bcd2bin((pos >> 8) & 0xff); - pos = MSFtoLBA(m, s, f) - 150; - dev->cd_end = pos; - break; - case 0x80: - dev->cd_end = (pos >> 24) & 0xff; - break; - case 0xc0: - if (pos == 0xffffffff) { - cdrom_log("CD-ROM %i: Playing from current position\n", dev->id); - pos = dev->cd_end; - } - dev->cd_end = pos; - break; - default: - break; - } - - cdrom_log("Toshiba Play Audio: Muted?=%d, LBA=%08X.\n", dev->audio_muted_soft, pos); - dev->cd_buflen = 0; - dev->cd_status = CD_STATUS_PLAYING; - return 1; -} - -uint8_t -cdrom_audio_scan(cdrom_t *dev, uint32_t pos, int type) -{ - int m = 0; - int s = 0; - int f = 0; - - if (dev->cd_status == CD_STATUS_DATA_ONLY) - return 0; - - cdrom_log("Audio Scan: MSF = %06x, type = %02x\n", pos, type); - switch (type) { - case 0x00: - if (pos == 0xffffffff) { - cdrom_log("CD-ROM %i: (type 0) Search from current position\n", dev->id); - pos = dev->seek_pos; - } - dev->seek_pos = pos; - break; - case 0x40: - m = bcd2bin((pos >> 24) & 0xff); - s = bcd2bin((pos >> 16) & 0xff); - f = bcd2bin((pos >> 8) & 0xff); - if (pos == 0xffffffff) { - cdrom_log("CD-ROM %i: (type 1) Search from current position\n", dev->id); - pos = dev->seek_pos; - } else - pos = MSFtoLBA(m, s, f) - 150; - - dev->seek_pos = pos; - break; - case 0x80: - dev->seek_pos = (pos >> 24) & 0xff; - break; - default: - break; - } - - dev->audio_muted_soft = 0; - /* Do this at this point, since it's at this point that we know the - actual LBA position to start playing from. */ - if (!(dev->ops->track_type(dev, pos) & CD_TRACK_AUDIO)) { - cdrom_log("CD-ROM %i: LBA %08X not on an audio track\n", dev->id, pos); - cdrom_stop(dev); - return 0; - } - - dev->cd_buflen = 0; - return 1; -} - -void -cdrom_audio_pause_resume(cdrom_t *dev, uint8_t resume) -{ - if ((dev->cd_status == CD_STATUS_PLAYING) || (dev->cd_status == CD_STATUS_PAUSED)) - dev->cd_status = (dev->cd_status & 0xfe) | (resume & 0x01); -} - -static void -cdrom_get_subchannel(cdrom_t *dev, uint32_t lba, subchannel_t *subc, int cooked) -{ - uint8_t *scb = dev->subch_buffer; - uint8_t q[16] = { 0 }; - - if ((lba == dev->seek_pos) && (dev->cd_status == CD_STATUS_PLAYING)) { - for (int i = 0; i < 12; i++) - for (int j = 0; j < 8; j++) - q[i] |= ((scb[(i << 3) + j] >> 6) & 0x01) << (7 - j); - - if (cooked) { - uint8_t temp = (q[0] >> 4) | ((q[0] & 0xf) << 4); - q[0] = temp; - - for (int i = 1; i < 10; i++) { - temp = bcd2bin(q[i]); - q[i] = temp; - } + if (ret <= 0) { + memset(dev->raw_buffer[dev->cur_buf ^ 1], 0x00, 2448); + dev->cached_sector = -1; } - subc->attr = q[0]; - subc->track = q[1]; - subc->index = q[2]; - subc->rel_m = q[3]; - subc->rel_s = q[4]; - subc->rel_f = q[5]; - subc->abs_m = q[7]; - subc->abs_s = q[8]; - subc->abs_f = q[9]; - } else if ((dev->ops != NULL) && (dev->ops->get_subchannel != NULL)) { - dev->ops->get_subchannel(dev, lba, subc); - - if (!cooked) { - uint8_t temp = (q[0] >> 4) | ((q[0] & 0xf) << 4); - q[0] = temp; - - subc->attr = (subc->attr >> 4) | ((subc->attr & 0xf) << 4); - subc->track = bin2bcd(subc->track); - subc->index = bin2bcd(subc->index); - subc->rel_m = bin2bcd(subc->rel_m); - subc->rel_s = bin2bcd(subc->rel_s); - subc->rel_f = bin2bcd(subc->rel_f); - subc->abs_m = bin2bcd(subc->abs_m); - subc->abs_s = bin2bcd(subc->abs_s); - subc->abs_f = bin2bcd(subc->abs_f); - } - } -} - -uint8_t -cdrom_get_current_status(cdrom_t *dev) -{ - uint8_t ret; - - if (dev->cd_status == CD_STATUS_DATA_ONLY) - ret = 0x15; - else { - if (dev->cd_status == CD_STATUS_PLAYING) - ret = 0x11; - else if (dev->cd_status == CD_STATUS_PAUSED) - ret = 0x12; - else - ret = 0x13; + dev->cur_buf ^= 1; } return ret; } -void -cdrom_get_current_subchannel(cdrom_t *dev, uint8_t *b, int msf) -{ - subchannel_t subc; - uint32_t dat; - - cdrom_get_subchannel(dev, dev->seek_pos, &subc, 1); - - cdrom_log("CD-ROM %i: Returned subchannel absolute at %02i:%02i.%02i, " - "relative at %02i:%02i.%02i, seek pos = %08x, cd_end = %08x.\n", - dev->id, subc.abs_m, subc.abs_s, subc.abs_f, subc.rel_m, subc.rel_s, subc.rel_f, - dev->seek_pos, dev->cd_end); - - /* Format code. */ - switch (b[0]) { - /* Mode 0 = Q subchannel mode, first 16 bytes are indentical to mode 1 (current position), - the rest are stuff like ISRC etc., which can be all zeroes. */ - case 0x01: - /* Current position. */ - b[1] = subc.attr; - b[2] = subc.track; - b[3] = subc.index; - - if (msf) { - b[4] = b[8] = 0x00; - - /* NEC CDR-260 speaks BCD. */ - if ((dev->type == CDROM_TYPE_NEC_260_100) || (dev->type == CDROM_TYPE_NEC_260_101)) { - /* NEC */ - b[5] = bin2bcd(subc.abs_m); - b[6] = bin2bcd(subc.abs_s); - b[7] = bin2bcd(subc.abs_f); - - b[9] = bin2bcd(subc.rel_m); - b[10] = bin2bcd(subc.rel_s); - b[11] = bin2bcd(subc.rel_f); - } else { - b[5] = subc.abs_m; - b[6] = subc.abs_s; - b[7] = subc.abs_f; - - b[9] = subc.rel_m; - b[10] = subc.rel_s; - b[11] = subc.rel_f; - } - } else { - dat = MSFtoLBA(subc.abs_m, subc.abs_s, subc.abs_f) - 150; - b[4] = (dat >> 24) & 0xff; - b[5] = (dat >> 16) & 0xff; - b[6] = (dat >> 8) & 0xff; - b[7] = dat & 0xff; - - dat = MSFtoLBA(subc.rel_m, subc.rel_s, subc.rel_f); - b[8] = (dat >> 24) & 0xff; - b[9] = (dat >> 16) & 0xff; - b[10] = (dat >> 8) & 0xff; - b[11] = dat & 0xff; - } - break; - case 0x02: - /* UPC - TODO: Finding and reporting the actual UPC data. */ - memset(&(b[1]), 0x00, 19); - memset(&(b[5]), 0x30, 13); - /* NEC CDR-260 speaks BCD. */ - if ((dev->type == CDROM_TYPE_NEC_260_100) || (dev->type == CDROM_TYPE_NEC_260_101)) - /* NEC */ - b[19] = bin2bcd(subc.abs_f); - else - b[19] = subc.abs_f; - break; - case 0x03: - /* ISRC - TODO: Finding and reporting the actual ISRC data. */ - memset(&(b[1]), 0x00, 19); - memset(&(b[5]), 0x30, 12); - /* NEC CDR-260 speaks BCD. */ - if ((dev->type == CDROM_TYPE_NEC_260_100) || (dev->type == CDROM_TYPE_NEC_260_101)) - /* NEC */ - b[18] = bin2bcd(subc.abs_f); - else - b[18] = subc.abs_f; - break; - default: - cdrom_log("b[0] = %02X\n", b[0]); - break; - } -} - -void -cdrom_get_current_subchannel_sony(cdrom_t *dev, uint8_t *b, int msf) -{ - subchannel_t subc; - uint32_t dat; - - cdrom_get_subchannel(dev, dev->seek_pos, &subc, 1); - - cdrom_log("CD-ROM %i: Returned subchannel at %02i:%02i.%02i, seek pos = %08x, cd_end = %08x, msf = %x.\n", dev->id, subc.abs_m, subc.abs_s, subc.abs_f, dev->seek_pos, dev->cd_end, msf); - - b[0] = subc.attr; - b[1] = subc.track; - b[2] = subc.index; - - if (msf) { - b[3] = subc.rel_m; - b[4] = subc.rel_s; - b[5] = subc.rel_f; - b[6] = subc.abs_m; - b[7] = subc.abs_s; - b[8] = subc.abs_f; - } else { - dat = MSFtoLBA(subc.rel_m, subc.rel_s, subc.rel_f); - b[3] = (dat >> 16) & 0xff; - b[4] = (dat >> 8) & 0xff; - b[5] = dat & 0xff; - dat = MSFtoLBA(subc.abs_m, subc.abs_s, subc.abs_f) - 150; - b[6] = (dat >> 16) & 0xff; - b[7] = (dat >> 8) & 0xff; - b[8] = dat & 0xff; - } -} - -uint8_t -cdrom_get_audio_status_pioneer(cdrom_t *dev, uint8_t *b) -{ - uint8_t ret; - subchannel_t subc; - - cdrom_get_subchannel(dev, dev->seek_pos, &subc, 0); - - if (dev->cd_status == CD_STATUS_DATA_ONLY) - ret = 0x05; - else { - if (dev->cd_status == CD_STATUS_PLAYING) - ret = dev->sound_on ? 0x00 : 0x02; - else if (dev->cd_status == CD_STATUS_PAUSED) - ret = 0x01; - else - ret = 0x03; - } - - b[0] = 0; - b[1] = subc.abs_m; - b[2] = subc.abs_s; - b[3] = subc.abs_f; - - return ret; -} - -uint8_t -cdrom_get_audio_status_sony(cdrom_t *dev, uint8_t *b, int msf) -{ - uint8_t ret; - subchannel_t subc; - uint32_t dat; - - cdrom_get_subchannel(dev, dev->seek_pos, &subc, 1); - - if (dev->cd_status == CD_STATUS_DATA_ONLY) - ret = 0x05; - else { - if (dev->cd_status == CD_STATUS_PLAYING) - ret = dev->sound_on ? 0x00 : 0x02; - else if (dev->cd_status == CD_STATUS_PAUSED) - ret = 0x01; - else - ret = 0x03; - } - - if (msf) { - b[0] = 0; - b[1] = subc.abs_m; - b[2] = subc.abs_s; - b[3] = subc.abs_f; - } else { - dat = MSFtoLBA(subc.abs_m, subc.abs_s, subc.abs_f) - 150; - b[0] = (dat >> 24) & 0xff; - b[1] = (dat >> 16) & 0xff; - b[2] = (dat >> 8) & 0xff; - b[3] = dat & 0xff; - } - - return ret; -} - -void -cdrom_get_current_subcodeq(cdrom_t *dev, uint8_t *b) -{ - subchannel_t subc; - - cdrom_get_subchannel(dev, dev->seek_pos, &subc, 0); - - b[0] = subc.attr; - b[1] = subc.track; - b[2] = subc.index; - b[3] = subc.rel_m; - b[4] = subc.rel_s; - b[5] = subc.rel_f; - b[6] = subc.abs_m; - b[7] = subc.abs_s; - b[8] = subc.abs_f; -} - -uint8_t -cdrom_get_current_subcodeq_playstatus(cdrom_t *dev, uint8_t *b) -{ - uint8_t ret; - - cdrom_get_current_subcodeq(dev, b); - - if ((dev->cd_status == CD_STATUS_DATA_ONLY) || - (dev->cd_status == CD_STATUS_PLAYING_COMPLETED) || - (dev->cd_status == CD_STATUS_STOPPED)) - ret = 0x03; - else - ret = (dev->cd_status == CD_STATUS_PLAYING) ? 0x00 : dev->audio_op; - - /*If a valid audio track is detected with audio on, unmute it.*/ - if (dev->ops->track_type(dev, dev->seek_pos) & CD_TRACK_AUDIO) - dev->audio_muted_soft = 0; - - cdrom_log("SubCodeQ: Play Status: Seek LBA=%08x, CDEND=%08x, mute=%d.\n", - dev->seek_pos, dev->cd_end, dev->audio_muted_soft); - return ret; -} - static void -read_toc_identify_sessions(raw_track_info_t *rti, int num, unsigned char *b) +cdrom_get_subchannel(cdrom_t *dev, const uint32_t lba, + subchannel_t *subc, const int cooked) +{ + uint8_t q[16] = { 0 }; + if (lba != dev->cached_sector) + dev->cached_sector = -1; + + (void) read_data(dev, lba); + + for (int i = 0; i < 12; i++) + for (int j = 0; j < 8; j++) + q[i] |= ((dev->raw_buffer[dev->cur_buf][RAW_SECTOR_SIZE + + (i << 3) + j] >> 6) & 0x01) << (7 - j); + + if (cooked) { + uint8_t temp = (q[0] >> 4) | ((q[0] & 0xf) << 4); + q[0] = temp; + + for (int i = 1; i < 10; i++) { + temp = bcd2bin(q[i]); + q[i] = temp; + } + } + + subc->attr = q[0]; + subc->track = q[1]; + subc->index = q[2]; + subc->rel_m = q[3]; + subc->rel_s = q[4]; + subc->rel_f = q[5]; + subc->abs_m = q[7]; + subc->abs_s = q[8]; + subc->abs_f = q[9]; +} + +static void +read_toc_identify_sessions(const raw_track_info_t *rti, const int num, unsigned char *b) { /* Bytes 2 and 3 = Number of first and last sessions */ b[2] = 0xff; @@ -1104,7 +369,7 @@ read_toc_identify_sessions(raw_track_info_t *rti, int num, unsigned char *b) } static int -find_track(raw_track_info_t *trti, int num, int first) +find_track(const raw_track_info_t *trti, const int num, const int first) { int ret = -1; @@ -1126,7 +391,7 @@ find_track(raw_track_info_t *trti, int num, int first) } static int -find_last_lead_out(raw_track_info_t *trti, int num) +find_last_lead_out(const raw_track_info_t *trti, const int num) { int ret = -1; @@ -1140,7 +405,7 @@ find_last_lead_out(raw_track_info_t *trti, int num) } static int -find_specific_track(raw_track_info_t *trti, int num, int track) +find_specific_track(const raw_track_info_t *trti, const int num, const int track) { int ret = -1; @@ -1156,29 +421,34 @@ find_specific_track(raw_track_info_t *trti, int num, int track) } static int -read_toc_normal(cdrom_t *dev, unsigned char *b, unsigned char start_track, int msf, int sony) +read_toc_normal(const cdrom_t *dev, unsigned char *b, + unsigned char start_track, const int msf, + const int sony) { - uint8_t rti[65536] = { 0 }; - uint8_t prti[65536] = { 0 }; - raw_track_info_t *trti = (raw_track_info_t *) rti; - raw_track_info_t *tprti = (raw_track_info_t *) prti; - int num = 0; - int len = 4; - int s = -1; + uint8_t rti[65536] = { 0 }; + uint8_t prti[65536] = { 0 }; + const raw_track_info_t *trti = (raw_track_info_t *) rti; + raw_track_info_t * tprti = (raw_track_info_t *) prti; + int num = 0; + int len = 4; + int t = -1; - cdrom_log("read_toc_normal(%016" PRIXPTR ", %016" PRIXPTR ", %02X, %i)\n", + if ((dev->is_bcd || dev->is_chinon) && (start_track < 0xa0)) + start_track = bcd2bin(start_track); + + cdrom_log(dev->log, "read_toc_normal(%016" PRIXPTR ", %016" PRIXPTR ", %02X, %i, %i)\n", (uintptr_t) dev, (uintptr_t) b, start_track, msf, sony); - dev->ops->get_raw_track_info(dev, &num, (raw_track_info_t *) rti); + dev->ops->get_raw_track_info(dev->local, &num, rti); if (num > 0) { int j = 0; for (int i = 0; i < num; i++) { if ((trti[i].point >= 0x01) && (trti[i].point <= 0x63)) { tprti[j] = trti[i]; - if ((s == -1) && (tprti[j].point >= start_track)) - s = j; - cdrom_log("Sorted %03i = Unsorted %03i (s = %03i)\n", j, i, s); + if ((t == -1) && (tprti[j].point >= start_track)) + t = j; + cdrom_log(dev->log, "Sorted %03i = Unsorted %03i\n", j, i); j++; } } @@ -1191,15 +461,15 @@ read_toc_normal(cdrom_t *dev, unsigned char *b, unsigned char start_track, int m if (trti[i].point == 0xa2) { tprti[j] = trti[i]; tprti[j].point = 0xaa; - if ((s == -1) && (tprti[j].point >= start_track)) - s = j; - cdrom_log("Sorted %03i = Unsorted %03i (s = %03i)\n", j, i, s); + if ((t == -1) && (tprti[j].point >= start_track)) + t = j; + cdrom_log(dev->log, "Sorted %03i = Unsorted %03i\n", j, i); j++; break; } } - if (s != -1) for (int i = s; i < j; i++) { + if (t != -1) for (int i = t; i < j; i++) { #ifdef ENABLE_CDROM_LOG uint8_t *c = &(b[len]); #endif @@ -1207,7 +477,11 @@ read_toc_normal(cdrom_t *dev, unsigned char *b, unsigned char start_track, int m if (!sony) b[len++] = 0; /* Reserved */ b[len++] = tprti[i].adr_ctl; /* ADR/CTL */ - b[len++] = tprti[i].point; /* Track number */ + if ((dev->is_bcd || dev->is_chinon) && (tprti[i].point >= 1) && + (tprti[i].point <= 99)) + b[len++] = bin2bcd(tprti[i].point); /* Track number */ + else + b[len++] = tprti[i].point; /* Track number */ if (!sony) b[len++] = 0; /* Reserved */ @@ -1215,7 +489,7 @@ read_toc_normal(cdrom_t *dev, unsigned char *b, unsigned char start_track, int m b[len++] = 0; /* NEC CDR-260 speaks BCD. */ - if ((dev->type == CDROM_TYPE_NEC_260_100) || (dev->type == CDROM_TYPE_NEC_260_101)) { + if (dev->is_bcd) { int m = tprti[i].pm; int s = tprti[i].ps; int f = tprti[i].pf; @@ -1229,7 +503,8 @@ read_toc_normal(cdrom_t *dev, unsigned char *b, unsigned char start_track, int m b[len++] = tprti[i].pf; } } else { - uint32_t temp = MSFtoLBA(tprti[i].pm, tprti[i].ps, tprti[i].pf) - 150; + const uint32_t temp = MSFtoLBA(tprti[i].pm, tprti[i].ps, + tprti[i].pf) - 150; b[len++] = temp >> 24; b[len++] = temp >> 16; @@ -1238,7 +513,7 @@ read_toc_normal(cdrom_t *dev, unsigned char *b, unsigned char start_track, int m } #ifdef ENABLE_CDROM_LOG - cdrom_log("Track %02X: %02X %02X %02X %02X %02X %02X %02X %02X\n", + cdrom_log(dev->log, "Track %02X: %02X %02X %02X %02X %02X %02X %02X %02X\n", i, c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]); #endif } @@ -1249,38 +524,44 @@ read_toc_normal(cdrom_t *dev, unsigned char *b, unsigned char start_track, int m } static int -read_toc_session(cdrom_t *dev, unsigned char *b, int msf) +read_toc_session(const cdrom_t *dev, unsigned char *b, const int msf) { - uint8_t rti[65536] = { 0 }; - raw_track_info_t *t = (raw_track_info_t *) rti; - raw_track_info_t *first = NULL; - int num = 0; - int len = 4; + uint8_t rti[65536] = { 0 }; + const raw_track_info_t *t = (raw_track_info_t *) rti; + const raw_track_info_t *first = NULL; + int num = 0; + int len = 4; - dev->ops->get_raw_track_info(dev, &num, (raw_track_info_t *) rti); + dev->ops->get_raw_track_info(dev->local, &num, rti); /* Bytes 2 and 3 = Number of first and last sessions */ read_toc_identify_sessions((raw_track_info_t *) rti, num, b); - cdrom_log("read_toc_session(%016" PRIXPTR ", %016" PRIXPTR ", %i)\n", + cdrom_log(dev->log, "read_toc_session(%016" PRIXPTR ", %016" PRIXPTR ", %i)\n", (uintptr_t) dev, (uintptr_t) b, msf); if (num != 0) { - for (int i = 0; i < num; i++) if ((t[i].session == b[3]) && (t[i].point >= 0x01) && (t[i].point <= 0x63)) { - first = &(t[i]); - break; + for (int i = 0; i < num; i++) { + if ((t[i].session == b[3]) && (t[i].point >= 0x01) && (t[i].point <= 0x63)) { + first = &(t[i]); + break; + } } if (first != NULL) { b[len++] = 0x00; b[len++] = first->adr_ctl; - b[len++] = first->point; + if ((dev->is_bcd || dev->is_chinon) && (first->point >= 1) && + (first->point <= 99)) + b[len++] = bin2bcd(first->point); + else + b[len++] = first->point; b[len++] = 0x00; if (msf) { b[len++] = 0x00; /* NEC CDR-260 speaks BCD. */ - if ((dev->type == CDROM_TYPE_NEC_260_100) || (dev->type == CDROM_TYPE_NEC_260_101)) { /*NEC*/ + if (dev->is_bcd) { int m = first->pm; int s = first->ps; int f = first->pf; @@ -1296,7 +577,8 @@ read_toc_session(cdrom_t *dev, unsigned char *b, int msf) b[len++] = first->pf; } } else { - uint32_t temp = MSFtoLBA(first->pm, first->ps, first->pf) - 150; + const uint32_t temp = MSFtoLBA(first->pm, first->ps, + first->pf) - 150; b[len++] = temp >> 24; b[len++] = temp >> 16; @@ -1313,32 +595,1444 @@ read_toc_session(cdrom_t *dev, unsigned char *b, int msf) } static int -read_toc_raw(cdrom_t *dev, unsigned char *b, unsigned char start_track) +read_toc_raw(const cdrom_t *dev, unsigned char *b, const unsigned char start_track) { - uint8_t rti[65536] = { 0 }; - raw_track_info_t *t = (raw_track_info_t *) rti; - int num = 0; - int len = 4; + uint8_t rti[65536] = { 0 }; + const raw_track_info_t *t = (raw_track_info_t *) rti; + int num = 0; + int len = 4; /* Bytes 2 and 3 = Number of first and last sessions */ read_toc_identify_sessions((raw_track_info_t *) rti, num, b); - cdrom_log("read_toc_raw(%016" PRIXPTR ", %016" PRIXPTR ", %02X)\n", + cdrom_log(dev->log, "read_toc_raw(%016" PRIXPTR ", %016" PRIXPTR ", %02X)\n", (uintptr_t) dev, (uintptr_t) b, start_track); - dev->ops->get_raw_track_info(dev, &num, (raw_track_info_t *) rti); + dev->ops->get_raw_track_info(dev->local, &num, rti); if (num != 0) for (int i = 0; i < num; i++) if (t[i].session >= start_track) { memcpy(&(b[len]), &(t[i]), 11); + + if ((dev->is_bcd || dev->is_chinon) && (b[3] >= 1) && (b[3] <= 99)) + b[3] = bin2bcd(b[3]); + + for (int j = 0; j < 3; j++) + if (dev->is_bcd) { + b[4 + j] = bin2bcd(b[4 + j]); + b[8 + j] = bin2bcd(b[8 + j]); + } + len += 11; } return len; } +static int +track_type_is_valid(UNUSED(const cdrom_t *dev), const int type, const int flags, const int audio, + const int mode2) +{ + if (!(flags & 0x70) && (flags & 0xf8)) { /* 0x08/0x80/0x88 are illegal modes */ + cdrom_log(dev->log, "[Any Mode] 0x08/0x80/0x88 are illegal modes\n"); + return 0; + } + + if ((type != 1) && !audio) { + if ((flags & 0x06) == 0x06) { + cdrom_log(dev->log, "[Any Data Mode] Invalid error flags\n"); + return 0; + } + + if (((flags & 0x700) == 0x300) || ((flags & 0x700) > 0x400)) { + cdrom_log(dev->log, "[Any Data Mode] Invalid subchannel data flags (%02X)\n", + flags & 0x700); + return 0; + } + + if ((flags & 0x18) == 0x08) { /* EDC/ECC without user data is an illegal mode */ + cdrom_log(dev->log, "[Any Data Mode] EDC/ECC without user data is an " + "illegal mode\n"); + return 0; + } + + if (((flags & 0xf0) == 0x90) || ((flags & 0xf0) == 0xc0)) { /* 0x90/0x98/0xC0/0xC8 are illegal modes */ + cdrom_log(dev->log, "[Any Data Mode] 0x90/0x98/0xC0/0xC8 are illegal modes\n"); + return 0; + } + + if (((type > 3) && (type != 8)) || (mode2 && (mode2 & 0x03))) { + if ((flags & 0xf0) == 0x30) { /* 0x30/0x38 are illegal modes */ + cdrom_log(dev->log, "[Any XA Mode 2] 0x30/0x38 are illegal modes\n"); + return 0; + } + if (((flags & 0xf0) == 0xb0) || ((flags & 0xf0) == 0xd0)) { /* 0xBx and 0xDx are illegal modes */ + cdrom_log(dev->log, "[Any XA Mode 2] 0xBx and 0xDx are illegal modes\n"); + return 0; + } + } + } + + return 1; +} + +static int +read_audio(cdrom_t *dev, const uint32_t lba, uint8_t *b) +{ + const int ret = read_data(dev, lba); + + memcpy(b, dev->raw_buffer[dev->cur_buf], 2352); + + dev->cdrom_sector_size = 2352; + + return ret; +} + + +static void +process_mode1(cdrom_t *dev, const int cdrom_sector_flags, uint8_t *b) +{ + dev->cdrom_sector_size = 0; + + if (cdrom_sector_flags & 0x80) { + /* Sync */ + cdrom_log(dev->log, "[Mode 1] Sync\n"); + memcpy(b, dev->raw_buffer[dev->cur_buf], 12); + dev->cdrom_sector_size += 12; + b += 12; + } + + if (cdrom_sector_flags & 0x20) { + /* Header */ + cdrom_log(dev->log, "[Mode 1] Header\n"); + memcpy(b, dev->raw_buffer[dev->cur_buf] + 12, 4); + dev->cdrom_sector_size += 4; + b += 4; + } + + if (cdrom_sector_flags & 0x40) { + /* Sub-header */ + if (!(cdrom_sector_flags & 0x10)) { + /* No user data */ + cdrom_log(dev->log, "[Mode 1] Sub-header\n"); + memcpy(b, dev->raw_buffer[dev->cur_buf] + 16, 8); + dev->cdrom_sector_size += 8; + b += 8; + } + } + + if (cdrom_sector_flags & 0x10) { + /* User data */ + cdrom_log(dev->log, "[Mode 1] User data\n"); + if (mult > 1) { + memcpy(b, dev->raw_buffer[dev->cur_buf] + 16 + + (part * dev->sector_size), dev->sector_size); + dev->cdrom_sector_size += dev->sector_size; + b += dev->sector_size; + } else { + memcpy(b, dev->raw_buffer[dev->cur_buf] + 16, 2048); + dev->cdrom_sector_size += 2048; + b += 2048; + } + } + + if (cdrom_sector_flags & 0x08) { + /* EDC/ECC */ + cdrom_log(dev->log, "[Mode 1] EDC/ECC\n"); + memcpy(b, dev->raw_buffer[dev->cur_buf] + 2064, (288 - ecc_diff)); + dev->cdrom_sector_size += (288 - ecc_diff); + } +} + +static void +process_mode2_non_xa(cdrom_t *dev, const int cdrom_sector_flags, + uint8_t *b) +{ + dev->cdrom_sector_size = 0; + + if (cdrom_sector_flags & 0x80) { + /* Sync */ + cdrom_log(dev->log, "[Mode 2 Formless] Sync\n"); + memcpy(b, dev->raw_buffer[dev->cur_buf], 12); + dev->cdrom_sector_size += 12; + b += 12; + } + + if (cdrom_sector_flags & 0x20) { + /* Header */ + cdrom_log(dev->log, "[Mode 2 Formless] Header\n"); + memcpy(b, dev->raw_buffer[dev->cur_buf] + 12, 4); + dev->cdrom_sector_size += 4; + b += 4; + } + + /* Mode 1 sector, expected type is 1 type. */ + if (cdrom_sector_flags & 0x40) { + /* Sub-header */ + cdrom_log(dev->log, "[Mode 2 Formless] Sub-header\n"); + memcpy(b, dev->raw_buffer[dev->cur_buf] + 16, 8); + dev->cdrom_sector_size += 8; + b += 8; + } + + if (cdrom_sector_flags & 0x10) { + /* User data */ + cdrom_log(dev->log, "[Mode 2 Formless] User data\n"); + memcpy(b, dev->raw_buffer[dev->cur_buf] + 24, (2336 - ecc_diff)); + dev->cdrom_sector_size += (2336 - ecc_diff); + } +} + +static void +process_mode2_xa_form1(cdrom_t *dev, const int cdrom_sector_flags, + uint8_t *b) +{ + dev->cdrom_sector_size = 0; + + if (cdrom_sector_flags & 0x80) { + /* Sync */ + cdrom_log(dev->log, "[XA Mode 2 Form 1] Sync\n"); + memcpy(b, dev->raw_buffer[dev->cur_buf], 12); + dev->cdrom_sector_size += 12; + b += 12; + } + + if (cdrom_sector_flags & 0x20) { + /* Header */ + cdrom_log(dev->log, "[XA Mode 2 Form 1] Header\n"); + memcpy(b, dev->raw_buffer[dev->cur_buf] + 12, 4); + dev->cdrom_sector_size += 4; + b += 4; + } + + if (cdrom_sector_flags & 0x40) { + /* Sub-header */ + cdrom_log(dev->log, "[XA Mode 2 Form 1] Sub-header\n"); + memcpy(b, dev->raw_buffer[dev->cur_buf] + 16, 8); + dev->cdrom_sector_size += 8; + b += 8; + } + + if (cdrom_sector_flags & 0x10) { + /* User data */ + cdrom_log(dev->log, "[XA Mode 2 Form 1] User data\n"); + if (mult > 1) { + memcpy(b, dev->raw_buffer[dev->cur_buf] + 24 + + (part * dev->sector_size), dev->sector_size); + dev->cdrom_sector_size += dev->sector_size; + b += dev->sector_size; + } else { + memcpy(b, dev->raw_buffer[dev->cur_buf] + 24, 2048); + dev->cdrom_sector_size += 2048; + b += 2048; + } + } + + if (cdrom_sector_flags & 0x08) { + /* EDC/ECC */ + cdrom_log(dev->log, "[XA Mode 2 Form 1] EDC/ECC\n"); + memcpy(b, dev->raw_buffer[dev->cur_buf] + 2072, (280 - ecc_diff)); + dev->cdrom_sector_size += (280 - ecc_diff); + } +} + +static void +process_mode2_xa_form2(cdrom_t *dev, const int cdrom_sector_flags, + uint8_t *b) +{ + dev->cdrom_sector_size = 0; + + if (cdrom_sector_flags & 0x80) { + /* Sync */ + cdrom_log(dev->log, "[XA Mode 2 Form 2] Sync\n"); + memcpy(b, dev->raw_buffer[dev->cur_buf], 12); + dev->cdrom_sector_size += 12; + b += 12; + } + + if (cdrom_sector_flags & 0x20) { + /* Header */ + cdrom_log(dev->log, "[XA Mode 2 Form 2] Header\n"); + memcpy(b, dev->raw_buffer[dev->cur_buf] + 12, 4); + dev->cdrom_sector_size += 4; + b += 4; + } + + if (cdrom_sector_flags & 0x40) { + /* Sub-header */ + cdrom_log(dev->log, "[XA Mode 2 Form 2] Sub-header\n"); + memcpy(b, dev->raw_buffer[dev->cur_buf] + 16, 8); + dev->cdrom_sector_size += 8; + b += 8; + } + + if (cdrom_sector_flags & 0x10) { + /* User data */ + cdrom_log(dev->log, "[XA Mode 2 Form 2] User data\n"); + memcpy(b, dev->raw_buffer[dev->cur_buf] + 24, + (2328 - ecc_diff)); + dev->cdrom_sector_size += (2328 - ecc_diff); + } +} + +static void +process_c2(cdrom_t *dev, const int cdrom_sector_flags, uint8_t *b) +{ + if ((cdrom_sector_flags & 0x06) == 0x02) { + /* Add error flags. */ + cdrom_log(dev->log, "Error flags\n"); + memcpy(b + dev->cdrom_sector_size, dev->extra_buffer, 294); + dev->cdrom_sector_size += 294; + } else if ((cdrom_sector_flags & 0x06) == 0x04) { + /* Add error flags. */ + cdrom_log(dev->log, "Full error flags\n"); + memcpy(b + dev->cdrom_sector_size, dev->extra_buffer, 296); + dev->cdrom_sector_size += 296; + } +} + +static void +cdrom_deinterleave_subch(uint8_t *d, const uint8_t *s) +{ + for (int i = 0; i < 8 * 12; i++) { + int dmask = 0x80; + int smask = 1 << (7 - (i / 12)); + + (*d) = 0; + + for (int j = 0; j < 8; j++) { + (*d) |= (s[(i % 12) * 8 + j] & smask) ? dmask : 0; + dmask >>= 1; + } + + d++; + } +} + +static void +process_c2_and_subch(cdrom_t *dev, const int cdrom_sector_flags, + uint8_t *b) +{ + if (dev->c2_first) + process_c2(dev, cdrom_sector_flags, b); + + if ((cdrom_sector_flags & 0x700) == 0x100) { + cdrom_log(dev->log, "Raw subchannel data\n"); + memcpy(b + dev->cdrom_sector_size, dev->raw_buffer[dev->cur_buf] + + 2352, 96); + dev->cdrom_sector_size += 96; + } else if ((cdrom_sector_flags & 0x700) == 0x200) { + cdrom_log(dev->log, "Q subchannel data\n"); + memcpy(b + dev->cdrom_sector_size, dev->raw_buffer[dev->cur_buf] + + 2352, 16); + dev->cdrom_sector_size += 16; + } else if ((cdrom_sector_flags & 0x700) == 0x400) { + cdrom_log(dev->log, "R/W subchannel data\n"); + cdrom_deinterleave_subch(b + dev->cdrom_sector_size, + dev->raw_buffer[dev->cur_buf] + 2352); + dev->cdrom_sector_size += 96; + } + + if (!dev->c2_first) + process_c2(dev, cdrom_sector_flags, b); +} + +static void +cdrom_drive_reset(cdrom_t *dev) +{ + dev->priv = NULL; + dev->insert = NULL; + dev->close = NULL; + dev->get_volume = NULL; + dev->get_channel = NULL; + + dev->cached_sector = -1; + + if (cdrom_drive_types[dev->type].speed == -1) + dev->real_speed = dev->speed; + else + dev->real_speed = cdrom_drive_types[dev->type].speed; +} + +static void +cdrom_unload(cdrom_t *dev) +{ + if (dev->log != NULL) { + cdrom_log(dev->log, "CDROM: cdrom_unload(%s)\n", dev->image_path); + } + + dev->cd_status = CD_STATUS_EMPTY; + dev->cached_sector = -1; + + if (dev->local != NULL) { + dev->ops->close(dev->local); + dev->local = NULL; + } + + dev->ops = NULL; +} + +#ifdef ENABLE_CDROM_LOG +static void +cdrom_toc_dump(cdrom_t *dev) +{ + uint8_t b[65536] = { 0 }; + int len = cdrom_read_toc(dev, b, CD_TOC_RAW, 0, 0, 65536); + const char *fn2 = "d:\\86boxnew\\toc_cue.dmp"; + FILE * fp = fopen(fn2, "wb"); + fwrite(b, 1, len, fp); + fflush(fp); + fclose(fp); + cdrom_log(dev->log, "Written TOC of %i bytes to %s\n", len, fn2); + + memset(b, 0x00, 65536); + len = cdrom_read_toc(dev, b, CD_TOC_NORMAL, 0, 0, 65536); + fn2 = "d:\\86boxnew\\toc_cue_cooked.dmp"; + fp = fopen(fn2, "wb"); + fwrite(b, 1, len, fp); + fflush(fp); + fclose(fp); + cdrom_log(dev->log, "Written cooked TOC of %i bytes to %s\n", len, fn2); + + memset(b, 0x00, 65536); + len = cdrom_read_toc(dev, b, CD_TOC_SESSION, 0, 0, 65536); + fn2 = "d:\\86boxnew\\toc_cue_session.dmp"; + fp = fopen(fn2, "wb"); + fwrite(b, 1, len, fp); + fflush(fp); + fclose(fp); + cdrom_log(dev->log, "Written session TOC of %i bytes to %s\n", len, fn2); +} +#endif + +/* Reset the CD-ROM Interface, whichever one that is. */ +void +cdrom_interface_reset(void) +{ + /* If we have a valid controller, add its device. */ + if ((cdrom_interface_current > 0) && + controllers[cdrom_interface_current].device) + device_add(controllers[cdrom_interface_current].device); +} + +const char * +cdrom_interface_get_internal_name(const int cdinterface) +{ + return device_get_internal_name(controllers[cdinterface].device); +} + int -cdrom_read_toc(cdrom_t *dev, unsigned char *b, int type, unsigned char start_track, int msf, int max_len) +cdrom_interface_get_from_internal_name(const char *s) +{ + int c = 0; + + while (controllers[c].device != NULL) { + if (!strcmp(controllers[c].device->internal_name, s)) + return c; + c++; + } + + return 0; +} + +const device_t * +cdrom_interface_get_device(const int cdinterface) +{ + return (controllers[cdinterface].device); +} + +int +cdrom_interface_has_config(const int cdinterface) +{ + const device_t *dev = cdrom_interface_get_device(cdinterface); + + if (dev == NULL) + return 0; + + if (!device_has_config(dev)) + return 0; + + return 1; +} + +int +cdrom_interface_get_flags(const int cdinterface) +{ + return (controllers[cdinterface].device->flags); +} + +int +cdrom_interface_available(const int cdinterface) +{ + return (device_available(controllers[cdinterface].device)); +} + +char * +cdrom_get_vendor(const int type) +{ + return (char *) cdrom_drive_types[type].vendor; +} + +void +cdrom_get_model(const int type, char *name, const int id) +{ + if (!strcmp(cdrom_drive_types[type].vendor, EMU_NAME)) + sprintf(name, "%s%02i", cdrom_drive_types[type].model, id); + else + sprintf(name, "%s", cdrom_drive_types[type].model); +} + +char * +cdrom_get_revision(const int type) +{ + return (char *) cdrom_drive_types[type].revision; +} + +int +cdrom_get_scsi_std(const int type) +{ + return cdrom_drive_types[type].scsi_std; +} + +int +cdrom_is_early(const int type) +{ + return (cdrom_drive_types[type].scsi_std == 1); +} + +int +cdrom_is_generic(const int type) +{ + return (cdrom_drive_types[type].speed == -1); +} + +int +cdrom_is_caddy(const int type) +{ + return cdrom_drive_types[type].caddy; +} + +int +cdrom_get_speed(const int type) +{ + return cdrom_drive_types[type].speed; +} + +int +cdrom_get_inquiry_len(const int type) +{ + return cdrom_drive_types[type].inquiry_len; +} + +int +cdrom_get_transfer_max(const int type, const int mode) +{ + return cdrom_drive_types[type].transfer_max[mode]; +} + +int +cdrom_has_dma(const int type) +{ + return (cdrom_drive_types[type].transfer_max[2] != -1); +} + +int +cdrom_get_type_count(void) +{ + int count = 0; + + while (1) { + if (strlen(cdrom_drive_types[count].vendor) == 0) + break; + else + count++; + } + + return count; +} + +void +cdrom_get_identify_model(const int type, char *name, const int id) +{ + char elements[2][512] = { 0 }; + + memcpy(elements[0], cdrom_drive_types[type].vendor, + strlen(cdrom_drive_types[type].vendor) + 1); + + memcpy(elements[1], cdrom_drive_types[type].model, + strlen(cdrom_drive_types[type].model) + 1); + + char *s = strstr(elements[1], " "); + + if (s != NULL) + s[0] = 0x00; + + if (!strcmp(cdrom_drive_types[type].vendor, EMU_NAME)) + sprintf(name, "%s%02i", elements[1], id); + else if (!strcmp(cdrom_drive_types[type].vendor, "ASUS")) + sprintf(name, "%s %s", elements[0], elements[1]); + else if (!strcmp(cdrom_drive_types[type].vendor, "NEC")) + sprintf(name, "%s %s", elements[0], elements[1]); + else if (!strcmp(cdrom_drive_types[type].vendor, "LITE-ON")) + sprintf(name, "%s", elements[1]); + else + sprintf(name, "%s %s", elements[0], elements[1]); +} + +void +cdrom_get_name(const int type, char *name) +{ + char n[2048] = { 0 }; + + cdrom_generate_name(type, n, 0); + + if (cdrom_drive_types[type].bus_type == BUS_TYPE_SCSI) + sprintf(name, "[SCSI-%i] %s", cdrom_drive_types[type].scsi_std, n); + else + sprintf(name, "%s", n); +} + +char * +cdrom_get_internal_name(const int type) +{ + return (char *) cdrom_drive_types[type].internal_name; +} + +int +cdrom_get_from_internal_name(const char *s) +{ + int c = 0; + int found = 0; + + while (strlen(cdrom_drive_types[c].internal_name) > 0) { + if (!strcmp((char *) cdrom_drive_types[c].internal_name, s)) { + found = 1; + break; + } + c++; + } + + if (!found) + c = -1; + + return c; +} + +/* TODO: Configuration migration, remove when no longer needed. */ +int +cdrom_get_from_name(const char *s) +{ + int c = 0; + int found = 0; + char n[2048] = { 0 }; + + if (strcmp(s, "none")) { + while (strlen(cdrom_drive_types[c].internal_name) > 0) { + memset(n, 0x00, 2048); + cdrom_generate_name(c, n, 1); + /* Special case some names. */ + if ((!strcmp(s, "86BOX_CD-ROM_1.00") && !strcmp(n, "86Box_86B_CD_3.50")) || + (!strcmp(s, "TEAC_CD_532E_2.0A") && !strcmp(n, "TEAC_CD-532E_2.0A")) || + !strcmp(n, s)) { + found = 1; + break; + } + c++; + } + } + + if (!found) { + if (strcmp(s, "none")) { + wchar_t tempmsg[2048]; + sprintf(n, "WARNING: CD-ROM \"%s\" not found - contact 86Box support\n", s); + swprintf(tempmsg, sizeof_w(tempmsg), L"%hs", n); + pclog("%s", n); + ui_msgbox_header(MBX_INFO, + plat_get_string(STRING_HW_NOT_AVAILABLE_TITLE), + tempmsg); + } + c = -1; + } + + return c; +} + +void +cdrom_set_type(const int model, const int type) +{ + cdrom[model].type = type; +} + +int +cdrom_get_type(const int model) +{ + return cdrom[model].type; +} + +int +cdrom_lba_to_msf_accurate(const int lba) +{ + int pos = lba + 150; + const int f = pos % 75; + pos -= f; + pos /= 75; + const int s = pos % 60; + pos -= s; + pos /= 60; + const int m = pos; + + return ((m << 16) | (s << 8) | f); +} + +void +cdrom_interleave_subch(uint8_t *d, const uint8_t *s) +{ + memset(d, 0x00, 96); + + for (int i = 0; i < 8 * 12; i++) { + int smask = 0x80; + int dmask = 1 << (7 - (i / 12)); + + for (int j = 0; j < 8; j++) { + d[(i % 12) * 8 + j] |= ((*s) & smask) ? dmask : 0; + smask >>= 1; + } + + s++; + } +} + +double +cdrom_seek_time(const cdrom_t *dev) +{ + uint32_t diff = dev->seek_diff; + const double sd = (double) (MAX_SEEK - MIN_SEEK); + + if (diff < MIN_SEEK) + return 0.0; + if (diff > MAX_SEEK) + diff = MAX_SEEK; + + diff -= MIN_SEEK; + + return cdrom_get_short_seek(dev) + + ((cdrom_get_long_seek(dev) * ((double) diff)) / sd); +} + +void +cdrom_stop(cdrom_t *dev) +{ + if (dev->cd_status > CD_STATUS_DVD) + dev->cd_status = CD_STATUS_STOPPED; +} + +void +cdrom_seek(cdrom_t *dev, const uint32_t pos, const uint8_t vendor_type) +{ + int m; + int s; + int f; + uint32_t real_pos = pos; + + if (dev == NULL) + return; + + cdrom_log(dev->log, "Seek to LBA %08X, vendor type = %02x.\n", pos, vendor_type); + + switch (vendor_type) { + case 0x40: + m = bcd2bin((pos >> 24) & 0xff); + s = bcd2bin((pos >> 16) & 0xff); + f = bcd2bin((pos >> 8) & 0xff); + real_pos = MSFtoLBA(m, s, f) - 150; + break; + case 0x80: + real_pos = bcd2bin((pos >> 24) & 0xff); + break; + default: + break; + } + + dev->seek_pos = real_pos; + cdrom_stop(dev); +} + +int +cdrom_is_pre(const cdrom_t *dev, const uint32_t lba) +{ + if (dev->ops && dev->ops->is_track_pre) + return dev->ops->is_track_pre(dev->local, lba); + + return 0; +} + +#include <86box/filters.h> + +static void +cdrom_audio_deemphasize(int16_t *buffer) +{ + for (int i = 0; i < 588; i++) + for (int j = 0; j < 2; j++) + buffer[(i * 2) + j] = deemph_iir(j, buffer[(i * 2) + j]); +} + +int +cdrom_audio_callback(cdrom_t *dev, int16_t *output, const int len) +{ + int ret = 1; + + while (dev->cd_buflen < len) { + if (dev->seek_pos < dev->cd_end) { + ret = dev->ops->read_sector(dev->local, + dev->raw_buffer[dev->cur_buf ^ 1], + dev->seek_pos); + if (!dev->sound_on) + memset(dev->raw_buffer[dev->cur_buf ^ 1], 0x00, 2352); + dev->cur_buf ^= 1; + if (ret) { + cdrom_log(dev->log, "Read LBA %08X successful\n", dev->seek_pos); + dev->cached_sector = dev->seek_pos; + /* Q subchannel data in bit 6: 4-5-6-7-0-1-2-3. */ + if ((dev->raw_buffer[dev->cur_buf][2353] >> 6) & 0x01) + /* Data sector, copy silence into buffer. */ + memset((uint8_t *) &(dev->cd_buffer[dev->cd_buflen]), + 0x00, RAW_SECTOR_SIZE); + else { + memcpy((uint8_t *) &(dev->cd_buffer[dev->cd_buflen]), + dev->raw_buffer[dev->cur_buf], RAW_SECTOR_SIZE); + if ((dev->raw_buffer[dev->cur_buf][2355] >> 6) & 0x01) + /* De-emphasize pre-emphasized audio. */ + cdrom_audio_deemphasize(&(dev->cd_buffer[dev->cd_buflen])); + } + dev->seek_pos++; + dev->cd_buflen += (RAW_SECTOR_SIZE / 2); + ret = 1; + } else { + cdrom_log(dev->log, "Read LBA %08X failed\n", dev->seek_pos); + memset(&(dev->cd_buffer[dev->cd_buflen]), 0x00, + (CD_BUF_SIZE - dev->cd_buflen) * 2); + dev->cd_status = CD_STATUS_STOPPED; + dev->cd_buflen = len; + ret = 0; + } + } else { + cdrom_log(dev->log, "Playing completed\n"); + memset(&dev->cd_buffer[dev->cd_buflen], 0x00, (CD_BUF_SIZE - dev->cd_buflen) * 2); + dev->cd_status = CD_STATUS_PLAYING_COMPLETED; + dev->cd_buflen = len; + ret = 0; + } + } + + memcpy(output, dev->cd_buffer, len * 2); + memmove(dev->cd_buffer, &dev->cd_buffer[len], (CD_BUF_SIZE - len) * 2); + dev->cd_buflen -= len; + + if (!dev->sound_on) + ret = 0; + + cdrom_log(dev->log, "Audio callback returning %i\n", ret); + return ret; +} + +uint8_t +cdrom_audio_play(cdrom_t *dev, const uint32_t pos, const uint32_t len, const int ismsf) +{ + track_info_t ti; + uint32_t pos2 = pos; + uint32_t len2 = len; + int ret = 0; + + if (dev->cd_status & CD_STATUS_HAS_AUDIO) { + cdrom_log(dev->log, "Play audio - %08X %08X %i\n", pos2, len, ismsf); + + if (ismsf & 0x100) { + /* Track-relative audio play. */ + pos2 = ismsf & 0xff; + if ((dev->is_bcd || dev->is_chinon) && (pos2 < 0xa0)) + pos2 = bcd2bin(pos2); + ret = dev->ops->get_track_info(dev->local, ismsf & 0xff, 0, &ti); + if (ret) + pos2 += MSFtoLBA(ti.m, ti.s, ti.f) - 150; + else { + cdrom_log(dev->log, "Unable to get the starting position for " + "track %08X\n", ismsf & 0xff); + cdrom_stop(dev); + } + } else if ((ismsf == 2) || (ismsf == 3)) { + if ((dev->is_bcd || dev->is_chinon) && (pos2 < 0xa0)) + pos2 = bcd2bin(pos2); + ret = dev->ops->get_track_info(dev->local, pos2, 0, &ti); + if (ret) { + pos2 = MSFtoLBA(ti.m, ti.s, ti.f) - 150; + if (ismsf == 2) { + /* We have to end at the *end* of the specified track, + not at the beginning. */ + if ((dev->is_bcd || dev->is_chinon) && (len2 < 0xa0)) + len2 = bcd2bin(len2); + ret = dev->ops->get_track_info(dev->local, len2, 1, &ti); + if (ret) + len2 = MSFtoLBA(ti.m, ti.s, ti.f) - 150; + else { + cdrom_log(dev->log, "Unable to get the ending position for " + "track %08X\n", pos2); + cdrom_stop(dev); + } + } + } else { + cdrom_log(dev->log, "Unable to get the starting position for " + "track %08X\n", pos2); + cdrom_stop(dev); + } + } else if (ismsf == 1) { + int m = (pos >> 16) & 0xff; + int s = (pos >> 8) & 0xff; + int f = pos & 0xff; + + /* NEC CDR-260 speaks BCD. */ + if (dev->is_bcd) + msf_from_bcd(&m, &s, &f); + + if (pos == 0xffffff) { + cdrom_log(dev->log, "Playing from current position (MSF)\n"); + pos2 = dev->seek_pos; + } else + pos2 = MSFtoLBA(m, s, f) - 150; + + m = (len >> 16) & 0xff; + s = (len >> 8) & 0xff; + f = len & 0xff; + + /* NEC CDR-260 speaks BCD. */ + if (dev->is_bcd) + msf_from_bcd(&m, &s, &f); + + len2 = MSFtoLBA(m, s, f) - 150; + + ret = 1; + + cdrom_log(dev->log, "MSF - pos = %08X len = %08X\n", pos2, len); + } else if (ismsf == 0) { + if (pos == 0xffffffff) { + cdrom_log(dev->log, "Playing from current position\n"); + pos2 = dev->seek_pos; + } + len2 += pos2; + + ret = 1; + } + } + + if (ret) { + /* + Do this at this point, since it's at this point that we know the + actual LBA position to start playing from. + */ + ret = (dev->ops->get_track_type(dev->local, pos2) == CD_TRACK_AUDIO); + + if (ret) { + dev->seek_diff = ABS(dev->seek_pos - pos2); + dev->seek_pos = pos2; + dev->cd_end = len2; + dev->cd_status = CD_STATUS_PLAYING; + dev->cd_buflen = 0; + } else { + cdrom_log(dev->log, "LBA %08X not on an audio track\n", pos); + cdrom_stop(dev); + } + } + + return ret; +} + +uint8_t +cdrom_audio_track_search(cdrom_t *dev, const uint32_t pos, + const int type, const uint8_t playbit) +{ + uint32_t pos2 = pos; + uint8_t ret = 0; + + if (dev->cd_status & CD_STATUS_HAS_AUDIO) { + cdrom_log(dev->log, "Audio Track Search: MSF = %06x, type = %02x, " + "playbit = %02x\n", pos, type, playbit); + + ret = 1; + + switch (type) { + case 0x00: + if (pos == 0xffffffff) { + cdrom_log(dev->log, "(Type 0) Search from current position\n"); + pos2 = dev->seek_pos; + } + dev->seek_pos = pos2; + break; + case 0x40: { + const int m = bcd2bin((pos >> 24) & 0xff); + const int s = bcd2bin((pos >> 16) & 0xff); + const int f = bcd2bin((pos >> 8) & 0xff); + if (pos == 0xffffffff) { + cdrom_log(dev->log, "(Type 1) Search from current position\n"); + pos2 = dev->seek_pos; + } else + pos2 = MSFtoLBA(m, s, f) - 150; + + dev->seek_pos = pos2; + break; + } case 0x80: { + track_info_t ti; + + pos2 = (pos2 >> 24) & 0xff; + if (pos2 < 0xa0) + pos2 = bcd2bin(pos2); + ret = dev->ops->get_track_info(dev->local, pos2, 1, &ti); + if (ret) + dev->seek_pos = MSFtoLBA(ti.m, ti.s, ti.f) - 150; + else { + cdrom_log(dev->log, "Unable to get the starting position for " + "track %08X\n", ismsf & 0xff); + cdrom_stop(dev); + } + break; + } default: + break; + } + + if (ret) { + if (pos2 != 0x00000000) + pos2--; + + cdrom_log(dev->log, "Track Search Toshiba: LBA=%08X.\n", pos); + + dev->cd_end = dev->cdrom_capacity; + dev->cd_buflen = 0; + + dev->cd_status = playbit ? CD_STATUS_PLAYING : CD_STATUS_HOLD; + + ret = 1; + } + } + + return ret; +} + +uint8_t +cdrom_audio_track_search_pioneer(cdrom_t *dev, const uint32_t pos, const uint8_t playbit) +{ + uint8_t ret = 0; + + if (dev->cd_status &= CD_STATUS_HAS_AUDIO) { + const int f = bcd2bin((pos >> 24) & 0xff); + const int s = bcd2bin((pos >> 16) & 0xff); + const int m = bcd2bin((pos >> 8) & 0xff); + uint32_t pos2; + + if (pos == 0xffffffff) + pos2 = dev->seek_pos; + else + pos2 = MSFtoLBA(m, s, f) - 150; + + dev->seek_pos = pos2; + + /* + Do this at this point, since it's at this point that we know the + actual LBA position to start playing from. + */ + if (dev->ops->get_track_type(dev->local, pos2) & CD_TRACK_AUDIO) { + dev->cd_end = dev->cdrom_capacity; + dev->cd_buflen = 0; + + dev->cd_status = playbit ? CD_STATUS_PLAYING : CD_STATUS_HOLD; + + ret = 1; + } else { + cdrom_log(dev->log, "LBA %08X not on an audio track\n", pos); + cdrom_stop(dev); + } + } + + return ret; +} + +uint8_t +cdrom_audio_play_pioneer(cdrom_t *dev, const uint32_t pos) +{ + uint8_t ret = 0; + + if (dev->cd_status & CD_STATUS_HAS_AUDIO) { + const int f = bcd2bin((pos >> 24) & 0xff); + const int s = bcd2bin((pos >> 16) & 0xff); + const int m = bcd2bin((pos >> 8) & 0xff); + uint32_t pos2 = MSFtoLBA(m, s, f) - 150; + dev->cd_end = pos2; + + dev->cd_buflen = 0; + + dev->cd_status = CD_STATUS_PLAYING; + + ret = 1; + } + + return ret; +} + +uint8_t +cdrom_audio_play_toshiba(cdrom_t *dev, const uint32_t pos, const int type) +{ + uint32_t pos2 = pos; + uint8_t ret = 0; + + if (dev->cd_status & CD_STATUS_HAS_AUDIO) { + /* Preliminary support, revert if too incomplete. */ + ret = 1; + + switch (type) { + case 0x00: + dev->cd_end = pos2; + break; + case 0x40: { + const int m = bcd2bin((pos >> 24) & 0xff); + const int s = bcd2bin((pos >> 16) & 0xff); + const int f = bcd2bin((pos >> 8) & 0xff); + pos2 = MSFtoLBA(m, s, f) - 150; + dev->cd_end = pos2; + break; + } case 0x80: { + track_info_t ti; + + pos2 = (pos2 >> 24) & 0xff; + if (pos2 < 0xa0) + pos2 = bcd2bin(pos2); + ret = dev->ops->get_track_info(dev->local, pos2, 1, &ti); + if (ret) + dev->cd_end = MSFtoLBA(ti.m, ti.s, ti.f) - 150; + else { + cdrom_log(dev->log, "Unable to get the starting position for " + "track %08X\n", ismsf & 0xff); + cdrom_stop(dev); + } + break; + } case 0xc0: + if (pos == 0xffffffff) { + cdrom_log(dev->log, "Playing from current position\n"); + pos2 = dev->cd_end; + } + dev->cd_end = pos2; + break; + default: + break; + } + + if (ret) { + cdrom_log(dev->log, "Toshiba Play Audio: LBA=%08X.\n", pos2); + + dev->cd_status = CD_STATUS_PLAYING; + dev->cd_buflen = 0; + } + } + + return ret; +} + +uint8_t +cdrom_audio_scan(cdrom_t *dev, const uint32_t pos) +{ + uint32_t pos2 = pos; + uint8_t ret = 0; + + if (dev->cd_status & CD_STATUS_HAS_AUDIO) { + cdrom_log(dev->log, "Audio Scan: MSF = %06x, type = %02x\n", pos, type); + + if (pos == 0xffffffff) { + cdrom_log(dev->log, "(Type 0) Search from current position\n"); + pos2 = dev->seek_pos; + } + dev->seek_pos = pos2; + + /* Do this at this point, since it's at this point that we know the + actual LBA position to start playing from. */ + if (dev->ops->get_track_type(dev->local, pos) & CD_TRACK_AUDIO) { + dev->cd_buflen = 0; + ret = 1; + } else { + cdrom_log(dev->log, "LBA %08X not on an audio track\n", pos); + cdrom_stop(dev); + } + } + + return ret; +} + +void +cdrom_audio_pause_resume(cdrom_t *dev, const uint8_t resume) +{ + if ((dev->cd_status == CD_STATUS_PLAYING) || (dev->cd_status == CD_STATUS_PAUSED)) + dev->cd_status = (dev->cd_status & 0xfe) | (resume & 0x01); +} + +uint8_t +cdrom_get_current_status(const cdrom_t *dev) +{ + const uint8_t ret = status_codes[dev->is_chinon] + [dev->cd_status & CD_STATUS_MASK]; + + return ret; +} + +void +cdrom_get_current_subchannel(cdrom_t *dev, uint8_t *b, const int msf) +{ + subchannel_t subc; + int base = 0; + int diff = 4; + + if (dev->cached_sector == -1) + cdrom_get_subchannel(dev, dev->seek_pos, &subc, 1); + else + cdrom_get_subchannel(dev, dev->cached_sector, &subc, 1); + + cdrom_log(dev->log, "Returned subchannel absolute at %02i:%02i.%02i, " + "relative at %02i:%02i.%02i, seek pos = %08x, cd_end = %08x.\n", + subc.abs_m, subc.abs_s, subc.abs_f, subc.rel_m, subc.rel_s, subc.rel_f, + dev->seek_pos, dev->cd_end); + + /* Format code. */ + switch (b[0]) { + /* + Mode 0 = Q subchannel mode, first 16 bytes are indentical to mode 1 (current + position), the rest are stuff like ISRC etc., which can be all zeroes. + */ + case 0x00: + if (dev->bus_type == CDROM_BUS_ATAPI) + break; + diff = 0; + fallthrough; + case 0x01: + /* Current position. */ + b[1] = subc.attr; + if ((dev->is_bcd || dev->is_chinon) && + (subc.track >= 1) && (subc.track <= 99)) + b[2] = bin2bcd(subc.track); + else + b[2] = subc.track; + b[3] = subc.index; + + if (msf) { + b[4] = b[8] = 0x00; + + /* NEC CDR-260 speaks BCD. */ + if (dev->is_bcd) { + b[5] = bin2bcd(subc.abs_m); + b[6] = bin2bcd(subc.abs_s); + b[7] = bin2bcd(subc.abs_f); + + b[9] = bin2bcd(subc.rel_m); + b[10] = bin2bcd(subc.rel_s); + b[11] = bin2bcd(subc.rel_f); + } else { + b[5] = subc.abs_m; + b[6] = subc.abs_s; + b[7] = subc.abs_f; + + b[9] = subc.rel_m; + b[10] = subc.rel_s; + b[11] = subc.rel_f; + } + } else { + uint32_t dat = MSFtoLBA(subc.abs_m, subc.abs_s, subc.abs_f) - 150; + b[4] = (dat >> 24) & 0xff; + b[5] = (dat >> 16) & 0xff; + b[6] = (dat >> 8) & 0xff; + b[7] = dat & 0xff; + + dat = MSFtoLBA(subc.rel_m, subc.rel_s, subc.rel_f); + b[8] = (dat >> 24) & 0xff; + b[9] = (dat >> 16) & 0xff; + b[10] = (dat >> 8) & 0xff; + b[11] = dat & 0xff; + } + if (b[0] != 0x00) + break; + base += 12; + fallthrough; + case 0x02: + /* UPC - TODO: Finding and reporting the actual UPC data. */ + memset(&(b[base]), 0x00, 20 - diff); + base += diff; + memset(&(b[base + 1]), 0x30, 13); + /* NEC CDR-260 speaks BCD. */ + if (dev->is_bcd) + b[base + 15] = bin2bcd(subc.abs_f); + else + b[base + 15] = subc.abs_f; + if (b[0] != 0x00) + break; + base += 16; + fallthrough; + case 0x03: + /* ISRC - TODO: Finding and reporting the actual ISRC data. */ + memset(&(b[base]), 0x00, 20 - diff); + base += diff; + memset(&(b[base]), 0x30, 12); + /* NEC CDR-260 speaks BCD. */ + if (dev->is_bcd) + b[base + 14] = bin2bcd(subc.abs_f); + else + b[base + 14] = subc.abs_f; + break; + default: + cdrom_log(dev->log, "b[0] = %02X\n", b[0]); + break; + } +} + +void +cdrom_get_current_subchannel_sony(cdrom_t *dev, uint8_t *b, const int msf) +{ + subchannel_t subc; + + cdrom_get_subchannel(dev, dev->seek_pos, &subc, 1); + + cdrom_log(dev->log, "Returned subchannel at %02i:%02i.%02i, seek pos = %08x, " + "cd_end = %08x, msf = %x.\n", + subc.abs_m, subc.abs_s, subc.abs_f, dev->seek_pos, dev->cd_end, msf); + + b[0] = subc.attr; + b[1] = subc.track; + b[2] = subc.index; + + if (msf) { + b[3] = subc.rel_m; + b[4] = subc.rel_s; + b[5] = subc.rel_f; + b[6] = subc.abs_m; + b[7] = subc.abs_s; + b[8] = subc.abs_f; + } else { + uint32_t dat = MSFtoLBA(subc.rel_m, subc.rel_s, subc.rel_f); + b[3] = (dat >> 16) & 0xff; + b[4] = (dat >> 8) & 0xff; + b[5] = dat & 0xff; + dat = MSFtoLBA(subc.abs_m, subc.abs_s, subc.abs_f) - 150; + b[6] = (dat >> 16) & 0xff; + b[7] = (dat >> 8) & 0xff; + b[8] = dat & 0xff; + } +} + +uint8_t +cdrom_get_audio_status_pioneer(cdrom_t *dev, uint8_t *b) +{ + uint8_t ret; + subchannel_t subc; + + cdrom_get_subchannel(dev, dev->seek_pos, &subc, 0); + + if (dev->cd_status & CD_STATUS_HAS_AUDIO) { + if (dev->cd_status == CD_STATUS_PLAYING) + ret = dev->sound_on ? 0x00 : 0x02; + else if (dev->cd_status == CD_STATUS_PAUSED) + ret = 0x01; + else + ret = 0x03; + } else + ret = 0x05; + + b[0] = 0; + b[1] = subc.abs_m; + b[2] = subc.abs_s; + b[3] = subc.abs_f; + + return ret; +} + +uint8_t +cdrom_get_audio_status_sony(cdrom_t *dev, uint8_t *b, const int msf) +{ + uint8_t ret; + subchannel_t subc; + + cdrom_get_subchannel(dev, dev->seek_pos, &subc, 1); + + if (dev->cd_status & CD_STATUS_HAS_AUDIO) { + if (dev->cd_status == CD_STATUS_PLAYING) + ret = dev->sound_on ? 0x00 : 0x02; + else if (dev->cd_status == CD_STATUS_PAUSED) + ret = 0x01; + else + ret = 0x03; + } else + ret = 0x05; + + if (msf) { + b[0] = 0; + b[1] = subc.abs_m; + b[2] = subc.abs_s; + b[3] = subc.abs_f; + } else { + const uint32_t dat = MSFtoLBA(subc.abs_m, subc.abs_s, subc.abs_f) - 150; + b[0] = (dat >> 24) & 0xff; + b[1] = (dat >> 16) & 0xff; + b[2] = (dat >> 8) & 0xff; + b[3] = dat & 0xff; + } + + return ret; +} + +void +cdrom_get_current_subcodeq(cdrom_t *dev, uint8_t *b) +{ + subchannel_t subc; + + cdrom_get_subchannel(dev, dev->seek_pos, &subc, 0); + + b[0] = (subc.attr >> 4) | ((subc.attr & 0xf) << 4); + b[1] = subc.track; + b[2] = subc.index; + b[3] = subc.rel_m; + b[4] = subc.rel_s; + b[5] = subc.rel_f; + b[6] = subc.abs_m; + b[7] = subc.abs_s; + b[8] = subc.abs_f; + + cdrom_log(dev->log, "SubCodeQ: %02X %02X %02X %02X %02X %02X %02X %02X " + "%02X\n", + b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8]); +} + +uint8_t +cdrom_get_current_subcodeq_playstatus(cdrom_t *dev, uint8_t *b) +{ + uint8_t ret; + + cdrom_get_current_subcodeq(dev, b); + + switch (dev->cd_status) { + default: case CD_STATUS_EMPTY: + case CD_STATUS_DATA_ONLY: case CD_STATUS_DVD: + case CD_STATUS_STOPPED: case CD_STATUS_PLAYING_COMPLETED: + ret = 0x03; + break; + case CD_STATUS_HOLD: + ret = 0x02; + break; + case CD_STATUS_PAUSED: + ret = 0x01; + break; + case CD_STATUS_PLAYING: + ret = 0x00; + break; + } + + cdrom_log(dev->log, "SubCodeQ: Play Status: Seek LBA=%08x, CDEND=%08x.\n", + dev->seek_pos, dev->cd_end); + return ret; +} + +int +cdrom_read_toc(const cdrom_t *dev, uint8_t *b, const int type, + const uint8_t start_track, const int msf, const int max_len) { int len; @@ -1353,7 +2047,7 @@ cdrom_read_toc(cdrom_t *dev, unsigned char *b, int type, unsigned char start_tra len = read_toc_raw(dev, b, start_track); break; default: - cdrom_log("CD-ROM %i: Unknown TOC read type: %i\n", dev->id, type); + cdrom_log(dev->log, "Unknown TOC read type: %i\n", type); return 0; } @@ -1366,11 +2060,10 @@ cdrom_read_toc(cdrom_t *dev, unsigned char *b, int type, unsigned char start_tra } int -cdrom_read_toc_sony(cdrom_t *dev, unsigned char *b, unsigned char start_track, int msf, int max_len) +cdrom_read_toc_sony(const cdrom_t *dev, uint8_t *b, const uint8_t start_track, + const int msf, const int max_len) { - int len; - - len = read_toc_normal(dev, b, start_track, msf, 1); + int len = read_toc_normal(dev, b, start_track, msf, 1); len = MIN(len, max_len); @@ -1392,7 +2085,7 @@ cdrom_get_track_buffer(cdrom_t *dev, uint8_t *buf) int last = -1; if (dev != NULL) - dev->ops->get_raw_track_info(dev, &num, (raw_track_info_t *) rti); + dev->ops->get_raw_track_info(dev->local, &num, rti); if (num > 0) { first = find_track(trti, num, 1); @@ -1428,7 +2121,7 @@ cdrom_get_track_buffer(cdrom_t *dev, uint8_t *buf) /* TODO: Actually implement this properly. */ void -cdrom_get_q(cdrom_t *dev, uint8_t *buf, int *curtoctrk, uint8_t mode) +cdrom_get_q(UNUSED(cdrom_t *dev), uint8_t *buf, UNUSED(int *curtoctrk), UNUSED(uint8_t mode)) { memset(buf, 0x00, 10); } @@ -1437,68 +2130,83 @@ uint8_t cdrom_mitsumi_audio_play(cdrom_t *dev, uint32_t pos, uint32_t len) { track_info_t ti; + int ret = 0; - if (dev->cd_status == CD_STATUS_DATA_ONLY) - return 0; + if (dev->cd_status & CD_STATUS_HAS_AUDIO) { + cdrom_log(dev->log, "Play Mitsumi audio - %08X %08X\n", pos, len); - cdrom_log("CD-ROM 0: Play Mitsumi audio - %08X %08X\n", pos, len); - dev->ops->get_track_info(dev, pos, 0, &ti); - pos = MSFtoLBA(ti.m, ti.s, ti.f) - 150; - dev->ops->get_track_info(dev, len, 1, &ti); - len = MSFtoLBA(ti.m, ti.s, ti.f) - 150; + ret = dev->ops->get_track_info(dev->local, pos, 0, &ti); - /* Do this at this point, since it's at this point that we know the - actual LBA position to start playing from. */ - if (!(dev->ops->track_type(dev, pos) & CD_TRACK_AUDIO)) { - cdrom_log("CD-ROM %i: LBA %08X not on an audio track\n", dev->id, pos); - cdrom_stop(dev); - return 0; + if (ret) { + pos = MSFtoLBA(ti.m, ti.s, ti.f) - 150; + ret = dev->ops->get_track_info(dev->local, len, 1, &ti); + + if (ret) { + len = MSFtoLBA(ti.m, ti.s, ti.f) - 150; + + /* + Do this at this point, since it's at this point that we know the + actual LBA position to start playing from. + */ + ret = (dev->ops->get_track_type(dev->local, pos) == CD_TRACK_AUDIO); + + if (ret) { + dev->seek_pos = pos; + dev->cd_end = len; + dev->cd_status = CD_STATUS_PLAYING; + dev->cd_buflen = 0; + } else { + cdrom_log(dev->log, "LBA %08X not on an audio track\n", pos); + cdrom_stop(dev); + } + } else { + cdrom_log(dev->log, "Unable to get the ending position for track %08X\n", + len); + cdrom_stop(dev); + } + } else { + cdrom_log(dev->log, "Unable to get the starting position for track %08X\n", pos); + cdrom_stop(dev); + } } - dev->seek_pos = pos; - dev->cd_end = len; - dev->cd_status = CD_STATUS_PLAYING; - dev->cd_buflen = 0; - - return 1; + return ret; } #endif uint8_t -cdrom_read_disc_info_toc(cdrom_t *dev, unsigned char *b, unsigned char track, int type) +cdrom_read_disc_info_toc(cdrom_t *dev, uint8_t *b, + const uint8_t track, const int type) { - uint8_t rti[65536] = { 0 }; - raw_track_info_t *trti = (raw_track_info_t *) rti; - int num = 0; - int first = -1; - int last = -1; - int t = -1; - uint32_t temp; - uint8_t ret = 1; + uint8_t rti[65536] = { 0 }; + const raw_track_info_t *trti = (raw_track_info_t *) rti; + int num = 0; + int first = -1; + int t = -1; + uint8_t ret = 1; + uint32_t temp; - if (dev != NULL) - dev->ops->get_raw_track_info(dev, &num, (raw_track_info_t *) rti); + cdrom_log(dev->log, "Read DISC Info TOC Type = %d, track = %d\n", type, track); - cdrom_log("Read DISC Info TOC Type = %d, track = %d\n", type, track); + dev->inv_field = track; + dev->ops->get_raw_track_info(dev->local, &num, rti); switch (type) { case 0: if (num > 0) { - first = find_track(trti, num, 1); - last = find_track(trti, num, 0); - } + if (num < 4) + ret = 0; + else { + b[0] = bin2bcd(trti[0].pm); + b[1] = bin2bcd(trti[1].pm); + b[2] = 0x00; + b[3] = 0x00; - if ((first == -1) || (last == -1)) + cdrom_log(dev->log, "Returned Toshiba/NEC disc information (type 0) " + "at %02i:%02i\n", b[0], b[1]); + } + } else ret = 0; - else { - b[0] = bin2bcd(first); - b[1] = bin2bcd(last); - b[2] = 0x00; - b[3] = 0x00; - - cdrom_log("CD-ROM %i: Returned Toshiba/NEC disc information (type 0) at %02i:%02i\n", - dev->id, b[0], b[1]); - } break; case 1: if (num > 0) @@ -1512,8 +2220,8 @@ cdrom_read_disc_info_toc(cdrom_t *dev, unsigned char *b, unsigned char track, in b[2] = bin2bcd(trti[t].pf); b[3] = 0x00; - cdrom_log("CD-ROM %i: Returned Toshiba/NEC disc information (type 1) at %02i:%02i.%02i\n", - dev->id, b[0], b[1], b[2]); + cdrom_log(dev->log, "Returned Toshiba/NEC disc information (type 1) at " + "%02i:%02i.%02i\n", b[0], b[1], b[2]); } break; case 2: @@ -1528,49 +2236,41 @@ cdrom_read_disc_info_toc(cdrom_t *dev, unsigned char *b, unsigned char track, in b[2] = bin2bcd(trti[t].pf); b[3] = trti[t].adr_ctl; - cdrom_log("CD-ROM %i: Returned Toshiba/NEC disc information (type 2) at " - "%02i:%02i.%02i, track=%d, attr=%02x.\n", dev->id, b[0], b[1], b[2], bcd2bin(track), b[3]); + cdrom_log(dev->log, "Returned Toshiba/NEC disc information (type 2) at " + "%02i:%02i.%02i, track=%d, attr=%02x.\n", b[0], b[1], + b[2], bcd2bin(track), b[3]); } break; case 3: /* Undocumented on NEC CD-ROM's, from information based on sr_vendor.c from the Linux kernel */ - switch (dev->type) { - case CDROM_TYPE_NEC_25_10a: - case CDROM_TYPE_NEC_38_103: - case CDROM_TYPE_NEC_75_103: - case CDROM_TYPE_NEC_77_106: - case CDROM_TYPE_NEC_211_100: - case CDROM_TYPE_NEC_464_105: - b[0x0e] = 0x00; + if (dev->is_nec) { + b[0x0e] = 0x00; - if (num > 0) - first = find_track(trti, num, 1); + if (num > 0) + first = find_track(trti, num, 1); - if (first == -1) - ret = 0; - else { - temp = MSFtoLBA(trti[first].pm, trti[first].ps, trti[first].pf) - 150; - b[0x0f] = temp >> 24; - b[0x10] = temp >> 16; - b[0x11] = temp >> 8; - b[0x12] = temp; - } - break; + if (first == -1) + ret = 0; + else { + temp = MSFtoLBA(trti[first].pm, trti[first].ps, trti[first].pf) - 150; + b[0x0f] = temp >> 24; + b[0x10] = temp >> 16; + b[0x11] = temp >> 8; + b[0x12] = temp; + } + } else { + b[0] = trti[0].ps; /* Disc type. */ - default: - b[0] = 0x00; /* Audio or CDROM disc. */ + if (num > 0) + first = find_track(trti, num, 1); - if (num > 0) - first = find_track(trti, num, 1); - - if (first == -1) - ret = 0; - else { - temp = MSFtoLBA(trti[first].pm, trti[first].ps, trti[first].pf) - 150; - b[0x1] = temp >> 24; - b[0x2] = temp >> 16; - b[0x3] = temp >> 8; - } - break; + if (first == -1) + ret = 0; + else { + temp = MSFtoLBA(trti[first].pm, trti[first].ps, trti[first].pf) - 150; + b[0x1] = temp >> 24; + b[0x2] = temp >> 16; + b[0x3] = temp >> 8; + } } break; default: @@ -1580,307 +2280,38 @@ cdrom_read_disc_info_toc(cdrom_t *dev, unsigned char *b, unsigned char track, in return ret; } -static int -track_type_is_valid(UNUSED(uint8_t id), int type, int flags, int audio, int mode2) +static uint32_t +cdrom_msf_to_lba(const int sector, const int ismsf, + int cdrom_sector_type, const uint8_t vendor_type) { - 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); - return 0; - } - - if ((type != 1) && !audio) { - if ((flags & 0x06) == 0x06) { - cdrom_log("CD-ROM %i: [Any Data Mode] Invalid error flags\n", id); - return 0; - } - - if (((flags & 0x700) == 0x300) || ((flags & 0x700) > 0x400)) { - cdrom_log("CD-ROM %i: [Any Data Mode] Invalid subchannel data flags (%02X)\n", id, flags & 0x700); - return 0; - } - - if ((flags & 0x18) == 0x08) { /* EDC/ECC without user data is an illegal mode */ - cdrom_log("CD-ROM %i: [Any Data Mode] EDC/ECC without user data is an illegal mode\n", id); - return 0; - } - - if (((flags & 0xf0) == 0x90) || ((flags & 0xf0) == 0xc0)) { /* 0x90/0x98/0xC0/0xC8 are illegal modes */ - cdrom_log("CD-ROM %i: [Any Data Mode] 0x90/0x98/0xC0/0xC8 are illegal modes\n", id); - return 0; - } - - if (((type > 3) && (type != 8)) || (mode2 && (mode2 & 0x03))) { - if ((flags & 0xf0) == 0x30) { /* 0x30/0x38 are illegal modes */ - cdrom_log("CD-ROM %i: [Any XA Mode 2] 0x30/0x38 are illegal modes\n", id); - return 0; - } - if (((flags & 0xf0) == 0xb0) || ((flags & 0xf0) == 0xd0)) { /* 0xBx and 0xDx are illegal modes */ - cdrom_log("CD-ROM %i: [Any XA Mode 2] 0xBx and 0xDx are illegal modes\n", id); - return 0; - } - } - } - - return 1; -} - -static int -read_audio(cdrom_t *dev, uint32_t lba, uint8_t *b) -{ - int ret = dev->ops->read_sector(dev, raw_buffer, lba); - - memcpy(b, raw_buffer, 2352); - - cdrom_sector_size = 2352; - - return ret; -} - -static void -process_mode1(cdrom_t *dev, int cdrom_sector_flags, uint8_t *b) -{ - cdrom_sector_size = 0; - - if (cdrom_sector_flags & 0x80) { - /* Sync */ - cdrom_log("CD-ROM %i: [Mode 1] Sync\n", dev->id); - memcpy(b, raw_buffer, 12); - cdrom_sector_size += 12; - b += 12; - } - - if (cdrom_sector_flags & 0x20) { - /* Header */ - cdrom_log("CD-ROM %i: [Mode 1] Header\n", dev->id); - memcpy(b, raw_buffer + 12, 4); - cdrom_sector_size += 4; - b += 4; - } - - if (cdrom_sector_flags & 0x40) { - /* Sub-header */ - if (!(cdrom_sector_flags & 0x10)) { - /* No user data */ - cdrom_log("CD-ROM %i: [Mode 1] Sub-header\n", dev->id); - memcpy(b, raw_buffer + 16, 8); - cdrom_sector_size += 8; - b += 8; - } - } - - if (cdrom_sector_flags & 0x10) { - /* User data */ - cdrom_log("CD-ROM %i: [Mode 1] User data\n", dev->id); - memcpy(b, raw_buffer + 16, 2048); - cdrom_sector_size += 2048; - b += 2048; - } - - if (cdrom_sector_flags & 0x08) { - /* EDC/ECC */ - cdrom_log("CD-ROM %i: [Mode 1] EDC/ECC\n", dev->id); - memcpy(b, raw_buffer + 2064, 288); - cdrom_sector_size += 288; - b += 288; - } -} - -static int -read_data(cdrom_t *dev, uint32_t lba) -{ - return dev->ops->read_sector(dev, raw_buffer, lba); -} - -static int -read_mode1(cdrom_t *dev, int cdrom_sector_flags, uint32_t lba, uint8_t *b) -{ - int ret = read_data(dev, lba); - - process_mode1(dev, cdrom_sector_flags, b); - - return ret; -} - -static int -read_mode2_non_xa(cdrom_t *dev, int cdrom_sector_flags, uint32_t lba, uint8_t *b) -{ - int ret = dev->ops->read_sector(dev, raw_buffer, lba); - - cdrom_sector_size = 0; - - if (cdrom_sector_flags & 0x80) { - /* Sync */ - cdrom_log("CD-ROM %i: [Mode 2 Formless] Sync\n", dev->id); - memcpy(b, raw_buffer, 12); - cdrom_sector_size += 12; - b += 12; - } - - if (cdrom_sector_flags & 0x20) { - /* Header */ - cdrom_log("CD-ROM %i: [Mode 2 Formless] Header\n", dev->id); - memcpy(b, raw_buffer + 12, 4); - cdrom_sector_size += 4; - b += 4; - } - - /* Mode 1 sector, expected type is 1 type. */ - if (cdrom_sector_flags & 0x40) { - /* Sub-header */ - cdrom_log("CD-ROM %i: [Mode 2 Formless] Sub-header\n", dev->id); - memcpy(b, raw_buffer + 16, 8); - cdrom_sector_size += 8; - b += 8; - } - - if (cdrom_sector_flags & 0x10) { - /* User data */ - cdrom_log("CD-ROM %i: [Mode 2 Formless] User data\n", dev->id); - memcpy(b, raw_buffer + 24, 2336); - cdrom_sector_size += 2336; - b += 2336; - } - - return ret; -} - -static void -process_mode2_xa_form1(cdrom_t *dev, int cdrom_sector_flags, uint8_t *b) -{ - cdrom_sector_size = 0; - - if (cdrom_sector_flags & 0x80) { - /* Sync */ - cdrom_log("CD-ROM %i: [XA Mode 2 Form 1] Sync\n", dev->id); - memcpy(b, raw_buffer, 12); - cdrom_sector_size += 12; - b += 12; - } - - if (cdrom_sector_flags & 0x20) { - /* Header */ - cdrom_log("CD-ROM %i: [XA Mode 2 Form 1] Header\n", dev->id); - memcpy(b, raw_buffer + 12, 4); - cdrom_sector_size += 4; - b += 4; - } - - if (cdrom_sector_flags & 0x40) { - /* Sub-header */ - cdrom_log("CD-ROM %i: [XA Mode 2 Form 1] Sub-header\n", dev->id); - memcpy(b, raw_buffer + 16, 8); - cdrom_sector_size += 8; - b += 8; - } - - if (cdrom_sector_flags & 0x10) { - /* User data */ - cdrom_log("CD-ROM %i: [XA Mode 2 Form 1] User data\n", dev->id); - memcpy(b, raw_buffer + 24, 2048); - cdrom_sector_size += 2048; - b += 2048; - } - - if (cdrom_sector_flags & 0x08) { - /* EDC/ECC */ - cdrom_log("CD-ROM %i: [XA Mode 2 Form 1] EDC/ECC\n", dev->id); - memcpy(b, raw_buffer + 2072, 280); - cdrom_sector_size += 280; - b += 280; - } -} - -static int -read_mode2_xa_form1(cdrom_t *dev, int cdrom_sector_flags, uint32_t lba, uint8_t *b) -{ - int ret = read_data(dev, lba); - - process_mode2_xa_form1(dev, cdrom_sector_flags, b); - - return ret; -} - -static int -read_mode2_xa_form2(cdrom_t *dev, int cdrom_sector_flags, uint32_t lba, uint8_t *b) -{ - int ret = dev->ops->read_sector(dev, raw_buffer, lba); - - cdrom_sector_size = 0; - - if (cdrom_sector_flags & 0x80) { - /* Sync */ - cdrom_log("CD-ROM %i: [XA Mode 2 Form 2] Sync\n", dev->id); - memcpy(b, raw_buffer, 12); - cdrom_sector_size += 12; - b += 12; - } - - if (cdrom_sector_flags & 0x20) { - /* Header */ - cdrom_log("CD-ROM %i: [XA Mode 2 Form 2] Header\n", dev->id); - memcpy(b, raw_buffer + 12, 4); - cdrom_sector_size += 4; - b += 4; - } - - if (cdrom_sector_flags & 0x40) { - /* Sub-header */ - cdrom_log("CD-ROM %i: [XA Mode 2 Form 2] Sub-header\n", dev->id); - memcpy(b, raw_buffer + 16, 8); - cdrom_sector_size += 8; - b += 8; - } - - if (cdrom_sector_flags & 0x10) { - /* User data */ - cdrom_log("CD-ROM %i: [XA Mode 2 Form 2] User data\n", dev->id); - memcpy(b, raw_buffer + 24, 2328); - cdrom_sector_size += 2328; - b += 2328; - } - - return ret; -} - -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; - uint8_t *temp_b; + int pos = sector; uint32_t lba; - int audio = 0; - int mode2 = 0; - int unk = 0; - int ret = 0; - if (dev->cd_status == CD_STATUS_EMPTY) - return 0; - - b = temp_b = buffer; - - *len = 0; + if ((cdrom_sector_type & 0x0f) >= 0x08) { + mult = cdrom_sector_type >> 4; + pos /= mult; + } if (ismsf) { - int m = (sector >> 16) & 0xff; - int s = (sector >> 8) & 0xff; - int f = sector & 0xff; + const int m = (pos >> 16) & 0xff; + const int s = (pos >> 8) & 0xff; + const int f = pos & 0xff; lba = MSFtoLBA(m, s, f) - 150; } else { switch (vendor_type) { case 0x00: - lba = sector; + lba = pos; break; case 0x40: { - int m = bcd2bin((sector >> 24) & 0xff); - int s = bcd2bin((sector >> 16) & 0xff); - int f = bcd2bin((sector >> 8) & 0xff); + const int m = bcd2bin((pos >> 24) & 0xff); + const int s = bcd2bin((pos >> 16) & 0xff); + const int f = bcd2bin((pos >> 8) & 0xff); lba = MSFtoLBA(m, s, f) - 150; break; } case 0x80: - lba = bcd2bin((sector >> 24) & 0xff); + lba = bcd2bin((pos >> 24) & 0xff); break; /* Never used values but the compiler complains. */ default: @@ -1888,132 +2319,617 @@ cdrom_readsector_raw(cdrom_t *dev, uint8_t *buffer, int sector, int ismsf, int c } } - if (dev->ops->track_type) - audio = dev->ops->track_type(dev, lba); + return lba; +} - mode2 = audio & CD_TRACK_MODE2; - unk = audio & CD_TRACK_UNK_DATA; - audio &= CD_TRACK_AUDIO; +int +cdrom_is_track_audio(cdrom_t *dev, const int sector, + const int ismsf, int cdrom_sector_type, + const uint8_t vendor_type) +{ + int audio = 0; + uint32_t lba = cdrom_msf_to_lba(sector, ismsf, + cdrom_sector_type, vendor_type); - memset(raw_buffer, 0, 2448); - memset(extra_buffer, 0, 296); + if (dev->ops->get_track_type) + audio = dev->ops->get_track_type(dev->local, lba); - if ((cdrom_sector_flags & 0xf8) == 0x08) { - /* 0x08 is an illegal mode */ - cdrom_log("CD-ROM %i: [Mode 1] 0x08 is an illegal mode\n", dev->id); - return 0; - } + audio &= CD_TRACK_AUDIO; - if (!track_type_is_valid(dev->id, cdrom_sector_type, cdrom_sector_flags, audio, mode2)) - return 0; + return audio; +} - if ((cdrom_sector_type > 5) && (cdrom_sector_type != 8)) { - cdrom_log("CD-ROM %i: Attempting to read an unrecognized sector type from an image\n", dev->id); - return 0; - } else if (cdrom_sector_type == 1) { - if (!audio || (dev->cd_status == CD_STATUS_DATA_ONLY)) { - cdrom_log("CD-ROM %i: [Audio] Attempting to read an audio sector from a data image\n", dev->id); - return 0; - } +int +cdrom_readsector_raw(cdrom_t *dev, uint8_t *buffer, const int sector, const int ismsf, + int cdrom_sector_type, const int cdrom_sector_flags, + int *len, const uint8_t vendor_type) +{ + int pos = sector; + int ret = 0; + const int old_type = cdrom_sector_type; - ret = read_audio(dev, lba, temp_b); - } else if (cdrom_sector_type == 2) { - if (audio || mode2) { - cdrom_log("CD-ROM %i: [Mode 1] Attempting to read a sector of another type\n", dev->id); - return 0; - } - - ret = read_mode1(dev, cdrom_sector_flags, lba, temp_b); - } else if (cdrom_sector_type == 3) { - if (audio || !mode2 || (mode2 & 0x03)) { - cdrom_log("CD-ROM %i: [Mode 2 Formless] Attempting to read a sector of another type\n", dev->id); - return 0; - } - - ret = read_mode2_non_xa(dev, cdrom_sector_flags, lba, temp_b); - } else if (cdrom_sector_type == 4) { - if (audio || !mode2 || ((mode2 & 0x03) != 1)) { - cdrom_log("CD-ROM %i: [XA Mode 2 Form 1] Attempting to read a sector of another type\n", dev->id); - return 0; - } - - read_mode2_xa_form1(dev, cdrom_sector_flags, lba, temp_b); - } else if (cdrom_sector_type == 5) { - if (audio || !mode2 || ((mode2 & 0x03) != 2)) { - cdrom_log("CD-ROM %i: [XA Mode 2 Form 2] Attempting to read a sector of another type\n", dev->id); - return 0; - } - - ret = read_mode2_xa_form2(dev, cdrom_sector_flags, lba, temp_b); - } else if (cdrom_sector_type == 8) { - if (audio) { - cdrom_log("CD-ROM %i: [Any Data] Attempting to read a data sector from an audio track\n", dev->id); - return 0; - } - - if (unk) { - /* This is needed to correctly read Mode 2 XA Form 1 sectors over IOCTL. */ - ret = read_data(dev, lba); - - if (raw_buffer[0x000f] == 0x02) { - cdrom_log("CD-ROM %i: [Any Data] Unknown data type determined to be XA Mode 2 Form 1\n", dev->id); - process_mode2_xa_form1(dev, cdrom_sector_flags, temp_b); - } else { - cdrom_log("CD-ROM %i: [Any Data] Unknown data type determined to be Mode 1\n", dev->id); - process_mode1(dev, cdrom_sector_flags, temp_b); - } - } else if (mode2 && ((mode2 & 0x03) == 1)) - ret = read_mode2_xa_form1(dev, cdrom_sector_flags, lba, temp_b); - else if (!mode2) - ret = read_mode1(dev, cdrom_sector_flags, lba, temp_b); - else { - cdrom_log("CD-ROM %i: [Any Data] Attempting to read a data sector whose cooked size " - "is not 2048 bytes\n", dev->id); - return 0; - } + if ((cdrom_sector_type & 0x0f) >= 0x08) { + mult = cdrom_sector_type >> 4; + cdrom_sector_type &= 0x0f; + part = pos % mult; + pos /= mult; + ecc_diff = (cdrom_sector_type & 0x01) ? 4 : 0; } else { - if (mode2) { - if ((mode2 & 0x03) == 0x01) - ret = read_mode2_xa_form1(dev, cdrom_sector_flags, lba, temp_b); - else if ((mode2 & 0x03) == 0x02) - ret = read_mode2_xa_form2(dev, cdrom_sector_flags, lba, temp_b); - else - ret = read_mode2_non_xa(dev, cdrom_sector_flags, lba, temp_b); + mult = 1; + part = 0; + ecc_diff = 0; + } + + if (dev->cd_status != CD_STATUS_EMPTY) { + uint8_t *temp_b; + uint8_t *b = temp_b = buffer; + int audio = 0; + uint32_t lba = cdrom_msf_to_lba(sector, ismsf, + old_type, vendor_type); + int mode2 = 0; + + *len = 0; + + if (dev->ops->get_track_type) + audio = dev->ops->get_track_type(dev->local, lba); + + const int dm = audio & CD_TRACK_MODE_MASK; + audio &= CD_TRACK_AUDIO; + + if (dm != CD_TRACK_NORMAL) + mode2 = 1; + + memset(dev->extra_buffer, 0, 296); + + if ((cdrom_sector_flags & 0xf8) == 0x08) { + /* 0x08 is an illegal mode */ + cdrom_log(dev->log, "[Mode 1] 0x08 is an illegal mode\n"); + } else if ((cdrom_sector_type > 5) && (cdrom_sector_type < 8)) { + cdrom_log(dev->log, "Attempting to read an unrecognized sector " + "type from an image\n"); + return 0; } else { - if (audio) - ret = read_audio(dev, lba, temp_b); - else - ret = read_mode1(dev, cdrom_sector_flags, lba, temp_b); + if ((cdrom_sector_type > 1) && audio && + (dev->cd_status & CD_STATUS_HAS_AUDIO)) { + cdrom_log(dev->log, "[%s] Attempting to read a data sector " + "from an audio track\n", + cdrom_req_modes[cdrom_sector_type]); + } else if ((cdrom_sector_type == 1) && + (!audio || !(dev->cd_status & CD_STATUS_HAS_AUDIO))) { + cdrom_log(dev->log, "[Audio] Attempting to read an audio " + "sector from a data track\n"); + } else if (audio) { + if (!track_type_is_valid(dev, cdrom_sector_type, + cdrom_sector_flags, 1, 0x00)) + ret = 0; + else + ret = read_audio(dev, lba, temp_b); + } else { + ret = read_data(dev, lba); + + /* Return with error if we had one. */ + if (ret > 0) { + int form = 0; + + if ((dev->raw_buffer[dev->cur_buf][0x000f] == 0x00) || + (dev->raw_buffer[dev->cur_buf][0x000f] > 0x02)) { + cdrom_log(dev->log, "[%s] Unknown mode: %02X\n", + cdrom_req_modes[cdrom_sector_type], + dev->raw_buffer[dev->cur_buf][0x000f]); + ret = 0; + } else if (mode2) { + if (dev->raw_buffer[dev->cur_buf][0x000f] == 0x01) + /* + Use Mode 1, since evidently specification-violating + discs exist. + */ + mode2 = 0; + else if (dev->raw_buffer[dev->cur_buf][0x0012] != + dev->raw_buffer[dev->cur_buf][0x0016]) { + cdrom_log(dev->log, "[%s] XA Mode 2 sector with " + "malformed sub-header\n", + cdrom_req_modes[cdrom_sector_type]); + ret = 0; + } else + form = ((dev->raw_buffer[dev->cur_buf][0x0012] & + 0x20) >> 5) + 1; + } else if (dev->raw_buffer[dev->cur_buf][0x000f] == 0x02) + mode2 = 1; + + if (ret > 0) { + const int mode_id = mode2 + form; + + cdrom_log(dev->log, "[%s] %s detected\n", + cdrom_req_modes[cdrom_sector_type], + cdrom_modes[mode_id]); + + if (!track_type_is_valid(dev, cdrom_sector_type, + cdrom_sector_flags, 0, + (mode2 << 2) + form)) { + cdrom_log(dev->log, "[%s] Invalid track type\n", + cdrom_req_modes[cdrom_sector_type]); + ret = 0; + } else if (cdrom_mode_masks[cdrom_sector_type] & + (1 << mode_id)) + cdrom_process_data[mode_id](dev, cdrom_sector_flags, + temp_b); + else { + cdrom_log(dev->log, "[%s] Attempting to read a " + "%s sector\n", + cdrom_req_modes[cdrom_sector_type], + cdrom_modes[mode_id]); + ret = 0; + } + } + } + } + + if (ret > 0) { + process_c2_and_subch(dev, cdrom_sector_flags, b); + *len = dev->cdrom_sector_size; + } } } - if ((cdrom_sector_flags & 0x06) == 0x02) { - /* Add error flags. */ - cdrom_log("CD-ROM %i: Error flags\n", dev->id); - memcpy(b + cdrom_sector_size, extra_buffer, 294); - cdrom_sector_size += 294; - } else if ((cdrom_sector_flags & 0x06) == 0x04) { - /* Add error flags. */ - cdrom_log("CD-ROM %i: Full error flags\n", dev->id); - memcpy(b + cdrom_sector_size, extra_buffer, 296); - cdrom_sector_size += 296; + return ret; +} + +/* + Read DVD Structure + + Yes, +2 instead of +4 is correct, I have verified this via Windows IOCTL, and it also matches + the MMC specification. + */ +int +cdrom_read_dvd_structure(const cdrom_t *dev, const uint8_t layer, const uint8_t format, + uint8_t *buffer, uint32_t *info) +{ + int max_layer = 0; + int ret = 0; + uint64_t total_sectors; + + if (format < 0xc0) { + if (dev->cd_status != CD_STATUS_DVD) { + *info = format; + ret = -(SENSE_ILLEGAL_REQUEST << 16) | (ASC_INCOMPATIBLE_FORMAT << 8); + } else if ((dev->ops != NULL) && (dev->ops->read_dvd_structure != NULL)) + ret = dev->ops->read_dvd_structure(dev->local, layer, format, buffer, info); } - if ((cdrom_sector_flags & 0x700) == 0x100) { - cdrom_log("CD-ROM %i: Raw subchannel data\n", dev->id); - memcpy(b + cdrom_sector_size, raw_buffer + 2352, 96); - cdrom_sector_size += 96; - } else if ((cdrom_sector_flags & 0x700) == 0x200) { - cdrom_log("CD-ROM %i: Q subchannel data\n", dev->id); - memcpy(b + cdrom_sector_size, raw_buffer + 2352, 16); - cdrom_sector_size += 16; - } else if ((cdrom_sector_flags & 0x700) == 0x400) { - cdrom_log("CD-ROM %i: R/W subchannel data\n", dev->id); - memcpy(b + cdrom_sector_size, raw_buffer + 2352, 96); - cdrom_sector_size += 96; + if (ret == 0) switch (format) { + case 0x00: /* Physical format information */ + total_sectors = (uint64_t) dev->cdrom_capacity; + + if (total_sectors > DVD_LAYER_0_SECTORS) + max_layer++; + + if (layer > max_layer) { + *info = layer; + ret = -(SENSE_ILLEGAL_REQUEST << 16) | (ASC_INV_FIELD_IN_CMD_PACKET << 8); + } else { + if (total_sectors == 0) { + *info = 0x00000000; + ret = -(SENSE_NOT_READY << 16) | (ASC_MEDIUM_NOT_PRESENT << 8); + } else { + buffer[4] = 0x01; /* DVD-ROM, part version 1. */ + buffer[5] = 0x0f; /* 120mm disc, minimum rate unspecified .*/ + if (max_layer == 1) + /* Two layers, OTP track path, read-only (per MMC-2 spec). */ + buffer[6] = 0x31; + else + /* One layer, read-only (per MMC-2 spec). */ + buffer[6] = 0x01; + buffer[7] = 0x10; /* Default densities. */ + + /* Start sector. */ + buffer[8] = 0x00; + buffer[9] = (0x030000 >> 16) & 0xff; + buffer[10] = (0x030000 >> 8) & 0xff; + buffer[11] = 0x030000 & 0xff; + + /* End sector. */ + buffer[12] = 0x00; + if (layer == 1) { + buffer[13] = ((total_sectors - DVD_LAYER_0_SECTORS) >> 16) & 0xff; + buffer[14] = ((total_sectors - DVD_LAYER_0_SECTORS) >> 8) & 0xff; + buffer[15] = (total_sectors - DVD_LAYER_0_SECTORS) & 0xff; + } else if (max_layer == 1) { + buffer[13] = (DVD_LAYER_0_SECTORS >> 16) & 0xff; + buffer[14] = (DVD_LAYER_0_SECTORS >> 8) & 0xff; + buffer[15] = DVD_LAYER_0_SECTORS & 0xff; + } else { + buffer[13] = (total_sectors >> 16) & 0xff; + buffer[14] = (total_sectors >> 8) & 0xff; + buffer[15] = total_sectors & 0xff; + } + + /* Layer 0 end sector. */ + buffer[16] = 0x00; + buffer[17] = (total_sectors >> 16) & 0xff; + buffer[18] = (total_sectors >> 8) & 0xff; + buffer[19] = total_sectors & 0xff; + + buffer[20] = 0x00; /* No BCA */ + + /* 2048 bytes of data + 2 byte header */ + ret = (2048 + 2); + } + } + break; + + case 0x01: /* DVD copyright information */ + buffer[4] = 0; /* No copyright data. */ + buffer[5] = 0; /* No region restrictions. */ + + /* 4 bytes of data + 2 byte header. */ + ret = (4 + 2); + break; + + case 0x04: /* DVD disc manufacturing information. */ + /* 2048 bytes of data + 2 byte header */ + ret = (2048 + 2); + break; + + case 0xff: + /* + * This lists all the command capabilities above. Add new ones + * in order and update the length and buffer return values. + */ + + buffer[4] = 0x00; /* Physical format */ + buffer[5] = 0x40; /* Not writable, is readable */ + buffer[6] = ((2048 + 4) >> 8) & 0xff; + buffer[7] = (2048 + 4) & 0xff; + + buffer[8] = 0x01; /* Copyright info */ + buffer[9] = 0x40; /* Not writable, is readable */ + buffer[10] = ((4 + 2) >> 8) & 0xff; + buffer[11] = (4 + 2) & 0xff; + + buffer[12] = 0x03; /* BCA info */ + buffer[13] = 0x40; /* Not writable, is readable */ + buffer[14] = ((188 + 2) >> 8) & 0xff; + buffer[15] = (188 + 2) & 0xff; + + buffer[16] = 0x04; /* Manufacturing info */ + buffer[17] = 0x40; /* Not writable, is readable */ + buffer[18] = ((2048 + 2) >> 8) & 0xff; + buffer[19] = (2048 + 2) & 0xff; + + /* data written + 4 byte header */ + ret = (16 + 2); + break; + + default: + *info = format; + ret = -(SENSE_ILLEGAL_REQUEST << 16) | (ASC_INV_FIELD_IN_CMD_PACKET << 8); + break; } - *len = cdrom_sector_size; + return ret; +} + +void +cdrom_read_disc_information(const cdrom_t *dev, uint8_t *buffer) +{ + uint8_t rti[65536] = { 0 }; + raw_track_info_t *t = (raw_track_info_t *) rti; + int num = 0; + int first = 0; + int sessions = 0; + int ls_first = 0; + int ls_last = 0; + int t_b0 = -1; + + dev->ops->get_raw_track_info(dev->local, &num, rti); + + for (int i = 0; i < num; i++) + if (t[i].session > sessions) + sessions = t[i].session; + else if ((first == 0) && (t[i].point >= 1) && (t[i].point <= 99)) + first = t[i].point; + + for (int i = 0; i < num; i++) + if ((t[i].session == sessions) && (t[i].point >= 1) && (t[i].point <= 99)) { + ls_first = t[i].point; + break; + } + + for (int i = (num - 1); i >= 0; i--) + if ((t[i].session == sessions) && (t[i].point >= 1) && (t[i].point <= 99)) { + ls_last = t[i].point; + break; + } + + for (int i = (num - 1); i >= 0; i--) + if (t[i].point == 0xb0) { + t_b0 = i; + break; + } + + memset(buffer, 0x00, 34); + + buffer[ 0] = 0x00; /* Disc Information Length (MSB) */ + buffer[ 1] = 0x20; /* Disc Information Lenght (LSB) */ + buffer[ 2] = 0x0e; /* Last session complete, disc finalized */ + buffer[ 3] = first; /* Number of First Track on Disc */ + buffer[ 4] = sessions; /* Number of Sessions (LSB) */ + buffer[ 5] = ls_first; /* First Track Number in Last Session (LSB) */ + buffer[ 5] = ls_last; /* Last Track Number in Last Session (LSB) */ + buffer[ 7] = 0x20; /* Unrestricted use */ + buffer[ 8] = t[0].ps; /* Disc Type */ + buffer[ 9] = 0x00; /* Number Of Sessions (MSB) */ + buffer[10] = 0x00; /* First Track Number in Last Session (MSB) */ + buffer[11] = 0x00; /* Last Track Number in Last Session (MSB) */ + + if (t_b0 == -1) { + /* Single-session disc. */ + + /* Last Session Lead-in Start Time MSF is 00:00:00 */ + + /* Last Possible Start Time for Start of Lead-out */ + buffer[20] = t[2].pm; + buffer[21] = t[2].ps; + buffer[22] = t[2].pf; + } else { + /* Multi-session disc. */ + + /* Last Session Lead-in Start Time MSF */ + buffer[17] = t[t_b0].m; + buffer[18] = t[t_b0].s; + buffer[19] = t[t_b0].f; + + /* Last Possible Start Time for Start of Lead-out */ + buffer[20] = t[t_b0].pm; + buffer[21] = t[t_b0].ps; + buffer[22] = t[t_b0].pf; + } +} + +int +cdrom_read_track_information(cdrom_t *dev, const uint8_t *cdb, uint8_t *buffer) +{ + uint8_t rti[65536] = { 0 }; + const raw_track_info_t *t = (raw_track_info_t *) rti; + const raw_track_info_t *track = NULL; + const raw_track_info_t lead_in = { 0 }; + const uint32_t pos = (cdb[2] << 24) | (cdb[3] << 16) | + (cdb[4] << 8) | cdb[5]; + uint32_t real_pos = pos; + int num = 0; + int ret; + + dev->ops->get_raw_track_info(dev->local, &num, rti); + + switch (cdb[1] & 0x03) { + default: + ret = -cdb[1]; + break; + case 0x00: + if (num < 4) + ret = -pos; + else { + for (int i = 0; i < num; i++) { + const raw_track_info_t *ct = &(t[i]); + const uint32_t start = ((ct->pm * 60 * 75) + (ct->ps * 75) + + ct->pf) - 150; + if (pos > start) { + track = ct; + break; + } + } + + if (track == NULL) + ret = -cdb[1]; + else + ret = 36; + } + break; + case 0x01: + switch (pos) { + default: + /* + TODO: Does READ TRACK INFORMATION use track AAh + or the raw A0h, A1h, and A2h? + */ + if (pos == 0xaa) + real_pos = 0xa2; + + for (int i = 0; i < num; i++) { + const raw_track_info_t *ct = &(t[i]); + if (ct->point == real_pos) { + track = ct; + break; + } + } + + if (track == NULL) + ret = -pos; + else + ret = 36; + break; + case 0x00: + track = &lead_in; + ret = 36; + break; + case 0xff: + ret = -pos; + break; + } + break; + case 0x02: + for (int i = 0; i < num; i++) { + const raw_track_info_t *ct = &(t[i]); + if ((ct->session == pos) && (ct->point >= 1) && (ct->point <= 99)) { + track = ct; + break; + } + } + + if (track == NULL) + ret = -pos; + else + ret = 36; + break; + } + + if (ret == 36) { + uint32_t start = ((track->pm * 60 * 75) + (track->ps * 75) + + track->pf) - 150; + uint32_t len = 0x00000000; + uint8_t mode = 0xf; + + memset(buffer, 0, 36); + buffer[0] = 0x00; + buffer[1] = 0x22; + buffer[2] = track->point; /* Track number (LSB). */ + buffer[3] = track->session; /* Session number (LSB). */ + /* Not damaged, primary copy. */ + buffer[5] = track->adr_ctl & 0x04; + + if ((track->point >= 1) && (track->point >= 99)) { + for (int i = 0; i < num; i++) { + const raw_track_info_t *ct = &(t[i]); + const uint32_t ts = ((ct->pm * 60 * 75) + (ct->ps * 75) + + ct->pf) - 150; + if ((ts > start) && ((ct->point == 0xa2) || ((ct->point >= 1) && + (ct->point <= 99)))) { + len = ts - start; + break; + } + } + + if (track->adr_ctl & 0x04) { + ret = read_data(dev, start); + mode = dev->raw_buffer[dev->cur_buf][3]; + } + } else if (track->point != 0xa2) + start = 0x00000000; + + /* Not reserved track, not blank, not packet writing, not fixed packet. */ + buffer[ 6] = mode << 0; + /* Last recorded address not valid, next recordable address not valid. */ + buffer[ 7] = 0x00; + + buffer[ 8] = (start >> 24) & 0xff; + buffer[ 9] = (start >> 16) & 0xff; + buffer[10] = (start >> 8) & 0xff; + buffer[11] = start & 0xff; + + buffer[24] = (len >> 24) & 0xff; + buffer[25] = (len >> 16) & 0xff; + buffer[26] = (len >> 8) & 0xff; + buffer[27] = len & 0xff; + } + + return ret; +} + +uint8_t +cdrom_get_current_mode(cdrom_t *dev) +{ + if (dev->cached_sector == -1) + (void) read_data(dev, dev->seek_pos); + else + (void) read_data(dev, dev->cached_sector); + + return dev->raw_buffer[dev->cur_buf][3]; +} + +void +cdrom_set_empty(cdrom_t *dev) +{ + dev->cd_status = CD_STATUS_EMPTY; + dev->cached_sector = -1; +} + +void +cdrom_update_status(cdrom_t *dev) +{ + const int was_empty = (dev->cd_status == CD_STATUS_EMPTY); + + if (dev->ops->load != NULL) + dev->ops->load(dev->local); + + /* All good, reset state. */ + dev->seek_pos = 0; + dev->cd_buflen = 0; + + if (dev->ops->is_dvd(dev->local)) + dev->cd_status = CD_STATUS_DVD; + else + dev->cd_status = dev->ops->has_audio(dev->local) ? CD_STATUS_STOPPED : + CD_STATUS_DATA_ONLY; + + dev->cached_sector = -1; + dev->cdrom_capacity = dev->ops->get_last_block(dev->local); + + if (dev->cd_status != CD_STATUS_EMPTY) { + /* Signal media change to the emulated machine. */ + cdrom_insert(dev->id); + + /* The drive was previously empty, transition directly to UNIT ATTENTION. */ + if (was_empty) + cdrom_insert(dev->id); + } +} + +int +cdrom_load(cdrom_t *dev, const char *fn, const int skip_insert) +{ + const int was_empty = cdrom_is_empty(dev->id); + int ret = 0; + + /* Make sure to not STRCPY if the two are pointing + at the same place. */ + if (fn != dev->image_path) + strcpy(dev->image_path, fn); + + /* Open the target. */ + if ((strlen(dev->image_path) != 0) && + (strstr(dev->image_path, "ioctl://") == dev->image_path)) + dev->local = ioctl_open(dev, dev->image_path); + else + dev->local = image_open(dev, dev->image_path); + + dev->cached_sector = -1; + + if (dev->local == NULL) { + dev->ops = NULL; + dev->image_path[0] = 0; + + ret = 1; + } else { + /* All good, reset state. */ + dev->seek_pos = 0; + dev->cd_buflen = 0; + + if ((dev->ops->is_empty != NULL) && dev->ops->is_empty(dev->local)) + dev->cd_status = CD_STATUS_EMPTY; + else if (dev->ops->is_dvd(dev->local)) + dev->cd_status = CD_STATUS_DVD; + else + dev->cd_status = dev->ops->has_audio(dev->local) ? CD_STATUS_STOPPED : + CD_STATUS_DATA_ONLY; + + dev->cdrom_capacity = dev->ops->get_last_block(dev->local); + + cdrom_log(dev->log, "CD-ROM capacity: %i sectors (%" PRIi64 " bytes)\n", + dev->cdrom_capacity, ((uint64_t) dev->cdrom_capacity) << 11ULL); + } + +#ifdef ENABLE_CDROM_LOG + cdrom_toc_dump(dev); +#endif + + if (!skip_insert && (dev->cd_status != CD_STATUS_EMPTY)) { + /* Signal media change to the emulated machine. */ + cdrom_insert(dev->id); + + /* The drive was previously empty, transition directly to UNIT ATTENTION. */ + if (was_empty) + cdrom_insert(dev->id); + } return ret; } @@ -2024,65 +2940,50 @@ cdrom_global_init(void) { /* Clear the global data. */ memset(cdrom, 0x00, sizeof(cdrom)); + + for (uint8_t i = 0; i < CDROM_NUM; i++) + cdrom[i].cached_sector = -1; } -static void -cdrom_drive_reset(cdrom_t *dev) -{ - dev->priv = NULL; - dev->insert = NULL; - dev->close = NULL; - dev->get_volume = NULL; - dev->get_channel = NULL; -} - -#ifdef ENABLE_CDROM_LOG -static void -cdrom_toc_dump(cdrom_t *dev) -{ - uint8_t b[65536] = { 0 }; - int len = cdrom_read_toc(dev, b, CD_TOC_RAW, 0, 0, 65536); - const char *fn2 = "d:\\86boxnew\\toc_cue.dmp"; - FILE * f = fopen(fn2, "wb"); - fwrite(b, 1, len, f); - fflush(f); - fclose(f); - pclog("Written TOC of %i bytes to %s\n", len, fn2); - - memset(b, 0x00, 65536); - len = cdrom_read_toc(dev, b, CD_TOC_NORMAL, 0, 0, 65536); - fn2 = "d:\\86boxnew\\toc_cue_cooked.dmp"; - f = fopen(fn2, "wb"); - fwrite(b, 1, len, f); - fflush(f); - fclose(f); - pclog("Written cooked TOC of %i bytes to %s\n", len, fn2); - - memset(b, 0x00, 65536); - len = cdrom_read_toc(dev, b, CD_TOC_SESSION, 0, 0, 65536); - fn2 = "d:\\86boxnew\\toc_cue_session.dmp"; - f = fopen(fn2, "wb"); - fwrite(b, 1, len, f); - fflush(f); - fclose(f); - pclog("Written session TOC of %i bytes to %s\n", len, fn2); -} -#endif - void cdrom_hard_reset(void) { - cdrom_t *dev; + cdrom_assigned_letters = 0; 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); + cdrom_t *dev = &cdrom[i]; - dev->id = i; + if (dev->bus_type) { + dev->id = i; + + const char *vendor = cdrom_drive_types[dev->type].vendor; + + dev->is_early = cdrom_is_early(dev->type); + dev->is_bcd = !strcmp(vendor, "NEC"); + dev->is_nec = (dev->bus_type == CDROM_BUS_SCSI) && + !strcmp(vendor, "NEC"); + dev->is_chinon = !strcmp(vendor, "CHINON"); + dev->is_pioneer = !strcmp(vendor, "PIONEER"); + dev->is_plextor = !strcmp(vendor, "PLEXTOR"); + dev->is_sony = (dev->bus_type == CDROM_BUS_SCSI) && + (!strcmp(vendor, "DEC") || + !strcmp(vendor, "ShinaKen") || + !strcmp(vendor, "SONY") || + !strcmp(vendor, "TEXEL")); + dev->is_toshiba = !strcmp(vendor, "TOSHIBA"); + + dev->c2_first = !strcmp(vendor, "NEC") || + !strcmp(vendor, "PLEXTOR"); cdrom_drive_reset(dev); + char n[1024] = { 0 }; + + sprintf(n, "CD-ROM %i ", i + 1); + dev->log = log_open(n); + + cdrom_log(dev->log, "Hard reset\n"); + switch (dev->bus_type) { case CDROM_BUS_ATAPI: case CDROM_BUS_SCSI: @@ -2093,7 +2994,10 @@ cdrom_hard_reset(void) break; } - dev->cd_status = CD_STATUS_EMPTY; + dev->cd_status = CD_STATUS_EMPTY; + dev->host_letter = 0xff; + + dev->cached_sector = -1; if (strlen(dev->image_path) > 0) { #ifdef _WIN32 @@ -2105,18 +3009,7 @@ cdrom_hard_reset(void) dev->image_path[strlen(dev->image_path) - 1] = '/'; #endif - if ((strlen(dev->image_path) != 0) && (strstr(dev->image_path, "ioctl://") == dev->image_path)) - cdrom_ioctl_open(dev, dev->image_path); - else - cdrom_image_open(dev, dev->image_path); - - cdrom_insert(i); - cdrom_insert(i); - -#ifdef ENABLE_CDROM_LOG - if (i == 0) - cdrom_toc_dump(dev); -#endif + cdrom_load(dev, dev->image_path, 0); } } } @@ -2127,10 +3020,8 @@ cdrom_hard_reset(void) void cdrom_close(void) { - cdrom_t *dev; - for (uint8_t i = 0; i < CDROM_NUM; i++) { - dev = &cdrom[i]; + cdrom_t *dev = &cdrom[i]; if (dev->bus_type == CDROM_BUS_SCSI) memset(&scsi_devices[dev->scsi_device_id], 0x00, sizeof(scsi_device_t)); @@ -2138,54 +3029,61 @@ cdrom_close(void) if (dev->close) dev->close(dev->priv); - if (dev->ops && dev->ops->exit) - dev->ops->exit(dev); + cdrom_unload(dev); dev->ops = NULL; dev->priv = NULL; cdrom_drive_reset(dev); + + if (dev->log != NULL) { + cdrom_log(dev->log, "Log closed\n"); + + log_close(dev->log); + dev->log = NULL; + } } } /* Signal disc change to the emulated machine. */ void -cdrom_insert(uint8_t id) +cdrom_insert(const uint8_t id) { - cdrom_t *dev = &cdrom[id]; + const cdrom_t *dev = &cdrom[id]; if (dev->bus_type && dev->insert) dev->insert(dev->priv); } void -cdrom_exit(uint8_t id) +cdrom_exit(const uint8_t id) { cdrom_t *dev = &cdrom[id]; strcpy(dev->prev_image_path, dev->image_path); + dev->cached_sector = -1; + if (dev->ops) { - if (dev->ops->exit) - dev->ops->exit(dev); + cdrom_unload(dev); dev->ops = NULL; } memset(dev->image_path, 0, sizeof(dev->image_path)); - cdrom_log("cdrom_exit(%i): cdrom_insert(%i)\n", id, id); + cdrom_log(dev->log, "cdrom_exit(): cdrom_insert()\n"); cdrom_insert(id); } int -cdrom_is_empty(uint8_t id) +cdrom_is_empty(const uint8_t id) { - cdrom_t *dev = &cdrom[id]; - int ret = 0; + const cdrom_t *dev = &cdrom[id]; + int ret = 0; /* This entire block should be in cdrom.c/cdrom_eject(dev*) ... */ - if (strlen(dev->image_path) == 0) + if ((strlen(dev->image_path) == 0) || (dev->cd_status == CD_STATUS_EMPTY)) /* Switch from empty to empty. Do nothing. */ ret = 1; @@ -2194,36 +3092,34 @@ cdrom_is_empty(uint8_t id) /* The mechanics of ejecting a CD-ROM from a drive. */ void -cdrom_eject(uint8_t id) +cdrom_eject(const uint8_t id) { - cdrom_t *dev = &cdrom[id]; + const cdrom_t *dev = &cdrom[id]; - /* This entire block should be in cdrom.c/cdrom_eject(dev*) ... */ - if (strlen(dev->image_path) == 0) - /* Switch from empty to empty. Do nothing. */ - return; + if (strlen(dev->image_path) != 0) { + cdrom_exit(id); - cdrom_exit(id); + plat_cdrom_ui_update(id, 0); - plat_cdrom_ui_update(id, 0); - - config_save(); + config_save(); + } } /* The mechanics of re-loading a CD-ROM drive. */ void -cdrom_reload(uint8_t id) +cdrom_reload(const uint8_t id) { - cdrom_t *dev = &cdrom[id]; - int was_empty = cdrom_is_empty(id); + cdrom_t *dev = &cdrom[id]; - if ((strcmp(dev->image_path, dev->prev_image_path) == 0) || (strlen(dev->prev_image_path) == 0) || (strlen(dev->image_path) > 0)) { + if ((strcmp(dev->image_path, dev->prev_image_path) == 0) || + (strlen(dev->prev_image_path) == 0) || + (strlen(dev->image_path) > 0)) { /* Switch from empty to empty. Do nothing. */ return; } - if (dev->ops && dev->ops->exit) - dev->ops->exit(dev); + cdrom_unload(dev); + dev->ops = NULL; memset(dev->image_path, 0, sizeof(dev->image_path)); @@ -2242,22 +3138,7 @@ cdrom_reload(uint8_t id) dev->image_path[strlen(dev->image_path) - 1] = '/'; #endif - if ((strlen(dev->image_path) != 0) && (strstr(dev->image_path, "ioctl://") == dev->image_path)) - cdrom_ioctl_open(dev, dev->image_path); - else - cdrom_image_open(dev, dev->image_path); - -#ifdef ENABLE_CDROM_LOG - cdrom_toc_dump(dev); -#endif - - /* Signal media change to the emulated machine. */ - cdrom_log("cdrom_reload(%i): cdrom_insert(%i)\n", id, id); - cdrom_insert(id); - - /* The drive was previously empty, transition directly to UNIT ATTENTION. */ - if (was_empty) - cdrom_insert(id); + cdrom_load(dev, dev->image_path, 0); } plat_cdrom_ui_update(id, 1); diff --git a/src/cdrom/cdrom_image.c b/src/cdrom/cdrom_image.c index 0c7870902..6bc284fd3 100644 --- a/src/cdrom/cdrom_image.c +++ b/src/cdrom/cdrom_image.c @@ -6,63 +6,1705 @@ * * This file is part of the 86Box distribution. * - * CD-ROM image support. + * CD-ROM image file handling module. * + * Authors: Miran Grca, + * RichardG, + * Cacodemon345 * - * - * Authors: RichardG867, - * Miran Grca, - * bit, - * - * Copyright 2015-2019 Richardg867. - * Copyright 2015-2019 Miran Grca. - * Copyright 2017-2019 bit. + * Copyright 2016-2025 Miran Grca. + * Copyright 2016-2025 RichardG. + * Copyright 2024-2025 Cacodemon345. */ +#define __STDC_FORMAT_MACROS +#include #include +#ifdef ENABLE_IMAGE_LOG #include -#include +#endif #include -#include +#include #include -#include -#define HAVE_STDARG_H +#include +#include +#ifndef _WIN32 +# include +#endif #include <86box/86box.h> -#include <86box/config.h> +#include <86box/log.h> #include <86box/path.h> #include <86box/plat.h> -#include <86box/scsi_device.h> -#include <86box/cdrom_image_backend.h> #include <86box/cdrom.h> #include <86box/cdrom_image.h> +#include <86box/cdrom_image_viso.h> -#ifdef ENABLE_CDROM_IMAGE_LOG -int cdrom_image_do_log = ENABLE_CDROM_IMAGE_LOG; +#include + +#define MAX_LINE_LENGTH 512 +#define MAX_FILENAME_LENGTH 256 +#define CROSS_LEN 512 + +static char temp_keyword[1024]; + +#define INDEX_SPECIAL -2 /* Track A0h onwards. */ +#define INDEX_NONE -1 /* Empty block. */ +#define INDEX_ZERO 0 /* Block not in the file, return all 0x00's. */ +#define INDEX_NORMAL 1 /* Block in the file. */ + +typedef struct track_index_t { + /* + Is the current block in the file? If not, return all 0x00's. -1 means not + yet loaded. + */ + int32_t type; + /* The amount of bytes to skip at the beginning of each sector. */ + int32_t skip; + /* + Starting and ending sector LBA - negative in order to accomodate LBA -150 to -1 + to read the pregap of track 1. + */ + uint64_t start; + uint64_t length; + uint64_t file_start; + uint64_t file_length; + track_file_t *file; +} track_index_t; + +typedef struct track_t { + uint8_t session; + uint8_t attr; + uint8_t tno; + uint8_t point; + uint8_t extra[4]; + uint8_t mode; + uint8_t form; + uint8_t subch_type; + uint8_t skip; + uint32_t sector_size; + track_index_t idx[3]; +} track_t; + +typedef struct cd_image_t { + cdrom_t *dev; + void *log; + int is_dvd; + int has_audio; + int32_t tracks_num; + uint32_t bad_sectors_num; + track_t *tracks; + uint32_t *bad_sectors; +} cd_image_t; + +#ifdef ENABLE_IMAGE_LOG +int image_do_log = ENABLE_IMAGE_LOG; void -cdrom_image_log(const char *fmt, ...) +image_log(void *priv, const char *fmt, ...) { va_list ap; - if (cdrom_image_do_log) { + if (image_do_log) { va_start(ap, fmt); - pclog_ex(fmt, ap); + log_out(priv, fmt, ap); va_end(ap); } } + +static char *cit[4] = { "SPECIAL", "NONE", "ZERO", "NORMAL" }; #else -# define cdrom_image_log(fmt, ...) +# define image_log(priv, fmt, ...) #endif -/* 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. */ -#define MSFtoLBA(m, s, f) ((((m * 60) + s) * 75) + f) +typedef struct audio_file_t { + SNDFILE *file; + SF_INFO info; +} audio_file_t; + +/* Audio file functions */ +static int +audio_read(void *priv, uint8_t *buffer, const uint64_t seek, const size_t count) +{ + const track_file_t *tf = (track_file_t *) priv; + const audio_file_t *audio = (audio_file_t *) tf->priv; + const uint64_t samples_seek = seek / 4; + const uint64_t samples_count = count / 4; + + if ((seek & 3) || (count & 3)) { + image_log(tf->log, "CD Audio file: Reading on non-4-aligned boundaries.\n"); + } + + const sf_count_t res = sf_seek(audio->file, samples_seek, SEEK_SET); + + if (res == -1) + return 0; + + return !!sf_readf_short(audio->file, (short *) buffer, samples_count); +} + +static uint64_t +audio_get_length(void *priv) +{ + const track_file_t *tf = (track_file_t *) priv; + const audio_file_t *audio = (audio_file_t *) tf->priv; + + /* Assume 16-bit audio, 2 channel. */ + return audio->info.frames * 4ull; +} static void -image_get_track_info(cdrom_t *dev, uint32_t track, int end, track_info_t *ti) +audio_close(void *priv) { - cd_img_t *img = (cd_img_t *) dev->local; - track_t *ct = NULL; + track_file_t *tf = (track_file_t *) priv; + audio_file_t *audio = (audio_file_t *) tf->priv; + + memset(tf->fn, 0x00, sizeof(tf->fn)); + if (audio && audio->file) + sf_close(audio->file); + free(audio); + free(tf); +} + +static track_file_t * +audio_init(const uint8_t id, const char *filename, int *error) +{ + track_file_t *tf = (track_file_t *) calloc(sizeof(track_file_t), 1); + audio_file_t *audio = (audio_file_t *) calloc(sizeof(audio_file_t), 1); +#ifdef _WIN32 + wchar_t filename_w[4096]; +#endif + + if (tf == NULL || audio == NULL) { + goto cleanup_error; + } + + memset(tf->fn, 0x00, sizeof(tf->fn)); + strncpy(tf->fn, filename, sizeof(tf->fn) - 1); +#ifdef _WIN32 + mbstowcs(filename_w, filename, 4096); + audio->file = sf_wchar_open(filename_w, SFM_READ, &audio->info); +#else + audio->file = sf_open(filename, SFM_READ, &audio->info); +#endif + + if (audio->file == NULL) { + image_log(tf->log, "Audio file open error!"); + goto cleanup_error; + } + + if (audio->info.channels != 2 || audio->info.samplerate != 44100 || !audio->info.seekable) { + image_log(tf->log, "Audio file not seekable or in non-CD format!"); + sf_close(audio->file); + goto cleanup_error; + } + + *error = 0; + + tf->priv = audio; + tf->fp = NULL; + tf->close = audio_close; + tf->get_length = audio_get_length; + tf->read = audio_read; + + char n[1024] = { 0 }; + + sprintf(n, "CD-ROM %i Audio", id + 1); + tf->log = log_open(n); + + return tf; +cleanup_error: + free(tf); + free(audio); + *error = 1; + return NULL; +} + +/* Binary file functions. */ +static int +bin_read(void *priv, uint8_t *buffer, const uint64_t seek, const size_t count) +{ + const track_file_t *tf = (track_file_t *) priv; + + if (tf->fp == NULL) + return 0; + + image_log(tf->log, "binary_read(%08lx, pos=%" PRIu64 " count=%lu)\n", + tf->fp, seek, count); + + if (fseeko64(tf->fp, seek, SEEK_SET) == -1) { + image_log(tf->log, "binary_read failed during seek!\n"); + + return -1; + } + + if (fread(buffer, count, 1, tf->fp) != 1) { + image_log(tf->log, "binary_read failed during read!\n"); + + return -1; + } + + if (UNLIKELY(tf->motorola)) { + for (uint64_t i = 0; i < count; i += 2) { + const uint8_t buffer0 = buffer[i]; + const uint8_t buffer1 = buffer[i + 1]; + buffer[i] = buffer1; + buffer[i + 1] = buffer0; + } + } + + return 1; +} + +static uint64_t +bin_get_length(void *priv) +{ + const track_file_t *tf = (track_file_t *) priv; + + if (tf->fp == NULL) + return 0; + + fseeko64(tf->fp, 0, SEEK_END); + const off64_t len = ftello64(tf->fp); + image_log(tf->log, "binary_length(%08lx) = %" PRIu64 "\n", tf->fp, len); + + return len; +} + +static void +bin_close(void *priv) +{ + track_file_t *tf = (track_file_t *) priv; + + if (tf == NULL) + return; + + if (tf->fp != NULL) { + fclose(tf->fp); + tf->fp = NULL; + } + + memset(tf->fn, 0x00, sizeof(tf->fn)); + + free(priv); +} + +static track_file_t * +bin_init(const uint8_t id, const char *filename, int *error) +{ + track_file_t *tf = (track_file_t *) calloc(1, sizeof(track_file_t)); + struct stat stats; + + if (tf == NULL) { + *error = 1; + return NULL; + } + + memset(tf->fn, 0x00, sizeof(tf->fn)); + strncpy(tf->fn, filename, sizeof(tf->fn) - 1); + tf->fp = plat_fopen64(tf->fn, "rb"); + image_log(tf->log, "binary_open(%s) = %08lx\n", tf->fn, tf->fp); + + if (stat(tf->fn, &stats) != 0) { + /* Use a blank structure if stat failed. */ + memset(&stats, 0, sizeof(struct stat)); + } + *error = ((tf->fp == NULL) || ((stats.st_mode & S_IFMT) == S_IFDIR)); + + /* Set the function pointers. */ + if (!*error) { + tf->read = bin_read; + tf->get_length = bin_get_length; + tf->close = bin_close; + + char n[1024] = { 0 }; + + sprintf(n, "CD-ROM %i Bin ", id + 1); + tf->log = log_open(n); + } else { + /* 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->fp != NULL) && ((stats.st_mode & S_IFMT) == S_IFDIR)) { + /* tf is freed by bin_close */ + bin_close(tf); + } else + free(tf); + tf = NULL; + } + + return tf; +} + +static track_file_t * +index_file_init(const uint8_t id, const char *filename, int *error, int *is_viso) +{ + track_file_t *tf = NULL; + + *is_viso = 0; + + /* Current we only support .BIN files, either combined or one per + track. In the future, more is planned. */ + tf = bin_init(id, filename, error); + + if (*error) { + if ((tf != NULL) && (tf->close != NULL)) { + tf->close(tf); + tf = NULL; + } + + tf = viso_init(id, filename, error); + + if (!*error) + *is_viso = 1; + } + + return tf; +} + +static void +index_file_close(track_index_t *idx) +{ + if ((idx == NULL) || (idx->file == NULL)) + return; + + image_log(idx->file->log, "Log closed\n"); + + if (idx->file->log != NULL) { + log_close(idx->file->log); + idx->file->log = NULL; + } + + if (idx->file->close != NULL) + idx->file->close(idx->file); + + idx->file = NULL; +} + +/* Internal functions. */ +static int +image_get_track(const cd_image_t *img, const uint32_t sector) +{ + int ret = -1; + + for (int i = 0; i < img->tracks_num; i++) { + track_t *ct = &(img->tracks[i]); + for (int j = 0; j < 3; j++) { + const track_index_t *ci = &(ct->idx[j]); + if ((ci->type >= INDEX_ZERO) && (ci->length != 0ULL) && + ((sector + 150) >= ci->start) && ((sector + 150) <= (ci->start + ci->length - 1))) { + ret = i; + break; + } + } + } + + return ret; +} + +static void +image_get_track_and_index(const cd_image_t *img, const uint32_t sector, + int *track, int *index) +{ + *track = -1; + *index = -1; + + for (int i = 0; i < img->tracks_num; i++) { + track_t *ct = &(img->tracks[i]); + if ((ct->point >= 1) && (ct->point <= 99)) for (int j = 0; j < 3; j++) { + track_index_t *ci = &(ct->idx[j]); + if ((ci->type >= INDEX_ZERO) && (ci->length != 0ULL) && + ((sector + 150) >= ci->start) && ((sector + 150) <= (ci->start + ci->length - 1))) { + *track = i; + *index = j; + break; + } + } + } +} + +static int +image_is_sector_bad(const cd_image_t *img, const uint32_t sector) +{ + int ret = 0; + + if (img->bad_sectors_num > 0) for (int i = 0; i < img->bad_sectors_num; i++) + if (img->bad_sectors[i] == sector) { + ret = 1; + break; + } + + return ret; +} + +static int +image_is_track_audio(const cd_image_t *img, const uint32_t pos) +{ + int ret = 0; + + if (img->has_audio) { + const int track = image_get_track(img, pos); + + if (track >= 0) { + const track_t *trk = &(img->tracks[track]); + + ret = (trk->mode == 0); + } + } + + return ret; +} + +static int +image_can_read_pvd(track_file_t *file, const uint64_t start, + const uint64_t sector_size, const int xa) +{ + uint8_t buf[2448] = { 0 }; + /* First VD is located at sector 16. */ + uint64_t seek = start + (16ULL * sector_size); + uint8_t *pvd = (uint8_t *) buf; + + if (sector_size >= RAW_SECTOR_SIZE) { + if (xa) + pvd = &(buf[24]); + else + pvd = &(buf[16]); + } else if (sector_size >= 2332) { + if (xa) + pvd = &(buf[8]); + } + + file->read(file, buf, seek, sector_size); + + int ret = (((pvd[0] == 1) && + !strncmp((char *) &(pvd[1]), "CD001", 5) && + (pvd[6] == 1)) || + ((pvd[8] == 1) && + !strncmp((char *) &(pvd[9]), "CDROM", 5) && + (pvd[14] == 1))); + + if (ret) { + if (sector_size >= RAW_SECTOR_SIZE) { + if (xa) + /* Mode 2 XA, Form from the sub-header. */ + ret = 0x20 | (((buf[18] & 0x20) >> 5) + 1); + else + /* Mode from header. */ + ret = buf[15] << 4; + } else if (sector_size >= 2332) { + if (xa) + /* Mode 2 XA, Form from the sub-header. */ + ret = 0x20 | (((buf[2] & 0x20) >> 5) + 1); + else + /* Mode 2 non-XA. */ + ret = 0x20; + } else if (sector_size >= 2324) + /* Mode 2 XA Form 2. */ + ret = 0x22; + else if (!strncmp((char *) &(pvd[0x400]), "CD-XA001", 8)) + /* Mode 2 XA Form 1. */ + ret = 0x21; + else + /* Mode 1. */ + ret = 0x10; + } + + return ret; +} + +static int +image_cue_get_buffer(char *str, char **line, const int up) +{ + char *s = *line; + char *p = str; + int quote = 0; + int done = 0; + int space = 1; + + /* Copy to local buffer until we have end of string or whitespace. */ + while (!done) { + switch (*s) { + case '\0': + if (quote) { + /* Ouch, unterminated string.. */ + return 0; + } + done = 1; + break; + + case '\"': + quote ^= 1; + break; + + case ' ': + case '\t': + if (space) + break; + + if (!quote) { + done = 1; + break; + } + fallthrough; + + default: + if (up && islower((int) *s)) + *p++ = toupper((int) *s); + else + *p++ = *s; + space = 0; + break; + } + + if (!done) + s++; + } + *p = '\0'; + + *line = s; + + return 1; +} + +static int +image_cue_get_keyword(char **dest, char **line) +{ + const int success = image_cue_get_buffer(temp_keyword, line, 1); + + if (success) + *dest = temp_keyword; + + return success; +} + +/* Get a string from the input line, handling quotes properly. */ +static uint64_t +image_cue_get_number(char **line) +{ + char temp[128]; + uint64_t num; + + if (!image_cue_get_buffer(temp, line, 0)) + return 0; + + if (sscanf(temp, "%" PRIu64, &num) != 1) + return 0; + + return num; +} + +static int +image_cue_get_frame(uint64_t *frames, char **line) +{ + char temp[128]; + int min = 0; + int sec = 0; + int fr = 0; + + int success = image_cue_get_buffer(temp, line, 0); + if (!success) + return 0; + + success = sscanf(temp, "%d:%d:%d", &min, &sec, &fr) == 3; + if (!success) + return 0; + + *frames = MSF_TO_FRAMES(min, sec, fr); + + return 1; +} + +static int +image_cue_get_flags(track_t *cur, char **line) +{ + char temp[128]; + char temp2[128]; + + int success = image_cue_get_buffer(temp, line, 0); + if (!success) + return 0; + + memset(temp2, 0x00, sizeof(temp2)); + success = sscanf(temp, "%s", temp2) == 1; + if (!success) + return 0; + + if (strstr(temp2, "PRE") != NULL) + cur->attr |= 0x01; + if (strstr(temp2, "DCP") != NULL) + cur->attr |= 0x02; + if (strstr(temp2, "4CH") != NULL) + cur->attr |= 0x08; + + return 1; +} + +static track_t * +image_insert_track(cd_image_t *img, const uint8_t session, const uint8_t point) +{ + track_t *ct = NULL; + + img->tracks_num++; + if (img->tracks == NULL) { + img->tracks = calloc(1, sizeof(track_t)); + ct = &(img->tracks[0]); + } else { + img->tracks = realloc(img->tracks, img->tracks_num * sizeof(track_t)); + ct = &(img->tracks[img->tracks_num - 1]); + } + + image_log(img->log, " [TRACK ] Insert %02X: img->tracks[%2i]\n", + point, img->tracks_num - 1); + + memset(ct, 0x00, sizeof(track_t)); + + ct->session = session; + ct->point = point; + + for (int i = 0; i < 3; i++) + ct->idx[i].type = (point > 99) ? INDEX_SPECIAL : INDEX_NONE; + + if (point >= 0xb0) + ct->attr = 0x50; + + return ct; +} + +static void +image_process(cd_image_t *img) +{ + track_t *ct = NULL; + track_t *lt = NULL; + track_index_t *ci = NULL; + track_file_t *tf = NULL; + uint64_t tf_len = 0ULL; + uint64_t cur_pos = 0ULL; + int pos = 0; + int ls = 0; + int map[256] = { 0 }; + int lead[3] = { 0 }; + uint64_t spg[256] = { 0ULL }; + track_t *lo[256] = { 0 }; + + /* + Pass 2 - adjusting pre-gaps of the first track of every session and creating the + map so we can map from <01-99> to <01-99> + so that their times and length can be adjusted correctly in the third and fourth + passes - especially important for multi-session Cue files. + + We have to do that because Cue sheets do not explicitly indicate those pre-gaps + but they are required so we have the correct frames - the first track of each + session always has a pre-gap of at least 0:02:00. We do not adjust it if it is + already present. + */ + image_log(img->log, "Pass 2 (adjusting pre-gaps and preparing map)...\n"); + + /* Pre-gap of the first track of the first session. */ + ct = &(img->tracks[3]); + ci = &(ct->idx[0]); + + if (ci->type == INDEX_NONE) { + ci->type = INDEX_ZERO; + ci->start = 0ULL; + ci->length = 150ULL; + } + + image_log(img->log, " [PREGAP ] Adjusted pre-gap of track %02X (first in " + "session %i)\n", ct->point, ct->session); + + /* The other pre-gaps and the preparation of the map. */ + for (int i = 0; i < img->tracks_num; i++) { + ct = &(img->tracks[i]); + if (((ct->point >= 1) && (ct->point <= 99)) || (ct->point >= 0xb0)) { + if (ct->point == 0xb0) { + /* The first track of a session always has a pre-gap of at least 0:02:00. */ + track_t *ft = &(img->tracks[i + (ct->session == 1) + 4]); + ci = &(ft->idx[0]); + + if (ci->type == INDEX_NONE) { + if (ft->idx[1].type == INDEX_NORMAL) { + ci->type = INDEX_NORMAL; + ci->file_start = ft->idx[1].file_start - 150ULL; + } else { + ci->type = INDEX_ZERO; + ci->start = 0ULL; + ci->length = 150ULL; + } + } + + image_log(img->log, " [PREGAP ] Adjusted pre-gap of track %02X " + "(first in session %i)\n", ft->point, ct->session); + + /* Point B0h found, add the previous three lead tracks. */ + for (int j = 0; j < 3; j++) { + map[pos] = lead[j]; + image_log(img->log, " [REMAP ] Remap %3i to %3i (%02X)\n", pos, + map[pos], 0xa0 + j); + pos++; + } + } + + /* Add the current track. */ + map[pos] = i; + image_log(img->log, " [NORMAL ] Remap %3i to %3i\n", pos, map[pos]); + pos++; + } else if ((ct->point >= 0xa0) && (ct->point <= 0xa2)) { + /* + Collect lead track (A0 = first track in session, A1 = last track in session, + A2 = lead out). + */ + lead[ct->point & 0x03] = i; + + image_log(img->log, " [LEAD ] Lead %i = %3i (%02X)\n", ct->point & 0x03, i, + ct->point); + } + } + + /* Add the last three lead tracks. */ + for (int i = 0; i < 3; i++) { + map[pos] = lead[i]; + image_log(img->log, " [REMAP ] Remap %3i to %3i (%02X)\n", pos, map[pos], + 0xa0 + i); + pos++; + } + + /* + If these two mismatch, it is a fatal condition since it means something + has gone wrong enough that the Cue sheet processing has been messed up. + */ + if (pos != img->tracks_num) + log_fatal(img->log, "Something has gone wrong and we have remappped %3i tracks " + "instead of the expected %3i\n", pos, img->tracks_num); + + /* + Pass 3 - adjusting the time lengths of each index of track according to the + files. + + We have to do that because Cue sheets do not explicitly indicate the lengths + of track, so we have to deduce them from what the combination of the Cue sheet + and the various files give us. + */ + image_log(img->log, "Pass 3 (adjusting track file lengths according to the files)...\n"); + for (int i = (img->tracks_num - 1); i >= 0; i--) { + ct = &(img->tracks[map[i]]); + if (ct->idx[1].type != INDEX_SPECIAL) { + for (int j = 2; j >= 0; j--) { + ci = &(ct->idx[j]); + + /* + If the file is not NULL and is different from the previous file, + open it and read its length. + */ + if ((ci->file != NULL) && (ci->file != tf)) { + tf = ci->file; + if (tf != NULL) { + tf_len = tf->get_length(tf) / ct->sector_size; + image_log(img->log, " [FILE ] File length: %016" + PRIX64 " sectors\n", tf_len); + } + } + + if ((ci->type < INDEX_SPECIAL) || (ci->type > INDEX_NORMAL)) { + image_log(img->log, " [TRACK ] %02X, INDEX %02X, ATTR %02X,\n", + ci->type, j, + ct->attr); + log_fatal(img->log, " Unrecognized index type during " + "Pass 3: %2i\n", + ci->type); + } else if (ci->type == INDEX_NORMAL) { + /* Index was in the cue sheet and is present in the file. */ + ci->file_length = tf_len - ci->file_start; + tf_len -= ci->file_length; + } else { + /* Index was not in the cue sheet or is not present in the file, + keep its length at zero. */ + ci->file_start = tf_len; + } + + image_log(img->log, " [TRACK ] %02X/%02X, INDEX %02X, ATTR %02X, " + "MODE %02X/%02X, %8s,\n", + ct->session, + ct->point, j, + ct->attr, + ct->mode, ct->form, + cit[ci->type + 2]); + image_log(img->log, " file_start = %016" + PRIX64 " (%2i:%02i:%02i),\n", + ci->file_start, + (int) ((ci->file_start / 75) / 60), + (int) ((ci->file_start / 75) % 60), + (int) (ci->file_start % 75)); + image_log(img->log, " file_length = %016" + PRIX64 " (%2i:%02i:%02i),\n", + ci->file_length, + (int) ((ci->file_length / 75) / 60), + (int) ((ci->file_length / 75) % 60), + (int) (ci->file_length % 75)); + image_log(img->log, " remaining = %016" + PRIX64 " (%2i:%02i:%02i)\n", + tf_len, + (int) ((tf_len / 75) / 60), + (int) ((tf_len / 75) % 60), + (int) (tf_len % 75)); + } + } + } + + /* + Pass 4 - calculating the actual track starts and lengths for the TOC. + */ + image_log(img->log, "Pass 4 (calculating the actual track starts " + "and lengths for the TOC)...\n"); + for (int i = 0; i < img->tracks_num; i++) { + ct = &(img->tracks[map[i]]); + if (ct->idx[1].type != INDEX_SPECIAL) { + int session_changed = 0; + + /* + If the session has changed, store the last session + and mark that it has changed. + */ + if (ct->session != ls) { + ls = ct->session; + session_changed = 1; + } + + for (int j = 0; j < 3; j++) { + ci = &(ct->idx[j]); + + if ((ci->type < INDEX_SPECIAL) || (ci->type > INDEX_NORMAL)) { + image_log(img->log, " [TRACK ] %02X, INDEX %02X, ATTR %02X,\n", + ci->type, j, + ct->attr); + log_fatal(img->log, " Unrecognized index type during " + "Pass 4: %2i\n", + ci->type); + } else if (ci->type <= INDEX_NONE) + /* Index was not in the cue sheet, keep its length at zero. */ + ci->start = cur_pos; + else if (ci->type == INDEX_ZERO) { + /* Index was in the cue sheet and is not present in the file. */ + ci->start = cur_pos; + cur_pos += ci->length; + } else if (ci->type == INDEX_NORMAL) { + /* Index was in the cue sheet and is present in the file. */ + ci->start = cur_pos; + ci->length = ci->file_length; + cur_pos += ci->file_length; + } + + image_log(img->log, " [TRACK ] %02X/%02X, INDEX %02X, ATTR %02X, " + "MODE %02X/%02X, %8s,\n", + ct->session, + ct->point, j, + ct->attr, + ct->mode, ct->form, + cit[ci->type + 2]); + image_log(img->log, " start = %016" + PRIX64 " (%2i:%02i:%02i),\n", + ci->start, + (int) ((ci->start / 75) / 60), + (int) ((ci->start / 75) % 60), + (int) (ci->start % 75)); + image_log(img->log, " length = %016" + PRIX64 " (%2i:%02i:%02i),\n", + ci->length, + (int) ((ci->length / 75) / 60), + (int) ((ci->length / 75) % 60), + (int) (ci->length % 75)); + image_log(img->log, " cur_pos = %016" + PRIX64 " (%2i:%02i:%02i)\n", + cur_pos, + (int) ((cur_pos / 75) / 60), + (int) ((cur_pos / 75) % 60), + (int) (cur_pos % 75)); + + /* Set the pre-gap of the first track of this session. */ + if (session_changed) + spg[ct->session] = ct->idx[0].start; + } + } + } + + /* + Pass 5 - setting the lead out starts for all sessions. + */ + image_log(img->log, "Pass 5 (setting the lead out starts for all sessions)...\n"); + for (int i = 0; i <= ls; i++) { + lo[i] = NULL; + for (int j = (img->tracks_num - 1); j >= 0; j--) { + const track_t *jt = &(img->tracks[j]); + if ((jt->session == i) && (jt->point >= 1) && (jt->point <= 99)) { + lo[i] = &(img->tracks[j]); + image_log(img->log, " [TRACK ] %02X/%02X, INDEX %02X, ATTR %02X, " + "MODE %02X/%02X, %8s,\n", + ct->session, + ct->point, j, + ct->attr, + ct->mode, ct->form, + cit[ci->type + 2]); + image_log(img->log, " using to calculate the start of session " + "%02X lead out\n", + ct->session); + break; + } + } + } + + /* + Pass 6 - refinining modes and forms, and finalizing all the special tracks. + */ + image_log(img->log, "Pass 6 (refinining modes and forms, and finalizing " + "all the special tracks)...\n"); + for (int i = 0; i < img->tracks_num; i++) { + ct = &(img->tracks[i]); + lt = NULL; + switch (ct->point) { + default: + break; + case 1 ... 99: + ci = &(ct->idx[1]); + + if ((ci->type == INDEX_NORMAL) && (ct->mode >= 1)) { + image_log(img->log, " [TRACK ] %02X/01, INDEX %02X, ATTR %02X, " + "MODE %02X/%02X, %8s,\n", + ct->session, + ct->point, + ct->attr, + ct->mode, ct->form, + cit[ct->idx[1].type + 2]); + + /* Override the loaded modes with that we determine here. */ + int can_read_pvd = image_can_read_pvd(ci->file, + ci->file_start * ct->sector_size, + ct->sector_size, 0); + ct->skip = 0; + if (can_read_pvd) { + ct->mode = can_read_pvd >> 4; + ct->form = can_read_pvd & 0xf; + if (((ct->sector_size == 2332) || (ct->sector_size == 2336)) && + (ct->form >= 1)) + ct->skip = 8; + } else if (ct->sector_size >= 2332) { + can_read_pvd = image_can_read_pvd(ci->file, + ci->file_start * ct->sector_size, + ct->sector_size, 1); + if (can_read_pvd) { + ct->mode = can_read_pvd >> 4; + ct->form = can_read_pvd & 0xf; + if (((ct->sector_size == 2332) || (ct->sector_size == 2336)) && + (ct->form >= 1)) + ct->skip = 8; + } + } + + image_log(img->log, " NEW MODE: %02X/%02X\n", + ct->mode, ct->form); + } + break; + case 0xa0: + for (int j = 0; j < img->tracks_num; j++) { + track_t *jt = &(img->tracks[j]); + if ((jt->session == ct->session) && + (jt->point >= 1) && (jt->point <= 99)) { + lt = jt; + break; + } + } + + if (lt != NULL) { + int disc_type = 0x00; + + ct->attr = lt->attr; + + ct->mode = lt->mode; + ct->form = lt->form; + + if (lt->mode == 2) + disc_type = 0x20; + + for (int j = 0; j < 3; j++) { + ci = &(ct->idx[j]); + ci->type = INDEX_ZERO; + ci->start = (lt->point * 60 * 75) + (disc_type * 75); + ci->length = 0; + + image_log(img->log, " [TRACK ] %02X/%02X, INDEX %02X, " + "ATTR %02X, MODE %02X/%02X, %8s,\n", + ct->session, + ct->point, j, + ct->attr, + ct->mode, ct->form, + cit[ci->type + 2]); + image_log(img->log, " first track = %02X, " + "disc type = %02X\n", + lt->point, disc_type); + } + } + break; + case 0xa1: + for (int j = (img->tracks_num - 1); j >= 0; j--) { + track_t *jt = &(img->tracks[j]); + if ((jt->session == ct->session) && (jt->point >= 1) && (jt->point <= 99)) { + lt = jt; + break; + } + } + + if (lt != NULL) { + ct->attr = lt->attr; + + ct->mode = lt->mode; + ct->form = lt->form; + + for (int j = 0; j < 3; j++) { + ci = &(ct->idx[j]); + ci->type = INDEX_ZERO; + ci->start = (lt->point * 60 * 75); + ci->length = 0; + + image_log(img->log, " [TRACK ] %02X/%02X, INDEX %02X, " + "ATTR %02X, MODE %02X/%02X, %8s,\n", + ct->session, + ct->point, j, + ct->attr, + ct->mode, ct->form, + cit[ci->type + 2]); + image_log(img->log, " last track = %02X\n", + lt->point); + } + } + break; + case 0xa2: + if (lo[ct->session] != NULL) { + /* + We have a track to use for the calculation, first adjust the track's + attribute (ADR/Ctrl), mode, and form to match the last non-special track. + */ + lt = lo[ct->session]; + + ct->attr = lt->attr; + + ct->mode = lt->mode; + ct->form = lt->form; + + if (ct->idx[1].type != INDEX_NORMAL) { + /* + Index not normal, therefore, this is not a lead out track from a + second or afterwards session of a multi-session Cue sheet, calculate + the starting time and update all the indexes accordingly. + */ + const track_index_t *li = &(lt->idx[2]); + + for (int j = 0; j < 3; j++) { + image_log(img->log, " [TRACK ] %02X/%02X, INDEX %02X, " + "ATTR %02X, MODE %02X/%02X, %8s,\n", + ct->session, + ct->point, j, + ct->attr, + ct->mode, ct->form, + cit[ci->type + 2]); + + ci = &(ct->idx[j]); + ci->type = INDEX_ZERO; + ci->start = li->start + li->length; + ci->length = 0; + + image_log(img->log, " start = %016" PRIX64 + " (%2i:%02i:%02i)\n", + ci->start, + (int) ((ci->start / 75) / 60), + (int) ((ci->start / 75) % 60), + (int) (ci->start % 75)); + } + } +#ifdef ENABLE_IMAGE_LOG + else + image_log(img->log, " no start calculation done, " + "already specified\n"); +#endif + } +#ifdef ENABLE_IMAGE_LOG + else + image_log(img->log, " nothing done, no suitable last track " + "found\n"); +#endif + break; + case 0xb0: + /* + B0: MSF points to the beginning of the pre-gap + of the following session's first track. + */ + ct->extra[0] = (spg[ct->session + 1] / 75) / 60; + ct->extra[1] = (spg[ct->session + 1] / 75) % 60; + ct->extra[2] = spg[ct->session + 1] % 75; + + image_log(img->log, " [TRACK ] %02X/%02X, INDEX 01, " + "ATTR %02X, MODE %02X/%02X, %8s,\n", + ct->session, + ct->point, + ct->attr, + ct->mode, ct->form, + cit[ct->idx[1].type + 2]); + image_log(img->log, " %02X:%02X:%02X, %02X,\n", + ct->extra[0], ct->extra[1], ct->extra[2], ct->extra[3]); + + /* + B0 PMSF points to the start of the lead out track + of the last session. + */ + if (lo[ls] != NULL) { + lt = lo[ls]; + const track_index_t *li = &(lt->idx[2]); + + ct->idx[1].start = li->start + li->length; + + image_log(img->log, " start = %016" PRIX64 + " (%2i:%02i:%02i)\n", + ct->idx[1].start, + (int) ((ct->idx[1].start / 75) / 60), + (int) ((ct->idx[1].start / 75) % 60), + (int) (ct->idx[1].start % 75)); + } +#ifdef ENABLE_IMAGE_LOG + else + image_log(img->log, " no start calculation done, " + "no suitable last track found\n"); +#endif + break; + } + } + +#ifdef ENABLE_IMAGE_LOG + image_log(img->log, "Final tracks list:\n"); + for (int i = 0; i < img->tracks_num; i++) { + ct = &(img->tracks[i]); + for (int j = 0; j < 3; j++) { + ci = &(ct->idx[j]); + image_log(img->log, " [TRACK ] %02X INDEX %02X: [%8s, %016" PRIX64 "]\n", + ct->point, j, + cit[ci->type + 2], ci->file_start * ct->sector_size); + image_log(img->log, " TOC data: %02X %02X %02X " + "%%02X %02X %02X %02X 02X %02X %02X %02X\n", + ct->session, ct->attr, ct->tno, ct->point, + ct->extra[0], ct->extra[1], ct->extra[2], ct->extra[3], + (uint32_t) ((ci->start / 75) / 60), + (uint32_t) ((ci->start / 75) % 60), + (uint32_t) (ci->start % 75)); + } + } +#endif +} + +static void +image_set_track_subch_type(track_t *ct) +{ + if (ct->sector_size == 2448) + ct->subch_type = 0x08; + else if (ct->sector_size == 2368) + ct->subch_type = 0x10; + else + ct->subch_type = 0x00; +} + +static int +image_load_iso(cd_image_t *img, const char *filename) +{ + track_t *ct = NULL; + track_index_t *ci = NULL; + track_file_t *tf = NULL; + int success = 1; + int error = 1; + int is_viso = 0; + int sector_sizes[8] = { 2448, 2368, RAW_SECTOR_SIZE, 2336, + 2332, 2328, 2324, COOKED_SECTOR_SIZE }; + + img->tracks = NULL; + /* + Pass 1 - loading the ISO image. + */ + image_log(img->log, "Pass 1 (loading the ISO image)...\n"); + img->tracks_num = 0; + + image_insert_track(img, 1, 0xa0); + image_insert_track(img, 1, 0xa1); + image_insert_track(img, 1, 0xa2); + + /* Data track (shouldn't there be a lead in track?). */ + tf = index_file_init(img->dev->id, filename, &error, &is_viso); + + if (error) { + if (tf != NULL) { + tf->close(tf); + tf = NULL; + } + + success = 0; + } else if (is_viso) + success = 3; + + if (success) { + ct = image_insert_track(img, 1, 1); + ci = &(ct->idx[1]); + + ct->form = 0; + ct->mode = 0; + + for (int i = 0; i < 3; i++) + ct->idx[i].type = INDEX_NONE; + + ct->attr = DATA_TRACK; + + /* Try to detect ISO type. */ + ct->mode = 1; + ct->form = 0; + + ci->type = INDEX_NORMAL; + ci->file_start = 0ULL; + + ci->file = tf; + + for (int i = 0; i < 8; i++) { + ct->sector_size = sector_sizes[i]; + int can_read_pvd = image_can_read_pvd(ci->file, 0, ct->sector_size, 0); + if (can_read_pvd) { + ct->mode = can_read_pvd >> 4; + ct->form = can_read_pvd & 0xf; + if (((ct->sector_size == 2332) || (ct->sector_size == 2336)) && + (ct->form >= 1)) + ct->skip = 8; + break; + } else if (ct->sector_size >= 2332) { + can_read_pvd = image_can_read_pvd(ci->file, 0, ct->sector_size, 1); + if (can_read_pvd) { + ct->mode = can_read_pvd >> 4; + ct->form = can_read_pvd & 0xf; + if (((ct->sector_size == 2332) || (ct->sector_size == 2336)) && + (ct->form >= 1)) + ct->skip = 8; + break; + } + } + } + + image_set_track_subch_type(ct); + + image_log(img->log, " [TRACK ] %02X/%02X, ATTR %02X, MODE %02X/%02X,\n", + ct->session, + ct->point, + ct->attr, + ct->mode, ct->form); + image_log(img->log, " %02X:%02X:%02X, %02X, %i\n", + ct->sector_size); + } + + if (success) for (int i = 2; i >= 0; i--) { + if (ct->idx[i].file == NULL) + ct->idx[i].file = tf; + else + break; + } + + tf = NULL; + + if (success) + image_process(img); + else { + image_log(img->log, " [ISO ] Unable to open image or folder \"%s\"\n", + filename); + return 0; + } + + return success; +} + +static int +image_load_cue(cd_image_t *img, const char *cuefile) +{ + track_t *ct = NULL; + track_index_t *ci = NULL; + track_file_t *tf = NULL; + uint64_t frame = 0ULL; + uint64_t last = 0ULL; + uint8_t session = 1; + int last_t = -1; + int is_viso = 0; + int lead[3] = { 0 }; + int error; + char pathname[MAX_FILENAME_LENGTH]; + char buf[MAX_LINE_LENGTH]; + char *line; + char *command; + char *type; + char temp; + + img->tracks = NULL; + img->tracks_num = 0; + + /* Get a copy of the filename into pathname, we need it later. */ + memset(pathname, 0, MAX_FILENAME_LENGTH * sizeof(char)); + path_get_dirname(pathname, cuefile); + + /* Open the file. */ + FILE *fp = plat_fopen(cuefile, "r"); + if (fp == NULL) + return 0; + + int success = 0; + + /* + Pass 1 - loading the Cue sheet. + */ + image_log(img->log, "Pass 1 (loading the Cue sheet)...\n"); + img->tracks_num = 0; + + for (int i = 0; i < 3; i++) { + lead[i] = img->tracks_num; + (void) image_insert_track(img, session, 0xa0 + i); + } + + while (1) { + line = buf; + + /* Read a line from the cuesheet file. */ + if (feof(fp) || (fgets(buf, sizeof(buf), fp) == NULL) || ferror(fp)) + break; + + /* 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 (uint8_t i = 0; i < 2; i++) { + if (strlen(buf) > 0) { + if (buf[strlen(buf) - 1] == '\n') + buf[strlen(buf) - 1] = '\0'; + /* nuke trailing newline */ + else if (buf[strlen(buf) - 1] == '\r') + buf[strlen(buf) - 1] = '\0'; + /* nuke trailing newline */ + } + } + image_log(img->log, " [LINE ] \"%s\"\n", line); + + (void) image_cue_get_keyword(&command, &line); + + if (!strcmp(command, "FILE")) { + /* The file for the track. */ + char filename[MAX_FILENAME_LENGTH]; + char ansi[MAX_FILENAME_LENGTH]; + + tf = NULL; + + memset(ansi, 0, MAX_FILENAME_LENGTH * sizeof(char)); + memset(filename, 0, MAX_FILENAME_LENGTH * sizeof(char)); + + success = image_cue_get_buffer(ansi, &line, 0); + if (!success) + break; + success = image_cue_get_keyword(&type, &line); + if (!success) + break; + + error = 1; + is_viso = 0; + + if (!strcmp(type, "BINARY") || !strcmp(type, "MOTOROLA")) { + if (!path_abs(ansi)) + path_append_filename(filename, pathname, ansi); + else + strcpy(filename, ansi); + + tf = index_file_init(img->dev->id, filename, &error, &is_viso); + + if (tf) + tf->motorola = !strcmp(type, "MOTOROLA"); + } else if (!strcmp(type, "WAVE") || !strcmp(type, "AIFF") || + !strcmp(type, "MP3")) { + if (!path_abs(ansi)) + path_append_filename(filename, pathname, ansi); + else + strcpy(filename, ansi); + tf = audio_init(img->dev->id, filename, &error); + } + if (error) { + if (tf != NULL) { + tf->close(tf); + tf = NULL; + } + success = 0; + } else if (is_viso) + success = 3; + +#ifdef ENABLE_IMAGE_LOG + if (!success) + image_log(img->log, " [FILE ] Unable to open file \"%s\" " + "specified in cue sheet\n", filename); +#endif + } else if (!strcmp(command, "TRACK")) { + int t = image_cue_get_number(&line); + success = image_cue_get_keyword(&type, &line); + + if (!success) + break; + + if (last_t != -1) { + /* + Important: This has to be done like this because pointers + change due to realloc. + */ + ct = &(img->tracks[t]); + + for (int i = 2; i >= 0; i--) { + if (ct->idx[i].file == NULL) + ct->idx[i].file = tf; + else + break; + } + } + + last_t = t; + ct = image_insert_track(img, session, t); + + ct->form = 0; + ct->mode = 0; + + if (!strcmp(type, "AUDIO")) { + ct->sector_size = RAW_SECTOR_SIZE; + ct->attr = AUDIO_TRACK; + } else if (!memcmp(type, "MODE", 4)) { + uint32_t mode; + ct->attr = DATA_TRACK; + sscanf(type, "MODE%" PRIu32 "/%" PRIu32, + &mode, &(ct->sector_size)); + ct->mode = mode; + if (ct->mode == 2) switch(ct->sector_size) { + default: + break; + case 2324: case 2328: + ct->form = 2; + break; + case 2048: case 2332: case 2336: case 2352: case 2368: case 2448: + ct->form = 1; + break; + } + if (((ct->sector_size == 2336) || (ct->sector_size == 2332)) && (ct->mode == 2) && (ct->form == 1)) + ct->skip = 8; + } else if (!memcmp(type, "CD", 2)) { + ct->attr = DATA_TRACK; + ct->mode = 2; + sscanf(type, "CD%c/%i", &temp, &(ct->sector_size)); + } else + success = 0; + + if (success) { + image_set_track_subch_type(ct); + + last = ct->sector_size; + + image_log(img->log, " [TRACK ] %02X/%02X, ATTR %02X, MODE %02X/%02X,\n", + ct->session, + ct->point, + ct->attr, + ct->mode, ct->form); + image_log(img->log, " %i\n", + ct->sector_size); + } +#ifdef ENABLE_IMAGE_LOG + else + image_log(img->log, " [TRACK ] Unable to initialize track %02X " + "specified in Cue sheet\n", t); +#endif + } else if (!strcmp(command, "INDEX")) { + int t = image_cue_get_number(&line); + ci = &(ct->idx[t]); + + ci->type = INDEX_NORMAL; + ci->file = tf; + success = image_cue_get_frame(&frame, &line); + ci->file_start = frame; + + image_log(img->log, " [INDEX ] %02X (%8s): Initialization %s\n", + t, cit[ci->type + 2], success ? "successful" : "failed"); + } else if (!strcmp(command, "PREGAP")) { + ci = &(ct->idx[0]); + + ci->type = INDEX_ZERO; + ci->file = tf; + success = image_cue_get_frame(&frame, &line); + ci->length = frame; + + image_log(img->log, " [INDEX ] 00 (%8s): Initialization %s\n", + cit[ci->type + 2], success ? "successful" : "failed"); + } else if (!strcmp(command, "PAUSE") || !strcmp(command, "ZERO")) { + ci = &(ct->idx[1]); + + ci->type = INDEX_ZERO; + ci->file = tf; + success = image_cue_get_frame(&frame, &line); + ci->length = frame; + + image_log(img->log, " [INDEX ] 01 (%8s): Initialization %s\n", + cit[ci->type + 2], success ? "successful" : "failed"); + } else if (!strcmp(command, "POSTGAP")) { + ci = &(ct->idx[2]); + + ci->type = INDEX_ZERO; + ci->file = tf; + success = image_cue_get_frame(&frame, &line); + ci->length = frame; + + image_log(img->log, " [INDEX ] 02 (%8s): Initialization %s\n", + cit[ci->type + 2], success ? "successful" : "failed"); + } else if (!strcmp(command, "FLAGS")) { + success = image_cue_get_flags(ct, &line); + + image_log(img->log, " [FLAGS ] Initialization %s\n", + success ? "successful" : "failed"); + } else if (!strcmp(command, "REM")) { + success = 1; + char *space = strstr(line, " "); + if (space != NULL) { + space++; + if (space < (line + strlen(line))) { + (void) image_cue_get_keyword(&command, &space); + if (!strcmp(command, "LEAD-OUT")) { + ct = &(img->tracks[lead[2]]); + /* + Mark it this way so file pointers on it are not + going to be adjusted. + */ + last_t = -1; + ct->sector_size = last; + ci = &(ct->idx[1]); + ci->type = INDEX_NORMAL; + ci->file = tf; + success = image_cue_get_frame(&frame, &space); + ci->file_start = frame; + + image_log(img->log, " [LEAD-OUT] Initialization %s\n", + success ? "successful" : "failed"); + } else if (!strcmp(command, "SESSION")) { + session = image_cue_get_number(&space); + + if (session > 1) { + ct = image_insert_track(img, session - 1, 0xb0); + /* + Mark it this way so file pointers on it are not + going to be adjusted. + */ + last_t = -1; + ci = &(ct->idx[1]); + ci->start = (0x40 * 60 * 75) + (0x02 * 75); + + if (session == 2) { + ct->extra[3] = 0x02; + + /* + 00:00:00 on Wembley, C0:00:00 in the spec. + And what's in PMSF? + */ + ct = image_insert_track(img, session - 1, 0xc0); + /* + Mark it this way so file pointers on it are not + going to be adjusted. + */ + last_t = -1; + ci = &(ct->idx[1]); + /* Queen - Live at Wembley '86 CD 1. */ + ci->start = (0x5f * 75 * 60); + /* Optimum recording power. */ + ct->extra[0] = 0x00; + } else + ct->extra[3] = 0x01; + + for (int i = 0; i < 3; i++) { + lead[i] = img->tracks_num; + (void) image_insert_track(img, session, 0xa0 + i); + } + } + + image_log(img->log, " [SESSION ] Initialization successful\n"); + } + } + } + } else if (!strcmp(command, "CATALOG") || !strcmp(command, "CDTEXTFILE") || + !strcmp(command, "ISRC") || !strcmp(command, "PERFORMER") || + !strcmp(command, "SONGWRITER") || !strcmp(command, "TITLE") || + !strcmp(command, "")) { + /* Ignored commands. */ + image_log(img->log, " [CUE ] Ignored command \"%s\" in Cue sheet\n", + command); + success = 1; + } else { + image_log(img->log, " [CUE ] Unsupported command \"%s\" in Cue sheet\n", + command); + success = 0; + } + + if (!success) + break; + } + + if (success && (ct != NULL)) for (int i = 2; i >= 0; i--) { + if (ct->idx[i].file == NULL) + ct->idx[i].file = tf; + else + break; + } + + tf = NULL; + + fclose(fp); + + if (success) + image_process(img); + else { + image_log(img->log, " [CUE ] Unable to open Cue sheet \"%s\"\n", cuefile); + return 0; + } + + return success; +} + +/* Root functions. */ +static void +image_clear_tracks(cd_image_t *img) +{ + const track_file_t *last = NULL; + track_t *cur = NULL; + track_index_t *idx = NULL; + + if ((img->tracks != NULL) && (img->tracks_num > 0)) { + for (int i = 0; i < img->tracks_num; i++) { + cur = &img->tracks[i]; + + if (((cur->point >= 1) && (cur->point <= 99)) || + (cur->point == 0xa2)) for (int j = 0; j < 3; j++) { + idx = &(cur->idx[j]); + /* Make sure we do not attempt to close a NULL file. */ + if ((idx->file != NULL) && (idx->type == INDEX_NORMAL)) { + if (idx->file != last) { + last = idx->file; + index_file_close(idx); + } else + idx->file = NULL; + } + } + } + + /* Now free the array. */ + free(img->tracks); + img->tracks = NULL; + + /* Mark that there's no tracks. */ + img->tracks_num = 0; + } +} + +/* Shared functions. */ +static int +image_get_track_info(const void *local, const uint32_t track, + const int end, track_info_t *ti) +{ + const cd_image_t *img = (const cd_image_t *) local; + const track_t *ct = NULL; + int ret = 0; for (int i = 0; i < img->tracks_num; i++) { ct = &(img->tracks[i]); @@ -70,238 +1712,334 @@ image_get_track_info(cdrom_t *dev, uint32_t track, int end, track_info_t *ti) break; } - ti->number = ct->point; + if (ct != NULL) { + const uint32_t pos = end ? ct->idx[1].start : + (ct->idx[1].start + ct->idx[1].length); - if (ct == NULL) { - ti->attr = 0x14; - ti->m = 0; - ti->s = 2; - ti->f = 0; - } else { - uint32_t pos = end ? ct->idx[1].start : (ct->idx[1].start + ct->idx[1].length); - ti->attr = ct->attr; - ti->m = (pos / 75) / 60; - ti->s = (pos / 75) % 60; - ti->f = pos % 75; + ti->number = ct->point; + ti->attr = ct->attr; + ti->m = (pos / 75) / 60; + ti->s = (pos / 75) % 60; + ti->f = pos % 75; + + ret = 1; } + + return ret; } static void -image_get_raw_track_info(cdrom_t *dev, int *num, raw_track_info_t *rti) +image_get_raw_track_info(const void *local, int *num, uint8_t *buffer) { - cdi_get_raw_track_info((cd_img_t *) dev->local, num, (uint8_t *) rti); -} + const cd_image_t *img = (const cd_image_t *) local; + int len = 0; -static void -image_get_subchannel(cdrom_t *dev, uint32_t lba, subchannel_t *subc) -{ - cd_img_t *img = (cd_img_t *) dev->local; - TMSF rel_pos; - TMSF abs_pos; + image_log(img->log, "img->tracks_num = %i\n", img->tracks_num); - cdi_get_audio_sub(img, lba, &subc->attr, &subc->track, &subc->index, - &rel_pos, &abs_pos); + for (int i = 0; i < img->tracks_num; i++) { + const track_t *ct = &(img->tracks[i]); +#ifdef ENABLE_IMAGE_LOG + int old_len = len; +#endif + buffer[len++] = ct->session; /* Session number. */ + buffer[len++] = ct->attr; /* Track ADR and Control. */ + buffer[len++] = ct->tno; /* TNO (always 0). */ + buffer[len++] = ct->point; /* Point (track number). */ + for (int j = 0; j < 4; j++) + buffer[len++] = ct->extra[j]; + buffer[len++] = (ct->idx[1].start / 75) / 60; + buffer[len++] = (ct->idx[1].start / 75) % 60; + buffer[len++] = ct->idx[1].start % 75; + image_log(img->log, "%i: %02X %02X %02X %02X %02X %02X %02X\n", i, + buffer[old_len], buffer[old_len + 1], + buffer[old_len + 2], buffer[old_len + 3], + buffer[old_len + 8], buffer[old_len + 9], + buffer[old_len + 10]); + } - subc->abs_m = abs_pos.min; - subc->abs_s = abs_pos.sec; - subc->abs_f = abs_pos.fr; - - subc->rel_m = rel_pos.min; - subc->rel_s = rel_pos.sec; - subc->rel_f = rel_pos.fr; - - cdrom_image_log("image_get_subchannel(): %02X, %02X, %02i, %02i:%02i:%02i, %02i:%02i:%02i\n", - subc->attr, subc->track, subc->index, subc->abs_m, subc->abs_s, subc->abs_f, - subc->rel_m, subc->rel_s, subc->rel_f); + *num = img->tracks_num; } static int -image_get_capacity(cdrom_t *dev) +image_is_track_pre(const void *local, const uint32_t sector) { - cd_img_t *img = (cd_img_t *) dev->local; - uint32_t lb = 0; - track_t *lo = NULL; + const cd_image_t *img = (const cd_image_t *) local; + int ret = 0; - if (!img) - return 0; + if (img->has_audio) { + const int track = image_get_track(img, sector); - for (int i = (img->tracks_num - 1); i >= 0; i--) { - if (img->tracks[i].point == 0xa2) { - lo = &(img->tracks[i]); - break; + if (track >= 0) { + const track_t *trk = &(img->tracks[track]); + + ret = !!(trk->attr & 0x01); } } - if (lo != NULL) - lb = lo->idx[1].start - 1; + return ret; +} + +static int +image_read_sector(const void *local, uint8_t *buffer, + const uint32_t sector) +{ + const cd_image_t *img = (const cd_image_t *) local; + int m = 0; + int s = 0; + int f = 0; + int ret = 0; + uint32_t lba = sector; + int track; + int index; + uint8_t q[16] = { 0x00 }; + + if (sector == 0xffffffff) + lba = img->dev->seek_pos; + + const uint64_t sect = (uint64_t) lba; + + image_get_track_and_index(img, lba, &track, &index); + + const track_t *trk = &(img->tracks[track]); + const track_index_t *idx = &(trk->idx[index]); + const int track_is_raw = ((trk->sector_size == RAW_SECTOR_SIZE) || + (trk->sector_size == 2448)); + const uint64_t seek = ((sect + 150 - idx->start + idx->file_start) * + trk->sector_size) + trk->skip; + + if (track >= 0) { + /* Signal CIRC error to the guest if sector is bad. */ + ret = image_is_sector_bad(img, lba) ? -1 : 1; + + if (ret > 0) { + uint64_t offset = 0ULL; + + image_log(img->log, "cdrom_read_sector(%08X): track %02X, index %02X, %016" + PRIX64 ", %i, %i, %i, %i\n", + lba, track, index, idx->start, trk->sector_size, track_is_raw, + trk->mode, trk->form); + + memset(buffer, 0x00, 2448); + + if ((trk->attr & 0x04) && ((idx->type < INDEX_NORMAL) || !track_is_raw)) { + offset += 16ULL; + + /* Construct the header. */ + memset(buffer + 1, 0xff, 10); + buffer += 12; + FRAMES_TO_MSF(sector + 150, &m, &s, &f); + /* These have to be BCD. */ + buffer[0] = bin2bcd(m & 0xff); + buffer[1] = bin2bcd(s & 0xff); + buffer[2] = bin2bcd(f & 0xff); + /* Data, should reflect the actual sector type. */ + buffer[3] = trk->mode; + buffer += 4; + if (trk->form >= 1) { + offset += 8ULL; + + /* Construct the CD-I/XA sub-header. */ + buffer[2] = buffer[6] = (trk->form - 1) << 5; + buffer += 8; + } + } + + if (idx->type >= INDEX_NORMAL) { + /* Read the data from the file. */ + ret = idx->file->read(idx->file, buffer, seek, trk->sector_size); + } else + /* Index is not in the file, no read to fail here. */ + ret = 1; + + if ((ret > 0) && ((idx->type < INDEX_NORMAL) || (trk->subch_type != 0x08))) { + buffer -= offset; + + if (trk->subch_type == 0x10) + memcpy(q, &(buffer[2352]), 12); + else { + /* Construct Q. */ + q[0] = (trk->attr >> 4) | ((trk->attr & 0xf) << 4); + q[1] = bin2bcd(trk->point); + q[2] = index; + if (index == 0) { + /* + Pre-gap sector relative frame addresses count from + 00:01:74 downwards. + */ + FRAMES_TO_MSF((int32_t) (149 - (lba + 150 - idx->start)), &m, &s, &f); + } else { + FRAMES_TO_MSF((int32_t) (lba + 150 - idx->start), &m, &s, &f); + } + q[3] = bin2bcd(m & 0xff); + q[4] = bin2bcd(s & 0xff); + q[5] = bin2bcd(f & 0xff); + FRAMES_TO_MSF(lba + 150, &m, &s, &f); + q[7] = bin2bcd(m & 0xff); + q[8] = bin2bcd(s & 0xff); + q[9] = bin2bcd(f & 0xff); + } + + /* Construct raw subchannel data from Q only. */ + for (int i = 0; i < 12; i++) + for (int j = 0; j < 8; j++) + buffer[2352 + (i << 3) + j] = ((q[i] >> (7 - j)) & 0x01) << 6; + } + } + } + + return ret; +} + +static uint8_t +image_get_track_type(const void *local, const uint32_t sector) +{ + const cd_image_t *img = (cd_image_t *) local; + const int track = image_get_track(img, sector); + const track_t * trk = &(img->tracks[track]); + int ret = 0x00; + + if (image_is_track_audio(img, sector)) + ret = CD_TRACK_AUDIO; + else if (track >= 0) for (int i = 0; i < img->tracks_num; i++) { + const track_t *ct = &(img->tracks[i]); + const track_t *nt = &(img->tracks[i + 1]); + + if (ct->point == 0xa0) { + const uint8_t first = (ct->idx[1].start / 75 / 60); + const uint8_t last = (nt->idx[1].start / 75 / 60); + + if ((trk->point >= first) && (trk->point <= last)) { + ret = (ct->idx[1].start / 75) % 60; + break; + } + } + } + + return ret; +} + +static uint32_t +image_get_last_block(const void *local) +{ + const cd_image_t *img = (const cd_image_t *) local; + uint32_t lb = 0x00000000; + + if (img != NULL) { + const track_t *lo = NULL; + + for (int i = (img->tracks_num - 1); i >= 0; i--) { + if (img->tracks[i].point == 0xa2) { + lo = &(img->tracks[i]); + break; + } + } + + if (lo != NULL) + lb = lo->idx[1].start - 1; + } return lb; } static int -image_is_track_audio(cdrom_t *dev, uint32_t pos, int ismsf) -{ - cd_img_t *img = (cd_img_t *) dev->local; - int m; - int s; - int f; - - if (!img || (dev->cd_status == CD_STATUS_DATA_ONLY)) - return 0; - - if (ismsf) { - m = (pos >> 16) & 0xff; - s = (pos >> 8) & 0xff; - f = pos & 0xff; - pos = MSFtoLBA(m, s, f) - 150; - } - - return cdi_is_audio(img, pos); -} - -static int -image_is_track_pre(cdrom_t *dev, uint32_t lba) -{ - cd_img_t *img = (cd_img_t *) dev->local; - - if (!img || (dev->cd_status == CD_STATUS_DATA_ONLY)) - return 0; - - return cdi_is_pre(img, lba); -} - -static int -image_sector_size(struct cdrom *dev, uint32_t lba) -{ - cd_img_t *img = (cd_img_t *) dev->local; - - return cdi_get_sector_size(img, lba); -} - -static int -image_read_sector(struct cdrom *dev, uint8_t *b, uint32_t lba) -{ - cd_img_t *img = (cd_img_t *) dev->local; - - if (cdi_get_sector_size(img, lba) <= 2352) - return cdi_read_sector(img, b, 1, lba); - else - return cdi_read_sector_sub(img, b, lba); -} - -static int -image_track_type(cdrom_t *dev, uint32_t lba) -{ - cd_img_t *img = (cd_img_t *) dev->local; - - if (img) { - if (image_is_track_audio(dev, lba, 0)) - return CD_TRACK_AUDIO; - else if (cdi_is_mode2(img, lba)) - return CD_TRACK_MODE2 | cdi_get_mode2_form(img, lba); - } - - return 0; -} - -static int -image_ext_medium_changed(cdrom_t *dev) +image_read_dvd_structure(const void *local, const uint8_t layer, const uint8_t format, + uint8_t *buffer, uint32_t *info) { return 0; } +static int +image_is_dvd(const void *local) +{ + const cd_image_t *img = (const cd_image_t *) local; + + return img->is_dvd; +} + +static int +image_has_audio(const void *local) +{ + const cd_image_t *img = (const cd_image_t *) local; + + return img->has_audio; +} + static void -image_exit(cdrom_t *dev) +image_close(void *local) { - cd_img_t *img = (cd_img_t *) dev->local; + cd_image_t *img = (cd_image_t *) local; - cdrom_image_log("CDROM: image_exit(%s)\n", dev->image_path); - dev->cd_status = CD_STATUS_EMPTY; + if (img != NULL) { + image_clear_tracks(img); - if (img) { - cdi_close(img); - dev->local = NULL; + image_log(img->log, "Log closed\n"); + + log_close(img->log); + img->log = NULL; + + free(img); } - - dev->ops = NULL; } -static const cdrom_ops_t cdrom_image_ops = { +static const cdrom_ops_t image_ops = { image_get_track_info, image_get_raw_track_info, - image_get_subchannel, image_is_track_pre, - image_sector_size, image_read_sector, - image_track_type, - image_ext_medium_changed, - image_exit + image_get_track_type, + image_get_last_block, + image_read_dvd_structure, + image_is_dvd, + image_has_audio, + NULL, + image_close, + NULL }; -static int -image_open_abort(cdrom_t *dev) +/* Public functions. */ +void * +image_open(cdrom_t *dev, const char *path) { - cdrom_image_close(dev); - dev->ops = NULL; - dev->image_path[0] = 0; - return 1; -} - -int -cdrom_image_open(cdrom_t *dev, const char *fn) -{ - cd_img_t *img; - - /* Make sure to not STRCPY if the two are pointing - at the same place. */ - if (fn != dev->image_path) - strcpy(dev->image_path, fn); - - /* Create new instance of the CDROM_Image class. */ - img = (cd_img_t *) calloc(1, sizeof(cd_img_t)); - - /* This guarantees that if ops is not NULL, then - neither is the image pointer. */ - if (img == NULL) - return image_open_abort(dev); - - dev->local = img; - - /* Open the image. */ - int i = cdi_set_device(img, fn); - if (!i) - return image_open_abort(dev); - - /* All good, reset state. */ - if (i >= 2) - dev->cd_status = CD_STATUS_DATA_ONLY; - else - dev->cd_status = CD_STATUS_STOPPED; - dev->seek_pos = 0; - dev->cd_buflen = 0; - dev->cdrom_capacity = image_get_capacity(dev); - cdrom_image_log("CD-ROM capacity: %i sectors (%" PRIi64 " bytes)\n", dev->cdrom_capacity, - ((uint64_t) dev->cdrom_capacity) << 11ULL); -#ifdef ENABLE_CDROM_IMAGE_LOG - int cm, cs, cf; - cf = dev->cdrom_capacity % 75; - cs = (dev->cdrom_capacity / 75) % 60; - cm = (dev->cdrom_capacity / 75) / 60; - cdrom_image_log("CD-ROM capacity: %i sectors (%" PRIi64 " bytes) (time: %02i:%02i:%02i)\n", - dev->cdrom_capacity, ((uint64_t) dev->cdrom_capacity - 150ULL) * 2352ULL, cm, cs, cf); -#endif - - /* Attach this handler to the drive. */ - dev->ops = &cdrom_image_ops; - - return 0; -} - -void -cdrom_image_close(cdrom_t *dev) -{ - cdrom_image_log("CDROM: image_close(%s)\n", dev->image_path); - - if (dev && dev->ops && dev->ops->exit) - dev->ops->exit(dev); + const uintptr_t ext = path + strlen(path) - strrchr(path, '.'); + cd_image_t *img = (cd_image_t *) calloc(1, sizeof(cd_image_t)); + + if (img != NULL) { + int ret; + const int is_cue = ((ext == 4) && !stricmp(path + strlen(path) - ext + 1, "CUE")); + + img->dev = dev; + + if (is_cue) { + ret = image_load_cue(img, path); + + if (ret >= 2) + img->has_audio = 0; + else if (ret) + img->has_audio = 1; + else { + image_close(img); + img = NULL; + } + } else { + ret = image_load_iso(img, path); + + if (!ret) { + image_close(img); + img = NULL; + } else + img->has_audio = 0; + } + + if (ret) { + char n[1024] = { 0 }; + + sprintf(n, "CD-ROM %i Image", dev->id + 1); + img->log = log_open(n); + + dev->ops = &image_ops; + } else + warning("Unable to load CD-ROM image: %s\n", path); + } + + return img; } diff --git a/src/cdrom/cdrom_image_backend.c b/src/cdrom/cdrom_image_backend.c deleted file mode 100644 index 9d065a0cb..000000000 --- a/src/cdrom/cdrom_image_backend.c +++ /dev/null @@ -1,1499 +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. - * - * CD-ROM image file handling module. - * - * Authors: Miran Grca, - * RichardG, - * Cacodemon345 - * - * Copyright 2016-2025 Miran Grca. - * Copyright 2016-2025 Miran Grca. - * Copyright 2024-2025 Cacodemon345. - */ -#define __STDC_FORMAT_MACROS -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef _WIN32 -# include -# include -#else -# include -#endif -#define HAVE_STDARG_H -#include <86box/86box.h> -#include <86box/path.h> -#include <86box/plat.h> -#include <86box/cdrom_image_backend.h> - -#include - -#define CDROM_BCD(x) (((x) % 10) | (((x) / 10) << 4)) - -#define MAX_LINE_LENGTH 512 -#define MAX_FILENAME_LENGTH 256 -#define CROSS_LEN 512 - -static char temp_keyword[1024]; - -#ifdef ENABLE_CDROM_IMAGE_BACKEND_LOG -int cdrom_image_backend_do_log = ENABLE_CDROM_IMAGE_BACKEND_LOG; - -void -cdrom_image_backend_log(const char *fmt, ...) -{ - va_list ap; - - if (cdrom_image_backend_do_log) { - va_start(ap, fmt); - pclog_ex(fmt, ap); - va_end(ap); - } -} -#else -# define cdrom_image_backend_log(fmt, ...) -#endif - -typedef struct audio_file_t { - SNDFILE *file; - SF_INFO info; -} audio_file_t; - -/* Audio file functions */ -static int -audio_read(void *priv, uint8_t *buffer, uint64_t seek, size_t count) -{ - track_file_t *tf = (track_file_t *) priv; - audio_file_t *audio = (audio_file_t *) tf->priv; - uint64_t samples_seek = seek / 4; - uint64_t samples_count = count / 4; - - if ((seek & 3) || (count & 3)) { - cdrom_image_backend_log("CD Audio file: Reading on non-4-aligned boundaries.\n"); - } - - sf_count_t res = sf_seek(audio->file, samples_seek, SEEK_SET); - - if (res == -1) - return 0; - - return !!sf_readf_short(audio->file, (short *) buffer, samples_count); -} - -static uint64_t -audio_get_length(void *priv) -{ - track_file_t *tf = (track_file_t *) priv; - audio_file_t *audio = (audio_file_t *) tf->priv; - - /* Assume 16-bit audio, 2 channel. */ - return audio->info.frames * 4ull; -} - -static void -audio_close(void *priv) -{ - track_file_t *tf = (track_file_t *) priv; - audio_file_t *audio = (audio_file_t *) tf->priv; - - memset(tf->fn, 0x00, sizeof(tf->fn)); - if (audio && audio->file) - sf_close(audio->file); - free(audio); - free(tf); -} - -static track_file_t * -audio_init(const char *filename, int *error) -{ - track_file_t *tf = (track_file_t *) calloc(sizeof(track_file_t), 1); - audio_file_t *audio = (audio_file_t *) calloc(sizeof(audio_file_t), 1); -#ifdef _WIN32 - wchar_t filename_w[4096]; -#endif - - if (tf == NULL || audio == NULL) { - goto cleanup_error; - } - - memset(tf->fn, 0x00, sizeof(tf->fn)); - strncpy(tf->fn, filename, sizeof(tf->fn) - 1); -#ifdef _WIN32 - mbstowcs(filename_w, filename, 4096); - audio->file = sf_wchar_open(filename_w, SFM_READ, &audio->info); -#else - audio->file = sf_open(filename, SFM_READ, &audio->info); -#endif - - if (!audio->file) { - cdrom_image_backend_log("Audio file open error!"); - goto cleanup_error; - } - - if (audio->info.channels != 2 || audio->info.samplerate != 44100 || !audio->info.seekable) { - cdrom_image_backend_log("Audio file not seekable or in non-CD format!"); - sf_close(audio->file); - goto cleanup_error; - } - - *error = 0; - tf->priv = audio; - tf->fp = NULL; - tf->close = audio_close; - tf->get_length = audio_get_length; - tf->read = audio_read; - return tf; -cleanup_error: - free(tf); - free(audio); - *error = 1; - return NULL; -} - -/* Binary file functions. */ -static int -bin_read(void *priv, uint8_t *buffer, uint64_t seek, size_t count) -{ - track_file_t *tf = NULL; - - if ((tf = (track_file_t *) priv)->fp == NULL) - return 0; - - cdrom_image_backend_log("CDROM: binary_read(%08lx, pos=%" PRIu64 " count=%lu)\n", - tf->fp, seek, count); - - if (fseeko64(tf->fp, seek, SEEK_SET) == -1) { - cdrom_image_backend_log("CDROM: binary_read failed during seek!\n"); - - return -1; - } - - if (fread(buffer, count, 1, tf->fp) != 1) { - cdrom_image_backend_log("CDROM: binary_read failed during read!\n"); - - return -1; - } - - if (UNLIKELY(tf->motorola)) { - for (uint64_t i = 0; i < count; i += 2) { - uint8_t buffer0 = buffer[i]; - uint8_t buffer1 = buffer[i + 1]; - buffer[i] = buffer1; - buffer[i + 1] = buffer0; - } - } - - return 1; -} - -static uint64_t -bin_get_length(void *priv) -{ - track_file_t *tf = NULL; - - if ((tf = (track_file_t *) priv)->fp == NULL) - return 0; - - fseeko64(tf->fp, 0, SEEK_END); - const off64_t len = ftello64(tf->fp); - cdrom_image_backend_log("CDROM: binary_length(%08lx) = %" PRIu64 "\n", tf->fp, len); - - return len; -} - -static void -bin_close(void *priv) -{ - track_file_t *tf = (track_file_t *) priv; - - if (tf == NULL) - return; - - if (tf->fp != NULL) { - fclose(tf->fp); - tf->fp = NULL; - } - - memset(tf->fn, 0x00, sizeof(tf->fn)); - - free(priv); -} - -static track_file_t * -bin_init(const char *filename, int *error) -{ - track_file_t *tf = (track_file_t *) calloc(1, sizeof(track_file_t)); - struct stat stats; - - if (tf == NULL) { - *error = 1; - return NULL; - } - - memset(tf->fn, 0x00, sizeof(tf->fn)); - strncpy(tf->fn, filename, sizeof(tf->fn) - 1); - tf->fp = plat_fopen64(tf->fn, "rb"); - cdrom_image_backend_log("CDROM: binary_open(%s) = %08lx\n", tf->fn, tf->fp); - - if (stat(tf->fn, &stats) != 0) { - /* Use a blank structure if stat failed. */ - memset(&stats, 0, sizeof(struct stat)); - } - *error = ((tf->fp == NULL) || ((stats.st_mode & S_IFMT) == S_IFDIR)); - - /* Set the function pointers. */ - if (!*error) { - tf->read = bin_read; - tf->get_length = bin_get_length; - tf->close = bin_close; - } else { - /* 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->fp != NULL) && ((stats.st_mode & S_IFMT) == S_IFDIR)) { - /* tf is freed by bin_close */ - bin_close(tf); - } else - free(tf); - tf = NULL; - } - - return tf; -} - -static track_file_t * -track_file_init(const char *filename, int *error, int *is_viso) -{ - track_file_t *tf; - - *is_viso = 0; - - /* Current we only support .BIN files, either combined or one per - track. In the future, more is planned. */ - tf = bin_init(filename, error); - - if (*error) { - if ((tf != NULL) && (tf->close != NULL)) { - tf->close(tf); - tf = NULL; - } - - tf = viso_init(filename, error); - - if (!*error) - *is_viso = 1; - } - - return tf; -} - -static void -index_file_close(track_index_t *idx) -{ - if (idx == NULL) - return; - - if (idx->file == NULL) - return; - - if (idx->file->close == NULL) - return; - - idx->file->close(idx->file); - idx->file = NULL; -} - -void -cdi_get_raw_track_info(cd_img_t *cdi, int *num, uint8_t *buffer) -{ - int len = 0; - - cdrom_image_backend_log("cdi->tracks_num = %i\n", cdi->tracks_num); - - for (int i = 0; i < cdi->tracks_num; i++) { - track_t *ct = &(cdi->tracks[i]); -#ifdef ENABLE_CDROM_IMAGE_BACKEND_LOG - int old_len = len; -#endif - buffer[len++] = ct->session; /* Session number */ - buffer[len++] = ct->attr; /* Track ADR and Control */ - buffer[len++] = ct->tno; /* TNO (always 0) */ - buffer[len++] = ct->point; /* Point (for track points - track number) */ - for (int j = 0; j < 4; j++) - buffer[len++] = ct->extra[j]; - buffer[len++] = (ct->idx[1].start / 75) / 60; - buffer[len++] = (ct->idx[1].start / 75) % 60; - buffer[len++] = ct->idx[1].start % 75; - cdrom_image_backend_log("%i: %02X %02X %02X %02X %02X %02X %02X\n", i, - buffer[old_len], buffer[old_len + 1], buffer[old_len + 2], buffer[old_len + 3], - buffer[old_len + 8], buffer[old_len + 9], buffer[old_len + 10]); - } - - *num = cdi->tracks_num; -} - -static int -cdi_get_track(cd_img_t *cdi, uint32_t sector) -{ - int ret = -1; - - for (int i = 0; i < cdi->tracks_num; i++) { - track_t *ct = &(cdi->tracks[i]); - for (int j = 0; j < 3; j++) { - track_index_t *ci = &(ct->idx[j]); - if (((sector + 150) >= ci->start) && ((sector + 150) <= (ci->start + ci->length - 1))) { - ret = i; - break; - } - } - } - - return ret; -} - -static void -cdi_get_track_and_index(cd_img_t *cdi, uint32_t sector, int *track, int *index) -{ - *track = -1; - *index = -1; - - for (int i = 0; i < cdi->tracks_num; i++) { - track_t *ct = &(cdi->tracks[i]); - for (int j = 0; j < 3; j++) { - track_index_t *ci = &(ct->idx[j]); - if (((sector + 150) >= ci->start) && ((sector + 150) <= (ci->start + ci->length - 1))) { - *track = i; - *index = j; - break; - } - } - } -} - -/* TODO: See if track start is adjusted by 150 or not. */ -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); - - if (cur_track < 1) - return 0; - - *track = (uint8_t) cur_track; - const track_t *trk = &cdi->tracks[*track]; - *attr = trk->attr; - *index = 1; - - /* Absolute position should be adjusted by 150, not the relative ones. */ - FRAMES_TO_MSF(sector + 150, &abs_pos->min, &abs_pos->sec, &abs_pos->fr); - - /* Relative position is relative Index 1 start - pre-gap values will be negative. */ - FRAMES_TO_MSF((int32_t) (sector + 150 - trk->idx[1].start), &rel_pos->min, &rel_pos->sec, &rel_pos->fr); - - return 1; -} - -static __inline int -bin2bcd(int x) -{ - return (x % 10) | ((x / 10) << 4); -} - -int -cdi_read_sector(cd_img_t *cdi, uint8_t *buffer, int raw, uint32_t sector) -{ - const uint64_t sect = (uint64_t) sector; - int m = 0; - int s = 0; - int f = 0; - int ret = 0; - uint64_t offset = 0ULL; - int track; - int index; - int raw_size; - int cooked_size; - uint8_t q[16] = { 0x00 }; - - cdi_get_track_and_index(cdi, sector, &track, &index); - - if (track < 0) - return 0; - - const track_t *trk = &(cdi->tracks[track]); - const track_index_t *idx = &(trk->idx[index]); - const int track_is_raw = ((trk->sector_size == RAW_SECTOR_SIZE) || (trk->sector_size == 2448)); - const uint64_t seek = (sect + 150 - idx->start + idx->file_start) * trk->sector_size; - - cdrom_image_backend_log("cdrom_read_sector(%08X): track %02X, index %02X, %016" PRIX64 ", %016" PRIX64 ", %i\n", - sector, track, index, idx->start, trk->sector_size); - - if (track_is_raw) - raw_size = trk->sector_size; - else - raw_size = 2448; - - if ((trk->mode == 2) && (trk->form != 1)) { - if (trk->form == 2) - cooked_size = (track_is_raw ? 2328 : trk->sector_size); /* Both 2324 + ECC and 2328 variants are valid. */ - else - cooked_size = 2336; - } else - cooked_size = COOKED_SECTOR_SIZE; - - if ((trk->mode == 2) && (trk->form >= 1)) - offset = 24ULL; - else - offset = 16ULL; - - if (idx->type < INDEX_NORMAL) { - memset(buffer, 0x00, 2448); - if (trk->attr & 0x04) { - /* Construct the rest of the raw sector. */ - memset(buffer + 1, 0xff, 10); - buffer += 12; - FRAMES_TO_MSF(sector + 150, &m, &s, &f); - /* These have to be BCD. */ - buffer[0] = CDROM_BCD(m & 0xff); - buffer[1] = CDROM_BCD(s & 0xff); - buffer[2] = CDROM_BCD(f & 0xff); - /* Data, should reflect the actual sector type. */ - buffer[3] = trk->mode; - ret = 1; - } - } else if (raw && !track_is_raw) { - memset(buffer, 0x00, 2448); - /* We are doing a raw read but the track is cooked, length should be cooked size. */ - const int temp = idx->file->read(idx->file, buffer + offset, seek, cooked_size); - if (temp <= 0) - return temp; - if (trk->attr & 0x04) { - /* Construct the rest of the raw sector. */ - memset(buffer + 1, 0xff, 10); - buffer += 12; - FRAMES_TO_MSF(sector + 150, &m, &s, &f); - /* These have to be BCD. */ - buffer[0] = CDROM_BCD(m & 0xff); - buffer[1] = CDROM_BCD(s & 0xff); - buffer[2] = CDROM_BCD(f & 0xff); - /* Data, should reflect the actual sector type. */ - buffer[3] = trk->mode; - ret = 1; - } - } else if (!raw && track_is_raw) - /* The track is raw but we are doing a cooked read, length should be cooked size. */ - return idx->file->read(idx->file, buffer, seek + offset, cooked_size); - else { - /* The track is raw and we are doing a raw read, length should be raw size. */ - ret = idx->file->read(idx->file, buffer, seek, raw_size); - if (raw && (raw_size == 2448)) - return ret; - } - - /* Construct Q. */ - q[0] = (trk->attr >> 4) | ((trk->attr & 0xf) << 4); - q[1] = bin2bcd(trk->point); - q[2] = index; - if (index == 0) { - /* Pre-gap sector relative frame addresses count from 00:01:74 downwards. */ - FRAMES_TO_MSF((int32_t) (149 - (sector + 150 - idx->start)), &m, &s, &f); - } else { - FRAMES_TO_MSF((int32_t) (sector + 150 - idx->start), &m, &s, &f); - } - q[3] = bin2bcd(m); - q[4] = bin2bcd(s); - q[5] = bin2bcd(f); - FRAMES_TO_MSF(sector + 150, &m, &s, &f); - q[7] = bin2bcd(m); - q[8] = bin2bcd(s); - q[9] = bin2bcd(f); - - /* Construct raw subchannel data from Q only. */ - for (int i = 0; i < 12; i++) - for (int j = 0; j < 8; j++) - buffer[2352 + (i << 3) + j] = ((q[i] >> (7 - j)) & 0x01) << 6; - - return ret; -} - -/* TODO: Do CUE+BIN images with a sector size of 2448 even exist? */ -int -cdi_read_sector_sub(cd_img_t *cdi, uint8_t *buffer, uint32_t sector) -{ - int track; - int index; - - cdi_get_track_and_index(cdi, sector, &track, &index); - - if (track < 0) - return 0; - - const track_t *trk = &(cdi->tracks[track]); - const track_index_t *idx = &(trk->idx[index]); - - const uint64_t seek = (((uint64_t) sector + 150 - idx->start + idx->file_start) * trk->sector_size); - - if ((idx->type < INDEX_NORMAL) && (trk->sector_size != 2448)) - return 0; - - return idx->file->read(idx->file, buffer, seek, 2448); -} - -int -cdi_get_sector_size(cd_img_t *cdi, uint32_t sector) -{ - int track = cdi_get_track(cdi, sector); - - if (track < 0) - return 0; - - const track_t *trk = &(cdi->tracks[track]); - - return trk->sector_size; -} - -int -cdi_is_audio(cd_img_t *cdi, uint32_t sector) -{ - int track = cdi_get_track(cdi, sector); - - if (track < 0) - return 0; - - const track_t *trk = &(cdi->tracks[track]); - - return !!(trk->mode == 0); -} - -int -cdi_is_pre(cd_img_t *cdi, uint32_t sector) -{ - int track = cdi_get_track(cdi, sector); - - if (track < 0) - return 0; - - const track_t *trk = &(cdi->tracks[track]); - - return !!(trk->attr & 0x01); -} - -int -cdi_is_mode2(cd_img_t *cdi, uint32_t sector) -{ - int track = cdi_get_track(cdi, sector); - - if (track < 0) - return 0; - - const track_t *trk = &(cdi->tracks[track]); - - return !!(trk->mode == 2); -} - -int -cdi_get_mode2_form(cd_img_t *cdi, uint32_t sector) -{ - int track = cdi_get_track(cdi, sector); - - if (track < 0) - return 0; - - const track_t *trk = &(cdi->tracks[track]); - - return trk->form; -} - -static int -cdi_can_read_pvd(track_file_t *file, uint64_t sector_size, int mode2, int form) -{ - uint8_t pvd[COOKED_SECTOR_SIZE]; - uint64_t seek = 16ULL * sector_size; /* First VD is located at sector 16. */ - - if (sector_size == RAW_SECTOR_SIZE) { - if (mode2 && (form > 0)) - seek += 24; - else - seek += 16; - } else if (form > 0) - seek += 8; - - file->read(file, pvd, seek, COOKED_SECTOR_SIZE); - - return ((pvd[0] == 1 && !strncmp((char *) (&pvd[1]), "CD001", 5) && pvd[6] == 1) || (pvd[8] == 1 && !strncmp((char *) (&pvd[9]), "CDROM", 5) && pvd[14] == 1)); -} - -static int -cdi_cue_get_buffer(char *str, char **line, int up) -{ - char *s = *line; - char *p = str; - int quote = 0; - int done = 0; - int space = 1; - - /* Copy to local buffer until we have end of string or whitespace. */ - while (!done) { - switch (*s) { - case '\0': - if (quote) { - /* Ouch, unterminated string.. */ - return 0; - } - done = 1; - break; - - case '\"': - quote ^= 1; - break; - - case ' ': - case '\t': - if (space) - break; - - if (!quote) { - done = 1; - break; - } - fallthrough; - - default: - if (up && islower((int) *s)) - *p++ = toupper((int) *s); - else - *p++ = *s; - space = 0; - break; - } - - if (!done) - s++; - } - *p = '\0'; - - *line = s; - - return 1; -} - -static int -cdi_cue_get_keyword(char **dest, char **line) -{ - int success; - - success = cdi_cue_get_buffer(temp_keyword, line, 1); - if (success) - *dest = temp_keyword; - - return success; -} - -/* Get a string from the input line, handling quotes properly. */ -static uint64_t -cdi_cue_get_number(char **line) -{ - char temp[128]; - uint64_t num; - - if (!cdi_cue_get_buffer(temp, line, 0)) - return 0; - - if (sscanf(temp, "%" PRIu64, &num) != 1) - return 0; - - return num; -} - -static int -cdi_cue_get_frame(uint64_t *frames, char **line) -{ - char temp[128]; - int min = 0; - int sec = 0; - int fr = 0; - int success; - - success = cdi_cue_get_buffer(temp, line, 0); - if (!success) - return 0; - - success = sscanf(temp, "%d:%d:%d", &min, &sec, &fr) == 3; - if (!success) - return 0; - - *frames = MSF_TO_FRAMES(min, sec, fr); - - return 1; -} - -static int -cdi_cue_get_flags(track_t *cur, char **line) -{ - char temp[128]; - char temp2[128]; - int success; - - success = cdi_cue_get_buffer(temp, line, 0); - if (!success) - return 0; - - memset(temp2, 0x00, sizeof(temp2)); - success = sscanf(temp, "%s", temp2) == 1; - if (!success) - return 0; - - if (strstr(temp2, "PRE") != NULL) - cur->attr |= 0x01; - if (strstr(temp2, "DCP") != NULL) - cur->attr |= 0x02; - if (strstr(temp2, "4CH") != NULL) - cur->attr |= 0x08; - - return 1; -} - -static track_t * -cdi_insert_track(cd_img_t *cdi, uint8_t session, uint8_t point) -{ - track_t *ct = NULL; - - cdi->tracks_num++; - if (cdi->tracks == NULL) { - cdi->tracks = calloc(1, sizeof(track_t)); - ct = &(cdi->tracks[0]); - } else { - cdi->tracks = realloc(cdi->tracks, cdi->tracks_num * sizeof(track_t)); - ct = &(cdi->tracks[cdi->tracks_num - 1]); - } - cdrom_image_backend_log("%02X: cdi->tracks[%2i] = %016" PRIX64 "\n", point, cdi->tracks_num - 1, (uint64_t) ct); - - memset(ct, 0x00, sizeof(track_t)); - - ct->session = session; - ct->point = point; - - for (int i = 0; i < 3; i++) - ct->idx[i].type = (point > 99) ? INDEX_SPECIAL : INDEX_NONE; - - return ct; -} - -static void -cdi_last_3_passes(cd_img_t *cdi) -{ - track_t *ct = NULL; - track_t *lt = NULL; - track_index_t *ci = NULL; - track_file_t *tf = NULL; - uint64_t tf_len = 0ULL; - uint64_t cur_pos = 0ULL; - int map[256] = { 0 }; - int lead[3] = { 0 }; - int pos = 0; - int ls = 0; - uint64_t spg[256] = { 0ULL }; - track_t *lo[256] = { 0 }; - - cdrom_image_backend_log("A2 = %016" PRIX64 "\n", (uint64_t) &(cdi->tracks[2])); - - for (int i = 0; i < cdi->tracks_num; i++) { - ct = &(cdi->tracks[i]); - if (((ct->point >= 1) && (ct->point <= 99)) || (ct->point >= 0xb0)) { - if (ct->point == 0xb0) { - /* Point B0h found, add the previous three lead tracks. */ - for (int j = 0; j < 3; j++) { - map[pos] = lead[j]; - pos++; - } - } - - map[pos] = i; - pos++; - } else if ((ct->point >= 0xa0) && (ct->point <= 0xa2)) - lead[ct->point & 0x03] = i; - } - - /* The last lead tracks. */ - for (int i = 0; i < 3; i++) { - map[pos] = lead[i]; - pos++; - } -#ifdef ENABLE_CDROM_IMAGE_BACKEND_LOG - cdrom_image_backend_log("pos = %i, cdi->tracks_num = %i\n", pos, cdi->tracks_num); - for (int i = 0; i < pos; i++) - cdrom_image_backend_log("map[%02i] = %02X\n", i, map[i]); -#endif - - cdrom_image_backend_log("Second pass:\n"); - for (int i = (cdi->tracks_num - 1); i >= 0; i--) { - ct = &(cdi->tracks[map[i]]); - if (ct->idx[1].type != INDEX_SPECIAL) { - for (int j = 2; j >= 0; j--) { - ci = &(ct->idx[j]); - - if ((ci->type >= INDEX_ZERO) && (ci->file != tf)) { - tf = ci->file; - if (tf != NULL) { - tf_len = tf->get_length(tf) / ct->sector_size; - cdrom_image_backend_log(" File length: %016" PRIX64 " sectors\n", tf_len); - } - } - - if (ci->type == INDEX_NONE) { - /* Index was not in the cue sheet, keep its length at zero. */ - ci->file_start = tf_len; - } else if (ci->type == INDEX_NORMAL) { - /* Index was in the cue sheet and is present in the file. */ - ci->file_length = tf_len - ci->file_start; - tf_len -= ci->file_length; - } - - cdrom_image_backend_log(" TRACK %2i (%2i), ATTR %02X, INDEX %i: %2i, file_start = %016" - PRIX64 " (%2i:%02i:%02i), file_length = %016" PRIX64 " (%2i:%02i:%02i)\n", - i, map[i], - ct->attr, - j, ci->type, - ci->file_start, - (int) ((ci->file_start / 75) / 60), - (int) ((ci->file_start / 75) % 60), - (int) (ci->file_start % 75), - ci->file_length, - (int) ((ci->file_length / 75) / 60), - (int) ((ci->file_length / 75) % 60), - (int) (ci->file_length % 75)); - } - } - } - - cdrom_image_backend_log("Third pass:\n"); - for (int i = 0; i < cdi->tracks_num; i++) { - int session_changed = 0; - - ct = &(cdi->tracks[map[i]]); - if (ct->idx[1].type != INDEX_SPECIAL) { - if (ct->session != ls) { - /* The first track of a session always has a pre-gap of at least 0:02:00. */ - ci = &(ct->idx[0]); - if (ci->type == INDEX_NONE) { - ci->type = INDEX_ZERO; - ci->start = 0ULL; - ci->length = 150ULL; - } - - session_changed = 1; - ls = ct->session; - } - - for (int j = 0; j < 3; j++) { - ci = &(ct->idx[j]); - - if (ci->type == INDEX_NONE) - /* Index was not in the cue sheet, keep its length at zero. */ - ci->start = cur_pos; - else if (ci->type == INDEX_ZERO) { - /* Index was in the cue sheet and is not present in the file. */ - ci->start = cur_pos; - cur_pos += ci->length; - } else if (ci->type == INDEX_NORMAL) { - /* Index was in the cue sheet and is present in the file. */ - ci->start = cur_pos; - ci->length = ci->file_length; - cur_pos += ci->file_length; - } - - cdrom_image_backend_log(" TRACK %2i (%2i) (%2i), ATTR %02X, MODE %i, INDEX %i: %2i, " - "start = %016" PRIX64 " (%2i:%02i:%02i), length = %016" PRIX64 - " (%2i:%02i:%02i)\n", - i, map[i], - ct->point, ct->attr, - ct->mode, - j, ci->type, - ci->start, - (int) ((ci->start / 75) / 60), - (int) ((ci->start / 75) % 60), - (int) (ci->start % 75), - ci->length, - (int) ((ci->length / 75) / 60), - (int) ((ci->length / 75) % 60), - (int) (ci->length % 75)); - - /* Set the pre-gap of the first track of this session. */ - if (session_changed) - spg[ct->session] = ct->idx[0].start; - } - } - } - - /* Set the lead out starts for all sessions. */ - for (int i = 0; i <= ls; i++) { - lo[i] = NULL; - for (int j = (cdi->tracks_num - 1); j >= 0; j--) { - track_t *jt = &(cdi->tracks[j]); - if ((jt->session == ct->session) && (jt->point >= 1) && (jt->point <= 99)) { - lo[i] = &(cdi->tracks[j]); - break; - } - } - } - - cdrom_image_backend_log("Fourth pass:\n"); - for (int i = 0; i < cdi->tracks_num; i++) { - ct = &(cdi->tracks[i]); - lt = NULL; - switch (ct->point) { - case 0xa0: - for (int j = 0; j < cdi->tracks_num; j++) { - track_t *jt = &(cdi->tracks[j]); - if ((jt->session == ct->session) && (jt->point >= 1) && (jt->point <= 99)) { - lt = &(cdi->tracks[j]); - break; - } - } - if (lt != NULL) { - int disc_type = 0x00; - - ct->attr = lt->attr; - - ct->mode = lt->mode; - ct->form = lt->form; - - if (lt->mode == 2) - disc_type = (lt->form > 0) ? 0x20 : 0x10; - for (int j = 0; j < 3; j++) { - ci = &(ct->idx[j]); - ci->type = INDEX_ZERO; - ci->start = (lt->point * 60 * 75) + (disc_type * 75); - ci->length = 0; - } - } - break; - case 0xa1: - for (int j = (cdi->tracks_num - 1); j >= 0; j--) { - track_t *jt = &(cdi->tracks[j]); - if ((jt->session == ct->session) && (jt->point >= 1) && (jt->point <= 99)) { - lt = &(cdi->tracks[j]); - break; - } - } - if (lt != NULL) { - ct->attr = lt->attr; - - ct->mode = lt->mode; - ct->form = lt->form; - - for (int j = 0; j < 3; j++) { - ci = &(ct->idx[j]); - ci->type = INDEX_ZERO; - ci->start = (lt->point * 60 * 75); - ci->length = 0; - } - } - break; - case 0xa2: - if (lo[ct->session] != NULL) { - lt = lo[ct->session]; - - ct->attr = lt->attr; - - ct->mode = lt->mode; - ct->form = lt->form; - - if (ct->idx[1].type != INDEX_NORMAL) { - track_index_t *li = &(lt->idx[2]); - - for (int j = 0; j < 3; j++) { - ci = &(ct->idx[j]); - ci->type = INDEX_ZERO; - ci->start = li->start + li->length; - ci->length = 0; - } - } - } - break; - case 0xb0: - /* - B0 MSF (*NOT* PMSF) points to the beginning of the pre-gap - of the corresponding session's first track. - */ - ct->extra[0] = (spg[ct->session] / 75) / 60; - ct->extra[1] = (spg[ct->session] / 75) % 60; - ct->extra[2] = spg[ct->session] % 75; - - /* - B0 PMSF points to the start of the lead out track - of the last session. - */ - if (lo[ls] != NULL) { - lt = lo[ls]; - track_index_t *li = &(lt->idx[2]); - - ct->idx[1].start = li->start + li->length; - } - break; - } - -#ifdef ENABLE_CDROM_IMAGE_BACKEND_LOG - if ((ct->point >= 0xa0) && (ct->point <= 0xa2)) - cdrom_image_backend_log(" TRACK %02X, SESSION %i: start = %016" PRIX64 " (%2i:%02i:%02i)\n", - ct->point, ct->session, - ct->idx[1].start, - (int) ((ct->idx[1].start / 75) / 60), - (int) ((ct->idx[1].start / 75) % 60), - (int) (ct->idx[1].start % 75)); -#endif - } -} - -int -cdi_load_iso(cd_img_t *cdi, const char *filename) -{ - track_t *ct = NULL; - track_index_t *ci = NULL; - track_file_t *tf = NULL; - int success; - int error = 1; - int is_viso = 0; - - cdi->tracks = NULL; - success = 1; - - cdrom_image_backend_log("First pass:\n"); - cdi->tracks_num = 0; - - cdi_insert_track(cdi, 1, 0xa0); - cdi_insert_track(cdi, 1, 0xa1); - cdi_insert_track(cdi, 1, 0xa2); - - /* Data track (shouldn't there be a lead in track?). */ - tf = track_file_init(filename, &error, &is_viso); - - if (error) { - cdrom_image_backend_log("ISO: cannot open file '%s'!\n", filename); - - if (tf != NULL) { - tf->close(tf); - tf = NULL; - } - success = 0; - } else if (is_viso) - success = 3; - - if (success) { - ct = cdi_insert_track(cdi, 1, 1); - ci = &(ct->idx[1]); - - ct->form = 0; - ct->mode = 0; - - for (int i = 0; i < 3; i++) - ct->idx[i].type = INDEX_NONE; - - ct->attr = DATA_TRACK; - - /* Try to detect ISO type. */ - ct->mode = 1; - ct->form = 0; - - ci->type = INDEX_NORMAL; - ci->file_start = 0ULL; - - ci->file = tf; - - /* For Mode 2 XA, skip the first 8 bytes in every sector when sector size = 2336. */ - if (cdi_can_read_pvd(ci->file, RAW_SECTOR_SIZE, 0, 0)) - ct->sector_size = RAW_SECTOR_SIZE; - else if (cdi_can_read_pvd(ci->file, 2336, 1, 0)) { - ct->sector_size = 2336; - ct->mode = 2; - } else if (cdi_can_read_pvd(ci->file, 2324, 1, 2)) { - ct->sector_size = 2324; - ct->mode = 2; - ct->form = 2; - } else if (cdi_can_read_pvd(ci->file, 2328, 1, 2)) { - ct->sector_size = 2328; - ct->mode = 2; - ct->form = 2; - } else if (cdi_can_read_pvd(ci->file, 2336, 1, 1)) { - ct->sector_size = 2336; - ct->mode = 2; - ct->form = 1; - ct->skip = 8; - } else if (cdi_can_read_pvd(ci->file, RAW_SECTOR_SIZE, 1, 0)) { - ct->sector_size = RAW_SECTOR_SIZE; - ct->mode = 2; - } else if (cdi_can_read_pvd(ci->file, RAW_SECTOR_SIZE, 1, 1)) { - ct->sector_size = RAW_SECTOR_SIZE; - ct->mode = 2; - ct->form = 1; - } else { - /* We use 2048 mode 1 as the default. */ - ct->sector_size = COOKED_SECTOR_SIZE; - } - - cdrom_image_backend_log("TRACK 1: Mode = %i, Form = %i, Sector size = %08X\n", - ct->mode, ct->form, ct->sector_size); - } - - tf = NULL; - - if (!success) - return 0; - - cdi_last_3_passes(cdi); - - return success; -} - -int -cdi_load_cue(cd_img_t *cdi, const char *cuefile) -{ - track_t *ct = NULL; - track_index_t *ci = NULL; - track_file_t *tf = NULL; - uint64_t frame = 0ULL; - uint64_t last = 0ULL; - uint8_t session = 1; - int success; - int error; - int is_viso = 0; - int lead[3] = { 0 }; - char pathname[MAX_FILENAME_LENGTH]; - char buf[MAX_LINE_LENGTH]; - FILE *fp; - char *line; - char *command; - char *type; - char temp; - - cdi->tracks = NULL; - cdi->tracks_num = 0; - - /* Get a copy of the filename into pathname, we need it later. */ - memset(pathname, 0, MAX_FILENAME_LENGTH * sizeof(char)); - path_get_dirname(pathname, cuefile); - - /* Open the file. */ - fp = plat_fopen(cuefile, "r"); - if (fp == NULL) - return 0; - - success = 0; - - cdrom_image_backend_log("First pass:\n"); - cdi->tracks_num = 0; - - for (int i = 0; i < 3; i++) { - lead[i] = cdi->tracks_num; - (void *) cdi_insert_track(cdi, session, 0xa0 + i); - } - cdrom_image_backend_log("lead[2] = %016" PRIX64 "\n", (uint64_t) &(cdi->tracks[lead[2]])); - - while (1) { - line = buf; - - /* Read a line from the cuesheet file. */ - if (feof(fp) || (fgets(buf, sizeof(buf), fp) == NULL) || ferror(fp)) - break; - - /* 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 (uint8_t i = 0; i < 2; i++) { - if (strlen(buf) > 0) { - if (buf[strlen(buf) - 1] == '\n') - buf[strlen(buf) - 1] = '\0'; - /* nuke trailing newline */ - else if (buf[strlen(buf) - 1] == '\r') - buf[strlen(buf) - 1] = '\0'; - /* nuke trailing newline */ - } - } - cdrom_image_backend_log(" line = %s\n", line); - - (void) cdi_cue_get_keyword(&command, &line); - - if (!strcmp(command, "FILE")) { - /* The file for the track. */ - char filename[MAX_FILENAME_LENGTH]; - char ansi[MAX_FILENAME_LENGTH]; - - tf = NULL; - - memset(ansi, 0, MAX_FILENAME_LENGTH * sizeof(char)); - memset(filename, 0, MAX_FILENAME_LENGTH * sizeof(char)); - - success = cdi_cue_get_buffer(ansi, &line, 0); - if (!success) - break; - success = cdi_cue_get_keyword(&type, &line); - if (!success) - break; - - error = 1; - is_viso = 0; - - if (!strcmp(type, "BINARY") || !strcmp(type, "MOTOROLA")) { - if (!path_abs(ansi)) - path_append_filename(filename, pathname, ansi); - else - strcpy(filename, ansi); - - tf = track_file_init(filename, &error, &is_viso); - - if (tf) - tf->motorola = !strcmp(type, "MOTOROLA"); - } else if (!strcmp(type, "WAVE") || !strcmp(type, "AIFF") || !strcmp(type, "MP3")) { - if (!path_abs(ansi)) - path_append_filename(filename, pathname, ansi); - else - strcpy(filename, ansi); - tf = audio_init(filename, &error); - } - if (error) { - cdrom_image_backend_log("CUE: cannot open file '%s' in cue sheet!\n", - filename); - - if (tf != NULL) { - tf->close(tf); - tf = NULL; - } - success = 0; - } else if (is_viso) - success = 3; - } else if (!strcmp(command, "TRACK")) { - int t = cdi_cue_get_number(&line); - success = cdi_cue_get_keyword(&type, &line); - - if (!success) - break; - - ct = cdi_insert_track(cdi, session, t); - - cdrom_image_backend_log(" TRACK %i\n", t); - - ct->form = 0; - ct->mode = 0; - - if (!strcmp(type, "AUDIO")) { - ct->sector_size = RAW_SECTOR_SIZE; - ct->attr = AUDIO_TRACK; - } else if (!memcmp(type, "MODE", 4)) { - uint32_t mode; - ct->attr = DATA_TRACK; - sscanf(type, "MODE%" PRIu32 "/%" PRIu32, &mode, &(ct->sector_size)); - ct->mode = mode; - if (ct->mode == 2) switch(ct->sector_size) { - case 2324: case 2328: - ct->form = 2; - break; - case 2048: case 2336: case 2352: case 2448: - ct->form = 1; - break; - } - if ((ct->sector_size == 2336) && (ct->mode == 2) && (ct->form == 1)) - ct->skip = 8; - } else if (!memcmp(type, "CD", 2)) { - ct->attr = DATA_TRACK; - ct->mode = 2; - sscanf(type, "CD%c/%i", &temp, &(ct->sector_size)); - } else - success = 0; - - if (success) - last = ct->sector_size; - } else if (!strcmp(command, "INDEX")) { - int t = cdi_cue_get_number(&line); - ci = &(ct->idx[t]); - - cdrom_image_backend_log(" INDEX %i (1)\n", t); - - ci->type = INDEX_NORMAL; - ci->file = tf; - success = cdi_cue_get_frame(&frame, &line); - ci->file_start = frame; - } else if (!strcmp(command, "PREGAP")) { - ci = &(ct->idx[0]); - cdrom_image_backend_log(" INDEX 0 (0)\n"); - - ci->type = INDEX_ZERO; - ci->file = tf; - success = cdi_cue_get_frame(&frame, &line); - ci->length = frame; - } else if (!strcmp(command, "PAUSE")) { - ci = &(ct->idx[1]); - cdrom_image_backend_log(" INDEX 1 (0)\n"); - - ci->type = INDEX_ZERO; - ci->file = tf; - success = cdi_cue_get_frame(&frame, &line); - ci->length = frame; - } else if (!strcmp(command, "POSTGAP")) { - ci = &(ct->idx[2]); - cdrom_image_backend_log(" INDEX 2 (0)\n"); - - ci->type = INDEX_ZERO; - ci->file = tf; - success = cdi_cue_get_frame(&frame, &line); - ci->length = frame; - } else if (!strcmp(command, "ZERO")) { - ci = &(ct->idx[1]); - cdrom_image_backend_log(" INDEX 1 (0)\n"); - - ci->type = INDEX_ZERO; - ci->file = tf; - success = cdi_cue_get_frame(&frame, &line); - ci->length = frame; - } else if (!strcmp(command, "FLAGS")) - success = cdi_cue_get_flags(ct, &line); - else if (!strcmp(command, "REM")) { - success = 1; - char *space = strstr(line, " "); - if (space != NULL) { - space++; - if (space < (line + strlen(line))) { - (void) cdi_cue_get_keyword(&command, &space); - if (!strcmp(command, "LEAD-OUT")) { - ct = &(cdi->tracks[lead[2]]); - cdrom_image_backend_log("lead[2] = %016" PRIX64 "\n", (uint64_t) ct); - ct->sector_size = last; - ci = &(ct->idx[1]); - ci->type = INDEX_NORMAL; - ci->file = tf; - success = cdi_cue_get_frame(&frame, &space); - ci->file_start = frame; - - cdrom_image_backend_log(" LEAD-OUT\n"); - } else if (!strcmp(command, "SESSION")) { - session = cdi_cue_get_number(&space); - - if (session > 1) { - ct = cdi_insert_track(cdi, session - 1, 0xb0); - ci = &(ct->idx[1]); - ci->start = (0x40 * 60 * 75) + (0x02 * 75); - - if (session == 2) { - ct->extra[3] = 0x02; - - /* 5F:00:00 on Wembley, C0:00:00 in the spec. And what's in PMSF? */ - ct = cdi_insert_track(cdi, session - 1, 0xc0); - ci = &(ct->idx[1]); - ct->extra[0] = 0x5f; /* Optimum recording power. */ - } else - ct->extra[3] = 0x01; - - for (int i = 0; i < 3; i++) { - lead[i] = cdi->tracks_num; - (void *) cdi_insert_track(cdi, session, 0xa0 + i); - } - cdrom_image_backend_log("lead[2] = %016" PRIX64 "\n", - (uint64_t) &(cdi->tracks[lead[2]])); - } - - cdrom_image_backend_log(" SESSION %i\n", session); - } - } - } - } else if (!strcmp(command, "CATALOG") || !strcmp(command, "CDTEXTFILE") || - !strcmp(command, "ISRC") || !strcmp(command, "PERFORMER") || - !strcmp(command, "SONGWRITER") || !strcmp(command, "TITLE") || - !strcmp(command, "")) - /* Ignored commands. */ - success = 1; - else { - cdrom_image_backend_log("CUE: unsupported command '%s' in cue sheet!\n", command); - - success = 0; - } - - if (!success) - break; - } - - tf = NULL; - - fclose(fp); - - if (!success) - return 0; - - cdi_last_3_passes(cdi); - - return success; -} - -/* Root functions. */ -static void -cdi_clear_tracks(cd_img_t *cdi) -{ - track_file_t *last = NULL; - track_t *cur = NULL; - track_index_t *idx = NULL; - - if ((cdi->tracks == NULL) || (cdi->tracks_num == 0)) - return; - - for (int i = 0; i < cdi->tracks_num; i++) { - cur = &cdi->tracks[i]; - - if ((cur->point >= 1) && (cur->point <= 99)) for (int j = 0; j < 3; j++) { - idx = &(cur->idx[j]); - - /* Make sure we do not attempt to close a NULL file. */ - if (idx->file != NULL) { - if (idx->file != last) { - last = idx->file; - index_file_close(idx); - } else - idx->file = NULL; - } - } - } - - /* Now free the array. */ - free(cdi->tracks); - cdi->tracks = NULL; - - /* Mark that there's no tracks. */ - cdi->tracks_num = 0; -} - -void -cdi_close(cd_img_t *cdi) -{ - cdi_clear_tracks(cdi); - free(cdi); -} - -int -cdi_set_device(cd_img_t *cdi, const char *path) -{ - uintptr_t ext = path + strlen(path) - strrchr(path, '.'); - int ret; - - cdrom_image_backend_log("cdi_set_device(): %" PRIu64 ", %lli, %s\n", - ext, strlen(path), path + strlen(path) - ext + 1); - - if ((ext == 4) && !stricmp(path + strlen(path) - ext + 1, "CUE")) { - if ((ret = cdi_load_cue(cdi, path))) - return ret; - - cdi_clear_tracks(cdi); - } - - if ((ret = cdi_load_iso(cdi, path))) - return ret; - - cdi_close(cdi); - - return 0; -} diff --git a/src/cdrom/cdrom_image_viso.c b/src/cdrom/cdrom_image_viso.c index 24f60836d..cf132c560 100644 --- a/src/cdrom/cdrom_image_viso.c +++ b/src/cdrom/cdrom_image_viso.c @@ -21,7 +21,9 @@ #define __STDC_FORMAT_MACROS #include #include +#ifdef IMAGE_VISO_LOG #include +#endif #include #include #include @@ -29,15 +31,16 @@ #include #include #include -#define HAVE_STDARG_H #include <86box/86box.h> -#include <86box/bswap.h> -#include <86box/cdrom_image_backend.h> +#include <86box/cdrom.h> +#include <86box/cdrom_image.h> +#include <86box/cdrom_image_viso.h> +#include <86box/log.h> #include <86box/path.h> #include <86box/plat.h> +#include <86box/bswap.h> #include <86box/plat_dir.h> #include <86box/version.h> -#include <86box/timer.h> #include <86box/nvr.h> #ifndef S_ISDIR @@ -136,29 +139,30 @@ static const char rr_eid[] = "RRIP_1991A"; /* identifiers used in ER field for static const char rr_edesc[] = "THE ROCK RIDGE INTERCHANGE PROTOCOL PROVIDES SUPPORT FOR POSIX FILE SYSTEM SEMANTICS."; static int8_t tz_offset = 0; -#ifdef ENABLE_CDROM_IMAGE_VISO_LOG -int cdrom_image_viso_do_log = ENABLE_CDROM_IMAGE_VISO_LOG; +#ifdef IMAGE_VISO_LOG +int image_viso_do_log = IMAGE_VISO_LOG; void -cdrom_image_viso_log(const char *fmt, ...) +image_viso_log(void *priv, const char *fmt, ...) { va_list ap; - if (cdrom_image_viso_do_log) { + if (image_viso_do_log) { va_start(ap, fmt); - pclog_ex(fmt, ap); + log_out(priv, fmt, ap); va_end(ap); } } #else -# define cdrom_image_viso_log(fmt, ...) +# define image_viso_log(priv, fmt, ...) #endif static size_t -viso_pread(void *ptr, uint64_t offset, size_t size, size_t count, FILE *fp) +viso_pread(void *ptr, const uint64_t offset, const size_t size, + const size_t count, FILE *fp) { - uint64_t cur_pos = ftello64(fp); - size_t ret = 0; + const uint64_t cur_pos = ftello64(fp); + size_t ret = 0; if (fseeko64(fp, offset, SEEK_SET) != -1) ret = fread(ptr, size, count, fp); fseeko64(fp, cur_pos, SEEK_SET); @@ -166,10 +170,11 @@ viso_pread(void *ptr, uint64_t offset, size_t size, size_t count, FILE *fp) } static size_t -viso_pwrite(const void *ptr, uint64_t offset, size_t size, size_t count, FILE *fp) +viso_pwrite(const void *ptr, const uint64_t offset, const size_t size, + const size_t count, FILE *fp) { - uint64_t cur_pos = ftello64(fp); - size_t ret = 0; + const uint64_t cur_pos = ftello64(fp); + size_t ret = 0; if (fseeko64(fp, offset, SEEK_SET) != -1) ret = fwrite(ptr, size, count, fp); fseeko64(fp, cur_pos, SEEK_SET); @@ -691,22 +696,22 @@ viso_read(void *priv, uint8_t *buffer, uint64_t seek, size_t count) /* Close any existing FIFO entry's file. */ viso_entry_t *other_entry = viso->file_fifo[viso->file_fifo_pos]; if (other_entry && other_entry->file) { - cdrom_image_viso_log("VISO: Closing [%s]", other_entry->path); + image_viso_log(viso->tf.log, "Closing [%s]...\n", other_entry->path); fclose(other_entry->file); other_entry->file = NULL; - cdrom_image_viso_log("\n"); + image_viso_log(viso->tf.log, "Done\n"); } /* Open file. */ - cdrom_image_viso_log("VISO: Opening [%s]", entry->path); + image_viso_log(viso->tf.log, "Opening [%s]...\n", entry->path); if ((entry->file = fopen(entry->path, "rb"))) { - cdrom_image_viso_log("\n"); + image_viso_log(viso->tf.log, "Done\n"); /* Add this entry to the FIFO. */ viso->file_fifo[viso->file_fifo_pos++] = entry; viso->file_fifo_pos &= (sizeof(viso->file_fifo) / sizeof(viso->file_fifo[0])) - 1; } else { - cdrom_image_viso_log(" => failed\n"); + image_viso_log(viso->tf.log, "Failed\n"); /* Clear any existing FIFO entry. */ viso->file_fifo[viso->file_fifo_pos] = NULL; @@ -753,12 +758,12 @@ viso_close(void *priv) if (viso == NULL) return; - cdrom_image_viso_log("VISO: close()\n"); + image_viso_log(viso->tf.log, "close()\n"); /* De-allocate everything. */ if (tf->fp) fclose(tf->fp); -#ifndef ENABLE_CDROM_IMAGE_VISO_LOG +#ifndef ENABLE_IMAGE_VISO_LOG remove(nvr_path(viso->tf.fn)); #endif @@ -777,21 +782,31 @@ viso_close(void *priv) if (viso->entry_map) free(viso->entry_map); + if (tf->log != NULL) + log_close(tf->log); + free(viso); } track_file_t * -viso_init(const char *dirname, int *error) +viso_init(const uint8_t id, const char *dirname, int *error) { - cdrom_image_viso_log("VISO: init()\n"); - /* Initialize our data structure. */ viso_t *viso = (viso_t *) calloc(1, sizeof(viso_t)); uint8_t *data = NULL; uint8_t *p; *error = 1; + if (viso == NULL) goto end; + + char n[1024] = { 0 }; + + sprintf(n, "CD-ROM %i VISO ", id + 1); + viso->tf.log = log_open(n); + + image_viso_log(viso->tf.log, "init()\n"); + viso->sector_size = VISO_SECTOR_SIZE; viso->format = VISO_FORMAT_ISO | VISO_FORMAT_JOLIET | VISO_FORMAT_RR; viso->use_version_suffix = (viso->format & VISO_FORMAT_ISO); /* cleared later if required */ @@ -802,7 +817,7 @@ viso_init(const char *dirname, int *error) goto end; /* Open temporary file. */ -#ifdef ENABLE_CDROM_IMAGE_VISO_LOG +#ifdef ENABLE_IMAGE_VISO_LOG strcpy(viso->tf.fn, "viso-debug.iso"); #else plat_tempfile(viso->tf.fn, "viso", ".tmp"); @@ -812,7 +827,7 @@ viso_init(const char *dirname, int *error) goto end; /* Set up directory traversal. */ - cdrom_image_viso_log("VISO: Traversing directories:\n"); + image_viso_log(viso->tf.log, "Traversing directories:\n"); viso_entry_t *entry; viso_entry_t *last_entry; viso_entry_t *dir; @@ -839,7 +854,7 @@ viso_init(const char *dirname, int *error) if (!S_ISDIR(dir->stats.st_mode)) /* root is not a directory */ goto end; dir->parent = dir; /* for the root's path table and .. entries */ - cdrom_image_viso_log("[%08X] %s => [root]\n", dir, dir->path); + image_viso_log(viso->tf.log, "[%08X] %s => [root]\n", dir, dir->path); /* Traverse directories, starting with the root. */ viso_entry_t **dir_entries = NULL; @@ -889,7 +904,8 @@ viso_init(const char *dirname, int *error) /* Set basename. */ strcpy(entry->name_short, children_count ? ".." : "."); - cdrom_image_viso_log("[%08X] %s => %s\n", entry, dir->path, entry->name_short); + image_viso_log(viso->tf.log, "[%08X] %s => %s\n", entry, + dir->path, entry->name_short); } /* Iterate through this directory's children again, making the entries. */ @@ -897,12 +913,16 @@ viso_init(const char *dirname, int *error) rewinddir(dirp); while ((readdir_entry = readdir(dirp))) { /* Ignore . and .. pseudo-directories. */ - if ((readdir_entry->d_name[0] == '.') && ((readdir_entry->d_name[1] == '\0') || (*((uint16_t *) &readdir_entry->d_name[1]) == '.'))) + if ((readdir_entry->d_name[0] == '.') && + ((readdir_entry->d_name[1] == '\0') || + (*((uint16_t *) &readdir_entry->d_name[1]) == '.'))) continue; /* Add and fill entry. */ - entry = dir_entries[children_count++] = (viso_entry_t *) calloc(1, sizeof(viso_entry_t) + dir_path_len + strlen(readdir_entry->d_name) + 2); - if (!entry) + entry = dir_entries[children_count++] = + (viso_entry_t *) calloc(1, sizeof(viso_entry_t) + + dir_path_len + strlen(readdir_entry->d_name) + 2); + if (entry == NULL) break; entry->parent = dir; strcpy(entry->path, dir->path); @@ -972,10 +992,12 @@ have_eltorito_entry: continue; } - cdrom_image_viso_log("[%08X] %s => [%-12s] %s\n", entry, dir->path, entry->name_short, entry->basename); + image_viso_log(viso->tf.log, "[%08X] %s => [%-12s] %s\n", entry, + dir->path, entry->name_short, entry->basename); } } else { - cdrom_image_viso_log("VISO: Failed to enumerate [%s], will be empty\n", dir->path); + image_viso_log(viso->tf.log, "Failed to enumerate [%s], will be empty\n", + dir->path); } /* Add terminator. */ @@ -1129,13 +1151,17 @@ next_dir: /* Write El Torito boot descriptor. This is an awkward spot for that, but the spec requires it to be the second descriptor. */ if (!i && eltorito_entry) { - cdrom_image_viso_log("VISO: Writing El Torito boot descriptor for entry [%08X]\n", eltorito_entry); + image_viso_log(viso->tf.log, "Writing El Torito boot descriptor for " + "entry [%08X]\n", eltorito_entry); p = data; if (!(viso->format & VISO_FORMAT_ISO)) - VISO_LBE_32(p, ftello64(viso->tf.fp) / viso->sector_size); /* sector offset (HSF only) */ - *p++ = 0; /* type */ - memcpy(p, (viso->format & VISO_FORMAT_ISO) ? "CD001" : "CDROM", 5); /* standard ID */ + /* Sector offset (HSF only). */ + VISO_LBE_32(p, ftello64(viso->tf.fp) / viso->sector_size); + /* Type. */ + *p++ = 0; + /* Standard ID. */ + memcpy(p, (viso->format & VISO_FORMAT_ISO) ? "CD001" : "CDROM", 5); p += 5; *p++ = 1; /* version */ @@ -1236,7 +1262,7 @@ next_dir: /* Write each path table. */ for (int i = 0; i <= ((max_vd << 1) | 1); i++) { - cdrom_image_viso_log("VISO: Generating path table #%d:\n", i); + image_viso_log(viso->tf.log, "Generating path table #%d:\n", i); /* Save this path table's start offset. */ uint64_t pt_start = ftello64(viso->tf.fp); @@ -1257,7 +1283,9 @@ next_dir: continue; } - cdrom_image_viso_log("[%08X] %s => %s\n", dir, dir->path, ((i & 2) || (dir == viso->root_dir)) ? dir->basename : dir->name_short); + image_viso_log(viso->tf.log, "[%08X] %s => %s\n", dir, + dir->path, ((i & 2) || (dir == viso->root_dir)) ? dir->basename : + dir->name_short); /* Save this directory's path table index and offset. */ dir->pt_idx = pt_idx; @@ -1325,7 +1353,7 @@ next_dir: /* Write directory records for each type. */ int dir_type = VISO_DIR_CURRENT_ROOT; for (int i = 0; i <= max_vd; i++) { - cdrom_image_viso_log("VISO: Generating directory record set #%d:\n", i); + image_viso_log(viso->tf.log, "Generating directory record set #%d:\n", i); /* Go through directories. */ dir = viso->root_dir; @@ -1368,8 +1396,10 @@ next_dir: if ((entry == eltorito_entry) || (entry == eltorito_dir)) goto next_entry; - cdrom_image_viso_log("[%08X] %s => %s\n", entry, dir->path, - ((dir_type == VISO_DIR_PARENT) ? ".." : ((dir_type < VISO_DIR_PARENT) ? "." : (i ? entry->basename : entry->name_short)))); + image_viso_log(viso->tf.log, "[%08X] %s => %s\n", entry, dir->path, + ((dir_type == VISO_DIR_PARENT) ? ".." : + ((dir_type < VISO_DIR_PARENT) ? "." : + (i ? entry->basename : entry->name_short)))); /* Fill directory record. */ viso_fill_dir_record(data, entry, viso, dir_type); @@ -1436,7 +1466,8 @@ next_entry: /* Allocate entry map for sector->file lookups. */ size_t orig_sector_size = viso->sector_size; while (1) { - cdrom_image_viso_log("VISO: Allocating entry map for %zu %zu-byte sectors\n", viso->entry_map_size, viso->sector_size); + image_viso_log(viso->tf.log, "Allocating entry map for %zu %zu-byte sectors\n", + viso->entry_map_size, viso->sector_size); viso->entry_map = (viso_entry_t **) calloc(viso->entry_map_size, sizeof(viso_entry_t *)); if (viso->entry_map) { /* Successfully allocated. */ @@ -1477,7 +1508,7 @@ next_entry: viso->all_sectors = viso->metadata_sectors; /* Go through files, assigning sectors to them. */ - cdrom_image_viso_log("VISO: Assigning sectors to files:\n"); + image_viso_log(viso->tf.log, "Assigning sectors to files:\n"); size_t base_factor = viso->sector_size / orig_sector_size; viso_entry_t *prev_entry = viso->root_dir; viso_entry_t **entry_map_p = viso->entry_map; @@ -1522,7 +1553,8 @@ next_entry: size_t size = entry->stats.st_size / viso->sector_size; if (entry->stats.st_size % viso->sector_size) size++; /* round up to the next sector */ - cdrom_image_viso_log("[%08X] %s => %zu + %zu sectors\n", entry, entry->path, viso->all_sectors, size); + image_viso_log(viso->tf.log, "[%08X] %s => %zu + %zu sectors\n", entry, + entry->path, viso->all_sectors, size); /* Allocate sectors to this file. */ viso->all_sectors += size; @@ -1541,9 +1573,10 @@ next_entry: viso_pwrite(data, viso->vol_size_offsets[i], 8, 1, viso->tf.fp); /* Metadata processing is finished, read it back to memory. */ - cdrom_image_viso_log("VISO: Reading back %zu %zu-byte sectors of metadata\n", viso->metadata_sectors, viso->sector_size); + image_viso_log(viso->tf.log, "Reading back %zu %zu-byte sectors of metadata\n", + viso->metadata_sectors, viso->sector_size); viso->metadata = (uint8_t *) calloc(viso->metadata_sectors, viso->sector_size); - if (!viso->metadata) + if (viso->metadata == NULL) goto end; fseeko64(viso->tf.fp, 0, SEEK_SET); size_t metadata_size = viso->metadata_sectors * viso->sector_size; @@ -1554,7 +1587,7 @@ next_entry: /* We no longer need the temporary file; close and delete it. */ fclose(viso->tf.fp); viso->tf.fp = NULL; -#ifndef ENABLE_CDROM_IMAGE_VISO_LOG +#ifndef ENABLE_IMAGE_VISO_LOG remove(nvr_path(viso->tf.fn)); #endif @@ -1565,16 +1598,20 @@ end: /* Set the function pointers. */ viso->tf.priv = viso; if (!*error) { - cdrom_image_viso_log("VISO: Initialized\n"); + image_viso_log(viso->tf.log, "Initialized\n"); + viso->tf.read = viso_read; viso->tf.get_length = viso_get_length; viso->tf.close = viso_close; + return &viso->tf; } else { - cdrom_image_viso_log("VISO: Initialization failed\n"); - if (data) - free(data); - viso_close(&viso->tf); + if (viso != NULL) { + image_viso_log(viso->tf.log, "Initialization failed\n"); + if (data) + free(data); + viso_close(&viso->tf); + } return NULL; } } diff --git a/src/cdrom/cdrom_ioctl.c b/src/cdrom/cdrom_ioctl.c deleted file mode 100644 index 2bb691f30..000000000 --- a/src/cdrom/cdrom_ioctl.c +++ /dev/null @@ -1,267 +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. - * - * CD-ROM passthrough support. - * - * - * - * Authors: TheCollector1995, , - * Miran Grca, - * - * Copyright 2023 TheCollector1995. - * Copyright 2023 Miran Grca. - */ -#include -#include -#include -#include -#include -#include -#include -#define HAVE_STDARG_H -#include <86box/86box.h> -#include <86box/config.h> -#include <86box/path.h> -#include <86box/plat.h> -#include <86box/scsi_device.h> -#include <86box/cdrom.h> -#include <86box/plat_cdrom.h> - -#ifdef ENABLE_CDROM_IOCTL_LOG -int cdrom_ioctl_do_log = ENABLE_CDROM_IOCTL_LOG; - -void -cdrom_ioctl_log(const char *fmt, ...) -{ - va_list ap; - - if (cdrom_ioctl_do_log) { - va_start(ap, fmt); - pclog_ex(fmt, ap); - va_end(ap); - } -} -#else -# define cdrom_ioctl_log(fmt, ...) -#endif - -/* 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. */ -#define MSFtoLBA(m, s, f) ((((m * 60) + s) * 75) + f) - -static void -ioctl_get_track_info(cdrom_t *dev, uint32_t track, int end, track_info_t *ti) -{ - TMSF tmsf; - - plat_cdrom_get_audio_track_info(dev->local, end, track, &ti->number, &tmsf, &ti->attr); - - ti->m = tmsf.min; - ti->s = tmsf.sec; - ti->f = tmsf.fr; -} - -static void -ioctl_get_raw_track_info(cdrom_t *dev, int *num, raw_track_info_t *rti) -{ - plat_cdrom_get_raw_track_info(dev->local, num, rti); -} - -static void -ioctl_get_subchannel(cdrom_t *dev, uint32_t lba, subchannel_t *subc) -{ - TMSF rel_pos; - TMSF abs_pos; - - if ((dev->cd_status == CD_STATUS_PLAYING) || (dev->cd_status == CD_STATUS_PAUSED)) { - const uint32_t trk = plat_cdrom_get_track_start(dev->local, lba, &subc->attr, &subc->track); - - FRAMES_TO_MSF(lba + 150, &abs_pos.min, &abs_pos.sec, &abs_pos.fr); - - /* Absolute position should be adjusted by 150, not the relative ones. */ - FRAMES_TO_MSF(lba - trk, &rel_pos.min, &rel_pos.sec, &rel_pos.fr); - - subc->index = 1; - } else - plat_cdrom_get_audio_sub(dev->local, lba, &subc->attr, &subc->track, &subc->index, - &rel_pos, &abs_pos); - - subc->abs_m = abs_pos.min; - subc->abs_s = abs_pos.sec; - subc->abs_f = abs_pos.fr; - - subc->rel_m = rel_pos.min; - subc->rel_s = rel_pos.sec; - subc->rel_f = rel_pos.fr; - - cdrom_ioctl_log("ioctl_get_subchannel(): %02X, %02X, %02i, %02i:%02i:%02i, %02i:%02i:%02i\n", - subc->attr, subc->track, subc->index, subc->abs_m, subc->abs_s, subc->abs_f, - subc->rel_m, subc->rel_s, subc->rel_f); -} - -static int -ioctl_get_capacity(cdrom_t *dev) -{ - int ret; - - ret = plat_cdrom_get_last_block(dev->local); - cdrom_ioctl_log("GetCapacity=%x.\n", ret); - return ret; -} - -static int -ioctl_is_track_audio(cdrom_t *dev, uint32_t pos, int ismsf) -{ - int m; - int s; - int f; - - if (dev->cd_status == CD_STATUS_DATA_ONLY) - return 0; - - if (ismsf) { - m = (pos >> 16) & 0xff; - s = (pos >> 8) & 0xff; - f = pos & 0xff; - pos = MSFtoLBA(m, s, f) - 150; - } - - /* GetTrack requires LBA. */ - return plat_cdrom_is_track_audio(dev->local, pos); -} - -static int -ioctl_is_track_pre(cdrom_t *dev, uint32_t lba) -{ - return plat_cdrom_is_track_pre(dev->local, lba); -} - -static int -ioctl_sector_size(cdrom_t *dev, uint32_t lba) -{ - cdrom_ioctl_log("LBA=%x.\n", lba); - return plat_cdrom_get_sector_size(dev->local, lba); -} - -static int -ioctl_read_sector(cdrom_t *dev, uint8_t *b, uint32_t lba) -{ - cdrom_ioctl_log("cdrom_ioctl_read_sector(): Raw.\n"); - return plat_cdrom_read_sector(dev->local, b, lba); -} - -static int -ioctl_track_type(cdrom_t *dev, uint32_t lba) -{ - int ret = CD_TRACK_UNK_DATA; - - if (ioctl_is_track_audio(dev, lba, 0)) - ret = CD_TRACK_AUDIO; - - cdrom_ioctl_log("cdrom_ioctl_track_type(): %i\n", ret); - - return ret; -} - -static int -ioctl_ext_medium_changed(cdrom_t *dev) -{ - int ret; - - if ((dev->cd_status == CD_STATUS_PLAYING) || (dev->cd_status == CD_STATUS_PAUSED)) - ret = 0; - else - ret = plat_cdrom_ext_medium_changed(dev->local); - - if (ret == 1) { - dev->cd_status = CD_STATUS_STOPPED; - dev->cdrom_capacity = ioctl_get_capacity(dev); - } else if (ret == -1) - dev->cd_status = CD_STATUS_EMPTY; - - return ret; -} - -static void -ioctl_exit(cdrom_t *dev) -{ - cdrom_ioctl_log("CDROM: ioctl_exit(%s)\n", dev->image_path); - dev->cd_status = CD_STATUS_EMPTY; - - plat_cdrom_close(dev->local); - dev->local = NULL; - - dev->ops = NULL; -} - -static const cdrom_ops_t cdrom_ioctl_ops = { - ioctl_get_track_info, - ioctl_get_raw_track_info, - ioctl_get_subchannel, - ioctl_is_track_pre, - ioctl_sector_size, - ioctl_read_sector, - ioctl_track_type, - ioctl_ext_medium_changed, - ioctl_exit -}; - -static int -cdrom_ioctl_open_abort(cdrom_t *dev) -{ - cdrom_ioctl_close(dev); - dev->ops = NULL; - dev->image_path[0] = 0; - return 1; -} - -int -cdrom_ioctl_open(cdrom_t *dev, const char *drv) -{ - const char *actual_drv = &(drv[8]); - int local_size = plat_cdrom_get_local_size(); - - /* Make sure to not STRCPY if the two are pointing - at the same place. */ - if (drv != dev->image_path) - strcpy(dev->image_path, drv); - - /* Open the image. */ - if (strstr(drv, "ioctl://") != drv) - return cdrom_ioctl_open_abort(dev); - cdrom_ioctl_log("actual_drv = %s\n", actual_drv); - if (dev->local == NULL) - dev->local = calloc(1, local_size); - int i = plat_cdrom_set_drive(dev->local, actual_drv); - if (!i) - return cdrom_ioctl_open_abort(dev); - - /* All good, reset state. */ - dev->cd_status = CD_STATUS_STOPPED; - dev->seek_pos = 0; - dev->cd_buflen = 0; - dev->cdrom_capacity = ioctl_get_capacity(dev); - cdrom_ioctl_log("CD-ROM capacity: %i sectors (%" PRIi64 " bytes)\n", - dev->cdrom_capacity, ((uint64_t) dev->cdrom_capacity) << 11ULL); - - /* Attach this handler to the drive. */ - dev->ops = &cdrom_ioctl_ops; - - return 0; -} - -void -cdrom_ioctl_close(cdrom_t *dev) -{ - cdrom_ioctl_log("CDROM: ioctl_close(%s)\n", dev->image_path); - - if (dev && dev->ops && dev->ops->exit) - dev->ops->exit(dev); -} - diff --git a/src/cdrom/cdrom_mitsumi.c b/src/cdrom/cdrom_mitsumi.c index 0cebfe7f6..e27faab94 100644 --- a/src/cdrom/cdrom_mitsumi.c +++ b/src/cdrom/cdrom_mitsumi.c @@ -118,14 +118,6 @@ typedef struct mcd_t { int newstat; } mcd_t; -/* 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)) #define CD_DCB(x) ((((x) &0xf0) >> 4) * 10 + ((x) &0x0f)) @@ -156,9 +148,9 @@ mitsumi_cdrom_is_ready(const cdrom_t *dev) static void mitsumi_cdrom_reset(mcd_t *dev) { - cdrom_t cdrom; - - dev->stat = mitsumi_cdrom_is_ready(&cdrom) ? (STAT_READY | STAT_CHANGE) : 0; + cdrom_t *cdrom = calloc(1, sizeof(cdrom_t)); + + dev->stat = mitsumi_cdrom_is_ready(cdrom) ? (STAT_READY | STAT_CHANGE) : 0; dev->cmdrd_count = 0; dev->cmdbuf_count = 0; dev->buf_count = 0; @@ -176,12 +168,12 @@ mitsumi_cdrom_reset(mcd_t *dev) static int mitsumi_cdrom_read_sector(mcd_t *dev, int first) { - cdrom_t cdrom; + cdrom_t *cdrom = calloc(1, sizeof(cdrom_t)); uint8_t status; - int ret; + int ret = 0; if (dev->drvmode == DRV_MODE_CDDA) { - status = cdrom_mitsumi_audio_play(&cdrom, dev->readmsf, dev->readcount); + status = cdrom_mitsumi_audio_play(cdrom, dev->readmsf, dev->readcount); if (status == 1) return status; else @@ -195,15 +187,15 @@ mitsumi_cdrom_read_sector(mcd_t *dev, int first) dev->data = 0; return 0; } - cdrom_stop(&cdrom); - ret = cdrom_readsector_raw(&cdrom, dev->buf, cdrom.seek_pos, 0, 2, 0x10, (int *) &dev->readcount, 0); + cdrom_stop(cdrom); + ret = cdrom_readsector_raw(cdrom, dev->buf, cdrom->seek_pos, 0, 2, 0x10, (int *) &dev->readcount, 0); if (ret <= 0) return 0; if (dev->mode & 0x40) { dev->buf[12] = CD_BCD((dev->readmsf >> 16) & 0xff); dev->buf[13] = CD_BCD((dev->readmsf >> 8) & 0xff); } - dev->readmsf = cdrom_lba_to_msf_accurate(cdrom.seek_pos + 1); + dev->readmsf = cdrom_lba_to_msf_accurate(cdrom->seek_pos + 1); dev->buf_count = dev->dmalen + 1; dev->buf_idx = 0; dev->data = 1; @@ -224,7 +216,7 @@ static uint8_t mitsumi_cdrom_in(uint16_t port, void *priv) { mcd_t *dev = (mcd_t *) priv; - uint8_t ret; + uint8_t ret = 0xff; pclog("Mitsumi CD-ROM IN=%03x\n", port); switch (port & 1) { @@ -259,14 +251,14 @@ mitsumi_cdrom_in(uint16_t port, void *priv) break; } - return 0xff; + return ret; } static void mitsumi_cdrom_out(uint16_t port, uint8_t val, void *priv) { mcd_t *dev = (mcd_t *) priv; - cdrom_t cdrom; + cdrom_t *cdrom = calloc(1, sizeof(cdrom_t)); pclog("Mitsumi CD-ROM OUT=%03x, val=%02x\n", port, val); switch (port & 1) { @@ -348,19 +340,19 @@ mitsumi_cdrom_out(uint16_t port, uint8_t val, void *priv) break; } if (!dev->cmdrd_count) - dev->stat = mitsumi_cdrom_is_ready(&cdrom) ? (STAT_READY | (dev->change ? STAT_CHANGE : 0)) : 0; + dev->stat = mitsumi_cdrom_is_ready(cdrom) ? (STAT_READY | (dev->change ? STAT_CHANGE : 0)) : 0; return; } dev->cmd = val; dev->cmdbuf_idx = 0; dev->cmdrd_count = 0; dev->cmdbuf_count = 1; - dev->cmdbuf[0] = mitsumi_cdrom_is_ready(&cdrom) ? (STAT_READY | (dev->change ? STAT_CHANGE : 0)) : 0; + dev->cmdbuf[0] = mitsumi_cdrom_is_ready(cdrom) ? (STAT_READY | (dev->change ? STAT_CHANGE : 0)) : 0; dev->data = 0; switch (val) { case CMD_GET_INFO: - if (mitsumi_cdrom_is_ready(&cdrom)) { - cdrom_get_track_buffer(&cdrom, &(dev->cmdbuf[1])); + if (mitsumi_cdrom_is_ready(cdrom)) { + cdrom_get_track_buffer(cdrom, &(dev->cmdbuf[1])); dev->cmdbuf_count = 10; dev->readcount = 0; } else { @@ -369,8 +361,8 @@ mitsumi_cdrom_out(uint16_t port, uint8_t val, void *priv) } break; case CMD_GET_Q: - if (mitsumi_cdrom_is_ready(&cdrom)) { - cdrom_get_q(&cdrom, &(dev->cmdbuf[1]), &dev->cur_toc_track, dev->mode & MODE_GET_TOC); + if (mitsumi_cdrom_is_ready(cdrom)) { + cdrom_get_q(cdrom, &(dev->cmdbuf[1]), &dev->cur_toc_track, dev->mode & MODE_GET_TOC); dev->cmdbuf_count = 11; dev->readcount = 0; } else { @@ -386,7 +378,7 @@ mitsumi_cdrom_out(uint16_t port, uint8_t val, void *priv) break; case CMD_STOPCDDA: case CMD_STOP: - cdrom_stop(&cdrom); + cdrom_stop(cdrom); dev->drvmode = DRV_MODE_STOP; dev->cur_toc_track = 0; break; @@ -395,7 +387,7 @@ mitsumi_cdrom_out(uint16_t port, uint8_t val, void *priv) break; case CMD_READ1X: case CMD_READ2X: - if (mitsumi_cdrom_is_ready(&cdrom)) { + if (mitsumi_cdrom_is_ready(cdrom)) { dev->readcount = 0; dev->drvmode = (val == CMD_READ1X) ? DRV_MODE_CDDA : DRV_MODE_READ; dev->cmdrd_count = 6; @@ -411,7 +403,7 @@ mitsumi_cdrom_out(uint16_t port, uint8_t val, void *priv) dev->cmdbuf_count = 3; break; case CMD_EJECT: - cdrom_stop(&cdrom); + cdrom_stop(cdrom); cdrom_eject(0); dev->readcount = 0; break; @@ -440,10 +432,7 @@ mitsumi_cdrom_out(uint16_t port, uint8_t val, void *priv) static void * mitsumi_cdrom_init(UNUSED(const device_t *info)) { - mcd_t *dev; - - dev = malloc(sizeof(mcd_t)); - memset(dev, 0x00, sizeof(mcd_t)); + mcd_t *dev = calloc(1, sizeof(mcd_t)); dev->irq = MCD_DEFAULT_IRQ; dev->dma = MCD_DEFAULT_DMA; @@ -470,12 +459,12 @@ mitsumi_cdrom_close(void *priv) const device_t mitsumi_cdrom_device = { .name = "Mitsumi CD-ROM interface", .internal_name = "mcd", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 1, + .flags = DEVICE_ISA16, + .local = 0, .init = mitsumi_cdrom_init, .close = mitsumi_cdrom_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/82c100.c b/src/chipset/82c100.c index 689234ebb..a9d61b3b9 100644 --- a/src/chipset/82c100.c +++ b/src/chipset/82c100.c @@ -358,8 +358,7 @@ ct_82c100_init(UNUSED(const device_t *info)) { ct_82c100_t *dev; - dev = (ct_82c100_t *) malloc(sizeof(ct_82c100_t)); - memset(dev, 0x00, sizeof(ct_82c100_t)); + dev = (ct_82c100_t *) calloc(1, sizeof(ct_82c100_t)); ct_82c100_reset(dev); @@ -393,7 +392,7 @@ const device_t ct_82c100_device = { .init = ct_82c100_init, .close = ct_82c100_close, .reset = ct_82c100_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/CMakeLists.txt b/src/chipset/CMakeLists.txt index 6018dd045..d61b5c53d 100644 --- a/src/chipset/CMakeLists.txt +++ b/src/chipset/CMakeLists.txt @@ -17,7 +17,9 @@ add_library(chipset OBJECT 82c100.c + acc2036.c acc2168.c + cs8220.c cs8230.c ali1429.c ali1435.c @@ -39,12 +41,15 @@ add_library(chipset OBJECT intel_i450kx.c intel_sio.c intel_piix.c + isa486c.c ../ioapic.c neat.c + olivetti_eva.c opti283.c opti291.c opti391.c opti495.c + opti498.c opti499.c opti602.c opti822.c @@ -71,6 +76,7 @@ add_library(chipset OBJECT sis_5572_usb.c sis_5595_pmu.c sis_55xx.c + sl82c461.c via_vt82c49x.c via_vt82c505.c gc100.c @@ -83,7 +89,3 @@ add_library(chipset OBJECT vl82c480.c wd76c10.c ) - -if(OLIVETTI) - target_sources(chipset PRIVATE olivetti_eva.c) -endif() diff --git a/src/chipset/acc2036.c b/src/chipset/acc2036.c new file mode 100644 index 000000000..3984f82e0 --- /dev/null +++ b/src/chipset/acc2036.c @@ -0,0 +1,346 @@ +/* + * 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 ACC 2036 chipset. + * + * Authors: Miran Grca, + * + * Copyright 2025 Miran Grca. + */ +#include +#include +#include +#include +#include +#include +#include <86box/86box.h> +#include "cpu.h" +#include <86box/timer.h> +#include <86box/io.h> +#include <86box/device.h> +#include <86box/machine.h> +#include <86box/mem.h> +#include <86box/port_92.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> +#include <86box/fdd.h> +#include <86box/fdc.h> +#include <86box/chipset.h> + +typedef struct { + uint32_t virt; + uint32_t phys; + + mem_mapping_t mapping; +} ram_page_t; + +typedef struct { + uint8_t reg; + uint8_t regs[32]; + + ram_page_t ram_mid_pages[24]; + ram_page_t ems_pages[4]; +} acc2036_t; + +static uint8_t +acc2036_mem_read(uint32_t addr, void *priv) +{ + ram_page_t *dev = (ram_page_t *) priv; + uint8_t ret = 0xff; + + addr = (addr - dev->virt) + dev->phys; + + if (addr < (mem_size << 10)) + ret = ram[addr]; + + return ret; +} + +static uint16_t +acc2036_mem_readw(uint32_t addr, void *priv) +{ + ram_page_t *dev = (ram_page_t *) priv; + uint16_t ret = 0xffff; + + addr = (addr - dev->virt) + dev->phys; + + if (addr < (mem_size << 10)) + ret = *(uint16_t *) &(ram[addr]); + + return ret; +} + +static void +acc2036_mem_write(uint32_t addr, uint8_t val, void *priv) +{ + ram_page_t *dev = (ram_page_t *) priv; + + addr = (addr - dev->virt) + dev->phys; + + if (addr < (mem_size << 10)) + ram[addr] = val; +} + +static void +acc2036_mem_writew(uint32_t addr, uint16_t val, void *priv) +{ + ram_page_t *dev = (ram_page_t *) priv; + + addr = (addr - dev->virt) + dev->phys; + + if (addr < (mem_size << 10)) + *(uint16_t *) &(ram[addr]) = val; +} + +static void +acc2036_recalc(acc2036_t *dev) +{ + uint32_t ems_bases[4] = { 0x000c0000, 0x000c8000, 0x000d0000, 0x000e0000 }; + + int start_i = (ems_bases[dev->regs[0x0c] & 0x03] - 0x000a0000) >> 14; + int end_i = start_i + 3; + + for (int i = 0; i < 24; i++) { + ram_page_t *rp = &dev->ram_mid_pages[i]; + mem_mapping_disable(&rp->mapping); + } + + for (int i = 0; i < 4; i++) { + ram_page_t *ep = &dev->ems_pages[i]; + mem_mapping_disable(&ep->mapping); + } + + for (int i = 0; i < 24; i++) { + ram_page_t *rp = &dev->ram_mid_pages[i]; + + if ((dev->regs[0x03] & 0x08) && (i >= start_i) && (i <= end_i)) { + /* EMS */ + ram_page_t *ep = &dev->ems_pages[i - start_i]; + + mem_mapping_disable(&rp->mapping); + mem_mapping_set_addr(&ep->mapping, ep->virt, 0x000040000); + mem_mapping_set_exec(&ep->mapping, ram + ep->phys); + mem_set_mem_state_both(ep->virt, 0x00004000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + } else { + int master_write; + int master_read; + int bit; + int ew_flag; + int er_flag; + int flags; + uint8_t val; + + mem_mapping_set_addr(&rp->mapping, rp->virt, 0x000040000); + mem_mapping_set_exec(&rp->mapping, ram + rp->phys); + + if ((i >= 8) && (i <= 15)) { + /* 0C0000-0DFFFF */ + master_write = dev->regs[0x02] & 0x08; + master_read = dev->regs[0x02] & 0x04; + bit = ((i - 8) >> 1); + val = dev->regs[0x0d] & (1 << bit); + if (i >= 12) { + ew_flag = (dev->regs[0x07] & 0x80) ? MEM_WRITE_EXTANY : MEM_WRITE_EXTERNAL; + er_flag = (dev->regs[0x07] & 0x80) ? MEM_READ_EXTANY : MEM_READ_EXTERNAL; + } else { + ew_flag = (dev->regs[0x07] & 0x40) ? MEM_WRITE_EXTANY : MEM_WRITE_EXTERNAL; + er_flag = (dev->regs[0x07] & 0x40) ? MEM_READ_EXTANY : MEM_READ_EXTERNAL; + } + flags = (val && master_write) ? MEM_WRITE_INTERNAL : ew_flag; + flags |= (val && master_read) ? MEM_READ_INTERNAL : er_flag; + mem_set_mem_state_both(rp->virt, 0x00004000, flags); + } else if (i > 15) { + /* 0E0000-0FFFFF */ + master_write = dev->regs[0x02] & 0x02; + master_read = dev->regs[0x02] & 0x01; + bit = ((i - 8) >> 2); + val = dev->regs[0x0c] & (1 << bit); + if (i >= 20) { + ew_flag = MEM_WRITE_EXTANY; + er_flag = MEM_READ_EXTANY; + } else { + ew_flag = (dev->regs[0x0c] & 0x10) ? MEM_WRITE_EXTANY : MEM_WRITE_EXTERNAL; + er_flag = (dev->regs[0x0c] & 0x10) ? MEM_READ_EXTANY : MEM_READ_EXTERNAL; + } + flags = (val && master_write) ? MEM_WRITE_INTERNAL : ew_flag; + flags |= (val && master_read) ? MEM_READ_INTERNAL : er_flag; + mem_set_mem_state_both(rp->virt, 0x00004000, flags); + } + } + } + + if (dev->regs[0x00] & 0x40) + mem_set_mem_state_both(0x00fe0000, 0x00010000, MEM_READ_EXTANY | MEM_WRITE_EXTANY); + else + mem_set_mem_state_both(0x00fe0000, 0x00010000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + + for (int i = 0x01; i <= 0x06; i++) { + uint32_t base = 0x00fe0000 - (i * 0x00010000); + + if (dev->regs[i] & 0x40) + mem_set_mem_state_both(base, 0x00008000, MEM_READ_EXTANY | MEM_WRITE_EXTANY); + else + mem_set_mem_state_both(base, 0x00008000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + + if (dev->regs[i] & 0x80) + mem_set_mem_state_both(base + 0x00008000, 0x00008000, MEM_READ_EXTANY | MEM_WRITE_EXTANY); + else + mem_set_mem_state_both(base + 0x00008000, 0x00008000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + } + + mem_remap_top(0); + if (dev->regs[0x03] & 0x10) { + if (dev->regs[0x02] & 0x0c) + mem_remap_top(128); + else if (dev->regs[0x02] & 0x03) + mem_remap_top(256); + else + mem_remap_top(384); + } + + flushmmucache_nopc(); +} + +static uint8_t +acc2036_in(uint16_t port, void *priv) { + acc2036_t *dev = (acc2036_t *) priv; + uint8_t reg = dev->reg - 0x20; + uint8_t ret = 0xff; + + if (port & 0x0001) switch (dev->reg) { + default: + break; + case 0x20 ... 0x2e: + case 0x31 ... 0x3f: + ret = dev->regs[reg]; + break; + } else + ret = dev->reg; + + return ret; +} + +static void +acc2036_out(uint16_t port, uint8_t val, void *priv) { + acc2036_t *dev = (acc2036_t *) priv; + uint8_t reg = dev->reg - 0x20; + + if (port & 0x0001) switch (dev->reg) { + default: + break; + case 0x20 ... 0x23: + dev->regs[reg] = val; + acc2036_recalc(dev); + break; + case 0x24 ... 0x2b: + dev->regs[reg] = val; + dev->ems_pages[(reg - 0x04) >> 1].phys = ((dev->regs[reg & 0xfe] & 0x1f) << 19) | + ((dev->regs[reg | 0x01] & 0x1f) << 14); + acc2036_recalc(dev); + break; + case 0x2c: case 0x2d: + dev->regs[reg] = val; + acc2036_recalc(dev); + break; + case 0x2e: + dev->regs[reg] = val | 0x10; + break; + case 0x31: + dev->regs[reg] = val; + mem_a20_alt = (val & 0x01); + mem_a20_recalc(); + flushmmucache(); + if (val & 0x02) { + softresetx86(); /* Pulse reset! */ + cpu_set_edx(); + flushmmucache(); + } + break; + case 0x32 ... 0x3f: + dev->regs[reg] = val; + break; + } else + dev->reg = val; +} + +static void +acc2036_close(void *priv) +{ + acc2036_t *dev = (acc2036_t *) priv; + + free(dev); +} + +static void * +acc2036_init(UNUSED(const device_t *info)) +{ + acc2036_t *dev = (acc2036_t *) calloc(1, sizeof(acc2036_t)); + + for (int i = 0; i < 24; i++) { + ram_page_t *rp = &dev->ram_mid_pages[i]; + + rp->virt = 0x000a0000 + (i << 14); + rp->phys = 0x000a0000 + (i << 14); + mem_mapping_add(&rp->mapping, rp->virt, 0x00004000, + acc2036_mem_read, acc2036_mem_readw, NULL, + acc2036_mem_write, acc2036_mem_writew, NULL, + ram + rp->phys, MEM_MAPPING_INTERNAL, rp); + } + + for (int i = 0; i < 4; i++) { + ram_page_t *ep = &dev->ems_pages[i]; + + ep->virt = 0x000d0000 + (i << 14); + ep->phys = 0x00000000 + (i << 14); + mem_mapping_add(&ep->mapping, ep->virt, 0x00004000, + acc2036_mem_read, acc2036_mem_readw, NULL, + acc2036_mem_write, acc2036_mem_writew, NULL, + ram + ep->phys, MEM_MAPPING_INTERNAL, ep); + mem_mapping_disable(&ep->mapping); + } + + mem_mapping_disable(&ram_mid_mapping); + + dev->regs[0x00] = 0x02; + dev->regs[0x0e] = 0x10; + dev->regs[0x11] = 0x01; + dev->regs[0x13] = 0x40; + dev->regs[0x15] = 0x40; + dev->regs[0x17] = 0x40; + dev->regs[0x19] = 0x40; + dev->regs[0x1b] = 0x40; + dev->regs[0x1c] = 0x22; + dev->regs[0x1d] = 0xc4; + dev->regs[0x1f] = 0x30; + acc2036_recalc(dev); + + mem_a20_alt = 0x01; + mem_a20_recalc(); + flushmmucache(); + + io_sethandler(0x00f2, 0x0002, + acc2036_in, NULL, NULL, acc2036_out, NULL, NULL, dev); + + device_add(&port_92_device); + + return dev; +} + +const device_t acc2036_device = { + .name = "ACC 2036", + .internal_name = "acc2036", + .flags = 0, + .local = 0, + .init = acc2036_init, + .close = acc2036_close, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; diff --git a/src/chipset/acc2168.c b/src/chipset/acc2168.c index 9ce29bdff..dbbdc99f6 100644 --- a/src/chipset/acc2168.c +++ b/src/chipset/acc2168.c @@ -184,8 +184,7 @@ acc2168_close(void *priv) static void * acc2168_init(UNUSED(const device_t *info)) { - acc2168_t *dev = (acc2168_t *) malloc(sizeof(acc2168_t)); - memset(dev, 0, sizeof(acc2168_t)); + acc2168_t *dev = (acc2168_t *) calloc(1, sizeof(acc2168_t)); device_add(&port_92_device); io_sethandler(0x00f2, 0x0002, acc2168_read, NULL, NULL, acc2168_write, NULL, NULL, dev); @@ -201,7 +200,7 @@ const device_t acc2168_device = { .init = acc2168_init, .close = acc2168_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/ali1409.c b/src/chipset/ali1409.c index 3e4286f80..619843cda 100644 --- a/src/chipset/ali1409.c +++ b/src/chipset/ali1409.c @@ -40,9 +40,8 @@ #include <86box/fdc.h> #include <86box/smram.h> #include <86box/chipset.h> - +#include <86box/plat_unused.h> - #ifdef ENABLE_ALI1409_LOG int ali1409_do_log = ENABLE_ALI1409_LOG; @@ -62,91 +61,238 @@ ali1409_log(const char *fmt, ...) #endif typedef struct ali_1409_t { - uint8_t is_g; uint8_t index; uint8_t cfg_locked; - uint8_t reg_57h; uint8_t regs[256]; + uint8_t shadow[4]; uint8_t last_reg; } ali1409_t; +/* + This here is because from the two BIOS'es I used to reverse engineer this, + it is unclear which of the two interpretations of the shadow RAM register + operation is correct. + The 16 kB interpretation appears to work fine right now but it may be wrong, + so I left the 32 kB interpretation in as well. + */ +#ifdef INTERPRETATION_32KB +#define SHADOW_SIZE 0x00008000 +#else +#define SHADOW_SIZE 0x00004000 +#endif + +static void +ali1409_shadow_recalc(ali1409_t *dev) +{ + uint32_t base = 0x000c0000; + + for (uint8_t i = 0; i < 4; i++) { + uint8_t reg = 0x08 + i; + +#ifdef INTERPRETATION_32KB + for (uint8_t j = 0; j < 4; j += 2) { + uint8_t mask = (0x03 << j); +#else + for (uint8_t j = 0; j < 4; j++) { + uint8_t mask = (0x01 << j); +#endif + uint8_t r_on = dev->regs[reg] & 0x10; + uint8_t w_on = dev->regs[reg] & 0x20; + uint8_t val = dev->regs[reg] & mask; + uint8_t xor = (dev->shadow[i] ^ dev->regs[reg]) & (mask | 0x30); + int read = r_on ? MEM_READ_INTERNAL : MEM_READ_EXTANY; + int write = w_on ? MEM_WRITE_INTERNAL : MEM_WRITE_EXTANY; + + if (xor) { +#ifdef INTERPRETATION_32KB + switch (val >> j) { + case 0x00: + mem_set_mem_state_both(base, SHADOW_SIZE, MEM_READ_EXTANY | MEM_WRITE_EXTANY); + break; + case 0x01: + mem_set_mem_state_both(base, SHADOW_SIZE, MEM_READ_EXTANY | write); + break; + case 0x02: + mem_set_mem_state_both(base, SHADOW_SIZE, read | write); + break; + case 0x03: + mem_set_mem_state_both(base, SHADOW_SIZE, read | MEM_WRITE_EXTANY); + break; + } +#else + switch (val >> j) { + case 0x00: + mem_set_mem_state_both(base, SHADOW_SIZE, MEM_READ_EXTANY | MEM_WRITE_EXTANY); + break; + case 0x01: + mem_set_mem_state_both(base, SHADOW_SIZE, read | write); + break; + } +#endif + } + + base += SHADOW_SIZE; + } + + dev->shadow[i] = dev->regs[reg]; + } + + flushmmucache_nopc(); +} static void ali1409_write(uint16_t addr, uint8_t val, void *priv) { ali1409_t *dev = (ali1409_t *) priv; - ali1409_log ("INPUT:addr %02x ,Value %02x \n" , addr , val); + ali1409_log("[%04X:%08X] [W] %04X = %02X\n", CS, cpu_state.pc, addr, val); - if (addr & 1) { - if (dev->cfg_locked) { - if (dev->last_reg == 0x14 && val == 0x09) - dev->cfg_locked = 0; + if (addr & 0x0001) { + if (dev->cfg_locked) { + if ((dev->last_reg == 0x14) && (val == 0x09)) + dev->cfg_locked = 0; - dev->last_reg = val; - return; - } + dev->last_reg = val; + return; + } - if (dev->index == 0xff && val == 0xff) - dev->cfg_locked = 1; - else { - ali1409_log("Write reg %02x %02x %08x\n", dev->index, val, cs); - dev->regs[dev->index] = val; + /* It appears writing anything at all to register 0xFF locks it again. */ + if (dev->index == 0xff) + dev->cfg_locked = 1; + else if (dev->index < 0x44) { + ali1409_log("[%04X:%08X] [W] Register %02X = %02X\n", CS, cpu_state.pc, dev->index, val); - switch (dev->index) { - case 0xa: - switch ((val >> 4) & 3) { - case 0: - mem_set_mem_state(0xe0000, 0x10000, MEM_READ_EXTERNAL | MEM_WRITE_EXTERNAL); - break; - case 1: - mem_set_mem_state(0xe0000, 0x10000, MEM_READ_INTERNAL | MEM_WRITE_EXTERNAL); - break; - case 2: - mem_set_mem_state(0xe0000, 0x10000, MEM_READ_EXTERNAL | MEM_WRITE_INTERNAL); - break; - case 3: - mem_set_mem_state(0xe0000, 0x10000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); - break; - } + if (dev->index < 0x10) { + dev->regs[dev->index] = val; + + /* + There are still a lot of unknown here, but unfortunately, this is + as far as I have been able to come with two BIOS'es that are + available (the Acer 100T and an AMI Color dated 07/07/91). + */ + switch (dev->index) { + case 0x02: + /* + - Bit 7: The RAS address hold time: + - 0: 1/2 T; + - 1: 1 T. + - Bits 6-4: The RAS precharge time: + - 0, 0, 0: 1.5 T; + - 0, 0, 1: 2 T; + - 0, 1, 0: 2.5 T; + - 0, 1, 1: 3 T; + - 1, 0, 0: 3.5 T; + - 1, 0, 1: 4 T; + - 1, 1, 0: Reserved; + - 1, 1, 1: Reserved. + - Bit 3: Early miss cycle: + - 0: Disabled; + - 1: Enabled. + */ + break; + case 0x03: + /* + - Bit 6: CAS pulse for read cycle: + - 0: 1 T; + - 1: 1.5 T or 2 T. + I can not get the 2.5 T or 3 T setting to apply so + I have no idea what bit governs that. + - Bits 5, 4: CAS pulse for write cycle: + - 0, 0: 0.5 T or 1 T; + - 0, 1: 1.5 T or 2 T; + - 1, 0: 2.5 T or 3 T; + - 1, 1: Reserved. + - Bit 3: CAS active for read cycle: + - 0: Disabled; + - 1: Enabled. + - Bit 2: CAS active for write cycle: + - 0: Disabled; + - 1: Enabled. + */ + break; + case 0x06: + /* + - Bits 6-4: Clock divider: + - 0, 0, 0: / 2; + - 0, 0, 1: / 4; + - 0, 1, 0: / 8; + - 0, 1, 1: Reserved; + - 1, 0, 0: / 3; + - 1, 0, 1: / 6; + - 1, 1, 0: / 5; + - 1, 1, 1: / 10. + */ + switch ((val >> 4) & 7) { + default: + case 3: /* Reserved */ + cpu_set_isa_speed(7159091); break; - case 0xb: - switch ((val >> 4) & 3) { - case 0: - mem_set_mem_state(0xf0000, 0x10000, MEM_READ_EXTANY | MEM_WRITE_EXTANY); - break; - case 1: - mem_set_mem_state(0xf0000, 0x10000, MEM_READ_INTERNAL | MEM_WRITE_EXTANY); - break; - case 2: - mem_set_mem_state(0xf0000, 0x10000, MEM_READ_EXTANY| MEM_WRITE_INTERNAL); - break; - case 3: - mem_set_mem_state(0xf0000, 0x10000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); - break; - } + + case 0: + cpu_set_isa_speed(cpu_busspeed / 2); + break; + + case 1: + cpu_set_isa_speed(cpu_busspeed / 4); + break; + + case 2: + cpu_set_isa_speed(cpu_busspeed / 8); + break; + + case 4: + cpu_set_isa_speed(cpu_busspeed / 3); + break; + + case 5: + cpu_set_isa_speed(cpu_busspeed / 6); + break; + + case 6: + cpu_set_isa_speed(cpu_busspeed / 5); + break; + + case 7: + cpu_set_isa_speed(cpu_busspeed / 10); break; } + break; + case 0x08 ... 0x0b: + ali1409_shadow_recalc(dev); + break; + case 0x0c: + /* + This appears to be turbo in bit 4 (1 = on, 0 = off), + and bus speed in the rest of the bits. + */ + break; + case 0x0d: + cpu_cache_ext_enabled = !!(val & 0x08); + cpu_update_waitstates(); + break; } - } else - dev->index = val; + } + } + } else + dev->index = val; } static uint8_t ali1409_read(uint16_t addr, void *priv) { - ali1409_log ("reading at %02X\n",addr); const ali1409_t *dev = (ali1409_t *) priv; uint8_t ret = 0xff; if (dev->cfg_locked) ret = 0xff; - if (addr & 1) { - if ((dev->index >= 0xc0 || dev->index == 0x20) && cpu_iscyrix) - ret = 0xff; + else if (addr & 0x0001) { + if (dev->index < 0x44) ret = dev->regs[dev->index]; - } else - ret = dev->index; + } else + ret = dev->index; + + ali1409_log("[%04X:%08X] [R] %04X = %02X\n", CS, cpu_state.pc, addr, ret); + return ret; } @@ -161,24 +307,22 @@ ali1409_close(void *priv) } static void * -ali1409_init(const device_t *info) +ali1409_init(UNUSED(const device_t *info)) { - ali1409_t *dev = (ali1409_t *) malloc(sizeof(ali1409_t)); - memset(dev, 0, sizeof(ali1409_t)); + ali1409_t *dev = (ali1409_t *) calloc(1, sizeof(ali1409_t)); dev->cfg_locked = 1; - /* M1409 Ports: - 22h Index Port - 23h Data Port - */ - - ali1409_log ("Bus speed: %i",cpu_busspeed); - + ali1409_log("Bus speed: %i\n", cpu_busspeed); io_sethandler(0x0022, 0x0002, ali1409_read, NULL, NULL, ali1409_write, NULL, NULL, dev); - io_sethandler(0x037f, 0x0001, ali1409_read, NULL, NULL, ali1409_write, NULL, NULL, dev); - io_sethandler(0x03f3, 0x0001, ali1409_read, NULL, NULL, ali1409_write, NULL, NULL, dev); + + dev->regs[0x0f] = 0x08; + + cpu_set_isa_speed(7159091); + + cpu_cache_ext_enabled = 0; + cpu_update_waitstates(); return dev; } @@ -191,7 +335,7 @@ const device_t ali1409_device = { .init = ali1409_init, .close = ali1409_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/ali1429.c b/src/chipset/ali1429.c index 34c3e18c2..e2478078f 100644 --- a/src/chipset/ali1429.c +++ b/src/chipset/ali1429.c @@ -331,8 +331,7 @@ ali1429_defaults(ali1429_t *dev) static void * ali1429_init(const device_t *info) { - ali1429_t *dev = (ali1429_t *) malloc(sizeof(ali1429_t)); - memset(dev, 0, sizeof(ali1429_t)); + ali1429_t *dev = (ali1429_t *) calloc(1, sizeof(ali1429_t)); dev->cfg_locked = 1; GREEN = info->local; @@ -358,7 +357,7 @@ const device_t ali1429_device = { .init = ali1429_init, .close = ali1429_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -372,7 +371,7 @@ const device_t ali1429g_device = { .init = ali1429_init, .close = ali1429_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/ali1435.c b/src/chipset/ali1435.c index 9476d2b45..ff096ac55 100644 --- a/src/chipset/ali1435.c +++ b/src/chipset/ali1435.c @@ -282,8 +282,7 @@ ali1435_close(void *priv) static void * ali1435_init(UNUSED(const device_t *info)) { - ali1435_t *dev = (ali1435_t *) malloc(sizeof(ali1435_t)); - memset(dev, 0, sizeof(ali1435_t)); + ali1435_t *dev = (ali1435_t *) calloc(1, sizeof(ali1435_t)); dev->cfg_locked = 1; @@ -308,7 +307,7 @@ const device_t ali1435_device = { .init = ali1435_init, .close = ali1435_close, .reset = ali1435_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/ali1489.c b/src/chipset/ali1489.c index 3550f1da6..fc51bbed2 100644 --- a/src/chipset/ali1489.c +++ b/src/chipset/ali1489.c @@ -470,8 +470,7 @@ ali1489_close(void *priv) static void * ali1489_init(UNUSED(const device_t *info)) { - ali1489_t *dev = (ali1489_t *) malloc(sizeof(ali1489_t)); - memset(dev, 0, sizeof(ali1489_t)); + ali1489_t *dev = (ali1489_t *) calloc(1, sizeof(ali1489_t)); /* M1487/M1489 22h Index Port @@ -499,7 +498,7 @@ const device_t ali1489_device = { .init = ali1489_init, .close = ali1489_close, .reset = ali1489_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/ali1531.c b/src/chipset/ali1531.c index 9eb75f7cd..53324f8e6 100644 --- a/src/chipset/ali1531.c +++ b/src/chipset/ali1531.c @@ -22,6 +22,7 @@ #include #define HAVE_STDARG_H #include <86box/86box.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/device.h> @@ -225,12 +226,8 @@ ali1531_write(UNUSED(int func), int addr, uint8_t val, void *priv) ali1531_shadow_recalc(val, dev); break; - case 0x50: - case 0x51: - case 0x52: - case 0x54: - case 0x55: - case 0x56: + case 0x50 ... 0x52: + case 0x54 ... 0x56: dev->pci_conf[addr] = val; break; @@ -247,8 +244,7 @@ ali1531_write(UNUSED(int func), int addr, uint8_t val, void *priv) dev->pci_conf[addr] = val & 0x86; break; - case 0x59: - case 0x5a: + case 0x59 ... 0x5a: case 0x5c: dev->pci_conf[addr] = val; break; @@ -270,8 +266,7 @@ ali1531_write(UNUSED(int func), int addr, uint8_t val, void *priv) spd_write_drbs_interleaved(dev->pci_conf, 0x60, 0x6f, 1); break; - case 0x70: - case 0x71: + case 0x70 ... 0x71: dev->pci_conf[addr] = val; break; @@ -283,8 +278,7 @@ ali1531_write(UNUSED(int func), int addr, uint8_t val, void *priv) dev->pci_conf[addr] = val & 0x2b; break; - case 0x76: - case 0x77: + case 0x76 ... 0x77: dev->pci_conf[addr] = val; break; @@ -376,8 +370,7 @@ ali1531_close(void *priv) static void * ali1531_init(UNUSED(const device_t *info)) { - ali1531_t *dev = (ali1531_t *) malloc(sizeof(ali1531_t)); - memset(dev, 0, sizeof(ali1531_t)); + ali1531_t *dev = (ali1531_t *) calloc(1, sizeof(ali1531_t)); pci_add_card(PCI_ADD_NORTHBRIDGE, ali1531_read, ali1531_write, dev, &dev->pci_slot); @@ -396,7 +389,7 @@ const device_t ali1531_device = { .init = ali1531_init, .close = ali1531_close, .reset = ali1531_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/ali1541.c b/src/chipset/ali1541.c index d57ef51e7..ebbcd7e63 100644 --- a/src/chipset/ali1541.c +++ b/src/chipset/ali1541.c @@ -22,6 +22,7 @@ #include #define HAVE_STDARG_H #include <86box/86box.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/device.h> @@ -643,8 +644,7 @@ ali1541_close(void *priv) static void * ali1541_init(UNUSED(const device_t *info)) { - ali1541_t *dev = (ali1541_t *) malloc(sizeof(ali1541_t)); - memset(dev, 0, sizeof(ali1541_t)); + ali1541_t *dev = (ali1541_t *) calloc(1, sizeof(ali1541_t)); pci_add_card(PCI_ADD_NORTHBRIDGE, ali1541_read, ali1541_write, dev, &dev->pci_slot); @@ -665,7 +665,7 @@ const device_t ali1541_device = { .init = ali1541_init, .close = ali1541_close, .reset = ali1541_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/ali1543.c b/src/chipset/ali1543.c index f35ec7590..2f9273736 100644 --- a/src/chipset/ali1543.c +++ b/src/chipset/ali1543.c @@ -22,6 +22,7 @@ #include #define HAVE_STDARG_H #include <86box/86box.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/device.h> #include <86box/io.h> @@ -1599,8 +1600,7 @@ ali1543_close(void *priv) static void * ali1543_init(const device_t *info) { - ali1543_t *dev = (ali1543_t *) malloc(sizeof(ali1543_t)); - memset(dev, 0, sizeof(ali1543_t)); + ali1543_t *dev = (ali1543_t *) calloc(1, sizeof(ali1543_t)); /* Device 02: M1533 Southbridge */ pci_add_card(PCI_ADD_SOUTHBRIDGE, ali1533_read, ali1533_write, dev, &dev->pci_slot); @@ -1673,7 +1673,7 @@ const device_t ali1543_device = { .init = ali1543_init, .close = ali1543_close, .reset = ali1543_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1687,7 +1687,7 @@ const device_t ali1543c_device = { .init = ali1543_init, .close = ali1543_close, .reset = ali1543_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/ali1621.c b/src/chipset/ali1621.c index 6194dce19..d44c0f5a9 100644 --- a/src/chipset/ali1621.c +++ b/src/chipset/ali1621.c @@ -669,8 +669,7 @@ ali1621_close(void *priv) static void * ali1621_init(UNUSED(const device_t *info)) { - ali1621_t *dev = (ali1621_t *) malloc(sizeof(ali1621_t)); - memset(dev, 0, sizeof(ali1621_t)); + ali1621_t *dev = (ali1621_t *) calloc(1, sizeof(ali1621_t)); pci_add_card(PCI_ADD_NORTHBRIDGE, ali1621_read, ali1621_write, dev, &dev->pci_slot); @@ -692,7 +691,7 @@ const device_t ali1621_device = { .init = ali1621_init, .close = ali1621_close, .reset = ali1621_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/ali6117.c b/src/chipset/ali6117.c index cc2e465a2..88bb4b572 100644 --- a/src/chipset/ali6117.c +++ b/src/chipset/ali6117.c @@ -26,6 +26,7 @@ #include <86box/io.h> #include <86box/pci.h> #include <86box/pic.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/pit.h> #include <86box/device.h> @@ -466,8 +467,7 @@ ali6117_init(const device_t *info) ali6117_log("ALI6117: init()\n"); - ali6117_t *dev = (ali6117_t *) malloc(sizeof(ali6117_t)); - memset(dev, 0, sizeof(ali6117_t)); + ali6117_t *dev = (ali6117_t *) calloc(1, sizeof(ali6117_t)); dev->local = info->local; @@ -494,12 +494,12 @@ ali6117_init(const device_t *info) const device_t ali1217_device = { .name = "ALi M1217", .internal_name = "ali1217", - .flags = DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0x8, .init = ali6117_init, .close = ali6117_close, .reset = ali6117_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -508,12 +508,12 @@ const device_t ali1217_device = { const device_t ali6117d_device = { .name = "ALi M6117D", .internal_name = "ali6117d", - .flags = DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0x2, .init = ali6117_init, .close = ali6117_close, .reset = ali6117_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/compaq_386.c b/src/chipset/compaq_386.c index 8c241e087..bc81c5472 100644 --- a/src/chipset/compaq_386.c +++ b/src/chipset/compaq_386.c @@ -772,7 +772,7 @@ const device_t compaq_386_device = { .init = compaq_386_init, .close = compaq_386_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -786,7 +786,7 @@ const device_t compaq_genoa_device = { .init = compaq_genoa_init, .close = NULL, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/contaq_82c59x.c b/src/chipset/contaq_82c59x.c index 5c2910227..1981fd11c 100644 --- a/src/chipset/contaq_82c59x.c +++ b/src/chipset/contaq_82c59x.c @@ -322,8 +322,7 @@ contaq_82c59x_close(void *priv) static void * contaq_82c59x_init(const device_t *info) { - contaq_82c59x_t *dev = (contaq_82c59x_t *) malloc(sizeof(contaq_82c59x_t)); - memset(dev, 0x00, sizeof(contaq_82c59x_t)); + contaq_82c59x_t *dev = (contaq_82c59x_t *) calloc(1, sizeof(contaq_82c59x_t)); dev->green = info->local; @@ -359,7 +358,7 @@ const device_t contaq_82c596a_device = { .init = contaq_82c59x_init, .close = contaq_82c59x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -373,7 +372,7 @@ const device_t contaq_82c597_device = { .init = contaq_82c59x_init, .close = contaq_82c59x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/cs4031.c b/src/chipset/cs4031.c index fb439ec3a..cfec9ad30 100644 --- a/src/chipset/cs4031.c +++ b/src/chipset/cs4031.c @@ -164,8 +164,7 @@ cs4031_close(void *priv) static void * cs4031_init(UNUSED(const device_t *info)) { - cs4031_t *dev = (cs4031_t *) malloc(sizeof(cs4031_t)); - memset(dev, 0, sizeof(cs4031_t)); + cs4031_t *dev = (cs4031_t *) calloc(1, sizeof(cs4031_t)); dev->port_92 = device_add(&port_92_device); @@ -185,7 +184,7 @@ const device_t cs4031_device = { .init = cs4031_init, .close = cs4031_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/cs8220.c b/src/chipset/cs8220.c new file mode 100644 index 000000000..4c08ecef5 --- /dev/null +++ b/src/chipset/cs8220.c @@ -0,0 +1,289 @@ +/* + * 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 C&T CS8220 ("PC/AT") chipset. + * + * Authors: Miran Grca, + * + * Copyright 2025 Miran Grca. + */ +#include +#include +#include +#include +#include +#include <86box/86box.h> +#include "cpu.h" +#include <86box/timer.h> +#include <86box/io.h> +#include <86box/device.h> +#include <86box/machine.h> +#include <86box/mem.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> +#include <86box/fdd.h> +#include <86box/fdc.h> +#include <86box/chipset.h> + +typedef struct { + uint32_t virt; + uint32_t phys; + + uint32_t size; + + mem_mapping_t mapping; +} ram_bank_t; + +typedef struct { + uint8_t regs[3]; + + ram_bank_t ram_banks[3]; +} cs8220_t; + +static uint8_t +cs8220_mem_read(uint32_t addr, void *priv) +{ + ram_bank_t *dev = (ram_bank_t *) priv; + uint8_t ret = 0xff; + + addr = (addr - dev->virt) + dev->phys; + + if (addr < (mem_size << 10)) + ret = ram[addr]; + + return ret; +} + +static uint16_t +cs8220_mem_readw(uint32_t addr, void *priv) +{ + ram_bank_t *dev = (ram_bank_t *) priv; + uint16_t ret = 0xffff; + + addr = (addr - dev->virt) + dev->phys; + + if (addr < (mem_size << 10)) + ret = *(uint16_t *) &(ram[addr]); + + return ret; +} + +static void +cs8220_mem_write(uint32_t addr, uint8_t val, void *priv) +{ + ram_bank_t *dev = (ram_bank_t *) priv; + + addr = (addr - dev->virt) + dev->phys; + + if (addr < (mem_size << 10)) + ram[addr] = val; +} + +static void +cs8220_mem_writew(uint32_t addr, uint16_t val, void *priv) +{ + ram_bank_t *dev = (ram_bank_t *) priv; + + addr = (addr - dev->virt) + dev->phys; + + if (addr < (mem_size << 10)) + *(uint16_t *) &(ram[addr]) = val; +} + +static uint8_t +cs8220_in(uint16_t port, void *priv) { + cs8220_t *dev = (cs8220_t *) priv; + uint8_t ret = 0xff; + + switch (port) { + case 0x00a4 ... 0x00a5: + ret = dev->regs[port & 0x0001]; + break; + case 0x00ab: + ret = dev->regs[2]; + break; + } + + return ret; +} + +static void +cs8220_out(uint16_t port, uint8_t val, void *priv) { + cs8220_t *dev = (cs8220_t *) priv; + + switch (port) { + case 0x00a4: + dev->regs[0] = val; + mem_a20_alt = val & 0x40; + mem_a20_recalc(); + break; + case 0x00a5: + dev->regs[1] = val; + if (val & 0x01) { + mem_mapping_set_addr(&dev->ram_banks[0].mapping, 0, 0x000040000); + mem_mapping_disable(&dev->ram_banks[1].mapping); + mem_mapping_disable(&dev->ram_banks[2].mapping); + } else { + mem_mapping_set_addr(&dev->ram_banks[0].mapping, 0, dev->ram_banks[0].size); + mem_mapping_enable(&dev->ram_banks[1].mapping); + mem_mapping_enable(&dev->ram_banks[2].mapping); + } + break; + case 0x00ab: + dev->regs[2] = val; + break; + } +} + +static void +cs8220_close(void *priv) +{ + cs8220_t *dev = (cs8220_t *) priv; + + free(dev); +} + +static void * +cs8220_init(UNUSED(const device_t *info)) +{ + cs8220_t *dev = (cs8220_t *) calloc(1, sizeof(cs8220_t)); + + mem_mapping_disable(&ram_low_mapping); + mem_mapping_disable(&ram_mid_mapping); + mem_mapping_disable(&ram_high_mapping); + + /* + Dell System 200: 640 kB soldered on-board, any other RAM is expansion. + */ + if (!strcmp(machine_get_internal_name(), "dells200")) switch (mem_size) { + default: + dev->ram_banks[2].virt = 0x00100000; + dev->ram_banks[2].phys = 0x000a0000; + dev->ram_banks[2].size = (mem_size << 10) - 0x000a0000; + fallthrough; + case 640: + dev->ram_banks[0].virt = 0x00000000; + dev->ram_banks[0].phys = 0x00000000; + dev->ram_banks[0].size = 0x00080000; + dev->ram_banks[1].virt = 0x00080000; + dev->ram_banks[1].phys = 0x00080000; + dev->ram_banks[1].size = 0x00020000; + break; + /* + We are limited to steps of equal size, so we have to simulate some + memory expansions to work around the chipset's limits. + */ + } else switch (mem_size) { + case 256: + dev->ram_banks[0].virt = 0x00000000; + dev->ram_banks[0].phys = 0x00000000; + dev->ram_banks[0].size = 0x00020000; + dev->ram_banks[1].virt = 0x00020000; + dev->ram_banks[1].phys = 0x00020000; + dev->ram_banks[1].size = 0x00020000; + break; + case 384: + dev->ram_banks[0].virt = 0x00000000; + dev->ram_banks[0].phys = 0x00000000; + dev->ram_banks[0].size = 0x00020000; + /* Pretend there's a 128k expansion. */ + dev->ram_banks[2].virt = 0x00020000; + dev->ram_banks[2].phys = 0x00020000; + dev->ram_banks[2].size = 0x00040000; + break; + case 512: + dev->ram_banks[0].virt = 0x00000000; + dev->ram_banks[0].phys = 0x00000000; + dev->ram_banks[0].size = 0x00080000; + break; + default: + dev->ram_banks[2].virt = 0x00100000; + dev->ram_banks[2].phys = 0x000a0000; + dev->ram_banks[2].size = (mem_size << 10) - 0x000a0000; + fallthrough; + case 640: + dev->ram_banks[0].virt = 0x00000000; + dev->ram_banks[0].phys = 0x00000000; + dev->ram_banks[0].size = 0x00080000; + dev->ram_banks[1].virt = 0x00080000; + dev->ram_banks[1].phys = 0x00080000; + dev->ram_banks[1].size = 0x00020000; + break; + case 768: + dev->ram_banks[0].virt = 0x00000000; + dev->ram_banks[0].phys = 0x00000000; + dev->ram_banks[0].size = 0x00080000; + dev->ram_banks[1].virt = 0x00080000; + dev->ram_banks[1].phys = 0x00080000; + dev->ram_banks[1].size = 0x00020000; + /* Pretend there's a 128k expansion. */ + dev->ram_banks[2].virt = 0x00100000; + dev->ram_banks[2].phys = 0x00080000; + dev->ram_banks[2].size = 0x00020000; + break; + case 896: + dev->ram_banks[0].virt = 0x00000000; + dev->ram_banks[0].phys = 0x00000000; + dev->ram_banks[0].size = 0x00080000; + dev->ram_banks[1].virt = 0x00080000; + dev->ram_banks[1].phys = 0x00080000; + dev->ram_banks[1].size = 0x00020000; + /* Pretend there's a 256k expansion. */ + dev->ram_banks[2].virt = 0x00100000; + dev->ram_banks[2].phys = 0x00080000; + dev->ram_banks[2].size = 0x00040000; + break; + case 1024: + dev->ram_banks[0].virt = 0x00000000; + dev->ram_banks[0].phys = 0x00000000; + dev->ram_banks[0].size = 0x00080000; + dev->ram_banks[1].virt = 0x00100000; + dev->ram_banks[1].phys = 0x00080000; + dev->ram_banks[1].size = 0x00080000; + break; + } + + if (dev->ram_banks[0].size > 0x00000000) + mem_mapping_add(&dev->ram_banks[0].mapping, dev->ram_banks[0].virt, dev->ram_banks[0].size, + cs8220_mem_read, cs8220_mem_readw, NULL, + cs8220_mem_write, cs8220_mem_writew, NULL, + ram + dev->ram_banks[0].phys, MEM_MAPPING_INTERNAL, &(dev->ram_banks[0])); + + if (dev->ram_banks[1].size > 0x00000000) + mem_mapping_add(&dev->ram_banks[1].mapping, dev->ram_banks[1].virt, dev->ram_banks[1].size, + cs8220_mem_read, cs8220_mem_readw, NULL, + cs8220_mem_write, cs8220_mem_writew, NULL, + ram + dev->ram_banks[1].phys, MEM_MAPPING_INTERNAL, &(dev->ram_banks[1])); + + if (dev->ram_banks[2].size > 0x00000000) + mem_mapping_add(&dev->ram_banks[2].mapping, dev->ram_banks[2].virt, dev->ram_banks[2].size, + cs8220_mem_read, cs8220_mem_readw, NULL, + cs8220_mem_write, cs8220_mem_writew, NULL, + ram + dev->ram_banks[2].phys, MEM_MAPPING_INTERNAL, &(dev->ram_banks[2])); + + io_sethandler(0x00a4, 0x0002, + cs8220_in, NULL, NULL, cs8220_out, NULL, NULL, dev); + io_sethandler(0x00ab, 0x0001, + cs8220_in, NULL, NULL, cs8220_out, NULL, NULL, dev); + + return dev; +} + +const device_t cs8220_device = { + .name = "C&T CS8220 (PC/AT)", + .internal_name = "cs8220", + .flags = 0, + .local = 0, + .init = cs8220_init, + .close = cs8220_close, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; diff --git a/src/chipset/cs8230.c b/src/chipset/cs8230.c index 93a7f1bba..0374a44a6 100644 --- a/src/chipset/cs8230.c +++ b/src/chipset/cs8230.c @@ -157,8 +157,7 @@ cs8230_close(void *priv) static void * cs8230_init(UNUSED(const device_t *info)) { - cs8230_t *cs8230 = (cs8230_t *) malloc(sizeof(cs8230_t)); - memset(cs8230, 0, sizeof(cs8230_t)); + cs8230_t *cs8230 = (cs8230_t *) calloc(1, sizeof(cs8230_t)); io_sethandler(0x0022, 0x0002, cs8230_read, NULL, NULL, cs8230_write, NULL, NULL, cs8230); @@ -178,7 +177,7 @@ const device_t cs8230_device = { .init = cs8230_init, .close = cs8230_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/et6000.c b/src/chipset/et6000.c index f2cffd7f7..14ebf852e 100644 --- a/src/chipset/et6000.c +++ b/src/chipset/et6000.c @@ -137,8 +137,7 @@ et6000_close(void *priv) static void * et6000_init(UNUSED(const device_t *info)) { - et6000_t *dev = (et6000_t *) malloc(sizeof(et6000_t)); - memset(dev, 0, sizeof(et6000_t)); + et6000_t *dev = (et6000_t *) calloc(1, sizeof(et6000_t)); /* Port 92h */ device_add(&port_92_device); @@ -162,7 +161,7 @@ const device_t et6000_device = { .init = et6000_init, .close = et6000_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/gc100.c b/src/chipset/gc100.c index 0b4717903..e9eb05ecf 100644 --- a/src/chipset/gc100.c +++ b/src/chipset/gc100.c @@ -27,6 +27,7 @@ #define HAVE_STDARG_H #include <86box/86box.h> #include <86box/nmi.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/pit.h> #include <86box/mem.h> @@ -208,8 +209,7 @@ gc100_close(void *priv) static void * gc100_init(const device_t *info) { - gc100_t *dev = (gc100_t *) malloc(sizeof(gc100_t)); - memset(dev, 0, sizeof(gc100_t)); + gc100_t *dev = (gc100_t *) calloc(1, sizeof(gc100_t)); dev->reg[0x2] = 0xff; dev->reg[0x3] = 0x0; @@ -238,7 +238,7 @@ const device_t gc100_device = { .init = gc100_init, .close = gc100_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -252,7 +252,7 @@ const device_t gc100a_device = { .init = gc100_init, .close = gc100_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/headland.c b/src/chipset/headland.c index db5922470..1172d105d 100644 --- a/src/chipset/headland.c +++ b/src/chipset/headland.c @@ -594,8 +594,7 @@ headland_init(const device_t *info) headland_t *dev; int ht386 = 0; - dev = (headland_t *) malloc(sizeof(headland_t)); - memset(dev, 0x00, sizeof(headland_t)); + dev = (headland_t *) calloc(1, sizeof(headland_t)); dev->has_cri = (info->local & HEADLAND_HAS_CRI); dev->has_sleep = (info->local & HEADLAND_HAS_SLEEP); @@ -699,7 +698,7 @@ const device_t headland_gc10x_device = { .init = headland_init, .close = headland_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -713,7 +712,7 @@ const device_t headland_gc113_device = { .init = headland_init, .close = headland_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -727,7 +726,7 @@ const device_t headland_ht18a_device = { .init = headland_init, .close = headland_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -741,7 +740,7 @@ const device_t headland_ht18b_device = { .init = headland_init, .close = headland_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -755,7 +754,7 @@ const device_t headland_ht18c_device = { .init = headland_init, .close = headland_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -769,7 +768,7 @@ const device_t headland_ht21c_d_device = { .init = headland_init, .close = headland_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -783,7 +782,7 @@ const device_t headland_ht21e_device = { .init = headland_init, .close = headland_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/ims8848.c b/src/chipset/ims8848.c index 3e86a44e1..094ee31f8 100644 --- a/src/chipset/ims8848.c +++ b/src/chipset/ims8848.c @@ -381,8 +381,7 @@ ims8848_close(void *priv) static void * ims8848_init(UNUSED(const device_t *info)) { - ims8848_t *dev = (ims8848_t *) malloc(sizeof(ims8848_t)); - memset(dev, 0, sizeof(ims8848_t)); + ims8848_t *dev = (ims8848_t *) calloc(1, sizeof(ims8848_t)); device_add(&port_92_device); @@ -416,7 +415,7 @@ const device_t ims8848_device = { .init = ims8848_init, .close = ims8848_close, .reset = ims8848_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/intel_420ex.c b/src/chipset/intel_420ex.c index 34335d53c..662fd0509 100644 --- a/src/chipset/intel_420ex.c +++ b/src/chipset/intel_420ex.c @@ -533,8 +533,7 @@ i420ex_speed_changed(void *priv) static void * i420ex_init(const device_t *info) { - i420ex_t *dev = (i420ex_t *) malloc(sizeof(i420ex_t)); - memset(dev, 0, sizeof(i420ex_t)); + i420ex_t *dev = (i420ex_t *) calloc(1, sizeof(i420ex_t)); dev->smram = smram_add(); @@ -579,7 +578,7 @@ const device_t i420ex_device = { .init = i420ex_init, .close = i420ex_close, .reset = i420ex_reset, - { .available = NULL }, + .available = NULL, .speed_changed = i420ex_speed_changed, .force_redraw = NULL, .config = NULL @@ -593,7 +592,7 @@ const device_t i420ex_ide_device = { .init = i420ex_init, .close = i420ex_close, .reset = i420ex_reset, - { .available = NULL }, + .available = NULL, .speed_changed = i420ex_speed_changed, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/intel_4x0.c b/src/chipset/intel_4x0.c index 2f6afa940..8e6ce97c3 100644 --- a/src/chipset/intel_4x0.c +++ b/src/chipset/intel_4x0.c @@ -1013,7 +1013,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_430TX: if (!dev->smram_locked) { i4x0_smram_handler_phase0(dev); - regs[0x71] = (regs[0x71] & 0x20) | (val & 0xdf); + regs[0x71] = (regs[0x71] & 0x60) | (val & 0x9f); + regs[0x71] &= (val & 0x40); i4x0_smram_handler_phase1(dev); } break; @@ -1041,9 +1042,11 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) regs[0x72] = (val & 0x7f); else regs[0x72] = (regs[0x72] & 0x87) | (val & 0x78); - dev->smram_locked = (val & 0x10); - if (dev->smram_locked) - regs[0x72] &= 0xbf; + if (val & 0x08) { + dev->smram_locked = (val & 0x10); + if (dev->smram_locked) + regs[0x72] &= 0xbf; + } } } else { if (dev->smram_locked) @@ -1577,6 +1580,8 @@ i4x0_reset(void *priv) dev->regs[0x68 + i] = 0x00; } + dev->smram_locked = 0; + if (dev->type >= INTEL_430FX) { dev->regs[0x72] &= 0xef; /* Forcibly unlock the SMRAM register. */ i4x0_write(0, 0x72, 0x02, priv); @@ -1608,11 +1613,9 @@ i4x0_close(void *priv) static void * i4x0_init(const device_t *info) { - i4x0_t *dev = (i4x0_t *) malloc(sizeof(i4x0_t)); + i4x0_t *dev = (i4x0_t *) calloc(1, sizeof(i4x0_t)); uint8_t *regs; - memset(dev, 0, sizeof(i4x0_t)); - dev->smram_low = smram_add(); dev->smram_high = smram_add(); @@ -1658,7 +1661,12 @@ i4x0_init(const device_t *info) regs[0x57] = 0x31; regs[0x59] = 0x0f; regs[0x60] = regs[0x61] = regs[0x62] = regs[0x63] = 0x02; - dev->max_drb = 3; + /* At the very least the 420ZX seems to read to 0x64, per the SB486PV. */ + if (dev->type == INTEL_420ZX) { + regs[0x64] = 0x02; + dev->max_drb = 4; + } else + dev->max_drb = 3; dev->drb_unit = 1; dev->drb_default = 0x02; break; @@ -1967,7 +1975,7 @@ const device_t i420tx_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1981,7 +1989,7 @@ const device_t i420zx_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1995,7 +2003,7 @@ const device_t i430lx_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2009,7 +2017,7 @@ const device_t i430nx_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2023,7 +2031,7 @@ const device_t i430fx_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2037,7 +2045,7 @@ const device_t i430fx_rev02_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2051,7 +2059,7 @@ const device_t i430hx_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2065,7 +2073,7 @@ const device_t i430vx_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2079,7 +2087,7 @@ const device_t i430tx_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2093,7 +2101,7 @@ const device_t i440fx_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2107,7 +2115,7 @@ const device_t i440lx_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2121,7 +2129,7 @@ const device_t i440ex_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2135,7 +2143,7 @@ const device_t i440bx_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2149,7 +2157,7 @@ const device_t i440bx_no_agp_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2163,7 +2171,7 @@ const device_t i440gx_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2177,7 +2185,7 @@ const device_t i440zx_device = { .init = i4x0_init, .close = i4x0_close, .reset = i4x0_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/intel_82335.c b/src/chipset/intel_82335.c index da0cc30f6..bd53e0d05 100644 --- a/src/chipset/intel_82335.c +++ b/src/chipset/intel_82335.c @@ -171,8 +171,7 @@ intel_82335_close(void *priv) static void * 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)); + intel_82335_t *dev = (intel_82335_t *) calloc(1, sizeof(intel_82335_t)); memset(dev->regs, 0, sizeof(dev->regs)); @@ -209,7 +208,7 @@ const device_t intel_82335_device = { .init = intel_82335_init, .close = intel_82335_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/intel_i450kx.c b/src/chipset/intel_i450kx.c index 2f6547309..34cc6a62f 100644 --- a/src/chipset/intel_i450kx.c +++ b/src/chipset/intel_i450kx.c @@ -799,8 +799,8 @@ i450kx_close(void *priv) static void * i450kx_init(UNUSED(const device_t *info)) { - i450kx_t *dev = (i450kx_t *) malloc(sizeof(i450kx_t)); - memset(dev, 0, sizeof(i450kx_t)); + i450kx_t *dev = (i450kx_t *) calloc(1, sizeof(i450kx_t)); + pci_add_card(PCI_ADD_NORTHBRIDGE, pb_read, pb_write, dev, &dev->pb_slot); /* Device 19h: Intel 450KX PCI Bridge PB */ pci_add_card(PCI_ADD_NORTHBRIDGE_SEC, mc_read, mc_write, dev, &dev->mc_slot); /* Device 14h: Intel 450KX Memory Controller MC */ @@ -824,7 +824,7 @@ const device_t i450kx_device = { .init = i450kx_init, .close = i450kx_close, .reset = i450kx_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/intel_piix.c b/src/chipset/intel_piix.c index c6a6fc0ac..e0d80f348 100644 --- a/src/chipset/intel_piix.c +++ b/src/chipset/intel_piix.c @@ -59,7 +59,6 @@ typedef struct piix_io_trap_t { } piix_io_trap_t; typedef struct _piix_ { - uint8_t cur_readout_reg; uint8_t rev; uint8_t type; uint8_t func_shift; @@ -67,7 +66,6 @@ typedef struct _piix_ { uint8_t pci_slot; uint8_t no_mirq0; uint8_t regs[4][256]; - uint8_t readout_regs[256]; uint16_t func0_id; uint16_t nvr_io_base; uint16_t acpi_io_base; @@ -157,6 +155,7 @@ piix_ide_handlers(piix_t *dev, int bus) uint16_t side; if (bus & 0x01) { + piix_log("Disabling primary IDE...\n"); ide_pri_disable(); if (dev->type == 5) { @@ -172,11 +171,14 @@ piix_ide_handlers(piix_t *dev, int bus) ide_set_side(0, side); } - if ((dev->regs[1][0x04] & 0x01) && (dev->regs[1][0x41] & 0x80)) + if ((dev->regs[1][0x04] & 0x01) && (dev->regs[1][0x41] & 0x80)) { + piix_log("Enabling primary IDE...\n"); ide_pri_enable(); + } } if (bus & 0x02) { + piix_log("Disabling secondary IDE...\n"); ide_sec_disable(); if (dev->type == 5) { @@ -192,8 +194,10 @@ piix_ide_handlers(piix_t *dev, int bus) ide_set_side(1, side); } - if ((dev->regs[1][0x04] & 0x01) && (dev->regs[1][0x43] & 0x80)) + if ((dev->regs[1][0x04] & 0x01) && (dev->regs[1][0x43] & 0x80)) { + piix_log("Enabling secondary IDE...\n"); ide_sec_enable(); + } } } @@ -467,6 +471,13 @@ piix_write(int func, int addr, uint8_t val, void *priv) uint8_t *fregs; uint16_t base; + /* Dell OptiPlex Gn+ shows that register 02:FF is aliased in 01:FF. */ + if ((dev->type == 4) && (func == 1) && (addr == 0xff)) + func = 2; + + if ((func == 1) || (addr == 0xf8) || (addr == 0xf9)) + piix_log("[W] %02X:%02X = %02X\n", func, addr, val); + /* Return on unsupported function. */ if (dev->max_func > 0) { if (func > dev->max_func) @@ -738,6 +749,8 @@ piix_write(int func, int addr, uint8_t val, void *priv) fregs[addr] = val; break; case 0xb0: + if (val & 0x10) + warning("Write %02X to B0\n", val); if (dev->type == 4) fregs[addr] = (fregs[addr] & 0x8c) | (val & 0x73); else if (dev->type == 5) @@ -747,6 +760,8 @@ piix_write(int func, int addr, uint8_t val, void *priv) alt_access = !!(val & 0x20); break; case 0xb1: + if (val & 0x18) + warning("Write %02X to B1\n", val); if (dev->type > 3) fregs[addr] = val & 0xdf; break; @@ -925,6 +940,12 @@ piix_write(int func, int addr, uint8_t val, void *priv) if (dev->type > 4) fregs[addr] = val; break; + case 0xf8: + case 0xf9: + /* Undocumented! */ + if (dev->type == 4) + fregs[addr] = val; + break; default: break; } @@ -1171,6 +1192,10 @@ piix_read(int func, int addr, void *priv) uint8_t ret = 0xff; const uint8_t *fregs; + /* Dell OptiPlex Gn+ shows that register 02:FF is aliased in 01:FF. */ + if ((dev->type == 4) && (func == 1) && (addr == 0xff)) + func = 2; + if ((dev->type == 3) && (func == 2) && (dev->max_func == 1) && (addr >= 0x40)) ret = 0x00; @@ -1185,31 +1210,6 @@ piix_read(int func, int addr, void *priv) return ret; } -static void -board_write(uint16_t port, uint8_t val, void *priv) -{ - piix_t *dev = (piix_t *) priv; - - if (port == 0x00e0) - dev->cur_readout_reg = val; - else if (port == 0x00e1) - dev->readout_regs[dev->cur_readout_reg] = val; -} - -static uint8_t -board_read(uint16_t port, void *priv) -{ - const piix_t *dev = (piix_t *) priv; - uint8_t ret = 0x64; - - if (port == 0x00e0) - ret = dev->cur_readout_reg; - else if (port == 0x00e1) - ret = dev->readout_regs[dev->cur_readout_reg]; - - return ret; -} - static void piix_reset_hard(piix_t *dev) { @@ -1226,7 +1226,7 @@ piix_reset_hard(piix_t *dev) sff_set_slot(dev->bm[1], dev->pci_slot); sff_set_irq_pin(dev->bm[1], PCI_INTA); - sff_set_irq_line(dev->bm[1], 14); + sff_set_irq_line(dev->bm[1], 15); sff_set_irq_mode(dev->bm[1], IRQ_MODE_LEGACY); } @@ -1342,6 +1342,10 @@ piix_reset_hard(piix_t *dev) fregs[0x45] = 0x55; fregs[0x46] = 0x01; } + if (dev->type == 4) { + fregs[0xf8] = 0x30; + fregs[0xf9] = 0x0f; + } if ((dev->type == 1) && (dev->rev == 2)) dev->max_func = 0; /* It starts with IDE disabled, then enables it. */ else @@ -1538,8 +1542,7 @@ piix_speed_changed(void *priv) static void * piix_init(const device_t *info) { - piix_t *dev = (piix_t *) malloc(sizeof(piix_t)); - memset(dev, 0, sizeof(piix_t)); + piix_t *dev = (piix_t *) calloc(1, sizeof(piix_t)); dev->type = info->local & 0x0f; /* If (dev->type == 4) and (dev->rev & 0x08), then this is PIIX4E. */ @@ -1618,47 +1621,16 @@ piix_init(const device_t *info) else cpu_set_isa_pci_div(3); - dma_alias_set(); + if (dev->type > 1) + dma_alias_set(); + else + dma_alias_set_piix(); if (dev->type < 4) pci_enable_mirq(0); if (dev->type < 3) pci_enable_mirq(1); - dev->readout_regs[0] = 0xff; - dev->readout_regs[1] = 0x40; - dev->readout_regs[2] = 0xff; - - /* Port E1 register 01 (TODO: Find how multipliers > 3.0 are defined): - - Bit 6: 1 = can boot, 0 = no; - Bit 7, 1 = multiplier (00 = 2.5, 01 = 2.0, 10 = 3.0, 11 = 1.5); - Bit 5, 4 = bus speed (00 = 50 MHz, 01 = 66 MHz, 10 = 60 MHz, 11 = ????): - Bit 7, 5, 4, 1: 0000 = 125 MHz, 0010 = 166 MHz, 0100 = 150 MHz, 0110 = ??? MHz; - 0001 = 100 MHz, 0011 = 133 MHz, 0101 = 120 MHz, 0111 = ??? MHz; - 1000 = 150 MHz, 1010 = 200 MHz, 1100 = 180 MHz, 1110 = ??? MHz; - 1001 = 75 MHz, 1011 = 100 MHz, 1101 = 90 MHz, 1111 = ??? MHz */ - - if (cpu_busspeed <= 40000000) - dev->readout_regs[1] |= 0x30; - else if ((cpu_busspeed > 40000000) && (cpu_busspeed <= 50000000)) - dev->readout_regs[1] |= 0x00; - else if ((cpu_busspeed > 50000000) && (cpu_busspeed <= 60000000)) - dev->readout_regs[1] |= 0x20; - else if (cpu_busspeed > 60000000) - dev->readout_regs[1] |= 0x10; - - if (cpu_dmulti <= 1.5) - dev->readout_regs[1] |= 0x82; - else if ((cpu_dmulti > 1.5) && (cpu_dmulti <= 2.0)) - dev->readout_regs[1] |= 0x02; - else if ((cpu_dmulti > 2.0) && (cpu_dmulti <= 2.5)) - dev->readout_regs[1] |= 0x00; - else if (cpu_dmulti > 2.5) - dev->readout_regs[1] |= 0x80; - - io_sethandler(0x00e0, 0x0002, board_read, NULL, NULL, board_write, NULL, NULL, dev); - #if 0 device_add(&i8254_sec_device); #endif @@ -1674,7 +1646,7 @@ const device_t piix_device = { .init = piix_init, .close = piix_close, .reset = piix_reset, - { .available = NULL }, + .available = NULL, .speed_changed = piix_speed_changed, .force_redraw = NULL, .config = NULL @@ -1688,7 +1660,7 @@ const device_t piix_no_mirq_device = { .init = piix_init, .close = piix_close, .reset = piix_reset, - { .available = NULL }, + .available = NULL, .speed_changed = piix_speed_changed, .force_redraw = NULL, .config = NULL @@ -1702,7 +1674,7 @@ const device_t piix_rev02_device = { .init = piix_init, .close = piix_close, .reset = piix_reset, - { .available = NULL }, + .available = NULL, .speed_changed = piix_speed_changed, .force_redraw = NULL, .config = NULL @@ -1716,7 +1688,7 @@ const device_t piix3_device = { .init = piix_init, .close = piix_close, .reset = piix_reset, - { .available = NULL }, + .available = NULL, .speed_changed = piix_speed_changed, .force_redraw = NULL, .config = NULL @@ -1730,7 +1702,7 @@ const device_t piix3_ioapic_device = { .init = piix_init, .close = piix_close, .reset = piix_reset, - { .available = NULL }, + .available = NULL, .speed_changed = piix_speed_changed, .force_redraw = NULL, .config = NULL @@ -1744,7 +1716,7 @@ const device_t piix4_device = { .init = piix_init, .close = piix_close, .reset = piix_reset, - { .available = NULL }, + .available = NULL, .speed_changed = piix_speed_changed, .force_redraw = NULL, .config = NULL @@ -1758,7 +1730,7 @@ const device_t piix4e_device = { .init = piix_init, .close = piix_close, .reset = piix_reset, - { .available = NULL }, + .available = NULL, .speed_changed = piix_speed_changed, .force_redraw = NULL, .config = NULL @@ -1772,7 +1744,7 @@ const device_t slc90e66_device = { .init = piix_init, .close = piix_close, .reset = piix_reset, - { .available = NULL }, + .available = NULL, .speed_changed = piix_speed_changed, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/intel_sio.c b/src/chipset/intel_sio.c index 03a292da8..b11ec0765 100644 --- a/src/chipset/intel_sio.c +++ b/src/chipset/intel_sio.c @@ -355,7 +355,23 @@ sio_config_read(uint16_t port, UNUSED(void *priv)) ret = 0xff; break; case 5: - ret = 0xd3; + /* + Dell Dimension XPS P60 jumpers: + - Bit 5: Disable CMOS Setup (1 = yes, 0 = no). + + Dell OptiPlex 560/L jumpers: + - Bit 1: Password (1 = disable, 0 = enable); + - Bit 5: Clear CMOS (1 = no, 0 = yes). + - Bits 7, 6: Board type: + - 0, 0 = L; + - 0, 1 = MT; + - 1, 0 = M; + - 1, 1 = M. + */ + if (!strcmp(machine_get_internal_name(), "opti560l")) + ret = 0x20; + else + ret = 0xd3; switch (cpu_pci_speed) { case 20000000: @@ -508,8 +524,7 @@ sio_speed_changed(void *priv) static void * sio_init(const device_t *info) { - sio_t *dev = (sio_t *) malloc(sizeof(sio_t)); - memset(dev, 0, sizeof(sio_t)); + sio_t *dev = (sio_t *) calloc(1, sizeof(sio_t)); pci_add_card(PCI_ADD_SOUTHBRIDGE, sio_read, sio_write, dev, &dev->pci_slot); @@ -568,7 +583,7 @@ const device_t sio_device = { .init = sio_init, .close = sio_close, .reset = sio_reset, - { .available = NULL }, + .available = NULL, .speed_changed = sio_speed_changed, .force_redraw = NULL, .config = NULL @@ -582,7 +597,7 @@ const device_t sio_zb_device = { .init = sio_init, .close = sio_close, .reset = sio_reset, - { .available = NULL }, + .available = NULL, .speed_changed = sio_speed_changed, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/isa486c.c b/src/chipset/isa486c.c new file mode 100644 index 000000000..6494ed1b8 --- /dev/null +++ b/src/chipset/isa486c.c @@ -0,0 +1,131 @@ +#include +#include +#include +#include +#include +#include +#define HAVE_STDARG_H +#include <86box/86box.h> +#include "cpu.h" +#include <86box/io.h> +#include <86box/device.h> +#include <86box/mem.h> +#include <86box/plat_unused.h> +#include <86box/chipset.h> + +typedef struct isa486c_t { + uint8_t regs[3]; +} isa486c_t; + +static void +isa486c_recalcmapping(isa486c_t *dev) +{ + uint32_t shflags = 0; + uint32_t bases[5] = { 0x000c0000, 0x000c8000, 0x000d0000, 0x000d8000, 0x000e0000 }; + uint32_t sizes[5] = { 0x00008000, 0x00008000, 0x00008000, 0x00008000, 0x00020000 }; + + if (dev->regs[1] & 0x20) + shflags = MEM_READ_EXTANY | MEM_WRITE_INTERNAL; + else + shflags = MEM_READ_INTERNAL | MEM_WRITE_EXTANY; + + shadowbios = 0; + shadowbios_write = 0; + + for (uint8_t i = 0; i < 5; i++) + if (dev->regs[1] & (1 << i)) { + if (i == 4) { + shadowbios = 1; + shadowbios_write = !!(dev->regs[1] & 0x20); + } + + mem_set_mem_state_both(bases[i], sizes[i], shflags); + } else + mem_set_mem_state_both(bases[i], sizes[i], MEM_READ_EXTANY | MEM_WRITE_EXTANY); + + flushmmucache_nopc(); +} + +static void +isa486c_write(uint16_t addr, uint8_t val, void *priv) +{ + isa486c_t *dev = (isa486c_t *) priv; + + switch (addr) { + case 0x0023: + dev->regs[0] = val; + break; + /* + Port 25h: + - Bit 0 = Video BIOS (C000-C7FF) shadow enabled; + - Bit 1 = C800-C8FF shadow enabled; + - Bit 2 = D000-D7FF shadow enabled; + - Bit 3 = D800-DFFF shadow enabled; + - Bit 4 = E000-FFFF shadow enabled (or F0000-FFFFF?); + - Bit 5 = If set, read from ROM, write to shadow; + - Bit 6 = KEN Video & BIOS enabled (cacheability!). + */ + case 0x0025: + dev->regs[1] = val; + isa486c_recalcmapping(dev); + break; + case 0x0027: + dev->regs[2] = val; + break; + } +} + +static uint8_t +isa486c_read(uint16_t addr, void *priv) +{ + isa486c_t *dev = (isa486c_t *) priv; + uint8_t ret = 0xff; + + switch (addr) { + case 0x0023: + ret = dev->regs[0]; + break; + case 0x0025: + ret = dev->regs[1]; + break; + case 0x0027: + ret = dev->regs[2]; + break; + } + + return ret; +} + +static void +isa486c_close(void *priv) +{ + isa486c_t *dev = (isa486c_t *) priv; + + free(dev); +} + +static void * +isa486c_init(UNUSED(const device_t *info)) +{ + isa486c_t *dev = (isa486c_t *) calloc(1, sizeof(isa486c_t)); + + io_sethandler(0x0023, 0x0001, isa486c_read, NULL, NULL, isa486c_write, NULL, NULL, dev); + io_sethandler(0x0025, 0x0001, isa486c_read, NULL, NULL, isa486c_write, NULL, NULL, dev); + io_sethandler(0x0027, 0x0001, isa486c_read, NULL, NULL, isa486c_write, NULL, NULL, dev); + + return dev; +} + +const device_t isa486c_device = { + .name = "ASUS ISA-486C Gate Array", + .internal_name = "isa486c", + .flags = 0, + .local = 0, + .init = isa486c_init, + .close = isa486c_close, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; diff --git a/src/chipset/neat.c b/src/chipset/neat.c index 97c4b8f1a..0aa6fe5b6 100644 --- a/src/chipset/neat.c +++ b/src/chipset/neat.c @@ -27,16 +27,18 @@ #include #define HAVE_STDARG_H #include <86box/86box.h> +#include "cpu.h" #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 - #define EMS_MAXPAGE 4 #define EMS_PGSIZE 16384 +#define EMS_PGMASK 16383 + +#define REG_MASK 0x0f /* CS8221 82C211 controller registers. */ #define REG_RA0 0x60 /* PROCCLK selector */ @@ -51,6 +53,7 @@ #define REG_RA1 0x61 /* Command Delay */ #define RA1_MASK 0xff /* 1111 1111 */ +#define RA1_MASK_SX 0xbf /* 1X11 1111 */ #define RA1_BUSDLY 0x03 /* AT BUS command delay */ #define RA1_BUSDLY_SH 0 #define RA1_BUS8DLY 0x0c /* AT BUS 8bit command delay */ @@ -79,6 +82,7 @@ #define ATWS_3 1 /* 3 wait states */ #define ATWS_4 2 /* 4 wait states */ #define ATWS_5 4 /* 5 wait states */ +#define RA2_387SX 0x80 /* CS8221 82C212 controller registers. */ #define REG_RB0 0x64 /* Version ID */ @@ -101,6 +105,9 @@ #define REG_RB2 0x66 /* Memory Enable 1 */ #define RB2_MASK 0x80 /* 1XXX XXXX */ +#define RB2_MASK_SX 0xe0 /* 111X XXXX */ +#define RB2_BOT256 0x20 /* bottom 256K is on sysboard (1) */ +#define RB2_MID256 0x40 /* middle 256K is on sysboard (1) */ #define RB2_TOP128 0x80 /* top 128K is on sysboard (1) */ #define REG_RB3 0x67 /* Memory Enable 2 */ @@ -194,37 +201,65 @@ #define RB10_P0EXT 0xc0 /* page 0 extension */ #define RB10_P0EXT_SH 6 -#define REG_RB11 0x6f /* Miscellaneous */ -#define RB11_MASK 0xe6 /* 111R R11R */ -#define RB11_GA20 0x02 /* gate for A20 */ -#define RB11_RASTMO 0x04 /* enable RAS timeout counter */ -#define RB11_EMSLEN 0xe0 /* EMS memory chunk size */ -#define RB11_EMSLEN_SH 5 +#define REG_RB12 0x6f /* Miscellaneous */ +#define RB12_MASK 0xe6 /* 111R R11R */ +#define RB12_MASK_SX 0xf6 /* 1111 R11R */ +#define RB12_GA20 0x02 /* gate for A20 */ +#define RB12_RASTMO 0x04 /* enable RAS timeout counter */ +#define RB12_EMSLEN 0xe0 /* EMS memory chunk size */ +#define RB12_EMSLEN_SH 5 -typedef struct emspage_t { - int8_t enabled; /* 1=ENABLED */ +#define MEM_FLAG_REMAP 0x10 +#define MEM_FLAG_EMS 0x08 +#define MEM_FLAG_ROMCS 0x04 +#define MEM_FLAG_READ 0x02 +#define MEM_FLAG_WRITE 0x01 +#define MEM_FMASK_REMAP 0x10 +#define MEM_FMASK_EMS 0x08 +#define MEM_FMASK_SHADOW 0x07 + +typedef struct ram_page_t { + int8_t enabled; /* 1=ENABLED */ char pad; - uint16_t page; /* selected page in EMS block */ - uint32_t start; /* start of EMS in RAM */ - uint8_t *addr; /* start addr in EMS RAM */ - mem_mapping_t mapping; /* mapping entry for page */ -} emspage_t; + uint32_t phys_base; + uint32_t virt_base; + mem_mapping_t mapping; /* mapping entry for page */ +} ram_page_t; typedef struct neat_t { - uint8_t regs[128]; /* all the CS8221 registers */ - uint8_t indx; /* programmed index into registers */ + uint8_t mem_flags[64]; + uint8_t regs[128]; /* all the CS8221 registers */ + uint8_t indx; /* programmed index into registers */ + uint8_t sx; - char pad; + uint16_t ems_base; /* configured base address */ + uint32_t ems_frame; /* configured frame address */ + uint16_t ems_size; /* EMS size in KB */ + uint16_t 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 */ + uint32_t remap_base; + + ram_page_t ems[EMS_MAXPAGE]; /* EMS page registers */ + ram_page_t shadow[32]; /* Shadow RAM pages */ } neat_t; +static uint8_t defaults[2][16] = { { 0x0a, 0x45, 0xfc, 0x00, 0x00, 0x0e, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x43, 0x10, 0x00, 0x00, 0x12 }, + { 0x0a, 0x45, 0x7c, 0x00, 0x00, 0x0e, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x43, 0x00, 0x00, 0x00, 0x08 } }; + +static uint8_t reg_masks[2][16] = { { RA0_MASK, RA1_MASK, RA2_MASK, 0x00, + RB0_MASK, RB1_MASK, RB2_MASK, RB3_MASK, + RB4_MASK, RB4_MASK, RB4_MASK, RB4_MASK, + RB8_MASK, RB9_MASK, RB10_MASK, RB12_MASK }, + { RA0_MASK, RA1_MASK_SX, RA2_MASK, 0x00, + RB0_MASK, RB1_MASK, RB2_MASK_SX, RB3_MASK, + RB4_MASK, RB4_MASK, RB4_MASK, RB4_MASK, + RB8_MASK, RB9_MASK, RB10_MASK, RB12_MASK_SX } }; + +static uint8_t masks[4] = { RB10_P0EXT, RB10_P1EXT, RB10_P2EXT, RB10_P3EXT }; +static uint8_t shifts[4] = { RB10_P0EXT_SH, RB10_P1EXT_SH, RB10_P2EXT_SH, RB10_P3EXT_SH }; + #ifdef ENABLE_NEAT_LOG int neat_do_log = ENABLE_NEAT_LOG; @@ -243,16 +278,83 @@ neat_log(const char *fmt, ...) # define neat_log(fmt, ...) #endif +static uint8_t +neat_read_ram(uint32_t addr, void *priv) +{ + neat_t *dev = (neat_t *) priv; + + if (dev->regs[REG_RB7] & RB7_EMSEN) + addr += (dev->ems_size << 10); + + if (cpu_use_exec) + addreadlookup(mem_logical_addr, addr); + + return ram[addr]; +} + +static uint16_t +neat_read_ramw(uint32_t addr, void *priv) +{ + neat_t *dev = (neat_t *) priv; + + if (dev->regs[REG_RB7] & RB7_EMSEN) + addr += (dev->ems_size << 10); + + if (cpu_use_exec) + addreadlookup(mem_logical_addr, addr); + + return *(uint16_t *) &ram[addr]; +} + +static void +neat_write_ram(uint32_t addr, uint8_t val, void *priv) +{ + neat_t *dev = (neat_t *) priv; + + if (dev->regs[REG_RB7] & RB7_EMSEN) + addr += (dev->ems_size << 10); + + if (cpu_use_exec) { + addwritelookup(mem_logical_addr, addr); + mem_write_ramb_page(addr, val, &pages[addr >> 12]); + } else + ram[addr] = val; +} + +static void +neat_write_ramw(uint32_t addr, uint16_t val, void *priv) +{ + neat_t *dev = (neat_t *) priv; + + if (dev->regs[REG_RB7] & RB7_EMSEN) + addr += (dev->ems_size << 10); + + if (cpu_use_exec) { + addwritelookup(mem_logical_addr, addr); + mem_write_ramw_page(addr, val, &pages[addr >> 12]); + } else + *(uint16_t *) &ram[addr] = val; +} + /* Read one byte from paged RAM. */ static uint8_t ems_readb(uint32_t addr, void *priv) { - neat_t *dev = (neat_t *) priv; - uint8_t ret = 0xff; + ram_page_t *dev = (ram_page_t *) priv; + uint8_t ret = 0xff; +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 3) + uint32_t old = addr; +#endif /* Grab the data. */ - ret = *(uint8_t *) (dev->ems[(addr & 0xffff) >> 14].addr + (addr & 0x3fff)); + addr = addr - dev->virt_base + dev->phys_base; + if (addr < (mem_size << 10)) + ret = *(uint8_t *) &(ram[addr]); + +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 3) + neat_log("[R08] %08X -> %08X (%08X): ret = %02X\n", old, addr, (mem_size << 10), ret); +#endif return ret; } @@ -260,12 +362,21 @@ ems_readb(uint32_t addr, void *priv) static uint16_t ems_readw(uint32_t addr, void *priv) { - neat_t *dev = (neat_t *) priv; - uint16_t ret = 0xffff; + ram_page_t *dev = (ram_page_t *) priv; + uint16_t ret = 0xffff; +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 3) + uint32_t old = addr; +#endif /* Grab the data. */ - ret = *(uint16_t *) (dev->ems[(addr & 0xffff) >> 14].addr + (addr & 0x3fff)); + addr = addr - dev->virt_base + dev->phys_base; + if (addr < (mem_size << 10)) + ret = *(uint16_t *) &(ram[addr]); + +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 3) + neat_log("[R16] %08X -> %08X (%08X): ret = %04X\n", old, addr, (mem_size << 10), ret); +#endif return ret; } @@ -273,59 +384,173 @@ ems_readw(uint32_t addr, void *priv) static void ems_writeb(uint32_t addr, uint8_t val, void *priv) { - neat_t *dev = (neat_t *) priv; + ram_page_t *dev = (ram_page_t *) priv; +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 3) + uint32_t old = addr; +#endif /* Write the data. */ - *(uint8_t *) (dev->ems[(addr & 0xffff) >> 14].addr + (addr & 0x3fff)) = val; + addr = addr - dev->virt_base + dev->phys_base; +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 3) + neat_log("[W08] %08X -> %08X (%08X): val = %02X\n", old, addr, (mem_size << 10), val); +#endif + + if (addr < (mem_size << 10)) + *(uint8_t *) &(ram[addr]) = val; } /* Write one word to paged RAM. */ static void ems_writew(uint32_t addr, uint16_t val, void *priv) { - neat_t *dev = (neat_t *) priv; + ram_page_t *dev = (ram_page_t *) priv; +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 3) + uint32_t old = addr; +#endif /* Write the data. */ - *(uint16_t *) (dev->ems[(addr & 0xffff) >> 14].addr + (addr & 0x3fff)) = val; + addr = addr - dev->virt_base + dev->phys_base; +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 3) + neat_log("[W16] %08X -> %08X (%08X): val = %04X\n", old, addr, (mem_size << 10), val); +#endif + + if (addr < (mem_size << 10)) + *(uint16_t *) &(ram[addr]) = val; +} + +static void +neat_mem_update_state(neat_t *dev, uint32_t addr, uint32_t size, uint8_t new_flags, uint8_t mask) +{ + if ((addr < 0x00100000) && + ((new_flags ^ dev->mem_flags[addr / EMS_PGSIZE]) & mask)) { + dev->mem_flags[addr / EMS_PGSIZE] &= ~mask; + dev->mem_flags[addr / EMS_PGSIZE] |= new_flags; + + new_flags = dev->mem_flags[addr / EMS_PGSIZE]; + + if (new_flags & MEM_FLAG_ROMCS) { + neat_log("neat_mem_update_state(): %08X-%08X: %02X (ROMCS)\n", addr, addr + size - 1, new_flags); + mem_set_mem_state(addr, size, MEM_READ_ROMCS | MEM_WRITE_ROMCS); + } else if (new_flags & MEM_FLAG_REMAP) { + neat_log("neat_mem_update_state(): %08X-%08X: %02X (REMAP)\n", addr, addr + size - 1, new_flags); + mem_set_mem_state(addr, size, MEM_READ_EXTERNAL | MEM_WRITE_EXTERNAL); + } else if (new_flags & MEM_FLAG_EMS) { + neat_log("neat_mem_update_state(): %08X-%08X: %02X (EMS)\n", addr, addr + size - 1, new_flags); + mem_set_mem_state(addr, size, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + } else switch (new_flags & (MEM_FLAG_READ | MEM_FLAG_WRITE)) { + case 0: + neat_log("neat_mem_update_state(): %08X-%08X: %02X (RE | WE)\n", addr, addr + size - 1, new_flags); + mem_set_mem_state(addr, size, MEM_READ_EXTERNAL | MEM_WRITE_EXTERNAL); + break; + case 1: + neat_log("neat_mem_update_state(): %08X-%08X: %02X (RE | WI)\n", addr, addr + size - 1, new_flags); + mem_set_mem_state(addr, size, MEM_READ_EXTERNAL | MEM_WRITE_INTERNAL); + break; + case 2: + neat_log("neat_mem_update_state(): %08X-%08X: %02X (RI | WE)\n", addr, addr + size - 1, new_flags); + mem_set_mem_state(addr, size, MEM_READ_INTERNAL | MEM_WRITE_EXTERNAL); + break; + case 3: + neat_log("neat_mem_update_state(): %08X-%08X: %02X (RI | WI)\n", addr, addr + size - 1, new_flags); + mem_set_mem_state(addr, size, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + break; + default: + break; + } + } + + flushmmucache_nopc(); +} + +static void +shadow_recalc(neat_t *dev) +{ + for (uint8_t i = 8; i < 32; i++) { + int romcs = 0; + int write = 1; + int shadow_reg = REG_RB3 + ((i - 8) >> 3); + int shadow_bit = i & 7; + int mem_flags; + int read; + + if (i >= 16) { + int rb1_romcs_bit = 7 - (i >> 2); + int rb1_write_bit = rb1_romcs_bit + 4; + + romcs = !(dev->regs[REG_RB1] & (1 << rb1_romcs_bit)); + write = !(dev->regs[REG_RB1] & (1 << rb1_write_bit)); + neat_log("Shadow %08X-%08X: [%02X, %02X] %02X:%02X, %02X, %02X\n", + dev->shadow[i].virt_base, dev->shadow[i].virt_base + EMS_PGSIZE - 1, + dev->regs[REG_RB1], dev->regs[shadow_reg], + shadow_reg, shadow_bit, + rb1_romcs_bit, rb1_write_bit); + } else { + shadow_bit ^= 4; + neat_log("Shadow %08X-%08X: [--, %02X] %02X:%02X, shadow bit ^= 4\n", + dev->shadow[i].virt_base, dev->shadow[i].virt_base + EMS_PGSIZE - 1, + dev->regs[shadow_reg], + shadow_reg, shadow_bit); + } + + read = dev->regs[shadow_reg] & (1 << shadow_bit); + write = write && read; + + mem_flags = romcs ? MEM_FLAG_ROMCS : 0x00; + mem_flags |= read ? MEM_FLAG_READ : 0x00; + mem_flags |= write ? MEM_FLAG_WRITE : 0x00; + + if ((mem_flags > 0x00) && !(mem_flags & MEM_FLAG_ROMCS)) + mem_mapping_set_addr(&(dev->shadow[i].mapping), dev->shadow[i].virt_base, EMS_PGSIZE); + else + mem_mapping_disable(&(dev->shadow[i].mapping)); + + neat_mem_update_state(dev, dev->shadow[i].virt_base, EMS_PGSIZE, mem_flags, MEM_FMASK_SHADOW); + } } /* Re-calculate the active-page physical address. */ static void -ems_recalc(neat_t *dev, emspage_t *ems) +ems_recalc(neat_t *dev, ram_page_t *ems) { - if (ems->page >= dev->ems_pages) { - /* That page does not exist. */ - ems->enabled = 0; - } + uint32_t page = ems->phys_base / EMS_PGSIZE; - /* Pre-calculate the page address in EMS RAM. */ - ems->addr = ram + ems->start + (ems->page * EMS_PGSIZE); + neat_log("ems_recalc(): %08X, %04X, %04X\n", ems->virt_base, page, dev->ems_pages); + + if ((dev->regs[REG_RB7] & RB7_EMSEN) && ems->enabled && (page < dev->ems_pages)) { + neat_log("ems_recalc(): %08X-%08X -> %08X-%08X\n", + ems->virt_base, ems->virt_base + EMS_PGSIZE - 1, + ems->phys_base, ems->phys_base + EMS_PGSIZE - 1); + mem_mapping_set_addr(&ems->mapping, ems->virt_base, EMS_PGSIZE); - if (ems->enabled) { /* Update the EMS RAM address for this page. */ - mem_mapping_set_exec(&ems->mapping, ems->addr); + mem_mapping_set_exec(&ems->mapping, ram + ems->phys_base); - /* Enable this page. */ - mem_mapping_enable(&ems->mapping); + neat_mem_update_state(dev, ems->virt_base, EMS_PGSIZE, MEM_FLAG_EMS, MEM_FMASK_EMS); -#if NEAT_DEBUG > 1 +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 2) neat_log("NEAT EMS: page %d set to %08lx, %sabled)\n", ems->page, ems->addr - ram, ems->enabled ? "en" : "dis"); #endif } else { /* Disable this page. */ mem_mapping_disable(&ems->mapping); + + neat_mem_update_state(dev, ems->virt_base, EMS_PGSIZE, 0x00, MEM_FMASK_EMS); } } static void ems_write(uint16_t port, uint8_t val, void *priv) { - neat_t *dev = (neat_t *) priv; - emspage_t *ems; - int vpage; + neat_t *dev = (neat_t *) priv; + ram_page_t *ems; + int vpage; + int8_t old_enabled; + uint32_t old_phys_base; + int8_t new_enabled; + uint32_t new_phys_base; -#if NEAT_DEBUG > 1 +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 2) neat_log("NEAT: ems_write(%04x, %02x)\n", port, val); #endif @@ -333,13 +558,29 @@ ems_write(uint16_t port, uint8_t val, void *priv) vpage = (port / EMS_PGSIZE); ems = &dev->ems[vpage]; + neat_log("Port: %04X, val: %02X\n", port, val); + switch (port & 0x000f) { case 0x0008: case 0x0009: - ems->enabled = !!(val & 0x80); - ems->page &= 0x0180; /* clear lower bits */ - ems->page |= (val & 0x7f); /* add new bits */ - ems_recalc(dev, ems); + old_enabled = ems->enabled; + old_phys_base = ems->phys_base; + new_enabled = !!(val & 0x80); + new_phys_base = (ems->phys_base & 0xffe00000) | ((val & 0x7f) * EMS_PGSIZE); + + if ((old_enabled != new_enabled) || (old_phys_base != new_phys_base)) { + if (old_enabled && (old_enabled == new_enabled)) { + ems->enabled = 0; + ems_recalc(dev, ems); + } + + ems->enabled = !!(val & 0x80); + + if (old_phys_base != new_phys_base) + ems->phys_base = (ems->phys_base & 0xffe00000) | ((val & 0x7f) * EMS_PGSIZE); + + ems_recalc(dev, ems); + } break; default: break; @@ -358,7 +599,8 @@ ems_read(uint16_t port, void *priv) switch (port & 0x000f) { case 0x0008: /* page number register */ - ret = dev->ems[vpage].page & 0x7f; + case 0x0009: + ret = (dev->ems[vpage].phys_base / EMS_PGSIZE) & 0x7f; if (dev->ems[vpage].enabled) ret |= 0x80; break; @@ -366,75 +608,97 @@ ems_read(uint16_t port, void *priv) break; } -#if NEAT_DEBUG > 1 + neat_log("Port: %04X, ret: %02X\n", port, ret); + +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 2) neat_log("NEAT: ems_read(%04x) = %02x\n", port, ret); #endif return ret; } -/* Initialize the EMS module. */ static void -ems_init(neat_t *dev, int en) +ems_recalc_all(neat_t *dev) { - uint8_t j; + for (uint8_t i = 0; i < EMS_MAXPAGE; i++) + ems_recalc(dev, &(dev->ems[i])); +} - /* Remove if needed. */ - if (!en) { - if (dev->ems_base > 0) - for (uint8_t i = 0; i < EMS_MAXPAGE; i++) { - /* Disable for now. */ - mem_mapping_disable(&dev->ems[i].mapping); +static void +ems_update_virt_base(neat_t *dev) +{ + for (uint8_t i = 0; i < EMS_MAXPAGE; i++) + dev->ems[i].virt_base = dev->ems_frame + (i * EMS_PGSIZE); +} - /* Remove I/O handler. */ - io_removehandler(dev->ems_base + (i * EMS_PGSIZE), 2, - ems_read, NULL, NULL, ems_write, NULL, NULL, dev); - } - -#ifdef ENABLE_NEAT_LOG - neat_log("NEAT: EMS disabled\n"); -#endif - - return; - } - - /* Get configured I/O address. */ - j = (dev->regs[REG_RB9] & RB9_BASE) >> RB9_BASE_SH; - dev->ems_base = 0x0208 + (0x10 * j); - - /* Get configured frame address. */ - 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. - */ +static void +ems_remove_handlers(neat_t *dev) +{ 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, - ems_readb, ems_readw, NULL, - ems_writeb, ems_writew, NULL, - ram, MEM_MAPPING_EXTERNAL, - dev); - - /* Disable for now. */ - mem_mapping_disable(&dev->ems[i].mapping); + neat_log("Removing I/O handler at %04X-%04X\n", + dev->ems_base + (i * EMS_PGSIZE), dev->ems_base + (i * EMS_PGSIZE) + 1); + /* Clean up any previous I/O port handler. */ + io_removehandler(dev->ems_base + (i * EMS_PGSIZE), 2, + ems_read, NULL, NULL, ems_write, NULL, NULL, dev); + } +} +static void +ems_set_handlers(neat_t *dev) +{ + for (uint8_t i = 0; i < EMS_MAXPAGE; i++) { + neat_log("Setting up I/O handler at %04X-%04X\n", + dev->ems_base + (i * EMS_PGSIZE), dev->ems_base + (i * EMS_PGSIZE) + 1); /* Set up an I/O port handler. */ io_sethandler(dev->ems_base + (i * EMS_PGSIZE), 2, ems_read, NULL, NULL, ems_write, NULL, NULL, dev); - - /* - * TODO: update the 'high_mem' mapping to reflect that we now - * have NN MB less extended memory available.. - */ } - neat_log("NEAT: EMS enabled, I/O=%04xH, Frame=%05XH\n", - dev->ems_base, dev->ems_frame); + ems_recalc_all(dev); +} + +static void +remap_update_states(neat_t *dev, uint8_t flag) +{ + for (uint8_t i = 0; i < 24; i++) + neat_mem_update_state(dev, 0x000a0000 + (i * EMS_PGSIZE), EMS_PGSIZE, flag, MEM_FMASK_REMAP); +} + +static void +remap_update(neat_t *dev, uint8_t val) +{ + if (dev->regs[REG_RB7] & RB7_UMAREL) { + mem_remap_top_ex_nomid(0, (dev->remap_base >= 1024) ? dev->remap_base : 1024); + + remap_update_states(dev, 0x00); + neat_log("0 kB at %08X\n", ((dev->remap_base >= 1024) ? dev->remap_base : 1024) << 10); + } + + if (val & RB7_EMSEN) + dev->remap_base = mem_size - dev->ems_size; + else + dev->remap_base = mem_size; + neat_log("Total contiguous memory now: %i kB\n", dev->remap_base); + + if (dev->remap_base >= 640) + mem_mapping_set_addr(&ram_low_mapping, 0x00000000, 0x000a0000); + else + mem_mapping_set_addr(&ram_low_mapping, 0x00000000, dev->remap_base << 10); + + if (dev->remap_base > 1024) { + uint32_t base = (val & RB7_EMSEN) ? (0x00100000 + (dev->ems_size << 10)) : 0x00100000; + + mem_mapping_set_addr(&ram_high_mapping, 0x00100000, (dev->remap_base << 10) - 0x00100000); + mem_mapping_set_exec(&ram_high_mapping, &(ram[base])); + } else + mem_mapping_disable(&ram_high_mapping); + + if (val & RB7_UMAREL) { + mem_remap_top_ex_nomid(384, (dev->remap_base >= 1024) ? dev->remap_base : 1024); + + remap_update_states(dev, MEM_FLAG_REMAP); + neat_log("384 kB at %08X\n", ((dev->remap_base >= 1024) ? dev->remap_base : 1024) << 10); + } } static void @@ -442,10 +706,12 @@ neat_write(uint16_t port, uint8_t val, void *priv) { neat_t *dev = (neat_t *) priv; uint8_t xval; + uint8_t j; uint8_t *reg; + uint8_t mask; int i; -#if NEAT_DEBUG > 2 +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 2) neat_log("NEAT: write(%04x, %02x)\n", port, val); #endif @@ -457,150 +723,209 @@ neat_write(uint16_t port, uint8_t val, void *priv) case 0x23: reg = &dev->regs[dev->indx]; xval = *reg ^ val; + mask = reg_masks[dev->sx][dev->indx & REG_MASK]; switch (dev->indx) { case REG_RA0: - val &= RA0_MASK; - *reg = (*reg & ~RA0_MASK) | val | (RA0_REV_ID << RA0_REV_SH); -#if NEAT_DEBUG > 1 + val &= mask; + *reg = (*reg & ~mask) | val | (RA0_REV_ID << RA0_REV_SH); + if ((xval & 0x20) && (val & 0x20)) + outb(0x64, 0xfe); +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 2) neat_log("NEAT: RA0=%02x(%02x)\n", val, *reg); #endif break; case REG_RA1: - val &= RA1_MASK; - *reg = (*reg & ~RA1_MASK) | val; -#if NEAT_DEBUG > 1 + val &= mask; + *reg = (*reg & ~mask) | val; +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 2) neat_log("NEAT: RA1=%02x(%02x)\n", val, *reg); #endif break; case REG_RA2: - val &= RA2_MASK; - *reg = (*reg & ~RA2_MASK) | val; -#if NEAT_DEBUG > 1 + val &= mask; + *reg = (*reg & ~mask) | val; +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 2) neat_log("NEAT: RA2=%02x(%02x)\n", val, *reg); #endif break; case REG_RB0: - val &= RB0_MASK; - *reg = (*reg & ~RB0_MASK) | val | (RB0_REV_ID << RB0_REV_SH); -#if NEAT_DEBUG > 1 + val &= mask; + *reg = (*reg & ~mask) | val | (RB0_REV_ID << RB0_REV_SH); +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 2) neat_log("NEAT: RB0=%02x(%02x)\n", val, *reg); #endif break; case REG_RB1: - val &= RB1_MASK; - *reg = (*reg & ~RB1_MASK) | val; -#if NEAT_DEBUG > 1 + val &= mask; + *reg = (*reg & ~mask) | val; + shadow_recalc(dev); +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 2) neat_log("NEAT: RB1=%02x(%02x)\n", val, *reg); #endif break; case REG_RB2: - val &= RB2_MASK; - *reg = (*reg & ~RB2_MASK) | val; -#if NEAT_DEBUG > 1 + val &= mask; + *reg = (*reg & ~mask) | val; + if (dev->sx) { + if (val & RB2_BOT256) + neat_mem_update_state(dev, 0x00000000, 0x00040000, + MEM_FLAG_READ | MEM_FLAG_WRITE, MEM_FMASK_SHADOW); + else + neat_mem_update_state(dev, 0x00000000, 0x00040000, + 0x00, MEM_FMASK_SHADOW); + + if (val & RB2_MID256) + neat_mem_update_state(dev, 0x00040000, 0x00040000, + MEM_FLAG_READ | MEM_FLAG_WRITE, MEM_FMASK_SHADOW); + else + neat_mem_update_state(dev, 0x00040000, 0x00040000, + 0x00, MEM_FMASK_SHADOW); + } + if (val & RB2_TOP128) + neat_mem_update_state(dev, 0x00080000, 0x00020000, + MEM_FLAG_READ | MEM_FLAG_WRITE, MEM_FMASK_SHADOW); + else + neat_mem_update_state(dev, 0x00080000, 0x00020000, + 0x00, MEM_FMASK_SHADOW); +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 2) neat_log("NEAT: RB2=%02x(%02x)\n", val, *reg); #endif break; case REG_RB3: - val &= RB3_MASK; - *reg = (*reg & ~RB3_MASK) | val; -#if NEAT_DEBUG > 1 + val &= mask; + *reg = (*reg & ~mask) | val; + shadow_recalc(dev); +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 2) neat_log("NEAT: RB3=%02x(%02x)\n", val, *reg); #endif break; case REG_RB4: - val &= RB4_MASK; - *reg = (*reg & ~RB4_MASK) | val; -#if NEAT_DEBUG > 1 + val &= mask; + *reg = (*reg & ~mask) | val; + shadow_recalc(dev); +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 2) neat_log("NEAT: RB4=%02x(%02x)\n", val, *reg); #endif break; case REG_RB5: - val &= RB5_MASK; - *reg = (*reg & ~RB5_MASK) | val; -#if NEAT_DEBUG > 1 + val &= mask; + *reg = (*reg & ~mask) | val; + shadow_recalc(dev); +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 2) neat_log("NEAT: RB5=%02x(%02x)\n", val, *reg); #endif break; case REG_RB6: - val &= RB6_MASK; - *reg = (*reg & ~RB6_MASK) | val; -#if NEAT_DEBUG > 1 + val &= mask; + *reg = (*reg & ~mask) | val; +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 2) neat_log("NEAT: RB6=%02x(%02x)\n", val, *reg); #endif break; case REG_RB7: - val &= RB7_MASK; - *reg = val; -#if NEAT_DEBUG > 1 + val &= mask; + + if (xval & (RB7_EMSEN | RB7_UMAREL)) + remap_update(dev, val); + + *reg = (*reg & ~mask) | val; + + if (xval & RB7_EMSEN) + ems_remove_handlers(dev); + + if ((xval & RB7_EMSEN) && (val & RB7_EMSEN)) + ems_set_handlers(dev); + +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 2) neat_log("NEAT: RB7=%02x(%02x)\n", val, *reg); #endif - if (val & RB7_EMSEN) - ems_init(dev, 1); - else if (xval & RB7_EMSEN) - ems_init(dev, 0); - - if (xval & RB7_UMAREL) { - if (val & RB7_UMAREL) - mem_remap_top(384); - else - mem_remap_top(0); - } break; case REG_RB8: - val &= RB8_MASK; - *reg = (*reg & ~RB8_MASK) | val; -#if NEAT_DEBUG > 1 + val &= mask; + *reg = (*reg & ~mask) | val; +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 2) neat_log("NEAT: RB8=%02x(%02x)\n", val, *reg); #endif break; case REG_RB9: - val &= RB9_MASK; - *reg = (*reg & ~RB9_MASK) | val; -#if NEAT_DEBUG > 1 + val &= mask; + *reg = (*reg & ~mask) | val; +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 2) neat_log("NEAT: RB9=%02x(%02x)\n", val, *reg); #endif - if (dev->regs[REG_RB7] & RB7_EMSEN) { - ems_init(dev, 0); - ems_init(dev, 1); - } + + ems_remove_handlers(dev); + + /* Get configured I/O address. */ + j = (dev->regs[REG_RB9] & RB9_BASE) >> RB9_BASE_SH; + dev->ems_base = 0x0208 + (0x10 * j); + + /* Get configured frame address. */ + j = (dev->regs[REG_RB9] & RB9_FRAME) >> RB9_FRAME_SH; + dev->ems_frame = 0xc0000 + (EMS_PGSIZE * j); + + ems_update_virt_base(dev); + + if (dev->regs[REG_RB7] & RB7_EMSEN) + ems_set_handlers(dev); break; case REG_RB10: - val &= RB10_MASK; - *reg = (*reg & ~RB10_MASK) | val; -#if NEAT_DEBUG > 1 + val &= mask; + *reg = (*reg & ~mask) | val; +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 2) neat_log("NEAT: RB10=%02x(%02x)\n", val, *reg); #endif - dev->ems[3].start = ((val & RB10_P3EXT) >> RB10_P3EXT_SH) << 21; - dev->ems[2].start = ((val & RB10_P2EXT) >> RB10_P2EXT_SH) << 21; - dev->ems[1].start = ((val & RB10_P1EXT) >> RB10_P1EXT_SH) << 21; - dev->ems[0].start = ((val & RB10_P0EXT) >> RB10_P0EXT_SH) << 21; - for (i = 0; i < EMS_MAXPAGE; i++) - ems_recalc(dev, &dev->ems[i]); + for (uint8_t i = 0; i < EMS_MAXPAGE; i++) { + ram_page_t *ems = &(dev->ems[i]); + + uint32_t old_phys_base = ems->phys_base & 0xffe00000; + uint32_t new_phys_base = (((val & masks[i]) >> shifts[i]) << 21); + + if (new_phys_base != old_phys_base) { + int8_t old_enabled = ems->enabled; + + if ((dev->regs[REG_RB7] & RB7_EMSEN) && old_enabled) { + ems->enabled = 0; + ems_recalc(dev, &(dev->ems[i])); + } + + ems->phys_base = ems->phys_base - old_phys_base + new_phys_base; + + if ((dev->regs[REG_RB7] & RB7_EMSEN) && old_enabled) { + ems->enabled = old_enabled; + ems_recalc(dev, &(dev->ems[i])); + } + } + } + + neat_log("%08X, %08X, %08X, %08X\n", + dev->ems[0].phys_base, dev->ems[1].phys_base, + dev->ems[2].phys_base, dev->ems[3].phys_base); break; - case REG_RB11: - val &= RB11_MASK; - *reg = (*reg & ~RB11_MASK) | val; -#if NEAT_DEBUG > 1 - neat_log("NEAT: RB11=%02x(%02x)\n", val, *reg); + case REG_RB12: + val &= mask; + *reg = (*reg & ~mask) | val; +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 2) + neat_log("NEAT: RB12=%02x(%02x)\n", val, *reg); #endif - i = (val & RB11_EMSLEN) >> RB11_EMSLEN_SH; + i = (val & RB12_EMSLEN) >> RB12_EMSLEN_SH; switch (i) { - case 0: /* "less than 2MB" */ + case 0: /* "less than 1MB" */ dev->ems_size = 512; break; @@ -616,11 +941,24 @@ neat_write(uint16_t port, uint8_t val, void *priv) default: break; } - dev->ems_pages = (dev->ems_size << 10) / EMS_PGSIZE; + + if (mem_size < 1024) + /* No RAM left for EMS at all. */ + dev->ems_size = 0; + else if (mem_size < (dev->ems_size + 1024)) + /* Limit EMS size to the entirety of the remaining extended memory. */ + dev->ems_size = mem_size - 1024; + if (dev->regs[REG_RB7] & RB7_EMSEN) { - neat_log("NEAT: EMS %iKB (%i pages)\n", - dev->ems_size, dev->ems_pages); + remap_update(dev, dev->regs[REG_RB7]); + + neat_log("NEAT: EMS %iKB\n", + dev->ems_size); } + + mem_a20_alt = !(val & RB12_GA20); + mem_a20_recalc(); + flushmmucache(); break; default: @@ -629,6 +967,7 @@ neat_write(uint16_t port, uint8_t val, void *priv) break; } break; + default: break; } @@ -646,15 +985,17 @@ neat_read(uint16_t port, void *priv) break; case 0x23: - if ((dev->indx >= 0x60) && (dev->indx <= 0x6f)) + if ((dev->indx >= 0x60) && (dev->indx <= 0x6e)) ret = dev->regs[dev->indx]; + else if (dev->indx == 0x6f) + ret = (dev->regs[dev->indx] & 0xfd) | ((~mem_a20_alt) & 0x02); break; default: break; } -#if NEAT_DEBUG > 2 +#if defined(ENABLE_NEAT_LOG) && (ENABLE_NEAT_LOG == 2) neat_log("NEAT: read(%04x) = %02x\n", port, ret); #endif @@ -674,16 +1015,86 @@ neat_init(UNUSED(const device_t *info)) { neat_t *dev; uint8_t dram_mode = 0; - uint8_t i; + uint8_t j; /* Create an instance. */ - dev = (neat_t *) malloc(sizeof(neat_t)); - memset(dev, 0x00, sizeof(neat_t)); + dev = (neat_t *) calloc(1, sizeof(neat_t)); + + dev->sx = info->local; + + if (mem_size > 1024) { + mem_mapping_set_handler(&ram_high_mapping, neat_read_ram, neat_read_ramw, NULL, + neat_write_ram, neat_write_ramw, NULL); + mem_mapping_set_p(&ram_high_mapping, dev); + } + + /* Get configured I/O address. */ + j = (dev->regs[REG_RB9] & RB9_BASE) >> RB9_BASE_SH; + dev->ems_base = 0x0208 + (0x10 * j); + + /* Get configured frame address. */ + j = (dev->regs[REG_RB9] & RB9_FRAME) >> RB9_FRAME_SH; + dev->ems_frame = 0xc0000 + (EMS_PGSIZE * j); + + ems_update_virt_base(dev); + + dev->ems_pages = (mem_size << 10) / EMS_PGSIZE; + dev->remap_base = mem_size; + + mem_mapping_disable(&ram_mid_mapping); + + for (int i = 0; i < 24; i++) { + if (i >= 20) + neat_mem_update_state(dev, 0x000a0000 + (i * EMS_PGSIZE), EMS_PGSIZE, MEM_FLAG_ROMCS, MEM_FMASK_SHADOW); + else { + /* This is needed to actually trigger an update. */ + dev->mem_flags[i + 40] = MEM_FLAG_ROMCS; + neat_mem_update_state(dev, 0x000a0000 + (i * EMS_PGSIZE), EMS_PGSIZE, 0x00, MEM_FMASK_SHADOW); + } + } + + /* + * 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 (uint8_t i = 0; i < EMS_MAXPAGE; i++) { + /* Create and initialize a page mapping. */ + mem_mapping_add(&dev->ems[i].mapping, + 0x00000000, 0x00000000, + ems_readb, ems_readw, NULL, + ems_writeb, ems_writew, NULL, + ram + dev->ems[i].virt_base, MEM_MAPPING_INTERNAL, + &(dev->ems[i])); + + /* Disable for now. */ + mem_mapping_disable(&dev->ems[i].mapping); + } + + for (uint8_t i = 0; i < 32; i++) { + dev->shadow[i].virt_base = dev->shadow[i].phys_base = + (i * EMS_PGSIZE) + 0x00080000; + dev->shadow[i].enabled = 1; + + /* Create and initialize a page mapping. */ + mem_mapping_add(&dev->shadow[i].mapping, + dev->shadow[i].virt_base, EMS_PGSIZE, + ems_readb, ems_readw, NULL, + ems_writeb, ems_writew, NULL, + ram + dev->shadow[i].virt_base, MEM_MAPPING_INTERNAL, + &(dev->shadow[i])); + + /* Disable for now. */ + mem_mapping_disable(&dev->shadow[i].mapping); + } /* Initialize some of the registers to specific defaults. */ - for (i = REG_RA0; i <= REG_RB11; i++) { + for (uint8_t i = REG_RA0; i <= REG_RB12; i++) { dev->indx = i; - neat_write(0x0023, 0x00, dev); + uint8_t def = defaults[dev->sx][i & REG_MASK]; + if ((i == REG_RA2) && (fpu_type == FPU_387)) + def |= RA2_387SX; + neat_write(0x0023, def, dev); } /* @@ -817,7 +1228,7 @@ neat_init(UNUSED(const device_t *info)) neat_log("NEAT: **INVALID DRAM SIZE %iKB !**\n", mem_size); } if (dram_mode > 0) { - neat_log("NEAT: using DRAM mode #%i (mem=%iKB)\n", i, mem_size); + neat_log("NEAT: using DRAM mode #%i (mem=%iKB)\n", dram_mode, mem_size); } /* Set up an I/O handler for the chipset. */ @@ -828,14 +1239,28 @@ neat_init(UNUSED(const device_t *info)) } const device_t neat_device = { - .name = "C&T CS8121 (NEAT)", + .name = "C&T CS8221 (NEAT)", .internal_name = "neat", .flags = 0, .local = 0, .init = neat_init, .close = neat_close, .reset = NULL, - { .available = NULL }, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t neat_sx_device = { + .name = "C&T CS8281 (NEATsx)", + .internal_name = "neat_sx", + .flags = 0, + .local = 1, + .init = neat_init, + .close = neat_close, + .reset = NULL, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/olivetti_eva.c b/src/chipset/olivetti_eva.c index 1f5eacc6c..0dcbdd21f 100644 --- a/src/chipset/olivetti_eva.c +++ b/src/chipset/olivetti_eva.c @@ -73,26 +73,24 @@ olivetti_eva_write(uint16_t addr, uint8_t val, void *priv) break; case 0x069: dev->reg_069 = val; - /* - * Unfortunately, if triggered, the BIOS remapping function fails causing - * a fatal error. Therefore, this code section is currently commented. - */ -#if 0 - if (val & 1) { + mem_remap_top(0); + if (val == 0x01) { /* * Set the register to 7 or above for the BIOS to trigger the * memory remapping function if shadowing is active. */ - dev->reg_069 = 0x7; + dev->reg_069 = 0x07; } - if (val & 8) { + if (val & 0x08) { /* * Activate shadowing for region e0000-fffff */ mem_remap_top(256); - mem_set_mem_state_both(0xa0000, 0x60000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + mem_set_mem_state_both(0xe0000, 0x20000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + } else { + mem_remap_top(384); + mem_set_mem_state_both(0xe0000, 0x20000, MEM_READ_EXTANY | MEM_WRITE_EXTANY); } -#endif break; default: break; @@ -134,8 +132,7 @@ olivetti_eva_close(void *priv) static void * 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)); + olivetti_eva_t *dev = (olivetti_eva_t *) calloc(1, sizeof(olivetti_eva_t)); /* GA98 registers */ dev->reg_065 = 0x00; @@ -144,7 +141,7 @@ olivetti_eva_init(UNUSED(const device_t *info)) dev->reg_067 = 0x00; /* RAM enable registers */ - dev->reg_069 = 0x0; + dev->reg_069 = 0x00; io_sethandler(0x0065, 0x0001, olivetti_eva_read, NULL, NULL, olivetti_eva_write, NULL, NULL, dev); io_sethandler(0x0067, 0x0001, olivetti_eva_read, NULL, NULL, olivetti_eva_write, NULL, NULL, dev); @@ -153,13 +150,6 @@ olivetti_eva_init(UNUSED(const device_t *info)) /* When shadowing is not enabled in BIOS, all upper memory is available as XMS */ mem_remap_top(384); - /* - * Default settings when NVRAM is cleared activate shadowing. - * Thus, to avoid boot errors, remap only 256k from UMB to XMS. - * Remove this block once BIOS memory remapping works. - */ - mem_remap_top(256); - return dev; } @@ -171,7 +161,7 @@ const device_t olivetti_eva_device = { .init = olivetti_eva_init, .close = olivetti_eva_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/opti283.c b/src/chipset/opti283.c index 63976985b..81780cf10 100644 --- a/src/chipset/opti283.c +++ b/src/chipset/opti283.c @@ -16,6 +16,7 @@ * Copyright 2021 Tiseno100. * Copyright 2021 Miran Grca. */ +#include #include #include #include @@ -158,7 +159,20 @@ opti283_shadow_recalc(opti283_t *dev) rom = dev->regs[0x11] & (1 << ((i >> 2) + 4)); opti283_log("OPTI 283: %i/%08X: %i, %i, %i\n", i, base, (i >= 4) ? (1 << (i - 4)) : (1 << (i + 4)), (1 << (i >> 2)), (1 << ((i >> 2) + 4))); - if (sh_enable && rom) { + if (sh_copy) { + if (base >= 0x000e0000) + shadowbios_write |= 1; + if (base >= 0x000d0000) + dev->shadow_high |= 1; + + if (base >= 0xe0000) { + mem_set_mem_state_both(base, 0x4000, MEM_READ_EXTANY | MEM_WRITE_INTERNAL); + opti283_log("OPTI 283: %08X-%08X READ_EXTANY, WRITE_INTERNAL\n", base, base + 0x3fff); + } else { + mem_set_mem_state_both(base, 0x4000, MEM_READ_EXTERNAL | MEM_WRITE_INTERNAL); + opti283_log("OPTI 283: %08X-%08X READ_EXTERNAL, WRITE_INTERNAL\n", base, base + 0x3fff); + } + } else if (sh_enable && rom) { if (base >= 0x000e0000) shadowbios |= 1; if (base >= 0x000d0000) @@ -171,13 +185,8 @@ opti283_shadow_recalc(opti283_t *dev) if (base >= 0x000e0000) shadowbios_write |= 1; - if (sh_copy) { - mem_set_mem_state_both(base, 0x4000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); - opti283_log("OPTI 283: %08X-%08X READ_INTERNAL, WRITE_INTERNAL\n", base, base + 0x3fff); - } else { - mem_set_mem_state_both(base, 0x4000, MEM_READ_INTERNAL | MEM_WRITE_EXTERNAL); - opti283_log("OPTI 283: %08X-%08X READ_INTERNAL, WRITE_EXTERNAL\n", base, base + 0x3fff); - } + mem_set_mem_state_both(base, 0x4000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + opti283_log("OPTI 283: %08X-%08X READ_INTERNAL, WRITE_INTERNAL\n", base, base + 0x3fff); } } else { if (base >= 0xe0000) { @@ -239,9 +248,21 @@ opti283_write(uint16_t addr, uint8_t val, void *priv) dev->regs[dev->index] = (dev->regs[dev->index] & 0x80) | (val & 0x7f); break; - case 0x14: + case 0x14: { + double bus_clk; + switch (val & 0x01) { + default: + case 0x00: + bus_clk = cpu_busspeed / 6.0; + break; + case 0x01: + bus_clk = cpu_busspeed / 4.0; + break; + } + cpu_set_isa_speed((int) round(bus_clk)); reset_on_hlt = !!(val & 0x40); fallthrough; + } case 0x11: case 0x12: case 0x13: @@ -284,8 +305,7 @@ opti283_close(void *priv) static void * opti283_init(UNUSED(const device_t *info)) { - opti283_t *dev = (opti283_t *) malloc(sizeof(opti283_t)); - memset(dev, 0x00, sizeof(opti283_t)); + opti283_t *dev = (opti283_t *) calloc(1, sizeof(opti283_t)); io_sethandler(0x0022, 0x0001, opti283_read, NULL, NULL, opti283_write, NULL, NULL, dev); io_sethandler(0x0023, 0x0001, opti283_read, NULL, NULL, opti283_write, NULL, NULL, dev); @@ -311,6 +331,8 @@ opti283_init(UNUSED(const device_t *info)) opti283_shadow_recalc(dev); + cpu_set_isa_speed((int) round(cpu_busspeed / 6.0)); + device_add(&port_92_device); return dev; @@ -324,7 +346,7 @@ const device_t opti283_device = { .init = opti283_init, .close = opti283_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/opti291.c b/src/chipset/opti291.c index 6d2256974..91b9010e2 100644 --- a/src/chipset/opti291.c +++ b/src/chipset/opti291.c @@ -138,8 +138,7 @@ opti291_close(void *priv) static void * opti291_init(UNUSED(const device_t *info)) { - opti291_t *dev = (opti291_t *) malloc(sizeof(opti291_t)); - memset(dev, 0, sizeof(opti291_t)); + opti291_t *dev = (opti291_t *) calloc(1, sizeof(opti291_t)); io_sethandler(0x022, 0x0001, opti291_read, NULL, NULL, opti291_write, NULL, NULL, dev); io_sethandler(0x024, 0x0001, opti291_read, NULL, NULL, opti291_write, NULL, NULL, dev); @@ -161,7 +160,7 @@ const device_t opti291_device = { .init = opti291_init, .close = opti291_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/opti391.c b/src/chipset/opti391.c index c22c2a04b..7d3c10c98 100644 --- a/src/chipset/opti391.c +++ b/src/chipset/opti391.c @@ -374,7 +374,7 @@ const device_t opti381_device = { .init = opti391_init, .close = opti391_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -388,7 +388,7 @@ const device_t opti481_device = { .init = opti391_init, .close = opti391_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -402,7 +402,7 @@ const device_t opti391_device = { .init = opti391_init, .close = opti391_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/opti495.c b/src/chipset/opti495.c index 84ef6a202..8521dbd17 100644 --- a/src/chipset/opti495.c +++ b/src/chipset/opti495.c @@ -8,14 +8,13 @@ * * Implementation of the OPTi 82C493/82C495 chipset. * - * - * * Authors: Tiseno100, * Miran Grca, * * Copyright 2008-2020 Tiseno100. * Copyright 2016-2020 Miran Grca. */ +#include #include #include #include @@ -28,6 +27,7 @@ #include <86box/io.h> #include <86box/device.h> #include <86box/mem.h> +#include <86box/plat_fallthrough.h> #include <86box/port_92.h> #include <86box/chipset.h> @@ -166,6 +166,27 @@ opti495_write(uint16_t addr, uint8_t val, void *priv) case 0x26: opti495_recalc(dev); break; + + case 0x25: { + double bus_clk; + switch (val & 0x03) { + default: + case 0x00: + bus_clk = cpu_busspeed / 6.0; + break; + case 0x01: + bus_clk = cpu_busspeed / 4.0; + break; + case 0x02: + bus_clk = cpu_busspeed / 3.0; + break; + case 0x03: + bus_clk = (cpu_busspeed * 2.0) / 5.0; + break; + } + cpu_set_isa_speed((int) round(bus_clk)); + break; + } } } @@ -219,8 +240,7 @@ opti495_close(void *priv) static void * opti495_init(const device_t *info) { - opti495_t *dev = (opti495_t *) malloc(sizeof(opti495_t)); - memset(dev, 0, sizeof(opti495_t)); + opti495_t *dev = (opti495_t *) calloc(1, sizeof(opti495_t)); device_add(&port_92_device); @@ -260,6 +280,8 @@ opti495_init(const device_t *info) io_sethandler(0x00e1, 0x0002, opti495_read, NULL, NULL, opti495_write, NULL, NULL, dev); + cpu_set_isa_speed((int) round(cpu_busspeed / 6.0)); + return dev; } @@ -271,21 +293,35 @@ const device_t opti493_device = { .init = opti495_init, .close = opti495_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL }; -const device_t opti495_device = { +const device_t opti495slc_device = { .name = "OPTi 82C495", - .internal_name = "opti495", + .internal_name = "opti495slc", .flags = 0, - .local = OPTI495XLC, + .local = OPTI495SLC, .init = opti495_init, .close = opti495_close, .reset = NULL, - { .available = NULL }, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t opti495sx_device = { + .name = "OPTi 82C495SX", + .internal_name = "opti495sx", + .flags = 0, + .local = OPTI495SX, + .init = opti495_init, + .close = opti495_close, + .reset = NULL, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/opti498.c b/src/chipset/opti498.c new file mode 100644 index 000000000..2d3dc6709 --- /dev/null +++ b/src/chipset/opti498.c @@ -0,0 +1,360 @@ +/* + * 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 OPTi 82C498 chipset. + * + * Authors: Miran Grca, + * + * Copyright 2025 Miran Grca. + */ +#include +#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/mem.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> +#include <86box/port_92.h> +#include <86box/chipset.h> + +#ifdef ENABLE_OPTI498_LOG +int opti498_do_log = ENABLE_OPTI498_LOG; + +static void +opti498_log(const char *fmt, ...) +{ + va_list ap; + + if (opti498_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define opti498_log(fmt, ...) +#endif + +typedef struct mem_remapping_t { + uint32_t phys; + uint32_t virt; +} mem_remapping_t; + +typedef struct opti498_t { + uint8_t index; + /* 0x30 for 496/497, 0x70 for 498. */ + uint8_t reg_base; + uint8_t shadow_high; + uint8_t regs[256]; + mem_remapping_t mem_remappings[2]; + mem_mapping_t mem_mappings[2]; +} opti498_t; + +static uint8_t +opti498_read_remapped_ram(uint32_t addr, void *priv) +{ + const mem_remapping_t *dev = (mem_remapping_t *) priv; + + return mem_read_ram((addr - dev->virt) + dev->phys, priv); +} + +static uint16_t +opti498_read_remapped_ramw(uint32_t addr, void *priv) +{ + const mem_remapping_t *dev = (mem_remapping_t *) priv; + + return mem_read_ramw((addr - dev->virt) + dev->phys, priv); +} + +static uint32_t +opti498_read_remapped_raml(uint32_t addr, void *priv) +{ + const mem_remapping_t *dev = (mem_remapping_t *) priv; + + return mem_read_raml((addr - dev->virt) + dev->phys, priv); +} + +static void +opti498_write_remapped_ram(uint32_t addr, uint8_t val, void *priv) +{ + const mem_remapping_t *dev = (mem_remapping_t *) priv; + + mem_write_ram((addr - dev->virt) + dev->phys, val, priv); +} + +static void +opti498_write_remapped_ramw(uint32_t addr, uint16_t val, void *priv) +{ + const mem_remapping_t *dev = (mem_remapping_t *) priv; + + mem_write_ramw((addr - dev->virt) + dev->phys, val, priv); +} + +static void +opti498_write_remapped_raml(uint32_t addr, uint32_t val, void *priv) +{ + const mem_remapping_t *dev = (mem_remapping_t *) priv; + + mem_write_raml((addr - dev->virt) + dev->phys, val, priv); +} + +static void +opti498_shadow_recalc(opti498_t *dev) +{ + uint32_t base; + uint32_t rbase; + uint8_t sh_enable; + uint8_t sh_mode; + uint8_t rom; + uint8_t sh_copy; + + shadowbios = shadowbios_write = 0; + dev->shadow_high = 0; + + opti498_log("OPTI 498: %02X %02X %02X %02X\n", dev->regs[0x02], dev->regs[0x03], dev->regs[0x04], dev->regs[0x05]); + + if (dev->regs[0x02] & 0x80) { + if (dev->regs[0x04] & 0x02) { + mem_set_mem_state_both(0xf0000, 0x10000, MEM_READ_EXTANY | MEM_WRITE_EXTANY); + opti498_log("OPTI 498: F0000-FFFFF READ_EXTANY, WRITE_EXTANY\n"); + } else { + shadowbios_write = 1; + mem_set_mem_state_both(0xf0000, 0x10000, MEM_READ_EXTANY | MEM_WRITE_INTERNAL); + opti498_log("OPTI 498: F0000-FFFFF READ_EXTANY, WRITE_INTERNAL\n"); + } + } else { + shadowbios = 1; + mem_set_mem_state_both(0xf0000, 0x10000, MEM_READ_INTERNAL | MEM_WRITE_DISABLED); + opti498_log("OPTI 498: F0000-FFFFF READ_INTERNAL, WRITE_DISABLED\n"); + } + + sh_copy = dev->regs[0x02] & 0x08; + for (uint8_t i = 0; i < 12; i++) { + base = 0xc0000 + (i << 14); + if (i >= 4) + sh_enable = dev->regs[0x03] & (1 << (i - 4)); + else + sh_enable = dev->regs[0x04] & (1 << (i + 4)); + sh_mode = dev->regs[0x02] & (1 << (i >> 2)); + rom = dev->regs[0x02] & (1 << ((i >> 2) + 4)); + opti498_log("OPTI 498: %i/%08X: %i, %i, %i\n", i, base, (i >= 4) ? (1 << (i - 4)) : (1 << (i + 4)), (1 << (i >> 2)), (1 << ((i >> 2) + 4))); + + if (sh_copy) { + if (base >= 0x000e0000) + shadowbios_write |= 1; + if (base >= 0x000d0000) + dev->shadow_high |= 1; + + if (base >= 0xe0000) { + mem_set_mem_state_both(base, 0x4000, MEM_READ_EXTANY | MEM_WRITE_INTERNAL); + opti498_log("OPTI 498: %08X-%08X READ_EXTANY, WRITE_INTERNAL\n", base, base + 0x3fff); + } else { + mem_set_mem_state_both(base, 0x4000, MEM_READ_EXTERNAL | MEM_WRITE_INTERNAL); + opti498_log("OPTI 498: %08X-%08X READ_EXTERNAL, WRITE_INTERNAL\n", base, base + 0x3fff); + } + } else if (sh_enable && rom) { + if (base >= 0x000e0000) + shadowbios |= 1; + if (base >= 0x000d0000) + dev->shadow_high |= 1; + + if (sh_mode) { + mem_set_mem_state_both(base, 0x4000, MEM_READ_INTERNAL | MEM_WRITE_DISABLED); + opti498_log("OPTI 498: %08X-%08X READ_INTERNAL, WRITE_DISABLED\n", base, base + 0x3fff); + } else { + if (base >= 0x000e0000) + shadowbios_write |= 1; + + mem_set_mem_state_both(base, 0x4000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + opti498_log("OPTI 498: %08X-%08X READ_INTERNAL, WRITE_INTERNAL\n", base, base + 0x3fff); + } + } else { + if (base >= 0xe0000) { + mem_set_mem_state_both(base, 0x4000, MEM_READ_EXTANY | MEM_WRITE_DISABLED); + opti498_log("OPTI 498: %08X-%08X READ_EXTANY, WRITE_DISABLED\n", base, base + 0x3fff); + } else { + mem_set_mem_state_both(base, 0x4000, MEM_READ_EXTERNAL | MEM_WRITE_DISABLED); + opti498_log("OPTI 498: %08X-%08X READ_EXTERNAL, WRITE_DISABLED\n", base, base + 0x3fff); + } + } + } + + rbase = ((uint32_t) (dev->regs[0x05] & 0x3f)) << 20; + + if (rbase > 0) { + dev->mem_remappings[0].virt = rbase; + mem_mapping_set_addr(&dev->mem_mappings[0], rbase, 0x00020000); + + if (!dev->shadow_high) { + rbase += 0x00020000; + dev->mem_remappings[1].virt = rbase; + mem_mapping_set_addr(&dev->mem_mappings[1], rbase, 0x00020000); + } else + mem_mapping_disable(&dev->mem_mappings[1]); + } else { + mem_mapping_disable(&dev->mem_mappings[0]); + mem_mapping_disable(&dev->mem_mappings[1]); + } + + flushmmucache_nopc(); +} + +static void +opti498_write(uint16_t addr, uint8_t val, void *priv) +{ + opti498_t *dev = (opti498_t *) priv; + uint8_t reg = dev->index - dev->reg_base; + + switch (addr) { + default: + break; + + case 0x22: + dev->index = val; + break; + + case 0x24: + opti498_log("OPTi 498: dev->regs[%02x] = %02x\n", dev->index, val); + + if ((reg >= 0x00) && (reg <= 0x0b)) switch (reg) { + default: + break; + + case 0x00: + dev->regs[reg] = (dev->regs[reg] & 0xc0) | (val & 0x3f); + break; + + case 0x01: + case 0x07 ... 0x0b: + dev->regs[reg] = val; + break; + + case 0x02: + case 0x03: + case 0x04: + case 0x05: + dev->regs[reg] = val; + opti498_shadow_recalc(dev); + break; + + case 0x06: { + double bus_clk; + dev->regs[reg] = val; + switch (val & 0x03) { + default: + case 0x00: + bus_clk = cpu_busspeed / 8.0; + break; + case 0x01: + bus_clk = cpu_busspeed / 6.0; + break; + case 0x02: + bus_clk = cpu_busspeed / 5.0; + break; + case 0x03: + bus_clk = cpu_busspeed / 4.0; + break; + } + cpu_set_isa_speed((int) round(bus_clk)); + reset_on_hlt = !!(val & 0x40); + break; + } + } + + dev->index = 0xff; + break; + } +} + +static uint8_t +opti498_read(uint16_t addr, void *priv) +{ + opti498_t *dev = (opti498_t *) priv; + uint8_t reg = dev->index - dev->reg_base; + uint8_t ret = 0xff; + + if (addr == 0x24) { + if ((reg >= 0x00) && (reg <= 0x0b)) + ret = dev->regs[reg]; + + dev->index = 0xff; + } + + return ret; +} + +static void +opti498_close(void *priv) +{ + opti498_t *dev = (opti498_t *) priv; + + free(dev); +} + +static void * +opti498_init(UNUSED(const device_t *info)) +{ + opti498_t *dev = (opti498_t *) calloc(1, sizeof(opti498_t)); + + dev->reg_base = info->local & 0xff; + + io_sethandler(0x0022, 0x0001, opti498_read, NULL, NULL, opti498_write, NULL, NULL, dev); + io_sethandler(0x0024, 0x0001, opti498_read, NULL, NULL, opti498_write, NULL, NULL, dev); + + dev->regs[0x00] = 0x1f; + dev->regs[0x01] = 0x8f; + dev->regs[0x02] = 0xf0; + dev->regs[0x07] = 0x70; + dev->regs[0x09] = 0x70; + + dev->mem_remappings[0].phys = 0x000a0000; + dev->mem_remappings[1].phys = 0x000d0000; + + mem_mapping_add(&dev->mem_mappings[0], 0, 0x00020000, + opti498_read_remapped_ram, opti498_read_remapped_ramw, opti498_read_remapped_raml, + opti498_write_remapped_ram, opti498_write_remapped_ramw, opti498_write_remapped_raml, + &ram[dev->mem_remappings[0].phys], MEM_MAPPING_INTERNAL, &dev->mem_remappings[0]); + mem_mapping_disable(&dev->mem_mappings[0]); + + mem_mapping_add(&dev->mem_mappings[1], 0, 0x00020000, + opti498_read_remapped_ram, opti498_read_remapped_ramw, opti498_read_remapped_raml, + opti498_write_remapped_ram, opti498_write_remapped_ramw, opti498_write_remapped_raml, + &ram[dev->mem_remappings[1].phys], MEM_MAPPING_INTERNAL, &dev->mem_remappings[1]); + mem_mapping_disable(&dev->mem_mappings[1]); + + opti498_shadow_recalc(dev); + + cpu_set_isa_speed((int) round(cpu_busspeed / 8.0)); + + device_add(&port_92_device); + + return dev; +} + +const device_t opti498_device = { + .name = "OPTi 82C498", + .internal_name = "opti498", + .flags = 0, + .local = 0x70, + .init = opti498_init, + .close = opti498_close, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; diff --git a/src/chipset/opti499.c b/src/chipset/opti499.c index ecadd2224..383b8e3e2 100644 --- a/src/chipset/opti499.c +++ b/src/chipset/opti499.c @@ -16,6 +16,7 @@ * Copyright 2008-2020 Tiseno100. * Copyright 2016-2020 Miran Grca. */ +#include #include #include #include @@ -148,9 +149,28 @@ opti499_write(uint16_t addr, uint8_t val, void *priv) default: break; - case 0x20: + case 0x20: { + double coeff = (val & 0x10) ? 1.0 : 2.0; + double bus_clk; + switch (dev->regs[0x25] & 0x03) { + default: + case 0x00: + bus_clk = (cpu_busspeed * coeff) / 6.0; + break; + case 0x01: + bus_clk = (cpu_busspeed * coeff) / 5.0; + break; + case 0x02: + bus_clk = (cpu_busspeed * coeff) / 4.0; + break; + case 0x03: + bus_clk = (cpu_busspeed * coeff) / 3.0; + break; + } + cpu_set_isa_speed((int) round(bus_clk)); reset_on_hlt = !(val & 0x02); break; + } case 0x21: cpu_cache_ext_enabled = !!(dev->regs[0x21] & 0x10); @@ -163,6 +183,28 @@ opti499_write(uint16_t addr, uint8_t val, void *priv) case 0x2d: opti499_recalc(dev); break; + + case 0x25: { + double coeff = (dev->regs[0x20] & 0x10) ? 1.0 : 2.0; + double bus_clk; + switch (val & 0x03) { + default: + case 0x00: + bus_clk = (cpu_busspeed * coeff) / 8.0; + break; + case 0x01: + bus_clk = (cpu_busspeed * coeff) / 6.0; + break; + case 0x02: + bus_clk = (cpu_busspeed * coeff) / 5.0; + break; + case 0x03: + bus_clk = (cpu_busspeed * coeff) / 4.0; + break; + } + cpu_set_isa_speed((int) round(bus_clk)); + break; + } } } @@ -229,6 +271,8 @@ opti499_reset(void *priv) cpu_update_waitstates(); opti499_recalc(dev); + + cpu_set_isa_speed((int) round((cpu_busspeed * 2.0) / 6.0)); } static void @@ -242,8 +286,7 @@ opti499_close(void *priv) static void * opti499_init(UNUSED(const device_t *info)) { - opti499_t *dev = (opti499_t *) malloc(sizeof(opti499_t)); - memset(dev, 0, sizeof(opti499_t)); + opti499_t *dev = (opti499_t *) calloc(1, sizeof(opti499_t)); device_add(&port_92_device); @@ -265,7 +308,7 @@ const device_t opti499_device = { .init = opti499_init, .close = opti499_close, .reset = opti499_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/opti5x7.c b/src/chipset/opti5x7.c index 494fdee64..03fde4173 100644 --- a/src/chipset/opti5x7.c +++ b/src/chipset/opti5x7.c @@ -172,8 +172,7 @@ opti5x7_close(void *priv) static void * opti5x7_init(const device_t *info) { - opti5x7_t *dev = (opti5x7_t *) malloc(sizeof(opti5x7_t)); - memset(dev, 0, sizeof(opti5x7_t)); + opti5x7_t *dev = (opti5x7_t *) calloc(1, sizeof(opti5x7_t)); dev->is_pci = info->local; @@ -193,7 +192,7 @@ const device_t opti5x7_device = { .init = opti5x7_init, .close = opti5x7_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -207,7 +206,7 @@ const device_t opti5x7_pci_device = { .init = opti5x7_init, .close = opti5x7_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/opti602.c b/src/chipset/opti602.c index 3b5614ff4..7082408c7 100644 --- a/src/chipset/opti602.c +++ b/src/chipset/opti602.c @@ -218,7 +218,7 @@ const device_t opti601_device = { .init = opti602_init, .close = opti602_close, .reset = opti602_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -232,7 +232,7 @@ const device_t opti602_device = { .init = opti602_init, .close = opti602_close, .reset = opti602_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/opti822.c b/src/chipset/opti822.c index 3e9316f2b..471fbe393 100644 --- a/src/chipset/opti822.c +++ b/src/chipset/opti822.c @@ -394,8 +394,7 @@ opti822_close(void *priv) static void * opti822_init(UNUSED(const device_t *info)) { - opti822_t *dev = (opti822_t *) malloc(sizeof(opti822_t)); - memset(dev, 0, sizeof(opti822_t)); + opti822_t *dev = (opti822_t *) calloc(1, sizeof(opti822_t)); pci_add_card(PCI_ADD_NORTHBRIDGE, opti822_pci_read, opti822_pci_write, dev, &dev->pci_slot); @@ -412,7 +411,7 @@ const device_t opti822_device = { .init = opti822_init, .close = opti822_close, .reset = opti822_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/opti895.c b/src/chipset/opti895.c index f1878a51b..16b324963 100644 --- a/src/chipset/opti895.c +++ b/src/chipset/opti895.c @@ -16,6 +16,7 @@ * Copyright 2008-2020 Tiseno100. * Copyright 2016-2020 Miran Grca. */ +#include #include #include #include @@ -182,6 +183,27 @@ opti895_write(uint16_t addr, uint8_t val, void *priv) smram_state_change(dev->smram, 0, !!(val & 0x80)); break; + case 0x25: { + double bus_clk; + switch (val & 0x03) { + default: + case 0x00: + bus_clk = cpu_busspeed / 6.0; + break; + case 0x01: + bus_clk = cpu_busspeed / 5.0; + break; + case 0x02: + bus_clk = cpu_busspeed / 4.0; + break; + case 0x03: + bus_clk = cpu_busspeed / 3.0; + break; + } + cpu_set_isa_speed((int) round(bus_clk)); + break; + } + case 0xe0: if (!(val & 0x01)) dev->forced_green = 0; @@ -259,8 +281,7 @@ opti895_close(void *priv) static void * opti895_init(const device_t *info) { - opti895_t *dev = (opti895_t *) malloc(sizeof(opti895_t)); - memset(dev, 0, sizeof(opti895_t)); + opti895_t *dev = (opti895_t *) calloc(1, sizeof(opti895_t)); device_add(&port_92_device); @@ -295,6 +316,8 @@ opti895_init(const device_t *info) smram_enable(dev->smram, 0x00030000, 0x000b0000, 0x00010000, 0, 1); + cpu_set_isa_speed((int) round(cpu_busspeed / 6.0)); + return dev; } @@ -306,7 +329,7 @@ const device_t opti802g_device = { .init = opti895_init, .close = opti895_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -320,7 +343,7 @@ const device_t opti802g_pci_device = { .init = opti895_init, .close = opti895_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -334,7 +357,7 @@ const device_t opti895_device = { .init = opti895_init, .close = opti895_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/scamp.c b/src/chipset/scamp.c index 122318862..855175dcd 100644 --- a/src/chipset/scamp.c +++ b/src/chipset/scamp.c @@ -47,13 +47,35 @@ #define ID_VL82C311 0xd6 -#define RAMMAP_REMP386 (1 << 4) +#define RAMMAP_ROMMOV 0x60 +#define RAMMAP_ROMMOV1 (1 << 6) +#define RAMMAP_ROMMOV0 (1 << 5) +#define RAMMAP_REMP384 (1 << 4) #define EMSEN1_EMSMAP (1 << 4) +#define EMSEN1_BFENAB (1 << 6) #define EMSEN1_EMSENAB (1 << 7) #define NR_ELEMS(x) (sizeof(x) / sizeof(x[0])) +#define EMS_MAXPAGE 4 +#define EMS_PGSIZE 16384 +#define EMS_PGMASK 16383 + +#define MEM_FLAG_SLOTBUS 0x40 +#define MEM_FLAG_REMAP 0x20 +#define MEM_FLAG_MEMCARD 0x10 +#define MEM_FLAG_EMS 0x08 +#define MEM_FLAG_ROMCS 0x04 +#define MEM_FLAG_READ 0x02 +#define MEM_FLAG_WRITE 0x01 +#define MEM_FMASK_SLOTBUS 0x40 +#define MEM_FMASK_REMAP 0x20 +#define MEM_FMASK_MEMCARD 0x10 +#define MEM_FMASK_EMS 0x08 +#define MEM_FMASK_ROMCS 0x04 +#define MEM_FMASK_RW 0x03 + /*Commodore SL386SX requires proper memory slot decoding to detect memory size. Therefore we emulate the SCAMP memory address decoding, and therefore are limited to the DRAM combinations supported by the actual chip*/ @@ -72,36 +94,43 @@ typedef struct ram_struct_t { int bank; } ram_struct_t; -typedef struct ems_struct_t { - void *parent; - int segment; -} ems_struct_t; +typedef struct card_mem_t { + int in_ram; + uint32_t virt_addr; + uint32_t phys_addr; + uint8_t *mem; +} mem_page_t; typedef struct scamp_t { - int cfg_index; - uint8_t cfg_regs[256]; - int cfg_enable; - int ram_config; + int cfg_index; + uint8_t cfg_regs[256]; + int cfg_enable; + int ram_config; int ems_index; int ems_autoinc; - uint16_t ems[0x24]; - mem_mapping_t ems_mappings[20]; /*a0000-effff*/ - uint32_t mappings[20]; + uint16_t ems[64]; mem_mapping_t ram_mapping[2]; ram_struct_t ram_struct[2]; - ems_struct_t ems_struct[20]; - uint32_t ram_virt_base[2]; - uint32_t ram_phys_base[2]; - uint32_t ram_mask[2]; - int row_virt_shift[2]; - int row_phys_shift[2]; - int ram_interleaved[2]; - int ibank_shift[2]; + uint32_t ram_virt_base[2]; + uint32_t ram_phys_base[2]; + uint32_t ram_mask[2]; + int row_virt_shift[2]; + int row_phys_shift[2]; + int ram_interleaved[2]; + int ibank_shift[2]; - port_92_t *port_92; + int mem_flags[64]; + mem_mapping_t mem_mappings[64]; /* The entire first 1 MB of memory space. */ + mem_page_t mem_pages[64]; + + uint32_t card_mem_size; + uint8_t *card_mem; + mem_page_t card_pages[4]; + + port_92_t *port_92; } scamp_t; static const struct { @@ -147,6 +176,70 @@ static const struct { { { BANK_1M_INTERLEAVED, BANK_4M_INTERLEAVED }, 0}, /*Undocumented - probably wrong!*/ }; +#ifdef ENABLE_SCAMP_LOG +int scamp_do_log = ENABLE_SCAMP_LOG; + +static void +scamp_log(const char *fmt, ...) +{ + va_list ap; + + if (scamp_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define scamp_log(fmt, ...) +#endif + +/* Read one byte from paged RAM. */ +static uint8_t +scamp_mem_readb(uint32_t addr, void *priv) +{ + mem_page_t *dev = (mem_page_t *) priv; + uint8_t ret = 0xff; + + if (dev->mem != NULL) + ret = *(uint8_t *) &(dev->mem[addr & EMS_PGMASK]); + + return ret; +} + +/* Read one word from paged RAM. */ +static uint16_t +scamp_mem_readw(uint32_t addr, void *priv) +{ + mem_page_t *dev = (mem_page_t *) priv; + uint16_t ret = 0xffff; + + if (dev->mem != NULL) + ret = *(uint16_t *) &(dev->mem[addr & EMS_PGMASK]); + + return ret; +} + +/* Write one byte to paged RAM. */ +static void +scamp_mem_writeb(uint32_t addr, uint8_t val, void *priv) +{ + mem_page_t *dev = (mem_page_t *) priv; + + if (dev->mem != NULL) + *(uint8_t *) &(dev->mem[addr & EMS_PGMASK]) = val; +} + +/* Write one word to paged RAM. */ +static void +scamp_mem_writew(uint32_t addr, uint16_t val, void *priv) +{ + mem_page_t *dev = (mem_page_t *) priv; + + if (dev->mem != NULL) + *(uint16_t *) &(dev->mem[addr & EMS_PGMASK]) = val; +} + /* The column bits masked when using 256kbit DRAMs in 4Mbit mode aren't contiguous, so we use separate routines for that special case */ static uint8_t @@ -332,208 +425,193 @@ recalc_mappings(void *priv) /* Once the BIOS programs the correct DRAM configuration, switch to regular linear memory mapping */ if (cur_rammap == ram_configs[dev->ram_config].rammap) { - mem_mapping_set_handler(&ram_low_mapping, - mem_read_ram, mem_read_ramw, mem_read_raml, - mem_write_ram, mem_write_ramw, mem_write_raml); - mem_mapping_set_addr(&ram_low_mapping, 0, 0xa0000); + mem_mapping_disable(&ram_low_mapping); + + for (uint8_t i = 0; i < 40; i++) + mem_mapping_enable(&(dev->mem_mappings[i])); + if (mem_size > 1024) mem_set_mem_state_both((1 << 20), (mem_size - 1024) << 10, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); mem_mapping_enable(&ram_high_mapping); - return; } else { mem_mapping_set_handler(&ram_low_mapping, ram_mirrored_read, NULL, NULL, ram_mirrored_write, NULL, NULL); + mem_mapping_disable(&ram_low_mapping); - } - if (rammap[cur_rammap].bank[0] == BANK_NONE) - bank_nr = 1; + for (uint8_t i = 0; i < 40; i++) + mem_mapping_disable(&(dev->mem_mappings[i])); - for (; bank_nr < 2; bank_nr++) { - old_virt_base = virt_base; - phys_bank = ram_configs[dev->ram_config].bank[bank_nr]; + if (rammap[cur_rammap].bank[0] == BANK_NONE) + bank_nr = 1; - dev->ram_virt_base[bank_nr] = virt_base; + for (; bank_nr < 2; bank_nr++) { + old_virt_base = virt_base; + phys_bank = ram_configs[dev->ram_config].bank[bank_nr]; - if (virt_base == 0) { - switch (rammap[cur_rammap].bank[bank_nr]) { - case BANK_NONE: - fatal(" Bank %i is empty!\n }\n}\n", bank_nr); - break; + dev->ram_virt_base[bank_nr] = virt_base; - case BANK_256K: - if (phys_bank != BANK_NONE) { - mem_mapping_set_addr(&ram_low_mapping, 0, 0x80000); - mem_mapping_set_p(&ram_low_mapping, (void *) &dev->ram_struct[bank_nr]); - } - virt_base += (1 << 19); - dev->row_virt_shift[bank_nr] = 10; - break; + if (virt_base == 0) { + switch (rammap[cur_rammap].bank[bank_nr]) { + case BANK_NONE: + fatal(" Bank %i is empty!\n }\n}\n", bank_nr); + break; - case BANK_256K_INTERLEAVED: - if (phys_bank != BANK_NONE) { - mem_mapping_set_addr(&ram_low_mapping, 0, 0xa0000); - mem_mapping_set_p(&ram_low_mapping, (void *) &dev->ram_struct[bank_nr]); - } - virt_base += (1 << 20); - dev->row_virt_shift[bank_nr] = 10; - break; + case BANK_256K: + if (phys_bank != BANK_NONE) { + mem_mapping_set_addr(&ram_low_mapping, 0, 0x80000); + mem_mapping_set_p(&ram_low_mapping, (void *) &dev->ram_struct[bank_nr]); + } + virt_base += (1 << 19); + dev->row_virt_shift[bank_nr] = 10; + break; - case BANK_1M: - if (phys_bank != BANK_NONE) { - mem_mapping_set_addr(&ram_low_mapping, 0, 0xa0000); - mem_mapping_set_p(&ram_low_mapping, (void *) &dev->ram_struct[bank_nr]); - mem_mapping_set_addr(&dev->ram_mapping[bank_nr], 0x100000, 0x100000); - mem_mapping_set_exec(&dev->ram_mapping[bank_nr], &ram[dev->ram_phys_base[bank_nr] + 0x100000]); - mem_set_mem_state_both((1 << 20), (1 << 20), MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); - } - virt_base += (1 << 21); - dev->row_virt_shift[bank_nr] = 11; - break; + case BANK_256K_INTERLEAVED: + if (phys_bank != BANK_NONE) { + mem_mapping_set_addr(&ram_low_mapping, 0, 0xa0000); + mem_mapping_set_p(&ram_low_mapping, (void *) &dev->ram_struct[bank_nr]); + } + virt_base += (1 << 20); + dev->row_virt_shift[bank_nr] = 10; + break; - case BANK_1M_INTERLEAVED: - if (phys_bank != BANK_NONE) { - mem_mapping_set_addr(&ram_low_mapping, 0, 0xa0000); - mem_mapping_set_p(&ram_low_mapping, (void *) &dev->ram_struct[bank_nr]); - mem_mapping_set_addr(&dev->ram_mapping[bank_nr], 0x100000, 0x300000); - mem_mapping_set_exec(&dev->ram_mapping[bank_nr], &ram[dev->ram_phys_base[bank_nr] + 0x100000]); - mem_set_mem_state_both((1 << 20), (3 << 20), MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); - } - virt_base += (1 << 22); - dev->row_virt_shift[bank_nr] = 11; - break; + case BANK_1M: + if (phys_bank != BANK_NONE) { + mem_mapping_set_addr(&ram_low_mapping, 0, 0xa0000); + mem_mapping_set_p(&ram_low_mapping, (void *) &dev->ram_struct[bank_nr]); + mem_mapping_set_addr(&dev->ram_mapping[bank_nr], 0x100000, 0x100000); + mem_mapping_set_exec(&dev->ram_mapping[bank_nr], &ram[dev->ram_phys_base[bank_nr] + 0x100000]); + mem_set_mem_state_both((1 << 20), (1 << 20), MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + } + virt_base += (1 << 21); + dev->row_virt_shift[bank_nr] = 11; + break; - case BANK_4M: - if (phys_bank != BANK_NONE) { - mem_mapping_set_addr(&ram_low_mapping, 0, 0xa0000); - mem_mapping_set_p(&ram_low_mapping, (void *) &dev->ram_struct[bank_nr]); - mem_mapping_set_addr(&dev->ram_mapping[bank_nr], 0x100000, 0x700000); - mem_mapping_set_exec(&dev->ram_mapping[bank_nr], &ram[dev->ram_phys_base[bank_nr] + 0x100000]); - mem_set_mem_state_both((1 << 20), (7 << 20), MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); - } - virt_base += (1 << 23); - dev->row_virt_shift[bank_nr] = 12; - break; + case BANK_1M_INTERLEAVED: + if (phys_bank != BANK_NONE) { + mem_mapping_set_addr(&ram_low_mapping, 0, 0xa0000); + mem_mapping_set_p(&ram_low_mapping, (void *) &dev->ram_struct[bank_nr]); + mem_mapping_set_addr(&dev->ram_mapping[bank_nr], 0x100000, 0x300000); + mem_mapping_set_exec(&dev->ram_mapping[bank_nr], &ram[dev->ram_phys_base[bank_nr] + 0x100000]); + mem_set_mem_state_both((1 << 20), (3 << 20), MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + } + virt_base += (1 << 22); + dev->row_virt_shift[bank_nr] = 11; + break; - case BANK_4M_INTERLEAVED: - if (phys_bank != BANK_NONE) { - mem_mapping_set_addr(&ram_low_mapping, 0, 0xa0000); - mem_mapping_set_p(&ram_low_mapping, (void *) &dev->ram_struct[bank_nr]); - mem_mapping_set_addr(&dev->ram_mapping[bank_nr], 0x100000, 0xf00000); - mem_mapping_set_exec(&dev->ram_mapping[bank_nr], &ram[dev->ram_phys_base[bank_nr] + 0x100000]); - mem_set_mem_state_both((1 << 20), (15 << 20), MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); - } - virt_base += (1 << 24); - dev->row_virt_shift[bank_nr] = 12; - break; + case BANK_4M: + if (phys_bank != BANK_NONE) { + mem_mapping_set_addr(&ram_low_mapping, 0, 0xa0000); + mem_mapping_set_p(&ram_low_mapping, (void *) &dev->ram_struct[bank_nr]); + mem_mapping_set_addr(&dev->ram_mapping[bank_nr], 0x100000, 0x700000); + mem_mapping_set_exec(&dev->ram_mapping[bank_nr], &ram[dev->ram_phys_base[bank_nr] + 0x100000]); + mem_set_mem_state_both((1 << 20), (7 << 20), MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + } + virt_base += (1 << 23); + dev->row_virt_shift[bank_nr] = 12; + break; - default: - break; + case BANK_4M_INTERLEAVED: + if (phys_bank != BANK_NONE) { + mem_mapping_set_addr(&ram_low_mapping, 0, 0xa0000); + mem_mapping_set_p(&ram_low_mapping, (void *) &dev->ram_struct[bank_nr]); + mem_mapping_set_addr(&dev->ram_mapping[bank_nr], 0x100000, 0xf00000); + mem_mapping_set_exec(&dev->ram_mapping[bank_nr], &ram[dev->ram_phys_base[bank_nr] + 0x100000]); + mem_set_mem_state_both((1 << 20), (15 << 20), MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + } + virt_base += (1 << 24); + dev->row_virt_shift[bank_nr] = 12; + break; + + default: + break; + } + } else { + switch (rammap[cur_rammap].bank[bank_nr]) { + case BANK_NONE: + break; + + case BANK_256K: + if (phys_bank != BANK_NONE) { + mem_mapping_set_addr(&dev->ram_mapping[bank_nr], virt_base, 0x80000); + mem_mapping_set_exec(&dev->ram_mapping[bank_nr], &ram[dev->ram_phys_base[bank_nr]]); + mem_set_mem_state_both(virt_base, (1 << 19), MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + } + virt_base += (1 << 19); + dev->row_virt_shift[bank_nr] = 10; + break; + + case BANK_256K_INTERLEAVED: + if (phys_bank != BANK_NONE) { + mem_mapping_set_addr(&dev->ram_mapping[bank_nr], virt_base, 0x100000); + mem_mapping_set_exec(&dev->ram_mapping[bank_nr], &ram[dev->ram_phys_base[bank_nr]]); + mem_set_mem_state_both(virt_base, (1 << 20), MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + } + virt_base += (1 << 20); + dev->row_virt_shift[bank_nr] = 10; + break; + + case BANK_1M: + if (phys_bank != BANK_NONE) { + mem_mapping_set_addr(&dev->ram_mapping[bank_nr], virt_base, 0x200000); + mem_mapping_set_exec(&dev->ram_mapping[bank_nr], &ram[dev->ram_phys_base[bank_nr]]); + mem_set_mem_state_both(virt_base, (1 << 21), MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + } + virt_base += (1 << 21); + dev->row_virt_shift[bank_nr] = 11; + break; + + case BANK_1M_INTERLEAVED: + if (phys_bank != BANK_NONE) { + mem_mapping_set_addr(&dev->ram_mapping[bank_nr], virt_base, 0x400000); + mem_mapping_set_exec(&dev->ram_mapping[bank_nr], &ram[dev->ram_phys_base[bank_nr]]); + mem_set_mem_state_both(virt_base, (1 << 22), MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + } + virt_base += (1 << 22); + dev->row_virt_shift[bank_nr] = 11; + break; + + case BANK_4M: + if (phys_bank != BANK_NONE) { + mem_mapping_set_addr(&dev->ram_mapping[bank_nr], virt_base, 0x800000); + mem_mapping_set_exec(&dev->ram_mapping[bank_nr], &ram[dev->ram_phys_base[bank_nr]]); + mem_set_mem_state_both(virt_base, (1 << 23), MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + } + virt_base += (1 << 23); + dev->row_virt_shift[bank_nr] = 12; + break; + + case BANK_4M_INTERLEAVED: + if (phys_bank != BANK_NONE) { + mem_mapping_set_addr(&dev->ram_mapping[bank_nr], virt_base, 0x1000000); + mem_mapping_set_exec(&dev->ram_mapping[bank_nr], &ram[dev->ram_phys_base[bank_nr]]); + mem_set_mem_state_both(virt_base, (1 << 24), MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + } + virt_base += (1 << 24); + dev->row_virt_shift[bank_nr] = 12; + break; + + default: + break; + } } - } else { + switch (rammap[cur_rammap].bank[bank_nr]) { - case BANK_NONE: - break; - case BANK_256K: - if (phys_bank != BANK_NONE) { - mem_mapping_set_addr(&dev->ram_mapping[bank_nr], virt_base, 0x80000); - mem_mapping_set_exec(&dev->ram_mapping[bank_nr], &ram[dev->ram_phys_base[bank_nr]]); - mem_set_mem_state_both(virt_base, (1 << 19), MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); - } - virt_base += (1 << 19); - dev->row_virt_shift[bank_nr] = 10; - break; - - case BANK_256K_INTERLEAVED: - if (phys_bank != BANK_NONE) { - mem_mapping_set_addr(&dev->ram_mapping[bank_nr], virt_base, 0x100000); - mem_mapping_set_exec(&dev->ram_mapping[bank_nr], &ram[dev->ram_phys_base[bank_nr]]); - mem_set_mem_state_both(virt_base, (1 << 20), MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); - } - virt_base += (1 << 20); - dev->row_virt_shift[bank_nr] = 10; - break; - case BANK_1M: - if (phys_bank != BANK_NONE) { - mem_mapping_set_addr(&dev->ram_mapping[bank_nr], virt_base, 0x200000); - mem_mapping_set_exec(&dev->ram_mapping[bank_nr], &ram[dev->ram_phys_base[bank_nr]]); - mem_set_mem_state_both(virt_base, (1 << 21), MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); - } - virt_base += (1 << 21); - dev->row_virt_shift[bank_nr] = 11; - break; - - case BANK_1M_INTERLEAVED: - if (phys_bank != BANK_NONE) { - mem_mapping_set_addr(&dev->ram_mapping[bank_nr], virt_base, 0x400000); - mem_mapping_set_exec(&dev->ram_mapping[bank_nr], &ram[dev->ram_phys_base[bank_nr]]); - mem_set_mem_state_both(virt_base, (1 << 22), MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); - } - virt_base += (1 << 22); - dev->row_virt_shift[bank_nr] = 11; - break; - case BANK_4M: - if (phys_bank != BANK_NONE) { - mem_mapping_set_addr(&dev->ram_mapping[bank_nr], virt_base, 0x800000); - mem_mapping_set_exec(&dev->ram_mapping[bank_nr], &ram[dev->ram_phys_base[bank_nr]]); - mem_set_mem_state_both(virt_base, (1 << 23), MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); - } - virt_base += (1 << 23); - dev->row_virt_shift[bank_nr] = 12; - break; - - case BANK_4M_INTERLEAVED: - if (phys_bank != BANK_NONE) { - mem_mapping_set_addr(&dev->ram_mapping[bank_nr], virt_base, 0x1000000); - mem_mapping_set_exec(&dev->ram_mapping[bank_nr], &ram[dev->ram_phys_base[bank_nr]]); - mem_set_mem_state_both(virt_base, (1 << 24), MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); - } - virt_base += (1 << 24); - dev->row_virt_shift[bank_nr] = 12; - break; - - default: - break; - } - } - switch (rammap[cur_rammap].bank[bank_nr]) { - case BANK_256K: - case BANK_1M: - case BANK_4M: - mem_mapping_set_handler(&dev->ram_mapping[bank_nr], - ram_mirrored_read, NULL, NULL, - ram_mirrored_write, NULL, NULL); - if (!old_virt_base) - mem_mapping_set_handler(&ram_low_mapping, + mem_mapping_set_handler(&dev->ram_mapping[bank_nr], ram_mirrored_read, NULL, NULL, ram_mirrored_write, NULL, NULL); - break; - - case BANK_256K_INTERLEAVED: - case BANK_1M_INTERLEAVED: - mem_mapping_set_handler(&dev->ram_mapping[bank_nr], - ram_mirrored_interleaved_read, NULL, NULL, - ram_mirrored_interleaved_write, NULL, NULL); - if (!old_virt_base) - mem_mapping_set_handler(&ram_low_mapping, - ram_mirrored_interleaved_read, NULL, NULL, - ram_mirrored_interleaved_write, NULL, NULL); - break; - - case BANK_4M_INTERLEAVED: - if (phys_bank == BANK_256K || phys_bank == BANK_256K_INTERLEAVED) { - mem_mapping_set_handler(&dev->ram_mapping[bank_nr], - ram_mirrored_256k_in_4mi_read, NULL, NULL, - ram_mirrored_256k_in_4mi_write, NULL, NULL); if (!old_virt_base) mem_mapping_set_handler(&ram_low_mapping, - ram_mirrored_256k_in_4mi_read, NULL, NULL, - ram_mirrored_256k_in_4mi_write, NULL, NULL); - } else { + ram_mirrored_read, NULL, NULL, + ram_mirrored_write, NULL, NULL); + break; + + case BANK_256K_INTERLEAVED: + case BANK_1M_INTERLEAVED: mem_mapping_set_handler(&dev->ram_mapping[bank_nr], ram_mirrored_interleaved_read, NULL, NULL, ram_mirrored_interleaved_write, NULL, NULL); @@ -541,13 +619,203 @@ recalc_mappings(void *priv) mem_mapping_set_handler(&ram_low_mapping, ram_mirrored_interleaved_read, NULL, NULL, ram_mirrored_interleaved_write, NULL, NULL); - } - break; + break; + case BANK_4M_INTERLEAVED: + if (phys_bank == BANK_256K || phys_bank == BANK_256K_INTERLEAVED) { + mem_mapping_set_handler(&dev->ram_mapping[bank_nr], + ram_mirrored_256k_in_4mi_read, NULL, NULL, + ram_mirrored_256k_in_4mi_write, NULL, NULL); + if (!old_virt_base) + mem_mapping_set_handler(&ram_low_mapping, + ram_mirrored_256k_in_4mi_read, NULL, NULL, + ram_mirrored_256k_in_4mi_write, NULL, NULL); + } else { + mem_mapping_set_handler(&dev->ram_mapping[bank_nr], + ram_mirrored_interleaved_read, NULL, NULL, + ram_mirrored_interleaved_write, NULL, NULL); + if (!old_virt_base) + mem_mapping_set_handler(&ram_low_mapping, + ram_mirrored_interleaved_read, NULL, NULL, + ram_mirrored_interleaved_write, NULL, NULL); + } + break; + + default: + break; + } + } + } +} + +static void +scamp_mem_update_state(scamp_t *dev, uint32_t addr, uint32_t size, uint8_t new_flags, uint8_t mask) +{ + int read_ext = MEM_READ_EXTERNAL; + int write_ext = MEM_WRITE_EXTERNAL; + + if ((addr < 0x00100000) && ((new_flags ^ dev->mem_flags[addr / EMS_PGSIZE]) & mask)) { + dev->mem_flags[addr / EMS_PGSIZE] &= ~mask; + dev->mem_flags[addr / EMS_PGSIZE] |= new_flags; + + new_flags = dev->mem_flags[addr / EMS_PGSIZE]; + + if (new_flags & MEM_FLAG_ROMCS) { + read_ext = MEM_READ_ROMCS; + write_ext = MEM_WRITE_ROMCS; + } + + if (new_flags & (MEM_FLAG_REMAP | MEM_FLAG_SLOTBUS)) { + scamp_log("scamp_mem_update_state(): %08X-%08X: %02X (REMAP)\n", addr, addr + size - 1, new_flags); + mem_set_mem_state(addr, size, read_ext | write_ext); + } else if (new_flags & (MEM_FLAG_EMS | MEM_FLAG_MEMCARD)) { + scamp_log("scamp_mem_update_state(): %08X-%08X: %02X (EMS)\n", addr, addr + size - 1, new_flags); + mem_set_mem_state(addr, size, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + } else switch (new_flags & (MEM_FLAG_READ | MEM_FLAG_WRITE)) { + case 0: + scamp_log("scamp_mem_update_state(): %08X-%08X: %02X (RE | WE)\n", addr, addr + size - 1, new_flags); + mem_set_mem_state(addr, size, read_ext | write_ext); + break; + case 1: + scamp_log("scamp_mem_update_state(): %08X-%08X: %02X (RE | WI)\n", addr, addr + size - 1, new_flags); + mem_set_mem_state(addr, size, read_ext | MEM_WRITE_INTERNAL); + break; + case 2: + scamp_log("scamp_mem_update_state(): %08X-%08X: %02X (RI | WE)\n", addr, addr + size - 1, new_flags); + mem_set_mem_state(addr, size, MEM_READ_INTERNAL | write_ext); + break; + case 3: + scamp_log("scamp_mem_update_state(): %08X-%08X: %02X (RI | WI)\n", addr, addr + size - 1, new_flags); + mem_set_mem_state(addr, size, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + break; default: break; } } + + flushmmucache_nopc(); +} + +static int +is_seg_in_ram(scamp_t *dev, uint8_t s) +{ + mem_page_t *mp = (mem_page_t *) dev->mem_mappings[s].priv; + const int ret = mp->in_ram; + + return ret; +} + +static void +recalc_ems(scamp_t *dev) +{ + const uint8_t seg_xlat[12] = { 40, 41, 42, 43, 52, 53, 54, 55, 44, 45, 46, 47 }; + const uint16_t seg_enable = dev->cfg_regs[CFG_EMSEN2] | ((dev->cfg_regs[CFG_EMSEN1] & 0xf) << 8); + + for (uint8_t s = 40; s < 60; s++) { + dev->mem_pages[s].phys_addr = dev->mem_pages[s].virt_addr; + dev->mem_pages[s].mem = ram + dev->mem_pages[s].phys_addr; + + if (is_seg_in_ram(dev, s)) + mem_mapping_set_exec(&(dev->mem_mappings[s]), dev->mem_pages[s].mem); + + scamp_mem_update_state(dev, s * EMS_PGSIZE, EMS_PGSIZE, 0x00, MEM_FMASK_EMS); + } + + for (uint8_t i = 0; i < 36; i++) { + uint8_t s = (i < 12) ? (i + 48) : (i + 4); + uint8_t on = (dev->cfg_regs[CFG_EMSEN1] & EMSEN1_EMSENAB); + uint32_t phys_addr = dev->ems[i] << 14; + + if (i < 12) { + if (dev->cfg_regs[CFG_EMSEN1] & EMSEN1_EMSMAP) + s = seg_xlat[i]; + + on = on && (seg_enable & (1 << i)); + } else + on = on && (dev->cfg_regs[CFG_EMSEN1] & EMSEN1_BFENAB); + + if (on) { + dev->mem_pages[s].phys_addr = phys_addr; + dev->mem_pages[s].mem = ram + dev->mem_pages[s].phys_addr; + + if (is_seg_in_ram(dev, s)) + mem_mapping_set_exec(&(dev->mem_mappings[s]), dev->mem_pages[s].mem); + + scamp_mem_update_state(dev, s * EMS_PGSIZE, EMS_PGSIZE, MEM_FLAG_EMS, MEM_FMASK_EMS); + } else if (i >= 12) { + dev->mem_pages[s].phys_addr = dev->mem_pages[s].virt_addr; + dev->mem_pages[s].mem = ram + dev->mem_pages[s].phys_addr; + + if (is_seg_in_ram(dev, s)) + mem_mapping_set_exec(&(dev->mem_mappings[s]), dev->mem_pages[s].mem); + + scamp_mem_update_state(dev, s * EMS_PGSIZE, EMS_PGSIZE, 0x00, MEM_FMASK_EMS); + } + } + + flushmmucache_nopc(); +} + +static void +shadow_control(scamp_t *dev, uint32_t addr, uint32_t size, int state) +{ + if (size == 0x8000) { + scamp_mem_update_state(dev, addr, EMS_PGSIZE, state, MEM_FMASK_RW); + scamp_mem_update_state(dev, addr + EMS_PGSIZE, EMS_PGSIZE, state, MEM_FMASK_RW); + } else + scamp_mem_update_state(dev, addr, size, state, MEM_FMASK_RW); + + flushmmucache_nopc(); +} + +static void +shadow_recalc(scamp_t *dev) +{ + uint8_t abaxs = (dev->cfg_regs[CFG_RAMMAP] & RAMMAP_REMP384) ? 0 : dev->cfg_regs[CFG_ABAXS]; + uint8_t caxs = (dev->cfg_regs[CFG_RAMMAP] & RAMMAP_REMP384) ? 0 : dev->cfg_regs[CFG_CAXS]; + uint8_t daxs = (dev->cfg_regs[CFG_RAMMAP] & RAMMAP_REMP384) ? 0 : dev->cfg_regs[CFG_DAXS]; + uint8_t feaxs = (dev->cfg_regs[CFG_RAMMAP] & RAMMAP_REMP384) ? 0 : dev->cfg_regs[CFG_FEAXS]; + + /*Enabling remapping will disable all shadowing*/ + if (dev->cfg_regs[CFG_RAMMAP] & RAMMAP_REMP384) + mem_remap_top_nomid(384); + else + mem_remap_top_nomid(0); + + for (uint8_t i = 40; i < 64; i++) { + if (dev->cfg_regs[CFG_RAMMAP] & RAMMAP_REMP384) + scamp_mem_update_state(dev, (i * EMS_PGSIZE), EMS_PGSIZE, MEM_FLAG_REMAP, MEM_FMASK_REMAP); + else + scamp_mem_update_state(dev, (i * EMS_PGSIZE), EMS_PGSIZE, 0x00, MEM_FMASK_REMAP); + } + + shadow_control(dev, 0xa0000, 0x4000, abaxs & 3); + shadow_control(dev, 0xa0000, 0x4000, abaxs & 3); + shadow_control(dev, 0xa8000, 0x4000, (abaxs >> 2) & 3); + shadow_control(dev, 0xa8000, 0x4000, (abaxs >> 2) & 3); + + shadow_control(dev, 0xb0000, 0x4000, (abaxs >> 4) & 3); + shadow_control(dev, 0xb0000, 0x4000, (abaxs >> 4) & 3); + shadow_control(dev, 0xb8000, 0x4000, (abaxs >> 6) & 3); + shadow_control(dev, 0xb8000, 0x4000, (abaxs >> 6) & 3); + + shadow_control(dev, 0xc0000, 0x4000, caxs & 3); + shadow_control(dev, 0xc4000, 0x4000, (caxs >> 2) & 3); + shadow_control(dev, 0xc8000, 0x4000, (caxs >> 4) & 3); + shadow_control(dev, 0xcc000, 0x4000, (caxs >> 6) & 3); + + shadow_control(dev, 0xd0000, 0x4000, daxs & 3); + shadow_control(dev, 0xd4000, 0x4000, (daxs >> 2) & 3); + shadow_control(dev, 0xd8000, 0x4000, (daxs >> 4) & 3); + shadow_control(dev, 0xdc000, 0x4000, (daxs >> 6) & 3); + + shadow_control(dev, 0xe0000, 0x4000, feaxs & 3); + shadow_control(dev, 0xe4000, 0x4000, feaxs & 3); + shadow_control(dev, 0xe8000, 0x4000, (feaxs >> 2) & 3); + shadow_control(dev, 0xec000, 0x4000, (feaxs >> 2) & 3); + + shadow_control(dev, 0xf0000, 0x8000, (feaxs >> 4) & 3); + shadow_control(dev, 0xf8000, 0x8000, (feaxs >> 6) & 3); } static void @@ -561,155 +829,84 @@ recalc_sltptr(scamp_t *dev) sltptr = 0xfe0000; if (sltptr >= 0xa0000) { - mem_set_mem_state(0, 0xa0000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + for (uint8_t i = 0; i < 40; i++) + scamp_mem_update_state(dev, i * EMS_PGSIZE, EMS_PGSIZE, 0x00, MEM_FMASK_SLOTBUS); + mem_set_mem_state(0x100000, sltptr - 0x100000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); mem_set_mem_state(sltptr, 0x1000000 - sltptr, MEM_READ_EXTANY | MEM_WRITE_EXTANY); + + if ((sltptr >= 0x40000) && (sltptr <= 0x90000)) { + dev->cfg_regs[CFG_EMSEN1] &= ~EMSEN1_BFENAB; + recalc_ems(dev); + } } else { - mem_set_mem_state(0, sltptr, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + for (uint8_t i = 0; i < (sltptr / EMS_PGSIZE); i++) + scamp_mem_update_state(dev, i * EMS_PGSIZE, EMS_PGSIZE, 0x00, MEM_FMASK_SLOTBUS); + + for (uint8_t i = (sltptr / EMS_PGSIZE); i < 40; i++) + scamp_mem_update_state(dev, i * EMS_PGSIZE, EMS_PGSIZE, MEM_FLAG_SLOTBUS, MEM_FMASK_SLOTBUS); + mem_set_mem_state(sltptr, 0xa0000 - sltptr, MEM_READ_EXTANY | MEM_WRITE_EXTANY); mem_set_mem_state(0x100000, 0xf00000, MEM_READ_EXTANY | MEM_WRITE_EXTANY); } -} - -static uint8_t -scamp_ems_read(uint32_t addr, void *priv) -{ - 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]; -} - -static void -scamp_ems_write(uint32_t addr, uint8_t val, void *priv) -{ - 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; -} - -static void -recalc_ems(scamp_t *dev) -{ - const uint32_t ems_base[12] = { - 0xc0000, 0xc4000, 0xc8000, 0xcc000, - 0xd0000, 0xd4000, 0xd8000, 0xdc000, - 0xe0000, 0xe4000, 0xe8000, 0xec000 - }; - uint32_t new_mappings[20]; - uint16_t ems_enable; - - for (int segment = 0; segment < 20; segment++) - new_mappings[segment] = 0xa0000 + segment * 0x4000; - - if (dev->cfg_regs[CFG_EMSEN1] & EMSEN1_EMSENAB) - ems_enable = dev->cfg_regs[CFG_EMSEN2] | ((dev->cfg_regs[CFG_EMSEN1] & 0xf) << 8); - else - ems_enable = 0; - - for (int segment = 0; segment < 12; segment++) { - if (ems_enable & (1 << segment)) { - uint32_t phys_addr = dev->ems[segment] << 14; - - /*If physical address is in remapped memory then adjust down to a0000-fffff range*/ - if ((dev->cfg_regs[CFG_RAMMAP] & RAMMAP_REMP386) && phys_addr >= (mem_size * 1024) - && phys_addr < ((mem_size + 384) * 1024)) - phys_addr = (phys_addr - mem_size * 1024) + 0xa0000; - new_mappings[(ems_base[segment] - 0xa0000) >> 14] = phys_addr; - } - } - - 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)) { - mem_mapping_set_exec(&dev->ems_mappings[segment], ram + dev->mappings[segment]); - mem_mapping_enable(&dev->ems_mappings[segment]); - } else - mem_mapping_disable(&dev->ems_mappings[segment]); - } - } -} - -static void -shadow_control(uint32_t addr, uint32_t size, int state, int ems_enable) -{ - if (ems_enable) - mem_set_mem_state(addr, size, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); - else - switch (state) { - case 0: - mem_set_mem_state(addr, size, MEM_READ_EXTANY | MEM_WRITE_EXTANY); - break; - case 1: - mem_set_mem_state(addr, size, MEM_READ_EXTANY | MEM_WRITE_INTERNAL); - break; - case 2: - mem_set_mem_state(addr, size, MEM_READ_INTERNAL | MEM_WRITE_EXTANY); - break; - case 3: - mem_set_mem_state(addr, size, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); - break; - default: - break; - } flushmmucache_nopc(); } static void -shadow_recalc(scamp_t *dev) +recalc_rommov(scamp_t *dev) { - uint8_t abaxs = (dev->cfg_regs[CFG_RAMMAP] & RAMMAP_REMP386) ? 0 : dev->cfg_regs[CFG_ABAXS]; - uint8_t caxs = (dev->cfg_regs[CFG_RAMMAP] & RAMMAP_REMP386) ? 0 : dev->cfg_regs[CFG_CAXS]; - uint8_t daxs = (dev->cfg_regs[CFG_RAMMAP] & RAMMAP_REMP386) ? 0 : dev->cfg_regs[CFG_DAXS]; - uint8_t feaxs = (dev->cfg_regs[CFG_RAMMAP] & RAMMAP_REMP386) ? 0 : dev->cfg_regs[CFG_FEAXS]; - uint32_t ems_enable; + switch ((dev->cfg_regs[CFG_RAMMAP] & RAMMAP_ROMMOV) >> 5) { + case 0x00: + scamp_mem_update_state(dev, 0x000c0000, EMS_PGSIZE, 0x00, MEM_FMASK_ROMCS); + scamp_mem_update_state(dev, 0x000c4000, EMS_PGSIZE, 0x00, MEM_FMASK_ROMCS); + scamp_mem_update_state(dev, 0x000c8000, EMS_PGSIZE, 0x00, MEM_FMASK_ROMCS); + scamp_mem_update_state(dev, 0x000cc000, EMS_PGSIZE, 0x00, MEM_FMASK_ROMCS); - if (dev->cfg_regs[CFG_EMSEN1] & EMSEN1_EMSENAB) { - if (dev->cfg_regs[CFG_EMSEN1] & EMSEN1_EMSMAP) /*Axxx/Bxxx/Dxxx*/ - ems_enable = (dev->cfg_regs[CFG_EMSEN2] & 0xf) | ((dev->cfg_regs[CFG_EMSEN1] & 0xf) << 4) | ((dev->cfg_regs[CFG_EMSEN2] & 0xf0) << 8); - else /*Cxxx/Dxxx/Exxx*/ - ems_enable = (dev->cfg_regs[CFG_EMSEN2] << 8) | ((dev->cfg_regs[CFG_EMSEN1] & 0xf) << 16); - } else - ems_enable = 0; + scamp_mem_update_state(dev, 0x000e0000, EMS_PGSIZE, MEM_FLAG_ROMCS, MEM_FMASK_ROMCS); + scamp_mem_update_state(dev, 0x000e4000, EMS_PGSIZE, MEM_FLAG_ROMCS, MEM_FMASK_ROMCS); + scamp_mem_update_state(dev, 0x000e8000, EMS_PGSIZE, MEM_FLAG_ROMCS, MEM_FMASK_ROMCS); + scamp_mem_update_state(dev, 0x000ec000, EMS_PGSIZE, MEM_FLAG_ROMCS, MEM_FMASK_ROMCS); + break; - /*Enabling remapping will disable all shadowing*/ - if (dev->cfg_regs[CFG_RAMMAP] & RAMMAP_REMP386) - mem_remap_top(384); + case 0x01: + scamp_mem_update_state(dev, 0x000c0000, EMS_PGSIZE, 0x00, MEM_FMASK_ROMCS); + scamp_mem_update_state(dev, 0x000c4000, EMS_PGSIZE, 0x00, MEM_FMASK_ROMCS); + scamp_mem_update_state(dev, 0x000c8000, EMS_PGSIZE, 0x00, MEM_FMASK_ROMCS); + scamp_mem_update_state(dev, 0x000cc000, EMS_PGSIZE, 0x00, MEM_FMASK_ROMCS); - shadow_control(0xa0000, 0x4000, abaxs & 3, ems_enable & 0x00001); - shadow_control(0xa0000, 0x4000, abaxs & 3, ems_enable & 0x00002); - shadow_control(0xa8000, 0x4000, (abaxs >> 2) & 3, ems_enable & 0x00004); - shadow_control(0xa8000, 0x4000, (abaxs >> 2) & 3, ems_enable & 0x00008); + scamp_mem_update_state(dev, 0x000e0000, EMS_PGSIZE, 0x00, MEM_FMASK_ROMCS); + scamp_mem_update_state(dev, 0x000e4000, EMS_PGSIZE, 0x00, MEM_FMASK_ROMCS); + scamp_mem_update_state(dev, 0x000e8000, EMS_PGSIZE, 0x00, MEM_FMASK_ROMCS); + scamp_mem_update_state(dev, 0x000ec000, EMS_PGSIZE, 0x00, MEM_FMASK_ROMCS); + break; - shadow_control(0xb0000, 0x4000, (abaxs >> 4) & 3, ems_enable & 0x00010); - shadow_control(0xb0000, 0x4000, (abaxs >> 4) & 3, ems_enable & 0x00020); - shadow_control(0xb8000, 0x4000, (abaxs >> 6) & 3, ems_enable & 0x00040); - shadow_control(0xb8000, 0x4000, (abaxs >> 6) & 3, ems_enable & 0x00080); + case 0x02: + scamp_mem_update_state(dev, 0x000c0000, EMS_PGSIZE, MEM_FLAG_ROMCS, MEM_FMASK_ROMCS); + scamp_mem_update_state(dev, 0x000c4000, EMS_PGSIZE, MEM_FLAG_ROMCS, MEM_FMASK_ROMCS); + scamp_mem_update_state(dev, 0x000c8000, EMS_PGSIZE, 0x00, MEM_FMASK_ROMCS); + scamp_mem_update_state(dev, 0x000cc000, EMS_PGSIZE, 0x00, MEM_FMASK_ROMCS); - shadow_control(0xc0000, 0x4000, caxs & 3, ems_enable & 0x00100); - shadow_control(0xc4000, 0x4000, (caxs >> 2) & 3, ems_enable & 0x00200); - shadow_control(0xc8000, 0x4000, (caxs >> 4) & 3, ems_enable & 0x00400); - shadow_control(0xcc000, 0x4000, (caxs >> 6) & 3, ems_enable & 0x00800); + scamp_mem_update_state(dev, 0x000e0000, EMS_PGSIZE, 0x00, MEM_FMASK_ROMCS); + scamp_mem_update_state(dev, 0x000e4000, EMS_PGSIZE, 0x00, MEM_FMASK_ROMCS); + scamp_mem_update_state(dev, 0x000e8000, EMS_PGSIZE, MEM_FLAG_ROMCS, MEM_FMASK_ROMCS); + scamp_mem_update_state(dev, 0x000ec000, EMS_PGSIZE, MEM_FLAG_ROMCS, MEM_FMASK_ROMCS); + break; - shadow_control(0xd0000, 0x4000, daxs & 3, ems_enable & 0x01000); - shadow_control(0xd4000, 0x4000, (daxs >> 2) & 3, ems_enable & 0x02000); - shadow_control(0xd8000, 0x4000, (daxs >> 4) & 3, ems_enable & 0x04000); - shadow_control(0xdc000, 0x4000, (daxs >> 6) & 3, ems_enable & 0x08000); + case 0x03: + scamp_mem_update_state(dev, 0x000c0000, EMS_PGSIZE, MEM_FLAG_ROMCS, MEM_FMASK_ROMCS); + scamp_mem_update_state(dev, 0x000c4000, EMS_PGSIZE, MEM_FLAG_ROMCS, MEM_FMASK_ROMCS); + scamp_mem_update_state(dev, 0x000c8000, EMS_PGSIZE, MEM_FLAG_ROMCS, MEM_FMASK_ROMCS); + scamp_mem_update_state(dev, 0x000cc000, EMS_PGSIZE, MEM_FLAG_ROMCS, MEM_FMASK_ROMCS); - shadow_control(0xe0000, 0x4000, feaxs & 3, ems_enable & 0x10000); - shadow_control(0xe4000, 0x4000, feaxs & 3, ems_enable & 0x20000); - shadow_control(0xe8000, 0x4000, (feaxs >> 2) & 3, ems_enable & 0x40000); - shadow_control(0xec000, 0x4000, (feaxs >> 2) & 3, ems_enable & 0x80000); + scamp_mem_update_state(dev, 0x000e0000, EMS_PGSIZE, 0x00, MEM_FMASK_ROMCS); + scamp_mem_update_state(dev, 0x000e4000, EMS_PGSIZE, 0x00, MEM_FMASK_ROMCS); + scamp_mem_update_state(dev, 0x000e8000, EMS_PGSIZE, 0x00, MEM_FMASK_ROMCS); + scamp_mem_update_state(dev, 0x000ec000, EMS_PGSIZE, 0x00, MEM_FMASK_ROMCS); + break; + } - shadow_control(0xf0000, 0x8000, (feaxs >> 4) & 3, 0); - shadow_control(0xf8000, 0x8000, (feaxs >> 6) & 3, 0); + flushmmucache_nopc(); } static void @@ -719,7 +916,7 @@ scamp_write(uint16_t addr, uint8_t val, void *priv) switch (addr) { case 0xe8: - dev->ems_index = val & 0x1f; + dev->ems_index = val & 0x3f; dev->ems_autoinc = val & 0x40; break; @@ -749,12 +946,14 @@ scamp_write(uint16_t addr, uint8_t val, void *priv) switch (dev->cfg_index) { case CFG_SLTPTR: recalc_sltptr(dev); + recalc_ems(dev); break; case CFG_RAMMAP: recalc_mappings(dev); mem_mapping_disable(&ram_remapped_mapping); shadow_recalc(dev); + recalc_rommov(dev); break; case CFG_EMSEN1: @@ -847,8 +1046,7 @@ static void * scamp_init(UNUSED(const device_t *info)) { uint32_t addr; - scamp_t *dev = (scamp_t *) malloc(sizeof(scamp_t)); - memset(dev, 0x00, sizeof(scamp_t)); + scamp_t *dev = (scamp_t *) calloc(1, sizeof(scamp_t)); dev->cfg_regs[CFG_ID] = ID_VL82C311; dev->cfg_enable = 1; @@ -878,9 +1076,8 @@ scamp_init(UNUSED(const device_t *info)) mem_mapping_set_handler(&ram_low_mapping, ram_mirrored_read, NULL, NULL, ram_mirrored_write, NULL, NULL); + mem_mapping_disable(&ram_mid_mapping); mem_mapping_disable(&ram_high_mapping); - mem_mapping_set_addr(&ram_mid_mapping, 0xf0000, 0x10000); - mem_mapping_set_exec(&ram_mid_mapping, ram + 0xf0000); addr = 0; for (uint8_t c = 0; c < 2; c++) { @@ -952,15 +1149,45 @@ scamp_init(UNUSED(const device_t *info)) mem_set_mem_state(0xfe0000, 0x20000, MEM_READ_EXTANY | MEM_WRITE_EXTANY); - 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], - 0xa0000 + c * 0x4000, 0x4000, - scamp_ems_read, NULL, NULL, - scamp_ems_write, NULL, NULL, - ram + 0xa0000 + c * 0x4000, MEM_MAPPING_INTERNAL, (void *) &dev->ems_struct[c]); - dev->mappings[c] = 0xa0000 + c * 0x4000; + for (uint8_t i = 0; i < 12; i++) + dev->ems[i] = (0x000c0000 + (i * EMS_PGSIZE)) >> 14; + + for (uint8_t i = 0; i < 24; i++) + dev->ems[i + 12] = (0x00040000 + (i * EMS_PGSIZE)) >> 14; + + for (uint8_t i = 0; i < 64; i++) { + dev->mem_pages[i].in_ram = 1; + dev->mem_pages[i].virt_addr = i * EMS_PGSIZE; + dev->mem_pages[i].phys_addr = dev->mem_pages[i].virt_addr; + dev->mem_pages[i].mem = ram + dev->mem_pages[i].phys_addr; + + mem_mapping_add(&(dev->mem_mappings[i]), + i * EMS_PGSIZE, EMS_PGSIZE, + scamp_mem_readb, scamp_mem_readw, NULL, + scamp_mem_writeb, scamp_mem_writew, NULL, + dev->mem_pages[i].mem, MEM_MAPPING_INTERNAL, + &(dev->mem_pages[i])); + + if (i < 40) { + mem_mapping_disable(&(dev->mem_mappings[i])); + + scamp_mem_update_state(dev, i * EMS_PGSIZE, EMS_PGSIZE, MEM_FLAG_READ | MEM_FLAG_WRITE, MEM_FMASK_RW); + } else { + /* This is needed to the state update actually occurs. */ + dev->mem_flags[i] = MEM_FLAG_READ | MEM_FLAG_WRITE; + scamp_mem_update_state(dev, i * EMS_PGSIZE, EMS_PGSIZE, 0x00, MEM_FMASK_RW); + + if (i >= 56) + scamp_mem_update_state(dev, i * EMS_PGSIZE, EMS_PGSIZE, MEM_FLAG_ROMCS, MEM_FMASK_ROMCS); + } + } + + dev->card_mem = NULL; + + for (uint8_t i = 0; i < 4; i++) { + dev->card_pages[i].virt_addr = i * EMS_PGSIZE; + dev->card_pages[i].phys_addr = dev->card_pages[i].virt_addr; + dev->card_pages[i].mem = dev->card_mem + dev->card_pages[i].phys_addr; } dev->port_92 = device_add(&port_92_device); @@ -976,7 +1203,7 @@ const device_t vlsi_scamp_device = { .init = scamp_init, .close = scamp_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/scat.c b/src/chipset/scat.c index d168b643f..43f93649e 100644 --- a/src/chipset/scat.c +++ b/src/chipset/scat.c @@ -1403,8 +1403,7 @@ scat_init(const device_t *info) uint32_t k; int sx; - dev = (scat_t *) malloc(sizeof(scat_t)); - memset(dev, 0x00, sizeof(scat_t)); + dev = (scat_t *) calloc(1, sizeof(scat_t)); dev->type = info->local; sx = (dev->type == 32) ? 1 : 0; @@ -1559,7 +1558,7 @@ const device_t scat_device = { .init = scat_init, .close = scat_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1573,7 +1572,7 @@ const device_t scat_4_device = { .init = scat_init, .close = scat_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1587,7 +1586,7 @@ const device_t scat_sx_device = { .init = scat_init, .close = scat_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5511.c b/src/chipset/sis_5511.c index aa841ed9c..38fcfe717 100644 --- a/src/chipset/sis_5511.c +++ b/src/chipset/sis_5511.c @@ -165,7 +165,7 @@ const device_t sis_5511_device = { .init = sis_5511_init, .close = sis_5511_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5511_h2p.c b/src/chipset/sis_5511_h2p.c index 7916d6ae2..c8cb44a0a 100644 --- a/src/chipset/sis_5511_h2p.c +++ b/src/chipset/sis_5511_h2p.c @@ -22,6 +22,7 @@ #include <86box/86box.h> #include <86box/device.h> #include <86box/io.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/dma.h> #include <86box/mem.h> @@ -258,7 +259,7 @@ sis_5511_host_to_pci_write(int addr, uint8_t val, void *priv) case 0x7a: /* DRAM Bank Register 2-1 */ case 0x7c: /* DRAM Bank Register 3-0 */ case 0x7e: /* DRAM Bank Register 3-1 */ - spd_write_drbs(dev->pci_conf, 0x70, 0x7e, 0x82); + spd_write_drbs(dev->pci_conf, 0x70, 0x7e, 0x02); break; case 0x71: /* DRAM Bank Register 0-0 */ @@ -454,7 +455,7 @@ const device_t sis_5511_h2p_device = { .init = sis_5511_host_to_pci_init, .close = sis_5511_host_to_pci_close, .reset = sis_5511_host_to_pci_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5513_ide.c b/src/chipset/sis_5513_ide.c index 5cbfbdea8..9e3a0ad07 100644 --- a/src/chipset/sis_5513_ide.c +++ b/src/chipset/sis_5513_ide.c @@ -456,7 +456,7 @@ const device_t sis_5513_ide_device = { .init = sis_5513_ide_init, .close = sis_5513_ide_close, .reset = sis_5513_ide_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -470,7 +470,7 @@ const device_t sis_5572_ide_device = { .init = sis_5513_ide_init, .close = sis_5513_ide_close, .reset = sis_5513_ide_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -484,7 +484,7 @@ const device_t sis_5582_ide_device = { .init = sis_5513_ide_init, .close = sis_5513_ide_close, .reset = sis_5513_ide_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -498,7 +498,7 @@ const device_t sis_5591_5600_ide_device = { .init = sis_5513_ide_init, .close = sis_5513_ide_close, .reset = sis_5513_ide_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5513_p2i.c b/src/chipset/sis_5513_p2i.c index ef9a6746d..b2346bbc4 100644 --- a/src/chipset/sis_5513_p2i.c +++ b/src/chipset/sis_5513_p2i.c @@ -22,6 +22,7 @@ #include <86box/86box.h> #include <86box/device.h> #include <86box/io.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/dma.h> @@ -106,7 +107,7 @@ sis_5513_apc_reset(sis_5513_pci_to_isa_t *dev) { memset(dev->apc_regs, 0x00, sizeof(dev->apc_regs)); - if (dev->rev == 0b0) { + if (dev->rev == 0xb0) { dev->apc_regs[0x03] = 0x80; dev->apc_regs[0x04] = 0x38; dev->apc_regs[0x07] = 0x01; @@ -115,7 +116,7 @@ sis_5513_apc_reset(sis_5513_pci_to_isa_t *dev) } static void -sis_5513_apc_write(uint16_t addr, uint8_t val, void *priv) +sis_5513_apc_write(UNUSED(uint16_t addr), uint8_t val, void *priv) { sis_5513_pci_to_isa_t *dev = (sis_5513_pci_to_isa_t *) priv; uint8_t nvr_index = nvr_get_index(dev->nvr, 0); @@ -135,7 +136,7 @@ sis_5513_apc_write(uint16_t addr, uint8_t val, void *priv) } static uint8_t -sis_5513_apc_read(uint16_t addr, void *priv) +sis_5513_apc_read(UNUSED(uint16_t addr), void *priv) { sis_5513_pci_to_isa_t *dev = (sis_5513_pci_to_isa_t *) priv; uint8_t nvr_index = nvr_get_index(dev->nvr, 0); @@ -1287,9 +1288,9 @@ sis_5513_pci_to_isa_init(UNUSED(const device_t *info)) acpi_set_nvr(dev->sis->acpi, dev->nvr); /* Set up the NVR file's name. */ - c = strlen(machine_get_internal_name()) + 9; + c = strlen(machine_get_nvr_name()) + 9; dev->fn = (char *) malloc(c + 1); - sprintf(dev->fn, "%s_apc.nvr", machine_get_internal_name()); + sprintf(dev->fn, "%s_apc.nvr", machine_get_nvr_name()); fp = nvr_fopen(dev->fn, "rb"); @@ -1318,7 +1319,7 @@ const device_t sis_5513_p2i_device = { .init = sis_5513_pci_to_isa_init, .close = sis_5513_pci_to_isa_close, .reset = sis_5513_pci_to_isa_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1332,7 +1333,7 @@ const device_t sis_5572_p2i_device = { .init = sis_5513_pci_to_isa_init, .close = sis_5513_pci_to_isa_close, .reset = sis_5513_pci_to_isa_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1347,7 +1348,7 @@ const device_t sis_5582_p2i_device = { .init = sis_5513_pci_to_isa_init, .close = sis_5513_pci_to_isa_close, .reset = sis_5513_pci_to_isa_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1362,7 +1363,7 @@ const device_t sis_5595_1997_p2i_device = { .init = sis_5513_pci_to_isa_init, .close = sis_5513_pci_to_isa_close, .reset = sis_5513_pci_to_isa_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1376,7 +1377,7 @@ const device_t sis_5595_p2i_device = { .init = sis_5513_pci_to_isa_init, .close = sis_5513_pci_to_isa_close, .reset = sis_5513_pci_to_isa_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5571.c b/src/chipset/sis_5571.c index 3fb111978..3980704fd 100644 --- a/src/chipset/sis_5571.c +++ b/src/chipset/sis_5571.c @@ -177,7 +177,7 @@ const device_t sis_5571_device = { .init = sis_5571_init, .close = sis_5571_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5571_h2p.c b/src/chipset/sis_5571_h2p.c index 4a4ee9b83..a28553487 100644 --- a/src/chipset/sis_5571_h2p.c +++ b/src/chipset/sis_5571_h2p.c @@ -22,6 +22,7 @@ #include <86box/86box.h> #include <86box/device.h> #include <86box/io.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/dma.h> #include <86box/mem.h> @@ -451,7 +452,7 @@ const device_t sis_5571_h2p_device = { .init = sis_5571_host_to_pci_init, .close = sis_5571_host_to_pci_close, .reset = sis_5571_host_to_pci_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5571_old.c b/src/chipset/sis_5571_old.c index f130ecd8a..495137aed 100644 --- a/src/chipset/sis_5571_old.c +++ b/src/chipset/sis_5571_old.c @@ -732,8 +732,7 @@ sis_5571_close(void *priv) static void * 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)); + sis_5571_t *dev = (sis_5571_t *) calloc(1, sizeof(sis_5571_t)); pci_add_card(PCI_ADD_NORTHBRIDGE, memory_pci_bridge_read, memory_pci_bridge_write, dev, &dev->nb_slot); pci_add_card(PCI_ADD_SOUTHBRIDGE, pci_isa_bridge_read, pci_isa_bridge_write, dev, &dev->sb_slot); @@ -765,7 +764,7 @@ const device_t sis_5571_device = { .init = sis_5571_init, .close = sis_5571_close, .reset = sis_5571_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5572_usb.c b/src/chipset/sis_5572_usb.c index 250c32587..bc7dc7d38 100644 --- a/src/chipset/sis_5572_usb.c +++ b/src/chipset/sis_5572_usb.c @@ -288,7 +288,7 @@ const device_t sis_5572_usb_device = { .init = sis_5572_usb_init, .close = sis_5572_usb_close, .reset = sis_5572_usb_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -302,7 +302,7 @@ const device_t sis_5582_usb_device = { .init = sis_5572_usb_init, .close = sis_5572_usb_close, .reset = sis_5572_usb_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -316,7 +316,7 @@ const device_t sis_5595_usb_device = { .init = sis_5572_usb_init, .close = sis_5572_usb_close, .reset = sis_5572_usb_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5581.c b/src/chipset/sis_5581.c index e2308c2d9..998ac5350 100644 --- a/src/chipset/sis_5581.c +++ b/src/chipset/sis_5581.c @@ -177,7 +177,7 @@ const device_t sis_5581_device = { .init = sis_5581_init, .close = sis_5581_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5581_h2p.c b/src/chipset/sis_5581_h2p.c index 30bd70bfe..83983376d 100644 --- a/src/chipset/sis_5581_h2p.c +++ b/src/chipset/sis_5581_h2p.c @@ -22,6 +22,7 @@ #include <86box/86box.h> #include <86box/device.h> #include <86box/io.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/dma.h> #include <86box/mem.h> @@ -545,7 +546,7 @@ const device_t sis_5581_h2p_device = { .init = sis_5581_host_to_pci_init, .close = sis_5581_host_to_pci_close, .reset = sis_5581_host_to_pci_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5591.c b/src/chipset/sis_5591.c index 969fcb8dd..3cb11cb5b 100644 --- a/src/chipset/sis_5591.c +++ b/src/chipset/sis_5591.c @@ -189,7 +189,7 @@ const device_t sis_5591_1997_device = { .init = sis_5591_init, .close = sis_5591_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -203,7 +203,7 @@ const device_t sis_5591_device = { .init = sis_5591_init, .close = sis_5591_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5591_h2p.c b/src/chipset/sis_5591_h2p.c index 8fcbeeb6f..74dd6dfbd 100644 --- a/src/chipset/sis_5591_h2p.c +++ b/src/chipset/sis_5591_h2p.c @@ -22,6 +22,7 @@ #include <86box/86box.h> #include <86box/device.h> #include <86box/io.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/dma.h> #include <86box/mem.h> @@ -486,7 +487,7 @@ const device_t sis_5591_h2p_device = { .init = sis_5591_host_to_pci_init, .close = sis_5591_host_to_pci_close, .reset = sis_5591_host_to_pci_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5595_pmu.c b/src/chipset/sis_5595_pmu.c index de351ad7c..7de9735f1 100644 --- a/src/chipset/sis_5595_pmu.c +++ b/src/chipset/sis_5595_pmu.c @@ -119,7 +119,7 @@ sis_5595_pmu_trap_io_mask(int size, uint16_t addr, uint8_t write, uint8_t val, v } static void -sis_5595_pmu_trap_io_ide_bm(int size, uint16_t addr, uint8_t write, uint8_t val, void *priv) +sis_5595_pmu_trap_io_ide_bm(UNUSED(int size), UNUSED(uint16_t addr), UNUSED(uint8_t write), UNUSED(uint8_t val), void *priv) { sis_5595_pmu_io_trap_t *trap = (sis_5595_pmu_io_trap_t *) priv; sis_5595_pmu_t *dev = (sis_5595_pmu_t *) trap->priv; @@ -433,7 +433,7 @@ const device_t sis_5595_1997_pmu_device = { .init = sis_5595_pmu_init, .close = sis_5595_pmu_close, .reset = sis_5595_pmu_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -447,7 +447,7 @@ const device_t sis_5595_pmu_device = { .init = sis_5595_pmu_init, .close = sis_5595_pmu_close, .reset = sis_5595_pmu_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_55xx.c b/src/chipset/sis_55xx.c index 2cad21f22..1cb0744eb 100644 --- a/src/chipset/sis_55xx.c +++ b/src/chipset/sis_55xx.c @@ -89,7 +89,7 @@ const device_t sis_55xx_common_device = { .init = sis_55xx_common_init, .close = sis_55xx_common_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5600.c b/src/chipset/sis_5600.c index ed7384740..1ed7f9ad0 100644 --- a/src/chipset/sis_5600.c +++ b/src/chipset/sis_5600.c @@ -189,7 +189,7 @@ const device_t sis_5600_1997_device = { .init = sis_5600_init, .close = sis_5600_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -203,7 +203,7 @@ const device_t sis_5600_device = { .init = sis_5600_init, .close = sis_5600_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_5600_h2p.c b/src/chipset/sis_5600_h2p.c index f6ee926da..c23309de4 100644 --- a/src/chipset/sis_5600_h2p.c +++ b/src/chipset/sis_5600_h2p.c @@ -22,6 +22,7 @@ #include <86box/86box.h> #include <86box/device.h> #include <86box/io.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/dma.h> #include <86box/mem.h> @@ -427,7 +428,7 @@ const device_t sis_5600_h2p_device = { .init = sis_5600_host_to_pci_init, .close = sis_5600_host_to_pci_close, .reset = sis_5600_host_to_pci_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_85c310.c b/src/chipset/sis_85c310.c index 296307fe1..dfbd4b465 100644 --- a/src/chipset/sis_85c310.c +++ b/src/chipset/sis_85c310.c @@ -130,8 +130,7 @@ rabbit_close(void *priv) static void * rabbit_init(UNUSED(const device_t *info)) { - rabbit_t *dev = (rabbit_t *) malloc(sizeof(rabbit_t)); - memset(dev, 0, sizeof(rabbit_t)); + rabbit_t *dev = (rabbit_t *) calloc(1, sizeof(rabbit_t)); io_sethandler(0x0022, 0x0002, rabbit_read, NULL, NULL, rabbit_write, NULL, NULL, dev); @@ -146,7 +145,7 @@ const device_t rabbit_device = { .init = rabbit_init, .close = rabbit_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_85c496.c b/src/chipset/sis_85c496.c index 3c3d5bd8c..10bccc1c8 100644 --- a/src/chipset/sis_85c496.c +++ b/src/chipset/sis_85c496.c @@ -637,8 +637,7 @@ static void * sis_85c496_init(const device_t *info) { - sis_85c496_t *dev = malloc(sizeof(sis_85c496_t)); - memset(dev, 0x00, sizeof(sis_85c496_t)); + sis_85c496_t *dev = calloc(1, sizeof(sis_85c496_t)); dev->smram = smram_add(); @@ -702,7 +701,7 @@ const device_t sis_85c496_device = { .init = sis_85c496_init, .close = sis_85c496_close, .reset = sis_85c496_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -716,7 +715,7 @@ const device_t sis_85c496_ls486e_device = { .init = sis_85c496_init, .close = sis_85c496_close, .reset = sis_85c496_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_85c4xx.c b/src/chipset/sis_85c4xx.c index f80ecf99e..be5bd668e 100644 --- a/src/chipset/sis_85c4xx.c +++ b/src/chipset/sis_85c4xx.c @@ -15,6 +15,7 @@ * * Copyright 2019-2020 Miran Grca. */ +#include #include #include #include @@ -33,27 +34,384 @@ #include <86box/mem.h> #include <86box/smram.h> #include <86box/pic.h> +#include <86box/plat_fallthrough.h> +#include <86box/keyboard.h> #include <86box/machine.h> #include <86box/chipset.h> +typedef struct ram_bank_t { + uint32_t virt_base; + uint32_t virt_size; + uint32_t phys_base; + uint32_t phys_size; + + mem_mapping_t mapping; +} ram_bank_t; + 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; + 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 ram_banks_val; + 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]; + ram_bank_t ram_banks[8]; + smram_t * smram; + port_92_t * port_92; } sis_85c4xx_t; +static uint8_t ram_4xx[64] = { 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, + 0x04, 0x00, 0x05, 0x00, 0x0b, 0x00, 0x00, 0x00, + 0x19, 0x00, 0x06, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x1b, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, + 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +static uint8_t ram_471[64] = { 0x00, 0x00, 0x01, 0x01, 0x02, 0x20, 0x09, 0x09, + 0x04, 0x04, 0x05, 0x05, 0x0b, 0x0b, 0x0b, 0x0b, + 0x13, 0x21, 0x06, 0x06, 0x0d, 0x0d, 0x0d, 0x0d, + 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, + 0x1b, 0x1b, 0x1b, 0x1b, 0x0f, 0x0f, 0x0f, 0x0f, + 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, + 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, + 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d }; +static uint8_t ram_asus[64] = { 0x00, 0x00, 0x01, 0x10, 0x10, 0x20, 0x03, 0x11, + 0x11, 0x05, 0x05, 0x12, 0x12, 0x13, 0x13, 0x13, + 0x13, 0x21, 0x06, 0x14, 0x14, 0x15, 0x15, 0x15, + 0x15, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, + 0x1d, 0x16, 0x16, 0x16, 0x16, 0x17, 0x17, 0x17, + 0x17, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, + 0x1e, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, + 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f }; +static uint8_t ram_tg486g[64] = { 0x10, 0x10, 0x10, 0x10, 0x10, 0x11, 0x11, 0x11, + 0x11, 0x12, 0x12, 0x12, 0x12, 0x13, 0x13, 0x13, + 0x13, 0x14, 0x14, 0x14, 0x14, 0x15, 0x15, 0x15, + 0x15, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, + 0x1d, 0x16, 0x16, 0x16, 0x16, 0x17, 0x17, 0x17, + 0x17, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, + 0x1e, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, + 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f }; + +static uint32_t banks_471[64][4] = { { 0x00100000, 0x00000000, 0x00000000, 0x00000000 }, /* 0x00 */ + { 0x00100000, 0x00100000, 0x00000000, 0x00000000 }, + { 0x00100000, 0x00100000, 0x00200000, 0x00000000 }, + { 0x00100000, 0x00100000, 0x00400000, 0x00000000 }, + { 0x00100000, 0x00100000, 0x00200000, 0x00400000 }, + { 0x00100000, 0x00100000, 0x00400000, 0x00400000 }, + { 0x00100000, 0x00100000, 0x01000000, 0x00000000 }, + { 0x00200000, 0x00000000, 0x00000000, 0x00000000 }, + { 0x00200000, 0x00200000, 0x00000000, 0x00000000 }, /* 0x08 */ + { 0x00200000, 0x00400000, 0x00000000, 0x00000000 }, + { 0x00200000, 0x00200000, 0x00400000, 0x00000000 }, + { 0x00200000, 0x00200000, 0x00400000, 0x00400000 }, + { 0x00200000, 0x01000000, 0x00000000, 0x00000000 }, + { 0x00200000, 0x00200000, 0x01000000, 0x00000000 }, + { 0x00200000, 0x00200000, 0x00400000, 0x01000000 }, + { 0x00200000, 0x00200000, 0x01000000, 0x01000000 }, + { 0x00400000, 0x00000000, 0x00000000, 0x00000000 }, /* 0x10 */ + { 0x00400000, 0x00400000, 0x00000000, 0x00000000 }, + { 0x00400000, 0x00400000, 0x00400000, 0x00000000 }, + { 0x00400000, 0x00400000, 0x00400000, 0x00400000 }, + { 0x00400000, 0x01000000, 0x00000000, 0x00000000 }, + { 0x00400000, 0x00400000, 0x01000000, 0x00000000 }, + { 0x00400000, 0x01000000, 0x01000000, 0x00000000 }, + { 0x00400000, 0x00400000, 0x01000000, 0x01000000 }, + { 0x00800000, 0x00000000, 0x00000000, 0x00000000 }, /* 0x18 */ + { 0x00800000, 0x00800000, 0x00000000, 0x00000000 }, + { 0x00800000, 0x00800000, 0x00800000, 0x00000000 }, + { 0x00800000, 0x00800000, 0x00800000, 0x00800000 }, + { 0x01000000, 0x00000000, 0x00000000, 0x00000000 }, + { 0x01000000, 0x01000000, 0x00000000, 0x00000000 }, + { 0x01000000, 0x01000000, 0x01000000, 0x00000000 }, + { 0x01000000, 0x01000000, 0x01000000, 0x01000000 }, + { 0x00100000, 0x00400000, 0x00000000, 0x00000000 }, /* 0x20 */ + { 0x00100000, 0x01000000, 0x00000000, 0x00000000 }, + { 0x00100000, 0x04000000, 0x00000000, 0x00000000 }, + { 0x00400000, 0x00800000, 0x00000000, 0x00000000 }, + { 0x00400000, 0x04000000, 0x00000000, 0x00000000 }, + { 0x00400000, 0x00400000, 0x04000000, 0x00000000 }, + { 0x01000000, 0x04000000, 0x00000000, 0x00000000 }, + { 0x01000000, 0x01000000, 0x04000000, 0x00000000 }, + { 0x04000000, 0x00000000, 0x00000000, 0x00000000 }, /* 0x28 */ + { 0x04000000, 0x04000000, 0x00000000, 0x00000000 }, + { 0x00400000, 0x02000000, 0x00000000, 0x00000000 }, + { 0x00400000, 0x02000000, 0x02000000, 0x00000000 }, + { 0x00400000, 0x00400000, 0x02000000, 0x00000000 }, + { 0x00400000, 0x00400000, 0x02000000, 0x02000000 }, + { 0x01000000, 0x02000000, 0x00000000, 0x00000000 }, + { 0x01000000, 0x02000000, 0x02000000, 0x00000000 }, + { 0x01000000, 0x01000000, 0x02000000, 0x00000000 }, /* 0x30 */ + { 0x01000000, 0x01000000, 0x02000000, 0x02000000 }, + { 0x02000000, 0x00000000, 0x00000000, 0x00000000 }, + { 0x02000000, 0x02000000, 0x00000000, 0x00000000 }, + { 0x02000000, 0x02000000, 0x02000000, 0x00000000 }, + { 0x02000000, 0x02000000, 0x02000000, 0x02000000 }, + { 0x00400000, 0x00800000, 0x00800000, 0x00000000 }, + { 0x00400000, 0x00800000, 0x00800000, 0x00800000 }, + { 0x00400000, 0x00400000, 0x00800000, 0x00000000 }, /* 0x38 */ + { 0x00400000, 0x00400000, 0x00800000, 0x00800000 }, + { 0x00800000, 0x01000000, 0x00000000, 0x00000000 }, + { 0x00800000, 0x00800000, 0x00800000, 0x01000000 }, + { 0x00800000, 0x00800000, 0x01000000, 0x00000000 }, + { 0x00800000, 0x00800000, 0x01000000, 0x01000000 }, + { 0x00800000, 0x00800000, 0x02000000, 0x00000000 }, + { 0x00800000, 0x00800000, 0x02000000, 0x02000000 } }; + +static uint32_t +sis_85c471_get_row(ram_bank_t *dev, uint32_t addr) +{ + uint32_t ret = 0x00000000; + + switch (dev->virt_size) { + case 0x00100000: + case 0x00200000: + ret |= (addr >> 13) & 0x00000001; + ret |= ((addr >> 12) & 0x00000001) << 1; + ret |= ((addr >> 14) & 0x0000003f) << 2; + ret |= ((addr >> 11) & 0x00000001) << 8; + ret |= ((addr >> 20) & 0x00000001) << 9; + ret |= ((addr >> 22) & 0x00000001) << 10; + ret |= ((addr >> 24) & 0x00000001) << 11; + break; + case 0x00400000: + case 0x00800000: + ret |= (addr >> 13) & 0x00000001; + ret |= ((addr >> 12) & 0x00000001) << 1; + ret |= ((addr >> 14) & 0x000000ff) << 2; + ret |= ((addr >> 22) & 0x00000001) << 10; + ret |= ((addr >> 24) & 0x00000001) << 11; + break; + case 0x01000000: + case 0x02000000: + case 0x04000000: + ret |= (addr >> 13) & 0x00000001; + ret |= ((addr >> 22) & 0x00000001) << 1; + ret |= ((addr >> 14) & 0x000000ff) << 2; + ret |= ((addr >> 23) & 0x00000001) << 10; + ret |= ((addr >> 24) & 0x00000001) << 11; + break; + } + + return ret; +} + +static uint32_t +sis_85c471_get_col(ram_bank_t *dev, uint32_t addr) +{ + uint32_t ret = 0x00000000; + + switch (dev->virt_size) { + case 0x00100000: + case 0x00200000: + ret |= (addr >> 3) & 0x00000001; + ret |= ((addr >> 2) & 0x00000001) << 1; + ret |= ((addr >> 4) & 0x0000003f) << 2; + ret |= ((addr >> 10) & 0x00000001) << 8; + ret |= ((addr >> 21) & 0x00000001) << 9; + ret |= ((addr >> 23) & 0x00000001) << 10; + ret |= ((addr >> 25) & 0x00000001) << 11; + break; + case 0x00400000: + case 0x00800000: + ret |= (addr >> 3) & 0x00000001; + ret |= ((addr >> 2) & 0x00000001) << 1; + ret |= ((addr >> 4) & 0x000000ff) << 2; + ret |= ((addr >> 23) & 0x00000001) << 10; + ret |= ((addr >> 25) & 0x00000001) << 11; + break; + case 0x01000000: + case 0x02000000: + case 0x04000000: + ret |= (addr >> 3) & 0x00000001; + ret |= ((addr >> 2) & 0x00000001) << 1; + ret |= ((addr >> 4) & 0x000001ff) << 2; + ret |= ((addr >> 25) & 0x00000001) << 11; + break; + } + + return ret; +} + +static uint32_t +sis_85c471_set_row(ram_bank_t *dev, uint32_t addr) +{ + uint32_t ret = 0x00000000; + + switch (dev->phys_size) { + case 0x00100000: + ret = (addr & 0x1ff) << 11; + break; + case 0x00200000: + ret = (addr & 0x3ff) << 11; + break; + case 0x00400000: + ret = (addr & 0x3ff) << 12; + break; + case 0x00800000: + ret = (addr & 0x7ff) << 12; + break; + case 0x01000000: + ret = (addr & 0x7ff) << 13; + break; + case 0x02000000: + ret = (addr & 0xfff) << 13; + break; + case 0x04000000: + ret = (addr & 0xfff) << 14; + break; + } + + return ret; +} + +static uint32_t +sis_85c471_set_col(ram_bank_t *dev, uint32_t addr) +{ + uint32_t ret = 0x00000000; + + switch (dev->phys_size) { + case 0x00100000: + case 0x00200000: + ret = (addr & 0x1ff) << 2; + break; + case 0x00400000: + case 0x00800000: + ret = (addr & 0x3ff) << 2; + break; + case 0x01000000: + case 0x02000000: + ret = (addr & 0x7ff) << 2; + break; + case 0x04000000: + ret = (addr & 0xfff) << 2; + break; + } + + return ret; +} + +uint8_t reg09 = 0x00; + +static uint8_t +sis_85c471_read_ram(uint32_t addr, void *priv) +{ + ram_bank_t *dev = (ram_bank_t *) priv; + uint32_t rel = addr - dev->virt_base; + uint8_t ret = 0xff; + + uint32_t row = sis_85c471_set_row(dev, sis_85c471_get_row(dev, rel)); + uint32_t col = sis_85c471_set_col(dev, sis_85c471_get_col(dev, rel)); + uint32_t dw = rel & 0x00000003; + rel = row | col | dw; + + addr = (rel + dev->phys_base); + + if ((addr < (mem_size << 10)) && (rel < dev->phys_size)) + ret = ram[addr]; + + return ret; +} + +static uint16_t +sis_85c471_read_ramw(uint32_t addr, void *priv) +{ + ram_bank_t *dev = (ram_bank_t *) priv; + uint32_t rel = addr - dev->virt_base; + uint16_t ret = 0xffff; + + uint32_t row = sis_85c471_set_row(dev, sis_85c471_get_row(dev, rel)); + uint32_t col = sis_85c471_set_col(dev, sis_85c471_get_col(dev, rel)); + uint32_t dw = rel & 0x00000003; + rel = row | col | dw; + + addr = (rel + dev->phys_base); + + if ((addr < (mem_size << 10)) && (rel < dev->phys_size)) + ret = *(uint16_t *) &(ram[addr]); + + return ret; +} + +static uint32_t +sis_85c471_read_raml(uint32_t addr, void *priv) +{ + ram_bank_t *dev = (ram_bank_t *) priv; + uint32_t rel = addr - dev->virt_base; + uint32_t ret = 0xffffffff; + + uint32_t row = sis_85c471_set_row(dev, sis_85c471_get_row(dev, rel)); + uint32_t col = sis_85c471_set_col(dev, sis_85c471_get_col(dev, rel)); + uint32_t dw = rel & 0x00000003; + rel = row | col | dw; + + addr = (rel + dev->phys_base); + + if ((addr < (mem_size << 10)) && (rel < dev->phys_size)) + ret = *(uint32_t *) &(ram[addr]); + + return ret; +} + +static void +sis_85c471_write_ram(uint32_t addr, uint8_t val, void *priv) +{ + ram_bank_t *dev = (ram_bank_t *) priv; + uint32_t rel = addr - dev->virt_base; + + uint32_t row = sis_85c471_set_row(dev, sis_85c471_get_row(dev, rel)); + uint32_t col = sis_85c471_set_col(dev, sis_85c471_get_col(dev, rel)); + uint32_t dw = rel & 0x00000003; + rel = row | col | dw; + + addr = (rel + dev->phys_base); + + if ((addr < (mem_size << 10)) && (rel < dev->phys_size)) + ram[addr] = val; +} + +static void +sis_85c471_write_ramw(uint32_t addr, uint16_t val, void *priv) +{ + ram_bank_t *dev = (ram_bank_t *) priv; + uint32_t rel = addr - dev->virt_base; + + uint32_t row = sis_85c471_set_row(dev, sis_85c471_get_row(dev, rel)); + uint32_t col = sis_85c471_set_col(dev, sis_85c471_get_col(dev, rel)); + uint32_t dw = rel & 0x00000003; + rel = row | col | dw; + + addr = (rel + dev->phys_base); + + if ((addr < (mem_size << 10)) && (rel < dev->phys_size)) + *(uint16_t *) &(ram[addr]) = val; +} + +static void +sis_85c471_write_raml(uint32_t addr, uint32_t val, void *priv) +{ + ram_bank_t *dev = (ram_bank_t *) priv; + uint32_t rel = addr - dev->virt_base; + + uint32_t row = sis_85c471_set_row(dev, sis_85c471_get_row(dev, rel)); + uint32_t col = sis_85c471_set_col(dev, sis_85c471_get_col(dev, rel)); + uint32_t dw = rel & 0x00000003; + rel = row | col | dw; + + addr = (rel + dev->phys_base); + + if ((addr < (mem_size << 10)) && (rel < dev->phys_size)) + *(uint32_t *) &(ram[addr]) = val; +} + static void sis_85c4xx_recalcremap(sis_85c4xx_t *dev) { @@ -158,6 +516,62 @@ sis_85c4xx_sw_smi_handler(sis_85c4xx_t *dev) NULL, NULL, NULL, sis_85c4xx_sw_smi_out, NULL, NULL, dev); } +static void +sis_85c471_banks_split(uint32_t *b_ex, uint32_t *banks) +{ + for (uint8_t i = 0; i < 4; i++) { + if ((banks[i] == 0x00200000) || (banks[i] == 0x00800000) || + (banks[i] == 0x02000000)) + b_ex[i << 1] = b_ex[(i << 1) + 1] = banks[i] >> 1; + else { + b_ex[i << 1] = banks[i]; + b_ex[(i << 1) + 1] = 0x00000000; + } + } +} + +static void +sis_85c471_banks_recalc(sis_85c4xx_t *dev) +{ + reg09 = dev->regs[0x09]; + + for (uint8_t i = 0; i < 8; i++) + mem_mapping_disable(&dev->ram_banks[i].mapping); + + mem_mapping_disable(&ram_low_mapping); + mem_mapping_disable(&ram_high_mapping); + mem_set_mem_state_both(1 << 20, 127 << 20, MEM_READ_EXTERNAL | MEM_WRITE_EXTERNAL); + + if ((dev->regs[0x09] & 0x3f) == dev->ram_banks_val) { + if (mem_size > 1024) { + mem_mapping_enable(&ram_low_mapping); + mem_mapping_enable(&ram_high_mapping); + mem_set_mem_state_both(1 << 20, (mem_size << 10) - (1 << 20), + MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + } + } else { + uint8_t banks_val = dev->regs[0x09] & 0x3f; + uint32_t *banks = banks_471[banks_val]; + uint32_t b_ex[8] = { 0x00000000 }; + uint32_t size = 0x00000000; + + sis_85c471_banks_split(b_ex, banks); + + for (uint8_t i = 0; i < 8; i++) if (b_ex[i] != 0x00000000) { + dev->ram_banks[i].virt_base = size; + dev->ram_banks[i].virt_size = b_ex[i]; + + mem_mapping_set_addr(&dev->ram_banks[i].mapping, size, b_ex[i]); + + size += b_ex[i]; + } + + mem_set_mem_state_both(1 << 20, 127 << 20, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + } + + flushmmucache_nopc(); +} + static void sis_85c4xx_out(uint16_t port, uint8_t val, void *priv) { @@ -174,12 +588,25 @@ sis_85c4xx_out(uint16_t port, uint8_t val, void *priv) case 0x23: if ((dev->cur_reg >= dev->reg_base) && (dev->cur_reg <= dev->reg_last)) { valxor = val ^ dev->regs[rel_reg]; - if (rel_reg == 0x00) + + if (!dev->is_471 && (rel_reg == 0x00)) dev->regs[rel_reg] = (dev->regs[rel_reg] & 0x1f) | (val & 0xe0); else dev->regs[rel_reg] = val; switch (rel_reg) { + case 0x00: + if (dev->is_471) { + if (val & 0x01) { + kbc_at_set_fast_reset(0); + cpu_cpurst_on_sr = 1; + } else { + kbc_at_set_fast_reset(1); + cpu_cpurst_on_sr = 0; + } + } + break; + case 0x01: cpu_cache_ext_enabled = ((val & 0x84) == 0x84); cpu_update_waitstates(); @@ -190,6 +617,13 @@ sis_85c4xx_out(uint16_t port, uint8_t val, void *priv) case 0x08: if (valxor) sis_85c4xx_recalcmapping(dev); + if ((rel_reg == 0x08) && dev->is_471) + flushmmucache(); + break; + + case 0x09: + if (dev->is_471) + sis_85c471_banks_recalc(dev); break; case 0x0b: @@ -198,6 +632,41 @@ sis_85c4xx_out(uint16_t port, uint8_t val, void *priv) sis_85c4xx_recalcremap(dev); break; + case 0x10: + if (dev->reg_base == 0x50) { + double bus_clk; + + switch (val & 0xe0) { + default: + case 0x00: + bus_clk = 7159091.0; + break; + case 0x02: + bus_clk = cpu_busspeed / 10.0; + break; + case 0x04: + bus_clk = cpu_busspeed / 8.0; + break; + case 0x06: + bus_clk = cpu_busspeed / 6.0; + break; + case 0x80: + bus_clk = cpu_busspeed / 5.0; + break; + case 0xa0: + bus_clk = cpu_busspeed / 4.0; + break; + case 0xc0: + bus_clk = cpu_busspeed / 3.0; + break; + case 0xe0: + bus_clk = cpu_busspeed / 2.0; + break; + } + cpu_set_isa_speed((int) round(bus_clk)); + } + break; + case 0x13: if (dev->is_471 && (valxor & 0xf0)) { smram_disable(dev->smram); @@ -297,14 +766,6 @@ sis_85c4xx_reset(void *priv) { sis_85c4xx_t *dev = (sis_85c4xx_t *) priv; int mem_size_mb = mem_size >> 10; - static uint8_t ram_4xx[64] = { 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x0b, 0x00, 0x00, 0x00, - 0x19, 0x00, 0x06, 0x00, 0x14, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x1b, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - static uint8_t ram_471[64] = { 0x00, 0x00, 0x01, 0x01, 0x02, 0x20, 0x09, 0x09, 0x04, 0x04, 0x05, 0x05, 0x0b, 0x0b, 0x0b, 0x0b, - 0x13, 0x21, 0x06, 0x06, 0x0d, 0x0d, 0x0d, 0x0d, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, - 0x1b, 0x1b, 0x1b, 0x1b, 0x0f, 0x0f, 0x0f, 0x0f, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, - 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e }; memset(dev->regs, 0x00, sizeof(dev->regs)); @@ -313,13 +774,44 @@ sis_85c4xx_reset(void *priv) if (dev->is_471) { dev->regs[0x09] = 0x40; - if (mem_size_mb >= 64) { - if ((mem_size_mb >= 65) && (mem_size_mb < 68)) - dev->regs[0x09] |= 0x22; + + if (!strcmp(machine_get_internal_name(), "vli486sv2g")) { + if (mem_size_mb == 64) + dev->regs[0x09] |= 0x1f; else - dev->regs[0x09] |= 0x24; - } else + dev->regs[0x09] |= ram_asus[mem_size_mb]; + } else if (mem_size_mb >= 64) { + if ((mem_size_mb >= 64) && (mem_size_mb < 68)) + dev->regs[0x09] |= 0x33; + else if ((mem_size_mb >= 68) && (mem_size_mb < 72)) + dev->regs[0x09] |= 0x2b; + else if ((mem_size_mb >= 72) && (mem_size_mb < 80)) + dev->regs[0x09] |= 0x2d; + else if ((mem_size_mb >= 80) && (mem_size_mb < 96)) + dev->regs[0x09] |= 0x2f; + else if ((mem_size_mb >= 96) && (mem_size_mb < 128)) + dev->regs[0x09] |= 0x34; + else + dev->regs[0x09] |= 0x35; + } else if (!strcmp(machine_get_internal_name(), "tg486g")) + dev->regs[0x09] |= ram_tg486g[mem_size_mb]; + else dev->regs[0x09] |= ram_471[mem_size_mb]; + dev->ram_banks_val = dev->regs[0x09] & 0x3f; + dev->regs[0x09] = 0x00; + + uint32_t *banks = banks_471[dev->ram_banks_val]; + uint32_t b_ex[8] = { 0x00000000 }; + uint32_t size = 0x00000000; + + sis_85c471_banks_split(b_ex, banks); + + for (uint8_t i = 0; i < 8; i++) { + dev->ram_banks[i].phys_base = size; + dev->ram_banks[i].phys_size = b_ex[i]; + + size += b_ex[i]; + } dev->regs[0x11] = 0x09; dev->regs[0x12] = 0xff; @@ -332,6 +824,11 @@ sis_85c4xx_reset(void *priv) port_92_remove(dev->port_92); soft_reset_mask = 0; + + sis_85c471_banks_recalc(dev); + + kbc_at_set_fast_reset(1); + cpu_cpurst_on_sr = 0; } else { /* Bits 6 and 7 must be clear on the SiS 40x. */ if (dev->reg_base == 0x60) @@ -352,6 +849,9 @@ sis_85c4xx_reset(void *priv) dev->force_flush = 1; sis_85c4xx_recalcmapping(dev); + + if (dev->reg_base == 0x50) + cpu_set_isa_speed((int) round(7159091.0)); } static void @@ -368,19 +868,26 @@ sis_85c4xx_close(void *priv) static void * sis_85c4xx_init(const device_t *info) { - sis_85c4xx_t *dev = (sis_85c4xx_t *) malloc(sizeof(sis_85c4xx_t)); - memset(dev, 0, sizeof(sis_85c4xx_t)); + sis_85c4xx_t *dev = (sis_85c4xx_t *) calloc(1, sizeof(sis_85c4xx_t)); dev->is_471 = (info->local >> 8) & 0xff; dev->reg_base = info->local & 0xff; if (dev->is_471) { - dev->reg_last = dev->reg_base + 0x76; + dev->reg_last = 0x76; dev->smram = smram_add(); dev->port_92 = device_add(&port_92_device); + + for (uint8_t i = 0; i < 8; i++) { + mem_mapping_add(&dev->ram_banks[i].mapping, 0x00000000, 0x00000000, + sis_85c471_read_ram, sis_85c471_read_ramw, sis_85c471_read_raml, + sis_85c471_write_ram, sis_85c471_write_ramw, sis_85c471_write_raml, + NULL, MEM_MAPPING_INTERNAL, &(dev->ram_banks[i])); + mem_mapping_disable(&dev->ram_banks[i].mapping); + } } else dev->reg_last = dev->reg_base + 0x11; @@ -403,7 +910,7 @@ const device_t sis_85c401_device = { .init = sis_85c4xx_init, .close = sis_85c4xx_close, .reset = sis_85c4xx_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -417,7 +924,7 @@ const device_t sis_85c460_device = { .init = sis_85c4xx_init, .close = sis_85c4xx_close, .reset = sis_85c4xx_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -432,7 +939,7 @@ const device_t sis_85c461_device = { .init = sis_85c4xx_init, .close = sis_85c4xx_close, .reset = sis_85c4xx_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -446,7 +953,7 @@ const device_t sis_85c471_device = { .init = sis_85c4xx_init, .close = sis_85c4xx_close, .reset = sis_85c4xx_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sis_85c50x.c b/src/chipset/sis_85c50x.c index 2286105ce..e932ff6ca 100644 --- a/src/chipset/sis_85c50x.c +++ b/src/chipset/sis_85c50x.c @@ -24,6 +24,7 @@ #include <86box/86box.h> #include <86box/device.h> #include <86box/io.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/apm.h> #include <86box/machine.h> @@ -684,7 +685,7 @@ const device_t sis_85c50x_device = { .init = sis_85c50x_init, .close = sis_85c50x_close, .reset = sis_85c50x_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -698,7 +699,7 @@ const device_t sis_550x_85c503_device = { .init = sis_85c50x_init, .close = sis_85c50x_close, .reset = sis_85c50x_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -712,7 +713,7 @@ const device_t sis_85c50x_5503_device = { .init = sis_85c50x_init, .close = sis_85c50x_close, .reset = sis_85c50x_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -726,7 +727,7 @@ const device_t sis_550x_device = { .init = sis_85c50x_init, .close = sis_85c50x_close, .reset = sis_85c50x_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/sl82c461.c b/src/chipset/sl82c461.c new file mode 100644 index 000000000..f94aa2e99 --- /dev/null +++ b/src/chipset/sl82c461.c @@ -0,0 +1,362 @@ +/* + * 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 Symphony SL82C461 (Haydn II) chipset. + * + * Symphony SL82C461 Configuration Registers (WARNING: May be inaccurate!): + * + * - Register 00h: + * - Bit 6: External cache present (if clear, AMI BIOS'es will not + * allow enabling external cache). + * + * - Register 01h: + * - Bit 0: Fast Gate A20 Enable (Handler mostly). + * Is it? Enabling/disabling fast gate A20 doesn't appear + * to do much to any register at all. + * + * - Register 02h: + * - Bit 0: Optional Chipset Turbo Pin; + * - Bits 4-2: + * - 000 = CLK2/3; + * - 001 = CLK2/4; + * - 010 = CLK2/5; + * - 011 = 7.159 MHz (ATCLK2); + * - 100 = CLK2/6; + * - 110 = CLK2/2.5; + * - 111 = CLK2/2. + * + * - Register 06h: + * - Bit 2: Decoupled Refresh Option. + * + * - Register 08h: + * - Bits 3, 2: I/O Recovery Time (SYSCLK): + * - 0, 0 = 0; + * - 1, 1 = 12. + * - Bit 1: Extended ALE. + * + * - Register 25h: + * Bit 7 here causes AMI 111192 CMOS Setup to return 7168 KB RAM + * instead of 6912 KB. This is 256 KB off. Relocation? + * Also, returning bit 5 clear instead of set, causes the AMI BIOS + * to set bits 0,1 of register 45h to 1,0 instead of 0,1. + * + * - Register 2Dh: + * - Bit 7: Enable 256KB Memory Relocation; + * - Bit 6: Enable 384KB Memory Relocation, bit 7 must also be set. + * + * - Register 2Eh: + * - Bit 7: CC000-CFFFF Shadow Read Enable; + * - Bit 6: CC000-CFFFF Shadow Write Enable; + * - Bit 5: C8000-CBFFF Shadow Read Enable; + * - Bit 4: C8000-CBFFF Shadow Write Enable; + * - Bit 3: C4000-C7FFF Shadow Read Enable; + * - Bit 2: C4000-C7FFF Shadow Write Enable; + * - Bit 1: C0000-C3FFF Shadow Read Enable; + * - Bit 0: C0000-C3FFF Shadow Write Enable. + * + * - Register 2Fh: + * - Bit 7: DC000-DFFFF Shadow Read Enable; + * - Bit 6: DC000-DFFFF Shadow Write Enable; + * - Bit 5: D8000-DBFFF Shadow Read Enable; + * - Bit 4: D8000-DBFFF Shadow Write Enable; + * - Bit 3: D4000-D7FFF Shadow Read Enable; + * - Bit 2: D4000-D7FFF Shadow Write Enable; + * - Bit 1: D0000-D3FFF Shadow Read Enable; + * - Bit 0: D0000-D3FFF Shadow Write Enable. + * + * - Register 30h: + * - Bit 7: E0000-EFFFF Shadow Read Enable; + * - Bit 6: E0000-EFFFF Shadow Write Enable. + * + * - Register 31h: + * - Bit 7: F0000-FFFFF Shadow Read Enable; + * - Bit 6: F0000-FFFFF Shadow Write Enable. + * + * - Register 33h (NOTE: Waitstates also affect register 32h): + * - Bits 3, 0: + * - 0,0 = 0 W/S; + * - 1,0 = 1 W/S; + * - 1,1 = 2 W/S. + * + * - Register 40h: + * - Bit 3: External Cache Enabled (0 = yes, 1 = no); + * I also see bits 5, 4, 3 of register 44h affected: + * - 38h (so all 3 set) when cache is disabled; + * - 00h (all 3 clear) when it's enabled. + * + * - Register 45h: + * - Bit 3: Video Shadow RAM Cacheable; + * - Bit 4: Adapter Shadow RAM Cacheable; + * - Bit 5: BIOS Shadow RAM Cacheable. + * + * Authors: Miran Grca, + * Tiseno100, + * + * Copyright 2025 Miran Grca. + * Copyright 2021-2025 Tiseno100. + */ +#include +#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/mem.h> +#include <86box/chipset.h> + +typedef struct { + uint8_t index; + uint8_t regs[256]; + uint8_t shadow[4]; +} sl82c461_t; + +#ifdef ENABLE_SL82C461_LOG +int sl82c461_do_log = ENABLE_SL82C461_LOG; + +static void +sl82c461_log(const char *fmt, ...) +{ + va_list ap; + + if (sl82c461_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +#define sl82c461_log(fmt, ...) +#endif + +static void +sl82c461_recalcmapping(sl82c461_t *dev) +{ + int do_shadow = 0; + + for (uint32_t i = 0; i < 8; i += 2) { + if ((dev->regs[0x2e] ^ dev->shadow[0x00]) & (3 << i)) { + uint32_t base = 0x000c0000 + ((i >> 1) << 14); + uint32_t read = ((dev->regs[0x2e] >> i) & 0x02) ? MEM_READ_INTERNAL : + MEM_READ_EXTANY; + uint32_t write = ((dev->regs[0x2e] >> i) & 0x01) ? MEM_WRITE_INTERNAL : + MEM_WRITE_EXTANY; + + mem_set_mem_state_both(base, 0x00004000, read | write); + + do_shadow++; + } + + if ((dev->regs[0x2f] ^ dev->shadow[0x01]) & (3 << i)) { + uint32_t base = 0x000d0000 + ((i >> 1) << 14); + uint32_t read = ((dev->regs[0x2f] >> i) & 0x02) ? MEM_READ_INTERNAL : + MEM_READ_EXTANY; + uint32_t write = ((dev->regs[0x2f] >> i) & 0x01) ? MEM_WRITE_INTERNAL : + MEM_WRITE_EXTANY; + + mem_set_mem_state_both(base, 0x00004000, read | write); + + do_shadow++; + } + } + + if ((dev->regs[0x30] ^ dev->shadow[0x02]) & 0xc0) { + uint32_t base = 0x000e0000; + uint32_t read = ((dev->regs[0x30] >> 6) & 0x02) ? MEM_READ_INTERNAL : + MEM_READ_EXTANY; + uint32_t write = ((dev->regs[0x30] >> 6) & 0x01) ? MEM_WRITE_INTERNAL : + MEM_WRITE_EXTANY; + + mem_set_mem_state_both(base, 0x00010000, read | write); + + do_shadow++; + } + + if ((dev->regs[0x31] ^ dev->shadow[0x03]) & 0xc0) { + uint32_t base = 0x000f0000; + uint32_t read = ((dev->regs[0x31] >> 6) & 0x02) ? MEM_READ_INTERNAL : + MEM_READ_EXTANY; + uint32_t write = ((dev->regs[0x31] >> 6) & 0x01) ? MEM_WRITE_INTERNAL : + MEM_WRITE_EXTANY; + + shadowbios = !!((dev->regs[0x31] >> 6) & 0x02); + shadowbios_write = !!((dev->regs[0x31] >> 6) & 0x01); + + mem_set_mem_state_both(base, 0x00010000, read | write); + + do_shadow++; + } + + if (do_shadow) { + memcpy(dev->shadow, &(dev->regs[0x2e]), 4 * sizeof(uint8_t)); + flushmmucache_nopc(); + } +} + +static void +sl82c461_write(uint16_t addr, uint8_t val, void *priv) +{ + sl82c461_t *dev = (sl82c461_t *) priv; + + sl82c461_log("[%04X:%08X] [W] %04X = %02X\n", CS, cpu_state.pc, addr, val); + + if (addr & 0x0001) { + dev->regs[dev->index] = val; + + switch (dev->index) { + case 0x01: + /* NOTE: This is to be verified. */ + mem_a20_alt = val & 1; + mem_a20_recalc(); + break; + case 0x02: { + double bus_clk; + switch (val & 0x1c) { + case 0x00: + bus_clk = cpu_busspeed / 3.0; + break; + case 0x04: + bus_clk = cpu_busspeed / 4.0; + break; + case 0x08: + bus_clk = cpu_busspeed / 5.0; + break; + default: + case 0x0c: + bus_clk = 7159091.0; + break; + case 0x10: + bus_clk = cpu_busspeed / 6.0; + break; + case 0x18: + bus_clk = cpu_busspeed / 2.5; + break; + case 0x1c: + bus_clk = cpu_busspeed / 2.0; + break; + } + cpu_set_isa_speed((int) round(bus_clk)); + break; + } case 0x2d: + switch (val & 0xc0) { + case 0xc0: + mem_remap_top(384); + break; + case 0x80: + mem_remap_top(256); + break; + default: + case 0x00: + mem_remap_top(0); + break; + } + break; + case 0x2e ... 0x31: + sl82c461_recalcmapping(dev); + break; + case 0x33: + switch (val & 0x09) { + default: + case 0x00: + cpu_waitstates = 0; + break; + case 0x08: + cpu_waitstates = 1; + break; + case 0x09: + cpu_waitstates = 2; + break; + } + cpu_update_waitstates(); + break; + case 0x40: + cpu_cache_ext_enabled = !(val & 0x08); + cpu_update_waitstates(); + break; + } + } else + dev->index = val; +} + +static uint8_t +sl82c461_read(uint16_t addr, void *priv) +{ + sl82c461_t *dev = (sl82c461_t *) priv; + uint8_t ret = 0x00; + + if (addr & 0x0001) + if (dev->index == 0x00) + ret = dev->regs[dev->index] | 0x40; + else + ret = dev->regs[dev->index]; + else + ret = dev->index; + + sl82c461_log("[%04X:%08X] [R] %04X = %02X\n", CS, cpu_state.pc, addr, ret); + + return ret; +} + +static void +sl82c461_close(void *priv) +{ + sl82c461_t *dev = (sl82c461_t *) priv; + + free(dev); +} + +static void * +sl82c461_init(const device_t *info) +{ + sl82c461_t *dev = (sl82c461_t *) calloc(1, sizeof(sl82c461_t)); + + dev->regs[0x00] = 0x40; + + dev->regs[0x02] = 0x0c; + dev->regs[0x40] = 0x08; + + memset(dev->shadow, 0xff, 4 * sizeof(uint8_t)); + + mem_a20_alt = 0x00; + mem_a20_recalc(); + + cpu_set_isa_speed(7159091.0); + + sl82c461_recalcmapping(dev); + + cpu_waitstates = 0; + cpu_cache_ext_enabled = 0; + + cpu_update_waitstates(); + + io_sethandler(0x00a8, 2, + sl82c461_read, NULL, NULL, + sl82c461_write, NULL, NULL, dev); + + return dev; +} + +const device_t sl82c461_device = { + .name = "Symphony SL82C461 (Haydn II)", + .internal_name = "sis_85c471", + .flags = 0, + .local = 0, + .init = sl82c461_init, + .close = sl82c461_close, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; diff --git a/src/chipset/stpc.c b/src/chipset/stpc.c index dbe39ec5c..13dbd97e9 100644 --- a/src/chipset/stpc.c +++ b/src/chipset/stpc.c @@ -912,8 +912,7 @@ stpc_init(const device_t *info) { stpc_log("STPC: init()\n"); - stpc_t *dev = (stpc_t *) malloc(sizeof(stpc_t)); - memset(dev, 0, sizeof(stpc_t)); + stpc_t *dev = (stpc_t *) calloc(1, sizeof(stpc_t)); dev->local = info->local; @@ -963,8 +962,7 @@ stpc_serial_init(UNUSED(const device_t *info)) { stpc_log("STPC: serial_init()\n"); - stpc_serial_t *dev = (stpc_serial_t *) malloc(sizeof(stpc_serial_t)); - memset(dev, 0, sizeof(stpc_serial_t)); + stpc_serial_t *dev = (stpc_serial_t *) calloc(1, sizeof(stpc_serial_t)); dev->uart[0] = device_add_inst(&ns16550_device, 1); dev->uart[1] = device_add_inst(&ns16550_device, 2); @@ -977,39 +975,24 @@ stpc_serial_init(UNUSED(const device_t *info)) static void stpc_lpt_handlers(stpc_lpt_t *dev, uint8_t val) { - uint8_t old_addr = (dev->reg1 & 0x03); - uint8_t new_addr = (val & 0x03); + const uint8_t new_addr = (val & 0x03); - switch (old_addr) { - case 0x1: - lpt3_remove(); - break; - - case 0x2: - lpt1_remove(); - break; - - case 0x3: - lpt2_remove(); - break; - default: - break; - } + lpt1_remove(); switch (new_addr) { case 0x1: stpc_log("STPC: Remapping parallel port to LPT3\n"); - lpt3_init(0x3bc); + lpt1_setup(LPT_MDA_ADDR); break; case 0x2: stpc_log("STPC: Remapping parallel port to LPT1\n"); - lpt1_init(0x378); + lpt1_setup(LPT1_ADDR); break; case 0x3: stpc_log("STPC: Remapping parallel port to LPT2\n"); - lpt2_init(0x278); + lpt1_setup(LPT2_ADDR); break; default: @@ -1017,9 +1000,11 @@ stpc_lpt_handlers(stpc_lpt_t *dev, uint8_t val) break; } - dev->reg1 = (val & 0x08); - dev->reg1 |= new_addr; - dev->reg1 |= 0x84; /* reserved bits that default to 1; hardwired? */ + if (dev != NULL) { + dev->reg1 = (val & 0x08); + dev->reg1 |= new_addr; + dev->reg1 |= 0x84; /* reserved bits that default to 1; hardwired? */ + } } static void @@ -1076,8 +1061,7 @@ stpc_lpt_init(UNUSED(const device_t *info)) { stpc_log("STPC: lpt_init()\n"); - stpc_lpt_t *dev = (stpc_lpt_t *) malloc(sizeof(stpc_lpt_t)); - memset(dev, 0, sizeof(stpc_lpt_t)); + stpc_lpt_t *dev = (stpc_lpt_t *) calloc(1, sizeof(stpc_lpt_t)); stpc_lpt_reset(dev); @@ -1096,7 +1080,7 @@ const device_t stpc_client_device = { .init = stpc_init, .close = stpc_close, .reset = stpc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1110,7 +1094,7 @@ const device_t stpc_consumer2_device = { .init = stpc_init, .close = stpc_close, .reset = stpc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1124,7 +1108,7 @@ const device_t stpc_elite_device = { .init = stpc_init, .close = stpc_close, .reset = stpc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1138,7 +1122,7 @@ const device_t stpc_atlas_device = { .init = stpc_init, .close = stpc_close, .reset = stpc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1153,7 +1137,7 @@ const device_t stpc_serial_device = { .init = stpc_serial_init, .close = stpc_serial_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1167,7 +1151,7 @@ const device_t stpc_lpt_device = { .init = stpc_lpt_init, .close = stpc_lpt_close, .reset = stpc_lpt_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/umc_8886.c b/src/chipset/umc_8886.c index 4242062c6..0ed062450 100644 --- a/src/chipset/umc_8886.c +++ b/src/chipset/umc_8886.c @@ -82,6 +82,8 @@ #include <86box/hdd.h> #include <86box/hdc.h> #include <86box/hdc_ide.h> +#include <86box/keyboard.h> +#include <86box/machine.h> #include <86box/pic.h> #include <86box/pci.h> #include <86box/port_92.h> @@ -392,8 +394,7 @@ umc_8886_close(void *priv) static void * umc_8886_init(const device_t *info) { - umc_8886_t *dev = (umc_8886_t *) malloc(sizeof(umc_8886_t)); - memset(dev, 0, sizeof(umc_8886_t)); + umc_8886_t *dev = (umc_8886_t *) calloc(1, sizeof(umc_8886_t)); /* Device 12: UMC 8886xx */ pci_add_card(PCI_ADD_SOUTHBRIDGE, umc_8886_read, umc_8886_write, dev, &dev->pci_slot); @@ -431,7 +432,7 @@ const device_t umc_8886f_device = { .init = umc_8886_init, .close = umc_8886_close, .reset = umc_8886_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -445,7 +446,7 @@ const device_t umc_8886af_device = { .init = umc_8886_init, .close = umc_8886_close, .reset = umc_8886_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -459,7 +460,7 @@ const device_t umc_8886bf_device = { .init = umc_8886_init, .close = umc_8886_close, .reset = umc_8886_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/umc_8890.c b/src/chipset/umc_8890.c index 7de2ca1d0..cb69ce6a8 100644 --- a/src/chipset/umc_8890.c +++ b/src/chipset/umc_8890.c @@ -38,6 +38,7 @@ #include <86box/smram.h> #include <86box/chipset.h> +#include <86box/plat_unused.h> #ifdef ENABLE_UMC_8890_LOG int umc_8890_do_log = ENABLE_UMC_8890_LOG; @@ -209,7 +210,7 @@ umc_8890_close(void *priv) static void * -umc_8890_init(const device_t *info) +umc_8890_init(UNUSED(const device_t *info)) { umc_8890_t *dev = (umc_8890_t *) calloc(1, sizeof(umc_8890_t)); @@ -234,7 +235,7 @@ const device_t umc_8890_device = { .init = umc_8890_init, .close = umc_8890_close, .reset = umc_8890_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/umc_hb4.c b/src/chipset/umc_hb4.c index c1f359f26..55901b32e 100644 --- a/src/chipset/umc_hb4.c +++ b/src/chipset/umc_hb4.c @@ -270,6 +270,8 @@ hb4_smram(hb4_t *dev) } umc_smram_recalc(dev->smram_base >> 12, 1); + + flushmmucache(); } static void @@ -398,60 +400,10 @@ hb4_close(void *priv) free(dev); } -static void -ims8848_write(uint16_t addr, uint8_t val, void *priv) -{ - hb4_t *dev = (hb4_t *) priv; - - switch (addr) { - case 0x22: - dev->idx = val; - break; - case 0x23: - if (((val & 0x0f) == ((dev->idx >> 4) & 0x0f)) && ((val & 0xf0) == ((dev->idx << 4) & 0xf0))) - dev->access_data = 1; - break; - case 0x24: - if (dev->access_data) - dev->access_data = 0; - break; - - default: - break; - } -} - -static uint8_t -ims8848_read(uint16_t addr, void *priv) -{ - uint8_t ret = 0xff; - hb4_t *dev = (hb4_t *) priv; - - switch (addr) { - case 0x22: - ret = dev->idx; - break; - case 0x23: - ret = (dev->idx >> 4) | (dev->idx << 4); - break; - case 0x24: - if (dev->access_data) { - ret = dev->pci_conf[dev->idx]; - dev->access_data = 0; - } - break; - default: - break; - } - - return ret; -} - static void * hb4_init(UNUSED(const device_t *info)) { - hb4_t *dev = (hb4_t *) malloc(sizeof(hb4_t)); - memset(dev, 0, sizeof(hb4_t)); + hb4_t *dev = (hb4_t *) calloc(1, sizeof(hb4_t)); pci_add_card(PCI_ADD_NORTHBRIDGE, hb4_read, hb4_write, dev, &dev->pci_slot); /* Device 10: UMC 8881x */ @@ -464,8 +416,6 @@ hb4_init(UNUSED(const device_t *info)) dev->smram_base = 0x000a0000; hb4_reset(dev); - io_sethandler(0x0022, 0x0003, ims8848_read, NULL, NULL, ims8848_write, NULL, NULL, dev); - return dev; } @@ -477,7 +427,7 @@ const device_t umc_hb4_device = { .init = hb4_init, .close = hb4_close, .reset = hb4_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/via_apollo.c b/src/chipset/via_apollo.c index 20e2c7f74..110b1f8e1 100644 --- a/src/chipset/via_apollo.c +++ b/src/chipset/via_apollo.c @@ -725,8 +725,7 @@ via_apollo_reset(void *priv) static void * via_apollo_init(const device_t *info) { - via_apollo_t *dev = (via_apollo_t *) malloc(sizeof(via_apollo_t)); - memset(dev, 0, sizeof(via_apollo_t)); + via_apollo_t *dev = (via_apollo_t *) calloc(1, sizeof(via_apollo_t)); dev->smram = smram_add(); if (dev->id != VIA_8601) @@ -793,7 +792,7 @@ const device_t via_vpx_device = { .init = via_apollo_init, .close = via_apollo_close, .reset = via_apollo_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -807,7 +806,7 @@ const device_t amd640_device = { .init = via_apollo_init, .close = via_apollo_close, .reset = via_apollo_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -821,7 +820,7 @@ const device_t via_vp3_device = { .init = via_apollo_init, .close = via_apollo_close, .reset = via_apollo_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -835,7 +834,7 @@ const device_t via_mvp3_device = { .init = via_apollo_init, .close = via_apollo_close, .reset = via_apollo_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -849,7 +848,7 @@ const device_t via_apro_device = { .init = via_apollo_init, .close = via_apollo_close, .reset = via_apollo_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -863,7 +862,7 @@ const device_t via_apro133_device = { .init = via_apollo_init, .close = via_apollo_close, .reset = via_apollo_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -877,7 +876,7 @@ const device_t via_apro133a_device = { .init = via_apollo_init, .close = via_apollo_close, .reset = via_apollo_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -891,7 +890,7 @@ const device_t via_vt8601_device = { .init = via_apollo_init, .close = via_apollo_close, .reset = via_apollo_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/via_pipc.c b/src/chipset/via_pipc.c index 1f153092b..248664983 100644 --- a/src/chipset/via_pipc.c +++ b/src/chipset/via_pipc.c @@ -59,8 +59,10 @@ 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_586 0x0586 #define VIA_PIPC_596A 0x05960900 #define VIA_PIPC_596B 0x05962300 +#define VIA_PIPC_596 0x0596 #define VIA_PIPC_686A 0x06861400 #define VIA_PIPC_686B 0x06864000 #define VIA_PIPC_8231 0x82311000 @@ -413,7 +415,9 @@ pipc_reset_hard(void *priv) dev->power_regs[0x34] = 0x68; dev->power_regs[0x40] = 0x20; - dev->power_regs[0x42] = 0x50; + dev->power_regs[0x42] = ((dev->local >> 16) == VIA_PIPC_586) ? 0x00 : 0x50; + acpi_set_irq_line(dev->acpi, 0x00); + dev->power_regs[0x48] = 0x01; if (dev->local == VIA_PIPC_686B) { @@ -489,14 +493,28 @@ pipc_reset_hard(void *priv) } dev->ac97_regs[i][0x1c] = 0x01; + if (i == 0) { + dev->ac97_regs[i][0x34] = 0xc0; + + dev->ac97_regs[i][0xc0] = 0x01; + dev->ac97_regs[i][0xc1] = 0x00; + dev->ac97_regs[i][0xc2] = 0x03; + dev->ac97_regs[i][0xc3] = 0x00; + + dev->ac97_regs[i][0xc4] = 0x00; + dev->ac97_regs[i][0xc5] = 0x00; + dev->ac97_regs[i][0xc6] = 0x00; + dev->ac97_regs[i][0xc7] = 0x00; + } + dev->ac97_regs[i][0x3d] = 0x03; - if (i == 0) + if (i == 0) { dev->ac97_regs[i][0x40] = 0x01; - - dev->ac97_regs[i][0x43] = 0x1c; - dev->ac97_regs[i][0x48] = 0x01; - dev->ac97_regs[i][0x4b] = 0x02; + dev->ac97_regs[i][0x43] = 0x1c; + dev->ac97_regs[i][0x48] = 0x01; + dev->ac97_regs[i][0x4b] = 0x00; + } pipc_sgd_handlers(dev, i); pipc_codec_handlers(dev, i); @@ -738,10 +756,12 @@ pipc_codec_handlers(pipc_t *dev, uint8_t modem) if (!dev->ac97) return; + uint32_t base = (dev->ac97_regs[modem][0x1d] << 8); + if (modem) - ac97_via_remap_modem_codec(dev->ac97, dev->ac97_regs[1][0x1d] << 8, dev->ac97_regs[1][0x04] & PCI_COMMAND_IO); + ac97_via_remap_modem_codec(dev->ac97, base, dev->ac97_regs[1][0x04] & PCI_COMMAND_IO); else - ac97_via_remap_audio_codec(dev->ac97, dev->ac97_regs[0][0x1d] << 8, dev->ac97_regs[0][0x04] & PCI_COMMAND_IO); + ac97_via_remap_audio_codec(dev->ac97, base, dev->ac97_regs[0][0x04] & PCI_COMMAND_IO); } static uint8_t @@ -1200,7 +1220,7 @@ pipc_write(int func, int addr, uint8_t val, void *priv) case 0x77: if ((dev->local >= VIA_PIPC_686A) && (val & 0x10)) - pclog("PIPC: Warning: Internal I/O APIC enabled.\n"); + warning("PIPC: Warning: Internal I/O APIC enabled.\n"); nvr_via_wp_set(!!(val & 0x04), 0x32, dev->nvr); nvr_via_wp_set(!!(val & 0x02), 0x0d, dev->nvr); break; @@ -1484,36 +1504,39 @@ pipc_write(int func, int addr, uint8_t val, void *priv) break; } } else if (func <= pm_func + 2) { /* AC97 / MC97 */ - /* Read-only addresses. */ - if ((addr < 0x4) || ((addr >= 0x6) && (addr < 0x9)) || ((addr >= 0xc) && (addr < 0x11)) || (addr == 0x16) || (addr == 0x17) || (addr == 0x1a) || (addr == 0x1b) || ((addr >= 0x1e) && (addr < 0x2c)) || ((addr >= 0x30) && (addr < 0x34)) || ((addr >= 0x35) && (addr < 0x3c)) || ((addr >= 0x3d) && (addr < 0x41)) || ((addr >= 0x45) && (addr < 0x4a)) || (addr >= 0x4c)) - return; - /* Small shortcut. */ func = func - pm_func - 1; - /* Check disable bits and specific read-only addresses for both controllers. */ - if ((func == 0) && (((addr >= 0x09) && (addr < 0xc)) || (addr == 0x44) || (dev->pci_isa_regs[0x85] & 0x04))) + /* Check disable bits. */ + if ((func == 0) && (dev->pci_isa_regs[0x85] & 0x04)) return; - if ((func == 1) && ((addr == 0x14) || (addr == 0x15) || (addr == 0x18) || (addr == 0x19) || (addr == 0x42) || (addr == 0x43) || (addr == 0x48) || (addr == 0x4a) || (addr == 0x4b) || (dev->pci_isa_regs[0x85] & 0x08))) + if ((func == 1) && (dev->pci_isa_regs[0x85] & 0x08)) return; switch (addr) { case 0x04: - dev->ac97_regs[func][addr] = val; + dev->ac97_regs[func][addr] = val & 0x01; pipc_sgd_handlers(dev, func); + if (func == 0) { + pipc_fmnmi_handlers(dev, func); + pipc_sb_handlers(dev, func); + } pipc_codec_handlers(dev, func); - pipc_fmnmi_handlers(dev, func); break; case 0x09: case 0x0a: case 0x0b: - if (dev->ac97_regs[func][0x44] & 0x20) + /* Not writable on audio, only on modem. */ + if ((func == 1) && (dev->ac97_regs[func][0x44] & 0x20)) dev->ac97_regs[func][addr] = val; break; - case 0x10: + /* + The lowest 10 bytes are always 0x01, indicating + a 256-byte I/O space. + */ case 0x11: dev->ac97_regs[func][addr] = val; pipc_sgd_handlers(dev, func); @@ -1521,21 +1544,26 @@ pipc_write(int func, int addr, uint8_t val, void *priv) case 0x14: case 0x15: - if (addr == 0x14) - val = (val & 0xfc) | 1; - dev->ac97_regs[func][addr] = val; - pipc_fmnmi_handlers(dev, func); + /* Not present on modem. */ + if (func == 0) { + if (addr == 0x14) + val = (val & 0xfc) | 1; + dev->ac97_regs[func][addr] = val; + pipc_fmnmi_handlers(dev, func); + } break; case 0x18: case 0x19: - if (addr == 0x18) - val = (val & 0xfc) | 1; - dev->ac97_regs[func][addr] = val; - pipc_sb_handlers(dev, func); + /* Not present on modem. */ + if (func == 0) { + if (addr == 0x18) + val = (val & 0xfc) | 1; + dev->ac97_regs[func][addr] = val; + pipc_sb_handlers(dev, func); + } break; - case 0x1c: case 0x1d: dev->ac97_regs[func][addr] = val; pipc_codec_handlers(dev, func); @@ -1545,39 +1573,84 @@ pipc_write(int func, int addr, uint8_t val, void *priv) case 0x2d: case 0x2e: case 0x2f: - if ((func == 0) && (dev->ac97_regs[func][0x42] & 0x20)) + if (((func == 0) && (dev->ac97_regs[func][0x42] & 0x20)) || + ((func == 1) && (dev->ac97_regs[func][0x44] & 0x10))) dev->ac97_regs[func][addr] = val; break; + case 0x3c: + dev->ac97_regs[func][addr] = val & 0x0f; + break; + case 0x41: dev->ac97_regs[func][addr] = val; ac97_via_write_control(dev->ac97, func, val); break; case 0x42: - case 0x4a: - case 0x4b: - dev->ac97_regs[0][addr] = dev->ac97_regs[1][addr] = val; - gameport_remap(dev->gameport, (dev->ac97_regs[0][0x42] & 0x08) ? ((dev->ac97_regs[0][0x4b] << 8) | (dev->ac97_regs[0][0x4a] & 0xf8)) : 0); - if (addr == 0x42) - pipc_sb_handlers(dev, func); + case 0x4a ... 0x4b: + if (func == 0) { + dev->ac97_regs[func][addr] = val; + gameport_remap(dev->gameport, (dev->ac97_regs[func][0x42] & 0x08) ? + ((dev->ac97_regs[func][0x4b] << 8) | + (dev->ac97_regs[func][0x4a] & 0xf8)) : 0); + + if (addr == 0x42) + pipc_sb_handlers(dev, func); + } break; case 0x43: - dev->ac97_regs[0][addr] = dev->ac97_regs[1][addr] = val; + if (func == 0) + dev->ac97_regs[func][addr] = val; break; case 0x44: - dev->ac97_regs[0][addr] = dev->ac97_regs[1][addr] = val & 0xf0; + if (func == 1) + dev->ac97_regs[func][addr] = val & 0xf0; break; - case 0x45: case 0x48: - dev->ac97_regs[0][addr] = dev->ac97_regs[1][addr] = val & 0x0f; + if (func == 0) + dev->ac97_regs[func][addr] = val & 0x0f; + break; + + case 0x80: + case 0x81: + case 0x82: + dev->ac97_regs[func][addr] = val; + break; + case 0x83: + dev->ac97_regs[func][addr] = ((dev->ac97_regs[func][addr] & 0x01) | + (val & 0xc0)) & ~(val & 0x0a); + break; + + case 0x88: + case 0x89: + dev->ac97_regs[func][addr] = val; + break; + case 0x8a: + case 0x8b: + dev->ac97_regs[func][addr] &= ~val; + break; + + case 0x8e: + case 0x8f: + dev->ac97_regs[func][addr] = val; + break; + + case 0xc4: + if (func == 0) + dev->ac97_regs[func][addr] = (dev->ac97_regs[func][addr] & 0x0c) | + (val & 0x03); + break; + case 0xc5: + if (func == 0) + dev->ac97_regs[func][addr] = (dev->ac97_regs[func][addr] & 0x60) | + (val & 0x9f); break; default: - dev->ac97_regs[func][addr] = val; break; } } @@ -1593,6 +1666,9 @@ pipc_reset(void *priv) pipc_write(pm_func, 0x48, 0x01, priv); pipc_write(pm_func, 0x49, 0x00, priv); + dev->power_regs[0x42] = ((dev->local >> 16) == VIA_PIPC_586) ? 0x00 : 0x50; + acpi_set_irq_line(dev->acpi, 0x00); + pipc_write(1, 0x04, 0x80, priv); pipc_write(1, 0x09, 0x85, priv); pipc_write(1, 0x10, 0xf1, priv); @@ -1627,8 +1703,7 @@ pipc_reset(void *priv) static void * pipc_init(const device_t *info) { - pipc_t *dev = (pipc_t *) malloc(sizeof(pipc_t)); - memset(dev, 0, sizeof(pipc_t)); + pipc_t *dev = (pipc_t *) calloc(1, sizeof(pipc_t)); pipc_log("PIPC: init()\n"); @@ -1695,6 +1770,8 @@ pipc_init(const device_t *info) acpi_set_nvr(dev->acpi, dev->nvr); acpi_init_gporeg(dev->acpi, 0xff, 0xbf, 0xff, 0x7f); + + acpi_set_irq_mode(dev->acpi, 0); } return dev; @@ -1721,7 +1798,7 @@ const device_t via_vt82c586b_device = { .init = pipc_init, .close = pipc_close, .reset = pipc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1735,7 +1812,7 @@ const device_t via_vt82c596a_device = { .init = pipc_init, .close = pipc_close, .reset = pipc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1749,7 +1826,7 @@ const device_t via_vt82c596b_device = { .init = pipc_init, .close = pipc_close, .reset = pipc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1763,7 +1840,7 @@ const device_t via_vt82c686a_device = { .init = pipc_init, .close = pipc_close, .reset = pipc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1777,7 +1854,7 @@ const device_t via_vt82c686b_device = { .init = pipc_init, .close = pipc_close, .reset = pipc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1791,7 +1868,7 @@ const device_t via_vt8231_device = { .init = pipc_init, .close = pipc_close, .reset = pipc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/via_vt82c49x.c b/src/chipset/via_vt82c49x.c index de55f7060..f8a5bb593 100644 --- a/src/chipset/via_vt82c49x.c +++ b/src/chipset/via_vt82c49x.c @@ -275,8 +275,8 @@ vt82c49x_write(uint16_t addr, uint8_t val, void *priv) case 0x71: if (dev->has_ide) { ide_pri_disable(); - ide_set_base(0, (val & 0x40) ? 0x170 : 0x1f0); - ide_set_side(0, (val & 0x40) ? 0x376 : 0x3f6); + ide_set_base(0, (val & 0x40) ? HDC_SECONDARY_BASE : HDC_PRIMARY_BASE); + ide_set_side(0, (val & 0x40) ? HDC_SECONDARY_SIDE : HDC_PRIMARY_SIDE); if (val & 0x01) ide_pri_enable(); vt82c49x_log("VT82C496 IDE now %sabled as %sary\n", (val & 0x01) ? "en" : "dis", @@ -342,8 +342,7 @@ vt82c49x_close(void *priv) static void * vt82c49x_init(const device_t *info) { - vt82c49x_t *dev = (vt82c49x_t *) malloc(sizeof(vt82c49x_t)); - memset(dev, 0x00, sizeof(vt82c49x_t)); + vt82c49x_t *dev = (vt82c49x_t *) calloc(1, sizeof(vt82c49x_t)); dev->smram_smm = smram_add(); dev->smram_low = smram_add(); @@ -375,7 +374,7 @@ const device_t via_vt82c49x_device = { .init = vt82c49x_init, .close = vt82c49x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -389,7 +388,7 @@ const device_t via_vt82c49x_pci_device = { .init = vt82c49x_init, .close = vt82c49x_close, .reset = vt82c49x_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -403,7 +402,7 @@ const device_t via_vt82c49x_ide_device = { .init = vt82c49x_init, .close = vt82c49x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -417,7 +416,7 @@ const device_t via_vt82c49x_pci_ide_device = { .init = vt82c49x_init, .close = vt82c49x_close, .reset = vt82c49x_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/via_vt82c505.c b/src/chipset/via_vt82c505.c index 34efbead9..dbbb447c7 100644 --- a/src/chipset/via_vt82c505.c +++ b/src/chipset/via_vt82c505.c @@ -167,7 +167,7 @@ vt82c505_in(uint16_t addr, void *priv) static void vt82c505_reset(void *priv) { - vt82c505_t *dev = (vt82c505_t *) malloc(sizeof(vt82c505_t)); + vt82c505_t *dev = (vt82c505_t *) calloc(1, sizeof(vt82c505_t)); dev->pci_conf[0x04] = 0x07; dev->pci_conf[0x07] = 0x00; @@ -204,8 +204,7 @@ vt82c505_close(void *priv) static void * vt82c505_init(UNUSED(const device_t *info)) { - vt82c505_t *dev = (vt82c505_t *) malloc(sizeof(vt82c505_t)); - memset(dev, 0, sizeof(vt82c505_t)); + vt82c505_t *dev = (vt82c505_t *) calloc(1, sizeof(vt82c505_t)); pci_add_card(PCI_ADD_NORTHBRIDGE, vt82c505_read, vt82c505_write, dev, &dev->pci_slot); @@ -232,7 +231,7 @@ const device_t via_vt82c505_device = { .init = vt82c505_init, .close = vt82c505_close, .reset = vt82c505_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/vl82c480.c b/src/chipset/vl82c480.c index 00adcc2a4..acb3568af 100644 --- a/src/chipset/vl82c480.c +++ b/src/chipset/vl82c480.c @@ -24,14 +24,16 @@ #include <86box/timer.h> #include <86box/device.h> #include <86box/io.h> +#include <86box/machine.h> #include <86box/mem.h> #include <86box/nmi.h> #include <86box/port_92.h> #include <86box/chipset.h> typedef struct vl82c480_t { - uint8_t idx; - uint8_t regs[256]; + uint8_t idx; + uint8_t regs[256]; + uint32_t banks[4]; } vl82c480_t; static int @@ -59,7 +61,7 @@ vl82c480_shflags(uint8_t access) } static void -vl82c480_recalc(vl82c480_t *dev) +vl82c480_recalc_shadow(vl82c480_t *dev) { uint32_t base; uint8_t access; @@ -69,8 +71,8 @@ vl82c480_recalc(vl82c480_t *dev) 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; + base = 0x000a0000 + (i << 16) + (j << 13); + access = (dev->regs[0x0d + i] >> j) & 3; mem_set_mem_state(base, 0x4000, vl82c480_shflags(access)); shadowbios |= ((base >= 0xe0000) && (access & 0x02)); shadowbios_write |= ((base >= 0xe0000) && (access & 0x01)); @@ -80,6 +82,37 @@ vl82c480_recalc(vl82c480_t *dev) flushmmucache(); } +static void +vl82c480_recalc_banks(vl82c480_t *dev) +{ + uint32_t sizes[8] = { 0, 0, 1024, 2048, 4096, 8192, 16384, 32768 }; + uint8_t shifts[4] = { 0, 4, 0, 4 }; + uint8_t regs[4] = { 0x02, 0x02, 0x03, 0x03 }; + uint32_t total = 0; + + for (uint8_t i = 0; i < 4; i++) { + uint8_t shift = shifts[i]; + uint8_t reg = regs[i]; + uint8_t cfg = (dev->regs[reg] >> shift) & 0x7; + uint32_t size = sizes[cfg]; + + total += MIN(dev->banks[i], size); + } + + if (total > 1024) { + mem_mapping_set_addr(&ram_low_mapping, 0x00000000, 0x000a0000); + mem_mapping_set_addr(&ram_high_mapping, 0x00100000, (total - 1024) << 10); + } else { + if (total >= 1024) + mem_mapping_set_addr(&ram_low_mapping, 0x00000000, 0x000a0000); + else + mem_mapping_disable(&ram_low_mapping); + mem_mapping_disable(&ram_high_mapping); + } + + flushmmucache(); +} + static void vl82c480_write(uint16_t addr, uint8_t val, void *priv) { @@ -91,11 +124,18 @@ vl82c480_write(uint16_t addr, uint8_t val, void *priv) break; case 0xed: - if (dev->idx >= 0x01 && dev->idx <= 0x24) { + if (((dev->idx >= 0x01) && (dev->idx <= 0x19)) || + ((dev->idx >= 0x20) && (dev->idx <= 0x24))) { switch (dev->idx) { default: dev->regs[dev->idx] = val; break; + case 0x02: case 0x03: + dev->regs[dev->idx] = val; + if (!strcmp(machine_get_internal_name(), "martin") || + !strcmp(machine_get_internal_name(), "prolineamt")) + vl82c480_recalc_banks(dev); + break; case 0x04: if (dev->regs[0x00] == 0x98) dev->regs[dev->idx] = (dev->regs[dev->idx] & 0x08) | (val & 0xf7); @@ -108,14 +148,9 @@ vl82c480_write(uint16_t addr, uint8_t val, void *priv) case 0x07: dev->regs[dev->idx] = (dev->regs[dev->idx] & 0x40) | (val & 0xbf); break; - case 0x0d: - case 0x0e: - case 0x0f: - case 0x10: - case 0x11: - case 0x12: + case 0x0d ... 0x12: dev->regs[dev->idx] = val; - vl82c480_recalc(dev); + vl82c480_recalc_shadow(dev); break; } } @@ -124,8 +159,8 @@ vl82c480_write(uint16_t addr, uint8_t val, void *priv) /* TODO: This is actually Fast A20 disable. */ #if 0 case 0xee: - if (mem_a20_alt) - outb(0x92, inb(0x92) & ~2); + mem_a20_alt = 0x00; + mem_a20_recalc(); break; #endif @@ -146,14 +181,16 @@ vl82c480_read(uint16_t addr, void *priv) break; case 0xed: - ret = dev->regs[dev->idx]; + if (((dev->idx >= 0x01) && (dev->idx <= 0x19)) || + ((dev->idx >= 0x20) && (dev->idx <= 0x24))) + 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); + mem_a20_alt = 0x02; + mem_a20_recalc(); break; #endif @@ -180,8 +217,12 @@ vl82c480_close(void *priv) static void * vl82c480_init(const device_t *info) { - vl82c480_t *dev = (vl82c480_t *) malloc(sizeof(vl82c480_t)); - memset(dev, 0, sizeof(vl82c480_t)); + vl82c480_t *dev = (vl82c480_t *) calloc(1, sizeof(vl82c480_t)); + uint32_t sizes[8] = { 0, 0, 1024, 2048, 4096, 8192, 16384, 32768 }; + uint32_t ms = mem_size; + uint8_t min_i = !strcmp(machine_get_internal_name(), "prolineamt") ? 1 : 0; + uint8_t min_j = !strcmp(machine_get_internal_name(), "prolineamt") ? 4 : 2; + uint8_t max_j = !strcmp(machine_get_internal_name(), "prolineamt") ? 8 : 7; dev->regs[0x00] = info->local; dev->regs[0x01] = 0xff; @@ -192,9 +233,31 @@ vl82c480_init(const device_t *info) dev->regs[0x07] = 0x21; dev->regs[0x08] = 0x38; + if (!strcmp(machine_get_internal_name(), "prolineamt")) { + dev->banks[0] = 4096; + + /* Bank 0 is ignored if 64 MB is installed. */ + if (ms != 65536) + ms -= 4096; + } + + if (ms > 0) for (uint8_t i = min_i; i < 4; i++) { + for (uint8_t j = min_j; j < max_j; j++) { + if (ms >= sizes[j]) + dev->banks[i] = sizes[j]; + else + break; + } + + ms -= dev->banks[i]; + + if ((ms == 0) || (dev->banks[i] == 0)) + break; + } + io_sethandler(0x00ec, 0x0004, vl82c480_read, NULL, NULL, vl82c480_write, NULL, NULL, dev); - device_add(&port_92_device); + device_add(&port_92_pci_device); return dev; } @@ -207,7 +270,7 @@ const device_t vl82c480_device = { .init = vl82c480_init, .close = vl82c480_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -221,7 +284,7 @@ const device_t vl82c486_device = { .init = vl82c480_init, .close = vl82c480_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/chipset/wd76c10.c b/src/chipset/wd76c10.c index df8558b05..48bb56483 100644 --- a/src/chipset/wd76c10.c +++ b/src/chipset/wd76c10.c @@ -37,6 +37,7 @@ #include <86box/port_92.h> #include <86box/serial.h> #include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> #include <86box/chipset.h> /* Lock/Unlock Procedures */ @@ -64,9 +65,10 @@ wd76c10_log(const char *fmt, ...) #endif typedef struct { - uint32_t enable; + uint32_t phys_on, enable; uint32_t virt_addr, phys_addr; uint32_t virt_size, phys_size; + uint32_t adj_virt_addr, adj_virt_size; } ram_bank_t; typedef struct { @@ -102,6 +104,7 @@ typedef struct int locked; uint32_t mem_top, hmwp_base; + uint32_t fast; ram_bank_t ram_banks[5]; @@ -120,6 +123,40 @@ static uint32_t bank_sizes[4] = { 0x00020000, /* 64 Kbit X 16 = 1024 Kbit 0x00200000, /* 1 Mbit X 16 = 16 Mbit = 2 MB, 10x10 */ 0x00800000 }; /* 4 Mbit X 16 = 64 Mbit = 8 MB, 11x11 */ +static uint32_t +wd76c10_calc_phys(uint32_t row, uint32_t col, uint32_t size, uint32_t a0) +{ + uint32_t ret = WD76C10_ADDR_INVALID; + + switch (size) { + default: + ret = WD76C10_ADDR_INVALID; + break; + case 0x00020000: + row = (row & 0x0000ff) << 9; + col = (col & 0x0000ff) << 1; + ret = row | col | a0; + break; + case 0x00080000: + row = (row & 0x0001ff) << 10; + col = (col & 0x0001ff) << 1; + ret = row | col | a0; + break; + case 0x00200000: + row = (row & 0x0003ff) << 11; + col = (col & 0x0003ff) << 1; + ret = row | col | a0; + break; + case 0x00800000: + row = (row & 0x0007ff) << 12; + col = (col & 0x0007ff) << 1; + ret = row | col | a0; + break; + } + + return ret; +} + static uint32_t wd76c10_calc_addr(wd76c10_t *dev, uint32_t addr) { @@ -158,20 +195,303 @@ wd76c10_calc_addr(wd76c10_t *dev, uint32_t addr) ret = WD76C10_ADDR_INVALID; /* Then, handle the physical memory banks. */ + int ilv4 = (dev->mem_ctl >> 8) & 4; + int8_t add = 0; + uint32_t pg = (dev->mem_ctl & 0x0800); + uint32_t nrt = WD76C10_ADDR_INVALID; + + if (ret != WD76C10_ADDR_INVALID) { + if (dev->fast) for (int8_t i = 0; i < 4; i++) { + rb = &(dev->ram_banks[i]); + + uint32_t ret2 = ret - rb->phys_addr; + + if (rb->phys_on && (ret >= rb->phys_addr) && + (ret < (rb->phys_addr + rb->phys_size))) { + if (ret2 < rb->phys_size) + nrt = ret2 + rb->phys_addr; + break; + } + } else for (int8_t i = 0; i < 4; i++) { + rb = &(dev->ram_banks[i]); + + int ilv2 = (dev->mem_ctl >> 8) & (1 << (i >> 1)); + uint32_t size = rb->virt_size; + uint32_t ret2 = ret - rb->virt_addr; + uint32_t ret4 = ret2; + uint32_t row = WD76C10_ADDR_INVALID; + uint32_t col = WD76C10_ADDR_INVALID; + uint32_t rb_or = 0; + + if (ilv4) { + size <<= 2; + switch (rb->virt_size) { + default: + ret4 = WD76C10_ADDR_INVALID; + break; + case 0x00020000: + if (pg) { + row = (ret2 >> 9) & 0x0000fc; + row |= (ret2 >> 17) & 0x000001; + row |= ((ret2 >> 19) & 0x000001) << 1; + row |= ((ret2 >> 18) & 0x000001) << 8; + row |= ((ret2 >> 20) & 0x000001) << 9; + row |= ((ret2 >> 22) & 0x000001) << 10; + col = (ret2 >> 1) & 0x000007ff; + rb_or = (ret2 >> 9) & 0x000003; + } else + ret4 = WD76C10_ADDR_INVALID; + break; + case 0x00080000: + if (pg) { + row = (ret2 >> 9) & 0x0000f8; + row |= (ret2 >> 17) & 0x000001; + row |= ((ret2 >> 19) & 0x000001) << 1; + row |= ((ret2 >> 21) & 0x000001) << 2; + row |= ((ret2 >> 18) & 0x000001) << 8; + row |= ((ret2 >> 20) & 0x000001) << 9; + row |= ((ret2 >> 22) & 0x000001) << 10; + col = (ret2 >> 1) & 0x000007ff; + rb_or = (ret2 >> 10) & 0x000003; + } else + ret4 = WD76C10_ADDR_INVALID; + break; + case 0x00200000: + if (pg) { + row = (ret2 >> 9) & 0x0000f0; + row |= (ret2 >> 17) & 0x000001; + row |= ((ret2 >> 19) & 0x000001) << 1; + row |= ((ret2 >> 21) & 0x000001) << 2; + row |= ((ret2 >> 23) & 0x000001) << 3; + row |= ((ret2 >> 18) & 0x000001) << 8; + row |= ((ret2 >> 20) & 0x000001) << 9; + row |= ((ret2 >> 22) & 0x000001) << 10; + col = (ret2 >> 1) & 0x000007ff; + rb_or = (ret2 >> 11) & 0x000003; + } else + ret4 = WD76C10_ADDR_INVALID; + break; + case 0x00800000: + if (pg) { + row = (ret2 >> 9) & 0x0000e0; + row |= (ret2 >> 17) & 0x000001; + row |= ((ret2 >> 19) & 0x000001) << 1; + row |= ((ret2 >> 21) & 0x000001) << 2; + row |= ((ret2 >> 23) & 0x000001) << 3; + row |= ((ret2 >> 24) & 0x000001) << 4; + row |= ((ret2 >> 18) & 0x000001) << 8; + row |= ((ret2 >> 20) & 0x000001) << 9; + row |= ((ret2 >> 22) & 0x000001) << 10; + col = (ret2 >> 1) & 0x000007ff; + rb_or = (ret2 >> 12) & 0x000003; + } else + ret4 = WD76C10_ADDR_INVALID; + break; + } + add = 3; + } else if (ilv2) { + size <<= 1; + switch (rb->virt_size) { + default: + ret4 = WD76C10_ADDR_INVALID; + break; + case 0x00020000: + if (pg) { + row = (ret2 >> 9) & 0x0000fe; + row |= (ret2 >> 17) & 0x000001; + row |= ((ret2 >> 18) & 0x000001) << 8; + row |= ((ret2 >> 20) & 0x000001) << 9; + row |= ((ret2 >> 22) & 0x000001) << 10; + col = (ret2 >> 1) & 0x000007ff; + rb_or = (ret2 >> 9) & 0x000001; + } else { + row = (ret2 >> 1) & 0x0007fe; + row |= (ret2 >> 13) & 0x000001; + col = (ret2 >> 9) & 0x0000ef; + col |= ((ret2 >> 17) & 0x000001) << 4; + col |= ((ret2 >> 18) & 0x000001) << 8; + col |= ((ret2 >> 20) & 0x000001) << 9; + col |= ((ret2 >> 22) & 0x000001) << 10; + rb_or = (ret2 >> 1) & 0x000001; + } + break; + case 0x00080000: + if (pg) { + row = (ret2 >> 9) & 0x0000fc; + row |= (ret2 >> 17) & 0x000001; + row |= ((ret2 >> 19) & 0x000001) << 1; + row |= ((ret2 >> 18) & 0x000001) << 8; + row |= ((ret2 >> 20) & 0x000001) << 9; + row |= ((ret2 >> 22) & 0x000001) << 10; + col = (ret2 >> 1) & 0x000007ff; + rb_or = (ret2 >> 10) & 0x000001; + } else { + row = (ret2 >> 1) & 0x0007fe; + row |= (ret2 >> 13) & 0x000001; + col = (ret2 >> 9) & 0x0000ee; + col |= (ret2 >> 17) & 0x000001; + col |= ((ret2 >> 19) & 0x000001) << 4; + col |= ((ret2 >> 18) & 0x000001) << 8; + col |= ((ret2 >> 20) & 0x000001) << 9; + col |= ((ret2 >> 22) & 0x000001) << 10; + rb_or = (ret2 >> 1) & 0x000001; + } + break; + case 0x00200000: + if (pg) { + row = (ret2 >> 9) & 0x0000f8; + row |= (ret2 >> 17) & 0x000001; + row |= ((ret2 >> 19) & 0x000001) << 1; + row |= ((ret2 >> 21) & 0x000001) << 2; + row |= ((ret2 >> 18) & 0x000001) << 8; + row |= ((ret2 >> 20) & 0x000001) << 9; + row |= ((ret2 >> 22) & 0x000001) << 10; + col = (ret2 >> 1) & 0x000007ff; + rb_or = (ret2 >> 11) & 0x000001; + } else { + row = (ret2 >> 1) & 0x0007fe; + row |= (ret2 >> 13) & 0x000001; + col = (ret2 >> 9) & 0x0000ec; + col |= (ret2 >> 17) & 0x000001; + col |= ((ret2 >> 19) & 0x000001) << 1; + col |= ((ret2 >> 21) & 0x000001) << 4; + col |= ((ret2 >> 18) & 0x000001) << 8; + col |= ((ret2 >> 20) & 0x000001) << 9; + col |= ((ret2 >> 22) & 0x000001) << 10; + rb_or = (ret2 >> 1) & 0x000001; + } + break; + case 0x00800000: + if (pg) { + row = (ret2 >> 9) & 0x0000f0; + row |= (ret2 >> 17) & 0x000001; + row |= ((ret2 >> 19) & 0x000001) << 1; + row |= ((ret2 >> 21) & 0x000001) << 2; + row |= ((ret2 >> 23) & 0x000001) << 3; + row |= ((ret2 >> 18) & 0x000001) << 8; + row |= ((ret2 >> 20) & 0x000001) << 9; + row |= ((ret2 >> 22) & 0x000001) << 10; + col = (ret2 >> 1) & 0x000007ff; + rb_or = (ret2 >> 12) & 0x000001; + } else { + row = (ret2 >> 1) & 0x0007fe; + row |= (ret2 >> 13) & 0x000001; + col = (ret2 >> 9) & 0x0000e0; + col |= (ret2 >> 17) & 0x000001; + col |= ((ret2 >> 19) & 0x000001) << 1; + col |= ((ret2 >> 21) & 0x000001) << 2; + col |= ((ret2 >> 23) & 0x000001) << 3; + col |= ((ret2 >> 12) & 0x000001) << 4; + col |= ((ret2 >> 18) & 0x000001) << 8; + col |= ((ret2 >> 20) & 0x000001) << 9; + col |= ((ret2 >> 22) & 0x000001) << 10; + rb_or = (ret2 >> 1) & 0x000001; + } + break; + } + add = 1; + } else if (pg) switch (rb->virt_size) { + default: + ret4 = WD76C10_ADDR_INVALID; + break; + case 0x00020000: + row = (ret2 >> 9) & 0x0000ff; + row |= ((ret2 >> 18) & 0x000001) << 8; + row |= ((ret2 >> 20) & 0x000001) << 9; + row |= ((ret2 >> 22) & 0x000001) << 10; + col = (ret2 >> 1) & 0x0007ff; + break; + case 0x00080000: + row = (ret2 >> 9) & 0x0000fe; + row |= (ret2 >> 17) & 0x000001; + row |= ((ret2 >> 18) & 0x000001) << 8; + row |= ((ret2 >> 20) & 0x000001) << 9; + row |= ((ret2 >> 22) & 0x000001) << 10; + col = (ret2 >> 1) & 0x0007ff; + break; + case 0x00200000: + row = (ret2 >> 9) & 0x0000fc; + row |= (ret2 >> 17) & 0x000001; + row |= ((ret2 >> 19) & 0x000001) << 1; + row |= ((ret2 >> 18) & 0x000001) << 8; + row |= ((ret2 >> 20) & 0x000001) << 9; + row |= ((ret2 >> 22) & 0x000001) << 10; + col = (ret2 >> 1) & 0x0007ff; + break; + case 0x00800000: + row = (ret2 >> 9) & 0x0000f8; + row |= (ret2 >> 17) & 0x000001; + row |= ((ret2 >> 19) & 0x000001) << 1; + row |= ((ret2 >> 21) & 0x000001) << 2; + row |= ((ret2 >> 18) & 0x000001) << 8; + row |= ((ret2 >> 20) & 0x000001) << 9; + row |= ((ret2 >> 22) & 0x000001) << 10; + col = (ret2 >> 1) & 0x0007ff; + break; + } else switch (rb->virt_size) { + default: + ret4 = WD76C10_ADDR_INVALID; + break; + case 0x00020000: + row = (ret2 >> 1) & 0x0007ff; + col = (ret2 >> 9) & 0x0000ff; + col |= ((ret2 >> 18) & 0x000001) << 8; + col |= ((ret2 >> 20) & 0x000001) << 9; + col |= ((ret2 >> 22) & 0x000001) << 10; + break; + case 0x00080000: + row = (ret2 >> 1) & 0x0007ff; + col = (ret2 >> 9) & 0x0000fe; + col |= (ret2 >> 17) & 0x000001; + col |= ((ret2 >> 18) & 0x000001) << 8; + col |= ((ret2 >> 20) & 0x000001) << 9; + col |= ((ret2 >> 22) & 0x000001) << 10; + break; + case 0x00200000: + row = (ret2 >> 1) & 0x0007ff; + col = (ret2 >> 9) & 0x0000fc; + col |= (ret2 >> 17) & 0x000001; + col |= ((ret2 >> 19) & 0x000001) << 1; + col |= ((ret2 >> 18) & 0x000001) << 8; + col |= ((ret2 >> 20) & 0x000001) << 9; + col |= ((ret2 >> 22) & 0x000001) << 10; + break; + case 0x00800000: + row = (ret2 >> 1) & 0x0007ff; + col = (ret2 >> 9) & 0x0000f8; + col |= (ret2 >> 17) & 0x000001; + col |= ((ret2 >> 19) & 0x000001) << 1; + col |= ((ret2 >> 21) & 0x000001) << 2; + col |= ((ret2 >> 18) & 0x000001) << 8; + col |= ((ret2 >> 20) & 0x000001) << 9; + col |= ((ret2 >> 22) & 0x000001) << 10; + break; + } + + if (row != WD76C10_ADDR_INVALID) { + ret4 = wd76c10_calc_phys(row & 0x0007ff, col & 0x0007ff, + rb->phys_size, ret2 & 0x000001); + + if (ilv4 || ilv2) + rb = &(dev->ram_banks[i | rb_or]); + + i += add; + } + + if (rb->enable && (ret >= rb->virt_addr) && + (ret < (rb->virt_addr + size))) { + if ((ret4 != WD76C10_ADDR_INVALID) && (rb->phys_size > 0x00000000)) + nrt = ret4 + rb->phys_addr; + break; + } + } + + ret = nrt; + } + if (ret >= (mem_size << 10)) /* The physical memory address is too high or disabled, which is invalid. */ ret = WD76C10_ADDR_INVALID; - /* Otherwise, map it to the correct bank so the BIOS can auto-size it correctly. */ - else for (uint8_t i = 0; i < 4; i++) { - rb = &(dev->ram_banks[i]); - if (rb->enable && (ret >= rb->virt_addr) && (ret < (rb->virt_addr + rb->virt_size))) { - if (rb->phys_size == 0x00000000) - ret = WD76C10_ADDR_INVALID; - else - ret = ((ret - rb->virt_addr) % rb->phys_size) + rb->phys_addr; - break; - } - } return ret; } @@ -184,8 +504,12 @@ wd76c10_read_ram(uint32_t addr, void *priv) addr = wd76c10_calc_addr(dev, addr); - if (addr != WD76C10_ADDR_INVALID) - ret = mem_read_ram(addr, priv); + if (addr != WD76C10_ADDR_INVALID) { + if (dev->fast) + ret = mem_read_ram(addr, priv); + else + ret = ram[addr]; + } return ret; } @@ -198,8 +522,12 @@ wd76c10_read_ramw(uint32_t addr, void *priv) addr = wd76c10_calc_addr(dev, addr); - if (addr != WD76C10_ADDR_INVALID) - ret = mem_read_ramw(addr, priv); + if (addr != WD76C10_ADDR_INVALID) { + if (dev->fast) + ret = mem_read_ramw(addr, priv); + else + ret = *(uint16_t *) &(ram[addr]); + } return ret; } @@ -211,8 +539,12 @@ wd76c10_write_ram(uint32_t addr, uint8_t val, void *priv) addr = wd76c10_calc_addr(dev, addr); - if (addr != WD76C10_ADDR_INVALID) - mem_write_ram(addr, val, priv); + if (addr != WD76C10_ADDR_INVALID) { + if (dev->fast) + mem_write_ram(addr, val, priv); + else + ram[addr] = val; + } } static void @@ -222,8 +554,12 @@ wd76c10_write_ramw(uint32_t addr, uint16_t val, void *priv) addr = wd76c10_calc_addr(dev, addr); - if (addr != WD76C10_ADDR_INVALID) - mem_write_ramw(addr, val, priv); + if (addr != WD76C10_ADDR_INVALID) { + if (dev->fast) + mem_write_ramw(addr, val, priv); + else + *(uint16_t *) &(ram[addr]) = val; + } } static void @@ -257,6 +593,9 @@ wd76c10_recalc_exec(wd76c10_t *dev, uint32_t base, uint32_t size) static void wd76c10_banks_recalc(wd76c10_t *dev) { + int match = 0; + dev->fast = 0; + for (uint8_t i = 0; i < 4; i++) { ram_bank_t *rb = &(dev->ram_banks[i]); uint8_t bit = i << 1; @@ -265,8 +604,42 @@ wd76c10_banks_recalc(wd76c10_t *dev) rb->enable = (dev->split_sa >> bit) & 0x01; rb->virt_addr = ((uint32_t) dev->bank_bases[i]) << 17; + if (rb->enable) { + rb->adj_virt_addr = rb->virt_addr; + rb->adj_virt_size = rb->virt_size; + + if (dev->mem_ctl & 0x0400) + rb->adj_virt_addr += (i * rb->adj_virt_size); + else if ((dev->mem_ctl >> 8) & (1 << (i >> 1))) + rb->adj_virt_addr += ((i & 1) * rb->adj_virt_size); + } else { + rb->adj_virt_addr = WD76C10_ADDR_INVALID; + rb->adj_virt_size = 0x00000000; + } + + if ((rb->enable == rb->phys_on) && + (rb->adj_virt_addr == rb->phys_addr) && + (rb->adj_virt_size == rb->phys_size)) + match++; + } + + dev->fast = (match == 4); + + for (uint8_t i = 0; i < 4; i++) { + ram_bank_t *rb = &(dev->ram_banks[i]); + if (cpu_use_exec) wd76c10_recalc_exec(dev, rb->virt_addr, rb->virt_size); + + wd76c10_log("Bank %i (%s), physical: %i, %08X-%08X, " + "virtual: %i, %08X-%08X, adj.: %i, %08X-%08X\n", + i, dev->fast ? "FAST" : "SLOW", + rb->phys_on, + rb->phys_addr, rb->phys_addr + rb->phys_size - 1, + rb->enable, + rb->virt_addr, rb->virt_addr + rb->virt_size - 1, + rb->enable, + rb->adj_virt_addr, rb->adj_virt_addr + rb->adj_virt_size - 1); } } @@ -541,16 +914,16 @@ wd76c10_ser_par_cs_recalc(wd76c10_t *dev) lpt1_remove(); switch ((dev->ser_par_cs >> 9) & 0x03) { case 1: - lpt1_init(0x3bc); - lpt1_irq(7); + lpt1_setup(LPT_MDA_ADDR); + lpt1_irq(LPT1_IRQ); break; case 2: - lpt1_init(0x378); - lpt1_irq(7); + lpt1_setup(LPT1_ADDR); + lpt1_irq(LPT1_IRQ); break; case 3: - lpt1_init(0x278); - lpt1_irq(7); + lpt1_setup(LPT2_ADDR); + lpt1_irq(LPT1_IRQ); break; } } @@ -879,12 +1252,12 @@ wd76c10_reset(void *priv) static void * -wd76c10_init(const device_t *info) +wd76c10_init(UNUSED(const device_t *info)) { wd76c10_t *dev = (wd76c10_t *) calloc(1, sizeof(wd76c10_t)); uint32_t total_mem = mem_size << 10; uint32_t accum_mem = 0x00000000; - ram_bank_t *rb; + ram_bank_t *rb = NULL; /* Calculate the physical RAM banks. */ for (uint8_t i = 0; i < 4; i++) { @@ -898,11 +1271,22 @@ wd76c10_init(const device_t *info) } } if (size != 0x00000000) { + rb->phys_on = 1; rb->phys_addr = accum_mem; rb->phys_size = size; + wd76c10_log("Bank %i size: %5i KiB, starting at %5i KiB\n", i, rb->phys_size >> 10, rb->phys_addr >> 10); total_mem -= size; accum_mem += size; - } + } else + rb->phys_addr = WD76C10_ADDR_INVALID; + } + + if (mem_size == 3072) { + /* Reorganize the banks a bit so, we have 2048, 0, 512, 512. */ + ram_bank_t rt = dev->ram_banks[3]; + dev->ram_banks[3] = dev->ram_banks[2]; + dev->ram_banks[2] = dev->ram_banks[1]; + dev->ram_banks[1] = rt; } rb = &(dev->ram_banks[4]); @@ -1022,7 +1406,7 @@ const device_t wd76c10_device = { .init = wd76c10_init, .close = wd76c10_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/codegen/codegen_ops_arith.h b/src/codegen/codegen_ops_arith.h index 28ee6d06c..50ef4310f 100644 --- a/src/codegen/codegen_ops_arith.h +++ b/src/codegen/codegen_ops_arith.h @@ -1,5 +1,5 @@ static uint32_t -ropINC_rw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropINC_rw(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; @@ -22,7 +22,7 @@ ropINC_rw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return op_pc; } static uint32_t -ropINC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropINC_rl(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; @@ -45,7 +45,7 @@ ropINC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return op_pc; } static uint32_t -ropDEC_rw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropDEC_rw(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; @@ -68,7 +68,7 @@ ropDEC_rw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return op_pc; } static uint32_t -ropDEC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropDEC_rl(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; @@ -93,7 +93,7 @@ ropDEC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod #define ROP_ARITH_RMW(name, op, writeback) \ static uint32_t \ - rop##name##_b_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ + rop##name##_b_rmw(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) \ { \ int src_reg; \ int dst_reg; \ @@ -129,7 +129,7 @@ ropDEC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return op_pc + 1; \ } \ static uint32_t \ - rop##name##_w_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ + rop##name##_w_rmw(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) \ { \ int src_reg; \ int dst_reg; \ @@ -165,7 +165,7 @@ ropDEC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return op_pc + 1; \ } \ static uint32_t \ - rop##name##_l_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ + rop##name##_l_rmw(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) \ { \ int src_reg; \ int dst_reg; \ @@ -203,7 +203,7 @@ ropDEC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod #define ROP_ARITH_RM(name, op, writeback) \ static uint32_t \ - rop##name##_b_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ + rop##name##_b_rm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) \ { \ int src_reg; \ int dst_reg; \ @@ -233,7 +233,7 @@ ropDEC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return op_pc + 1; \ } \ static uint32_t \ - rop##name##_w_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ + rop##name##_w_rm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) \ { \ int src_reg; \ int dst_reg; \ @@ -263,7 +263,7 @@ ropDEC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return op_pc + 1; \ } \ static uint32_t \ - rop##name##_l_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ + rop##name##_l_rm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) \ { \ int src_reg; \ int dst_reg; \ @@ -299,7 +299,7 @@ ROP_ARITH_RM(ADD, ADD, 1) 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) +ropCMP_b_rm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int src_reg; int dst_reg; @@ -326,7 +326,7 @@ ropCMP_b_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, c return op_pc + 1; } static uint32_t -ropCMP_w_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropCMP_w_rm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int src_reg; int dst_reg; @@ -353,7 +353,7 @@ ropCMP_w_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, c return op_pc + 1; } static uint32_t -ropCMP_l_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropCMP_l_rm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int src_reg; int dst_reg; @@ -381,7 +381,7 @@ 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) +ropCMP_b_rmw(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int src_reg; int dst_reg; @@ -408,7 +408,7 @@ ropCMP_b_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropCMP_w_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropCMP_w_rmw(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int src_reg; int dst_reg; @@ -435,7 +435,7 @@ ropCMP_w_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropCMP_l_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropCMP_l_rmw(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int src_reg; int dst_reg; @@ -463,7 +463,7 @@ ropCMP_l_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } static uint32_t -ropADD_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropADD_AL_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_B(REG_AL); @@ -478,7 +478,7 @@ ropADD_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropADD_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropADD_AX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_W(REG_AX); @@ -493,7 +493,7 @@ ropADD_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 2; } static uint32_t -ropADD_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropADD_EAX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_L(REG_EAX); @@ -510,7 +510,7 @@ ropADD_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc } static uint32_t -ropCMP_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropCMP_AL_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_B(REG_AL); @@ -525,7 +525,7 @@ ropCMP_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropCMP_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropCMP_AX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_W(REG_AX); @@ -540,7 +540,7 @@ ropCMP_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 2; } static uint32_t -ropCMP_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropCMP_EAX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_L(REG_EAX); @@ -557,7 +557,7 @@ ropCMP_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc } static uint32_t -ropSUB_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropSUB_AL_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_B(REG_AL); @@ -572,7 +572,7 @@ ropSUB_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropSUB_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropSUB_AX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_W(REG_AX); @@ -587,7 +587,7 @@ ropSUB_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 2; } static uint32_t -ropSUB_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropSUB_EAX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_L(REG_EAX); @@ -604,7 +604,7 @@ ropSUB_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc } static uint32_t -rop80(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +rop80(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; uint32_t imm; @@ -679,7 +679,7 @@ rop80(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblo } static uint32_t -rop81_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +rop81_w(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; uint32_t imm; @@ -753,7 +753,7 @@ rop81_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb return op_pc + 3; } static uint32_t -rop81_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +rop81_l(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; uint32_t imm; @@ -827,7 +827,7 @@ rop81_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb } static uint32_t -rop83_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +rop83_w(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; uint32_t imm; @@ -904,7 +904,7 @@ rop83_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb return op_pc + 2; } static uint32_t -rop83_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +rop83_l(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; uint32_t imm; diff --git a/src/codegen/codegen_ops_fpu.h b/src/codegen/codegen_ops_fpu.h index 242743dee..a82b10d82 100644 --- a/src/codegen/codegen_ops_fpu.h +++ b/src/codegen/codegen_ops_fpu.h @@ -1,5 +1,5 @@ static uint32_t -ropFXCH(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFXCH(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); @@ -9,7 +9,7 @@ ropFXCH(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb } static uint32_t -ropFLD(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFLD(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); @@ -19,7 +19,7 @@ ropFLD(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codebl } static uint32_t -ropFST(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFST(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); @@ -28,7 +28,7 @@ ropFST(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codebl return op_pc; } static uint32_t -ropFSTP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFSTP(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); @@ -39,7 +39,7 @@ ropFSTP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb } static uint32_t -ropFLDs(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFLDs(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; @@ -57,7 +57,7 @@ ropFLDs(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb return op_pc + 1; } static uint32_t -ropFLDd(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFLDd(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; @@ -76,7 +76,7 @@ ropFLDd(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb } static uint32_t -ropFILDw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFILDw(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; @@ -94,7 +94,7 @@ ropFILDw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc + 1; } static uint32_t -ropFILDl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFILDl(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; @@ -112,7 +112,7 @@ ropFILDl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc + 1; } static uint32_t -ropFILDq(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFILDq(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; @@ -133,7 +133,7 @@ ropFILDq(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code } static uint32_t -ropFSTs(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFSTs(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; int host_reg; @@ -153,7 +153,7 @@ ropFSTs(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb return op_pc + 1; } static uint32_t -ropFSTd(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFSTd(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; int host_reg1; @@ -194,24 +194,28 @@ ropFSTPd(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return new_pc; } -#define ropFarith(name, size, load, op) \ - static uint32_t \ - ropF##name##size(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ - { \ - x86seg *target_seg; \ - \ - FP_ENTER(); \ - op_pc--; \ - target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \ - \ - STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ - \ - CHECK_SEG_READ(target_seg); \ - load(target_seg); \ - \ - op(FPU_##name); \ - \ - return op_pc + 1; \ +#define ropFarith(name, size, load, op) \ + static uint32_t \ + ropF##name##size(UNUSED(uint8_t opcode), \ + uint32_t fetchdat, \ + uint32_t op_32, \ + uint32_t op_pc, \ + UNUSED(codeblock_t *block)) \ + { \ + x86seg *target_seg; \ + \ + FP_ENTER(); \ + op_pc--; \ + target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \ + \ + STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ + \ + CHECK_SEG_READ(target_seg); \ + load(target_seg); \ + \ + op(FPU_##name); \ + \ + return op_pc + 1; \ } ropFarith(ADD, s, MEM_LOAD_ADDR_EA_L, FP_OP_S); @@ -239,32 +243,40 @@ ropFarith(MUL, il, MEM_LOAD_ADDR_EA_L, FP_OP_IL); ropFarith(SUB, il, MEM_LOAD_ADDR_EA_L, FP_OP_IL); ropFarith(SUBR, il, MEM_LOAD_ADDR_EA_L, FP_OP_IL); -#define ropFcompare(name, size, load, op) \ - static uint32_t \ - ropF##name##size(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ - { \ - x86seg *target_seg; \ - \ - FP_ENTER(); \ - op_pc--; \ - target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \ - \ - STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ - \ - CHECK_SEG_READ(target_seg); \ - load(target_seg); \ - \ - op(); \ - \ - return op_pc + 1; \ - } \ - static uint32_t ropF##name##P##size(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ - { \ - uint32_t new_pc = ropF##name##size(opcode, fetchdat, op_32, op_pc, block); \ - \ - FP_POP(); \ - \ - return new_pc; \ +#define ropFcompare(name, size, load, op) \ + static uint32_t \ + ropF##name##size(UNUSED(uint8_t opcode), \ + uint32_t fetchdat, \ + uint32_t op_32, \ + uint32_t op_pc, \ + UNUSED(codeblock_t *block)) \ + { \ + x86seg *target_seg; \ + \ + FP_ENTER(); \ + op_pc--; \ + target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \ + \ + STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ + \ + CHECK_SEG_READ(target_seg); \ + load(target_seg); \ + \ + op(); \ + \ + return op_pc + 1; \ + } \ + static uint32_t ropF##name##P##size(uint8_t opcode, \ + uint32_t fetchdat, \ + uint32_t op_32, \ + uint32_t op_pc, \ + codeblock_t *block) \ + { \ + uint32_t new_pc = ropF##name##size(opcode, fetchdat, op_32, op_pc, block); \ + \ + FP_POP(); \ + \ + return new_pc; \ } ropFcompare(COM, s, MEM_LOAD_ADDR_EA_L, FP_COMPARE_S); @@ -348,7 +360,7 @@ ropFSUBs(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code #endif static uint32_t -ropFADD(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFADD(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_ADD, 0, opcode & 7); @@ -356,7 +368,7 @@ ropFADD(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb return op_pc; } static uint32_t -ropFCOM(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFCOM(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_COMPARE_REG(0, opcode & 7); @@ -364,7 +376,7 @@ ropFCOM(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb return op_pc; } static uint32_t -ropFDIV(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFDIV(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_DIV, 0, opcode & 7); @@ -372,7 +384,7 @@ ropFDIV(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb return op_pc; } static uint32_t -ropFDIVR(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFDIVR(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_DIVR, 0, opcode & 7); @@ -380,7 +392,7 @@ ropFDIVR(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc; } static uint32_t -ropFMUL(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFMUL(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_MUL, 0, opcode & 7); @@ -388,7 +400,7 @@ ropFMUL(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb return op_pc; } static uint32_t -ropFSUB(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFSUB(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_SUB, 0, opcode & 7); @@ -396,7 +408,7 @@ ropFSUB(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb return op_pc; } static uint32_t -ropFSUBR(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFSUBR(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_SUBR, 0, opcode & 7); @@ -405,7 +417,7 @@ ropFSUBR(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code } static uint32_t -ropFADDr(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFADDr(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_ADD, opcode & 7, 0); @@ -413,7 +425,7 @@ ropFADDr(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc; } static uint32_t -ropFDIVr(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFDIVr(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_DIV, opcode & 7, 0); @@ -421,7 +433,7 @@ ropFDIVr(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc; } static uint32_t -ropFDIVRr(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFDIVRr(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_DIVR, opcode & 7, 0); @@ -429,7 +441,7 @@ ropFDIVRr(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return op_pc; } static uint32_t -ropFMULr(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFMULr(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_MUL, opcode & 7, 0); @@ -437,7 +449,7 @@ ropFMULr(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc; } static uint32_t -ropFSUBr(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFSUBr(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_SUB, opcode & 7, 0); @@ -445,7 +457,7 @@ ropFSUBr(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc; } static uint32_t -ropFSUBRr(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFSUBRr(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_SUBR, opcode & 7, 0); @@ -454,7 +466,7 @@ ropFSUBRr(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod } static uint32_t -ropFADDP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFADDP(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_ADD, opcode & 7, 0); @@ -463,7 +475,7 @@ ropFADDP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc; } static uint32_t -ropFCOMP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFCOMP(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_COMPARE_REG(0, opcode & 7); @@ -472,7 +484,7 @@ ropFCOMP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc; } static uint32_t -ropFDIVP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFDIVP(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_DIV, opcode & 7, 0); @@ -481,7 +493,7 @@ ropFDIVP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc; } static uint32_t -ropFDIVRP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFDIVRP(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_DIVR, opcode & 7, 0); @@ -490,7 +502,7 @@ ropFDIVRP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return op_pc; } static uint32_t -ropFMULP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFMULP(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_MUL, opcode & 7, 0); @@ -499,7 +511,7 @@ ropFMULP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc; } static uint32_t -ropFSUBP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFSUBP(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_SUB, opcode & 7, 0); @@ -508,7 +520,7 @@ ropFSUBP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc; } static uint32_t -ropFSUBRP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFSUBRP(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_OP_REG(FPU_SUBR, opcode & 7, 0); @@ -518,7 +530,7 @@ ropFSUBRP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod } static uint32_t -ropFCOMPP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFCOMPP(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_COMPARE_REG(0, 1); @@ -528,7 +540,7 @@ ropFCOMPP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod } static uint32_t -ropFSTSW_AX(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFSTSW_AX(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; @@ -540,7 +552,7 @@ ropFSTSW_AX(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, c } static uint32_t -ropFISTw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFISTw(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; int host_reg; @@ -560,7 +572,7 @@ ropFISTw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc + 1; } static uint32_t -ropFISTl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFISTl(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; int host_reg; @@ -599,7 +611,7 @@ ropFISTPl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return new_pc; } static uint32_t -ropFISTPq(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFISTPq(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; int host_reg1; @@ -623,7 +635,7 @@ ropFISTPq(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod } static uint32_t -ropFLDCW(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFLDCW(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; @@ -640,7 +652,7 @@ ropFLDCW(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc + 1; } static uint32_t -ropFSTCW(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFSTCW(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; x86seg *target_seg; @@ -658,7 +670,7 @@ ropFSTCW(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code } static uint32_t -ropFCHS(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFCHS(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_FCHS(); @@ -666,17 +678,21 @@ ropFCHS(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb return op_pc; } -#define opFLDimm(name, v) \ - static uint32_t \ - ropFLD##name(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ - { \ - static double fp_imm = v; \ - static uint64_t *fptr = (uint64_t *) &fp_imm; \ - \ - FP_ENTER(); \ - FP_LOAD_IMM_Q(*fptr); \ - \ - return op_pc; \ +#define opFLDimm(name, v) \ + static uint32_t \ + ropFLD##name(UNUSED(uint8_t opcode), \ + UNUSED(uint32_t fetchdat), \ + UNUSED(uint32_t op_32), \ + uint32_t op_pc, \ + UNUSED(codeblock_t *block)) \ + { \ + static double fp_imm = v; \ + static uint64_t *fptr = (uint64_t *) &fp_imm; \ + \ + FP_ENTER(); \ + FP_LOAD_IMM_Q(*fptr); \ + \ + return op_pc; \ } // clang-format off @@ -689,7 +705,7 @@ opFLDimm(Z, 0.0) // clang-format on static uint32_t -ropFLDLN2(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) +ropFLDLN2(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { FP_ENTER(); FP_LOAD_IMM_Q(0x3fe62e42fefa39f0ULL); diff --git a/src/codegen/codegen_ops_jump.h b/src/codegen/codegen_ops_jump.h index da16ce03e..4572b623b 100644 --- a/src/codegen/codegen_ops_jump.h +++ b/src/codegen/codegen_ops_jump.h @@ -1,5 +1,5 @@ static uint32_t -ropJMP_r8(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropJMP_r8(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { uint32_t offset = fetchdat & 0xff; @@ -12,7 +12,7 @@ ropJMP_r8(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod } static uint32_t -ropJMP_r16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropJMP_r16(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { uint16_t offset = fetchdat & 0xffff; @@ -22,7 +22,7 @@ ropJMP_r16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, co } static uint32_t -ropJMP_r32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropJMP_r32(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { uint32_t offset = fastreadl(cs + op_pc); @@ -32,7 +32,7 @@ ropJMP_r32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, co } static uint32_t -ropJCXZ(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropJCXZ(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { uint32_t offset = fetchdat & 0xff; @@ -51,7 +51,7 @@ ropJCXZ(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb } static uint32_t -ropLOOP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropLOOP(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { uint32_t offset = fetchdat & 0xff; @@ -214,45 +214,51 @@ BRANCH_COND_S(int pc_offset, uint32_t op_pc, uint32_t offset, int not ) } } -#define ropBRANCH(name, func, not ) \ - static uint32_t \ - rop##name(uint8_t opcode, uint32_t fetchdat, \ - uint32_t op_32, uint32_t op_pc, \ - codeblock_t *block) \ - { \ - uint32_t offset = fetchdat & 0xff; \ - \ - if (offset & 0x80) \ - offset |= 0xffffff00; \ - \ - func(1, op_pc, offset, not ); \ - \ - return op_pc + 1; \ - } \ - static uint32_t \ - rop##name##_w(uint8_t opcode, \ - uint32_t fetchdat, uint32_t op_32, \ - uint32_t op_pc, codeblock_t *block) \ - { \ - uint32_t offset = fetchdat & 0xffff; \ - \ - if (offset & 0x8000) \ - offset |= 0xffff0000; \ - \ - func(2, op_pc, offset, not ); \ - \ - return op_pc + 2; \ - } \ - static uint32_t \ - rop##name##_l(uint8_t opcode, \ - uint32_t fetchdat, uint32_t op_32, \ - uint32_t op_pc, codeblock_t *block) \ - { \ - uint32_t offset = fastreadl(cs + op_pc); \ - \ - func(4, op_pc, offset, not ); \ - \ - return op_pc + 4; \ +#define ropBRANCH(name, func, not ) \ + static uint32_t \ + rop##name(UNUSED(uint8_t opcode), \ + uint32_t fetchdat, \ + UNUSED(uint32_t op_32), \ + uint32_t op_pc, \ + UNUSED(codeblock_t *block)) \ + { \ + uint32_t offset = fetchdat & 0xff; \ + \ + if (offset & 0x80) \ + offset |= 0xffffff00; \ + \ + func(1, op_pc, offset, not ); \ + \ + return op_pc + 1; \ + } \ + static uint32_t \ + rop##name##_w(UNUSED(uint8_t opcode), \ + uint32_t fetchdat, \ + UNUSED(uint32_t op_32), \ + uint32_t op_pc, \ + UNUSED(codeblock_t *block)) \ + { \ + uint32_t offset = fetchdat & 0xffff; \ + \ + if (offset & 0x8000) \ + offset |= 0xffff0000; \ + \ + func(2, op_pc, offset, not ); \ + \ + return op_pc + 2; \ + } \ + static uint32_t \ + rop##name##_l(UNUSED(uint8_t opcode), \ + UNUSED(uint32_t fetchdat), \ + UNUSED(uint32_t op_32), \ + uint32_t op_pc, \ + UNUSED(codeblock_t *block)) \ + { \ + uint32_t offset = fastreadl(cs + op_pc); \ + \ + func(4, op_pc, offset, not ); \ + \ + return op_pc + 4; \ } // clang-format off diff --git a/src/codegen/codegen_ops_logic.h b/src/codegen/codegen_ops_logic.h index 9f23723e2..2c79c4a2d 100644 --- a/src/codegen/codegen_ops_logic.h +++ b/src/codegen/codegen_ops_logic.h @@ -1,6 +1,6 @@ #define ROP_LOGIC(name, op, writeback) \ static uint32_t \ - rop##name##_b_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ + rop##name##_b_rmw(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) \ { \ int src_reg; \ int dst_reg; \ @@ -33,7 +33,7 @@ return op_pc + 1; \ } \ static uint32_t \ - rop##name##_w_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ + rop##name##_w_rmw(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) \ { \ int src_reg; \ int dst_reg; \ @@ -66,7 +66,7 @@ return op_pc + 1; \ } \ static uint32_t \ - rop##name##_l_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ + rop##name##_l_rmw(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) \ { \ int src_reg; \ int dst_reg; \ @@ -99,7 +99,7 @@ return op_pc + 1; \ } \ static uint32_t \ - rop##name##_b_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ + rop##name##_b_rm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) \ { \ int src_reg; \ int dst_reg; \ @@ -126,7 +126,7 @@ return op_pc + 1; \ } \ static uint32_t \ - rop##name##_w_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ + rop##name##_w_rm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) \ { \ int src_reg; \ int dst_reg; \ @@ -153,7 +153,7 @@ return op_pc + 1; \ } \ static uint32_t \ - rop##name##_l_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ + rop##name##_l_rm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) \ { \ int src_reg; \ int dst_reg; \ @@ -185,7 +185,7 @@ ROP_LOGIC(OR, OR, 1) 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) +ropTEST_b_rm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int src_reg; int dst_reg; @@ -209,7 +209,7 @@ ropTEST_b_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropTEST_w_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropTEST_w_rm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int src_reg; int dst_reg; @@ -233,7 +233,7 @@ ropTEST_w_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropTEST_l_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropTEST_l_rm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int src_reg; int dst_reg; @@ -258,7 +258,7 @@ ropTEST_l_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } static uint32_t -ropAND_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropAND_AL_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_B(REG_AL); @@ -270,7 +270,7 @@ ropAND_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropAND_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropAND_AX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_W(REG_AX); @@ -282,7 +282,7 @@ ropAND_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 2; } static uint32_t -ropAND_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropAND_EAX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_L(REG_EAX); @@ -296,7 +296,7 @@ ropAND_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc } static uint32_t -ropOR_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropOR_AL_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_B(REG_AL); @@ -308,7 +308,7 @@ ropOR_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropOR_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropOR_AX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_W(REG_AX); @@ -320,7 +320,7 @@ ropOR_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 2; } static uint32_t -ropOR_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropOR_EAX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_L(REG_EAX); @@ -334,7 +334,7 @@ ropOR_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } static uint32_t -ropTEST_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropTEST_AL_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_B(REG_AL); @@ -346,7 +346,7 @@ ropTEST_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc return op_pc + 1; } static uint32_t -ropTEST_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropTEST_AX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_W(REG_AX); @@ -358,7 +358,7 @@ ropTEST_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc return op_pc + 2; } static uint32_t -ropTEST_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropTEST_EAX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_L(REG_EAX); @@ -372,7 +372,7 @@ ropTEST_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_p } static uint32_t -ropXOR_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropXOR_AL_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_B(REG_AL); @@ -384,7 +384,7 @@ ropXOR_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropXOR_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropXOR_AX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_W(REG_AX); @@ -396,7 +396,7 @@ ropXOR_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 2; } static uint32_t -ropXOR_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropXOR_EAX_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_L(REG_EAX); @@ -410,7 +410,7 @@ ropXOR_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc } static uint32_t -ropF6(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropF6(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; int host_reg; @@ -458,7 +458,7 @@ ropF6(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblo return 0; } static uint32_t -ropF7_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropF7_w(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; int host_reg; @@ -506,7 +506,7 @@ ropF7_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb return 0; } static uint32_t -ropF7_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropF7_l(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg; int host_reg; diff --git a/src/codegen/codegen_ops_misc.h b/src/codegen/codegen_ops_misc.h index 61854ab37..db16dc09e 100644 --- a/src/codegen/codegen_ops_misc.h +++ b/src/codegen/codegen_ops_misc.h @@ -1,24 +1,24 @@ static uint32_t -ropNOP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropNOP(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { return op_pc; } static uint32_t -ropCLD(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropCLD(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { CLEAR_BITS((uintptr_t) &cpu_state.flags, D_FLAG); return op_pc; } static uint32_t -ropSTD(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropSTD(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { SET_BITS((uintptr_t) &cpu_state.flags, D_FLAG); return op_pc; } static uint32_t -ropCLI(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropCLI(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { if (!IOPLp && (cr4 & (CR4_VME | CR4_PVI))) return 0; @@ -29,7 +29,7 @@ ropCLI(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codebl return op_pc; } static uint32_t -ropSTI(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropSTI(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { if (!IOPLp && (cr4 & (CR4_VME | CR4_PVI))) return 0; @@ -38,7 +38,7 @@ ropSTI(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codebl } static uint32_t -ropFE(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFE(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg = NULL; int host_reg; @@ -88,7 +88,7 @@ ropFE(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblo } static uint32_t codegen_temp; static uint32_t -ropFF_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFF_16(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg = NULL; int host_reg; @@ -175,7 +175,7 @@ ropFF_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return 0; } static uint32_t -ropFF_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropFF_32(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg = NULL; int host_reg; diff --git a/src/codegen/codegen_ops_mmx.h b/src/codegen/codegen_ops_mmx.h index 4c5a92c8f..2e07bde77 100644 --- a/src/codegen/codegen_ops_mmx.h +++ b/src/codegen/codegen_ops_mmx.h @@ -1,5 +1,5 @@ static uint32_t -ropMOVQ_q_mm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOVQ_q_mm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg1; int host_reg2 = 0; @@ -25,7 +25,7 @@ ropMOVQ_q_mm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } static uint32_t -ropMOVQ_mm_q(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOVQ_mm_q(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { MMX_ENTER(); @@ -50,7 +50,7 @@ ropMOVQ_mm_q(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } static uint32_t -ropMOVD_l_mm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOVD_l_mm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; @@ -74,7 +74,7 @@ ropMOVD_l_mm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropMOVD_mm_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOVD_mm_l(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { MMX_ENTER(); @@ -95,36 +95,40 @@ ropMOVD_mm_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } -#define MMX_OP(name, func) \ - static uint32_t \ - name(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ - { \ - int src_reg1; \ - int src_reg2; \ - int xmm_src; \ - int xmm_dst; \ - \ - MMX_ENTER(); \ - \ - if ((fetchdat & 0xc0) == 0xc0) { \ - xmm_src = LOAD_MMX_Q_MMX(fetchdat & 7); \ - } else { \ - x86seg *target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \ - \ - STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ - \ - CHECK_SEG_READ(target_seg); \ - \ - MEM_LOAD_ADDR_EA_Q(target_seg); \ - src_reg1 = LOAD_Q_REG_1; \ - src_reg2 = LOAD_Q_REG_2; \ - xmm_src = LOAD_INT_TO_MMX(src_reg1, src_reg2); \ - } \ - xmm_dst = LOAD_MMX_Q_MMX((fetchdat >> 3) & 7); \ - func(xmm_dst, xmm_src); \ - STORE_MMX_Q_MMX((fetchdat >> 3) & 7, xmm_dst); \ - \ - return op_pc + 1; \ +#define MMX_OP(name, func) \ + static uint32_t \ + name(UNUSED(uint8_t opcode), \ + uint32_t fetchdat, \ + uint32_t op_32, \ + uint32_t op_pc, \ + UNUSED(codeblock_t *block)) \ + { \ + int src_reg1; \ + int src_reg2; \ + int xmm_src; \ + int xmm_dst; \ + \ + MMX_ENTER(); \ + \ + if ((fetchdat & 0xc0) == 0xc0) { \ + xmm_src = LOAD_MMX_Q_MMX(fetchdat & 7); \ + } else { \ + x86seg *target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); \ + \ + STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ + \ + CHECK_SEG_READ(target_seg); \ + \ + MEM_LOAD_ADDR_EA_Q(target_seg); \ + src_reg1 = LOAD_Q_REG_1; \ + src_reg2 = LOAD_Q_REG_2; \ + xmm_src = LOAD_INT_TO_MMX(src_reg1, src_reg2); \ + } \ + xmm_dst = LOAD_MMX_Q_MMX((fetchdat >> 3) & 7); \ + func(xmm_dst, xmm_src); \ + STORE_MMX_Q_MMX((fetchdat >> 3) & 7, xmm_dst); \ + \ + return op_pc + 1; \ } MMX_OP(ropPAND, MMX_AND) @@ -179,7 +183,7 @@ MMX_OP(ropPMULHW, MMX_PMULHW); MMX_OP(ropPMADDWD, MMX_PMADDWD); static uint32_t -ropPSxxW_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropPSxxW_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int xmm_dst; @@ -207,7 +211,7 @@ ropPSxxW_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 2; } static uint32_t -ropPSxxD_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropPSxxD_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int xmm_dst; @@ -235,7 +239,7 @@ ropPSxxD_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 2; } static uint32_t -ropPSxxQ_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropPSxxQ_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int xmm_dst; @@ -264,7 +268,7 @@ ropPSxxQ_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } static uint32_t -ropEMMS(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropEMMS(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), UNUSED(uint32_t op_pc), UNUSED(codeblock_t *block)) { codegen_mmx_entered = 0; diff --git a/src/codegen/codegen_ops_mov.h b/src/codegen/codegen_ops_mov.h index 04c4bf2bc..eb2a0202c 100644 --- a/src/codegen/codegen_ops_mov.h +++ b/src/codegen/codegen_ops_mov.h @@ -1,19 +1,19 @@ static uint32_t -ropMOV_rb_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_rb_imm(uint8_t opcode, uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { STORE_IMM_REG_B(opcode & 7, fetchdat & 0xff); return op_pc + 1; } static uint32_t -ropMOV_rw_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_rw_imm(uint8_t opcode, uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { STORE_IMM_REG_W(opcode & 7, fetchdat & 0xffff); return op_pc + 2; } static uint32_t -ropMOV_rl_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_rl_imm(uint8_t opcode, uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { fetchdat = fastreadl(cs + op_pc); @@ -23,7 +23,7 @@ ropMOV_rl_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } static uint32_t -ropMOV_b_r(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_b_r(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_B((fetchdat >> 3) & 7); @@ -44,7 +44,7 @@ ropMOV_b_r(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, co return op_pc + 1; } static uint32_t -ropMOV_w_r(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_w_r(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg = LOAD_REG_W((fetchdat >> 3) & 7); @@ -66,7 +66,7 @@ ropMOV_w_r(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, co } static uint32_t -ropMOV_l_r(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_l_r(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; @@ -90,7 +90,7 @@ ropMOV_l_r(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, co } static uint32_t -ropMOV_r_b(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_r_b(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { if ((fetchdat & 0xc0) == 0xc0) { int host_reg = LOAD_REG_B(fetchdat & 7); @@ -109,7 +109,7 @@ ropMOV_r_b(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, co return op_pc + 1; } static uint32_t -ropMOV_r_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_r_w(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { if ((fetchdat & 0xc0) == 0xc0) { int host_reg = LOAD_REG_W(fetchdat & 7); @@ -128,7 +128,7 @@ ropMOV_r_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, co return op_pc + 1; } static uint32_t -ropMOV_r_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_r_l(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { if ((fetchdat & 0xc0) == 0xc0) { int host_reg = LOAD_REG_L(fetchdat & 7); @@ -148,11 +148,17 @@ ropMOV_r_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, co } static uint32_t -ropMOV_b_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_b_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { if ((fetchdat & 0xc0) == 0xc0) { STORE_IMM_REG_B(fetchdat & 7, (fetchdat >> 8) & 0xff); - } else { + } +/* TODO: Fix the recompilation of that specific case so it no longer breaks NT 3.x NTVDM. */ +#ifndef RECOMPILE_MOVB_IMM_MEM_ALWAYS + else if (((fetchdat & 0xfc) == 0x80) && (op_32 & 0x200)) + return 0; +#endif + else { x86seg *target_seg = FETCH_EA(op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32); uint32_t imm = fastreadb(cs + op_pc + 1); int host_reg = LOAD_REG_IMM(imm); @@ -167,7 +173,7 @@ ropMOV_b_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 2; } static uint32_t -ropMOV_w_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_w_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { if ((fetchdat & 0xc0) == 0xc0) { STORE_IMM_REG_W(fetchdat & 7, (fetchdat >> 8) & 0xffff); @@ -186,7 +192,7 @@ ropMOV_w_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 3; } static uint32_t -ropMOV_l_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_l_imm(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { if ((fetchdat & 0xc0) == 0xc0) { uint32_t imm = fastreadl(cs + op_pc + 1); @@ -208,7 +214,7 @@ ropMOV_l_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } static uint32_t -ropMOV_AL_a(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_AL_a(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { uint32_t addr; @@ -226,7 +232,7 @@ ropMOV_AL_a(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, c return op_pc + ((op_32 & 0x200) ? 4 : 2); } static uint32_t -ropMOV_AX_a(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_AX_a(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { uint32_t addr; @@ -244,7 +250,7 @@ ropMOV_AX_a(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, c return op_pc + ((op_32 & 0x200) ? 4 : 2); } static uint32_t -ropMOV_EAX_a(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_EAX_a(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { uint32_t addr; @@ -263,7 +269,7 @@ ropMOV_EAX_a(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } static uint32_t -ropMOV_a_AL(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_a_AL(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { uint32_t addr; int host_reg; @@ -284,7 +290,7 @@ ropMOV_a_AL(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, c return op_pc + ((op_32 & 0x200) ? 4 : 2); } static uint32_t -ropMOV_a_AX(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_a_AX(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { uint32_t addr; int host_reg; @@ -305,7 +311,7 @@ ropMOV_a_AX(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, c return op_pc + ((op_32 & 0x200) ? 4 : 2); } static uint32_t -ropMOV_a_EAX(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_a_EAX(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { uint32_t addr; int host_reg; @@ -327,7 +333,7 @@ ropMOV_a_EAX(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } static uint32_t -ropLEA_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropLEA_w(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int dest_reg = (fetchdat >> 3) & 7; @@ -341,7 +347,7 @@ ropLEA_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code return op_pc + 1; } static uint32_t -ropLEA_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropLEA_l(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int dest_reg = (fetchdat >> 3) & 7; @@ -356,7 +362,7 @@ ropLEA_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, code } static uint32_t -ropMOVZX_w_b(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOVZX_w_b(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { if ((fetchdat & 0xc0) == 0xc0) { int host_reg = LOAD_REG_B(fetchdat & 7); @@ -377,7 +383,7 @@ ropMOVZX_w_b(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropMOVZX_l_b(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOVZX_l_b(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { if ((fetchdat & 0xc0) == 0xc0) { int host_reg = LOAD_REG_B(fetchdat & 7); @@ -398,7 +404,7 @@ ropMOVZX_l_b(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropMOVZX_l_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOVZX_l_w(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { if ((fetchdat & 0xc0) == 0xc0) { int host_reg = LOAD_REG_W(fetchdat & 7); @@ -420,7 +426,7 @@ ropMOVZX_l_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } static uint32_t -ropMOVSX_w_b(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOVSX_w_b(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { if ((fetchdat & 0xc0) == 0xc0) { int host_reg = LOAD_REG_B(fetchdat & 7); @@ -441,7 +447,7 @@ ropMOVSX_w_b(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropMOVSX_l_b(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOVSX_l_b(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { if ((fetchdat & 0xc0) == 0xc0) { int host_reg = LOAD_REG_B(fetchdat & 7); @@ -462,7 +468,7 @@ ropMOVSX_l_b(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropMOVSX_l_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOVSX_l_w(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { if ((fetchdat & 0xc0) == 0xc0) { int host_reg = LOAD_REG_W(fetchdat & 7); @@ -484,7 +490,7 @@ ropMOVSX_l_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } static uint32_t -ropMOV_w_seg(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_w_seg(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; @@ -531,7 +537,7 @@ ropMOV_w_seg(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return op_pc + 1; } static uint32_t -ropMOV_seg_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropMOV_seg_w(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; @@ -578,7 +584,7 @@ ropMOV_seg_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } #define ropLseg(seg, rseg) \ - static uint32_t ropL##seg(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ + static uint32_t ropL##seg(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) \ { \ int dest_reg = (fetchdat >> 3) & 7; \ x86seg *target_seg; \ @@ -594,12 +600,12 @@ ropMOV_seg_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, MEM_LOAD_ADDR_EA_L(target_seg); \ STORE_HOST_REG_ADDR((uintptr_t) &codegen_temp, 0); \ LOAD_EA(); \ - MEM_LOAD_ADDR_EA_W_OFFSET(target_seg, 4); \ + MEM_LOAD_ADDR_EA_W_OFFSET(target_seg, 4, op_32); \ } else { \ MEM_LOAD_ADDR_EA_W(target_seg); \ STORE_HOST_REG_ADDR_W((uintptr_t) &codegen_temp, 0); \ LOAD_EA(); \ - MEM_LOAD_ADDR_EA_W_OFFSET(target_seg, 2); \ + MEM_LOAD_ADDR_EA_W_OFFSET(target_seg, 2, op_32); \ } \ LOAD_SEG(0, &rseg); \ if (op_32 & 0x100) { \ diff --git a/src/codegen/codegen_ops_shift.h b/src/codegen/codegen_ops_shift.h index d750bfcad..a36fb3fdc 100644 --- a/src/codegen/codegen_ops_shift.h +++ b/src/codegen/codegen_ops_shift.h @@ -43,7 +43,7 @@ } static uint32_t -ropC0(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropC0(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg = NULL; int count; @@ -57,7 +57,7 @@ ropC0(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblo return op_pc + 2; } static uint32_t -ropC1_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropC1_w(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg = NULL; int count; @@ -71,7 +71,7 @@ ropC1_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb return op_pc + 2; } static uint32_t -ropC1_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropC1_l(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg = NULL; int count; @@ -86,7 +86,7 @@ ropC1_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb } static uint32_t -ropD0(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropD0(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg = NULL; int count = 1; @@ -100,7 +100,7 @@ ropD0(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblo return op_pc + 1; } static uint32_t -ropD1_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropD1_w(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg = NULL; int count = 1; @@ -114,7 +114,7 @@ ropD1_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeb return op_pc + 1; } static uint32_t -ropD1_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropD1_l(UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, UNUSED(codeblock_t *block)) { x86seg *target_seg = NULL; int count = 1; diff --git a/src/codegen/codegen_ops_stack.h b/src/codegen/codegen_ops_stack.h index 342ddedd4..b7e3d66fe 100644 --- a/src/codegen/codegen_ops_stack.h +++ b/src/codegen/codegen_ops_stack.h @@ -1,5 +1,5 @@ static uint32_t -ropPUSH_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropPUSH_16(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; @@ -12,7 +12,7 @@ ropPUSH_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, co return op_pc; } static uint32_t -ropPUSH_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropPUSH_32(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; @@ -26,7 +26,7 @@ ropPUSH_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, co } static uint32_t -ropPUSH_imm_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropPUSH_imm_16(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { uint16_t imm = fetchdat & 0xffff; int host_reg; @@ -40,7 +40,7 @@ ropPUSH_imm_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc return op_pc + 2; } static uint32_t -ropPUSH_imm_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropPUSH_imm_32(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { uint32_t imm = fastreadl(cs + op_pc); int host_reg; @@ -55,7 +55,7 @@ ropPUSH_imm_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc } static uint32_t -ropPUSH_imm_b16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropPUSH_imm_b16(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { uint16_t imm = fetchdat & 0xff; int host_reg; @@ -72,7 +72,7 @@ ropPUSH_imm_b16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_p return op_pc + 1; } static uint32_t -ropPUSH_imm_b32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropPUSH_imm_b32(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { uint32_t imm = fetchdat & 0xff; int host_reg; @@ -90,7 +90,7 @@ ropPUSH_imm_b32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_p } static uint32_t -ropPOP_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropPOP_16(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); LOAD_STACK_TO_EA(0); @@ -101,7 +101,7 @@ ropPOP_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return op_pc; } static uint32_t -ropPOP_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropPOP_32(uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); LOAD_STACK_TO_EA(0); @@ -113,7 +113,7 @@ ropPOP_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod } static uint32_t -ropRET_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropRET_16(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), UNUSED(uint32_t op_pc), UNUSED(codeblock_t *block)) { STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); LOAD_STACK_TO_EA(0); @@ -124,7 +124,7 @@ ropRET_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return -1; } static uint32_t -ropRET_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropRET_32(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), UNUSED(uint32_t op_pc), UNUSED(codeblock_t *block)) { STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); LOAD_STACK_TO_EA(0); @@ -136,7 +136,7 @@ ropRET_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod } static uint32_t -ropRET_imm_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropRET_imm_16(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), UNUSED(uint32_t op_pc), UNUSED(codeblock_t *block)) { uint16_t offset = fetchdat & 0xffff; @@ -149,7 +149,7 @@ ropRET_imm_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, return -1; } static uint32_t -ropRET_imm_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropRET_imm_32(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), UNUSED(uint32_t op_pc), UNUSED(codeblock_t *block)) { uint16_t offset = fetchdat & 0xffff; @@ -163,7 +163,7 @@ ropRET_imm_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, } static uint32_t -ropCALL_r16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropCALL_r16(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { uint16_t offset = fetchdat & 0xffff; int host_reg; @@ -178,7 +178,7 @@ ropCALL_r16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, c return -1; } static uint32_t -ropCALL_r32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropCALL_r32(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { uint32_t offset = fastreadl(cs + op_pc); int host_reg; @@ -194,7 +194,7 @@ ropCALL_r32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, c } static uint32_t -ropLEAVE_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropLEAVE_16(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; @@ -209,7 +209,7 @@ ropLEAVE_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, c return op_pc; } static uint32_t -ropLEAVE_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropLEAVE_32(UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int host_reg; @@ -224,32 +224,40 @@ ropLEAVE_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, c return op_pc; } -#define ROP_PUSH_SEG(seg) \ - static uint32_t \ - ropPUSH_##seg##_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ - { \ - int host_reg; \ - \ - STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ - LOAD_STACK_TO_EA(-2); \ - host_reg = LOAD_VAR_W((uintptr_t) &seg); \ - MEM_STORE_ADDR_EA_W(&cpu_state.seg_ss, host_reg); \ - SP_MODIFY(-2); \ - \ - return op_pc; \ - } \ - static uint32_t \ - ropPUSH_##seg##_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ - { \ - int host_reg; \ - \ - STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ - LOAD_STACK_TO_EA(-4); \ - host_reg = LOAD_VAR_W((uintptr_t) &seg); \ - MEM_STORE_ADDR_EA_L(&cpu_state.seg_ss, host_reg); \ - SP_MODIFY(-4); \ - \ - return op_pc; \ +#define ROP_PUSH_SEG(seg) \ + static uint32_t \ + ropPUSH_##seg##_16(UNUSED(uint8_t opcode), \ + UNUSED(uint32_t fetchdat), \ + UNUSED(uint32_t op_32), \ + uint32_t op_pc, \ + UNUSED(codeblock_t *block)) \ + { \ + int host_reg; \ + \ + STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ + LOAD_STACK_TO_EA(-2); \ + host_reg = LOAD_VAR_W((uintptr_t) &seg); \ + MEM_STORE_ADDR_EA_W(&cpu_state.seg_ss, host_reg); \ + SP_MODIFY(-2); \ + \ + return op_pc; \ + } \ + static uint32_t \ + ropPUSH_##seg##_32(UNUSED(uint8_t opcode), \ + UNUSED(uint32_t fetchdat), \ + UNUSED(uint32_t op_32), \ + uint32_t op_pc, \ + UNUSED(codeblock_t *block)) \ + { \ + int host_reg; \ + \ + STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ + LOAD_STACK_TO_EA(-4); \ + host_reg = LOAD_VAR_W((uintptr_t) &seg); \ + MEM_STORE_ADDR_EA_L(&cpu_state.seg_ss, host_reg); \ + SP_MODIFY(-4); \ + \ + return op_pc; \ } ROP_PUSH_SEG(CS) @@ -259,28 +267,36 @@ ROP_PUSH_SEG(FS) ROP_PUSH_SEG(GS) ROP_PUSH_SEG(SS) -#define ROP_POP_SEG(seg, rseg) \ - static uint32_t \ - ropPOP_##seg##_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ - { \ - STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ - LOAD_STACK_TO_EA(0); \ - MEM_LOAD_ADDR_EA_W(&cpu_state.seg_ss); \ - LOAD_SEG(0, &rseg); \ - SP_MODIFY(2); \ - \ - return op_pc; \ - } \ - static uint32_t \ - ropPOP_##seg##_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ - { \ - STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ - LOAD_STACK_TO_EA(0); \ - MEM_LOAD_ADDR_EA_W(&cpu_state.seg_ss); \ - LOAD_SEG(0, &rseg); \ - SP_MODIFY(4); \ - \ - return op_pc; \ +#define ROP_POP_SEG(seg, rseg) \ + static uint32_t \ + ropPOP_##seg##_16(UNUSED(uint8_t opcode), \ + UNUSED(uint32_t fetchdat), \ + UNUSED(uint32_t op_32), \ + uint32_t op_pc, \ + UNUSED(codeblock_t *block)) \ + { \ + STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ + LOAD_STACK_TO_EA(0); \ + MEM_LOAD_ADDR_EA_W(&cpu_state.seg_ss); \ + LOAD_SEG(0, &rseg); \ + SP_MODIFY(2); \ + \ + return op_pc; \ + } \ + static uint32_t \ + ropPOP_##seg##_32(UNUSED(uint8_t opcode), \ + UNUSED(uint32_t fetchdat), \ + UNUSED(uint32_t op_32), \ + uint32_t op_pc, \ + UNUSED(codeblock_t *block)) \ + { \ + STORE_IMM_ADDR_L((uintptr_t) &cpu_state.oldpc, op_old_pc); \ + LOAD_STACK_TO_EA(0); \ + MEM_LOAD_ADDR_EA_W(&cpu_state.seg_ss); \ + LOAD_SEG(0, &rseg); \ + SP_MODIFY(4); \ + \ + return op_pc; \ } ROP_POP_SEG(DS, cpu_state.seg_ds) diff --git a/src/codegen/codegen_ops_x86-64.h b/src/codegen/codegen_ops_x86-64.h index 08b9ee5f2..129d9a740 100644 --- a/src/codegen/codegen_ops_x86-64.h +++ b/src/codegen/codegen_ops_x86-64.h @@ -55,7 +55,7 @@ call_long(uintptr_t func) } static __inline void -load_param_1_32(codeblock_t *block, uint32_t param) +load_param_1_32(UNUSED(codeblock_t *block), uint32_t param) { #if _WIN64 addbyte(0xb9); /*MOVL $fetchdat,%ecx*/ @@ -93,7 +93,7 @@ static __inline void load_param_1_64(codeblock_t *block, uint64_t param) #endif static __inline void -load_param_2_32(codeblock_t *block, uint32_t param) +load_param_2_32(UNUSED(codeblock_t *block), uint32_t param) { #if _WIN64 addbyte(0xba); /*MOVL $fetchdat,%edx*/ @@ -118,7 +118,7 @@ load_param_2_reg_32(int reg) #endif } static __inline void -load_param_2_64(codeblock_t *block, uint64_t param) +load_param_2_64(UNUSED(codeblock_t *block), uint64_t param) { addbyte(0x48); #if _WIN64 @@ -1049,11 +1049,18 @@ MEM_LOAD_ADDR_EA_W(x86seg *seg) /*done:*/ } static __inline void -MEM_LOAD_ADDR_EA_W_OFFSET(x86seg *seg, int offset) +MEM_LOAD_ADDR_EA_W_OFFSET(x86seg *seg, int offset, int op_32) { addbyte(0x83); /*ADD EAX, offset*/ addbyte(0xc0); addbyte(offset); + if (!(op_32 & 0x200)) { + addbyte(0x25); /* AND EAX, ffffh */ + addbyte(0xff); + addbyte(0xff); + addbyte(0x00); + addbyte(0x00); + } MEM_LOAD_ADDR_EA_W(seg); } static __inline void @@ -1492,7 +1499,7 @@ MEM_STORE_ADDR_EA_L(x86seg *seg, int host_reg) /*done:*/ } static __inline void -MEM_STORE_ADDR_EA_Q(x86seg *seg, int host_reg, int host_reg2) +MEM_STORE_ADDR_EA_Q(x86seg *seg, int host_reg, UNUSED(int host_reg2)) { if ((seg == &cpu_state.seg_ds && codegen_flat_ds && !(cpu_cur_status & CPU_STATUS_NOTFLATDS)) || (seg == &cpu_state.seg_ss && codegen_flat_ss && !(cpu_cur_status & CPU_STATUS_NOTFLATSS))) { addbyte(0x31); /*XOR ECX, ECX*/ @@ -3926,7 +3933,7 @@ FP_LOAD_REG(int reg) return REG_EBX; } static __inline void -FP_LOAD_REG_D(int reg, int *host_reg1, int *host_reg2) +FP_LOAD_REG_D(int reg, int *host_reg1, UNUSED(int *host_reg2)) { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); @@ -4086,7 +4093,7 @@ FP_LOAD_REG_INT(int reg) return REG_EBX; } static __inline void -FP_LOAD_REG_INT_Q(int reg, int *host_reg1, int *host_reg2) +FP_LOAD_REG_INT_Q(int reg, int *host_reg1, UNUSED(int *host_reg2)) { addbyte(0x89); /*MOV EBX, EAX*/ addbyte(0xc3); @@ -4693,7 +4700,7 @@ LOAD_MMX_D(int guest_reg) return host_reg; } static __inline void -LOAD_MMX_Q(int guest_reg, int *host_reg1, int *host_reg2) +LOAD_MMX_Q(int guest_reg, int *host_reg1, UNUSED(int *host_reg2)) { int host_reg = REG_EBX; @@ -4725,7 +4732,7 @@ LOAD_MMX_Q_MMX(int guest_reg) } static __inline int -LOAD_INT_TO_MMX(int src_reg1, int src_reg2) +LOAD_INT_TO_MMX(int src_reg1, UNUSED(int src_reg2)) { int dst_reg = find_host_xmm_reg(); host_reg_xmm_mapping[dst_reg] = 100; @@ -4758,7 +4765,7 @@ STORE_MMX_LQ(int guest_reg, int host_reg1) addbyte((uint8_t) cpu_state_offset(MM[guest_reg].l[0])); } static __inline void -STORE_MMX_Q(int guest_reg, int host_reg1, int host_reg2) +STORE_MMX_Q(int guest_reg, int host_reg1, UNUSED(int host_reg2)) { if (host_reg1 & 8) addbyte(0x4c); diff --git a/src/codegen/codegen_ops_x86.h b/src/codegen/codegen_ops_x86.h index c48324c2a..3fbefdeaa 100644 --- a/src/codegen/codegen_ops_x86.h +++ b/src/codegen/codegen_ops_x86.h @@ -789,7 +789,7 @@ MEM_LOAD_ADDR_EA_W(x86seg *seg) host_reg_mapping[0] = 8; } static __inline void -MEM_LOAD_ADDR_EA_W_OFFSET(x86seg *seg, int offset) +MEM_LOAD_ADDR_EA_W_OFFSET(x86seg *seg, int offset, int op_32) { if ((seg == &cpu_state.seg_ds && codegen_flat_ds && !(cpu_cur_status & CPU_STATUS_NOTFLATDS)) || (seg == &cpu_state.seg_ss && codegen_flat_ss && !(cpu_cur_status & CPU_STATUS_NOTFLATSS))) { addbyte(0x31); /*XOR EDX, EDX*/ @@ -802,6 +802,13 @@ MEM_LOAD_ADDR_EA_W_OFFSET(x86seg *seg, int offset) addbyte(0x83); /*ADD EAX, offset*/ addbyte(0xc0); addbyte(offset); + if (!(op_32 & 0x200)) { + addbyte(0x25); /* AND EAX, ffffh */ + addbyte(0xff); + addbyte(0xff); + addbyte(0x00); + addbyte(0x00); + } addbyte(0xe8); /*CALL mem_load_addr_ea_w*/ addlong(mem_load_addr_ea_w - (uint32_t) (&codeblock[block_current].data[block_pos + 4])); diff --git a/src/codegen/codegen_ops_xchg.h b/src/codegen/codegen_ops_xchg.h index 28a558078..467f711e4 100644 --- a/src/codegen/codegen_ops_xchg.h +++ b/src/codegen/codegen_ops_xchg.h @@ -1,16 +1,20 @@ -#define OP_XCHG_AX_(reg) \ - static uint32_t \ - ropXCHG_AX_##reg(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ - { \ - int ax_reg, host_reg, temp_reg; \ - \ - ax_reg = LOAD_REG_W(REG_AX); \ - host_reg = LOAD_REG_W(REG_##reg); \ - temp_reg = COPY_REG(host_reg); \ - STORE_REG_TARGET_W_RELEASE(ax_reg, REG_##reg); \ - STORE_REG_TARGET_W_RELEASE(temp_reg, REG_AX); \ - \ - return op_pc; \ +#define OP_XCHG_AX_(reg) \ + static uint32_t \ + ropXCHG_AX_##reg(UNUSED(uint8_t opcode), \ + UNUSED(uint32_t fetchdat), \ + UNUSED(uint32_t op_32), \ + uint32_t op_pc, \ + UNUSED(codeblock_t *block)) \ + { \ + int ax_reg, host_reg, temp_reg; \ + \ + ax_reg = LOAD_REG_W(REG_AX); \ + host_reg = LOAD_REG_W(REG_##reg); \ + temp_reg = COPY_REG(host_reg); \ + STORE_REG_TARGET_W_RELEASE(ax_reg, REG_##reg); \ + STORE_REG_TARGET_W_RELEASE(temp_reg, REG_AX); \ + \ + return op_pc; \ } OP_XCHG_AX_(BX) @@ -21,19 +25,23 @@ OP_XCHG_AX_(DI) OP_XCHG_AX_(SP) OP_XCHG_AX_(BP) -#define OP_XCHG_EAX_(reg) \ - static uint32_t \ - ropXCHG_EAX_##reg(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ - { \ - int eax_reg, host_reg, temp_reg; \ - \ - eax_reg = LOAD_REG_L(REG_EAX); \ - host_reg = LOAD_REG_L(REG_##reg); \ - temp_reg = COPY_REG(host_reg); \ - STORE_REG_TARGET_L_RELEASE(eax_reg, REG_##reg); \ - STORE_REG_TARGET_L_RELEASE(temp_reg, REG_EAX); \ - \ - return op_pc; \ +#define OP_XCHG_EAX_(reg) \ + static uint32_t \ + ropXCHG_EAX_##reg(UNUSED(uint8_t opcode), \ + UNUSED(uint32_t fetchdat), \ + UNUSED(uint32_t op_32), \ + uint32_t op_pc, \ + UNUSED(codeblock_t *block)) \ + { \ + int eax_reg, host_reg, temp_reg; \ + \ + eax_reg = LOAD_REG_L(REG_EAX); \ + host_reg = LOAD_REG_L(REG_##reg); \ + temp_reg = COPY_REG(host_reg); \ + STORE_REG_TARGET_L_RELEASE(eax_reg, REG_##reg); \ + STORE_REG_TARGET_L_RELEASE(temp_reg, REG_EAX); \ + \ + return op_pc; \ } OP_XCHG_EAX_(EBX) @@ -45,7 +53,7 @@ OP_XCHG_EAX_(ESP) 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) +ropXCHG_b(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int src_reg; int dst_reg; @@ -63,7 +71,7 @@ ropXCHG_b(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return op_pc + 1; } static uint32_t -ropXCHG_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropXCHG_w(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int src_reg; int dst_reg; @@ -81,7 +89,7 @@ ropXCHG_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, cod return op_pc + 1; } static uint32_t -ropXCHG_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) +ropXCHG_l(UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc, UNUSED(codeblock_t *block)) { int src_reg; int dst_reg; diff --git a/src/codegen/codegen_x86-64.c b/src/codegen/codegen_x86-64.c index 59f411612..fb775a2d0 100644 --- a/src/codegen/codegen_x86-64.c +++ b/src/codegen/codegen_x86-64.c @@ -125,7 +125,7 @@ add_to_block_list(codeblock_t *block) } static void -remove_from_block_list(codeblock_t *block, uint32_t pc) +remove_from_block_list(codeblock_t *block, UNUSED(uint32_t pc)) { if (!block->page_mask) return; @@ -499,14 +499,14 @@ static int opcode_modrm[256] = { int opcode_0f_modrm[256] = { 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, /*00*/ - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, /*10*/ + 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, /*10*/ 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*20*/ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /*30*/ + 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, /*30*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /*40*/ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*50*/ + 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, /*50*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, /*60*/ - 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, /*70*/ + 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, /*70*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*80*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /*90*/ @@ -818,7 +818,9 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p int over = 0; int pc_off = 0; int test_modrm = 1; + int in_lock = 0; int c; + uint32_t op87 = 0x00000000; op_ea_seg = &cpu_state.seg_ds; op_ssegs = 0; @@ -872,6 +874,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p break; case 0xd8: + op87 = (op87 & 0xf800) | ((opcode & 0x07) << 8) | (fetchdat & 0xff); 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; @@ -882,6 +885,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p block->flags |= CODEBLOCK_HAS_FPU; break; case 0xd9: + op87 = (op87 & 0xf800) | ((opcode & 0x07) << 8) | (fetchdat & 0xff); 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; @@ -891,6 +895,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p block->flags |= CODEBLOCK_HAS_FPU; break; case 0xda: + op87 = (op87 & 0xf800) | ((opcode & 0x07) << 8) | (fetchdat & 0xff); 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; @@ -900,6 +905,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p block->flags |= CODEBLOCK_HAS_FPU; break; case 0xdb: + op87 = (op87 & 0xf800) | ((opcode & 0x07) << 8) | (fetchdat & 0xff); 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; @@ -909,6 +915,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p block->flags |= CODEBLOCK_HAS_FPU; break; case 0xdc: + op87 = (op87 & 0xf800) | ((opcode & 0x07) << 8) | (fetchdat & 0xff); 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; @@ -919,6 +926,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p block->flags |= CODEBLOCK_HAS_FPU; break; case 0xdd: + op87 = (op87 & 0xf800) | ((opcode & 0x07) << 8) | (fetchdat & 0xff); 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; @@ -928,6 +936,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p block->flags |= CODEBLOCK_HAS_FPU; break; case 0xde: + op87 = (op87 & 0xf800) | ((opcode & 0x07) << 8) | (fetchdat & 0xff); 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; @@ -937,6 +946,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p block->flags |= CODEBLOCK_HAS_FPU; break; case 0xdf: + op87 = (op87 & 0xf800) | ((opcode & 0x07) << 8) | (fetchdat & 0xff); 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; @@ -947,6 +957,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p break; case 0xf0: /*LOCK*/ + in_lock = 0; break; case 0xf2: /*REPNE*/ @@ -1000,6 +1011,13 @@ generate_call: recomp_op_table = recomp_opcodes; } + if (op87 != 0x0000) { + STORE_IMM_ADDR_L((uintptr_t) &x87_op, op87); + } + + if (in_lock && ((opcode == 0x90) || (opcode == 0xec))) + goto codegen_skip; + if (recomp_op_table && recomp_op_table[(opcode | op_32) & 0x1ff]) { uint32_t new_pc = recomp_op_table[(opcode | op_32) & 0x1ff](opcode, fetchdat, op_32, op_pc, block); if (new_pc) { @@ -1027,7 +1045,13 @@ generate_call: } } - op = op_table[((opcode >> opcode_shift) | op_32) & opcode_mask]; +codegen_skip: + if (in_lock && ((opcode == 0x90) || (opcode == 0xec))) + /* This is always ILLEGAL. */ + op = x86_dynarec_opcodes_3DNOW[0xff]; + else + op = op_table[((opcode >> opcode_shift) | op_32) & opcode_mask]; + if (op_ssegs != last_ssegs) { last_ssegs = op_ssegs; addbyte(0xC6); /*MOVB $0,(ssegs)*/ diff --git a/src/codegen/codegen_x86.c b/src/codegen/codegen_x86.c index df0ed3bfd..e0b9b633a 100644 --- a/src/codegen/codegen_x86.c +++ b/src/codegen/codegen_x86.c @@ -1643,14 +1643,14 @@ static int opcode_modrm[256] = { int opcode_0f_modrm[256] = { 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, /*00*/ - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, /*10*/ + 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, /*10*/ 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*20*/ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /*30*/ + 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, /*30*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /*40*/ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*50*/ + 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, /*50*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, /*60*/ - 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, /*70*/ + 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, /*70*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*80*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /*90*/ @@ -1857,7 +1857,9 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p int over = 0; int pc_off = 0; int test_modrm = 1; + int in_lock = 0; int c; + uint32_t op87 = 0x00000000; op_ea_seg = &cpu_state.seg_ds; op_ssegs = 0; @@ -1912,6 +1914,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p break; case 0xd8: + op87 = (op87 & 0xf800) | ((opcode & 0x07) << 8) | (fetchdat & 0xff); 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; @@ -1922,6 +1925,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p block->flags |= CODEBLOCK_HAS_FPU; break; case 0xd9: + op87 = (op87 & 0xf800) | ((opcode & 0x07) << 8) | (fetchdat & 0xff); 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; @@ -1931,6 +1935,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p block->flags |= CODEBLOCK_HAS_FPU; break; case 0xda: + op87 = (op87 & 0xf800) | ((opcode & 0x07) << 8) | (fetchdat & 0xff); 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; @@ -1940,6 +1945,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p block->flags |= CODEBLOCK_HAS_FPU; break; case 0xdb: + op87 = (op87 & 0xf800) | ((opcode & 0x07) << 8) | (fetchdat & 0xff); 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; @@ -1949,6 +1955,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p block->flags |= CODEBLOCK_HAS_FPU; break; case 0xdc: + op87 = (op87 & 0xf800) | ((opcode & 0x07) << 8) | (fetchdat & 0xff); 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; @@ -1959,6 +1966,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p block->flags |= CODEBLOCK_HAS_FPU; break; case 0xdd: + op87 = (op87 & 0xf800) | ((opcode & 0x07) << 8) | (fetchdat & 0xff); 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; @@ -1968,6 +1976,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p block->flags |= CODEBLOCK_HAS_FPU; break; case 0xde: + op87 = (op87 & 0xf800) | ((opcode & 0x07) << 8) | (fetchdat & 0xff); 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; @@ -1977,6 +1986,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p block->flags |= CODEBLOCK_HAS_FPU; break; case 0xdf: + op87 = (op87 & 0xf800) | ((opcode & 0x07) << 8) | (fetchdat & 0xff); 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; @@ -1987,6 +1997,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p break; case 0xf0: /*LOCK*/ + in_lock = 1; break; case 0xf2: /*REPNE*/ @@ -2041,6 +2052,13 @@ generate_call: recomp_op_table = recomp_opcodes; } + if (op87 != 0x0000) { + STORE_IMM_ADDR_L((uintptr_t) &x87_op, op87); + } + + if (in_lock && ((opcode == 0x90) || (opcode == 0xec))) + goto codegen_skip; + if (recomp_op_table && recomp_op_table[(opcode | op_32) & 0x1ff]) { uint32_t new_pc = recomp_op_table[(opcode | op_32) & 0x1ff](opcode, fetchdat, op_32, op_pc, block); if (new_pc) { @@ -2067,7 +2085,13 @@ generate_call: } } - op = op_table[((opcode >> opcode_shift) | op_32) & opcode_mask]; +codegen_skip: + if (in_lock && ((opcode == 0x90) || (opcode == 0xec))) + /* This is always ILLEGAL. */ + op = x86_dynarec_opcodes_3DNOW[0xff]; + else + op = op_table[((opcode >> opcode_shift) | op_32) & opcode_mask]; + if (op_ssegs != last_ssegs) { last_ssegs = op_ssegs; diff --git a/src/codegen_new/codegen.c b/src/codegen_new/codegen.c index a3f4ede8f..26a74016a 100644 --- a/src/codegen_new/codegen.c +++ b/src/codegen_new/codegen.c @@ -21,8 +21,7 @@ #define MAX_INSTRUCTION_COUNT 50 -static struct -{ +static struct { uint32_t pc; int op_ssegs; x86seg *op_ea_seg; @@ -360,14 +359,14 @@ static uint8_t opcode_modrm[256] = { static uint8_t opcode_0f_modrm[256] = { 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, /*00*/ - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, /*10*/ + 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, /*10*/ 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*20*/ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /*30*/ + 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, /*30*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /*40*/ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*50*/ + 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, /*50*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, /*60*/ - 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, /*70*/ + 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, /*70*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*80*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /*90*/ @@ -396,7 +395,9 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p int over = 0; int test_modrm = 1; int pc_off = 0; + int in_lock = 0; uint32_t next_pc = 0; + uint16_t op87 = 0x0000; #ifdef DEBUG_EXTRA uint8_t last_prefix = 0; #endif @@ -452,6 +453,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p #ifdef DEBUG_EXTRA last_prefix = 0xd8; #endif + op87 = (op87 & 0xf800) | ((opcode & 0x07) << 8) | (fetchdat & 0xff); 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; @@ -465,6 +467,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p #ifdef DEBUG_EXTRA last_prefix = 0xd9; #endif + op87 = (op87 & 0xf800) | ((opcode & 0x07) << 8) | (fetchdat & 0xff); 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; @@ -477,6 +480,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p #ifdef DEBUG_EXTRA last_prefix = 0xda; #endif + op87 = (op87 & 0xf800) | ((opcode & 0x07) << 8) | (fetchdat & 0xff); 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; @@ -489,6 +493,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p #ifdef DEBUG_EXTRA last_prefix = 0xdb; #endif + op87 = (op87 & 0xf800) | ((opcode & 0x07) << 8) | (fetchdat & 0xff); 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; @@ -501,6 +506,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p #ifdef DEBUG_EXTRA last_prefix = 0xdc; #endif + op87 = (op87 & 0xf800) | ((opcode & 0x07) << 8) | (fetchdat & 0xff); 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; @@ -514,6 +520,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p #ifdef DEBUG_EXTRA last_prefix = 0xdd; #endif + op87 = (op87 & 0xf800) | ((opcode & 0x07) << 8) | (fetchdat & 0xff); 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; @@ -526,6 +533,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p #ifdef DEBUG_EXTRA last_prefix = 0xde; #endif + op87 = (op87 & 0xf800) | ((opcode & 0x07) << 8) | (fetchdat & 0xff); 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; @@ -538,6 +546,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p #ifdef DEBUG_EXTRA last_prefix = 0xdf; #endif + op87 = (op87 & 0xf800) | ((opcode & 0x07) << 8) | (fetchdat & 0xff); 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; @@ -548,6 +557,7 @@ codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_p break; case 0xf0: /*LOCK*/ + in_lock = 1; break; case 0xf2: /*REPNE*/ @@ -658,12 +668,18 @@ generate_call: } } codegen_mark_code_present(block, cs + old_pc, (op_pc - old_pc) - pc_off); + if (op87 != 0x0000) { + uop_MOV_IMM(ir, IREG_x87_op, op87); + } /* It is apparently a prefixed instruction. */ #if 0 if ((recomp_op_table == recomp_opcodes) && (opcode == 0x48)) goto codegen_skip; #endif + if (in_lock && ((opcode == 0x90) || (opcode == 0xec))) + goto codegen_skip; + if (recomp_op_table && recomp_op_table[(opcode | op_32) & recomp_opcode_mask]) { uint32_t new_pc = recomp_op_table[(opcode | op_32) & recomp_opcode_mask](block, ir, opcode, fetchdat, op_32, op_pc); if (new_pc) { @@ -681,13 +697,17 @@ generate_call: } } - // codegen_skip: +codegen_skip: if ((op_table == x86_dynarec_opcodes_REPNE || op_table == x86_dynarec_opcodes_REPE) && !op_table[opcode | op_32]) { op_table = x86_dynarec_opcodes; recomp_op_table = recomp_opcodes; } - op = op_table[((opcode >> opcode_shift) | op_32) & opcode_mask]; + if (in_lock && ((opcode == 0x90) || (opcode == 0xec))) + /* This is always ILLEGAL. */ + op = x86_dynarec_opcodes_3DNOW[0xff]; + else + op = op_table[((opcode >> opcode_shift) | op_32) & opcode_mask]; if (!test_modrm || (op_table == x86_dynarec_opcodes && opcode_modrm[opcode]) || (op_table == x86_dynarec_opcodes_0f && opcode_0f_modrm[opcode]) || (op_table == x86_dynarec_opcodes_3DNOW)) { int stack_offset = 0; diff --git a/src/codegen_new/codegen.h b/src/codegen_new/codegen.h index eecfa249b..0ff6a90d6 100644 --- a/src/codegen_new/codegen.h +++ b/src/codegen_new/codegen.h @@ -306,6 +306,7 @@ struct ir_data_t; x86seg *codegen_generate_ea(struct ir_data_t *ir, x86seg *op_ea_seg, uint32_t fetchdat, int op_ssegs, uint32_t *op_pc, uint32_t op_32, int stack_offset); extern void codegen_check_seg_read(codeblock_t *block, struct ir_data_t *ir, x86seg *seg); extern void codegen_check_seg_write(codeblock_t *block, struct ir_data_t *ir, x86seg *seg); +extern void codegen_check_regs(void); extern int codegen_purge_purgable_list(void); /*Delete a random code block to free memory. This is obviously quite expensive, and diff --git a/src/codegen_new/codegen_accumulate.c b/src/codegen_new/codegen_accumulate.c index 29b05ad77..087d9c797 100644 --- a/src/codegen_new/codegen_accumulate.c +++ b/src/codegen_new/codegen_accumulate.c @@ -8,8 +8,7 @@ #include "codegen_accumulate.h" #include "codegen_ir.h" -static struct -{ +static struct { int count; int dest_reg; } acc_regs[] = { diff --git a/src/codegen_new/codegen_backend_arm64_uops.c b/src/codegen_new/codegen_backend_arm64_uops.c index deaf53c20..82cc79cfd 100644 --- a/src/codegen_new/codegen_backend_arm64_uops.c +++ b/src/codegen_new/codegen_backend_arm64_uops.c @@ -931,6 +931,8 @@ codegen_MEM_LOAD_REG(codeblock_t *block, uop_t *uop) host_arm64_ADD_REG(block, REG_X0, seg_reg, addr_reg, 0); if (uop->imm_data) host_arm64_ADD_IMM(block, REG_X0, REG_X0, uop->imm_data); + if (uop->is_a16) + host_arm64_AND_IMM(block, REG_X0, REG_X0, 0xffff); if (REG_IS_B(dest_size) || REG_IS_BH(dest_size)) { host_arm64_call(block, codegen_mem_load_byte); } else if (REG_IS_W(dest_size)) { diff --git a/src/codegen_new/codegen_backend_arm_uops.c b/src/codegen_new/codegen_backend_arm_uops.c index d8c223884..b6963562c 100644 --- a/src/codegen_new/codegen_backend_arm_uops.c +++ b/src/codegen_new/codegen_backend_arm_uops.c @@ -995,6 +995,8 @@ codegen_MEM_LOAD_REG(codeblock_t *block, uop_t *uop) host_arm_ADD_REG(block, REG_R0, seg_reg, addr_reg); if (uop->imm_data) host_arm_ADD_IMM(block, REG_R0, REG_R0, uop->imm_data); + if (uop->is_a16) + host_arm_AND_IMM(block, REG_R0, REG_R0, 0xffff); if (REG_IS_B(dest_size) || REG_IS_BH(dest_size)) { host_arm_BL(block, (uintptr_t) codegen_mem_load_byte); } else if (REG_IS_W(dest_size)) { diff --git a/src/codegen_new/codegen_backend_x86-64.c b/src/codegen_new/codegen_backend_x86-64.c index 3cbca28f8..20d02a8db 100644 --- a/src/codegen_new/codegen_backend_x86-64.c +++ b/src/codegen_new/codegen_backend_x86-64.c @@ -315,15 +315,21 @@ codegen_backend_init(void) # endif host_x86_CALL(block, (void *) x86gpf); codegen_exit_rout = &codeblock[block_current].data[block_pos]; +#ifdef _WIN64 host_x86_ADD64_REG_IMM(block, REG_RSP, 0x38); +#else + host_x86_ADD64_REG_IMM(block, REG_RSP, 0x48); +#endif host_x86_POP(block, REG_R15); host_x86_POP(block, REG_R14); host_x86_POP(block, REG_R13); host_x86_POP(block, REG_R12); +#ifdef _WIN64 host_x86_POP(block, REG_RDI); host_x86_POP(block, REG_RSI); +#endif host_x86_POP(block, REG_RBP); - host_x86_POP(block, REG_RDX); + host_x86_POP(block, REG_RBX); host_x86_RET(block); block_write_data = NULL; @@ -346,13 +352,19 @@ codegen_backend_prologue(codeblock_t *block) block_pos = BLOCK_START; /*Entry code*/ host_x86_PUSH(block, REG_RBX); host_x86_PUSH(block, REG_RBP); +#ifdef _WIN64 host_x86_PUSH(block, REG_RSI); host_x86_PUSH(block, REG_RDI); +#endif host_x86_PUSH(block, REG_R12); host_x86_PUSH(block, REG_R13); host_x86_PUSH(block, REG_R14); host_x86_PUSH(block, REG_R15); +#ifdef _WIN64 host_x86_SUB64_REG_IMM(block, REG_RSP, 0x38); +#else + host_x86_SUB64_REG_IMM(block, REG_RSP, 0x48); +#endif host_x86_MOV64_REG_IMM(block, REG_RBP, ((uintptr_t) &cpu_state) + 128); if (block->flags & CODEBLOCK_HAS_FPU) { host_x86_MOV32_REG_ABS(block, REG_EAX, &cpu_state.TOP); @@ -360,21 +372,27 @@ codegen_backend_prologue(codeblock_t *block) host_x86_MOV32_BASE_OFFSET_REG(block, REG_RSP, IREG_TOP_diff_stack_offset, REG_EAX); } if (block->flags & CODEBLOCK_NO_IMMEDIATES) - host_x86_MOV64_REG_IMM(block, REG_R12, (uintptr_t) ram); + host_x86_MOV64_REG_IMM(block, REG_R12, ((uintptr_t) ram) + 2147483648ULL); } void codegen_backend_epilogue(codeblock_t *block) { +#ifdef _WIN64 host_x86_ADD64_REG_IMM(block, REG_RSP, 0x38); +#else + host_x86_ADD64_REG_IMM(block, REG_RSP, 0x48); +#endif host_x86_POP(block, REG_R15); host_x86_POP(block, REG_R14); host_x86_POP(block, REG_R13); host_x86_POP(block, REG_R12); +#ifdef _WIN64 host_x86_POP(block, REG_RDI); host_x86_POP(block, REG_RSI); +#endif host_x86_POP(block, REG_RBP); - host_x86_POP(block, REG_RDX); + host_x86_POP(block, REG_RBX); host_x86_RET(block); } #endif diff --git a/src/codegen_new/codegen_backend_x86-64_defs.h b/src/codegen_new/codegen_backend_x86-64_defs.h index 12f05f01c..7c58fec31 100644 --- a/src/codegen_new/codegen_backend_x86-64_defs.h +++ b/src/codegen_new/codegen_backend_x86-64_defs.h @@ -1,5 +1,5 @@ /*RBP = cpu_state + 128 - R12 = ram (if block->flags & CODEBLOCK_NO_IMMEDIATES)*/ + R12 = ram + 2147483648 (if block->flags & CODEBLOCK_NO_IMMEDIATES)*/ #define REG_AX 0 #define REG_CX 1 #define REG_DX 2 diff --git a/src/codegen_new/codegen_backend_x86-64_ops.c b/src/codegen_new/codegen_backend_x86-64_ops.c index 236a86ce7..1569e693c 100644 --- a/src/codegen_new/codegen_backend_x86-64_ops.c +++ b/src/codegen_new/codegen_backend_x86-64_ops.c @@ -505,10 +505,15 @@ host_x86_MOV8_ABS_IMM(codeblock_t *block, void *p, uint32_t imm_data) { int64_t offset = (uintptr_t) p - (((uintptr_t) &cpu_state) + 128); - if (offset >= -128 && offset < 127) { + if (offset >= -128 && offset <= 127) { codegen_alloc_bytes(block, 4); codegen_addbyte3(block, 0xc6, 0x45, offset); /*MOVB offset[RBP], imm_data*/ codegen_addbyte(block, imm_data); + } else if (offset < (1ULL << 32)) { + codegen_alloc_bytes(block, 7); + codegen_addbyte2(block, 0xc6, 0x85); /*MOVB offset[RBP], imm_data*/ + codegen_addlong(block, offset); + codegen_addbyte(block, imm_data); } else { if ((uintptr_t) p >> 32) fatal("host_x86_MOV8_ABS_IMM - out of range %p\n", p); @@ -523,10 +528,15 @@ host_x86_MOV16_ABS_IMM(codeblock_t *block, void *p, uint16_t imm_data) { int64_t offset = (uintptr_t) p - (((uintptr_t) &cpu_state) + 128); - if (offset >= -128 && offset < 127) { + if (offset >= -128 && offset <= 127) { codegen_alloc_bytes(block, 6); codegen_addbyte4(block, 0x66, 0xc7, 0x45, offset); /*MOV offset[RBP], imm_data*/ codegen_addword(block, imm_data); + } else if (offset < (1ULL << 32)) { + codegen_alloc_bytes(block, 9); + codegen_addbyte3(block, 0x66, 0xc7, 0x85); /*MOV offset[RBP], imm_data*/ + codegen_addlong(block, offset); + codegen_addword(block, imm_data); } else { if ((uintptr_t) p >> 32) fatal("host_x86_MOV32_ABS_IMM - out of range %p\n", p); @@ -541,10 +551,15 @@ host_x86_MOV32_ABS_IMM(codeblock_t *block, void *p, uint32_t imm_data) { int64_t offset = (uintptr_t) p - (((uintptr_t) &cpu_state) + 128); - if (offset >= -128 && offset < 127) { + if (offset >= -128 && offset <= 127) { codegen_alloc_bytes(block, 7); codegen_addbyte3(block, 0xc7, 0x45, offset); /*MOV offset[RBP], imm_data*/ codegen_addlong(block, imm_data); + } else if (offset < (1ULL << 32)) { + codegen_alloc_bytes(block, 10); + codegen_addbyte2(block, 0xc7, 0x85); /*MOV offset[RBP], imm_data*/ + codegen_addlong(block, offset); + codegen_addlong(block, imm_data); } else { if ((uintptr_t) p >> 32) fatal("host_x86_MOV32_ABS_IMM - out of range %p\n", p); @@ -563,9 +578,13 @@ host_x86_MOV8_ABS_REG(codeblock_t *block, void *p, int src_reg) if (src_reg & 8) fatal("host_x86_MOV8_ABS_REG - bad reg\n"); - if (offset >= -128 && offset < 127) { + if (offset >= -128 && offset <= 127) { codegen_alloc_bytes(block, 3); codegen_addbyte3(block, 0x88, 0x45 | ((src_reg & 7) << 3), offset); /*MOVB offset[RBP], src_reg*/ + } else if (offset < (1ULL << 32)) { + codegen_alloc_bytes(block, 6); + codegen_addbyte2(block, 0x88, 0x85 | ((src_reg & 7) << 3)); /*MOVB offset[RBP], src_reg*/ + codegen_addlong(block, offset); } else { if ((uintptr_t) p >> 32) fatal("host_x86_MOV8_ABS_REG - out of range %p\n", p); @@ -583,7 +602,7 @@ host_x86_MOV16_ABS_REG(codeblock_t *block, void *p, int src_reg) if (src_reg & 8) fatal("host_x86_MOV16_ABS_REG - bad reg\n"); - if (offset >= -128 && offset < 127) { + if (offset >= -128 && offset <= 127) { codegen_alloc_bytes(block, 4); codegen_addbyte4(block, 0x66, 0x89, 0x45 | ((src_reg & 7) << 3), offset); /*MOV offset[RBP], src_reg*/ } else if (offset < (1ULL << 32)) { @@ -603,7 +622,7 @@ host_x86_MOV32_ABS_REG(codeblock_t *block, void *p, int src_reg) if (src_reg & 8) fatal("host_x86_MOV32_ABS_REG - bad reg\n"); - if (offset >= -128 && offset < 127) { + if (offset >= -128 && offset <= 127) { codegen_alloc_bytes(block, 3); codegen_addbyte3(block, 0x89, 0x45 | ((src_reg & 7) << 3), offset); /*MOV offset[RBP], src_reg*/ } else if (offset < (1ULL << 32)) { @@ -627,9 +646,13 @@ host_x86_MOV64_ABS_REG(codeblock_t *block, void *p, int src_reg) if (src_reg & 8) fatal("host_x86_MOV64_ABS_REG - bad reg\n"); - if (offset >= -128 && offset < 127) { + if (offset >= -128 && offset <= 127) { codegen_alloc_bytes(block, 4); codegen_addbyte4(block, 0x48, 0x89, 0x45 | ((src_reg & 7) << 3), offset); /*MOV offset[RBP], src_reg*/ + } else if (offset < (1ULL << 32)) { + codegen_alloc_bytes(block, 7); + codegen_addbyte3(block, 0x48, 0x89, 0x85 | ((src_reg & 7) << 3)); /*MOV offset[RBP], src_reg*/ + codegen_addlong(block, offset); } else { if ((uintptr_t) p >> 32) fatal("host_x86_MOV64_ABS_REG - out of range %p\n", p); @@ -683,43 +706,47 @@ void host_x86_MOV8_REG_ABS(codeblock_t *block, int dst_reg, void *p) { int64_t offset = (uintptr_t) p - (((uintptr_t) &cpu_state) + 128); - int64_t ram_offset = (uintptr_t) p - (uintptr_t) ram; + int64_t ram_offset = (uintptr_t) p - (((uintptr_t) ram) + 2147483648ULL); if (dst_reg & 8) fatal("host_x86_MOV8_REG_ABS reg & 8\n"); - if (offset >= -128 && offset < 127) { + if (offset >= -128 && offset <= 127) { codegen_alloc_bytes(block, 3); codegen_addbyte3(block, 0x8a, 0x45 | ((dst_reg & 7) << 3), offset); /*MOV dst_reg, offset[RBP]*/ } else if (offset < (1ULL << 32)) { codegen_alloc_bytes(block, 6); codegen_addbyte2(block, 0x8a, 0x85 | ((dst_reg & 7) << 3)); /*MOV dst_reg, offset[RBP]*/ codegen_addlong(block, offset); - } else if ((ram_offset < (1ULL << 32)) && (block->flags & CODEBLOCK_NO_IMMEDIATES)) { + } else if ((ram_offset >= -2147483648LL) && (ram_offset <= 2147483647LL) && (block->flags & CODEBLOCK_NO_IMMEDIATES)) { codegen_alloc_bytes(block, 8); codegen_addbyte4(block, 0x41, 0x8a, 0x84 | ((dst_reg & 7) << 3), 0x24); /*MOV dst_reg, ram_offset[R12]*/ codegen_addlong(block, ram_offset); } else { - fatal("host_x86_MOV8_REG_ABS - out of range\n"); + codegen_alloc_bytes(block, 10); + codegen_addbyte2(block, 0x49, 0xb9); /*MOV R9, p*/ + codegen_addquad(block, (uintptr_t) p); + codegen_alloc_bytes(block, 3); + codegen_addbyte3(block, 0x41, 0x8a, 0x01 | ((dst_reg & 7) << 3)); /*MOV dst_reg, [R9]*/ } } void host_x86_MOV16_REG_ABS(codeblock_t *block, int dst_reg, void *p) { int64_t offset = (uintptr_t) p - (((uintptr_t) &cpu_state) + 128); - int64_t ram_offset = (uintptr_t) p - (uintptr_t) ram; + int64_t ram_offset = (uintptr_t) p - (((uintptr_t) ram) + 2147483648ULL); if (dst_reg & 8) fatal("host_x86_MOV16_REG_ABS reg & 8\n"); - if (offset >= -128 && offset < 127) { + if (offset >= -128 && offset <= 127) { codegen_alloc_bytes(block, 4); codegen_addbyte4(block, 0x66, 0x8b, 0x45 | ((dst_reg & 7) << 3), offset); /*MOV dst_reg, offset[RBP]*/ } else if (offset < (1ULL << 32)) { codegen_alloc_bytes(block, 7); codegen_addbyte3(block, 0x66, 0x8b, 0x85 | ((dst_reg & 7) << 3)); /*MOV dst_reg, offset[RBP]*/ codegen_addlong(block, offset); - } else if ((ram_offset < (1ULL << 32)) && (block->flags & CODEBLOCK_NO_IMMEDIATES)) { + } else if ((ram_offset >= -2147483648LL) && (ram_offset <= 2147483647LL) && (block->flags & CODEBLOCK_NO_IMMEDIATES)) { codegen_alloc_bytes(block, 9); codegen_addbyte4(block, 0x66, 0x41, 0x8b, 0x84 | ((dst_reg & 7) << 3)); /*MOV dst_reg, ram_offset[R12]*/ codegen_addbyte(block, 0x24); @@ -737,24 +764,29 @@ void host_x86_MOV32_REG_ABS(codeblock_t *block, int dst_reg, void *p) { int64_t offset = (uintptr_t) p - (((uintptr_t) &cpu_state) + 128); - int64_t ram_offset = (uintptr_t) p - (uintptr_t) ram; + int64_t ram_offset = (uintptr_t) p - (((uintptr_t) ram) + 2147483648ULL); if (dst_reg & 8) fatal("host_x86_MOV32_REG_ABS reg & 8\n"); - if (offset >= -128 && offset < 127) { + if (offset >= -128 && offset <= 127) { codegen_alloc_bytes(block, 3); codegen_addbyte3(block, 0x8b, 0x45 | ((dst_reg & 7) << 3), offset); /*MOV dst_reg, offset[RBP]*/ } else if (offset < (1ULL << 32)) { codegen_alloc_bytes(block, 6); codegen_addbyte2(block, 0x8b, 0x85 | ((dst_reg & 7) << 3)); /*MOV dst_reg, offset[RBP]*/ codegen_addlong(block, offset); - } else if ((ram_offset < (1ULL << 32)) && (block->flags & CODEBLOCK_NO_IMMEDIATES)) { + } else if ((ram_offset >= -2147483648LL) && (ram_offset <= 2147483647LL) && (block->flags & CODEBLOCK_NO_IMMEDIATES)) { codegen_alloc_bytes(block, 8); codegen_addbyte4(block, 0x41, 0x8b, 0x84 | ((dst_reg & 7) << 3), 0x24); /*MOV dst_reg, ram_offset[R12]*/ codegen_addlong(block, ram_offset); + } else if ((ram_offset < -2147483648LL) || (ram_offset > 2147483647LL) || !(block->flags & CODEBLOCK_NO_IMMEDIATES)) { + codegen_alloc_bytes(block, 13); + codegen_addbyte2(block, 0x49, 0xb9); /*MOV r9,(uintptr_t) p*/ + codegen_addquad(block, (uintptr_t) p); + codegen_addbyte3(block, 0x41, 0x8b, 0x01 | ((dst_reg & 7) << 3)); /*MOV dst_reg, [R9]*/ } else { - fatal("host_x86_MOV32_REG_ABS - out of range\n"); + fatal("host_x86_MOV32_REG_ABS - RAM offset = %016" PRIX64 " (p - ram = %016" PRIX64 ")\n", ram_offset, (uintptr_t) p - (uintptr_t) ram); codegen_alloc_bytes(block, 6); codegen_addbyte(block, 0x8b); /*MOV [p], src_reg*/ codegen_addbyte(block, 0x05 | ((dst_reg & 7) << 3)); @@ -769,7 +801,7 @@ host_x86_MOV64_REG_ABS(codeblock_t *block, int dst_reg, void *p) if (dst_reg & 8) fatal("host_x86_MOV64_REG_ABS reg & 8\n"); - if (offset >= -128 && offset < 127) { + if (offset >= -128 && offset <= 127) { codegen_alloc_bytes(block, 4); codegen_addbyte4(block, 0x48, 0x8b, 0x45 | ((dst_reg & 7) << 3), offset); /*MOV dst_reg, offset[RBP]*/ } else if (offset < (1ULL << 32)) { @@ -822,14 +854,14 @@ host_x86_MOV16_REG_BASE_OFFSET(codeblock_t *block, int dst_reg, int base_reg, in if ((dst_reg & 8) || (base_reg & 8)) fatal("host_x86_MOV16_REG_BASE_OFFSET reg & 8\n"); - if (offset >= -128 && offset < 127) { + if (offset >= -128 && offset <= 127) { if (base_reg == REG_RSP) { codegen_alloc_bytes(block, 5); - codegen_addbyte(block, 0x66); + codegen_addbyte(block, 0x66); /* MOV dst_reg, [RSP + offset] */ codegen_addbyte4(block, 0x8b, 0x40 | base_reg | (dst_reg << 3), 0x24, offset); } else { codegen_alloc_bytes(block, 4); - codegen_addbyte4(block, 0x66, 0x8b, 0x40 | base_reg | (dst_reg << 3), offset); + codegen_addbyte4(block, 0x66, 0x8b, 0x40 | base_reg | (dst_reg << 3), offset); /* MOV dst_reg, [base_reg + offset] */ } } else fatal("MOV16_REG_BASE_OFFSET - offset %i\n", offset); @@ -840,13 +872,13 @@ host_x86_MOV32_REG_BASE_OFFSET(codeblock_t *block, int dst_reg, int base_reg, in if ((dst_reg & 8) || (base_reg & 8)) fatal("host_x86_MOV32_REG_BASE_OFFSET reg & 8\n"); - if (offset >= -128 && offset < 127) { + if (offset >= -128 && offset <= 127) { if (base_reg == REG_RSP) { codegen_alloc_bytes(block, 4); - codegen_addbyte4(block, 0x8b, 0x40 | base_reg | (dst_reg << 3), 0x24, offset); + codegen_addbyte4(block, 0x8b, 0x40 | base_reg | (dst_reg << 3), 0x24, offset); /* MOV dst_reg, [RSP + offset] */ } else { codegen_alloc_bytes(block, 3); - codegen_addbyte3(block, 0x8b, 0x40 | base_reg | (dst_reg << 3), offset); + codegen_addbyte3(block, 0x8b, 0x40 | base_reg | (dst_reg << 3), offset); /* MOV dst_reg, [base_reg + offset] */ } } else fatal("MOV32_REG_BASE_OFFSET - offset %i\n", offset); @@ -857,14 +889,14 @@ host_x86_MOV64_REG_BASE_OFFSET(codeblock_t *block, int dst_reg, int base_reg, in if ((dst_reg & 8) || (base_reg & 8)) fatal("host_x86_MOV64_REG_BASE_OFFSET reg & 8\n"); - if (offset >= -128 && offset < 127) { + if (offset >= -128 && offset <= 127) { if (base_reg == REG_RSP) { codegen_alloc_bytes(block, 5); - codegen_addbyte(block, 0x48); + codegen_addbyte(block, 0x48); /* MOV dst_reg, [RSP + offset] */ codegen_addbyte4(block, 0x8b, 0x40 | base_reg | (dst_reg << 3), 0x24, offset); } else { codegen_alloc_bytes(block, 4); - codegen_addbyte4(block, 0x48, 0x8b, 0x40 | base_reg | (dst_reg << 3), offset); + codegen_addbyte4(block, 0x48, 0x8b, 0x40 | base_reg | (dst_reg << 3), offset); /* MOV dst_reg, [base_reg + offset] */ } } else fatal("MOV32_REG_BASE_OFFSET - offset %i\n", offset); @@ -876,13 +908,13 @@ host_x86_MOV32_BASE_OFFSET_REG(codeblock_t *block, int base_reg, int offset, int if ((src_reg & 8) || (base_reg & 8)) fatal("host_x86_MOV32_BASE_OFFSET_REG reg & 8\n"); - if (offset >= -128 && offset < 127) { + if (offset >= -128 && offset <= 127) { if (base_reg == REG_RSP) { - codegen_alloc_bytes(block, 4); + codegen_alloc_bytes(block, 4); /* MOV [RSP + offset], src_reg*/ codegen_addbyte4(block, 0x89, 0x40 | base_reg | (src_reg << 3), 0x24, offset); } else { codegen_alloc_bytes(block, 3); - codegen_addbyte3(block, 0x89, 0x40 | base_reg | (src_reg << 3), offset); + codegen_addbyte3(block, 0x89, 0x40 | base_reg | (src_reg << 3), offset); /* MOV [base_reg + offset], src_reg*/ } } else fatal("MOV32_BASE_OFFSET_REG - offset %i\n", offset); @@ -893,14 +925,14 @@ host_x86_MOV64_BASE_OFFSET_REG(codeblock_t *block, int base_reg, int offset, int if ((src_reg & 8) || (base_reg & 8)) fatal("host_x86_MOV64_BASE_OFFSET_REG reg & 8\n"); - if (offset >= -128 && offset < 127) { + if (offset >= -128 && offset <= 127) { if (base_reg == REG_RSP) { codegen_alloc_bytes(block, 5); - codegen_addbyte(block, 0x48); + codegen_addbyte(block, 0x48); /* MOV [RSP + offset], src_reg*/ codegen_addbyte4(block, 0x89, 0x40 | base_reg | (src_reg << 3), 0x24, offset); } else { codegen_alloc_bytes(block, 4); - codegen_addbyte4(block, 0x48, 0x89, 0x40 | base_reg | (src_reg << 3), offset); + codegen_addbyte4(block, 0x48, 0x89, 0x40 | base_reg | (src_reg << 3), offset); /* MOV [base_reg + offset], src_reg*/ } } else fatal("MOV64_BASE_OFFSET_REG - offset %i\n", offset); @@ -912,14 +944,14 @@ host_x86_MOV32_BASE_OFFSET_IMM(codeblock_t *block, int base_reg, int offset, uin if (base_reg & 8) fatal("host_x86_MOV32_BASE_OFFSET_IMM reg & 8\n"); - if (offset >= -128 && offset < 127) { + if (offset >= -128 && offset <= 127) { if (base_reg == REG_RSP) { codegen_alloc_bytes(block, 8); - codegen_addbyte4(block, 0xc7, 0x40 | base_reg, 0x24, offset); + codegen_addbyte4(block, 0xc7, 0x40 | base_reg, 0x24, offset); /* MOV [RSP + offset], imm_data */ codegen_addlong(block, imm_data); } else { codegen_alloc_bytes(block, 7); - codegen_addbyte3(block, 0xc7, 0x40 | base_reg, offset); + codegen_addbyte3(block, 0xc7, 0x40 | base_reg, offset); /* MOV [base_reg + offset], src_reg*/ codegen_addlong(block, imm_data); } } else @@ -1084,16 +1116,16 @@ void host_x86_MOVZX_REG_ABS_16_8(codeblock_t *block, int dst_reg, void *p) { int64_t offset = (uintptr_t) p - (((uintptr_t) &cpu_state) + 128); - int64_t ram_offset = (uintptr_t) p - (uintptr_t) ram; + int64_t ram_offset = (uintptr_t) p - (((uintptr_t) ram) + 2147483648ULL); if (dst_reg & 8) fatal("host_x86_MOVZX_REG_ABS_16_8 - bad reg\n"); - if (offset >= -128 && offset < 127) { + if (offset >= -128 && offset <= 127) { codegen_alloc_bytes(block, 5); codegen_addbyte(block, 0x66); codegen_addbyte4(block, 0x0f, 0xb6, 0x45 | ((dst_reg & 7) << 3), offset); /*MOVZX dst_reg, offset[RBP]*/ - } else if ((ram_offset < (1ULL << 32)) && (block->flags & CODEBLOCK_NO_IMMEDIATES)) { + } else if ((ram_offset >= -2147483648LL) && (ram_offset <= 2147483647LL) && (block->flags & CODEBLOCK_NO_IMMEDIATES)) { codegen_alloc_bytes(block, 10); codegen_addbyte2(block, 0x66, 0x41); codegen_addbyte4(block, 0x0f, 0xb6, 0x84 | ((dst_reg & 7) << 3), 0x24); /*MOVZX dst_reg, ram_offset[R12]*/ @@ -1111,14 +1143,14 @@ void host_x86_MOVZX_REG_ABS_32_8(codeblock_t *block, int dst_reg, void *p) { int64_t offset = (uintptr_t) p - (((uintptr_t) &cpu_state) + 128); - int64_t ram_offset = (uintptr_t) p - (uintptr_t) ram; + int64_t ram_offset = (uintptr_t) p - (((uintptr_t) ram) + 2147483648ULL); #if 0 if (dst_reg & 8) fatal("host_x86_MOVZX_REG_ABS_32_8 - bad reg\n"); #endif - if (offset >= -128 && offset < 127) { + if (offset >= -128 && offset <= 127) { if (dst_reg & 8) { codegen_alloc_bytes(block, 5); codegen_addbyte(block, 0x44); @@ -1127,7 +1159,7 @@ host_x86_MOVZX_REG_ABS_32_8(codeblock_t *block, int dst_reg, void *p) codegen_alloc_bytes(block, 4); codegen_addbyte4(block, 0x0f, 0xb6, 0x45 | ((dst_reg & 7) << 3), offset); /*MOVZX dst_reg, offset[RBP]*/ } - } else if ((ram_offset < (1ULL << 32)) && (block->flags & CODEBLOCK_NO_IMMEDIATES)) { + } else if ((ram_offset >= -2147483648LL) && (ram_offset <= 2147483647LL) && (block->flags & CODEBLOCK_NO_IMMEDIATES)) { if (dst_reg & 8) fatal("host_x86_MOVZX_REG_ABS_32_8 - bad reg\n"); @@ -1150,15 +1182,15 @@ void host_x86_MOVZX_REG_ABS_32_16(codeblock_t *block, int dst_reg, void *p) { int64_t offset = (uintptr_t) p - (((uintptr_t) &cpu_state) + 128); - int64_t ram_offset = (uintptr_t) p - (uintptr_t) ram; + int64_t ram_offset = (uintptr_t) p - (((uintptr_t) ram) + 2147483648ULL); if (dst_reg & 8) fatal("host_x86_MOVZX_REG_ABS_32_16 - bad reg\n"); - if (offset >= -128 && offset < 127) { + if (offset >= -128 && offset <= 127) { codegen_alloc_bytes(block, 4); codegen_addbyte4(block, 0x0f, 0xb7, 0x45 | ((dst_reg & 7) << 3), offset); /*MOVZX dst_reg, offset[RBP]*/ - } else if ((ram_offset < (1ULL << 32)) && (block->flags & CODEBLOCK_NO_IMMEDIATES)) { + } else if ((ram_offset >= -2147483648LL) && (ram_offset <= 2147483647LL) && (block->flags & CODEBLOCK_NO_IMMEDIATES)) { codegen_alloc_bytes(block, 9); codegen_addbyte(block, 0x41); codegen_addbyte4(block, 0x0f, 0xb7, 0x84 | ((dst_reg & 7) << 3), 0x24); /*MOVZX dst_reg, ram_offset[R12]*/ diff --git a/src/codegen_new/codegen_backend_x86-64_uops.c b/src/codegen_new/codegen_backend_x86-64_uops.c index 46af68e75..655896b54 100644 --- a/src/codegen_new/codegen_backend_x86-64_uops.c +++ b/src/codegen_new/codegen_backend_x86-64_uops.c @@ -997,8 +997,12 @@ codegen_MEM_LOAD_REG(codeblock_t *block, uop_t *uop) int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); host_x86_LEA_REG_REG(block, REG_ESI, seg_reg, addr_reg); - if (uop->imm_data) + if (uop->imm_data) { host_x86_ADD32_REG_IMM(block, REG_ESI, uop->imm_data); + if (uop->is_a16) { + host_x86_AND32_REG_IMM(block, REG_ESI, 0x0000ffff); + } + } if (REG_IS_B(dest_size)) { host_x86_CALL(block, codegen_mem_load_byte); } else if (REG_IS_W(dest_size)) { diff --git a/src/codegen_new/codegen_backend_x86_uops.c b/src/codegen_new/codegen_backend_x86_uops.c index cd79b9b47..02c441234 100644 --- a/src/codegen_new/codegen_backend_x86_uops.c +++ b/src/codegen_new/codegen_backend_x86_uops.c @@ -981,8 +981,12 @@ codegen_MEM_LOAD_REG(codeblock_t *block, uop_t *uop) int dest_size = IREG_GET_SIZE(uop->dest_reg_a_real); host_x86_LEA_REG_REG(block, REG_ESI, seg_reg, addr_reg); - if (uop->imm_data) + if (uop->imm_data) { host_x86_ADD32_REG_IMM(block, REG_ESI, uop->imm_data); + if (uop->is_a16) { + host_x86_AND32_REG_IMM(block, REG_ESI, 0x0000ffff); + } + } if (REG_IS_B(dest_size)) { host_x86_CALL(block, codegen_mem_load_byte); } else if (REG_IS_W(dest_size)) { diff --git a/src/codegen_new/codegen_block.c b/src/codegen_new/codegen_block.c index a8ea0e06e..ff82384be 100644 --- a/src/codegen_new/codegen_block.c +++ b/src/codegen_new/codegen_block.c @@ -217,6 +217,7 @@ block_free_list_get(void) void codegen_init(void) { + codegen_check_regs(); codegen_allocator_init(); codegen_backend_init(); diff --git a/src/codegen_new/codegen_ir.c b/src/codegen_new/codegen_ir.c index 6345bbe86..ed8ae051f 100644 --- a/src/codegen_new/codegen_ir.c +++ b/src/codegen_new/codegen_ir.c @@ -2,6 +2,7 @@ #include <86box/86box.h> #include "cpu.h" #include <86box/mem.h> +#include <86box/plat_unused.h> #include "codegen.h" #include "codegen_allocator.h" diff --git a/src/codegen_new/codegen_ir_defs.h b/src/codegen_new/codegen_ir_defs.h index 26a1c3cb4..d55e57f3d 100644 --- a/src/codegen_new/codegen_ir_defs.h +++ b/src/codegen_new/codegen_ir_defs.h @@ -340,6 +340,7 @@ typedef struct uop_t { void *p; ir_host_reg_t dest_reg_a_real; ir_host_reg_t src_reg_a_real, src_reg_b_real, src_reg_c_real; + int is_a16; int jump_dest_uop; int jump_list_next; void *jump_dest; @@ -364,6 +365,8 @@ uop_alloc(ir_data_t *ir, uint32_t uop_type) uop = &ir->uops[ir->wr_pos++]; + uop->is_a16 = 0; + uop->dest_reg_a = invalid_ir_reg; uop->src_reg_a = invalid_ir_reg; uop->src_reg_b = invalid_ir_reg; @@ -410,7 +413,7 @@ uop_gen_reg_src1(uint32_t uop_type, ir_data_t *ir, int src_reg_a) } static inline void -uop_gen_reg_src1_arg(uint32_t uop_type, ir_data_t *ir, int arg, int src_reg_a) +uop_gen_reg_src1_arg(uint32_t uop_type, ir_data_t *ir, UNUSED(int arg), int src_reg_a) { uop_t *uop = uop_alloc(ir, uop_type); @@ -488,8 +491,14 @@ uop_gen_reg_dst_src2_imm(uint32_t uop_type, ir_data_t *ir, int dest_reg, int src uop_t *uop = uop_alloc(ir, uop_type); uop->type = uop_type; + uop->is_a16 = 0; uop->src_reg_a = codegen_reg_read(src_reg_a); - uop->src_reg_b = codegen_reg_read(src_reg_b); + if (src_reg_b == IREG_eaa16) { + uop->src_reg_b = codegen_reg_read(IREG_eaaddr); + uop->is_a16 = 1; + } else + uop->src_reg_b = codegen_reg_read(src_reg_b); + uop->is_a16 = 0; uop->dest_reg_a = codegen_reg_write(dest_reg, ir->wr_pos - 1); uop->imm_data = imm; } diff --git a/src/codegen_new/codegen_ops.c b/src/codegen_new/codegen_ops.c index 59e148659..bb7d1f3ee 100644 --- a/src/codegen_new/codegen_ops.c +++ b/src/codegen_new/codegen_ops.c @@ -2,6 +2,7 @@ #include <86box/86box.h> #include "cpu.h" #include <86box/mem.h> +#include <86box/plat_unused.h> #include "codegen.h" #include "codegen_ir.h" diff --git a/src/codegen_new/codegen_ops_3dnow.c b/src/codegen_new/codegen_ops_3dnow.c index 8b4d471ba..e827d0d27 100644 --- a/src/codegen_new/codegen_ops_3dnow.c +++ b/src/codegen_new/codegen_ops_3dnow.c @@ -16,28 +16,29 @@ #include "codegen_ops_3dnow.h" #include "codegen_ops_helpers.h" -#define ropParith(func) \ - uint32_t rop##func(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ - { \ - int dest_reg = (fetchdat >> 3) & 7; \ - \ - uop_MMX_ENTER(ir); \ - codegen_mark_code_present(block, cs + op_pc, 1); \ - if ((fetchdat & 0xc0) == 0xc0) { \ - int src_reg = fetchdat & 7; \ - uop_##func(ir, IREG_MM(dest_reg), IREG_MM(dest_reg), IREG_MM(src_reg)); \ - } else { \ - x86seg *target_seg; \ - \ - uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ - target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ - codegen_check_seg_read(block, ir, target_seg); \ - uop_MEM_LOAD_REG(ir, IREG_temp0_Q, ireg_seg_base(target_seg), IREG_eaaddr); \ - uop_##func(ir, IREG_MM(dest_reg), IREG_MM(dest_reg), IREG_temp0_Q); \ - } \ - \ - codegen_mark_code_present(block, cs + op_pc + 1, 1); \ - return op_pc + 2; \ +#define ropParith(func) \ + uint32_t rop##func(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), \ + uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + { \ + int dest_reg = (fetchdat >> 3) & 7; \ + \ + uop_MMX_ENTER(ir); \ + codegen_mark_code_present(block, cs + op_pc, 1); \ + if ((fetchdat & 0xc0) == 0xc0) { \ + int src_reg = fetchdat & 7; \ + uop_##func(ir, IREG_MM(dest_reg), IREG_MM(dest_reg), IREG_MM(src_reg)); \ + } else { \ + x86seg *target_seg; \ + \ + uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ + target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ + codegen_check_seg_read(block, ir, target_seg); \ + uop_MEM_LOAD_REG(ir, IREG_temp0_Q, ireg_seg_base(target_seg), IREG_eaaddr); \ + uop_##func(ir, IREG_MM(dest_reg), IREG_MM(dest_reg), IREG_temp0_Q); \ + } \ + \ + codegen_mark_code_present(block, cs + op_pc + 1, 1); \ + return op_pc + 2; \ } // clang-format off @@ -192,7 +193,7 @@ ropPFRSQRT(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t f } uint32_t -ropPFRSQIT1(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPFRSQIT1(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_MMX_ENTER(ir); diff --git a/src/codegen_new/codegen_ops_arith.c b/src/codegen_new/codegen_ops_arith.c index 9e136ace5..c899c13d8 100644 --- a/src/codegen_new/codegen_ops_arith.c +++ b/src/codegen_new/codegen_ops_arith.c @@ -22,7 +22,7 @@ get_cf(ir_data_t *ir, int dest_reg) } uint32_t -ropADC_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropADC_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint8_t imm_data = fastreadb(cs + op_pc); @@ -39,7 +39,7 @@ ropADC_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ return op_pc + 1; } uint32_t -ropADC_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropADC_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t imm_data = fastreadw(cs + op_pc); @@ -274,7 +274,7 @@ ropADC_l_rmw(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t } uint32_t -ropADD_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropADD_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint8_t imm_data = fastreadb(cs + op_pc); @@ -289,7 +289,7 @@ ropADD_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ return op_pc + 1; } uint32_t -ropADD_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropADD_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t imm_data = fastreadw(cs + op_pc); @@ -511,7 +511,7 @@ ropADD_l_rmw(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t } uint32_t -ropCMP_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropCMP_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint8_t imm_data = fastreadb(cs + op_pc); @@ -526,7 +526,7 @@ ropCMP_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ return op_pc + 1; } uint32_t -ropCMP_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropCMP_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t imm_data = fastreadw(cs + op_pc); @@ -734,7 +734,7 @@ ropCMP_l_rmw(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t } uint32_t -ropSBB_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropSBB_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint8_t imm_data = fastreadb(cs + op_pc); @@ -751,7 +751,7 @@ ropSBB_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ return op_pc + 1; } uint32_t -ropSBB_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropSBB_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t imm_data = fastreadw(cs + op_pc); @@ -988,7 +988,7 @@ ropSBB_l_rmw(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t } uint32_t -ropSUB_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropSUB_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint8_t imm_data = fastreadb(cs + op_pc); @@ -1003,7 +1003,7 @@ ropSUB_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ return op_pc + 1; } uint32_t -ropSUB_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropSUB_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t imm_data = fastreadw(cs + op_pc); @@ -2293,7 +2293,7 @@ rebuild_c(ir_data_t *ir) } uint32_t -ropINC_r16(UNUSED(UNUSED(codeblock_t *block)), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropINC_r16(UNUSED(UNUSED(codeblock_t *block)), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { rebuild_c(ir); @@ -2307,7 +2307,7 @@ ropINC_r16(UNUSED(UNUSED(codeblock_t *block)), ir_data_t *ir, UNUSED(uint8_t opc return op_pc; } uint32_t -ropINC_r32(UNUSED(UNUSED(codeblock_t *block)), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropINC_r32(UNUSED(UNUSED(codeblock_t *block)), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { rebuild_c(ir); @@ -2322,7 +2322,7 @@ ropINC_r32(UNUSED(UNUSED(codeblock_t *block)), ir_data_t *ir, UNUSED(uint8_t opc } uint32_t -ropDEC_r16(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropDEC_r16(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { rebuild_c(ir); @@ -2336,7 +2336,7 @@ ropDEC_r16(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, uint32_t f return op_pc; } uint32_t -ropDEC_r32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropDEC_r32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { rebuild_c(ir); diff --git a/src/codegen_new/codegen_ops_branch.c b/src/codegen_new/codegen_ops_branch.c index cedb54177..2039b6d79 100644 --- a/src/codegen_new/codegen_ops_branch.c +++ b/src/codegen_new/codegen_ops_branch.c @@ -815,43 +815,59 @@ ropJNLE_common(codeblock_t *block, ir_data_t *ir, uint32_t dest_addr, uint32_t n } } -#define ropJ(cond) \ - uint32_t ropJ##cond##_8(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ - { \ - uint32_t offset = (int32_t) (int8_t) fastreadb(cs + op_pc); \ - uint32_t dest_addr = op_pc + 1 + offset; \ - int ret; \ - \ - if (!(op_32 & 0x100)) \ - dest_addr &= 0xffff; \ - ret = ropJ##cond##_common(block, ir, dest_addr, op_pc + 1); \ - \ - codegen_mark_code_present(block, cs + op_pc, 1); \ - return ret ? dest_addr : (op_pc + 1); \ - } \ - uint32_t ropJ##cond##_16(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ - { \ - uint32_t offset = (int32_t) (int16_t) fastreadw(cs + op_pc); \ - uint32_t dest_addr = (op_pc + 2 + offset) & 0xffff; \ - int ret; \ - \ - ret = ropJ##cond##_common(block, ir, dest_addr, op_pc + 2); \ - \ - codegen_mark_code_present(block, cs + op_pc, 2); \ - return ret ? dest_addr : (op_pc + 2); \ - } \ - uint32_t ropJ##cond##_32(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ - { \ - uint32_t offset = fastreadl(cs + op_pc); \ - uint32_t dest_addr = op_pc + 4 + offset; \ - int ret; \ - \ - ret = ropJ##cond##_common(block, ir, dest_addr, op_pc + 4); \ - \ - codegen_mark_code_present(block, cs + op_pc, 4); \ - return ret ? dest_addr : (op_pc + 4); \ +#define ropJ(cond) \ + uint32_t ropJ##cond##_8(codeblock_t *block, \ + ir_data_t *ir, \ + UNUSED(uint8_t opcode), \ + UNUSED(uint32_t fetchdat), \ + uint32_t op_32, \ + uint32_t op_pc) \ + { \ + uint32_t offset = (int32_t) (int8_t) fastreadb(cs + op_pc); \ + uint32_t dest_addr = op_pc + 1 + offset; \ + int ret; \ + \ + if (!(op_32 & 0x100)) \ + dest_addr &= 0xffff; \ + ret = ropJ##cond##_common(block, ir, dest_addr, op_pc + 1); \ + \ + codegen_mark_code_present(block, cs + op_pc, 1); \ + return ret ? dest_addr : (op_pc + 1); \ + } \ + uint32_t ropJ##cond##_16(codeblock_t *block, \ + ir_data_t *ir, \ + UNUSED(uint8_t opcode), \ + UNUSED(uint32_t fetchdat), \ + UNUSED(uint32_t op_32), \ + uint32_t op_pc) \ + { \ + uint32_t offset = (int32_t) (int16_t) fastreadw(cs + op_pc); \ + uint32_t dest_addr = (op_pc + 2 + offset) & 0xffff; \ + int ret; \ + \ + ret = ropJ##cond##_common(block, ir, dest_addr, op_pc + 2); \ + \ + codegen_mark_code_present(block, cs + op_pc, 2); \ + return ret ? dest_addr : (op_pc + 2); \ + } \ + uint32_t ropJ##cond##_32(codeblock_t *block, \ + ir_data_t *ir, \ + UNUSED(uint8_t opcode), \ + UNUSED(uint32_t fetchdat), \ + UNUSED(uint32_t op_32), \ + uint32_t op_pc) \ + { \ + uint32_t offset = fastreadl(cs + op_pc); \ + uint32_t dest_addr = op_pc + 4 + offset; \ + int ret; \ + \ + ret = ropJ##cond##_common(block, ir, dest_addr, op_pc + 4); \ + \ + codegen_mark_code_present(block, cs + op_pc, 4); \ + return ret ? dest_addr : (op_pc + 4); \ } +// clang-format off ropJ(O) ropJ(NO) ropJ(B) @@ -868,9 +884,10 @@ ropJ(L) ropJ(NL) ropJ(LE) ropJ(NLE) +// clang-format on uint32_t -ropJCXZ(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) +ropJCXZ(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc) { uint32_t offset = (int32_t) (int8_t) fastreadb(cs + op_pc); uint32_t dest_addr = op_pc + 1 + offset; @@ -892,7 +909,7 @@ ropJCXZ(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetc } uint32_t -ropLOOP(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) +ropLOOP(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc) { uint32_t offset = (int32_t) (int8_t) fastreadb(cs + op_pc); uint32_t dest_addr = op_pc + 1 + offset; @@ -932,7 +949,7 @@ ropLOOP(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetc } uint32_t -ropLOOPE(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) +ropLOOPE(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc) { uint32_t offset = (int32_t) (int8_t) fastreadb(cs + op_pc); uint32_t dest_addr = op_pc + 1 + offset; @@ -965,7 +982,7 @@ ropLOOPE(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fet return op_pc + 1; } uint32_t -ropLOOPNE(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) +ropLOOPNE(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc) { uint32_t offset = (int32_t) (int8_t) fastreadb(cs + op_pc); uint32_t dest_addr = op_pc + 1 + offset; diff --git a/src/codegen_new/codegen_ops_fpu_arith.c b/src/codegen_new/codegen_ops_fpu_arith.c index a7b5290f4..1568852df 100644 --- a/src/codegen_new/codegen_ops_fpu_arith.c +++ b/src/codegen_new/codegen_ops_fpu_arith.c @@ -79,7 +79,7 @@ ropFCOMP(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fet return op_pc; } uint32_t -ropFCOMPP(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropFCOMPP(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_FP_ENTER(ir); uop_FCOM(ir, IREG_temp0_W, IREG_ST(0), IREG_ST(1)); @@ -289,7 +289,7 @@ ropFUCOMP(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fe return op_pc; } uint32_t -ropFUCOMPP(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropFUCOMPP(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_FP_ENTER(ir); uop_FCOM(ir, IREG_temp0_W, IREG_ST(0), IREG_ST(1)); @@ -300,131 +300,139 @@ ropFUCOMPP(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t f return op_pc; } -#define ropF_arith_mem(name, load_uop) \ - uint32_t ropFADD##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ - { \ - x86seg *target_seg; \ - \ - if ((cpu_state.npxc >> 10) & 3) \ - return 0; \ - uop_FP_ENTER(ir); \ - uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ - op_pc--; \ - target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ - codegen_check_seg_read(block, ir, target_seg); \ - load_uop(ir, IREG_temp0_D, ireg_seg_base(target_seg), IREG_eaaddr); \ - uop_FADD(ir, IREG_ST(0), IREG_ST(0), IREG_temp0_D); \ - uop_MOV_IMM(ir, IREG_tag(0), TAG_VALID); \ - \ - return op_pc + 1; \ - } \ - uint32_t ropFCOM##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ - { \ - x86seg *target_seg; \ - \ - uop_FP_ENTER(ir); \ - uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ - op_pc--; \ - target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ - codegen_check_seg_read(block, ir, target_seg); \ - load_uop(ir, IREG_temp0_D, ireg_seg_base(target_seg), IREG_eaaddr); \ - uop_FCOM(ir, IREG_temp1_W, IREG_ST(0), IREG_temp0_D); \ - uop_AND_IMM(ir, IREG_NPXS, IREG_NPXS, ~(FPU_SW_C0 | FPU_SW_C2 | FPU_SW_C3)); \ - uop_OR(ir, IREG_NPXS, IREG_NPXS, IREG_temp1_W); \ - \ - return op_pc + 1; \ - } \ - uint32_t ropFCOMP##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ - { \ - x86seg *target_seg; \ - \ - uop_FP_ENTER(ir); \ - uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ - op_pc--; \ - target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ - codegen_check_seg_read(block, ir, target_seg); \ - load_uop(ir, IREG_temp0_D, ireg_seg_base(target_seg), IREG_eaaddr); \ - uop_FCOM(ir, IREG_temp1_W, IREG_ST(0), IREG_temp0_D); \ - uop_AND_IMM(ir, IREG_NPXS, IREG_NPXS, ~(FPU_SW_C0 | FPU_SW_C2 | FPU_SW_C3)); \ - uop_OR(ir, IREG_NPXS, IREG_NPXS, IREG_temp1_W); \ - fpu_POP(block, ir); \ - \ - return op_pc + 1; \ - } \ - uint32_t ropFDIV##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ - { \ - x86seg *target_seg; \ - \ - uop_FP_ENTER(ir); \ - uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ - op_pc--; \ - target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ - codegen_check_seg_read(block, ir, target_seg); \ - load_uop(ir, IREG_temp0_D, ireg_seg_base(target_seg), IREG_eaaddr); \ - uop_FDIV(ir, IREG_ST(0), IREG_ST(0), IREG_temp0_D); \ - uop_MOV_IMM(ir, IREG_tag(0), TAG_VALID); \ - \ - return op_pc + 1; \ - } \ - uint32_t ropFDIVR##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ - { \ - x86seg *target_seg; \ - \ - uop_FP_ENTER(ir); \ - uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ - op_pc--; \ - target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ - codegen_check_seg_read(block, ir, target_seg); \ - load_uop(ir, IREG_temp0_D, ireg_seg_base(target_seg), IREG_eaaddr); \ - uop_FDIV(ir, IREG_ST(0), IREG_temp0_D, IREG_ST(0)); \ - uop_MOV_IMM(ir, IREG_tag(0), TAG_VALID); \ - \ - return op_pc + 1; \ - } \ - uint32_t ropFMUL##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ - { \ - x86seg *target_seg; \ - \ - uop_FP_ENTER(ir); \ - uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ - op_pc--; \ - target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ - codegen_check_seg_read(block, ir, target_seg); \ - load_uop(ir, IREG_temp0_D, ireg_seg_base(target_seg), IREG_eaaddr); \ - uop_FMUL(ir, IREG_ST(0), IREG_ST(0), IREG_temp0_D); \ - uop_MOV_IMM(ir, IREG_tag(0), TAG_VALID); \ - \ - return op_pc + 1; \ - } \ - uint32_t ropFSUB##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ - { \ - x86seg *target_seg; \ - \ - uop_FP_ENTER(ir); \ - uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ - op_pc--; \ - target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ - codegen_check_seg_read(block, ir, target_seg); \ - load_uop(ir, IREG_temp0_D, ireg_seg_base(target_seg), IREG_eaaddr); \ - uop_FSUB(ir, IREG_ST(0), IREG_ST(0), IREG_temp0_D); \ - uop_MOV_IMM(ir, IREG_tag(0), TAG_VALID); \ - \ - return op_pc + 1; \ - } \ - uint32_t ropFSUBR##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ - { \ - x86seg *target_seg; \ - \ - uop_FP_ENTER(ir); \ - uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ - op_pc--; \ - target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ - codegen_check_seg_read(block, ir, target_seg); \ - load_uop(ir, IREG_temp0_D, ireg_seg_base(target_seg), IREG_eaaddr); \ - uop_FSUB(ir, IREG_ST(0), IREG_temp0_D, IREG_ST(0)); \ - uop_MOV_IMM(ir, IREG_tag(0), TAG_VALID); \ - \ - return op_pc + 1; \ +#define ropF_arith_mem(name, load_uop) \ + uint32_t ropFADD##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), \ + uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + { \ + x86seg *target_seg; \ + \ + if ((cpu_state.npxc >> 10) & 3) \ + return 0; \ + uop_FP_ENTER(ir); \ + uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ + op_pc--; \ + target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ + codegen_check_seg_read(block, ir, target_seg); \ + load_uop(ir, IREG_temp0_D, ireg_seg_base(target_seg), IREG_eaaddr); \ + uop_FADD(ir, IREG_ST(0), IREG_ST(0), IREG_temp0_D); \ + uop_MOV_IMM(ir, IREG_tag(0), TAG_VALID); \ + \ + return op_pc + 1; \ + } \ + uint32_t ropFCOM##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), \ + uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + { \ + x86seg *target_seg; \ + \ + uop_FP_ENTER(ir); \ + uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ + op_pc--; \ + target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ + codegen_check_seg_read(block, ir, target_seg); \ + load_uop(ir, IREG_temp0_D, ireg_seg_base(target_seg), IREG_eaaddr); \ + uop_FCOM(ir, IREG_temp1_W, IREG_ST(0), IREG_temp0_D); \ + uop_AND_IMM(ir, IREG_NPXS, IREG_NPXS, ~(FPU_SW_C0 | FPU_SW_C2 | FPU_SW_C3)); \ + uop_OR(ir, IREG_NPXS, IREG_NPXS, IREG_temp1_W); \ + \ + return op_pc + 1; \ + } \ + uint32_t ropFCOMP##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), \ + uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + { \ + x86seg *target_seg; \ + \ + uop_FP_ENTER(ir); \ + uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ + op_pc--; \ + target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ + codegen_check_seg_read(block, ir, target_seg); \ + load_uop(ir, IREG_temp0_D, ireg_seg_base(target_seg), IREG_eaaddr); \ + uop_FCOM(ir, IREG_temp1_W, IREG_ST(0), IREG_temp0_D); \ + uop_AND_IMM(ir, IREG_NPXS, IREG_NPXS, ~(FPU_SW_C0 | FPU_SW_C2 | FPU_SW_C3)); \ + uop_OR(ir, IREG_NPXS, IREG_NPXS, IREG_temp1_W); \ + fpu_POP(block, ir); \ + \ + return op_pc + 1; \ + } \ + uint32_t ropFDIV##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), \ + uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + { \ + x86seg *target_seg; \ + \ + uop_FP_ENTER(ir); \ + uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ + op_pc--; \ + target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ + codegen_check_seg_read(block, ir, target_seg); \ + load_uop(ir, IREG_temp0_D, ireg_seg_base(target_seg), IREG_eaaddr); \ + uop_FDIV(ir, IREG_ST(0), IREG_ST(0), IREG_temp0_D); \ + uop_MOV_IMM(ir, IREG_tag(0), TAG_VALID); \ + \ + return op_pc + 1; \ + } \ + uint32_t ropFDIVR##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), \ + uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + { \ + x86seg *target_seg; \ + \ + uop_FP_ENTER(ir); \ + uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ + op_pc--; \ + target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ + codegen_check_seg_read(block, ir, target_seg); \ + load_uop(ir, IREG_temp0_D, ireg_seg_base(target_seg), IREG_eaaddr); \ + uop_FDIV(ir, IREG_ST(0), IREG_temp0_D, IREG_ST(0)); \ + uop_MOV_IMM(ir, IREG_tag(0), TAG_VALID); \ + \ + return op_pc + 1; \ + } \ + uint32_t ropFMUL##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), \ + uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + { \ + x86seg *target_seg; \ + \ + uop_FP_ENTER(ir); \ + uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ + op_pc--; \ + target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ + codegen_check_seg_read(block, ir, target_seg); \ + load_uop(ir, IREG_temp0_D, ireg_seg_base(target_seg), IREG_eaaddr); \ + uop_FMUL(ir, IREG_ST(0), IREG_ST(0), IREG_temp0_D); \ + uop_MOV_IMM(ir, IREG_tag(0), TAG_VALID); \ + \ + return op_pc + 1; \ + } \ + uint32_t ropFSUB##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), \ + uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + { \ + x86seg *target_seg; \ + \ + uop_FP_ENTER(ir); \ + uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ + op_pc--; \ + target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ + codegen_check_seg_read(block, ir, target_seg); \ + load_uop(ir, IREG_temp0_D, ireg_seg_base(target_seg), IREG_eaaddr); \ + uop_FSUB(ir, IREG_ST(0), IREG_ST(0), IREG_temp0_D); \ + uop_MOV_IMM(ir, IREG_tag(0), TAG_VALID); \ + \ + return op_pc + 1; \ + } \ + uint32_t ropFSUBR##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), \ + uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + { \ + x86seg *target_seg; \ + \ + uop_FP_ENTER(ir); \ + uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ + op_pc--; \ + target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ + codegen_check_seg_read(block, ir, target_seg); \ + load_uop(ir, IREG_temp0_D, ireg_seg_base(target_seg), IREG_eaaddr); \ + uop_FSUB(ir, IREG_ST(0), IREG_temp0_D, IREG_ST(0)); \ + uop_MOV_IMM(ir, IREG_tag(0), TAG_VALID); \ + \ + return op_pc + 1; \ } // clang-format off @@ -432,144 +440,154 @@ ropF_arith_mem(s, uop_MEM_LOAD_SINGLE) ropF_arith_mem(d, uop_MEM_LOAD_DOUBLE) // clang-format on -#define ropFI_arith_mem(name, temp_reg) \ - uint32_t ropFIADD##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ - { \ - x86seg *target_seg; \ - \ - uop_FP_ENTER(ir); \ - uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ - op_pc--; \ - target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ - codegen_check_seg_read(block, ir, target_seg); \ - uop_MEM_LOAD_REG(ir, temp_reg, ireg_seg_base(target_seg), IREG_eaaddr); \ - uop_MOV_DOUBLE_INT(ir, IREG_temp0_D, temp_reg); \ - uop_FADD(ir, IREG_ST(0), IREG_ST(0), IREG_temp0_D); \ - uop_MOV_IMM(ir, IREG_tag(0), TAG_VALID); \ - \ - return op_pc + 1; \ - } \ - uint32_t ropFICOM##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ - { \ - x86seg *target_seg; \ - \ - uop_FP_ENTER(ir); \ - uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ - op_pc--; \ - target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ - codegen_check_seg_read(block, ir, target_seg); \ - uop_MEM_LOAD_REG(ir, temp_reg, ireg_seg_base(target_seg), IREG_eaaddr); \ - uop_MOV_DOUBLE_INT(ir, IREG_temp0_D, temp_reg); \ - uop_FCOM(ir, IREG_temp1_W, IREG_ST(0), IREG_temp0_D); \ - uop_AND_IMM(ir, IREG_NPXS, IREG_NPXS, ~(FPU_SW_C0 | FPU_SW_C2 | FPU_SW_C3)); \ - uop_OR(ir, IREG_NPXS, IREG_NPXS, IREG_temp1_W); \ - \ - return op_pc + 1; \ - } \ - uint32_t ropFICOMP##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ - { \ - x86seg *target_seg; \ - \ - uop_FP_ENTER(ir); \ - uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ - op_pc--; \ - target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ - codegen_check_seg_read(block, ir, target_seg); \ - uop_MEM_LOAD_REG(ir, temp_reg, ireg_seg_base(target_seg), IREG_eaaddr); \ - uop_MOV_DOUBLE_INT(ir, IREG_temp0_D, temp_reg); \ - uop_FCOM(ir, IREG_temp1_W, IREG_ST(0), IREG_temp0_D); \ - uop_AND_IMM(ir, IREG_NPXS, IREG_NPXS, ~(FPU_SW_C0 | FPU_SW_C2 | FPU_SW_C3)); \ - uop_OR(ir, IREG_NPXS, IREG_NPXS, IREG_temp1_W); \ - fpu_POP(block, ir); \ - \ - return op_pc + 1; \ - } \ - uint32_t ropFIDIV##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ - { \ - x86seg *target_seg; \ - \ - uop_FP_ENTER(ir); \ - uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ - op_pc--; \ - target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ - codegen_check_seg_read(block, ir, target_seg); \ - uop_MEM_LOAD_REG(ir, temp_reg, ireg_seg_base(target_seg), IREG_eaaddr); \ - uop_MOV_DOUBLE_INT(ir, IREG_temp0_D, temp_reg); \ - uop_FDIV(ir, IREG_ST(0), IREG_ST(0), IREG_temp0_D); \ - uop_MOV_IMM(ir, IREG_tag(0), TAG_VALID); \ - \ - return op_pc + 1; \ - } \ - uint32_t ropFIDIVR##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ - { \ - x86seg *target_seg; \ - \ - uop_FP_ENTER(ir); \ - uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ - op_pc--; \ - target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ - codegen_check_seg_read(block, ir, target_seg); \ - uop_MEM_LOAD_REG(ir, temp_reg, ireg_seg_base(target_seg), IREG_eaaddr); \ - uop_MOV_DOUBLE_INT(ir, IREG_temp0_D, temp_reg); \ - uop_FDIV(ir, IREG_ST(0), IREG_temp0_D, IREG_ST(0)); \ - uop_MOV_IMM(ir, IREG_tag(0), TAG_VALID); \ - \ - return op_pc + 1; \ - } \ - uint32_t ropFIMUL##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ - { \ - x86seg *target_seg; \ - \ - uop_FP_ENTER(ir); \ - uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ - op_pc--; \ - target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ - codegen_check_seg_read(block, ir, target_seg); \ - uop_MEM_LOAD_REG(ir, temp_reg, ireg_seg_base(target_seg), IREG_eaaddr); \ - uop_MOV_DOUBLE_INT(ir, IREG_temp0_D, temp_reg); \ - uop_FMUL(ir, IREG_ST(0), IREG_ST(0), IREG_temp0_D); \ - uop_MOV_IMM(ir, IREG_tag(0), TAG_VALID); \ - \ - return op_pc + 1; \ - } \ - uint32_t ropFISUB##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ - { \ - x86seg *target_seg; \ - \ - uop_FP_ENTER(ir); \ - uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ - op_pc--; \ - target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ - codegen_check_seg_read(block, ir, target_seg); \ - uop_MEM_LOAD_REG(ir, temp_reg, ireg_seg_base(target_seg), IREG_eaaddr); \ - uop_MOV_DOUBLE_INT(ir, IREG_temp0_D, temp_reg); \ - uop_FSUB(ir, IREG_ST(0), IREG_ST(0), IREG_temp0_D); \ - uop_MOV_IMM(ir, IREG_tag(0), TAG_VALID); \ - \ - return op_pc + 1; \ - } \ - uint32_t ropFISUBR##name(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ - { \ - x86seg *target_seg; \ - \ - uop_FP_ENTER(ir); \ - uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ - op_pc--; \ - target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ - codegen_check_seg_read(block, ir, target_seg); \ - uop_MEM_LOAD_REG(ir, temp_reg, ireg_seg_base(target_seg), IREG_eaaddr); \ - uop_MOV_DOUBLE_INT(ir, IREG_temp0_D, temp_reg); \ - uop_FSUB(ir, IREG_ST(0), IREG_temp0_D, IREG_ST(0)); \ - uop_MOV_IMM(ir, IREG_tag(0), TAG_VALID); \ - \ - return op_pc + 1; \ +#define ropFI_arith_mem(name, temp_reg) \ + uint32_t ropFIADD##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), \ + uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + { \ + x86seg *target_seg; \ + \ + uop_FP_ENTER(ir); \ + uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ + op_pc--; \ + target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ + codegen_check_seg_read(block, ir, target_seg); \ + uop_MEM_LOAD_REG(ir, temp_reg, ireg_seg_base(target_seg), IREG_eaaddr); \ + uop_MOV_DOUBLE_INT(ir, IREG_temp0_D, temp_reg); \ + uop_FADD(ir, IREG_ST(0), IREG_ST(0), IREG_temp0_D); \ + uop_MOV_IMM(ir, IREG_tag(0), TAG_VALID); \ + \ + return op_pc + 1; \ + } \ + uint32_t ropFICOM##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), \ + uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + { \ + x86seg *target_seg; \ + \ + uop_FP_ENTER(ir); \ + uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ + op_pc--; \ + target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ + codegen_check_seg_read(block, ir, target_seg); \ + uop_MEM_LOAD_REG(ir, temp_reg, ireg_seg_base(target_seg), IREG_eaaddr); \ + uop_MOV_DOUBLE_INT(ir, IREG_temp0_D, temp_reg); \ + uop_FCOM(ir, IREG_temp1_W, IREG_ST(0), IREG_temp0_D); \ + uop_AND_IMM(ir, IREG_NPXS, IREG_NPXS, ~(FPU_SW_C0 | FPU_SW_C2 | FPU_SW_C3)); \ + uop_OR(ir, IREG_NPXS, IREG_NPXS, IREG_temp1_W); \ + \ + return op_pc + 1; \ + } \ + uint32_t ropFICOMP##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), \ + uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + { \ + x86seg *target_seg; \ + \ + uop_FP_ENTER(ir); \ + uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ + op_pc--; \ + target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ + codegen_check_seg_read(block, ir, target_seg); \ + uop_MEM_LOAD_REG(ir, temp_reg, ireg_seg_base(target_seg), IREG_eaaddr); \ + uop_MOV_DOUBLE_INT(ir, IREG_temp0_D, temp_reg); \ + uop_FCOM(ir, IREG_temp1_W, IREG_ST(0), IREG_temp0_D); \ + uop_AND_IMM(ir, IREG_NPXS, IREG_NPXS, ~(FPU_SW_C0 | FPU_SW_C2 | FPU_SW_C3)); \ + uop_OR(ir, IREG_NPXS, IREG_NPXS, IREG_temp1_W); \ + fpu_POP(block, ir); \ + \ + return op_pc + 1; \ + } \ + uint32_t ropFIDIV##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), \ + uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + { \ + x86seg *target_seg; \ + \ + uop_FP_ENTER(ir); \ + uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ + op_pc--; \ + target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ + codegen_check_seg_read(block, ir, target_seg); \ + uop_MEM_LOAD_REG(ir, temp_reg, ireg_seg_base(target_seg), IREG_eaaddr); \ + uop_MOV_DOUBLE_INT(ir, IREG_temp0_D, temp_reg); \ + uop_FDIV(ir, IREG_ST(0), IREG_ST(0), IREG_temp0_D); \ + uop_MOV_IMM(ir, IREG_tag(0), TAG_VALID); \ + \ + return op_pc + 1; \ + } \ + uint32_t ropFIDIVR##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), \ + uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + { \ + x86seg *target_seg; \ + \ + uop_FP_ENTER(ir); \ + uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ + op_pc--; \ + target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ + codegen_check_seg_read(block, ir, target_seg); \ + uop_MEM_LOAD_REG(ir, temp_reg, ireg_seg_base(target_seg), IREG_eaaddr); \ + uop_MOV_DOUBLE_INT(ir, IREG_temp0_D, temp_reg); \ + uop_FDIV(ir, IREG_ST(0), IREG_temp0_D, IREG_ST(0)); \ + uop_MOV_IMM(ir, IREG_tag(0), TAG_VALID); \ + \ + return op_pc + 1; \ + } \ + uint32_t ropFIMUL##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), \ + uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + { \ + x86seg *target_seg; \ + \ + uop_FP_ENTER(ir); \ + uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ + op_pc--; \ + target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ + codegen_check_seg_read(block, ir, target_seg); \ + uop_MEM_LOAD_REG(ir, temp_reg, ireg_seg_base(target_seg), IREG_eaaddr); \ + uop_MOV_DOUBLE_INT(ir, IREG_temp0_D, temp_reg); \ + uop_FMUL(ir, IREG_ST(0), IREG_ST(0), IREG_temp0_D); \ + uop_MOV_IMM(ir, IREG_tag(0), TAG_VALID); \ + \ + return op_pc + 1; \ + } \ + uint32_t ropFISUB##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), \ + uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + { \ + x86seg *target_seg; \ + \ + uop_FP_ENTER(ir); \ + uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ + op_pc--; \ + target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ + codegen_check_seg_read(block, ir, target_seg); \ + uop_MEM_LOAD_REG(ir, temp_reg, ireg_seg_base(target_seg), IREG_eaaddr); \ + uop_MOV_DOUBLE_INT(ir, IREG_temp0_D, temp_reg); \ + uop_FSUB(ir, IREG_ST(0), IREG_ST(0), IREG_temp0_D); \ + uop_MOV_IMM(ir, IREG_tag(0), TAG_VALID); \ + \ + return op_pc + 1; \ + } \ + uint32_t ropFISUBR##name(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), \ + uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + { \ + x86seg *target_seg; \ + \ + uop_FP_ENTER(ir); \ + uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ + op_pc--; \ + target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ + codegen_check_seg_read(block, ir, target_seg); \ + uop_MEM_LOAD_REG(ir, temp_reg, ireg_seg_base(target_seg), IREG_eaaddr); \ + uop_MOV_DOUBLE_INT(ir, IREG_temp0_D, temp_reg); \ + uop_FSUB(ir, IREG_ST(0), IREG_temp0_D, IREG_ST(0)); \ + uop_MOV_IMM(ir, IREG_tag(0), TAG_VALID); \ + \ + return op_pc + 1; \ } +// clang-format off ropFI_arith_mem(l, IREG_temp0) ropFI_arith_mem(w, IREG_temp0_W) +// clang-format on uint32_t -ropFABS(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropFABS(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_FP_ENTER(ir); uop_FABS(ir, IREG_ST(0), IREG_ST(0)); @@ -579,7 +597,7 @@ ropFABS(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint3 } uint32_t -ropFCHS(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropFCHS(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_FP_ENTER(ir); uop_FCHS(ir, IREG_ST(0), IREG_ST(0)); @@ -588,7 +606,7 @@ ropFCHS(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint3 return op_pc; } uint32_t -ropFSQRT(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropFSQRT(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_FP_ENTER(ir); uop_FSQRT(ir, IREG_ST(0), IREG_ST(0)); @@ -597,7 +615,7 @@ ropFSQRT(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint return op_pc; } uint32_t -ropFTST(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropFTST(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_FP_ENTER(ir); uop_FTST(ir, IREG_temp0_W, IREG_ST(0)); diff --git a/src/codegen_new/codegen_ops_fpu_constant.c b/src/codegen_new/codegen_ops_fpu_constant.c index a91d675c5..6ec2f6888 100644 --- a/src/codegen_new/codegen_ops_fpu_constant.c +++ b/src/codegen_new/codegen_ops_fpu_constant.c @@ -19,7 +19,7 @@ #include "codegen_ops_helpers.h" uint32_t -ropFLD1(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropFLD1(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_FP_ENTER(ir); uop_MOV_IMM(ir, IREG_temp0, 1); @@ -30,7 +30,7 @@ ropFLD1(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetc return op_pc; } uint32_t -ropFLDZ(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropFLDZ(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_FP_ENTER(ir); uop_MOV_IMM(ir, IREG_temp0, 0); diff --git a/src/codegen_new/codegen_ops_fpu_misc.c b/src/codegen_new/codegen_ops_fpu_misc.c index 31b668488..938204a70 100644 --- a/src/codegen_new/codegen_ops_fpu_misc.c +++ b/src/codegen_new/codegen_ops_fpu_misc.c @@ -98,7 +98,7 @@ ropFSTSW(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fet return op_pc + 1; } uint32_t -ropFSTSW_AX(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropFSTSW_AX(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_FP_ENTER(ir); uop_MOV(ir, IREG_AX, IREG_NPXS); diff --git a/src/codegen_new/codegen_ops_helpers.c b/src/codegen_new/codegen_ops_helpers.c index f2a4ce41a..037d91469 100644 --- a/src/codegen_new/codegen_ops_helpers.c +++ b/src/codegen_new/codegen_ops_helpers.c @@ -18,8 +18,8 @@ void LOAD_IMMEDIATE_FROM_RAM_16_unaligned(UNUSED(codeblock_t *block), ir_data_t *ir, int dest_reg, uint32_t addr) { /*Word access that crosses two pages. Perform reads from both pages, shift and combine*/ - uop_MOVZX_REG_PTR_8(ir, IREG_temp3_W, get_ram_ptr(addr)); - uop_MOVZX_REG_PTR_8(ir, dest_reg, get_ram_ptr(addr + 1)); + uop_MOVZX_REG_PTR_8(ir, IREG_temp3_W, get_ram_ptr(addr + 1)); + uop_MOVZX_REG_PTR_8(ir, dest_reg, get_ram_ptr(addr)); uop_SHL_IMM(ir, IREG_temp3_W, IREG_temp3_W, 8); uop_OR(ir, dest_reg, dest_reg, IREG_temp3_W); } diff --git a/src/codegen_new/codegen_ops_helpers.h b/src/codegen_new/codegen_ops_helpers.h index 5a8f1e1c7..92b721099 100644 --- a/src/codegen_new/codegen_ops_helpers.h +++ b/src/codegen_new/codegen_ops_helpers.h @@ -71,7 +71,7 @@ fpu_PUSH(codeblock_t *block, ir_data_t *ir) } static inline void -CHECK_SEG_LIMITS(codeblock_t *block, ir_data_t *ir, x86seg *seg, int addr_reg, int end_offset) +CHECK_SEG_LIMITS(UNUSED(codeblock_t *block), ir_data_t *ir, x86seg *seg, int addr_reg, int end_offset) { if ((seg == &cpu_state.seg_ds && codegen_flat_ds && !(cpu_cur_status & CPU_STATUS_NOTFLATDS)) || (seg == &cpu_state.seg_ss && codegen_flat_ss && !(cpu_cur_status & CPU_STATUS_NOTFLATSS))) return; @@ -85,7 +85,7 @@ CHECK_SEG_LIMITS(codeblock_t *block, ir_data_t *ir, x86seg *seg, int addr_reg, i } static inline void -LOAD_IMMEDIATE_FROM_RAM_8(codeblock_t *block, ir_data_t *ir, int dest_reg, uint32_t addr) +LOAD_IMMEDIATE_FROM_RAM_8(UNUSED(codeblock_t *block), ir_data_t *ir, int dest_reg, uint32_t addr) { uop_MOVZX_REG_PTR_8(ir, dest_reg, get_ram_ptr(addr)); } diff --git a/src/codegen_new/codegen_ops_jump.c b/src/codegen_new/codegen_ops_jump.c index fb2f1e5ba..430b16b2b 100644 --- a/src/codegen_new/codegen_ops_jump.c +++ b/src/codegen_new/codegen_ops_jump.c @@ -15,7 +15,7 @@ #include "codegen_ops_mov.h" uint32_t -ropJMP_r8(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) +ropJMP_r8(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc) { uint32_t offset = (int32_t) (int8_t) fastreadb(cs + op_pc); uint32_t dest_addr = op_pc + 1 + offset; @@ -29,7 +29,7 @@ ropJMP_r8(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fe return dest_addr; } uint32_t -ropJMP_r16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropJMP_r16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint32_t offset = (int32_t) (int16_t) fastreadw(cs + op_pc); uint32_t dest_addr = op_pc + 2 + offset; @@ -42,7 +42,7 @@ ropJMP_r16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t f return dest_addr; } uint32_t -ropJMP_r32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropJMP_r32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint32_t offset = fastreadl(cs + op_pc); uint32_t dest_addr = op_pc + 4 + offset; @@ -54,7 +54,7 @@ ropJMP_r32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t f } uint32_t -ropJMP_far_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropJMP_far_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t new_pc = fastreadw(cs + op_pc); uint16_t new_cs = fastreadw(cs + op_pc + 2); @@ -69,7 +69,7 @@ ropJMP_far_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ return -1; } uint32_t -ropJMP_far_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropJMP_far_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint32_t new_pc = fastreadl(cs + op_pc); uint16_t new_cs = fastreadw(cs + op_pc + 4); @@ -85,7 +85,7 @@ ropJMP_far_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ } uint32_t -ropCALL_r16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropCALL_r16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint32_t offset = (int32_t) (int16_t) fastreadw(cs + op_pc); uint16_t ret_addr = op_pc + 2; @@ -104,7 +104,7 @@ ropCALL_r16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t return -1; } uint32_t -ropCALL_r32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropCALL_r32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint32_t offset = fastreadl(cs + op_pc); uint32_t ret_addr = op_pc + 4; @@ -122,7 +122,7 @@ ropCALL_r32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t } uint32_t -ropRET_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), UNUSED(uint32_t op_pc)) +ropRET_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), UNUSED(uint32_t op_pc)) { uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); @@ -138,7 +138,7 @@ ropRET_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uin return -1; } uint32_t -ropRET_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), UNUSED(uint32_t op_pc)) +ropRET_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), UNUSED(uint32_t op_pc)) { uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); @@ -154,7 +154,7 @@ ropRET_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uin } uint32_t -ropRET_imm_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropRET_imm_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t offset = fastreadw(cs + op_pc); @@ -173,7 +173,7 @@ ropRET_imm_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ return -1; } uint32_t -ropRET_imm_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropRET_imm_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t offset = fastreadw(cs + op_pc); @@ -192,7 +192,7 @@ ropRET_imm_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ } uint32_t -ropRETF_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), UNUSED(uint32_t op_pc)) +ropRETF_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), UNUSED(uint32_t op_pc)) { if ((msw & 1) && !(cpu_state.eflags & VM_FLAG)) return 0; @@ -215,7 +215,7 @@ ropRETF_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), ui return -1; } uint32_t -ropRETF_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), UNUSED(uint32_t op_pc)) +ropRETF_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), UNUSED(uint32_t op_pc)) { if ((msw & 1) && !(cpu_state.eflags & VM_FLAG)) return 0; @@ -239,7 +239,7 @@ ropRETF_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), ui } uint32_t -ropRETF_imm_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropRETF_imm_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t offset; @@ -266,7 +266,7 @@ ropRETF_imm_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32 return -1; } uint32_t -ropRETF_imm_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropRETF_imm_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t offset; diff --git a/src/codegen_new/codegen_ops_logic.c b/src/codegen_new/codegen_ops_logic.c index 684052fea..f289f1cba 100644 --- a/src/codegen_new/codegen_ops_logic.c +++ b/src/codegen_new/codegen_ops_logic.c @@ -16,7 +16,7 @@ #include "codegen_ops_logic.h" uint32_t -ropAND_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropAND_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint8_t imm_data = fastreadb(cs + op_pc); @@ -29,7 +29,7 @@ ropAND_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ return op_pc + 1; } uint32_t -ropAND_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropAND_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t imm_data = fastreadw(cs + op_pc); @@ -226,7 +226,7 @@ ropAND_l_rmw(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t } uint32_t -ropOR_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropOR_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint8_t imm_data = fastreadb(cs + op_pc); @@ -239,7 +239,7 @@ ropOR_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t return op_pc + 1; } uint32_t -ropOR_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropOR_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t imm_data = fastreadw(cs + op_pc); @@ -437,7 +437,7 @@ ropOR_l_rmw(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t } uint32_t -ropTEST_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropTEST_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint8_t imm_data = fastreadb(cs + op_pc); @@ -449,7 +449,7 @@ ropTEST_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32 return op_pc + 1; } uint32_t -ropTEST_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropTEST_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t imm_data = fastreadw(cs + op_pc); @@ -557,7 +557,7 @@ ropTEST_l_rm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t } uint32_t -ropXOR_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropXOR_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint8_t imm_data = fastreadb(cs + op_pc); @@ -570,7 +570,7 @@ ropXOR_AL_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ return op_pc + 1; } uint32_t -ropXOR_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropXOR_AX_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t imm_data = fastreadw(cs + op_pc); diff --git a/src/codegen_new/codegen_ops_misc.c b/src/codegen_new/codegen_ops_misc.c index 545634672..33e01d951 100644 --- a/src/codegen_new/codegen_ops_misc.c +++ b/src/codegen_new/codegen_ops_misc.c @@ -485,108 +485,112 @@ ropFF_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fet } uint32_t -ropNOP(UNUSED(codeblock_t *block), UNUSED(ir_data_t *ir), UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropNOP(UNUSED(codeblock_t *block), UNUSED(ir_data_t *ir), UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { return op_pc; } uint32_t -ropCBW(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropCBW(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_MOVSX(ir, IREG_AX, IREG_AL); return op_pc; } uint32_t -ropCDQ(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropCDQ(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_SAR_IMM(ir, IREG_EDX, IREG_EAX, 31); return op_pc; } uint32_t -ropCWD(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropCWD(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_SAR_IMM(ir, IREG_DX, IREG_AX, 15); return op_pc; } uint32_t -ropCWDE(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropCWDE(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_MOVSX(ir, IREG_EAX, IREG_AX); return op_pc; } -#define ropLxS(name, seg) \ - uint32_t rop##name##_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 dest_reg = (fetchdat >> 3) & 7; \ - \ - if ((fetchdat & 0xc0) == 0xc0) \ - return 0; \ - \ - codegen_mark_code_present(block, cs + op_pc, 1); \ - uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ - target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ - codegen_check_seg_read(block, ir, target_seg); \ - uop_MEM_LOAD_REG(ir, IREG_temp0_W, ireg_seg_base(target_seg), IREG_eaaddr); \ - uop_MEM_LOAD_REG_OFFSET(ir, IREG_temp1_W, ireg_seg_base(target_seg), IREG_eaaddr, 2); \ - uop_LOAD_SEG(ir, seg, IREG_temp1_W); \ - uop_MOV(ir, IREG_16(dest_reg), IREG_temp0_W); \ - \ - if (seg == &cpu_state.seg_ss) \ - CPU_BLOCK_END(); \ - \ - return op_pc + 1; \ - } \ - uint32_t rop##name##_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 dest_reg = (fetchdat >> 3) & 7; \ - \ - if ((fetchdat & 0xc0) == 0xc0) \ - return 0; \ - \ - codegen_mark_code_present(block, cs + op_pc, 1); \ - uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ - target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ - codegen_check_seg_read(block, ir, target_seg); \ - uop_MEM_LOAD_REG(ir, IREG_temp0, ireg_seg_base(target_seg), IREG_eaaddr); \ - uop_MEM_LOAD_REG_OFFSET(ir, IREG_temp1_W, ireg_seg_base(target_seg), IREG_eaaddr, 4); \ - uop_LOAD_SEG(ir, seg, IREG_temp1_W); \ - uop_MOV(ir, IREG_32(dest_reg), IREG_temp0); \ - \ - if (seg == &cpu_state.seg_ss) \ - CPU_BLOCK_END(); \ - \ - return op_pc + 1; \ +#define ropLxS(name, seg) \ + uint32_t rop##name##_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), \ + uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + { \ + x86seg *target_seg = NULL; \ + int dest_reg = (fetchdat >> 3) & 7; \ + \ + if ((fetchdat & 0xc0) == 0xc0) \ + return 0; \ + \ + codegen_mark_code_present(block, cs + op_pc, 1); \ + uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ + target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ + codegen_check_seg_read(block, ir, target_seg); \ + uop_MEM_LOAD_REG(ir, IREG_temp0_W, ireg_seg_base(target_seg), (op_32 & 0x200) ? IREG_eaaddr : IREG_eaa16); \ + uop_MEM_LOAD_REG_OFFSET(ir, IREG_temp1_W, ireg_seg_base(target_seg), (op_32 & 0x200) ? IREG_eaaddr : IREG_eaa16, 2); \ + uop_LOAD_SEG(ir, seg, IREG_temp1_W); \ + uop_MOV(ir, IREG_16(dest_reg), IREG_temp0_W); \ + \ + if (seg == &cpu_state.seg_ss) \ + CPU_BLOCK_END(); \ + \ + return op_pc + 1; \ + } \ + uint32_t rop##name##_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), \ + uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + { \ + x86seg *target_seg = NULL; \ + int dest_reg = (fetchdat >> 3) & 7; \ + \ + if ((fetchdat & 0xc0) == 0xc0) \ + return 0; \ + \ + codegen_mark_code_present(block, cs + op_pc, 1); \ + uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ + target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ + codegen_check_seg_read(block, ir, target_seg); \ + uop_MEM_LOAD_REG(ir, IREG_temp0, ireg_seg_base(target_seg), (op_32 & 0x200) ? IREG_eaaddr : IREG_eaa16); \ + uop_MEM_LOAD_REG_OFFSET(ir, IREG_temp1_W, ireg_seg_base(target_seg), (op_32 & 0x200) ? IREG_eaaddr : IREG_eaa16, 4); \ + uop_LOAD_SEG(ir, seg, IREG_temp1_W); \ + uop_MOV(ir, IREG_32(dest_reg), IREG_temp0); \ + \ + if (seg == &cpu_state.seg_ss) \ + CPU_BLOCK_END(); \ + \ + return op_pc + 1; \ } +// clang-format off ropLxS(LDS, &cpu_state.seg_ds) ropLxS(LES, &cpu_state.seg_es) ropLxS(LFS, &cpu_state.seg_fs) ropLxS(LGS, &cpu_state.seg_gs) ropLxS(LSS, &cpu_state.seg_ss) +// clang-format on uint32_t -ropCLC(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropCLC(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_CALL_FUNC(ir, flags_rebuild); uop_AND_IMM(ir, IREG_flags, IREG_flags, ~C_FLAG); return op_pc; } uint32_t -ropCMC(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropCMC(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_CALL_FUNC(ir, flags_rebuild); uop_XOR_IMM(ir, IREG_flags, IREG_flags, C_FLAG); return op_pc; } uint32_t -ropSTC(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropSTC(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_CALL_FUNC(ir, flags_rebuild); uop_OR_IMM(ir, IREG_flags, IREG_flags, C_FLAG); @@ -594,20 +598,20 @@ ropSTC(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32 } uint32_t -ropCLD(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropCLD(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_AND_IMM(ir, IREG_flags, IREG_flags, ~D_FLAG); return op_pc; } uint32_t -ropSTD(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropSTD(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_OR_IMM(ir, IREG_flags, IREG_flags, D_FLAG); return op_pc; } uint32_t -ropCLI(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropCLI(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { if (!IOPLp && (cr4 & (CR4_VME | CR4_PVI))) return 0; @@ -616,7 +620,7 @@ ropCLI(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32 return op_pc; } uint32_t -ropSTI(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropSTI(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { if (!IOPLp && (cr4 & (CR4_VME | CR4_PVI))) return 0; diff --git a/src/codegen_new/codegen_ops_mmx_arith.c b/src/codegen_new/codegen_ops_mmx_arith.c index e99b4c56d..f01d64273 100644 --- a/src/codegen_new/codegen_ops_mmx_arith.c +++ b/src/codegen_new/codegen_ops_mmx_arith.c @@ -2,6 +2,7 @@ #include <86box/86box.h> #include "cpu.h" #include <86box/mem.h> +#include <86box/plat_unused.h> #include "x86.h" #include "x86_flags.h" @@ -15,27 +16,28 @@ #include "codegen_ops_mmx_arith.h" #include "codegen_ops_helpers.h" -#define ropParith(func) \ - uint32_t rop##func(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ - { \ - int dest_reg = (fetchdat >> 3) & 7; \ - \ - uop_MMX_ENTER(ir); \ - codegen_mark_code_present(block, cs + op_pc, 1); \ - if ((fetchdat & 0xc0) == 0xc0) { \ - int src_reg = fetchdat & 7; \ - uop_##func(ir, IREG_MM(dest_reg), IREG_MM(dest_reg), IREG_MM(src_reg)); \ - } else { \ - x86seg *target_seg; \ - \ - uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ - target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ - codegen_check_seg_read(block, ir, target_seg); \ - uop_MEM_LOAD_REG(ir, IREG_temp0_Q, ireg_seg_base(target_seg), IREG_eaaddr); \ - uop_##func(ir, IREG_MM(dest_reg), IREG_MM(dest_reg), IREG_temp0_Q); \ - } \ - \ - return op_pc + 1; \ +#define ropParith(func) \ + uint32_t rop##func(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), \ + uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + { \ + int dest_reg = (fetchdat >> 3) & 7; \ + \ + uop_MMX_ENTER(ir); \ + codegen_mark_code_present(block, cs + op_pc, 1); \ + if ((fetchdat & 0xc0) == 0xc0) { \ + int src_reg = fetchdat & 7; \ + uop_##func(ir, IREG_MM(dest_reg), IREG_MM(dest_reg), IREG_MM(src_reg)); \ + } else { \ + x86seg *target_seg; \ + \ + uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ + target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ + codegen_check_seg_read(block, ir, target_seg); \ + uop_MEM_LOAD_REG(ir, IREG_temp0_Q, ireg_seg_base(target_seg), IREG_eaaddr); \ + uop_##func(ir, IREG_MM(dest_reg), IREG_MM(dest_reg), IREG_temp0_Q); \ + } \ + \ + return op_pc + 1; \ } // clang-format off @@ -58,4 +60,4 @@ ropParith(PSUBUSW) ropParith(PMADDWD) ropParith(PMULHW) ropParith(PMULLW) - // clang-format on +// clang-format on diff --git a/src/codegen_new/codegen_ops_mmx_cmp.c b/src/codegen_new/codegen_ops_mmx_cmp.c index 6f38cba67..cf0cededb 100644 --- a/src/codegen_new/codegen_ops_mmx_cmp.c +++ b/src/codegen_new/codegen_ops_mmx_cmp.c @@ -2,6 +2,7 @@ #include <86box/86box.h> #include "cpu.h" #include <86box/mem.h> +#include <86box/plat_unused.h> #include "x86.h" #include "x86_flags.h" @@ -15,27 +16,28 @@ #include "codegen_ops_mmx_cmp.h" #include "codegen_ops_helpers.h" -#define ropPcmp(func) \ - uint32_t rop##func(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ - { \ - int dest_reg = (fetchdat >> 3) & 7; \ - \ - uop_MMX_ENTER(ir); \ - codegen_mark_code_present(block, cs + op_pc, 1); \ - if ((fetchdat & 0xc0) == 0xc0) { \ - int src_reg = fetchdat & 7; \ - uop_##func(ir, IREG_MM(dest_reg), IREG_MM(dest_reg), IREG_MM(src_reg)); \ - } else { \ - x86seg *target_seg; \ - \ - uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ - target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ - codegen_check_seg_read(block, ir, target_seg); \ - uop_MEM_LOAD_REG(ir, IREG_temp0_Q, ireg_seg_base(target_seg), IREG_eaaddr); \ - uop_##func(ir, IREG_MM(dest_reg), IREG_MM(dest_reg), IREG_temp0_Q); \ - } \ - \ - return op_pc + 1; \ +#define ropPcmp(func) \ + uint32_t rop##func(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), \ + uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + { \ + int dest_reg = (fetchdat >> 3) & 7; \ + \ + uop_MMX_ENTER(ir); \ + codegen_mark_code_present(block, cs + op_pc, 1); \ + if ((fetchdat & 0xc0) == 0xc0) { \ + int src_reg = fetchdat & 7; \ + uop_##func(ir, IREG_MM(dest_reg), IREG_MM(dest_reg), IREG_MM(src_reg)); \ + } else { \ + x86seg *target_seg; \ + \ + uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ + target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ + codegen_check_seg_read(block, ir, target_seg); \ + uop_MEM_LOAD_REG(ir, IREG_temp0_Q, ireg_seg_base(target_seg), IREG_eaaddr); \ + uop_##func(ir, IREG_MM(dest_reg), IREG_MM(dest_reg), IREG_temp0_Q); \ + } \ + \ + return op_pc + 1; \ } // clang-format off @@ -45,4 +47,4 @@ ropPcmp(PCMPEQD) ropPcmp(PCMPGTB) ropPcmp(PCMPGTW) ropPcmp(PCMPGTD) - // clang-format on +// clang-format on diff --git a/src/codegen_new/codegen_ops_mmx_pack.c b/src/codegen_new/codegen_ops_mmx_pack.c index d25edd52e..c62aa10d0 100644 --- a/src/codegen_new/codegen_ops_mmx_pack.c +++ b/src/codegen_new/codegen_ops_mmx_pack.c @@ -2,6 +2,7 @@ #include <86box/86box.h> #include "cpu.h" #include <86box/mem.h> +#include <86box/plat_unused.h> #include "x86.h" #include "x86_flags.h" @@ -15,27 +16,28 @@ #include "codegen_ops_mmx_pack.h" #include "codegen_ops_helpers.h" -#define ropPpack(func) \ - uint32_t rop##func(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ - { \ - int dest_reg = (fetchdat >> 3) & 7; \ - \ - uop_MMX_ENTER(ir); \ - codegen_mark_code_present(block, cs + op_pc, 1); \ - if ((fetchdat & 0xc0) == 0xc0) { \ - int src_reg = fetchdat & 7; \ - uop_##func(ir, IREG_MM(dest_reg), IREG_MM(dest_reg), IREG_MM(src_reg)); \ - } else { \ - x86seg *target_seg; \ - \ - uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ - target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ - codegen_check_seg_read(block, ir, target_seg); \ - uop_MEM_LOAD_REG(ir, IREG_temp0_Q, ireg_seg_base(target_seg), IREG_eaaddr); \ - uop_##func(ir, IREG_MM(dest_reg), IREG_MM(dest_reg), IREG_temp0_Q); \ - } \ - \ - return op_pc + 1; \ +#define ropPpack(func) \ + uint32_t rop##func(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), \ + uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ + { \ + int dest_reg = (fetchdat >> 3) & 7; \ + \ + uop_MMX_ENTER(ir); \ + codegen_mark_code_present(block, cs + op_pc, 1); \ + if ((fetchdat & 0xc0) == 0xc0) { \ + int src_reg = fetchdat & 7; \ + uop_##func(ir, IREG_MM(dest_reg), IREG_MM(dest_reg), IREG_MM(src_reg)); \ + } else { \ + x86seg *target_seg; \ + \ + uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ + target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); \ + codegen_check_seg_read(block, ir, target_seg); \ + uop_MEM_LOAD_REG(ir, IREG_temp0_Q, ireg_seg_base(target_seg), IREG_eaaddr); \ + uop_##func(ir, IREG_MM(dest_reg), IREG_MM(dest_reg), IREG_temp0_Q); \ + } \ + \ + return op_pc + 1; \ } // clang-format off @@ -48,4 +50,4 @@ ropPpack(PUNPCKLDQ) ropPpack(PUNPCKHBW) ropPpack(PUNPCKHWD) ropPpack(PUNPCKHDQ) - // clang-format on +// clang-format on diff --git a/src/codegen_new/codegen_ops_mov.c b/src/codegen_new/codegen_ops_mov.c index eae7045a8..f79a959a7 100644 --- a/src/codegen_new/codegen_ops_mov.c +++ b/src/codegen_new/codegen_ops_mov.c @@ -15,7 +15,7 @@ #include "codegen_ops_mov.h" uint32_t -ropMOV_rb_imm(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropMOV_rb_imm(codeblock_t *block, ir_data_t *ir, uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint8_t imm = fastreadb(cs + op_pc); @@ -25,7 +25,7 @@ ropMOV_rb_imm(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchd return op_pc + 1; } uint32_t -ropMOV_rw_imm(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropMOV_rw_imm(codeblock_t *block, ir_data_t *ir, uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t imm = fastreadw(cs + op_pc); @@ -172,7 +172,7 @@ ropMOV_r_l(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t f } uint32_t -ropMOV_AL_abs(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) +ropMOV_AL_abs(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc) { uint32_t addr; @@ -189,7 +189,7 @@ ropMOV_AL_abs(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ return op_pc + ((op_32 & 0x200) ? 4 : 2); } uint32_t -ropMOV_AX_abs(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) +ropMOV_AX_abs(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc) { uint32_t addr; @@ -206,7 +206,7 @@ ropMOV_AX_abs(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ return op_pc + ((op_32 & 0x200) ? 4 : 2); } uint32_t -ropMOV_EAX_abs(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) +ropMOV_EAX_abs(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc) { uint32_t addr = 0; @@ -233,7 +233,7 @@ ropMOV_EAX_abs(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32 } uint32_t -ropMOV_abs_AL(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) +ropMOV_abs_AL(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc) { uint32_t addr; @@ -250,7 +250,7 @@ ropMOV_abs_AL(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ return op_pc + ((op_32 & 0x200) ? 4 : 2); } uint32_t -ropMOV_abs_AX(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) +ropMOV_abs_AX(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc) { uint32_t addr; @@ -267,7 +267,7 @@ ropMOV_abs_AX(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_ return op_pc + ((op_32 & 0x200) ? 4 : 2); } uint32_t -ropMOV_abs_EAX(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) +ropMOV_abs_EAX(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc) { uint32_t addr; @@ -296,7 +296,13 @@ ropMOV_b_imm(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t imm = fastreadb(cs + op_pc + 1); uop_MOV_IMM(ir, IREG_8(dest_reg), imm); - } else { + } +/* TODO: Fix the recompilation of that specific case so it no longer breaks NT 3.x NTVDM. */ +#ifndef RECOMPILE_MOVB_IMM_MEM_ALWAYS + else if (((fetchdat & 0xfc) == 0x80) && (op_32 & 0x200)) + return 0; +#endif + else { uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); target_seg = codegen_generate_ea(ir, op_ea_seg, fetchdat, op_ssegs, &op_pc, op_32, 0); codegen_check_seg_write(block, ir, target_seg); @@ -614,7 +620,7 @@ ropMOVZX_32_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32 } uint32_t -ropXCHG_AX(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropXCHG_AX(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { int reg2 = IREG_16(opcode & 7); @@ -625,7 +631,7 @@ ropXCHG_AX(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, uint32_t f return op_pc; } uint32_t -ropXCHG_EAX(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropXCHG_EAX(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { int reg2 = IREG_32(opcode & 7); @@ -716,7 +722,7 @@ ropXCHG_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t f } uint32_t -ropXLAT(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) +ropXLAT(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), uint32_t op_32, uint32_t op_pc) { uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); diff --git a/src/codegen_new/codegen_ops_stack.c b/src/codegen_new/codegen_ops_stack.c index 92ad9509d..f93289197 100644 --- a/src/codegen_new/codegen_ops_stack.c +++ b/src/codegen_new/codegen_ops_stack.c @@ -16,7 +16,7 @@ #include "codegen_ops_misc.h" uint32_t -ropPUSH_r16(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPUSH_r16(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { int sp_reg; @@ -28,7 +28,7 @@ ropPUSH_r16(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, uint32_t return op_pc; } uint32_t -ropPUSH_r32(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPUSH_r32(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { int sp_reg; @@ -41,7 +41,7 @@ ropPUSH_r32(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, uint32_t } uint32_t -ropPOP_r16(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPOP_r16(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); @@ -57,7 +57,7 @@ ropPOP_r16(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, uint32_t f return op_pc; } uint32_t -ropPOP_r32(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPOP_r32(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); @@ -74,7 +74,7 @@ ropPOP_r32(UNUSED(codeblock_t *block), ir_data_t *ir, uint8_t opcode, uint32_t f } uint32_t -ropPUSH_imm_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPUSH_imm_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t imm = fastreadw(cs + op_pc); int sp_reg; @@ -88,7 +88,7 @@ ropPUSH_imm_16(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32 return op_pc + 2; } uint32_t -ropPUSH_imm_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPUSH_imm_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint32_t imm = fastreadl(cs + op_pc); int sp_reg; @@ -103,7 +103,7 @@ ropPUSH_imm_32(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32 } uint32_t -ropPUSH_imm_16_8(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPUSH_imm_16_8(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint16_t imm = (int16_t) (int8_t) fastreadb(cs + op_pc); int sp_reg; @@ -117,7 +117,7 @@ ropPUSH_imm_16_8(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint return op_pc + 1; } uint32_t -ropPUSH_imm_32_8(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPUSH_imm_32_8(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uint32_t imm = (int32_t) (int8_t) fastreadb(cs + op_pc); int sp_reg; @@ -196,63 +196,68 @@ ropPOP_L(codeblock_t *block, ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fet return op_pc + 1; } -#define ROP_PUSH_SEG(seg) \ - uint32_t ropPUSH_##seg##_16(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ - { \ - int sp_reg; \ - \ - uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ - sp_reg = LOAD_SP_WITH_OFFSET(ir, -2); \ - uop_MEM_STORE_REG(ir, IREG_SS_base, sp_reg, IREG_##seg##_seg_W); \ - SUB_SP(ir, 2); \ - \ - return op_pc; \ - } \ - uint32_t ropPUSH_##seg##_32(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ - { \ - int sp_reg; \ - \ - uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ - sp_reg = LOAD_SP_WITH_OFFSET(ir, -4); \ - uop_MOVZX(ir, IREG_temp0, IREG_##seg##_seg_W); \ - uop_MEM_STORE_REG(ir, IREG_SS_base, sp_reg, IREG_temp0); \ - SUB_SP(ir, 4); \ - \ - return op_pc; \ +#define ROP_PUSH_SEG(seg) \ + uint32_t ropPUSH_##seg##_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), \ + UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) \ + { \ + int sp_reg; \ + \ + uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ + sp_reg = LOAD_SP_WITH_OFFSET(ir, -2); \ + uop_MEM_STORE_REG(ir, IREG_SS_base, sp_reg, IREG_##seg##_seg_W); \ + SUB_SP(ir, 2); \ + \ + return op_pc; \ + } \ + uint32_t ropPUSH_##seg##_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), \ + UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) \ + { \ + int sp_reg; \ + \ + uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ + sp_reg = LOAD_SP_WITH_OFFSET(ir, -4); \ + uop_MOVZX(ir, IREG_temp0, IREG_##seg##_seg_W); \ + uop_MEM_STORE_REG(ir, IREG_SS_base, sp_reg, IREG_temp0); \ + SUB_SP(ir, 4); \ + \ + return op_pc; \ } -#define ROP_POP_SEG(seg, rseg) \ - uint32_t ropPOP_##seg##_16(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ - { \ - uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ - \ - if (stack32) \ - uop_MEM_LOAD_REG(ir, IREG_temp0_W, IREG_SS_base, IREG_ESP); \ - else { \ - uop_MOVZX(ir, IREG_eaaddr, IREG_SP); \ - uop_MEM_LOAD_REG(ir, IREG_temp0_W, IREG_SS_base, IREG_eaaddr); \ - } \ - uop_LOAD_SEG(ir, &rseg, IREG_temp0_W); \ - ADD_SP(ir, 2); \ - \ - return op_pc; \ - } \ - uint32_t ropPOP_##seg##_32(codeblock_t *block, ir_data_t *ir, uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc) \ - { \ - uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ - \ - if (stack32) \ - uop_MEM_LOAD_REG(ir, IREG_temp0_W, IREG_SS_base, IREG_ESP); \ - else { \ - uop_MOVZX(ir, IREG_eaaddr, IREG_SP); \ - uop_MEM_LOAD_REG(ir, IREG_temp0_W, IREG_SS_base, IREG_eaaddr); \ - } \ - uop_LOAD_SEG(ir, &rseg, IREG_temp0_W); \ - ADD_SP(ir, 4); \ - \ - return op_pc; \ +#define ROP_POP_SEG(seg, rseg) \ + uint32_t ropPOP_##seg##_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), \ + UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) \ + { \ + uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ + \ + if (stack32) \ + uop_MEM_LOAD_REG(ir, IREG_temp0_W, IREG_SS_base, IREG_ESP); \ + else { \ + uop_MOVZX(ir, IREG_eaaddr, IREG_SP); \ + uop_MEM_LOAD_REG(ir, IREG_temp0_W, IREG_SS_base, IREG_eaaddr); \ + } \ + uop_LOAD_SEG(ir, &rseg, IREG_temp0_W); \ + ADD_SP(ir, 2); \ + \ + return op_pc; \ + } \ + uint32_t ropPOP_##seg##_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), \ + UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) \ + { \ + uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); \ + \ + if (stack32) \ + uop_MEM_LOAD_REG(ir, IREG_temp0_W, IREG_SS_base, IREG_ESP); \ + else { \ + uop_MOVZX(ir, IREG_eaaddr, IREG_SP); \ + uop_MEM_LOAD_REG(ir, IREG_temp0_W, IREG_SS_base, IREG_eaaddr); \ + } \ + uop_LOAD_SEG(ir, &rseg, IREG_temp0_W); \ + ADD_SP(ir, 4); \ + \ + return op_pc; \ } +// clang-format off ROP_PUSH_SEG(CS) ROP_PUSH_SEG(DS) ROP_PUSH_SEG(ES) @@ -263,9 +268,10 @@ ROP_POP_SEG(DS, cpu_state.seg_ds) ROP_POP_SEG(ES, cpu_state.seg_es) ROP_POP_SEG(FS, cpu_state.seg_fs) ROP_POP_SEG(GS, cpu_state.seg_gs) +// clang-format on uint32_t -ropLEAVE_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropLEAVE_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); @@ -281,7 +287,7 @@ ropLEAVE_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), u return op_pc; } uint32_t -ropLEAVE_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropLEAVE_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); @@ -298,7 +304,7 @@ ropLEAVE_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), u } uint32_t -ropPUSHA_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPUSHA_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { int sp_reg; @@ -317,7 +323,7 @@ ropPUSHA_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), u return op_pc; } uint32_t -ropPUSHA_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPUSHA_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { int sp_reg; @@ -337,7 +343,7 @@ ropPUSHA_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), u } uint32_t -ropPOPA_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPOPA_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { int sp_reg; @@ -355,7 +361,7 @@ ropPOPA_16(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), ui return op_pc; } uint32_t -ropPOPA_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPOPA_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { int sp_reg; @@ -374,7 +380,7 @@ ropPOPA_32(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), ui } uint32_t -ropPUSHF(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPUSHF(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { int sp_reg; @@ -384,13 +390,15 @@ ropPUSHF(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); uop_CALL_FUNC(ir, flags_rebuild); sp_reg = LOAD_SP_WITH_OFFSET(ir, -2); + uop_AND_IMM(ir, IREG_flags, IREG_flags, 0x7fd5); + uop_OR_IMM(ir, IREG_flags, IREG_flags, 0x0002); uop_MEM_STORE_REG(ir, IREG_SS_base, sp_reg, IREG_flags); SUB_SP(ir, 2); return op_pc; } uint32_t -ropPUSHFD(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uint32_t fetchdat, UNUSED(uint32_t op_32), uint32_t op_pc) +ropPUSHFD(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), UNUSED(uint32_t fetchdat), UNUSED(uint32_t op_32), uint32_t op_pc) { int sp_reg; @@ -400,6 +408,8 @@ ropPUSHFD(UNUSED(codeblock_t *block), ir_data_t *ir, UNUSED(uint8_t opcode), uin uop_MOV_IMM(ir, IREG_oldpc, cpu_state.oldpc); uop_CALL_FUNC(ir, flags_rebuild); + uop_AND_IMM(ir, IREG_flags, IREG_flags, 0x7fd5); + uop_OR_IMM(ir, IREG_flags, IREG_flags, 0x0002); if (cpu_CR4_mask & CR4_VME) uop_AND_IMM(ir, IREG_temp0_W, IREG_eflags, 0x3c); else if (CPUID) diff --git a/src/codegen_new/codegen_reg.c b/src/codegen_new/codegen_reg.c index a3f000826..75cf25ded 100644 --- a/src/codegen_new/codegen_reg.c +++ b/src/codegen_new/codegen_reg.c @@ -169,6 +169,9 @@ struct [IREG_GS_limit_high] = { REG_DWORD, &cpu_state.seg_gs.limit_high, REG_INTEGER, REG_PERMANENT}, [IREG_SS_limit_high] = { REG_DWORD, &cpu_state.seg_ss.limit_high, REG_INTEGER, REG_PERMANENT}, + [IREG_eaa16] = { REG_WORD, &cpu_state.eaaddr, REG_INTEGER, REG_PERMANENT}, + [IREG_x87_op] = { REG_WORD, &x87_op, REG_INTEGER, REG_PERMANENT}, + /*Temporary registers are stored on the stack, and are not guaranteed to be preserved across uOPs. They will not be written back if they will not be read again.*/ @@ -223,6 +226,20 @@ reg_is_native_size(ir_reg_t ir_reg) return 0; } +void +codegen_check_regs(void) +{ + int i = 0; + for (i = 0; i < IREG_COUNT; i++) { + if (ireg_data[i].is_volatile == REG_VOLATILE) + continue; + + if (ireg_data[i].p && ((uintptr_t)ireg_data[i].p - (uintptr_t)&cpu_state) >= sizeof(cpu_state)) { + fatal("Register number %d outside cpu_state!\n", i); + } + } +} + void codegen_reg_reset(void) { diff --git a/src/codegen_new/codegen_reg.h b/src/codegen_new/codegen_reg.h index ebb90b42f..2185fde45 100644 --- a/src/codegen_new/codegen_reg.h +++ b/src/codegen_new/codegen_reg.h @@ -132,7 +132,10 @@ enum { IREG_GS_limit_high = 86, IREG_SS_limit_high = 87, - IREG_COUNT = 88, + IREG_eaa16 = 88, + IREG_x87_op = 89, + + IREG_COUNT = 90, IREG_INVALID = 255, diff --git a/src/config.c b/src/config.c index 8284fec6d..d33813e7d 100644 --- a/src/config.c +++ b/src/config.c @@ -8,20 +8,19 @@ * * Configuration file handler. * - * - * * Authors: Sarah Walker, * Miran Grca, * Fred N. van Kempen, * Overdoze, * David Hrdlička, + * Jasmine Iwanek, * * Copyright 2008-2019 Sarah Walker. * Copyright 2016-2019 Miran Grca. * Copyright 2017-2019 Fred N. van Kempen. * Copyright 2018-2019 David Hrdlička. * Copyright 2021 Andreas J. Reichel. - * Copyright 2021-2022 Jasmine Iwanek. + * Copyright 2021-2025 Jasmine Iwanek. * * NOTE: Forcing config files to be in Unicode encoding breaks * it on Windows XP, and possibly also Vista. Use the @@ -29,12 +28,13 @@ */ #include +#ifdef ENABLE_CONFIG_LOG #include +#endif #include #include #include #include -#include #define HAVE_STDARG_H #include <86box/86box.h> #include "cpu.h" @@ -46,6 +46,7 @@ #include <86box/ini.h> #include <86box/config.h> #include <86box/isamem.h> +#include <86box/isarom.h> #include <86box/isartc.h> #include <86box/lpt.h> #include <86box/serial.h> @@ -53,10 +54,8 @@ #include <86box/hdc.h> #include <86box/hdc_ide.h> #include <86box/fdd.h> -#include <86box/fdc.h> #include <86box/fdc_ext.h> #include <86box/gameport.h> -#include <86box/serial.h> #include <86box/serial_passthrough.h> #include <86box/machine.h> #include <86box/mouse.h> @@ -79,6 +78,12 @@ #include <86box/snd_opl.h> #include <86box/version.h> +#ifndef USE_SDL_UI +/* Deliberate to not make the 86box.h header kitchen-sink. */ +#include <86box/qt-glsl.h> +extern char gl3_shader_file[MAX_USER_SHADERS][512]; +#endif + static int cx; static int cy; static int cw; @@ -103,6 +108,7 @@ config_log(const char *fmt, ...) # define config_log(fmt, ...) #endif + /* Load "General" section. */ static void load_general(void) @@ -123,10 +129,10 @@ load_general(void) video_fullscreen_scale = ini_section_get_int(cat, "video_fullscreen_scale", 1); - video_fullscreen_first = ini_section_get_int(cat, "video_fullscreen_first", 1); - video_filter_method = ini_section_get_int(cat, "video_filter_method", 1); + inhibit_multimedia_keys = ini_section_get_int(cat, "inhibit_multimedia_keys", 0); + force_43 = !!ini_section_get_int(cat, "force_43", 0); scale = ini_section_get_int(cat, "scale", 1); if (scale > 9) @@ -170,6 +176,7 @@ load_general(void) kbd_req_capture = ini_section_get_int(cat, "kbd_req_capture", 0); hide_status_bar = ini_section_get_int(cat, "hide_status_bar", 0); hide_tool_bar = ini_section_get_int(cat, "hide_tool_bar", 0); + sound_muted = ini_section_get_int(cat, "sound_muted", 0); confirm_reset = ini_section_get_int(cat, "confirm_reset", 1); confirm_exit = ini_section_get_int(cat, "confirm_exit", 1); @@ -178,6 +185,8 @@ load_general(void) p = ini_section_get_string(cat, "language", NULL); if (p != NULL) lang_id = plat_language_code(p); + else + lang_id = plat_language_code(DEFAULT_LANGUAGE); mouse_sensitivity = ini_section_get_double(cat, "mouse_sensitivity", 1.0); if (mouse_sensitivity < 0.1) @@ -185,19 +194,12 @@ load_general(void) else if (mouse_sensitivity > 2.0) mouse_sensitivity = 2.0; - p = ini_section_get_string(cat, "iconset", NULL); - if (p != NULL) - strcpy(icon_set, p); - else - strcpy(icon_set, ""); - enable_discord = !!ini_section_get_int(cat, "enable_discord", 0); open_dir_usr_path = ini_section_get_int(cat, "open_dir_usr_path", 0); video_framerate = ini_section_get_int(cat, "video_gl_framerate", -1); video_vsync = ini_section_get_int(cat, "video_gl_vsync", 0); - strncpy(video_shader, ini_section_get_string(cat, "video_gl_shader", ""), sizeof(video_shader) - 1); window_remember = ini_section_get_int(cat, "window_remember", 0); if (window_remember) { @@ -300,7 +302,7 @@ load_machine(void) /* Only copy if a file with the new name doesn't already exist. */ FILE *g = nvr_fopen(new_fn, "rb"); - if (!g) { + if (g == NULL) { FILE *f = nvr_fopen(entry->d_name, "rb"); g = nvr_fopen(new_fn, "wb"); @@ -361,7 +363,7 @@ load_machine(void) while (!cpu_family_is_eligible(&cpu_families[c], machine)) { if (cpu_families[c++].package == 0) { /* End of list. */ - fatal("No eligible CPU families for the selected machine\n"); + fatal("Configuration: No eligible CPU families for the selected machine\n"); return; } } @@ -441,7 +443,6 @@ load_video(void) if (free_p) { free(p); p = NULL; - free_p = 0; } } @@ -457,6 +458,7 @@ load_video(void) ibm8514_active = ibm8514_standalone_enabled; xga_standalone_enabled = !!ini_section_get_int(cat, "xga", 0); xga_active = xga_standalone_enabled; + da2_standalone_enabled = !!ini_section_get_int(cat, "da2", 0); show_second_monitors = !!ini_section_get_int(cat, "show_second_monitors", 1); video_fullscreen_scale_maximized = !!ini_section_get_int(cat, "video_fullscreen_scale_maximized", 0); @@ -475,8 +477,6 @@ load_input_devices(void) { ini_section_t cat = ini_find_section(config, "Input devices"); char temp[512]; - int c; - int d; char *p; p = ini_section_get_string(cat, "mouse_type", NULL); @@ -495,8 +495,8 @@ load_input_devices(void) /* Workaround for ini_section_get_int returning 0 on non-integer data */ joystick_type = joystick_get_from_internal_name("2axis_2button"); else { - c = ini_section_get_int(cat, "joystick_type", 8); - switch (c) { + int js = ini_section_get_int(cat, "joystick_type", 8); + switch (js) { case JS_TYPE_2AXIS_4BUTTON: joystick_type = joystick_get_from_internal_name("2axis_4button"); break; @@ -527,25 +527,25 @@ load_input_devices(void) } else joystick_type = JS_TYPE_NONE; - for (c = 0; c < joystick_get_max_joysticks(joystick_type); c++) { - sprintf(temp, "joystick_%i_nr", c); - joystick_state[c].plat_joystick_nr = ini_section_get_int(cat, temp, 0); + for (int js = 0; js < joystick_get_max_joysticks(joystick_type); js++) { + sprintf(temp, "joystick_%i_nr", js); + joystick_state[0][js].plat_joystick_nr = ini_section_get_int(cat, temp, 0); - if (joystick_state[c].plat_joystick_nr) { - for (d = 0; d < joystick_get_axis_count(joystick_type); d++) { - sprintf(temp, "joystick_%i_axis_%i", c, d); - joystick_state[c].axis_mapping[d] = ini_section_get_int(cat, temp, d); + if (joystick_state[0][js].plat_joystick_nr) { + for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) { + sprintf(temp, "joystick_%i_axis_%i", js, axis_nr); + joystick_state[0][js].axis_mapping[axis_nr] = ini_section_get_int(cat, temp, axis_nr); } - for (d = 0; d < joystick_get_button_count(joystick_type); d++) { - sprintf(temp, "joystick_%i_button_%i", c, d); - joystick_state[c].button_mapping[d] = ini_section_get_int(cat, temp, d); + for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) { + sprintf(temp, "joystick_%i_button_%i", js, button_nr); + joystick_state[0][js].button_mapping[button_nr] = ini_section_get_int(cat, temp, button_nr); } - for (d = 0; d < joystick_get_pov_count(joystick_type); d++) { - sprintf(temp, "joystick_%i_pov_%i", c, d); + for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) { + sprintf(temp, "joystick_%i_pov_%i", js, pov_nr); p = ini_section_get_string(cat, temp, "0, 0"); - joystick_state[c].pov_mapping[d][0] = joystick_state[c].pov_mapping[d][1] = 0; - sscanf(p, "%i, %i", &joystick_state[c].pov_mapping[d][0], - &joystick_state[c].pov_mapping[d][1]); + joystick_state[0][js].pov_mapping[pov_nr][0] = joystick_state[0][js].pov_mapping[pov_nr][1] = 0; + sscanf(p, "%i, %i", &joystick_state[0][js].pov_mapping[pov_nr][0], + &joystick_state[0][js].pov_mapping[pov_nr][1]); } } } @@ -620,7 +620,7 @@ load_sound(void) memset(temp, '\0', sizeof(temp)); p = ini_section_get_string(cat, "sound_type", "float"); if (strlen(p) > 511) - fatal("load_sound(): strlen(p) > 511\n"); + fatal("Configuration: Length of sound_type is more than 511\n"); else strncpy(temp, p, 511); if (!strcmp(temp, "float") || !strcmp(temp, "1")) @@ -746,11 +746,9 @@ load_ports(void) ini_section_t cat = ini_find_section(config, "Ports (COM & LPT)"); char *p; char temp[512]; - int c; - memset(temp, 0, sizeof(temp)); - for (c = 0; c < SERIAL_MAX; c++) { + for (int c = 0; c < (SERIAL_MAX - 1); c++) { sprintf(temp, "serial%d_enabled", c + 1); com_ports[c].enabled = !!ini_section_get_int(cat, temp, (c >= 2) ? 0 : 1); @@ -761,7 +759,7 @@ load_ports(void) config_log("Serial Port %d: passthrough enabled.\n\n", c + 1); } - for (c = 0; c < PARALLEL_MAX; c++) { + for (int c = 0; c < PARALLEL_MAX; c++) { sprintf(temp, "lpt%d_enabled", c + 1); lpt_ports[c].enabled = !!ini_section_get_int(cat, temp, (c == 0) ? 1 : 0); @@ -769,6 +767,28 @@ load_ports(void) p = ini_section_get_string(cat, temp, "none"); lpt_ports[c].device = lpt_device_get_from_internal_name(p); } + +#if 0 +// TODO: Load + for (c = 0; c < GAMEPORT_MAX; c++) { + sprintf(temp, "gameport%d_enabled", c + 1); + game_ports[c].enabled = !!ini_section_get_int(cat, temp, (c == 0) ? 1 : 0); + + sprintf(temp, "gameport%d_device", c + 1); + p = ini_section_get_string(cat, temp, "none"); + game_ports[c].device = gameport_get_from_internal_name(p); + } + + for (uint8_t c = 0; c < GAMEPORT_MAX; c++) { + sprintf(temp, "gameport%d_type", c); + + p = ini_section_get_string(cat, temp, "none"); + gameport_type[c] = gameport_get_from_internal_name(p); + + if (!strcmp(p, "none")) + ini_section_delete_var(cat, temp); + } +#endif } /* Load "Storage Controllers" section. */ @@ -779,11 +799,10 @@ load_storage_controllers(void) ini_section_t migration_cat; char *p; char temp[512]; - int c; int min = 0; int free_p = 0; - for (c = min; c < SCSI_CARD_MAX; c++) { + for (int c = min; c < SCSI_CARD_MAX; c++) { sprintf(temp, "scsicard_%d", c + 1); p = ini_section_get_string(cat, temp, NULL); @@ -855,7 +874,6 @@ load_storage_controllers(void) if (free_p) { free(p); p = NULL; - free_p = 0; } ide_ter_enabled = !!ini_section_get_int(cat, "ide_ter", 0); @@ -874,7 +892,7 @@ load_storage_controllers(void) if (p[0] != 0x00) { if (path_abs(p)) { if (strlen(p) > 511) - fatal("load_storage_controllers(): strlen(p) > 511 (cassette_fname)\n"); + fatal("Configuration: Length of cassette_file is more than 511\n"); else strncpy(cassette_fname, p, 511); } else @@ -884,7 +902,7 @@ load_storage_controllers(void) p = ini_section_get_string(cat, "cassette_mode", "load"); if (strlen(p) > 511) - fatal("load_storage_controllers(): strlen(p) > 511\n"); + fatal("Configuration: Length of cassette_mode is more than 511\n"); else strncpy(cassette_mode, p, 511); @@ -895,8 +913,8 @@ load_storage_controllers(void) if (p) { if (path_abs(p)) { if (strlen(p) > (MAX_IMAGE_PATH_LEN - 1)) - fatal("load_storage_controllers(): strlen(p) > 2047 " - "(cassette_image_history[%i])\n", i); + fatal("Configuration: Length of cassette_image_history_%02i is more " + "than %i\n", i + 1, MAX_IMAGE_PATH_LEN - 1); else snprintf(cassette_image_history[i], MAX_IMAGE_PATH_LEN, "%s", p); } else @@ -935,7 +953,7 @@ load_storage_controllers(void) ini_section_delete_var(cat, "cassette_ui_writeprot"); } - for (c = 0; c < 2; c++) { + for (int c = 0; c < 2; c++) { sprintf(temp, "cartridge_%02i_fn", c + 1); p = ini_section_get_string(cat, temp, ""); @@ -945,7 +963,8 @@ load_storage_controllers(void) if (p[0] != 0x00) { if (path_abs(p)) { if (strlen(p) > 511) - fatal("load_storage_controllers(): strlen(p) > 511 (cart_fns[%i])\n", c); + fatal("Configuration: Length of cartridge_%02i_fn is more than 511\n", + c + 1); else strncpy(cart_fns[c], p, 511); } else @@ -960,8 +979,8 @@ load_storage_controllers(void) if (p) { if (path_abs(p)) { if (strlen(p) > (MAX_IMAGE_PATH_LEN - 1)) - fatal("load_storage_controllers(): strlen(p) > 2047 " - "(cart_image_history[%i][%i])\n", c, i); + fatal("Configuration: Length of cartridge_%02i_image_history_%02i " + "is more than %i\n", c + 1, i + 1, MAX_IMAGE_PATH_LEN - 1); else snprintf(cart_image_history[c][i], MAX_IMAGE_PATH_LEN, "%s", p); } else @@ -1000,8 +1019,8 @@ load_hard_disks(void) sscanf(p, "%u, %u, %u, %i, %s", &hdd[c].spt, &hdd[c].hpc, &hdd[c].tracks, (int *) &hdd[c].wp, s); - hdd[c].bus = hdd_string_to_bus(s, 0); - switch (hdd[c].bus) { + hdd[c].bus_type = hdd_string_to_bus(s, 0); + switch (hdd[c].bus_type) { default: case HDD_BUS_DISABLED: max_spt = max_hpc = max_tracks = 0; @@ -1047,7 +1066,7 @@ load_hard_disks(void) hdd[c].tracks = max_tracks; sprintf(temp, "hdd_%02i_speed", c + 1); - switch (hdd[c].bus) { + switch (hdd[c].bus_type) { case HDD_BUS_IDE: case HDD_BUS_ESDI: case HDD_BUS_ATAPI: @@ -1063,28 +1082,28 @@ load_hard_disks(void) /* MFM/RLL */ sprintf(temp, "hdd_%02i_mfm_channel", c + 1); - if (hdd[c].bus == HDD_BUS_MFM) + if (hdd[c].bus_type == HDD_BUS_MFM) hdd[c].mfm_channel = !!ini_section_get_int(cat, temp, c & 1); else ini_section_delete_var(cat, temp); /* XTA */ sprintf(temp, "hdd_%02i_xta_channel", c + 1); - if (hdd[c].bus == HDD_BUS_XTA) + if (hdd[c].bus_type == HDD_BUS_XTA) hdd[c].xta_channel = !!ini_section_get_int(cat, temp, c & 1); else ini_section_delete_var(cat, temp); /* ESDI */ sprintf(temp, "hdd_%02i_esdi_channel", c + 1); - if (hdd[c].bus == HDD_BUS_ESDI) + if (hdd[c].bus_type == HDD_BUS_ESDI) hdd[c].esdi_channel = !!ini_section_get_int(cat, temp, c & 1); else ini_section_delete_var(cat, temp); /* IDE */ sprintf(temp, "hdd_%02i_ide_channel", c + 1); - if ((hdd[c].bus == HDD_BUS_IDE) || (hdd[c].bus == HDD_BUS_ATAPI)) { + if ((hdd[c].bus_type == HDD_BUS_IDE) || (hdd[c].bus_type == HDD_BUS_ATAPI)) { sprintf(tmp2, "%01u:%01u", c >> 1, c & 1); p = ini_section_get_string(cat, temp, tmp2); sscanf(p, "%01u:%01u", &board, &dev); @@ -1098,7 +1117,7 @@ load_hard_disks(void) ini_section_delete_var(cat, temp); /* SCSI */ - if (hdd[c].bus == HDD_BUS_SCSI) { + if (hdd[c].bus_type == HDD_BUS_SCSI) { sprintf(temp, "hdd_%02i_scsi_location", c + 1); sprintf(tmp2, "%01u:%02u", SCSI_BUS_MAX, c + 2); p = ini_section_get_string(cat, temp, tmp2); @@ -1138,7 +1157,8 @@ load_hard_disks(void) if (p[0] != 0x00) { if (path_abs(p)) { if (strlen(p) > 511) - fatal("load_hard_disks(): strlen(p) > 511 (hdd[%i].fn)\n", c); + fatal("Configuration: Length of hdd_%02i_fn is more " + "than 511\n", c + 1); else strncpy(hdd[c].fn, p, 511); } else @@ -1187,12 +1207,12 @@ load_floppy_and_cdrom_drives(void) char temp[512]; char tmp2[512]; char *p; - char *def_type; char s[512]; unsigned int board = 0; unsigned int dev = 0; int c; int d = 0; + int count = cdrom_get_type_count(); memset(temp, 0x00, sizeof(temp)); for (c = 0; c < FDD_NUM; c++) { @@ -1211,7 +1231,7 @@ load_floppy_and_cdrom_drives(void) if (p[0] != 0x00) { if (path_abs(p)) { if (strlen(p) > 511) - fatal("load_floppy_and_cdrom_drives(): strlen(p) > 511 (floppyfns[%i])\n", c); + fatal("Configuration: Length of fdd_%02i_fn is more than 511\n", c + 1); else strncpy(floppyfns[c], p, 511); } else @@ -1259,8 +1279,8 @@ load_floppy_and_cdrom_drives(void) if (p) { if (path_abs(p)) { if (strlen(p) > (MAX_IMAGE_PATH_LEN - 1)) - fatal("load_floppy_and_cdrom_drives(): strlen(p) > 2047 " - "(fdd_image_history[%i][%i])\n", c, i); + fatal("Configuration: Length of fdd_%02i_image_history_%02i is more " + "than %i\n", c + 1, i + 1, MAX_IMAGE_PATH_LEN - 1); else snprintf(fdd_image_history[c][i], MAX_IMAGE_PATH_LEN, "%s", p); } else @@ -1292,12 +1312,20 @@ load_floppy_and_cdrom_drives(void) cdrom[c].speed = ini_section_get_int(cat, temp, 8); sprintf(temp, "cdrom_%02i_type", c + 1); - def_type = (c == 1) ? "86BOX_CD-ROM_1.00" : "none"; - p = ini_section_get_string(cat, temp, def_type); - cdrom_set_type(c, cdrom_get_from_internal_name(p)); - if (cdrom_get_type(c) > KNOWN_CDROM_DRIVE_TYPES) - cdrom_set_type(c, KNOWN_CDROM_DRIVE_TYPES); - if (!strcmp(p, def_type)) + p = ini_section_get_string(cat, temp, "86cd"); + /* TODO: Configuration migration, remove when no longer needed. */ + int cdrom_type = cdrom_get_from_internal_name(p); + if (cdrom_type == -1) { + cdrom_type = cdrom_get_from_name(p); + if (cdrom_type == -1) + cdrom_set_type(c, cdrom_get_from_internal_name("86cd")); + else + cdrom_set_type(c, cdrom_type); + } else + cdrom_set_type(c, cdrom_type); + if (cdrom_get_type(c) >= count) + cdrom_set_type(c, count - 1); + if (!strcmp(p, "86cd")) ini_section_delete_var(cat, temp); /* Default values, needed for proper operation of the Settings dialog. */ @@ -1355,7 +1383,7 @@ load_floppy_and_cdrom_drives(void) if (p[0] != 0x00) { if (path_abs(p)) { if (strlen(p) > 511) - fatal("load_floppy_and_cdrom_drives(): strlen(p) > 511 (cdrom[%i].image_path)\n", c); + fatal("Configuration: Length of cdrom_%02i_image_path is more than 511\n", c + 1); else strncpy(cdrom[c].image_path, p, 511); } else @@ -1370,8 +1398,8 @@ load_floppy_and_cdrom_drives(void) if (p) { if (path_abs(p)) { if (strlen(p) > (MAX_IMAGE_PATH_LEN - 1)) - fatal("load_floppy_and_cdrom_drives(): strlen(p) > 2047 " - "(cdrom[%i].image_history[%i])\n", c, i); + fatal("Configuration: Length of cdrom_%02i_image_history_%02i is more " + "than %i\n", c + 1, i + 1, MAX_IMAGE_PATH_LEN - 1); else snprintf(cdrom[c].image_history[i], MAX_IMAGE_PATH_LEN, "%s", p); } else @@ -1386,6 +1414,12 @@ load_floppy_and_cdrom_drives(void) sprintf(temp, "cdrom_%02i_parameters", c + 1); ini_section_delete_var(cat, temp); + sprintf(temp, "cdrom_%02i_speed", c + 1); + ini_section_delete_var(cat, temp); + + sprintf(temp, "cdrom_%02i_type", c + 1); + ini_section_delete_var(cat, temp); + sprintf(temp, "cdrom_%02i_ide_channel", c + 1); ini_section_delete_var(cat, temp); @@ -1484,8 +1518,7 @@ load_other_removable_devices(void) if (p[0] != 0x00) { if (path_abs(p)) { if (strlen(p) > 511) - fatal("load_other_removable_devices(): strlen(p) > 511 (zip_drives[%i].image_path)\n", - c); + fatal("Configuration: Length of zip_%02i_image_path is more than 511\n", c + 1); else strncpy(zip_drives[c].image_path, p, 511); } else @@ -1500,8 +1533,8 @@ load_other_removable_devices(void) if (p) { if (path_abs(p)) { if (strlen(p) > (MAX_IMAGE_PATH_LEN - 1)) - fatal("load_other_removable_devices(): strlen(p) > 2047 " - "(zip_drives[%i].image_history[%i])\n", c, i); + fatal("Configuration: Length of zip_%02i_image_history_%02i is more than %i\n", + c + 1, i + 1, MAX_IMAGE_PATH_LEN - 1); else snprintf(zip_drives[c].image_history[i], MAX_IMAGE_PATH_LEN, "%s", p); } else @@ -1597,8 +1630,7 @@ load_other_removable_devices(void) if (p[0] != 0x00) { if (path_abs(p)) { if (strlen(p) > 511) - fatal("load_other_removable_devices(): strlen(p) > 511 (mo_drives[%i].image_path)\n", - c); + fatal("Configuration: Length of mo_%02i_image_path is more than 511\n", c + 1); else strncpy(mo_drives[c].image_path, p, 511); } else @@ -1613,8 +1645,8 @@ load_other_removable_devices(void) if (p) { if (path_abs(p)) { if (strlen(p) > (MAX_IMAGE_PATH_LEN - 1)) - fatal("load_other_removable_devices(): strlen(p) > 2047 " - "(mo_drives[%i].image_history[%i])\n", c, i); + fatal("Configuration: Length of mo_%02i_image_history_%02i is more than %i\n", + c + 1, i + 1, MAX_IMAGE_PATH_LEN - 1); else snprintf(mo_drives[c].image_history[i], MAX_IMAGE_PATH_LEN, "%s", p); } else @@ -1671,6 +1703,7 @@ load_other_peripherals(void) if (!novell_keycard_enabled) ini_section_delete_var(cat, "novell_keycard_enabled"); + // ISA RAM Boards for (uint8_t c = 0; c < ISAMEM_MAX; c++) { sprintf(temp, "isamem%d_type", c); @@ -1681,6 +1714,17 @@ load_other_peripherals(void) ini_section_delete_var(cat, temp); } + // ISA ROM Boards + for (uint8_t c = 0; c < ISAROM_MAX; c++) { + sprintf(temp, "isarom%d_type", c); + + p = ini_section_get_string(cat, temp, "none"); + isarom_type[c] = isarom_get_from_internal_name(p); + + if (!strcmp(p, "none")) + ini_section_delete_var(cat, temp); + } + p = ini_section_get_string(cat, "isartc_type", "none"); isartc_type = isartc_get_from_internal_name(p); @@ -1688,6 +1732,81 @@ load_other_peripherals(void) ini_section_delete_var(cat, temp); } +#ifndef USE_SDL_UI +/* Load OpenGL 3.0 renderer options. */ +static void +load_gl3_shaders(void) +{ + ini_section_t cat = ini_find_section(config, "GL3 Shaders"); + char *p; + char temp[512]; + int i = 0, shaders = 0; + memset(temp, 0, sizeof(temp)); + memset(gl3_shader_file, 0, sizeof(gl3_shader_file)); + + shaders = ini_section_get_int(cat, "shaders", 0); + if (shaders > MAX_USER_SHADERS) + shaders = MAX_USER_SHADERS; + + if (shaders == 0) { + ini_section_t general = ini_find_section(config, "General"); + if (general) { + p = ini_section_get_string(general, "video_gl_shader", NULL); + if (p) { + if (strlen(p) > 511) + fatal("Configuration: Length of video_gl_shadr is more than 511\n"); + else + strncpy(gl3_shader_file[0], p, 511); + ini_delete_var(config, general, "video_gl_shader"); + return; + } + } + } + + for (i = 0; i < shaders; i++) { + temp[0] = 0; + snprintf(temp, 512, "shader%d", i); + p = ini_section_get_string(cat, temp, ""); + if (p[0]) { + strncpy(gl3_shader_file[i], p, 512); + } else { + gl3_shader_file[i][0] = 0; + break; + } + } +} +#endif + +/* Load "Keybinds" section. */ +static void +load_keybinds(void) +{ + ini_section_t cat = ini_find_section(config, "Keybinds"); + char *p; + char temp[512]; + memset(temp, 0, sizeof(temp)); + + /* Now load values from config */ + for (int x = 0; x < NUM_ACCELS; x++) { + p = ini_section_get_string(cat, acc_keys[x].name, "default"); + /* Check if the binding was marked as cleared */ + if (strcmp(p, "none") == 0) + acc_keys[x].seq[0] = '\0'; + /* If there's no binding in the file, leave it alone. */ + else if (strcmp(p, "default") != 0) { + /* + It would be ideal to validate whether the user entered a + valid combo at this point, but the Qt method for testing that is + not available from C. Fortunately, if you feed Qt an invalid + keysequence string it just assigns nothing, so this won't blow up. + However, to improve the user experience, we should validate keys + and erase any bad combos from config on mainwindow load. + */ + strcpy(acc_keys[x].seq, p); + } + } +} + /* Load the specified or a default configuration file. */ void config_load(void) @@ -1706,7 +1825,7 @@ config_load(void) config = ini_read(cfg_path); - if (!config) { + if (config == NULL) { config = ini_new(); config_changed = 1; @@ -1727,14 +1846,13 @@ config_load(void) gfxcard[0] = video_get_video_from_internal_name("cga"); vid_api = plat_vidapi("default"); vid_resize = 0; - video_fullscreen_first = 1; video_fullscreen_scale = 1; time_sync = TIME_SYNC_ENABLED; hdc_current[0] = hdc_get_from_internal_name("none"); com_ports[0].enabled = 1; com_ports[1].enabled = 1; - for (i = 2; i < SERIAL_MAX; i++) + for (i = 2; i < (SERIAL_MAX - 1); i++) com_ports[i].enabled = 0; lpt_ports[0].enabled = 1; @@ -1756,6 +1874,8 @@ config_load(void) cdrom[0].sound_on = 1; mem_size = 64; isartc_type = 0; + for (i = 0; i < ISAROM_MAX; i++) + isarom_type[i] = 0; for (i = 0; i < ISAMEM_MAX; i++) isamem_type[i] = 0; @@ -1768,6 +1888,8 @@ config_load(void) cassette_pcm = 0; cassette_ui_writeprot = 0; + lang_id = plat_language_code(DEFAULT_LANGUAGE); + config_log("Config file not present or invalid!\n"); } else { load_general(); /* General */ @@ -1784,6 +1906,10 @@ config_load(void) load_floppy_and_cdrom_drives(); /* Floppy and CD-ROM drives */ load_other_removable_devices(); /* Other removable devices */ load_other_peripherals(); /* Other peripherals */ +#ifndef USE_SDL_UI + load_gl3_shaders(); /* GL3 Shaders */ +#endif + load_keybinds(); /* Load shortcut keybinds */ /* Migrate renamed device configurations. */ c = ini_find_section(config, "MDA"); @@ -1821,6 +1947,14 @@ save_general(void) const char *va_name; + ini_section_set_int(cat, "inhibit_multimedia_keys", inhibit_multimedia_keys); + if (inhibit_multimedia_keys == 0) + ini_section_delete_var(cat, "inhibit_multimedia_keys"); + + ini_section_set_int(cat, "sound_muted", sound_muted); + if (sound_muted == 0) + ini_section_delete_var(cat, "sound_muted"); + ini_section_set_int(cat, "vid_resize", vid_resize); if (vid_resize == 0) ini_section_delete_var(cat, "vid_resize"); @@ -1836,11 +1970,6 @@ save_general(void) else ini_section_set_int(cat, "video_fullscreen_scale", video_fullscreen_scale); - if (video_fullscreen_first == 1) - ini_section_delete_var(cat, "video_fullscreen_first"); - else - ini_section_set_int(cat, "video_fullscreen_first", video_fullscreen_first); - if (video_filter_method == 1) ini_section_delete_var(cat, "video_filter_method"); else @@ -1942,18 +2071,13 @@ save_general(void) else ini_section_delete_var(cat, "mouse_sensitivity"); - if (lang_id == DEFAULT_LANGUAGE) + if (lang_id == plat_language_code(DEFAULT_LANGUAGE)) ini_section_delete_var(cat, "language"); else { plat_language_code_r(lang_id, buffer, 511); ini_section_set_string(cat, "language", buffer); } - if (!strcmp(icon_set, "")) - ini_section_delete_var(cat, "iconset"); - else - ini_section_set_string(cat, "iconset", icon_set); - if (enable_discord) ini_section_set_int(cat, "enable_discord", enable_discord); else @@ -1972,10 +2096,6 @@ save_general(void) ini_section_set_int(cat, "video_gl_vsync", video_vsync); else ini_section_delete_var(cat, "video_gl_vsync"); - if (strlen(video_shader) > 0) - ini_section_set_string(cat, "video_gl_shader", video_shader); - else - ini_section_delete_var(cat, "video_gl_shader"); if (do_auto_pause) ini_section_set_int(cat, "do_auto_pause", do_auto_pause); @@ -2115,6 +2235,11 @@ save_video(void) else ini_section_set_int(cat, "xga", xga_standalone_enabled); + if (da2_standalone_enabled == 0) + ini_section_delete_var(cat, "da2"); + else + ini_section_set_int(cat, "da2", da2_standalone_enabled); + // TODO for (uint8_t i = 1; i < GFXCARD_MAX; i ++) { if (gfxcard[i] == 0) @@ -2143,50 +2268,49 @@ save_input_devices(void) ini_section_t cat = ini_find_or_create_section(config, "Input devices"); char temp[512]; char tmp2[512]; - int c; - int d; ini_section_set_string(cat, "mouse_type", mouse_get_internal_name(mouse_type)); if (!joystick_type) { ini_section_delete_var(cat, "joystick_type"); - for (c = 0; c < 16; c++) { - sprintf(tmp2, "joystick_%i_nr", c); + for (int js = 0; js < MAX_PLAT_JOYSTICKS; js++) { + sprintf(tmp2, "joystick_%i_nr", js); ini_section_delete_var(cat, tmp2); - for (d = 0; d < 16; d++) { - sprintf(tmp2, "joystick_%i_axis_%i", c, d); + for (int axis_nr = 0; axis_nr < MAX_JOY_AXES; axis_nr++) { + sprintf(tmp2, "joystick_%i_axis_%i", js, axis_nr); ini_section_delete_var(cat, tmp2); } - for (d = 0; d < 16; d++) { - sprintf(tmp2, "joystick_%i_button_%i", c, d); + for (int button_nr = 0; button_nr < MAX_JOY_BUTTONS; button_nr++) { + sprintf(tmp2, "joystick_%i_button_%i", js, button_nr); ini_section_delete_var(cat, tmp2); } - for (d = 0; d < 16; d++) { - sprintf(tmp2, "joystick_%i_pov_%i", c, d); + for (int pov_nr = 0; pov_nr < MAX_JOY_POVS; pov_nr++) { + sprintf(tmp2, "joystick_%i_pov_%i", js, pov_nr); ini_section_delete_var(cat, tmp2); } } } else { ini_section_set_string(cat, "joystick_type", joystick_get_internal_name(joystick_type)); - for (c = 0; c < joystick_get_max_joysticks(joystick_type); c++) { - sprintf(tmp2, "joystick_%i_nr", c); - ini_section_set_int(cat, tmp2, joystick_state[c].plat_joystick_nr); + for (int js = 0; js < joystick_get_max_joysticks(joystick_type); js++) { + sprintf(tmp2, "joystick_%i_nr", js); + ini_section_set_int(cat, tmp2, joystick_state[0][js].plat_joystick_nr); - if (joystick_state[c].plat_joystick_nr) { - for (d = 0; d < joystick_get_axis_count(joystick_type); d++) { - sprintf(tmp2, "joystick_%i_axis_%i", c, d); - ini_section_set_int(cat, tmp2, joystick_state[c].axis_mapping[d]); + if (joystick_state[0][js].plat_joystick_nr) { + for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) { + sprintf(tmp2, "joystick_%i_axis_%i", js, axis_nr); + ini_section_set_int(cat, tmp2, joystick_state[0][js].axis_mapping[axis_nr]); } - for (d = 0; d < joystick_get_button_count(joystick_type); d++) { - sprintf(tmp2, "joystick_%i_button_%i", c, d); - ini_section_set_int(cat, tmp2, joystick_state[c].button_mapping[d]); + for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) { + sprintf(tmp2, "joystick_%i_button_%i", js, button_nr); + ini_section_set_int(cat, tmp2, joystick_state[0][js].button_mapping[button_nr]); } - for (d = 0; d < joystick_get_pov_count(joystick_type); d++) { - sprintf(tmp2, "joystick_%i_pov_%i", c, d); - sprintf(temp, "%i, %i", joystick_state[c].pov_mapping[d][0], joystick_state[c].pov_mapping[d][1]); + for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) { + sprintf(tmp2, "joystick_%i_pov_%i", js, pov_nr); + sprintf(temp, "%i, %i", joystick_state[0][js].pov_mapping[pov_nr][0], + joystick_state[0][js].pov_mapping[pov_nr][1]); ini_section_set_string(cat, tmp2, temp); } } @@ -2346,10 +2470,8 @@ save_ports(void) { ini_section_t cat = ini_find_or_create_section(config, "Ports (COM & LPT)"); char temp[512]; - int c; - int d; - for (c = 0; c < SERIAL_MAX; c++) { + for (int c = 0; c < (SERIAL_MAX - 1); c++) { sprintf(temp, "serial%d_enabled", c + 1); if (((c < 2) && com_ports[c].enabled) || ((c >= 2) && !com_ports[c].enabled)) ini_section_delete_var(cat, temp); @@ -2363,9 +2485,9 @@ save_ports(void) ini_section_delete_var(cat, temp); } - for (c = 0; c < PARALLEL_MAX; c++) { + for (int c = 0; c < PARALLEL_MAX; c++) { sprintf(temp, "lpt%d_enabled", c + 1); - d = (c == 0) ? 1 : 0; + int d = (c == 0) ? 1 : 0; if (lpt_ports[c].enabled == d) ini_section_delete_var(cat, temp); else @@ -2379,6 +2501,54 @@ save_ports(void) lpt_device_get_internal_name(lpt_ports[c].device)); } +#if 0 +// TODO: Save + for (c = 0; c < GAMEPORT_MAX; c++) { + sprintf(temp, "gameport%d_enabled", c + 1); + d = (c == 0) ? 1 : 0; + if (game_ports[c].enabled == d) + ini_section_delete_var(cat, temp); + else + ini_section_set_int(cat, temp, game_ports[c].enabled); + + sprintf(temp, "gameport%d_device", c + 1); + if (game_ports[c].device == 0) + ini_section_delete_var(cat, temp); + else + ini_section_set_string(cat, temp, + gameport_get_internal_name(game_ports[c].device)); + } + + for (uint8_t c = 0; c < GAMEPORT_MAX; c++) { + sprintf(temp, "gameport%d_enabled", c); + if (gameport_type[c] == 0) + ini_section_delete_var(cat, temp); + else + ini_section_set_string(cat, temp, + gameport_get_internal_name(gameport_type[c])); + } +#endif + + ini_delete_section_if_empty(config, cat); +} + +/* Save "Keybinds" section. */ +static void +save_keybinds(void) +{ + ini_section_t cat = ini_find_or_create_section(config, "Keybinds"); + + for (int x = 0; x < NUM_ACCELS; x++) { + /* Has accelerator been changed from default? */ + if (strcmp(def_acc_keys[x].seq, acc_keys[x].seq) == 0) + ini_section_delete_var(cat, acc_keys[x].name); + /* Check for a cleared binding to avoid saving it as an empty string */ + else if (acc_keys[x].seq[0] == '\0') + ini_section_set_string(cat, acc_keys[x].name, "none"); + else + ini_section_set_string(cat, acc_keys[x].name, acc_keys[x].seq); + } + ini_delete_section_if_empty(config, cat); } @@ -2556,6 +2726,7 @@ save_other_peripherals(void) else ini_section_set_int(cat, "novell_keycard_enabled", novell_keycard_enabled); + // ISA RAM Boards for (uint8_t c = 0; c < ISAMEM_MAX; c++) { sprintf(temp, "isamem%d_type", c); if (isamem_type[c] == 0) @@ -2565,6 +2736,16 @@ save_other_peripherals(void) isamem_get_internal_name(isamem_type[c])); } + // ISA ROM Boards + for (uint8_t c = 0; c < ISAROM_MAX; c++) { + sprintf(temp, "isarom%d_type", c); + if (isarom_type[c] == 0) + ini_section_delete_var(cat, temp); + else + ini_section_set_string(cat, temp, + isarom_get_internal_name(isarom_type[c])); + } + if (isartc_type == 0) ini_section_delete_var(cat, "isartc_type"); else @@ -2574,6 +2755,40 @@ save_other_peripherals(void) ini_delete_section_if_empty(config, cat); } +#ifndef USE_SDL_UI +/* Save "GL3 Shaders" section. */ +static void +save_gl3_shaders(void) +{ + ini_section_t cat = ini_find_or_create_section(config, "GL3 Shaders"); + char temp[512]; + int shaders = 0, i = 0; + + for (i = 0; i < MAX_USER_SHADERS; i++) { + if (gl3_shader_file[i][0] == 0) { + temp[0] = 0; + snprintf(temp, 512, "shader%d", i); + ini_section_delete_var(cat, temp); + break; + } + shaders++; + } + + ini_section_set_int(cat, "shaders", shaders); + if (shaders == 0) { + ini_section_delete_var(cat, "shaders"); + } else { + for (i = 0; i < shaders; i++) { + temp[0] = 0; + snprintf(temp, 512, "shader%d", i); + ini_section_set_string(cat, temp, gl3_shader_file[i]); + } + } + + ini_delete_section_if_empty(config, cat); +} +#endif + /* Save "Hard Disks" section. */ static void save_hard_disks(void) @@ -2587,7 +2802,7 @@ save_hard_disks(void) 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); + p = hdd_bus_to_string(hdd[c].bus_type, 0); sprintf(tmp2, "%u, %u, %u, %i, %s", hdd[c].spt, hdd[c].hpc, hdd[c].tracks, hdd[c].wp, p); ini_section_set_string(cat, temp, tmp2); @@ -2595,25 +2810,26 @@ save_hard_disks(void) ini_section_delete_var(cat, temp); sprintf(temp, "hdd_%02i_mfm_channel", c + 1); - if (hdd_is_valid(c) && (hdd[c].bus == HDD_BUS_MFM)) + if (hdd_is_valid(c) && (hdd[c].bus_type == HDD_BUS_MFM)) ini_section_set_int(cat, temp, hdd[c].mfm_channel); else ini_section_delete_var(cat, temp); sprintf(temp, "hdd_%02i_xta_channel", c + 1); - if (hdd_is_valid(c) && (hdd[c].bus == HDD_BUS_XTA)) + if (hdd_is_valid(c) && (hdd[c].bus_type == HDD_BUS_XTA)) ini_section_set_int(cat, temp, hdd[c].xta_channel); else ini_section_delete_var(cat, temp); sprintf(temp, "hdd_%02i_esdi_channel", c + 1); - if (hdd_is_valid(c) && (hdd[c].bus == HDD_BUS_ESDI)) + if (hdd_is_valid(c) && (hdd[c].bus_type == HDD_BUS_ESDI)) ini_section_set_int(cat, temp, hdd[c].esdi_channel); else ini_section_delete_var(cat, temp); sprintf(temp, "hdd_%02i_ide_channel", c + 1); - if (!hdd_is_valid(c) || ((hdd[c].bus != HDD_BUS_IDE) && (hdd[c].bus != HDD_BUS_ATAPI))) + if (!hdd_is_valid(c) || ((hdd[c].bus_type != HDD_BUS_IDE) && + (hdd[c].bus_type != HDD_BUS_ATAPI))) ini_section_delete_var(cat, temp); else { sprintf(tmp2, "%01u:%01u", hdd[c].ide_channel >> 1, hdd[c].ide_channel & 1); @@ -2624,7 +2840,7 @@ save_hard_disks(void) ini_section_delete_var(cat, temp); sprintf(temp, "hdd_%02i_scsi_location", c + 1); - if (hdd[c].bus != HDD_BUS_SCSI) + if (hdd[c].bus_type != HDD_BUS_SCSI) ini_section_delete_var(cat, temp); else { sprintf(tmp2, "%01u:%02u", hdd[c].scsi_id >> 4, @@ -2656,8 +2872,9 @@ save_hard_disks(void) ini_section_delete_var(cat, temp); sprintf(temp, "hdd_%02i_speed", c + 1); - if (!hdd_is_valid(c) || ((hdd[c].bus != HDD_BUS_ESDI) && (hdd[c].bus != HDD_BUS_IDE) && - (hdd[c].bus != HDD_BUS_SCSI) && (hdd[c].bus != HDD_BUS_ATAPI))) + if (!hdd_is_valid(c) || + ((hdd[c].bus_type != HDD_BUS_ESDI) && (hdd[c].bus_type != HDD_BUS_IDE) && + (hdd[c].bus_type != HDD_BUS_SCSI) && (hdd[c].bus_type != HDD_BUS_ATAPI))) ini_section_delete_var(cat, temp); else ini_section_set_string(cat, temp, hdd_preset_get_internal_name(hdd[c].speed_preset)); @@ -2742,11 +2959,12 @@ save_floppy_and_cdrom_drives(void) ini_section_set_int(cat, temp, cdrom[c].speed); sprintf(temp, "cdrom_%02i_type", c + 1); - if ((cdrom[c].bus_type == 0) || (cdrom[c].bus_type == CDROM_BUS_MITSUMI)) + char *tn = cdrom_get_internal_name(cdrom_get_type(c)); + if ((cdrom[c].bus_type == 0) || (cdrom[c].bus_type == CDROM_BUS_MITSUMI) || + !strcmp(tn, "86cd")) ini_section_delete_var(cat, temp); else - ini_section_set_string(cat, temp, - cdrom_get_internal_name(cdrom_get_type(c))); + ini_section_set_string(cat, temp, tn); sprintf(temp, "cdrom_%02i_parameters", c + 1); if (cdrom[c].bus_type == 0) @@ -2861,6 +3079,19 @@ save_other_removable_devices(void) else ini_section_set_string(cat, temp, zip_drives[c].image_path); } + + for (int i = 0; i < MAX_PREV_IMAGES; i++) { + sprintf(temp, "zip_%02i_image_history_%02i", c + 1, i + 1); + if ((zip_drives[c].image_history[i] == 0) || strlen(zip_drives[c].image_history[i]) == 0) + ini_section_delete_var(cat, temp); + else { + path_normalize(zip_drives[c].image_history[i]); + if (!strnicmp(zip_drives[c].image_history[i], usr_path, strlen(usr_path))) + ini_section_set_string(cat, temp, &zip_drives[c].image_history[i][strlen(usr_path)]); + else + ini_section_set_string(cat, temp, zip_drives[c].image_history[i]); + } + } } for (c = 0; c < MO_NUM; c++) { @@ -2904,6 +3135,19 @@ save_other_removable_devices(void) else ini_section_set_string(cat, temp, mo_drives[c].image_path); } + + for (int i = 0; i < MAX_PREV_IMAGES; i++) { + sprintf(temp, "mo_%02i_image_history_%02i", c + 1, i + 1); + if ((mo_drives[c].image_history[i] == 0) || strlen(mo_drives[c].image_history[i]) == 0) + ini_section_delete_var(cat, temp); + else { + path_normalize(mo_drives[c].image_history[i]); + if (!strnicmp(mo_drives[c].image_history[i], usr_path, strlen(usr_path))) + ini_section_set_string(cat, temp, &mo_drives[c].image_history[i][strlen(usr_path)]); + else + ini_section_set_string(cat, temp, mo_drives[c].image_history[i]); + } + } } ini_delete_section_if_empty(config, cat); @@ -2926,6 +3170,10 @@ config_save(void) save_floppy_and_cdrom_drives(); /* Floppy and CD-ROM drives */ save_other_removable_devices(); /* Other removable devices */ save_other_peripherals(); /* Other peripherals */ +#ifndef USE_SDL_UI + save_gl3_shaders(); /* GL3 Shaders */ +#endif + save_keybinds(); /* Key bindings */ ini_write(config, cfg_path); } diff --git a/src/cpu/386.c b/src/cpu/386.c index 8b612604d..ed4b40ab2 100644 --- a/src/cpu/386.c +++ b/src/cpu/386.c @@ -27,6 +27,7 @@ #include <86box/fdc.h> #include <86box/machine.h> #include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> #include <86box/gdbstub.h> #ifndef OPS_286_386 # define OPS_286_386 @@ -263,18 +264,21 @@ exec386_2386(int32_t cycs) ol = opcode_length[fetchdat & 0xff]; if ((ol == 3) && opcode_has_modrm[fetchdat & 0xff] && (((fetchdat >> 14) & 0x03) == 0x03)) ol = 2; - if (cpu_16bitbus) { + + if (is386) + ins_fetch_fault = cpu_386_check_instruction_fault(); + + /* Breakpoint fault has priority over other faults. */ + if ((cpu_state.abrt == 0) & ins_fetch_fault) { + x86gen(); + ins_fetch_fault = 0; + /* No instructions executed at this point. */ + goto block_ended; + } else if (cpu_16bitbus) { CHECK_READ_CS(MIN(ol, 2)); } else { CHECK_READ_CS(MIN(ol, 4)); } - ins_fetch_fault = cpu_386_check_instruction_fault(); - - /* Breakpoint fault has priority over other faults. */ - if (ins_fetch_fault) { - ins_fetch_fault = 0; - cpu_state.abrt = 1; - } if (!cpu_state.abrt) { #ifdef ENABLE_386_LOG @@ -286,7 +290,6 @@ exec386_2386(int32_t cycs) trap |= !!(cpu_state.flags & T_FLAG); cpu_state.pc++; - cpu_state.eflags &= ~(RF_FLAG); if (opcode == 0xf0) in_lock = 1; x86_2386_opcodes[(opcode | cpu_state.op32) & 0x3ff](fetchdat); @@ -314,6 +317,7 @@ exec386_2386(int32_t cycs) if (cpu_end_block_after_ins) cpu_end_block_after_ins--; +block_ended: if (cpu_state.abrt) { flags_rebuild(); tempi = cpu_state.abrt & ABRT_MASK; @@ -336,6 +340,17 @@ exec386_2386(int32_t cycs) #endif } } + + if (is386 && !x86_was_reset && ins_fetch_fault) + x86gen(); + } else if (new_ne) { + flags_rebuild(); + new_ne = 0; +#ifndef USE_NEW_DYNAREC + oldcs = CS; +#endif + cpu_state.oldpc = cpu_state.pc; + x86_int(16); } else if (trap) { flags_rebuild(); if (trap & 2) dr[6] |= 0x8000; diff --git a/src/cpu/386_common.c b/src/cpu/386_common.c index dcbe3608c..2853e3c9a 100644 --- a/src/cpu/386_common.c +++ b/src/cpu/386_common.c @@ -72,6 +72,7 @@ extern uint8_t *pccache2; extern int optype; extern uint32_t pccache; +int new_ne = 0; int in_sys = 0; int unmask_a20_in_smm = 0; uint32_t old_rammask = 0xffffffff; @@ -106,6 +107,12 @@ uint32_t backupregs[16]; x86seg _oldds; +uint8_t rep_op = 0x00; +uint8_t is_smint = 0; + +uint16_t io_port = 0x0000; +uint32_t io_val = 0x00000000; + int opcode_has_modrm[256] = { 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, /*00*/ 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, /*10*/ @@ -1214,7 +1221,7 @@ smram_restore_state_amd_k(uint32_t *saved_state) } static void -smram_save_state_cyrix(uint32_t *saved_state, UNUSED(int in_hlt)) +smram_save_state_cyrix(uint32_t *saved_state, int in_hlt) { saved_state[0] = dr[7]; saved_state[1] = cpu_state.flags | (cpu_state.eflags << 16); @@ -1223,6 +1230,35 @@ smram_save_state_cyrix(uint32_t *saved_state, UNUSED(int in_hlt)) saved_state[4] = cpu_state.pc; saved_state[5] = CS | (CPL << 21); saved_state[6] = 0x00000000; + saved_state[7] = 0x00010000; + + if (((opcode >= 0x6e) && (opcode <= 0x6f)) || ((opcode >= 0xe6) && (opcode <= 0xe7)) || + ((opcode >= 0xee) && (opcode <= 0xef))) { + saved_state[6] |= 0x00000002; + saved_state[7] = (opcode & 0x01) ? (cpu_state.op32 ? 0x000f0000 : 0x00030000) : 0x00010000; + } else if (((opcode == 0xf2) || (opcode == 0xf3)) && (rep_op >= 0x6e) && (rep_op <= 0x6f)) { + saved_state[6] |= 0x00000006; + saved_state[7] = (rep_op & 0x01) ? (cpu_state.op32 ? 0x000f0000 : 0x00030000) : 0x00010000; + } else if (((opcode == 0xf2) || (opcode == 0xf3)) && (rep_op >= 0x6e) && (rep_op <= 0x6f)) { + saved_state[6] |= 0x00000004; + saved_state[7] = (rep_op & 0x01) ? (cpu_state.op32 ? 0x000f0000 : 0x00030000) : 0x00010000; + } + + if (is_smint) { + saved_state[6] |= 0x00000008; + is_smint = 0; + } + + if (in_hlt) + saved_state[6] |= 0x00000010; + + saved_state[7] |= io_port; + saved_state[8] = io_val; + + if (saved_state[6] & 0x00000002) + saved_state[9] = ESI; + else + saved_state[9] = EDI; } static void @@ -1233,6 +1269,13 @@ smram_restore_state_cyrix(uint32_t *saved_state) cpu_state.eflags = saved_state[1] >> 16; cr0 = saved_state[2]; cpu_state.pc = saved_state[4]; + /* Restore CPL. */ + cpu_state.seg_cs.access = (cpu_state.seg_cs.access & ~0x9f) | (((saved_state[5] >> 21) & 0x03) << 5); + + if (saved_state[6] & 0x00000002) + ESI = saved_state[9]; + else + EDI = saved_state[9]; } void @@ -1367,6 +1410,9 @@ enter_smm(int in_hlt) writememl(0, smram_state - 0x14, saved_state[4]); writememl(0, smram_state - 0x18, saved_state[5]); writememl(0, smram_state - 0x24, saved_state[6]); + writememl(0, smram_state - 0x28, saved_state[7]); + writememl(0, smram_state - 0x2c, saved_state[8]); + writememl(0, smram_state - 0x30, saved_state[9]); } else { for (uint8_t n = 0; n < SMM_SAVE_STATE_MAP_SIZE; n++) { smram_state -= 4; @@ -1403,26 +1449,44 @@ enter_smm(int in_hlt) void enter_smm_check(int in_hlt) { - if ((in_smm == 0) && smi_line) { -#ifdef ENABLE_386_COMMON_LOG - x386_common_log("SMI while not in SMM\n"); -#endif - enter_smm(in_hlt); - } else if ((in_smm == 1) && smi_line) { - /* Mark this so that we don't latch more than one SMI. */ -#ifdef ENABLE_386_COMMON_LOG - x386_common_log("SMI while in unlatched SMM\n"); -#endif - smi_latched = 1; - } else if ((in_smm == 2) && smi_line) { - /* Mark this so that we don't latch more than one SMI. */ -#ifdef ENABLE_386_COMMON_LOG - x386_common_log("SMI while in latched SMM\n"); -#endif - } + uint8_t ccr1_check = ((ccr1 & (CCR1_USE_SMI | CCR1_SMAC | CCR1_SM3)) == + (CCR1_USE_SMI | CCR1_SM3)) && (cyrix.arr[3].size > 0); + + if (smi_line) { + if (!is_cxsmm || ccr1_check) switch (in_smm) { + default: +#ifdef ENABLE_386_COMMON_LOG + fatal("SMI while in_smm = %i\n", in_smm); + break; +#endif + case 0: +#ifdef ENABLE_386_COMMON_LOG + x386_common_log("SMI while not in SMM\n"); +#endif + enter_smm(in_hlt); + break; + case 1: + /* Mark this so that we don't latch more than one SMI. */ +#ifdef ENABLE_386_COMMON_LOG + x386_common_log("SMI while in unlatched SMM\n"); +#endif + smi_latched = 1; + break; + case 2: +#ifdef ENABLE_386_COMMON_LOG + x386_common_log("SMI while in latched SMM\n"); +#endif + break; + } +#ifdef ENABLE_386_COMMON_LOG + else { + x386_common_log("SMI while in Cyrix disabled mode\n"); + x386_common_log("lol\n"); + } +#endif - if (smi_line) smi_line = 0; + } } void @@ -1451,6 +1515,9 @@ leave_smm(void) else cyrix_load_seg_descriptor_2386(smram_state - 0x20, &cpu_state.seg_cs); saved_state[6] = readmeml(0, smram_state - 0x24); + saved_state[7] = readmeml(0, smram_state - 0x28); + saved_state[8] = readmeml(0, smram_state - 0x2c); + saved_state[9] = readmeml(0, smram_state - 0x30); } else { for (uint8_t n = 0; n < SMM_SAVE_STATE_MAP_SIZE; n++) { smram_state -= 4; @@ -1824,7 +1891,7 @@ cpu_386_check_instruction_fault(void) } int -sysenter(uint32_t fetchdat) +sysenter(UNUSED(uint32_t fetchdat)) { #ifdef ENABLE_386_COMMON_LOG x386_common_log("SYSENTER called\n"); @@ -1906,7 +1973,7 @@ sysenter(uint32_t fetchdat) } int -sysexit(uint32_t fetchdat) +sysexit(UNUSED(uint32_t fetchdat)) { #ifdef ENABLE_386_COMMON_LOG x386_common_log("SYSEXIT called\n"); @@ -1993,7 +2060,7 @@ sysexit(uint32_t fetchdat) } int -syscall_op(uint32_t fetchdat) +syscall_op(UNUSED(uint32_t fetchdat)) { #ifdef ENABLE_386_COMMON_LOG x386_common_log("SYSCALL called\n"); @@ -2045,7 +2112,7 @@ syscall_op(uint32_t fetchdat) } int -sysret(uint32_t fetchdat) +sysret(UNUSED(uint32_t fetchdat)) { #ifdef ENABLE_386_COMMON_LOG x386_common_log("SYSRET called\n"); @@ -2137,6 +2204,12 @@ cpu_fast_off_reset(void) void smi_raise(void) { + uint8_t ccr1_check = ((ccr1 & (CCR1_USE_SMI | CCR1_SMAC | CCR1_SM3)) == + (CCR1_USE_SMI | CCR1_SM3)) && (cyrix.arr[3].size > 0); + + if (is_cxsmm && !ccr1_check) + return; + if (is486 && (cpu_fast_off_flags & 0x80000000)) cpu_fast_off_advance(); diff --git a/src/cpu/386_common.h b/src/cpu/386_common.h index ec40612ee..83ef4e72b 100644 --- a/src/cpu/386_common.h +++ b/src/cpu/386_common.h @@ -277,6 +277,19 @@ int checkio(uint32_t port, int mask); #define CHECK_WRITE(chseg, low, high) \ CHECK_WRITE_COMMON(chseg, low, high) +#define CHECK_WRITE_2OP(chseg, low, high, low2, high2) \ + if ((low < (chseg)->limit_low) || (high > (chseg)->limit_high) || (low2 < (chseg)->limit_low) || (high2 > (chseg)->limit_high) || !((chseg)->access & 2) || ((msw & 1) && !(cpu_state.eflags & VM_FLAG) && ((chseg)->access & 8))) { \ + x86gpf("Limit check (WRITE)", 0); \ + return 1; \ + } \ + if (msw & 1 && !(cpu_state.eflags & VM_FLAG) && !((chseg)->access & 0x80)) { \ + if ((chseg) == &cpu_state.seg_ss) \ + x86ss(NULL, (chseg)->seg & 0xfffc); \ + else \ + x86np("Write to seg not present", (chseg)->seg & 0xfffc); \ + return 1; \ + } + #define CHECK_WRITE_REP(chseg, low, high) \ if ((low < (chseg)->limit_low) || (high > (chseg)->limit_high)) { \ x86gpf("Limit check (WRITE REP)", 0); \ diff --git a/src/cpu/386_dynarec.c b/src/cpu/386_dynarec.c index 590d6f5c7..fd6285057 100644 --- a/src/cpu/386_dynarec.c +++ b/src/cpu/386_dynarec.c @@ -30,6 +30,7 @@ #include <86box/fdc.h> #include <86box/machine.h> #include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> #include <86box/gdbstub.h> #ifdef USE_DYNAREC # include "codegen.h" @@ -275,11 +276,7 @@ exec386_dynarec_int(void) cpu_block_end = 0; x86_was_reset = 0; -# ifdef USE_DEBUG_REGS_486 - if (trap & 2) { -# else if (trap == 2) { -# endif /* Handle the T bit in the new TSS first. */ CPU_BLOCK_END(); goto block_ended; @@ -296,13 +293,6 @@ exec386_dynarec_int(void) cpu_state.ea_seg = &cpu_state.seg_ds; cpu_state.ssegs = 0; -# ifdef USE_DEBUG_REGS_486 - if (UNLIKELY(cpu_386_check_instruction_fault())) { - x86gen(); - goto block_ended; - } -# endif - fetchdat = fastreadl_fetch(cs + cpu_state.pc); # ifdef ENABLE_386_DYNAREC_LOG if (in_smm) @@ -357,6 +347,8 @@ exec386_dynarec_int(void) CPU_BLOCK_END(); if (smi_line) CPU_BLOCK_END(); + else if (new_ne) + CPU_BLOCK_END(); else if (trap) CPU_BLOCK_END(); else if (nmi && nmi_enable && nmi_mask) @@ -366,14 +358,8 @@ exec386_dynarec_int(void) } block_ended: - if (!cpu_state.abrt && trap) { -# ifdef USE_DEBUG_REGS_486 - //pclog("Debug trap 0x%X\n", trap); - if (trap & 2) dr[6] |= 0x8000; - if (trap & 1) dr[6] |= 0x4000; -# else + if (!cpu_state.abrt && !new_ne && trap) { dr[6] |= (trap == 2) ? 0x8000 : 0x4000; -# endif trap = 0; # ifndef USE_NEW_DYNAREC @@ -386,7 +372,11 @@ block_ended: cpu_end_block_after_ins = 0; } +#if defined(__linux__) && !defined(__clang__) && defined(USE_NEW_DYNAREC) +static inline void __attribute__((optimize("O2"))) +#else static __inline void +#endif exec386_dynarec_dyn(void) { uint32_t start_pc = 0; @@ -598,6 +588,8 @@ exec386_dynarec_dyn(void) if (cpu_init) CPU_BLOCK_END(); + if (new_ne) + CPU_BLOCK_END(); if ((cpu_state.flags & T_FLAG) || (trap == 2)) CPU_BLOCK_END(); if (smi_line) @@ -622,7 +614,7 @@ exec386_dynarec_dyn(void) cpu_end_block_after_ins = 0; - if ((!cpu_state.abrt || (cpu_state.abrt & ABRT_EXPECTED)) && !x86_was_reset) + if ((!cpu_state.abrt || (cpu_state.abrt & ABRT_EXPECTED)) && !new_ne && !x86_was_reset) codegen_block_end_recompile(block); if (x86_was_reset) @@ -698,6 +690,8 @@ exec386_dynarec_dyn(void) if (cpu_init) CPU_BLOCK_END(); + if (new_ne) + CPU_BLOCK_END(); if (cpu_state.flags & T_FLAG) CPU_BLOCK_END(); if (smi_line) @@ -722,7 +716,7 @@ exec386_dynarec_dyn(void) cpu_end_block_after_ins = 0; - if ((!cpu_state.abrt || (cpu_state.abrt & ABRT_EXPECTED)) && !x86_was_reset) + if ((!cpu_state.abrt || (cpu_state.abrt & ABRT_EXPECTED)) && !new_ne && !x86_was_reset) codegen_block_end(); if (x86_was_reset) @@ -805,6 +799,15 @@ exec386_dynarec(int32_t cycs) } } + if (new_ne) { +# ifndef USE_NEW_DYNAREC + oldcs = CS; +# endif + cpu_state.oldpc = cpu_state.pc; + new_ne = 0; + x86_int(16); + } + if (smi_line) enter_smm_check(0); else if (nmi && nmi_enable && nmi_mask) { @@ -882,6 +885,9 @@ exec386(int32_t cycs) cycdiff = 0; oldcyc = cycles; while (cycdiff < cycle_period) { +#ifdef USE_DEBUG_REGS_486 + int ins_fetch_fault = 0; +#endif ins_cycles = cycles; #ifndef USE_NEW_DYNAREC @@ -899,8 +905,14 @@ exec386(int32_t cycs) cpu_state.ssegs = 0; #ifdef USE_DEBUG_REGS_486 - if (UNLIKELY(cpu_386_check_instruction_fault())) { + if (is386) + ins_fetch_fault = cpu_386_check_instruction_fault(); + + /* Breakpoint fault has priority over other faults. */ + if ((cpu_state.abrt == 0) & ins_fetch_fault) { x86gen(); + ins_fetch_fault = 0; + /* No instructions executed at this point. */ goto block_ended; } #endif @@ -952,11 +964,13 @@ exec386(int32_t cycs) block_ended: #endif if (cpu_state.abrt) { + uint8_t oop = opcode; flags_rebuild(); tempi = cpu_state.abrt & ABRT_MASK; cpu_state.abrt = 0; x86_doabrt(tempi); if (cpu_state.abrt) { + pclog("Double fault - %02X\n", oop); cpu_state.abrt = 0; #ifndef USE_NEW_DYNAREC CS = oldcs; @@ -973,23 +987,31 @@ block_ended: #endif } } + +#ifdef USE_DEBUG_REGS_486 + if (is386 && !x86_was_reset && ins_fetch_fault) + x86gen(); +#endif + } else if (new_ne) { + flags_rebuild(); + + new_ne = 0; +#ifndef USE_NEW_DYNAREC + oldcs = CS; +#endif + cpu_state.oldpc = cpu_state.pc; + x86_int(16); } else if (trap) { flags_rebuild(); #ifdef USE_DEBUG_REGS_486 - if (trap & 1) - dr[6] |= 0x4000; - if (trap & 2) - dr[6] |= 0x8000; + if (trap & 2) dr[6] |= 0x8000; + if (trap & 1) dr[6] |= 0x4000; #endif - trap = 0; #ifndef USE_NEW_DYNAREC oldcs = CS; #endif cpu_state.oldpc = cpu_state.pc; -#ifndef USE_DEBUG_REGS_486 - dr[6] |= 0x4000; -#endif x86_int(1); } diff --git a/src/cpu/386_dynarec_ops.c b/src/cpu/386_dynarec_ops.c index c31b725b2..3d9a7e080 100644 --- a/src/cpu/386_dynarec_ops.c +++ b/src/cpu/386_dynarec_ops.c @@ -1,6 +1,7 @@ #include -#include #include +#include +#include #include #include #include diff --git a/src/cpu/386_ops.h b/src/cpu/386_ops.h index b8ef9edda..5113ca817 100644 --- a/src/cpu/386_ops.h +++ b/src/cpu/386_ops.h @@ -206,6 +206,7 @@ extern void x386_dynarec_log(const char *fmt, ...); # include "x86_ops_mmx_mov.h" # include "x86_ops_mmx_pack.h" # include "x86_ops_mmx_shift.h" +# include "x86_ops_mmx_emmi.h" #endif #include "x86_ops_mov.h" #ifdef OPS_286_386 @@ -859,12 +860,12 @@ const OpFn OP_TABLE(c486_0f)[1024] = { /*00*/ op0F00_a16, op0F01_l_a16, opLAR_l_a16, opLSL_l_a16, ILLEGAL, ILLEGAL, opCLTS, opLOADALL386, opINVD, opWBINVD, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, /*10*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, /*20*/ opMOV_r_CRx_a16,opMOV_r_DRx_a16,opMOV_CRx_r_a16,opMOV_DRx_r_a16,opMOV_r_TRx_a16,ILLEGAL, opMOV_TRx_r_a16,ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, -/*30*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, opRDSHR_a16, opWRSHR_a16, opSVDC_a16, opRSDC_a16, opSVLDT_a16, opRSLDT_a16, opSVTS_a16, opRSTS_a16, opSMINT, ILLEGAL, +/*30*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, opRDSHR_a16, opWRSHR_a16, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, /*40*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, /*50*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, /*60*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, -/*70*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*70*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, opSVDC_a16, opRSDC_a16, opSVLDT_a16, opRSLDT_a16, opSVTS_a16, opRSTS_a16, opSMINT, ILLEGAL, /*80*/ opJO_l, opJNO_l, opJB_l, opJNB_l, opJE_l, opJNE_l, opJBE_l, opJNBE_l, opJS_l, opJNS_l, opJP_l, opJNP_l, opJL_l, opJNL_l, opJLE_l, opJNLE_l, /*90*/ opSETO_a16, opSETNO_a16, opSETB_a16, opSETNB_a16, opSETE_a16, opSETNE_a16, opSETBE_a16, opSETNBE_a16, opSETS_a16, opSETNS_a16, opSETP_a16, opSETNP_a16, opSETL_a16, opSETNL_a16, opSETLE_a16, opSETNLE_a16, @@ -1384,7 +1385,6 @@ const OpFn OP_TABLE(pentium_0f)[1024] = { // clang-format on }; -# ifdef USE_CYRIX_6X86 const OpFn OP_TABLE(c6x86_0f)[1024] = { // clang-format off /*16-bit data, 16-bit addr*/ @@ -1392,7 +1392,7 @@ const OpFn OP_TABLE(c6x86_0f)[1024] = { /*00*/ op0F00_a16, op0F01_w_a16, opLAR_w_a16, opLSL_w_a16, ILLEGAL, ILLEGAL, opCLTS, ILLEGAL, opINVD, opWBINVD, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, /*10*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, /*20*/ opMOV_r_CRx_a16,opMOV_r_DRx_a16,opMOV_CRx_r_a16,opMOV_DRx_r_a16,opMOV_r_TRx_a16,ILLEGAL, opMOV_TRx_r_a16,ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, -/*30*/ opWRMSR, opRDTSC, opRDMSR, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*30*/ opWRMSR, opRDTSC, opRDMSR, ILLEGAL, ILLEGAL, ILLEGAL, opRDSHR_a16, opWRSHR_a16, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, /*40*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, /*50*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, @@ -1414,7 +1414,7 @@ const OpFn OP_TABLE(c6x86_0f)[1024] = { /*00*/ op0F00_a16, op0F01_l_a16, opLAR_l_a16, opLSL_l_a16, ILLEGAL, ILLEGAL, opCLTS, ILLEGAL, opINVD, opWBINVD, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, /*10*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, /*20*/ opMOV_r_CRx_a16,opMOV_r_DRx_a16,opMOV_CRx_r_a16,opMOV_DRx_r_a16,opMOV_r_TRx_a16,ILLEGAL, opMOV_TRx_r_a16,ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, -/*30*/ opWRMSR, opRDTSC, opRDMSR, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*30*/ opWRMSR, opRDTSC, opRDMSR, ILLEGAL, ILLEGAL, ILLEGAL, opRDSHR_a16, opWRSHR_a16, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, /*40*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, /*50*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, @@ -1436,7 +1436,7 @@ const OpFn OP_TABLE(c6x86_0f)[1024] = { /*00*/ op0F00_a32, op0F01_w_a32, opLAR_w_a32, opLSL_w_a32, ILLEGAL, ILLEGAL, opCLTS, ILLEGAL, opINVD, opWBINVD, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, /*10*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, /*20*/ opMOV_r_CRx_a32,opMOV_r_DRx_a32,opMOV_CRx_r_a32,opMOV_DRx_r_a32,opMOV_r_TRx_a32,ILLEGAL, opMOV_TRx_r_a32,ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, -/*30*/ opWRMSR, opRDTSC, opRDMSR, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*30*/ opWRMSR, opRDTSC, opRDMSR, ILLEGAL, ILLEGAL, ILLEGAL, opRDSHR_a32, opWRSHR_a32, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, /*40*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, /*50*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, @@ -1458,7 +1458,99 @@ const OpFn OP_TABLE(c6x86_0f)[1024] = { /*00*/ op0F00_a32, op0F01_l_a32, opLAR_l_a32, opLSL_l_a32, ILLEGAL, ILLEGAL, opCLTS, ILLEGAL, opINVD, opWBINVD, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, /*10*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, /*20*/ opMOV_r_CRx_a32,opMOV_r_DRx_a32,opMOV_CRx_r_a32,opMOV_DRx_r_a32,opMOV_r_TRx_a32,ILLEGAL, opMOV_TRx_r_a32,ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, -/*30*/ opWRMSR, opRDTSC, opRDMSR, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*30*/ opWRMSR, opRDTSC, opRDMSR, ILLEGAL, ILLEGAL, ILLEGAL, opRDSHR_a32, opWRSHR_a32, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, + +/*40*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*50*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*60*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*70*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, opSVDC_a32, opRSDC_a32, opSVLDT_a32, opRSLDT_a32, opSVTS_a32, opRSTS_a32, opSMINT, ILLEGAL, + +/*80*/ opJO_l, opJNO_l, opJB_l, opJNB_l, opJE_l, opJNE_l, opJBE_l, opJNBE_l, opJS_l, opJNS_l, opJP_l, opJNP_l, opJL_l, opJNL_l, opJLE_l, opJNLE_l, +/*90*/ opSETO_a32, opSETNO_a32, opSETB_a32, opSETNB_a32, opSETE_a32, opSETNE_a32, opSETBE_a32, opSETNBE_a32, opSETS_a32, opSETNS_a32, opSETP_a32, opSETNP_a32, opSETL_a32, opSETNL_a32, opSETLE_a32, opSETNLE_a32, +/*a0*/ opPUSH_FS_l, opPOP_FS_l, opCPUID, opBT_l_r_a32, opSHLD_l_i_a32, opSHLD_l_CL_a32,ILLEGAL, ILLEGAL, opPUSH_GS_l, opPOP_GS_l, opRSM, opBTS_l_r_a32, opSHRD_l_i_a32, opSHRD_l_CL_a32,ILLEGAL, opIMUL_l_l_a32, +/*b0*/ opCMPXCHG_b_a32,opCMPXCHG_l_a32,opLSS_l_a32, opBTR_l_r_a32, opLFS_l_a32, opLGS_l_a32, opMOVZX_l_b_a32,opMOVZX_l_w_a32,ILLEGAL, ILLEGAL, opBA_l_a32, opBTC_l_r_a32, opBSF_l_a32, opBSR_l_a32, opMOVSX_l_b_a32,opMOVSX_l_w_a32, + +/*c0*/ opXADD_b_a32, opXADD_l_a32, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, opCMPXCHG8B_a32,opBSWAP_EAX, opBSWAP_ECX, opBSWAP_EDX, opBSWAP_EBX, opBSWAP_ESP, opBSWAP_EBP, opBSWAP_ESI, opBSWAP_EDI, +/*d0*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*e0*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*f0*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, + // clang-format on +}; + +const OpFn OP_TABLE(c6x86l_0f)[1024] = { + // clang-format off + /*16-bit data, 16-bit addr*/ +/* 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f*/ +/*00*/ op0F00_a16, op0F01_w_a16, opLAR_w_a16, opLSL_w_a16, ILLEGAL, ILLEGAL, opCLTS, ILLEGAL, opINVD, opWBINVD, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*10*/ opMOV_b_r_a16, opMOV_w_r_a16, opMOV_r_b_a16, opMOV_r_w_a16, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*20*/ opMOV_r_CRx_a16,opMOV_r_DRx_a16,opMOV_CRx_r_a16,opMOV_DRx_r_a16,opMOV_r_TRx_a16,ILLEGAL, opMOV_TRx_r_a16,ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*30*/ opWRMSR, opRDTSC, opRDMSR, ILLEGAL, ILLEGAL, ILLEGAL, opRDSHR_a16, opWRSHR_a16, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, + +/*40*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*50*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*60*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*70*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, opSVDC_a16, opRSDC_a16, opSVLDT_a16, opRSLDT_a16, opSVTS_a16, opRSTS_a16, opSMINT, ILLEGAL, + +/*80*/ opJO_w, opJNO_w, opJB_w, opJNB_w, opJE_w, opJNE_w, opJBE_w, opJNBE_w, opJS_w, opJNS_w, opJP_w, opJNP_w, opJL_w, opJNL_w, opJLE_w, opJNLE_w, +/*90*/ opSETO_a16, opSETNO_a16, opSETB_a16, opSETNB_a16, opSETE_a16, opSETNE_a16, opSETBE_a16, opSETNBE_a16, opSETS_a16, opSETNS_a16, opSETP_a16, opSETNP_a16, opSETL_a16, opSETNL_a16, opSETLE_a16, opSETNLE_a16, +/*a0*/ opPUSH_FS_w, opPOP_FS_w, opCPUID, opBT_w_r_a16, opSHLD_w_i_a16, opSHLD_w_CL_a16,ILLEGAL, ILLEGAL, opPUSH_GS_w, opPOP_GS_w, opRSM, opBTS_w_r_a16, opSHRD_w_i_a16, opSHRD_w_CL_a16,ILLEGAL, opIMUL_w_w_a16, +/*b0*/ opCMPXCHG_b_a16,opCMPXCHG_w_a16,opLSS_w_a16, opBTR_w_r_a16, opLFS_w_a16, opLGS_w_a16, opMOVZX_w_b_a16,opMOVZX_w_w_a16,ILLEGAL, ILLEGAL, opBA_w_a16, opBTC_w_r_a16, opBSF_w_a16, opBSR_w_a16, opMOVSX_w_b_a16,ILLEGAL, + +/*c0*/ opXADD_b_a16, opXADD_w_a16, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, opCMPXCHG8B_a16,opBSWAP_EAX, opBSWAP_ECX, opBSWAP_EDX, opBSWAP_EBX, opBSWAP_ESP, opBSWAP_EBP, opBSWAP_ESI, opBSWAP_EDI, +/*d0*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*e0*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*f0*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, opSVDC_a16, opRSDC_a16, opSVLDT_a16, opRSLDT_a16, opSVTS_a16, opRSTS_a16, opSMINT, ILLEGAL, + + /*32-bit data, 16-bit addr*/ +/* 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f*/ +/*00*/ op0F00_a16, op0F01_l_a16, opLAR_l_a16, opLSL_l_a16, ILLEGAL, ILLEGAL, opCLTS, ILLEGAL, opINVD, opWBINVD, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*10*/ opMOV_b_r_a16, opMOV_l_r_a16, opMOV_r_b_a16, opMOV_r_l_a16, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*20*/ opMOV_r_CRx_a16,opMOV_r_DRx_a16,opMOV_CRx_r_a16,opMOV_DRx_r_a16,opMOV_r_TRx_a16,ILLEGAL, opMOV_TRx_r_a16,ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*30*/ opWRMSR, opRDTSC, opRDMSR, ILLEGAL, ILLEGAL, ILLEGAL, opRDSHR_a16, opWRSHR_a16, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, + +/*40*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*50*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*60*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*70*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, + +/*80*/ opJO_l, opJNO_l, opJB_l, opJNB_l, opJE_l, opJNE_l, opJBE_l, opJNBE_l, opJS_l, opJNS_l, opJP_l, opJNP_l, opJL_l, opJNL_l, opJLE_l, opJNLE_l, +/*90*/ opSETO_a16, opSETNO_a16, opSETB_a16, opSETNB_a16, opSETE_a16, opSETNE_a16, opSETBE_a16, opSETNBE_a16, opSETS_a16, opSETNS_a16, opSETP_a16, opSETNP_a16, opSETL_a16, opSETNL_a16, opSETLE_a16, opSETNLE_a16, +/*a0*/ opPUSH_FS_l, opPOP_FS_l, opCPUID, opBT_l_r_a16, opSHLD_l_i_a16, opSHLD_l_CL_a16,ILLEGAL, ILLEGAL, opPUSH_GS_l, opPOP_GS_l, opRSM, opBTS_l_r_a16, opSHRD_l_i_a16, opSHRD_l_CL_a16,ILLEGAL, opIMUL_l_l_a16, +/*b0*/ opCMPXCHG_b_a16,opCMPXCHG_l_a16,opLSS_l_a16, opBTR_l_r_a16, opLFS_l_a16, opLGS_l_a16, opMOVZX_l_b_a16,opMOVZX_l_w_a16,ILLEGAL, ILLEGAL, opBA_l_a16, opBTC_l_r_a16, opBSF_l_a16, opBSR_l_a16, opMOVSX_l_b_a16,opMOVSX_l_w_a16, + +/*c0*/ opXADD_b_a16, opXADD_l_a16, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, opCMPXCHG8B_a16,opBSWAP_EAX, opBSWAP_ECX, opBSWAP_EDX, opBSWAP_EBX, opBSWAP_ESP, opBSWAP_EBP, opBSWAP_ESI, opBSWAP_EDI, +/*d0*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*e0*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*f0*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, + + /*16-bit data, 32-bit addr*/ +/* 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f*/ +/*00*/ op0F00_a32, op0F01_w_a32, opLAR_w_a32, opLSL_w_a32, ILLEGAL, ILLEGAL, opCLTS, ILLEGAL, opINVD, opWBINVD, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*10*/ opMOV_b_r_a32, opMOV_w_r_a32, opMOV_r_b_a32, opMOV_r_w_a32, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*20*/ opMOV_r_CRx_a32,opMOV_r_DRx_a32,opMOV_CRx_r_a32,opMOV_DRx_r_a32,opMOV_r_TRx_a32,ILLEGAL, opMOV_TRx_r_a32,ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*30*/ opWRMSR, opRDTSC, opRDMSR, ILLEGAL, ILLEGAL, ILLEGAL, opRDSHR_a32, opWRSHR_a32, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, + +/*40*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*50*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*60*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*70*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, opSVDC_a32, opRSDC_a32, opSVLDT_a32, opRSLDT_a32, opSVTS_a32, opRSTS_a32, opSMINT, ILLEGAL, + +/*80*/ opJO_w, opJNO_w, opJB_w, opJNB_w, opJE_w, opJNE_w, opJBE_w, opJNBE_w, opJS_w, opJNS_w, opJP_w, opJNP_w, opJL_w, opJNL_w, opJLE_w, opJNLE_w, +/*90*/ opSETO_a32, opSETNO_a32, opSETB_a32, opSETNB_a32, opSETE_a32, opSETNE_a32, opSETBE_a32, opSETNBE_a32, opSETS_a32, opSETNS_a32, opSETP_a32, opSETNP_a32, opSETL_a32, opSETNL_a32, opSETLE_a32, opSETNLE_a32, +/*a0*/ opPUSH_FS_w, opPOP_FS_w, opCPUID, opBT_w_r_a32, opSHLD_w_i_a32, opSHLD_w_CL_a32,ILLEGAL, ILLEGAL, opPUSH_GS_w, opPOP_GS_w, opRSM, opBTS_w_r_a32, opSHRD_w_i_a32, opSHRD_w_CL_a32,ILLEGAL, opIMUL_w_w_a32, +/*b0*/ opCMPXCHG_b_a32,opCMPXCHG_w_a32,opLSS_w_a32, opBTR_w_r_a32, opLFS_w_a32, opLGS_w_a32, opMOVZX_w_b_a32,opMOVZX_w_w_a32,ILLEGAL, ILLEGAL, opBA_w_a32, opBTC_w_r_a32, opBSF_w_a32, opBSR_w_a32, opMOVSX_w_b_a32,ILLEGAL, + +/*c0*/ opXADD_b_a32, opXADD_w_a32, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, opCMPXCHG8B_a32,opBSWAP_EAX, opBSWAP_ECX, opBSWAP_EDX, opBSWAP_EBX, opBSWAP_ESP, opBSWAP_EBP, opBSWAP_ESI, opBSWAP_EDI, +/*d0*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*e0*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*f0*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, + + /*32-bit data, 32-bit addr*/ +/* 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f*/ +/*00*/ op0F00_a32, op0F01_l_a32, opLAR_l_a32, opLSL_l_a32, ILLEGAL, ILLEGAL, opCLTS, ILLEGAL, opINVD, opWBINVD, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*10*/ opMOV_b_r_a32, opMOV_l_r_a32, opMOV_r_b_a32, opMOV_r_l_a32, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*20*/ opMOV_r_CRx_a32,opMOV_r_DRx_a32,opMOV_CRx_r_a32,opMOV_DRx_r_a32,opMOV_r_TRx_a32,ILLEGAL, opMOV_TRx_r_a32,ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*30*/ opWRMSR, opRDTSC, opRDMSR, ILLEGAL, ILLEGAL, ILLEGAL, opRDSHR_a32, opWRSHR_a32, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, /*40*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, /*50*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, @@ -1476,7 +1568,6 @@ const OpFn OP_TABLE(c6x86_0f)[1024] = { /*f0*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, // clang-format on }; -# endif /* USE_CYRIX_6X86 */ const OpFn OP_TABLE(pentiummmx_0f)[1024] = { // clang-format off @@ -1754,7 +1845,6 @@ const OpFn OP_TABLE(k62_0f)[1024] = { // clang-format on }; -# ifdef USE_CYRIX_6X86 const OpFn OP_TABLE(c6x86mx_0f)[1024] = { // clang-format off /*16-bit data, 16-bit addr*/ @@ -1765,7 +1855,7 @@ const OpFn OP_TABLE(c6x86mx_0f)[1024] = { /*30*/ opWRMSR, opRDTSC, opRDMSR, opRDPMC, ILLEGAL, ILLEGAL, opRDSHR_a16, opWRSHR_a16, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, /*40*/ opCMOVO_w_a16, opCMOVNO_w_a16, opCMOVB_w_a16, opCMOVNB_w_a16, opCMOVE_w_a16, opCMOVNE_w_a16, opCMOVBE_w_a16, opCMOVNBE_w_a16,opCMOVS_w_a16, opCMOVNS_w_a16, opCMOVP_w_a16, opCMOVNP_w_a16, opCMOVL_w_a16, opCMOVNL_w_a16, opCMOVLE_w_a16, opCMOVNLE_w_a16, -/*50*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*50*/ opPAVEB_a16, opPADDSIW_a16, opPMAGW_a16, ILLEGAL, opPDISTIB_a16, opPSUBSIW_a16, ILLEGAL, ILLEGAL, opPMVZB_a16, opPMULHRWC_a16, opPMVNZB_a16, opPMVLZB_a16, opPMVGEZB_a16, opPMULHRIW_a16, opPMACHRIW_a16, ILLEGAL, /*60*/ opPUNPCKLBW_a16,opPUNPCKLWD_a16,opPUNPCKLDQ_a16,opPACKSSWB_a16, opPCMPGTB_a16, opPCMPGTW_a16, opPCMPGTD_a16, opPACKUSWB_a16, opPUNPCKHBW_a16,opPUNPCKHWD_a16,opPUNPCKHDQ_a16,opPACKSSDW_a16, ILLEGAL, ILLEGAL, opMOVD_l_mm_a16,opMOVQ_q_mm_a16, /*70*/ ILLEGAL, opPSxxW_imm, opPSxxD_imm, opPSxxQ_imm, opPCMPEQB_a16, opPCMPEQW_a16, opPCMPEQD_a16, opEMMS, opSVDC_a16, opRSDC_a16, opSVLDT_a16, opRSLDT_a16, opSVTS_a16, opRSTS_a16, opMOVD_mm_l_a16_cx,opMOVQ_mm_q_a16, @@ -1787,7 +1877,7 @@ const OpFn OP_TABLE(c6x86mx_0f)[1024] = { /*30*/ opWRMSR, opRDTSC, opRDMSR, opRDPMC, ILLEGAL, ILLEGAL, opRDSHR_a16, opWRSHR_a16, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, /*40*/ opCMOVO_l_a16, opCMOVNO_l_a16, opCMOVB_l_a16, opCMOVNB_l_a16, opCMOVE_l_a16, opCMOVNE_l_a16, opCMOVBE_l_a16, opCMOVNBE_l_a16,opCMOVS_l_a16, opCMOVNS_l_a16, opCMOVP_l_a16, opCMOVNP_l_a16, opCMOVL_l_a16, opCMOVNL_l_a16, opCMOVLE_l_a16, opCMOVNLE_l_a16, -/*50*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*50*/ opPAVEB_a16, opPADDSIW_a16, opPMAGW_a16, ILLEGAL, opPDISTIB_a16, opPSUBSIW_a16, ILLEGAL, ILLEGAL, opPMVZB_a16, opPMULHRWC_a16, opPMVNZB_a16, opPMVLZB_a16, opPMVGEZB_a16, opPMULHRIW_a16, opPMACHRIW_a16, ILLEGAL, /*60*/ opPUNPCKLBW_a16,opPUNPCKLWD_a16,opPUNPCKLDQ_a16,opPACKSSWB_a16, opPCMPGTB_a16, opPCMPGTW_a16, opPCMPGTD_a16, opPACKUSWB_a16, opPUNPCKHBW_a16,opPUNPCKHWD_a16,opPUNPCKHDQ_a16,opPACKSSDW_a16, ILLEGAL, ILLEGAL, opMOVD_l_mm_a16,opMOVQ_q_mm_a16, /*70*/ ILLEGAL, opPSxxW_imm, opPSxxD_imm, opPSxxQ_imm, opPCMPEQB_a16, opPCMPEQW_a16, opPCMPEQD_a16, opEMMS, opSVDC_a16, opRSDC_a16, opSVLDT_a16, opRSLDT_a16, opSVTS_a16, opRSTS_a16, opMOVD_mm_l_a16_cx,opMOVQ_mm_q_a16, @@ -1809,7 +1899,7 @@ const OpFn OP_TABLE(c6x86mx_0f)[1024] = { /*30*/ opWRMSR, opRDTSC, opRDMSR, opRDPMC, ILLEGAL, ILLEGAL, opRDSHR_a32, opWRSHR_a32, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, /*40*/ opCMOVO_w_a32, opCMOVNO_w_a32, opCMOVB_w_a32, opCMOVNB_w_a32, opCMOVE_w_a32, opCMOVNE_w_a32, opCMOVBE_w_a32, opCMOVNBE_w_a32,opCMOVS_w_a32, opCMOVNS_w_a32, opCMOVP_w_a32, opCMOVNP_w_a32, opCMOVL_w_a32, opCMOVNL_w_a32, opCMOVLE_w_a32, opCMOVNLE_w_a32, -/*50*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*50*/ opPAVEB_a32, opPADDSIW_a32, opPMAGW_a32, ILLEGAL, opPDISTIB_a32, opPSUBSIW_a32, ILLEGAL, ILLEGAL, opPMVZB_a32, opPMULHRWC_a32, opPMVNZB_a32, opPMVLZB_a32, opPMVGEZB_a32, opPMULHRIW_a32, opPMACHRIW_a32, ILLEGAL, /*60*/ opPUNPCKLBW_a32,opPUNPCKLWD_a32,opPUNPCKLDQ_a32,opPACKSSWB_a32, opPCMPGTB_a32, opPCMPGTW_a32, opPCMPGTD_a32, opPACKUSWB_a32, opPUNPCKHBW_a32,opPUNPCKHWD_a32,opPUNPCKHDQ_a32,opPACKSSDW_a32, ILLEGAL, ILLEGAL, opMOVD_l_mm_a32,opMOVQ_q_mm_a32, /*70*/ ILLEGAL, opPSxxW_imm, opPSxxD_imm, opPSxxQ_imm, opPCMPEQB_a32, opPCMPEQW_a32, opPCMPEQD_a32, opEMMS, opSVDC_a32, opRSDC_a32, opSVLDT_a32, opRSLDT_a32, opSVTS_a32, opRSTS_a32, opMOVD_mm_l_a32_cx,opMOVQ_mm_q_a32, @@ -1831,7 +1921,7 @@ const OpFn OP_TABLE(c6x86mx_0f)[1024] = { /*30*/ opWRMSR, opRDTSC, opRDMSR, opRDPMC, ILLEGAL, ILLEGAL, opRDSHR_a32, opWRSHR_a32, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, /*40*/ opCMOVO_l_a32, opCMOVNO_l_a32, opCMOVB_l_a32, opCMOVNB_l_a32, opCMOVE_l_a32, opCMOVNE_l_a32, opCMOVBE_l_a32, opCMOVNBE_l_a32,opCMOVS_l_a32, opCMOVNS_l_a32, opCMOVP_l_a32, opCMOVNP_l_a32, opCMOVL_l_a32, opCMOVNL_l_a32, opCMOVLE_l_a32, opCMOVNLE_l_a32, -/*50*/ ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, +/*50*/ opPAVEB_a32, opPADDSIW_a32, opPMAGW_a32, ILLEGAL, opPDISTIB_a32, opPSUBSIW_a32, ILLEGAL, ILLEGAL, opPMVZB_a32, opPMULHRWC_a32, opPMVNZB_a32, opPMVLZB_a32, opPMVGEZB_a32, opPMULHRIW_a32, opPMACHRIW_a32, ILLEGAL, /*60*/ opPUNPCKLBW_a32,opPUNPCKLWD_a32,opPUNPCKLDQ_a32,opPACKSSWB_a32, opPCMPGTB_a32, opPCMPGTW_a32, opPCMPGTD_a32, opPACKUSWB_a32, opPUNPCKHBW_a32,opPUNPCKHWD_a32,opPUNPCKHDQ_a32,opPACKSSDW_a32, ILLEGAL, ILLEGAL, opMOVD_l_mm_a32,opMOVQ_q_mm_a32, /*70*/ ILLEGAL, opPSxxW_imm, opPSxxD_imm, opPSxxQ_imm, opPCMPEQB_a32, opPCMPEQW_a32, opPCMPEQD_a32, opEMMS, opSVDC_a16, opRSDC_a16, opSVLDT_a16, opRSLDT_a16, opSVTS_a16, opRSTS_a16, opMOVD_mm_l_a32_cx,opMOVQ_mm_q_a32, @@ -1846,7 +1936,6 @@ const OpFn OP_TABLE(c6x86mx_0f)[1024] = { /*f0*/ ILLEGAL, opPSLLW_a32, opPSLLD_a32, opPSLLQ_a32, ILLEGAL, opPMADDWD_a32, ILLEGAL, ILLEGAL, opPSUBB_a32, opPSUBW_a32, opPSUBD_a32, ILLEGAL, opPADDB_a32, opPADDW_a32, opPADDD_a32, ILLEGAL, // clang-format on }; -# endif /* USE_CYRIX_6X86 */ const OpFn OP_TABLE(pentiumpro_0f)[1024] = { // clang-format off diff --git a/src/cpu/8080.c b/src/cpu/8080.c deleted file mode 100644 index 7a7e7b96c..000000000 --- a/src/cpu/8080.c +++ /dev/null @@ -1,290 +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. - * - * 8080 CPU emulation. - * - * Authors: Cacodemon345 - * - * Copyright 2022 Cacodemon345 - */ - -#include -#include -#include "cpu.h" -#include <86box/timer.h> -#include <86box/i8080.h> -#include <86box/mem.h> -#include <86box/plat_unused.h> - -static int completed = 1; -static int in_rep = 0; -static int repeating = 0; -static int rep_c_flag = 0; -static int oldc; -static int cycdiff; -#ifdef UNUSED_8080_VARS -static int prefetching = 1; -static int refresh = 0; -static int clear_lock = 0; - -static uint32_t cpu_src = 0; -static uint32_t cpu_dest = 0; -static uint32_t cpu_data = 0; -#endif - -static void -clock_start(void) -{ - cycdiff = cycles; -} - -static void -clock_end(void) -{ - int diff = cycdiff - cycles; - - /* On 808x systems, clock speed is usually crystal frequency divided by an integer. */ - tsc += (uint64_t) diff * (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 -i8080_wait(int c, int bus) -{ - cycles -= c; - if (bus < 2) { - clock_end(); - clock_start(); - } -} - -#ifdef UNUSED_8080_FUNCS -static uint8_t -readmemb(uint32_t a) -{ - uint8_t ret; - - i8080_wait(4, 1); - ret = read_mem_b(a); - - return ret; -} - -static uint8_t -ins_fetch(i8080 *cpu) -{ - uint8_t ret = cpu->readmembyte(cpu->pmembase + cpu->pc); - - cpu->pc++; - return ret; -} -#endif - -void -transfer_from_808x(i8080 *cpu) -{ - cpu->hl = BX; - cpu->bc = CX; - cpu->de = DX; - cpu->a = AL; - cpu->flags = cpu_state.flags & 0xFF; - cpu->sp = BP; - cpu->pc = cpu_state.pc; - cpu->oldpc = cpu_state.oldpc; - cpu->pmembase = cs; - cpu->dmembase = ds; -} - -void -transfer_to_808x(i8080 *cpu) -{ - BX = cpu->hl; - CX = cpu->bc; - DX = cpu->de; - AL = cpu->a; - cpu_state.flags &= 0xFF00; - cpu_state.flags |= cpu->flags & 0xFF; - BP = cpu->sp; - cpu_state.pc = cpu->pc; -} - -uint8_t -getreg_i8080(i8080 *cpu, uint8_t reg) -{ - uint8_t ret = 0xFF; - switch (reg) { - case 0x0: - ret = cpu->b; - break; - case 0x1: - ret = cpu->c; - break; - case 0x2: - ret = cpu->d; - break; - case 0x3: - ret = cpu->e; - break; - case 0x4: - ret = cpu->h; - break; - case 0x5: - ret = cpu->l; - break; - case 0x6: - ret = cpu->readmembyte(cpu->dmembase + cpu->sp); - break; - case 0x7: - ret = cpu->a; - break; - } - return ret; -} - -uint8_t -getreg_i8080_emu(i8080 *cpu, uint8_t reg) -{ - uint8_t ret = 0xFF; - switch (reg) { - case 0x0: - ret = CH; - break; - case 0x1: - ret = CL; - break; - case 0x2: - ret = DH; - break; - case 0x3: - ret = DL; - break; - case 0x4: - ret = BH; - break; - case 0x5: - ret = BL; - break; - case 0x6: - ret = cpu->readmembyte(cpu->dmembase + BP); - break; - case 0x7: - ret = AL; - break; - } - return ret; -} - -void -setreg_i8080_emu(i8080 *cpu, uint8_t reg, uint8_t val) -{ - switch (reg) { - case 0x0: - CH = val; - break; - case 0x1: - CL = val; - break; - case 0x2: - DH = val; - break; - case 0x3: - DL = val; - break; - case 0x4: - BH = val; - break; - case 0x5: - BL = val; - break; - case 0x6: - cpu->writemembyte(cpu->dmembase + BP, val); - break; - case 0x7: - AL = val; - break; - } -} - -void -setreg_i8080(i8080 *cpu, uint8_t reg, uint8_t val) -{ - switch (reg) { - case 0x0: - cpu->b = val; - break; - case 0x1: - cpu->c = val; - break; - case 0x2: - cpu->d = val; - break; - case 0x3: - cpu->e = val; - break; - case 0x4: - cpu->h = val; - break; - case 0x5: - cpu->l = val; - break; - case 0x6: - cpu->writemembyte(cpu->dmembase + cpu->sp, val); - break; - case 0x7: - cpu->a = val; - break; - } -} - -void -interpret_exec8080(UNUSED(i8080 *cpu), uint8_t opcode) -{ - switch (opcode) { - case 0x00: - { - break; - } - } -} - -/* Actually implement i8080 emulation. */ -void -exec8080(i8080 *cpu, int cycs) -{ -#ifdef UNUSED_8080_VARS - uint8_t temp = 0, temp2; - uint8_t old_af; - uint8_t handled = 0; - uint16_t addr, tempw; - uint16_t new_ip; - int bits; -#endif - - cycles += cycs; - - while (cycles > 0) { - cpu->startclock(); - - if (!repeating) { - cpu->oldpc = cpu->pc; - opcode = cpu->fetchinstruction(cpu); - oldc = cpu->flags & C_FLAG_I8080; - i8080_wait(1, 0); - } - completed = 1; - if (completed) { - repeating = 0; - in_rep = 0; - rep_c_flag = 0; - cpu->endclock(); - if (cpu->checkinterrupts) - cpu->checkinterrupts(); - } - } -} diff --git a/src/cpu/808x.c b/src/cpu/808x.c index d815551ae..dda688ee1 100644 --- a/src/cpu/808x.c +++ b/src/cpu/808x.c @@ -18,10 +18,13 @@ #include #include #include +#include #include #include #include +#include "i8080.h" + #define HAVE_STDARG_H #include <86box/86box.h> #include "cpu.h" @@ -35,6 +38,8 @@ #include <86box/ppi.h> #include <86box/timer.h> #include <86box/gdbstub.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> /* Is the CPU 8088 or 8086. */ int is8086 = 0; @@ -69,6 +74,9 @@ static int in_rep = 0, repeating = 0, rep_c_flag = 0; static int oldc, clear_lock = 0; static int refresh = 0, cycdiff; +static i8080 emulated_processor; +static bool cpu_md_write_disable = 1; + /* Various things needed for 8087. */ #define OP_TABLE(name) ops_##name @@ -153,6 +161,98 @@ x808x_log(const char *fmt, ...) static void pfq_add(int c, int add); static void set_pzs(int bits); +void +prefetch_queue_set_pos(int pos) +{ + pfq_pos = pos; +} + +void +prefetch_queue_set_ip(uint16_t ip) +{ + pfq_ip = ip; +} + +void +prefetch_queue_set_prefetching(int p) +{ + prefetching = p; +} + +int +prefetch_queue_get_pos(void) +{ + return pfq_pos; +} + +uint16_t +prefetch_queue_get_ip(void) +{ + return pfq_ip; +} + +int +prefetch_queue_get_prefetching(void) +{ + return prefetching; +} + +int +prefetch_queue_get_size(void) +{ + return pfq_size; +} +static void set_if(int cond); + +void +sync_from_i8080(void) +{ + AL = emulated_processor.a; + BH = emulated_processor.h; + BL = emulated_processor.l; + CH = emulated_processor.b; + CL = emulated_processor.c; + DH = emulated_processor.d; + DL = emulated_processor.e; + BP = emulated_processor.sp; + + cpu_state.pc = emulated_processor.pc; + cpu_state.flags &= 0xFF00; + cpu_state.flags |= emulated_processor.sf << 7; + cpu_state.flags |= emulated_processor.zf << 6; + cpu_state.flags |= emulated_processor.hf << 4; + cpu_state.flags |= emulated_processor.pf << 2; + cpu_state.flags |= 1 << 1; + cpu_state.flags |= emulated_processor.cf << 0; + set_if(emulated_processor.iff); +} + +void +sync_to_i8080(void) +{ + if (!is_nec) + return; + emulated_processor.a = AL; + emulated_processor.h = BH; + emulated_processor.l = BL; + emulated_processor.b = CH; + emulated_processor.c = CL; + emulated_processor.d = DH; + emulated_processor.e = DL; + emulated_processor.sp = BP; + emulated_processor.pc = cpu_state.pc; + emulated_processor.iff = !!(cpu_state.flags & I_FLAG); + + emulated_processor.sf = (cpu_state.flags >> 7) & 1; + emulated_processor.zf = (cpu_state.flags >> 6) & 1; + emulated_processor.hf = (cpu_state.flags >> 4) & 1; + emulated_processor.pf = (cpu_state.flags >> 2) & 1; + emulated_processor.cf = (cpu_state.flags >> 0) & 1; + + emulated_processor.interrupt_delay = noint; +} + + uint16_t get_last_addr(void) { @@ -539,6 +639,33 @@ load_seg(uint16_t seg, x86seg *s) s->seg = seg & 0xffff; } +uint8_t fetch_i8080_opcode(UNUSED(void* priv), uint16_t addr) +{ + return readmemb(cs + addr); +} + +uint8_t fetch_i8080_data(UNUSED(void* priv), uint16_t addr) +{ + return readmemb(ds + addr); +} + +void put_i8080_data(UNUSED(void* priv), uint16_t addr, uint8_t val) +{ + writememb(ds, addr, val); +} + +static uint8_t i8080_port_in(UNUSED(void* priv), uint8_t port) +{ + cpu_io(8, 0, port); + return AL; +} + +static void i8080_port_out(UNUSED(void* priv), uint8_t port, uint8_t val) +{ + AL = val; + cpu_io(8, 1, port); +} + void reset_808x(int hard) { @@ -576,6 +703,14 @@ reset_808x(int hard) use_custom_nmi_vector = 0x00; custom_nmi_vector = 0x00000000; + + cpu_md_write_disable = 1; + i8080_init(&emulated_processor); + emulated_processor.write_byte = put_i8080_data; + emulated_processor.read_byte = fetch_i8080_data; + emulated_processor.read_byte_seg = fetch_i8080_opcode; + emulated_processor.port_in = i8080_port_in; + emulated_processor.port_out = i8080_port_out; } static void @@ -815,7 +950,7 @@ pop(void) } static void -access(int num, int bits) +access(int num, UNUSED(int bits)) { switch (num) { case 0: @@ -951,6 +1086,11 @@ interrupt(uint16_t addr) uint16_t new_cs, new_ip; uint16_t tempf; + if (!(cpu_state.flags & MD_FLAG) && is_nec) { + sync_from_i8080(); + x808x_log("CALLN/INT#/NMI#\n"); + } + addr <<= 2; cpu_state.eaaddr = addr; old_cs = CS; @@ -967,6 +1107,8 @@ interrupt(uint16_t addr) tempf = cpu_state.flags & (is_nec ? 0x8fd7 : 0x0fd7); push(&tempf); cpu_state.flags &= ~(I_FLAG | T_FLAG); + if (is_nec) + cpu_state.flags |= MD_FLAG; access(40, 16); push(&old_cs); old_ip = cpu_state.pc; @@ -977,6 +1119,65 @@ interrupt(uint16_t addr) push(&old_ip); } +/* Ditto, but for breaking into emulation mode. */ +static void +interrupt_brkem(uint16_t addr) +{ + uint16_t old_cs, old_ip; + uint16_t new_cs, new_ip; + uint16_t tempf; + + 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); + tempf = cpu_state.flags & (is_nec ? 0x8fd7 : 0x0fd7); + push(&tempf); + cpu_state.flags &= ~(MD_FLAG); + cpu_md_write_disable = 0; + access(40, 16); + push(&old_cs); + old_ip = cpu_state.pc; + load_cs(new_cs); + access(68, 16); + set_ip(new_ip); + access(41, 16); + push(&old_ip); + sync_to_i8080(); + x808x_log("BRKEM mode\n"); +} + +void +retem_i8080(void) +{ + sync_from_i8080(); + + prefetching = 0; + pfq_clear(); + + set_ip(pop()); + load_cs(pop()); + cpu_state.flags = pop(); + + emulated_processor.iff = !!(cpu_state.flags & I_FLAG); + + cpu_md_write_disable = 1; + + noint = 1; + nmi_enable = 1; + + x808x_log("RETEM mode\n"); +} + void interrupt_808x(uint16_t addr) { @@ -990,6 +1191,11 @@ custom_nmi(void) uint16_t new_cs, new_ip; uint16_t tempf; + if (!(cpu_state.flags & MD_FLAG) && is_nec) { + sync_from_i8080(); + pclog("NMI# (CUTSOM)\n"); + } + cpu_state.eaaddr = 0x0002; old_cs = CS; access(5, 16); @@ -1007,6 +1213,8 @@ custom_nmi(void) tempf = cpu_state.flags & (is_nec ? 0x8fd7 : 0x0fd7); push(&tempf); cpu_state.flags &= ~(I_FLAG | T_FLAG); + if (is_nec) + cpu_state.flags |= MD_FLAG; access(40, 16); push(&old_cs); old_ip = cpu_state.pc; @@ -1419,7 +1627,7 @@ set_pzs(int bits) } static void -set_co_mul(int bits, int carry) +set_co_mul(UNUSED(int bits), int carry) { set_cf(carry); set_of(carry); @@ -1634,28 +1842,75 @@ cpu_data_opff_rm(void) } } +uint8_t +cpu_inb(uint16_t port) +{ + int old_cycles = cycles; + uint8_t ret; + + wait(is_mazovia ? 5 : 4, 1); + old_cycles = cycles; + + ret = inb(port); + + resub_cycles(old_cycles); + + return ret; +} + uint16_t cpu_inw(uint16_t port) { + int old_cycles = cycles; + uint16_t ret; + + wait(is_mazovia ? 5 : 4, 1); if (is8086 && !(port & 1)) { - wait(4, 0); + old_cycles = cycles; + ret = inw(port); } else { - wait(8, 0); + wait(is_mazovia ? 5 : 4, 1); + old_cycles = cycles; + ret = inb(port++); + ret |= (inb(port) << 8); } - return inw(port); + resub_cycles(old_cycles); + + return ret; +} + +void +cpu_outb(uint16_t port, uint16_t val) +{ + int old_cycles = cycles; + + wait(is_mazovia ? 5 : 4, 1); + old_cycles = cycles; + + outb(port, val); + + resub_cycles(old_cycles); } void cpu_outw(uint16_t port, uint16_t val) { + int old_cycles = cycles; + + wait(is_mazovia ? 5 : 4, 1); + if (is8086 && !(port & 1)) { - wait(4, 0); + old_cycles = cycles; + outw(port, val); } else { - wait(8, 0); + wait(is_mazovia ? 5 : 4, 1); + old_cycles = cycles; + outb(port++, val); + outb(port, val >> 8); } - return outw(port, val); + resub_cycles(old_cycles); } /* Executes instructions up to the specified number of cycles. */ @@ -1681,6 +1936,15 @@ execx86(int cycs) while (cycles > 0) { clock_start(); + if (is_nec && !(cpu_state.flags & MD_FLAG)) { + i8080_step(&emulated_processor); + set_if(emulated_processor.iff); + cycles -= emulated_processor.cyc; + emulated_processor.cyc = 0; + completed = 1; + goto exec_completed; + } + if (!repeating) { cpu_state.oldpc = cpu_state.pc; opcode = pfq_fetchb(); @@ -1804,8 +2068,7 @@ execx86(int cycs) writememw(es, DI, cpu_inw(DX)); DI += (cpu_state.flags & D_FLAG) ? -2 : 2; } else { - wait(4, 0); - writememb(es, DI, inb(DX)); + writememb(es, DI, cpu_inb(DX)); DI += (cpu_state.flags & D_FLAG) ? -1 : 1; } @@ -1833,8 +2096,7 @@ execx86(int cycs) cpu_outw(DX, readmemw(dest_seg, SI)); SI += (cpu_state.flags & D_FLAG) ? -2 : 2; } else { - wait(4, 0); - outb(DX, readmemb(dest_seg + SI)); + cpu_outb(DX, readmemb(dest_seg + SI)); SI += (cpu_state.flags & D_FLAG) ? -1 : 1; } if (in_rep == 0) @@ -2256,8 +2518,8 @@ execx86(int cycs) break; case 0xFF: /* BRKEM */ - /* Unimplemented for now. */ - fatal("808x: Unsupported 8080 emulation mode attempted to enter into!"); + interrupt_brkem(pfq_fetchb()); + handled = 1; break; default: @@ -2769,11 +3031,12 @@ execx86(int cycs) break; case 0x9D: /*POPF*/ access(25, 16); - if (is_nec) + if (is_nec && cpu_md_write_disable) cpu_state.flags = pop() | 0x8002; else cpu_state.flags = pop() | 0x0002; wait(1, 0); + sync_to_i8080(); break; case 0x9E: /*SAHF*/ wait(1, 0); @@ -3039,13 +3302,15 @@ execx86(int cycs) access(62, 8); set_ip(new_ip); access(45, 8); - if (is_nec) + if (is_nec && cpu_md_write_disable) cpu_state.flags = pop() | 0x8002; else cpu_state.flags = pop() | 0x0002; wait(5, 0); noint = 1; nmi_enable = 1; + if (is_nec && !(cpu_state.flags & MD_FLAG)) + sync_to_i8080(); break; case 0xD0: @@ -3174,10 +3439,13 @@ execx86(int cycs) set_pzs(8); break; case 0xD6: /*SALC*/ - wait(1, 0); - AL = (cpu_state.flags & C_FLAG) ? 0xff : 0x00; - wait(1, 0); - break; + if (!is_nec) { + wait(1, 0); + AL = (cpu_state.flags & C_FLAG) ? 0xff : 0x00; + wait(1, 0); + break; + } + fallthrough; case 0xD7: /*XLATB*/ cpu_state.eaaddr = (BX + AL) & 0xffff; access(4, 8); @@ -3571,7 +3839,7 @@ execx86(int cycs) break; } } - +exec_completed: if (completed) { repeating = 0; ovr_seg = NULL; diff --git a/src/cpu/CMakeLists.txt b/src/cpu/CMakeLists.txt index 890d02e3e..dc7f5ac11 100644 --- a/src/cpu/CMakeLists.txt +++ b/src/cpu/CMakeLists.txt @@ -29,7 +29,7 @@ add_library(cpu OBJECT x86seg_2386.c x87.c x87_timings.c - 8080.c + i8080.c ) if(AMD_K5) @@ -42,20 +42,12 @@ endif() endif() -if(CYRIX_6X86) - target_compile_definitions(cpu PRIVATE USE_CYRIX_6X86) - -if(DYNAREC) - add_library(ct686 OBJECT codegen_timing_686.c) - target_link_libraries(86Box ct686) -endif() -endif() - if(DYNAREC) target_sources(cpu PRIVATE 386_dynarec_ops.c) add_library(cgt OBJECT codegen_timing_486.c + codegen_timing_686.c codegen_timing_common.c codegen_timing_k6.c codegen_timing_pentium.c diff --git a/src/cpu/codegen_timing_486.c b/src/cpu/codegen_timing_486.c index 90d682211..d8f05cfd3 100644 --- a/src/cpu/codegen_timing_486.c +++ b/src/cpu/codegen_timing_486.c @@ -328,7 +328,7 @@ codegen_timing_486_start(void) } void -codegen_timing_486_prefix(uint8_t prefix, uint32_t fetchdat) +codegen_timing_486_prefix(uint8_t prefix, UNUSED(uint32_t fetchdat)) { timing_count += COUNT(opcode_timings_486[prefix], 0); last_prefix = prefix; diff --git a/src/cpu/codegen_timing_k5.c b/src/cpu/codegen_timing_k5.c index 42b1129fe..8ce2f4cea 100644 --- a/src/cpu/codegen_timing_k5.c +++ b/src/cpu/codegen_timing_k5.c @@ -8,6 +8,7 @@ #include <86box/mem.h> #include "cpu.h" #include <86box/machine.h> +#include <86box/plat_unused.h> #include "x86.h" #include "x86_ops.h" @@ -2037,7 +2038,7 @@ codegen_timing_k5_start(void) } void -codegen_timing_k5_prefix(uint8_t prefix, uint32_t fetchdat) +codegen_timing_k5_prefix(uint8_t prefix, UNUSED(uint32_t fetchdat)) { if (prefix != 0x0f) decode_timestamp++; @@ -2047,7 +2048,7 @@ codegen_timing_k5_prefix(uint8_t prefix, uint32_t fetchdat) } void -codegen_timing_k5_opcode(uint8_t opcode, uint32_t fetchdat, int op_32, uint32_t op_pc) +codegen_timing_k5_opcode(uint8_t opcode, UNUSED(uint32_t fetchdat), int op_32, uint32_t op_pc) { const risc86_instruction_t **ins_table; const uint64_t *deps; diff --git a/src/cpu/codegen_timing_k6.c b/src/cpu/codegen_timing_k6.c index 5566fbbcd..34297211b 100644 --- a/src/cpu/codegen_timing_k6.c +++ b/src/cpu/codegen_timing_k6.c @@ -8,6 +8,7 @@ #include <86box/mem.h> #include "cpu.h" #include <86box/machine.h> +#include <86box/plat_unused.h> #include "x86.h" #include "x86_ops.h" @@ -2037,7 +2038,7 @@ codegen_timing_k6_start(void) } void -codegen_timing_k6_prefix(uint8_t prefix, uint32_t fetchdat) +codegen_timing_k6_prefix(uint8_t prefix, UNUSED(uint32_t fetchdat)) { if (prefix != 0x0f) decode_timestamp++; @@ -2047,7 +2048,7 @@ codegen_timing_k6_prefix(uint8_t prefix, uint32_t fetchdat) } void -codegen_timing_k6_opcode(uint8_t opcode, uint32_t fetchdat, int op_32, uint32_t op_pc) +codegen_timing_k6_opcode(uint8_t opcode, UNUSED(uint32_t fetchdat), int op_32, uint32_t op_pc) { const risc86_instruction_t **ins_table; const uint64_t *deps; diff --git a/src/cpu/codegen_timing_p6.c b/src/cpu/codegen_timing_p6.c index a22813068..42db319c3 100644 --- a/src/cpu/codegen_timing_p6.c +++ b/src/cpu/codegen_timing_p6.c @@ -1845,7 +1845,7 @@ codegen_timing_p6_start(void) } void -codegen_timing_p6_prefix(uint8_t prefix, uint32_t fetchdat) +codegen_timing_p6_prefix(uint8_t prefix, UNUSED(uint32_t fetchdat)) { if (prefix != 0x0f) decode_timestamp++; @@ -1855,7 +1855,7 @@ codegen_timing_p6_prefix(uint8_t prefix, uint32_t fetchdat) } void -codegen_timing_p6_opcode(uint8_t opcode, uint32_t fetchdat, int op_32, UNUSED(uint32_t op_pc)) +codegen_timing_p6_opcode(uint8_t opcode, UNUSED(uint32_t fetchdat), int op_32, UNUSED(uint32_t op_pc)) { const macro_op_t **ins_table; const uint64_t *deps; diff --git a/src/cpu/codegen_timing_winchip.c b/src/cpu/codegen_timing_winchip.c index 3597517ce..0d39f4151 100644 --- a/src/cpu/codegen_timing_winchip.c +++ b/src/cpu/codegen_timing_winchip.c @@ -328,7 +328,7 @@ codegen_timing_winchip_start(void) } void -codegen_timing_winchip_prefix(uint8_t prefix, uint32_t fetchdat) +codegen_timing_winchip_prefix(uint8_t prefix, UNUSED(uint32_t fetchdat)) { timing_count += COUNT(opcode_timings_winchip[prefix], 0); last_prefix = prefix; diff --git a/src/cpu/codegen_timing_winchip2.c b/src/cpu/codegen_timing_winchip2.c index f37fe3366..696a059cf 100644 --- a/src/cpu/codegen_timing_winchip2.c +++ b/src/cpu/codegen_timing_winchip2.c @@ -589,7 +589,7 @@ codegen_timing_winchip2_start(void) } static void -codegen_timing_winchip2_prefix(uint8_t prefix, uint32_t fetchdat) +codegen_timing_winchip2_prefix(uint8_t prefix, UNUSED(uint32_t fetchdat)) { if (prefix == 0x0f) { /*0fh prefix is 'free'*/ diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index 0802fa3ac..ec026d95e 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -40,6 +40,7 @@ #include <86box/nmi.h> #include <86box/pic.h> #include <86box/pci.h> +#include <86box/smram.h> #include <86box/timer.h> #include <86box/gdbstub.h> #include <86box/plat_fallthrough.h> @@ -50,13 +51,6 @@ #endif /* USE_DYNAREC */ #include "x87_timings.h" -#define CCR1_USE_SMI (1 << 1) -#define CCR1_SMAC (1 << 2) -#define CCR1_SM3 (1 << 7) - -#define CCR3_SMI_LOCK (1 << 0) -#define CCR3_NMI_EN (1 << 1) - enum { CPUID_FPU = (1 << 0), /* On-chip Floating Point Unit */ CPUID_VME = (1 << 1), /* Virtual 8086 mode extensions */ @@ -209,6 +203,7 @@ int is286; int is386; int is6117; int is486 = 1; +int is586 = 0; int cpu_isintel; int cpu_iscyrix; int hascache; @@ -279,13 +274,21 @@ uint8_t do_translate2 = 0; void (*cpu_exec)(int32_t cycs); -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; +uint8_t ccr0; +uint8_t ccr1; +uint8_t ccr2; +uint8_t ccr3; +uint8_t ccr4; +uint8_t ccr5; +uint8_t ccr6; +uint8_t ccr7; + +uint8_t reg_30 = 0x00; +uint8_t arr[24] = { 0 }; +uint8_t rcr[8] = { 0 }; + +/* Table for FXTRACT. */ +double exp_pow_table[0x800]; static int cyrix_addr; @@ -382,6 +385,14 @@ cpu_is_eligible(const cpu_family_t *cpu_family, int cpu, int machine) if (cpu_override) return 1; + /* Cyrix 6x86MX on the NuPRO 592. */ + if (((cpu_s->cyrix_id & 0xff00) == 0x0400) && (strstr(machine_s->internal_name, "nupro") != NULL)) + return 0; + + /* Cyrix 6x86MX or MII on the P5MMS98. */ + if ((cpu_s->cpu_type == CPU_Cx6x86MX) && (strstr(machine_s->internal_name, "p5mms98") != NULL)) + return 0; + /* Check CPU blocklist. */ if (machine_s->cpu.block) { i = 0; @@ -551,13 +562,16 @@ cpu_set(void) cpu_16bitbus = (cpu_s->cpu_type == CPU_286) || (cpu_s->cpu_type == CPU_386SX) || (cpu_s->cpu_type == CPU_486SLC) || (cpu_s->cpu_type == CPU_IBM386SLC) || (cpu_s->cpu_type == CPU_IBM486SLC); cpu_64bitbus = (cpu_s->cpu_type >= CPU_WINCHIP); + is586 = cpu_64bitbus || (cpu_s->cpu_type == CPU_P24T); + if (cpu_s->multi) cpu_busspeed = cpu_s->rspeed / cpu_s->multi; else cpu_busspeed = cpu_s->rspeed; cpu_multi = (int) ceil(cpu_s->multi); cpu_dmulti = cpu_s->multi; - ccr0 = ccr1 = ccr2 = ccr3 = ccr4 = ccr5 = ccr6 = 0; + ccr0 = ccr1 = ccr2 = ccr3 = ccr4 = ccr5 = ccr6 = ccr7 = 0; + ccr4 = 0x85; cpu_update_waitstates(); @@ -1418,7 +1432,6 @@ cpu_set(void) #endif /* USE_DYNAREC */ break; -#ifdef USE_CYRIX_6X86 case CPU_Cx6x86: case CPU_Cx6x86L: case CPU_CxGX1: @@ -1442,19 +1455,27 @@ cpu_set(void) } # endif /* USE_DYNAREC */ if (fpu_softfloat) { + x86_opcodes_d9_a16 = ops_sf_fpu_cyrix_d9_a16; + x86_opcodes_d9_a32 = ops_sf_fpu_cyrix_d9_a32; 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; + x86_opcodes_db_a16 = ops_sf_fpu_cyrix_686_db_a16; + x86_opcodes_db_a32 = ops_sf_fpu_cyrix_686_db_a32; + x86_opcodes_dd_a16 = ops_sf_fpu_cyrix_dd_a16; + x86_opcodes_dd_a32 = ops_sf_fpu_cyrix_dd_a32; + x86_opcodes_df_a16 = ops_sf_fpu_cyrix_686_df_a16; + x86_opcodes_df_a32 = ops_sf_fpu_cyrix_686_df_a32; } else { + x86_opcodes_d9_a16 = ops_fpu_cyrix_d9_a16; + x86_opcodes_d9_a32 = ops_fpu_cyrix_d9_a32; 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; + x86_opcodes_db_a16 = ops_fpu_cyrix_686_db_a16; + x86_opcodes_db_a32 = ops_fpu_cyrix_686_db_a32; + x86_opcodes_dd_a16 = ops_fpu_cyrix_dd_a16; + x86_opcodes_dd_a32 = ops_fpu_cyrix_dd_a32; + x86_opcodes_df_a16 = ops_fpu_cyrix_686_df_a16; + x86_opcodes_df_a32 = ops_fpu_cyrix_686_df_a32; } } @@ -1462,22 +1483,16 @@ cpu_set(void) if (cpu_s->cpu_type == CPU_Cx6x86MX) x86_setopcodes(ops_386, ops_c6x86mx_0f, dynarec_ops_386, dynarec_ops_c6x86mx_0f); else if (cpu_s->cpu_type == CPU_Cx6x86L) - x86_setopcodes(ops_386, ops_pentium_0f, dynarec_ops_386, dynarec_ops_pentium_0f); + x86_setopcodes(ops_386, ops_c6x86l_0f, dynarec_ops_386, dynarec_ops_c6x86l_0f); else - x86_setopcodes(ops_386, ops_c6x86mx_0f, dynarec_ops_386, dynarec_ops_c6x86mx_0f); -# if 0 x86_setopcodes(ops_386, ops_c6x86_0f, dynarec_ops_386, dynarec_ops_c6x86_0f); -# endif # else if (cpu_s->cpu_type == CPU_Cx6x86MX) x86_setopcodes(ops_386, ops_c6x86mx_0f); else if (cpu_s->cpu_type == CPU_Cx6x86L) - x86_setopcodes(ops_386, ops_pentium_0f); + x86_setopcodes(ops_386, ops_c6x86l_0f); else - x86_setopcodes(ops_386, ops_c6x86mx_0f); -# if 0 x86_setopcodes(ops_386, ops_c6x86_0f); -# endif # endif /* USE_DYNAREC */ timing_rr = 1; /* register dest - register src */ @@ -1537,7 +1552,6 @@ cpu_set(void) else if (CPU_Cx6x86) CPUID = 0; /* Disabled on powerup by default */ break; -#endif /* USE_CYRIX_6X86 */ #ifdef USE_AMD_K5 case CPU_K5: @@ -2382,7 +2396,6 @@ cpu_CPUID(void) EAX = EBX = ECX = EDX = 0; break; -#ifdef USE_CYRIX_6X86 case CPU_Cx6x86: if (!EAX) { EAX = 0x00000001; @@ -2435,15 +2448,9 @@ cpu_CPUID(void) EAX = CPUID; EBX = ECX = 0; EDX = CPUID_FPU | CPUID_DE | CPUID_TSC | CPUID_MSR | CPUID_CMPXCHG8B | CPUID_CMOV | CPUID_MMX; - /* - Return anything non-zero in bits 32-63 of the BIOS signature MSR - to indicate there has been an update. - */ - msr.bbl_cr_dx[3] = 0xffffffff00000000ULL; } else EAX = EBX = ECX = EDX = 0; break; -#endif /* USE_CYRIX_6X86 */ case CPU_PENTIUMPRO: if (!EAX) { @@ -2455,6 +2462,11 @@ cpu_CPUID(void) EAX = CPUID; EBX = ECX = 0; EDX = CPUID_FPU | CPUID_VME | CPUID_DE | CPUID_PSE | CPUID_TSC | CPUID_MSR | CPUID_PAE | CPUID_MCE | CPUID_CMPXCHG8B | CPUID_MTRR | CPUID_PGE | CPUID_MCA | CPUID_SEP | CPUID_CMOV; + /* + Return anything non-zero in bits 32-63 of the BIOS signature MSR + to indicate there has been an update. + */ + msr.bbl_cr_dx[3] = 0xffffffff00000000ULL; } else if (EAX == 2) { EAX = 0x03020101; /* Instruction TLB: 4 KB pages, 4-way set associative, 32 entries Instruction TLB: 4 MB pages, fully associative, 2 entries @@ -2616,10 +2628,33 @@ cpu_ven_reset(void) msr.amd_efer = (cpu_s->cpu_type >= CPU_K6_2C) ? 2ULL : 0ULL; break; + case CPU_Cx6x86MX: + ccr0 = 0x00; + ccr1 = 0x00; + ccr2 = 0x00; + ccr3 = 0x00; + ccr4 = 0x80; + ccr5 = 0x00; + ccr6 = 0x00; + memset(arr, 0x00, 24); + memset(rcr, 0x00, 3); + cyrix.arr[3].base = 0x00; + cyrix.arr[3].size = 0; /* Disabled */ + cyrix.smhr &= ~SMHR_VALID; + CPUID = cpu_s->cpuid_model; + reg_30 = 0xff; + break; + case CPU_PENTIUMPRO: case CPU_PENTIUM2: case CPU_PENTIUM2D: msr.mtrr_cap = 0x00000508ULL; + + /* 4 GB cacheable space on Deschutes 651h and later (including the 1632h + Overdrive) according to the Pentium II Processor Specification Update. + Covington 651h (no L2 cache) reports the same 512 MB value as Klamath. */ + if (CPUID >= (!strncmp(cpu_f->internal_name, "celeron", 7) ? 0x660 : 0x651)) + msr.bbl_cr_ctl3 |= 0x00300000; break; case CPU_CYRIX3S: @@ -3120,7 +3155,6 @@ pentium_invalid_rdmsr: cpu_log("RDMSR: ECX = %08X, val = %08X%08X\n", ECX, EDX, EAX); break; -#ifdef USE_CYRIX_6X86 case CPU_Cx6x86: case CPU_Cx6x86L: case CPU_CxGX1: @@ -3160,7 +3194,6 @@ pentium_invalid_rdmsr: } cpu_log("RDMSR: ECX = %08X, val = %08X%08X\n", ECX, EDX, EAX); break; -#endif /* USE_CYRIX_6X86 */ case CPU_PENTIUMPRO: case CPU_PENTIUM2: @@ -3268,7 +3301,6 @@ pentium_invalid_rdmsr: case 0x88 ... 0x8b: EAX = msr.bbl_cr_dx[ECX - 0x88] & 0xffffffff; EDX = msr.bbl_cr_dx[ECX - 0x88] >> 32; - // EDX |= 0xffffffff; break; /* Unknown */ case 0xae: @@ -3941,7 +3973,6 @@ pentium_invalid_wrmsr: } break; -#ifdef USE_CYRIX_6X86 case CPU_Cx6x86: case CPU_Cx6x86L: case CPU_CxGX1: @@ -3951,12 +3982,15 @@ pentium_invalid_wrmsr: /* Test Data */ case 0x03: msr.tr3 = EAX; + break; /* Test Address */ case 0x04: msr.tr4 = EAX; + break; /* Test Command/Status */ case 0x05: msr.tr5 = EAX & 0x008f0f3b; + break; /* Time Stamp Counter */ case 0x10: timer_set_new_tsc(EAX | ((uint64_t) EDX << 32)); @@ -3975,7 +4009,6 @@ pentium_invalid_wrmsr: break; } break; -#endif /* USE_CYRIX_6X86 */ case CPU_PENTIUMPRO: case CPU_PENTIUM2: @@ -4075,7 +4108,7 @@ pentium_invalid_wrmsr: break; /* BBL_CR_CTL3 - L2 Cache Control Register 3 */ case 0x11e: - msr.bbl_cr_ctl3 = EAX | ((uint64_t) EDX << 32); + msr.bbl_cr_ctl3 = (msr.bbl_cr_ctl3 & 0x02f00000) | (EAX & ~0x02f00000) | ((uint64_t) EDX << 32); break; /* Unknown */ case 0x131: @@ -4227,121 +4260,179 @@ cpu_write(uint16_t addr, uint8_t val, UNUSED(void *priv)) picintc(1 << 13); else nmi = 0; - return; - } else if (addr >= 0xf1) - return; /* FPU stuff */ - - if (!(addr & 1)) + } else if ((addr < 0xf1) && !(addr & 1)) cyrix_addr = val; - else - switch (cyrix_addr) { - case 0xc0: /* CCR0 */ - ccr0 = val; - break; - case 0xc1: /* CCR1 */ - if ((ccr3 & CCR3_SMI_LOCK) && !in_smm) - val = (val & ~(CCR1_USE_SMI | CCR1_SMAC | CCR1_SM3)) | (ccr1 & (CCR1_USE_SMI | CCR1_SMAC | CCR1_SM3)); - ccr1 = val; - break; - case 0xc2: /* CCR2 */ - ccr2 = val; - break; - case 0xc3: /* CCR3 */ - if ((ccr3 & CCR3_SMI_LOCK) && !in_smm) - val = (val & ~(CCR3_NMI_EN)) | (ccr3 & CCR3_NMI_EN) | CCR3_SMI_LOCK; - ccr3 = val; - break; - case 0xcd: - if (!(ccr3 & CCR3_SMI_LOCK) || in_smm) { - cyrix.arr[3].base = (cyrix.arr[3].base & ~0xff000000) | (val << 24); - cyrix.smhr &= ~SMHR_VALID; - } - break; - case 0xce: - if (!(ccr3 & CCR3_SMI_LOCK) || in_smm) { - cyrix.arr[3].base = (cyrix.arr[3].base & ~0x00ff0000) | (val << 16); - cyrix.smhr &= ~SMHR_VALID; - } - break; - case 0xcf: - 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 */ - else if (val & 0xf) - cyrix.arr[3].size = 2048 << (val & 0xf); - else - cyrix.arr[3].size = 0; /* Disabled */ - cyrix.smhr &= ~SMHR_VALID; - } - break; + else if (addr < 0xf1) switch (cyrix_addr) { + default: + if ((cyrix_addr >= 0xc0) && (cyrix_addr != 0xff)) + fatal("Writing unimplemented Cyrix register %02X\n", cyrix_addr); + break; - case 0xe8: /* CCR4 */ - if ((ccr3 & 0xf0) == 0x10) { - ccr4 = val; -#ifdef USE_CYRIX_6X86 - if (cpu_s->cpu_type >= CPU_Cx6x86) { - if (val & 0x80) - CPUID = cpu_s->cpuid_model; - else - CPUID = 0; - } -#endif /* USE_CYRIX_6X86 */ + case 0x30: /* ???? */ + reg_30 = val; + break; + + case 0xc0: /* CCR0 */ + ccr0 = val; + break; + case 0xc1: { /* CCR1 */ + uint8_t old = ccr1; + if ((ccr3 & CCR3_SMI_LOCK) && !in_smm) + val = (val & ~(CCR1_USE_SMI | CCR1_SMAC | CCR1_SM3)) | (ccr1 & (CCR1_USE_SMI | CCR1_SMAC | CCR1_SM3)); + ccr1 = val; + if ((old ^ ccr1) & (CCR1_SMAC)) { + if (ccr1 & CCR1_SMAC) + smram_backup_all(); + smram_recalc_all(!(ccr1 & CCR1_SMAC)); + } + break; + } case 0xc2: /* CCR2 */ + ccr2 = val; + break; + case 0xc3: /* CCR3 */ + if ((ccr3 & CCR3_SMI_LOCK) && !in_smm) + val = (val & ~(CCR3_NMI_EN)) | (ccr3 & CCR3_NMI_EN) | CCR3_SMI_LOCK; + ccr3 = val; + break; + + case 0xc4 ... 0xcc: + if (ccr5 & 0x20) + arr[cyrix_addr - 0xc4] = val; + break; + case 0xcd: + if ((ccr5 & 0x20) || (!(ccr3 & CCR3_SMI_LOCK) || in_smm)) { + arr[cyrix_addr - 0xc4] = val; + cyrix.arr[3].base = (cyrix.arr[3].base & ~0xff000000) | (val << 24); + cyrix.smhr &= ~SMHR_VALID; + } + break; + case 0xce: + if ((ccr5 & 0x20) || (!(ccr3 & CCR3_SMI_LOCK) || in_smm)) { + arr[cyrix_addr - 0xc4] = val; + cyrix.arr[3].base = (cyrix.arr[3].base & ~0x00ff0000) | (val << 16); + cyrix.smhr &= ~SMHR_VALID; + } + break; + case 0xcf: + if ((ccr5 & 0x20) || (!(ccr3 & CCR3_SMI_LOCK) || in_smm)) { + arr[cyrix_addr - 0xc4] = val; + cyrix.arr[3].base = (cyrix.arr[3].base & ~0x0000f000) | ((val & 0xf0) << 8); + if ((val & 0xf) == 0xf) + cyrix.arr[3].size = 1ULL << 32; /* 4 GB */ + else if (val & 0xf) + cyrix.arr[3].size = 2048 << (val & 0xf); + else + cyrix.arr[3].size = 0; /* Disabled */ + cyrix.smhr &= ~SMHR_VALID; + } + break; + case 0xd0 ... 0xdb: + if (((ccr3 & 0xf0) == 0x10) && (ccr5 & 0x20)) + arr[cyrix_addr - 0xc4] = val; + break; + + case 0xdc ... 0xe3: + if ((ccr3 & 0xf0) == 0x10) + rcr[cyrix_addr - 0xdc] = val; + break; + + case 0xe8: /* CCR4 */ + if ((ccr3 & 0xf0) == 0x10) { + ccr4 = val; + if (cpu_s->cpu_type >= CPU_Cx6x86) { + if (val & 0x80) + CPUID = cpu_s->cpuid_model; + else + CPUID = 0; } - break; - case 0xe9: /* CCR5 */ - if ((ccr3 & 0xf0) == 0x10) - ccr5 = val; - break; - case 0xea: /* CCR6 */ - if ((ccr3 & 0xf0) == 0x10) - ccr6 = val; - break; - } + } + break; + case 0xe9: /* CCR5 */ + if ((ccr3 & 0xf0) == 0x10) + ccr5 = val; + break; + case 0xea: /* CCR6 */ + if ((ccr3 & 0xf0) == 0x10) + ccr6 = val; + break; + case 0xeb: /* CCR7 */ + ccr7 = val & 5; + break; + } } static uint8_t cpu_read(uint16_t addr, UNUSED(void *priv)) { + uint8_t ret = 0xff; + if (addr == 0xf007) - return 0x7f; + ret = 0x7f; + else if ((addr < 0xf0) && (addr & 1)) switch (cyrix_addr) { + default: + if (cyrix_addr >= 0xc0) + fatal("Reading unimplemented Cyrix register %02X\n", cyrix_addr); + break; - if (addr >= 0xf0) - return 0xff; /* FPU stuff */ + case 0x30: /* ???? */ + ret = reg_30; + break; - if (addr & 1) { - switch (cyrix_addr) { - case 0xc0: - return ccr0; - case 0xc1: - return ccr1; - case 0xc2: - return ccr2; - case 0xc3: - return ccr3; - case 0xe8: - return ((ccr3 & 0xf0) == 0x10) ? ccr4 : 0xff; - case 0xe9: - return ((ccr3 & 0xf0) == 0x10) ? ccr5 : 0xff; - case 0xea: - return ((ccr3 & 0xf0) == 0x10) ? ccr6 : 0xff; - case 0xfe: - return cpu_s->cyrix_id & 0xff; - case 0xff: - return cpu_s->cyrix_id >> 8; + case 0xc0: + ret = ccr0; + break; + case 0xc1: + ret = ccr1; + break; + case 0xc2: + ret = ccr2; + break; + case 0xc3: + ret = ccr3; + break; - default: - break; - } + case 0xc4 ... 0xcc: + if (ccr5 & 0x20) + ret = arr[cyrix_addr - 0xc4]; + break; + case 0xcd ... 0xcf: + if ((ccr5 & 0x20) || (!(ccr3 & CCR3_SMI_LOCK) || in_smm)) + ret = arr[cyrix_addr - 0xc4]; + break; + case 0xd0 ... 0xdb: + if (((ccr3 & 0xf0) == 0x10) && (ccr5 & 0x20)) + ret = arr[cyrix_addr - 0xc4]; + break; - if ((cyrix_addr & 0xf0) == 0xc0) - return 0xff; + case 0xdc ... 0xe3: + if ((ccr3 & 0xf0) == 0x10) + ret = rcr[cyrix_addr - 0xdc]; + break; - if (cyrix_addr == 0x20 && (cpu_s->cpu_type == CPU_Cx5x86)) - return 0xff; + case 0xe8: + if ((ccr3 & 0xf0) == 0x10) + ret = ccr4; + break; + case 0xe9: + if ((ccr3 & 0xf0) == 0x10) + ret = ccr5; + break; + case 0xea: + if ((ccr3 & 0xf0) == 0x10) + ret = ccr6; + break; + case 0xeb: + ret = ccr7; + break; + case 0xfe: + ret = cpu_s->cyrix_id & 0xff; + break; + case 0xff: + ret = cpu_s->cyrix_id >> 8; + break; } - return 0xff; + return ret; } void diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index f969390d2..b6f5f593c 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -87,30 +87,32 @@ enum { enum { CPU_PKG_8088 = (1 << 0), CPU_PKG_8088_EUROPC = (1 << 1), - CPU_PKG_8086 = (1 << 2), - CPU_PKG_8086_MAZOVIA = (1 << 3), - CPU_PKG_188 = (1 << 4), - CPU_PKG_186 = (1 << 5), - CPU_PKG_286 = (1 << 6), - CPU_PKG_386SX = (1 << 7), - CPU_PKG_386DX = (1 << 8), - CPU_PKG_386DX_DESKPRO386 = (1 << 9), - CPU_PKG_M6117 = (1 << 10), - CPU_PKG_386SLC_IBM = (1 << 11), - CPU_PKG_486SLC = (1 << 12), - CPU_PKG_486SLC_IBM = (1 << 13), - CPU_PKG_486BL = (1 << 14), - CPU_PKG_486DLC = (1 << 15), - CPU_PKG_SOCKET1 = (1 << 16), - CPU_PKG_SOCKET3 = (1 << 17), - CPU_PKG_SOCKET3_PC330 = (1 << 18), - CPU_PKG_STPC = (1 << 19), - CPU_PKG_SOCKET4 = (1 << 20), - CPU_PKG_SOCKET5_7 = (1 << 21), - CPU_PKG_SOCKET8 = (1 << 22), - CPU_PKG_SLOT1 = (1 << 23), - CPU_PKG_SLOT2 = (1 << 24), - CPU_PKG_SOCKET370 = (1 << 25) + CPU_PKG_8088_VTECH = (1 << 2), + CPU_PKG_8086 = (1 << 3), + CPU_PKG_8086_MAZOVIA = (1 << 4), + CPU_PKG_8086_VTECH = (1 << 5), + CPU_PKG_188 = (1 << 6), + CPU_PKG_186 = (1 << 7), + CPU_PKG_286 = (1 << 8), + CPU_PKG_386SX = (1 << 9), + CPU_PKG_386DX = (1 << 10), + CPU_PKG_386DX_DESKPRO386 = (1 << 11), + CPU_PKG_M6117 = (1 << 12), + CPU_PKG_386SLC_IBM = (1 << 13), + CPU_PKG_486SLC = (1 << 14), + CPU_PKG_486SLC_IBM = (1 << 15), + CPU_PKG_486BL = (1 << 16), + CPU_PKG_486DLC = (1 << 17), + CPU_PKG_SOCKET1 = (1 << 18), + CPU_PKG_SOCKET3 = (1 << 19), + CPU_PKG_SOCKET3_PC330 = (1 << 20), + CPU_PKG_STPC = (1 << 21), + CPU_PKG_SOCKET4 = (1 << 22), + CPU_PKG_SOCKET5_7 = (1 << 23), + CPU_PKG_SOCKET8 = (1 << 24), + CPU_PKG_SLOT1 = (1 << 25), + CPU_PKG_SLOT2 = (1 << 26), + CPU_PKG_SOCKET370 = (1 << 27) }; #define CPU_SUPPORTS_DYNAREC 1 @@ -118,6 +120,13 @@ enum { #define CPU_ALTERNATE_XTAL 4 #define CPU_FIXED_MULTIPLIER 8 +#define CCR1_USE_SMI (1 << 1) +#define CCR1_SMAC (1 << 2) +#define CCR1_SM3 (1 << 7) + +#define CCR3_SMI_LOCK (1 << 0) +#define CCR3_NMI_EN (1 << 1) + #if (defined __amd64__ || defined _M_X64) # define LOOKUP_INV -1LL #else @@ -326,7 +335,10 @@ typedef struct { uint8_t tag[8]; x86seg *ea_seg; - uint32_t eaaddr; + union { + uint32_t eaaddr; + uint16_t eaa16[2]; + }; int flags_op; uint32_t flags_res; @@ -404,6 +416,8 @@ typedef struct { uint16_t eflags; uint32_t _smbase; + + uint32_t x87_op; } cpu_state_t; #define in_smm cpu_state._in_smm @@ -511,6 +525,7 @@ extern int is286; extern int is386; extern int is6117; extern int is486; +extern int is586; extern int is_am486; extern int is_am486dxl; extern int is_pentium; @@ -587,6 +602,16 @@ extern uint32_t _tr[8]; extern uint32_t cache_index; extern uint8_t _cache[2048]; +/* For the Cyrix 6x86(MX) */ +extern uint8_t ccr0; +extern uint8_t ccr1; +extern uint8_t ccr2; +extern uint8_t ccr3; +extern uint8_t ccr4; +extern uint8_t ccr5; +extern uint8_t ccr6; +extern uint8_t ccr7; + /*Segments - _cs,_ds,_es,_ss are the segment structures CS,DS,ES,SS is the 16-bit data @@ -761,6 +786,8 @@ typedef struct { uint32_t smhr; } cyrix_t; +#define x87_op cpu_state.x87_op + extern uint32_t addr64; extern uint32_t addr64_2; extern uint32_t addr64a[8]; @@ -814,9 +841,22 @@ extern int lock_legal_80[8]; extern int lock_legal_f6[8]; extern int lock_legal_fe[8]; +extern int new_ne; + extern int in_lock; extern int cpu_override_interpreter; extern int is_lock_legal(uint32_t fetchdat); +extern void prefetch_queue_set_pos(int pos); +extern void prefetch_queue_set_ip(uint16_t ip); +extern void prefetch_queue_set_prefetching(int p); +extern int prefetch_queue_get_pos(void); +extern uint16_t prefetch_queue_get_ip(void); +extern int prefetch_queue_get_prefetching(void); +extern int prefetch_queue_get_size(void); + +#define prefetch_queue_set_suspended(s) prefetch_queue_set_prefetching(!s) +#define prefetch_queue_get_suspended !prefetch_queue_get_prefetching + #endif /*EMU_CPU_H*/ diff --git a/src/cpu/cpu_table.c b/src/cpu/cpu_table.c index b2ef71075..8524306dc 100644 --- a/src/cpu/cpu_table.c +++ b/src/cpu/cpu_table.c @@ -262,6 +262,50 @@ const cpu_family_t cpu_families[] = { { .name = "", 0 } } }, + { + .package = CPU_PKG_8088_VTECH, + .manufacturer = "Intel", + .name = "8088", + .internal_name = "8088_vtech", + .cpus = (const CPU[]) { + { + .name = "4.77", + .cpu_type = CPU_8088, + .fpus = fpus_8088, + .rspeed = 4772728, + .multi = 1, + .voltage = 5000, + .edx_reset = 0, + .cpuid_model = 0, + .cyrix_id = 0, + .cpu_flags = 0, + .mem_read_cycles = 0, + .mem_write_cycles = 0, + .cache_read_cycles = 0, + .cache_write_cycles = 0, + .atclk_div = 1 + }, + + { + .name = "10", + .cpu_type = CPU_8088, + .fpus = fpus_8088, + .rspeed = 10000000, + .multi = 1, + .voltage = 5000, + .edx_reset = 0, + .cpuid_model = 0, + .cyrix_id = 0, + .cpu_flags = 0, + .mem_read_cycles = 0, + .mem_write_cycles = 0, + .cache_read_cycles = 0, + .cache_write_cycles = 0, + .atclk_div = 1 + }, + { .name = "", 0 } + } + }, { .package = CPU_PKG_8086, .manufacturer = "Intel", @@ -399,6 +443,49 @@ const cpu_family_t cpu_families[] = { { .name = "", 0 } } }, + { + .package = CPU_PKG_8086_VTECH, + .manufacturer = "Intel", + .name = "8086", + .internal_name = "8086_vtech", + .cpus = (const CPU[]) { + { + .name = "4.77", + .cpu_type = CPU_8086, + .fpus = fpus_8088, + .rspeed = 4772728, + .multi = 1, + .voltage = 5000, + .edx_reset = 0, + .cpuid_model = 0, + .cyrix_id = 0, + .cpu_flags = 0, + .mem_read_cycles = 0, + .mem_write_cycles = 0, + .cache_read_cycles = 0, + .cache_write_cycles = 0, + .atclk_div = 1 + }, + { + .name = "10", + .cpu_type = CPU_8086, + .fpus = fpus_8088, + .rspeed = 10000000, + .multi = 1, + .voltage = 5000, + .edx_reset = 0, + .cpuid_model = 0, + .cyrix_id = 0, + .cpu_flags = 0, + .mem_read_cycles = 0, + .mem_write_cycles = 0, + .cache_read_cycles = 0, + .cache_write_cycles = 0, + .atclk_div = 1 + }, + { .name = "", 0 } + } + }, { .package = CPU_PKG_188, .manufacturer = "Intel", @@ -6008,7 +6095,6 @@ const cpu_family_t cpu_families[] = { { .name = "", 0 } } }, -#ifdef USE_CYRIX_6X86 { .package = CPU_PKG_SOCKET5_7, .manufacturer = "Cyrix", @@ -6280,6 +6366,74 @@ const cpu_family_t cpu_families[] = { .name = "MII", .internal_name = "mii", .cpus = (const CPU[]) { + { + .name = "IBM 133 (PR166)", + .cpu_type = CPU_Cx6x86MX, + .fpus = fpus_internal, + .rspeed = 133333333, + .multi = 2.0, + .voltage = 2900, + .edx_reset = 0x601, + .cpuid_model = 0x601, + .cyrix_id = 0x0851, + .cpu_flags = CPU_SUPPORTS_DYNAREC | CPU_REQUIRES_DYNAREC, + .mem_read_cycles = 12, + .mem_write_cycles = 12, + .cache_read_cycles = 6, + .cache_write_cycles = 6, + .atclk_div = 16 + }, + { + .name = "166 (PR200)", + .cpu_type = CPU_Cx6x86MX, + .fpus = fpus_internal, + .rspeed = 166666666, + .multi = 2.5, + .voltage = 2900, + .edx_reset = 0x601, + .cpuid_model = 0x601, + .cyrix_id = 0x0852, + .cpu_flags = CPU_SUPPORTS_DYNAREC | CPU_REQUIRES_DYNAREC, + .mem_read_cycles = 15, + .mem_write_cycles = 15, + .cache_read_cycles = 7, + .cache_write_cycles = 7, + .atclk_div = 20 + }, + { + .name = "187.5 (PR233)", + .cpu_type = CPU_Cx6x86MX, + .fpus = fpus_internal, + .rspeed = 187500000, + .multi = 2.5, + .voltage = 2900, + .edx_reset = 0x601, + .cpuid_model = 0x601, + .cyrix_id = 0x0852, + .cpu_flags = CPU_SUPPORTS_DYNAREC | CPU_REQUIRES_DYNAREC, + .mem_read_cycles = 15, + .mem_write_cycles = 15, + .cache_read_cycles = 7, + .cache_write_cycles = 7, + .atclk_div = 45/2 + }, + { + .name = "208.3 (PR266)", + .cpu_type = CPU_Cx6x86MX, + .fpus = fpus_internal, + .rspeed = 208333333, + .multi = 2.5, + .voltage = 2700, + .edx_reset = 0x601, + .cpuid_model = 0x601, + .cyrix_id = 0x0852, + .cpu_flags = CPU_SUPPORTS_DYNAREC | CPU_REQUIRES_DYNAREC, + .mem_read_cycles = 17, + .mem_write_cycles = 17, + .cache_read_cycles = 7, + .cache_write_cycles = 7, + .atclk_div = 25 + }, { .name = "233 (PR300)", .cpu_type = CPU_Cx6x86MX, @@ -6289,7 +6443,7 @@ const cpu_family_t cpu_families[] = { .voltage = 2900, .edx_reset = 0x601, .cpuid_model = 0x601, - .cyrix_id = 0x0852, + .cyrix_id = 0x0854, .cpu_flags = CPU_SUPPORTS_DYNAREC | CPU_REQUIRES_DYNAREC, .mem_read_cycles = 21, .mem_write_cycles = 21, @@ -6323,7 +6477,7 @@ const cpu_family_t cpu_families[] = { .voltage = 2900, .edx_reset = 0x601, .cpuid_model = 0x601, - .cyrix_id = 0x0853, + .cyrix_id = 0x0852, .cpu_flags = CPU_SUPPORTS_DYNAREC | CPU_REQUIRES_DYNAREC, .mem_read_cycles = 23, .mem_write_cycles = 23, @@ -6331,6 +6485,23 @@ const cpu_family_t cpu_families[] = { .cache_write_cycles = 7, .atclk_div = 30 }, + { + .name = "270 (PR350)", + .cpu_type = CPU_Cx6x86MX, + .fpus = fpus_internal, + .rspeed = 270000000, + .multi = 3.0, + .voltage = 2900, + .edx_reset = 0x601, + .cpuid_model = 0x601, + .cyrix_id = 0x0853, + .cpu_flags = CPU_SUPPORTS_DYNAREC | CPU_REQUIRES_DYNAREC, + .mem_read_cycles = 25, + .mem_write_cycles = 25, + .cache_read_cycles = 8, + .cache_write_cycles = 8, + .atclk_div = 32 + }, { .name = "285 (PR400)", .cpu_type = CPU_Cx6x86MX, @@ -6368,7 +6539,6 @@ const cpu_family_t cpu_families[] = { { .name = "", 0 } } }, -#endif /* USE_CYRIX_6X86 */ { .package = CPU_PKG_SOCKET8, .manufacturer = "Intel", @@ -7623,7 +7793,7 @@ const cpu_family_t cpu_families[] = { { .package = CPU_PKG_SOCKET370, .manufacturer = "VIA", - .name = "Cyrix III", + .name = "Cyrix III (Samuel)", .internal_name = "c3_samuel", .cpus = (const CPU[]) { { /* out of multiplier range */ diff --git a/src/cpu/i8080.c b/src/cpu/i8080.c new file mode 100644 index 000000000..688923997 --- /dev/null +++ b/src/cpu/i8080.c @@ -0,0 +1,826 @@ +/* + * 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 8080 CPU emulation + * + * Authors: Cacodemon345 + * Nicolas Allemand + * + * Copyright (c) 2018 Nicolas Allemand + * Copyright (c) 2024 Cacodemon345 + * + */ + +#include "i8080.h" +#include + +// Changes from upstream: +// Add CALLN and RETEM instructions. +// Add code for instruction fetches. + +// this array defines the number of cycles one opcode takes. +// note that there are some special cases: conditional RETs and CALLs +// add +6 cycles if the condition is met +// clang-format off +static const uint8_t OPCODES_CYCLES[256] = { +// 0 1 2 3 4 5 6 7 8 9 A B C D E F + 4, 10, 7, 5, 5, 5, 7, 4, 4, 10, 7, 5, 5, 5, 7, 4, // 0 + 4, 10, 7, 5, 5, 5, 7, 4, 4, 10, 7, 5, 5, 5, 7, 4, // 1 + 4, 10, 16, 5, 5, 5, 7, 4, 4, 10, 16, 5, 5, 5, 7, 4, // 2 + 4, 10, 13, 5, 10, 10, 10, 4, 4, 10, 13, 5, 5, 5, 7, 4, // 3 + 5, 5, 5, 5, 5, 5, 7, 5, 5, 5, 5, 5, 5, 5, 7, 5, // 4 + 5, 5, 5, 5, 5, 5, 7, 5, 5, 5, 5, 5, 5, 5, 7, 5, // 5 + 5, 5, 5, 5, 5, 5, 7, 5, 5, 5, 5, 5, 5, 5, 7, 5, // 6 + 7, 7, 7, 7, 7, 7, 7, 7, 5, 5, 5, 5, 5, 5, 7, 5, // 7 + 4, 4, 4, 4, 4, 4, 7, 4, 4, 4, 4, 4, 4, 4, 7, 4, // 8 + 4, 4, 4, 4, 4, 4, 7, 4, 4, 4, 4, 4, 4, 4, 7, 4, // 9 + 4, 4, 4, 4, 4, 4, 7, 4, 4, 4, 4, 4, 4, 4, 7, 4, // A + 4, 4, 4, 4, 4, 4, 7, 4, 4, 4, 4, 4, 4, 4, 7, 4, // B + 5, 10, 10, 10, 11, 11, 7, 11, 5, 10, 10, 10, 11, 17, 7, 11, // C + 5, 10, 10, 10, 11, 11, 7, 11, 5, 10, 10, 10, 11, 17, 7, 11, // D + 5, 10, 10, 18, 11, 11, 7, 11, 5, 5, 10, 4, 11, 17, 7, 11, // E + 5, 10, 10, 4, 11, 11, 7, 11, 5, 5, 10, 4, 11, 17, 7, 11 // F +}; +// clang-format on + +static const char* DISASSEMBLE_TABLE[] = {"nop", "lxi b,#", "stax b", "inx b", + "inr b", "dcr b", "mvi b,#", "rlc", "ill", "dad b", "ldax b", "dcx b", + "inr c", "dcr c", "mvi c,#", "rrc", "ill", "lxi d,#", "stax d", "inx d", + "inr d", "dcr d", "mvi d,#", "ral", "ill", "dad d", "ldax d", "dcx d", + "inr e", "dcr e", "mvi e,#", "rar", "ill", "lxi h,#", "shld", "inx h", + "inr h", "dcr h", "mvi h,#", "daa", "ill", "dad h", "lhld", "dcx h", + "inr l", "dcr l", "mvi l,#", "cma", "ill", "lxi sp,#", "sta $", "inx sp", + "inr M", "dcr M", "mvi M,#", "stc", "ill", "dad sp", "lda $", "dcx sp", + "inr a", "dcr a", "mvi a,#", "cmc", "mov b,b", "mov b,c", "mov b,d", + "mov b,e", "mov b,h", "mov b,l", "mov b,M", "mov b,a", "mov c,b", "mov c,c", + "mov c,d", "mov c,e", "mov c,h", "mov c,l", "mov c,M", "mov c,a", "mov d,b", + "mov d,c", "mov d,d", "mov d,e", "mov d,h", "mov d,l", "mov d,M", "mov d,a", + "mov e,b", "mov e,c", "mov e,d", "mov e,e", "mov e,h", "mov e,l", "mov e,M", + "mov e,a", "mov h,b", "mov h,c", "mov h,d", "mov h,e", "mov h,h", "mov h,l", + "mov h,M", "mov h,a", "mov l,b", "mov l,c", "mov l,d", "mov l,e", "mov l,h", + "mov l,l", "mov l,M", "mov l,a", "mov M,b", "mov M,c", "mov M,d", "mov M,e", + "mov M,h", "mov M,l", "hlt", "mov M,a", "mov a,b", "mov a,c", "mov a,d", + "mov a,e", "mov a,h", "mov a,l", "mov a,M", "mov a,a", "add b", "add c", + "add d", "add e", "add h", "add l", "add M", "add a", "adc b", "adc c", + "adc d", "adc e", "adc h", "adc l", "adc M", "adc a", "sub b", "sub c", + "sub d", "sub e", "sub h", "sub l", "sub M", "sub a", "sbb b", "sbb c", + "sbb d", "sbb e", "sbb h", "sbb l", "sbb M", "sbb a", "ana b", "ana c", + "ana d", "ana e", "ana h", "ana l", "ana M", "ana a", "xra b", "xra c", + "xra d", "xra e", "xra h", "xra l", "xra M", "xra a", "ora b", "ora c", + "ora d", "ora e", "ora h", "ora l", "ora M", "ora a", "cmp b", "cmp c", + "cmp d", "cmp e", "cmp h", "cmp l", "cmp M", "cmp a", "rnz", "pop b", + "jnz $", "jmp $", "cnz $", "push b", "adi #", "rst 0", "rz", "ret", "jz $", + "ill", "cz $", "call $", "aci #", "rst 1", "rnc", "pop d", "jnc $", "out p", + "cnc $", "push d", "sui #", "rst 2", "rc", "ill", "jc $", "in p", "cc $", + "ill", "sbi #", "rst 3", "rpo", "pop h", "jpo $", "xthl", "cpo $", "push h", + "ani #", "rst 4", "rpe", "pchl", "jpe $", "xchg", "cpe $", "ill", "xri #", + "rst 5", "rp", "pop psw", "jp $", "di", "cp $", "push psw", "ori #", + "rst 6", "rm", "sphl", "jm $", "ei", "cm $", "ill", "cpi #", "rst 7"}; + +#define SET_ZSP(c, val) \ + do { \ + c->zf = (val) == 0; \ + c->sf = (val) >> 7; \ + c->pf = parity(val); \ + } while (0) + +// memory helpers (the only four to use `read_byte` and `write_byte` function +// pointers) + +// reads a byte from memory +static inline uint8_t i8080_rb(i8080* const c, uint16_t addr) { + return c->read_byte(c->userdata, addr); +} + +// writes a byte to memory +static inline void i8080_wb(i8080* const c, uint16_t addr, uint8_t val) { + c->write_byte(c->userdata, addr, val); +} + +// reads a word from memory +static inline uint16_t i8080_rw(i8080* const c, uint16_t addr) { + return c->read_byte(c->userdata, addr + 1) << 8 | + c->read_byte(c->userdata, addr); +} + +// writes a word to memory +static inline void i8080_ww(i8080* const c, uint16_t addr, uint16_t val) { + c->write_byte(c->userdata, addr, val & 0xFF); + c->write_byte(c->userdata, addr + 1, val >> 8); +} + +// returns the next byte in memory (and updates the program counter) +static inline uint8_t i8080_next_byte(i8080* const c) { + return c->read_byte_seg ? (c->read_byte_seg(c->userdata, c->pc++)) : i8080_rb(c, c->pc++); +} + +// returns the next word in memory (and updates the program counter) +static inline uint16_t i8080_next_word(i8080* const c) { + uint16_t result = 0; + if (c->read_byte_seg) + result = c->read_byte_seg(c, c->pc) | (c->read_byte_seg(c, c->pc + 1) << 8); + else + result = i8080_rw(c, c->pc); + c->pc += 2; + return result; +} + +// paired registers helpers (setters and getters) +static inline void i8080_set_bc(i8080* const c, uint16_t val) { + c->b = val >> 8; + c->c = val & 0xFF; +} + +static inline void i8080_set_de(i8080* const c, uint16_t val) { + c->d = val >> 8; + c->e = val & 0xFF; +} + +static inline void i8080_set_hl(i8080* const c, uint16_t val) { + c->h = val >> 8; + c->l = val & 0xFF; +} + +static inline uint16_t i8080_get_bc(i8080* const c) { + return (c->b << 8) | c->c; +} + +static inline uint16_t i8080_get_de(i8080* const c) { + return (c->d << 8) | c->e; +} + +static inline uint16_t i8080_get_hl(i8080* const c) { + return (c->h << 8) | c->l; +} + +// stack helpers + +// pushes a value into the stack and updates the stack pointer +static inline void i8080_push_stack(i8080* const c, uint16_t val) { + c->sp -= 2; + i8080_ww(c, c->sp, val); +} + +// pops a value from the stack and updates the stack pointer +static inline uint16_t i8080_pop_stack(i8080* const c) { + uint16_t val = i8080_rw(c, c->sp); + c->sp += 2; + return val; +} + +// opcodes + +// returns the parity of byte: 0 if number of 1 bits in `val` is odd, else 1 +static inline bool parity(uint8_t val) { + uint8_t nb_one_bits = 0; + for (int i = 0; i < 8; i++) { + nb_one_bits += ((val >> i) & 1); + } + + return (nb_one_bits & 1) == 0; +} + +// returns if there was a carry between bit "bit_no" and "bit_no - 1" when +// executing "a + b + cy" +static inline bool carry(int bit_no, uint8_t a, uint8_t b, bool cy) { + int16_t result = a + b + cy; + int16_t carry = result ^ a ^ b; + return carry & (1 << bit_no); +} + +// adds a value (+ an optional carry flag) to a register +static inline void i8080_add( + i8080* const c, uint8_t* const reg, uint8_t val, bool cy) { + uint8_t result = *reg + val + cy; + c->cf = carry(8, *reg, val, cy); + c->hf = carry(4, *reg, val, cy); + SET_ZSP(c, result); + *reg = result; +} + +// substracts a byte (+ an optional carry flag) from a register +// see https://stackoverflow.com/a/8037485 +static inline void i8080_sub( + i8080* const c, uint8_t* const reg, uint8_t val, bool cy) { + i8080_add(c, reg, ~val, !cy); + c->cf = !c->cf; +} + +// adds a word to HL +static inline void i8080_dad(i8080* const c, uint16_t val) { + c->cf = ((i8080_get_hl(c) + val) >> 16) & 1; + i8080_set_hl(c, i8080_get_hl(c) + val); +} + +// increments a byte +static inline uint8_t i8080_inr(i8080* const c, uint8_t val) { + uint8_t result = val + 1; + c->hf = (result & 0xF) == 0; + SET_ZSP(c, result); + return result; +} + +// decrements a byte +static inline uint8_t i8080_dcr(i8080* const c, uint8_t val) { + uint8_t result = val - 1; + c->hf = !((result & 0xF) == 0xF); + SET_ZSP(c, result); + return result; +} + +// executes a logic "and" between register A and a byte, then stores the +// result in register A +static inline void i8080_ana(i8080* const c, uint8_t val) { + uint8_t result = c->a & val; + c->cf = 0; + c->hf = ((c->a | val) & 0x08) != 0; + SET_ZSP(c, result); + c->a = result; +} + +// executes a logic "xor" between register A and a byte, then stores the +// result in register A +static inline void i8080_xra(i8080* const c, uint8_t val) { + c->a ^= val; + c->cf = 0; + c->hf = 0; + SET_ZSP(c, c->a); +} + +// executes a logic "or" between register A and a byte, then stores the +// result in register A +static inline void i8080_ora(i8080* const c, uint8_t val) { + c->a |= val; + c->cf = 0; + c->hf = 0; + SET_ZSP(c, c->a); +} + +// compares the register A to another byte +static inline void i8080_cmp(i8080* const c, uint8_t val) { + int16_t result = c->a - val; + c->cf = result >> 8; + c->hf = ~(c->a ^ result ^ val) & 0x10; + SET_ZSP(c, result & 0xFF); +} + +// sets the program counter to a given address +static inline void i8080_jmp(i8080* const c, uint16_t addr) { + c->pc = addr; +} + +// jumps to next address pointed by the next word in memory if a condition +// is met +static inline void i8080_cond_jmp(i8080* const c, bool condition) { + uint16_t addr = i8080_next_word(c); + if (condition) { + c->pc = addr; + } +} + +// pushes the current pc to the stack, then jumps to an address +static inline void i8080_call(i8080* const c, uint16_t addr) { + i8080_push_stack(c, c->pc); + i8080_jmp(c, addr); +} + +// calls to next word in memory if a condition is met +static inline void i8080_cond_call(i8080* const c, bool condition) { + uint16_t addr = i8080_next_word(c); + if (condition) { + i8080_call(c, addr); + c->cyc += 6; + } +} + +// returns from subroutine +static inline void i8080_ret(i8080* const c) { + c->pc = i8080_pop_stack(c); +} + +// returns from subroutine if a condition is met +static inline void i8080_cond_ret(i8080* const c, bool condition) { + if (condition) { + i8080_ret(c); + c->cyc += 6; + } +} + +// pushes register A and the flags into the stack +static inline void i8080_push_psw(i8080* const c) { + // note: bit 3 and 5 are always 0 + uint8_t psw = 0; + psw |= c->sf << 7; + psw |= c->zf << 6; + psw |= c->hf << 4; + psw |= c->pf << 2; + psw |= 1 << 1; // bit 1 is always 1 + psw |= c->cf << 0; + i8080_push_stack(c, c->a << 8 | psw); +} + +// pops register A and the flags from the stack +static inline void i8080_pop_psw(i8080* const c) { + uint16_t af = i8080_pop_stack(c); + c->a = af >> 8; + uint8_t psw = af & 0xFF; + + c->sf = (psw >> 7) & 1; + c->zf = (psw >> 6) & 1; + c->hf = (psw >> 4) & 1; + c->pf = (psw >> 2) & 1; + c->cf = (psw >> 0) & 1; +} + +// rotate register A left +static inline void i8080_rlc(i8080* const c) { + c->cf = c->a >> 7; + c->a = (c->a << 1) | c->cf; +} + +// rotate register A right +static inline void i8080_rrc(i8080* const c) { + c->cf = c->a & 1; + c->a = (c->a >> 1) | (c->cf << 7); +} + +// rotate register A left with the carry flag +static inline void i8080_ral(i8080* const c) { + bool cy = c->cf; + c->cf = c->a >> 7; + c->a = (c->a << 1) | cy; +} + +// rotate register A right with the carry flag +static inline void i8080_rar(i8080* const c) { + bool cy = c->cf; + c->cf = c->a & 1; + c->a = (c->a >> 1) | (cy << 7); +} + +// Decimal Adjust Accumulator: the eight-bit number in register A is adjusted +// to form two four-bit binary-coded-decimal digits. +// For example, if A=$2B and DAA is executed, A becomes $31. +static inline void i8080_daa(i8080* const c) { + bool cy = c->cf; + uint8_t correction = 0; + + uint8_t lsb = c->a & 0x0F; + uint8_t msb = c->a >> 4; + + if (c->hf || lsb > 9) { + correction += 0x06; + } + + if (c->cf || msb > 9 || (msb >= 9 && lsb > 9)) { + correction += 0x60; + cy = 1; + } + + i8080_add(c, &c->a, correction, 0); + c->cf = cy; +} + +// switches the value of registers DE and HL +static inline void i8080_xchg(i8080* const c) { + uint16_t de = i8080_get_de(c); + i8080_set_de(c, i8080_get_hl(c)); + i8080_set_hl(c, de); +} + +// switches the value of a word at (sp) and HL +static inline void i8080_xthl(i8080* const c) { + uint16_t val = i8080_rw(c, c->sp); + i8080_ww(c, c->sp, i8080_get_hl(c)); + i8080_set_hl(c, val); +} + +extern void interrupt_808x(uint16_t addr); +extern void retem_i8080(void); +// executes one opcode +static inline void i8080_execute(i8080* const c, uint8_t opcode) { + c->cyc += OPCODES_CYCLES[opcode]; + + // when DI is executed, interrupts won't be serviced + // until the end of next instruction: + if (c->interrupt_delay > 0) { + c->interrupt_delay -= 1; + } + + switch (opcode) { + case 0x7F: c->a = c->a; break; // MOV A,A + case 0x78: c->a = c->b; break; // MOV A,B + case 0x79: c->a = c->c; break; // MOV A,C + case 0x7A: c->a = c->d; break; // MOV A,D + case 0x7B: c->a = c->e; break; // MOV A,E + case 0x7C: c->a = c->h; break; // MOV A,H + case 0x7D: c->a = c->l; break; // MOV A,L + case 0x7E: c->a = i8080_rb(c, i8080_get_hl(c)); break; // MOV A,M + + case 0x0A: c->a = i8080_rb(c, i8080_get_bc(c)); break; // LDAX B + case 0x1A: c->a = i8080_rb(c, i8080_get_de(c)); break; // LDAX D + case 0x3A: c->a = i8080_rb(c, i8080_next_word(c)); break; // LDA word + + case 0x47: c->b = c->a; break; // MOV B,A + case 0x40: c->b = c->b; break; // MOV B,B + case 0x41: c->b = c->c; break; // MOV B,C + case 0x42: c->b = c->d; break; // MOV B,D + case 0x43: c->b = c->e; break; // MOV B,E + case 0x44: c->b = c->h; break; // MOV B,H + case 0x45: c->b = c->l; break; // MOV B,L + case 0x46: c->b = i8080_rb(c, i8080_get_hl(c)); break; // MOV B,M + + case 0x4F: c->c = c->a; break; // MOV C,A + case 0x48: c->c = c->b; break; // MOV C,B + case 0x49: c->c = c->c; break; // MOV C,C + case 0x4A: c->c = c->d; break; // MOV C,D + case 0x4B: c->c = c->e; break; // MOV C,E + case 0x4C: c->c = c->h; break; // MOV C,H + case 0x4D: c->c = c->l; break; // MOV C,L + case 0x4E: c->c = i8080_rb(c, i8080_get_hl(c)); break; // MOV C,M + + case 0x57: c->d = c->a; break; // MOV D,A + case 0x50: c->d = c->b; break; // MOV D,B + case 0x51: c->d = c->c; break; // MOV D,C + case 0x52: c->d = c->d; break; // MOV D,D + case 0x53: c->d = c->e; break; // MOV D,E + case 0x54: c->d = c->h; break; // MOV D,H + case 0x55: c->d = c->l; break; // MOV D,L + case 0x56: c->d = i8080_rb(c, i8080_get_hl(c)); break; // MOV D,M + + case 0x5F: c->e = c->a; break; // MOV E,A + case 0x58: c->e = c->b; break; // MOV E,B + case 0x59: c->e = c->c; break; // MOV E,C + case 0x5A: c->e = c->d; break; // MOV E,D + case 0x5B: c->e = c->e; break; // MOV E,E + case 0x5C: c->e = c->h; break; // MOV E,H + case 0x5D: c->e = c->l; break; // MOV E,L + case 0x5E: c->e = i8080_rb(c, i8080_get_hl(c)); break; // MOV E,M + + case 0x67: c->h = c->a; break; // MOV H,A + case 0x60: c->h = c->b; break; // MOV H,B + case 0x61: c->h = c->c; break; // MOV H,C + case 0x62: c->h = c->d; break; // MOV H,D + case 0x63: c->h = c->e; break; // MOV H,E + case 0x64: c->h = c->h; break; // MOV H,H + case 0x65: c->h = c->l; break; // MOV H,L + case 0x66: c->h = i8080_rb(c, i8080_get_hl(c)); break; // MOV H,M + + case 0x6F: c->l = c->a; break; // MOV L,A + case 0x68: c->l = c->b; break; // MOV L,B + case 0x69: c->l = c->c; break; // MOV L,C + case 0x6A: c->l = c->d; break; // MOV L,D + case 0x6B: c->l = c->e; break; // MOV L,E + case 0x6C: c->l = c->h; break; // MOV L,H + case 0x6D: c->l = c->l; break; // MOV L,L + case 0x6E: c->l = i8080_rb(c, i8080_get_hl(c)); break; // MOV L,M + + case 0x77: i8080_wb(c, i8080_get_hl(c), c->a); break; // MOV M,A + case 0x70: i8080_wb(c, i8080_get_hl(c), c->b); break; // MOV M,B + case 0x71: i8080_wb(c, i8080_get_hl(c), c->c); break; // MOV M,C + case 0x72: i8080_wb(c, i8080_get_hl(c), c->d); break; // MOV M,D + case 0x73: i8080_wb(c, i8080_get_hl(c), c->e); break; // MOV M,E + case 0x74: i8080_wb(c, i8080_get_hl(c), c->h); break; // MOV M,H + case 0x75: i8080_wb(c, i8080_get_hl(c), c->l); break; // MOV M,L + + case 0x3E: c->a = i8080_next_byte(c); break; // MVI A,byte + case 0x06: c->b = i8080_next_byte(c); break; // MVI B,byte + case 0x0E: c->c = i8080_next_byte(c); break; // MVI C,byte + case 0x16: c->d = i8080_next_byte(c); break; // MVI D,byte + case 0x1E: c->e = i8080_next_byte(c); break; // MVI E,byte + case 0x26: c->h = i8080_next_byte(c); break; // MVI H,byte + case 0x2E: c->l = i8080_next_byte(c); break; // MVI L,byte + case 0x36: + i8080_wb(c, i8080_get_hl(c), i8080_next_byte(c)); + break; // MVI M,byte + + case 0x02: i8080_wb(c, i8080_get_bc(c), c->a); break; // STAX B + case 0x12: i8080_wb(c, i8080_get_de(c), c->a); break; // STAX D + case 0x32: i8080_wb(c, i8080_next_word(c), c->a); break; // STA word + + case 0x01: i8080_set_bc(c, i8080_next_word(c)); break; // LXI B,word + case 0x11: i8080_set_de(c, i8080_next_word(c)); break; // LXI D,word + case 0x21: i8080_set_hl(c, i8080_next_word(c)); break; // LXI H,word + case 0x31: c->sp = i8080_next_word(c); break; // LXI SP,word + case 0x2A: i8080_set_hl(c, i8080_rw(c, i8080_next_word(c))); break; // LHLD + case 0x22: i8080_ww(c, i8080_next_word(c), i8080_get_hl(c)); break; // SHLD + case 0xF9: c->sp = i8080_get_hl(c); break; // SPHL + + case 0xEB: i8080_xchg(c); break; // XCHG + case 0xE3: i8080_xthl(c); break; // XTHL + + case 0x87: i8080_add(c, &c->a, c->a, 0); break; // ADD A + case 0x80: i8080_add(c, &c->a, c->b, 0); break; // ADD B + case 0x81: i8080_add(c, &c->a, c->c, 0); break; // ADD C + case 0x82: i8080_add(c, &c->a, c->d, 0); break; // ADD D + case 0x83: i8080_add(c, &c->a, c->e, 0); break; // ADD E + case 0x84: i8080_add(c, &c->a, c->h, 0); break; // ADD H + case 0x85: i8080_add(c, &c->a, c->l, 0); break; // ADD L + case 0x86: + i8080_add(c, &c->a, i8080_rb(c, i8080_get_hl(c)), 0); + break; // ADD M + case 0xC6: i8080_add(c, &c->a, i8080_next_byte(c), 0); break; // ADI byte + + case 0x8F: i8080_add(c, &c->a, c->a, c->cf); break; // ADC A + case 0x88: i8080_add(c, &c->a, c->b, c->cf); break; // ADC B + case 0x89: i8080_add(c, &c->a, c->c, c->cf); break; // ADC C + case 0x8A: i8080_add(c, &c->a, c->d, c->cf); break; // ADC D + case 0x8B: i8080_add(c, &c->a, c->e, c->cf); break; // ADC E + case 0x8C: i8080_add(c, &c->a, c->h, c->cf); break; // ADC H + case 0x8D: i8080_add(c, &c->a, c->l, c->cf); break; // ADC L + case 0x8E: + i8080_add(c, &c->a, i8080_rb(c, i8080_get_hl(c)), c->cf); + break; // ADC M + case 0xCE: i8080_add(c, &c->a, i8080_next_byte(c), c->cf); break; // ACI byte + + case 0x97: i8080_sub(c, &c->a, c->a, 0); break; // SUB A + case 0x90: i8080_sub(c, &c->a, c->b, 0); break; // SUB B + case 0x91: i8080_sub(c, &c->a, c->c, 0); break; // SUB C + case 0x92: i8080_sub(c, &c->a, c->d, 0); break; // SUB D + case 0x93: i8080_sub(c, &c->a, c->e, 0); break; // SUB E + case 0x94: i8080_sub(c, &c->a, c->h, 0); break; // SUB H + case 0x95: i8080_sub(c, &c->a, c->l, 0); break; // SUB L + case 0x96: + i8080_sub(c, &c->a, i8080_rb(c, i8080_get_hl(c)), 0); + break; // SUB M + case 0xD6: i8080_sub(c, &c->a, i8080_next_byte(c), 0); break; // SUI byte + + case 0x9F: i8080_sub(c, &c->a, c->a, c->cf); break; // SBB A + case 0x98: i8080_sub(c, &c->a, c->b, c->cf); break; // SBB B + case 0x99: i8080_sub(c, &c->a, c->c, c->cf); break; // SBB C + case 0x9A: i8080_sub(c, &c->a, c->d, c->cf); break; // SBB D + case 0x9B: i8080_sub(c, &c->a, c->e, c->cf); break; // SBB E + case 0x9C: i8080_sub(c, &c->a, c->h, c->cf); break; // SBB H + case 0x9D: i8080_sub(c, &c->a, c->l, c->cf); break; // SBB L + case 0x9E: + i8080_sub(c, &c->a, i8080_rb(c, i8080_get_hl(c)), c->cf); + break; // SBB M + case 0xDE: i8080_sub(c, &c->a, i8080_next_byte(c), c->cf); break; // SBI byte + + case 0x09: i8080_dad(c, i8080_get_bc(c)); break; // DAD B + case 0x19: i8080_dad(c, i8080_get_de(c)); break; // DAD D + case 0x29: i8080_dad(c, i8080_get_hl(c)); break; // DAD H + case 0x39: i8080_dad(c, c->sp); break; // DAD SP + + case 0xF3: c->iff = 0; break; // DI + case 0xFB: + c->iff = 1; + c->interrupt_delay = 1; + break; // EI + case 0x00: break; // NOP + case 0x76: c->halted = 1; break; // HLT + + case 0x3C: c->a = i8080_inr(c, c->a); break; // INR A + case 0x04: c->b = i8080_inr(c, c->b); break; // INR B + case 0x0C: c->c = i8080_inr(c, c->c); break; // INR C + case 0x14: c->d = i8080_inr(c, c->d); break; // INR D + case 0x1C: c->e = i8080_inr(c, c->e); break; // INR E + case 0x24: c->h = i8080_inr(c, c->h); break; // INR H + case 0x2C: c->l = i8080_inr(c, c->l); break; // INR L + case 0x34: + i8080_wb(c, i8080_get_hl(c), i8080_inr(c, i8080_rb(c, i8080_get_hl(c)))); + break; // INR M + + case 0x3D: c->a = i8080_dcr(c, c->a); break; // DCR A + case 0x05: c->b = i8080_dcr(c, c->b); break; // DCR B + case 0x0D: c->c = i8080_dcr(c, c->c); break; // DCR C + case 0x15: c->d = i8080_dcr(c, c->d); break; // DCR D + case 0x1D: c->e = i8080_dcr(c, c->e); break; // DCR E + case 0x25: c->h = i8080_dcr(c, c->h); break; // DCR H + case 0x2D: c->l = i8080_dcr(c, c->l); break; // DCR L + case 0x35: + i8080_wb(c, i8080_get_hl(c), i8080_dcr(c, i8080_rb(c, i8080_get_hl(c)))); + break; // DCR M + + case 0x03: i8080_set_bc(c, i8080_get_bc(c) + 1); break; // INX B + case 0x13: i8080_set_de(c, i8080_get_de(c) + 1); break; // INX D + case 0x23: i8080_set_hl(c, i8080_get_hl(c) + 1); break; // INX H + case 0x33: c->sp += 1; break; // INX SP + + case 0x0B: i8080_set_bc(c, i8080_get_bc(c) - 1); break; // DCX B + case 0x1B: i8080_set_de(c, i8080_get_de(c) - 1); break; // DCX D + case 0x2B: i8080_set_hl(c, i8080_get_hl(c) - 1); break; // DCX H + case 0x3B: c->sp -= 1; break; // DCX SP + + case 0x27: i8080_daa(c); break; // DAA + case 0x2F: c->a = ~c->a; break; // CMA + case 0x37: c->cf = 1; break; // STC + case 0x3F: c->cf = !c->cf; break; // CMC + + case 0x07: i8080_rlc(c); break; // RLC (rotate left) + case 0x0F: i8080_rrc(c); break; // RRC (rotate right) + case 0x17: i8080_ral(c); break; // RAL + case 0x1F: i8080_rar(c); break; // RAR + + case 0xA7: i8080_ana(c, c->a); break; // ANA A + case 0xA0: i8080_ana(c, c->b); break; // ANA B + case 0xA1: i8080_ana(c, c->c); break; // ANA C + case 0xA2: i8080_ana(c, c->d); break; // ANA D + case 0xA3: i8080_ana(c, c->e); break; // ANA E + case 0xA4: i8080_ana(c, c->h); break; // ANA H + case 0xA5: i8080_ana(c, c->l); break; // ANA L + case 0xA6: i8080_ana(c, i8080_rb(c, i8080_get_hl(c))); break; // ANA M + case 0xE6: i8080_ana(c, i8080_next_byte(c)); break; // ANI byte + + case 0xAF: i8080_xra(c, c->a); break; // XRA A + case 0xA8: i8080_xra(c, c->b); break; // XRA B + case 0xA9: i8080_xra(c, c->c); break; // XRA C + case 0xAA: i8080_xra(c, c->d); break; // XRA D + case 0xAB: i8080_xra(c, c->e); break; // XRA E + case 0xAC: i8080_xra(c, c->h); break; // XRA H + case 0xAD: i8080_xra(c, c->l); break; // XRA L + case 0xAE: i8080_xra(c, i8080_rb(c, i8080_get_hl(c))); break; // XRA M + case 0xEE: i8080_xra(c, i8080_next_byte(c)); break; // XRI byte + + case 0xB7: i8080_ora(c, c->a); break; // ORA A + case 0xB0: i8080_ora(c, c->b); break; // ORA B + case 0xB1: i8080_ora(c, c->c); break; // ORA C + case 0xB2: i8080_ora(c, c->d); break; // ORA D + case 0xB3: i8080_ora(c, c->e); break; // ORA E + case 0xB4: i8080_ora(c, c->h); break; // ORA H + case 0xB5: i8080_ora(c, c->l); break; // ORA L + case 0xB6: i8080_ora(c, i8080_rb(c, i8080_get_hl(c))); break; // ORA M + case 0xF6: i8080_ora(c, i8080_next_byte(c)); break; // ORI byte + + case 0xBF: i8080_cmp(c, c->a); break; // CMP A + case 0xB8: i8080_cmp(c, c->b); break; // CMP B + case 0xB9: i8080_cmp(c, c->c); break; // CMP C + case 0xBA: i8080_cmp(c, c->d); break; // CMP D + case 0xBB: i8080_cmp(c, c->e); break; // CMP E + case 0xBC: i8080_cmp(c, c->h); break; // CMP H + case 0xBD: i8080_cmp(c, c->l); break; // CMP L + case 0xBE: i8080_cmp(c, i8080_rb(c, i8080_get_hl(c))); break; // CMP M + case 0xFE: i8080_cmp(c, i8080_next_byte(c)); break; // CPI byte + + case 0xC3: i8080_jmp(c, i8080_next_word(c)); break; // JMP + case 0xC2: i8080_cond_jmp(c, c->zf == 0); break; // JNZ + case 0xCA: i8080_cond_jmp(c, c->zf == 1); break; // JZ + case 0xD2: i8080_cond_jmp(c, c->cf == 0); break; // JNC + case 0xDA: i8080_cond_jmp(c, c->cf == 1); break; // JC + case 0xE2: i8080_cond_jmp(c, c->pf == 0); break; // JPO + case 0xEA: i8080_cond_jmp(c, c->pf == 1); break; // JPE + case 0xF2: i8080_cond_jmp(c, c->sf == 0); break; // JP + case 0xFA: i8080_cond_jmp(c, c->sf == 1); break; // JM + + case 0xE9: c->pc = i8080_get_hl(c); break; // PCHL + case 0xCD: i8080_call(c, i8080_next_word(c)); break; // CALL + + case 0xC4: i8080_cond_call(c, c->zf == 0); break; // CNZ + case 0xCC: i8080_cond_call(c, c->zf == 1); break; // CZ + case 0xD4: i8080_cond_call(c, c->cf == 0); break; // CNC + case 0xDC: i8080_cond_call(c, c->cf == 1); break; // CC + case 0xE4: i8080_cond_call(c, c->pf == 0); break; // CPO + case 0xEC: i8080_cond_call(c, c->pf == 1); break; // CPE + case 0xF4: i8080_cond_call(c, c->sf == 0); break; // CP + case 0xFC: i8080_cond_call(c, c->sf == 1); break; // CM + + case 0xC9: i8080_ret(c); break; // RET + case 0xC0: i8080_cond_ret(c, c->zf == 0); break; // RNZ + case 0xC8: i8080_cond_ret(c, c->zf == 1); break; // RZ + case 0xD0: i8080_cond_ret(c, c->cf == 0); break; // RNC + case 0xD8: i8080_cond_ret(c, c->cf == 1); break; // RC + case 0xE0: i8080_cond_ret(c, c->pf == 0); break; // RPO + case 0xE8: i8080_cond_ret(c, c->pf == 1); break; // RPE + case 0xF0: i8080_cond_ret(c, c->sf == 0); break; // RP + case 0xF8: i8080_cond_ret(c, c->sf == 1); break; // RM + + case 0xC7: i8080_call(c, 0x00); break; // RST 0 + case 0xCF: i8080_call(c, 0x08); break; // RST 1 + case 0xD7: i8080_call(c, 0x10); break; // RST 2 + case 0xDF: i8080_call(c, 0x18); break; // RST 3 + case 0xE7: i8080_call(c, 0x20); break; // RST 4 + case 0xEF: i8080_call(c, 0x28); break; // RST 5 + case 0xF7: i8080_call(c, 0x30); break; // RST 6 + case 0xFF: i8080_call(c, 0x38); break; // RST 7 + + case 0xC5: i8080_push_stack(c, i8080_get_bc(c)); break; // PUSH B + case 0xD5: i8080_push_stack(c, i8080_get_de(c)); break; // PUSH D + case 0xE5: i8080_push_stack(c, i8080_get_hl(c)); break; // PUSH H + case 0xF5: i8080_push_psw(c); break; // PUSH PSW + case 0xC1: i8080_set_bc(c, i8080_pop_stack(c)); break; // POP B + case 0xD1: i8080_set_de(c, i8080_pop_stack(c)); break; // POP D + case 0xE1: i8080_set_hl(c, i8080_pop_stack(c)); break; // POP H + case 0xF1: i8080_pop_psw(c); break; // POP PSW + + case 0xDB: c->a = c->port_in(c->userdata, i8080_next_byte(c)); break; // IN + case 0xD3: c->port_out(c->userdata, i8080_next_byte(c), c->a); break; // OUT + + case 0x08: + case 0x10: + case 0x18: + case 0x20: + case 0x28: + case 0x30: + case 0x38: break; // undocumented NOPs + + case 0xD9: i8080_ret(c); break; // undocumented RET + + case 0xDD: + case 0xED: + { + if (opcode == 0xED) { + uint8_t data = i8080_next_byte(c); + if (data == 0xED) { + interrupt_808x(i8080_next_byte(c)); + break; + } else if (data == 0xFD) { + retem_i8080(); + break; + } + else { + i8080_call(c, (i8080_next_byte(c) << 8) | data); break; + } + } + } + case 0xFD: i8080_call(c, i8080_next_word(c)); break; // undocumented CALLs + + case 0xCB: i8080_jmp(c, i8080_next_word(c)); break; // undocumented JMP + } +} + +// initialises the emulator with default values +void i8080_init(i8080* const c) { + c->read_byte = NULL; + c->write_byte = NULL; + c->port_in = NULL; + c->port_out = NULL; + c->userdata = NULL; + + c->cyc = 0; + + c->pc = 0; + c->sp = 0; + + c->a = 0; + c->b = 0; + c->c = 0; + c->d = 0; + c->e = 0; + c->h = 0; + c->l = 0; + + c->sf = 0; + c->zf = 0; + c->hf = 0; + c->pf = 0; + c->cf = 0; + c->iff = 0; + + c->halted = 0; + c->interrupt_pending = 0; + c->interrupt_vector = 0; + c->interrupt_delay = 0; +} + +// executes one instruction +void i8080_step(i8080* const c) { + // interrupt processing: if an interrupt is pending and IFF is set, + // we execute the interrupt vector passed by the user. + if (c->interrupt_pending && c->iff && c->interrupt_delay == 0) { + c->interrupt_pending = 0; + c->iff = 0; + c->halted = 0; + + i8080_execute(c, c->interrupt_vector); + } else if (!c->halted) { + i8080_execute(c, i8080_next_byte(c)); + } +} + +// asks for an interrupt to be serviced +void i8080_interrupt(i8080* const c, uint8_t opcode) { + c->interrupt_pending = 1; + c->interrupt_vector = opcode; +} + +// outputs a debug trace of the emulator state to the standard output, +// including registers and flags +void i8080_debug_output(i8080* const c, bool print_disassembly) { + uint8_t f = 0; + f |= c->sf << 7; + f |= c->zf << 6; + f |= c->hf << 4; + f |= c->pf << 2; + f |= 1 << 1; // bit 1 is always 1 + f |= c->cf << 0; + + printf("PC: %04X, AF: %04X, BC: %04X, DE: %04X, HL: %04X, SP: %04X, CYC: %lu", + c->pc, c->a << 8 | f, i8080_get_bc(c), i8080_get_de(c), i8080_get_hl(c), + c->sp, c->cyc); + + printf("\t(%02X %02X %02X %02X)", i8080_rb(c, c->pc), i8080_rb(c, c->pc + 1), + i8080_rb(c, c->pc + 2), i8080_rb(c, c->pc + 3)); + + if (print_disassembly) { + printf(" - %s", DISASSEMBLE_TABLE[i8080_rb(c, c->pc)]); + } + + printf("\n"); +} + +#undef SET_ZSP diff --git a/src/cpu/i8080.h b/src/cpu/i8080.h new file mode 100644 index 000000000..43406e43e --- /dev/null +++ b/src/cpu/i8080.h @@ -0,0 +1,35 @@ +#ifndef I8080_I8080_H_ +#define I8080_I8080_H_ + +#include +#include +#include + +typedef struct i8080 { + // memory + io interface + uint8_t (*read_byte)(void*, uint16_t); // user function to read from memory + void (*write_byte)(void*, uint16_t, uint8_t); // same for writing to memory + uint8_t (*read_byte_seg)(void*, uint16_t); // user function to read from memory (Code segment) + uint8_t (*port_in)(void*, uint8_t); // user function to read from port + void (*port_out)(void*, uint8_t, uint8_t); // same for writing to port + void* userdata; // user custom pointer + + unsigned long cyc; // cycle count + + uint16_t pc, sp; // program counter, stack pointer + uint8_t a, b, c, d, e, h, l; // registers + // flags: sign, zero, half-carry, parity, carry, interrupt flip-flop + bool sf : 1, zf : 1, hf : 1, pf : 1, cf : 1, iff : 1; + bool halted : 1; + + bool interrupt_pending : 1; + uint8_t interrupt_vector; + uint8_t interrupt_delay; +} i8080; + +void i8080_init(i8080* const c); +void i8080_step(i8080* const c); +void i8080_interrupt(i8080* const c, uint8_t opcode); +void i8080_debug_output(i8080* const c, bool print_disassembly); + +#endif // I8080_I8080_H_ diff --git a/src/cpu/x86.c b/src/cpu/x86.c index 8a0bd830f..1b0de661b 100644 --- a/src/cpu/x86.c +++ b/src/cpu/x86.c @@ -271,6 +271,14 @@ reset_common(int hard) stack32 = 0; msr.fcr = (1 << 8) | (1 << 9) | (1 << 12) | (1 << 16) | (1 << 19) | (1 << 21); msw = 0; + new_ne = 0; + x87_op = 0; + + ccr0 = ccr1 = ccr2 = ccr3 = ccr4 = ccr5 = ccr6 = ccr7 = 0; + ccr4 = 0x85; + cyrix.arr[3].base = 0x30000; + cyrix.arr[3].size = 65536; + if (hascache) cr0 = 1 << 30; else @@ -318,7 +326,6 @@ reset_common(int hard) resetreadlookup(); makemod1table(); cpu_set_edx(); - mmu_perm = 4; } x86seg_reset(); #ifdef USE_DYNAREC diff --git a/src/cpu/x86.h b/src/cpu/x86.h index 327af8964..ccfeadea0 100644 --- a/src/cpu/x86.h +++ b/src/cpu/x86.h @@ -103,4 +103,10 @@ extern int fpu_cycles; extern void x86illegal(void); +extern uint8_t rep_op; +extern uint8_t is_smint; + +extern uint16_t io_port; +extern uint32_t io_val; + #endif /*EMU_X86_H*/ diff --git a/src/cpu/x86_flags.h b/src/cpu/x86_flags.h index e82041783..7d5c41ca8 100644 --- a/src/cpu/x86_flags.h +++ b/src/cpu/x86_flags.h @@ -741,7 +741,7 @@ setadc8(uint8_t a, uint8_t b) cpu_state.flags |= C_FLAG; if (!((a ^ b) & 0x80) && ((a ^ c) & 0x80)) cpu_state.flags |= V_FLAG; - if (((a & 0xF) + (b & 0xF)) & 0x10) + if (((a & 0xF) + (b & 0xF) + tempc) & 0x10) cpu_state.flags |= A_FLAG; } static __inline void @@ -755,7 +755,7 @@ setadc16(uint16_t a, uint16_t b) cpu_state.flags |= C_FLAG; if (!((a ^ b) & 0x8000) && ((a ^ c) & 0x8000)) cpu_state.flags |= V_FLAG; - if (((a & 0xF) + (b & 0xF)) & 0x10) + if (((a & 0xF) + (b & 0xF) + tempc) & 0x10) cpu_state.flags |= A_FLAG; } static __inline void @@ -785,7 +785,7 @@ setsbc8(uint8_t a, uint8_t b) cpu_state.flags |= C_FLAG; if ((a ^ b) & (a ^ c) & 0x80) cpu_state.flags |= V_FLAG; - if (((a & 0xF) - (b & 0xF)) & 0x10) + if (((a & 0xF) - ((b & 0xF) + tempc)) & 0x10) cpu_state.flags |= A_FLAG; } static __inline void @@ -800,7 +800,7 @@ setsbc16(uint16_t a, uint16_t b) cpu_state.flags |= C_FLAG; if ((a ^ b) & (a ^ c) & 0x8000) cpu_state.flags |= V_FLAG; - if (((a & 0xF) - (b & 0xF)) & 0x10) + if (((a & 0xF) - ((b & 0xF) + tempc)) & 0x10) cpu_state.flags |= A_FLAG; } diff --git a/src/cpu/x86_ops.h b/src/cpu/x86_ops.h index 3dfb3f917..ed95d04d9 100644 --- a/src/cpu/x86_ops.h +++ b/src/cpu/x86_ops.h @@ -90,10 +90,9 @@ extern const OpFn dynarec_ops_winchip2_0f[1024]; extern const OpFn dynarec_ops_pentium_0f[1024]; extern const OpFn dynarec_ops_pentiummmx_0f[1024]; -# ifdef USE_CYRIX_6X86 extern const OpFn dynarec_ops_c6x86_0f[1024]; +extern const OpFn dynarec_ops_c6x86l_0f[1024]; extern const OpFn dynarec_ops_c6x86mx_0f[1024]; -# endif /* USE_CYRIX_6X86 */ extern const OpFn dynarec_ops_k6_0f[1024]; extern const OpFn dynarec_ops_k62_0f[1024]; @@ -232,10 +231,9 @@ extern const OpFn ops_winchip2_0f[1024]; extern const OpFn ops_pentium_0f[1024]; extern const OpFn ops_pentiummmx_0f[1024]; -#ifdef USE_CYRIX_6X86 extern const OpFn ops_c6x86_0f[1024]; +extern const OpFn ops_c6x86l_0f[1024]; extern const OpFn ops_c6x86mx_0f[1024]; -#endif /* USE_CYRIX_6X86 */ extern const OpFn ops_k6_0f[1024]; extern const OpFn ops_k62_0f[1024]; @@ -263,14 +261,20 @@ 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_cyrix_d9_a16[256]; +extern const OpFn ops_sf_fpu_cyrix_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_cyrix_686_db_a16[256]; +extern const OpFn ops_sf_fpu_cyrix_686_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_cyrix_dd_a16[256]; +extern const OpFn ops_sf_fpu_cyrix_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]; @@ -295,6 +299,8 @@ extern const OpFn ops_fpu_d8_a16[32]; extern const OpFn ops_fpu_d8_a32[32]; extern const OpFn ops_fpu_d9_a16[256]; extern const OpFn ops_fpu_d9_a32[256]; +extern const OpFn ops_fpu_cyrix_d9_a16[256]; +extern const OpFn ops_fpu_cyrix_d9_a32[256]; extern const OpFn ops_fpu_da_a16[256]; extern const OpFn ops_fpu_da_a32[256]; extern const OpFn ops_fpu_db_a16[256]; @@ -303,6 +309,8 @@ extern const OpFn ops_fpu_dc_a16[32]; extern const OpFn ops_fpu_dc_a32[32]; extern const OpFn ops_fpu_dd_a16[256]; extern const OpFn ops_fpu_dd_a32[256]; +extern const OpFn ops_fpu_cyrix_dd_a16[256]; +extern const OpFn ops_fpu_cyrix_dd_a32[256]; extern const OpFn ops_fpu_de_a16[256]; extern const OpFn ops_fpu_de_a32[256]; extern const OpFn ops_fpu_df_a16[256]; @@ -314,15 +322,23 @@ 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_cyrix_686_db_a16[256]; +extern const OpFn ops_sf_fpu_cyrix_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_sf_fpu_cyrix_686_df_a16[256]; +extern const OpFn ops_sf_fpu_cyrix_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]; extern const OpFn ops_fpu_686_db_a32[256]; +extern const OpFn ops_fpu_cyrix_686_db_a16[256]; +extern const OpFn ops_fpu_cyrix_686_db_a32[256]; extern const OpFn ops_fpu_686_df_a16[256]; extern const OpFn ops_fpu_686_df_a32[256]; +extern const OpFn ops_fpu_cyrix_686_df_a16[256]; +extern const OpFn ops_fpu_cyrix_686_df_a32[256]; extern const OpFn ops_REPE[1024]; extern const OpFn ops_REPNE[1024]; diff --git a/src/cpu/x86_ops_3dnow.h b/src/cpu/x86_ops_3dnow.h index b72cbc06c..2b4ed1a6d 100644 --- a/src/cpu/x86_ops_3dnow.h +++ b/src/cpu/x86_ops_3dnow.h @@ -20,7 +20,7 @@ opPREFETCH_a32(uint32_t fetchdat) } static int -opFEMMS(uint32_t fetchdat) +opFEMMS(UNUSED(uint32_t fetchdat)) { ILLEGAL_ON(!cpu_has_feature(CPU_FEATURE_MMX)); if (cr0 & 0xc) { @@ -33,7 +33,7 @@ opFEMMS(uint32_t fetchdat) } static int -opPAVGUSB(uint32_t fetchdat) +opPAVGUSB(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -54,7 +54,7 @@ opPAVGUSB(uint32_t fetchdat) return 0; } static int -opPF2ID(uint32_t fetchdat) +opPF2ID(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -69,7 +69,7 @@ opPF2ID(uint32_t fetchdat) return 0; } static int -opPF2IW(uint32_t fetchdat) +opPF2IW(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -84,7 +84,7 @@ opPF2IW(uint32_t fetchdat) return 0; } static int -opPFACC(uint32_t fetchdat) +opPFACC(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -101,7 +101,7 @@ opPFACC(uint32_t fetchdat) return 0; } static int -opPFNACC(uint32_t fetchdat) +opPFNACC(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -118,7 +118,7 @@ opPFNACC(uint32_t fetchdat) return 0; } static int -opPFPNACC(uint32_t fetchdat) +opPFPNACC(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -135,7 +135,7 @@ opPFPNACC(uint32_t fetchdat) return 0; } static int -opPSWAPD(uint32_t fetchdat) +opPSWAPD(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -155,7 +155,7 @@ opPSWAPD(uint32_t fetchdat) return 0; } static int -opPFADD(uint32_t fetchdat) +opPFADD(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -170,7 +170,7 @@ opPFADD(uint32_t fetchdat) return 0; } static int -opPFCMPEQ(uint32_t fetchdat) +opPFCMPEQ(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -185,7 +185,7 @@ opPFCMPEQ(uint32_t fetchdat) return 0; } static int -opPFCMPGE(uint32_t fetchdat) +opPFCMPGE(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -200,7 +200,7 @@ opPFCMPGE(uint32_t fetchdat) return 0; } static int -opPFCMPGT(uint32_t fetchdat) +opPFCMPGT(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -215,7 +215,7 @@ opPFCMPGT(uint32_t fetchdat) return 0; } static int -opPFMAX(uint32_t fetchdat) +opPFMAX(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -232,7 +232,7 @@ opPFMAX(uint32_t fetchdat) return 0; } static int -opPFMIN(uint32_t fetchdat) +opPFMIN(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -249,7 +249,7 @@ opPFMIN(uint32_t fetchdat) return 0; } static int -opPFMUL(uint32_t fetchdat) +opPFMUL(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -264,7 +264,7 @@ opPFMUL(uint32_t fetchdat) return 0; } static int -opPFRCP(uint32_t fetchdat) +opPFRCP(UNUSED(uint32_t fetchdat)) { MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -293,7 +293,7 @@ opPFRCP(uint32_t fetchdat) } /*Since opPFRCP() calculates a full precision reciprocal, treat the followup iterations as MOVs*/ static int -opPFRCPIT1(uint32_t fetchdat) +opPFRCPIT1(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -308,7 +308,7 @@ opPFRCPIT1(uint32_t fetchdat) return 0; } static int -opPFRCPIT2(uint32_t fetchdat) +opPFRCPIT2(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -323,7 +323,7 @@ opPFRCPIT2(uint32_t fetchdat) return 0; } static int -opPFRSQRT(uint32_t fetchdat) +opPFRSQRT(UNUSED(uint32_t fetchdat)) { MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -352,7 +352,7 @@ opPFRSQRT(uint32_t fetchdat) } /*Since opPFRSQRT() calculates a full precision inverse square root, treat the followup iteration as a NOP*/ static int -opPFRSQIT1(uint32_t fetchdat) +opPFRSQIT1(UNUSED(uint32_t fetchdat)) { MMX_REG src; @@ -362,7 +362,7 @@ opPFRSQIT1(uint32_t fetchdat) return 0; } static int -opPFSUB(uint32_t fetchdat) +opPFSUB(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -377,7 +377,7 @@ opPFSUB(uint32_t fetchdat) return 0; } static int -opPFSUBR(uint32_t fetchdat) +opPFSUBR(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -392,7 +392,7 @@ opPFSUBR(uint32_t fetchdat) return 0; } static int -opPI2FD(uint32_t fetchdat) +opPI2FD(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -407,7 +407,7 @@ opPI2FD(uint32_t fetchdat) return 0; } static int -opPI2FW(uint32_t fetchdat) +opPI2FW(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); @@ -422,7 +422,7 @@ opPI2FW(uint32_t fetchdat) return 0; } static int -opPMULHRW(uint32_t fetchdat) +opPMULHRW(UNUSED(uint32_t fetchdat)) { MMX_REG src; MMX_REG *dst = MMX_GETREGP(cpu_reg); diff --git a/src/cpu/x86_ops_amd.h b/src/cpu/x86_ops_amd.h index 9e6bcce55..54da4a79d 100644 --- a/src/cpu/x86_ops_amd.h +++ b/src/cpu/x86_ops_amd.h @@ -22,12 +22,8 @@ opSYSCALL(uint32_t fetchdat) ret = syscall_op(fetchdat); - if (ret <= 1) { - CLOCK_CYCLES(20); - PREFETCH_RUN(20, 7, -1, 0, 0, 0, 0, 0); - PREFETCH_FLUSH(); + if (ret <= 1) CPU_BLOCK_END(); - } return ret; } @@ -41,12 +37,8 @@ opSYSRET(uint32_t fetchdat) ret = sysret(fetchdat); - if (ret <= 1) { - CLOCK_CYCLES(20); - PREFETCH_RUN(20, 7, -1, 0, 0, 0, 0, 0); - PREFETCH_FLUSH(); + if (ret <= 1) CPU_BLOCK_END(); - } return ret; } diff --git a/src/cpu/x86_ops_arith.h b/src/cpu/x86_ops_arith.h index 4e3f74e36..0764877a4 100644 --- a/src/cpu/x86_ops_arith.h +++ b/src/cpu/x86_ops_arith.h @@ -313,7 +313,7 @@ return 0; \ } \ \ - static int op##name##_EAX_imm(uint32_t fetchdat) \ + static int op##name##_EAX_imm(UNUSED(uint32_t fetchdat)) \ { \ uint32_t dst = EAX; \ uint32_t src = getlong(); \ @@ -581,7 +581,7 @@ opCMP_AX_imm(uint32_t fetchdat) } static int -opCMP_EAX_imm(uint32_t fetchdat) +opCMP_EAX_imm(UNUSED(uint32_t fetchdat)) { uint32_t src = getlong(); @@ -747,7 +747,7 @@ opTEST_AX(uint32_t fetchdat) return 0; } static int -opTEST_EAX(uint32_t fetchdat) +opTEST_EAX(UNUSED(uint32_t fetchdat)) { uint32_t temp = getlong(); if (cpu_state.abrt) diff --git a/src/cpu/x86_ops_bcd.h b/src/cpu/x86_ops_bcd.h index a04dea65a..a0d18875d 100644 --- a/src/cpu/x86_ops_bcd.h +++ b/src/cpu/x86_ops_bcd.h @@ -1,5 +1,5 @@ static int -opAAA(uint32_t fetchdat) +opAAA(UNUSED(uint32_t fetchdat)) { flags_rebuild(); if ((cpu_state.flags & A_FLAG) || ((AL & 0xF) > 9)) { @@ -46,7 +46,7 @@ opAAM(uint32_t fetchdat) } static int -opAAS(uint32_t fetchdat) +opAAS(UNUSED(uint32_t fetchdat)) { flags_rebuild(); if ((cpu_state.flags & A_FLAG) || ((AL & 0xF) > 9)) { @@ -63,7 +63,7 @@ opAAS(uint32_t fetchdat) } static int -opDAA(uint32_t fetchdat) +opDAA(UNUSED(uint32_t fetchdat)) { uint16_t tempw; uint16_t old_AL; @@ -100,7 +100,7 @@ opDAA(uint32_t fetchdat) } static int -opDAS(uint32_t fetchdat) +opDAS(UNUSED(uint32_t fetchdat)) { uint16_t tempw; uint16_t old_AL; diff --git a/src/cpu/x86_ops_call.h b/src/cpu/x86_ops_call.h index 9d52a2764..ee54dceff 100644 --- a/src/cpu/x86_ops_call.h +++ b/src/cpu/x86_ops_call.h @@ -209,7 +209,7 @@ opCALL_far_w(uint32_t fetchdat) return 0; } static int -opCALL_far_l(uint32_t fetchdat) +opCALL_far_l(UNUSED(uint32_t fetchdat)) { uint32_t old_cs; uint32_t old_pc; diff --git a/src/cpu/x86_ops_cyrix.h b/src/cpu/x86_ops_cyrix.h index 672ebd08e..c95d4b038 100644 --- a/src/cpu/x86_ops_cyrix.h +++ b/src/cpu/x86_ops_cyrix.h @@ -35,7 +35,13 @@ opSVDC_common(uint32_t fetchdat) static int opSVDC_a16(uint32_t fetchdat) { - if (in_smm) { + uint8_t ins_check = ((ccr1 & (CCR1_USE_SMI | CCR1_SM3)) == + (CCR1_USE_SMI | CCR1_SM3)) && + ((ccr1 & CCR1_SMAC) || in_smm) && + (cyrix.arr[3].size > 0) && + (CPL == 0); + + if (ins_check) { fetch_ea_16(fetchdat); SEG_CHECK_WRITE(cpu_state.ea_seg); opSVDC_common(fetchdat); @@ -47,7 +53,13 @@ opSVDC_a16(uint32_t fetchdat) static int opSVDC_a32(uint32_t fetchdat) { - if (in_smm) { + uint8_t ins_check = ((ccr1 & (CCR1_USE_SMI | CCR1_SM3)) == + (CCR1_USE_SMI | CCR1_SM3)) && + ((ccr1 & CCR1_SMAC) || in_smm) && + (cyrix.arr[3].size > 0) && + (CPL == 0); + + if (ins_check) { fetch_ea_32(fetchdat); SEG_CHECK_WRITE(cpu_state.ea_seg); opSVDC_common(fetchdat); @@ -63,18 +75,23 @@ opRSDC_common(uint32_t fetchdat) switch (rmdat & 0x38) { case 0x00: /*ES*/ cyrix_load_seg_descriptor(easeg + cpu_state.eaaddr, &cpu_state.seg_es); + ES = readmemw(0, easeg + cpu_state.eaaddr + 8); break; case 0x18: /*DS*/ cyrix_load_seg_descriptor(easeg + cpu_state.eaaddr, &cpu_state.seg_ds); + DS = readmemw(0, easeg + cpu_state.eaaddr + 8); break; case 0x10: /*SS*/ cyrix_load_seg_descriptor(easeg + cpu_state.eaaddr, &cpu_state.seg_ss); + SS = readmemw(0, easeg + cpu_state.eaaddr + 8); break; case 0x20: /*FS*/ cyrix_load_seg_descriptor(easeg + cpu_state.eaaddr, &cpu_state.seg_fs); + FS = readmemw(0, easeg + cpu_state.eaaddr + 8); break; case 0x28: /*GS*/ cyrix_load_seg_descriptor(easeg + cpu_state.eaaddr, &cpu_state.seg_gs); + GS = readmemw(0, easeg + cpu_state.eaaddr + 8); break; default: x86illegal(); @@ -83,7 +100,13 @@ opRSDC_common(uint32_t fetchdat) static int opRSDC_a16(uint32_t fetchdat) { - if (in_smm) { + uint8_t ins_check = ((ccr1 & (CCR1_USE_SMI | CCR1_SM3)) == + (CCR1_USE_SMI | CCR1_SM3)) && + ((ccr1 & CCR1_SMAC) || in_smm) && + (cyrix.arr[3].size > 0) && + (CPL == 0); + + if (ins_check) { fetch_ea_16(fetchdat); SEG_CHECK_READ(cpu_state.ea_seg); opRSDC_common(fetchdat); @@ -95,7 +118,13 @@ opRSDC_a16(uint32_t fetchdat) static int opRSDC_a32(uint32_t fetchdat) { - if (in_smm) { + uint8_t ins_check = ((ccr1 & (CCR1_USE_SMI | CCR1_SM3)) == + (CCR1_USE_SMI | CCR1_SM3)) && + ((ccr1 & CCR1_SMAC) || in_smm) && + (cyrix.arr[3].size > 0) && + (CPL == 0); + + if (ins_check) { fetch_ea_32(fetchdat); SEG_CHECK_READ(cpu_state.ea_seg); opRSDC_common(fetchdat); @@ -108,7 +137,13 @@ opRSDC_a32(uint32_t fetchdat) static int opSVLDT_a16(uint32_t fetchdat) { - if (in_smm) { + uint8_t ins_check = ((ccr1 & (CCR1_USE_SMI | CCR1_SM3)) == + (CCR1_USE_SMI | CCR1_SM3)) && + ((ccr1 & CCR1_SMAC) || in_smm) && + (cyrix.arr[3].size > 0) && + (CPL == 0); + + if (ins_check) { fetch_ea_16(fetchdat); SEG_CHECK_WRITE(cpu_state.ea_seg); cyrix_write_seg_descriptor(easeg + cpu_state.eaaddr, &ldt); @@ -121,7 +156,13 @@ opSVLDT_a16(uint32_t fetchdat) static int opSVLDT_a32(uint32_t fetchdat) { - if (in_smm) { + uint8_t ins_check = ((ccr1 & (CCR1_USE_SMI | CCR1_SM3)) == + (CCR1_USE_SMI | CCR1_SM3)) && + ((ccr1 & CCR1_SMAC) || in_smm) && + (cyrix.arr[3].size > 0) && + (CPL == 0); + + if (ins_check) { fetch_ea_32(fetchdat); SEG_CHECK_WRITE(cpu_state.ea_seg); cyrix_write_seg_descriptor(easeg + cpu_state.eaaddr, &ldt); @@ -135,7 +176,13 @@ opSVLDT_a32(uint32_t fetchdat) static int opRSLDT_a16(uint32_t fetchdat) { - if (in_smm) { + uint8_t ins_check = ((ccr1 & (CCR1_USE_SMI | CCR1_SM3)) == + (CCR1_USE_SMI | CCR1_SM3)) && + ((ccr1 & CCR1_SMAC) || in_smm) && + (cyrix.arr[3].size > 0) && + (CPL == 0); + + if (ins_check) { fetch_ea_16(fetchdat); SEG_CHECK_READ(cpu_state.ea_seg); cyrix_load_seg_descriptor(easeg + cpu_state.eaaddr, &ldt); @@ -147,7 +194,13 @@ opRSLDT_a16(uint32_t fetchdat) static int opRSLDT_a32(uint32_t fetchdat) { - if (in_smm) { + uint8_t ins_check = ((ccr1 & (CCR1_USE_SMI | CCR1_SM3)) == + (CCR1_USE_SMI | CCR1_SM3)) && + ((ccr1 & CCR1_SMAC) || in_smm) && + (cyrix.arr[3].size > 0) && + (CPL == 0); + + if (ins_check) { fetch_ea_32(fetchdat); SEG_CHECK_READ(cpu_state.ea_seg); cyrix_load_seg_descriptor(easeg + cpu_state.eaaddr, &ldt); @@ -160,7 +213,13 @@ opRSLDT_a32(uint32_t fetchdat) static int opSVTS_a16(uint32_t fetchdat) { - if (in_smm) { + uint8_t ins_check = ((ccr1 & (CCR1_USE_SMI | CCR1_SM3)) == + (CCR1_USE_SMI | CCR1_SM3)) && + ((ccr1 & CCR1_SMAC) || in_smm) && + (cyrix.arr[3].size > 0) && + (CPL == 0); + + if (ins_check) { fetch_ea_16(fetchdat); SEG_CHECK_WRITE(cpu_state.ea_seg); cyrix_write_seg_descriptor(easeg + cpu_state.eaaddr, &tr); @@ -173,7 +232,13 @@ opSVTS_a16(uint32_t fetchdat) static int opSVTS_a32(uint32_t fetchdat) { - if (in_smm) { + uint8_t ins_check = ((ccr1 & (CCR1_USE_SMI | CCR1_SM3)) == + (CCR1_USE_SMI | CCR1_SM3)) && + ((ccr1 & CCR1_SMAC) || in_smm) && + (cyrix.arr[3].size > 0) && + (CPL == 0); + + if (ins_check) { fetch_ea_32(fetchdat); SEG_CHECK_WRITE(cpu_state.ea_seg); cyrix_write_seg_descriptor(easeg + cpu_state.eaaddr, &tr); @@ -187,7 +252,13 @@ opSVTS_a32(uint32_t fetchdat) static int opRSTS_a16(uint32_t fetchdat) { - if (in_smm) { + uint8_t ins_check = ((ccr1 & (CCR1_USE_SMI | CCR1_SM3)) == + (CCR1_USE_SMI | CCR1_SM3)) && + ((ccr1 & CCR1_SMAC) || in_smm) && + (cyrix.arr[3].size > 0) && + (CPL == 0); + + if (ins_check) { fetch_ea_16(fetchdat); SEG_CHECK_WRITE(cpu_state.ea_seg); cyrix_write_seg_descriptor(easeg + cpu_state.eaaddr, &tr); @@ -200,7 +271,13 @@ opRSTS_a16(uint32_t fetchdat) static int opRSTS_a32(uint32_t fetchdat) { - if (in_smm) { + uint8_t ins_check = ((ccr1 & (CCR1_USE_SMI | CCR1_SM3)) == + (CCR1_USE_SMI | CCR1_SM3)) && + ((ccr1 & CCR1_SMAC) || in_smm) && + (cyrix.arr[3].size > 0) && + (CPL == 0); + + if (ins_check) { fetch_ea_32(fetchdat); SEG_CHECK_WRITE(cpu_state.ea_seg); cyrix_write_seg_descriptor(easeg + cpu_state.eaaddr, &tr); @@ -212,32 +289,72 @@ opRSTS_a32(uint32_t fetchdat) } static int -opSMINT(uint32_t fetchdat) +opSMINT(UNUSED(uint32_t fetchdat)) { + uint8_t ccr1_check = ((ccr1 & (CCR1_USE_SMI | CCR1_SMAC | CCR1_SM3)) == + (CCR1_USE_SMI | CCR1_SMAC | CCR1_SM3)) && + (cyrix.arr[3].size > 0); + if (in_smm) fatal("opSMINT\n"); - else - x86illegal(); + else if (ccr1_check) { + is_smint = 1; + enter_smm(0); + } return 1; } static int -opRDSHR_a16(uint32_t fetchdat) +opRDSHR_a16(UNUSED(uint32_t fetchdat)) { - if (in_smm) - fatal("opRDSHR_a16\n"); - else + uint8_t ins_check = ((ccr1 & (CCR1_USE_SMI | CCR1_SM3)) == + (CCR1_USE_SMI | CCR1_SM3)) && + ((ccr1 & CCR1_SMAC) || in_smm) && + (cyrix.arr[3].size > 0) && + (CPL == 0); + + if (ins_check) { + fetch_ea_16(fetchdat); + if (cpu_mod == 3) { + cpu_state.regs[cpu_rm].l = cyrix.smhr; + CLOCK_CYCLES(timing_rr); + PREFETCH_RUN(timing_rr, 2, rmdat, 0, 0, 0, 0, 0); + } else { + SEG_CHECK_WRITE(cpu_state.ea_seg); + seteal(cyrix.smhr); + CLOCK_CYCLES(is486 ? 1 : 2); + PREFETCH_RUN(2, 2, rmdat, 0, 0, 0, 1, 0); + } + return cpu_state.abrt; + } else x86illegal(); return 1; } static int -opRDSHR_a32(uint32_t fetchdat) +opRDSHR_a32(UNUSED(uint32_t fetchdat)) { - if (in_smm) - fatal("opRDSHR_a32\n"); - else + uint8_t ins_check = ((ccr1 & (CCR1_USE_SMI | CCR1_SM3)) == + (CCR1_USE_SMI | CCR1_SM3)) && + ((ccr1 & CCR1_SMAC) || in_smm) && + (cyrix.arr[3].size > 0) && + (CPL == 0); + + if (ins_check) { + fetch_ea_32(fetchdat); + if (cpu_mod == 3) { + cpu_state.regs[cpu_rm].l = cyrix.smhr; + CLOCK_CYCLES(timing_rr); + PREFETCH_RUN(timing_rr, 2, rmdat, 0, 0, 0, 0, 1); + } else { + SEG_CHECK_WRITE(cpu_state.ea_seg); + seteal(cyrix.smhr); + CLOCK_CYCLES(is486 ? 1 : 2); + PREFETCH_RUN(2, 2, rmdat, 0, 0, 0, 1, 1); + } + return cpu_state.abrt; + } else x86illegal(); return 1; @@ -246,9 +363,31 @@ opRDSHR_a32(uint32_t fetchdat) static int opWRSHR_a16(uint32_t fetchdat) { - if (in_smm) - fatal("opWRSHR_a16\n"); - else + uint8_t ins_check = ((ccr1 & (CCR1_USE_SMI | CCR1_SM3)) == + (CCR1_USE_SMI | CCR1_SM3)) && + ((ccr1 & CCR1_SMAC) || in_smm) && + (cyrix.arr[3].size > 0) && + (CPL == 0); + + if (ins_check) { + fetch_ea_16(fetchdat); + if (cpu_mod == 3) { + cyrix.smhr = cpu_state.regs[cpu_rm].l; + CLOCK_CYCLES(timing_rr); + PREFETCH_RUN(timing_rr, 2, rmdat, 0, 0, 0, 0, 0); + } else { + uint32_t temp; + SEG_CHECK_READ(cpu_state.ea_seg); + CHECK_READ(cpu_state.ea_seg, cpu_state.eaaddr, cpu_state.eaaddr + 3); + temp = geteal(); + if (cpu_state.abrt) + return 1; + cyrix.smhr = temp; + CLOCK_CYCLES(is486 ? 1 : 4); + PREFETCH_RUN(4, 2, rmdat, 0, 1, 0, 0, 0); + } + return 0; + } else x86illegal(); return 1; @@ -256,9 +395,31 @@ opWRSHR_a16(uint32_t fetchdat) static int opWRSHR_a32(uint32_t fetchdat) { - if (in_smm) - fatal("opWRSHR_a32\n"); - else + uint8_t ins_check = ((ccr1 & (CCR1_USE_SMI | CCR1_SM3)) == + (CCR1_USE_SMI | CCR1_SM3)) && + ((ccr1 & CCR1_SMAC) || in_smm) && + (cyrix.arr[3].size > 0) && + (CPL == 0); + + if (ins_check) { + fetch_ea_32(fetchdat); + if (cpu_mod == 3) { + cyrix.smhr = cpu_state.regs[cpu_rm].l; + CLOCK_CYCLES(timing_rr); + PREFETCH_RUN(timing_rr, 2, rmdat, 0, 0, 0, 0, 1); + } else { + uint32_t temp; + SEG_CHECK_READ(cpu_state.ea_seg); + CHECK_READ(cpu_state.ea_seg, cpu_state.eaaddr, cpu_state.eaaddr + 3); + temp = geteal(); + if (cpu_state.abrt) + return 1; + cyrix.smhr = temp; + CLOCK_CYCLES(is486 ? 1 : 4); + PREFETCH_RUN(4, 2, rmdat, 0, 1, 0, 0, 1); + } + return 0; + } else x86illegal(); return 1; diff --git a/src/cpu/x86_ops_flag.h b/src/cpu/x86_ops_flag.h index 019472aa0..7e7324341 100644 --- a/src/cpu/x86_ops_flag.h +++ b/src/cpu/x86_ops_flag.h @@ -1,5 +1,5 @@ static int -opCMC(uint32_t fetchdat) +opCMC(UNUSED(uint32_t fetchdat)) { flags_rebuild(); cpu_state.flags ^= C_FLAG; @@ -9,7 +9,7 @@ opCMC(uint32_t fetchdat) } static int -opCLC(uint32_t fetchdat) +opCLC(UNUSED(uint32_t fetchdat)) { flags_rebuild(); cpu_state.flags &= ~C_FLAG; @@ -18,7 +18,7 @@ opCLC(uint32_t fetchdat) return 0; } static int -opCLD(uint32_t fetchdat) +opCLD(UNUSED(uint32_t fetchdat)) { cpu_state.flags &= ~D_FLAG; CLOCK_CYCLES(2); @@ -26,7 +26,7 @@ opCLD(uint32_t fetchdat) return 0; } static int -opCLI(uint32_t fetchdat) +opCLI(UNUSED(uint32_t fetchdat)) { if (!IOPLp) { if ((!(cpu_state.eflags & VM_FLAG) && (cr4 & CR4_PVI)) || ((cpu_state.eflags & VM_FLAG) && (cr4 & CR4_VME))) { @@ -44,7 +44,7 @@ opCLI(uint32_t fetchdat) } static int -opSTC(uint32_t fetchdat) +opSTC(UNUSED(uint32_t fetchdat)) { flags_rebuild(); cpu_state.flags |= C_FLAG; @@ -53,7 +53,7 @@ opSTC(uint32_t fetchdat) return 0; } static int -opSTD(uint32_t fetchdat) +opSTD(UNUSED(uint32_t fetchdat)) { cpu_state.flags |= D_FLAG; CLOCK_CYCLES(2); @@ -61,7 +61,7 @@ opSTD(uint32_t fetchdat) return 0; } static int -opSTI(uint32_t fetchdat) +opSTI(UNUSED(uint32_t fetchdat)) { if (!IOPLp) { if ((!(cpu_state.eflags & VM_FLAG) && (cr4 & CR4_PVI)) || ((cpu_state.eflags & VM_FLAG) && (cr4 & CR4_VME))) { @@ -87,7 +87,7 @@ opSTI(uint32_t fetchdat) } static int -opSAHF(uint32_t fetchdat) +opSAHF(UNUSED(uint32_t fetchdat)) { flags_rebuild(); cpu_state.flags = (cpu_state.flags & 0xff00) | (AH & 0xd5) | 2; @@ -101,7 +101,7 @@ opSAHF(uint32_t fetchdat) return 0; } static int -opLAHF(uint32_t fetchdat) +opLAHF(UNUSED(uint32_t fetchdat)) { flags_rebuild(); AH = cpu_state.flags & 0xff; @@ -111,7 +111,7 @@ opLAHF(uint32_t fetchdat) } static int -opPUSHF(uint32_t fetchdat) +opPUSHF(UNUSED(uint32_t fetchdat)) { if ((cpu_state.eflags & VM_FLAG) && (IOPL < 3)) { if (cr4 & CR4_VME) { @@ -121,6 +121,7 @@ opPUSHF(uint32_t fetchdat) temp = (cpu_state.flags & ~I_FLAG) | 0x3000; if (cpu_state.eflags & VIF_FLAG) temp |= I_FLAG; + temp = (temp & 0x7fd5) | 2; PUSH_W(temp); } else { x86gpf(NULL, 0); @@ -128,6 +129,7 @@ opPUSHF(uint32_t fetchdat) } } else { flags_rebuild(); + cpu_state.flags = (cpu_state.flags & 0x7fd5) | 2; PUSH_W(cpu_state.flags); } CLOCK_CYCLES(4); @@ -135,7 +137,7 @@ opPUSHF(uint32_t fetchdat) return cpu_state.abrt; } static int -opPUSHFD(uint32_t fetchdat) +opPUSHFD(UNUSED(uint32_t fetchdat)) { uint16_t tempw; if ((cpu_state.eflags & VM_FLAG) && (IOPL < 3)) { @@ -149,6 +151,7 @@ opPUSHFD(uint32_t fetchdat) else tempw = cpu_state.eflags & 4; flags_rebuild(); + cpu_state.flags = (cpu_state.flags & 0x7fd5) | 2; PUSH_L(cpu_state.flags | (tempw << 16)); CLOCK_CYCLES(4); PREFETCH_RUN(4, 1, -1, 0, 0, 0, 1, 0); @@ -156,7 +159,31 @@ opPUSHFD(uint32_t fetchdat) } static int -opPOPF_186(uint32_t fetchdat) +opPOPF_186(UNUSED(uint32_t fetchdat)) +{ + uint16_t tempw; + + tempw = POP_W(); + if (cpu_state.abrt) + return 1; + + cpu_state.flags = (cpu_state.flags & 0x7000) | (tempw & 0x0fd5) | 2; + flags_extract(); +#ifdef USE_DEBUG_REGS_486 + rf_flag_no_clear = 1; +#endif + + CLOCK_CYCLES(5); + PREFETCH_RUN(5, 1, -1, 1, 0, 0, 0, 0); + +#if (defined(USE_DYNAREC) && defined(USE_NEW_DYNAREC)) + codegen_flags_changed = 0; +#endif + + return 0; +} +static int +opPOPF_286(UNUSED(uint32_t fetchdat)) { uint16_t tempw; @@ -192,43 +219,7 @@ opPOPF_186(uint32_t fetchdat) return 0; } static int -opPOPF_286(uint32_t fetchdat) -{ - uint16_t tempw; - - if ((cpu_state.eflags & VM_FLAG) && (IOPL < 3)) { - x86gpf(NULL, 0); - return 1; - } - - tempw = POP_W(); - if (cpu_state.abrt) - return 1; - - if (!(msw & 1)) - cpu_state.flags = (cpu_state.flags & 0x7000) | (tempw & 0x0fd5) | 2; - else if (!(CPL)) - cpu_state.flags = (tempw & 0x7fd5) | 2; - else if (IOPLp) - cpu_state.flags = (cpu_state.flags & 0x3000) | (tempw & 0x4fd5) | 2; - else - cpu_state.flags = (cpu_state.flags & 0x3200) | (tempw & 0x4dd5) | 2; - flags_extract(); -#ifdef USE_DEBUG_REGS_486 - rf_flag_no_clear = 1; -#endif - - CLOCK_CYCLES(5); - PREFETCH_RUN(5, 1, -1, 1, 0, 0, 0, 0); - -#if (defined(USE_DYNAREC) && defined(USE_NEW_DYNAREC)) - codegen_flags_changed = 0; -#endif - - return 0; -} -static int -opPOPF(uint32_t fetchdat) +opPOPF(UNUSED(uint32_t fetchdat)) { uint16_t tempw; @@ -284,7 +275,7 @@ opPOPF(uint32_t fetchdat) return 0; } static int -opPOPFD(uint32_t fetchdat) +opPOPFD(UNUSED(uint32_t fetchdat)) { uint32_t templ; diff --git a/src/cpu/x86_ops_flag_2386.h b/src/cpu/x86_ops_flag_2386.h index ba34ae5e7..787b268dc 100644 --- a/src/cpu/x86_ops_flag_2386.h +++ b/src/cpu/x86_ops_flag_2386.h @@ -1,5 +1,5 @@ static int -opCMC(uint32_t fetchdat) +opCMC(UNUSED(uint32_t fetchdat)) { flags_rebuild(); cpu_state.flags ^= C_FLAG; @@ -9,7 +9,7 @@ opCMC(uint32_t fetchdat) } static int -opCLC(uint32_t fetchdat) +opCLC(UNUSED(uint32_t fetchdat)) { flags_rebuild(); cpu_state.flags &= ~C_FLAG; @@ -18,7 +18,7 @@ opCLC(uint32_t fetchdat) return 0; } static int -opCLD(uint32_t fetchdat) +opCLD(UNUSED(uint32_t fetchdat)) { cpu_state.flags &= ~D_FLAG; CLOCK_CYCLES(2); @@ -26,7 +26,7 @@ opCLD(uint32_t fetchdat) return 0; } static int -opCLI(uint32_t fetchdat) +opCLI(UNUSED(uint32_t fetchdat)) { if (!IOPLp) { if ((!(cpu_state.eflags & VM_FLAG) && (cr4 & CR4_PVI)) || ((cpu_state.eflags & VM_FLAG) && (cr4 & CR4_VME))) { @@ -44,7 +44,7 @@ opCLI(uint32_t fetchdat) } static int -opSTC(uint32_t fetchdat) +opSTC(UNUSED(uint32_t fetchdat)) { flags_rebuild(); cpu_state.flags |= C_FLAG; @@ -53,7 +53,7 @@ opSTC(uint32_t fetchdat) return 0; } static int -opSTD(uint32_t fetchdat) +opSTD(UNUSED(uint32_t fetchdat)) { cpu_state.flags |= D_FLAG; CLOCK_CYCLES(2); @@ -61,7 +61,7 @@ opSTD(uint32_t fetchdat) return 0; } static int -opSTI(uint32_t fetchdat) +opSTI(UNUSED(uint32_t fetchdat)) { if (!IOPLp) { if ((!(cpu_state.eflags & VM_FLAG) && (cr4 & CR4_PVI)) || ((cpu_state.eflags & VM_FLAG) && (cr4 & CR4_VME))) { @@ -87,7 +87,7 @@ opSTI(uint32_t fetchdat) } static int -opSAHF(uint32_t fetchdat) +opSAHF(UNUSED(uint32_t fetchdat)) { flags_rebuild(); cpu_state.flags = (cpu_state.flags & 0xff00) | (AH & 0xd5) | 2; @@ -101,7 +101,7 @@ opSAHF(uint32_t fetchdat) return 0; } static int -opLAHF(uint32_t fetchdat) +opLAHF(UNUSED(uint32_t fetchdat)) { flags_rebuild(); AH = cpu_state.flags & 0xff; @@ -111,7 +111,7 @@ opLAHF(uint32_t fetchdat) } static int -opPUSHF(uint32_t fetchdat) +opPUSHF(UNUSED(uint32_t fetchdat)) { if ((cpu_state.eflags & VM_FLAG) && (IOPL < 3)) { if (cr4 & CR4_VME) { @@ -121,6 +121,7 @@ opPUSHF(uint32_t fetchdat) temp = (cpu_state.flags & ~I_FLAG) | 0x3000; if (cpu_state.eflags & VIF_FLAG) temp |= I_FLAG; + temp = (temp & 0x7fd5) | 2; PUSH_W(temp); } else { x86gpf(NULL, 0); @@ -128,6 +129,7 @@ opPUSHF(uint32_t fetchdat) } } else { flags_rebuild(); + cpu_state.flags = (cpu_state.flags & 0x7fd5) | 2; PUSH_W(cpu_state.flags); } CLOCK_CYCLES(4); @@ -135,7 +137,7 @@ opPUSHF(uint32_t fetchdat) return cpu_state.abrt; } static int -opPUSHFD(uint32_t fetchdat) +opPUSHFD(UNUSED(uint32_t fetchdat)) { uint16_t tempw; if ((cpu_state.eflags & VM_FLAG) && (IOPL < 3)) { @@ -149,6 +151,7 @@ opPUSHFD(uint32_t fetchdat) else tempw = cpu_state.eflags & 4; flags_rebuild(); + cpu_state.flags = (cpu_state.flags & 0x7fd5) | 2; PUSH_L(cpu_state.flags | (tempw << 16)); CLOCK_CYCLES(4); PREFETCH_RUN(4, 1, -1, 0, 0, 0, 1, 0); @@ -156,7 +159,29 @@ opPUSHFD(uint32_t fetchdat) } static int -opPOPF_186(uint32_t fetchdat) +opPOPF_186(UNUSED(uint32_t fetchdat)) +{ + uint16_t tempw; + + tempw = POP_W(); + if (cpu_state.abrt) + return 1; + + cpu_state.flags = (cpu_state.flags & 0x7000) | (tempw & 0x0fd5) | 2; + flags_extract(); + rf_flag_no_clear = 1; + + CLOCK_CYCLES(5); + PREFETCH_RUN(5, 1, -1, 1, 0, 0, 0, 0); + +#if (defined(USE_DYNAREC) && defined(USE_NEW_DYNAREC)) + codegen_flags_changed = 0; +#endif + + return 0; +} +static int +opPOPF_286(UNUSED(uint32_t fetchdat)) { uint16_t tempw; @@ -190,41 +215,7 @@ opPOPF_186(uint32_t fetchdat) return 0; } static int -opPOPF_286(uint32_t fetchdat) -{ - uint16_t tempw; - - if ((cpu_state.eflags & VM_FLAG) && (IOPL < 3)) { - x86gpf(NULL, 0); - return 1; - } - - tempw = POP_W(); - if (cpu_state.abrt) - return 1; - - if (!(msw & 1)) - cpu_state.flags = (cpu_state.flags & 0x7000) | (tempw & 0x0fd5) | 2; - else if (!(CPL)) - cpu_state.flags = (tempw & 0x7fd5) | 2; - else if (IOPLp) - cpu_state.flags = (cpu_state.flags & 0x3000) | (tempw & 0x4fd5) | 2; - else - cpu_state.flags = (cpu_state.flags & 0x3200) | (tempw & 0x4dd5) | 2; - flags_extract(); - rf_flag_no_clear = 1; - - CLOCK_CYCLES(5); - PREFETCH_RUN(5, 1, -1, 1, 0, 0, 0, 0); - -#if (defined(USE_DYNAREC) && defined(USE_NEW_DYNAREC)) - codegen_flags_changed = 0; -#endif - - return 0; -} -static int -opPOPF(uint32_t fetchdat) +opPOPF(UNUSED(uint32_t fetchdat)) { uint16_t tempw; @@ -278,7 +269,7 @@ opPOPF(uint32_t fetchdat) return 0; } static int -opPOPFD(uint32_t fetchdat) +opPOPFD(UNUSED(uint32_t fetchdat)) { uint32_t templ; diff --git a/src/cpu/x86_ops_fpu.h b/src/cpu/x86_ops_fpu.h index 11f603c19..afc79dd42 100644 --- a/src/cpu/x86_ops_fpu.h +++ b/src/cpu/x86_ops_fpu.h @@ -4,93 +4,109 @@ static int opESCAPE_d8_a16(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_opcodes_d8_a16[(fetchdat >> 3) & 0x1f](fetchdat); } static int opESCAPE_d8_a32(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_opcodes_d8_a32[(fetchdat >> 3) & 0x1f](fetchdat); } static int opESCAPE_d9_a16(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_opcodes_d9_a16[fetchdat & 0xff](fetchdat); } static int opESCAPE_d9_a32(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_opcodes_d9_a32[fetchdat & 0xff](fetchdat); } static int opESCAPE_da_a16(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_opcodes_da_a16[fetchdat & 0xff](fetchdat); } static int opESCAPE_da_a32(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_opcodes_da_a32[fetchdat & 0xff](fetchdat); } static int opESCAPE_db_a16(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_opcodes_db_a16[fetchdat & 0xff](fetchdat); } static int opESCAPE_db_a32(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_opcodes_db_a32[fetchdat & 0xff](fetchdat); } static int opESCAPE_dc_a16(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_opcodes_dc_a16[(fetchdat >> 3) & 0x1f](fetchdat); } static int opESCAPE_dc_a32(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_opcodes_dc_a32[(fetchdat >> 3) & 0x1f](fetchdat); } static int opESCAPE_dd_a16(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_opcodes_dd_a16[fetchdat & 0xff](fetchdat); } static int opESCAPE_dd_a32(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_opcodes_dd_a32[fetchdat & 0xff](fetchdat); } static int opESCAPE_de_a16(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_opcodes_de_a16[fetchdat & 0xff](fetchdat); } static int opESCAPE_de_a32(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_opcodes_de_a32[fetchdat & 0xff](fetchdat); } static int opESCAPE_df_a16(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_opcodes_df_a16[fetchdat & 0xff](fetchdat); } static int opESCAPE_df_a32(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_opcodes_df_a32[fetchdat & 0xff](fetchdat); } static int -opWAIT(uint32_t fetchdat) +opWAIT(UNUSED(uint32_t fetchdat)) { if ((cr0 & 0xa) == 0xa) { x86_int(7); @@ -99,8 +115,8 @@ opWAIT(uint32_t fetchdat) if (fpu_softfloat) { if (fpu_state.swd & FPU_SW_Summary) { - if (is486 && (cr0 & 0x20)) - x86_int(16); + if (cr0 & 0x20) + new_ne = 1; else picint(1 << 13); return 1; diff --git a/src/cpu/x86_ops_fpu_2386.h b/src/cpu/x86_ops_fpu_2386.h index d8996d2e1..7488a3d85 100644 --- a/src/cpu/x86_ops_fpu_2386.h +++ b/src/cpu/x86_ops_fpu_2386.h @@ -4,93 +4,109 @@ static int opESCAPE_d8_a16(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_2386_opcodes_d8_a16[(fetchdat >> 3) & 0x1f](fetchdat); } static int opESCAPE_d8_a32(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_2386_opcodes_d8_a32[(fetchdat >> 3) & 0x1f](fetchdat); } static int opESCAPE_d9_a16(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_2386_opcodes_d9_a16[fetchdat & 0xff](fetchdat); } static int opESCAPE_d9_a32(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_2386_opcodes_d9_a32[fetchdat & 0xff](fetchdat); } static int opESCAPE_da_a16(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_2386_opcodes_da_a16[fetchdat & 0xff](fetchdat); } static int opESCAPE_da_a32(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_2386_opcodes_da_a32[fetchdat & 0xff](fetchdat); } static int opESCAPE_db_a16(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_2386_opcodes_db_a16[fetchdat & 0xff](fetchdat); } static int opESCAPE_db_a32(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_2386_opcodes_db_a32[fetchdat & 0xff](fetchdat); } static int opESCAPE_dc_a16(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_2386_opcodes_dc_a16[(fetchdat >> 3) & 0x1f](fetchdat); } static int opESCAPE_dc_a32(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_2386_opcodes_dc_a32[(fetchdat >> 3) & 0x1f](fetchdat); } static int opESCAPE_dd_a16(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_2386_opcodes_dd_a16[fetchdat & 0xff](fetchdat); } static int opESCAPE_dd_a32(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_2386_opcodes_dd_a32[fetchdat & 0xff](fetchdat); } static int opESCAPE_de_a16(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_2386_opcodes_de_a16[fetchdat & 0xff](fetchdat); } static int opESCAPE_de_a32(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_2386_opcodes_de_a32[fetchdat & 0xff](fetchdat); } static int opESCAPE_df_a16(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_2386_opcodes_df_a16[fetchdat & 0xff](fetchdat); } static int opESCAPE_df_a32(uint32_t fetchdat) { + x87_op = ((opcode & 0x07) << 8) | (fetchdat & 0xff); return x86_2386_opcodes_df_a32[fetchdat & 0xff](fetchdat); } static int -opWAIT(uint32_t fetchdat) +opWAIT(UNUSED(uint32_t fetchdat)) { if ((cr0 & 0xa) == 0xa) { x86_int(7); @@ -99,7 +115,10 @@ opWAIT(uint32_t fetchdat) if (fpu_softfloat) { if (fpu_state.swd & FPU_SW_Summary) { - picint(1 << 13); + if (cr0 & 0x20) + new_ne = 1; + else + picint(1 << 13); return 1; } } diff --git a/src/cpu/x86_ops_i686.h b/src/cpu/x86_ops_i686.h index 5e5dc3c7c..0809fac74 100644 --- a/src/cpu/x86_ops_i686.h +++ b/src/cpu/x86_ops_i686.h @@ -18,12 +18,8 @@ opSYSENTER(uint32_t fetchdat) { int ret = sysenter(fetchdat); - if (ret <= 1) { - CLOCK_CYCLES(20); - PREFETCH_RUN(20, 7, -1, 0, 0, 0, 0, 0); - PREFETCH_FLUSH(); + if (ret <= 1) CPU_BLOCK_END(); - } return ret; } @@ -33,12 +29,8 @@ opSYSEXIT(uint32_t fetchdat) { int ret = sysexit(fetchdat); - if (ret <= 1) { - CLOCK_CYCLES(20); - PREFETCH_RUN(20, 7, -1, 0, 0, 0, 0, 0); - PREFETCH_FLUSH(); + if (ret <= 1) CPU_BLOCK_END(); - } return ret; } @@ -54,8 +46,6 @@ sf_fx_save_stor_common(uint32_t fetchdat, int bits) if (CPUID < 0x650) return ILLEGAL(fetchdat); - FP_ENTER(); - if (bits == 32) { fetch_ea_32(fetchdat); } else { @@ -90,12 +80,18 @@ sf_fx_save_stor_common(uint32_t fetchdat, int bits) /* 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); + if (bits == 32) + fpu_state.fip = readmeml(easeg, cpu_state.eaaddr + 8); + else + fpu_state.fip = readmemw(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); + if (bits == 32) + fpu_state.fdp = readmeml(easeg, cpu_state.eaaddr + 16); + else + fpu_state.fdp = readmemw(easeg, cpu_state.eaaddr + 16); fpu_state.fds = readmemw(easeg, cpu_state.eaaddr + 20); /* load i387 register file */ @@ -118,7 +114,7 @@ sf_fx_save_stor_common(uint32_t fetchdat, int bits) fpu_state.swd &= ~(FPU_SW_Summary | FPU_SW_Backward); } - CLOCK_CYCLES((cr0 & 1) ? 34 : 44); + CLOCK_CYCLES(1); } else { /* FXSAVE */ writememw(easeg, cpu_state.eaaddr, i387_get_control_word()); @@ -139,7 +135,10 @@ sf_fx_save_stor_common(uint32_t fetchdat, int bits) * x87 CS FPU IP Selector * + 16 bit, in 16/32 bit mode only */ - writememl(easeg, cpu_state.eaaddr + 8, fpu_state.fip); + if (bits == 32) + writememl(easeg, cpu_state.eaaddr + 8, fpu_state.fip); + else + writememl(easeg, cpu_state.eaaddr + 8, fpu_state.fip & 0xffff); writememl(easeg, cpu_state.eaaddr + 12, fpu_state.fcs); /* @@ -152,7 +151,10 @@ sf_fx_save_stor_common(uint32_t fetchdat, int bits) * 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); + if (bits == 32) + writememl(easeg, cpu_state.eaaddr + 16, fpu_state.fdp); + else + writememl(easeg, cpu_state.eaaddr + 16, fpu_state.fdp & 0xffff); writememl(easeg, cpu_state.eaaddr + 20, fpu_state.fds); /* store i387 register file */ @@ -163,7 +165,7 @@ sf_fx_save_stor_common(uint32_t fetchdat, int bits) writememw(easeg, cpu_state.eaaddr + (index * 16) + 40, fp.signExp); } - CLOCK_CYCLES((cr0 & 1) ? 56 : 67); + CLOCK_CYCLES(1); } return cpu_state.abrt; @@ -263,8 +265,6 @@ fx_save_stor_common(uint32_t fetchdat, int bits) return cpu_state.abrt; } - FP_ENTER(); - old_eaaddr = cpu_state.eaaddr; if (fxinst == 1) { @@ -276,13 +276,19 @@ fx_save_stor_common(uint32_t fetchdat, int bits) cpu_state.TOP = (fpus >> 11) & 7; cpu_state.npxs &= fpus & ~0x3800; - x87_pc_off = readmeml(easeg, cpu_state.eaaddr + 8); + if (bits == 32) + x87_pc_off = readmeml(easeg, cpu_state.eaaddr + 8); + else + x87_pc_off = readmemw(easeg, cpu_state.eaaddr + 8); x87_pc_seg = readmemw(easeg, cpu_state.eaaddr + 12); ftwb = readmemb(easeg, cpu_state.eaaddr + 4); + x87_op = readmemw(easeg, cpu_state.eaaddr + 6) & 0x07ff; - x87_op_off = readmeml(easeg, cpu_state.eaaddr + 16); - x87_op_off |= (readmemw(easeg, cpu_state.eaaddr + 6) >> 12) << 16; + if (bits == 32) + x87_op_off = readmeml(easeg, cpu_state.eaaddr + 16); + else + x87_op_off = readmemw(easeg, cpu_state.eaaddr +16); x87_op_seg = readmemw(easeg, cpu_state.eaaddr + 20); for (i = 0; i <= 7; i++) { @@ -327,7 +333,7 @@ fx_save_stor_common(uint32_t fetchdat, int bits) } } - CLOCK_CYCLES((cr0 & 1) ? 34 : 44); + CLOCK_CYCLES(1); } else { /* FXSAVE */ if ((twd & 0x0003) != 0x0003) @@ -351,11 +357,17 @@ fx_save_stor_common(uint32_t fetchdat, int bits) writememw(easeg, cpu_state.eaaddr + 2, cpu_state.npxs); writememb(easeg, cpu_state.eaaddr + 4, ftwb); - writememw(easeg, cpu_state.eaaddr + 6, (x87_op_off >> 16) << 12); - writememl(easeg, cpu_state.eaaddr + 8, x87_pc_off); + writememw(easeg, cpu_state.eaaddr + 6, x87_op); + if (bits == 32) + writememl(easeg, cpu_state.eaaddr + 8, x87_pc_off); + else + writememl(easeg, cpu_state.eaaddr + 8, x87_pc_off & 0xffff); writememw(easeg, cpu_state.eaaddr + 12, x87_pc_seg); - writememl(easeg, cpu_state.eaaddr + 16, x87_op_off); + if (bits == 32) + writememl(easeg, cpu_state.eaaddr + 16, x87_op_off); + else + writememl(easeg, cpu_state.eaaddr + 16, x87_op_off & 0xffff); writememw(easeg, cpu_state.eaaddr + 20, x87_op_seg); if (cpu_state.ismmx) { @@ -372,7 +384,7 @@ fx_save_stor_common(uint32_t fetchdat, int bits) cpu_state.eaaddr = old_eaaddr; - CLOCK_CYCLES((cr0 & 1) ? 56 : 67); + CLOCK_CYCLES(1); } return cpu_state.abrt; @@ -400,8 +412,7 @@ static int opHINT_NOP_a16(uint32_t fetchdat) { fetch_ea_16(fetchdat); - CLOCK_CYCLES((is486) ? 1 : 3); - PREFETCH_RUN(3, 1, -1, 0, 0, 0, 0, 0); + CLOCK_CYCLES(1); return 0; } @@ -409,7 +420,6 @@ static int opHINT_NOP_a32(uint32_t fetchdat) { fetch_ea_32(fetchdat); - CLOCK_CYCLES((is486) ? 1 : 3); - PREFETCH_RUN(3, 1, -1, 0, 0, 0, 0, 0); + CLOCK_CYCLES(1); return 0; } diff --git a/src/cpu/x86_ops_inc_dec.h b/src/cpu/x86_ops_inc_dec.h index 3eb908c57..b33d02f45 100644 --- a/src/cpu/x86_ops_inc_dec.h +++ b/src/cpu/x86_ops_inc_dec.h @@ -1,5 +1,5 @@ #define INC_DEC_OP(name, reg, inc, setflags) \ - static int op##name(uint32_t fetchdat) \ + static int op##name(UNUSED(uint32_t fetchdat)) \ { \ setflags(reg, 1); \ reg += inc; \ diff --git a/src/cpu/x86_ops_int.h b/src/cpu/x86_ops_int.h index a73ed62e0..1ed5e6c2f 100644 --- a/src/cpu/x86_ops_int.h +++ b/src/cpu/x86_ops_int.h @@ -1,5 +1,5 @@ static int -opINT3(uint32_t fetchdat) +opINT3(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); @@ -18,7 +18,7 @@ opINT3(uint32_t fetchdat) } static int -opINT1(uint32_t fetchdat) +opINT1(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); @@ -75,7 +75,7 @@ opINT(uint32_t fetchdat) } static int -opINTO(uint32_t fetchdat) +opINTO(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); diff --git a/src/cpu/x86_ops_io.h b/src/cpu/x86_ops_io.h index 8a99b8668..36bf05cd3 100644 --- a/src/cpu/x86_ops_io.h +++ b/src/cpu/x86_ops_io.h @@ -75,7 +75,7 @@ opOUT_EAX_imm(uint32_t fetchdat) } static int -opIN_AL_DX(uint32_t fetchdat) +opIN_AL_DX(UNUSED(uint32_t fetchdat)) { check_io_perm(DX, 1); AL = inb(DX); @@ -86,7 +86,7 @@ opIN_AL_DX(uint32_t fetchdat) return 0; } static int -opIN_AX_DX(uint32_t fetchdat) +opIN_AX_DX(UNUSED(uint32_t fetchdat)) { check_io_perm(DX, 2); AX = inw(DX); @@ -97,7 +97,7 @@ opIN_AX_DX(uint32_t fetchdat) return 0; } static int -opIN_EAX_DX(uint32_t fetchdat) +opIN_EAX_DX(UNUSED(uint32_t fetchdat)) { check_io_perm(DX, 4); EAX = inl(DX); @@ -109,7 +109,7 @@ opIN_EAX_DX(uint32_t fetchdat) } static int -opOUT_AL_DX(uint32_t fetchdat) +opOUT_AL_DX(UNUSED(uint32_t fetchdat)) { check_io_perm(DX, 1); outb(DX, AL); @@ -120,7 +120,7 @@ opOUT_AL_DX(uint32_t fetchdat) return x86_was_reset; } static int -opOUT_AX_DX(uint32_t fetchdat) +opOUT_AX_DX(UNUSED(uint32_t fetchdat)) { check_io_perm(DX, 2); outw(DX, AX); @@ -131,7 +131,7 @@ opOUT_AX_DX(uint32_t fetchdat) return 0; } static int -opOUT_EAX_DX(uint32_t fetchdat) +opOUT_EAX_DX(UNUSED(uint32_t fetchdat)) { check_io_perm(DX, 4); outl(DX, EAX); diff --git a/src/cpu/x86_ops_jump.h b/src/cpu/x86_ops_jump.h index 97ca673d7..fc99fc5fd 100644 --- a/src/cpu/x86_ops_jump.h +++ b/src/cpu/x86_ops_jump.h @@ -51,7 +51,7 @@ return 0; \ } \ \ - static int opJ##condition##_l(uint32_t fetchdat) \ + static int opJ##condition##_l(UNUSED(uint32_t fetchdat)) \ { \ uint32_t offset = getlong(); \ if (cpu_state.abrt) \ @@ -256,7 +256,7 @@ opJMP_r16(uint32_t fetchdat) return 0; } static int -opJMP_r32(uint32_t fetchdat) +opJMP_r32(UNUSED(uint32_t fetchdat)) { int32_t offset = (int32_t) getlong(); if (cpu_state.abrt) @@ -289,7 +289,7 @@ opJMP_far_a16(uint32_t fetchdat) return 0; } static int -opJMP_far_a32(uint32_t fetchdat) +opJMP_far_a32(UNUSED(uint32_t fetchdat)) { uint16_t seg; uint32_t addr; @@ -323,7 +323,7 @@ opCALL_r16(uint32_t fetchdat) return 0; } static int -opCALL_r32(uint32_t fetchdat) +opCALL_r32(UNUSED(uint32_t fetchdat)) { int32_t addr = getlong(); @@ -339,7 +339,7 @@ opCALL_r32(uint32_t fetchdat) } static int -opRET_w(uint32_t fetchdat) +opRET_w(UNUSED(uint32_t fetchdat)) { uint16_t ret; @@ -355,7 +355,7 @@ opRET_w(uint32_t fetchdat) return 0; } static int -opRET_l(uint32_t fetchdat) +opRET_l(UNUSED(uint32_t fetchdat)) { uint32_t ret; diff --git a/src/cpu/x86_ops_misc.h b/src/cpu/x86_ops_misc.h index c0b9de437..5ae28abc4 100644 --- a/src/cpu/x86_ops_misc.h +++ b/src/cpu/x86_ops_misc.h @@ -1,5 +1,5 @@ static int -opCBW(uint32_t fetchdat) +opCBW(UNUSED(uint32_t fetchdat)) { AH = (AL & 0x80) ? 0xff : 0; CLOCK_CYCLES(3); @@ -7,7 +7,7 @@ opCBW(uint32_t fetchdat) return 0; } static int -opCWDE(uint32_t fetchdat) +opCWDE(UNUSED(uint32_t fetchdat)) { EAX = (AX & 0x8000) ? (0xffff0000 | AX) : AX; CLOCK_CYCLES(3); @@ -15,7 +15,7 @@ opCWDE(uint32_t fetchdat) return 0; } static int -opCWD(uint32_t fetchdat) +opCWD(UNUSED(uint32_t fetchdat)) { DX = (AX & 0x8000) ? 0xFFFF : 0; CLOCK_CYCLES(2); @@ -23,7 +23,7 @@ opCWD(uint32_t fetchdat) return 0; } static int -opCDQ(uint32_t fetchdat) +opCDQ(UNUSED(uint32_t fetchdat)) { EDX = (EAX & 0x80000000) ? 0xffffffff : 0; CLOCK_CYCLES(2); @@ -32,7 +32,7 @@ opCDQ(uint32_t fetchdat) } static int -opNOP(uint32_t fetchdat) +opNOP(UNUSED(uint32_t fetchdat)) { CLOCK_CYCLES((is486) ? 1 : 3); PREFETCH_RUN(3, 1, -1, 0, 0, 0, 0, 0); @@ -40,7 +40,7 @@ opNOP(uint32_t fetchdat) } static int -opSETALC(uint32_t fetchdat) +opSETALC(UNUSED(uint32_t fetchdat)) { AL = (CF_SET()) ? 0xff : 0; CLOCK_CYCLES(timing_rr); @@ -701,7 +701,7 @@ opF7_l_a32(uint32_t fetchdat) } static int -opHLT(uint32_t fetchdat) +opHLT(UNUSED(uint32_t fetchdat)) { if ((CPL || (cpu_state.eflags & VM_FLAG)) && (cr0 & 1)) { x86gpf(NULL, 0); @@ -753,7 +753,7 @@ opLOCK(uint32_t fetchdat) return 0; cpu_state.pc++; - ILLEGAL_ON((fetchdat & 0xff) == 0x90); + ILLEGAL_ON(((fetchdat & 0xff) == 0x90) || ((fetchdat & 0xff) == 0xec)); CLOCK_CYCLES(4); PREFETCH_PREFIX(); @@ -856,7 +856,7 @@ opBOUND_l_a32(uint32_t fetchdat) } static int -opCLTS(uint32_t fetchdat) +opCLTS(UNUSED(uint32_t fetchdat)) { if ((CPL || (cpu_state.eflags & VM_FLAG)) && (cr0 & 1)) { x86gpf(NULL, 0); @@ -869,14 +869,14 @@ opCLTS(uint32_t fetchdat) } static int -opINVD(uint32_t fetchdat) +opINVD(UNUSED(uint32_t fetchdat)) { CLOCK_CYCLES(1000); CPU_BLOCK_END(); return 0; } static int -opWBINVD(uint32_t fetchdat) +opWBINVD(UNUSED(uint32_t fetchdat)) { if ((CPL || (cpu_state.eflags & VM_FLAG)) && (cr0 & 1)) { x86gpf(NULL, 0); @@ -888,7 +888,7 @@ opWBINVD(uint32_t fetchdat) } static int -opLOADALL(uint32_t fetchdat) +opLOADALL(UNUSED(uint32_t fetchdat)) { if (CPL && (cr0 & 1)) { x86gpf(NULL, 0); @@ -998,7 +998,7 @@ loadall_load_segment(uint32_t addr, x86seg *s) } static int -opLOADALL386(uint32_t fetchdat) +opLOADALL386(UNUSED(uint32_t fetchdat)) { uint32_t la_addr = es + EDI; @@ -1046,7 +1046,7 @@ opLOADALL386(uint32_t fetchdat) } static int -opCPUID(uint32_t fetchdat) +opCPUID(UNUSED(uint32_t fetchdat)) { if (CPUID) { cpu_CPUID(); @@ -1059,7 +1059,7 @@ opCPUID(uint32_t fetchdat) } static int -opRDMSR(uint32_t fetchdat) +opRDMSR(UNUSED(uint32_t fetchdat)) { if (cpu_has_feature(CPU_FEATURE_MSR)) { cpu_RDMSR(); @@ -1072,7 +1072,7 @@ opRDMSR(uint32_t fetchdat) } static int -opWRMSR(uint32_t fetchdat) +opWRMSR(UNUSED(uint32_t fetchdat)) { if (cpu_has_feature(CPU_FEATURE_MSR)) { cpu_WRMSR(); @@ -1085,7 +1085,7 @@ opWRMSR(uint32_t fetchdat) } static int -opRSM(uint32_t fetchdat) +opRSM(UNUSED(uint32_t fetchdat)) { if (in_smm) { leave_smm(); diff --git a/src/cpu/x86_ops_mmx.h b/src/cpu/x86_ops_mmx.h index ab5e19762..9a2d797a8 100644 --- a/src/cpu/x86_ops_mmx.h +++ b/src/cpu/x86_ops_mmx.h @@ -22,19 +22,19 @@ } #define MMX_ENTER() \ - if (!cpu_has_feature(CPU_FEATURE_MMX)) { \ + if (!cpu_has_feature(CPU_FEATURE_MMX) || (cr0 & 0x4)) { \ cpu_state.pc = cpu_state.oldpc; \ x86illegal(); \ return 1; \ } \ - if (cr0 & 0xc) { \ + if (cr0 & 0x8) { \ x86_int(7); \ return 1; \ } \ x87_set_mmx() static int -opEMMS(uint32_t fetchdat) +opEMMS(UNUSED(uint32_t fetchdat)) { if (!cpu_has_feature(CPU_FEATURE_MMX)) { cpu_state.pc = cpu_state.oldpc; diff --git a/src/cpu/x86_ops_mmx_emmi.h b/src/cpu/x86_ops_mmx_emmi.h new file mode 100644 index 000000000..4c994be0f --- /dev/null +++ b/src/cpu/x86_ops_mmx_emmi.h @@ -0,0 +1,807 @@ +/* Notes: "src2" means "first operand" */ + +static int +opPMULHRWC_a16(UNUSED(uint32_t fetchdat)) +{ + MMX_REG src; + MMX_REG *dst; + + if (!(ccr7 & 1)) { + x86illegal(); + return 1; + } + + MMX_ENTER(); + + fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + + MMX_GETSRC(); + + dst->w[0] = ((int32_t) (dst->sw[0] * (int32_t) src.sw[0]) + 0x4000) >> 15; + dst->w[1] = ((int32_t) (dst->sw[1] * (int32_t) src.sw[1]) + 0x4000) >> 15; + dst->w[2] = ((int32_t) (dst->sw[2] * (int32_t) src.sw[2]) + 0x4000) >> 15; + dst->w[3] = ((int32_t) (dst->sw[3] * (int32_t) src.sw[3]) + 0x4000) >> 15; + + MMX_SETEXP(cpu_reg); + + return 0; +} + +static int +opPMULHRWC_a32(UNUSED(uint32_t fetchdat)) +{ + MMX_REG src; + MMX_REG *dst; + + if (!(ccr7 & 1)) { + x86illegal(); + return 1; + } + + MMX_ENTER(); + + fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + + MMX_GETSRC(); + + dst->w[0] = ((int32_t) (dst->sw[0] * (int32_t) src.sw[0]) + 0x4000) >> 15; + dst->w[1] = ((int32_t) (dst->sw[1] * (int32_t) src.sw[1]) + 0x4000) >> 15; + dst->w[2] = ((int32_t) (dst->sw[2] * (int32_t) src.sw[2]) + 0x4000) >> 15; + dst->w[3] = ((int32_t) (dst->sw[3] * (int32_t) src.sw[3]) + 0x4000) >> 15; + + MMX_SETEXP(cpu_reg); + + return 0; +} + +static int +opPMULHRIW_a16(uint32_t fetchdat) +{ + MMX_REG src, src2; + MMX_REG *dst; + + if (!(ccr7 & 1)) { + x86illegal(); + return 1; + } + + MMX_ENTER(); + + fetch_ea_16(fetchdat); + + src2 = MMX_GETREG(cpu_reg); + dst = MMX_GETREGP(cpu_reg ^ 1); + + MMX_GETSRC(); + + dst->w[0] = (((int32_t) src2.sw[0] * (int32_t) src.sw[0]) + 0x4000) >> 15; + dst->w[1] = (((int32_t) src2.sw[1] * (int32_t) src.sw[1]) + 0x4000) >> 15; + dst->w[2] = (((int32_t) src2.sw[2] * (int32_t) src.sw[2]) + 0x4000) >> 15; + dst->w[3] = (((int32_t) src2.sw[3] * (int32_t) src.sw[3]) + 0x4000) >> 15; + + MMX_SETEXP(cpu_reg ^ 1); + return 0; +} + +static int +opPMULHRIW_a32(uint32_t fetchdat) +{ + MMX_REG src, src2; + MMX_REG *dst; + + if (!(ccr7 & 1)) { + x86illegal(); + return 1; + } + + MMX_ENTER(); + + fetch_ea_32(fetchdat); + + src2 = MMX_GETREG(cpu_reg); + dst = MMX_GETREGP(cpu_reg ^ 1); + + MMX_GETSRC(); + + dst->w[0] = (((int32_t) src2.sw[0] * (int32_t) src.sw[0]) + 0x4000) >> 15; + dst->w[1] = (((int32_t) src2.sw[1] * (int32_t) src.sw[1]) + 0x4000) >> 15; + dst->w[2] = (((int32_t) src2.sw[2] * (int32_t) src.sw[2]) + 0x4000) >> 15; + dst->w[3] = (((int32_t) src2.sw[3] * (int32_t) src.sw[3]) + 0x4000) >> 15; + + MMX_SETEXP(cpu_reg ^ 1); + return 0; +} + +static int +opPDISTIB_a16(uint32_t fetchdat) +{ + MMX_REG src, src2; + MMX_REG *dst; + + if (!(ccr7 & 1)) { + x86illegal(); + return 1; + } + + MMX_ENTER(); + + fetch_ea_16(fetchdat); + + if (cpu_mod == 3) { + x86illegal(); + return 1; + } + + src2 = MMX_GETREG(cpu_reg); + dst = MMX_GETREGP(cpu_reg ^ 1); + + MMX_GETSRC(); + + dst->b[0] = USATB(dst->b[0] + abs(src2.b[0] - src.b[0])); + dst->b[1] = USATB(dst->b[1] + abs(src2.b[1] - src.b[1])); + dst->b[2] = USATB(dst->b[2] + abs(src2.b[2] - src.b[2])); + dst->b[3] = USATB(dst->b[3] + abs(src2.b[3] - src.b[3])); + dst->b[4] = USATB(dst->b[4] + abs(src2.b[4] - src.b[4])); + dst->b[5] = USATB(dst->b[5] + abs(src2.b[5] - src.b[5])); + dst->b[6] = USATB(dst->b[6] + abs(src2.b[6] - src.b[6])); + dst->b[7] = USATB(dst->b[7] + abs(src2.b[7] - src.b[7])); + + MMX_SETEXP(cpu_reg ^ 1); + return 0; +} + +static int +opPDISTIB_a32(uint32_t fetchdat) +{ + MMX_REG src, src2; + MMX_REG *dst; + + if (!(ccr7 & 1)) { + x86illegal(); + return 1; + } + + MMX_ENTER(); + + fetch_ea_32(fetchdat); + + if (cpu_mod == 3) { + x86illegal(); + return 1; + } + + src2 = MMX_GETREG(cpu_reg); + dst = MMX_GETREGP(cpu_reg ^ 1); + + MMX_GETSRC(); + + dst->b[0] = USATB(dst->b[0] + abs(src2.b[0] - src.b[0])); + dst->b[1] = USATB(dst->b[1] + abs(src2.b[1] - src.b[1])); + dst->b[2] = USATB(dst->b[2] + abs(src2.b[2] - src.b[2])); + dst->b[3] = USATB(dst->b[3] + abs(src2.b[3] - src.b[3])); + dst->b[4] = USATB(dst->b[4] + abs(src2.b[4] - src.b[4])); + dst->b[5] = USATB(dst->b[5] + abs(src2.b[5] - src.b[5])); + dst->b[6] = USATB(dst->b[6] + abs(src2.b[6] - src.b[6])); + dst->b[7] = USATB(dst->b[7] + abs(src2.b[7] - src.b[7])); + + MMX_SETEXP(cpu_reg ^ 1); + return 0; +} + +static int +opPMACHRIW_a16(uint32_t fetchdat) +{ + MMX_REG src, src2; + MMX_REG *dst; + + if (!(ccr7 & 1)) { + x86illegal(); + return 1; + } + + MMX_ENTER(); + + fetch_ea_16(fetchdat); + + if (cpu_mod == 3) { + x86illegal(); + return 1; + } + + src2 = MMX_GETREG(cpu_reg); + dst = MMX_GETREGP(cpu_reg ^ 1); + + MMX_GETSRC(); + + dst->w[0] += (((int32_t) src2.sw[0] * (int32_t) src.sw[0]) + 0x4000) >> 15; + dst->w[1] += (((int32_t) src2.sw[1] * (int32_t) src.sw[1]) + 0x4000) >> 15; + dst->w[2] += (((int32_t) src2.sw[2] * (int32_t) src.sw[2]) + 0x4000) >> 15; + dst->w[3] += (((int32_t) src2.sw[3] * (int32_t) src.sw[3]) + 0x4000) >> 15; + + MMX_SETEXP(cpu_reg ^ 1); + return 0; +} + +static int +opPMACHRIW_a32(uint32_t fetchdat) +{ + MMX_REG src, src2; + MMX_REG *dst; + + if (!(ccr7 & 1)) { + x86illegal(); + return 1; + } + + MMX_ENTER(); + + fetch_ea_32(fetchdat); + + if (cpu_mod == 3) { + x86illegal(); + return 1; + } + + src2 = MMX_GETREG(cpu_reg); + dst = MMX_GETREGP(cpu_reg ^ 1); + + MMX_GETSRC(); + + dst->w[0] += (((int32_t) src2.sw[0] * (int32_t) src.sw[0]) + 0x4000) >> 15; + dst->w[1] += (((int32_t) src2.sw[1] * (int32_t) src.sw[1]) + 0x4000) >> 15; + dst->w[2] += (((int32_t) src2.sw[2] * (int32_t) src.sw[2]) + 0x4000) >> 15; + dst->w[3] += (((int32_t) src2.sw[3] * (int32_t) src.sw[3]) + 0x4000) >> 15; + + MMX_SETEXP(cpu_reg ^ 1); + return 0; +} + +static int +opPADDSIW_a16(uint32_t fetchdat) +{ + MMX_REG src, src2; + MMX_REG *dst; + + if (!(ccr7 & 1)) { + x86illegal(); + return 1; + } + + MMX_ENTER(); + + fetch_ea_16(fetchdat); + + src2 = MMX_GETREG(cpu_reg); + dst = MMX_GETREGP(cpu_reg ^ 1); + + MMX_GETSRC(); + + dst->sw[0] = SSATW(src2.sw[0] + src.sw[0]); + dst->sw[1] = SSATW(src2.sw[1] + src.sw[1]); + dst->sw[2] = SSATW(src2.sw[2] + src.sw[2]); + dst->sw[3] = SSATW(src2.sw[3] + src.sw[3]); + + MMX_SETEXP(cpu_reg ^ 1); + + return 0; +} + +static int +opPADDSIW_a32(uint32_t fetchdat) +{ + MMX_REG src, src2; + MMX_REG *dst; + + if (!(ccr7 & 1)) { + x86illegal(); + return 1; + } + + MMX_ENTER(); + + fetch_ea_32(fetchdat); + + src2 = MMX_GETREG(cpu_reg); + dst = MMX_GETREGP(cpu_reg ^ 1); + + MMX_GETSRC(); + + dst->sw[0] = SSATW(src2.sw[0] + src.sw[0]); + dst->sw[1] = SSATW(src2.sw[1] + src.sw[1]); + dst->sw[2] = SSATW(src2.sw[2] + src.sw[2]); + dst->sw[3] = SSATW(src2.sw[3] + src.sw[3]); + + MMX_SETEXP(cpu_reg ^ 1); + + return 0; +} + +static int +opPSUBSIW_a16(uint32_t fetchdat) +{ + MMX_REG src, src2; + MMX_REG *dst; + + if (!(ccr7 & 1)) { + x86illegal(); + return 1; + } + + MMX_ENTER(); + + fetch_ea_16(fetchdat); + + src2 = MMX_GETREG(cpu_reg); + dst = MMX_GETREGP(cpu_reg ^ 1); + + MMX_GETSRC(); + + dst->sw[0] = SSATW(src2.sw[0] - src.sw[0]); + dst->sw[1] = SSATW(src2.sw[1] - src.sw[1]); + dst->sw[2] = SSATW(src2.sw[2] - src.sw[2]); + dst->sw[3] = SSATW(src2.sw[3] - src.sw[3]); + + MMX_SETEXP(cpu_reg); + + return 0; +} + +static int +opPSUBSIW_a32(uint32_t fetchdat) +{ + MMX_REG src, src2; + MMX_REG *dst; + + if (!(ccr7 & 1)) { + x86illegal(); + return 1; + } + + MMX_ENTER(); + + fetch_ea_32(fetchdat); + + src2 = MMX_GETREG(cpu_reg); + dst = MMX_GETREGP(cpu_reg ^ 1); + + MMX_GETSRC(); + + dst->sw[0] = SSATW(src2.sw[0] - src.sw[0]); + dst->sw[1] = SSATW(src2.sw[1] - src.sw[1]); + dst->sw[2] = SSATW(src2.sw[2] - src.sw[2]); + dst->sw[3] = SSATW(src2.sw[3] - src.sw[3]); + + MMX_SETEXP(cpu_reg); + + return 0; +} + +static int +opPAVEB_a16(uint32_t fetchdat) +{ + MMX_REG src; + MMX_REG *dst; + + if (!(ccr7 & 1)) { + x86illegal(); + return 1; + } + + MMX_ENTER(); + + fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + + MMX_GETSRC(); + + dst->b[0] = (dst->b[0] + src.b[0]) >> 1; + dst->b[1] = (dst->b[1] + src.b[1]) >> 1; + dst->b[2] = (dst->b[2] + src.b[2]) >> 1; + dst->b[3] = (dst->b[3] + src.b[3]) >> 1; + dst->b[4] = (dst->b[4] + src.b[4]) >> 1; + dst->b[5] = (dst->b[5] + src.b[5]) >> 1; + dst->b[6] = (dst->b[6] + src.b[6]) >> 1; + dst->b[7] = (dst->b[7] + src.b[7]) >> 1; + + MMX_SETEXP(cpu_reg); + return 0; +} + +static int +opPAVEB_a32(uint32_t fetchdat) +{ + MMX_REG src; + MMX_REG *dst; + + if (!(ccr7 & 1)) { + x86illegal(); + return 1; + } + + MMX_ENTER(); + + fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + + MMX_GETSRC(); + + dst->b[0] = (dst->b[0] + src.b[0]) >> 1; + dst->b[1] = (dst->b[1] + src.b[1]) >> 1; + dst->b[2] = (dst->b[2] + src.b[2]) >> 1; + dst->b[3] = (dst->b[3] + src.b[3]) >> 1; + dst->b[4] = (dst->b[4] + src.b[4]) >> 1; + dst->b[5] = (dst->b[5] + src.b[5]) >> 1; + dst->b[6] = (dst->b[6] + src.b[6]) >> 1; + dst->b[7] = (dst->b[7] + src.b[7]) >> 1; + + MMX_SETEXP(cpu_reg); + return 0; +} + +static int +opPMAGW_a16(uint32_t fetchdat) +{ + MMX_REG src; + MMX_REG *dst; + + if (!(ccr7 & 1)) { + x86illegal(); + return 1; + } + + MMX_ENTER(); + + fetch_ea_16(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + + MMX_GETSRC(); + + if (abs(src.sw[0]) > abs(dst->sw[0])) dst->sw[0] = src.sw[0]; + if (abs(src.sw[1]) > abs(dst->sw[1])) dst->sw[1] = src.sw[1]; + if (abs(src.sw[2]) > abs(dst->sw[2])) dst->sw[2] = src.sw[2]; + if (abs(src.sw[3]) > abs(dst->sw[3])) dst->sw[3] = src.sw[3]; + + MMX_SETEXP(cpu_reg); + + return 0; +} + +static int +opPMAGW_a32(uint32_t fetchdat) +{ + MMX_REG src; + MMX_REG *dst; + + if (!(ccr7 & 1)) { + x86illegal(); + return 1; + } + + MMX_ENTER(); + + fetch_ea_32(fetchdat); + + dst = MMX_GETREGP(cpu_reg); + + MMX_GETSRC(); + + if (abs(src.sw[0]) > abs(dst->sw[0])) dst->sw[0] = src.sw[0]; + if (abs(src.sw[1]) > abs(dst->sw[1])) dst->sw[1] = src.sw[1]; + if (abs(src.sw[2]) > abs(dst->sw[2])) dst->sw[2] = src.sw[2]; + if (abs(src.sw[3]) > abs(dst->sw[3])) dst->sw[3] = src.sw[3]; + + MMX_SETEXP(cpu_reg); + + return 0; +} + +static int +opPMVZB_a16(uint32_t fetchdat) +{ + MMX_REG src, src2; + MMX_REG *dst; + + if (!(ccr7 & 1)) { + x86illegal(); + return 1; + } + + MMX_ENTER(); + + fetch_ea_16(fetchdat); + + if (cpu_mod == 3) { + x86illegal(); + return 1; + } + + dst = MMX_GETREGP(cpu_reg); + src2 = MMX_GETREG(cpu_reg ^ 1); + + MMX_GETSRC(); + + if (src2.b[0] == 0) dst->b[0] = src.b[0]; + if (src2.b[1] == 0) dst->b[1] = src.b[1]; + if (src2.b[2] == 0) dst->b[2] = src.b[2]; + if (src2.b[3] == 0) dst->b[3] = src.b[3]; + if (src2.b[4] == 0) dst->b[4] = src.b[4]; + if (src2.b[5] == 0) dst->b[5] = src.b[5]; + if (src2.b[6] == 0) dst->b[6] = src.b[6]; + if (src2.b[7] == 0) dst->b[7] = src.b[7]; + + MMX_SETEXP(cpu_reg); + return 0; +} + +static int +opPMVZB_a32(uint32_t fetchdat) +{ + MMX_REG src, src2; + MMX_REG *dst; + + if (!(ccr7 & 1)) { + x86illegal(); + return 1; + } + + MMX_ENTER(); + + fetch_ea_32(fetchdat); + + if (cpu_mod == 3) { + x86illegal(); + return 1; + } + + dst = MMX_GETREGP(cpu_reg); + src2 = MMX_GETREG(cpu_reg ^ 1); + + MMX_GETSRC(); + + if (src2.b[0] == 0) dst->b[0] = src.b[0]; + if (src2.b[1] == 0) dst->b[1] = src.b[1]; + if (src2.b[2] == 0) dst->b[2] = src.b[2]; + if (src2.b[3] == 0) dst->b[3] = src.b[3]; + if (src2.b[4] == 0) dst->b[4] = src.b[4]; + if (src2.b[5] == 0) dst->b[5] = src.b[5]; + if (src2.b[6] == 0) dst->b[6] = src.b[6]; + if (src2.b[7] == 0) dst->b[7] = src.b[7]; + + MMX_SETEXP(cpu_reg); + return 0; +} + +static int +opPMVNZB_a16(uint32_t fetchdat) +{ + MMX_REG src, src2; + MMX_REG *dst; + + if (!(ccr7 & 1)) { + x86illegal(); + return 1; + } + + MMX_ENTER(); + + fetch_ea_16(fetchdat); + + if (cpu_mod == 3) { + x86illegal(); + return 1; + } + + dst = MMX_GETREGP(cpu_reg); + src2 = MMX_GETREG(cpu_reg ^ 1); + + MMX_GETSRC(); + + if (src2.b[0] != 0) dst->b[0] = src.b[0]; + if (src2.b[1] != 0) dst->b[1] = src.b[1]; + if (src2.b[2] != 0) dst->b[2] = src.b[2]; + if (src2.b[3] != 0) dst->b[3] = src.b[3]; + if (src2.b[4] != 0) dst->b[4] = src.b[4]; + if (src2.b[5] != 0) dst->b[5] = src.b[5]; + if (src2.b[6] != 0) dst->b[6] = src.b[6]; + if (src2.b[7] != 0) dst->b[7] = src.b[7]; + + MMX_SETEXP(cpu_reg); + return 0; +} + +static int +opPMVNZB_a32(uint32_t fetchdat) +{ + MMX_REG src, src2; + MMX_REG *dst; + + if (!(ccr7 & 1)) { + x86illegal(); + return 1; + } + + MMX_ENTER(); + + fetch_ea_32(fetchdat); + + if (cpu_mod == 3) { + x86illegal(); + return 1; + } + + dst = MMX_GETREGP(cpu_reg); + src2 = MMX_GETREG(cpu_reg ^ 1); + + MMX_GETSRC(); + + if (src2.b[0] != 0) dst->b[0] = src.b[0]; + if (src2.b[1] != 0) dst->b[1] = src.b[1]; + if (src2.b[2] != 0) dst->b[2] = src.b[2]; + if (src2.b[3] != 0) dst->b[3] = src.b[3]; + if (src2.b[4] != 0) dst->b[4] = src.b[4]; + if (src2.b[5] != 0) dst->b[5] = src.b[5]; + if (src2.b[6] != 0) dst->b[6] = src.b[6]; + if (src2.b[7] != 0) dst->b[7] = src.b[7]; + + MMX_SETEXP(cpu_reg); + return 0; +} + +static int +opPMVLZB_a16(uint32_t fetchdat) +{ + MMX_REG src, src2; + MMX_REG *dst; + + if (!(ccr7 & 1)) { + x86illegal(); + return 1; + } + + MMX_ENTER(); + + fetch_ea_16(fetchdat); + + if (cpu_mod == 3) { + x86illegal(); + return 1; + } + + dst = MMX_GETREGP(cpu_reg); + src2 = MMX_GETREG(cpu_reg ^ 1); + + MMX_GETSRC(); + + if (src2.sb[0] < 0) dst->b[0] = src.b[0]; + if (src2.sb[1] < 0) dst->b[1] = src.b[1]; + if (src2.sb[2] < 0) dst->b[2] = src.b[2]; + if (src2.sb[3] < 0) dst->b[3] = src.b[3]; + if (src2.sb[4] < 0) dst->b[4] = src.b[4]; + if (src2.sb[5] < 0) dst->b[5] = src.b[5]; + if (src2.sb[6] < 0) dst->b[6] = src.b[6]; + if (src2.sb[7] < 0) dst->b[7] = src.b[7]; + + MMX_SETEXP(cpu_reg); + return 0; +} + +static int +opPMVLZB_a32(uint32_t fetchdat) +{ + MMX_REG src, src2; + MMX_REG *dst; + + if (!(ccr7 & 1)) { + x86illegal(); + return 1; + } + + MMX_ENTER(); + + fetch_ea_32(fetchdat); + + if (cpu_mod == 3) { + x86illegal(); + return 1; + } + + dst = MMX_GETREGP(cpu_reg); + src2 = MMX_GETREG(cpu_reg ^ 1); + + MMX_GETSRC(); + + if (src2.sb[0] < 0) dst->b[0] = src.b[0]; + if (src2.sb[1] < 0) dst->b[1] = src.b[1]; + if (src2.sb[2] < 0) dst->b[2] = src.b[2]; + if (src2.sb[3] < 0) dst->b[3] = src.b[3]; + if (src2.sb[4] < 0) dst->b[4] = src.b[4]; + if (src2.sb[5] < 0) dst->b[5] = src.b[5]; + if (src2.sb[6] < 0) dst->b[6] = src.b[6]; + if (src2.sb[7] < 0) dst->b[7] = src.b[7]; + + MMX_SETEXP(cpu_reg); + return 0; +} + +static int +opPMVGEZB_a16(uint32_t fetchdat) +{ + MMX_REG src, src2; + MMX_REG *dst; + + if (!(ccr7 & 1)) { + x86illegal(); + return 1; + } + + MMX_ENTER(); + + fetch_ea_16(fetchdat); + + if (cpu_mod == 3) { + x86illegal(); + return 1; + } + + dst = MMX_GETREGP(cpu_reg); + src2 = MMX_GETREG(cpu_reg ^ 1); + + MMX_GETSRC(); + + if (src2.sb[0] >= 0) dst->b[0] = src.b[0]; + if (src2.sb[1] >= 0) dst->b[1] = src.b[1]; + if (src2.sb[2] >= 0) dst->b[2] = src.b[2]; + if (src2.sb[3] >= 0) dst->b[3] = src.b[3]; + if (src2.sb[4] >= 0) dst->b[4] = src.b[4]; + if (src2.sb[5] >= 0) dst->b[5] = src.b[5]; + if (src2.sb[6] >= 0) dst->b[6] = src.b[6]; + if (src2.sb[7] >= 0) dst->b[7] = src.b[7]; + + MMX_SETEXP(cpu_reg); + return 0; +} + +static int +opPMVGEZB_a32(uint32_t fetchdat) +{ + MMX_REG src, src2; + MMX_REG *dst; + + if (!(ccr7 & 1)) { + x86illegal(); + return 1; + } + + MMX_ENTER(); + + fetch_ea_32(fetchdat); + + if (cpu_mod == 3) { + x86illegal(); + return 1; + } + + dst = MMX_GETREGP(cpu_reg); + src2 = MMX_GETREG(cpu_reg ^ 1); + + MMX_GETSRC(); + + if (src2.sb[0] >= 0) dst->b[0] = src.b[0]; + if (src2.sb[1] >= 0) dst->b[1] = src.b[1]; + if (src2.sb[2] >= 0) dst->b[2] = src.b[2]; + if (src2.sb[3] >= 0) dst->b[3] = src.b[3]; + if (src2.sb[4] >= 0) dst->b[4] = src.b[4]; + if (src2.sb[5] >= 0) dst->b[5] = src.b[5]; + if (src2.sb[6] >= 0) dst->b[6] = src.b[6]; + if (src2.sb[7] >= 0) dst->b[7] = src.b[7]; + + MMX_SETEXP(cpu_reg); + return 0; +} \ No newline at end of file diff --git a/src/cpu/x86_ops_mmx_mov.h b/src/cpu/x86_ops_mmx_mov.h index 8855f8ccd..0bf928198 100644 --- a/src/cpu/x86_ops_mmx_mov.h +++ b/src/cpu/x86_ops_mmx_mov.h @@ -110,7 +110,6 @@ opMOVD_mm_l_a32(uint32_t fetchdat) return 0; } -#ifdef USE_CYRIX_6X86 /*Cyrix maps both MOVD and SMINT to the same opcode*/ static int opMOVD_mm_l_a16_cx(uint32_t fetchdat) @@ -170,7 +169,6 @@ opMOVD_mm_l_a32_cx(uint32_t fetchdat) return 0; } -#endif /* USE_CYRIX_6X86 */ static int opMOVQ_q_mm_a16(uint32_t fetchdat) diff --git a/src/cpu/x86_ops_mov.h b/src/cpu/x86_ops_mov.h index e77876d5c..787a727d3 100644 --- a/src/cpu/x86_ops_mov.h +++ b/src/cpu/x86_ops_mov.h @@ -129,7 +129,7 @@ opMOV_SP_imm(uint32_t fetchdat) } static int -opMOV_EAX_imm(uint32_t fetchdat) +opMOV_EAX_imm(UNUSED(uint32_t fetchdat)) { uint32_t templ = getlong(); if (cpu_state.abrt) @@ -140,7 +140,7 @@ opMOV_EAX_imm(uint32_t fetchdat) return 0; } static int -opMOV_EBX_imm(uint32_t fetchdat) +opMOV_EBX_imm(UNUSED(uint32_t fetchdat)) { uint32_t templ = getlong(); if (cpu_state.abrt) @@ -151,7 +151,7 @@ opMOV_EBX_imm(uint32_t fetchdat) return 0; } static int -opMOV_ECX_imm(uint32_t fetchdat) +opMOV_ECX_imm(UNUSED(uint32_t fetchdat)) { uint32_t templ = getlong(); if (cpu_state.abrt) @@ -162,7 +162,7 @@ opMOV_ECX_imm(uint32_t fetchdat) return 0; } static int -opMOV_EDX_imm(uint32_t fetchdat) +opMOV_EDX_imm(UNUSED(uint32_t fetchdat)) { uint32_t templ = getlong(); if (cpu_state.abrt) @@ -173,7 +173,7 @@ opMOV_EDX_imm(uint32_t fetchdat) return 0; } static int -opMOV_ESI_imm(uint32_t fetchdat) +opMOV_ESI_imm(UNUSED(uint32_t fetchdat)) { uint32_t templ = getlong(); if (cpu_state.abrt) @@ -184,7 +184,7 @@ opMOV_ESI_imm(uint32_t fetchdat) return 0; } static int -opMOV_EDI_imm(uint32_t fetchdat) +opMOV_EDI_imm(UNUSED(uint32_t fetchdat)) { uint32_t templ = getlong(); if (cpu_state.abrt) @@ -195,7 +195,7 @@ opMOV_EDI_imm(uint32_t fetchdat) return 0; } static int -opMOV_EBP_imm(uint32_t fetchdat) +opMOV_EBP_imm(UNUSED(uint32_t fetchdat)) { uint32_t templ = getlong(); if (cpu_state.abrt) @@ -206,7 +206,7 @@ opMOV_EBP_imm(uint32_t fetchdat) return 0; } static int -opMOV_ESP_imm(uint32_t fetchdat) +opMOV_ESP_imm(UNUSED(uint32_t fetchdat)) { uint32_t templ = getlong(); if (cpu_state.abrt) @@ -326,7 +326,7 @@ opMOV_AL_a16(uint32_t fetchdat) return 0; } static int -opMOV_AL_a32(uint32_t fetchdat) +opMOV_AL_a32(UNUSED(uint32_t fetchdat)) { uint8_t temp; uint32_t addr = getlong(); @@ -356,7 +356,7 @@ opMOV_AX_a16(uint32_t fetchdat) return 0; } static int -opMOV_AX_a32(uint32_t fetchdat) +opMOV_AX_a32(UNUSED(uint32_t fetchdat)) { uint16_t temp; uint32_t addr = getlong(); @@ -386,7 +386,7 @@ opMOV_EAX_a16(uint32_t fetchdat) return 0; } static int -opMOV_EAX_a32(uint32_t fetchdat) +opMOV_EAX_a32(UNUSED(uint32_t fetchdat)) { uint32_t temp; uint32_t addr = getlong(); @@ -413,7 +413,7 @@ opMOV_a16_AL(uint32_t fetchdat) return cpu_state.abrt; } static int -opMOV_a32_AL(uint32_t fetchdat) +opMOV_a32_AL(UNUSED(uint32_t fetchdat)) { uint32_t addr = getlong(); SEG_CHECK_WRITE(cpu_state.ea_seg); @@ -435,7 +435,7 @@ opMOV_a16_AX(uint32_t fetchdat) return cpu_state.abrt; } static int -opMOV_a32_AX(uint32_t fetchdat) +opMOV_a32_AX(UNUSED(uint32_t fetchdat)) { uint32_t addr = getlong(); if (cpu_state.abrt) @@ -459,7 +459,7 @@ opMOV_a16_EAX(uint32_t fetchdat) return cpu_state.abrt; } static int -opMOV_a32_EAX(uint32_t fetchdat) +opMOV_a32_EAX(UNUSED(uint32_t fetchdat)) { uint32_t addr = getlong(); if (cpu_state.abrt) @@ -515,7 +515,7 @@ opLEA_l_a32(uint32_t fetchdat) } static int -opXLAT_a16(uint32_t fetchdat) +opXLAT_a16(UNUSED(uint32_t fetchdat)) { uint32_t addr = (BX + AL) & 0xFFFF; uint8_t temp; @@ -530,7 +530,7 @@ opXLAT_a16(uint32_t fetchdat) return 0; } static int -opXLAT_a32(uint32_t fetchdat) +opXLAT_a32(UNUSED(uint32_t fetchdat)) { uint32_t addr = EBX + AL; uint8_t temp; diff --git a/src/cpu/x86_ops_mov_ctrl.h b/src/cpu/x86_ops_mov_ctrl.h index b4f0c498a..3f5d6a4d7 100644 --- a/src/cpu/x86_ops_mov_ctrl.h +++ b/src/cpu/x86_ops_mov_ctrl.h @@ -184,7 +184,7 @@ opMOV_CRx_r_a16(uint32_t fetchdat) fetch_ea_16(fetchdat); switch (cpu_reg) { case 0: - if ((cpu_state.regs[cpu_rm].l ^ cr0) & (0x00000001 | WP_FLAG)) + if ((cpu_state.regs[cpu_rm].l ^ cr0) & 0x00000001) flushmmucache(); else if ((cpu_state.regs[cpu_rm].l ^ cr0) & 0x80000000) { if (is_p6 || cpu_use_dynarec) @@ -193,15 +193,14 @@ opMOV_CRx_r_a16(uint32_t fetchdat) flushmmucache_nopc(); cpu_flush_pending = 1; } - } + } else if ((cpu_state.regs[cpu_rm].l ^ cr0) & WP_FLAG) + flushmmucache_write(); /* Make sure CPL = 0 when switching from real mode to protected mode. */ if ((cpu_state.regs[cpu_rm].l & 0x01) && !(cr0 & 0x01)) cpu_state.seg_cs.access &= 0x9f; cr0 = cpu_state.regs[cpu_rm].l; if (cpu_16bitbus) cr0 |= 0x10; - if (!(cr0 & 0x80000000)) - mmu_perm = 4; if (hascache && !(cr0 & (1 << 30))) cpu_cache_int_enabled = 1; else @@ -249,7 +248,7 @@ opMOV_CRx_r_a32(uint32_t fetchdat) fetch_ea_32(fetchdat); switch (cpu_reg) { case 0: - if ((cpu_state.regs[cpu_rm].l ^ cr0) & (0x00000001 | WP_FLAG)) + if ((cpu_state.regs[cpu_rm].l ^ cr0) & 0x00000001) flushmmucache(); else if ((cpu_state.regs[cpu_rm].l ^ cr0) & 0x80000000) { if (is_p6 || cpu_use_dynarec) @@ -258,15 +257,14 @@ opMOV_CRx_r_a32(uint32_t fetchdat) flushmmucache_nopc(); cpu_flush_pending = 1; } - } + } else if ((cpu_state.regs[cpu_rm].l ^ cr0) & WP_FLAG) + flushmmucache_write(); /* Make sure CPL = 0 when switching from real mode to protected mode. */ if ((cpu_state.regs[cpu_rm].l & 0x01) && !(cr0 & 0x01)) cpu_state.seg_cs.access &= 0x9f; cr0 = cpu_state.regs[cpu_rm].l; if (cpu_16bitbus) cr0 |= 0x10; - if (!(cr0 & 0x80000000)) - mmu_perm = 4; if (hascache && !(cr0 & (1 << 30))) cpu_cache_int_enabled = 1; else diff --git a/src/cpu/x86_ops_mov_ctrl_2386.h b/src/cpu/x86_ops_mov_ctrl_2386.h index 13e08a145..0d13cc833 100644 --- a/src/cpu/x86_ops_mov_ctrl_2386.h +++ b/src/cpu/x86_ops_mov_ctrl_2386.h @@ -180,20 +180,19 @@ opMOV_CRx_r_a16(uint32_t fetchdat) fetch_ea_16(fetchdat); switch (cpu_reg) { case 0: - if ((cpu_state.regs[cpu_rm].l ^ cr0) & (0x00000001 | WP_FLAG)) + if ((cpu_state.regs[cpu_rm].l ^ cr0) & 0x00000001) flushmmucache(); else if ((cpu_state.regs[cpu_rm].l ^ cr0) & 0x80000000) { flushmmucache_nopc(); cpu_flush_pending = 1; - } + } else if ((cpu_state.regs[cpu_rm].l ^ cr0) & WP_FLAG) + flushmmucache_write(); /* Make sure CPL = 0 when switching from real mode to protected mode. */ if ((cpu_state.regs[cpu_rm].l & 0x01) && !(cr0 & 0x01)) cpu_state.seg_cs.access &= 0x9f; cr0 = cpu_state.regs[cpu_rm].l; if (cpu_16bitbus) cr0 |= 0x10; - if (!(cr0 & 0x80000000)) - mmu_perm = 4; if (hascache && !(cr0 & (1 << 30))) cpu_cache_int_enabled = 1; else @@ -241,20 +240,19 @@ opMOV_CRx_r_a32(uint32_t fetchdat) fetch_ea_32(fetchdat); switch (cpu_reg) { case 0: - if ((cpu_state.regs[cpu_rm].l ^ cr0) & (0x00000001 | WP_FLAG)) + if ((cpu_state.regs[cpu_rm].l ^ cr0) & 0x00000001) flushmmucache(); else if ((cpu_state.regs[cpu_rm].l ^ cr0) & 0x80000000) { flushmmucache_nopc(); cpu_flush_pending = 1; - } + } else if ((cpu_state.regs[cpu_rm].l ^ cr0) & WP_FLAG) + flushmmucache_write(); /* Make sure CPL = 0 when switching from real mode to protected mode. */ if ((cpu_state.regs[cpu_rm].l & 0x01) && !(cr0 & 0x01)) cpu_state.seg_cs.access &= 0x9f; cr0 = cpu_state.regs[cpu_rm].l; if (cpu_16bitbus) cr0 |= 0x10; - if (!(cr0 & 0x80000000)) - mmu_perm = 4; if (hascache && !(cr0 & (1 << 30))) cpu_cache_int_enabled = 1; else diff --git a/src/cpu/x86_ops_mov_seg.h b/src/cpu/x86_ops_mov_seg.h index 7fcc92312..f5bd02923 100644 --- a/src/cpu/x86_ops_mov_seg.h +++ b/src/cpu/x86_ops_mov_seg.h @@ -272,9 +272,13 @@ opLDS_w_a16(uint32_t fetchdat) fetch_ea_16(fetchdat); ILLEGAL_ON(cpu_mod == 3); SEG_CHECK_READ(cpu_state.ea_seg); - CHECK_READ(cpu_state.ea_seg, cpu_state.eaaddr, cpu_state.eaaddr + 3); - addr = readmemw(easeg, cpu_state.eaaddr); - seg = readmemw(easeg, cpu_state.eaaddr + 2); + CHECK_READ(cpu_state.ea_seg, cpu_state.eaa16[0], ((cpu_state.eaa16[0] + 1) & 0xffff)); + addr = readmemw(easeg, cpu_state.eaa16[0]); + if (cpu_state.abrt) + return 1; + cpu_state.eaa16[0] += 2; + CHECK_READ(cpu_state.ea_seg, cpu_state.eaa16[0], ((cpu_state.eaa16[0] + 1) & 0xffff)); + seg = readmemw(easeg, cpu_state.eaa16[0]); if (cpu_state.abrt) return 1; op_loadseg(seg, &cpu_state.seg_ds); @@ -318,9 +322,13 @@ opLDS_l_a16(uint32_t fetchdat) fetch_ea_16(fetchdat); ILLEGAL_ON(cpu_mod == 3); SEG_CHECK_READ(cpu_state.ea_seg); - CHECK_READ(cpu_state.ea_seg, cpu_state.eaaddr, cpu_state.eaaddr + 5); - addr = readmeml(easeg, cpu_state.eaaddr); - seg = readmemw(easeg, cpu_state.eaaddr + 4); + CHECK_READ(cpu_state.ea_seg, cpu_state.eaa16[0], ((cpu_state.eaa16[0] + 3) & 0xffff)); + addr = readmeml(easeg, cpu_state.eaa16[0]); + if (cpu_state.abrt) + return 1; + cpu_state.eaa16[0] += 4; + CHECK_READ(cpu_state.ea_seg, cpu_state.eaa16[0], ((cpu_state.eaa16[0] + 1) & 0xffff)); + seg = readmemw(easeg, cpu_state.eaa16[0]); if (cpu_state.abrt) return 1; op_loadseg(seg, &cpu_state.seg_ds); @@ -365,9 +373,13 @@ opLSS_w_a16(uint32_t fetchdat) fetch_ea_16(fetchdat); ILLEGAL_ON(cpu_mod == 3); SEG_CHECK_READ(cpu_state.ea_seg); - CHECK_READ(cpu_state.ea_seg, cpu_state.eaaddr, cpu_state.eaaddr + 3); - addr = readmemw(easeg, cpu_state.eaaddr); - seg = readmemw(easeg, cpu_state.eaaddr + 2); + CHECK_READ(cpu_state.ea_seg, cpu_state.eaa16[0], ((cpu_state.eaa16[0] + 1) & 0xffff)); + addr = readmemw(easeg, cpu_state.eaa16[0]); + if (cpu_state.abrt) + return 1; + cpu_state.eaa16[0] += 2; + CHECK_READ(cpu_state.ea_seg, cpu_state.eaa16[0], ((cpu_state.eaa16[0] + 1) & 0xffff)); + seg = readmemw(easeg, cpu_state.eaa16[0]); if (cpu_state.abrt) return 1; op_loadseg(seg, &cpu_state.seg_ss); @@ -411,9 +423,13 @@ opLSS_l_a16(uint32_t fetchdat) fetch_ea_16(fetchdat); ILLEGAL_ON(cpu_mod == 3); SEG_CHECK_READ(cpu_state.ea_seg); - CHECK_READ(cpu_state.ea_seg, cpu_state.eaaddr, cpu_state.eaaddr + 5); - addr = readmeml(easeg, cpu_state.eaaddr); - seg = readmemw(easeg, cpu_state.eaaddr + 4); + CHECK_READ(cpu_state.ea_seg, cpu_state.eaa16[0], ((cpu_state.eaa16[0] + 3) & 0xffff)); + addr = readmeml(easeg, cpu_state.eaa16[0]); + if (cpu_state.abrt) + return 1; + cpu_state.eaa16[0] += 4; + CHECK_READ(cpu_state.ea_seg, cpu_state.eaa16[0], ((cpu_state.eaa16[0] + 1) & 0xffff)); + seg = readmemw(easeg, cpu_state.eaa16[0]); if (cpu_state.abrt) return 1; op_loadseg(seg, &cpu_state.seg_ss); @@ -457,9 +473,13 @@ opLSS_l_a32(uint32_t fetchdat) fetch_ea_16(fetchdat); \ SEG_CHECK_READ(cpu_state.ea_seg); \ ILLEGAL_ON(cpu_mod == 3); \ - CHECK_READ(cpu_state.ea_seg, cpu_state.eaaddr, cpu_state.eaaddr + 3); \ - addr = readmemw(easeg, cpu_state.eaaddr); \ - seg = readmemw(easeg, cpu_state.eaaddr + 2); \ + CHECK_READ(cpu_state.ea_seg, cpu_state.eaa16[0], ((cpu_state.eaa16[0] + 1) & 0xffff)); \ + addr = readmemw(easeg, cpu_state.eaa16[0]); \ + if (cpu_state.abrt) \ + return 1; \ + cpu_state.eaa16[0] += 2; \ + CHECK_READ(cpu_state.ea_seg, cpu_state.eaa16[0], ((cpu_state.eaa16[0] + 1) & 0xffff)); \ + seg = readmemw(easeg, cpu_state.eaa16[0]); \ if (cpu_state.abrt) \ return 1; \ op_loadseg(seg, &sel); \ @@ -502,9 +522,13 @@ opLSS_l_a32(uint32_t fetchdat) fetch_ea_16(fetchdat); \ SEG_CHECK_READ(cpu_state.ea_seg); \ ILLEGAL_ON(cpu_mod == 3); \ - CHECK_READ(cpu_state.ea_seg, cpu_state.eaaddr, cpu_state.eaaddr + 5); \ - addr = readmeml(easeg, cpu_state.eaaddr); \ - seg = readmemw(easeg, cpu_state.eaaddr + 4); \ + CHECK_READ(cpu_state.ea_seg, cpu_state.eaa16[0], ((cpu_state.eaa16[0] + 3) & 0xffff)); \ + addr = readmeml(easeg, cpu_state.eaa16[0]); \ + if (cpu_state.abrt) \ + return 1; \ + cpu_state.eaa16[0] += 4; \ + CHECK_READ(cpu_state.ea_seg, cpu_state.eaa16[0], ((cpu_state.eaa16[0] + 1) & 0xffff)); \ + seg = readmemw(easeg, cpu_state.eaa16[0]); \ if (cpu_state.abrt) \ return 1; \ op_loadseg(seg, &sel); \ diff --git a/src/cpu/x86_ops_msr.h b/src/cpu/x86_ops_msr.h index daae01d84..a59cecdd4 100644 --- a/src/cpu/x86_ops_msr.h +++ b/src/cpu/x86_ops_msr.h @@ -1,5 +1,5 @@ static int -opRDTSC(uint32_t fetchdat) +opRDTSC(UNUSED(uint32_t fetchdat)) { if (!cpu_has_feature(CPU_FEATURE_RDTSC)) { cpu_state.pc = cpu_state.oldpc; @@ -21,7 +21,7 @@ opRDTSC(uint32_t fetchdat) } static int -opRDPMC(uint32_t fetchdat) +opRDPMC(UNUSED(uint32_t fetchdat)) { if (ECX > 1 || (!(cr4 & CR4_PCE) && (cr0 & 1) && CPL)) { x86gpf("RDPMC not allowed", 0); diff --git a/src/cpu/x86_ops_pmode.h b/src/cpu/x86_ops_pmode.h index 4f32b0e37..81f194f14 100644 --- a/src/cpu/x86_ops_pmode.h +++ b/src/cpu/x86_ops_pmode.h @@ -172,12 +172,12 @@ opLAR(w_a16, fetch_ea_16, 0, 0) return cpu_state.abrt; \ } - opLSL(w_a16, fetch_ea_16, 0, 0) - opLSL(w_a32, fetch_ea_32, 0, 1) - opLSL(l_a16, fetch_ea_16, 1, 0) - opLSL(l_a32, fetch_ea_32, 1, 1) +opLSL(w_a16, fetch_ea_16, 0, 0) +opLSL(w_a32, fetch_ea_32, 0, 1) +opLSL(l_a16, fetch_ea_16, 1, 0) +opLSL(l_a32, fetch_ea_32, 1, 1) - static int op0F00_common(uint32_t fetchdat, int ea32) +static int op0F00_common(uint32_t fetchdat, UNUSED(int ea32)) { int dpl; int valid; @@ -359,7 +359,7 @@ op0F00_a32(uint32_t fetchdat) } static int -op0F01_common(uint32_t fetchdat, int is32, int is286, int ea32) +op0F01_common(UNUSED(uint32_t fetchdat), int is32, int is286, UNUSED(int ea32)) { uint32_t base; uint16_t limit; diff --git a/src/cpu/x86_ops_rep.h b/src/cpu/x86_ops_rep.h index a49db7e81..6449912e9 100644 --- a/src/cpu/x86_ops_rep.h +++ b/src/cpu/x86_ops_rep.h @@ -1,5 +1,5 @@ #define REP_OPS(size, CNT_REG, SRC_REG, DEST_REG) \ - static int opREP_INSB_##size(uint32_t fetchdat) \ + static int opREP_INSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ \ @@ -38,7 +38,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_INSW_##size(uint32_t fetchdat) \ + static int opREP_INSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ \ @@ -77,7 +77,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_INSL_##size(uint32_t fetchdat) \ + static int opREP_INSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ \ @@ -117,7 +117,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_OUTSB_##size(uint32_t fetchdat) \ + static int opREP_OUTSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ \ @@ -148,7 +148,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_OUTSW_##size(uint32_t fetchdat) \ + static int opREP_OUTSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ \ @@ -179,7 +179,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_OUTSL_##size(uint32_t fetchdat) \ + static int opREP_OUTSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ \ @@ -211,7 +211,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_MOVSB_##size(uint32_t fetchdat) \ + static int opREP_MOVSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -264,7 +264,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_MOVSW_##size(uint32_t fetchdat) \ + static int opREP_MOVSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -318,7 +318,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_MOVSL_##size(uint32_t fetchdat) \ + static int opREP_MOVSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -373,7 +373,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_STOSB_##size(uint32_t fetchdat) \ + static int opREP_STOSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int writes = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -405,7 +405,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_STOSW_##size(uint32_t fetchdat) \ + static int opREP_STOSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int writes = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -437,7 +437,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_STOSL_##size(uint32_t fetchdat) \ + static int opREP_STOSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int writes = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -470,7 +470,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_LODSB_##size(uint32_t fetchdat) \ + static int opREP_LODSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -502,7 +502,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_LODSW_##size(uint32_t fetchdat) \ + static int opREP_LODSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -534,7 +534,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_LODSL_##size(uint32_t fetchdat) \ + static int opREP_LODSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -570,7 +570,7 @@ #define CHEK_READ(a, b, c) #define REP_OPS_CMPS_SCAS(size, CNT_REG, SRC_REG, DEST_REG, FV) \ - static int opREP_CMPSB_##size(uint32_t fetchdat) \ + static int opREP_CMPSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0, tempz; \ \ @@ -623,7 +623,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_CMPSW_##size(uint32_t fetchdat) \ + static int opREP_CMPSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0, tempz; \ \ @@ -677,7 +677,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_CMPSL_##size(uint32_t fetchdat) \ + static int opREP_CMPSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0, tempz; \ \ @@ -732,7 +732,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_SCASB_##size(uint32_t fetchdat) \ + static int opREP_SCASB_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0, tempz; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -767,7 +767,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_SCASW_##size(uint32_t fetchdat) \ + static int opREP_SCASW_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0, tempz; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -802,7 +802,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_SCASL_##size(uint32_t fetchdat) \ + static int opREP_SCASL_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0, tempz; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -855,6 +855,7 @@ opREPNE(uint32_t fetchdat) CLOCK_CYCLES(2); PREFETCH_PREFIX(); + rep_op = fetchdat & 0xff; if (x86_opcodes_REPNE[(fetchdat & 0xff) | cpu_state.op32]) return x86_opcodes_REPNE[(fetchdat & 0xff) | cpu_state.op32](fetchdat >> 8); return x86_opcodes[(fetchdat & 0xff) | cpu_state.op32](fetchdat >> 8); @@ -869,6 +870,7 @@ opREPE(uint32_t fetchdat) CLOCK_CYCLES(2); PREFETCH_PREFIX(); + rep_op = fetchdat & 0xff; if (x86_opcodes_REPE[(fetchdat & 0xff) | cpu_state.op32]) return x86_opcodes_REPE[(fetchdat & 0xff) | cpu_state.op32](fetchdat >> 8); return x86_opcodes[(fetchdat & 0xff) | cpu_state.op32](fetchdat >> 8); diff --git a/src/cpu/x86_ops_rep_2386.h b/src/cpu/x86_ops_rep_2386.h index fe5048340..3b96d54e3 100644 --- a/src/cpu/x86_ops_rep_2386.h +++ b/src/cpu/x86_ops_rep_2386.h @@ -1,5 +1,5 @@ #define REP_OPS(size, CNT_REG, SRC_REG, DEST_REG) \ - static int opREP_INSB_##size(uint32_t fetchdat) \ + static int opREP_INSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ \ @@ -38,7 +38,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_INSW_##size(uint32_t fetchdat) \ + static int opREP_INSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ \ @@ -77,7 +77,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_INSL_##size(uint32_t fetchdat) \ + static int opREP_INSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ \ @@ -117,7 +117,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_OUTSB_##size(uint32_t fetchdat) \ + static int opREP_OUTSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ \ @@ -148,7 +148,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_OUTSW_##size(uint32_t fetchdat) \ + static int opREP_OUTSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ \ @@ -179,7 +179,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_OUTSL_##size(uint32_t fetchdat) \ + static int opREP_OUTSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ \ @@ -211,7 +211,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_MOVSB_##size(uint32_t fetchdat) \ + static int opREP_MOVSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -264,7 +264,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_MOVSW_##size(uint32_t fetchdat) \ + static int opREP_MOVSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -318,7 +318,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_MOVSL_##size(uint32_t fetchdat) \ + static int opREP_MOVSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, writes = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -373,7 +373,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_STOSB_##size(uint32_t fetchdat) \ + static int opREP_STOSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int writes = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -405,7 +405,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_STOSW_##size(uint32_t fetchdat) \ + static int opREP_STOSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int writes = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -437,7 +437,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_STOSL_##size(uint32_t fetchdat) \ + static int opREP_STOSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int writes = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -470,7 +470,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_LODSB_##size(uint32_t fetchdat) \ + static int opREP_LODSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -502,7 +502,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_LODSW_##size(uint32_t fetchdat) \ + static int opREP_LODSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -534,7 +534,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_LODSL_##size(uint32_t fetchdat) \ + static int opREP_LODSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -570,7 +570,7 @@ #define CHEK_READ(a, b, c) #define REP_OPS_CMPS_SCAS(size, CNT_REG, SRC_REG, DEST_REG, FV) \ - static int opREP_CMPSB_##size(uint32_t fetchdat) \ + static int opREP_CMPSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0, tempz; \ \ @@ -619,7 +619,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_CMPSW_##size(uint32_t fetchdat) \ + static int opREP_CMPSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0, tempz; \ \ @@ -669,7 +669,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_CMPSL_##size(uint32_t fetchdat) \ + static int opREP_CMPSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0, tempz; \ \ @@ -720,7 +720,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_SCASB_##size(uint32_t fetchdat) \ + static int opREP_SCASB_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0, tempz; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -755,7 +755,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_SCASW_##size(uint32_t fetchdat) \ + static int opREP_SCASW_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0, tempz; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -790,7 +790,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_SCASL_##size(uint32_t fetchdat) \ + static int opREP_SCASL_##size(UNUSED(uint32_t fetchdat)) \ { \ int reads = 0, total_cycles = 0, tempz; \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ @@ -843,6 +843,7 @@ opREPNE(uint32_t fetchdat) CLOCK_CYCLES(2); PREFETCH_PREFIX(); + rep_op = fetchdat & 0xff; if (x86_2386_opcodes_REPNE[(fetchdat & 0xff) | cpu_state.op32]) return x86_2386_opcodes_REPNE[(fetchdat & 0xff) | cpu_state.op32](fetchdat >> 8); return x86_2386_opcodes[(fetchdat & 0xff) | cpu_state.op32](fetchdat >> 8); @@ -857,6 +858,7 @@ opREPE(uint32_t fetchdat) CLOCK_CYCLES(2); PREFETCH_PREFIX(); + rep_op = fetchdat & 0xff; if (x86_2386_opcodes_REPE[(fetchdat & 0xff) | cpu_state.op32]) return x86_2386_opcodes_REPE[(fetchdat & 0xff) | cpu_state.op32](fetchdat >> 8); return x86_2386_opcodes[(fetchdat & 0xff) | cpu_state.op32](fetchdat >> 8); diff --git a/src/cpu/x86_ops_rep_dyn.h b/src/cpu/x86_ops_rep_dyn.h index cf32209cc..1220c0da3 100644 --- a/src/cpu/x86_ops_rep_dyn.h +++ b/src/cpu/x86_ops_rep_dyn.h @@ -1,5 +1,5 @@ #define REP_OPS(size, CNT_REG, SRC_REG, DEST_REG) \ - static int opREP_INSB_##size(uint32_t fetchdat) \ + static int opREP_INSB_##size(UNUSED(uint32_t fetchdat)) \ { \ addr64 = 0x00000000; \ \ @@ -32,7 +32,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_INSW_##size(uint32_t fetchdat) \ + static int opREP_INSW_##size(UNUSED(uint32_t fetchdat)) \ { \ addr64a[0] = addr64a[1] = 0x00000000; \ \ @@ -65,7 +65,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_INSL_##size(uint32_t fetchdat) \ + static int opREP_INSL_##size(UNUSED(uint32_t fetchdat)) \ { \ addr64a[0] = addr64a[1] = addr64a[2] = addr64a[3] = 0x00000000; \ \ @@ -99,7 +99,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_OUTSB_##size(uint32_t fetchdat) \ + static int opREP_OUTSB_##size(UNUSED(uint32_t fetchdat)) \ { \ if (CNT_REG > 0) { \ uint8_t temp; \ @@ -124,7 +124,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_OUTSW_##size(uint32_t fetchdat) \ + static int opREP_OUTSW_##size(UNUSED(uint32_t fetchdat)) \ { \ if (CNT_REG > 0) { \ uint16_t temp; \ @@ -149,7 +149,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_OUTSL_##size(uint32_t fetchdat) \ + static int opREP_OUTSL_##size(UNUSED(uint32_t fetchdat)) \ { \ if (CNT_REG > 0) { \ uint32_t temp; \ @@ -175,7 +175,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_MOVSB_##size(uint32_t fetchdat) \ + static int opREP_MOVSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ addr64 = addr64_2 = 0x00000000; \ @@ -223,7 +223,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_MOVSW_##size(uint32_t fetchdat) \ + static int opREP_MOVSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ addr64a[0] = addr64a[1] = 0x00000000; \ @@ -272,7 +272,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_MOVSL_##size(uint32_t fetchdat) \ + static int opREP_MOVSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ addr64a[0] = addr64a[1] = addr64a[2] = addr64a[3] = 0x00000000; \ @@ -322,7 +322,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_STOSB_##size(uint32_t fetchdat) \ + static int opREP_STOSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ if (trap) \ @@ -350,7 +350,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_STOSW_##size(uint32_t fetchdat) \ + static int opREP_STOSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ if (trap) \ @@ -378,7 +378,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_STOSL_##size(uint32_t fetchdat) \ + static int opREP_STOSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ if (trap) \ @@ -407,7 +407,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_LODSB_##size(uint32_t fetchdat) \ + static int opREP_LODSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ if (trap) \ @@ -435,7 +435,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_LODSW_##size(uint32_t fetchdat) \ + static int opREP_LODSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ if (trap) \ @@ -463,7 +463,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_LODSL_##size(uint32_t fetchdat) \ + static int opREP_LODSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int cycles_end = cycles - ((is386 && cpu_use_dynarec) ? 1000 : 100); \ if (trap) \ @@ -495,7 +495,7 @@ #define CHEK_READ(a, b, c) #define REP_OPS_CMPS_SCAS(size, CNT_REG, SRC_REG, DEST_REG, FV) \ - static int opREP_CMPSB_##size(uint32_t fetchdat) \ + static int opREP_CMPSB_##size(UNUSED(uint32_t fetchdat)) \ { \ int tempz; \ \ @@ -545,7 +545,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_CMPSW_##size(uint32_t fetchdat) \ + static int opREP_CMPSW_##size(UNUSED(uint32_t fetchdat)) \ { \ int tempz; \ \ @@ -596,7 +596,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_CMPSL_##size(uint32_t fetchdat) \ + static int opREP_CMPSL_##size(UNUSED(uint32_t fetchdat)) \ { \ int tempz; \ \ @@ -648,7 +648,7 @@ return cpu_state.abrt; \ } \ \ - static int opREP_SCASB_##size(uint32_t fetchdat) \ + static int opREP_SCASB_##size(UNUSED(uint32_t fetchdat)) \ { \ int tempz; \ int cycles_end = cycles - 1000; \ @@ -680,7 +680,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_SCASW_##size(uint32_t fetchdat) \ + static int opREP_SCASW_##size(UNUSED(uint32_t fetchdat)) \ { \ int tempz; \ int cycles_end = cycles - 1000; \ @@ -712,7 +712,7 @@ } \ return cpu_state.abrt; \ } \ - static int opREP_SCASL_##size(uint32_t fetchdat) \ + static int opREP_SCASL_##size(UNUSED(uint32_t fetchdat)) \ { \ int tempz; \ int cycles_end = cycles - 1000; \ @@ -761,6 +761,7 @@ opREPNE(uint32_t fetchdat) cpu_state.pc++; CLOCK_CYCLES(2); + rep_op = fetchdat & 0xff; if (x86_opcodes_REPNE[(fetchdat & 0xff) | cpu_state.op32]) return x86_opcodes_REPNE[(fetchdat & 0xff) | cpu_state.op32](fetchdat >> 8); return x86_opcodes[(fetchdat & 0xff) | cpu_state.op32](fetchdat >> 8); @@ -774,6 +775,7 @@ opREPE(uint32_t fetchdat) cpu_state.pc++; CLOCK_CYCLES(2); + rep_op = fetchdat & 0xff; if (x86_opcodes_REPE[(fetchdat & 0xff) | cpu_state.op32]) return x86_opcodes_REPE[(fetchdat & 0xff) | cpu_state.op32](fetchdat >> 8); return x86_opcodes[(fetchdat & 0xff) | cpu_state.op32](fetchdat >> 8); diff --git a/src/cpu/x86_ops_ret.h b/src/cpu/x86_ops_ret.h index d30d4eb8f..8bf72e9ed 100644 --- a/src/cpu/x86_ops_ret.h +++ b/src/cpu/x86_ops_ret.h @@ -15,7 +15,7 @@ op_loadcs(readmemw(ss, ESP + 2)); \ } else { \ cpu_state.pc = readmemw(ss, SP); \ - op_loadcs(readmemw(ss, SP + 2)); \ + op_loadcs(readmemw(ss, (SP + 2) & 0xffff)); \ } \ if (cpu_state.abrt) \ return 1; \ @@ -47,7 +47,7 @@ cycles -= timing_retf_rm; static int -opRETF_a16(uint32_t fetchdat) +opRETF_a16(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); @@ -60,7 +60,7 @@ opRETF_a16(uint32_t fetchdat) return 0; } static int -opRETF_a32(uint32_t fetchdat) +opRETF_a32(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); @@ -103,7 +103,7 @@ opRETF_a32_imm(uint32_t fetchdat) } static int -opIRET_186(uint32_t fetchdat) +opIRET_186(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); @@ -146,7 +146,7 @@ opIRET_186(uint32_t fetchdat) } static int -opIRET_286(uint32_t fetchdat) +opIRET_286(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); @@ -189,7 +189,7 @@ opIRET_286(uint32_t fetchdat) } static int -opIRET(uint32_t fetchdat) +opIRET(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); @@ -260,7 +260,7 @@ opIRET(uint32_t fetchdat) } static int -opIRETD(uint32_t fetchdat) +opIRETD(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); diff --git a/src/cpu/x86_ops_ret_2386.h b/src/cpu/x86_ops_ret_2386.h index ca85bf2b0..02233fd1d 100644 --- a/src/cpu/x86_ops_ret_2386.h +++ b/src/cpu/x86_ops_ret_2386.h @@ -15,7 +15,7 @@ op_loadcs(readmemw(ss, ESP + 2)); \ } else { \ cpu_state.pc = readmemw(ss, SP); \ - op_loadcs(readmemw(ss, SP + 2)); \ + op_loadcs(readmemw(ss, (SP + 2) & 0xffff)); \ } \ if (cpu_state.abrt) \ return 1; \ @@ -47,7 +47,7 @@ cycles -= timing_retf_rm; static int -opRETF_a16(uint32_t fetchdat) +opRETF_a16(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); @@ -60,7 +60,7 @@ opRETF_a16(uint32_t fetchdat) return 0; } static int -opRETF_a32(uint32_t fetchdat) +opRETF_a32(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); @@ -103,7 +103,7 @@ opRETF_a32_imm(uint32_t fetchdat) } static int -opIRET_186(uint32_t fetchdat) +opIRET_186(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); @@ -144,7 +144,7 @@ opIRET_186(uint32_t fetchdat) } static int -opIRET_286(uint32_t fetchdat) +opIRET_286(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); @@ -185,7 +185,7 @@ opIRET_286(uint32_t fetchdat) } static int -opIRET(uint32_t fetchdat) +opIRET(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); @@ -254,7 +254,7 @@ opIRET(uint32_t fetchdat) } static int -opIRETD(uint32_t fetchdat) +opIRETD(UNUSED(uint32_t fetchdat)) { int cycles_old = cycles; UN_USED(cycles_old); diff --git a/src/cpu/x86_ops_stack.h b/src/cpu/x86_ops_stack.h index fbf603ddb..f5d608fbb 100644 --- a/src/cpu/x86_ops_stack.h +++ b/src/cpu/x86_ops_stack.h @@ -1,5 +1,5 @@ #define PUSH_W_OP(reg) \ - static int opPUSH_##reg(uint32_t fetchdat) \ + static int opPUSH_##reg(UNUSED(uint32_t fetchdat)) \ { \ PUSH_W(reg); \ CLOCK_CYCLES((is486) ? 1 : 2); \ @@ -8,7 +8,7 @@ } #define PUSH_L_OP(reg) \ - static int opPUSH_##reg(uint32_t fetchdat) \ + static int opPUSH_##reg(UNUSED(uint32_t fetchdat)) \ { \ PUSH_L(reg); \ CLOCK_CYCLES((is486) ? 1 : 2); \ @@ -17,7 +17,7 @@ } #define POP_W_OP(reg) \ - static int opPOP_##reg(uint32_t fetchdat) \ + static int opPOP_##reg(UNUSED(uint32_t fetchdat)) \ { \ reg = POP_W(); \ CLOCK_CYCLES((is486) ? 1 : 4); \ @@ -26,7 +26,7 @@ } #define POP_L_OP(reg) \ - static int opPOP_##reg(uint32_t fetchdat) \ + static int opPOP_##reg(UNUSED(uint32_t fetchdat)) \ { \ reg = POP_L(); \ CLOCK_CYCLES((is486) ? 1 : 4); \ @@ -71,7 +71,7 @@ POP_L_OP(EBP) POP_L_OP(ESP) static int -opPUSHA_w(uint32_t fetchdat) +opPUSHA_w(UNUSED(uint32_t fetchdat)) { if (stack32) { writememw(ss, ESP - 2, AX); @@ -101,7 +101,7 @@ opPUSHA_w(uint32_t fetchdat) return cpu_state.abrt; } static int -opPUSHA_l(uint32_t fetchdat) +opPUSHA_l(UNUSED(uint32_t fetchdat)) { if (stack32) { writememl(ss, ESP - 4, EAX); @@ -132,7 +132,7 @@ opPUSHA_l(uint32_t fetchdat) } static int -opPOPA_w(uint32_t fetchdat) +opPOPA_w(UNUSED(uint32_t fetchdat)) { if (stack32) { DI = readmemw(ss, ESP); @@ -186,7 +186,7 @@ opPOPA_w(uint32_t fetchdat) return 0; } static int -opPOPA_l(uint32_t fetchdat) +opPOPA_l(UNUSED(uint32_t fetchdat)) { if (stack32) { EDI = readmeml(ss, ESP); @@ -250,7 +250,7 @@ opPUSH_imm_w(uint32_t fetchdat) return cpu_state.abrt; } static int -opPUSH_imm_l(uint32_t fetchdat) +opPUSH_imm_l(UNUSED(uint32_t fetchdat)) { uint32_t val = getlong(); if (cpu_state.abrt) @@ -550,7 +550,7 @@ opENTER_l(uint32_t fetchdat) } static int -opLEAVE_w(uint32_t fetchdat) +opLEAVE_w(UNUSED(uint32_t fetchdat)) { uint32_t tempESP = ESP; uint16_t temp; @@ -568,7 +568,7 @@ opLEAVE_w(uint32_t fetchdat) return 0; } static int -opLEAVE_l(uint32_t fetchdat) +opLEAVE_l(UNUSED(uint32_t fetchdat)) { uint32_t tempESP = ESP; uint32_t temp; @@ -587,14 +587,14 @@ opLEAVE_l(uint32_t fetchdat) } #define PUSH_SEG_OPS(seg) \ - static int opPUSH_##seg##_w(uint32_t fetchdat) \ + static int opPUSH_##seg##_w(UNUSED(uint32_t fetchdat)) \ { \ PUSH_W(seg); \ CLOCK_CYCLES(2); \ PREFETCH_RUN(2, 1, -1, 0, 0, 1, 0, 0); \ return cpu_state.abrt; \ } \ - static int opPUSH_##seg##_l(uint32_t fetchdat) \ + static int opPUSH_##seg##_l(UNUSED(uint32_t fetchdat)) \ { \ PUSH_L(seg); \ CLOCK_CYCLES(2); \ @@ -603,7 +603,7 @@ opLEAVE_l(uint32_t fetchdat) } #define POP_SEG_OPS(seg, realseg) \ - static int opPOP_##seg##_w(uint32_t fetchdat) \ + static int opPOP_##seg##_w(UNUSED(uint32_t fetchdat)) \ { \ uint16_t temp_seg; \ uint32_t temp_esp = ESP; \ @@ -617,7 +617,7 @@ opLEAVE_l(uint32_t fetchdat) PREFETCH_RUN(is486 ? 3 : 7, 1, -1, 0, 0, 1, 0, 0); \ return cpu_state.abrt; \ } \ - static int opPOP_##seg##_l(uint32_t fetchdat) \ + static int opPOP_##seg##_l(UNUSED(uint32_t fetchdat)) \ { \ uint32_t temp_seg; \ uint32_t temp_esp = ESP; \ diff --git a/src/cpu/x86_ops_string.h b/src/cpu/x86_ops_string.h index 619386fcb..d3a7d89a9 100644 --- a/src/cpu/x86_ops_string.h +++ b/src/cpu/x86_ops_string.h @@ -1,5 +1,5 @@ static int -opMOVSB_a16(uint32_t fetchdat) +opMOVSB_a16(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -35,7 +35,7 @@ opMOVSB_a16(uint32_t fetchdat) return 0; } static int -opMOVSB_a32(uint32_t fetchdat) +opMOVSB_a32(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -71,7 +71,7 @@ opMOVSB_a32(uint32_t fetchdat) } static int -opMOVSW_a16(uint32_t fetchdat) +opMOVSW_a16(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -107,7 +107,7 @@ opMOVSW_a16(uint32_t fetchdat) return 0; } static int -opMOVSW_a32(uint32_t fetchdat) +opMOVSW_a32(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -144,7 +144,7 @@ opMOVSW_a32(uint32_t fetchdat) } static int -opMOVSL_a16(uint32_t fetchdat) +opMOVSL_a16(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -180,7 +180,7 @@ opMOVSL_a16(uint32_t fetchdat) return 0; } static int -opMOVSL_a32(uint32_t fetchdat) +opMOVSL_a32(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -217,7 +217,7 @@ opMOVSL_a32(uint32_t fetchdat) } static int -opCMPSB_a16(uint32_t fetchdat) +opCMPSB_a16(UNUSED(uint32_t fetchdat)) { uint8_t src; uint8_t dst; @@ -258,7 +258,7 @@ opCMPSB_a16(uint32_t fetchdat) return 0; } static int -opCMPSB_a32(uint32_t fetchdat) +opCMPSB_a32(UNUSED(uint32_t fetchdat)) { uint8_t src; uint8_t dst; @@ -300,7 +300,7 @@ opCMPSB_a32(uint32_t fetchdat) } static int -opCMPSW_a16(uint32_t fetchdat) +opCMPSW_a16(UNUSED(uint32_t fetchdat)) { uint16_t src; uint16_t dst; @@ -342,7 +342,7 @@ opCMPSW_a16(uint32_t fetchdat) return 0; } static int -opCMPSW_a32(uint32_t fetchdat) +opCMPSW_a32(UNUSED(uint32_t fetchdat)) { uint16_t src; uint16_t dst; @@ -385,7 +385,7 @@ opCMPSW_a32(uint32_t fetchdat) } static int -opCMPSL_a16(uint32_t fetchdat) +opCMPSL_a16(UNUSED(uint32_t fetchdat)) { uint32_t src; uint32_t dst; @@ -427,7 +427,7 @@ opCMPSL_a16(uint32_t fetchdat) return 0; } static int -opCMPSL_a32(uint32_t fetchdat) +opCMPSL_a32(UNUSED(uint32_t fetchdat)) { uint32_t src; uint32_t dst; @@ -470,7 +470,7 @@ opCMPSL_a32(uint32_t fetchdat) } static int -opSTOSB_a16(uint32_t fetchdat) +opSTOSB_a16(UNUSED(uint32_t fetchdat)) { SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_WRITE(&cpu_state.seg_es, DI, DI); @@ -486,7 +486,7 @@ opSTOSB_a16(uint32_t fetchdat) return 0; } static int -opSTOSB_a32(uint32_t fetchdat) +opSTOSB_a32(UNUSED(uint32_t fetchdat)) { SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_WRITE(&cpu_state.seg_es, EDI, EDI); @@ -503,7 +503,7 @@ opSTOSB_a32(uint32_t fetchdat) } static int -opSTOSW_a16(uint32_t fetchdat) +opSTOSW_a16(UNUSED(uint32_t fetchdat)) { SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_WRITE(&cpu_state.seg_es, DI, DI + 1UL); @@ -519,7 +519,7 @@ opSTOSW_a16(uint32_t fetchdat) return 0; } static int -opSTOSW_a32(uint32_t fetchdat) +opSTOSW_a32(UNUSED(uint32_t fetchdat)) { SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_WRITE(&cpu_state.seg_es, EDI, EDI + 1UL); @@ -536,7 +536,7 @@ opSTOSW_a32(uint32_t fetchdat) } static int -opSTOSL_a16(uint32_t fetchdat) +opSTOSL_a16(UNUSED(uint32_t fetchdat)) { SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_WRITE(&cpu_state.seg_es, DI, DI + 3UL); @@ -552,7 +552,7 @@ opSTOSL_a16(uint32_t fetchdat) return 0; } static int -opSTOSL_a32(uint32_t fetchdat) +opSTOSL_a32(UNUSED(uint32_t fetchdat)) { SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_WRITE(&cpu_state.seg_es, EDI, EDI + 3UL); @@ -569,7 +569,7 @@ opSTOSL_a32(uint32_t fetchdat) } static int -opLODSB_a16(uint32_t fetchdat) +opLODSB_a16(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -588,7 +588,7 @@ opLODSB_a16(uint32_t fetchdat) return 0; } static int -opLODSB_a32(uint32_t fetchdat) +opLODSB_a32(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -608,7 +608,7 @@ opLODSB_a32(uint32_t fetchdat) } static int -opLODSW_a16(uint32_t fetchdat) +opLODSW_a16(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -627,7 +627,7 @@ opLODSW_a16(uint32_t fetchdat) return 0; } static int -opLODSW_a32(uint32_t fetchdat) +opLODSW_a32(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -647,7 +647,7 @@ opLODSW_a32(uint32_t fetchdat) } static int -opLODSL_a16(uint32_t fetchdat) +opLODSL_a16(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -666,7 +666,7 @@ opLODSL_a16(uint32_t fetchdat) return 0; } static int -opLODSL_a32(uint32_t fetchdat) +opLODSL_a32(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -686,7 +686,7 @@ opLODSL_a32(uint32_t fetchdat) } static int -opSCASB_a16(uint32_t fetchdat) +opSCASB_a16(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -705,7 +705,7 @@ opSCASB_a16(uint32_t fetchdat) return 0; } static int -opSCASB_a32(uint32_t fetchdat) +opSCASB_a32(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -725,7 +725,7 @@ opSCASB_a32(uint32_t fetchdat) } static int -opSCASW_a16(uint32_t fetchdat) +opSCASW_a16(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -744,7 +744,7 @@ opSCASW_a16(uint32_t fetchdat) return 0; } static int -opSCASW_a32(uint32_t fetchdat) +opSCASW_a32(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -764,7 +764,7 @@ opSCASW_a32(uint32_t fetchdat) } static int -opSCASL_a16(uint32_t fetchdat) +opSCASL_a16(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -783,7 +783,7 @@ opSCASL_a16(uint32_t fetchdat) return 0; } static int -opSCASL_a32(uint32_t fetchdat) +opSCASL_a32(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -803,7 +803,7 @@ opSCASL_a32(uint32_t fetchdat) } static int -opINSB_a16(uint32_t fetchdat) +opINSB_a16(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -829,7 +829,7 @@ opINSB_a16(uint32_t fetchdat) return 0; } static int -opINSB_a32(uint32_t fetchdat) +opINSB_a32(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -856,7 +856,7 @@ opINSB_a32(uint32_t fetchdat) } static int -opINSW_a16(uint32_t fetchdat) +opINSW_a16(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -882,7 +882,7 @@ opINSW_a16(uint32_t fetchdat) return 0; } static int -opINSW_a32(uint32_t fetchdat) +opINSW_a32(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -909,7 +909,7 @@ opINSW_a32(uint32_t fetchdat) } static int -opINSL_a16(uint32_t fetchdat) +opINSL_a16(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -935,7 +935,7 @@ opINSL_a16(uint32_t fetchdat) return 0; } static int -opINSL_a32(uint32_t fetchdat) +opINSL_a32(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -962,7 +962,7 @@ opINSL_a32(uint32_t fetchdat) } static int -opOUTSB_a16(uint32_t fetchdat) +opOUTSB_a16(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -982,7 +982,7 @@ opOUTSB_a16(uint32_t fetchdat) return 0; } static int -opOUTSB_a32(uint32_t fetchdat) +opOUTSB_a32(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -1003,7 +1003,7 @@ opOUTSB_a32(uint32_t fetchdat) } static int -opOUTSW_a16(uint32_t fetchdat) +opOUTSW_a16(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -1023,7 +1023,7 @@ opOUTSW_a16(uint32_t fetchdat) return 0; } static int -opOUTSW_a32(uint32_t fetchdat) +opOUTSW_a32(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -1044,7 +1044,7 @@ opOUTSW_a32(uint32_t fetchdat) } static int -opOUTSL_a16(uint32_t fetchdat) +opOUTSL_a16(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -1064,7 +1064,7 @@ opOUTSL_a16(uint32_t fetchdat) return 0; } static int -opOUTSL_a32(uint32_t fetchdat) +opOUTSL_a32(UNUSED(uint32_t fetchdat)) { uint32_t temp; diff --git a/src/cpu/x86_ops_string_2386.h b/src/cpu/x86_ops_string_2386.h index 98875e54f..32d69d4b2 100644 --- a/src/cpu/x86_ops_string_2386.h +++ b/src/cpu/x86_ops_string_2386.h @@ -1,5 +1,5 @@ static int -opMOVSB_a16(uint32_t fetchdat) +opMOVSB_a16(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -35,7 +35,7 @@ opMOVSB_a16(uint32_t fetchdat) return 0; } static int -opMOVSB_a32(uint32_t fetchdat) +opMOVSB_a32(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -71,7 +71,7 @@ opMOVSB_a32(uint32_t fetchdat) } static int -opMOVSW_a16(uint32_t fetchdat) +opMOVSW_a16(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -107,7 +107,7 @@ opMOVSW_a16(uint32_t fetchdat) return 0; } static int -opMOVSW_a32(uint32_t fetchdat) +opMOVSW_a32(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -144,7 +144,7 @@ opMOVSW_a32(uint32_t fetchdat) } static int -opMOVSL_a16(uint32_t fetchdat) +opMOVSL_a16(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -180,7 +180,7 @@ opMOVSL_a16(uint32_t fetchdat) return 0; } static int -opMOVSL_a32(uint32_t fetchdat) +opMOVSL_a32(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -217,7 +217,7 @@ opMOVSL_a32(uint32_t fetchdat) } static int -opCMPSB_a16(uint32_t fetchdat) +opCMPSB_a16(UNUSED(uint32_t fetchdat)) { uint8_t src; uint8_t dst; @@ -254,7 +254,7 @@ opCMPSB_a16(uint32_t fetchdat) return 0; } static int -opCMPSB_a32(uint32_t fetchdat) +opCMPSB_a32(UNUSED(uint32_t fetchdat)) { uint8_t src; uint8_t dst; @@ -292,7 +292,7 @@ opCMPSB_a32(uint32_t fetchdat) } static int -opCMPSW_a16(uint32_t fetchdat) +opCMPSW_a16(UNUSED(uint32_t fetchdat)) { uint16_t src; uint16_t dst; @@ -330,7 +330,7 @@ opCMPSW_a16(uint32_t fetchdat) return 0; } static int -opCMPSW_a32(uint32_t fetchdat) +opCMPSW_a32(UNUSED(uint32_t fetchdat)) { uint16_t src; uint16_t dst; @@ -369,7 +369,7 @@ opCMPSW_a32(uint32_t fetchdat) } static int -opCMPSL_a16(uint32_t fetchdat) +opCMPSL_a16(UNUSED(uint32_t fetchdat)) { uint32_t src; uint32_t dst; @@ -407,7 +407,7 @@ opCMPSL_a16(uint32_t fetchdat) return 0; } static int -opCMPSL_a32(uint32_t fetchdat) +opCMPSL_a32(UNUSED(uint32_t fetchdat)) { uint32_t src; uint32_t dst; @@ -446,7 +446,7 @@ opCMPSL_a32(uint32_t fetchdat) } static int -opSTOSB_a16(uint32_t fetchdat) +opSTOSB_a16(UNUSED(uint32_t fetchdat)) { SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_WRITE(&cpu_state.seg_es, DI, DI); @@ -462,7 +462,7 @@ opSTOSB_a16(uint32_t fetchdat) return 0; } static int -opSTOSB_a32(uint32_t fetchdat) +opSTOSB_a32(UNUSED(uint32_t fetchdat)) { SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_WRITE(&cpu_state.seg_es, EDI, EDI); @@ -479,7 +479,7 @@ opSTOSB_a32(uint32_t fetchdat) } static int -opSTOSW_a16(uint32_t fetchdat) +opSTOSW_a16(UNUSED(uint32_t fetchdat)) { SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_WRITE(&cpu_state.seg_es, DI, DI + 1UL); @@ -495,7 +495,7 @@ opSTOSW_a16(uint32_t fetchdat) return 0; } static int -opSTOSW_a32(uint32_t fetchdat) +opSTOSW_a32(UNUSED(uint32_t fetchdat)) { SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_WRITE(&cpu_state.seg_es, EDI, EDI + 1UL); @@ -512,7 +512,7 @@ opSTOSW_a32(uint32_t fetchdat) } static int -opSTOSL_a16(uint32_t fetchdat) +opSTOSL_a16(UNUSED(uint32_t fetchdat)) { SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_WRITE(&cpu_state.seg_es, DI, DI + 3UL); @@ -528,7 +528,7 @@ opSTOSL_a16(uint32_t fetchdat) return 0; } static int -opSTOSL_a32(uint32_t fetchdat) +opSTOSL_a32(UNUSED(uint32_t fetchdat)) { SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_WRITE(&cpu_state.seg_es, EDI, EDI + 3UL); @@ -545,7 +545,7 @@ opSTOSL_a32(uint32_t fetchdat) } static int -opLODSB_a16(uint32_t fetchdat) +opLODSB_a16(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -564,7 +564,7 @@ opLODSB_a16(uint32_t fetchdat) return 0; } static int -opLODSB_a32(uint32_t fetchdat) +opLODSB_a32(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -584,7 +584,7 @@ opLODSB_a32(uint32_t fetchdat) } static int -opLODSW_a16(uint32_t fetchdat) +opLODSW_a16(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -603,7 +603,7 @@ opLODSW_a16(uint32_t fetchdat) return 0; } static int -opLODSW_a32(uint32_t fetchdat) +opLODSW_a32(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -623,7 +623,7 @@ opLODSW_a32(uint32_t fetchdat) } static int -opLODSL_a16(uint32_t fetchdat) +opLODSL_a16(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -642,7 +642,7 @@ opLODSL_a16(uint32_t fetchdat) return 0; } static int -opLODSL_a32(uint32_t fetchdat) +opLODSL_a32(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -662,7 +662,7 @@ opLODSL_a32(uint32_t fetchdat) } static int -opSCASB_a16(uint32_t fetchdat) +opSCASB_a16(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -681,7 +681,7 @@ opSCASB_a16(uint32_t fetchdat) return 0; } static int -opSCASB_a32(uint32_t fetchdat) +opSCASB_a32(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -701,7 +701,7 @@ opSCASB_a32(uint32_t fetchdat) } static int -opSCASW_a16(uint32_t fetchdat) +opSCASW_a16(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -720,7 +720,7 @@ opSCASW_a16(uint32_t fetchdat) return 0; } static int -opSCASW_a32(uint32_t fetchdat) +opSCASW_a32(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -740,7 +740,7 @@ opSCASW_a32(uint32_t fetchdat) } static int -opSCASL_a16(uint32_t fetchdat) +opSCASL_a16(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -759,7 +759,7 @@ opSCASL_a16(uint32_t fetchdat) return 0; } static int -opSCASL_a32(uint32_t fetchdat) +opSCASL_a32(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -779,7 +779,7 @@ opSCASL_a32(uint32_t fetchdat) } static int -opINSB_a16(uint32_t fetchdat) +opINSB_a16(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -805,7 +805,7 @@ opINSB_a16(uint32_t fetchdat) return 0; } static int -opINSB_a32(uint32_t fetchdat) +opINSB_a32(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -832,7 +832,7 @@ opINSB_a32(uint32_t fetchdat) } static int -opINSW_a16(uint32_t fetchdat) +opINSW_a16(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -858,7 +858,7 @@ opINSW_a16(uint32_t fetchdat) return 0; } static int -opINSW_a32(uint32_t fetchdat) +opINSW_a32(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -885,7 +885,7 @@ opINSW_a32(uint32_t fetchdat) } static int -opINSL_a16(uint32_t fetchdat) +opINSL_a16(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -911,7 +911,7 @@ opINSL_a16(uint32_t fetchdat) return 0; } static int -opINSL_a32(uint32_t fetchdat) +opINSL_a32(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -938,7 +938,7 @@ opINSL_a32(uint32_t fetchdat) } static int -opOUTSB_a16(uint32_t fetchdat) +opOUTSB_a16(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -958,7 +958,7 @@ opOUTSB_a16(uint32_t fetchdat) return 0; } static int -opOUTSB_a32(uint32_t fetchdat) +opOUTSB_a32(UNUSED(uint32_t fetchdat)) { uint8_t temp; @@ -979,7 +979,7 @@ opOUTSB_a32(uint32_t fetchdat) } static int -opOUTSW_a16(uint32_t fetchdat) +opOUTSW_a16(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -999,7 +999,7 @@ opOUTSW_a16(uint32_t fetchdat) return 0; } static int -opOUTSW_a32(uint32_t fetchdat) +opOUTSW_a32(UNUSED(uint32_t fetchdat)) { uint16_t temp; @@ -1020,7 +1020,7 @@ opOUTSW_a32(uint32_t fetchdat) } static int -opOUTSL_a16(uint32_t fetchdat) +opOUTSL_a16(UNUSED(uint32_t fetchdat)) { uint32_t temp; @@ -1040,7 +1040,7 @@ opOUTSL_a16(uint32_t fetchdat) return 0; } static int -opOUTSL_a32(uint32_t fetchdat) +opOUTSL_a32(UNUSED(uint32_t fetchdat)) { uint32_t temp; diff --git a/src/cpu/x86_ops_xchg.h b/src/cpu/x86_ops_xchg.h index 70e7be58c..826181a8e 100644 --- a/src/cpu/x86_ops_xchg.h +++ b/src/cpu/x86_ops_xchg.h @@ -116,7 +116,7 @@ opXCHG_l_a32(uint32_t fetchdat) } static int -opXCHG_AX_BX(uint32_t fetchdat) +opXCHG_AX_BX(UNUSED(uint32_t fetchdat)) { uint16_t temp = AX; AX = BX; @@ -126,7 +126,7 @@ opXCHG_AX_BX(uint32_t fetchdat) return 0; } static int -opXCHG_AX_CX(uint32_t fetchdat) +opXCHG_AX_CX(UNUSED(uint32_t fetchdat)) { uint16_t temp = AX; AX = CX; @@ -136,7 +136,7 @@ opXCHG_AX_CX(uint32_t fetchdat) return 0; } static int -opXCHG_AX_DX(uint32_t fetchdat) +opXCHG_AX_DX(UNUSED(uint32_t fetchdat)) { uint16_t temp = AX; AX = DX; @@ -146,7 +146,7 @@ opXCHG_AX_DX(uint32_t fetchdat) return 0; } static int -opXCHG_AX_SI(uint32_t fetchdat) +opXCHG_AX_SI(UNUSED(uint32_t fetchdat)) { uint16_t temp = AX; AX = SI; @@ -156,7 +156,7 @@ opXCHG_AX_SI(uint32_t fetchdat) return 0; } static int -opXCHG_AX_DI(uint32_t fetchdat) +opXCHG_AX_DI(UNUSED(uint32_t fetchdat)) { uint16_t temp = AX; AX = DI; @@ -166,7 +166,7 @@ opXCHG_AX_DI(uint32_t fetchdat) return 0; } static int -opXCHG_AX_BP(uint32_t fetchdat) +opXCHG_AX_BP(UNUSED(uint32_t fetchdat)) { uint16_t temp = AX; AX = BP; @@ -176,7 +176,7 @@ opXCHG_AX_BP(uint32_t fetchdat) return 0; } static int -opXCHG_AX_SP(uint32_t fetchdat) +opXCHG_AX_SP(UNUSED(uint32_t fetchdat)) { uint16_t temp = AX; AX = SP; @@ -187,7 +187,7 @@ opXCHG_AX_SP(uint32_t fetchdat) } static int -opXCHG_EAX_EBX(uint32_t fetchdat) +opXCHG_EAX_EBX(UNUSED(uint32_t fetchdat)) { uint32_t temp = EAX; EAX = EBX; @@ -197,7 +197,7 @@ opXCHG_EAX_EBX(uint32_t fetchdat) return 0; } static int -opXCHG_EAX_ECX(uint32_t fetchdat) +opXCHG_EAX_ECX(UNUSED(uint32_t fetchdat)) { uint32_t temp = EAX; EAX = ECX; @@ -207,7 +207,7 @@ opXCHG_EAX_ECX(uint32_t fetchdat) return 0; } static int -opXCHG_EAX_EDX(uint32_t fetchdat) +opXCHG_EAX_EDX(UNUSED(uint32_t fetchdat)) { uint32_t temp = EAX; EAX = EDX; @@ -217,7 +217,7 @@ opXCHG_EAX_EDX(uint32_t fetchdat) return 0; } static int -opXCHG_EAX_ESI(uint32_t fetchdat) +opXCHG_EAX_ESI(UNUSED(uint32_t fetchdat)) { uint32_t temp = EAX; EAX = ESI; @@ -227,7 +227,7 @@ opXCHG_EAX_ESI(uint32_t fetchdat) return 0; } static int -opXCHG_EAX_EDI(uint32_t fetchdat) +opXCHG_EAX_EDI(UNUSED(uint32_t fetchdat)) { uint32_t temp = EAX; EAX = EDI; @@ -237,7 +237,7 @@ opXCHG_EAX_EDI(uint32_t fetchdat) return 0; } static int -opXCHG_EAX_EBP(uint32_t fetchdat) +opXCHG_EAX_EBP(UNUSED(uint32_t fetchdat)) { uint32_t temp = EAX; EAX = EBP; @@ -247,7 +247,7 @@ opXCHG_EAX_EBP(uint32_t fetchdat) return 0; } static int -opXCHG_EAX_ESP(uint32_t fetchdat) +opXCHG_EAX_ESP(UNUSED(uint32_t fetchdat)) { uint32_t temp = EAX; EAX = ESP; @@ -258,7 +258,7 @@ opXCHG_EAX_ESP(uint32_t fetchdat) } #define opBSWAP(reg) \ - static int opBSWAP_##reg(uint32_t fetchdat) \ + static int opBSWAP_##reg(UNUSED(uint32_t fetchdat)) \ { \ reg = (reg >> 24) | ((reg >> 8) & 0xff00) | ((reg << 8) & 0xff0000) | ((reg << 24) & 0xff000000); \ CLOCK_CYCLES(1); \ @@ -275,4 +275,4 @@ opBSWAP(ESI) opBSWAP(EDI) opBSWAP(EBP) opBSWAP(ESP) - // clang-format on +// clang-format on diff --git a/src/cpu/x86seg.c b/src/cpu/x86seg.c index 61c0edd9f..145752237 100644 --- a/src/cpu/x86seg.c +++ b/src/cpu/x86seg.c @@ -1113,7 +1113,7 @@ loadcscall(uint16_t seg) x86seg_log("Type %04X\n", type); if (type == 0x0c00) { - PUSHL_SEL(oldss); + is586 ? PUSHL(oldss) : PUSHL_SEL(oldss); PUSHL(oldsp2); if (cpu_state.abrt) { SS = oldss; @@ -1334,6 +1334,12 @@ pmoderetf(int is32, uint16_t off) if (CPL == (seg & 0x0003)) { x86seg_log("RETF CPL = RPL %04X\n", segdat[2]); switch (segdat[2] & 0x1f00) { + case 0x1000: + case 0x1100: + case 0x1200: + case 0x1300: + /* Data segment, apparently valid when CPL is the same, used by MS LINK for DOS. */ + fallthrough; case 0x1800: case 0x1900: case 0x1a00: @@ -1384,6 +1390,12 @@ pmoderetf(int is32, uint16_t off) cycles -= timing_retf_pm; } else { switch (segdat[2] & 0x1f00) { + case 0x1000: + case 0x1100: + case 0x1200: + case 0x1300: + /* Data segment, apparently valid when CPL is the same, used by MS LINK for DOS. */ + fallthrough; case 0x1800: case 0x1900: case 0x1a00: @@ -1605,6 +1617,12 @@ pmodeint(int num, int soft) return; } switch (segdat2[2] & 0x1f00) { + case 0x1000: + case 0x1100: + case 0x1200: + case 0x1300: + /* Data segment, apparently valid when CPL is the same, used by MS CodeView for DOS. */ + fallthrough; case 0x1800: case 0x1900: case 0x1a00: @@ -1678,10 +1696,17 @@ pmodeint(int num, int soft) cpl_override = 1; if (type >= 0x0800) { if (cpu_state.eflags & VM_FLAG) { - PUSHL_SEL(GS); - PUSHL_SEL(FS); - PUSHL_SEL(DS); - PUSHL_SEL(ES); + if (is586) { + PUSHL(GS); + PUSHL(FS); + PUSHL(DS); + PUSHL(ES); + } else { + PUSHL_SEL(GS); + PUSHL_SEL(FS); + PUSHL_SEL(DS); + PUSHL_SEL(ES); + } if (cpu_state.abrt) return; op_loadseg(0, &cpu_state.seg_ds); @@ -1689,10 +1714,10 @@ pmodeint(int num, int soft) op_loadseg(0, &cpu_state.seg_fs); op_loadseg(0, &cpu_state.seg_gs); } - PUSHL_SEL(oldss); + is586 ? PUSHL(oldss) : PUSHL_SEL(oldss); PUSHL(oldsp); PUSHL(cpu_state.flags | (cpu_state.eflags << 16)); - PUSHL_SEL(CS); + is586 ? PUSHL(CS) : PUSHL_SEL(CS); PUSHL(cpu_state.pc); if (cpu_state.abrt) return; @@ -1728,7 +1753,7 @@ pmodeint(int num, int soft) } if (type > 0x0800) { PUSHL(cpu_state.flags | (cpu_state.eflags << 16)); - PUSHL_SEL(CS); + is586 ? PUSHL(CS) : PUSHL_SEL(CS); PUSHL(cpu_state.pc); if (cpu_state.abrt) return; @@ -1976,6 +2001,12 @@ pmodeiret(int is32) } switch (segdat[2] & 0x1f00) { + case 0x1000: + case 0x1100: + case 0x1200: + case 0x1300: + /* Data segment, apparently valid when CPL is the same, used by MS CodeView for DOS. */ + fallthrough; case 0x1800: case 0x1900: case 0x1a00: @@ -2574,19 +2605,17 @@ cyrix_load_seg_descriptor(uint32_t addr, x86seg *seg) cpu_cur_status &= ~CPU_STATUS_NOTFLATDS; else cpu_cur_status |= CPU_STATUS_NOTFLATDS; -#ifdef USE_DYNAREC - codegen_flat_ds = 0; -#endif } + + if (seg == &cpu_state.seg_cs) + set_use32(segdat[3] & 0x40); + if (seg == &cpu_state.seg_ss) { if (seg->base == 0 && seg->limit_low == 0 && seg->limit_high == 0xffffffff) cpu_cur_status &= ~CPU_STATUS_NOTFLATSS; else cpu_cur_status |= CPU_STATUS_NOTFLATSS; set_stack32((segdat[3] & 0x40) ? 1 : 0); -#ifdef USE_DYNAREC - codegen_flat_ss = 0; -#endif } } } diff --git a/src/cpu/x87.c b/src/cpu/x87.c index 577fa1a40..fecca0772 100644 --- a/src/cpu/x87.c +++ b/src/cpu/x87.c @@ -20,6 +20,7 @@ #include "softfloat3e/config.h" #include "softfloat3e/fpu_trans.h" #include "softfloat3e/specialize.h" +#include <86box/plat_unused.h> uint32_t x87_pc_off; uint32_t x87_op_off; @@ -312,7 +313,7 @@ FPU_write_eflags_fpu_compare(int float_relation) } uint16_t -FPU_exception(uint32_t fetchdat, uint16_t exceptions, int store) +FPU_exception(UNUSED(uint32_t fetchdat), uint16_t exceptions, int store) { uint16_t status; uint16_t unmasked; @@ -355,10 +356,10 @@ FPU_exception(uint32_t fetchdat, uint16_t exceptions, int store) nmi = 1; } #else - if (is486 && (cr0 & 0x20)) - x86_int(16); - else - picint(1 << 13); + if (cr0 & 0x20) + new_ne = 1; + else + picint(1 << 13); #endif // FPU_8087 } return unmasked; diff --git a/src/cpu/x87.h b/src/cpu/x87.h index 2ad0c7b10..4d53725c9 100644 --- a/src/cpu/x87.h +++ b/src/cpu/x87.h @@ -228,8 +228,8 @@ FPU_save_regi_tag(extFloat80_t reg, int tag, int stnr) #define FPU_check_pending_exceptions() \ do { \ if (fpu_state.swd & FPU_SW_Summary) { \ - if (is486 && (cr0 & 0x20)) \ - x86_int(16); \ + if (cr0 & 0x20) \ + new_ne = 1; \ else \ picint(1 << 13); \ return 1; \ diff --git a/src/cpu/x87_ops.h b/src/cpu/x87_ops.h index e1bc5858a..0bd8209e1 100644 --- a/src/cpu/x87_ops.h +++ b/src/cpu/x87_ops.h @@ -36,6 +36,8 @@ extern void fpu_log(const char *fmt, ...); # endif #endif +extern double exp_pow_table[0x800]; + static int rounding_modes[4] = { FE_TONEAREST, FE_DOWNWARD, FE_UPWARD, FE_TOWARDZERO }; #define ST(x) cpu_state.ST[((cpu_state.TOP + (x)) & 7)] @@ -99,8 +101,8 @@ typedef union { dst = src1 / (double) src2; \ else { \ fpu_log("FPU : divide by zero\n"); \ - if (is486 && (cr0 & 0x20)) \ - x86_int(16); \ + if (cr0 & 0x20) \ + new_ne = 1; \ else \ picint(1 << 13); \ return 1; \ @@ -241,6 +243,24 @@ x87_fround32_64(double b) return (int64_t) x87_fround32(b); } +static __inline int64_t +x87_fround_nearest(double b) +{ + double da, dc; + int64_t a, c; + + da = floor(b); + dc = floor(b + 1.0); + a = (int64_t) da; + c = (int64_t) dc; + if ((b - a) < (c - b)) + return a; + else if ((b - a) > (c - b)) + return c; + else + return (a & 1) ? c : a; +} + static __inline int64_t x87_fround(double b) { @@ -402,11 +422,19 @@ x87_compare(double a, double b) * situations, eg comparison of infinity (Unreal) */ uint32_t result = 0; double ea = a, eb = b; + const uint64_t ia = 0x3fec1a6ff866a936ULL; + const uint64_t ib = 0x3fec1a6ff866a938ULL; + + /* Hack to make CHKCOP happy. */ + if (!memcmp(&ea, &ia, 8) && !memcmp(&eb, &ib, 8)) + return FPU_SW_C3; if ((fpu_type < FPU_287XL) && !(cpu_state.npxc & 0x1000) && ((a == INFINITY) || (a == -INFINITY)) && ((b == INFINITY) || (b == -INFINITY))) eb = ea; - if (ea == eb) + if ((isnan(a) || isnan(b))) + result |= FPU_SW_C3 | FPU_SW_C2 | FPU_SW_C0; + else if (ea == eb) result |= FPU_SW_C3; else if (ea < eb) result |= FPU_SW_C0; @@ -455,7 +483,9 @@ x87_ucompare(double a, double b) * situations, eg comparison of infinity (Unreal) */ uint32_t result = 0; - if (a == b) + if ((isnan(a) || isnan(b))) + result |= FPU_SW_C3 | FPU_SW_C2 | FPU_SW_C0; + else if (a == b) result |= FPU_SW_C3; else if (a < b) result |= FPU_SW_C0; @@ -542,7 +572,7 @@ op_nofpu_a32(uint32_t fetchdat) #ifdef FPU_8087 static int -FPU_ILLEGAL_a16(uint32_t fetchdat) +FPU_ILLEGAL_a16(UNUSED(uint32_t fetchdat)) { geteaw(); wait(timing_rr, 0); @@ -1267,6 +1297,86 @@ const OpFn OP_TABLE(sf_fpu_d9_a32)[256] = { // clang-format on }; +const OpFn OP_TABLE(sf_fpu_cyrix_d9_a16)[256] = { + // clang-format off + /*0x00*/ sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, + /*0x08*/ ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + /*0x10*/ sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, + /*0x18*/ sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, + /*0x20*/ sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, + /*0x28*/ sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, + /*0x30*/ sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, + /*0x38*/ sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, + + /*0x40*/ sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, + /*0x48*/ ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + /*0x50*/ sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, + /*0x58*/ sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, + /*0x60*/ sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, + /*0x68*/ sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, + /*0x70*/ sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, + /*0x78*/ sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, + + /*0x80*/ sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, sf_FLDs_a16, + /*0x88*/ ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + /*0x90*/ sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, sf_FSTs_a16, + /*0x98*/ sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, sf_FSTPs_a16, + /*0xa0*/ sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, sf_FLDENV_a16, + /*0xa8*/ sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, sf_FLDCW_a16, + /*0xb0*/ sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, sf_FNSTENV_a16, + /*0xb8*/ sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, sf_FNSTCW_a16, + + /*0xc0*/ sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, sf_FLD_sti, + /*0xc8*/ sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, + /*0xd0*/ sf_FNOP, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + /*0xd8*/ 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*/ + /*0xe0*/ sf_FCHS, sf_FABS, ILLEGAL_a16, ILLEGAL_a16, sf_FTST, sf_FXAM, sf_FTSTP, ILLEGAL_a16, + /*0xe8*/ sf_FLD1, sf_FLDL2T, sf_FLDL2E, sf_FLDPI, sf_FLDEG2, sf_FLDLN2, sf_FLDZ, ILLEGAL_a16, + /*0xf0*/ sf_F2XM1, sf_FYL2X, sf_FPTAN, sf_FPATAN, sf_FXTRACT, sf_FPREM1, sf_FDECSTP, sf_FINCSTP, + /*0xf8*/ 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_cyrix_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, sf_FTSTP, 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, @@ -1750,6 +1860,87 @@ const OpFn OP_TABLE(sf_fpu_686_db_a32)[256] = { }; # endif +# ifndef OPS_286_386 +const OpFn OP_TABLE(sf_fpu_cyrix_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, sf_FRINT2, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + // clang-format on +}; +const OpFn OP_TABLE(sf_fpu_cyrix_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, sf_FRINT2, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + // clang-format on +}; +# endif + 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, @@ -1946,6 +2137,86 @@ const OpFn OP_TABLE(sf_fpu_dd_a32)[256] = { // clang-format on }; +const OpFn OP_TABLE(sf_fpu_cyrix_dd_a16)[256] = { + // clang-format off + /*0x00*/ sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, + /*0x08*/ ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + /*0x10*/ sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, + /*0x18*/ sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, + /*0x20*/ sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, + /*0x28*/ ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + /*0x30*/ sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, + /*0x38*/ sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, + + /*0x40*/ sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, + /*0x48*/ ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + /*0x50*/ sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, + /*0x58*/ sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, + /*0x60*/ sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, + /*0x68*/ ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + /*0x70*/ sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, + /*0x78*/ sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, + + /*0x80*/ sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, sf_FLDd_a16, + /*0x88*/ ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + /*0x90*/ sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, sf_FSTd_a16, + /*0x98*/ sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, sf_FSTPd_a16, + /*0xa0*/ sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, sf_FRSTOR_a16, + /*0xa8*/ ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + /*0xb0*/ sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, sf_FNSAVE_a16, + /*0xb8*/ sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, sf_FNSTSW_a16, + + /*0xc0*/ sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, sf_FFREE_sti, + /*0xc8*/ sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, sf_FXCH_sti, + /*0xd0*/ sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, sf_FST_sti, + /*0xd8*/ sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, sf_FSTP_sti, + /*0xe0*/ sf_FUCOM_sti, sf_FUCOM_sti, sf_FUCOM_sti, sf_FUCOM_sti, sf_FUCOM_sti, sf_FUCOM_sti, sf_FUCOM_sti, sf_FUCOM_sti, + /*0xe8*/ sf_FUCOMP_sti, sf_FUCOMP_sti, sf_FUCOMP_sti, sf_FUCOMP_sti, sf_FUCOMP_sti, sf_FUCOMP_sti, sf_FUCOMP_sti, sf_FUCOMP_sti, + /*0xf0*/ ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + /*0xf8*/ ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, sf_FRICHOP, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_cyrix_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, sf_FRICHOP, 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, @@ -2348,6 +2619,88 @@ const OpFn OP_TABLE(sf_fpu_686_df_a32)[256] = { }; # endif +# ifndef OPS_286_386 +const OpFn OP_TABLE(sf_fpu_cyrix_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, + sf_FBLD_PACKED_BCD_a16, sf_FBLD_PACKED_BCD_a16, sf_FBLD_PACKED_BCD_a16, sf_FBLD_PACKED_BCD_a16, sf_FBLD_PACKED_BCD_a16, sf_FBLD_PACKED_BCD_a16, sf_FBLD_PACKED_BCD_a16, sf_FBLD_PACKED_BCD_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, + sf_FBLD_PACKED_BCD_a16, sf_FBLD_PACKED_BCD_a16, sf_FBLD_PACKED_BCD_a16, sf_FBLD_PACKED_BCD_a16, sf_FBLD_PACKED_BCD_a16, sf_FBLD_PACKED_BCD_a16, sf_FBLD_PACKED_BCD_a16, sf_FBLD_PACKED_BCD_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, + sf_FBLD_PACKED_BCD_a16, sf_FBLD_PACKED_BCD_a16, sf_FBLD_PACKED_BCD_a16, sf_FBLD_PACKED_BCD_a16, sf_FBLD_PACKED_BCD_a16, sf_FBLD_PACKED_BCD_a16, sf_FBLD_PACKED_BCD_a16, sf_FBLD_PACKED_BCD_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, sf_FRINEAR, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + // clang-format on +}; + +const OpFn OP_TABLE(sf_fpu_cyrix_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, + sf_FBLD_PACKED_BCD_a32, sf_FBLD_PACKED_BCD_a32, sf_FBLD_PACKED_BCD_a32, sf_FBLD_PACKED_BCD_a32, sf_FBLD_PACKED_BCD_a32, sf_FBLD_PACKED_BCD_a32, sf_FBLD_PACKED_BCD_a32, sf_FBLD_PACKED_BCD_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, + sf_FBLD_PACKED_BCD_a32, sf_FBLD_PACKED_BCD_a32, sf_FBLD_PACKED_BCD_a32, sf_FBLD_PACKED_BCD_a32, sf_FBLD_PACKED_BCD_a32, sf_FBLD_PACKED_BCD_a32, sf_FBLD_PACKED_BCD_a32, sf_FBLD_PACKED_BCD_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, + sf_FBLD_PACKED_BCD_a32, sf_FBLD_PACKED_BCD_a32, sf_FBLD_PACKED_BCD_a32, sf_FBLD_PACKED_BCD_a32, sf_FBLD_PACKED_BCD_a32, sf_FBLD_PACKED_BCD_a32, sf_FBLD_PACKED_BCD_a32, sf_FBLD_PACKED_BCD_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, sf_FRINEAR, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + // clang-format on +}; +# endif + 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, @@ -2526,6 +2879,86 @@ const OpFn OP_TABLE(fpu_d9_a32)[256] = { // clang-format on }; +const OpFn OP_TABLE(fpu_cyrix_d9_a16)[256] = { + // clang-format off + opFLDs_a16, opFLDs_a16, opFLDs_a16, opFLDs_a16, opFLDs_a16, opFLDs_a16, opFLDs_a16, opFLDs_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + opFSTs_a16, opFSTs_a16, opFSTs_a16, opFSTs_a16, opFSTs_a16, opFSTs_a16, opFSTs_a16, opFSTs_a16, + opFSTPs_a16, opFSTPs_a16, opFSTPs_a16, opFSTPs_a16, opFSTPs_a16, opFSTPs_a16, opFSTPs_a16, opFSTPs_a16, + opFLDENV_a16, opFLDENV_a16, opFLDENV_a16, opFLDENV_a16, opFLDENV_a16, opFLDENV_a16, opFLDENV_a16, opFLDENV_a16, + opFLDCW_a16, opFLDCW_a16, opFLDCW_a16, opFLDCW_a16, opFLDCW_a16, opFLDCW_a16, opFLDCW_a16, opFLDCW_a16, + opFSTENV_a16, opFSTENV_a16, opFSTENV_a16, opFSTENV_a16, opFSTENV_a16, opFSTENV_a16, opFSTENV_a16, opFSTENV_a16, + opFSTCW_a16, opFSTCW_a16, opFSTCW_a16, opFSTCW_a16, opFSTCW_a16, opFSTCW_a16, opFSTCW_a16, opFSTCW_a16, + + opFLDs_a16, opFLDs_a16, opFLDs_a16, opFLDs_a16, opFLDs_a16, opFLDs_a16, opFLDs_a16, opFLDs_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + opFSTs_a16, opFSTs_a16, opFSTs_a16, opFSTs_a16, opFSTs_a16, opFSTs_a16, opFSTs_a16, opFSTs_a16, + opFSTPs_a16, opFSTPs_a16, opFSTPs_a16, opFSTPs_a16, opFSTPs_a16, opFSTPs_a16, opFSTPs_a16, opFSTPs_a16, + opFLDENV_a16, opFLDENV_a16, opFLDENV_a16, opFLDENV_a16, opFLDENV_a16, opFLDENV_a16, opFLDENV_a16, opFLDENV_a16, + opFLDCW_a16, opFLDCW_a16, opFLDCW_a16, opFLDCW_a16, opFLDCW_a16, opFLDCW_a16, opFLDCW_a16, opFLDCW_a16, + opFSTENV_a16, opFSTENV_a16, opFSTENV_a16, opFSTENV_a16, opFSTENV_a16, opFSTENV_a16, opFSTENV_a16, opFSTENV_a16, + opFSTCW_a16, opFSTCW_a16, opFSTCW_a16, opFSTCW_a16, opFSTCW_a16, opFSTCW_a16, opFSTCW_a16, opFSTCW_a16, + + opFLDs_a16, opFLDs_a16, opFLDs_a16, opFLDs_a16, opFLDs_a16, opFLDs_a16, opFLDs_a16, opFLDs_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + opFSTs_a16, opFSTs_a16, opFSTs_a16, opFSTs_a16, opFSTs_a16, opFSTs_a16, opFSTs_a16, opFSTs_a16, + opFSTPs_a16, opFSTPs_a16, opFSTPs_a16, opFSTPs_a16, opFSTPs_a16, opFSTPs_a16, opFSTPs_a16, opFSTPs_a16, + opFLDENV_a16, opFLDENV_a16, opFLDENV_a16, opFLDENV_a16, opFLDENV_a16, opFLDENV_a16, opFLDENV_a16, opFLDENV_a16, + opFLDCW_a16, opFLDCW_a16, opFLDCW_a16, opFLDCW_a16, opFLDCW_a16, opFLDCW_a16, opFLDCW_a16, opFLDCW_a16, + opFSTENV_a16, opFSTENV_a16, opFSTENV_a16, opFSTENV_a16, opFSTENV_a16, opFSTENV_a16, opFSTENV_a16, opFSTENV_a16, + opFSTCW_a16, opFSTCW_a16, opFSTCW_a16, opFSTCW_a16, opFSTCW_a16, opFSTCW_a16, opFSTCW_a16, opFSTCW_a16, + + opFLD, opFLD, opFLD, opFLD, opFLD, opFLD, opFLD, opFLD, + opFXCH, opFXCH, opFXCH, opFXCH, opFXCH, opFXCH, opFXCH, opFXCH, + opFNOP, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, /*Invalid*/ + opFCHS, opFABS, ILLEGAL_a16, ILLEGAL_a16, opFTST, opFXAM, opFTSTP, ILLEGAL_a16, + opFLD1, opFLDL2T, opFLDL2E, opFLDPI, opFLDEG2, opFLDLN2, opFLDZ, ILLEGAL_a16, + opF2XM1, opFYL2X, opFPTAN, opFPATAN, opFXTRACT, opFPREM1, opFDECSTP, opFINCSTP, + opFPREM, opFYL2XP1, opFSQRT, opFSINCOS, opFRNDINT, opFSCALE, opFSIN, opFCOS + // clang-format on +}; + +const OpFn OP_TABLE(fpu_cyrix_d9_a32)[256] = { + // clang-format off + opFLDs_a32, opFLDs_a32, opFLDs_a32, opFLDs_a32, opFLDs_a32, opFLDs_a32, opFLDs_a32, opFLDs_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + opFSTs_a32, opFSTs_a32, opFSTs_a32, opFSTs_a32, opFSTs_a32, opFSTs_a32, opFSTs_a32, opFSTs_a32, + opFSTPs_a32, opFSTPs_a32, opFSTPs_a32, opFSTPs_a32, opFSTPs_a32, opFSTPs_a32, opFSTPs_a32, opFSTPs_a32, + opFLDENV_a32, opFLDENV_a32, opFLDENV_a32, opFLDENV_a32, opFLDENV_a32, opFLDENV_a32, opFLDENV_a32, opFLDENV_a32, + opFLDCW_a32, opFLDCW_a32, opFLDCW_a32, opFLDCW_a32, opFLDCW_a32, opFLDCW_a32, opFLDCW_a32, opFLDCW_a32, + opFSTENV_a32, opFSTENV_a32, opFSTENV_a32, opFSTENV_a32, opFSTENV_a32, opFSTENV_a32, opFSTENV_a32, opFSTENV_a32, + opFSTCW_a32, opFSTCW_a32, opFSTCW_a32, opFSTCW_a32, opFSTCW_a32, opFSTCW_a32, opFSTCW_a32, opFSTCW_a32, + + opFLDs_a32, opFLDs_a32, opFLDs_a32, opFLDs_a32, opFLDs_a32, opFLDs_a32, opFLDs_a32, opFLDs_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + opFSTs_a32, opFSTs_a32, opFSTs_a32, opFSTs_a32, opFSTs_a32, opFSTs_a32, opFSTs_a32, opFSTs_a32, + opFSTPs_a32, opFSTPs_a32, opFSTPs_a32, opFSTPs_a32, opFSTPs_a32, opFSTPs_a32, opFSTPs_a32, opFSTPs_a32, + opFLDENV_a32, opFLDENV_a32, opFLDENV_a32, opFLDENV_a32, opFLDENV_a32, opFLDENV_a32, opFLDENV_a32, opFLDENV_a32, + opFLDCW_a32, opFLDCW_a32, opFLDCW_a32, opFLDCW_a32, opFLDCW_a32, opFLDCW_a32, opFLDCW_a32, opFLDCW_a32, + opFSTENV_a32, opFSTENV_a32, opFSTENV_a32, opFSTENV_a32, opFSTENV_a32, opFSTENV_a32, opFSTENV_a32, opFSTENV_a32, + opFSTCW_a32, opFSTCW_a32, opFSTCW_a32, opFSTCW_a32, opFSTCW_a32, opFSTCW_a32, opFSTCW_a32, opFSTCW_a32, + + opFLDs_a32, opFLDs_a32, opFLDs_a32, opFLDs_a32, opFLDs_a32, opFLDs_a32, opFLDs_a32, opFLDs_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + opFSTs_a32, opFSTs_a32, opFSTs_a32, opFSTs_a32, opFSTs_a32, opFSTs_a32, opFSTs_a32, opFSTs_a32, + opFSTPs_a32, opFSTPs_a32, opFSTPs_a32, opFSTPs_a32, opFSTPs_a32, opFSTPs_a32, opFSTPs_a32, opFSTPs_a32, + opFLDENV_a32, opFLDENV_a32, opFLDENV_a32, opFLDENV_a32, opFLDENV_a32, opFLDENV_a32, opFLDENV_a32, opFLDENV_a32, + opFLDCW_a32, opFLDCW_a32, opFLDCW_a32, opFLDCW_a32, opFLDCW_a32, opFLDCW_a32, opFLDCW_a32, opFLDCW_a32, + opFSTENV_a32, opFSTENV_a32, opFSTENV_a32, opFSTENV_a32, opFSTENV_a32, opFSTENV_a32, opFSTENV_a32, opFSTENV_a32, + opFSTCW_a32, opFSTCW_a32, opFSTCW_a32, opFSTCW_a32, opFSTCW_a32, opFSTCW_a32, opFSTCW_a32, opFSTCW_a32, + + opFLD, opFLD, opFLD, opFLD, opFLD, opFLD, opFLD, opFLD, + opFXCH, opFXCH, opFXCH, opFXCH, opFXCH, opFXCH, opFXCH, opFXCH, + opFNOP, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, /*Invalid*/ + opFCHS, opFABS, ILLEGAL_a32, ILLEGAL_a32, opFTST, opFXAM, opFTSTP, ILLEGAL_a32, + opFLD1, opFLDL2T, opFLDL2E, opFLDPI, opFLDEG2, opFLDLN2, opFLDZ, ILLEGAL_a32, + opF2XM1, opFYL2X, opFPTAN, opFPATAN, opFXTRACT, opFPREM1, opFDECSTP, opFINCSTP, + opFPREM, opFYL2XP1, opFSQRT, opFSINCOS, opFRNDINT, opFSCALE, opFSIN, opFCOS + // clang-format on +}; + const OpFn OP_TABLE(fpu_287_da_a16)[256] = { // clang-format off opFADDil_a16, opFADDil_a16, opFADDil_a16, opFADDil_a16, opFADDil_a16, opFADDil_a16, opFADDil_a16, opFADDil_a16, @@ -3009,6 +3442,87 @@ const OpFn OP_TABLE(fpu_686_db_a32)[256] = { }; # endif +# ifndef OPS_286_386 +const OpFn OP_TABLE(fpu_cyrix_686_db_a16)[256] = { + // clang-format off + opFILDil_a16, opFILDil_a16, opFILDil_a16, opFILDil_a16, opFILDil_a16, opFILDil_a16, opFILDil_a16, opFILDil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + opFISTil_a16, opFISTil_a16, opFISTil_a16, opFISTil_a16, opFISTil_a16, opFISTil_a16, opFISTil_a16, opFISTil_a16, + opFISTPil_a16, opFISTPil_a16, opFISTPil_a16, opFISTPil_a16, opFISTPil_a16, opFISTPil_a16, opFISTPil_a16, opFISTPil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + opFLDe_a16, opFLDe_a16, opFLDe_a16, opFLDe_a16, opFLDe_a16, opFLDe_a16, opFLDe_a16, opFLDe_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + opFSTPe_a16, opFSTPe_a16, opFSTPe_a16, opFSTPe_a16, opFSTPe_a16, opFSTPe_a16, opFSTPe_a16, opFSTPe_a16, + + opFILDil_a16, opFILDil_a16, opFILDil_a16, opFILDil_a16, opFILDil_a16, opFILDil_a16, opFILDil_a16, opFILDil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + opFISTil_a16, opFISTil_a16, opFISTil_a16, opFISTil_a16, opFISTil_a16, opFISTil_a16, opFISTil_a16, opFISTil_a16, + opFISTPil_a16, opFISTPil_a16, opFISTPil_a16, opFISTPil_a16, opFISTPil_a16, opFISTPil_a16, opFISTPil_a16, opFISTPil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + opFLDe_a16, opFLDe_a16, opFLDe_a16, opFLDe_a16, opFLDe_a16, opFLDe_a16, opFLDe_a16, opFLDe_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + opFSTPe_a16, opFSTPe_a16, opFSTPe_a16, opFSTPe_a16, opFSTPe_a16, opFSTPe_a16, opFSTPe_a16, opFSTPe_a16, + + opFILDil_a16, opFILDil_a16, opFILDil_a16, opFILDil_a16, opFILDil_a16, opFILDil_a16, opFILDil_a16, opFILDil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + opFISTil_a16, opFISTil_a16, opFISTil_a16, opFISTil_a16, opFISTil_a16, opFISTil_a16, opFISTil_a16, opFISTil_a16, + opFISTPil_a16, opFISTPil_a16, opFISTPil_a16, opFISTPil_a16, opFISTPil_a16, opFISTPil_a16, opFISTPil_a16, opFISTPil_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + opFLDe_a16, opFLDe_a16, opFLDe_a16, opFLDe_a16, opFLDe_a16, opFLDe_a16, opFLDe_a16, opFLDe_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + opFSTPe_a16, opFSTPe_a16, opFSTPe_a16, opFSTPe_a16, opFSTPe_a16, opFSTPe_a16, opFSTPe_a16, opFSTPe_a16, + + opFCMOVNB, opFCMOVNB, opFCMOVNB, opFCMOVNB, opFCMOVNB, opFCMOVNB, opFCMOVNB, opFCMOVNB, + opFCMOVNE, opFCMOVNE, opFCMOVNE, opFCMOVNE, opFCMOVNE, opFCMOVNE, opFCMOVNE, opFCMOVNE, + opFCMOVNBE, opFCMOVNBE, opFCMOVNBE, opFCMOVNBE, opFCMOVNBE, opFCMOVNBE, opFCMOVNBE, opFCMOVNBE, + opFCMOVNU, opFCMOVNU, opFCMOVNU, opFCMOVNU, opFCMOVNU, opFCMOVNU, opFCMOVNU, opFCMOVNU, + opFNOP, opFNOP, opFCLEX, opFINIT, opFNOP, opFNOP, ILLEGAL_a16, ILLEGAL_a16, + opFUCOMI, opFUCOMI, opFUCOMI, opFUCOMI, opFUCOMI, opFUCOMI, opFUCOMI, opFUCOMI, + opFCOMI, opFCOMI, opFCOMI, opFCOMI, opFCOMI, opFCOMI, opFCOMI, opFCOMI, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, opFRINT2, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + // clang-format on +}; +const OpFn OP_TABLE(fpu_cyrix_686_db_a32)[256] = { + // clang-format off + opFILDil_a32, opFILDil_a32, opFILDil_a32, opFILDil_a32, opFILDil_a32, opFILDil_a32, opFILDil_a32, opFILDil_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + opFISTil_a32, opFISTil_a32, opFISTil_a32, opFISTil_a32, opFISTil_a32, opFISTil_a32, opFISTil_a32, opFISTil_a32, + opFISTPil_a32, opFISTPil_a32, opFISTPil_a32, opFISTPil_a32, opFISTPil_a32, opFISTPil_a32, opFISTPil_a32, opFISTPil_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + opFLDe_a32, opFLDe_a32, opFLDe_a32, opFLDe_a32, opFLDe_a32, opFLDe_a32, opFLDe_a32, opFLDe_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + opFSTPe_a32, opFSTPe_a32, opFSTPe_a32, opFSTPe_a32, opFSTPe_a32, opFSTPe_a32, opFSTPe_a32, opFSTPe_a32, + + opFILDil_a32, opFILDil_a32, opFILDil_a32, opFILDil_a32, opFILDil_a32, opFILDil_a32, opFILDil_a32, opFILDil_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + opFISTil_a32, opFISTil_a32, opFISTil_a32, opFISTil_a32, opFISTil_a32, opFISTil_a32, opFISTil_a32, opFISTil_a32, + opFISTPil_a32, opFISTPil_a32, opFISTPil_a32, opFISTPil_a32, opFISTPil_a32, opFISTPil_a32, opFISTPil_a32, opFISTPil_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + opFLDe_a32, opFLDe_a32, opFLDe_a32, opFLDe_a32, opFLDe_a32, opFLDe_a32, opFLDe_a32, opFLDe_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + opFSTPe_a32, opFSTPe_a32, opFSTPe_a32, opFSTPe_a32, opFSTPe_a32, opFSTPe_a32, opFSTPe_a32, opFSTPe_a32, + + opFILDil_a32, opFILDil_a32, opFILDil_a32, opFILDil_a32, opFILDil_a32, opFILDil_a32, opFILDil_a32, opFILDil_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + opFISTil_a32, opFISTil_a32, opFISTil_a32, opFISTil_a32, opFISTil_a32, opFISTil_a32, opFISTil_a32, opFISTil_a32, + opFISTPil_a32, opFISTPil_a32, opFISTPil_a32, opFISTPil_a32, opFISTPil_a32, opFISTPil_a32, opFISTPil_a32, opFISTPil_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + opFLDe_a32, opFLDe_a32, opFLDe_a32, opFLDe_a32, opFLDe_a32, opFLDe_a32, opFLDe_a32, opFLDe_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + opFSTPe_a32, opFSTPe_a32, opFSTPe_a32, opFSTPe_a32, opFSTPe_a32, opFSTPe_a32, opFSTPe_a32, opFSTPe_a32, + + opFCMOVNB, opFCMOVNB, opFCMOVNB, opFCMOVNB, opFCMOVNB, opFCMOVNB, opFCMOVNB, opFCMOVNB, + opFCMOVNE, opFCMOVNE, opFCMOVNE, opFCMOVNE, opFCMOVNE, opFCMOVNE, opFCMOVNE, opFCMOVNE, + opFCMOVNBE, opFCMOVNBE, opFCMOVNBE, opFCMOVNBE, opFCMOVNBE, opFCMOVNBE, opFCMOVNBE, opFCMOVNBE, + opFCMOVNU, opFCMOVNU, opFCMOVNU, opFCMOVNU, opFCMOVNU, opFCMOVNU, opFCMOVNU, opFCMOVNU, + opFNOP, opFNOP, opFCLEX, opFINIT, opFNOP, opFNOP, ILLEGAL_a32, ILLEGAL_a32, + opFUCOMI, opFUCOMI, opFUCOMI, opFUCOMI, opFUCOMI, opFUCOMI, opFUCOMI, opFUCOMI, + opFCOMI, opFCOMI, opFCOMI, opFCOMI, opFCOMI, opFCOMI, opFCOMI, opFCOMI, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, opFRINT2, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + // clang-format on +}; +# endif + const OpFn OP_TABLE(fpu_287_dc_a16)[32] = { // clang-format off opFADDd_a16, opFMULd_a16, opFCOMd_a16, opFCOMPd_a16, opFSUBd_a16, opFSUBRd_a16, opFDIVd_a16, opFDIVRd_a16, @@ -3205,6 +3719,86 @@ const OpFn OP_TABLE(fpu_dd_a32)[256] = { // clang-format on }; +const OpFn OP_TABLE(fpu_cyrix_dd_a16)[256] = { + // clang-format off + opFLDd_a16, opFLDd_a16, opFLDd_a16, opFLDd_a16, opFLDd_a16, opFLDd_a16, opFLDd_a16, opFLDd_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + opFSTd_a16, opFSTd_a16, opFSTd_a16, opFSTd_a16, opFSTd_a16, opFSTd_a16, opFSTd_a16, opFSTd_a16, + opFSTPd_a16, opFSTPd_a16, opFSTPd_a16, opFSTPd_a16, opFSTPd_a16, opFSTPd_a16, opFSTPd_a16, opFSTPd_a16, + opFSTOR_a16, opFSTOR_a16, opFSTOR_a16, opFSTOR_a16, opFSTOR_a16, opFSTOR_a16, opFSTOR_a16, opFSTOR_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + opFSAVE_a16, opFSAVE_a16, opFSAVE_a16, opFSAVE_a16, opFSAVE_a16, opFSAVE_a16, opFSAVE_a16, opFSAVE_a16, + opFSTSW_a16, opFSTSW_a16, opFSTSW_a16, opFSTSW_a16, opFSTSW_a16, opFSTSW_a16, opFSTSW_a16, opFSTSW_a16, + + opFLDd_a16, opFLDd_a16, opFLDd_a16, opFLDd_a16, opFLDd_a16, opFLDd_a16, opFLDd_a16, opFLDd_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + opFSTd_a16, opFSTd_a16, opFSTd_a16, opFSTd_a16, opFSTd_a16, opFSTd_a16, opFSTd_a16, opFSTd_a16, + opFSTPd_a16, opFSTPd_a16, opFSTPd_a16, opFSTPd_a16, opFSTPd_a16, opFSTPd_a16, opFSTPd_a16, opFSTPd_a16, + opFSTOR_a16, opFSTOR_a16, opFSTOR_a16, opFSTOR_a16, opFSTOR_a16, opFSTOR_a16, opFSTOR_a16, opFSTOR_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + opFSAVE_a16, opFSAVE_a16, opFSAVE_a16, opFSAVE_a16, opFSAVE_a16, opFSAVE_a16, opFSAVE_a16, opFSAVE_a16, + opFSTSW_a16, opFSTSW_a16, opFSTSW_a16, opFSTSW_a16, opFSTSW_a16, opFSTSW_a16, opFSTSW_a16, opFSTSW_a16, + + opFLDd_a16, opFLDd_a16, opFLDd_a16, opFLDd_a16, opFLDd_a16, opFLDd_a16, opFLDd_a16, opFLDd_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + opFSTd_a16, opFSTd_a16, opFSTd_a16, opFSTd_a16, opFSTd_a16, opFSTd_a16, opFSTd_a16, opFSTd_a16, + opFSTPd_a16, opFSTPd_a16, opFSTPd_a16, opFSTPd_a16, opFSTPd_a16, opFSTPd_a16, opFSTPd_a16, opFSTPd_a16, + opFSTOR_a16, opFSTOR_a16, opFSTOR_a16, opFSTOR_a16, opFSTOR_a16, opFSTOR_a16, opFSTOR_a16, opFSTOR_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + opFSAVE_a16, opFSAVE_a16, opFSAVE_a16, opFSAVE_a16, opFSAVE_a16, opFSAVE_a16, opFSAVE_a16, opFSAVE_a16, + opFSTSW_a16, opFSTSW_a16, opFSTSW_a16, opFSTSW_a16, opFSTSW_a16, opFSTSW_a16, opFSTSW_a16, opFSTSW_a16, + + opFFREE, opFFREE, opFFREE, opFFREE, opFFREE, opFFREE, opFFREE, opFFREE, + opFXCH, opFXCH, opFXCH, opFXCH, opFXCH, opFXCH, opFXCH, opFXCH, + opFST, opFST, opFST, opFST, opFST, opFST, opFST, opFST, + opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, + opFUCOM, opFUCOM, opFUCOM, opFUCOM, opFUCOM, opFUCOM, opFUCOM, opFUCOM, + opFUCOMP, opFUCOMP, opFUCOMP, opFUCOMP, opFUCOMP, opFUCOMP, opFUCOMP, opFUCOMP, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, opFRICHOP, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + // clang-format on +}; + +const OpFn OP_TABLE(fpu_cyrix_dd_a32)[256] = { + // clang-format off + opFLDd_a32, opFLDd_a32, opFLDd_a32, opFLDd_a32, opFLDd_a32, opFLDd_a32, opFLDd_a32, opFLDd_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + opFSTd_a32, opFSTd_a32, opFSTd_a32, opFSTd_a32, opFSTd_a32, opFSTd_a32, opFSTd_a32, opFSTd_a32, + opFSTPd_a32, opFSTPd_a32, opFSTPd_a32, opFSTPd_a32, opFSTPd_a32, opFSTPd_a32, opFSTPd_a32, opFSTPd_a32, + opFSTOR_a32, opFSTOR_a32, opFSTOR_a32, opFSTOR_a32, opFSTOR_a32, opFSTOR_a32, opFSTOR_a32, opFSTOR_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + opFSAVE_a32, opFSAVE_a32, opFSAVE_a32, opFSAVE_a32, opFSAVE_a32, opFSAVE_a32, opFSAVE_a32, opFSAVE_a32, + opFSTSW_a32, opFSTSW_a32, opFSTSW_a32, opFSTSW_a32, opFSTSW_a32, opFSTSW_a32, opFSTSW_a32, opFSTSW_a32, + + opFLDd_a32, opFLDd_a32, opFLDd_a32, opFLDd_a32, opFLDd_a32, opFLDd_a32, opFLDd_a32, opFLDd_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + opFSTd_a32, opFSTd_a32, opFSTd_a32, opFSTd_a32, opFSTd_a32, opFSTd_a32, opFSTd_a32, opFSTd_a32, + opFSTPd_a32, opFSTPd_a32, opFSTPd_a32, opFSTPd_a32, opFSTPd_a32, opFSTPd_a32, opFSTPd_a32, opFSTPd_a32, + opFSTOR_a32, opFSTOR_a32, opFSTOR_a32, opFSTOR_a32, opFSTOR_a32, opFSTOR_a32, opFSTOR_a32, opFSTOR_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + opFSAVE_a32, opFSAVE_a32, opFSAVE_a32, opFSAVE_a32, opFSAVE_a32, opFSAVE_a32, opFSAVE_a32, opFSAVE_a32, + opFSTSW_a32, opFSTSW_a32, opFSTSW_a32, opFSTSW_a32, opFSTSW_a32, opFSTSW_a32, opFSTSW_a32, opFSTSW_a32, + + opFLDd_a32, opFLDd_a32, opFLDd_a32, opFLDd_a32, opFLDd_a32, opFLDd_a32, opFLDd_a32, opFLDd_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + opFSTd_a32, opFSTd_a32, opFSTd_a32, opFSTd_a32, opFSTd_a32, opFSTd_a32, opFSTd_a32, opFSTd_a32, + opFSTPd_a32, opFSTPd_a32, opFSTPd_a32, opFSTPd_a32, opFSTPd_a32, opFSTPd_a32, opFSTPd_a32, opFSTPd_a32, + opFSTOR_a32, opFSTOR_a32, opFSTOR_a32, opFSTOR_a32, opFSTOR_a32, opFSTOR_a32, opFSTOR_a32, opFSTOR_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + opFSAVE_a32, opFSAVE_a32, opFSAVE_a32, opFSAVE_a32, opFSAVE_a32, opFSAVE_a32, opFSAVE_a32, opFSAVE_a32, + opFSTSW_a32, opFSTSW_a32, opFSTSW_a32, opFSTSW_a32, opFSTSW_a32, opFSTSW_a32, opFSTSW_a32, opFSTSW_a32, + + opFFREE, opFFREE, opFFREE, opFFREE, opFFREE, opFFREE, opFFREE, opFFREE, + opFXCH, opFXCH, opFXCH, opFXCH, opFXCH, opFXCH, opFXCH, opFXCH, + opFST, opFST, opFST, opFST, opFST, opFST, opFST, opFST, + opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, + opFUCOM, opFUCOM, opFUCOM, opFUCOM, opFUCOM, opFUCOM, opFUCOM, opFUCOM, + opFUCOMP, opFUCOMP, opFUCOMP, opFUCOMP, opFUCOMP, opFUCOMP, opFUCOMP, opFUCOMP, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, opFRICHOP, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + // clang-format on +}; + const OpFn OP_TABLE(fpu_287_de_a16)[256] = { // clang-format off opFADDiw_a16, opFADDiw_a16, opFADDiw_a16, opFADDiw_a16, opFADDiw_a16, opFADDiw_a16, opFADDiw_a16, opFADDiw_a16, @@ -3607,6 +4201,88 @@ const OpFn OP_TABLE(fpu_686_df_a32)[256] = { }; # endif +# ifndef OPS_286_386 +const OpFn OP_TABLE(fpu_cyrix_686_df_a16)[256] = { + // clang-format off + opFILDiw_a16, opFILDiw_a16, opFILDiw_a16, opFILDiw_a16, opFILDiw_a16, opFILDiw_a16, opFILDiw_a16, opFILDiw_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + opFISTiw_a16, opFISTiw_a16, opFISTiw_a16, opFISTiw_a16, opFISTiw_a16, opFISTiw_a16, opFISTiw_a16, opFISTiw_a16, + opFISTPiw_a16, opFISTPiw_a16, opFISTPiw_a16, opFISTPiw_a16, opFISTPiw_a16, opFISTPiw_a16, opFISTPiw_a16, opFISTPiw_a16, + FBLD_a16, FBLD_a16, FBLD_a16, FBLD_a16, FBLD_a16, FBLD_a16, FBLD_a16, FBLD_a16, + opFILDiq_a16, opFILDiq_a16, opFILDiq_a16, opFILDiq_a16, opFILDiq_a16, opFILDiq_a16, opFILDiq_a16, opFILDiq_a16, + FBSTP_a16, FBSTP_a16, FBSTP_a16, FBSTP_a16, FBSTP_a16, FBSTP_a16, FBSTP_a16, FBSTP_a16, + FISTPiq_a16, FISTPiq_a16, FISTPiq_a16, FISTPiq_a16, FISTPiq_a16, FISTPiq_a16, FISTPiq_a16, FISTPiq_a16, + + opFILDiw_a16, opFILDiw_a16, opFILDiw_a16, opFILDiw_a16, opFILDiw_a16, opFILDiw_a16, opFILDiw_a16, opFILDiw_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + opFISTiw_a16, opFISTiw_a16, opFISTiw_a16, opFISTiw_a16, opFISTiw_a16, opFISTiw_a16, opFISTiw_a16, opFISTiw_a16, + opFISTPiw_a16, opFISTPiw_a16, opFISTPiw_a16, opFISTPiw_a16, opFISTPiw_a16, opFISTPiw_a16, opFISTPiw_a16, opFISTPiw_a16, + FBLD_a16, FBLD_a16, FBLD_a16, FBLD_a16, FBLD_a16, FBLD_a16, FBLD_a16, FBLD_a16, + opFILDiq_a16, opFILDiq_a16, opFILDiq_a16, opFILDiq_a16, opFILDiq_a16, opFILDiq_a16, opFILDiq_a16, opFILDiq_a16, + FBSTP_a16, FBSTP_a16, FBSTP_a16, FBSTP_a16, FBSTP_a16, FBSTP_a16, FBSTP_a16, FBSTP_a16, + FISTPiq_a16, FISTPiq_a16, FISTPiq_a16, FISTPiq_a16, FISTPiq_a16, FISTPiq_a16, FISTPiq_a16, FISTPiq_a16, + + opFILDiw_a16, opFILDiw_a16, opFILDiw_a16, opFILDiw_a16, opFILDiw_a16, opFILDiw_a16, opFILDiw_a16, opFILDiw_a16, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + opFISTiw_a16, opFISTiw_a16, opFISTiw_a16, opFISTiw_a16, opFISTiw_a16, opFISTiw_a16, opFISTiw_a16, opFISTiw_a16, + opFISTPiw_a16, opFISTPiw_a16, opFISTPiw_a16, opFISTPiw_a16, opFISTPiw_a16, opFISTPiw_a16, opFISTPiw_a16, opFISTPiw_a16, + FBLD_a16, FBLD_a16, FBLD_a16, FBLD_a16, FBLD_a16, FBLD_a16, FBLD_a16, FBLD_a16, + opFILDiq_a16, opFILDiq_a16, opFILDiq_a16, opFILDiq_a16, opFILDiq_a16, opFILDiq_a16, opFILDiq_a16, opFILDiq_a16, + FBSTP_a16, FBSTP_a16, FBSTP_a16, FBSTP_a16, FBSTP_a16, FBSTP_a16, FBSTP_a16, FBSTP_a16, + FISTPiq_a16, FISTPiq_a16, FISTPiq_a16, FISTPiq_a16, FISTPiq_a16, FISTPiq_a16, FISTPiq_a16, FISTPiq_a16, + + opFFREEP, opFFREEP, opFFREEP, opFFREEP, opFFREEP, opFFREEP, opFFREEP, opFFREEP, + opFXCH, opFXCH, opFXCH, opFXCH, opFXCH, opFXCH, opFXCH, opFXCH, + opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, + opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, + opFSTSW_AX, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + opFUCOMIP, opFUCOMIP, opFUCOMIP, opFUCOMIP, opFUCOMIP, opFUCOMIP, opFUCOMIP, opFUCOMIP, + opFCOMIP, opFCOMIP, opFCOMIP, opFCOMIP, opFCOMIP, opFCOMIP, opFCOMIP, opFCOMIP, + ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, opFRINEAR, ILLEGAL_a16, ILLEGAL_a16, ILLEGAL_a16, + // clang-format on +}; + +const OpFn OP_TABLE(fpu_cyrix_686_df_a32)[256] = { + // clang-format off + opFILDiw_a32, opFILDiw_a32, opFILDiw_a32, opFILDiw_a32, opFILDiw_a32, opFILDiw_a32, opFILDiw_a32, opFILDiw_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + opFISTiw_a32, opFISTiw_a32, opFISTiw_a32, opFISTiw_a32, opFISTiw_a32, opFISTiw_a32, opFISTiw_a32, opFISTiw_a32, + opFISTPiw_a32, opFISTPiw_a32, opFISTPiw_a32, opFISTPiw_a32, opFISTPiw_a32, opFISTPiw_a32, opFISTPiw_a32, opFISTPiw_a32, + FBLD_a32, FBLD_a32, FBLD_a32, FBLD_a32, FBLD_a32, FBLD_a32, FBLD_a32, FBLD_a32, + opFILDiq_a32, opFILDiq_a32, opFILDiq_a32, opFILDiq_a32, opFILDiq_a32, opFILDiq_a32, opFILDiq_a32, opFILDiq_a32, + FBSTP_a32, FBSTP_a32, FBSTP_a32, FBSTP_a32, FBSTP_a32, FBSTP_a32, FBSTP_a32, FBSTP_a32, + FISTPiq_a32, FISTPiq_a32, FISTPiq_a32, FISTPiq_a32, FISTPiq_a32, FISTPiq_a32, FISTPiq_a32, FISTPiq_a32, + + opFILDiw_a32, opFILDiw_a32, opFILDiw_a32, opFILDiw_a32, opFILDiw_a32, opFILDiw_a32, opFILDiw_a32, opFILDiw_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + opFISTiw_a32, opFISTiw_a32, opFISTiw_a32, opFISTiw_a32, opFISTiw_a32, opFISTiw_a32, opFISTiw_a32, opFISTiw_a32, + opFISTPiw_a32, opFISTPiw_a32, opFISTPiw_a32, opFISTPiw_a32, opFISTPiw_a32, opFISTPiw_a32, opFISTPiw_a32, opFISTPiw_a32, + FBLD_a32, FBLD_a32, FBLD_a32, FBLD_a32, FBLD_a32, FBLD_a32, FBLD_a32, FBLD_a32, + opFILDiq_a32, opFILDiq_a32, opFILDiq_a32, opFILDiq_a32, opFILDiq_a32, opFILDiq_a32, opFILDiq_a32, opFILDiq_a32, + FBSTP_a32, FBSTP_a32, FBSTP_a32, FBSTP_a32, FBSTP_a32, FBSTP_a32, FBSTP_a32, FBSTP_a32, + FISTPiq_a32, FISTPiq_a32, FISTPiq_a32, FISTPiq_a32, FISTPiq_a32, FISTPiq_a32, FISTPiq_a32, FISTPiq_a32, + + opFILDiw_a32, opFILDiw_a32, opFILDiw_a32, opFILDiw_a32, opFILDiw_a32, opFILDiw_a32, opFILDiw_a32, opFILDiw_a32, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + opFISTiw_a32, opFISTiw_a32, opFISTiw_a32, opFISTiw_a32, opFISTiw_a32, opFISTiw_a32, opFISTiw_a32, opFISTiw_a32, + opFISTPiw_a32, opFISTPiw_a32, opFISTPiw_a32, opFISTPiw_a32, opFISTPiw_a32, opFISTPiw_a32, opFISTPiw_a32, opFISTPiw_a32, + FBLD_a32, FBLD_a32, FBLD_a32, FBLD_a32, FBLD_a32, FBLD_a32, FBLD_a32, FBLD_a32, + opFILDiq_a32, opFILDiq_a32, opFILDiq_a32, opFILDiq_a32, opFILDiq_a32, opFILDiq_a32, opFILDiq_a32, opFILDiq_a32, + FBSTP_a32, FBSTP_a32, FBSTP_a32, FBSTP_a32, FBSTP_a32, FBSTP_a32, FBSTP_a32, FBSTP_a32, + FISTPiq_a32, FISTPiq_a32, FISTPiq_a32, FISTPiq_a32, FISTPiq_a32, FISTPiq_a32, FISTPiq_a32, FISTPiq_a32, + + opFFREEP, opFFREEP, opFFREEP, opFFREEP, opFFREEP, opFFREEP, opFFREEP, opFFREEP, + opFXCH, opFXCH, opFXCH, opFXCH, opFXCH, opFXCH, opFXCH, opFXCH, + opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, + opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, opFSTP, + opFSTSW_AX, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + opFUCOMIP, opFUCOMIP, opFUCOMIP, opFUCOMIP, opFUCOMIP, opFUCOMIP, opFUCOMIP, opFUCOMIP, + opFCOMIP, opFCOMIP, opFCOMIP, opFCOMIP, opFCOMIP, opFCOMIP, opFCOMIP, opFCOMIP, + ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, opFRINEAR, ILLEGAL_a32, ILLEGAL_a32, ILLEGAL_a32, + // clang-format on +}; +# endif + const OpFn OP_TABLE(nofpu_a16)[256] = { // clang-format off op_nofpu_a16, op_nofpu_a16, op_nofpu_a16, op_nofpu_a16, op_nofpu_a16, op_nofpu_a16, op_nofpu_a16, op_nofpu_a16, diff --git a/src/cpu/x87_ops_arith.h b/src/cpu/x87_ops_arith.h index 31c26231b..8d0c02167 100644 --- a/src/cpu/x87_ops_arith.h +++ b/src/cpu/x87_ops_arith.h @@ -1,5 +1,5 @@ #define opFPU(name, optype, a_size, load_var, get, use_var, cycle_postfix) \ - static int opFADD##name##_a##a_size(uint32_t fetchdat) \ + static int opFADD##name##_a##a_size(UNUSED(uint32_t fetchdat)) \ { \ optype t; \ FP_ENTER(); \ @@ -18,7 +18,7 @@ CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fadd##cycle_postfix) : ((x87_concurrency.fadd##cycle_postfix) * cpu_multi)); \ return 0; \ } \ - static int opFCOM##name##_a##a_size(uint32_t fetchdat) \ + static int opFCOM##name##_a##a_size(UNUSED(uint32_t fetchdat)) \ { \ optype t; \ FP_ENTER(); \ @@ -27,13 +27,13 @@ load_var = get(); \ if (cpu_state.abrt) \ return 1; \ - cpu_state.npxs &= ~(FPU_SW_C0 | FPU_SW_C2 | FPU_SW_C3); \ + cpu_state.npxs &= ~(FPU_SW_C0 | FPU_SW_C2 | FPU_SW_C3); \ cpu_state.npxs |= x87_compare(ST(0), (double) use_var); \ 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 opFCOMP##name##_a##a_size(uint32_t fetchdat) \ + static int opFCOMP##name##_a##a_size(UNUSED(uint32_t fetchdat)) \ { \ optype t; \ FP_ENTER(); \ @@ -42,14 +42,14 @@ load_var = get(); \ if (cpu_state.abrt) \ return 1; \ - cpu_state.npxs &= ~(FPU_SW_C0 | FPU_SW_C2 | FPU_SW_C3); \ + cpu_state.npxs &= ~(FPU_SW_C0 | FPU_SW_C2 | FPU_SW_C3); \ cpu_state.npxs |= x87_compare(ST(0), (double) use_var); \ x87_pop(); \ 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 opFDIV##name##_a##a_size(uint32_t fetchdat) \ + static int opFDIV##name##_a##a_size(UNUSED(uint32_t fetchdat)) \ { \ optype t; \ FP_ENTER(); \ @@ -64,7 +64,7 @@ CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fadd##cycle_postfix) : ((x87_concurrency.fadd##cycle_postfix) * cpu_multi)); \ return 0; \ } \ - static int opFDIVR##name##_a##a_size(uint32_t fetchdat) \ + static int opFDIVR##name##_a##a_size(UNUSED(uint32_t fetchdat)) \ { \ optype t; \ FP_ENTER(); \ @@ -79,7 +79,7 @@ CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fdiv##cycle_postfix) : ((x87_concurrency.fdiv##cycle_postfix) * cpu_multi)); \ return 0; \ } \ - static int opFMUL##name##_a##a_size(uint32_t fetchdat) \ + static int opFMUL##name##_a##a_size(UNUSED(uint32_t fetchdat)) \ { \ optype t; \ FP_ENTER(); \ @@ -94,7 +94,7 @@ CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fmul##cycle_postfix) : ((x87_concurrency.fmul##cycle_postfix) * cpu_multi)); \ return 0; \ } \ - static int opFSUB##name##_a##a_size(uint32_t fetchdat) \ + static int opFSUB##name##_a##a_size(UNUSED(uint32_t fetchdat)) \ { \ optype t; \ FP_ENTER(); \ @@ -109,7 +109,7 @@ CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.fadd##cycle_postfix) : ((x87_concurrency.fadd##cycle_postfix) * cpu_multi)); \ return 0; \ } \ - static int opFSUBR##name##_a##a_size(uint32_t fetchdat) \ + static int opFSUBR##name##_a##a_size(UNUSED(uint32_t fetchdat)) \ { \ optype t; \ FP_ENTER(); \ @@ -208,7 +208,7 @@ opFCOMP(uint32_t fetchdat) } static int -opFCOMPP(uint32_t fetchdat) +opFCOMPP(UNUSED(uint32_t fetchdat)) { uint64_t *p, *q; FP_ENTER(); @@ -229,7 +229,7 @@ opFCOMPP(uint32_t fetchdat) } #ifndef FPU_8087 static int -opFUCOMPP(uint32_t fetchdat) +opFUCOMPP(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; diff --git a/src/cpu/x87_ops_loadstore.h b/src/cpu/x87_ops_loadstore.h index 0936f325b..d0b31ac85 100644 --- a/src/cpu/x87_ops_loadstore.h +++ b/src/cpu/x87_ops_loadstore.h @@ -17,7 +17,7 @@ * Copyright 2016-2019 Miran Grca. */ static int -opFILDiw_a16(uint32_t fetchdat) +opFILDiw_a16(UNUSED(uint32_t fetchdat)) { int16_t temp; FP_ENTER(); @@ -50,7 +50,7 @@ opFILDiw_a32(uint32_t fetchdat) #endif static int -opFISTiw_a16(uint32_t fetchdat) +opFISTiw_a16(UNUSED(uint32_t fetchdat)) { FP_ENTER(); fetch_ea_16(fetchdat); @@ -75,7 +75,7 @@ opFISTiw_a32(uint32_t fetchdat) #endif static int -opFISTPiw_a16(uint32_t fetchdat) +opFISTPiw_a16(UNUSED(uint32_t fetchdat)) { FP_ENTER(); fetch_ea_16(fetchdat); @@ -106,7 +106,7 @@ opFISTPiw_a32(uint32_t fetchdat) #endif static int -opFILDiq_a16(uint32_t fetchdat) +opFILDiq_a16(UNUSED(uint32_t fetchdat)) { int64_t temp64; FP_ENTER(); @@ -145,7 +145,7 @@ opFILDiq_a32(uint32_t fetchdat) #endif static int -FBLD_a16(uint32_t fetchdat) +FBLD_a16(UNUSED(uint32_t fetchdat)) { uint16_t load_reg_hi = 0xffff; uint64_t load_reg_lo = BX_CONST64(0xC000000000000000); @@ -228,7 +228,7 @@ FBLD_a32(uint32_t fetchdat) #endif static int -FBSTP_a16(uint32_t fetchdat) +FBSTP_a16(UNUSED(uint32_t fetchdat)) { double dt; double tempd; @@ -296,7 +296,7 @@ FBSTP_a32(uint32_t fetchdat) #endif static int -FISTPiq_a16(uint32_t fetchdat) +FISTPiq_a16(UNUSED(uint32_t fetchdat)) { int64_t temp64; FP_ENTER(); @@ -337,7 +337,7 @@ FISTPiq_a32(uint32_t fetchdat) #endif static int -opFILDil_a16(uint32_t fetchdat) +opFILDil_a16(UNUSED(uint32_t fetchdat)) { int32_t templ; FP_ENTER(); @@ -370,7 +370,7 @@ opFILDil_a32(uint32_t fetchdat) #endif static int -opFISTil_a16(uint32_t fetchdat) +opFISTil_a16(UNUSED(uint32_t fetchdat)) { FP_ENTER(); fetch_ea_16(fetchdat); @@ -395,7 +395,7 @@ opFISTil_a32(uint32_t fetchdat) #endif static int -opFISTPil_a16(uint32_t fetchdat) +opFISTPil_a16(UNUSED(uint32_t fetchdat)) { FP_ENTER(); fetch_ea_16(fetchdat); @@ -426,7 +426,7 @@ opFISTPil_a32(uint32_t fetchdat) #endif static int -opFLDe_a16(uint32_t fetchdat) +opFLDe_a16(UNUSED(uint32_t fetchdat)) { double t; FP_ENTER(); @@ -459,7 +459,7 @@ opFLDe_a32(uint32_t fetchdat) #endif static int -opFSTPe_a16(uint32_t fetchdat) +opFSTPe_a16(UNUSED(uint32_t fetchdat)) { FP_ENTER(); fetch_ea_16(fetchdat); @@ -490,7 +490,7 @@ opFSTPe_a32(uint32_t fetchdat) #endif static int -opFLDd_a16(uint32_t fetchdat) +opFLDd_a16(UNUSED(uint32_t fetchdat)) { x87_td t; FP_ENTER(); @@ -523,7 +523,7 @@ opFLDd_a32(uint32_t fetchdat) #endif static int -opFSTd_a16(uint32_t fetchdat) +opFSTd_a16(UNUSED(uint32_t fetchdat)) { x87_td t; FP_ENTER(); @@ -552,7 +552,7 @@ opFSTd_a32(uint32_t fetchdat) #endif static int -opFSTPd_a16(uint32_t fetchdat) +opFSTPd_a16(UNUSED(uint32_t fetchdat)) { x87_td t; FP_ENTER(); @@ -587,7 +587,7 @@ opFSTPd_a32(uint32_t fetchdat) #endif static int -opFLDs_a16(uint32_t fetchdat) +opFLDs_a16(UNUSED(uint32_t fetchdat)) { x87_ts ts; FP_ENTER(); @@ -620,7 +620,7 @@ opFLDs_a32(uint32_t fetchdat) #endif static int -opFSTs_a16(uint32_t fetchdat) +opFSTs_a16(UNUSED(uint32_t fetchdat)) { x87_ts ts; FP_ENTER(); @@ -649,7 +649,7 @@ opFSTs_a32(uint32_t fetchdat) #endif static int -opFSTPs_a16(uint32_t fetchdat) +opFSTPs_a16(UNUSED(uint32_t fetchdat)) { x87_ts ts; FP_ENTER(); diff --git a/src/cpu/x87_ops_misc.h b/src/cpu/x87_ops_misc.h index 96750468a..9a01f7496 100644 --- a/src/cpu/x87_ops_misc.h +++ b/src/cpu/x87_ops_misc.h @@ -12,7 +12,7 @@ opFI(uint32_t fetchdat) } #else static int -opFSTSW_AX(uint32_t fetchdat) +opFSTSW_AX(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -24,7 +24,7 @@ opFSTSW_AX(uint32_t fetchdat) #endif static int -opFNOP(uint32_t fetchdat) +opFNOP(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -34,7 +34,7 @@ opFNOP(uint32_t fetchdat) } static int -opFXTRACT(uint32_t fetchdat) +opFXTRACT(UNUSED(uint32_t fetchdat)) { x87_conv_t test; int64_t exp80; @@ -46,7 +46,7 @@ opFXTRACT(uint32_t fetchdat) test.eind.d = ST(0); exp80 = test.eind.ll & 0x7ff0000000000000LL; exp80final = (exp80 >> 52) - BIAS64; - mant = test.eind.d / (pow(2.0, (double) exp80final)); + mant = test.eind.d / exp_pow_table[exp80 >> 52]; ST(0) = (double) exp80final; FP_TAG_VALID; x87_push(mant); @@ -56,7 +56,7 @@ opFXTRACT(uint32_t fetchdat) } static int -opFCLEX(uint32_t fetchdat) +opFCLEX(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -67,7 +67,7 @@ opFCLEX(uint32_t fetchdat) } static int -opFINIT(uint32_t fetchdat) +opFINIT(UNUSED(uint32_t fetchdat)) { uint64_t *p; FP_ENTER(); @@ -208,7 +208,7 @@ FSTOR(void) return cpu_state.abrt; } static int -opFSTOR_a16(uint32_t fetchdat) +opFSTOR_a16(UNUSED(uint32_t fetchdat)) { FP_ENTER(); fetch_ea_16(fetchdat); @@ -429,7 +429,7 @@ FSAVE(void) return cpu_state.abrt; } static int -opFSAVE_a16(uint32_t fetchdat) +opFSAVE_a16(UNUSED(uint32_t fetchdat)) { FP_ENTER(); fetch_ea_16(fetchdat); @@ -450,7 +450,7 @@ opFSAVE_a32(uint32_t fetchdat) #endif static int -opFSTSW_a16(uint32_t fetchdat) +opFSTSW_a16(UNUSED(uint32_t fetchdat)) { FP_ENTER(); fetch_ea_16(fetchdat); @@ -516,7 +516,7 @@ opFXCH(uint32_t fetchdat) } static int -opFCHS(uint32_t fetchdat) +opFCHS(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -528,7 +528,7 @@ opFCHS(uint32_t fetchdat) } static int -opFABS(uint32_t fetchdat) +opFABS(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -540,7 +540,7 @@ opFABS(uint32_t fetchdat) } static int -opFTST(uint32_t fetchdat) +opFTST(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -554,8 +554,26 @@ opFTST(uint32_t fetchdat) return 0; } +#ifndef FPU_8087 static int -opFXAM(uint32_t fetchdat) +opFTSTP(UNUSED(uint32_t fetchdat)) +{ + FP_ENTER(); + cpu_state.pc++; + cpu_state.npxs &= ~(FPU_SW_C0 | FPU_SW_C2 | FPU_SW_C3); + if (ST(0) == 0.0) + cpu_state.npxs |= FPU_SW_C3; + else if (ST(0) < 0.0) + cpu_state.npxs |= FPU_SW_C0; + x87_pop(); + 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; +} +#endif + +static int +opFXAM(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -567,10 +585,24 @@ opFXAM(uint32_t fetchdat) if (cpu_state.tag[cpu_state.TOP & 7] == 3) cpu_state.npxs |= (FPU_SW_C0 | FPU_SW_C3); #endif - else if (ST(0) == 0.0) - cpu_state.npxs |= FPU_SW_C3; - else - cpu_state.npxs |= FPU_SW_C2; + else switch (fpclassify(ST(0))) + { + case FP_SUBNORMAL: + cpu_state.npxs |= FPU_SW_C2 | FPU_SW_C3; + break; + case FP_NAN: + cpu_state.npxs |= FPU_SW_C0; + break; + case FP_INFINITE: + cpu_state.npxs |= FPU_SW_C0 | FPU_SW_C2; + break; + case FP_ZERO: + cpu_state.npxs |= FPU_SW_C3; + break; + case FP_NORMAL: + cpu_state.npxs |= FPU_SW_C2; + break; + } if (ST(0) < 0.0) cpu_state.npxs |= FPU_SW_C1; CLOCK_CYCLES_FPU((fpu_type >= FPU_487SX) ? (x87_timings.fxam) : (x87_timings.fxam * cpu_multi)); @@ -579,7 +611,7 @@ opFXAM(uint32_t fetchdat) } static int -opFLD1(uint32_t fetchdat) +opFLD1(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -590,7 +622,7 @@ opFLD1(uint32_t fetchdat) } static int -opFLDL2T(uint32_t fetchdat) +opFLDL2T(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -601,7 +633,7 @@ opFLDL2T(uint32_t fetchdat) } static int -opFLDL2E(uint32_t fetchdat) +opFLDL2E(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -612,7 +644,7 @@ opFLDL2E(uint32_t fetchdat) } static int -opFLDPI(uint32_t fetchdat) +opFLDPI(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -623,7 +655,7 @@ opFLDPI(uint32_t fetchdat) } static int -opFLDEG2(uint32_t fetchdat) +opFLDEG2(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -634,7 +666,7 @@ opFLDEG2(uint32_t fetchdat) } static int -opFLDLN2(uint32_t fetchdat) +opFLDLN2(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -645,7 +677,7 @@ opFLDLN2(uint32_t fetchdat) } static int -opFLDZ(uint32_t fetchdat) +opFLDZ(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -657,7 +689,7 @@ opFLDZ(uint32_t fetchdat) } static int -opF2XM1(uint32_t fetchdat) +opF2XM1(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -669,7 +701,7 @@ opF2XM1(uint32_t fetchdat) } static int -opFYL2X(uint32_t fetchdat) +opFYL2X(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -682,7 +714,7 @@ opFYL2X(uint32_t fetchdat) } static int -opFYL2XP1(uint32_t fetchdat) +opFYL2XP1(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -695,7 +727,7 @@ opFYL2XP1(uint32_t fetchdat) } static int -opFPTAN(uint32_t fetchdat) +opFPTAN(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -709,7 +741,7 @@ opFPTAN(uint32_t fetchdat) } static int -opFPATAN(uint32_t fetchdat) +opFPATAN(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -722,7 +754,7 @@ opFPATAN(uint32_t fetchdat) } static int -opFDECSTP(uint32_t fetchdat) +opFDECSTP(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -737,7 +769,7 @@ opFDECSTP(uint32_t fetchdat) } static int -opFINCSTP(uint32_t fetchdat) +opFINCSTP(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -752,7 +784,7 @@ opFINCSTP(uint32_t fetchdat) } static int -opFPREM(uint32_t fetchdat) +opFPREM(UNUSED(uint32_t fetchdat)) { int64_t temp64; FP_ENTER(); @@ -773,7 +805,7 @@ opFPREM(uint32_t fetchdat) } static int -opFPREM1(uint32_t fetchdat) +opFPREM1(UNUSED(uint32_t fetchdat)) { int64_t temp64; FP_ENTER(); @@ -794,7 +826,7 @@ opFPREM1(uint32_t fetchdat) } static int -opFSQRT(uint32_t fetchdat) +opFSQRT(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -807,7 +839,7 @@ opFSQRT(uint32_t fetchdat) #ifndef FPU_8087 static int -opFSINCOS(uint32_t fetchdat) +opFSINCOS(UNUSED(uint32_t fetchdat)) { double td; FP_ENTER(); @@ -824,7 +856,7 @@ opFSINCOS(uint32_t fetchdat) #endif static int -opFRNDINT(uint32_t fetchdat) +opFRNDINT(UNUSED(uint32_t fetchdat)) { double dst0; @@ -838,8 +870,71 @@ opFRNDINT(uint32_t fetchdat) return 0; } +#ifndef FPU_8087 +#ifndef OPS_286_386 static int -opFSCALE(uint32_t fetchdat) +opFRINT2(UNUSED(uint32_t fetchdat)) +{ + double dst0, st0, integral, frac; + int prevRound; + + FP_ENTER(); + cpu_state.pc++; + prevRound = fegetround(); + fesetround(FE_TONEAREST); + st0 = ST(0); + frac = modf(st0, &integral); + if (frac == 0.5 || frac == -0.5) { + dst0 = (st0 < 0) ? floor(st0) : ceil(st0); + } else { + dst0 = round(st0); + } + fesetround(prevRound); + ST(0) = (double) dst0; + FP_TAG_VALID; + 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; +} + +static int +opFRINEAR(UNUSED(uint32_t fetchdat)) +{ + int prevRound; + + FP_ENTER(); + cpu_state.pc++; + prevRound = fegetround(); + fesetround(FE_TONEAREST); + ST(0) = (double) x87_fround_nearest(ST(0)); + fesetround(prevRound); + FP_TAG_VALID; + 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; +} +#endif + +static int +opFRICHOP(UNUSED(uint32_t fetchdat)) +{ + int prevRound; + + FP_ENTER(); + cpu_state.pc++; + prevRound = fegetround(); + fesetround(FE_TONEAREST); + ST(0) = (double) ((int64_t)(ST(0))); + fesetround(prevRound); + FP_TAG_VALID; + 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; +} +#endif + +static int +opFSCALE(UNUSED(uint32_t fetchdat)) { int64_t temp64; FP_ENTER(); @@ -855,7 +950,7 @@ opFSCALE(uint32_t fetchdat) #ifndef FPU_8087 static int -opFSIN(uint32_t fetchdat) +opFSIN(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -868,7 +963,7 @@ opFSIN(uint32_t fetchdat) } static int -opFCOS(uint32_t fetchdat) +opFCOS(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -909,7 +1004,7 @@ FLDENV(void) } static int -opFLDENV_a16(uint32_t fetchdat) +opFLDENV_a16(UNUSED(uint32_t fetchdat)) { FP_ENTER(); fetch_ea_16(fetchdat); @@ -930,7 +1025,7 @@ opFLDENV_a32(uint32_t fetchdat) #endif static int -opFLDCW_a16(uint32_t fetchdat) +opFLDCW_a16(UNUSED(uint32_t fetchdat)) { uint16_t tempw; FP_ENTER(); @@ -1011,7 +1106,7 @@ FSTENV(void) } static int -opFSTENV_a16(uint32_t fetchdat) +opFSTENV_a16(UNUSED(uint32_t fetchdat)) { FP_ENTER(); fetch_ea_16(fetchdat); @@ -1032,7 +1127,7 @@ opFSTENV_a32(uint32_t fetchdat) #endif static int -opFSTCW_a16(uint32_t fetchdat) +opFSTCW_a16(UNUSED(uint32_t fetchdat)) { FP_ENTER(); fetch_ea_16(fetchdat); diff --git a/src/cpu/x87_ops_sf.h b/src/cpu/x87_ops_sf.h index 31416447e..0d4fee81a 100644 --- a/src/cpu/x87_ops_sf.h +++ b/src/cpu/x87_ops_sf.h @@ -235,7 +235,7 @@ fpu_load_environment(void) } static int -sf_FLDCW_a16(uint32_t fetchdat) +sf_FLDCW_a16(UNUSED(uint32_t fetchdat)) { uint16_t tempw; @@ -288,7 +288,7 @@ sf_FLDCW_a32(uint32_t fetchdat) #endif static int -sf_FNSTCW_a16(uint32_t fetchdat) +sf_FNSTCW_a16(UNUSED(uint32_t fetchdat)) { uint16_t cwd = i387_get_control_word(); @@ -317,7 +317,7 @@ sf_FNSTCW_a32(uint32_t fetchdat) #endif static int -sf_FNSTSW_a16(uint32_t fetchdat) +sf_FNSTSW_a16(UNUSED(uint32_t fetchdat)) { uint16_t swd = i387_get_status_word(); @@ -359,7 +359,7 @@ sf_FI(uint32_t fetchdat) } #else static int -sf_FNSTSW_AX(uint32_t fetchdat) +sf_FNSTSW_AX(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -371,7 +371,7 @@ sf_FNSTSW_AX(uint32_t fetchdat) #endif static int -sf_FRSTOR_a16(uint32_t fetchdat) +sf_FRSTOR_a16(UNUSED(uint32_t fetchdat)) { floatx80 tmp; int offset; @@ -414,7 +414,7 @@ sf_FRSTOR_a32(uint32_t fetchdat) #endif static int -sf_FNSAVE_a16(uint32_t fetchdat) +sf_FNSAVE_a16(UNUSED(uint32_t fetchdat)) { floatx80 stn; int offset; @@ -488,7 +488,7 @@ sf_FNSAVE_a32(uint32_t fetchdat) #endif static int -sf_FNCLEX(uint32_t fetchdat) +sf_FNCLEX(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -499,7 +499,7 @@ sf_FNCLEX(uint32_t fetchdat) } static int -sf_FNINIT(uint32_t fetchdat) +sf_FNINIT(UNUSED(uint32_t fetchdat)) { FP_ENTER(); cpu_state.pc++; @@ -525,7 +525,7 @@ sf_FNINIT(uint32_t fetchdat) } static int -sf_FLDENV_a16(uint32_t fetchdat) +sf_FLDENV_a16(UNUSED(uint32_t fetchdat)) { int tag; @@ -572,7 +572,7 @@ sf_FLDENV_a32(uint32_t fetchdat) #endif static int -sf_FNSTENV_a16(uint32_t fetchdat) +sf_FNSTENV_a16(UNUSED(uint32_t fetchdat)) { FP_ENTER(); fetch_ea_16(fetchdat); @@ -605,7 +605,7 @@ sf_FNSTENV_a32(uint32_t fetchdat) #endif static int -sf_FNOP(uint32_t fetchdat) +sf_FNOP(UNUSED(uint32_t fetchdat)) { FP_ENTER(); FPU_check_pending_exceptions(); diff --git a/src/cpu/x87_ops_sf_arith.h b/src/cpu/x87_ops_sf_arith.h index edbd64dcf..7abde322b 100644 --- a/src/cpu/x87_ops_sf_arith.h +++ b/src/cpu/x87_ops_sf_arith.h @@ -1,7 +1,7 @@ #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; \ + floatx80 a, result; \ struct softfloat_status_t status; \ optype temp; \ FP_ENTER(); \ @@ -31,7 +31,7 @@ next_ins: } \ static int sf_FDIV##name##_a##a_size(uint32_t fetchdat) \ { \ - floatx80 a, result; \ + floatx80 a, result; \ struct softfloat_status_t status; \ optype temp; \ FP_ENTER(); \ @@ -61,7 +61,7 @@ next_ins: } \ static int sf_FDIVR##name##_a##a_size(uint32_t fetchdat) \ { \ - floatx80 a, result; \ + floatx80 a, result; \ struct softfloat_status_t status; \ optype temp; \ FP_ENTER(); \ @@ -91,7 +91,7 @@ next_ins: } \ static int sf_FMUL##name##_a##a_size(uint32_t fetchdat) \ { \ - floatx80 a, result; \ + floatx80 a, result; \ struct softfloat_status_t status; \ optype temp; \ FP_ENTER(); \ @@ -121,7 +121,7 @@ next_ins: } \ static int sf_FSUB##name##_a##a_size(uint32_t fetchdat) \ { \ - floatx80 a, result; \ + floatx80 a, result; \ struct softfloat_status_t status; \ optype temp; \ FP_ENTER(); \ @@ -151,7 +151,7 @@ next_ins: } \ static int sf_FSUBR##name##_a##a_size(uint32_t fetchdat) \ { \ - floatx80 a, result; \ + floatx80 a, result; \ struct softfloat_status_t status; \ optype temp; \ FP_ENTER(); \ @@ -800,3 +800,88 @@ next_ins: CONCURRENCY_CYCLES((fpu_type >= FPU_487SX) ? (x87_concurrency.frndint) : (x87_concurrency.frndint * cpu_multi)); return 0; } + +#ifndef FPU_8087 +#ifndef OPS_286_386 +static int +sf_FRINT2(uint32_t fetchdat) +{ + floatx80 result; + struct softfloat_status_t status; + + FP_ENTER(); + FPU_check_pending_exceptions(); + 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 = extF80_roundToInt(FPU_read_regi(0), softfloat_round_near_maxMag, true, &status); + + if (!FPU_exception(fetchdat, status.softfloat_exceptionFlags, 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; +} + +static int +sf_FRINEAR(uint32_t fetchdat) +{ + floatx80 result; + struct softfloat_status_t status; + + FP_ENTER(); + FPU_check_pending_exceptions(); + 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 = extF80_roundToInt(FPU_read_regi(0), softfloat_round_near_even, true, &status); + + if (!FPU_exception(fetchdat, status.softfloat_exceptionFlags, 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; +} +#endif + +static int +sf_FRICHOP(uint32_t fetchdat) +{ + floatx80 result; + struct softfloat_status_t status; + + FP_ENTER(); + FPU_check_pending_exceptions(); + 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 = extF80_roundToInt(FPU_read_regi(0), softfloat_round_to_zero, true, &status); + + if (!FPU_exception(fetchdat, status.softfloat_exceptionFlags, 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; +} +#endif diff --git a/src/cpu/x87_ops_sf_compare.h b/src/cpu/x87_ops_sf_compare.h index c4a38b375..d90526b82 100644 --- a/src/cpu/x87_ops_sf_compare.h +++ b/src/cpu/x87_ops_sf_compare.h @@ -459,8 +459,36 @@ sf_FTST(uint32_t fetchdat) return 0; } +#ifndef FPU_8087 static int -sf_FXAM(uint32_t fetchdat) +sf_FTSTP(uint32_t fetchdat) +{ + const floatx80 Const_Z = packFloatx80(0, 0x0000, 0); + struct softfloat_status_t status; + int rc; + + FP_ENTER(); + FPU_check_pending_exceptions(); + cpu_state.pc++; + clear_C1(); + if (IS_TAG_EMPTY(0)) { + FPU_exception(fetchdat, FPU_EX_Stack_Underflow, 0); + setcc(FPU_SW_C0 | FPU_SW_C2 | FPU_SW_C3); + } else { + status = i387cw_to_softfloat_status_word(i387_get_control_word()); + rc = extF80_compare_normal(FPU_read_regi(0), Const_Z, &status); + setcc(FPU_status_word_flags_fpu_compare(rc)); + FPU_exception(fetchdat, status.softfloat_exceptionFlags, 0); + FPU_pop(); + } + 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; +} +#endif + +static int +sf_FXAM(UNUSED(uint32_t fetchdat)) { floatx80 reg; int sign; diff --git a/src/cpu/x87_ops_sf_misc.h b/src/cpu/x87_ops_sf_misc.h index 0aab2ec08..746e85c6f 100644 --- a/src/cpu/x87_ops_sf_misc.h +++ b/src/cpu/x87_ops_sf_misc.h @@ -81,7 +81,7 @@ sf_FABS(uint32_t fetchdat) } static int -sf_FDECSTP(uint32_t fetchdat) +sf_FDECSTP(UNUSED(uint32_t fetchdat)) { FP_ENTER(); FPU_check_pending_exceptions(); @@ -94,7 +94,7 @@ sf_FDECSTP(uint32_t fetchdat) } static int -sf_FINCSTP(uint32_t fetchdat) +sf_FINCSTP(UNUSED(uint32_t fetchdat)) { FP_ENTER(); FPU_check_pending_exceptions(); diff --git a/src/ddma.c b/src/ddma.c index 7cbe2831e..0ca1bb879 100644 --- a/src/ddma.c +++ b/src/ddma.c @@ -193,7 +193,7 @@ const device_t ddma_device = { .init = ddma_init, .close = ddma_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device.c b/src/device.c index 9a904f550..910ff4ff9 100644 --- a/src/device.c +++ b/src/device.c @@ -19,7 +19,7 @@ * Copyright 2016-2019 Miran Grca. * Copyright 2008-2019 Sarah Walker. * Copyright 2021 Andreas J. Reichel. - * Copyright 2021-2022 Jasmine Iwanek. + * Copyright 2021-2025 Jasmine Iwanek. * * 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 @@ -45,6 +45,7 @@ #include #include #include +#include #define HAVE_STDARG_H #include <86box/86box.h> #include <86box/ini.h> @@ -52,8 +53,10 @@ #include <86box/device.h> #include <86box/machine.h> #include <86box/mem.h> +#include <86box/plat.h> #include <86box/rom.h> #include <86box/sound.h> +#include <86box/ui.h> #define DEVICE_MAX 256 /* max # of devices */ @@ -89,38 +92,38 @@ device_init(void) } void -device_set_context(device_context_t *c, const device_t *dev, int inst) +device_set_context(device_context_t *ctx, const device_t *dev, int inst) { - memset(c, 0, sizeof(device_context_t)); - c->dev = dev; - c->instance = inst; + memset(ctx, 0, sizeof(device_context_t)); + ctx->dev = dev; + ctx->instance = inst; if (inst) { - sprintf(c->name, "%s #%i", dev->name, inst); + sprintf(ctx->name, "%s #%i", dev->name, inst); /* If a numbered section is not present, but a non-numbered of the same name is, rename the non-numbered section to numbered. */ - const void *sec = config_find_section(c->name); + const void *sec = config_find_section(ctx->name); void * single_sec = config_find_section((char *) dev->name); if ((sec == NULL) && (single_sec != NULL)) - config_rename_section(single_sec, c->name); + config_rename_section(single_sec, ctx->name); } else if (!strcmp(dev->name, "PS/2 Mouse")) { - sprintf(c->name, "%s", dev->name); + sprintf(ctx->name, "%s", dev->name); /* Migrate the old "Standard PS/2 Mouse" section */ - const void *sec = config_find_section(c->name); + const void *sec = config_find_section(ctx->name); void * old_sec = config_find_section("Standard PS/2 Mouse"); if ((sec == NULL) && (old_sec != NULL)) - config_rename_section(old_sec, c->name); + config_rename_section(old_sec, ctx->name); } else if (!strcmp(dev->name, "Microsoft RAMCard")) { - sprintf(c->name, "%s", dev->name); + sprintf(ctx->name, "%s", dev->name); - /* Migrate the old "Standard PS/2 Mouse" section */ - const void *sec = config_find_section(c->name); + /* Migrate the old "Microsoft RAMCard for IBM PC" section */ + const void *sec = config_find_section(ctx->name); void * old_sec = config_find_section("Microsoft RAMCard for IBM PC"); if ((sec == NULL) && (old_sec != NULL)) - config_rename_section(old_sec, c->name); + config_rename_section(old_sec, ctx->name); } else - sprintf(c->name, "%s", dev->name); + sprintf(ctx->name, "%s", dev->name); } static void @@ -153,7 +156,25 @@ device_add_common(const device_t *dev, void *p, void *params, int inst) { device_t *init_dev = NULL; void *priv = NULL; - int c; + int16_t c; + + /* + IMPORTANT: This is needed to gracefully handle machine + device addition if the relevant device is NULL. + */ + if (dev == NULL) + return NULL; + + if (!device_available(dev)) { + wchar_t temp[512] = { 0 }; + swprintf(temp, sizeof_w(temp), + plat_get_string(STRING_HW_NOT_AVAILABLE_DEVICE), + dev->name); + ui_msgbox_header(MBX_INFO, + plat_get_string(STRING_HW_NOT_AVAILABLE_TITLE), + temp); + return ((void *) dev->name); + } if (params != NULL) { init_dev = calloc(1, sizeof(device_t)); @@ -162,7 +183,7 @@ device_add_common(const device_t *dev, void *p, void *params, int inst) } else init_dev = (device_t *) dev; - for (c = 0; c < 256; c++) { + for (c = 0; c < DEVICE_MAX; c++) { if (!inst && (devices[c] == dev)) { device_log("DEVICE: device already exists!\n"); return (NULL); @@ -171,7 +192,8 @@ device_add_common(const device_t *dev, void *p, void *params, int inst) break; } if (c >= DEVICE_MAX) { - fatal("DEVICE: too many devices\n"); + fatal("Attempting to initialize more than the maximum " + "limit of %i devices\n", DEVICE_MAX); return NULL; } @@ -244,6 +266,7 @@ void * device_add_linked(const device_t *dev, void *priv) { void *ret; + device_common_priv = priv; ret = device_add_common(dev, NULL, NULL, 0); device_common_priv = NULL; @@ -311,7 +334,8 @@ device_close_all(void) #endif if (devices[c]->close != NULL) devices[c]->close(device_priv[c]); - devices[c] = device_priv[c] = NULL; + devices[c] = NULL; + device_priv[c] = NULL; } } } @@ -366,60 +390,142 @@ device_get_priv(const device_t *dev) int device_available(const device_t *dev) { - const device_config_t *config = NULL; - const device_config_bios_t *bios = NULL; + int ret = machine_device_available(dev); + if (ret == 0) { + /* No CONFIG_BIOS field present, use the classic available(). */ + if (dev->available != NULL) + ret = (dev->available()); + else + ret = (dev != NULL); + } else + ret = (ret == -1); + + return ret; +} + +uint8_t +device_get_bios_type(const device_t *dev, const char *internal_name) +{ if (dev != NULL) { - config = dev->config; + const device_config_t *config = dev->config; if (config != NULL) { - while (config->type != -1) { + while (config->type != CONFIG_END) { if (config->type == CONFIG_BIOS) { - int roms_present = 0; - - bios = (const device_config_bios_t *) config->bios; - - /* Go through the ROM's in the device configuration. */ - while (bios->files_no != 0) { - int i = 0; - for (int bf = 0; bf < bios->files_no; bf++) - i += !!rom_present(bios->files[bf]); - if (i == bios->files_no) - roms_present++; + const device_config_bios_t *bios = (const device_config_bios_t *) config->bios; + while ((bios != NULL) && + (bios->name != NULL) && + (bios->internal_name != NULL) && + (bios->files_no != 0)) { + if (!strcmp(internal_name, bios->internal_name)) + return bios->bios_type; + bios++; + } + } + config++; + } + } + } + + return 0; +} + +uint8_t +device_get_bios_num_files(const device_t *dev, const char *internal_name) +{ + if (dev != NULL) { + const device_config_t *config = dev->config; + if (config != NULL) { + while (config->type != CONFIG_END) { + if (config->type == CONFIG_BIOS) { + const device_config_bios_t *bios = (const device_config_bios_t *) config->bios; + while ((bios != NULL) && + (bios->name != NULL) && + (bios->internal_name != NULL) && + (bios->files_no != 0)) { + if (!strcmp(internal_name, bios->internal_name)) + return bios->files_no; + bios++; + } + } + config++; + } + } + } + + return 0; +} + +uint32_t +device_get_bios_local(const device_t *dev, const char *internal_name) +{ + if (dev != NULL) { + const device_config_t *config = dev->config; + if (config != NULL) { + while (config->type != CONFIG_END) { + if (config->type == CONFIG_BIOS) { + const device_config_bios_t *bios = (const device_config_bios_t *) config->bios; + while ((bios != NULL) && + (bios->name != NULL) && + (bios->internal_name != NULL) && + (bios->files_no != 0)) { + printf("Internal name was: %s", internal_name); + if (!strcmp(internal_name, bios->internal_name)) + return bios->local; + bios++; + } + } + config++; + } + } + } + + return 0; +} + +uint32_t +device_get_bios_file_size(const device_t *dev, const char *internal_name) +{ + if (dev != NULL) { + const device_config_t *config = dev->config; + if (config != NULL) { + while (config->type != CONFIG_END) { + if (config->type == CONFIG_BIOS) { + const device_config_bios_t *bios = (const device_config_bios_t *) config->bios; + + /* Go through the ROM's in the device configuration. */ + while ((bios != NULL) && + (bios->name != NULL) && + (bios->internal_name != NULL) && + (bios->files_no != 0)) { + if (!strcmp(internal_name, bios->internal_name)) + return bios->size; bios++; } - - return (roms_present ? -1 : 0); } config++; } } - - /* No CONFIG_BIOS field present, use the classic available(). */ - if (dev->available != NULL) - return (dev->available()); - else - return 1; } - /* A NULL device is never available. */ return 0; } const char * device_get_bios_file(const device_t *dev, const char *internal_name, int file_no) { - const device_config_t *config = NULL; - const device_config_bios_t *bios = NULL; - if (dev != NULL) { - config = dev->config; + const device_config_t *config = dev->config; if (config != NULL) { - while (config->type != -1) { + while (config->type != CONFIG_END) { if (config->type == CONFIG_BIOS) { - bios = config->bios; + const device_config_bios_t *bios = (const device_config_bios_t *) config->bios; /* Go through the ROM's in the device configuration. */ - while (bios->files_no != 0) { + while ((bios != NULL) && + (bios->name != NULL) && + (bios->internal_name != NULL) && + (bios->files_no != 0)) { if (!strcmp(internal_name, bios->internal_name)) { if (file_no < bios->files_no) return bios->files[file_no]; @@ -452,7 +558,7 @@ device_has_config(const device_t *dev) config = dev->config; - while (config->type != -1) { + while (config->type != CONFIG_END) { c++; config++; } @@ -460,28 +566,13 @@ device_has_config(const device_t *dev) return (c > 0) ? 1 : 0; } -int -device_poll(const device_t *dev) -{ - for (uint16_t c = 0; c < DEVICE_MAX; c++) { - if (devices[c] != NULL) { - if (devices[c] == dev) { - if (devices[c]->poll) - return (devices[c]->poll(device_priv[c])); - } - } - } - - return 0; -} - void device_get_name(const device_t *dev, int bus, char *name) { const char *sbus = NULL; const char *fbus; char *tname; - char pbus[8] = { 0 }; + char pbus[16] = { 0 }; if (dev == NULL) return; @@ -489,14 +580,29 @@ device_get_name(const device_t *dev, int bus, char *name) name[0] = 0x00; if (bus) { - if (dev->flags & DEVICE_ISA) - sbus = (dev->flags & DEVICE_AT) ? "ISA16" : "ISA"; + if ((dev->flags & (DEVICE_SIDECAR | DEVICE_ISA)) == + (DEVICE_SIDECAR | DEVICE_ISA)) + sbus = "ISA/Sidecar"; + else if (dev->flags & DEVICE_SIDECAR) + sbus = "Sidecar"; + else if (dev->flags & DEVICE_XT_KBC) + sbus = "XT KBC"; + else if (dev->flags & DEVICE_ISA16) + sbus = "ISA16"; + else if (dev->flags & DEVICE_AT_KBC) + sbus = "AT KBC"; + else if (dev->flags & DEVICE_PS2_KBC) + sbus = "PS/2 KBC"; + else if (dev->flags & DEVICE_ISA) + sbus = "ISA"; else if (dev->flags & DEVICE_CBUS) sbus = "C-BUS"; else if (dev->flags & DEVICE_PCMCIA) sbus = "PCMCIA"; else if (dev->flags & DEVICE_MCA) sbus = "MCA"; + else if (dev->flags & DEVICE_MCA32) + sbus = "MCA32"; else if (dev->flags & DEVICE_HIL) sbus = "HP HIL"; else if (dev->flags & DEVICE_EISA) @@ -510,7 +616,7 @@ device_get_name(const device_t *dev, int bus, char *name) else if (dev->flags & DEVICE_PCI) sbus = "PCI"; else if (dev->flags & DEVICE_CARDBUS) - sbus = "CARDBUS"; + sbus = "CardBus"; else if (dev->flags & DEVICE_USB) sbus = "USB"; else if (dev->flags & DEVICE_AGP) @@ -543,8 +649,7 @@ device_get_name(const device_t *dev, int bus, char *name) strcat(pbus, ")"); /* Allocate the temporary device name string and set it to all zeroes. */ - tname = (char *) malloc(strlen(dev->name) + 1); - memset(tname, 0x00, strlen(dev->name) + 1); + tname = (char *) calloc(1, strlen(dev->name) + 1); /* First strip the bus string with parentheses. */ fbus = strstr(dev->name, pbus); @@ -612,262 +717,271 @@ device_get_instance(void) } const char * -device_get_config_string(const char *s) +device_get_config_string(const char *str) { - const device_config_t *c = device_current.dev->config; + const char *ret = ""; - while (c && c->type != -1) { - if (!strcmp(s, c->name)) - return (config_get_string((char *) device_current.name, (char *) s, (char *) c->default_string)); + if (device_current.dev != NULL) { + const device_config_t *cfg = device_current.dev->config; - c++; + while ((cfg != NULL) && (cfg->type != CONFIG_END)) { + if (!strcmp(str, cfg->name)) { + const char *s = (config_get_string((char *) device_current.name, + (char *) str, (char *) cfg->default_string)); + ret = (s == NULL) ? "" : s; + break; + } + + cfg++; + } } - return (NULL); + return ret; } int -device_get_config_int(const char *s) +device_get_config_int(const char *str) { - const device_config_t *c = device_current.dev->config; + if (device_current.dev != NULL) { + const device_config_t *cfg = device_current.dev->config; - while (c && c->type != -1) { - if (!strcmp(s, c->name)) - return (config_get_int((char *) device_current.name, (char *) s, c->default_int)); + while ((cfg != NULL) && (cfg->type != CONFIG_END)) { + if (!strcmp(str, cfg->name)) + return (config_get_int((char *) device_current.name, (char *) str, cfg->default_int)); - c++; + cfg++; + } } return 0; } int -device_get_config_int_ex(const char *s, int def) +device_get_config_int_ex(const char *str, int def) { - const device_config_t *c = device_current.dev->config; + if (device_current.dev != NULL) { + const device_config_t *cfg = device_current.dev->config; - while (c && c->type != -1) { - if (!strcmp(s, c->name)) - return (config_get_int((char *) device_current.name, (char *) s, def)); + while ((cfg != NULL) && (cfg->type != CONFIG_END)) { + if (!strcmp(str, cfg->name)) + return (config_get_int((char *) device_current.name, (char *) str, def)); - c++; + cfg++; + } } return def; } int -device_get_config_hex16(const char *s) +device_get_config_hex16(const char *str) { - const device_config_t *c = device_current.dev->config; + if (device_current.dev != NULL) { + const device_config_t *cfg = device_current.dev->config; - while (c && c->type != -1) { - if (!strcmp(s, c->name)) - return (config_get_hex16((char *) device_current.name, (char *) s, c->default_int)); + while ((cfg != NULL) && (cfg->type != CONFIG_END)) { + if (!strcmp(str, cfg->name)) + return (config_get_hex16((char *) device_current.name, (char *) str, cfg->default_int)); - c++; + cfg++; + } } return 0; } int -device_get_config_hex20(const char *s) +device_get_config_hex20(const char *str) { - const device_config_t *c = device_current.dev->config; + if (device_current.dev != NULL) { + const device_config_t *cfg = device_current.dev->config; - while (c && c->type != -1) { - if (!strcmp(s, c->name)) - return (config_get_hex20((char *) device_current.name, (char *) s, c->default_int)); + while ((cfg != NULL) && (cfg->type != CONFIG_END)) { + if (!strcmp(str, cfg->name)) + return (config_get_hex20((char *) device_current.name, (char *) str, cfg->default_int)); - c++; + cfg++; + } } return 0; } int -device_get_config_mac(const char *s, int def) +device_get_config_mac(const char *str, int def) { - const device_config_t *c = device_current.dev->config; + if (device_current.dev != NULL) { + const device_config_t *cfg = device_current.dev->config; - while (c && c->type != -1) { - if (!strcmp(s, c->name)) - return (config_get_mac((char *) device_current.name, (char *) s, def)); + while ((cfg != NULL) && (cfg->type != CONFIG_END)) { + if (!strcmp(str, cfg->name)) + return (config_get_mac((char *) device_current.name, (char *) str, def)); - c++; + cfg++; + } } return def; } void -device_set_config_int(const char *s, int val) +device_set_config_int(const char *str, int val) { - const device_config_t *c = device_current.dev->config; + if (device_current.dev != NULL) { + const device_config_t *cfg = device_current.dev->config; - while (c && c->type != -1) { - if (!strcmp(s, c->name)) { - config_set_int((char *) device_current.name, (char *) s, val); - break; + while ((cfg != NULL) && (cfg->type != CONFIG_END)) { + if (!strcmp(str, cfg->name)) { + config_set_int((char *) device_current.name, (char *) str, val); + break; + } + + cfg++; } - - c++; } } void -device_set_config_hex16(const char *s, int val) +device_set_config_hex16(const char *str, int val) { - const device_config_t *c = device_current.dev->config; + if (device_current.dev != NULL) { + const device_config_t *cfg = device_current.dev->config; - while (c && c->type != -1) { - if (!strcmp(s, c->name)) { - config_set_hex16((char *) device_current.name, (char *) s, val); - break; + while ((cfg != NULL) && (cfg->type != CONFIG_END)) { + if (!strcmp(str, cfg->name)) { + config_set_hex16((char *) device_current.name, (char *) str, val); + break; + } + + cfg++; } - - c++; } } void -device_set_config_hex20(const char *s, int val) +device_set_config_hex20(const char *str, int val) { - const device_config_t *c = device_current.dev->config; + if (device_current.dev != NULL) { + const device_config_t *cfg = device_current.dev->config; - while (c && c->type != -1) { - if (!strcmp(s, c->name)) { - config_set_hex20((char *) device_current.name, (char *) s, val); - break; + while ((cfg != NULL) && (cfg->type != CONFIG_END)) { + if (!strcmp(str, cfg->name)) { + config_set_hex20((char *) device_current.name, (char *) str, val); + break; + } + + cfg++; } - - c++; } } void -device_set_config_mac(const char *s, int val) +device_set_config_mac(const char *str, int val) { - const device_config_t *c = device_current.dev->config; + if (device_current.dev != NULL) { + const device_config_t *cfg = device_current.dev->config; - while (c && c->type != -1) { - if (!strcmp(s, c->name)) { - config_set_mac((char *) device_current.name, (char *) s, val); - break; + while ((cfg != NULL) && (cfg->type != CONFIG_END)) { + if (!strcmp(str, cfg->name)) { + config_set_mac((char *) device_current.name, (char *) str, val); + break; + } + + cfg++; } - - c++; } } int -device_is_valid(const device_t *device, int m) +device_is_valid(const device_t *device, int mch) { - if (device == NULL) - return 1; + int ret = 1; - if ((device->flags & DEVICE_PCJR) && !machine_has_bus(m, MACHINE_BUS_PCJR)) - return 0; + if ((device != NULL) && ((device->flags & DEVICE_BUS) != 0)) { + /* Hide PCI devices on machines with only an internal PCI bus. */ + if ((device->flags & DEVICE_PCI) && + machine_has_flags(mch, MACHINE_PCI_INTERNAL)) + ret = 0; + else + ret = machine_has_bus(mch, device->flags & DEVICE_BUS); + } - if ((device->flags & DEVICE_XTKBC) && machine_has_bus(m, MACHINE_BUS_ISA16) && !machine_has_bus(m, MACHINE_BUS_DM_KBC)) - return 0; - - if ((device->flags & DEVICE_AT) && !machine_has_bus(m, MACHINE_BUS_ISA16)) - return 0; - - if ((device->flags & DEVICE_ATKBC) && !machine_has_bus(m, MACHINE_BUS_ISA16) && !machine_has_bus(m, MACHINE_BUS_DM_KBC)) - return 0; - - if ((device->flags & DEVICE_PS2) && !machine_has_bus(m, MACHINE_BUS_PS2_PORTS)) - return 0; - - if ((device->flags & DEVICE_ISA) && !machine_has_bus(m, MACHINE_BUS_ISA)) - return 0; - - if ((device->flags & DEVICE_CBUS) && !machine_has_bus(m, MACHINE_BUS_CBUS)) - return 0; - - if ((device->flags & DEVICE_PCMCIA) && !machine_has_bus(m, MACHINE_BUS_PCMCIA) && !machine_has_bus(m, MACHINE_BUS_ISA)) - return 0; - - if ((device->flags & DEVICE_MCA) && !machine_has_bus(m, MACHINE_BUS_MCA)) - return 0; - - if ((device->flags & DEVICE_HIL) && !machine_has_bus(m, MACHINE_BUS_HIL)) - return 0; - - if ((device->flags & DEVICE_EISA) && !machine_has_bus(m, MACHINE_BUS_EISA)) - return 0; - - if ((device->flags & DEVICE_AT32) && !machine_has_bus(m, MACHINE_BUS_AT32)) - return 0; - - if ((device->flags & DEVICE_OLB) && !machine_has_bus(m, MACHINE_BUS_OLB)) - return 0; - - if ((device->flags & DEVICE_VLB) && !machine_has_bus(m, MACHINE_BUS_VLB)) - return 0; - - if ((device->flags & DEVICE_PCI) && !machine_has_bus(m, MACHINE_BUS_PCI)) - return 0; - - if ((device->flags & DEVICE_CARDBUS) && !machine_has_bus(m, MACHINE_BUS_CARDBUS) && !machine_has_bus(m, MACHINE_BUS_PCI)) - return 0; - - if ((device->flags & DEVICE_USB) && !machine_has_bus(m, MACHINE_BUS_USB)) - return 0; - - if ((device->flags & DEVICE_AGP) && !machine_has_bus(m, MACHINE_BUS_AGP)) - return 0; - - if ((device->flags & DEVICE_AC97) && !machine_has_bus(m, MACHINE_BUS_AC97)) - return 0; - - return 1; + return ret; } int -machine_get_config_int(char *s) +machine_get_config_int(char *str) { - const device_t *d = machine_get_device(machine); - const device_config_t *c; + const device_t *dev = machine_get_device(machine); - if (d == NULL) - return 0; + if (dev != NULL) { + const device_config_t *cfg = dev->config; - c = d->config; - while (c && c->type != -1) { - if (!strcmp(s, c->name)) - return (config_get_int((char *) d->name, s, c->default_int)); + while ((cfg != NULL) && (cfg->type != CONFIG_END)) { + if (!strcmp(str, cfg->name)) + return (config_get_int((char *) dev->name, str, cfg->default_int)); - c++; + cfg++; + } } - return 0; } -char * -machine_get_config_string(char *s) +const char * +machine_get_config_string(char *str) { - const device_t *d = machine_get_device(machine); - const device_config_t *c; + const device_t *dev = machine_get_device(machine); + const char *ret = ""; - if (d == NULL) - return 0; + if (dev != NULL) { + const device_config_t *cfg = dev->config; - c = d->config; - while (c && c->type != -1) { - if (!strcmp(s, c->name)) - return (config_get_string((char *) d->name, s, (char *) c->default_string)); + while ((cfg != NULL) && (cfg->type != CONFIG_END)) { + if (!strcmp(str, cfg->name)) { + const char *s = config_get_string((char *) dev->name, str, + (char *) cfg->default_string); + ret = (s == NULL) ? "" : s; + break; + } - c++; + cfg++; + } } - return NULL; + return ret; } -const device_t* +int +machine_device_available(const device_t *dev) +{ + if (dev != NULL) { + const device_config_t *config = dev->config; + if ((config != NULL) && (config->type == CONFIG_BIOS)) { + int roms_present = 0; + const device_config_bios_t *bios = (const device_config_bios_t *) config->bios; + + /* Go through the ROM's in the device configuration. */ + while ((bios != NULL) && + (bios->name != NULL) && + (bios->internal_name != NULL) && + (bios->files_no != 0)) { + int i = 0; + for (uint8_t bf = 0; bf < bios->files_no; bf++) + i += !!rom_present(bios->files[bf]); + if (i == bios->files_no) + roms_present++; + bios++; + } + + return (roms_present ? -1 : -2); + } + } + + /* NULL device or no CONFIG_BIOS field, return 0. */ + return 0; +} + +const device_t * device_context_get_device(void) { return device_current.dev; @@ -881,7 +995,7 @@ const device_t device_none = { .init = NULL, .close = NULL, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -895,7 +1009,7 @@ const device_t device_internal = { .init = NULL, .close = NULL, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/CMakeLists.txt b/src/device/CMakeLists.txt index ae3fbf3f2..999b83aeb 100644 --- a/src/device/CMakeLists.txt +++ b/src/device/CMakeLists.txt @@ -13,51 +13,55 @@ # # Copyright 2020-2021 David Hrdlička. # Copyright 2021 Andreas J. Reichel. -# Copyright 2021-2024 Jasmine Iwanek. +# Copyright 2021-2025 Jasmine Iwanek. # add_library(dev OBJECT + access_bus.c bugger.c - cassette.c cartridge.c + cassette.c + clock_ics9xxx.c + dell_jumper.c hasp.c hwm.c + hwm_gl518sm.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 - unittester.c - clock_ics9xxx.c - isapnp.c i2c.c i2c_gpio.c - smbus_piix4.c - smbus_ali7101.c - smbus_sis5595.c - keyboard.c - keyboard_xt.c + ibm_5161.c + isamem.c + isarom.c + isartc.c + isapnp.c kbc_at.c kbc_at_dev.c + keyboard.c keyboard_at.c + keyboard_xt.c + lpt.c mouse.c mouse_bus.c - mouse_serial.c - mouse_ps2.c - nec_mate_unk.c - phoenix_486_jumper.c - serial_passthrough.c - novell_cardkey.c mouse_microtouch_touchscreen.c + mouse_ps2.c + mouse_serial.c + nec_mate_unk.c + novell_cardkey.c + pci_bridge.c + phoenix_486_jumper.c + postcard.c + serial.c + serial_passthrough.c + smbus_ali7101.c + smbus_piix4.c + smbus_sis5595.c + tulip_jumper.c + unittester.c ) -if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") +if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT MSVC) target_link_libraries(86Box atomic) endif() diff --git a/src/device/access_bus.c b/src/device/access_bus.c new file mode 100644 index 000000000..951454e19 --- /dev/null +++ b/src/device/access_bus.c @@ -0,0 +1,122 @@ +/* + * 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 ACCESS.bus. + * + * Authors: Miran Grca, + * + * Copyright 2024-2025 Miran Grca. + */ +#include +#include +#include +#include +#include +#include <86box/86box.h> +#include <86box/io.h> +#include <86box/device.h> +#include <86box/access_bus.h> +#include <86box/plat_unused.h> + +static uint8_t +access_bus_in(uint16_t port, void *priv) +{ + const access_bus_t *dev = (access_bus_t *) priv; + uint8_t ret = 0xff; + + switch (port & 3) { + case 0: + ret = (dev->status & 0xbf); + break; + case 1: + ret = (dev->own_addr & 0x7f); + break; + case 2: + ret = dev->data; + break; + case 3: + ret = (dev->clock & 0x87); + break; + + default: + break; + } + + return ret; +} + +static void +access_bus_out(uint16_t port, uint8_t val, void *priv) +{ + access_bus_t *dev = (access_bus_t *) priv; + + switch (port & 3) { + case 0: + dev->control = (val & 0xcf); + break; + case 1: + dev->own_addr = (val & 0x7f); + break; + case 2: + dev->data = val; + break; + case 3: + dev->clock &= 0x80; + dev->clock |= (val & 0x07); + break; + + default: + break; + } +} + +void +access_bus_handler(access_bus_t *dev, uint8_t enable, uint16_t base) +{ + if (dev->enable && (dev->base >= 0x0100) && (dev->base <= 0x0ffc)) + io_removehandler(dev->base, 0x0004, + access_bus_in, NULL, NULL, access_bus_out, NULL, NULL, dev); + + dev->enable = enable; + dev->base = base; + + if (dev->enable && (dev->base >= 0x0100) && (dev->base <= 0x0ffc)) + io_sethandler(dev->base, 0x0004, + access_bus_in, NULL, NULL, access_bus_out, NULL, NULL, dev); +} + + +static void +access_bus_close(void *priv) +{ + access_bus_t *dev = (access_bus_t *) priv; + + free(dev); +} + +static void * +access_bus_init(UNUSED(const device_t *info)) +{ + access_bus_t *dev = (access_bus_t *) calloc(1, sizeof(access_bus_t)); + + return dev; +} + +const device_t access_bus_device = { + .name = "ACCESS.bus", + .internal_name = "access_bus", + .flags = 0, + .local = 0, + .init = access_bus_init, + .close = access_bus_close, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; diff --git a/src/device/bugger.c b/src/device/bugger.c index c2678d66a..6a30df7be 100644 --- a/src/device/bugger.c +++ b/src/device/bugger.c @@ -84,7 +84,10 @@ static uint8_t bug_spcfg; /* serial port configuration */ #define FIFO_LEN 256 static uint8_t bug_buff[FIFO_LEN]; /* serial port data buffer */ static uint8_t *bug_bptr; -#define UISTR_LEN 24 + +static char LED_R[] = "R"; +static char LED_G[] = "G"; +#define UISTR_LEN (17 + 8 * sizeof(LED_G) + 8 * sizeof(LED_R)) static char bug_str[UISTR_LEN]; /* UI output string */ extern void ui_sb_bugui(char *__str); @@ -112,16 +115,16 @@ static void bug_setui(void) { /* Format all current info in a string. */ - sprintf(bug_str, "%02X:%02X %c%c%c%c%c%c%c%c-%c%c%c%c%c%c%c%c", + sprintf(bug_str, "%02X:%02X %s%s%s%s%s%s%s%s-%s%s%s%s%s%s%s%s", bug_seg2, bug_seg1, - (bug_ledg & 0x80) ? 'G' : 'g', (bug_ledg & 0x40) ? 'G' : 'g', - (bug_ledg & 0x20) ? 'G' : 'g', (bug_ledg & 0x10) ? 'G' : 'g', - (bug_ledg & 0x08) ? 'G' : 'g', (bug_ledg & 0x04) ? 'G' : 'g', - (bug_ledg & 0x02) ? 'G' : 'g', (bug_ledg & 0x01) ? 'G' : 'g', - (bug_ledr & 0x80) ? 'R' : 'r', (bug_ledr & 0x40) ? 'R' : 'r', - (bug_ledr & 0x20) ? 'R' : 'r', (bug_ledr & 0x10) ? 'R' : 'r', - (bug_ledr & 0x08) ? 'R' : 'r', (bug_ledr & 0x04) ? 'R' : 'r', - (bug_ledr & 0x02) ? 'R' : 'r', (bug_ledr & 0x01) ? 'R' : 'r'); + (bug_ledg & 0x80) ? LED_G : "g", (bug_ledg & 0x40) ? LED_G : "g", + (bug_ledg & 0x20) ? LED_G : "g", (bug_ledg & 0x10) ? LED_G : "g", + (bug_ledg & 0x08) ? LED_G : "g", (bug_ledg & 0x04) ? LED_G : "g", + (bug_ledg & 0x02) ? LED_G : "g", (bug_ledg & 0x01) ? LED_G : "g", + (bug_ledr & 0x80) ? LED_R : "r", (bug_ledr & 0x40) ? LED_R : "r", + (bug_ledr & 0x20) ? LED_R : "r", (bug_ledr & 0x10) ? LED_R : "r", + (bug_ledr & 0x08) ? LED_R : "r", (bug_ledr & 0x04) ? LED_R : "r", + (bug_ledr & 0x02) ? LED_R : "r", (bug_ledr & 0x01) ? LED_R : "r"); /* Send formatted string to the UI. */ ui_sb_bugui(bug_str); @@ -346,12 +349,12 @@ bug_close(UNUSED(void *priv)) const device_t bugger_device = { .name = "ISA/PCI Bus Bugger", .internal_name = "bugger", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0, .init = bug_init, .close = bug_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/cartridge.c b/src/device/cartridge.c index 52f36a4ca..00464026a 100644 --- a/src/device/cartridge.c +++ b/src/device/cartridge.c @@ -22,6 +22,7 @@ #include #define HAVE_STDARG_H #include <86box/86box.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/plat.h> #include <86box/ui.h> @@ -104,6 +105,7 @@ cart_image_load(int drive, char *fn) if (size < 0x1200) { cartridge_log("cart_image_load(): File size %i is too small\n", size); cart_load_error(drive, fn); + fclose(fp); return; } if (size & 0x00000fff) { @@ -112,8 +114,7 @@ cart_image_load(int drive, char *fn) (void) !fread(&base, 1, 2, fp); base <<= 4; fseek(fp, 0x00000200, SEEK_SET); - carts[drive].buf = (uint8_t *) malloc(size); - memset(carts[drive].buf, 0x00, size); + carts[drive].buf = (uint8_t *) calloc(1, size); (void) !fread(carts[drive].buf, 1, size, fp); fclose(fp); } else { @@ -121,8 +122,7 @@ cart_image_load(int drive, char *fn) if (size == 32768) base += 0x8000; fseek(fp, 0x00000000, SEEK_SET); - carts[drive].buf = (uint8_t *) malloc(size); - memset(carts[drive].buf, 0x00, size); + carts[drive].buf = (uint8_t *) calloc(1, size); (void) !fread(carts[drive].buf, 1, size, fp); fclose(fp); } diff --git a/src/device/cassette.c b/src/device/cassette.c index a239c6393..5cde2fbd0 100644 --- a/src/device/cassette.c +++ b/src/device/cassette.c @@ -131,9 +131,7 @@ pc_cas_free(pc_cassette_t *cas) pc_cassette_t * pc_cas_new(void) { - pc_cassette_t *cas; - - cas = malloc(sizeof(pc_cassette_t)); + pc_cassette_t *cas = calloc(1, sizeof( pc_cassette_t)); if (cas == NULL) { return (NULL); @@ -717,12 +715,12 @@ cassette_init(UNUSED(const device_t *info)) const device_t cassette_device = { .name = "IBM PC/PCjr Cassette Device", .internal_name = "cassette", - .flags = 0, + .flags = DEVICE_CASETTE, .local = 0, .init = cassette_init, .close = cassette_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/clock_ics9xxx.c b/src/device/clock_ics9xxx.c index 263170741..02f033e9b 100644 --- a/src/device/clock_ics9xxx.c +++ b/src/device/clock_ics9xxx.c @@ -1181,8 +1181,7 @@ ics9xxx_find_bus_match(ics9xxx_t *dev, uint32_t bus, uint8_t preset_mask, uint8_ static void * ics9xxx_init(const device_t *info) { - ics9xxx_t *dev = (ics9xxx_t *) malloc(sizeof(ics9xxx_t)); - memset(dev, 0, sizeof(ics9xxx_t)); + ics9xxx_t *dev = (ics9xxx_t *) calloc(1, sizeof(ics9xxx_t)); dev->model_idx = info->local; dev->model = (ics9xxx_model_t *) &ics9xxx_models[dev->model_idx]; @@ -1267,8 +1266,7 @@ ics9xxx_close(void *priv) device_t * ics9xxx_get(uint8_t model) { - device_t *dev = (device_t *) malloc(sizeof(device_t)); - memset(dev, 0, sizeof(device_t)); + device_t *dev = (device_t *) calloc(1, sizeof(device_t)); dev->name = "ICS9xxx-xx Clock Generator"; dev->local = model; diff --git a/src/device/dell_jumper.c b/src/device/dell_jumper.c new file mode 100644 index 000000000..12fc3d13b --- /dev/null +++ b/src/device/dell_jumper.c @@ -0,0 +1,175 @@ +/* + * 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 Dell 486 and 586 Jumper Readout. + * + * Register 0x02: + * - Bit 0: ATX power: 1 = off, 0 = on. + * + * Register 0x05: + * - Appears to be: 0x02 = On-board audio enabled; + * 0x07 = On-board audio disabled. + * + * Register 0x07: + * - Bit 0: On-board NIC: 1 = present, 0 = absent; + * - Bit 1: On-board audio: 1 = present, 0 = absent; + * - Bits 4-2: + * - 0, 0, 0 = GXL; + * - 0, 0, 1 = GL+; + * - 0, 1, 0 = GXMT; + * - 0, 1, 1 = GMT+; + * - 1, 0, 0 = GXM; + * - 1, 0, 1 = GM+; + * - 1, 1, 0 = WS; + * - 1, 1, 1 = GWS+. + * + * Authors: Miran Grca, + * + * Copyright 2025 Miran Grca. + */ +#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/machine.h> +#include <86box/sound.h> +#include <86box/chipset.h> +#include <86box/plat.h> +#include <86box/plat_unused.h> + +typedef struct dell_jumper_t { + uint8_t index; + uint8_t regs[256]; +} dell_jumper_t; + +#ifdef ENABLE_DELL_JUMPER_LOG +int dell_jumper_do_log = ENABLE_DELL_JUMPER_LOG; + +static void +dell_jumper_log(const char *fmt, ...) +{ + va_list ap; + + if (dell_jumper_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define dell_jumper_log(fmt, ...) +#endif + +static void +dell_jumper_write(uint16_t addr, uint8_t val, void *priv) +{ + dell_jumper_t *dev = (dell_jumper_t *) priv; + + dell_jumper_log("Dell Jumper: Write %02x\n", val); + + if (addr & 1) switch (dev->index) { + default: + dev->regs[dev->index] = val; + break; + case 0x02: + dev->regs[dev->index] = val; + if (val & 0x04) + /* Soft power off. */ + plat_power_off(); + break; + case 0x05: + dev->regs[dev->index] = (dev->regs[dev->index] & 0x02) | (val & 0xfd); + if (machine_snd != NULL) switch (val & 0x05) { + default: + case 0x05: + sb_vibra16s_onboard_relocate_base(0x0000, machine_snd); + break; + case 0x00: + sb_vibra16s_onboard_relocate_base(0x0220, machine_snd); + break; + } + break; + case 0x07: + break; + } else + dev->index = val; +} + +static uint8_t +dell_jumper_read(uint16_t addr, void *priv) +{ + const dell_jumper_t *dev = (dell_jumper_t *) priv; + uint8_t ret = 0xff; + + dell_jumper_log("Dell Jumper: Read %02x\n", dev->jumper); + + if (addr & 1) + ret = dev->regs[dev->index]; + else + ret = dev->index; + + return ret; +} + +static void +dell_jumper_reset(void *priv) +{ + dell_jumper_t *dev = (dell_jumper_t *) priv; + + dev->index = 0x00; + memset(dev->regs, 0x00, 256); + + if (sound_card_current[0] == SOUND_INTERNAL) + /* GXL, on-board audio present, on-board NIC absent. */ + dev->regs[0x07] = 0x02; + else + /* GXL, on-board audio absent, on-board NIC absent. */ + dev->regs[0x07] = 0x00; +} + +static void +dell_jumper_close(void *priv) +{ + dell_jumper_t *dev = (dell_jumper_t *) priv; + + free(dev); +} + +static void * +dell_jumper_init(const device_t *info) +{ + dell_jumper_t *dev = (dell_jumper_t *) calloc(1, sizeof(dell_jumper_t)); + + dell_jumper_reset(dev); + + io_sethandler(0x00e8, 0x0002, dell_jumper_read, NULL, NULL, dell_jumper_write, NULL, NULL, dev); + + return dev; +} + +const device_t dell_jumper_device = { + .name = "Dell Jumper Readout", + .internal_name = "dell_jumper", + .flags = 0, + .local = 0, + .init = dell_jumper_init, + .close = dell_jumper_close, + .reset = dell_jumper_reset, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; diff --git a/src/device/hasp.c b/src/device/hasp.c index 9873c3460..53228c2a0 100644 --- a/src/device/hasp.c +++ b/src/device/hasp.c @@ -27,6 +27,7 @@ #include #define HAVE_STDARG_H #include <86box/86box.h> +#include <86box/timer.h> #include <86box/lpt.h> #include <86box/device.h> @@ -305,8 +306,7 @@ hasp_read_status(void *priv) static void * hasp_init(void *lpt, int type) { - hasp_t *dev = malloc(sizeof(hasp_t)); - memset(dev, 0, sizeof(hasp_t)); + hasp_t *dev = calloc(1, sizeof(hasp_t)); hasp_log("HASP: init(%d)\n", type); @@ -335,13 +335,16 @@ hasp_close(void *priv) } const lpt_device_t lpt_hasp_savquest_device = { - .name = "Protection Dongle for Savage Quest", - .internal_name = "dongle_savquest", - .init = hasp_init_savquest, - .close = hasp_close, - .write_data = hasp_write_data, - .write_ctrl = NULL, - .read_data = NULL, - .read_status = hasp_read_status, - .read_ctrl = NULL + .name = "Protection Dongle for Savage Quest", + .internal_name = "dongle_savquest", + .init = hasp_init_savquest, + .close = hasp_close, + .write_data = hasp_write_data, + .write_ctrl = NULL, + .autofeed = NULL, + .strobe = NULL, + .read_status = hasp_read_status, + .read_ctrl = NULL, + .epp_write_data = NULL, + .epp_request_read = NULL }; diff --git a/src/device/hwm_gl518sm.c b/src/device/hwm_gl518sm.c index 6ba1083d9..cfc16664a 100644 --- a/src/device/hwm_gl518sm.c +++ b/src/device/hwm_gl518sm.c @@ -282,8 +282,7 @@ gl518sm_close(void *priv) static void * gl518sm_init(const device_t *info) { - gl518sm_t *dev = (gl518sm_t *) malloc(sizeof(gl518sm_t)); - memset(dev, 0, sizeof(gl518sm_t)); + gl518sm_t *dev = (gl518sm_t *) calloc(1, sizeof(gl518sm_t)); dev->local = info->local; @@ -325,7 +324,7 @@ const device_t gl518sm_2c_device = { .init = gl518sm_init, .close = gl518sm_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -340,7 +339,7 @@ const device_t gl518sm_2d_device = { .init = gl518sm_init, .close = gl518sm_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -355,7 +354,7 @@ const device_t gl520sm_2c_device = { .init = gl518sm_init, .close = gl518sm_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -371,7 +370,7 @@ const device_t gl520sm_2d_device = { .init = gl518sm_init, .close = gl518sm_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/hwm_lm75.c b/src/device/hwm_lm75.c index 14b638365..29fe2024f 100644 --- a/src/device/hwm_lm75.c +++ b/src/device/hwm_lm75.c @@ -216,8 +216,7 @@ lm75_close(void *priv) static void * lm75_init(const device_t *info) { - lm75_t *dev = (lm75_t *) malloc(sizeof(lm75_t)); - memset(dev, 0, sizeof(lm75_t)); + lm75_t *dev = (lm75_t *) calloc(1, sizeof(lm75_t)); dev->local = info->local; @@ -243,7 +242,7 @@ const device_t lm75_1_4a_device = { .init = lm75_init, .close = lm75_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -259,7 +258,7 @@ const device_t lm75_w83781d_device = { .init = lm75_init, .close = lm75_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/hwm_lm78.c b/src/device/hwm_lm78.c index f3003db26..909713833 100644 --- a/src/device/hwm_lm78.c +++ b/src/device/hwm_lm78.c @@ -102,9 +102,9 @@ lm78_log(const char *fmt, ...) void lm78_nvram(lm78_t *dev, uint8_t save) { - size_t l = strlen(machine_get_internal_name_ex(machine)) + 14; + size_t l = strlen(machine_get_nvr_name_ex(machine)) + 14; char *nvr_path = (char *) malloc(l); - sprintf(nvr_path, "%s_as99127f.nvr", machine_get_internal_name_ex(machine)); + sprintf(nvr_path, "%s_as99127f.nvr", machine_get_nvr_name_ex(machine)); FILE *fp = nvr_fopen(nvr_path, save ? "wb" : "rb"); if (fp) { @@ -771,8 +771,7 @@ lm78_close(void *priv) static void * lm78_init(const device_t *info) { - lm78_t *dev = (lm78_t *) malloc(sizeof(lm78_t)); - memset(dev, 0, sizeof(lm78_t)); + lm78_t *dev = (lm78_t *) calloc(1, sizeof(lm78_t)); dev->local = info->local; @@ -857,7 +856,7 @@ const device_t lm78_device = { .init = lm78_init, .close = lm78_close, .reset = lm78_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -872,7 +871,7 @@ const device_t w83781d_device = { .init = lm78_init, .close = lm78_close, .reset = lm78_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -887,7 +886,7 @@ const device_t w83781d_p5a_device = { .init = lm78_init, .close = lm78_close, .reset = lm78_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -903,7 +902,7 @@ const device_t as99127f_device = { .init = lm78_init, .close = lm78_close, .reset = lm78_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -918,7 +917,7 @@ const device_t as99127f_rev2_device = { .init = lm78_init, .close = lm78_close, .reset = lm78_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -933,7 +932,7 @@ const device_t w83782d_device = { .init = lm78_init, .close = lm78_close, .reset = lm78_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/hwm_vt82c686.c b/src/device/hwm_vt82c686.c index b6a0dddda..8623a9f6b 100644 --- a/src/device/hwm_vt82c686.c +++ b/src/device/hwm_vt82c686.c @@ -183,8 +183,7 @@ vt82c686_close(void *priv) static void * vt82c686_init(UNUSED(const device_t *info)) { - vt82c686_t *dev = (vt82c686_t *) malloc(sizeof(vt82c686_t)); - memset(dev, 0, sizeof(vt82c686_t)); + vt82c686_t *dev = (vt82c686_t *) calloc(1, sizeof(vt82c686_t)); /* Set default values. Since this hardware monitor has a complex voltage factor system, the values struct contains voltage values *before* applying their respective factors. */ @@ -222,7 +221,7 @@ const device_t via_vt82c686_hwm_device = { .init = vt82c686_init, .close = vt82c686_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/i2c.c b/src/device/i2c.c index 56e6f8f4c..eb80f413b 100644 --- a/src/device/i2c.c +++ b/src/device/i2c.c @@ -67,8 +67,7 @@ i2c_log(const char *fmt, ...) void * i2c_addbus(char *name) { - i2c_bus_t *bus = (i2c_bus_t *) malloc(sizeof(i2c_bus_t)); - memset(bus, 0, sizeof(i2c_bus_t)); + i2c_bus_t *bus = (i2c_bus_t *) calloc(1, sizeof(i2c_bus_t)); bus->name = name; @@ -127,8 +126,7 @@ i2c_sethandler(void *bus_handle, uint8_t base, int size, 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)); + q = (i2c_t *) calloc(1, sizeof(i2c_t)); if (p) { p->next = q; q->prev = p; diff --git a/src/device/i2c_gpio.c b/src/device/i2c_gpio.c index 22bdaffd3..61a3dbe05 100644 --- a/src/device/i2c_gpio.c +++ b/src/device/i2c_gpio.c @@ -59,8 +59,7 @@ i2c_gpio_log(int level, const char *fmt, ...) void * i2c_gpio_init(char *bus_name) { - i2c_gpio_t *dev = (i2c_gpio_t *) malloc(sizeof(i2c_gpio_t)); - memset(dev, 0, sizeof(i2c_gpio_t)); + i2c_gpio_t *dev = (i2c_gpio_t *) calloc(1, sizeof(i2c_gpio_t)); i2c_gpio_log(1, "I2C GPIO %s: init()\n", bus_name); diff --git a/src/device/ibm_5161.c b/src/device/ibm_5161.c index 762a379a1..456227676 100644 --- a/src/device/ibm_5161.c +++ b/src/device/ibm_5161.c @@ -116,7 +116,7 @@ const device_t ibm_5161_device = { .init = ibm_5161_init, .close = ibm_5161_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/isamem.c b/src/device/isamem.c index a3baf466d..b1095da1f 100644 --- a/src/device/isamem.c +++ b/src/device/isamem.c @@ -27,16 +27,20 @@ * modern boards even have multiple 'copies' of those registers, * which can be switched very fast, to allow for multitasking. * - * TODO: The EV159 is supposed to support 16b EMS transfers, but the + * TODO: The EV-159 is supposed to support 16b EMS transfers, but the * EMM.sys driver for it doesn't seem to want to do that.. * + * EV-125 (It supports backfill) + * https://theretroweb.com/expansioncard/documentation/50250.pdf * + * EV-158 (RAM 10000) + * http://web.archive.org/web/19961104093221/http://www.everex.com/supp/techlib/memmem.html * * Authors: Fred N. van Kempen, * Jasmine Iwanek * * Copyright 2018 Fred N. van Kempen. - * Copyright 2022-2024 Jasmine Iwanek. + * Copyright 2022-2025 Jasmine Iwanek. * * Redistribution and use in source and binary forms, with * or without modification, are permitted provided that the @@ -102,7 +106,7 @@ #define ISAMEM_BRXT_CARD 13 #define ISAMEM_BRAT_CARD 14 #define ISAMEM_EV165A_CARD 15 -#define ISAMEM_LOTECH_CARD 16 +#define ISAMEM_LOTECH_EMS_CARD 16 #define ISAMEM_DEBUG 0 @@ -304,16 +308,13 @@ ems_writew(uint32_t addr, uint16_t val, void *priv) static uint8_t ems_in(uint16_t port, void *priv) { - const emsreg_t *dev = (emsreg_t *) priv; - uint8_t ret = 0xff; -#ifdef ENABLE_ISAMEM_LOG - int vpage; -#endif - + const emsreg_t *dev = (emsreg_t *) priv; + uint8_t ret = 0xff; /* Get the viewport page number. */ #ifdef ENABLE_ISAMEM_LOG - vpage = (port / EMS_PGSIZE); + int vpage = (port / EMS_PGSIZE); #endif + port &= (EMS_PGSIZE - 1); switch (port & 0x0001) { @@ -339,13 +340,11 @@ ems_in(uint16_t port, void *priv) static uint8_t consecutive_ems_in(uint16_t port, void *priv) { - const memdev_t *dev = (memdev_t *) priv; - uint8_t ret = 0xff; - int vpage; - + const memdev_t *dev = (memdev_t *) priv; + uint8_t ret = 0xff; /* Get the viewport page number. */ - vpage = (port - dev->base_addr[0]); - + int vpage = (port - dev->base_addr[0]); + ret = dev->ems[vpage].page; if (dev->ems[vpage].enabled) ret |= 0x80; @@ -359,11 +358,10 @@ consecutive_ems_in(uint16_t port, void *priv) static void ems_out(uint16_t port, uint8_t val, void *priv) { - emsreg_t *dev = (emsreg_t *) priv; - int vpage; - + emsreg_t *dev = (emsreg_t *) priv; /* Get the viewport page number. */ - vpage = (port / EMS_PGSIZE); + int vpage = (port / EMS_PGSIZE); + port &= (EMS_PGSIZE - 1); switch (port & 0x0001) { @@ -433,11 +431,9 @@ ems_out(uint16_t port, uint8_t val, void *priv) static void consecutive_ems_out(uint16_t port, uint8_t val, void *priv) { - memdev_t *dev = (memdev_t *) priv; - int vpage; - + memdev_t *dev = (memdev_t *) priv; /* Get the viewport page number. */ - vpage = (port - dev->base_addr[0]); + int vpage = (port - dev->base_addr[0]); isamem_log("ISAMEM: write(%04x, %02x) to page mapping registers! (page=%d)\n", port, val, vpage); @@ -483,8 +479,7 @@ isamem_init(const device_t *info) uint8_t *ptr; /* Find our device and create an instance. */ - dev = (memdev_t *) malloc(sizeof(memdev_t)); - memset(dev, 0x00, sizeof(memdev_t)); + dev = (memdev_t *) calloc(1, sizeof(memdev_t)); dev->name = info->name; dev->board = info->local; @@ -579,7 +574,7 @@ isamem_init(const device_t *info) dev->flags |= FLAG_FAST; break; - case ISAMEM_LOTECH_CARD: /* Lotech EMS */ + case ISAMEM_LOTECH_EMS_CARD: /* Lotech EMS */ /* The Lotech EMS cannot have more than 4096KB per board. */ ems_max = EMS_LOTECH_MAXSIZE; fallthrough; @@ -801,7 +796,7 @@ isamem_init(const device_t *info) mem_mapping_disable(&dev->ems[i].mapping); /* Set up an I/O port handler. */ - if (dev->board != ISAMEM_LOTECH_CARD) + if (dev->board != ISAMEM_LOTECH_EMS_CARD) io_sethandler(dev->base_addr[0] + (EMS_PGSIZE * i), 2, ems_in, NULL, NULL, ems_out, NULL, NULL, &(dev->ems[i])); @@ -832,7 +827,7 @@ isamem_init(const device_t *info) } } - if (dev->board == ISAMEM_LOTECH_CARD) + if (dev->board == ISAMEM_LOTECH_EMS_CARD) io_sethandler(dev->base_addr[0], 4, consecutive_ems_in, NULL, NULL, consecutive_ems_out, NULL, NULL, dev); } @@ -856,32 +851,34 @@ isamem_close(void *priv) static const device_config_t ibmxt_32k_config[] = { // clang-format off { - .name = "size", - .description = "Memory size", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 32, - .file_filter = "", - .spinner = { - .min = 32, - .max = 576, - .step = 32 + .name = "size", + .description = "Memory size", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 32, + .file_filter = NULL, + .spinner = { + .min = 32, + .max = 576, + .step = 32 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "start", - .description = "Start Address", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 64, - .file_filter = "", - .spinner = { - .min = 0, - .max = 608, - .step = 32 + .name = "start", + .description = "Start Address", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 64, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 608, + .step = 32 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -895,7 +892,7 @@ static const device_t ibmxt_32k_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ibmxt_32k_config @@ -904,32 +901,34 @@ static const device_t ibmxt_32k_device = { static const device_config_t ibmxt_64k_config[] = { // clang-format off { - .name = "size", - .description = "Memory size", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 64, - .file_filter = "", - .spinner = { - .min = 64, - .max = 576, - .step = 64 + .name = "size", + .description = "Memory size", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 64, + .file_filter = NULL, + .spinner = { + .min = 64, + .max = 576, + .step = 64 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "start", - .description = "Start Address", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 64, - .file_filter = "", - .spinner = { - .min = 0, - .max = 576, - .step = 64 + .name = "start", + .description = "Start Address", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 64, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 576, + .step = 64 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -943,7 +942,7 @@ static const device_t ibmxt_64k_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ibmxt_64k_config @@ -952,32 +951,34 @@ static const device_t ibmxt_64k_device = { static const device_config_t ibmxt_config[] = { // clang-format off { - .name = "size", - .description = "Memory size", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 128, - .file_filter = "", - .spinner = { - .min = 64, - .max = 576, - .step = 64 + .name = "size", + .description = "Memory size", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 128, + .file_filter = NULL, + .spinner = { + .min = 64, + .max = 576, + .step = 64 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "start", - .description = "Start Address", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 256, - .file_filter = "", - .spinner = { - .min = 0, - .max = 576, - .step = 64 + .name = "start", + .description = "Start Address", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 256, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 576, + .step = 64 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -991,7 +992,7 @@ static const device_t ibmxt_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ibmxt_config @@ -1000,37 +1001,40 @@ static const device_t ibmxt_device = { static const device_config_t genericxt_config[] = { // clang-format off { - .name = "size", - .description = "Memory size", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 16, - .file_filter = "", - .spinner = { - .min = 0, - .max = 640, - .step = 16 + .name = "size", + .description = "Memory size", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 16, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 640, + .step = 16 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "start", - .description = "Start Address", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { - .min = 0, - .max = 624, - .step = 16 + .name = "start", + .description = "Start Address", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 640, + .step = 16 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; +// This also nicely accounts for the Everex EV-138 static const device_t genericxt_device = { .name = "Generic PC/XT Memory Expansion", .internal_name = "genericxt", @@ -1039,7 +1043,7 @@ static const device_t genericxt_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = genericxt_config @@ -1048,32 +1052,34 @@ static const device_t genericxt_device = { static const device_config_t msramcard_config[] = { // clang-format off { - .name = "size", - .description = "Memory size", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 64, - .file_filter = "", - .spinner = { - .min = 0, - .max = 256, - .step = 64 + .name = "size", + .description = "Memory size", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 64, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 256, + .step = 64 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "start", - .description = "Start Address", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { - .min = 0, - .max = 624, - .step = 64 + .name = "start", + .description = "Start Address", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 624, + .step = 64 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -1087,7 +1093,7 @@ static const device_t msramcard_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = msramcard_config @@ -1096,32 +1102,34 @@ static const device_t msramcard_device = { static const device_config_t mssystemcard_config[] = { // clang-format off { - .name = "size", - .description = "Memory size", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 64, - .file_filter = "", - .spinner = { - .min = 0, - .max = 256, - .step = 64 + .name = "size", + .description = "Memory size", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 64, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 256, + .step = 64 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "start", - .description = "Start Address", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { - .min = 0, - .max = 624, - .step = 64 + .name = "start", + .description = "Start Address", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 624, + .step = 64 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -1135,7 +1143,7 @@ static const device_t mssystemcard_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = mssystemcard_config @@ -1149,7 +1157,7 @@ static const device_t ibmat_128k_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1158,32 +1166,34 @@ static const device_t ibmat_128k_device = { static const device_config_t ibmat_config[] = { // clang-format off { - .name = "size", - .description = "Memory size", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 512, - .file_filter = "", - .spinner = { - .min = 0, - .max = 12288, - .step = 512 + .name = "size", + .description = "Memory size", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 512, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 12288, + .step = 512 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "start", - .description = "Start Address", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 1024, - .file_filter = "", - .spinner = { - .min = 0, - .max = 15872, - .step = 512 + .name = "start", + .description = "Start Address", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 1024, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 15872, + .step = 512 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -1197,7 +1207,7 @@ static const device_t ibmat_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ibmat_config @@ -1206,37 +1216,40 @@ static const device_t ibmat_device = { static const device_config_t genericat_config[] = { // clang-format off { - .name = "size", - .description = "Memory size", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 512, - .file_filter = "", - .spinner = { - .min = 0, - .max = 16384, - .step = 128 + .name = "size", + .description = "Memory size", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 512, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 16384, + .step = 128 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "start", - .description = "Start Address", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 1024, - .file_filter = "", - .spinner = { - .min = 0, - .max = 15872, - .step = 128 + .name = "start", + .description = "Start Address", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 1024, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 15872, + .step = 128 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; +// This also nicely accounts for the Everex EV-135 static const device_t genericat_device = { .name = "Generic PC/AT Memory Expansion", .internal_name = "genericat", @@ -1245,7 +1258,7 @@ static const device_t genericat_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = genericat_config @@ -1254,32 +1267,34 @@ static const device_t genericat_device = { static const device_config_t p5pak_config[] = { // clang-format off { - .name = "size", - .description = "Memory size", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 128, - .file_filter = "", - .spinner = { - .min = 0, - .max = 384, - .step = 64 + .name = "size", + .description = "Memory size", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 128, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 384, + .step = 64 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "start", - .description = "Start Address", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 512, - .file_filter = "", - .spinner = { - .min = 64, - .max = 576, - .step = 64 + .name = "start", + .description = "Start Address", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 512, + .file_filter = NULL, + .spinner = { + .min = 64, + .max = 576, + .step = 64 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -1293,7 +1308,7 @@ static const device_t p5pak_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = p5pak_config @@ -1302,32 +1317,34 @@ static const device_t p5pak_device = { static const device_config_t a6pak_config[] = { // clang-format off { - .name = "size", - .description = "Memory size", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 64, - .file_filter = "", - .spinner = { - .min = 0, - .max = 576, - .step = 64 + .name = "size", + .description = "Memory size", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 64, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 384, + .step = 64 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "start", - .description = "Start Address", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 256, - .file_filter = "", - .spinner = { - .min = 64, - .max = 512, - .step = 64 + .name = "start", + .description = "Start Address", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 256, + .file_filter = NULL, + .spinner = { + .min = 64, + .max = 512, + .step = 64 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -1341,7 +1358,7 @@ static const device_t a6pak_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = a6pak_config @@ -1350,28 +1367,29 @@ static const device_t a6pak_device = { static const device_config_t ems5150_config[] = { // clang-format off { - .name = "size", - .description = "Memory size", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 256, - .file_filter = "", - .spinner = { - .min = 0, - .max = 2048, - .step = 64 + .name = "size", + .description = "Memory size", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 256, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 2048, + .step = 64 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Disabled", .value = 0x0000 }, { .description = "Board 1", .value = 0x0208 }, { .description = "Board 2", .value = 0x020a }, @@ -1379,6 +1397,7 @@ static const device_config_t ems5150_config[] = { { .description = "Board 4", .value = 0x020e }, { .description = "" } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -1392,7 +1411,7 @@ static const device_t ems5150_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ems5150_config @@ -1401,98 +1420,104 @@ static const device_t ems5150_device = { static const device_config_t ev159_config[] = { // clang-format off { - .name = "size", - .description = "Memory size", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 512, - .file_filter = "", - .spinner = { - .min = 0, - .max = 3072, - .step = 512 + .name = "size", + .description = "Memory size", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 512, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 3072, + .step = 512 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "start", - .description = "Start Address", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { - .min = 0, - .max = 16128, - .step = 128 + .name = "start", + .description = "Start Address", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 16128, + .step = 128 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "length", - .description = "Contiguous Size", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { - .min = 0, - .max = 16384, - .step = 128 + .name = "length", + .description = "Contiguous Size", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 16384, + .step = 128 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "width", - .description = "I/O Width", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "width", + .description = "I/O Width", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "8-bit", .value = 0 }, { .description = "16-bit", .value = 1 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "speed", - .description = "Transfer Speed", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "speed", + .description = "Transfer Speed", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Standard (150ns)", .value = 0 }, { .description = "High-Speed (120ns)", .value = 1 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "ems", - .description = "EMS mode", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "ems", + .description = "EMS mode", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Disabled", .value = 0 }, { .description = "Enabled", .value = 1 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x0258, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x0258, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "208H", .value = 0x0208 }, { .description = "218H", .value = 0x0218 }, { .description = "258H", .value = 0x0258 }, @@ -1502,16 +1527,17 @@ static const device_config_t ev159_config[] = { { .description = "2E8H", .value = 0x02E8 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "base2", - .description = "Address for > 2 MB", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x0268, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base2", + .description = "Address for > 2 MB", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x0268, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "208H", .value = 0x0208 }, { .description = "218H", .value = 0x0218 }, { .description = "258H", .value = 0x0258 }, @@ -1521,6 +1547,7 @@ static const device_config_t ev159_config[] = { { .description = "2E8H", .value = 0x02E8 }, { .description = "" } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -1534,7 +1561,7 @@ static const device_t ev159_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ev159_config @@ -1543,70 +1570,74 @@ static const device_t ev159_device = { static const device_config_t ev165a_config[] = { // clang-format off { - .name = "size", - .description = "Memory size", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 512, - .file_filter = "", - .spinner = { - .min = 0, - .max = 2048, - .step = 512 + .name = "size", + .description = "Memory size", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 256, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 2048, + .step = 256 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "start", - .description = "Start Address", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { - .min = 0, - .max = 896, - .step = 128 + .name = "start", + .description = "Start Address", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 64, + .file_filter = NULL, + .spinner = { + .min = 64, + .max = 640, + .step = 64 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "length", .description = "Contiguous Size", .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { - .min = 0, - .max = 16384, - .step = 128 + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 2048, + .step = 256 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "ems", - .description = "EMS mode", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "ems", + .description = "EMS mode", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Disabled", .value = 0 }, { .description = "Enabled", .value = 1 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x0258, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x0258, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "208H", .value = 0x0208 }, { .description = "218H", .value = 0x0218 }, { .description = "258H", .value = 0x0258 }, @@ -1616,20 +1647,21 @@ static const device_config_t ev165a_config[] = { { .description = "2E8H", .value = 0x02E8 }, { .description = "" } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; static const device_t ev165a_device = { - .name = "Everex Magi Magic EV-165A", + .name = "Everex Maxi Magic EV-165A", .internal_name = "ev165a", .flags = DEVICE_ISA, .local = ISAMEM_EV165A_CARD, .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ev165a_config @@ -1638,48 +1670,51 @@ static const device_t ev165a_device = { static const device_config_t brxt_config[] = { // clang-format off { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x0268, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x0268, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "208H", .value = 0x0208 }, { .description = "218H", .value = 0x0218 }, { .description = "258H", .value = 0x0258 }, { .description = "268H", .value = 0x0268 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "frame", - .description = "Frame Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0xD0000, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { .description = "D000H", .value = 0xD0000 }, - { .description = "E000H", .value = 0xE0000 }, - { .description = "" } + .name = "frame", + .description = "Frame Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0xD0000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "D000H", .value = 0xD0000 }, + { .description = "E000H", .value = 0xE0000 }, + { .description = "" } }, + .bios = { { 0 } } }, { - .name = "size", - .description = "Memory size", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 512, - .file_filter = "", - .spinner = { - .min = 0, - .max = 2048, - .step = 512 + .name = "size", + .description = "Memory size", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 512, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 2048, + .step = 512 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -1693,7 +1728,7 @@ static const device_t brxt_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = brxt_config @@ -1703,89 +1738,96 @@ static const device_t brxt_device = { static const device_config_t brat_config[] = { // clang-format off { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x0268, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x0268, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "208H", .value = 0x0208 }, { .description = "218H", .value = 0x0218 }, { .description = "258H", .value = 0x0258 }, { .description = "268H", .value = 0x0268 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "frame", - .description = "Frame Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0xD0000, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "frame", + .description = "Frame Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0xD0000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "D000H", .value = 0xD0000 }, { .description = "E000H", .value = 0xE0000 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "width", - .description = "I/O Width", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 8, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "width", + .description = "I/O Width", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 8, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "8-bit", .value = 8 }, { .description = "16-bit", .value = 16 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "speed", - .description = "Transfer Speed", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "speed", + .description = "Transfer Speed", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Standard", .value = 0 }, { .description = "High-Speed", .value = 1 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "size", - .description = "Memory size", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 512, - .file_filter = "", - .spinner = { - .min = 0, - .max = 4096, - .step = 512 + .name = "size", + .description = "Memory size", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 512, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 4096, + .step = 512 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "start", - .description = "Start Address", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { - .min = 0, - .max = 14336, - .step = 512 + .name = "start", + .description = "Start Address", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 14336, + .step = 512 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -1799,7 +1841,7 @@ static const device_t brat_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = brat_config @@ -1809,66 +1851,69 @@ static const device_t brat_device = { static const device_config_t lotech_config[] = { // clang-format off { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x0260, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x0260, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "260H", .value = 0x0260 }, { .description = "264H", .value = 0x0264 }, { .description = "268H", .value = 0x0268 }, { .description = "26CH", .value = 0x026C }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "frame", - .description = "Frame Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0xe0000, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "frame", + .description = "Frame Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0xe0000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "C000H", .value = 0xC0000 }, { .description = "D000H", .value = 0xD0000 }, { .description = "E000H", .value = 0xE0000 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "size", - .description = "Memory size", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 2048, - .file_filter = "", - .spinner = { - .min = 512, - .max = 4096, - .step = 512 + .name = "size", + .description = "Memory size", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 2048, + .file_filter = NULL, + .spinner = { + .min = 512, + .max = 4096, + .step = 512 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; -static const device_t lotech_device = { - .name = "Lo-tech EMS Board", +static const device_t lotech_ems_device = { + .name = "Lo-tech EMS Board", .internal_name = "lotechems", - .flags = DEVICE_ISA, - .local = ISAMEM_LOTECH_CARD, - .init = isamem_init, - .close = isamem_close, - .reset = NULL, - { .available = NULL }, + .flags = DEVICE_ISA, + .local = ISAMEM_LOTECH_EMS_CARD, + .init = isamem_init, + .close = isamem_close, + .reset = NULL, + .available = NULL, .speed_changed = NULL, - .force_redraw = NULL, - .config = lotech_config + .force_redraw = NULL, + .config = lotech_config }; #ifdef USE_ISAMEM_RAMPAGE @@ -1877,14 +1922,14 @@ static const device_t lotech_device = { static const device_config_t rampage_config[] = { // clang-format off { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x0218, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x0218, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "208H", .value = 0x0208 }, { .description = "218H", .value = 0x0218 }, { .description = "258H", .value = 0x0258 }, @@ -1894,33 +1939,37 @@ static const device_config_t rampage_config[] = { { .description = "2E8H", .value = 0x02E8 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "size", - .description = "Memory size", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 256, /* Technically 128k, but banks 2-7 must be 256, headaches elsewise */ - .file_filter = "", - .spinner = { - .min = 256, - .max = 2048, - .step = 256 + .name = "size", + .description = "Memory size", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 256, /* Technically 128k, but banks 2-7 must be 256, headaches elsewise */ + .file_filter = NULL, + .spinner = { + .min = 256, + .max = 2048, + .step = 256 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "start", - .description = "Start Address", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 640, - .file_filter = "", - .spinner = { - .min = 0, - .max = 640, - .step = 64 + .name = "start", + .description = "Start Address", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 640, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 640, + .step = 64 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -1934,7 +1983,7 @@ static const device_t rampage_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = rampage_config @@ -1945,14 +1994,14 @@ static const device_t rampage_device = { static const device_config_t iab_config[] = { // clang-format off { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x0258, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x0258, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "208H", .value = 0x0208 }, { .description = "218H", .value = 0x0218 }, { .description = "258H", .value = 0x0258 }, @@ -1962,64 +2011,69 @@ static const device_config_t iab_config[] = { { .description = "2E8H", .value = 0x02E8 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "frame", - .description = "Frame Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "frame", + .description = "Frame Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Disabled", .value = 0x00000 }, { .description = "C000H", .value = 0xC0000 }, { .description = "D000H", .value = 0xD0000 }, { .description = "E000H", .value = 0xE0000 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "width", - .description = "I/O Width", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 8, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "width", + .description = "I/O Width", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 8, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "8-bit", .value = 8 }, { .description = "16-bit", .value = 16 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "speed", - .description = "Transfer Speed", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "speed", + .description = "Transfer Speed", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Standard", .value = 0 }, { .description = "High-Speed", .value = 1 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "size", - .description = "Memory size", - .type = CONFIG_SPINNER, - .default_string = "", - .default_int = 128, - .file_filter = "", - .spinner = { - .min = 0, - .max = 8192, - .step = 128 + .name = "size", + .description = "Memory size", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 128, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 8192, + .step = 128 }, - .selection = { { 0 } } + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -2033,7 +2087,7 @@ static const device_t iab_device = { .init = isamem_init, .close = isamem_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = iab_config @@ -2072,7 +2126,7 @@ static const struct { #ifdef USE_ISAMEM_IAB { &iab_device }, #endif /* USE_ISAMEM_IAB */ - { &lotech_device }, + { &lotech_ems_device }, { NULL } // clang-format on }; @@ -2111,12 +2165,12 @@ isamem_get_internal_name(int board) } int -isamem_get_from_internal_name(const char *s) +isamem_get_from_internal_name(const char *str) { int c = 0; while (boards[c].dev != NULL) { - if (!strcmp(boards[c].dev->internal_name, s)) + if (!strcmp(boards[c].dev->internal_name, str)) return c; c++; } diff --git a/src/device/isapnp.c b/src/device/isapnp.c index 470147953..1ee8be040 100644 --- a/src/device/isapnp.c +++ b/src/device/isapnp.c @@ -121,6 +121,25 @@ typedef struct { isapnp_device_t *current_ld; } isapnp_t; +static isapnp_device_t * +isapnp_create_ld(isapnp_card_t *card) +{ + /* Allocate logical device. */ + isapnp_device_t *ld = calloc(1, sizeof(isapnp_device_t)); + + /* Add to the end of the card's logical device list. */ + isapnp_device_t *prev_ld = card->first_ld; + if (prev_ld) { + while (prev_ld->next) + prev_ld = prev_ld->next; + prev_ld->next = ld; + } else { + card->first_ld = ld; + } + + return ld; +} + static void isapnp_device_config_changed(isapnp_card_t *card, isapnp_device_t *ld) { @@ -532,8 +551,12 @@ isapnp_write_common(isapnp_t *dev, isapnp_card_t *card, isapnp_device_t *ld, uin ld = ld->next; } - if (!ld) - isapnp_log("ISAPnP: CSN %02X has no device %02X\n", card->csn, val); + if (!ld) { + isapnp_log("ISAPnP: CSN %02X has no device %02X, creating one\n", card->csn, val); + dev->current_ld_card = card; + dev->current_ld = isapnp_create_ld(card); + dev->current_ld->number = val; + } break; @@ -656,7 +679,7 @@ isapnp_write_data(UNUSED(uint16_t addr), uint8_t val, void *priv) static void * isapnp_init(UNUSED(const device_t *info)) { - isapnp_t *dev = (isapnp_t *) malloc(sizeof(isapnp_t)); + isapnp_t *dev = (isapnp_t *) calloc(1, sizeof(isapnp_t)); memset(dev, 0, sizeof(isapnp_t)); io_sethandler(0x279, 1, NULL, NULL, NULL, isapnp_write_addr, NULL, NULL, dev); @@ -705,8 +728,7 @@ isapnp_add_card(uint8_t *rom, uint16_t rom_size, if (!dev) dev = (isapnp_t *) device_add(&isapnp_device); - isapnp_card_t *card = (isapnp_card_t *) malloc(sizeof(isapnp_card_t)); - memset(card, 0, sizeof(isapnp_card_t)); + isapnp_card_t *card = (isapnp_card_t *) calloc(1, sizeof(isapnp_card_t)); card->enable = 1; card->priv = priv; @@ -763,8 +785,7 @@ isapnp_update_card_rom(void *priv, uint8_t *rom, uint16_t rom_size) uint8_t mem_range_df = 0; uint8_t mem_range_32_df = 0; uint32_t len; - isapnp_device_t *ld = NULL; - isapnp_device_t *prev_ld = NULL; + isapnp_device_t *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. @@ -912,18 +933,7 @@ isapnp_update_card_rom(void *priv, uint8_t *rom, uint16_t rom_size) memset(ld->io_len, 0, sizeof(ld->io_len)); } else { /* Create logical device. */ - ld = (isapnp_device_t *) malloc(sizeof(isapnp_device_t)); - memset(ld, 0, sizeof(isapnp_device_t)); - - /* Add to end of list. */ - prev_ld = card->first_ld; - if (prev_ld) { - while (prev_ld->next) - prev_ld = prev_ld->next; - prev_ld->next = ld; - } else { - card->first_ld = ld; - } + ld = isapnp_create_ld(card); } /* Set and increment logical device number. */ @@ -1220,7 +1230,7 @@ static const device_t isapnp_device = { .init = isapnp_init, .close = isapnp_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/isarom.c b/src/device/isarom.c new file mode 100644 index 000000000..f742a9eae --- /dev/null +++ b/src/device/isarom.c @@ -0,0 +1,643 @@ +/* + * 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 ISA ROM card Expansions. + * + * Authors: Jasmine Iwanek, + * + * Copyright 2025 Jasmine Iwanek. + */ +#include +#include +#include +#include +#include +#define HAVE_STDARG_H +#include <86box/86box.h> +#include <86box/io.h> +#include <86box/device.h> +#include <86box/mem.h> +#include <86box/rom.h> +#include <86box/nvr.h> +#include <86box/isarom.h> + +#define ISAROM_CARD 0 +#define ISAROM_CARD_DUAL 1 +#define ISAROM_CARD_QUAD 2 + +#ifdef ENABLE_ISAROM_LOG +int isarom_do_log = ENABLE_ISAROM_LOG; + +static void +isarom_log(const char *fmt, ...) +{ + va_list ap; + + if (isarom_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define isarom_log(fmt, ...) +#endif + +typedef struct isarom_t { + struct { + rom_t rom; + uint32_t addr; + const char *fn; + uint32_t size; + uint32_t len; + char nvr_path[64]; + uint8_t wp; + } socket[4]; + uint8_t inst; + uint8_t type; +} isarom_t; + +static inline uint8_t +get_limit(uint8_t type) +{ + if (type == ISAROM_CARD_DUAL) + return 2; + if (type == ISAROM_CARD_QUAD) + return 4; + return 1; +} + +static inline void +isarom_save_nvr(char *path, uint8_t *data, size_t size) +{ + if (path[0] == 0x00) + return; + + FILE *fp = nvr_fopen(path, "wb"); + if (fp) { + fwrite(data, 1, size, fp); + fclose(fp); + } +} + +void +isarom_close(void *priv) +{ + isarom_t *dev = (isarom_t *) priv; + if (!priv) + return; + + for (uint8_t i = 0; i < get_limit(dev->type); i++) + if (dev->socket[i].rom.rom) { + isarom_log("isarom[%u]: saving NVR for socket %u -> %s (%u bytes)\n", + dev->inst, i, dev->socket[i].nvr_path, dev->socket[i].size); + isarom_save_nvr(dev->socket[i].nvr_path, dev->socket[i].rom.rom, dev->socket[i].size); + } + + free(dev); +} + +static void * +isarom_init(const device_t *info) +{ + isarom_t *dev = (isarom_t *) calloc(1, sizeof(isarom_t)); + if (!dev) + return NULL; + + dev->inst = device_get_instance(); + dev->type = (uint8_t) info->local; + + isarom_log("isarom[%u]: initializing device (type=%u)\n", dev->inst, dev->type); + + for (uint8_t i = 0; i < get_limit(dev->type); i++) { + char key_fn[12]; + char key_addr[14]; + char key_size[14]; + char key_writes[22]; + char suffix[4] = ""; + if (i > 0) + snprintf(suffix, sizeof(suffix), "%d", i + 1); + + snprintf(key_fn, sizeof(key_fn), "bios_fn%s", suffix); + snprintf(key_addr, sizeof(key_addr), "bios_addr%s", suffix); + snprintf(key_size, sizeof(key_size), "bios_size%s", suffix); + snprintf(key_writes, sizeof(key_writes), "rom_writes_enabled%s", suffix); + + dev->socket[i].fn = device_get_config_string(key_fn); + dev->socket[i].addr = device_get_config_hex20(key_addr); + dev->socket[i].size = device_get_config_int(key_size); + // Note: 2K is the smallest ROM I've found, but 86box's memory granularity is 4k, the number below is fine + // as we'll end up allocating no less than 4k due to the device config limits. + dev->socket[i].len = (dev->socket[i].size > 2048) ? dev->socket[i].size - 1 : 0; + dev->socket[i].wp = (uint8_t) device_get_config_int(key_writes) ? 1 : 0; + + isarom_log("isarom[%u]: socket %u: addr=0x%05X size=%u wp=%u fn=%s\n", + dev->inst, i, dev->socket[i].addr, dev->socket[i].size, + dev->socket[i].wp, dev->socket[i].fn ? dev->socket[i].fn : "(null)"); + + if (dev->socket[i].addr != 0 && dev->socket[i].fn != NULL) { + rom_init(&dev->socket[i].rom, + dev->socket[i].fn, + dev->socket[i].addr, + dev->socket[i].size, + dev->socket[i].len, + 0, + MEM_MAPPING_EXTERNAL); + + isarom_log("isarom[%u]: ROM initialized for socket %u\n", dev->inst, i); + + if (dev->socket[i].wp) { + mem_mapping_set_write_handler(&dev->socket[i].rom.mapping, rom_write, rom_writew, rom_writel); + snprintf(dev->socket[i].nvr_path, sizeof(dev->socket[i].nvr_path), "isarom_%i_%i.nvr", dev->inst, i + 1); + FILE *fp = nvr_fopen(dev->socket[i].nvr_path, "rb"); + if (fp != NULL) { + fread(dev->socket[i].rom.rom, 1, dev->socket[i].size, fp); + fclose(fp); + isarom_log("isarom[%u]: loaded %zu bytes from %s\n", dev->inst, read_bytes, dev->socket[i].nvr_path); + } else + isarom_log("isarom[%u]: NVR not found, skipping load (%s)\n", dev->inst, dev->socket[i].nvr_path); + } + } + } + + return dev; +} + +#define BIOS_FILE_FILTER "ROM files (*.bin *.rom)|*.bin,*.rom" + +#define BIOS_ADDR_SELECTION { \ + { "Disabled", 0x00000 }, \ + { "C000H", 0xc0000 }, \ + { "C200H", 0xc2000 }, \ + { "C400H", 0xc4000 }, \ + { "C600H", 0xc6000 }, \ + { "C800H", 0xc8000 }, \ + { "CA00H", 0xca000 }, \ + { "CC00H", 0xcc000 }, \ + { "CE00H", 0xce000 }, \ + { "D000H", 0xd0000 }, \ + { "D200H", 0xd2000 }, \ + { "D400H", 0xd4000 }, \ + { "D600H", 0xd6000 }, \ + { "D800H", 0xd8000 }, \ + { "DA00H", 0xda000 }, \ + { "DC00H", 0xdc000 }, \ + { "DE00H", 0xde000 }, \ + { "E000H", 0xe0000 }, \ + { "E200H", 0xe2000 }, \ + { "E400H", 0xe4000 }, \ + { "E600H", 0xe6000 }, \ + { "E800H", 0xe8000 }, \ + { "EA00H", 0xea000 }, \ + { "EC00H", 0xec000 }, \ + { "EE00H", 0xee000 }, \ + { "", 0 } \ +} + +#define BIOS_SIZE_SELECTION { \ + { "4K", 4096 }, \ + { "8K", 8192 }, \ + { "16K", 16384 }, \ + { "32K", 32768 }, \ + { "64K", 65536 }, \ + { "", 0 } \ +} + +// clang-format off +static const device_config_t isarom_config[] = { + { + .name = "bios_fn", + .description = "BIOS file", + .type = CONFIG_FNAME, + .default_string = NULL, + .default_int = 0, + .file_filter = BIOS_FILE_FILTER, + .spinner = { 0 }, + .selection = { }, + .bios = { { 0 } } + }, + { + .name = "bios_addr", + .description = "BIOS Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0x00000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = BIOS_ADDR_SELECTION, + .bios = { { 0 } } + }, + { + .name = "bios_size", + .description = "BIOS size", + .type = CONFIG_INT, + .default_string = NULL, + .default_int = 8192, + .file_filter = NULL, + .spinner = { 0 }, + .selection = BIOS_SIZE_SELECTION, + .bios = { { 0 } } + }, + { + .name = "rom_writes_enabled", + .description = "Enable BIOS extension ROM Writes", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } +}; + +static const device_config_t isarom_dual_config[] = { + { + .name = "bios_fn", + .description = "BIOS file (ROM #1)", + .type = CONFIG_FNAME, + .default_string = NULL, + .default_int = 0, + .file_filter = BIOS_FILE_FILTER, + .spinner = { 0 }, + .selection = { }, + .bios = { { 0 } } + }, + { + .name = "bios_addr", + .description = "BIOS address (ROM #1)", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0x00000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = BIOS_ADDR_SELECTION, + .bios = { { 0 } } + }, + { + .name = "bios_size", + .description = "BIOS size (ROM #1)", + .type = CONFIG_INT, + .default_string = NULL, + .default_int = 8192, + .file_filter = NULL, + .spinner = { 0 }, + .selection = BIOS_SIZE_SELECTION, + .bios = { { 0 } } + }, + { + .name = "rom_writes_enabled", + .description = "Enable BIOS extension ROM Writes (ROM #1)", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { + .name = "bios_fn2", + .description = "BIOS file (ROM #2)", + .type = CONFIG_FNAME, + .default_string = NULL, + .default_int = 0, + .file_filter = BIOS_FILE_FILTER, + .spinner = { 0 }, + .selection = { }, + .bios = { { 0 } } + }, + { + .name = "bios_addr2", + .description = "BIOS address (ROM #2)", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0x00000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = BIOS_ADDR_SELECTION, + .bios = { { 0 } } + }, + { + .name = "bios_size2", + .description = "BIOS size (ROM #2)", + .type = CONFIG_INT, + .default_string = NULL, + .default_int = 8192, + .file_filter = NULL, + .spinner = { 0 }, + .selection = BIOS_SIZE_SELECTION, + .bios = { { 0 } } + }, + { + .name = "rom_writes_enabled2", + .description = "Enable BIOS extension ROM Writes (ROM #2)", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } +}; + +static const device_config_t isarom_quad_config[] = { + { + .name = "bios_fn", + .description = "BIOS file (ROM #1)", + .type = CONFIG_FNAME, + .default_string = NULL, + .default_int = 0, + .file_filter = BIOS_FILE_FILTER, + .spinner = { 0 }, + .selection = { }, + .bios = { { 0 } } + }, + { + .name = "bios_addr", + .description = "BIOS address (ROM #1)", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0x00000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = BIOS_ADDR_SELECTION, + .bios = { { 0 } } + }, + { + .name = "bios_size", + .description = "BIOS size (ROM #1)", + .type = CONFIG_INT, + .default_string = NULL, + .default_int = 8192, + .file_filter = NULL, + .spinner = { 0 }, + .selection = BIOS_SIZE_SELECTION, + .bios = { { 0 } } + }, + { + .name = "rom_writes_enabled", + .description = "Enable BIOS extension ROM Writes (ROM #1)", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { + .name = "bios_fn2", + .description = "BIOS file (ROM #2)", + .type = CONFIG_FNAME, + .default_string = NULL, + .default_int = 0, + .file_filter = BIOS_FILE_FILTER, + .spinner = { 0 }, + .selection = { }, + .bios = { { 0 } } + }, + { + .name = "bios_addr2", + .description = "BIOS address (ROM #2)", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0x00000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = BIOS_ADDR_SELECTION, + .bios = { { 0 } } + }, + { + .name = "bios_size2", + .description = "BIOS size (ROM #2)", + .type = CONFIG_INT, + .default_string = NULL, + .default_int = 8192, + .file_filter = NULL, + .spinner = { 0 }, + .selection = BIOS_SIZE_SELECTION, + .bios = { { 0 } } + }, + { + .name = "rom_writes_enabled2", + .description = "Enable BIOS extension ROM Writes (ROM #2)", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { + .name = "bios_fn3", + .description = "BIOS file (ROM #3)", + .type = CONFIG_FNAME, + .default_string = NULL, + .default_int = 0, + .file_filter = "ROM files (*.bin *.rom)|*.bin,*.rom", + .spinner = { 0 }, + .selection = { }, + .bios = { { 0 } } + }, + { + .name = "bios_addr3", + .description = "BIOS address (ROM #3)", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0x00000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = BIOS_ADDR_SELECTION, + .bios = { { 0 } } + }, + { + .name = "bios_size3", + .description = "BIOS size (ROM #3)", + .type = CONFIG_INT, + .default_string = NULL, + .default_int = 8192, + .file_filter = NULL, + .spinner = { 0 }, + .selection = BIOS_SIZE_SELECTION, + .bios = { { 0 } } + }, + { + .name = "rom_writes_enabled3", + .description = "Enable BIOS extension ROM Writes (ROM #3)", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { + .name = "bios_fn4", + .description = "BIOS file (ROM #4)", + .type = CONFIG_FNAME, + .default_string = NULL, + .default_int = 0, + .file_filter = BIOS_FILE_FILTER, + .spinner = { 0 }, + .selection = { }, + .bios = { { 0 } } + }, + { + .name = "bios_addr4", + .description = "BIOS address (ROM #4)", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0x00000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = BIOS_ADDR_SELECTION, + .bios = { { 0 } } + }, + { + .name = "bios_size4", + .description = "BIOS size (ROM #4)", + .type = CONFIG_INT, + .default_string = NULL, + .default_int = 8192, + .file_filter = NULL, + .spinner = { 0 }, + .selection = BIOS_SIZE_SELECTION, + .bios = { { 0 } } + }, + { + .name = "rom_writes_enabled4", + .description = "Enable BIOS extension ROM Writes (ROM #4)", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } +}; +// clang-format on + +static const device_t isarom_device = { + .name = "Generic ISA ROM Board", + .internal_name = "isarom", + .flags = DEVICE_ISA, + .local = ISAROM_CARD, + .init = isarom_init, + .close = isarom_close, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = isarom_config +}; + +static const device_t isarom_dual_device = { + .name = "Generic Dual ISA ROM Board", + .internal_name = "isarom_dual", + .flags = DEVICE_ISA, + .local = ISAROM_CARD_DUAL, + .init = isarom_init, + .close = isarom_close, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = isarom_dual_config +}; + +static const device_t isarom_quad_device = { + .name = "Generic Quad ISA ROM Board", + .internal_name = "isarom_quad", + .flags = DEVICE_ISA, + .local = ISAROM_CARD_QUAD, + .init = isarom_init, + .close = isarom_close, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = isarom_quad_config +}; + +static const struct { + const device_t *dev; +} boards[] = { + // clang-format off + { &device_none }, + { &isarom_device }, + { &isarom_dual_device }, + { &isarom_quad_device }, + { NULL } + // clang-format on +}; + +void +isarom_reset(void) +{ + for (uint8_t i = 0; i < ISAROM_MAX; i++) { + if (isarom_type[i] == 0) + continue; + + /* Add the device instance to the system. */ + device_add_inst(boards[isarom_type[i]].dev, i + 1); + } +} + +const char * +isarom_get_name(int board) +{ + if (boards[board].dev == NULL) + return NULL; + + return (boards[board].dev->name); +} + +const char * +isarom_get_internal_name(int board) +{ + return device_get_internal_name(boards[board].dev); +} + +int +isarom_get_from_internal_name(const char *str) +{ + int c = 0; + + while (boards[c].dev != NULL) { + if (!strcmp(boards[c].dev->internal_name, str)) + return c; + c++; + } + + /* Not found. */ + return 0; +} + +const device_t * +isarom_get_device(int board) +{ + /* Add the device instance to the system. */ + return boards[board].dev; +} + +int +isarom_has_config(int board) +{ + if (boards[board].dev == NULL) + return 0; + + return (boards[board].dev->config ? 1 : 0); +} diff --git a/src/device/isartc.c b/src/device/isartc.c index 7721d9885..0540dc1f0 100644 --- a/src/device/isartc.c +++ b/src/device/isartc.c @@ -76,17 +76,23 @@ #include <86box/machine.h> #include <86box/io.h> #include <86box/device.h> +#include <86box/mem.h> #include <86box/nvr.h> +#include <86box/rom.h> #include <86box/ui.h> #include <86box/plat.h> #include <86box/pic.h> #include <86box/isartc.h> -#define ISARTC_EV170 0 -#define ISARTC_DTK 1 -#define ISARTC_P5PAK 2 -#define ISARTC_A6PAK 3 -#define ISARTC_VENDEX 4 +#define ISARTC_EV170 0 +#define ISARTC_DTK 1 +#define ISARTC_P5PAK 2 +#define ISARTC_A6PAK 3 +#define ISARTC_VENDEX 4 +#define ISARTC_MM58167 10 + +#define ISARTC_ROM_MM58167_1 "roms/rtc/glatick/GLaTICK_0.8.5_NS_RP.ROM" +#define ISARTC_ROM_MM58167_2 "roms/rtc/glatick/GLaTICK_0.8.5_86B.ROM" #define ISARTC_DEBUG 0 @@ -101,6 +107,7 @@ typedef struct rtcdev_t { int8_t irq; /* configured IRQ channel */ int8_t base_addrsz; uint32_t base_addr; /* configured I/O address */ + rom_t rom; /* BIOS ROM, If configured */ /* Fields for the specific driver. */ void (*f_wr)(uint16_t, uint8_t, void *); @@ -513,8 +520,7 @@ isartc_init(const device_t *info) is_at = is_at || !strcmp(machine_get_internal_name(), "xi8088"); /* Create a device instance. */ - dev = (rtcdev_t *) malloc(sizeof(rtcdev_t)); - memset(dev, 0x00, sizeof(rtcdev_t)); + dev = (rtcdev_t *) calloc(1, sizeof(rtcdev_t)); dev->name = info->name; dev->board = info->local; dev->irq = -1; @@ -524,6 +530,14 @@ isartc_init(const device_t *info) /* Do per-board initialization. */ switch (dev->board) { + case ISARTC_MM58167: /* Generic MM58167 RTC */ + { + uint32_t rom_addr = device_get_config_hex20("bios_addr"); + if (rom_addr != 0) + rom_init(&dev->rom, ISARTC_ROM_MM58167_1, + rom_addr, 0x0800, 0x7ff, 0, MEM_MAPPING_EXTERNAL); + + } case ISARTC_EV170: /* Everex EV-170 Magic I/O */ dev->flags |= FLAG_YEAR80; dev->base_addr = device_get_config_hex16("base"); @@ -614,24 +628,38 @@ isartc_close(void *priv) static const device_config_t ev170_config[] = { // clang-format off { - "base", "Address", CONFIG_HEX16, "", 0x02C0, "", { 0 }, - { - { "240H", 0x0240 }, - { "2C0H", 0x02c0 }, - { "" } + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x02C0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "240H", .value = 0x0240 }, + { .description = "2C0H", .value = 0x02c0 }, + { .description = "" } }, + .bios = { { 0 } } }, { - "irq", "IRQ", CONFIG_SELECTION, "", -1, "", { 0 }, - { - { "Disabled", -1 }, - { "IRQ2", 2 }, - { "IRQ5", 5 }, - { "IRQ7", 7 }, - { "" } + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Disabled", .value = -1 }, + { .description = "IRQ2", .value = 2 }, + { .description = "IRQ5", .value = 5 }, + { .description = "IRQ7", .value = 7 }, + { .description = "" } }, + .bios = { { 0 } } }, - { "", "", -1 } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -643,7 +671,7 @@ static const device_t ev170_device = { .init = isartc_init, .close = isartc_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ev170_config @@ -652,14 +680,21 @@ static const device_t ev170_device = { static const device_config_t pii147_config[] = { // clang-format off { - "base", "Address", CONFIG_HEX16, "", 0x0240, "", { 0 }, - { - { "Clock 1", 0x0240 }, - { "Clock 2", 0x0340 }, - { "" } + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x0240, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Clock 1", .value = 0x0240 }, + { .description = "Clock 2", .value = 0x0340 }, + { .description = "" } }, + .bios = { { 0 } } }, - { "", "", -1 } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -671,7 +706,7 @@ static const device_t pii147_device = { .init = isartc_init, .close = isartc_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = pii147_config @@ -680,16 +715,23 @@ static const device_t pii147_device = { static const device_config_t p5pak_config[] = { // clang-format off { - "irq", "IRQ", CONFIG_SELECTION, "", -1, "", { 0 }, - { - { "Disabled", -1 }, - { "IRQ2", 2 }, - { "IRQ3", 3 }, - { "IRQ5", 5 }, - { "" } + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Disabled", -1 }, + { .description = "IRQ2", 2 }, + { .description = "IRQ3", 3 }, + { .description = "IRQ5", 5 }, + { .description = "" } }, + .bios = { { 0 } } }, - { "", "", -1 } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -701,7 +743,7 @@ static const device_t p5pak_device = { .init = isartc_init, .close = isartc_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = p5pak_config @@ -710,16 +752,23 @@ static const device_t p5pak_device = { static const device_config_t a6pak_config[] = { // clang-format off { - "irq", "IRQ", CONFIG_SELECTION, "", -1, "", { 0 }, - { - { "Disabled", -1 }, - { "IRQ2", 2 }, - { "IRQ3", 3 }, - { "IRQ5", 5 }, - { "" } + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Disabled", .value = -1 }, + { .description = "IRQ2", .value = 2 }, + { .description = "IRQ3", .value = 3 }, + { .description = "IRQ5", .value = 5 }, + { .description = "" } }, + .bios = { { 0 } } }, - { "", "", -1 } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -731,12 +780,99 @@ static const device_t a6pak_device = { .init = isartc_init, .close = isartc_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = a6pak_config }; +static const device_config_t mm58167_config[] = { + // clang-format off + { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x02C0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "240H", .value = 0x0240 }, + { .description = "2C0H", .value = 0x02c0 }, + { .description = "340H", .value = 0x0340 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Disabled", .value = -1 }, + { .description = "IRQ2", .value = 2 }, + { .description = "IRQ5", .value = 5 }, + { .description = "IRQ7", .value = 7 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { + .name = "bios_addr", + .description = "BIOS Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0xcc000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Disabled", .value = 0x00000 }, + { .description = "C800H", .value = 0xc8000 }, + { .description = "CA00H", .value = 0xca000 }, + { .description = "CC00H", .value = 0xcc000 }, + { .description = "CE00H", .value = 0xce000 }, + { .description = "D000H", .value = 0xd0000 }, + { .description = "D200H", .value = 0xd2000 }, + { .description = "D400H", .value = 0xd4000 }, + { .description = "D600H", .value = 0xd6000 }, + { .description = "D800H", .value = 0xd8000 }, + { .description = "DA00H", .value = 0xda000 }, + { .description = "DC00H", .value = 0xdc000 }, + { .description = "DE00H", .value = 0xde000 }, + { .description = "E000H", .value = 0xe0000 }, + { .description = "E200H", .value = 0xe2000 }, + { .description = "E400H", .value = 0xe4000 }, + { .description = "E600H", .value = 0xe6000 }, + { .description = "E800H", .value = 0xe8000 }, + { .description = "EA00H", .value = 0xea000 }, + { .description = "EC00H", .value = 0xec000 }, + { .description = "EE00H", .value = 0xee000 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on +}; + +static const device_t mm58167_device = { + .name = "Generic MM58167 RTC", + .internal_name = "rtc_mm58167", + .flags = DEVICE_ISA | DEVICE_SIDECAR, + .local = ISARTC_MM58167, + .init = isartc_init, + .close = isartc_close, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = mm58167_config +}; + /* Onboard RTC devices */ const device_t vendex_xt_rtc_onboard_device = { .name = "National Semiconductor MM58167 (Vendex)", @@ -746,7 +882,7 @@ const device_t vendex_xt_rtc_onboard_device = { .init = isartc_init, .close = isartc_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -756,12 +892,13 @@ static const struct { const device_t *dev; } boards[] = { // clang-format off - { &device_none }, - { &ev170_device }, - { &pii147_device }, - { &p5pak_device }, - { &a6pak_device }, - { NULL }, + { &device_none }, + { &ev170_device }, + { &pii147_device }, + { &p5pak_device }, + { &a6pak_device }, + { &mm58167_device }, + { NULL } // clang-format on }; @@ -782,12 +919,12 @@ isartc_get_internal_name(int board) } int -isartc_get_from_internal_name(char *s) +isartc_get_from_internal_name(const char *str) { int c = 0; while (boards[c].dev != NULL) { - if (!strcmp(boards[c].dev->internal_name, s)) + if (!strcmp(boards[c].dev->internal_name, str)) return c; c++; } diff --git a/src/device/kbc_at.c b/src/device/kbc_at.c index 5c3c9ac6e..d19b08f84 100644 --- a/src/device/kbc_at.c +++ b/src/device/kbc_at.c @@ -145,6 +145,11 @@ typedef struct atkbc_t { /* Internal FIFO for the purpose of commands with multi-byte output. */ uint8_t key_ctrl_queue[64]; + uint8_t handler_enable[2]; + + uint16_t base_addr[2]; + uint16_t irq[2]; + uint32_t flags; /* Main timers. */ @@ -157,8 +162,13 @@ typedef struct atkbc_t { /* 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 *priv, uint8_t val); - uint8_t (*write64_ven)(void *priv, uint8_t val); + struct { + uint8_t (*read)(uint16_t port, void *priv); + void (*write)(uint16_t port, uint8_t val, void *priv); + } handlers[2]; + + uint8_t (*write_cmd_data_ven)(void *priv, uint8_t val); + uint8_t (*write_cmd_ven)(void *priv, uint8_t val); } atkbc_t; /* Keyboard controller ports. */ @@ -167,8 +177,6 @@ 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 uint8_t kbc_handler_set = 0; - static void (*kbc_at_do_poll)(atkbc_t *dev); /* Non-translated to translated scan codes. */ @@ -362,12 +370,19 @@ kbc_do_irq(atkbc_t *dev) if (dev->do_irq) { /* 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. */ - picint_common(1 << 1, 0, 0, NULL); - picint_common(1 << 12, 0, 0, NULL); - if (dev->channel >= 2) - picint_common(1 << 12, 0, 1, NULL); - else - picint_common(1 << 1, 0, 1, NULL); + if (dev->irq[0] != 0xffff) + picint_common(1 << dev->irq[0], 0, 0, NULL); + + if (dev->irq[1] != 0xffff) + picint_common(1 << dev->irq[1], 0, 0, NULL); + + if (dev->channel >= 2) { + if (dev->irq[1] != 0xffff) + picint_common(1 << dev->irq[1], 0, 1, NULL); + } else { + if (dev->irq[0] != 0xffff) + picint_common(1 << dev->irq[0], 0, 1, NULL); + } dev->do_irq = 0; } @@ -404,7 +419,9 @@ kbc_send_to_ob(atkbc_t *dev, uint8_t val, uint8_t channel, uint8_t stat_hi) } else if (dev->mem[0x20] & 0x01) kbc_set_do_irq(dev, channel); } else if (dev->mem[0x20] & 0x01) - picintlevel(1 << 1, &dev->irq_state); /* AT KBC: IRQ 1 is level-triggered because it is tied to OBF. */ + /* AT KBC: IRQ 1 is level-triggered because it is tied to OBF. */ + if (dev->irq[0] != 0xffff) + picintlevel(1 << dev->irq[0], &dev->irq_state); #ifdef WRONG_CONDITION if ((dev->channel > 0) || dev->is_asic || (kbc_ven == KBC_VEN_IBM_PS1) || (kbc_ven == KBC_VEN_IBM)) @@ -509,9 +526,6 @@ kbc_scan_kbd_at(atkbc_t *dev) } } -static void -write_p2(atkbc_t *dev, uint8_t val); - static void kbc_at_poll_at(atkbc_t *dev) { @@ -778,6 +792,7 @@ 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; @@ -786,10 +801,12 @@ write_p2(atkbc_t *dev, uint8_t val) /* PS/2: Handle IRQ's. */ if (dev->misc_flags & FLAG_PS2) { /* IRQ 12 */ - picint_common(1 << 12, 0, val & 0x20, NULL); + if (dev->irq[1] != 0xffff) + picint_common(1 << dev->irq[1], 0, val & 0x20, NULL); /* IRQ 1 */ - picint_common(1 << 1, 0, val & 0x10, NULL); + if (dev->irq[0] != 0xffff) + picint_common(1 << dev->irq[0], 0, val & 0x10, NULL); } #endif @@ -810,27 +827,20 @@ write_p2(atkbc_t *dev, uint8_t val) 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) || !strcmp(machine_get_internal_name(), "spc7700plw")) - smbase = 0x00030000; + softresetx86(); /* Pulse reset! */ + cpu_set_edx(); + flushmmucache(); + if ((kbc_ven == KBC_VEN_ALI) || + !strcmp(machine_get_internal_name(), "spc7700plw") || + !strcmp(machine_get_internal_name(), "pl4600c")) + 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. */ - if ((kbc_ven == KBC_VEN_SIEMENS) || !strcmp(machine_get_internal_name(), "acera1g")) - is486 ? loadcs(0xf000) : loadcs_2386(0xf000); - } + /* 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. */ + if ((kbc_ven == KBC_VEN_SIEMENS) || !strcmp(machine_get_internal_name(), "acera1g")) + is486 ? loadcs(0xf000) : loadcs_2386(0xf000); } } @@ -860,6 +870,25 @@ write_p2(atkbc_t *dev, uint8_t val) } } +uint8_t +kbc_at_read_p(void *priv, uint8_t port, uint8_t mask) +{ + atkbc_t *dev = (atkbc_t *) priv; + uint8_t *p = (port == 2) ? &dev->p2 : &dev->p1; + uint8_t ret = *p & mask; + + return ret; +} + +void +kbc_at_write_p(void *priv, uint8_t port, uint8_t mask, uint8_t val) +{ + atkbc_t *dev = (atkbc_t *) priv; + uint8_t *p = (port == 2) ? &dev->p2 : &dev->p1; + + *p = (*p & mask) | val; +} + static void write_p2_fast_a20(atkbc_t *dev, uint8_t val) { @@ -924,220 +953,7 @@ pulse_poll(void *priv) } 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; - - /* TODO: Make this command do nothing on the Regional HT6542, - or else, Efflixi's Award OPTi 495 BIOS gets a stuck key - in Norton Commander 3.0. */ - 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"; - Compaq: 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) +write_cmd_data_ami(void *priv, uint8_t val) { atkbc_t *dev = (atkbc_t *) priv; @@ -1207,39 +1023,47 @@ kbc_at_set_ps2(void *priv, const uint8_t ps2) } static uint8_t -write64_ami(void *priv, uint8_t val) +write_cmd_ami(void *priv, uint8_t val) { atkbc_t *dev = (atkbc_t *) priv; uint8_t kbc_ven = dev->flags & KBC_VEN_MASK; + uint8_t ret = 1; switch (val) { + default: + break; + 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; + ret = 0; + break; 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; + ret = 0; + break; case 0xa0: /* copyright message */ kbc_at_queue_add(dev, 0x28); kbc_at_queue_add(dev, 0x00); - return 0; + ret = 0; + break; 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; + ret = 0; + break; 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; + ret = 0; } break; @@ -1248,7 +1072,7 @@ write64_ami(void *priv, uint8_t val) 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; + ret = 0; } break; @@ -1256,7 +1080,7 @@ write64_ami(void *priv, uint8_t val) if (!(dev->misc_flags & FLAG_PS2)) { kbc_at_log("ATkbc: AMI - write clock = low\n"); dev->misc_flags &= ~FLAG_CLOCK; - return 0; + ret = 0; } break; @@ -1264,14 +1088,15 @@ write64_ami(void *priv, uint8_t val) if (!(dev->misc_flags & FLAG_PS2)) { kbc_at_log("ATkbc: AMI - write clock = high\n"); dev->misc_flags |= FLAG_CLOCK; - return 0; + ret = 0; } + break; 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; + ret = 0; } break; @@ -1279,7 +1104,7 @@ write64_ami(void *priv, uint8_t val) if (!(dev->misc_flags & FLAG_PS2)) { kbc_at_log("ATkbc: AMI - write cache bad\n"); dev->misc_flags &= FLAG_CACHE; - return 0; + ret = 0; } break; @@ -1287,7 +1112,7 @@ write64_ami(void *priv, uint8_t val) if (!(dev->misc_flags & FLAG_PS2)) { kbc_at_log("ATkbc: AMI - write cache good\n"); dev->misc_flags |= FLAG_CACHE; - return 0; + ret = 0; } break; @@ -1295,7 +1120,7 @@ write64_ami(void *priv, uint8_t val) 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; + ret = 0; } break; @@ -1305,7 +1130,7 @@ write64_ami(void *priv, uint8_t val) dev->wantdata = 1; dev->state = STATE_KBC_PARAM; dev->command_phase = 1; - return 0; + ret = 0; } break; @@ -1316,7 +1141,8 @@ write64_ami(void *priv, uint8_t val) dev->p1 &= ~(1 << (val & 0x03)); kbc_delay_to_ob(dev, dev->ob, 0, 0x00); dev->pending++; - return 0; + ret = 0; + break; /* TODO: The ICS SB486PV sends command B4 but expects to read *TWO* bytes. */ case 0xb4: case 0xb5: @@ -1324,9 +1150,13 @@ write64_ami(void *priv, uint8_t val) 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); + if (strstr(machine_get_internal_name(), "sb486pv") != NULL) + kbc_delay_to_ob(dev, 0x03, 0, 0x00); + else + kbc_delay_to_ob(dev, dev->ob, 0, 0x00); dev->pending++; - return 0; + ret = 0; + break; case 0xb8 ... 0xbb: /* set KBC lines P10-P13 (P1 bits 0-3) high */ @@ -1336,7 +1166,8 @@ write64_ami(void *priv, uint8_t val) kbc_delay_to_ob(dev, dev->ob, 0, 0x00); dev->pending++; } - return 0; + ret = 0; + break; case 0xbc: case 0xbd: /* set KBC lines P22-P23 (P2 bits 2-3) high */ @@ -1345,13 +1176,15 @@ write64_ami(void *priv, uint8_t val) write_p2(dev, dev->p2 | (4 << (val & 0x01))); kbc_delay_to_ob(dev, dev->ob, 0, 0x00); dev->pending++; - return 0; + ret = 0; + break; case 0xc1: /* write P1 */ kbc_at_log("ATkbc: AMI MegaKey - write P1\n"); dev->wantdata = 1; dev->state = STATE_KBC_PARAM; - return 0; + ret = 0; + break; case 0xc4: /* set KBC line P14 low */ @@ -1359,14 +1192,16 @@ write64_ami(void *priv, uint8_t val) dev->p1 &= 0xef; kbc_delay_to_ob(dev, dev->ob, 0, 0x00); dev->pending++; - return 0; + ret = 0; + break; 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; + ret = 0; + break; case 0xc8: /* @@ -1375,7 +1210,8 @@ write64_ami(void *priv, uint8_t val) */ kbc_at_log("ATkbc: AMI - unblock KBC lines P22 and P23\n"); dev->ami_flags &= 0xfb; - return 0; + ret = 0; + break; case 0xc9: /* @@ -1384,7 +1220,15 @@ write64_ami(void *priv, uint8_t val) */ kbc_at_log("ATkbc: AMI - block KBC lines P22 and P23\n"); dev->ami_flags |= 0x04; - return 0; + ret = 0; + break; + + case 0xcb: /* set keyboard mode */ + kbc_at_log("ATkbc: AMI - set keyboard mode\n"); + dev->wantdata = 1; + dev->state = STATE_KBC_PARAM; + ret = 0; + break; case 0xcc: /* set KBC line P14 high */ @@ -1392,32 +1236,36 @@ write64_ami(void *priv, uint8_t val) dev->p1 |= 0x10; kbc_delay_to_ob(dev, dev->ob, 0, 0x00); dev->pending++; - return 0; + ret = 0; + break; 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; + ret = 0; + break; case 0xef: /* ??? - sent by AMI486 */ kbc_at_log("ATkbc: ??? - sent by AMI486\n"); - return 0; - - default: + ret = 0; break; } - return write64_generic(dev, val); + return ret; } static uint8_t -write60_phoenix(void *priv, uint8_t val) +write_cmd_data_phoenix(void *priv, uint8_t val) { atkbc_t *dev = (atkbc_t *) priv; + uint8_t ret = 1; switch (dev->command) { + default: + break; + /* TODO: Make this actually load the password. */ case 0xa3: /* Load Extended Password */ kbc_at_log("ATkbc: Phoenix - Load Extended Password\n"); @@ -1427,120 +1275,139 @@ write60_phoenix(void *priv, uint8_t val) dev->wantdata = 1; dev->state = STATE_KBC_PARAM; } - return 0; + ret = 0; + break; case 0xaf: /* Set Inactivity Timer */ kbc_at_log("ATkbc: Phoenix - Set Inactivity Timer\n"); dev->mem[0x3a] = val; dev->command_phase = 0; - return 0; + ret = 0; + break; case 0xb8: /* Set Extended Memory Access Index */ kbc_at_log("ATkbc: Phoenix - Set Extended Memory Access Index\n"); dev->mem_addr = val; dev->command_phase = 0; - return 0; + ret = 0; + break; case 0xbb: /* Set Extended Memory */ kbc_at_log("ATkbc: Phoenix - Set Extended Memory\n"); dev->mem[dev->mem_addr] = val; dev->command_phase = 0; - return 0; + ret = 0; + break; case 0xbd: /* Set MultiKey Variable */ kbc_at_log("ATkbc: Phoenix - Set MultiKey Variable\n"); if ((dev->mem_addr > 0) && (dev->mem_addr <= multikey_vars[0x00])) dev->mem[multikey_vars[dev->mem_addr]] = val; dev->command_phase = 0; - return 0; + ret = 0; + break; case 0xc7: /* Set Port1 bits */ kbc_at_log("ATkbc: Phoenix - Set Port1 bits\n"); dev->p1 |= val; dev->command_phase = 0; - return 0; + ret = 0; + break; case 0xc8: /* Clear Port1 bits */ kbc_at_log("ATkbc: Phoenix - Clear Port1 bits\n"); dev->p1 &= ~val; dev->command_phase = 0; - return 0; + ret = 0; + break; case 0xc9: /* Set Port2 bits */ kbc_at_log("ATkbc: Phoenix - Set Port2 bits\n"); write_p2(dev, dev->p2 | val); dev->command_phase = 0; - return 0; + ret = 0; + break; case 0xca: /* Clear Port2 bits */ kbc_at_log("ATkbc: Phoenix - Clear Port2 bits\n"); write_p2(dev, dev->p2 & ~val); dev->command_phase = 0; - return 0; - - default: + ret = 0; break; } - return 1; + return ret; } static uint8_t -write64_phoenix(void *priv, uint8_t val) +write_cmd_phoenix(void *priv, uint8_t val) { atkbc_t *dev = (atkbc_t *) priv; + uint8_t ret = 1; switch (val) { + default: + break; + case 0x00 ... 0x1f: kbc_at_log("ATkbc: Phoenix - alias read from %08X\n", val); kbc_delay_to_ob(dev, dev->mem[val + 0x20], 0, 0x00); - return 0; + ret = 0; + break; case 0x40 ... 0x5f: kbc_at_log("ATkbc: Phoenix - alias write to %08X\n", dev->command); dev->wantdata = 1; dev->state = STATE_KBC_PARAM; - return 0; + ret = 0; + break; case 0xa2: /* Test Extended Password */ kbc_at_log("ATkbc: Phoenix - Test Extended Password\n"); kbc_at_queue_add(dev, 0xf1); /* Extended Password not loaded */ - return 0; + ret = 0; + break; /* TODO: Make this actually load the password. */ case 0xa3: /* Load Extended Password */ kbc_at_log("ATkbc: Phoenix - Load Extended Password\n"); dev->wantdata = 1; dev->state = STATE_KBC_PARAM; - return 0; + ret = 0; + break; case 0xaf: /* Set Inactivity Timer */ kbc_at_log("ATkbc: Phoenix - Set Inactivity Timer\n"); dev->wantdata = 1; dev->state = STATE_KBC_PARAM; - return 0; + ret = 0; + break; case 0xb8: /* Set Extended Memory Access Index */ kbc_at_log("ATkbc: Phoenix - Set Extended Memory Access Index\n"); dev->wantdata = 1; dev->state = STATE_KBC_PARAM; - return 0; + ret = 0; + break; case 0xb9: /* Get Extended Memory Access Index */ kbc_at_log("ATkbc: Phoenix - Get Extended Memory Access Index\n"); kbc_at_queue_add(dev, dev->mem_addr); - return 0; + ret = 0; + break; case 0xba: /* Get Extended Memory */ kbc_at_log("ATkbc: Phoenix - Get Extended Memory\n"); kbc_at_queue_add(dev, dev->mem[dev->mem_addr]); - return 0; + ret = 0; + break; case 0xbb: /* Set Extended Memory */ kbc_at_log("ATkbc: Phoenix - Set Extended Memory\n"); dev->wantdata = 1; dev->state = STATE_KBC_PARAM; - return 0; + ret = 0; + break; case 0xbc: /* Get MultiKey Variable */ kbc_at_log("ATkbc: Phoenix - Get MultiKey Variable\n"); @@ -1550,122 +1417,147 @@ write64_phoenix(void *priv, uint8_t val) kbc_at_queue_add(dev, dev->mem[multikey_vars[dev->mem_addr]]); else kbc_at_queue_add(dev, 0xff); - return 0; + ret = 0; + break; case 0xbd: /* Set MultiKey Variable */ kbc_at_log("ATkbc: Phoenix - Set MultiKey Variable\n"); dev->wantdata = 1; dev->state = STATE_KBC_PARAM; - return 0; + ret = 0; + break; case 0xc7: /* Set Port1 bits */ kbc_at_log("ATkbc: Phoenix - Set Port1 bits\n"); dev->wantdata = 1; dev->state = STATE_KBC_PARAM; - return 0; + ret = 0; + break; case 0xc8: /* Clear Port1 bits */ kbc_at_log("ATkbc: Phoenix - Clear Port1 bits\n"); dev->wantdata = 1; dev->state = STATE_KBC_PARAM; - return 0; + ret = 0; + break; case 0xc9: /* Set Port2 bits */ kbc_at_log("ATkbc: Phoenix - Set Port2 bits\n"); dev->wantdata = 1; dev->state = STATE_KBC_PARAM; - return 0; + ret = 0; + break; case 0xca: /* Clear Port2 bits */ kbc_at_log("ATkbc: Phoenix - Clear Port2 bits\n"); dev->wantdata = 1; dev->state = STATE_KBC_PARAM; - return 0; + ret = 0; + break; /* TODO: Handle these three commands properly - configurable revision level and proper CPU bits. */ case 0xd5: /* Read MultiKey code revision level */ kbc_at_log("ATkbc: Phoenix - Read MultiKey code revision level\n"); - kbc_at_queue_add(dev, 0x04); - kbc_at_queue_add(dev, 0x16); - return 0; + if (dev->misc_flags & FLAG_PS2) { + if (dev->flags & DEVICE_PCI) { + kbc_at_queue_add(dev, 0x04); + kbc_at_queue_add(dev, 0x16); + } else { + kbc_at_queue_add(dev, 0x01); + kbc_at_queue_add(dev, 0x38); + } + } else { + kbc_at_queue_add(dev, 0x01); + kbc_at_queue_add(dev, 0x29); + } + ret = 0; + break; case 0xd6: /* Read Version Information */ kbc_at_log("ATkbc: Phoenix - Read Version Information\n"); kbc_at_queue_add(dev, 0x81); - kbc_at_queue_add(dev, 0xac); - return 0; + if (dev->misc_flags & FLAG_PS2) + kbc_at_queue_add(dev, 0xac); + else + kbc_at_queue_add(dev, 0xaa); + ret = 0; + break; case 0xd7: /* Read MultiKey model numbers */ kbc_at_log("ATkbc: Phoenix - Read MultiKey model numbers\n"); - kbc_at_queue_add(dev, 0x02); - kbc_at_queue_add(dev, 0x87); - kbc_at_queue_add(dev, 0x02); - return 0; - - default: + if (dev->misc_flags & FLAG_PS2) { + if (dev->flags & DEVICE_PCI) { + kbc_at_queue_add(dev, 0x02); + kbc_at_queue_add(dev, 0x87); + kbc_at_queue_add(dev, 0x02); + } else { + kbc_at_queue_add(dev, 0x99); + kbc_at_queue_add(dev, 0x75); + kbc_at_queue_add(dev, 0x01); + } + } else { + kbc_at_queue_add(dev, 0x90); + kbc_at_queue_add(dev, 0x88); + kbc_at_queue_add(dev, 0xd0); + } + ret = 0; break; } - return write64_generic(dev, val); + return ret; } static uint8_t -write64_siemens(void *priv, uint8_t val) +write_cmd_siemens(void *priv, uint8_t val) { atkbc_t *dev = (atkbc_t *) priv; + uint8_t ret = 1; switch (val) { + default: + ret = write_cmd_ami(dev, val); + break; + case 0x92: /*Siemens Award - 92 sent by PCD-2L BIOS*/ kbc_at_log("Siemens Award - 92 sent by PCD-2L BIOS\n"); - return 0; + ret = 0; + break; case 0x94: /*Siemens Award - 94 sent by PCD-2L BIOS*/ kbc_at_log("Siemens Award - 94 sent by PCD-2L BIOS\n"); - return 0; + ret = 0; + break; case 0x9a: /*Siemens Award - 9A sent by PCD-2L BIOS*/ kbc_at_log("Siemens Award - 9A sent by PCD-2L BIOS\n"); - return 0; + ret = 0; + break; case 0x9c: /*Siemens Award - 9C sent by PCD-2L BIOS*/ kbc_at_log("Siemens Award - 9C sent by PCD-2L BIOS\n"); - return 0; + ret = 0; + break; 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: + ret = 0; break; } - return write64_ami(dev, val); + return ret; } 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) +write_cmd_olivetti(void *priv, uint8_t val) { atkbc_t *dev = (atkbc_t *) priv; + uint8_t ret = 1; switch (val) { + default: + break; + case 0x80: /* Olivetti-specific command */ /* * bit 7: bus expansion board present (M300) / keyboard unlocked (M290) @@ -1676,101 +1568,133 @@ write64_olivetti(void *priv, uint8_t val) */ kbc_delay_to_ob(dev, (0x0c | (is386 ? 0x00 : 0x80)) & 0xdf, 0, 0x00); dev->p1 = ((dev->p1 + 1) & 3) | (dev->p1 & 0xfc); - return 0; - - default: + ret = 0; break; } - return write64_generic(dev, val); + return ret; } static uint8_t -write64_quadtel(void *priv, uint8_t val) +write_cmd_data_quadtel(void *priv, UNUSED(uint8_t val)) +{ + const atkbc_t *dev = (atkbc_t *) priv; + uint8_t ret = 1; + + switch (dev->command) { + default: + break; + + case 0xcf: /*??? - sent by MegaPC BIOS*/ + kbc_at_log("ATkbc: ??? - sent by MegaPC BIOS\n"); + ret = 0; + break; + } + + return ret; +} + +static uint8_t +write_cmd_quadtel(void *priv, uint8_t val) { atkbc_t *dev = (atkbc_t *) priv; + uint8_t ret = 1; switch (val) { + default: + break; + case 0xaf: kbc_at_log("ATkbc: bad KBC command AF\n"); - return 1; + break; 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: + ret = 0; break; } - return write64_generic(dev, val); + return ret; } static uint8_t -write60_toshiba(void *priv, uint8_t val) +write_cmd_data_toshiba(void *priv, uint8_t val) { const atkbc_t *dev = (atkbc_t *) priv; + uint8_t ret = 1; switch (dev->command) { + default: + break; + case 0xb6: /* T3100e - set color/mono switch */ kbc_at_log("ATkbc: T3100e - set color/mono switch\n"); t3100e_mono_set(val); - return 0; - - default: + ret = 0; break; } - return 1; + return ret; } static uint8_t -write64_toshiba(void *priv, uint8_t val) +write_cmd_toshiba(void *priv, uint8_t val) { atkbc_t *dev = (atkbc_t *) priv; + uint8_t ret = 1; switch (val) { + default: + break; + case 0xaf: kbc_at_log("ATkbc: bad KBC command AF\n"); - return 1; + break; case 0xb0: /* T3100e: Turbo on */ kbc_at_log("ATkbc: T3100e: Turbo on\n"); t3100e_turbo_set(1); - return 0; + ret = 0; + break; case 0xb1: /* T3100e: Turbo off */ kbc_at_log("ATkbc: T3100e: Turbo off\n"); t3100e_turbo_set(0); - return 0; + ret = 0; + break; case 0xb2: /* T3100e: Select external display */ kbc_at_log("ATkbc: T3100e: Select external display\n"); t3100e_display_set(0x00); - return 0; + ret = 0; + break; case 0xb3: /* T3100e: Select internal display */ kbc_at_log("ATkbc: T3100e: Select internal display\n"); t3100e_display_set(0x01); - return 0; + ret = 0; + break; 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; + ret = 0; + break; 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; + ret = 0; + break; 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; + ret = 0; + break; /* TODO: Toshiba KBC mode switching. */ case 0xb7: /* T3100e: Emulate PS/2 keyboard */ @@ -1784,7 +1708,8 @@ write64_toshiba(void *priv, uint8_t val) kbc_at_log("ATkbc: T3100e: Emulate AT keyboard\n"); kbc_at_do_poll = kbc_at_poll_at; } - return 0; + ret = 0; + break; case 0xbb: /* T3100e: Read 'Fn' key. Return it for right Ctrl and right Alt; on the real @@ -1796,12 +1721,14 @@ write64_toshiba(void *priv, uint8_t val) kbc_delay_to_ob(dev, 0x04, 0, 0x00); else kbc_delay_to_ob(dev, 0x00, 0, 0x00); - return 0; + ret = 0; + break; case 0xbc: /* T3100e: Reset Fn+Key notification */ kbc_at_log("ATkbc: T3100e: Reset Fn+Key notification\n"); t3100e_notify_set(0x00); - return 0; + ret = 0; + break; case 0xc0: /* Read P1 */ kbc_at_log("ATkbc: read P1\n"); @@ -1810,13 +1737,174 @@ write64_toshiba(void *priv, uint8_t val) * 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: + ret = 0; break; } - return write64_generic(dev, val); + return ret; +} + +static uint8_t +read_p1(atkbc_t *dev) +{ + uint8_t kbc_ven = dev->flags & KBC_VEN_MASK; + uint8_t ret = 0xff; + uint8_t current_drive; + uint8_t fixed_bits; + + /* + 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"; + Compaq: 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. + */ + 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 (!strcmp(machine_get_internal_name(), "dells333sl")) + /* + Dell System 333s/L: + - Bit 5: Stuck in reboot loop if clear. + */ + ret = 0x20 | (video_is_mda() ? 0x40 : 0x00); + else if (kbc_ven == KBC_VEN_IBM_PS1) { + current_drive = fdc_get_current_drive(); + /* (B0 or F0) | (fdd_is_525(current_drive) on bit 6) */ + ret = dev->p1 | fixed_bits | (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. + + (B0 or F0) | 0x04 | (display on bit 6) | (fpu on bit 3) + */ + ret = (dev->p1 | fixed_bits | (video_is_mda() ? 0x40 : 0x00) | + (hasfpu ? 0x08 : 0x00)) & 0xdf; + } else if (kbc_ven == KBC_VEN_TRIGEM_AMI) { + /* Switch settings: + - 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) */ + ret = dev->p1 | fixed_bits; + } else if (((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_1) && + ((dev->flags & KBC_TYPE_MASK) < KBC_TYPE_GREEN)) { + if (!strcmp(machine_get_internal_name(), "dell466np")) + /* + Dell 466/NP: + - Bit 2: Keyboard fuse (must be set); + - Bit 4: Password disable jumper (must be clear); + - Bit 5: Manufacturing jumper (must be set). + */ + ret = 0x24; + else if (!strcmp(machine_get_internal_name(), "optiplex_gxl")) + /* + Dell OptiPlex GXL/GXM: + - Bit 3: Password disable jumper (must be clear); + - Bit 4: Keyboard fuse (must be set); + - Bit 5: Manufacturing jumper (must be set). + */ + ret = 0x30; + else if (!strcmp(machine_get_internal_name(), "dellplato") || + !strcmp(machine_get_internal_name(), "dellhannibalp") || + !strcmp(machine_get_internal_name(), "dellxp60")) + /* + Dell Dimension XPS Pxxx & Pxxxa/Mxxxa: + - Bit 3: Password disable jumper (must be clear); + - Bit 4: Clear CMOS jumper (must be set). + */ + ret = 0x10; + else { + /* (B0 or F0) | (0x08 or 0x0c) */ + ret = ((dev->p1 | fixed_bits) & 0xf0) | + (((dev->flags & KBC_VEN_MASK) == KBC_VEN_ACER) ? 0x08 : 0x0c); + + if (!strcmp(machine_get_internal_name(), "alfredo")) + ret &= 0xef; + } + } else if (kbc_ven == KBC_VEN_COMPAQ) + ret = dev->p1 | (hasfpu ? 0x00 : 0x04); + else + /* (B0 or F0) | (0x04 or 0x44) */ + ret = dev->p1 | fixed_bits; + + dev->p1 = ((dev->p1 + 1) & 3) | (dev->p1 & 0xfc); + + return ret; } static void @@ -1836,7 +1924,18 @@ kbc_at_process_cmd(void *priv) /* Clear the keyboard controller queue. */ kbc_at_queue_reset(dev); - switch (dev->ib) { + /* + If we have a vendor-specific handler, run that. Otherwise, or if + that handler fails, attempt to process it as a generic command. + */ + if (dev->write_cmd_ven) + bad = dev->write_cmd_ven(dev, dev->ib); + + if (bad) switch (dev->ib) { + default: + kbc_at_log(bad ? "ATkbc: bad controller command %02X\n" : "", dev->ib); + break; + /* Read data from KBC memory. */ case 0x20 ... 0x3f: kbc_delay_to_ob(dev, dev->mem[dev->ib], 0, 0x00); @@ -1850,18 +1949,70 @@ kbc_at_process_cmd(void *priv) dev->state = STATE_KBC_PARAM; break; + /* TODO: Are these undocmented VL82C113 commands? */ + case 0x80: /* Tulip command */ + kbc_at_log("ATkbc: Tulip command\n"); + kbc_delay_to_ob(dev, 0xff, 0, 0x00); + break; + + case 0x8c: /* Tulip reset command */ + kbc_at_log("ATkbc: Tulip reset command\n"); + dev->wantdata = 1; + dev->state = STATE_KBC_PARAM; + break; + + 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); + } + break; + + case 0xa5: /* load security */ + kbc_at_log("ATkbc: load security\n"); + dev->wantdata = 1; + dev->state = STATE_KBC_PARAM; + break; + + case 0xa7: /* disable auxiliary port */ + if (dev->misc_flags & FLAG_PS2) { + kbc_at_log("ATkbc: disable auxiliary port\n"); + set_enable_aux(dev, 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); + } + 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 */ + 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. */ + /* + 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(0x1000); - picintc(0x0002); + if (dev->irq[1] != 0xffff) + picintc(1 << dev->irq[1]); + if (dev->irq[0] != 0xffff) + picintc(1 << dev->irq[0]); } dev->status = (dev->status & 0x0f) | 0x60; @@ -1876,11 +2027,17 @@ kbc_at_process_cmd(void *priv) } 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. */ + /* + 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); - picintclevel(0x0002, &dev->irq_state); + if (dev->irq[0] != 0xffff) + picintclevel(1 << dev->irq[0], &dev->irq_state); dev->irq_state = 0; } @@ -1914,12 +2071,13 @@ kbc_at_process_cmd(void *priv) break; case 0xac: /* diagnostic dump */ - if (dev->misc_flags & FLAG_PS2) { + 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. */ + /* PSW - Program Status Word - always return 0x00 because we do not emulate this byte. */ + dev->mem[0x33] = 0x00; /* 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]); @@ -1939,10 +2097,33 @@ kbc_at_process_cmd(void *priv) 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; + /* TODO: Make this command do nothing on the Regional HT6542, + or else, Efflixi's Award OPTi 495 BIOS gets a stuck key + in Norton Commander 3.0. */ + case 0xaf: /* read keyboard version */ + kbc_at_log("ATkbc: read keyboard version\n"); + kbc_delay_to_ob(dev, kbc_award_revision, 0, 0x00); + break; + + case 0xc0: /* read P1 */ + kbc_at_log("ATkbc: read P1\n"); + kbc_delay_to_ob(dev, read_p1(dev), 0, 0x00); + break; + + 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); + } + 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); + } break; case 0xca: /* read keyboard mode */ @@ -1950,12 +2131,6 @@ kbc_at_process_cmd(void *priv) 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; @@ -1976,6 +2151,22 @@ kbc_at_process_cmd(void *priv) dev->state = STATE_KBC_PARAM; 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; + } + break; + + case 0xd4: /* write to auxiliary port */ + if (dev->misc_flags & FLAG_PS2) { + kbc_at_log("ATkbc: write to auxiliary port\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"); @@ -1987,18 +2178,10 @@ kbc_at_process_cmd(void *priv) 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); + case 0xf0 ... 0xff: /* pulse P2 */ + kbc_at_log("ATkbc: pulse %01X\n", dev->ib & 0x0f); + pulse_output(dev, dev->ib & 0x0f); + break; } /* If the command needs data, remember the command. */ @@ -2009,13 +2192,44 @@ kbc_at_process_cmd(void *priv) dev->wantdata = 0; dev->state = STATE_MAIN_IBF; - switch (dev->command) { + /* + Run the vendor-specific handler if we have one. Otherwise, or if it + returns an error, log a bad controller command. + */ + if (dev->write_cmd_data_ven) + bad = dev->write_cmd_data_ven(dev, dev->ib); + + if (bad) switch (dev->command) { + default: + kbc_at_log("ATkbc: bad controller command %02x data %02x\n", dev->command, dev->ib); + break; + case 0x60 ... 0x7f: dev->mem[(dev->command & 0x1f) + 0x20] = dev->ib; if (dev->command == 0x60) write_cmd(dev, dev->ib); break; + case 0x8c: /* Tulip reset command */ + kbc_at_log("ATkbc: Tulip rset command\n"); + + dma_reset(); + dma_set_at(1); + + device_reset_all(DEVICE_ALL); + + cpu_alt_reset = 0; + + pci_reset(); + + mem_a20_alt = 0; + mem_a20_recalc(); + + flushmmucache(); + + resetx86(); + break; + case 0xa5: /* load security */ if (dev->misc_flags & FLAG_PS2) { kbc_at_log("ATkbc: load security (%02X)\n", dev->ib); @@ -2027,11 +2241,6 @@ kbc_at_process_cmd(void *priv) } 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), @@ -2074,26 +2283,12 @@ kbc_at_process_cmd(void *priv) 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) +kbc_at_port_1_write(uint16_t port, uint8_t val, void *priv) { atkbc_t *dev = (atkbc_t *) priv; uint8_t kbc_ven = dev->flags & KBC_VEN_MASK; @@ -2101,39 +2296,89 @@ kbc_at_write(uint16_t port, uint8_t val, void *priv) 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"); + dev->status &= ~STAT_CD; - /* Fast A20 - ignore all other bits. */ - write_p2_fast_a20(dev, (dev->p2 & 0xfd) | (val & 0x02)); + if (fast_a20 && dev->wantdata && (dev->command == 0xd1)) { + kbc_at_log("ATkbc: write P2\n"); - dev->wantdata = 0; - dev->state = STATE_MAIN_IBF; - return; - } - break; + /* Fast A20 - ignore all other bits. */ + write_p2_fast_a20(dev, (dev->p2 & 0xfd) | (val & 0x02)); - 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; - } else if (fast_reset && ((val & 0xf0) == 0xf0)) { - pulse_output(dev, val & 0x0f); + dev->wantdata = 0; + dev->state = STATE_MAIN_IBF; - dev->state = STATE_MAIN_IBF; - return; - } - break; + /* + Explicitly clear IBF so that any preceding + command is not executed. + */ + dev->status &= ~STAT_IFULL; + return; + } - default: - break; + dev->ib = val; + dev->status |= STAT_IFULL; +} + +static void +kbc_at_port_2_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); + + 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; + + /* + Explicitly clear IBF so that any preceding + command is not executed. + */ + dev->status &= ~STAT_IFULL; + return; + } else if (fast_reset && ((val & 0xf0) == 0xf0)) { + pulse_output(dev, val & 0x0f); + + dev->state = STATE_MAIN_IBF; + + /* + Explicitly clear IBF so that any preceding + command is not executed. + */ + dev->status &= ~STAT_IFULL; + return; + } else if (val == 0xad) { + /* Fast track it because of the Bochs BIOS. */ + kbc_at_log("ATkbc: disable keyboard\n"); + set_enable_kbd(dev, 0); + + dev->state = STATE_MAIN_IBF; + + /* + Explicitly clear IBF so that any preceding + command is not executed. + */ + dev->status &= ~STAT_IFULL; + return; + } else if (val == 0xae) { + /* Fast track it because of the LG MultiNet. */ + kbc_at_log("ATkbc: enable keyboard\n"); + set_enable_kbd(dev, 1); + + dev->state = STATE_MAIN_IBF; + + /* + Explicitly clear IBF so that any preceding + command is not executed. + */ + dev->status &= ~STAT_IFULL; + return; } dev->ib = val; @@ -2141,7 +2386,7 @@ kbc_at_write(uint16_t port, uint8_t val, void *priv) } static uint8_t -kbc_at_read(uint16_t port, void *priv) +kbc_at_port_1_read(uint16_t port, void *priv) { atkbc_t *dev = (atkbc_t *) priv; uint8_t ret = 0xff; @@ -2149,26 +2394,32 @@ kbc_at_read(uint16_t port, void *priv) 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)) - picintclevel(1 << 1, &dev->irq_state); - if ((strstr(machine_get_internal_name(), "pb41") != NULL) && (cpu_override_dynarec == 1)) - cpu_override_dynarec = 0; - break; + 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) && (dev->irq[0] != 0xffff)) + picintclevel(1 << dev->irq[0], &dev->irq_state); + if ((strstr(machine_get_internal_name(), "pb41") != NULL) && (cpu_override_dynarec == 1)) + cpu_override_dynarec = 0; - case 0x64: - ret = dev->status; - break; + kbc_at_log("ATkbc: [%04X:%08X] read (%04X) = %02X\n", CS, cpu_state.pc, port, ret); - default: - kbc_at_log("ATkbc: read(%04x) invalid!\n",port); - break; - } + return ret; +} + +static uint8_t +kbc_at_port_2_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); + + ret = dev->status; kbc_at_log("ATkbc: [%04X:%08X] read (%04X) = %02X\n", CS, cpu_state.pc, port, ret); @@ -2207,11 +2458,14 @@ kbc_at_reset(void *priv) if ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_1) { dev->misc_flags |= FLAG_PS2; kbc_at_do_poll = kbc_at_poll_ps2; - picintc(0x1000); - picintc(0x0002); + if (dev->irq[1] != 0xffff) + picintc(1 << dev->irq[1]); + if (dev->irq[0] != 0xffff) + picintc(1 << dev->irq[0]); } else { kbc_at_do_poll = kbc_at_poll_at; - picintclevel(0x0002, &dev->irq_state); + if (dev->irq[0] != 0xffff) + picintclevel(1 << dev->irq[0], &dev->irq_state); dev->irq_state = 0; } @@ -2254,19 +2508,44 @@ kbc_at_close(void *priv) } void -kbc_at_handler(int set, void *priv) +kbc_at_port_handler(int num, int set, uint16_t port, void *priv) { - if (kbc_handler_set) { - io_removehandler(0x0060, 1, kbc_at_read, NULL, NULL, kbc_at_write, NULL, NULL, priv); - io_removehandler(0x0064, 1, kbc_at_read, NULL, NULL, kbc_at_write, NULL, NULL, priv); + atkbc_t *dev = (atkbc_t *) priv; + + if (dev->handler_enable[num] && (dev->base_addr[num] != 0x0000)) + io_removehandler(dev->base_addr[num], 1, + dev->handlers[num].read, NULL, NULL, + dev->handlers[num].write, NULL, NULL, priv); + + dev->handler_enable[num] = set; + dev->base_addr[num] = port; + + if (dev->handler_enable[num] && (dev->base_addr[num] != 0x0000)) + io_sethandler(dev->base_addr[num], 1, + dev->handlers[num].read, NULL, NULL, + dev->handlers[num].write, NULL, NULL, priv); +} + +void +kbc_at_handler(int set, uint16_t port, void *priv) +{ + kbc_at_port_handler(0, set, port, priv); + kbc_at_port_handler(1, set, port + 0x0004, priv); +} + +void +kbc_at_set_irq(int num, uint16_t irq, void *priv) +{ + atkbc_t *dev = (atkbc_t *) priv; + + if (dev->irq[num] != 0xffff) { + if ((num == 0) && ((dev->flags & KBC_TYPE_MASK) < KBC_TYPE_PS2_1)) + picintclevel(1 << dev->irq[num], &dev->irq_state); + else + picintc(1 << dev->irq[num]); } - kbc_handler_set = set; - - if (kbc_handler_set) { - io_sethandler(0x0060, 1, kbc_at_read, NULL, NULL, kbc_at_write, NULL, NULL, priv); - io_sethandler(0x0064, 1, kbc_at_read, NULL, NULL, kbc_at_write, NULL, NULL, priv); - } + dev->irq[num] = irq; } static void * @@ -2275,8 +2554,7 @@ 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 = (atkbc_t *) calloc(1, sizeof(atkbc_t)); dev->flags = info->local; @@ -2288,52 +2566,51 @@ kbc_at_init(const device_t *info) if (info->flags & DEVICE_PCI) dev->misc_flags |= FLAG_PCI; - kbc_handler_set = 0; - kbc_at_handler(1, dev); + dev->handlers[0].read = kbc_at_port_1_read; + dev->handlers[0].write = kbc_at_port_1_write; + dev->handlers[1].read = kbc_at_port_2_read; + dev->handlers[1].write = kbc_at_port_2_write; + + dev->irq[0] = 1; + dev->irq[1] = 12; timer_add(&dev->kbc_poll_timer, kbc_at_poll, dev, 1); timer_add(&dev->pulse_cb, pulse_poll, dev, 0); timer_add(&dev->kbc_dev_poll_timer, kbc_at_dev_poll, dev, 1); - dev->write60_ven = NULL; - dev->write64_ven = NULL; + dev->write_cmd_data_ven = NULL; + dev->write_cmd_ven = NULL; kbc_ami_revision = '8'; kbc_award_revision = 0x42; switch (dev->flags & KBC_VEN_MASK) { + default: + break; + 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_IBM: - case KBC_VEN_COMPAQ: - dev->write64_ven = write64_generic; + dev->write_cmd_data_ven = write_cmd_data_ami; + dev->write_cmd_ven = write_cmd_siemens; break; case KBC_VEN_OLIVETTI: - dev->write64_ven = write64_olivetti; + dev->write_cmd_ven = write_cmd_olivetti; break; case KBC_VEN_ALI: kbc_ami_revision = 'F'; kbc_award_revision = 0x43; - dev->write60_ven = write60_ami; - dev->write64_ven = write64_ami; + dev->write_cmd_data_ven = write_cmd_data_ami; + dev->write_cmd_ven = write_cmd_ami; break; case KBC_VEN_TRIGEM_AMI: kbc_ami_revision = 'Z'; - dev->write60_ven = write60_ami; - dev->write64_ven = write64_ami; + dev->write_cmd_data_ven = write_cmd_data_ami; + dev->write_cmd_ven = write_cmd_ami; break; case KBC_VEN_AMI: @@ -2356,26 +2633,23 @@ kbc_at_init(const device_t *info) else kbc_ami_revision = 'F'; - dev->write60_ven = write60_ami; - dev->write64_ven = write64_ami; + dev->write_cmd_data_ven = write_cmd_data_ami; + dev->write_cmd_ven = write_cmd_ami; break; case KBC_VEN_PHOENIX: - dev->write60_ven = write60_phoenix; - dev->write64_ven = write64_phoenix; + dev->write_cmd_data_ven = write_cmd_data_phoenix; + dev->write_cmd_ven = write_cmd_phoenix; break; case KBC_VEN_QUADTEL: - dev->write60_ven = write60_quadtel; - dev->write64_ven = write64_quadtel; + dev->write_cmd_data_ven = write_cmd_data_quadtel; + dev->write_cmd_ven = write_cmd_quadtel; break; case KBC_VEN_TOSHIBA: - dev->write60_ven = write60_toshiba; - dev->write64_ven = write64_toshiba; - break; - - default: + dev->write_cmd_data_ven = write_cmd_data_toshiba; + dev->write_cmd_ven = write_cmd_toshiba; break; } @@ -2386,8 +2660,7 @@ kbc_at_init(const device_t *info) #endif 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] = (kbc_at_port_t *) calloc(1, sizeof(kbc_at_port_t)); kbc_at_ports[i]->out_new = -1; } @@ -2399,6 +2672,8 @@ kbc_at_init(const device_t *info) fast_reset = 0x00; + kbc_at_handler(1, 0x0060, dev); + return dev; } @@ -2410,7 +2685,7 @@ const device_t keyboard_at_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2424,7 +2699,7 @@ const device_t keyboard_at_siemens_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2438,7 +2713,7 @@ const device_t keyboard_at_ami_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2452,7 +2727,7 @@ const device_t keyboard_at_tg_ami_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2466,7 +2741,7 @@ const device_t keyboard_at_toshiba_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2480,7 +2755,7 @@ const device_t keyboard_at_olivetti_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2494,7 +2769,7 @@ const device_t keyboard_at_ncr_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2508,7 +2783,21 @@ const device_t keyboard_at_compaq_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t keyboard_at_phoenix_device = { + .name = "PC/AT Keyboard (Phoenix)", + .internal_name = "keyboard_at_phoenix", + .flags = DEVICE_KBC, + .local = KBC_TYPE_ISA | KBC_VEN_PHOENIX, + .init = kbc_at_init, + .close = kbc_at_close, + .reset = kbc_at_reset, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2522,7 +2811,7 @@ const device_t keyboard_ps2_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2536,7 +2825,7 @@ const device_t keyboard_ps2_ps1_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2550,7 +2839,7 @@ const device_t keyboard_ps2_ps1_pci_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2564,7 +2853,7 @@ const device_t keyboard_ps2_xi8088_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2578,7 +2867,21 @@ const device_t keyboard_ps2_ami_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t keyboard_ps2_compaq_device = { + .name = "PS/2 Keyboard (Compaq)", + .internal_name = "keyboard_at_compaq", + .flags = DEVICE_KBC, + .local = KBC_TYPE_PS2_1 | 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 @@ -2592,7 +2895,7 @@ const device_t keyboard_ps2_holtek_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2606,7 +2909,7 @@ const device_t keyboard_ps2_phoenix_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2620,7 +2923,7 @@ const device_t keyboard_ps2_tg_ami_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2634,7 +2937,7 @@ const device_t keyboard_ps2_mca_1_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2648,7 +2951,7 @@ const device_t keyboard_ps2_mca_2_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2662,7 +2965,7 @@ const device_t keyboard_ps2_quadtel_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2676,7 +2979,7 @@ const device_t keyboard_ps2_pci_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2690,7 +2993,7 @@ const device_t keyboard_ps2_ami_pci_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2704,7 +3007,7 @@ const device_t keyboard_ps2_ali_pci_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2718,7 +3021,7 @@ const device_t keyboard_ps2_intel_ami_pci_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2732,7 +3035,7 @@ const device_t keyboard_ps2_tg_ami_pci_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2746,7 +3049,21 @@ const device_t keyboard_ps2_acer_pci_device = { .init = kbc_at_init, .close = kbc_at_close, .reset = kbc_at_reset, - { .available = NULL }, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t keyboard_ps2_phoenix_pci_device = { + .name = "PS/2 Keyboard (Phoenix)", + .internal_name = "keyboard_ps2_phoenix_pci", + .flags = DEVICE_KBC | DEVICE_PCI, + .local = KBC_TYPE_PS2_1 | KBC_VEN_PHOENIX, + .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 index c1041e6e1..b20e38860 100644 --- a/src/device/kbc_at_dev.c +++ b/src/device/kbc_at_dev.c @@ -58,7 +58,7 @@ kbc_at_dev_log(const char *fmt, ...) # define kbc_at_dev_log(fmt, ...) #endif -static void +void kbc_at_dev_queue_reset(atkbc_dev_t *dev, uint8_t reset_main) { if (reset_main) { @@ -95,10 +95,6 @@ kbc_at_dev_queue_add(atkbc_dev_t *dev, uint8_t val, uint8_t main) 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 @@ -123,6 +119,8 @@ kbc_at_dev_poll(void *priv) (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]; + if (dev->port->out_new != 0xfe) + dev->last_scan_code = dev->port->out_new; dev->queue_start = (dev->queue_start + 1) & dev->fifo_mask; } if (dev->ignore || !(*dev->scan) || dev->port->wantcmd) @@ -143,6 +141,8 @@ kbc_at_dev_poll(void *priv) 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]; + if (dev->port->out_new != 0xfe) + dev->last_scan_code = dev->port->out_new; dev->cmd_queue_start = (dev->cmd_queue_start + 1) & 0xf; } if (dev->cmd_queue_start == dev->cmd_queue_end) @@ -166,6 +166,8 @@ kbc_at_dev_poll(void *priv) 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]; + if (dev->port->out_new != 0xfe) + dev->last_scan_code = dev->port->out_new; dev->cmd_queue_start = (dev->cmd_queue_start + 1) & 0xf; } if (dev->cmd_queue_start == dev->cmd_queue_end) diff --git a/src/device/keyboard.c b/src/device/keyboard.c index 2eff2159b..16904fe3b 100644 --- a/src/device/keyboard.c +++ b/src/device/keyboard.c @@ -18,10 +18,13 @@ * Copyright 2015-2019 Miran Grca. * Copyright 2017-2019 Fred N. van Kempen. */ +#include #include #include #include +#include #include +#define HAVE_STDARG_H #include <86box/86box.h> #include <86box/machine.h> #include <86box/keyboard.h> @@ -33,22 +36,22 @@ uint16_t scancode_map[768] = { 0 }; int keyboard_scan; -#ifdef _WIN32 -/* Windows: F8+F12 */ -uint16_t key_prefix_1_1 = 0x042; /* F8 */ -uint16_t key_prefix_1_2 = 0x000; /* Invalid */ -uint16_t key_prefix_2_1 = 0x000; /* Invalid */ -uint16_t key_prefix_2_2 = 0x000; /* Invalid */ -uint16_t key_uncapture_1 = 0x058; /* F12 */ -uint16_t key_uncapture_2 = 0x000; /* Invalid */ +#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 -/* WxWidgets cannot do two regular keys.. CTRL+END */ -uint16_t key_prefix_1_1 = 0x01d; /* Left Ctrl */ -uint16_t key_prefix_1_2 = 0x11d; /* Right Ctrl */ -uint16_t key_prefix_2_1 = 0x000; /* Invalid */ -uint16_t key_prefix_2_2 = 0x000; /* Invalid */ -uint16_t key_uncapture_1 = 0x04f; /* Numpad End */ -uint16_t key_uncapture_2 = 0x14f; /* End */ +# define kbc_at_log(fmt, ...) #endif void (*keyboard_send)(uint16_t val); @@ -61,15 +64,62 @@ static int keydelay[512]; #endif static scancode *scan_table; /* scancode table for keyboard */ -static uint8_t caps_lock = 0; -static uint8_t num_lock = 0; -static uint8_t scroll_lock = 0; -static uint8_t shift = 0; +static volatile uint8_t caps_lock = 0; +static volatile uint8_t num_lock = 0; +static volatile uint8_t scroll_lock = 0; +static volatile uint8_t kana_lock = 0; +static volatile uint8_t kbd_in_reset = 0; +static uint8_t shift = 0; + +static int key5576mode = 0; + +typedef struct { + const uint16_t sc; + const uint8_t mk[4]; + const uint8_t brk[4]; +} scconvtbl; + +static scconvtbl scconv55_8a[18 + 1] = +{ + // clang-format off + {.sc = 0x02 , .mk = { 0x48 }, .brk = { 0 } }, /* '1' -> 'Clear/ /SysRq' */ + {.sc = 0x03 , .mk = { 0x49 }, .brk = { 0 } }, /* '2' -> '終了 (Exit)' */ + {.sc = 0x04 , .mk = { 0x46 }, .brk = { 0 } }, /* '3' -> 'メッセージ (Message)/ /応答 (Respond)' */ + {.sc = 0x05 , .mk = { 0x44 }, .brk = { 0 } }, /* '4' -> 'サイズ変換 (Change Size)/ /横倍角 (2x Width)' */ + {.sc = 0x06 , .mk = { 0x42 }, .brk = { 0 } }, /* '5' -> '単語登録 (Register Word)/ /再交換 (Re-change)' */ + {.sc = 0x07 , .mk = { 0x43 }, .brk = { 0 } }, /* '6' -> '漢字 (Kanji)/ /番号 (Number)' */ + {.sc = 0x08 , .mk = { 0x40 }, .brk = { 0 } }, /* '7' -> '取消 (Cancel)' */ + {.sc = 0x09 , .mk = { 0x51 }, .brk = { 0 } }, /* '8' -> 'コピー (Copy)/ /移動 (Move)' */ + {.sc = 0x3d , .mk = { 0x76 }, .brk = { 0 } }, /* 'F3' -> 'Cr Bnk/領域呼出 (Call Range)/All Cr/登録 (Register)' */ + {.sc = 0x3e , .mk = { 0x77 }, .brk = { 0 } }, /* 'F4' -> '割込み (Interrupt)' */ + {.sc = 0x3f , .mk = { 0x78 }, .brk = { 0 } }, /* 'F5' -> 'UF1' */ + {.sc = 0x40 , .mk = { 0x79 }, .brk = { 0 } }, /* 'F6' -> 'UF2' */ + {.sc = 0x41 , .mk = { 0x7a }, .brk = { 0 } }, /* 'F7' -> 'UF3' */ + {.sc = 0x42 , .mk = { 0x7b }, .brk = { 0 } }, /* 'F8' -> 'UF4' */ + {.sc = 0x43 , .mk = { 0x7c }, .brk = { 0 } }, /* 'F9' -> 'EOF/Erase/ErInp' */ + {.sc = 0x44 , .mk = { 0x7d }, .brk = { 0 } }, /* 'F10' -> 'Attn/ /CrSel' */ + {.sc = 0x57 , .mk = { 0x7e }, .brk = { 0 } }, /* 'F11' -> 'PA1/ /DvCncl' */ + {.sc = 0x58 , .mk = { 0x7f }, .brk = { 0 } }, /* 'F12' -> 'PA2/ /PA3' */ + {.sc = 0 , .mk = { 0 }, .brk = { 0 } } /* end */ + // clang-format on +}; void keyboard_init(void) { + num_lock = 0; + caps_lock = 0; + scroll_lock = 0; + kana_lock = 0; + shift = 0; + kbd_in_reset = 0; + memset(recv_key, 0x00, sizeof(recv_key)); + memset(recv_key_ui, 0x00, sizeof(recv_key)); + memset(oldkey, 0x00, sizeof(recv_key)); +#if 0 + memset(key_delay, 0x00, sizeof(recv_key)); +#endif keyboard_scan = 1; scan_table = NULL; @@ -121,6 +171,36 @@ key_process(uint16_t scan, int down) oldkey[scan] = down; + kbc_at_log("Key %04X,%d in process\n", scan, down); + + c = 0; + /* According to Japanese DOS K3.3 manual (N:SC18-2194-1), + IBM 5576-002, -003 keyboards have the one-time key conversion mode + that emulates 18 out of 131 keys on IBM 5576-001 keyboard. + It is triggered by pressing L-Shift (⇧) + L-Ctrl + R-Alt (前面キー) + when the scancode set is 82h or 8ah. + */ + if (key5576mode) { + int i = 0; + if (!down) { + /* Do and exit the 5576-001 emulation when a key is pressed other than trigger keys. */ + if (scan != 0x1d && scan != 0x2a && scan != 0x138) + { + key5576mode = 0; + kbc_at_log("5576-001 key emulation disabled.\n"); + } + } + while (scconv55_8a[i].sc != 0) + { + if (scconv55_8a[i].sc == scan) { + while (scconv55_8a[i].mk[c] != 0) + keyboard_send(scconv55_8a[i].mk[c++]); + return; + } + i++; + } + } + if (down && (codes[scan].mk[0] == 0)) return; @@ -147,12 +227,22 @@ key_process(uint16_t scan, int down) if (fake_shift_needed(scan)) keyboard_send(0x101); } + + /* Enter the 5576-001 emulation mode. */ + if (keyboard_mode == 0x8a && down && ((keyboard_get_shift() & 0x43) == 0x43)) + { + key5576mode = 1; + kbc_at_log("5576-001 key emulation enabled.\n"); + } } /* Handle a keystroke event from the UI layer. */ void keyboard_input(int down, uint16_t scan) { + if (kbd_in_reset) + return; + /* Special case for E1 1D, translate it to 0100 - special case. */ if ((scan >> 8) == 0xe1) { if ((scan & 0xff) == 0x1d) @@ -227,13 +317,16 @@ keyboard_input(int down, uint16_t scan) shift &= ~0x80; break; case 0x03a: /* Caps Lock */ - caps_lock ^= 1; + if (!(machine_has_bus(machine, MACHINE_AT) > 0)) + caps_lock ^= 1; break; case 0x045: - num_lock ^= 1; + if (!(machine_has_bus(machine, MACHINE_AT) > 0)) + num_lock ^= 1; break; case 0x046: - scroll_lock ^= 1; + if (!(machine_has_bus(machine, MACHINE_AT) > 0)) + scroll_lock ^= 1; break; default: @@ -242,7 +335,7 @@ keyboard_input(int down, uint16_t scan) } } - /* pclog("Received scan code: %03X (%s)\n", scan & 0x1ff, down ? "down" : "up"); */ + /* kbc_at_log("Received scan code: %03X (%s)\n", scan & 0x1ff, down ? "down" : "up"); */ recv_key_ui[scan & 0x1ff] = down; if (mouse_capture || !kbd_req_capture || video_fullscreen) { @@ -251,6 +344,32 @@ keyboard_input(int down, uint16_t scan) } } +void +keyboard_all_up(void) +{ + for (unsigned short i = 0; i < 0x200; i++) { + if (recv_key_ui[i]) + recv_key_ui[i] = 0; + + if (recv_key[i]) { + recv_key[i] = 0; + key_process(i, 0); + } + } +} + +void +keyboard_set_in_reset(uint8_t in_reset) +{ + kbd_in_reset = in_reset; +} + +uint8_t +keyboard_get_in_reset(void) +{ + return kbd_in_reset; +} + static uint8_t keyboard_do_break(uint16_t scan) { @@ -270,11 +389,12 @@ keyboard_do_break(uint16_t scan) Caps Lock, Num Lock, and Scroll Lock when receving the "Set keyboard LEDs" command. */ void -keyboard_update_states(uint8_t cl, uint8_t nl, uint8_t sl) +keyboard_update_states(uint8_t cl, uint8_t nl, uint8_t sl, uint8_t kl) { caps_lock = cl; num_lock = nl; scroll_lock = sl; + kana_lock = kl; } uint8_t @@ -284,7 +404,7 @@ keyboard_get_shift(void) } void -keyboard_get_states(uint8_t *cl, uint8_t *nl, uint8_t *sl) +keyboard_get_states(uint8_t *cl, uint8_t *nl, uint8_t *sl, uint8_t *kl) { if (cl) *cl = caps_lock; @@ -292,6 +412,8 @@ keyboard_get_states(uint8_t *cl, uint8_t *nl, uint8_t *sl) *nl = num_lock; if (sl) *sl = scroll_lock; + if (kl) + *kl = kana_lock; } /* Called by the UI to update the states of Caps Lock, Num Lock, and Scroll Lock. */ @@ -335,7 +457,7 @@ keyboard_set_states(uint8_t cl, uint8_t nl, uint8_t sl) } } - keyboard_update_states(cl, nl, sl); + keyboard_update_states(cl, nl, sl, kana_lock); } int @@ -376,19 +498,6 @@ keyboard_isfsexit_up(void) return (!recv_key_ui[0x01d] && !recv_key_ui[0x11d] && !recv_key_ui[0x038] && !recv_key_ui[0x138] && !recv_key_ui[0x051] && !recv_key_ui[0x151]); } -/* Do we have the mouse uncapture combination in the keyboard buffer? */ -int -keyboard_ismsexit(void) -{ - if ((key_prefix_2_1 != 0x000) || (key_prefix_2_2 != 0x000)) - return ((recv_key_ui[key_prefix_1_1] || recv_key_ui[key_prefix_1_2]) && - (recv_key_ui[key_prefix_2_1] || recv_key_ui[key_prefix_2_2]) && - (recv_key_ui[key_uncapture_1] || recv_key_ui[key_uncapture_2])); - else - return ((recv_key_ui[key_prefix_1_1] || recv_key_ui[key_prefix_1_2]) && - (recv_key_ui[key_uncapture_1] || recv_key_ui[key_uncapture_2])); -} - /* This is so we can disambiguate scan codes that would otherwise conflict and get passed on incorrectly. */ uint16_t diff --git a/src/device/keyboard_at.c b/src/device/keyboard_at.c index 882174e4e..7fa2b9706 100644 --- a/src/device/keyboard_at.c +++ b/src/device/keyboard_at.c @@ -25,6 +25,7 @@ #include <86box/device.h> #include <86box/keyboard.h> #include <86box/mouse.h> +#include <86box/machine.h> #define FLAG_PS2 0x08 /* dev is AT or PS/2 */ #define FLAG_AT 0x00 /* dev is AT or PS/2 */ @@ -53,10 +54,10 @@ const uint8_t id_bytes[16][4] = { { 0x00, 0x00, 0x00, 0x00 }, /* AT 84-key */ { 0x00, 0x00, 0x00, 0x00 }, { 0x00, 0x00, 0x00, 0x00 }, { 0x00, 0x00, 0x00, 0x00 }, - { 0x00, 0x00, 0x00, 0x00 }, + { 0x00, 0x00, 0x00, 0x00 }, /* FLAG_PS2 = 0x08 */ { 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 */ + { 0xab, 0x90, 0x00, 0x00 }, /* PS/55 106-key JIS (IBM-J 5576-002) */ /* Japanese keyboard ID - TODO: Find the actual Korean one. */ { 0xab, 0x90, 0x00, 0x00 }, /* PS/2 Korean */ { 0x00, 0x00, 0x00, 0x00 }, @@ -427,11 +428,11 @@ static const scancode scancode_set1[512] = { { .mk = {0xe0, 0x57, 0 }, .brk = { 0xe0, 0xd7, 0 } }, /* 157 */ { .mk = {0xe0, 0x58, 0 }, .brk = { 0xe0, 0xd8, 0 } }, /* 158 */ { .mk = {0xe0, 0x59, 0 }, .brk = { 0xe0, 0xd9, 0 } }, /* 159 */ - { .mk = {0xe0, 0x5a, 0 }, .brk = { 0xe0, 0xaa, 0 } }, /* 15a */ + { .mk = {0xe0, 0x5a, 0 }, .brk = { 0xe0, 0xda, 0 } }, /* 15a */ { .mk = {0xe0, 0x5b, 0 }, .brk = { 0xe0, 0xdb, 0 } }, /* 15b */ { .mk = {0xe0, 0x5c, 0 }, .brk = { 0xe0, 0xdc, 0 } }, /* 15c */ { .mk = {0xe0, 0x5d, 0 }, .brk = { 0xe0, 0xdd, 0 } }, /* 15d */ - { .mk = {0xe0, 0x5e, 0 }, .brk = { 0xe0, 0xee, 0 } }, /* 15e */ + { .mk = {0xe0, 0x5e, 0 }, .brk = { 0xe0, 0xde, 0 } }, /* 15e */ { .mk = {0xe0, 0x5f, 0 }, .brk = { 0xe0, 0xdf, 0 } }, /* 15f */ { .mk = { 0 }, .brk = { 0 } }, /* 160 */ { .mk = {0xe0, 0x61, 0 }, .brk = { 0xe0, 0xe1, 0 } }, /* 161 */ @@ -1630,6 +1631,1585 @@ static const scancode scancode_set3[512] = { // clang-format on }; +/* IBM Japan 5576-001, 002 and 003 keyboards have three extra scancode sets; 81h, 82h, 8ah. + To implement them, we need take the following into consideration. + * Add a UI to switch the type of keyboards and keyboard IDs. + * Add modified scancode set 1 and 2 (in these modes, language input keys are used as an alternative key). + * Japanese keyboards traditionally use a bit-paired layout. Its key mapping doesn't match with foreign keyboards. + + 5576 keyboards kept 101-key compatible scancode sets because PS/55 had to support western (PS/2) versions of operating systems. + The default scancode set is 2. + In Japanese DOS, the keyboard driver confirms its keyboard ID, and sends a command to switch the scancode set to 8Ah. + Japanese OS/2 and Windows use the scancode set 81h or 82h. + + The OADG standard (1991-) and modern Japanese keyboards use the same keyboard ID and scancode set ID as PS/2 keyboards use. + Three extra scancode sets are no longer available. Instead, language input keys are available in scancode set 1 and 2. + However, their physical key layout is a bit-paired layout. + Users have to choose the correct keyboard layout on setup, and the driver needs to remap keys. + + Currently, the key mapping is designed to match with the Japanese layout keyboard. + + [Japanese DOS and keyboard scancode set comparison] + | | K3.3 | J4.0 | J5.0 | J4.0/V | J5.0/V | OS/2 J1.3 | DOS 5(US)| + |---------------------------|:----:|:----:|:----:|:------:|:------:|:---------:|:--------:| + | IBM 101 US English | n/a | n/a | n/a | 2 | 2 | 2 | 2 | + | IBM-J 5576-00x (obsolete) | 8Ah | 8Ah | 8Ah | 82h | 82h | 81h | 2 | + | OADG (modern Japanese) | n/a | n/a | n/a | 2 | 2 | 2 | 2 | +*/ + +/* Scancode set 81h : Set 01 with language specific keys support used by OS/2 */ +static const scancode scancode_set81[512] = { + // clang-format off + { .mk = { 0 }, .brk = { 0 } }, /* 000 */ + { .mk = { 0x01, 0 }, .brk = { 0x81, 0 } }, /* 001 */ + { .mk = { 0x02, 0 }, .brk = { 0x82, 0 } }, /* 002 */ + { .mk = { 0x03, 0 }, .brk = { 0x83, 0 } }, /* 003 */ + { .mk = { 0x04, 0 }, .brk = { 0x84, 0 } }, /* 004 */ + { .mk = { 0x05, 0 }, .brk = { 0x85, 0 } }, /* 005 */ + { .mk = { 0x06, 0 }, .brk = { 0x86, 0 } }, /* 006 */ + { .mk = { 0x07, 0 }, .brk = { 0x87, 0 } }, /* 007 */ + { .mk = { 0x08, 0 }, .brk = { 0x88, 0 } }, /* 008 */ + { .mk = { 0x09, 0 }, .brk = { 0x89, 0 } }, /* 009 */ + { .mk = { 0x0a, 0 }, .brk = { 0x8a, 0 } }, /* 00a */ + { .mk = { 0x0b, 0 }, .brk = { 0x8b, 0 } }, /* 00b */ + { .mk = { 0x0c, 0 }, .brk = { 0x8c, 0 } }, /* 00c */ + { .mk = { 0x0d, 0 }, .brk = { 0x8d, 0 } }, /* 00d */ + { .mk = { 0x0e, 0 }, .brk = { 0x8e, 0 } }, /* 00e */ + { .mk = { 0x0f, 0 }, .brk = { 0x8f, 0 } }, /* 00f */ + { .mk = { 0x10, 0 }, .brk = { 0x90, 0 } }, /* 010 */ + { .mk = { 0x11, 0 }, .brk = { 0x91, 0 } }, /* 011 */ + { .mk = { 0x12, 0 }, .brk = { 0x92, 0 } }, /* 012 */ + { .mk = { 0x13, 0 }, .brk = { 0x93, 0 } }, /* 013 */ + { .mk = { 0x14, 0 }, .brk = { 0x94, 0 } }, /* 014 */ + { .mk = { 0x15, 0 }, .brk = { 0x95, 0 } }, /* 015 */ + { .mk = { 0x16, 0 }, .brk = { 0x96, 0 } }, /* 016 */ + { .mk = { 0x17, 0 }, .brk = { 0x97, 0 } }, /* 017 */ + { .mk = { 0x18, 0 }, .brk = { 0x98, 0 } }, /* 018 */ + { .mk = { 0x19, 0 }, .brk = { 0x99, 0 } }, /* 019 */ + { .mk = { 0x1a, 0 }, .brk = { 0x9a, 0 } }, /* 01a */ + { .mk = { 0x1b, 0 }, .brk = { 0x9b, 0 } }, /* 01b */ + { .mk = { 0x1c, 0 }, .brk = { 0x9c, 0 } }, /* 01c */ + { .mk = { 0x1d, 0 }, .brk = { 0x9d, 0 } }, /* 01d */ + { .mk = { 0x1e, 0 }, .brk = { 0x9e, 0 } }, /* 01e */ + { .mk = { 0x1f, 0 }, .brk = { 0x9f, 0 } }, /* 01f */ + { .mk = { 0x20, 0 }, .brk = { 0xa0, 0 } }, /* 020 */ + { .mk = { 0x21, 0 }, .brk = { 0xa1, 0 } }, /* 021 */ + { .mk = { 0x22, 0 }, .brk = { 0xa2, 0 } }, /* 022 */ + { .mk = { 0x23, 0 }, .brk = { 0xa3, 0 } }, /* 023 */ + { .mk = { 0x24, 0 }, .brk = { 0xa4, 0 } }, /* 024 */ + { .mk = { 0x25, 0 }, .brk = { 0xa5, 0 } }, /* 025 */ + { .mk = { 0x26, 0 }, .brk = { 0xa6, 0 } }, /* 026 */ + { .mk = { 0x27, 0 }, .brk = { 0xa7, 0 } }, /* 027 */ + { .mk = { 0x28, 0 }, .brk = { 0xa8, 0 } }, /* 028* */ + { .mk = { 0x77, 0 }, .brk = { 0xf7, 0 } }, /* 029 0x45 Hankaku, Zenkaku */ + { .mk = { 0x2a, 0 }, .brk = { 0xaa, 0 } }, /* 02a */ + { .mk = { 0x1b, 0 }, .brk = { 0x9b, 0 } }, /* 02b 0x17 Mu */ + { .mk = { 0x2c, 0 }, .brk = { 0xac, 0 } }, /* 02c */ + { .mk = { 0x2d, 0 }, .brk = { 0xad, 0 } }, /* 02d */ + { .mk = { 0x2e, 0 }, .brk = { 0xae, 0 } }, /* 02e */ + { .mk = { 0x2f, 0 }, .brk = { 0xaf, 0 } }, /* 02f */ + { .mk = { 0x30, 0 }, .brk = { 0xb0, 0 } }, /* 030 */ + { .mk = { 0x31, 0 }, .brk = { 0xb1, 0 } }, /* 031 */ + { .mk = { 0x32, 0 }, .brk = { 0xb2, 0 } }, /* 032 */ + { .mk = { 0x33, 0 }, .brk = { 0xb3, 0 } }, /* 033 */ + { .mk = { 0x34, 0 }, .brk = { 0xb4, 0 } }, /* 034 */ + { .mk = { 0x35, 0 }, .brk = { 0xb5, 0 } }, /* 035 */ + { .mk = { 0x36, 0 }, .brk = { 0xb6, 0 } }, /* 036 */ + { .mk = { 0x37, 0 }, .brk = { 0xb7, 0 } }, /* 037 * (asterisk) */ + { .mk = { 0x70, 0 }, .brk = { 0xf0, 0 } }, /* 038 0x3A LALT = Kanji */ + { .mk = { 0x39, 0 }, .brk = { 0xb9, 0 } }, /* 039 */ + { .mk = { 0x3a, 0 }, .brk = { 0xba, 0 } }, /* 03a */ + { .mk = { 0x3b, 0 }, .brk = { 0xbb, 0 } }, /* 03b */ + { .mk = { 0x3c, 0 }, .brk = { 0xbc, 0 } }, /* 03c */ + { .mk = { 0x3d, 0 }, .brk = { 0xbd, 0 } }, /* 03d */ + { .mk = { 0x3e, 0 }, .brk = { 0xbe, 0 } }, /* 03e */ + { .mk = { 0x3f, 0 }, .brk = { 0xbf, 0 } }, /* 03f */ + { .mk = { 0x40, 0 }, .brk = { 0xc0, 0 } }, /* 040 */ + { .mk = { 0x41, 0 }, .brk = { 0xc1, 0 } }, /* 041 */ + { .mk = { 0x42, 0 }, .brk = { 0xc2, 0 } }, /* 042 */ + { .mk = { 0x43, 0 }, .brk = { 0xc3, 0 } }, /* 043 */ + { .mk = { 0x44, 0 }, .brk = { 0xc4, 0 } }, /* 044 */ + { .mk = { 0x45, 0 }, .brk = { 0xc5, 0 } }, /* 045 NUMLOCKCLEAR -> Shift + SCRLOCK :TODO */ + { .mk = { 0x46, 0 }, .brk = { 0xc6, 0 } }, /* 046 0x75 SCROLLLOCK */ + { .mk = { 0x47, 0 }, .brk = { 0xc7, 0 } }, /* 047 */ + { .mk = { 0x48, 0 }, .brk = { 0xc8, 0 } }, /* 048 */ + { .mk = { 0x49, 0 }, .brk = { 0xc9, 0 } }, /* 049 */ + { .mk = { 0x4a, 0 }, .brk = { 0xca, 0 } }, /* 04a */ + { .mk = { 0x4b, 0 }, .brk = { 0xcb, 0 } }, /* 04b */ + { .mk = { 0x4c, 0 }, .brk = { 0xcc, 0 } }, /* 04c */ + { .mk = { 0x4d, 0 }, .brk = { 0xcd, 0 } }, /* 04d */ + { .mk = { 0x4e, 0 }, .brk = { 0xce, 0 } }, /* 04e */ + { .mk = { 0x4f, 0 }, .brk = { 0xcf, 0 } }, /* 04f */ + { .mk = { 0x50, 0 }, .brk = { 0xd0, 0 } }, /* 050 */ + { .mk = { 0x51, 0 }, .brk = { 0xd1, 0 } }, /* 051 */ + { .mk = { 0x52, 0 }, .brk = { 0xd2, 0 } }, /* 052 */ + { .mk = { 0x53, 0 }, .brk = { 0xd3, 0 } }, /* 053 */ + { .mk = { 0x54, 0 }, .brk = { 0xd4, 0 } }, /* 054 */ + { .mk = { 0x55, 0 }, .brk = { 0xd5, 0 } }, /* 055 */ + { .mk = { 0x56, 0 }, .brk = { 0xd6, 0 } }, /* 056 */ + { .mk = { 0x57, 0 }, .brk = { 0xd7, 0 } }, /* 057 F11 */ + { .mk = { 0x58, 0 }, .brk = { 0xd8, 0 } }, /* 058 F12 */ + { .mk = { 0x59, 0 }, .brk = { 0xd9, 0 } }, /* 059 */ + { .mk = { 0x5a, 0 }, .brk = { 0xda, 0 } }, /* 05a */ + { .mk = { 0x5b, 0 }, .brk = { 0xdb, 0 } }, /* 05b */ + { .mk = { 0x5c, 0 }, .brk = { 0xdc, 0 } }, /* 05c */ + { .mk = { 0x5d, 0 }, .brk = { 0xdd, 0 } }, /* 05d */ + { .mk = { 0x5e, 0 }, .brk = { 0xde, 0 } }, /* 05e */ + { .mk = { 0x5f, 0 }, .brk = { 0xdf, 0 } }, /* 05f */ + { .mk = { 0x60, 0 }, .brk = { 0xe0, 0 } }, /* 060 */ + { .mk = { 0x61, 0 }, .brk = { 0xe1, 0 } }, /* 061 */ + { .mk = { 0x62, 0 }, .brk = { 0xe2, 0 } }, /* 062 */ + { .mk = { 0x63, 0 }, .brk = { 0xe3, 0 } }, /* 063 */ + { .mk = { 0x64, 0 }, .brk = { 0xe4, 0 } }, /* 064 */ + { .mk = { 0x65, 0 }, .brk = { 0xe5, 0 } }, /* 065 */ + { .mk = { 0x66, 0 }, .brk = { 0xe6, 0 } }, /* 066 */ + { .mk = { 0x67, 0 }, .brk = { 0xe7, 0 } }, /* 067 */ + { .mk = { 0x68, 0 }, .brk = { 0xe8, 0 } }, /* 068 */ + { .mk = { 0x69, 0 }, .brk = { 0xe9, 0 } }, /* 069 */ + { .mk = { 0x6a, 0 }, .brk = { 0xea, 0 } }, /* 06a */ + { .mk = { 0x6b, 0 }, .brk = { 0xeb, 0 } }, /* 06b */ + { .mk = { 0x6c, 0 }, .brk = { 0xec, 0 } }, /* 06c */ + { .mk = { 0x6d, 0 }, .brk = { 0xed, 0 } }, /* 06d */ + { .mk = { 0x6e, 0 }, .brk = { 0xee, 0 } }, /* 06e */ + { .mk = { 0x6f, 0 }, .brk = { 0xef, 0 } }, /* 06f */ + { .mk = {0xe0, 0x38, 0 }, .brk = { 0xe0, 0xb8, 0 } }, /* 070 0x36 Kana */ + { .mk = { 0x71, 0 }, .brk = { 0xf1, 0 } }, /* 071 */ + { .mk = { 0x72, 0 }, .brk = { 0xf2, 0 } }, /* 072 */ + { .mk = { 0x73, 0 }, .brk = { 0xf3, 0 } }, /* 073 0x0b Ro, Underline */ + { .mk = { 0x74, 0 }, .brk = { 0xf4, 0 } }, /* 074 */ + { .mk = { 0x75, 0 }, .brk = { 0xf5, 0 } }, /* 075 */ + { .mk = { 0x76, 0 }, .brk = { 0xf6, 0 } }, /* 076 */ + { .mk = { 0x77, 0 }, .brk = { 0xf7, 0 } }, /* 077 */ + { .mk = { 0x78, 0 }, .brk = { 0xf8, 0 } }, /* 078 */ + { .mk = { 0x79, 0 }, .brk = { 0xf9, 0 } }, /* 079 0x35 Henkan */ + { .mk = { 0x7a, 0 }, .brk = { 0xfa, 0 } }, /* 07a */ + { .mk = { 0x7b, 0 }, .brk = { 0xfb, 0 } }, /* 07b 0x33 Muhenkan */ + { .mk = { 0x7c, 0 }, .brk = { 0xfc, 0 } }, /* 07c */ + { .mk = { 0x2b, 0 }, .brk = { 0xab, 0 } }, /* 07d 0x30 Yen, Vertical line */ + { .mk = { 0x7e, 0 }, .brk = { 0xfe, 0 } }, /* 07e */ + { .mk = { 0x7f, 0 }, .brk = { 0xff, 0 } }, /* 07f */ + { .mk = { 0x80, 0 }, .brk = { 0 } }, /* 080 */ + { .mk = { 0x81, 0 }, .brk = { 0 } }, /* 081 */ + { .mk = { 0x82, 0 }, .brk = { 0 } }, /* 082 */ + { .mk = { 0 }, .brk = { 0 } }, /* 083 */ + { .mk = { 0 }, .brk = { 0 } }, /* 084 */ + { .mk = { 0x85, 0 }, .brk = { 0 } }, /* 085 */ + { .mk = { 0x86, 0 }, .brk = { 0 } }, /* 086 */ + { .mk = { 0x87, 0 }, .brk = { 0 } }, /* 087 */ + { .mk = { 0x88, 0 }, .brk = { 0 } }, /* 088 */ + { .mk = { 0x89, 0 }, .brk = { 0 } }, /* 089 */ + { .mk = { 0x8a, 0 }, .brk = { 0 } }, /* 08a */ + { .mk = { 0x8b, 0 }, .brk = { 0 } }, /* 08b */ + { .mk = { 0x8c, 0 }, .brk = { 0 } }, /* 08c */ + { .mk = { 0x8d, 0 }, .brk = { 0 } }, /* 08d */ + { .mk = { 0x8e, 0 }, .brk = { 0 } }, /* 08e */ + { .mk = { 0x8f, 0 }, .brk = { 0 } }, /* 08f */ + { .mk = { 0x90, 0 }, .brk = { 0 } }, /* 090 */ + { .mk = { 0x91, 0 }, .brk = { 0 } }, /* 091 */ + { .mk = { 0x92, 0 }, .brk = { 0 } }, /* 092 */ + { .mk = { 0x93, 0 }, .brk = { 0 } }, /* 093 */ + { .mk = { 0x94, 0 }, .brk = { 0 } }, /* 094 */ + { .mk = { 0x95, 0 }, .brk = { 0 } }, /* 095 */ + { .mk = { 0x96, 0 }, .brk = { 0 } }, /* 096 */ + { .mk = { 0x97, 0 }, .brk = { 0 } }, /* 097 */ + { .mk = { 0x98, 0 }, .brk = { 0 } }, /* 098 */ + { .mk = { 0x99, 0 }, .brk = { 0 } }, /* 099 */ + { .mk = { 0x9a, 0 }, .brk = { 0 } }, /* 09a */ + { .mk = { 0x9b, 0 }, .brk = { 0 } }, /* 09b */ + { .mk = { 0x9c, 0 }, .brk = { 0 } }, /* 09c */ + { .mk = { 0x9d, 0 }, .brk = { 0 } }, /* 09d */ + { .mk = { 0x9e, 0 }, .brk = { 0 } }, /* 09e */ + { .mk = { 0x9f, 0 }, .brk = { 0 } }, /* 09f */ + { .mk = { 0xa0, 0 }, .brk = { 0 } }, /* 0a0 */ + { .mk = { 0xa1, 0 }, .brk = { 0 } }, /* 0a1 */ + { .mk = { 0xa2, 0 }, .brk = { 0 } }, /* 0a2 */ + { .mk = { 0xa3, 0 }, .brk = { 0 } }, /* 0a3 */ + { .mk = { 0xa4, 0 }, .brk = { 0 } }, /* 0a4 */ + { .mk = { 0xa5, 0 }, .brk = { 0 } }, /* 0a5 */ + { .mk = { 0xa6, 0 }, .brk = { 0 } }, /* 0a6 */ + { .mk = { 0xa7, 0 }, .brk = { 0 } }, /* 0a7 */ + { .mk = { 0xa8, 0 }, .brk = { 0 } }, /* 0a8 */ + { .mk = { 0xa9, 0 }, .brk = { 0 } }, /* 0a9 */ + { .mk = { 0xaa, 0 }, .brk = { 0 } }, /* 0aa */ + { .mk = { 0xab, 0 }, .brk = { 0 } }, /* 0ab */ + { .mk = { 0xac, 0 }, .brk = { 0 } }, /* 0ac */ + { .mk = { 0xad, 0 }, .brk = { 0 } }, /* 0ad */ + { .mk = { 0xae, 0 }, .brk = { 0 } }, /* 0ae */ + { .mk = { 0xaf, 0 }, .brk = { 0 } }, /* 0af */ + { .mk = { 0xb0, 0 }, .brk = { 0 } }, /* 0b0 */ + { .mk = { 0xb1, 0 }, .brk = { 0 } }, /* 0b1 */ + { .mk = { 0xb2, 0 }, .brk = { 0 } }, /* 0b2 */ + { .mk = { 0xb3, 0 }, .brk = { 0 } }, /* 0b3 */ + { .mk = { 0xb4, 0 }, .brk = { 0 } }, /* 0b4 */ + { .mk = { 0xb5, 0 }, .brk = { 0 } }, /* 0b5 */ + { .mk = { 0xb6, 0 }, .brk = { 0 } }, /* 0b6 */ + { .mk = { 0xb7, 0 }, .brk = { 0 } }, /* 0b7 */ + { .mk = { 0xb8, 0 }, .brk = { 0 } }, /* 0b8 */ + { .mk = { 0xb9, 0 }, .brk = { 0 } }, /* 0b9 */ + { .mk = { 0xba, 0 }, .brk = { 0 } }, /* 0ba */ + { .mk = { 0xbb, 0 }, .brk = { 0 } }, /* 0bb */ + { .mk = { 0xbc, 0 }, .brk = { 0 } }, /* 0bc */ + { .mk = { 0xbd, 0 }, .brk = { 0 } }, /* 0bd */ + { .mk = { 0xbe, 0 }, .brk = { 0 } }, /* 0be */ + { .mk = { 0xbf, 0 }, .brk = { 0 } }, /* 0bf */ + { .mk = { 0xc0, 0 }, .brk = { 0 } }, /* 0c0 */ + { .mk = { 0xc1, 0 }, .brk = { 0 } }, /* 0c1 */ + { .mk = { 0xc2, 0 }, .brk = { 0 } }, /* 0c2 */ + { .mk = { 0xc3, 0 }, .brk = { 0 } }, /* 0c3 */ + { .mk = { 0xc4, 0 }, .brk = { 0 } }, /* 0c4 */ + { .mk = { 0xc5, 0 }, .brk = { 0 } }, /* 0c5 */ + { .mk = { 0xc6, 0 }, .brk = { 0 } }, /* 0c6 */ + { .mk = { 0xc7, 0 }, .brk = { 0 } }, /* 0c7 */ + { .mk = { 0xc8, 0 }, .brk = { 0 } }, /* 0c8 */ + { .mk = { 0xc9, 0 }, .brk = { 0 } }, /* 0c9 */ + { .mk = { 0xca, 0 }, .brk = { 0 } }, /* 0ca */ + { .mk = { 0xcb, 0 }, .brk = { 0 } }, /* 0cb */ + { .mk = { 0xcc, 0 }, .brk = { 0 } }, /* 0cc */ + { .mk = { 0xcd, 0 }, .brk = { 0 } }, /* 0cd */ + { .mk = { 0xce, 0 }, .brk = { 0 } }, /* 0ce */ + { .mk = { 0xcf, 0 }, .brk = { 0 } }, /* 0cf */ + { .mk = { 0xd0, 0 }, .brk = { 0 } }, /* 0d0 */ + { .mk = { 0xd1, 0 }, .brk = { 0 } }, /* 0d1 */ + { .mk = { 0xd2, 0 }, .brk = { 0 } }, /* 0d2 */ + { .mk = { 0xd3, 0 }, .brk = { 0 } }, /* 0d3 */ + { .mk = { 0xd4, 0 }, .brk = { 0 } }, /* 0d4 */ + { .mk = { 0xd5, 0 }, .brk = { 0 } }, /* 0d5 */ + { .mk = { 0xd6, 0 }, .brk = { 0 } }, /* 0d6 */ + { .mk = { 0xd7, 0 }, .brk = { 0 } }, /* 0d7 */ + { .mk = { 0xd8, 0 }, .brk = { 0 } }, /* 0d8 */ + { .mk = { 0xd9, 0 }, .brk = { 0 } }, /* 0d9 */ + { .mk = { 0xda, 0 }, .brk = { 0 } }, /* 0da */ + { .mk = { 0xdb, 0 }, .brk = { 0 } }, /* 0db */ + { .mk = { 0xdc, 0 }, .brk = { 0 } }, /* 0dc */ + { .mk = { 0xdd, 0 }, .brk = { 0 } }, /* 0dd */ + { .mk = { 0xde, 0 }, .brk = { 0 } }, /* 0de */ + { .mk = { 0xdf, 0 }, .brk = { 0 } }, /* 0df */ + { .mk = { 0xe0, 0 }, .brk = { 0 } }, /* 0e0 */ + { .mk = { 0xe1, 0 }, .brk = { 0 } }, /* 0e1 */ + { .mk = { 0xe2, 0 }, .brk = { 0 } }, /* 0e2 */ + { .mk = { 0xe3, 0 }, .brk = { 0 } }, /* 0e3 */ + { .mk = { 0xe4, 0 }, .brk = { 0 } }, /* 0e4 */ + { .mk = { 0xe5, 0 }, .brk = { 0 } }, /* 0e5 */ + { .mk = { 0xe6, 0 }, .brk = { 0 } }, /* 0e6 */ + { .mk = { 0xe7, 0 }, .brk = { 0 } }, /* 0e7 */ + { .mk = { 0xe8, 0 }, .brk = { 0 } }, /* 0e8 */ + { .mk = { 0xe9, 0 }, .brk = { 0 } }, /* 0e9 */ + { .mk = { 0xea, 0 }, .brk = { 0 } }, /* 0ea */ + { .mk = { 0xeb, 0 }, .brk = { 0 } }, /* 0eb */ + { .mk = { 0xec, 0 }, .brk = { 0 } }, /* 0ec */ + { .mk = { 0xed, 0 }, .brk = { 0 } }, /* 0ed */ + { .mk = { 0xee, 0 }, .brk = { 0 } }, /* 0ee */ + { .mk = { 0xef, 0 }, .brk = { 0 } }, /* 0ef */ + { .mk = { 0 }, .brk = { 0 } }, /* 0f0 */ + { .mk = { 0xf1, 0 }, .brk = { 0 } }, /* 0f1 */ + { .mk = { 0xf2, 0 }, .brk = { 0 } }, /* 0f2 */ + { .mk = { 0xf3, 0 }, .brk = { 0 } }, /* 0f3 */ + { .mk = { 0xf4, 0 }, .brk = { 0 } }, /* 0f4 */ + { .mk = { 0xf5, 0 }, .brk = { 0 } }, /* 0f5 */ + { .mk = { 0xf6, 0 }, .brk = { 0 } }, /* 0f6 */ + { .mk = { 0xf7, 0 }, .brk = { 0 } }, /* 0f7 */ + { .mk = { 0xf8, 0 }, .brk = { 0 } }, /* 0f8 */ + { .mk = { 0xf9, 0 }, .brk = { 0 } }, /* 0f9 */ + { .mk = { 0xfa, 0 }, .brk = { 0 } }, /* 0fa */ + { .mk = { 0xfb, 0 }, .brk = { 0 } }, /* 0fb */ + { .mk = { 0xfc, 0 }, .brk = { 0 } }, /* 0fc */ + { .mk = { 0xfd, 0 }, .brk = { 0 } }, /* 0fd */ + { .mk = { 0xfe, 0 }, .brk = { 0 } }, /* 0fe */ + { .mk = { 0xff, 0 }, .brk = { 0 } }, /* 0ff */ + { .mk = {0xe1, 0x1d, 0 }, .brk = { 0xe1, 0x9d, 0 } }, /* 100 */ + { .mk = {0xe0, 0x01, 0 }, .brk = { 0xe0, 0x81, 0 } }, /* 101 */ + { .mk = {0xe0, 0x02, 0 }, .brk = { 0xe0, 0x82, 0 } }, /* 102 */ + { .mk = {0xe0, 0x03, 0 }, .brk = { 0xe0, 0x83, 0 } }, /* 103 */ + { .mk = {0xe0, 0x04, 0 }, .brk = { 0xe0, 0x84, 0 } }, /* 104 */ + { .mk = {0xe0, 0x05, 0 }, .brk = { 0xe0, 0x85, 0 } }, /* 105 */ + { .mk = {0xe0, 0x06, 0 }, .brk = { 0xe0, 0x86, 0 } }, /* 106 */ + { .mk = {0xe0, 0x07, 0 }, .brk = { 0xe0, 0x87, 0 } }, /* 107 */ + { .mk = {0xe0, 0x08, 0 }, .brk = { 0xe0, 0x88, 0 } }, /* 108 */ + { .mk = {0xe0, 0x09, 0 }, .brk = { 0xe0, 0x89, 0 } }, /* 109 */ + { .mk = {0xe0, 0x0a, 0 }, .brk = { 0xe0, 0x8a, 0 } }, /* 10a */ + { .mk = {0xe0, 0x0b, 0 }, .brk = { 0xe0, 0x8b, 0 } }, /* 10b */ + { .mk = {0xe0, 0x0c, 0 }, .brk = { 0xe0, 0x8c, 0 } }, /* 10c */ + { .mk = { 0 }, .brk = { 0 } }, /* 10d */ + { .mk = {0xe0, 0x0e, 0 }, .brk = { 0xe0, 0x8e, 0 } }, /* 10e */ + { .mk = {0xe0, 0x0f, 0 }, .brk = { 0xe0, 0x8f, 0 } }, /* 10f */ + { .mk = {0xe0, 0x10, 0 }, .brk = { 0xe0, 0x90, 0 } }, /* 110 */ + { .mk = {0xe0, 0x11, 0 }, .brk = { 0xe0, 0x91, 0 } }, /* 112 */ + { .mk = {0xe0, 0x12, 0 }, .brk = { 0xe0, 0x92, 0 } }, /* 113 */ + { .mk = {0xe0, 0x13, 0 }, .brk = { 0xe0, 0x93, 0 } }, /* 113 */ + { .mk = {0xe0, 0x14, 0 }, .brk = { 0xe0, 0x94, 0 } }, /* 114 */ + { .mk = {0xe0, 0x15, 0 }, .brk = { 0xe0, 0x95, 0 } }, /* 115 */ + { .mk = {0xe0, 0x16, 0 }, .brk = { 0xe0, 0x96, 0 } }, /* 116 */ + { .mk = {0xe0, 0x17, 0 }, .brk = { 0xe0, 0x97, 0 } }, /* 117 */ + { .mk = {0xe0, 0x18, 0 }, .brk = { 0xe0, 0x98, 0 } }, /* 118 */ + { .mk = {0xe0, 0x19, 0 }, .brk = { 0xe0, 0x99, 0 } }, /* 119 */ + { .mk = {0xe0, 0x1a, 0 }, .brk = { 0xe0, 0x9a, 0 } }, /* 11a */ + { .mk = {0xe0, 0x1b, 0 }, .brk = { 0xe0, 0x9b, 0 } }, /* 11b */ + { .mk = {0xe0, 0x1c, 0 }, .brk = { 0xe0, 0x9c, 0 } }, /* 11c */ + { .mk = {0xe0, 0x1d, 0 }, .brk = { 0xe0, 0x9d, 0 } }, /* 11d */ + { .mk = {0xe0, 0x1e, 0 }, .brk = { 0xe0, 0x9e, 0 } }, /* 11e */ + { .mk = {0xe0, 0x1f, 0 }, .brk = { 0xe0, 0x9f, 0 } }, /* 11f */ + { .mk = {0xe0, 0x20, 0 }, .brk = { 0xe0, 0xa0, 0 } }, /* 120 */ + { .mk = {0xe0, 0x21, 0 }, .brk = { 0xe0, 0xa1, 0 } }, /* 121 */ + { .mk = {0xe0, 0x22, 0 }, .brk = { 0xe0, 0xa2, 0 } }, /* 122 */ + { .mk = {0xe0, 0x23, 0 }, .brk = { 0xe0, 0xa3, 0 } }, /* 123 */ + { .mk = {0xe0, 0x24, 0 }, .brk = { 0xe0, 0xa4, 0 } }, /* 124 */ + { .mk = {0xe0, 0x25, 0 }, .brk = { 0xe0, 0xa5, 0 } }, /* 125 */ + { .mk = {0xe0, 0x26, 0 }, .brk = { 0xe0, 0xa6, 0 } }, /* 126 */ + { .mk = { 0 }, .brk = { 0 } }, /* 127 */ + { .mk = { 0 }, .brk = { 0 } }, /* 128 */ + { .mk = { 0 }, .brk = { 0 } }, /* 129 */ + { .mk = { 0 }, .brk = { 0 } }, /* 12a */ + { .mk = { 0 }, .brk = { 0 } }, /* 12b */ + { .mk = {0xe0, 0x2c, 0 }, .brk = { 0xe0, 0xac, 0 } }, /* 12c */ + { .mk = {0xe0, 0x2d, 0 }, .brk = { 0xe0, 0xad, 0 } }, /* 12d */ + { .mk = {0xe0, 0x2e, 0 }, .brk = { 0xe0, 0xae, 0 } }, /* 12e */ + { .mk = {0xe0, 0x2f, 0 }, .brk = { 0xe0, 0xaf, 0 } }, /* 12f */ + { .mk = {0xe0, 0x30, 0 }, .brk = { 0xe0, 0xb0, 0 } }, /* 130 */ + { .mk = {0xe0, 0x31, 0 }, .brk = { 0xe0, 0xb1, 0 } }, /* 131 */ + { .mk = {0xe0, 0x32, 0 }, .brk = { 0xe0, 0xb2, 0 } }, /* 132 */ + { .mk = { 0 }, .brk = { 0 } }, /* 133 */ + { .mk = {0xe0, 0x34, 0 }, .brk = { 0xe0, 0xb4, 0 } }, /* 134 */ + { .mk = {0xe0, 0x35, 0 }, .brk = { 0xe0, 0xb5, 0 } }, /* 135 */ + { .mk = { 0 }, .brk = { 0 } }, /* 136 */ + { .mk = {0xe0, 0x37, 0 }, .brk = { 0xe0, 0xb7, 0 } }, /* 137 */ + { .mk = { 0x38, 0 }, .brk = { 0xb8, 0 } }, /* 138* 0x31 R-Alt */ + { .mk = { 0 }, .brk = { 0 } }, /* 139 */ + { .mk = {0xe0, 0x3a, 0 }, .brk = { 0xe0, 0xba, 0 } }, /* 13a */ + { .mk = {0xe0, 0x3b, 0 }, .brk = { 0xe0, 0xbb, 0 } }, /* 13b */ + { .mk = {0xe0, 0x3c, 0 }, .brk = { 0xe0, 0xbc, 0 } }, /* 13c */ + { .mk = {0xe0, 0x3d, 0 }, .brk = { 0xe0, 0xbd, 0 } }, /* 13d */ + { .mk = {0xe0, 0x3e, 0 }, .brk = { 0xe0, 0xbe, 0 } }, /* 13e */ + { .mk = {0xe0, 0x3f, 0 }, .brk = { 0xe0, 0xbf, 0 } }, /* 13f */ + { .mk = {0xe0, 0x40, 0 }, .brk = { 0xe0, 0xc0, 0 } }, /* 140 */ + { .mk = {0xe0, 0x41, 0 }, .brk = { 0xe0, 0xc1, 0 } }, /* 141 */ + { .mk = {0xe0, 0x42, 0 }, .brk = { 0xe0, 0xc2, 0 } }, /* 142 */ + { .mk = {0xe0, 0x43, 0 }, .brk = { 0xe0, 0xc3, 0 } }, /* 143 */ + { .mk = {0xe0, 0x44, 0 }, .brk = { 0xe0, 0xc4, 0 } }, /* 144 */ + { .mk = { 0 }, .brk = { 0 } }, /* 145 */ + { .mk = {0xe0, 0x46, 0 }, .brk = { 0xe0, 0xc6, 0 } }, /* 146 */ + { .mk = {0xe0, 0x47, 0 }, .brk = { 0xe0, 0xc7, 0 } }, /* 147 */ + { .mk = {0xe0, 0x48, 0 }, .brk = { 0xe0, 0xc8, 0 } }, /* 148 */ + { .mk = {0xe0, 0x49, 0 }, .brk = { 0xe0, 0xc9, 0 } }, /* 149 */ + { .mk = { 0 }, .brk = { 0 } }, /* 14a */ + { .mk = {0xe0, 0x4b, 0 }, .brk = { 0xe0, 0xcb, 0 } }, /* 14b */ + { .mk = {0xe0, 0x4c, 0 }, .brk = { 0xe0, 0xcc, 0 } }, /* 14c */ + { .mk = {0xe0, 0x4d, 0 }, .brk = { 0xe0, 0xcd, 0 } }, /* 14d */ + { .mk = {0xe0, 0x4e, 0 }, .brk = { 0xe0, 0xce, 0 } }, /* 14e */ + { .mk = {0xe0, 0x4f, 0 }, .brk = { 0xe0, 0xcf, 0 } }, /* 14f */ + { .mk = {0xe0, 0x50, 0 }, .brk = { 0xe0, 0xd0, 0 } }, /* 150 */ + { .mk = {0xe0, 0x51, 0 }, .brk = { 0xe0, 0xd1, 0 } }, /* 151 */ + { .mk = {0xe0, 0x52, 0 }, .brk = { 0xe0, 0xd2, 0 } }, /* 152 */ + { .mk = {0xe0, 0x53, 0 }, .brk = { 0xe0, 0xd3, 0 } }, /* 153 */ + { .mk = { 0 }, .brk = { 0 } }, /* 154 */ + { .mk = {0xe0, 0x55, 0 }, .brk = { 0xe0, 0xd5, 0 } }, /* 155 */ + { .mk = { 0 }, .brk = { 0 } }, /* 156 */ + { .mk = {0xe0, 0x57, 0 }, .brk = { 0xe0, 0xd7, 0 } }, /* 157 */ + { .mk = {0xe0, 0x58, 0 }, .brk = { 0xe0, 0xd8, 0 } }, /* 158 */ + { .mk = {0xe0, 0x59, 0 }, .brk = { 0xe0, 0xd9, 0 } }, /* 159 */ + { .mk = {0xe0, 0x5a, 0 }, .brk = { 0xe0, 0xaa, 0 } }, /* 15a */ + { .mk = { 0x7b, 0 }, .brk = { 0xfb, 0 } }, /* 15b 0x33 LGUI->Muhenkan (in emulator only) */ + { .mk = { 0x79, 0 }, .brk = { 0xf9, 0 } }, /* 15c 0x35 RGUI->Henkan (in emulator only) */ + { .mk = {0xe0, 0x38, 0 }, .brk = { 0xe0, 0xb8, 0 } }, /* 15d 0x36 APPLICATION->Kana (in emulator only) */ + { .mk = {0xe0, 0x5e, 0 }, .brk = { 0xe0, 0xee, 0 } }, /* 15e */ + { .mk = {0xe0, 0x5f, 0 }, .brk = { 0xe0, 0xdf, 0 } }, /* 15f */ + { .mk = { 0 }, .brk = { 0 } }, /* 160 */ + { .mk = {0xe0, 0x61, 0 }, .brk = { 0xe0, 0xe1, 0 } }, /* 161 */ + { .mk = {0xe0, 0x62, 0 }, .brk = { 0xe0, 0xe2, 0 } }, /* 162 */ + { .mk = {0xe0, 0x63, 0 }, .brk = { 0xe0, 0xe3, 0 } }, /* 163 */ + { .mk = {0xe0, 0x64, 0 }, .brk = { 0xe0, 0xe4, 0 } }, /* 164 */ + { .mk = {0xe0, 0x65, 0 }, .brk = { 0xe0, 0xe5, 0 } }, /* 165 */ + { .mk = {0xe0, 0x66, 0 }, .brk = { 0xe0, 0xe6, 0 } }, /* 166 */ + { .mk = {0xe0, 0x67, 0 }, .brk = { 0xe0, 0xe7, 0 } }, /* 167 */ + { .mk = {0xe0, 0x68, 0 }, .brk = { 0xe0, 0xe8, 0 } }, /* 168 */ + { .mk = {0xe0, 0x69, 0 }, .brk = { 0xe0, 0xe9, 0 } }, /* 169 */ + { .mk = {0xe0, 0x6a, 0 }, .brk = { 0xe0, 0xea, 0 } }, /* 16a */ + { .mk = {0xe0, 0x6b, 0 }, .brk = { 0xe0, 0xeb, 0 } }, /* 16b */ + { .mk = {0xe0, 0x6c, 0 }, .brk = { 0xe0, 0xec, 0 } }, /* 16c */ + { .mk = {0xe0, 0x6d, 0 }, .brk = { 0xe0, 0xed, 0 } }, /* 16d */ + { .mk = {0xe0, 0x6e, 0 }, .brk = { 0xe0, 0xee, 0 } }, /* 16e */ + { .mk = { 0 }, .brk = { 0 } }, /* 16f */ + { .mk = {0xe0, 0x70, 0 }, .brk = { 0xe0, 0xf0, 0 } }, /* 170 */ + { .mk = {0xe0, 0x71, 0 }, .brk = { 0xe0, 0xf1, 0 } }, /* 171 */ + { .mk = {0xe0, 0x72, 0 }, .brk = { 0xe0, 0xf2, 0 } }, /* 172 */ + { .mk = {0xe0, 0x73, 0 }, .brk = { 0xe0, 0xf3, 0 } }, /* 173 */ + { .mk = {0xe0, 0x74, 0 }, .brk = { 0xe0, 0xf4, 0 } }, /* 174 */ + { .mk = {0xe0, 0x75, 0 }, .brk = { 0xe0, 0xf5, 0 } }, /* 175 */ + { .mk = { 0 }, .brk = { 0 } }, /* 176 */ + { .mk = {0xe0, 0x77, 0 }, .brk = { 0xe0, 0xf7, 0 } }, /* 177 */ + { .mk = {0xe0, 0x78, 0 }, .brk = { 0xe0, 0xf8, 0 } }, /* 178 */ + { .mk = {0xe0, 0x79, 0 }, .brk = { 0xe0, 0xf9, 0 } }, /* 179 */ + { .mk = {0xe0, 0x7a, 0 }, .brk = { 0xe0, 0xfa, 0 } }, /* 17a */ + { .mk = {0xe0, 0x7b, 0 }, .brk = { 0xe0, 0xfb, 0 } }, /* 17b */ + { .mk = {0xe0, 0x7c, 0 }, .brk = { 0xe0, 0xfc, 0 } }, /* 17c */ + { .mk = {0xe0, 0x7d, 0 }, .brk = { 0xe0, 0xfd, 0 } }, /* 17d */ + { .mk = {0xe0, 0x7e, 0 }, .brk = { 0xe0, 0xfe, 0 } }, /* 17e */ + { .mk = {0xe0, 0x7f, 0 }, .brk = { 0xe0, 0xff, 0 } }, /* 17f */ + { .mk = { 0 }, .brk = { 0 } }, /* 180 */ + { .mk = { 0 }, .brk = { 0 } }, /* 181 */ + { .mk = { 0 }, .brk = { 0 } }, /* 182 */ + { .mk = { 0 }, .brk = { 0 } }, /* 183 */ + { .mk = { 0 }, .brk = { 0 } }, /* 184 */ + { .mk = { 0 }, .brk = { 0 } }, /* 185 */ + { .mk = { 0 }, .brk = { 0 } }, /* 186 */ + { .mk = { 0 }, .brk = { 0 } }, /* 187 */ + { .mk = { 0 }, .brk = { 0 } }, /* 188 */ + { .mk = { 0 }, .brk = { 0 } }, /* 189 */ + { .mk = { 0 }, .brk = { 0 } }, /* 18a */ + { .mk = { 0 }, .brk = { 0 } }, /* 18b */ + { .mk = { 0 }, .brk = { 0 } }, /* 18c */ + { .mk = { 0 }, .brk = { 0 } }, /* 18d */ + { .mk = { 0 }, .brk = { 0 } }, /* 18e */ + { .mk = { 0 }, .brk = { 0 } }, /* 18f */ + { .mk = { 0 }, .brk = { 0 } }, /* 190 */ + { .mk = { 0 }, .brk = { 0 } }, /* 191 */ + { .mk = { 0 }, .brk = { 0 } }, /* 192 */ + { .mk = { 0 }, .brk = { 0 } }, /* 193 */ + { .mk = { 0 }, .brk = { 0 } }, /* 194 */ + { .mk = { 0 }, .brk = { 0 } }, /* 195 */ + { .mk = { 0 }, .brk = { 0 } }, /* 196 */ + { .mk = { 0 }, .brk = { 0 } }, /* 197 */ + { .mk = { 0 }, .brk = { 0 } }, /* 198 */ + { .mk = { 0 }, .brk = { 0 } }, /* 199 */ + { .mk = { 0 }, .brk = { 0 } }, /* 19a */ + { .mk = { 0 }, .brk = { 0 } }, /* 19b */ + { .mk = { 0 }, .brk = { 0 } }, /* 19c */ + { .mk = { 0 }, .brk = { 0 } }, /* 19d */ + { .mk = { 0 }, .brk = { 0 } }, /* 19e */ + { .mk = { 0 }, .brk = { 0 } }, /* 19f */ + { .mk = { 0 }, .brk = { 0 } }, /* 1a0 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1a1 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1a2 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1a3 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1a4 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1a5 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1a6 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1a7 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1a8 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1a9 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1aa */ + { .mk = { 0 }, .brk = { 0 } }, /* 1ab */ + { .mk = { 0 }, .brk = { 0 } }, /* 1ac */ + { .mk = { 0 }, .brk = { 0 } }, /* 1ad */ + { .mk = { 0 }, .brk = { 0 } }, /* 1ae */ + { .mk = { 0 }, .brk = { 0 } }, /* 1af */ + { .mk = { 0 }, .brk = { 0 } }, /* 1b0 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1b1 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1b2 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1b3 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1b4 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1b5 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1b6 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1b7 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1b8 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1b9 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1ba */ + { .mk = { 0 }, .brk = { 0 } }, /* 1bb */ + { .mk = { 0 }, .brk = { 0 } }, /* 1bc */ + { .mk = { 0 }, .brk = { 0 } }, /* 1bd */ + { .mk = { 0 }, .brk = { 0 } }, /* 1be */ + { .mk = { 0 }, .brk = { 0 } }, /* 1bf */ + { .mk = { 0 }, .brk = { 0 } }, /* 1c0 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1c1 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1c2 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1c3 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1c4 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1c5 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1c6 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1c7 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1c8 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1c9 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1ca */ + { .mk = { 0 }, .brk = { 0 } }, /* 1cb */ + { .mk = { 0 }, .brk = { 0 } }, /* 1cv */ + { .mk = { 0 }, .brk = { 0 } }, /* 1cd */ + { .mk = { 0 }, .brk = { 0 } }, /* 1ce */ + { .mk = { 0 }, .brk = { 0 } }, /* 1cf */ + { .mk = { 0 }, .brk = { 0 } }, /* 1d0 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1d1 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1d2 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1d3 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1d4 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1d5 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1d6 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1d7 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1d8 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1d9 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1da */ + { .mk = { 0 }, .brk = { 0 } }, /* 1db */ + { .mk = { 0 }, .brk = { 0 } }, /* 1dc */ + { .mk = { 0 }, .brk = { 0 } }, /* 1dd */ + { .mk = { 0 }, .brk = { 0 } }, /* 1de */ + { .mk = { 0 }, .brk = { 0 } }, /* 1df */ + { .mk = { 0 }, .brk = { 0 } }, /* 1e0 */ + { .mk = {0xe0, 0xe1, 0 }, .brk = { 0 } }, /* 1e1 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1e2 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1e3 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1e4 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1e5 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1e6 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1e7 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1e8 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1e9 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1ea */ + { .mk = { 0 }, .brk = { 0 } }, /* 1eb */ + { .mk = { 0 }, .brk = { 0 } }, /* 1ec */ + { .mk = { 0 }, .brk = { 0 } }, /* 1ed */ + { .mk = {0xe0, 0xee, 0 }, .brk = { 0 } }, /* 1ee */ + { .mk = { 0 }, .brk = { 0 } }, /* 1ef */ + { .mk = { 0 }, .brk = { 0 } }, /* 1f0 */ + { .mk = {0xe0, 0xf1, 0 }, .brk = { 0 } }, /* 1f1 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1f2 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1f3 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1f4 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1f5 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1f6 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1f7 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1f8 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1f9 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1fa */ + { .mk = { 0 }, .brk = { 0 } }, /* 1fb */ + { .mk = { 0 }, .brk = { 0 } }, /* 1fc */ + { .mk = { 0 }, .brk = { 0 } }, /* 1fd */ + { .mk = {0xe0, 0xfe, 0 }, .brk = { 0 } }, /* 1fe */ + { .mk = {0xe0, 0xff, 0 }, .brk = { 0 } } /* 1ff */ + // clang-format on + }; +/* Scancode set 82h : Set 02 with language specific keys support used by DOS/V */ +static const scancode scancode_set82[512] = { + // clang-format off + { .mk = { 0 }, .brk = { 0 } }, /* 000 */ + { .mk = { 0x76, 0 }, .brk = { 0xF0, 0x76, 0 } }, /* 001 */ + { .mk = { 0x16, 0 }, .brk = { 0xF0, 0x16, 0 } }, /* 002 */ + { .mk = { 0x1E, 0 }, .brk = { 0xF0, 0x1E, 0 } }, /* 003 */ + { .mk = { 0x26, 0 }, .brk = { 0xF0, 0x26, 0 } }, /* 004 */ + { .mk = { 0x25, 0 }, .brk = { 0xF0, 0x25, 0 } }, /* 005 */ + { .mk = { 0x2E, 0 }, .brk = { 0xF0, 0x2E, 0 } }, /* 006 */ + { .mk = { 0x36, 0 }, .brk = { 0xF0, 0x36, 0 } }, /* 007 */ + { .mk = { 0x3D, 0 }, .brk = { 0xF0, 0x3D, 0 } }, /* 008 */ + { .mk = { 0x3E, 0 }, .brk = { 0xF0, 0x3E, 0 } }, /* 009 */ + { .mk = { 0x46, 0 }, .brk = { 0xF0, 0x46, 0 } }, /* 00a */ + { .mk = { 0x45, 0 }, .brk = { 0xF0, 0x45, 0 } }, /* 00b */ + { .mk = { 0x4E, 0 }, .brk = { 0xF0, 0x4E, 0 } }, /* 00c */ + { .mk = { 0x55, 0 }, .brk = { 0xF0, 0x55, 0 } }, /* 00d */ + { .mk = { 0x66, 0 }, .brk = { 0xF0, 0x66, 0 } }, /* 00e */ + { .mk = { 0x0D, 0 }, .brk = { 0xF0, 0x0D, 0 } }, /* 00f */ + { .mk = { 0x15, 0 }, .brk = { 0xF0, 0x15, 0 } }, /* 010 */ + { .mk = { 0x1D, 0 }, .brk = { 0xF0, 0x1D, 0 } }, /* 011 */ + { .mk = { 0x24, 0 }, .brk = { 0xF0, 0x24, 0 } }, /* 012 */ + { .mk = { 0x2D, 0 }, .brk = { 0xF0, 0x2D, 0 } }, /* 013 */ + { .mk = { 0x2C, 0 }, .brk = { 0xF0, 0x2C, 0 } }, /* 014 */ + { .mk = { 0x35, 0 }, .brk = { 0xF0, 0x35, 0 } }, /* 015 */ + { .mk = { 0x3C, 0 }, .brk = { 0xF0, 0x3C, 0 } }, /* 016 */ + { .mk = { 0x43, 0 }, .brk = { 0xF0, 0x43, 0 } }, /* 017 */ + { .mk = { 0x44, 0 }, .brk = { 0xF0, 0x44, 0 } }, /* 018 */ + { .mk = { 0x4D, 0 }, .brk = { 0xF0, 0x4D, 0 } }, /* 019 */ + { .mk = { 0x54, 0 }, .brk = { 0xF0, 0x54, 0 } }, /* 01a */ + { .mk = { 0x5B, 0 }, .brk = { 0xF0, 0x5B, 0 } }, /* 01b */ + { .mk = { 0x5A, 0 }, .brk = { 0xF0, 0x5A, 0 } }, /* 01c */ + { .mk = { 0x14, 0 }, .brk = { 0xF0, 0x14, 0 } }, /* 01d */ + { .mk = { 0x1C, 0 }, .brk = { 0xF0, 0x1C, 0 } }, /* 01e */ + { .mk = { 0x1B, 0 }, .brk = { 0xF0, 0x1B, 0 } }, /* 01f */ + { .mk = { 0x23, 0 }, .brk = { 0xF0, 0x23, 0 } }, /* 020 */ + { .mk = { 0x2B, 0 }, .brk = { 0xF0, 0x2B, 0 } }, /* 021 */ + { .mk = { 0x34, 0 }, .brk = { 0xF0, 0x34, 0 } }, /* 022 */ + { .mk = { 0x33, 0 }, .brk = { 0xF0, 0x33, 0 } }, /* 023 */ + { .mk = { 0x3B, 0 }, .brk = { 0xF0, 0x3B, 0 } }, /* 024 */ + { .mk = { 0x42, 0 }, .brk = { 0xF0, 0x42, 0 } }, /* 025 */ + { .mk = { 0x4B, 0 }, .brk = { 0xF0, 0x4B, 0 } }, /* 026 */ + { .mk = { 0x4C, 0 }, .brk = { 0xF0, 0x4C, 0 } }, /* 027 */ + { .mk = { 0x52, 0 }, .brk = { 0xF0, 0x52, 0 } }, /* 028* */ + { .mk = { 0x62, 0 }, .brk = { 0xf0, 0x62, 0 } }, /* 029 0x45 Hankaku, Zenkaku */ + { .mk = { 0x12, 0 }, .brk = { 0xF0, 0x12, 0 } }, /* 02a */ + { .mk = { 0x5b, 0 }, .brk = { 0xf0, 0x5b, 0 } }, /* 02b 0x17 Mu */ + { .mk = { 0x1A, 0 }, .brk = { 0xF0, 0x1A, 0 } }, /* 02c */ + { .mk = { 0x22, 0 }, .brk = { 0xF0, 0x22, 0 } }, /* 02d */ + { .mk = { 0x21, 0 }, .brk = { 0xF0, 0x21, 0 } }, /* 02e */ + { .mk = { 0x2A, 0 }, .brk = { 0xF0, 0x2A, 0 } }, /* 02f */ + { .mk = { 0x32, 0 }, .brk = { 0xF0, 0x32, 0 } }, /* 030 */ + { .mk = { 0x31, 0 }, .brk = { 0xF0, 0x31, 0 } }, /* 031 */ + { .mk = { 0x3A, 0 }, .brk = { 0xF0, 0x3A, 0 } }, /* 032 */ + { .mk = { 0x41, 0 }, .brk = { 0xF0, 0x41, 0 } }, /* 033 */ + { .mk = { 0x49, 0 }, .brk = { 0xF0, 0x49, 0 } }, /* 034 */ + { .mk = { 0x4A, 0 }, .brk = { 0xF0, 0x4A, 0 } }, /* 035 */ + { .mk = { 0x59, 0 }, .brk = { 0xF0, 0x59, 0 } }, /* 036 */ + { .mk = { 0x7C, 0 }, .brk = { 0xF0, 0x7C, 0 } }, /* 037 */ + { .mk = { 0x13, 0 }, .brk = { 0xF0, 0x13, 0 } }, /* 038 0x3A LALT = Kanji */ + { .mk = { 0x29, 0 }, .brk = { 0xF0, 0x29, 0 } }, /* 039 */ + { .mk = { 0x58, 0 }, .brk = { 0xF0, 0x58, 0 } }, /* 03a */ + { .mk = { 0x05, 0 }, .brk = { 0xF0, 0x05, 0 } }, /* 03b */ + { .mk = { 0x06, 0 }, .brk = { 0xF0, 0x06, 0 } }, /* 03c */ + { .mk = { 0x04, 0 }, .brk = { 0xF0, 0x04, 0 } }, /* 03d */ + { .mk = { 0x0C, 0 }, .brk = { 0xF0, 0x0C, 0 } }, /* 03e */ + { .mk = { 0x03, 0 }, .brk = { 0xF0, 0x03, 0 } }, /* 03f */ + { .mk = { 0x0B, 0 }, .brk = { 0xF0, 0x0B, 0 } }, /* 040 */ + { .mk = { 0x83, 0 }, .brk = { 0xF0, 0x83, 0 } }, /* 041 */ + { .mk = { 0x0A, 0 }, .brk = { 0xF0, 0x0A, 0 } }, /* 042 */ + { .mk = { 0x01, 0 }, .brk = { 0xF0, 0x01, 0 } }, /* 043 */ + { .mk = { 0x09, 0 }, .brk = { 0xF0, 0x09, 0 } }, /* 044 */ + { .mk = { 0x77, 0 }, .brk = { 0xF0, 0x77, 0 } }, /* 045 NUMLOCKCLEAR -> Shift + SCRLOCK :TODO */ + { .mk = { 0x7E, 0 }, .brk = { 0xF0, 0x7E, 0 } }, /* 046 0x75 SCROLLLOCK */ + { .mk = { 0x6C, 0 }, .brk = { 0xF0, 0x6C, 0 } }, /* 047 */ + { .mk = { 0x75, 0 }, .brk = { 0xF0, 0x75, 0 } }, /* 048 */ + { .mk = { 0x7D, 0 }, .brk = { 0xF0, 0x7D, 0 } }, /* 049 */ + { .mk = { 0x7B, 0 }, .brk = { 0xF0, 0x7B, 0 } }, /* 04a */ + { .mk = { 0x6B, 0 }, .brk = { 0xF0, 0x6B, 0 } }, /* 04b */ + { .mk = { 0x73, 0 }, .brk = { 0xF0, 0x73, 0 } }, /* 04c */ + { .mk = { 0x74, 0 }, .brk = { 0xF0, 0x74, 0 } }, /* 04d */ + { .mk = { 0x79, 0 }, .brk = { 0xF0, 0x79, 0 } }, /* 04e */ + { .mk = { 0x69, 0 }, .brk = { 0xF0, 0x69, 0 } }, /* 04f */ + { .mk = { 0x72, 0 }, .brk = { 0xF0, 0x72, 0 } }, /* 050 */ + { .mk = { 0x7A, 0 }, .brk = { 0xF0, 0x7A, 0 } }, /* 051 */ + { .mk = { 0x70, 0 }, .brk = { 0xF0, 0x70, 0 } }, /* 052 */ + { .mk = { 0x71, 0 }, .brk = { 0xF0, 0x71, 0 } }, /* 053 */ + { .mk = { 0x84, 0 }, .brk = { 0xF0, 0x84, 0 } }, /* 054 */ + { .mk = { 0x60, 0 }, .brk = { 0xF0, 0x60, 0 } }, /* 055 */ + { .mk = { 0x61, 0 }, .brk = { 0xF0, 0x61, 0 } }, /* 056 */ + { .mk = { 0x78, 0 }, .brk = { 0xF0, 0x78, 0 } }, /* 057 */ + { .mk = { 0x07, 0 }, .brk = { 0xF0, 0x07, 0 } }, /* 058 */ + { .mk = { 0x0F, 0 }, .brk = { 0xF0, 0x0F, 0 } }, /* 059 */ + { .mk = { 0x17, 0 }, .brk = { 0xF0, 0x17, 0 } }, /* 05a */ + { .mk = { 0x1F, 0 }, .brk = { 0xF0, 0x1F, 0 } }, /* 05b */ + { .mk = { 0x27, 0 }, .brk = { 0xF0, 0x27, 0 } }, /* 05c */ + { .mk = { 0x2F, 0 }, .brk = { 0xF0, 0x2F, 0 } }, /* 05d */ + { .mk = { 0x37, 0 }, .brk = { 0xF0, 0x37, 0 } }, /* 05e */ + { .mk = { 0x3F, 0 }, .brk = { 0xF0, 0x3F, 0 } }, /* 05f */ + { .mk = { 0x47, 0 }, .brk = { 0xF0, 0x47, 0 } }, /* 060 */ + { .mk = { 0x4F, 0 }, .brk = { 0xF0, 0x4F, 0 } }, /* 061 */ + { .mk = { 0x56, 0 }, .brk = { 0xF0, 0x56, 0 } }, /* 062 */ + { .mk = { 0x5E, 0 }, .brk = { 0xF0, 0x5E, 0 } }, /* 063 */ + { .mk = { 0x08, 0 }, .brk = { 0xF0, 0x08, 0 } }, /* 064 */ + { .mk = { 0x10, 0 }, .brk = { 0xF0, 0x10, 0 } }, /* 065 */ + { .mk = { 0x18, 0 }, .brk = { 0xF0, 0x18, 0 } }, /* 066 */ + { .mk = { 0x20, 0 }, .brk = { 0xF0, 0x20, 0 } }, /* 067 */ + { .mk = { 0x28, 0 }, .brk = { 0xF0, 0x28, 0 } }, /* 068 */ + { .mk = { 0x30, 0 }, .brk = { 0xF0, 0x30, 0 } }, /* 069 */ + { .mk = { 0x38, 0 }, .brk = { 0xF0, 0x38, 0 } }, /* 06a */ + { .mk = { 0x40, 0 }, .brk = { 0xF0, 0x40, 0 } }, /* 06b */ + { .mk = { 0x48, 0 }, .brk = { 0xF0, 0x48, 0 } }, /* 06c */ + { .mk = { 0x50, 0 }, .brk = { 0xF0, 0x50, 0 } }, /* 06d */ + { .mk = { 0x57, 0 }, .brk = { 0xF0, 0x57, 0 } }, /* 06e */ + { .mk = { 0x6F, 0 }, .brk = { 0xF0, 0x6F, 0 } }, /* 06f */ + { .mk = {0xe0, 0x11, 0 }, .brk = { 0xe0, 0xf0, 0x11, 0 } }, /* 070 0x36 Kana */ + { .mk = { 0x19, 0 }, .brk = { 0xF0, 0x19, 0 } }, /* 071 */ + { .mk = { 0x39, 0 }, .brk = { 0xF0, 0x39, 0 } }, /* 072 */ + { .mk = { 0x51, 0 }, .brk = { 0xF0, 0x51, 0 } }, /* 073 0x0b Ro, Underline */ + { .mk = { 0x53, 0 }, .brk = { 0xF0, 0x53, 0 } }, /* 074 */ + { .mk = { 0x5C, 0 }, .brk = { 0xF0, 0x5C, 0 } }, /* 075 */ + { .mk = { 0x5F, 0 }, .brk = { 0xF0, 0x5F, 0 } }, /* 076 */ + { .mk = { 0x62, 0 }, .brk = { 0xF0, 0x62, 0 } }, /* 077 */ + { .mk = { 0x63, 0 }, .brk = { 0xF0, 0x63, 0 } }, /* 078 */ + { .mk = { 0x64, 0 }, .brk = { 0xF0, 0x64, 0 } }, /* 079 0x35 Henkan */ + { .mk = { 0x65, 0 }, .brk = { 0xF0, 0x65, 0 } }, /* 07a */ + { .mk = { 0x67, 0 }, .brk = { 0xF0, 0x67, 0 } }, /* 07b 0x33 Muhenkan */ + { .mk = { 0x68, 0 }, .brk = { 0xF0, 0x68, 0 } }, /* 07c */ + { .mk = { 0x5d, 0 }, .brk = { 0xf0, 0x5d, 0 } }, /* 07d 0x30 Yen, Vertical line */ + { .mk = { 0x6D, 0 }, .brk = { 0xF0, 0x6D, 0 } }, /* 07e */ + { .mk = { 0x6E, 0 }, .brk = { 0xF0, 0x6E, 0 } }, /* 07f */ + { .mk = { 0x80, 0 }, .brk = { 0xf0, 0x80, 0 } }, /* 080 */ + { .mk = { 0x81, 0 }, .brk = { 0xf0, 0x81, 0 } }, /* 081 */ + { .mk = { 0x82, 0 }, .brk = { 0xf0, 0x82, 0 } }, /* 082 */ + { .mk = { 0 }, .brk = { 0 } }, /* 083 */ + { .mk = { 0 }, .brk = { 0 } }, /* 084 */ + { .mk = { 0x85, 0 }, .brk = { 0xf0, 0x54, 0 } }, /* 085 */ + { .mk = { 0x86, 0 }, .brk = { 0xf0, 0x86, 0 } }, /* 086 */ + { .mk = { 0x87, 0 }, .brk = { 0xf0, 0x87, 0 } }, /* 087 */ + { .mk = { 0x88, 0 }, .brk = { 0xf0, 0x88, 0 } }, /* 088 */ + { .mk = { 0x89, 0 }, .brk = { 0xf0, 0x89, 0 } }, /* 089 */ + { .mk = { 0x8a, 0 }, .brk = { 0xf0, 0x8a, 0 } }, /* 08a */ + { .mk = { 0x8b, 0 }, .brk = { 0xf0, 0x8b, 0 } }, /* 08b */ + { .mk = { 0x8c, 0 }, .brk = { 0xf0, 0x8c, 0 } }, /* 08c */ + { .mk = { 0x8d, 0 }, .brk = { 0xf0, 0x8d, 0 } }, /* 08d */ + { .mk = { 0x8e, 0 }, .brk = { 0xf0, 0x8e, 0 } }, /* 08e */ + { .mk = { 0x8f, 0 }, .brk = { 0xf0, 0x8f, 0 } }, /* 08f */ + { .mk = { 0x90, 0 }, .brk = { 0xf0, 0x90, 0 } }, /* 090 */ + { .mk = { 0x91, 0 }, .brk = { 0xf0, 0x91, 0 } }, /* 091 */ + { .mk = { 0x92, 0 }, .brk = { 0xf0, 0x92, 0 } }, /* 092 */ + { .mk = { 0x93, 0 }, .brk = { 0xf0, 0x93, 0 } }, /* 093 */ + { .mk = { 0x94, 0 }, .brk = { 0xf0, 0x94, 0 } }, /* 094 */ + { .mk = { 0x95, 0 }, .brk = { 0xf0, 0x95, 0 } }, /* 095 */ + { .mk = { 0x96, 0 }, .brk = { 0xf0, 0x96, 0 } }, /* 096 */ + { .mk = { 0x97, 0 }, .brk = { 0xf0, 0x97, 0 } }, /* 097 */ + { .mk = { 0x98, 0 }, .brk = { 0xf0, 0x98, 0 } }, /* 098 */ + { .mk = { 0x99, 0 }, .brk = { 0xf0, 0x99, 0 } }, /* 099 */ + { .mk = { 0x9a, 0 }, .brk = { 0xf0, 0x9a, 0 } }, /* 09a */ + { .mk = { 0x9b, 0 }, .brk = { 0xf0, 0x9b, 0 } }, /* 09b */ + { .mk = { 0x9c, 0 }, .brk = { 0xf0, 0x9c, 0 } }, /* 09c */ + { .mk = { 0x9d, 0 }, .brk = { 0xf0, 0x9d, 0 } }, /* 09d */ + { .mk = { 0x9e, 0 }, .brk = { 0xf0, 0x9e, 0 } }, /* 09e */ + { .mk = { 0x9f, 0 }, .brk = { 0xf0, 0x9f, 0 } }, /* 09f */ + { .mk = { 0xa0, 0 }, .brk = { 0xf0, 0xa0, 0 } }, /* 0a0 */ + { .mk = { 0xa1, 0 }, .brk = { 0xf0, 0xa1, 0 } }, /* 0a1 */ + { .mk = { 0xa2, 0 }, .brk = { 0xf0, 0xa2, 0 } }, /* 0a2 */ + { .mk = { 0xa3, 0 }, .brk = { 0xf0, 0xa3, 0 } }, /* 0a3 */ + { .mk = { 0xa4, 0 }, .brk = { 0xf0, 0xa4, 0 } }, /* 0a4 */ + { .mk = { 0xa5, 0 }, .brk = { 0xf0, 0xa5, 0 } }, /* 0a5 */ + { .mk = { 0xa6, 0 }, .brk = { 0xf0, 0xa6, 0 } }, /* 0a6 */ + { .mk = { 0xa7, 0 }, .brk = { 0xf0, 0xa7, 0 } }, /* 0a7 */ + { .mk = { 0xa8, 0 }, .brk = { 0xf0, 0xa8, 0 } }, /* 0a8 */ + { .mk = { 0xa9, 0 }, .brk = { 0xf0, 0xa9, 0 } }, /* 0a9 */ + { .mk = { 0xaa, 0 }, .brk = { 0xf0, 0xaa, 0 } }, /* 0aa */ + { .mk = { 0xab, 0 }, .brk = { 0xf0, 0xab, 0 } }, /* 0ab */ + { .mk = { 0xac, 0 }, .brk = { 0xf0, 0xac, 0 } }, /* 0ac */ + { .mk = { 0xad, 0 }, .brk = { 0xf0, 0xad, 0 } }, /* 0ad */ + { .mk = { 0xae, 0 }, .brk = { 0xf0, 0xae, 0 } }, /* 0ae */ + { .mk = { 0xaf, 0 }, .brk = { 0xf0, 0xaf, 0 } }, /* 0af */ + { .mk = { 0xb0, 0 }, .brk = { 0xf0, 0xb0, 0 } }, /* 0b0 */ + { .mk = { 0xb1, 0 }, .brk = { 0xf0, 0xb1, 0 } }, /* 0b1 */ + { .mk = { 0xb2, 0 }, .brk = { 0xf0, 0xb2, 0 } }, /* 0b2 */ + { .mk = { 0xb3, 0 }, .brk = { 0xf0, 0xb3, 0 } }, /* 0b3 */ + { .mk = { 0xb4, 0 }, .brk = { 0xf0, 0xb4, 0 } }, /* 0b4 */ + { .mk = { 0xb5, 0 }, .brk = { 0xf0, 0xb5, 0 } }, /* 0b5 */ + { .mk = { 0xb6, 0 }, .brk = { 0xf0, 0xb6, 0 } }, /* 0b6 */ + { .mk = { 0xb7, 0 }, .brk = { 0xf0, 0xb7, 0 } }, /* 0b7 */ + { .mk = { 0xb8, 0 }, .brk = { 0xf0, 0xb8, 0 } }, /* 0b8 */ + { .mk = { 0xb9, 0 }, .brk = { 0xf0, 0xb9, 0 } }, /* 0b9 */ + { .mk = { 0xba, 0 }, .brk = { 0xf0, 0xba, 0 } }, /* 0ba */ + { .mk = { 0xbb, 0 }, .brk = { 0xf0, 0xbb, 0 } }, /* 0bb */ + { .mk = { 0xbc, 0 }, .brk = { 0xf0, 0xbc, 0 } }, /* 0bc */ + { .mk = { 0xbd, 0 }, .brk = { 0xf0, 0xbd, 0 } }, /* 0bd */ + { .mk = { 0xbe, 0 }, .brk = { 0xf0, 0xbe, 0 } }, /* 0be */ + { .mk = { 0xbf, 0 }, .brk = { 0xf0, 0xbf, 0 } }, /* 0bf */ + { .mk = { 0xc0, 0 }, .brk = { 0xf0, 0xc0, 0 } }, /* 0c0 */ + { .mk = { 0xc1, 0 }, .brk = { 0xf0, 0xc1, 0 } }, /* 0c1 */ + { .mk = { 0xc2, 0 }, .brk = { 0xf0, 0xc2, 0 } }, /* 0c2 */ + { .mk = { 0xc3, 0 }, .brk = { 0xf0, 0xc3, 0 } }, /* 0c3 */ + { .mk = { 0xc4, 0 }, .brk = { 0xf0, 0xc4, 0 } }, /* 0c4 */ + { .mk = { 0xc5, 0 }, .brk = { 0xf0, 0xc5, 0 } }, /* 0c5 */ + { .mk = { 0xc6, 0 }, .brk = { 0xf0, 0xc6, 0 } }, /* 0c6 */ + { .mk = { 0xc7, 0 }, .brk = { 0xf0, 0xc7, 0 } }, /* 0c7 */ + { .mk = { 0xc8, 0 }, .brk = { 0xf0, 0xc8, 0 } }, /* 0c8 */ + { .mk = { 0xc9, 0 }, .brk = { 0xf0, 0xc9, 0 } }, /* 0c9 */ + { .mk = { 0xca, 0 }, .brk = { 0xf0, 0xca, 0 } }, /* 0ca */ + { .mk = { 0xcb, 0 }, .brk = { 0xf0, 0xcb, 0 } }, /* 0cb */ + { .mk = { 0xcc, 0 }, .brk = { 0xf0, 0xcc, 0 } }, /* 0cc */ + { .mk = { 0xcd, 0 }, .brk = { 0xf0, 0xcd, 0 } }, /* 0cd */ + { .mk = { 0xce, 0 }, .brk = { 0xf0, 0xce, 0 } }, /* 0ce */ + { .mk = { 0xcf, 0 }, .brk = { 0xf0, 0xcf, 0 } }, /* 0cf */ + { .mk = { 0xd0, 0 }, .brk = { 0xf0, 0xd0, 0 } }, /* 0d0 */ + { .mk = { 0xd1, 0 }, .brk = { 0xf0, 0xd0, 0 } }, /* 0d1 */ + { .mk = { 0xd2, 0 }, .brk = { 0xf0, 0xd2, 0 } }, /* 0d2 */ + { .mk = { 0xd3, 0 }, .brk = { 0xf0, 0xd3, 0 } }, /* 0d3 */ + { .mk = { 0xd4, 0 }, .brk = { 0xf0, 0xd4, 0 } }, /* 0d4 */ + { .mk = { 0xd5, 0 }, .brk = { 0xf0, 0xd5, 0 } }, /* 0d5 */ + { .mk = { 0xd6, 0 }, .brk = { 0xf0, 0xd6, 0 } }, /* 0d6 */ + { .mk = { 0xd7, 0 }, .brk = { 0xf0, 0xd7, 0 } }, /* 0d7 */ + { .mk = { 0xd8, 0 }, .brk = { 0xf0, 0xd8, 0 } }, /* 0d8 */ + { .mk = { 0xd9, 0 }, .brk = { 0xf0, 0xd9, 0 } }, /* 0d9 */ + { .mk = { 0xda, 0 }, .brk = { 0xf0, 0xda, 0 } }, /* 0da */ + { .mk = { 0xdb, 0 }, .brk = { 0xf0, 0xdb, 0 } }, /* 0db */ + { .mk = { 0xdc, 0 }, .brk = { 0xf0, 0xdc, 0 } }, /* 0dc */ + { .mk = { 0xdd, 0 }, .brk = { 0xf0, 0xdd, 0 } }, /* 0dd */ + { .mk = { 0xde, 0 }, .brk = { 0xf0, 0xde, 0 } }, /* 0de */ + { .mk = { 0xdf, 0 }, .brk = { 0xf0, 0xdf, 0 } }, /* 0df */ + { .mk = { 0xe0, 0 }, .brk = { 0xf0, 0xe0, 0 } }, /* 0e0 */ + { .mk = { 0xe1, 0 }, .brk = { 0xf0, 0xe1, 0 } }, /* 0e1 */ + { .mk = { 0xe2, 0 }, .brk = { 0xf0, 0xe2, 0 } }, /* 0e2 */ + { .mk = { 0xe3, 0 }, .brk = { 0xf0, 0xe3, 0 } }, /* 0e3 */ + { .mk = { 0xe4, 0 }, .brk = { 0xf0, 0xe4, 0 } }, /* 0e4 */ + { .mk = { 0xe5, 0 }, .brk = { 0xf0, 0xe5, 0 } }, /* 0e5 */ + { .mk = { 0xe6, 0 }, .brk = { 0xf0, 0xe6, 0 } }, /* 0e6 */ + { .mk = { 0xe7, 0 }, .brk = { 0xf0, 0xe7, 0 } }, /* 0e7 */ + { .mk = { 0xe8, 0 }, .brk = { 0xf0, 0xe8, 0 } }, /* 0e8 */ + { .mk = { 0xe9, 0 }, .brk = { 0xf0, 0xe9, 0 } }, /* 0e9 */ + { .mk = { 0xea, 0 }, .brk = { 0xf0, 0xea, 0 } }, /* 0ea */ + { .mk = { 0xeb, 0 }, .brk = { 0xf0, 0xeb, 0 } }, /* 0eb */ + { .mk = { 0xec, 0 }, .brk = { 0xf0, 0xec, 0 } }, /* 0ec */ + { .mk = { 0xed, 0 }, .brk = { 0xf0, 0xed, 0 } }, /* 0ed */ + { .mk = { 0xee, 0 }, .brk = { 0xf0, 0xee, 0 } }, /* 0ee */ + { .mk = { 0xef, 0 }, .brk = { 0xf0, 0xef, 0 } }, /* 0ef */ + { .mk = { 0 }, .brk = { 0 } }, /* 0f0 */ + { .mk = { 0xf1, 0 }, .brk = { 0xf0, 0xf1, 0 } }, /* 0f1 */ + { .mk = { 0xf2, 0 }, .brk = { 0xf0, 0xf2, 0 } }, /* 0f2 */ + { .mk = { 0xf3, 0 }, .brk = { 0xf0, 0xf3, 0 } }, /* 0f3 */ + { .mk = { 0xf4, 0 }, .brk = { 0xf0, 0xf4, 0 } }, /* 0f4 */ + { .mk = { 0xf5, 0 }, .brk = { 0xf0, 0xf5, 0 } }, /* 0f5 */ + { .mk = { 0xf6, 0 }, .brk = { 0xf0, 0xf6, 0 } }, /* 0f6 */ + { .mk = { 0xf7, 0 }, .brk = { 0xf0, 0xf7, 0 } }, /* 0f7 */ + { .mk = { 0xf8, 0 }, .brk = { 0xf0, 0xf8, 0 } }, /* 0f8 */ + { .mk = { 0xf9, 0 }, .brk = { 0xf0, 0xf9, 0 } }, /* 0f9 */ + { .mk = { 0xfa, 0 }, .brk = { 0xf0, 0xfa, 0 } }, /* 0fa */ + { .mk = { 0xfb, 0 }, .brk = { 0xf0, 0xfb, 0 } }, /* 0fb */ + { .mk = { 0xfc, 0 }, .brk = { 0xf0, 0xfc, 0 } }, /* 0fc */ + { .mk = { 0xfd, 0 }, .brk = { 0xf0, 0xfd, 0 } }, /* 0fd */ + { .mk = { 0xfe, 0 }, .brk = { 0xf0, 0xfe, 0 } }, /* 0fe */ + { .mk = { 0xff, 0 }, .brk = { 0xf0, 0xff, 0 } }, /* 0ff */ + { .mk = {0xe1, 0x14, 0 }, .brk = { 0xe1, 0xf0, 0x14, 0 } }, /* 100 */ + { .mk = {0xe0, 0x76, 0 }, .brk = { 0xe0, 0xF0, 0x76, 0 } }, /* 101 */ + { .mk = {0xe0, 0x16, 0 }, .brk = { 0xe0, 0xF0, 0x16, 0 } }, /* 102 */ + { .mk = {0xe0, 0x1E, 0 }, .brk = { 0xe0, 0xF0, 0x1E, 0 } }, /* 103 */ + { .mk = {0xe0, 0x26, 0 }, .brk = { 0xe0, 0xF0, 0x26, 0 } }, /* 104 */ + { .mk = {0xe0, 0x25, 0 }, .brk = { 0xe0, 0xF0, 0x25, 0 } }, /* 105 */ + { .mk = {0xe0, 0x2E, 0 }, .brk = { 0xe0, 0xF0, 0x2E, 0 } }, /* 106 */ + { .mk = {0xe0, 0x36, 0 }, .brk = { 0xe0, 0xF0, 0x36, 0 } }, /* 107 */ + { .mk = {0xe0, 0x3D, 0 }, .brk = { 0xe0, 0xF0, 0x3D, 0 } }, /* 108 */ + { .mk = {0xe0, 0x3E, 0 }, .brk = { 0xe0, 0xF0, 0x3E, 0 } }, /* 109 */ + { .mk = {0xe0, 0x46, 0 }, .brk = { 0xe0, 0xF0, 0x46, 0 } }, /* 10a */ + { .mk = {0xe0, 0x45, 0 }, .brk = { 0xe0, 0xF0, 0x45, 0 } }, /* 10b */ + { .mk = {0xe0, 0x4E, 0 }, .brk = { 0xe0, 0xF0, 0x4E, 0 } }, /* 10c */ + { .mk = { 0 }, .brk = { 0 } }, /* 10d */ + { .mk = {0xe0, 0x66, 0 }, .brk = { 0xe0, 0xF0, 0x66, 0 } }, /* 10e */ + { .mk = {0xe0, 0x0D, 0 }, .brk = { 0xe0, 0xF0, 0x0D, 0 } }, /* 10f */ + { .mk = {0xe0, 0x15, 0 }, .brk = { 0xe0, 0xF0, 0x15, 0 } }, /* 110 */ + { .mk = {0xe0, 0x1D, 0 }, .brk = { 0xe0, 0xF0, 0x1D, 0 } }, /* 112 */ + { .mk = {0xe0, 0x24, 0 }, .brk = { 0xe0, 0xF0, 0x24, 0 } }, /* 113 */ + { .mk = {0xe0, 0x2D, 0 }, .brk = { 0xe0, 0xF0, 0x2D, 0 } }, /* 113 */ + { .mk = {0xe0, 0x2C, 0 }, .brk = { 0xe0, 0xF0, 0x2C, 0 } }, /* 114 */ + { .mk = {0xe0, 0x35, 0 }, .brk = { 0xe0, 0xF0, 0x35, 0 } }, /* 115 */ + { .mk = {0xe0, 0x3C, 0 }, .brk = { 0xe0, 0xF0, 0x3C, 0 } }, /* 116 */ + { .mk = {0xe0, 0x43, 0 }, .brk = { 0xe0, 0xF0, 0x43, 0 } }, /* 117 */ + { .mk = {0xe0, 0x44, 0 }, .brk = { 0xe0, 0xF0, 0x44, 0 } }, /* 118 */ + { .mk = {0xe0, 0x4D, 0 }, .brk = { 0xe0, 0xF0, 0x4D, 0 } }, /* 119 */ + { .mk = {0xe0, 0x54, 0 }, .brk = { 0xe0, 0xF0, 0x54, 0 } }, /* 11a */ + { .mk = {0xe0, 0x5B, 0 }, .brk = { 0xe0, 0xF0, 0x5B, 0 } }, /* 11b */ + { .mk = {0xe0, 0x5A, 0 }, .brk = { 0xe0, 0xF0, 0x5A, 0 } }, /* 11c */ + { .mk = {0xe0, 0x14, 0 }, .brk = { 0xe0, 0xF0, 0x14, 0 } }, /* 11d */ + { .mk = {0xe0, 0x1C, 0 }, .brk = { 0xe0, 0xF0, 0x1C, 0 } }, /* 11e */ + { .mk = {0xe0, 0x1B, 0 }, .brk = { 0xe0, 0xF0, 0x1B, 0 } }, /* 11f */ + { .mk = {0xe0, 0x23, 0 }, .brk = { 0xe0, 0xF0, 0x23, 0 } }, /* 120 */ + { .mk = {0xe0, 0x2B, 0 }, .brk = { 0xe0, 0xF0, 0x2B, 0 } }, /* 121 */ + { .mk = {0xe0, 0x34, 0 }, .brk = { 0xe0, 0xF0, 0x34, 0 } }, /* 122 */ + { .mk = {0xe0, 0x33, 0 }, .brk = { 0xe0, 0xF0, 0x33, 0 } }, /* 123 */ + { .mk = {0xe0, 0x3B, 0 }, .brk = { 0xe0, 0xF0, 0x3B, 0 } }, /* 124 */ + { .mk = {0xe0, 0x42, 0 }, .brk = { 0xe0, 0xF0, 0x42, 0 } }, /* 125 */ + { .mk = {0xe0, 0x4B, 0 }, .brk = { 0xe0, 0xF0, 0x4B, 0 } }, /* 126 */ + { .mk = { 0 }, .brk = { 0 } }, /* 127 */ + { .mk = { 0 }, .brk = { 0 } }, /* 128 */ + { .mk = { 0 }, .brk = { 0 } }, /* 129 */ + { .mk = { 0 }, .brk = { 0 } }, /* 12a */ + { .mk = { 0 }, .brk = { 0 } }, /* 12b */ + { .mk = {0xe0, 0x1A, 0 }, .brk = { 0xe0, 0xF0, 0x1A, 0 } }, /* 12c */ + { .mk = {0xe0, 0x22, 0 }, .brk = { 0xe0, 0xF0, 0x22, 0 } }, /* 12d */ + { .mk = {0xe0, 0x21, 0 }, .brk = { 0xe0, 0xF0, 0x21, 0 } }, /* 12e */ + { .mk = {0xe0, 0x2A, 0 }, .brk = { 0xe0, 0xF0, 0x2A, 0 } }, /* 12f */ + { .mk = {0xe0, 0x32, 0 }, .brk = { 0xe0, 0xF0, 0x32, 0 } }, /* 130 */ + { .mk = {0xe0, 0x31, 0 }, .brk = { 0xe0, 0xF0, 0x31, 0 } }, /* 131 */ + { .mk = {0xe0, 0x3A, 0 }, .brk = { 0xe0, 0xF0, 0x3A, 0 } }, /* 132 */ + { .mk = { 0 }, .brk = { 0 } }, /* 133 */ + { .mk = {0xe0, 0x49, 0 }, .brk = { 0xe0, 0xF0, 0x49, 0 } }, /* 134 */ + { .mk = {0xe0, 0x4A, 0 }, .brk = { 0xe0, 0xF0, 0x4A, 0 } }, /* 135 */ + { .mk = { 0 }, .brk = { 0 } }, /* 136 */ + { .mk = {0xe0, 0x7C, 0 }, .brk = { 0xe0, 0xF0, 0x7C, 0 } }, /* 137 */ + { .mk = {0xe0, 0x11, 0 }, .brk = { 0xe0, 0xF0, 0x11, 0 } }, /* 138* 0x31 R-Alt */ + { .mk = { 0 }, .brk = { 0 } }, /* 139 */ + { .mk = {0xe0, 0x58, 0 }, .brk = { 0xe0, 0xF0, 0x58, 0 } }, /* 13a */ + { .mk = {0xe0, 0x05, 0 }, .brk = { 0xe0, 0xF0, 0x05, 0 } }, /* 13b */ + { .mk = {0xe0, 0x06, 0 }, .brk = { 0xe0, 0xF0, 0x06, 0 } }, /* 13c */ + { .mk = {0xe0, 0x04, 0 }, .brk = { 0xe0, 0xF0, 0x04, 0 } }, /* 13d */ + { .mk = {0xe0, 0x0C, 0 }, .brk = { 0xe0, 0xF0, 0x0C, 0 } }, /* 13e */ + { .mk = {0xe0, 0x03, 0 }, .brk = { 0xe0, 0xF0, 0x03, 0 } }, /* 13f */ + { .mk = {0xe0, 0x0B, 0 }, .brk = { 0xe0, 0xF0, 0x0B, 0 } }, /* 140 */ + { .mk = {0xe0, 0x02, 0 }, .brk = { 0xe0, 0xF0, 0x02, 0 } }, /* 141 */ + { .mk = {0xe0, 0x0A, 0 }, .brk = { 0xe0, 0xF0, 0x0A, 0 } }, /* 142 */ + { .mk = {0xe0, 0x01, 0 }, .brk = { 0xe0, 0xF0, 0x01, 0 } }, /* 143 */ + { .mk = {0xe0, 0x09, 0 }, .brk = { 0xe0, 0xF0, 0x09, 0 } }, /* 144 */ + { .mk = { 0 }, .brk = { 0 } }, /* 145 */ + { .mk = {0xe0, 0x7E, 0 }, .brk = { 0xe0, 0xF0, 0x7E, 0 } }, /* 146 */ + { .mk = {0xe0, 0x6C, 0 }, .brk = { 0xe0, 0xF0, 0x6C, 0 } }, /* 147 */ + { .mk = {0xe0, 0x75, 0 }, .brk = { 0xe0, 0xF0, 0x75, 0 } }, /* 148 */ + { .mk = {0xe0, 0x7D, 0 }, .brk = { 0xe0, 0xF0, 0x7D, 0 } }, /* 149 */ + { .mk = { 0 }, .brk = { 0 } }, /* 14a */ + { .mk = {0xe0, 0x6B, 0 }, .brk = { 0xe0, 0xF0, 0x6B, 0 } }, /* 14b */ + { .mk = {0xe0, 0x73, 0 }, .brk = { 0xe0, 0xF0, 0x73, 0 } }, /* 14c */ + { .mk = {0xe0, 0x74, 0 }, .brk = { 0xe0, 0xF0, 0x74, 0 } }, /* 14d */ + { .mk = {0xe0, 0x79, 0 }, .brk = { 0xe0, 0xF0, 0x79, 0 } }, /* 14e */ + { .mk = {0xe0, 0x69, 0 }, .brk = { 0xe0, 0xF0, 0x69, 0 } }, /* 14f */ + { .mk = {0xe0, 0x72, 0 }, .brk = { 0xe0, 0xF0, 0x72, 0 } }, /* 150 */ + { .mk = {0xe0, 0x7A, 0 }, .brk = { 0xe0, 0xF0, 0x7A, 0 } }, /* 151 */ + { .mk = {0xe0, 0x70, 0 }, .brk = { 0xe0, 0xF0, 0x70, 0 } }, /* 152 */ + { .mk = {0xe0, 0x71, 0 }, .brk = { 0xe0, 0xF0, 0x71, 0 } }, /* 153 */ + { .mk = { 0 }, .brk = { 0 } }, /* 154 */ + { .mk = {0xe0, 0x60, 0 }, .brk = { 0xe0, 0xF0, 0x60, 0 } }, /* 155 */ + { .mk = { 0 }, .brk = { 0 } }, /* 156 */ + { .mk = {0xe0, 0x78, 0 }, .brk = { 0xe0, 0xF0, 0x78, 0 } }, /* 157 */ + { .mk = {0xe0, 0x07, 0 }, .brk = { 0xe0, 0xF0, 0x07, 0 } }, /* 158 */ + { .mk = {0xe0, 0x0F, 0 }, .brk = { 0xe0, 0xF0, 0x0F, 0 } }, /* 159 */ + { .mk = {0xe0, 0x17, 0 }, .brk = { 0xe0, 0xF0, 0x17, 0 } }, /* 15a */ + { .mk = { 0x67, 0 }, .brk = { 0xf0, 0x67, 0 } }, /* 15b 0x33 LGUI->Muhenkan (in emulator only) */ + { .mk = { 0x64, 0 }, .brk = { 0xf0, 0x64, 0 } }, /* 15c 0x35 RGUI->Henkan (in emulator only) */ + { .mk = {0xe0, 0x11, 0 }, .brk = { 0xe0, 0xf0, 0x11, 0 } }, /* 15d 0x36 APPLICATION->Kana (in emulator only) */ + { .mk = {0xe0, 0x37, 0 }, .brk = { 0xe0, 0xF0, 0x37, 0 } }, /* 15e */ + { .mk = {0xe0, 0x3F, 0 }, .brk = { 0xe0, 0xF0, 0x3F, 0 } }, /* 15f */ + { .mk = { 0 }, .brk = { 0 } }, /* 160 */ + { .mk = {0xe0, 0x4F, 0 }, .brk = { 0xe0, 0xF0, 0x4F, 0 } }, /* 161 */ + { .mk = {0xe0, 0x56, 0 }, .brk = { 0xe0, 0xF0, 0x56, 0 } }, /* 162 */ + { .mk = {0xe0, 0x5E, 0 }, .brk = { 0xe0, 0xF0, 0x5E, 0 } }, /* 163 */ + { .mk = {0xe0, 0x08, 0 }, .brk = { 0xe0, 0xF0, 0x08, 0 } }, /* 164 */ + { .mk = {0xe0, 0x10, 0 }, .brk = { 0xe0, 0xF0, 0x10, 0 } }, /* 165 */ + { .mk = {0xe0, 0x18, 0 }, .brk = { 0xe0, 0xF0, 0x18, 0 } }, /* 166 */ + { .mk = {0xe0, 0x20, 0 }, .brk = { 0xe0, 0xF0, 0x20, 0 } }, /* 167 */ + { .mk = {0xe0, 0x28, 0 }, .brk = { 0xe0, 0xF0, 0x28, 0 } }, /* 168 */ + { .mk = {0xe0, 0x30, 0 }, .brk = { 0xe0, 0xF0, 0x30, 0 } }, /* 169 */ + { .mk = {0xe0, 0x38, 0 }, .brk = { 0xe0, 0xF0, 0x38, 0 } }, /* 16a */ + { .mk = {0xe0, 0x40, 0 }, .brk = { 0xe0, 0xF0, 0x40, 0 } }, /* 16b */ + { .mk = {0xe0, 0x48, 0 }, .brk = { 0xe0, 0xF0, 0x48, 0 } }, /* 16c */ + { .mk = {0xe0, 0x50, 0 }, .brk = { 0xe0, 0xF0, 0x50, 0 } }, /* 16d */ + { .mk = {0xe0, 0x57, 0 }, .brk = { 0xe0, 0xF0, 0x57, 0 } }, /* 16e */ + { .mk = { 0 }, .brk = { 0 } }, /* 16f */ + { .mk = {0xe0, 0x13, 0 }, .brk = { 0xe0, 0xF0, 0x13, 0 } }, /* 170 */ + { .mk = {0xe0, 0x19, 0 }, .brk = { 0xe0, 0xF0, 0x19, 0 } }, /* 171 */ + { .mk = {0xe0, 0x39, 0 }, .brk = { 0xe0, 0xF0, 0x39, 0 } }, /* 172 */ + { .mk = {0xe0, 0x51, 0 }, .brk = { 0xe0, 0xF0, 0x51, 0 } }, /* 173 */ + { .mk = {0xe0, 0x53, 0 }, .brk = { 0xe0, 0xF0, 0x53, 0 } }, /* 174 */ + { .mk = {0xe0, 0x5C, 0 }, .brk = { 0xe0, 0xF0, 0x5C, 0 } }, /* 175 */ + { .mk = { 0 }, .brk = { 0 } }, /* 176 */ + { .mk = {0xe0, 0x62, 0 }, .brk = { 0xe0, 0xF0, 0x62, 0 } }, /* 177 */ + { .mk = {0xe0, 0x63, 0 }, .brk = { 0xe0, 0xF0, 0x63, 0 } }, /* 178 */ + { .mk = {0xe0, 0x64, 0 }, .brk = { 0xe0, 0xF0, 0x64, 0 } }, /* 179 */ + { .mk = {0xe0, 0x65, 0 }, .brk = { 0xe0, 0xF0, 0x65, 0 } }, /* 17a */ + { .mk = {0xe0, 0x67, 0 }, .brk = { 0xe0, 0xF0, 0x67, 0 } }, /* 17b */ + { .mk = {0xe0, 0x68, 0 }, .brk = { 0xe0, 0xF0, 0x68, 0 } }, /* 17c */ + { .mk = {0xe0, 0x6A, 0 }, .brk = { 0xe0, 0xF0, 0x6A, 0 } }, /* 17d */ + { .mk = {0xe0, 0x6D, 0 }, .brk = { 0xe0, 0xF0, 0x6D, 0 } }, /* 17e */ + { .mk = {0xe0, 0x6E, 0 }, .brk = { 0xe0, 0xF0, 0x6E, 0 } }, /* 17f */ + { .mk = { 0 }, .brk = { 0 } }, /* 180 */ + { .mk = { 0 }, .brk = { 0 } }, /* 181 */ + { .mk = { 0 }, .brk = { 0 } }, /* 182 */ + { .mk = { 0 }, .brk = { 0 } }, /* 183 */ + { .mk = { 0 }, .brk = { 0 } }, /* 184 */ + { .mk = { 0 }, .brk = { 0 } }, /* 185 */ + { .mk = { 0 }, .brk = { 0 } }, /* 186 */ + { .mk = { 0 }, .brk = { 0 } }, /* 187 */ + { .mk = { 0 }, .brk = { 0 } }, /* 188 */ + { .mk = { 0 }, .brk = { 0 } }, /* 189 */ + { .mk = { 0 }, .brk = { 0 } }, /* 18a */ + { .mk = { 0 }, .brk = { 0 } }, /* 18b */ + { .mk = { 0 }, .brk = { 0 } }, /* 18c */ + { .mk = { 0 }, .brk = { 0 } }, /* 18d */ + { .mk = { 0 }, .brk = { 0 } }, /* 18e */ + { .mk = { 0 }, .brk = { 0 } }, /* 18f */ + { .mk = { 0 }, .brk = { 0 } }, /* 190 */ + { .mk = { 0 }, .brk = { 0 } }, /* 191 */ + { .mk = { 0 }, .brk = { 0 } }, /* 192 */ + { .mk = { 0 }, .brk = { 0 } }, /* 193 */ + { .mk = { 0 }, .brk = { 0 } }, /* 194 */ + { .mk = { 0 }, .brk = { 0 } }, /* 195 */ + { .mk = { 0 }, .brk = { 0 } }, /* 196 */ + { .mk = { 0 }, .brk = { 0 } }, /* 197 */ + { .mk = { 0 }, .brk = { 0 } }, /* 198 */ + { .mk = { 0 }, .brk = { 0 } }, /* 199 */ + { .mk = { 0 }, .brk = { 0 } }, /* 19a */ + { .mk = { 0 }, .brk = { 0 } }, /* 19b */ + { .mk = { 0 }, .brk = { 0 } }, /* 19c */ + { .mk = { 0 }, .brk = { 0 } }, /* 19d */ + { .mk = { 0 }, .brk = { 0 } }, /* 19e */ + { .mk = { 0 }, .brk = { 0 } }, /* 19f */ + { .mk = { 0 }, .brk = { 0 } }, /* 1a0 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1a1 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1a2 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1a3 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1a4 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1a5 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1a6 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1a7 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1a8 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1a9 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1aa */ + { .mk = { 0 }, .brk = { 0 } }, /* 1ab */ + { .mk = { 0 }, .brk = { 0 } }, /* 1ac */ + { .mk = { 0 }, .brk = { 0 } }, /* 1ad */ + { .mk = { 0 }, .brk = { 0 } }, /* 1ae */ + { .mk = { 0 }, .brk = { 0 } }, /* 1af */ + { .mk = { 0 }, .brk = { 0 } }, /* 1b0 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1b1 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1b2 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1b3 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1b4 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1b5 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1b6 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1b7 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1b8 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1b9 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1ba */ + { .mk = { 0 }, .brk = { 0 } }, /* 1bb */ + { .mk = { 0 }, .brk = { 0 } }, /* 1bc */ + { .mk = { 0 }, .brk = { 0 } }, /* 1bd */ + { .mk = { 0 }, .brk = { 0 } }, /* 1be */ + { .mk = { 0 }, .brk = { 0 } }, /* 1bf */ + { .mk = { 0 }, .brk = { 0 } }, /* 1c0 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1c1 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1c2 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1c3 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1c4 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1c5 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1c6 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1c7 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1c8 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1c9 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1ca */ + { .mk = { 0 }, .brk = { 0 } }, /* 1cb */ + { .mk = { 0 }, .brk = { 0 } }, /* 1cv */ + { .mk = { 0 }, .brk = { 0 } }, /* 1cd */ + { .mk = { 0 }, .brk = { 0 } }, /* 1ce */ + { .mk = { 0 }, .brk = { 0 } }, /* 1cf */ + { .mk = { 0 }, .brk = { 0 } }, /* 1d0 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1d1 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1d2 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1d3 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1d4 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1d5 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1d6 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1d7 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1d8 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1d9 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1da */ + { .mk = { 0 }, .brk = { 0 } }, /* 1db */ + { .mk = { 0 }, .brk = { 0 } }, /* 1dc */ + { .mk = { 0 }, .brk = { 0 } }, /* 1dd */ + { .mk = { 0 }, .brk = { 0 } }, /* 1de */ + { .mk = { 0 }, .brk = { 0 } }, /* 1df */ + { .mk = { 0 }, .brk = { 0 } }, /* 1e0 */ + { .mk = {0xe0, 0xe1, 0 }, .brk = { 0xe0, 0xF0, 0xE1, 0 } }, /* 1e1 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1e2 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1e3 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1e4 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1e5 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1e6 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1e7 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1e8 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1e9 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1ea */ + { .mk = { 0 }, .brk = { 0 } }, /* 1eb */ + { .mk = { 0 }, .brk = { 0 } }, /* 1ec */ + { .mk = { 0 }, .brk = { 0 } }, /* 1ed */ + { .mk = {0xe0, 0xee, 0 }, .brk = { 0xe0, 0xF0, 0xEE, 0 } }, /* 1ee */ + { .mk = { 0 }, .brk = { 0 } }, /* 1ef */ + { .mk = { 0 }, .brk = { 0 } }, /* 1f0 */ + { .mk = {0xe0, 0xf1, 0 }, .brk = { 0xe0, 0xF0, 0xF1, 0 } }, /* 1f1 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1f2 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1f3 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1f4 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1f5 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1f6 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1f7 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1f8 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1f9 */ + { .mk = { 0 }, .brk = { 0 } }, /* 1fa */ + { .mk = { 0 }, .brk = { 0 } }, /* 1fb */ + { .mk = { 0 }, .brk = { 0 } }, /* 1fc */ + { .mk = { 0 }, .brk = { 0 } }, /* 1fd */ + { .mk = {0xe0, 0xfe, 0 }, .brk = { 0xe0, 0xF0, 0xFE, 0 } }, /* 1fe */ + { .mk = {0xe0, 0xff, 0 }, .brk = { 0xe0, 0xF0, 0xFF, 0 } } /* 1ff */ + // clang-format on +}; +/* Scancode set 8Ah : IBM 5556 keyboard compatible scancode set used by J-DOS */ +static scancode scancode_set8a[512] = +{ + // clang-format off + {.mk = { 0 }, .brk = { 0 } }, /* 000 */ + {.mk = { 0x3d, 0 }, .brk = { 0 } }, /* 001 */ + {.mk = { 0x24, 0 }, .brk = { 0 } }, /* 002 */ + {.mk = { 0x25, 0 }, .brk = { 0 } }, /* 003 */ + {.mk = { 0x26, 0 }, .brk = { 0 } }, /* 004 */ + {.mk = { 0x27, 0 }, .brk = { 0 } }, /* 005 */ + {.mk = { 0x28, 0 }, .brk = { 0 } }, /* 006 */ + {.mk = { 0x29, 0 }, .brk = { 0 } }, /* 007 */ + {.mk = { 0x2a, 0 }, .brk = { 0 } }, /* 008 */ + {.mk = { 0x2b, 0 }, .brk = { 0 } }, /* 009 */ + {.mk = { 0x2c, 0 }, .brk = { 0 } }, /* 00a */ + {.mk = { 0x2d, 0 }, .brk = { 0 } }, /* 00b */ + {.mk = { 0x2e, 0 }, .brk = { 0 } }, /* 00c */ + {.mk = { 0x2f, 0 }, .brk = { 0 } }, /* 00d */ + {.mk = { 0x3e, 0 }, .brk = { 0 } }, /* 00e */ + {.mk = { 0x3c, 0 }, .brk = { 0 } }, /* 00f */ + {.mk = { 0x18, 0 }, .brk = { 0 } }, /* 010 */ + {.mk = { 0x19, 0 }, .brk = { 0 } }, /* 011 */ + {.mk = { 0x1a, 0 }, .brk = { 0 } }, /* 012 */ + {.mk = { 0x1b, 0 }, .brk = { 0 } }, /* 013 */ + {.mk = { 0x1c, 0 }, .brk = { 0 } }, /* 014 */ + {.mk = { 0x1d, 0 }, .brk = { 0 } }, /* 015 */ + {.mk = { 0x1e, 0 }, .brk = { 0 } }, /* 016 */ + {.mk = { 0x1f, 0 }, .brk = { 0 } }, /* 017 */ + {.mk = { 0x20, 0 }, .brk = { 0 } }, /* 018 */ + {.mk = { 0x21, 0 }, .brk = { 0 } }, /* 019 */ + {.mk = { 0x22, 0 }, .brk = { 0 } }, /* 01a */ + {.mk = { 0x23, 0 }, .brk = { 0 } }, /* 01b */ + {.mk = { 0x3b, 0 }, .brk = { 0 } }, /* 01c */ + {.mk = { 0x41, 0 }, .brk = { 0xc1, 0 } }, /* 01d LCTRL */ + {.mk = { 0x0c, 0 }, .brk = { 0 } }, /* 01e */ + {.mk = { 0x0d, 0 }, .brk = { 0 } }, /* 01f */ + {.mk = { 0x0e, 0 }, .brk = { 0 } }, /* 020 */ + {.mk = { 0x0f, 0 }, .brk = { 0 } }, /* 021 */ + {.mk = { 0x10, 0 }, .brk = { 0 } }, /* 022 */ + {.mk = { 0x11, 0 }, .brk = { 0 } }, /* 023 */ + {.mk = { 0x12, 0 }, .brk = { 0 } }, /* 024 */ + {.mk = { 0x13, 0 }, .brk = { 0 } }, /* 025 */ + {.mk = { 0x14, 0 }, .brk = { 0 } }, /* 026 */ + {.mk = { 0x15, 0 }, .brk = { 0 } }, /* 027 */ + {.mk = { 0x16, 0 }, .brk = { 0 } }, /* 028* */ + {.mk = { 0x45, 0 }, .brk = { 0 } }, /* 029 0x45 Hankaku, Zenkaku */ + {.mk = { 0x38, 0 }, .brk = { 0xb8, 0 } }, /* 02a LSHIFT */ + {.mk = { 0x17, 0 }, .brk = { 0 } }, /* 02b 0x17 Mu */ + {.mk = { 0x01, 0 }, .brk = { 0 } }, /* 02c */ + {.mk = { 0x02, 0 }, .brk = { 0 } }, /* 02d */ + {.mk = { 0x03, 0 }, .brk = { 0 } }, /* 02e */ + {.mk = { 0x04, 0 }, .brk = { 0 } }, /* 02f */ + {.mk = { 0x05, 0 }, .brk = { 0 } }, /* 030 */ + {.mk = { 0x06, 0 }, .brk = { 0 } }, /* 031 */ + {.mk = { 0x07, 0 }, .brk = { 0 } }, /* 032 */ + {.mk = { 0x08, 0 }, .brk = { 0 } }, /* 033 */ + {.mk = { 0x09, 0 }, .brk = { 0 } }, /* 034 */ + {.mk = { 0x0a, 0 }, .brk = { 0 } }, /* 035 */ + {.mk = { 0x39, 0 }, .brk = { 0xb9, 0 } }, /* 036 RSHIFT */ + {.mk = { 0x64, 0 }, .brk = { 0 } }, /* 037 * (asterisk) */ + {.mk = { 0x3A, 0 }, .brk = { 0xba, 0 } }, /* 038 0x3A LALT = Kanji */ + {.mk = { 0x34, 0 }, .brk = { 0 } }, /* 039 */ + {.mk = { 0x32, 0 }, .brk = { 0xb2, 0 } }, /* 03a CAPSLOCK */ + {.mk = { 0x68, 0 }, .brk = { 0 } }, /* 03b F1 */ + {.mk = { 0x69, 0 }, .brk = { 0 } }, /* 03c */ + {.mk = { 0x6a, 0 }, .brk = { 0 } }, /* 03d */ + {.mk = { 0x6b, 0 }, .brk = { 0 } }, /* 03e */ + {.mk = { 0x6c, 0 }, .brk = { 0 } }, /* 03f */ + {.mk = { 0x6d, 0 }, .brk = { 0 } }, /* 040 */ + {.mk = { 0x6e, 0 }, .brk = { 0 } }, /* 041 */ + {.mk = { 0x6f, 0 }, .brk = { 0 } }, /* 042 */ + {.mk = { 0x70, 0 }, .brk = { 0 } }, /* 043 */ + {.mk = { 0x71, 0 }, .brk = { 0 } }, /* 044 F10 */ + {.mk = { 0x47, 0 }, .brk = { 0 } }, /* 045 NUMLOCKCLEAR -> Shift + SCRLOCK :TODO */ + {.mk = { 0x75, 0 }, .brk = { 0 } }, /* 046 0x75 SCROLLLOCK */ + {.mk = { 0x5d, 0 }, .brk = { 0 } }, /* 047 KP7 */ + {.mk = { 0x5e, 0 }, .brk = { 0 } }, /* 048 */ + {.mk = { 0x5f, 0 }, .brk = { 0 } }, /* 049 */ + {.mk = { 0x67, 0 }, .brk = { 0 } }, /* 04a KP_MINUS */ + {.mk = { 0x5a, 0 }, .brk = { 0 } }, /* 04b */ + {.mk = { 0x5b, 0 }, .brk = { 0 } }, /* 04c */ + {.mk = { 0x5c, 0 }, .brk = { 0 } }, /* 04d */ + {.mk = { 0x63, 0 }, .brk = { 0 } }, /* 04e */ + {.mk = { 0x57, 0 }, .brk = { 0 } }, /* 04f */ + {.mk = { 0x58, 0 }, .brk = { 0 } }, /* 050 */ + {.mk = { 0x59, 0 }, .brk = { 0 } }, /* 051 */ + {.mk = { 0x55, 0 }, .brk = { 0 } }, /* 052 KP0 */ + {.mk = { 0x56, 0 }, .brk = { 0 } }, /* 053 KP_PERIOD */ + {.mk = { 0 }, .brk = { 0 } }, /* 054 */ + {.mk = { 0 }, .brk = { 0 } }, /* 055 */ + {.mk = { 0 }, .brk = { 0 } }, /* 056 */ + {.mk = { 0x72, 0 }, .brk = { 0 } }, /* 057 F11 */ + {.mk = { 0x73, 0 }, .brk = { 0 } }, /* 058 F12 */ + {.mk = { 0 }, .brk = { 0 } }, /* 059 */ + {.mk = { 0 }, .brk = { 0 } }, /* 05a */ + {.mk = { 0 }, .brk = { 0 } }, /* 05b */ + {.mk = { 0 }, .brk = { 0 } }, /* 05c */ + {.mk = { 0 }, .brk = { 0 } }, /* 05d */ + {.mk = { 0 }, .brk = { 0 } }, /* 05e */ + {.mk = { 0 }, .brk = { 0 } }, /* 05f */ + {.mk = { 0 }, .brk = { 0 } }, /* 060 */ + {.mk = { 0 }, .brk = { 0 } }, /* 061 */ + {.mk = { 0 }, .brk = { 0 } }, /* 062 */ + {.mk = { 0 }, .brk = { 0 } }, /* 063 */ + {.mk = { 0 }, .brk = { 0 } }, /* 064 */ + {.mk = { 0 }, .brk = { 0 } }, /* 065 */ + {.mk = { 0 }, .brk = { 0 } }, /* 066 */ + {.mk = { 0 }, .brk = { 0 } }, /* 067 */ + {.mk = { 0 }, .brk = { 0 } }, /* 068 */ + {.mk = { 0 }, .brk = { 0 } }, /* 069 */ + {.mk = { 0 }, .brk = { 0 } }, /* 06a */ + {.mk = { 0 }, .brk = { 0 } }, /* 06b */ + {.mk = { 0 }, .brk = { 0 } }, /* 06c */ + {.mk = { 0 }, .brk = { 0 } }, /* 06d */ + {.mk = { 0 }, .brk = { 0 } }, /* 06e */ + {.mk = { 0 }, .brk = { 0 } }, /* 06f */ + {.mk = { 0x36, 0 }, .brk = { 0xb6, 0 } }, /* 070 0x36 Kana */ + {.mk = { 0 }, .brk = { 0 } }, /* 071 */ + {.mk = { 0 }, .brk = { 0 } }, /* 072 */ + {.mk = { 0x0b, 0 }, .brk = { 0 } }, /* 073 0x0b Ro, Underline */ + {.mk = { 0 }, .brk = { 0 } }, /* 074 */ + {.mk = { 0 }, .brk = { 0 } }, /* 075 */ + {.mk = { 0 }, .brk = { 0 } }, /* 076 */ + {.mk = { 0 }, .brk = { 0 } }, /* 077 */ + {.mk = { 0 }, .brk = { 0 } }, /* 078 */ + {.mk = { 0x35, 0 }, .brk = { 0 } }, /* 079 0x35 Henkan */ + {.mk = { 0 }, .brk = { 0 } }, /* 07a */ + {.mk = { 0x33, 0 }, .brk = { 0 } }, /* 07b 0x33 Muhenkan */ + {.mk = { 0 }, .brk = { 0 } }, /* 07c */ + {.mk = { 0x30, 0 }, .brk = { 0 } }, /* 07d 0x30 Yen, Vertical line */ + {.mk = { 0 }, .brk = { 0 } }, /* 07e */ + {.mk = { 0 }, .brk = { 0 } }, /* 07f */ + {.mk = { 0 }, .brk = { 0 } }, /* 080 */ + {.mk = { 0 }, .brk = { 0 } }, /* 081 */ + {.mk = { 0 }, .brk = { 0 } }, /* 082 */ + {.mk = { 0 }, .brk = { 0 } }, /* 083 */ + {.mk = { 0 }, .brk = { 0 } }, /* 084 */ + {.mk = { 0 }, .brk = { 0 } }, /* 085 */ + {.mk = { 0 }, .brk = { 0 } }, /* 086 */ + {.mk = { 0 }, .brk = { 0 } }, /* 087 */ + {.mk = { 0 }, .brk = { 0 } }, /* 088 */ + {.mk = { 0 }, .brk = { 0 } }, /* 089 */ + {.mk = { 0 }, .brk = { 0 } }, /* 08a */ + {.mk = { 0 }, .brk = { 0 } }, /* 08b */ + {.mk = { 0 }, .brk = { 0 } }, /* 08c */ + {.mk = { 0 }, .brk = { 0 } }, /* 08d */ + {.mk = { 0 }, .brk = { 0 } }, /* 08e */ + {.mk = { 0 }, .brk = { 0 } }, /* 08f */ + {.mk = { 0 }, .brk = { 0 } }, /* 090 */ + {.mk = { 0 }, .brk = { 0 } }, /* 091 */ + {.mk = { 0 }, .brk = { 0 } }, /* 092 */ + {.mk = { 0 }, .brk = { 0 } }, /* 093 */ + {.mk = { 0 }, .brk = { 0 } }, /* 094 */ + {.mk = { 0 }, .brk = { 0 } }, /* 095 */ + {.mk = { 0 }, .brk = { 0 } }, /* 096 */ + {.mk = { 0 }, .brk = { 0 } }, /* 097 */ + {.mk = { 0 }, .brk = { 0 } }, /* 098 */ + {.mk = { 0 }, .brk = { 0 } }, /* 099 */ + {.mk = { 0 }, .brk = { 0 } }, /* 09a */ + {.mk = { 0 }, .brk = { 0 } }, /* 09b */ + {.mk = { 0 }, .brk = { 0 } }, /* 09c */ + {.mk = { 0 }, .brk = { 0 } }, /* 09d */ + {.mk = { 0 }, .brk = { 0 } }, /* 09e */ + {.mk = { 0 }, .brk = { 0 } }, /* 09f */ + {.mk = { 0 }, .brk = { 0 } }, /* 0a0 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0a1 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0a2 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0a3 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0a4 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0a5 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0a6 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0a7 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0a8 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0a9 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0aa */ + {.mk = { 0 }, .brk = { 0 } }, /* 0ab */ + {.mk = { 0 }, .brk = { 0 } }, /* 0ac */ + {.mk = { 0 }, .brk = { 0 } }, /* 0ad */ + {.mk = { 0 }, .brk = { 0 } }, /* 0ae */ + {.mk = { 0 }, .brk = { 0 } }, /* 0af */ + {.mk = { 0 }, .brk = { 0 } }, /* 0b0 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0b1 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0b2 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0b3 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0b4 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0b5 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0b6 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0b7 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0b8 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0b9 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0ba */ + {.mk = { 0 }, .brk = { 0 } }, /* 0bb */ + {.mk = { 0 }, .brk = { 0 } }, /* 0bc */ + {.mk = { 0 }, .brk = { 0 } }, /* 0bd */ + {.mk = { 0 }, .brk = { 0 } }, /* 0be */ + {.mk = { 0 }, .brk = { 0 } }, /* 0bf */ + {.mk = { 0 }, .brk = { 0 } }, /* 0c0 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0c1 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0c2 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0c3 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0c4 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0c5 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0c6 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0c7 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0c8 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0c9 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0ca */ + {.mk = { 0 }, .brk = { 0 } }, /* 0cb */ + {.mk = { 0 }, .brk = { 0 } }, /* 0cc */ + {.mk = { 0 }, .brk = { 0 } }, /* 0cd */ + {.mk = { 0 }, .brk = { 0 } }, /* 0ce */ + {.mk = { 0 }, .brk = { 0 } }, /* 0cf */ + {.mk = { 0 }, .brk = { 0 } }, /* 0d0 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0d1 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0d2 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0d3 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0d4 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0d5 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0d6 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0d7 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0d8 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0d9 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0da */ + {.mk = { 0 }, .brk = { 0 } }, /* 0db */ + {.mk = { 0 }, .brk = { 0 } }, /* 0dc */ + {.mk = { 0 }, .brk = { 0 } }, /* 0dd */ + {.mk = { 0 }, .brk = { 0 } }, /* 0de */ + {.mk = { 0 }, .brk = { 0 } }, /* 0df */ + {.mk = { 0 }, .brk = { 0 } }, /* 0e0 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0e1 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0e2 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0e3 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0e4 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0e5 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0e6 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0e7 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0e8 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0e9 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0ea */ + {.mk = { 0 }, .brk = { 0 } }, /* 0eb */ + {.mk = { 0 }, .brk = { 0 } }, /* 0ec */ + {.mk = { 0 }, .brk = { 0 } }, /* 0ed */ + {.mk = { 0 }, .brk = { 0 } }, /* 0ee */ + {.mk = { 0 }, .brk = { 0 } }, /* 0ef */ + {.mk = { 0 }, .brk = { 0 } }, /* 0f0 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0f1 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0f2 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0f3 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0f4 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0f5 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0f6 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0f7 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0f8 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0f9 */ + {.mk = { 0 }, .brk = { 0 } }, /* 0fa */ + {.mk = { 0 }, .brk = { 0 } }, /* 0fb */ + {.mk = { 0 }, .brk = { 0 } }, /* 0fc */ + {.mk = { 0 }, .brk = { 0 } }, /* 0fd */ + {.mk = { 0 }, .brk = { 0 } }, /* 0fe */ + {.mk = { 0 }, .brk = { 0 } }, /* 0ff */ + {.mk = { 0 }, .brk = { 0 } }, /* 100 */ + {.mk = { 0 }, .brk = { 0 } }, /* 101 */ + {.mk = { 0 }, .brk = { 0 } }, /* 102 */ + {.mk = { 0 }, .brk = { 0 } }, /* 103 */ + {.mk = { 0 }, .brk = { 0 } }, /* 104 */ + {.mk = { 0 }, .brk = { 0 } }, /* 105 */ + {.mk = { 0 }, .brk = { 0 } }, /* 106 */ + {.mk = { 0 }, .brk = { 0 } }, /* 107 */ + {.mk = { 0 }, .brk = { 0 } }, /* 108 */ + {.mk = { 0 }, .brk = { 0 } }, /* 109 */ + {.mk = { 0 }, .brk = { 0 } }, /* 10a */ + {.mk = { 0 }, .brk = { 0 } }, /* 10b */ + {.mk = { 0 }, .brk = { 0 } }, /* 10c */ + {.mk = { 0 }, .brk = { 0 } }, /* 10d */ + {.mk = { 0 }, .brk = { 0 } }, /* 10e */ + {.mk = { 0 }, .brk = { 0 } }, /* 10f */ + {.mk = { 0 }, .brk = { 0 } }, /* 110 */ + {.mk = { 0 }, .brk = { 0 } }, /* 112 */ + {.mk = { 0 }, .brk = { 0 } }, /* 113 */ + {.mk = { 0 }, .brk = { 0 } }, /* 113 */ + {.mk = { 0 }, .brk = { 0 } }, /* 114 */ + {.mk = { 0 }, .brk = { 0 } }, /* 115 */ + {.mk = { 0 }, .brk = { 0 } }, /* 116 */ + {.mk = { 0 }, .brk = { 0 } }, /* 117 */ + {.mk = { 0 }, .brk = { 0 } }, /* 118 */ + {.mk = { 0 }, .brk = { 0 } }, /* 119 */ + {.mk = { 0 }, .brk = { 0 } }, /* 11a */ + {.mk = { 0 }, .brk = { 0 } }, /* 11b */ + {.mk = { 0x60, 0 }, .brk = { 0 } }, /* 11c KP_Enter */ + {.mk = { 0x37, 0 }, .brk = { 0xb7, 0 } }, /* 11d R-Ctrl */ + {.mk = { 0 }, .brk = { 0 } }, /* 11e */ + {.mk = { 0 }, .brk = { 0 } }, /* 11f */ + {.mk = { 0 }, .brk = { 0 } }, /* 120 */ + {.mk = { 0 }, .brk = { 0 } }, /* 121 */ + {.mk = { 0 }, .brk = { 0 } }, /* 122 */ + {.mk = { 0 }, .brk = { 0 } }, /* 123 */ + {.mk = { 0 }, .brk = { 0 } }, /* 124 */ + {.mk = { 0 }, .brk = { 0 } }, /* 125 */ + {.mk = { 0 }, .brk = { 0 } }, /* 126 */ + {.mk = { 0 }, .brk = { 0 } }, /* 127 */ + {.mk = { 0 }, .brk = { 0 } }, /* 128 */ + {.mk = { 0 }, .brk = { 0 } }, /* 129 */ + {.mk = { 0 }, .brk = { 0 } }, /* 12a */ + {.mk = { 0 }, .brk = { 0 } }, /* 12b */ + {.mk = { 0 }, .brk = { 0 } }, /* 12c */ + {.mk = { 0 }, .brk = { 0 } }, /* 12d */ + {.mk = { 0 }, .brk = { 0 } }, /* 12e */ + {.mk = { 0 }, .brk = { 0 } }, /* 12f */ + {.mk = { 0 }, .brk = { 0 } }, /* 130 */ + {.mk = { 0 }, .brk = { 0 } }, /* 131 */ + {.mk = { 0 }, .brk = { 0 } }, /* 132 */ + {.mk = { 0 }, .brk = { 0 } }, /* 133 */ + {.mk = { 0 }, .brk = { 0 } }, /* 134 */ + {.mk = { 0x65, 0 }, .brk = { 0 } }, /* 135 KP_DIVIDE */ + {.mk = { 0 }, .brk = { 0 } }, /* 136 */ + {.mk = { 0x74, 0 }, .brk = { 0 } }, /* 137 PRINTSCREEN */ + {.mk = { 0x31, 0 }, .brk = { 0xb1, 0 } }, /* 138* 0x31 R-Alt */ + {.mk = { 0 }, .brk = { 0 } }, /* 139 */ + {.mk = { 0 }, .brk = { 0 } }, /* 13a */ + {.mk = { 0 }, .brk = { 0 } }, /* 13b */ + {.mk = { 0 }, .brk = { 0 } }, /* 13c */ + {.mk = { 0 }, .brk = { 0 } }, /* 13d */ + {.mk = { 0 }, .brk = { 0 } }, /* 13e */ + {.mk = { 0 }, .brk = { 0 } }, /* 13f */ + {.mk = { 0 }, .brk = { 0 } }, /* 140 */ + {.mk = { 0 }, .brk = { 0 } }, /* 141 */ + {.mk = { 0 }, .brk = { 0 } }, /* 142 */ + {.mk = { 0 }, .brk = { 0 } }, /* 143 */ + {.mk = { 0 }, .brk = { 0 } }, /* 144 */ + {.mk = { 0 }, .brk = { 0 } }, /* 145 */ + {.mk = { 0 }, .brk = { 0 } }, /* 146 */ + {.mk = { 0x4c, 0 }, .brk = { 0 } }, /* 147 Home */ + {.mk = { 0x4e, 0 }, .brk = { 0 } }, /* 148 Up */ + {.mk = { 0x52, 0 }, .brk = { 0 } }, /* 149 PageUp */ + {.mk = { 0 }, .brk = { 0 } }, /* 14a */ + {.mk = { 0x4b, 0 }, .brk = { 0 } }, /* 14b Left */ + {.mk = { 0 }, .brk = { 0 } }, /* 14c */ + {.mk = { 0x4d, 0 }, .brk = { 0 } }, /* 14d Right */ + {.mk = { 0 }, .brk = { 0 } }, /* 14e */ + {.mk = { 0x53, 0 }, .brk = { 0 } }, /* 14f End */ + {.mk = { 0x4a, 0 }, .brk = { 0 } }, /* 150 Down */ + {.mk = { 0x54, 0 }, .brk = { 0 } }, /* 151 PageDown */ + {.mk = { 0x4f, 0 }, .brk = { 0 } }, /* 152 Ins */ + {.mk = { 0x50, 0 }, .brk = { 0 } }, /* 153 Del */ + {.mk = { 0 }, .brk = { 0 } }, /* 154 */ + {.mk = { 0 }, .brk = { 0 } }, /* 155 */ + {.mk = { 0 }, .brk = { 0 } }, /* 156 */ + {.mk = { 0 }, .brk = { 0 } }, /* 157 */ + {.mk = { 0 }, .brk = { 0 } }, /* 158 */ + {.mk = { 0 }, .brk = { 0 } }, /* 159 */ + {.mk = { 0 }, .brk = { 0 } }, /* 15a */ + {.mk = { 0x33, 0 }, .brk = { 0 } }, /* 15b 0x33 LGUI->Muhenkan (in emulator only) */ + {.mk = { 0x35, 0 }, .brk = { 0 } }, /* 15c 0x35 RGUI->Henkan (in emulator only) */ + {.mk = { 0x36, 0 }, .brk = { 0xb6, 0 } }, /* 15d 0x36 APPLICATION->Kana (in emulator only) */ + {.mk = { 0 }, .brk = { 0 } }, /* 15e */ + {.mk = { 0 }, .brk = { 0 } }, /* 15f */ + {.mk = { 0 }, .brk = { 0 } }, /* 160 */ + {.mk = { 0 }, .brk = { 0 } }, /* 161 */ + {.mk = { 0 }, .brk = { 0 } }, /* 162 */ + {.mk = { 0 }, .brk = { 0 } }, /* 163 */ + {.mk = { 0 }, .brk = { 0 } }, /* 164 */ + {.mk = { 0 }, .brk = { 0 } }, /* 165 */ + {.mk = { 0 }, .brk = { 0 } }, /* 166 */ + {.mk = { 0 }, .brk = { 0 } }, /* 167 */ + {.mk = { 0 }, .brk = { 0 } }, /* 168 */ + {.mk = { 0 }, .brk = { 0 } }, /* 169 */ + {.mk = { 0 }, .brk = { 0 } }, /* 16a */ + {.mk = { 0 }, .brk = { 0 } }, /* 16b */ + {.mk = { 0 }, .brk = { 0 } }, /* 16c */ + {.mk = { 0 }, .brk = { 0 } }, /* 16d */ + {.mk = { 0 }, .brk = { 0 } }, /* 16e */ + {.mk = { 0 }, .brk = { 0 } }, /* 16f */ + {.mk = { 0 }, .brk = { 0 } }, /* 170 */ + {.mk = { 0 }, .brk = { 0 } }, /* 171 */ + {.mk = { 0 }, .brk = { 0 } }, /* 172 */ + {.mk = { 0 }, .brk = { 0 } }, /* 173 */ + {.mk = { 0 }, .brk = { 0 } }, /* 174 */ + {.mk = { 0 }, .brk = { 0 } }, /* 175 */ + {.mk = { 0 }, .brk = { 0 } }, /* 176 */ + {.mk = { 0 }, .brk = { 0 } }, /* 177 */ + {.mk = { 0 }, .brk = { 0 } }, /* 178 */ + {.mk = { 0 }, .brk = { 0 } }, /* 179 */ + {.mk = { 0 }, .brk = { 0 } }, /* 17a */ + {.mk = { 0 }, .brk = { 0 } }, /* 17b */ + {.mk = { 0 }, .brk = { 0 } }, /* 17c */ + {.mk = { 0 }, .brk = { 0 } }, /* 17d */ + {.mk = { 0 }, .brk = { 0 } }, /* 17e */ + {.mk = { 0 }, .brk = { 0 } }, /* 17f */ + {.mk = { 0 }, .brk = { 0 } }, /* 180 */ + {.mk = { 0 }, .brk = { 0 } }, /* 181 */ + {.mk = { 0 }, .brk = { 0 } }, /* 182 */ + {.mk = { 0 }, .brk = { 0 } }, /* 183 */ + {.mk = { 0 }, .brk = { 0 } }, /* 184 */ + {.mk = { 0 }, .brk = { 0 } }, /* 185 */ + {.mk = { 0 }, .brk = { 0 } }, /* 186 */ + {.mk = { 0 }, .brk = { 0 } }, /* 187 */ + {.mk = { 0 }, .brk = { 0 } }, /* 188 */ + {.mk = { 0 }, .brk = { 0 } }, /* 189 */ + {.mk = { 0 }, .brk = { 0 } }, /* 18a */ + {.mk = { 0 }, .brk = { 0 } }, /* 18b */ + {.mk = { 0 }, .brk = { 0 } }, /* 18c */ + {.mk = { 0 }, .brk = { 0 } }, /* 18d */ + {.mk = { 0 }, .brk = { 0 } }, /* 18e */ + {.mk = { 0 }, .brk = { 0 } }, /* 18f */ + {.mk = { 0 }, .brk = { 0 } }, /* 190 */ + {.mk = { 0 }, .brk = { 0 } }, /* 191 */ + {.mk = { 0 }, .brk = { 0 } }, /* 192 */ + {.mk = { 0 }, .brk = { 0 } }, /* 193 */ + {.mk = { 0 }, .brk = { 0 } }, /* 194 */ + {.mk = { 0 }, .brk = { 0 } }, /* 195 */ + {.mk = { 0 }, .brk = { 0 } }, /* 196 */ + {.mk = { 0 }, .brk = { 0 } }, /* 197 */ + {.mk = { 0 }, .brk = { 0 } }, /* 198 */ + {.mk = { 0 }, .brk = { 0 } }, /* 199 */ + {.mk = { 0 }, .brk = { 0 } }, /* 19a */ + {.mk = { 0 }, .brk = { 0 } }, /* 19b */ + {.mk = { 0 }, .brk = { 0 } }, /* 19c */ + {.mk = { 0 }, .brk = { 0 } }, /* 19d */ + {.mk = { 0 }, .brk = { 0 } }, /* 19e */ + {.mk = { 0 }, .brk = { 0 } }, /* 19f */ + {.mk = { 0 }, .brk = { 0 } }, /* 1a0 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1a1 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1a2 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1a3 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1a4 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1a5 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1a6 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1a7 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1a8 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1a9 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1aa */ + {.mk = { 0 }, .brk = { 0 } }, /* 1ab */ + {.mk = { 0 }, .brk = { 0 } }, /* 1ac */ + {.mk = { 0 }, .brk = { 0 } }, /* 1ad */ + {.mk = { 0 }, .brk = { 0 } }, /* 1ae */ + {.mk = { 0 }, .brk = { 0 } }, /* 1af */ + {.mk = { 0 }, .brk = { 0 } }, /* 1b0 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1b1 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1b2 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1b3 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1b4 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1b5 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1b6 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1b7 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1b8 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1b9 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1ba */ + {.mk = { 0 }, .brk = { 0 } }, /* 1bb */ + {.mk = { 0 }, .brk = { 0 } }, /* 1bc */ + {.mk = { 0 }, .brk = { 0 } }, /* 1bd */ + {.mk = { 0 }, .brk = { 0 } }, /* 1be */ + {.mk = { 0 }, .brk = { 0 } }, /* 1bf */ + {.mk = { 0 }, .brk = { 0 } }, /* 1c0 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1c1 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1c2 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1c3 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1c4 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1c5 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1c6 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1c7 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1c8 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1c9 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1ca */ + {.mk = { 0 }, .brk = { 0 } }, /* 1cb */ + {.mk = { 0 }, .brk = { 0 } }, /* 1cv */ + {.mk = { 0 }, .brk = { 0 } }, /* 1cd */ + {.mk = { 0 }, .brk = { 0 } }, /* 1ce */ + {.mk = { 0 }, .brk = { 0 } }, /* 1cf */ + {.mk = { 0 }, .brk = { 0 } }, /* 1d0 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1d1 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1d2 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1d3 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1d4 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1d5 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1d6 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1d7 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1d8 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1d9 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1da */ + {.mk = { 0 }, .brk = { 0 } }, /* 1db */ + {.mk = { 0 }, .brk = { 0 } }, /* 1dc */ + {.mk = { 0 }, .brk = { 0 } }, /* 1dd */ + {.mk = { 0 }, .brk = { 0 } }, /* 1de */ + {.mk = { 0 }, .brk = { 0 } }, /* 1df */ + {.mk = { 0 }, .brk = { 0 } }, /* 1e0 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1e1 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1e2 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1e3 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1e4 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1e5 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1e6 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1e7 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1e8 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1e9 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1ea */ + {.mk = { 0 }, .brk = { 0 } }, /* 1eb */ + {.mk = { 0 }, .brk = { 0 } }, /* 1ec */ + {.mk = { 0 }, .brk = { 0 } }, /* 1ed */ + {.mk = { 0 }, .brk = { 0 } }, /* 1ee */ + {.mk = { 0 }, .brk = { 0 } }, /* 1ef */ + {.mk = { 0 }, .brk = { 0 } }, /* 1f0 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1f1 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1f2 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1f3 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1f4 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1f5 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1f6 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1f7 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1f8 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1f9 */ + {.mk = { 0 }, .brk = { 0 } }, /* 1fa */ + {.mk = { 0 }, .brk = { 0 } }, /* 1fb */ + {.mk = { 0 }, .brk = { 0 } }, /* 1fc */ + {.mk = { 0 }, .brk = { 0 } }, /* 1fd */ + {.mk = { 0 }, .brk = { 0 } }, /* 1fe */ + {.mk = { 0 }, .brk = { 0 } } /* 1ff */ + // clang-format on +}; + #ifdef ENABLE_KEYBOARD_AT_LOG int keyboard_at_do_log = ENABLE_KEYBOARD_AT_LOG; @@ -1664,6 +3244,18 @@ keyboard_at_set_scancode_set(void) case 0x03: keyboard_set_table(scancode_set3); break; + + case 0x81: + keyboard_set_table(scancode_set81); + break; + + case 0x82: + keyboard_set_table(scancode_set82); + break; + + case 0x8a: + keyboard_set_table(scancode_set8a); + break; } } @@ -1684,7 +3276,7 @@ add_data_kbd(uint16_t val) dev->ignore = 1; - keyboard_get_states(NULL, &num_lock, NULL); + keyboard_get_states(NULL, &num_lock, NULL, NULL); shift_states = keyboard_get_shift() & STATE_SHIFT_MASK; switch (val) { @@ -1884,6 +3476,10 @@ keyboard_at_bat(void *priv) keyboard_scan = 1; + keyboard_all_up(); + keyboard_update_states(0, 0, 0, 0); + + keyboard_set_in_reset(0); kbc_at_dev_queue_add(dev, 0xaa, 0); } else { bat_counter--; @@ -1898,7 +3494,6 @@ keyboard_at_invalid_cmd(atkbc_dev_t *dev) kbc_at_dev_queue_add(dev, inv_cmd_response, 0); } - static void keyboard_at_write(void *priv) { @@ -1918,23 +3513,29 @@ keyboard_at_write(void *priv) switch (dev->command) { case 0xed: /* Set/reset LEDs */ kbc_at_dev_queue_add(dev, 0xfa, 0); + keyboard_update_states(!!(val & 0x4), !!(val & 0x2), val & 0x1, !!(val & 0x8)); 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: + kbc_at_dev_queue_add(dev, 0xfa, 0); /* ACK */ 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: + case 0x81: + case 0x82: + case 0x8a: + kbc_at_dev_queue_add(dev, 0xfa, 0); /* ACK */ 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. */ + kbc_at_dev_queue_add(dev, 0xfe, 0); /* Resend */ fatal("%s: Scan code set [%02X] invalid, resend\n", dev->name, val); dev->flags |= FLAG_CTRLDAT; dev->state = DEV_STATE_MAIN_WANT_IN; @@ -1961,18 +3562,24 @@ keyboard_at_write(void *priv) } } else { if (dev->flags & FLAG_CTRLDAT) { - /* Special case - another command during another command that wants input - proceed + /* + 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; + command in progress is ED (Set/reset LEDs). + + It appears to also apply to command EE (Echo), F4 (Enable), F5 (Diable and Set + Default), and F6 (SetDefault). + */ + if ((val == 0xed) || (val == 0xee) || (val == 0xf4) || (val == 0xf5) || (val == 0xf6)) dev->flags &= ~FLAG_CTRLDAT; - } else + else dev->state = DEV_STATE_MAIN_WANT_IN; } switch (val) { case 0xed: /* set/reset LEDs */ + if ((dev->flags & FLAG_CTRLDAT) && (dev->command == 0xed)) + keyboard_scan = 1; dev->command = val; keyboard_at_log("%s: set/reset LEDs\n", dev->name); dev->flags |= FLAG_CTRLDAT; @@ -2003,7 +3610,7 @@ keyboard_at_write(void *priv) break; case 0xf2: /* read ID */ - keyboard_at_log("%s: read keyboard id\n", dev->name); + keyboard_at_log("%s: read keyboard id: ", 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); @@ -2012,7 +3619,9 @@ keyboard_at_write(void *priv) break; kbc_at_dev_queue_add(dev, id_bytes[dev->type][i], 0); + keyboard_at_log("%02X ", id_bytes[dev->type][i]); } + keyboard_at_log("\n"); break; case 0xf3: /* set command mode */ @@ -2033,6 +3642,13 @@ keyboard_at_write(void *priv) case 0xf6: /* set defaults */ keyboard_at_log("%s: set defaults%s\n", dev->name, (val == 0xf6) ? "" : " and disable keyboard"); + dev->port->out_new = -1; + dev->port->wantcmd = 0; + + kbc_at_dev_queue_reset(dev, 1); + + dev->last_scan_code = 0x00; + keyboard_scan = !(val & 0x01); keyboard_at_log("%s: val = %02X, keyboard_scan = %i\n", dev->name, val, keyboard_scan); @@ -2102,11 +3718,11 @@ keyboard_at_write(void *priv) /* 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, 0xfa, 0); kbc_at_dev_queue_add(dev, dev->last_scan_code, 0); break; case 0xff: /* reset */ + keyboard_set_in_reset(1); kbc_at_dev_reset(dev, 1); bat_counter = 1000; break; @@ -2117,6 +3733,44 @@ keyboard_at_write(void *priv) } } +#ifdef SCAN_CODE_TABLES_COMPARISON +/* Non-translated to translated scan codes. */ +static const uint8_t nont_to_t[256] = { + 0x00, 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 +}; +#endif + /* * Initialize the device for use by the user. * @@ -2138,6 +3792,13 @@ keyboard_at_init(const device_t *info) 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") */; + /* + We assume that the IBM PS/55 machine uses the 5576-002 keyboard (JP/CN layout) here. + This is not smart but suitable for supporting a keyboard ID that is rarely used in standard PCs. + At least, the Taiwanese PS/55 uses the same keyboard ID and scancode set. The Korean one is unknown. + */ + if (!!strstr(machine_getname(), "PS/55")) + dev->type = FLAG_PS2 | KBD_JIS; keyboard_at_log("%s: type=%d\n", dev->name, dev->type); @@ -2155,9 +3816,142 @@ keyboard_at_init(const device_t *info) keyboard_send = add_data_kbd; SavedKbd = dev; + keyboard_update_states(0, 0, 0, 0); inv_cmd_response = (dev->type & FLAG_PS2) ? 0xfe : 0xfa; +#ifdef SCAN_CODE_TABLES_COMPARISON + pclog_toggle_suppr(); + + pclog("Scan code set 01 vs. 81 (make):\n===============================\n"); + for (int i = 0; i < 512; i++) { + pclog("Scan code %03X:", i); + int j = 0; + do { + if (scancode_set1[i].mk[j] == scancode_set81[i].mk[j]) + pclog(" --"); + else + pclog(" (%02X != %02X)", scancode_set1[i].mk[j], scancode_set81[i].mk[j]); + j++; + } while ((scancode_set1[i].mk[j] != 0) && (scancode_set81[i].mk[j] != 0)); + pclog("\n"); + } + + pclog("\nScan code set 01 vs. 81 (break):\n================================\n"); + for (int i = 0; i < 512; i++) { + pclog("Scan code %03X:", i); + int j = 0; + do { + if (scancode_set1[i].brk[j] == scancode_set81[i].brk[j]) + pclog(" --"); + else + pclog(" (%02X != %02X)", scancode_set1[i].brk[j], scancode_set81[i].brk[j]); + j++; + } while ((scancode_set1[i].brk[j] != 0) && (scancode_set81[i].brk[j] != 0)); + pclog("\n"); + } + + pclog("\nScan code set 02 vs. 82 (make):\n===============================\n"); + for (int i = 0; i < 512; i++) { + pclog("Scan code %03X:", i); + int j = 0; + do { + if (scancode_set2[i].mk[j] == scancode_set82[i].mk[j]) + pclog(" --"); + else + pclog(" (%02X != %02X)", scancode_set2[i].mk[j], scancode_set82[i].mk[j]); + j++; + } while ((scancode_set2[i].mk[j] != 0) && (scancode_set82[i].mk[j] != 0)); + pclog("\n"); + } + + pclog("\nScan code set 02 vs. 82 (break):\n================================\n"); + for (int i = 0; i < 512; i++) { + pclog("Scan code %03X:", i); + int j = 0; + do { + if (scancode_set2[i].brk[j] == scancode_set82[i].brk[j]) + pclog(" --"); + else + pclog(" (%02X != %02X)", scancode_set2[i].brk[j], scancode_set82[i].brk[j]); + j++; + } while ((scancode_set2[i].brk[j] != 0) && (scancode_set82[i].brk[j] != 0)); + pclog("\n"); + } + + pclog("\nScan code set 01 vs. 02 (make):\n===============================\n"); + for (int i = 0; i < 512; i++) { + pclog("Scan code %03X:", i); + int j = 0; + int k = 0; + int was_f0 = 0; + do { + if (scancode_set2[i].mk[k] == 0xf0) + was_f0 = 1; + else { + uint8_t code = nont_to_t[scancode_set2[i].mk[k]]; + + if (was_f0) { + if (code & 0x80) + code = 0x00; + else + code |= 0x80; + + was_f0 = 0; + } + + if (scancode_set1[i].mk[j] == code) + pclog(" --"); + else + pclog(" (%02X != %02X)", scancode_set1[i].mk[j], code); + + j++; + } + + k++; + } while ((scancode_set1[i].mk[j] != 0) && (scancode_set2[i].mk[k] != 0)); + pclog("\n"); + } + + pclog("\nScan code set 01 vs. 02 (break):\n================================\n"); + for (int i = 0; i < 512; i++) { + pclog("Scan code %03X:", i); + int j = 0; + int k = 0; + int was_f0 = 0; + do { + if (scancode_set2[i].brk[k] == 0xf0) + was_f0 = 1; + else { + uint8_t code = nont_to_t[scancode_set2[i].brk[k]]; + + if (was_f0) { + if (code & 0x80) + code = 0x00; + else + code |= 0x80; + + was_f0 = 0; + } + + if (scancode_set1[i].brk[j] == code) + pclog(" --"); + else + pclog(" (%02X != %02X)", scancode_set1[i].brk[j], code); + + j++; + } + + k++; + } while ((scancode_set1[i].brk[j] != 0) && (scancode_set2[i].brk[k] != 0)); + pclog("\n"); + } + + pclog_toggle_suppr(); + + fatal("Comparison finished\n"); +#endif + /* Return our private data to the I/O layer. */ return dev; } @@ -2173,6 +3967,8 @@ keyboard_at_close(void *priv) /* Disable the scancode maps. */ keyboard_set_table(NULL); + keyboard_update_states(0, 0, 0, 0); + SavedKbd = NULL; free(dev); @@ -2181,14 +3977,14 @@ keyboard_at_close(void *priv) static const device_config_t keyboard_at_config[] = { // clang-format off { - .name = "type", - .description = "Type", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 1, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "type", + .description = "Type", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .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 }, @@ -2197,7 +3993,8 @@ static const device_config_t keyboard_at_config[] = { { .description = "PS/2 106-key JIS", .value = FLAG_PS2 | KBD_JIS }, { .description = "PS/2 Korean", .value = FLAG_PS2 | KBD_KOREAN }, { .description = "" } - } + }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END @@ -2209,12 +4006,12 @@ static const device_config_t keyboard_at_config[] = { const device_t keyboard_at_generic_device = { .name = "Standard AT or PS/2 Keyboard", .internal_name = "ps2", - .flags = DEVICE_PS2, + .flags = DEVICE_PS2_KBC, .local = 0, .init = keyboard_at_init, .close = keyboard_at_close, .reset = NULL, - { .poll = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = keyboard_at_config diff --git a/src/device/keyboard_xt.c b/src/device/keyboard_xt.c index b90f4a77a..5190de839 100644 --- a/src/device/keyboard_xt.c +++ b/src/device/keyboard_xt.c @@ -29,6 +29,7 @@ #include #include <86box/86box.h> #include <86box/device.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/fdd.h> #include <86box/machine.h> @@ -68,6 +69,7 @@ enum { KBD_TYPE_ZENITH, KBD_TYPE_PRAVETZ, KBD_TYPE_HYUNDAI, + KBD_TYPE_FE2010, KBD_TYPE_XTCLONE }; @@ -79,10 +81,12 @@ typedef struct xtkbd_t { uint8_t pa; uint8_t pb; uint8_t pd; + uint8_t cfg; uint8_t clock; uint8_t key_waiting; uint8_t type; uint8_t pravetz_flags; + uint8_t cpu_speed; pc_timer_t send_delay_timer; } xtkbd_t; @@ -740,7 +744,7 @@ kbd_adddata_process(uint16_t val, void (*adddata)(uint16_t val)) if (!adddata) return; - keyboard_get_states(NULL, &num_lock, NULL); + keyboard_get_states(NULL, &num_lock, NULL, NULL); shift_states = keyboard_get_shift() & STATE_LSHIFT; if (is_amstrad) @@ -798,6 +802,7 @@ kbd_write(uint16_t port, uint8_t val, void *priv) kbd_adddata(0xaa); } } + kbd->pb = val; if (!(kbd->pb & 0x80) || (kbd->type == KBD_TYPE_HYUNDAI)) kbd->clock = !!(kbd->pb & 0x40); @@ -829,12 +834,26 @@ kbd_write(uint16_t port, uint8_t val, void *priv) kbd_log("XTkbd: Cassette motor is %s\n", !(val & 0x08) ? "ON" : "OFF"); #endif break; -#ifdef ENABLE_KEYBOARD_XT_LOG + case 0x62: /* Switch Register (aka Port C) */ +#ifdef ENABLE_KEYBOARD_XT_LOG if ((kbd->type == KBD_TYPE_PC81) || (kbd->type == KBD_TYPE_PC82) || (kbd->type == KBD_TYPE_PRAVETZ)) kbd_log("XTkbd: Cassette IN is %i\n", !!(val & 0x10)); - break; #endif + if (kbd->type == KBD_TYPE_FE2010) { + kbd_log("XTkbd: Switch register in is %02X\n", val); + if (!(kbd->cfg & 0x08)) + kbd->pd = (kbd->pd & 0x30) | (val & 0xcf); + } + break; + + case 0x63: + if (kbd->type == KBD_TYPE_FE2010) { + kbd_log("XTkbd: Configuration register in is %02X\n", val); + if (!(kbd->cfg & 0x08)) + kbd->cfg = val; + } + break; case 0xc0 ... 0xcf: /* Pravetz Flags */ kbd_log("XTkbd: Port %02X out: %02X\n", port, val); @@ -845,6 +864,14 @@ kbd_write(uint16_t port, uint8_t val, void *priv) } break; + case 0x1f0: + kbd_log("XTkbd: Port %04X out: %02X\n", port, val); + if (kbd->type == KBD_TYPE_VTECH) { + kbd->cpu_speed = val; + cpu_dynamic_switch(kbd->cpu_speed >> 7); + } + break; + default: break; } @@ -862,12 +889,14 @@ kbd_read(uint16_t port, void *priv) (kbd->type == KBD_TYPE_PC82) || (kbd->type == KBD_TYPE_PRAVETZ) || (kbd->type == KBD_TYPE_XT82) || (kbd->type == KBD_TYPE_XT86) || (kbd->type == KBD_TYPE_XTCLONE) || (kbd->type == KBD_TYPE_COMPAQ) || - (kbd->type == KBD_TYPE_ZENITH) || (kbd->type == KBD_TYPE_HYUNDAI))) { + (kbd->type == KBD_TYPE_ZENITH) || (kbd->type == KBD_TYPE_HYUNDAI) || + (kbd->type == KBD_TYPE_VTECH))) { if ((kbd->type == KBD_TYPE_PC81) || (kbd->type == KBD_TYPE_PC82) || (kbd->type == KBD_TYPE_XTCLONE) || (kbd->type == KBD_TYPE_COMPAQ) || (kbd->type == KBD_TYPE_PRAVETZ) || (kbd->type == KBD_TYPE_HYUNDAI)) ret = (kbd->pd & ~0x02) | (hasfpu ? 0x02 : 0x00); - else if ((kbd->type == KBD_TYPE_XT82) || (kbd->type == KBD_TYPE_XT86)) + else if ((kbd->type == KBD_TYPE_XT82) || (kbd->type == KBD_TYPE_XT86) || + (kbd->type == KBD_TYPE_VTECH)) /* According to Ruud on the PCem forum, this is supposed to return 0xFF on the XT. */ ret = 0xff; @@ -899,7 +928,12 @@ kbd_read(uint16_t port, void *priv) break; case 0x62: /* Switch Register (aka Port C) */ - if ((kbd->type == KBD_TYPE_PC81) || (kbd->type == KBD_TYPE_PC82) || + if (kbd->type == KBD_TYPE_FE2010) { + if (kbd->pb & 0x04) /* PB2 */ + ret = (kbd->pd & 0x0d) | (hasfpu ? 0x02 : 0x00); + else + ret = kbd->pd >> 4; + } else if ((kbd->type == KBD_TYPE_PC81) || (kbd->type == KBD_TYPE_PC82) || (kbd->type == KBD_TYPE_PRAVETZ)) { if (kbd->pb & 0x04) /* PB2 */ switch (mem_size + isa_mem_size) { @@ -925,16 +959,8 @@ kbd_read(uint16_t port, void *priv) } else { if (kbd->pb & 0x08) /* PB3 */ ret = kbd->pd >> 4; - else { - /* LaserXT = Always 512k RAM; - LaserXT/3 = Bit 0: set = 512k, clear = 256k. */ -#ifdef USE_LASERXT - if (kbd->type == KBD_TYPE_VTECH) - ret = ((mem_size == 512) ? 0x0d : 0x0c) | (hasfpu ? 0x02 : 0x00); - else -#endif /* USE_LASERXT */ - ret = (kbd->pd & 0x0d) | (hasfpu ? 0x02 : 0x00); - } + else + ret = (kbd->pd & 0x0d) | (hasfpu ? 0x02 : 0x00); } ret |= (ppispeakon ? 0x20 : 0); @@ -955,7 +981,8 @@ kbd_read(uint16_t port, void *priv) case 0x63: /* Keyboard Configuration Register (aka Port D) */ if ((kbd->type == KBD_TYPE_XT82) || (kbd->type == KBD_TYPE_XT86) || (kbd->type == KBD_TYPE_XTCLONE) || (kbd->type == KBD_TYPE_COMPAQ) || - (kbd->type == KBD_TYPE_TOSHIBA) || (kbd->type == KBD_TYPE_HYUNDAI)) + (kbd->type == KBD_TYPE_TOSHIBA) || (kbd->type == KBD_TYPE_HYUNDAI) || + (kbd->type == KBD_TYPE_VTECH)) ret = kbd->pd; break; @@ -965,6 +992,12 @@ kbd_read(uint16_t port, void *priv) kbd_log("XTkbd: Port %02X in : %02X\n", port, ret); break; + case 0x1f0: + if (kbd->type == KBD_TYPE_VTECH) + ret = kbd->cpu_speed; + kbd_log("XTkbd: Port %04X in : %02X\n", port, ret); + break; + default: break; } @@ -983,7 +1016,7 @@ kbd_reset(void *priv) kbd->pb = 0x00; kbd->pravetz_flags = 0x00; - keyboard_scan = 1; + keyboard_scan = 1; key_queue_start = 0; key_queue_end = 0; @@ -1000,18 +1033,21 @@ kbd_init(const device_t *info) { xtkbd_t *kbd; - kbd = (xtkbd_t *) malloc(sizeof(xtkbd_t)); - memset(kbd, 0x00, sizeof(xtkbd_t)); + kbd = (xtkbd_t *) calloc(1, sizeof(xtkbd_t)); io_sethandler(0x0060, 4, kbd_read, NULL, NULL, kbd_write, NULL, NULL, kbd); keyboard_send = kbd_adddata_ex; - kbd_reset(kbd); kbd->type = info->local; - if (kbd->type == KBD_TYPE_PRAVETZ) { + if (kbd->type == KBD_TYPE_VTECH) + kbd->cpu_speed = (!!cpu) << 2; + kbd_reset(kbd); + if (kbd->type == KBD_TYPE_PRAVETZ) io_sethandler(0x00c0, 16, kbd_read, NULL, NULL, kbd_write, NULL, NULL, kbd); - } + if (kbd->type == KBD_TYPE_VTECH) + io_sethandler(0x01f0, 1, + kbd_read, NULL, NULL, kbd_write, NULL, NULL, kbd); key_queue_start = key_queue_end = 0; @@ -1021,7 +1057,8 @@ kbd_init(const device_t *info) (kbd->type == KBD_TYPE_PRAVETZ) || (kbd->type == KBD_TYPE_XT82) || (kbd->type <= KBD_TYPE_XT86) || (kbd->type == KBD_TYPE_XTCLONE) || (kbd->type == KBD_TYPE_COMPAQ) || (kbd->type == KBD_TYPE_TOSHIBA) || - (kbd->type == KBD_TYPE_OLIVETTI) || (kbd->type == KBD_TYPE_HYUNDAI)) { + (kbd->type == KBD_TYPE_OLIVETTI) || (kbd->type == KBD_TYPE_HYUNDAI) || + (kbd->type == KBD_TYPE_VTECH) || (kbd->type == KBD_TYPE_FE2010)) { /* DIP switch readout: bit set = OFF, clear = ON. */ if (kbd->type == KBD_TYPE_OLIVETTI) /* Olivetti M19 @@ -1035,13 +1072,13 @@ kbd_init(const device_t *info) /* Switches 7, 8 - floppy drives. */ kbd->pd = get_fdd_switch_settings(); - /* Siitches 5, 6 - video card type */ + /* Switches 5, 6 - video card type */ kbd->pd |= get_videomode_switch_settings(); /* Switches 3, 4 - memory size. */ if ((kbd->type == KBD_TYPE_XT86) || (kbd->type == KBD_TYPE_XTCLONE) || (kbd->type == KBD_TYPE_HYUNDAI) || (kbd->type == KBD_TYPE_COMPAQ) || - (kbd->type == KBD_TYPE_TOSHIBA)) { + (kbd->type == KBD_TYPE_TOSHIBA) || (kbd->type == KBD_TYPE_FE2010)) { switch (mem_size) { case 256: kbd->pd |= 0x00; @@ -1057,7 +1094,7 @@ kbd_init(const device_t *info) kbd->pd |= 0x0c; break; } - } else if (kbd->type == KBD_TYPE_XT82) { + } else if ((kbd->type == KBD_TYPE_XT82) || (kbd->type == KBD_TYPE_VTECH)) { switch (mem_size) { case 64: /* 1x64k */ kbd->pd |= 0x00; @@ -1075,9 +1112,13 @@ kbd_init(const device_t *info) } } else if (kbd->type == KBD_TYPE_PC82) { switch (mem_size) { +#ifdef PC82_192K_3BANK case 192: /* 3x64k, not supported by stock BIOS due to bugs */ kbd->pd |= 0x08; break; +#else + case 192: /* 2x64k + 2x32k */ +#endif case 64: /* 4x16k */ case 96: /* 2x32k + 2x16k */ case 128: /* 4x32k */ @@ -1188,7 +1229,7 @@ const device_t keyboard_pc_device = { .init = kbd_init, .close = kbd_close, .reset = kbd_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1202,7 +1243,7 @@ const device_t keyboard_pc82_device = { .init = kbd_init, .close = kbd_close, .reset = kbd_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1216,7 +1257,7 @@ const device_t keyboard_pravetz_device = { .init = kbd_init, .close = kbd_close, .reset = kbd_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1230,7 +1271,7 @@ const device_t keyboard_xt_device = { .init = kbd_init, .close = kbd_close, .reset = kbd_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1244,7 +1285,7 @@ const device_t keyboard_xt86_device = { .init = kbd_init, .close = kbd_close, .reset = kbd_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1258,7 +1299,7 @@ const device_t keyboard_xt_compaq_device = { .init = kbd_init, .close = kbd_close, .reset = kbd_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1272,7 +1313,7 @@ const device_t keyboard_tandy_device = { .init = kbd_init, .close = kbd_close, .reset = kbd_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1286,27 +1327,25 @@ const device_t keyboard_xt_t1x00_device = { .init = kbd_init, .close = kbd_close, .reset = kbd_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL }; -#ifdef USE_LASERXT const device_t keyboard_xt_lxt3_device = { - .name = "VTech Laser XT3 Keyboard", - .internal_name = "keyboard_xt_lxt3", + .name = "VTech Laser Turbo XT Keyboard", + .internal_name = "keyboard_xt_lxt", .flags = 0, .local = KBD_TYPE_VTECH, .init = kbd_init, .close = kbd_close, .reset = kbd_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL }; -#endif /* USE_LASERXT */ const device_t keyboard_xt_olivetti_device = { .name = "Olivetti XT Keyboard", @@ -1316,7 +1355,7 @@ const device_t keyboard_xt_olivetti_device = { .init = kbd_init, .close = kbd_close, .reset = kbd_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1330,7 +1369,7 @@ const device_t keyboard_xt_zenith_device = { .init = kbd_init, .close = kbd_close, .reset = kbd_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1338,13 +1377,27 @@ const device_t keyboard_xt_zenith_device = { const device_t keyboard_xt_hyundai_device = { .name = "Hyundai XT Keyboard", - .internal_name = "keyboard_x_hyundai", + .internal_name = "keyboard_xt_hyundai", .flags = 0, .local = KBD_TYPE_HYUNDAI, .init = kbd_init, .close = kbd_close, .reset = kbd_reset, - { .available = NULL }, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t keyboard_xt_fe2010_device = { + .name = "Faraday FE2010 XT Keyboard", + .internal_name = "keyboard_xt_fe2010", + .flags = 0, + .local = KBD_TYPE_FE2010, + .init = kbd_init, + .close = kbd_close, + .reset = kbd_reset, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1358,7 +1411,7 @@ const device_t keyboard_xtclone_device = { .init = kbd_init, .close = kbd_close, .reset = kbd_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/lpt.c b/src/device/lpt.c new file mode 100644 index 000000000..11afc04f9 --- /dev/null +++ b/src/device/lpt.c @@ -0,0 +1,839 @@ +/* Copyright holders: Sarah Walker + see COPYING for more details +*/ +#include +#include +#include +#include +#include +#define HAVE_STDARG_H +#include <86box/86box.h> +#include <86box/io.h> +#include <86box/fifo.h> +#include <86box/timer.h> +#include <86box/dma.h> +#include <86box/lpt.h> +#include <86box/pic.h> +#include <86box/sound.h> +#include <86box/prt_devs.h> +#include <86box/thread.h> +#include <86box/device.h> +#include <86box/machine.h> +#include <86box/network.h> + +lpt_port_t lpt_ports[PARALLEL_MAX]; + +const lpt_device_t lpt_none_device = { + .name = "None", + .internal_name = "none", + .init = NULL, + .close = NULL, + .write_data = NULL, + .write_ctrl = NULL, + .read_status = NULL, + .read_ctrl = NULL +}; + +static const struct { + const char *internal_name; + const lpt_device_t *device; +} lpt_devices[] = { + // clang-format off + {"none", &lpt_none_device }, + {"dss", &dss_device }, + {"lpt_dac", &lpt_dac_device }, + {"lpt_dac_stereo", &lpt_dac_stereo_device }, + {"text_prt", &lpt_prt_text_device }, + {"dot_matrix", &lpt_prt_escp_device }, + {"postscript", &lpt_prt_ps_device }, +#ifdef USE_PCL + {"pcl", &lpt_prt_pcl_device }, +#endif + {"plip", &lpt_plip_device }, + {"dongle_savquest", &lpt_hasp_savquest_device }, + {"", NULL } + // clang-format on +}; + +#ifdef ENABLE_LPT_LOG +int lpt_do_log = ENABLE_LPT_LOG; + +static void +lpt_log(const char *fmt, ...) +{ + va_list ap; + + if (lpt_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define lpt_log(fmt, ...) +#endif + +const char * +lpt_device_get_name(const int id) +{ + if (strlen(lpt_devices[id].internal_name) == 0) + return NULL; + if (lpt_devices[id].device == NULL) + return "None"; + return lpt_devices[id].device->name; +} + +const char * +lpt_device_get_internal_name(const int id) +{ + if (strlen(lpt_devices[id].internal_name) == 0) + return NULL; + return lpt_devices[id].internal_name; +} + +int +lpt_device_get_from_internal_name(const char *s) +{ + int c = 0; + + while (strlen(lpt_devices[c].internal_name) != 0) { + if (strcmp(lpt_devices[c].internal_name, s) == 0) + return c; + c++; + } + + return 0; +} + +void +lpt_devices_init(void) +{ + 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) + lpt_ports[i].priv = lpt_ports[i].dt->init(&lpt_ports[i]); + } +} + +void +lpt_devices_close(void) +{ + for (uint8_t i = 0; i < PARALLEL_MAX; i++) { + lpt_port_t *dev = &lpt_ports[i]; + + if (lpt_ports[i].dt && lpt_ports[i].dt->close) + dev->dt->close(dev->priv); + + dev->dt = NULL; + } +} + +static uint8_t +lpt_get_ctrl_raw(const lpt_port_t *dev) +{ + uint8_t ret; + + if (dev->dt && dev->dt->read_ctrl && dev->priv) + ret = (dev->dt->read_ctrl(dev->priv) & 0xef) | dev->enable_irq; + else + ret = 0xc0 | dev->ctrl | dev->enable_irq; + + return ret & 0xdf; +} + +static uint8_t +lpt_is_epp(const lpt_port_t *dev) +{ + return (dev->epp || ((dev->ecp) && ((dev->ecr & 0xe0) == 0x80))); +} + +static uint8_t +lpt_get_ctrl(const lpt_port_t *dev) +{ + uint8_t ret = lpt_get_ctrl_raw(dev); + + if (!dev->ecp && !dev->epp) + ret |= 0x20; + + return ret; +} + +static void +lpt_write_fifo(lpt_port_t *dev, const uint8_t val, const uint8_t tag) +{ + if (!fifo_get_full(dev->fifo)) { + fifo_write_evt_tagged(tag, val, dev->fifo); + + if (!timer_is_enabled(&dev->fifo_out_timer)) + timer_set_delay_u64(&dev->fifo_out_timer, (uint64_t) ((1000000.0 / 2500000.0) * (double) TIMER_USEC)); + } +} + +static void +lpt_ecp_update_irq(lpt_port_t *dev) +{ + if (!(dev->ecr & 0x04) && ((dev->fifo_stat | dev->dma_stat) & 0x04)) + picintlevel(1 << dev->irq, &dev->irq_state); + else + picintclevel(1 << dev->irq, &dev->irq_state); +} + +static void +lpt_autofeed(lpt_port_t *dev, const uint8_t val) +{ + if (dev->dt && dev->dt->autofeed && dev->priv) + dev->dt->autofeed(val, dev->priv); + + dev->autofeed = val; +} + +static void +lpt_strobe(lpt_port_t *dev, const uint8_t val) +{ + if (dev->dt && dev->dt->strobe && dev->priv) + dev->dt->strobe(dev->strobe, val, dev->priv); + + dev->strobe = val; +} + +static void +lpt_fifo_out_callback(void *priv) +{ + lpt_port_t *dev = (lpt_port_t *) priv; + + switch (dev->state) { + default: + break; + + case LPT_STATE_READ_DMA: + ; + int ret = 0xff; + + if (dev->dma == 0xff) + ret = DMA_NODATA; + else + ret = dma_channel_read(dev->dma); + + lpt_log("DMA %02X: %08X\n", dev->dma, ret); + + if (ret != DMA_NODATA) { + fifo_write_evt_tagged(0x01, (uint8_t) (ret & 0xff), dev->fifo); + + if (ret & DMA_OVER) + /* Internal flag to indicate we have finished the DMA reads. */ + dev->dma_stat = 0x08; + } + + timer_advance_u64(&dev->fifo_out_timer, + (uint64_t) ((1000000.0 / 2500000.0) * (double) TIMER_USEC)); + + if (dev->dma_stat || fifo_get_full(dev->fifo)) + dev->state = LPT_STATE_WRITE_FIFO; + break; + + case LPT_STATE_WRITE_FIFO: + if (!fifo_get_empty(dev->fifo)) { + uint8_t tag = 0x00; + const uint8_t val = fifo_read_evt_tagged(&tag, dev->fifo); + + lpt_log("FIFO: %02X, TAG = %02X\n", val, tag); + + /* We do not currently support sending commands. */ + if (tag == 0x01) { + if (dev->dt && dev->dt->write_data && dev->priv) + dev->dt->write_data(val, dev->priv); + + lpt_strobe(dev, 1); + lpt_strobe(dev, 0); + } + } + + if (dev->ecr & 0x08) { + if (fifo_get_empty(dev->fifo)) { + if (dev->dma_stat) { + /* Now actually set the external flag. */ + dev->dma_stat = 0x04; + dev->state = LPT_STATE_IDLE; + lpt_ecp_update_irq(dev); + lpt_autofeed(dev, 0); + } else { + dev->state = LPT_STATE_READ_DMA; + + timer_advance_u64(&dev->fifo_out_timer, + (uint64_t) ((1000000.0 / 2500000.0) * (double) TIMER_USEC)); + } + } else + timer_advance_u64(&dev->fifo_out_timer, + (uint64_t) ((1000000.0 / 2500000.0) * (double) TIMER_USEC)); + } else if (!fifo_get_empty(dev->fifo)) + timer_advance_u64(&dev->fifo_out_timer, + (uint64_t) ((1000000.0 / 2500000.0) * (double) TIMER_USEC)); + else + lpt_autofeed(dev, 0); + break; + } +} + +void +lpt_write(const uint16_t port, const uint8_t val, void *priv) +{ + lpt_port_t *dev = (lpt_port_t *) priv; + uint16_t mask = 0x0407; + + lpt_log("[W] %04X = %02X\n", port, val); + + /* This is needed so the parallel port at 3BC works. */ + if (dev->addr & 0x0004) + mask = 0x0403; + + switch (port & mask) { + case 0x0000: + if (dev->ecp) { + if ((dev->ecr & 0xe0) == 0x60) + /* AFIFO */ + lpt_write_fifo(dev, val, 0x00); + else if (!(dev->ecr & 0xc0) && (!(dev->ecr & 0x20) || !(lpt_get_ctrl_raw(dev) & 0x20)) && + dev->dt && dev->dt->write_data && dev->priv) + /* DATAR */ + dev->dt->write_data(val, dev->priv); + dev->dat = val; + } else { + /* DTR */ + if ((!dev->ext || !(lpt_get_ctrl_raw(dev) & 0x20)) && dev->dt && + dev->dt->write_data && dev->priv) + dev->dt->write_data(val, dev->priv); + dev->dat = val; + } + break; + + case 0x0001: + break; + + case 0x0002: + if (dev->dt && dev->dt->write_ctrl && dev->priv) { + if (dev->ecp) + dev->dt->write_ctrl((val & 0xfc) | dev->autofeed | dev->strobe, dev->priv); + else + dev->dt->write_ctrl(val, dev->priv); + } + dev->ctrl = val; + dev->enable_irq = val & 0x10; + if (!(val & 0x10) && (dev->irq != 0xff)) + picintc(1 << dev->irq); + dev->irq_state = 0; + break; + + case 0x0003: + if (lpt_is_epp(dev)) { + if (dev->dt && dev->dt->epp_write_data && dev->priv) + dev->dt->epp_write_data(1, val, dev->priv); + } + break; + + case 0x0004 ... 0x0007: + if (lpt_is_epp(dev)) { + if (dev->dt && dev->dt->epp_write_data && dev->priv) + dev->dt->epp_write_data(0, val, dev->priv); + } + break; + + case 0x0400: case 0x0404: + switch (dev->ecr >> 5) { + default: + break; + case 2: + lpt_write_fifo(dev, val, 0x01); + break; + case 3: + if (!(lpt_get_ctrl_raw(dev) & 0x20)) + lpt_write_fifo(dev, val, 0x01); + break; + case 6: + /* TFIFO */ + if (!fifo_get_full(dev->fifo)) + fifo_write_evt(val, dev->fifo); + break; + } + break; + + case 0x0402: case 0x0406: + if (!(val & 0x0c)) + lpt_autofeed(dev, 0x00); + else + lpt_autofeed(dev, 0x02); + + if ((dev->ecr & 0x04) && !(val & 0x04)) { + dev->dma_stat = 0x00; + fifo_reset(dev->fifo); + if (val & 0x08) { + dev->state = LPT_STATE_READ_DMA; + dev->fifo_stat = 0x00; + if (!timer_is_enabled(&dev->fifo_out_timer)) + timer_set_delay_u64(&dev->fifo_out_timer, (uint64_t) ((1000000.0 / 2500000.0) * (double) TIMER_USEC)); + } else { + dev->state = LPT_STATE_WRITE_FIFO; + if (lpt_get_ctrl_raw(dev) & 0x20) + dev->fifo_stat = fifo_get_ready(dev->fifo) ? 0x04 : 0x00; + else + dev->fifo_stat = fifo_get_ready(dev->fifo) ? 0x00 : 0x04; + } + } else if ((val & 0x04) && !(dev->ecr & 0x04)) { + if (timer_is_enabled(&dev->fifo_out_timer)) + timer_disable(&dev->fifo_out_timer); + + dev->state = LPT_STATE_IDLE; + } + dev->ecr = val; + lpt_ecp_update_irq(dev); + break; + + default: + break; + } +} + +static void +lpt_fifo_d_ready_evt(void *priv) +{ + lpt_port_t *dev = (lpt_port_t *) priv; + + if (!(dev->ecr & 0x08)) { + if (lpt_get_ctrl_raw(dev) & 0x20) + dev->fifo_stat = fifo_get_ready(dev->fifo) ? 0x04 : 0x00; + else + dev->fifo_stat = fifo_get_ready(dev->fifo) ? 0x00 : 0x04; + } + + lpt_ecp_update_irq(dev); +} + +void +lpt_write_to_fifo(void *priv, const uint8_t val) +{ + lpt_port_t *dev = (lpt_port_t *) priv; + + if (dev->ecp) { + if (((dev->ecr & 0xe0) == 0x20) && (lpt_get_ctrl_raw(dev) & 0x20)) + dev->dat = val; + else if (((dev->ecr & 0xe0) == 0x60) && (lpt_get_ctrl_raw(dev) & 0x20) && + !fifo_get_full(dev->fifo)) + fifo_write_evt_tagged(0x01, val, dev->fifo); + + if (((dev->ecr & 0x0c) == 0x08) && (dev->dma != 0xff)) { + const int ret = dma_channel_write(dev->dma, val); + + if (ret & DMA_OVER) + dev->dma_stat |= 0x04; + } + } else { + if (dev->ext && (lpt_get_ctrl_raw(dev) & 0x20)) + dev->dat = val; + } +} + +void +lpt_write_to_dat(void *priv, const uint8_t val) +{ + lpt_port_t *dev = (lpt_port_t *) priv; + + dev->dat = val; +} + +static uint8_t +lpt_read_fifo(const lpt_port_t *dev) +{ + uint8_t ret = 0xff; + + if (!fifo_get_empty(dev->fifo)) + ret = fifo_read(dev->fifo); + + return ret; +} + +uint8_t +lpt_read_status(const int port) +{ + lpt_port_t *dev = &lpt_ports[port]; + uint8_t low_bits = 0x07; + uint8_t ret; + + if (dev->ext) { + low_bits = 0x03 | (dev->irq_state ? 0x00 : 0x04); + if (dev->irq != 0xff) + picintclevel(1 << dev->irq, &dev->irq_state); + dev->irq_state = 0; + } + if (dev->epp || dev->ecp) { + low_bits = lpt_is_epp(dev) ? 0x02 : 0x03; + if (lpt_get_ctrl_raw(dev) & 0x10) + low_bits |= (dev->irq_state ? 0x00 : 0x04); + else + low_bits |= 0x04; + } + + if (dev->dt && dev->dt->read_status && dev->priv) + ret = (dev->dt->read_status(dev->priv) & 0xf8) | low_bits; + else + ret = 0xd8 | low_bits; + + return ret; +} + +uint8_t +lpt_read(const uint16_t port, void *priv) +{ + const lpt_port_t *dev = (lpt_port_t *) priv; + uint16_t mask = 0x0407; + uint8_t ret = 0xff; + + /* This is needed so the parallel port at 3BC works. */ + if (dev->addr & 0x0004) + mask = 0x0403; + + switch (port & mask) { + case 0x0000: + if (dev->ecp) { + if (!(dev->ecr & 0xc0)) + ret = dev->dat; + } else { + /* DTR */ + ret = dev->dat; + } + break; + + case 0x0001: + ret = lpt_read_status(dev->id); + break; + + case 0x0002: + ret = lpt_get_ctrl(dev); + if (dev->ecp) + ret = (ret & 0xfc) | (dev->ctrl & 0x03); + break; + + case 0x0003: + if (lpt_is_epp(dev)) { + if (dev->dt && dev->dt->epp_request_read && dev->priv) + dev->dt->epp_request_read(1, dev->priv); + ret = dev->dat; + } + break; + + case 0x0004 ... 0x0007: + if (lpt_is_epp(dev)) { + if (dev->dt && dev->dt->epp_request_read && dev->priv) + dev->dt->epp_request_read(0, dev->priv); + ret = dev->dat; + } + break; + + case 0x0400: case 0x0404: + switch (dev->ecr >> 5) { + default: + break; + case 3: + if (lpt_get_ctrl_raw(dev) & 0x20) + ret = lpt_read_fifo(dev); + break; + case 6: + /* TFIFO */ + if (!fifo_get_empty(dev->fifo)) + ret = fifo_read_evt(dev->fifo); + break; + case 7: + /* CNFGA */ + ret = 0x14; + break; + } + break; + + case 0x0401: case 0x0405: + if ((dev->ecr & 0xe0) == 0xe0) { + /* CNFGB */ + ret = 0x08; + ret |= (dev->irq_state ? 0x40 : 0x00); + ret |= ((dev->irq == 0x05) ? 0x30 : 0x00); + if ((dev->dma >= 1) && (dev->dma <= 3)) + ret |= dev->dma; + } + break; + + case 0x0402: case 0x0406: + ret = dev->ecr | dev->fifo_stat | (dev->dma_stat & 0x04); + ret |= (fifo_get_full(dev->fifo) ? 0x02 : 0x00); + ret |= (fifo_get_empty(dev->fifo) ? 0x01 : 0x00); + break; + + default: + break; + } + + lpt_log("[R] %04X = %02X\n", port, ret); + + return ret; +} + +uint8_t +lpt_read_port(const int port, const uint16_t reg) +{ + lpt_port_t *dev = &(lpt_ports[port]); + + return lpt_read(reg, dev); +} + +void +lpt_irq(void *priv, const int raise) +{ + lpt_port_t *dev = (lpt_port_t *) priv; + + if (dev->enable_irq) { + if (dev->irq != 0xff) { + if (dev->ext) { + if (raise) + picintlevel(1 << dev->irq, &dev->irq_state); + else + picintclevel(1 << dev->irq, &dev->irq_state); + } else { + if (raise) + picint(1 << dev->irq); + else + picintc(1 << dev->irq); + } + } + + if (!dev->ext || (dev->irq == 0xff)) + dev->irq_state = raise; + } else { + if (dev->irq != 0xff) { + if (dev->ext) + picintclevel(1 << dev->irq, &dev->irq_state); + else + picintc(1 << dev->irq); + } + + dev->irq_state = 0; + } +} + +void +lpt_set_ext(const int port, const uint8_t ext) +{ + if (lpt_ports[port].enabled) + lpt_ports[port].ext = ext; +} + +void +lpt_set_ecp(const int port, const uint8_t ecp) +{ + if (lpt_ports[port].enabled) { + const uint16_t addr = lpt_ports[port].addr; + lpt_port_setup(port, 0xfff); + lpt_ports[port].ecp = ecp; + lpt_port_setup(port, addr); + } +} + +void +lpt_set_epp(const int port, const uint8_t epp) +{ + if (lpt_ports[port].enabled) { + const uint16_t addr = lpt_ports[port].addr; + lpt_port_setup(port, 0xfff); + lpt_ports[port].epp = epp; + lpt_port_setup(port, addr); + } +} + +void +lpt_set_lv2(const int port, const uint8_t lv2) +{ + if (lpt_ports[port].enabled) { + const uint16_t addr = lpt_ports[port].addr; + lpt_port_setup(port, 0xfff); + lpt_ports[port].lv2 = lv2; + lpt_port_setup(port, addr); + } +} + +void +lpt_close(void) +{ + for (uint8_t i = 0; i < PARALLEL_MAX; i++) { + if (lpt_ports[i].enabled) { + fifo_close(lpt_ports[i].fifo); + lpt_ports[i].fifo = NULL; + + timer_disable(&lpt_ports[i].fifo_out_timer); + } + } +} + +void +lpt_port_zero(lpt_port_t *dev) +{ + lpt_port_t temp = { 0 }; + + temp.irq = dev->irq; + temp.id = dev->id; + temp.device = dev->device; + temp.dt = dev->dt; + temp.priv = dev->priv; + temp.enabled = dev->enabled; + temp.fifo = dev->fifo; + temp.fifo_out_timer = dev->fifo_out_timer; + + if (dev->enabled) + lpt_port_remove(dev->id); + + memset(dev, 0x00, sizeof(lpt_port_t)); + + dev->addr = 0xffff; + dev->irq = temp.irq; + dev->id = temp.id; + dev->device = temp.device; + dev->dt = temp.dt; + dev->priv = temp.priv; + dev->enabled = temp.enabled; + dev->fifo = temp.fifo; + dev->fifo_out_timer = temp.fifo_out_timer; + + if (machine_has_bus(machine, MACHINE_BUS_MCA)) + dev->ext = 1; +} + +void +lpt_reset(void) +{ + for (uint8_t i = 0; i < PARALLEL_MAX; i++) { + if (lpt_ports[i].enabled) + if (timer_is_enabled(&lpt_ports[i].fifo_out_timer)) + timer_disable(&lpt_ports[i].fifo_out_timer); + + lpt_port_zero(&(lpt_ports[i])); + + if (lpt_ports[i].enabled) { + if (lpt_ports[i].irq_state) { + if (lpt_ports[i].irq == 0xff) + lpt_ports[i].irq_state = 0x00; + else { + picintclevel(lpt_ports[i].irq, &lpt_ports[i].irq_state); + picintc(lpt_ports[i].irq); + } + } + + lpt_ports[i].enable_irq = 0x00; + lpt_ports[i].ext = !!(machine_has_bus(machine, MACHINE_BUS_MCA)); + lpt_ports[i].epp = 0; + lpt_ports[i].ecp = 0; + lpt_ports[i].ecr = 0x15; + lpt_ports[i].dat = 0xff; + lpt_ports[i].fifo_stat = 0x00; + lpt_ports[i].dma_stat = 0x00; + } + } +} + +void +lpt_init(void) +{ + const uint16_t default_ports[PARALLEL_MAX] = { LPT1_ADDR, LPT2_ADDR, LPT_MDA_ADDR, LPT4_ADDR }; + const uint8_t default_irqs[PARALLEL_MAX] = { LPT1_IRQ, LPT2_IRQ, LPT_MDA_IRQ, LPT4_IRQ }; + + for (uint8_t i = 0; i < PARALLEL_MAX; i++) { + lpt_ports[i].id = i; + lpt_ports[i].dt = NULL; + lpt_ports[i].priv = NULL; + lpt_ports[i].fifo = NULL; + memset(&lpt_ports[i].fifo_out_timer, 0x00, sizeof(pc_timer_t)); + + lpt_port_zero(&(lpt_ports[i])); + + lpt_ports[i].addr = 0xffff; + lpt_ports[i].irq = 0xff; + lpt_ports[i].dma = 0xff; + lpt_ports[i].enable_irq = 0x00; + lpt_ports[i].ext = 0; + lpt_ports[i].epp = 0; + lpt_ports[i].ecp = 0; + lpt_ports[i].ecr = 0x15; + + if (lpt_ports[i].enabled) { + lpt_port_setup(i, default_ports[i]); + lpt_port_irq(i, default_irqs[i]); + + lpt_ports[i].fifo = fifo16_init(); + + fifo_set_trigger_len(lpt_ports[i].fifo, 8); + + fifo_set_d_ready_evt(lpt_ports[i].fifo, lpt_fifo_d_ready_evt); + fifo_set_priv(lpt_ports[i].fifo, &lpt_ports[i]); + + timer_add(&lpt_ports[i].fifo_out_timer, lpt_fifo_out_callback, &lpt_ports[i], 0); + } + } +} + +void +lpt_port_setup(const int i, const uint16_t port) +{ + if (lpt_ports[i].enabled) { + if (lpt_ports[i].addr != 0xffff) { + io_removehandler(lpt_ports[i].addr, 0x0007, lpt_read, NULL, NULL, lpt_write, NULL, NULL, &lpt_ports[i]); + io_removehandler(lpt_ports[i].addr + 0x0400, 0x0007, lpt_read, NULL, NULL, lpt_write, NULL, NULL, &lpt_ports[i]); + } + if (port != 0xffff) { + lpt_log("Set handler: %04X-%04X\n", port, port + 0x0003); + io_sethandler(port, 0x0003, lpt_read, NULL, NULL, lpt_write, NULL, NULL, &lpt_ports[i]); + if (lpt_ports[i].epp) + io_sethandler(lpt_ports[i].addr + 0x0003, 0x0003, lpt_read, NULL, NULL, lpt_write, NULL, NULL, &lpt_ports[i]); + if (lpt_ports[i].ecp || lpt_ports[i].lv2) { + io_sethandler(port + 0x0400, 0x0003, lpt_read, NULL, NULL, lpt_write, NULL, NULL, &lpt_ports[i]); + if (lpt_ports[i].epp) + io_sethandler(lpt_ports[i].addr + 0x0403, 0x0003, lpt_read, NULL, NULL, lpt_write, NULL, NULL, &lpt_ports[i]); + } + } + lpt_ports[i].addr = port; + } else + lpt_ports[i].addr = 0xffff; +} + +void +lpt_port_irq(const int i, const uint8_t irq) +{ + if (lpt_ports[i].enabled) + lpt_ports[i].irq = irq; + else + lpt_ports[i].irq = 0xff; + + lpt_log("Port %i IRQ = %02X\n", i, irq); +} + +void +lpt_port_dma(const int i, const uint8_t dma) +{ + if (lpt_ports[i].enabled) + lpt_ports[i].dma = dma; + else + lpt_ports[i].dma = 0xff; + + lpt_log("Port %i DMA = %02X\n", i, dma); +} + +void +lpt_port_remove(const int i) +{ + if (lpt_ports[i].enabled && (lpt_ports[i].addr != 0xffff)) { + io_removehandler(lpt_ports[i].addr, 0x0007, lpt_read, NULL, NULL, lpt_write, NULL, NULL, &lpt_ports[i]); + io_removehandler(lpt_ports[i].addr + 0x0400, 0x0007, lpt_read, NULL, NULL, lpt_write, NULL, NULL, &lpt_ports[i]); + + lpt_ports[i].addr = 0xffff; + } +} + +void +lpt1_remove_ams(void) +{ + if (lpt_ports[0].enabled) + io_removehandler(lpt_ports[0].addr + 1, 0x0002, lpt_read, NULL, NULL, lpt_write, NULL, NULL, &lpt_ports[0]); +} diff --git a/src/device/mouse.c b/src/device/mouse.c index 604109668..0bf87934d 100644 --- a/src/device/mouse.c +++ b/src/device/mouse.c @@ -61,7 +61,7 @@ static const device_t mouse_none_device = { .init = NULL, .close = NULL, .reset = NULL, - { .poll = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -75,7 +75,7 @@ static const device_t mouse_internal_device = { .init = NULL, .close = NULL, .reset = NULL, - { .poll = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -83,35 +83,36 @@ 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 }, #ifdef USE_GENIBUS - { &mouse_genibus_device }, + { &mouse_genibus_device }, #endif - { &mouse_mssystems_device }, - { &mouse_msserial_device }, - { &mouse_ltserial_device }, - { &mouse_ps2_device }, + { &mouse_mssystems_device }, + { &mouse_mssystems_bus_device }, + { &mouse_msserial_device }, + { &mouse_ltserial_device }, + { &mouse_ps2_device }, #ifdef USE_WACOM - { &mouse_wacom_device }, - { &mouse_wacom_artpad_device }, + { &mouse_wacom_device }, + { &mouse_wacom_artpad_device }, #endif - { &mouse_mtouch_device }, - { NULL } + { &mouse_mtouch_device }, + { NULL } // clang-format on }; static _Atomic double mouse_x; static _Atomic double mouse_y; static atomic_int mouse_z; +static atomic_int mouse_w; static atomic_int mouse_buttons; static int mouse_delta_b; static int mouse_old_b; -static const device_t *mouse_curr; static void *mouse_priv; static int mouse_nbut; static int mouse_raw; @@ -157,6 +158,7 @@ mouse_clear_coords(void) mouse_clear_y(); mouse_z = 0; + mouse_w = 0; } void @@ -356,6 +358,14 @@ mouse_wheel_moved(void) return ret; } +int +mouse_hwheel_moved(void) +{ + int ret = !!(atomic_load(&mouse_w)); + + return ret; +} + int mouse_moved(void) { @@ -374,13 +384,14 @@ mouse_state_changed(void) int b; int b_mask = (1 << mouse_nbut) - 1; int wheel = (mouse_nbut >= 4); + int hwheel = (mouse_nbut >= 6); int ret; b = atomic_load(&mouse_buttons); mouse_delta_b = (b ^ mouse_old_b); mouse_old_b = b; - ret = mouse_moved() || ((atomic_load(&mouse_z) != 0) && wheel) || (mouse_delta_b & b_mask); + ret = mouse_moved() || ((atomic_load(&mouse_z) != 0) && wheel) || ((atomic_load(&mouse_w) != 0) && hwheel) || (mouse_delta_b & b_mask); return ret; } @@ -476,6 +487,18 @@ mouse_clear_z(void) atomic_store(&mouse_z, 0); } +void +mouse_set_w(int w) +{ + atomic_fetch_add(&mouse_w, w); +} + +void +mouse_clear_w(void) +{ + atomic_store(&mouse_w, 0); +} + void mouse_subtract_z(int *delta_z, int min, int max, int invert) { @@ -496,6 +519,26 @@ mouse_subtract_z(int *delta_z, int min, int max, int invert) atomic_store(&mouse_z, invert ? -real_z : real_z); } +void +mouse_subtract_w(int *delta_w, int min, int max, int invert) +{ + int w = atomic_load(&mouse_w); + int real_w = invert ? -w : w; + + if (real_w > max) { + *delta_w = max; + real_w -= max; + } else if (real_w < min) { + *delta_w = min; + real_w += ABS(min); + } else { + *delta_w = real_w; + real_w = 0; + } + + atomic_store(&mouse_w, invert ? -real_w : real_w); +} + void mouse_set_buttons_ex(int b) { @@ -537,17 +580,10 @@ mouse_get_abs_coords(double *x_abs, double *y_abs) void mouse_process(void) { - if (mouse_curr == NULL) - return; - if ((mouse_input_mode >= 1) && mouse_poll_ex) mouse_poll_ex(); - else if ((mouse_input_mode == 0) && ((mouse_dev_poll != NULL) || (mouse_curr->poll != NULL))) { - if (mouse_curr->poll != NULL) - mouse_curr->poll(mouse_priv); - else - mouse_dev_poll(mouse_priv); - } + else if ((mouse_input_mode == 0) && (mouse_dev_poll != NULL)) + mouse_dev_poll(mouse_priv); } void @@ -559,9 +595,6 @@ mouse_set_poll_ex(void (*poll_ex)(void)) void mouse_set_poll(int (*func)(void *), void *arg) { - if (mouse_type != MOUSE_TYPE_INTERNAL) - return; - mouse_dev_poll = func; mouse_priv = arg; } @@ -629,7 +662,7 @@ mouse_set_raw(int raw) void mouse_reset(void) { - if (mouse_curr != NULL) + if (mouse_priv != NULL) return; /* Mouse already initialized. */ mouse_log("MOUSE: reset(type=%d, '%s')\n", @@ -651,19 +684,13 @@ mouse_reset(void) sample_rate = 100.0; timer_on_auto(&mouse_timer, 1000000.0 / sample_rate); - mouse_curr = mouse_devices[mouse_type].device; - - if ((mouse_type > 1) && (mouse_curr != NULL)) - mouse_priv = device_add(mouse_curr); + if ((mouse_type > 1) && (mouse_devices[mouse_type].device != NULL)) + mouse_priv = device_add(mouse_devices[mouse_type].device); } void mouse_close(void) { - if (mouse_curr == NULL) - return; - - mouse_curr = NULL; mouse_priv = NULL; mouse_nbut = 0; mouse_dev_poll = NULL; @@ -680,7 +707,6 @@ mouse_init(void) mouse_clear_buttons(); mouse_type = MOUSE_TYPE_NONE; - mouse_curr = NULL; mouse_priv = NULL; mouse_nbut = 0; mouse_dev_poll = NULL; diff --git a/src/device/mouse_bus.c b/src/device/mouse_bus.c index fdd58b404..c81bc6aba 100644 --- a/src/device/mouse_bus.c +++ b/src/device/mouse_bus.c @@ -614,8 +614,7 @@ bm_init(const device_t *info) mouse_t *dev; int hz; - dev = (mouse_t *) malloc(sizeof(mouse_t)); - memset(dev, 0x00, sizeof(mouse_t)); + dev = (mouse_t *) calloc(1, sizeof(mouse_t)); if ((info->local & ~MOUSE_TYPE_ONBOARD) == MOUSE_TYPE_INPORT) dev->flags = FLAG_INPORT; @@ -681,72 +680,78 @@ bm_init(const device_t *info) mouse_set_sample_rate(0.0); + mouse_set_poll(bm_poll, dev); + return dev; } static const device_config_t lt_config[] = { // clang-format off { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x23c, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x23c, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "0x230", .value = 0x230 }, { .description = "0x234", .value = 0x234 }, { .description = "0x238", .value = 0x238 }, { .description = "0x23C", .value = 0x23c }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 5, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 5, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "IRQ 2", .value = 2 }, { .description = "IRQ 3", .value = 3 }, { .description = "IRQ 4", .value = 4 }, { .description = "IRQ 5", .value = 5 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "hz", - .description = "Hz", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 45, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "hz", + .description = "Hz", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 45, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Non-timed (original)", .value = 0 }, { .description = "30 Hz (JMP2 = 1)", .value = 30 }, { .description = "45 Hz (JMP2 not populated)", .value = 45 }, { .description = "60 Hz (JMP2 = 2)", .value = 60 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "buttons", - .description = "Buttons", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 2, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "buttons", + .description = "Buttons", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Two", .value = 2 }, { .description = "Three", .value = 3 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -755,50 +760,53 @@ static const device_config_t lt_config[] = { static const device_config_t ms_config[] = { // clang-format off { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x23c, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x23c, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "0x230", .value = 0x230 }, { .description = "0x234", .value = 0x234 }, { .description = "0x238", .value = 0x238 }, { .description = "0x23C", .value = 0x23c }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 5, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 5, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "IRQ 2", .value = 2 }, { .description = "IRQ 3", .value = 3 }, { .description = "IRQ 4", .value = 4 }, { .description = "IRQ 5", .value = 5 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "buttons", - .description = "Buttons", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 2, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "buttons", + .description = "Buttons", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Two", .value = 2 }, { .description = "Three", .value = 3 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -807,12 +815,12 @@ static const device_config_t ms_config[] = { const device_t mouse_logibus_device = { .name = "Logitech/Microsoft Bus Mouse", .internal_name = "logibus", - .flags = DEVICE_ISA, + .flags = DEVICE_ISA | DEVICE_SIDECAR, .local = MOUSE_TYPE_LOGIBUS, .init = bm_init, .close = bm_close, .reset = NULL, - { .poll = bm_poll }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = lt_config @@ -826,7 +834,7 @@ const device_t mouse_logibus_onboard_device = { .init = bm_init, .close = bm_close, .reset = NULL, - { .poll = bm_poll }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -835,12 +843,12 @@ const device_t mouse_logibus_onboard_device = { const device_t mouse_msinport_device = { .name = "Microsoft Bus Mouse (InPort)", .internal_name = "msbus", - .flags = DEVICE_ISA, + .flags = DEVICE_ISA | DEVICE_SIDECAR, .local = MOUSE_TYPE_INPORT, .init = bm_init, .close = bm_close, .reset = NULL, - { .poll = bm_poll }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ms_config diff --git a/src/device/mouse_microtouch_touchscreen.c b/src/device/mouse_microtouch_touchscreen.c index 442b25b91..512fcc0df 100644 --- a/src/device/mouse_microtouch_touchscreen.c +++ b/src/device/mouse_microtouch_touchscreen.c @@ -128,8 +128,7 @@ mtouch_initnvr(void *priv) FILE *fp; /* Allocate and initialize the EEPROM. */ - dev->nvr = (uint8_t *) malloc(NVR_SIZE); - memset(dev->nvr, 0x00, NVR_SIZE); + dev->nvr = (uint8_t *) calloc(1, NVR_SIZE); fp = nvr_fopen(dev->nvr_path, "rb"); if (fp) { @@ -314,7 +313,7 @@ mtouch_process_commands(mouse_microtouch_t *dev) } static void -mtouch_write(serial_t *serial, void *priv, uint8_t data) +mtouch_write(UNUSED(serial_t *serial), void *priv, uint8_t data) { mouse_microtouch_t *dev = (mouse_microtouch_t *) priv; @@ -496,7 +495,7 @@ mtouch_poll_global(void) } void * -mtouch_init(const device_t *info) +mtouch_init(UNUSED(const device_t *info)) { mouse_microtouch_t *dev = calloc(1, sizeof(mouse_microtouch_t)); @@ -526,6 +525,7 @@ mtouch_init(const device_t *info) mouse_input_mode = device_get_config_int("crosshair") + 1; mouse_set_buttons(2); + mouse_set_poll(mtouch_poll, dev); mouse_set_poll_ex(mtouch_poll_global); mtouch_inst = dev; @@ -550,42 +550,49 @@ mtouch_close(void *priv) static const device_config_t mtouch_config[] = { // clang-format off { - .name = "port", - .description = "Serial Port", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "port", + .description = "Serial Port", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "COM1", .value = 0 }, { .description = "COM2", .value = 1 }, { .description = "COM3", .value = 2 }, { .description = "COM4", .value = 3 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "identity", - .description = "Controller", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 0, - .file_filter = NULL, - .spinner = { 0 }, - .selection = { - { .description = "A3 - SMT2 Serial / SMT3(R)V", .value = 0 }, - { .description = "A4 - SMT2 PCBus", .value = 1 }, - { .description = "P5 - TouchPen 4(+)", .value = 2 }, - { .description = "Q1 - SMT3(R) Serial", .value = 3 } - } + .name = "identity", + .description = "Controller", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "A3 - SMT2 Serial / SMT3(R)V", .value = 0 }, + { .description = "A4 - SMT2 PCBus", .value = 1 }, + { .description = "P5 - TouchPen 4(+)", .value = 2 }, + { .description = "Q1 - SMT3(R) Serial", .value = 3 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "crosshair", - .description = "Show Crosshair", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "crosshair", + .description = "Show Crosshair", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -599,7 +606,7 @@ const device_t mouse_mtouch_device = { .init = mtouch_init, .close = mtouch_close, .reset = NULL, - { .poll = mtouch_poll }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = mtouch_config diff --git a/src/device/mouse_ps2.c b/src/device/mouse_ps2.c index e5f9dd410..2c1722f51 100644 --- a/src/device/mouse_ps2.c +++ b/src/device/mouse_ps2.c @@ -34,13 +34,15 @@ enum { MODE_ECHO }; -#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 */ +#define FLAG_HWHL 0x800 /* Report horizontal wheel movements. */ +#define FLAG_EXPLORER_HWHL 0x400 /* Has tilt-wheel/horizontal scroll wheel */ +#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 */ #define FIFO_SIZE 16 @@ -82,10 +84,16 @@ ps2_report_coordinates(atkbc_dev_t *dev, int main) int overflow_y; int b = mouse_get_buttons_ex(); int delta_z; + int delta_w; mouse_subtract_coords(&delta_x, &delta_y, &overflow_x, &overflow_y, -256, 255, 1, 0); - mouse_subtract_z(&delta_z, -8, 7, 1); + + if (dev->flags & FLAG_5BTN) + mouse_subtract_z(&delta_z, -32, 31, 1); + else + mouse_subtract_z(&delta_z, -8, 7, 1); + mouse_subtract_w(&delta_w, -1, 1, 0); buff[0] |= (overflow_y << 7) | (overflow_x << 6) | ((delta_y & 0x0100) >> 3) | ((delta_x & 0x0100) >> 4) | @@ -97,10 +105,21 @@ ps2_report_coordinates(atkbc_dev_t *dev, int main) kbc_at_dev_queue_add(dev, buff[1], main); kbc_at_dev_queue_add(dev, buff[2], main); if (dev->flags & FLAG_INTMODE) { - delta_z &= 0x0f; + delta_z &= (dev->flags & FLAG_HWHL) ? 0x3f : 0x0f; if (dev->flags & FLAG_5BTN) { - if (b & 8) + if ((dev->flags & FLAG_HWHL) && (delta_z || delta_w)) + { + if (delta_w) { + delta_z = delta_w; + delta_z &= 0x3f; + delta_z |= 0x40; + } else { + delta_z &= 0x3f; + delta_z |= 0x80; + } + } + else if (b & 8) delta_z |= 0x10; if (b & 16) delta_z |= 0x20; @@ -120,7 +139,7 @@ ps2_set_defaults(atkbc_dev_t *dev) dev->rate = 100; mouse_set_sample_rate(100.0); dev->resolution = 2; - dev->flags &= 0x188; + dev->flags &= 0x688; mouse_scan = 0; } @@ -298,6 +317,13 @@ ps2_write(void *priv) (last_data[2] == 0xf3) && (last_data[3] == 0xc8) && (last_data[4] == 0xf3) && (last_data[5] == 0x50)) dev->flags |= FLAG_5BTN; + + if ((dev->flags & FLAG_5BTN) && (dev->flags & FLAG_EXPLORER_HWHL) && + (last_data[0] == 0xf3) && (last_data[1] == 0xc8) && + (last_data[2] == 0xf3) && (last_data[3] == 0x50) && + (last_data[4] == 0xf3) && (last_data[5] == 0x28)) + dev->flags |= FLAG_HWHL; + } } @@ -307,13 +333,13 @@ ps2_poll(void *priv) atkbc_dev_t *dev = (atkbc_dev_t *) priv; int packet_size = (dev->flags & FLAG_INTMODE) ? 4 : 3; - int cond = (!mouse_capture && !video_fullscreen) || (!mouse_scan || !mouse_state_changed()) || - ((dev->mode == MODE_STREAM) && (kbc_at_dev_queue_pos(dev, 1) >= (FIFO_SIZE - packet_size))); + int cond = (mouse_capture || video_fullscreen) && mouse_scan && (dev->mode == MODE_STREAM) && + mouse_state_changed() && (kbc_at_dev_queue_pos(dev, 1) < (FIFO_SIZE - packet_size)); - if (!cond && (dev->mode == MODE_STREAM)) + if (cond) ps2_report_coordinates(dev, 1); - return cond; + return !cond; } /* @@ -336,6 +362,8 @@ mouse_ps2_init(const device_t *info) dev->flags |= FLAG_INTELLI; if (i > 4) dev->flags |= FLAG_EXPLORER; + if (i > 5) + dev->flags |= FLAG_EXPLORER_HWHL; mouse_ps2_log("%s: buttons=%d\n", dev->name, i); @@ -352,6 +380,8 @@ mouse_ps2_init(const device_t *info) if (dev->port != NULL) kbc_at_dev_reset(dev, 0); + mouse_set_poll(ps2_poll, dev); + /* Return our private data to the I/O layer. */ return dev; } @@ -367,20 +397,22 @@ ps2_close(void *priv) static const device_config_t ps2_config[] = { // clang-format off { - .name = "buttons", - .description = "Buttons", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 2, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { .description = "Two", .value = 2 }, - { .description = "Three", .value = 3 }, - { .description = "Wheel", .value = 4 }, - { .description = "Five + Wheel", .value = 5 }, - { .description = "" } - } + .name = "buttons", + .description = "Buttons", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Two", .value = 2 }, + { .description = "Three", .value = 3 }, + { .description = "Wheel", .value = 4 }, + { .description = "Five + Wheel", .value = 5 }, + { .description = "Five + 2 Wheels", .value = 6 }, + { .description = "" } + }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END @@ -391,12 +423,12 @@ static const device_config_t ps2_config[] = { const device_t mouse_ps2_device = { .name = "PS/2 Mouse", .internal_name = "ps2", - .flags = DEVICE_PS2, + .flags = DEVICE_PS2_KBC, .local = MOUSE_TYPE_PS2, .init = mouse_ps2_init, .close = ps2_close, .reset = NULL, - { .poll = ps2_poll }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ps2_config diff --git a/src/device/mouse_serial.c b/src/device/mouse_serial.c index fa3190536..7505cf3a3 100644 --- a/src/device/mouse_serial.c +++ b/src/device/mouse_serial.c @@ -146,7 +146,11 @@ sermouse_transmit_byte(mouse_t *dev, int do_next) serial_write_fifo(dev->serial, dev->buf[dev->buf_pos]); if (do_next) { - dev->buf_pos = (dev->buf_pos + 1) % dev->buf_len; + /* If we have a buffer length of 0, pretend the state is STATE_SKIP_PACKET. */ + if (dev->buf_len == 0) + dev->buf_pos = 0; + else + dev->buf_pos = (dev->buf_pos + 1) % dev->buf_len; if (dev->buf_pos != 0) sermouse_set_period(dev, dev->transmit_period); @@ -747,7 +751,7 @@ sermouse_timer(void *priv) if (!dev->prompt && !dev->continuous) sermouse_transmit_report(dev, (dev->state == STATE_TRANSMIT_REPORT)); else - dev->state = STATE_IDLE; + dev->state = STATE_IDLE; break; case STATE_TRANSMIT_REPORT: case STATE_TRANSMIT: @@ -829,10 +833,6 @@ sermouse_close(void *priv) { mouse_t *dev = (mouse_t *) priv; - /* Detach serial port from the mouse. */ - if (dev && dev->serial && dev->serial->sd) - memset(dev->serial->sd, 0, sizeof(serial_device_t)); - free(dev); } @@ -843,10 +843,17 @@ sermouse_init(const device_t *info) mouse_t *dev; void (*rcr_callback)(struct serial_s *serial, void *priv); void (*dev_write)(struct serial_s *serial, void *priv, uint8_t data); - void (*transmit_period_callback)(struct serial_s *serial, void *priv, double transmit_period); + void (*transmit_period_callback)(struct serial_s *serial, void *priv, + double transmit_period); - dev = (mouse_t *) malloc(sizeof(mouse_t)); - memset(dev, 0x00, sizeof(mouse_t)); + if (info->local == MOUSE_TYPE_MSYSTEMSB) { + uintptr_t irqbase = ((device_get_config_int("irq") << 16) | + (device_get_config_hex16("addr") << 20)) | + ns16450_device.local; + device_add_params(&ns16450_device, (void*)irqbase); + } + + dev = (mouse_t *) calloc(1, sizeof(mouse_t)); dev->name = info->name; dev->but = device_get_config_int("buttons"); dev->rev = device_get_config_int("revision"); @@ -859,7 +866,7 @@ sermouse_init(const device_t *info) if (dev->but > 2) dev->flags |= FLAG_3BTN; - if (info->local == MOUSE_TYPE_MSYSTEMS) { + if (info->local == MOUSE_TYPE_MSYSTEMS || info->local == MOUSE_TYPE_MSYSTEMSB) { dev->format = 0; dev->type = info->local; dev->id_len = 1; @@ -890,7 +897,7 @@ sermouse_init(const device_t *info) } } - dev->port = device_get_config_int("port"); + dev->port = (info->local == MOUSE_TYPE_MSYSTEMSB) ? (SERIAL_MAX - 1) : device_get_config_int("port"); /* Attach a serial port to the mouse. */ rcr_callback = dev->rts_toggle ? sermouse_callback : NULL; @@ -910,6 +917,8 @@ sermouse_init(const device_t *info) /* Tell them how many buttons we have. */ mouse_set_buttons(dev->but); + mouse_set_poll(sermouse_poll, dev); + /* Return our private data to the I/O layer. */ return dev; } @@ -917,78 +926,158 @@ sermouse_init(const device_t *info) static const device_config_t msssermouse_config[] = { // clang-format off { - .name = "port", - .description = "Serial Port", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "port", + .description = "Serial Port", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "COM1", .value = 0 }, { .description = "COM2", .value = 1 }, { .description = "COM3", .value = 2 }, { .description = "COM4", .value = 3 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "buttons", - .description = "Buttons", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 2, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "buttons", + .description = "Buttons", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Two", .value = 2 }, { .description = "Three", .value = 3 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "rts_toggle", - .description = "RTS toggle", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "rts_toggle", + .description = "RTS toggle", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; +static const device_config_t mssbusmouse_config[] = { + // clang-format off + { + .name = "addr", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x238, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "0x338", .value = 0x338 }, + { .description = "0x238", .value = 0x238 }, + { .description = "0x3f8", .value = 0x3f8 }, + { .description = "0x2f8", .value = 0x2f8 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + + { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 5, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "IRQ 2", .value = 2 }, + { .description = "IRQ 3", .value = 3 }, + { .description = "IRQ 4", .value = 4 }, + { .description = "IRQ 5", .value = 5 }, + { .description = "IRQ 7", .value = 7 }, + { .description = "IRQ 10", .value = 10 }, + { .description = "IRQ 11", .value = 11 }, + { .description = "IRQ 12", .value = 12 }, + { .description = "IRQ 15", .value = 15 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { + .name = "buttons", + .description = "Buttons", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Two", .value = 2 }, + { .description = "Three", .value = 3 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { + .name = "rts_toggle", + .description = "RTS toggle", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on + }; + static const device_config_t mssermouse_config[] = { // clang-format off { - .name = "port", - .description = "Serial Port", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "port", + .description = "Serial Port", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "COM1", .value = 0 }, { .description = "COM2", .value = 1 }, { .description = "COM3", .value = 2 }, { .description = "COM4", .value = 3 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "buttons", - .description = "Buttons", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 2, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "buttons", + .description = "Buttons", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Two", .value = 2 }, { .description = "Three", .value = 3 }, { .description = "Wheel", .value = 4 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -997,57 +1086,64 @@ static const device_config_t mssermouse_config[] = { static const device_config_t ltsermouse_config[] = { // clang-format off { - .name = "port", - .description = "Serial Port", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "port", + .description = "Serial Port", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "COM1", .value = 0 }, { .description = "COM2", .value = 1 }, { .description = "COM3", .value = 2 }, { .description = "COM4", .value = 3 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "buttons", - .description = "Buttons", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 2, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "buttons", + .description = "Buttons", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Two", .value = 2 }, { .description = "Three", .value = 3 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "revision", - .description = "Revision", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 3, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "revision", + .description = "Revision", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 3, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "LOGIMOUSE R7 1.0", .value = 1 }, { .description = "LOGIMOUSE R7 2.0", .value = 2 }, { .description = "LOGIMOUSE C7 3.0", .value = 3 }, { .description = "Logitech MouseMan", .value = 4 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "rts_toggle", - .description = "RTS toggle", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "rts_toggle", + .description = "RTS toggle", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -1061,12 +1157,26 @@ const device_t mouse_mssystems_device = { .init = sermouse_init, .close = sermouse_close, .reset = NULL, - { .poll = sermouse_poll }, + .available = NULL, .speed_changed = sermouse_speed_changed, .force_redraw = NULL, .config = msssermouse_config }; +const device_t mouse_mssystems_bus_device = { + .name = "Mouse Systems Bus Mouse", + .internal_name = "mssystems_bus", + .flags = DEVICE_ISA, + .local = MOUSE_TYPE_MSYSTEMSB, + .init = sermouse_init, + .close = sermouse_close, + .reset = NULL, + .available = NULL, + .speed_changed = sermouse_speed_changed, + .force_redraw = NULL, + .config = mssbusmouse_config +}; + const device_t mouse_msserial_device = { .name = "Microsoft Serial Mouse", .internal_name = "msserial", @@ -1075,7 +1185,7 @@ const device_t mouse_msserial_device = { .init = sermouse_init, .close = sermouse_close, .reset = NULL, - { .poll = sermouse_poll }, + .available = NULL, .speed_changed = sermouse_speed_changed, .force_redraw = NULL, .config = mssermouse_config @@ -1089,7 +1199,7 @@ const device_t mouse_ltserial_device = { .init = sermouse_init, .close = sermouse_close, .reset = NULL, - { .poll = sermouse_poll }, + .available = NULL, .speed_changed = sermouse_speed_changed, .force_redraw = NULL, .config = ltsermouse_config diff --git a/src/device/mouse_wacom_tablet.c b/src/device/mouse_wacom_tablet.c index d299d8bab..3b50882ab 100644 --- a/src/device/mouse_wacom_tablet.c +++ b/src/device/mouse_wacom_tablet.c @@ -662,8 +662,10 @@ wacom_init(const device_t *info) if (dev->tablet_type->type == WACOM_TYPE_IV) { wacom_reset_artpad(dev); wacom_process_settings_dword(dev, 0xE2018000); - } - else wacom_reset(dev); + } else + wacom_reset(dev); + + mouse_set_poll(wacom_poll, dev); return dev; } @@ -693,20 +695,21 @@ wacom_close(void *priv) static const device_config_t wacom_config[] = { // clang-format off { - .name = "port", - .description = "Serial Port", - .type = CONFIG_SELECTION, + .name = "port", + .description = "Serial Port", + .type = CONFIG_SELECTION, .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .default_int = 0, + .file_filter = "", + .spinner = { 0 }, + .selection = { { .description = "COM1", .value = 0 }, { .description = "COM2", .value = 1 }, { .description = "COM3", .value = 2 }, { .description = "COM4", .value = 3 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -720,7 +723,7 @@ const device_t mouse_wacom_device = { .init = wacom_init, .close = wacom_close, .reset = NULL, - { .poll = wacom_poll }, + .available = NULL, .speed_changed = wacom_speed_changed, .force_redraw = NULL, .config = wacom_config @@ -730,11 +733,11 @@ const device_t mouse_wacom_artpad_device = { .name = "Wacom ArtPad", .internal_name = "wacom_serial_artpad", .flags = DEVICE_COM, - .local = (uintptr_t)&artpad_id, + .local = (uintptr_t) &artpad_id, .init = wacom_init, .close = wacom_close, .reset = NULL, - { .poll = wacom_poll }, + .available = NULL, .speed_changed = wacom_speed_changed, .force_redraw = NULL, .config = wacom_config diff --git a/src/device/nec_mate_unk.c b/src/device/nec_mate_unk.c index 165962f30..c0393eaa2 100644 --- a/src/device/nec_mate_unk.c +++ b/src/device/nec_mate_unk.c @@ -30,7 +30,7 @@ #include <86box/plat_unused.h> static uint8_t -nec_mate_unk_read(UNUSED(uint16_t addr), void *priv) +nec_mate_unk_read(UNUSED(uint16_t addr), UNUSED(void *priv)) { /* Expected by this NEC machine. @@ -49,7 +49,7 @@ nec_mate_unk_close(void *priv) } static void * -nec_mate_unk_init(const device_t *info) +nec_mate_unk_init(UNUSED(const device_t *info)) { /* We have to return something non-NULL. */ uint8_t *dev = (uint8_t *) calloc(1, sizeof(uint8_t)); @@ -68,7 +68,7 @@ const device_t nec_mate_unk_device = { .init = nec_mate_unk_init, .close = nec_mate_unk_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/novell_cardkey.c b/src/device/novell_cardkey.c index 4730b6bb4..08334e751 100644 --- a/src/device/novell_cardkey.c +++ b/src/device/novell_cardkey.c @@ -27,8 +27,7 @@ #include <86box/plat.h> #include <86box/novell_cardkey.h> -typedef struct novell_cardkey_t -{ +typedef struct novell_cardkey_t { char serial_number_str[13]; } novell_cardkey_t; @@ -61,7 +60,7 @@ novell_cardkey_read(uint16_t port, void *priv) return val ^ 0xFF; } -void* novell_cardkey_init(const device_t* info) +void* novell_cardkey_init(UNUSED(const device_t* info)) { char sernumstr[13] = { '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 0 }; int i = 0; @@ -95,28 +94,29 @@ void novell_cardkey_close(void* priv) static const device_config_t keycard_config[] = { // clang-format off { - .name = "serial_number", - .description = "Serial Number", - .type = CONFIG_STRING, + .name = "serial_number", + .description = "Serial Number", + .type = CONFIG_STRING, .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { { 0 } } + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; const device_t novell_keycard_device = { - .name = "Novell Netware 2.x Key Card", + .name = "Novell NetWare 2.x Key Card", .internal_name = "mssystems", .flags = DEVICE_ISA, .local = 0, .init = novell_cardkey_init, .close = novell_cardkey_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = keycard_config diff --git a/src/device/pci_bridge.c b/src/device/pci_bridge.c index c1f551162..bf49baf14 100644 --- a/src/device/pci_bridge.c +++ b/src/device/pci_bridge.c @@ -30,8 +30,10 @@ #include <86box/mem.h> #include <86box/device.h> #include <86box/pci.h> +#include <86box/plat_fallthrough.h> #define PCI_BRIDGE_DEC_21150 0x10110022 +#define PCI_BRIDGE_DEC_21152 0x10110024 #define AGP_BRIDGE_ALI_M5243 0x10b95243 #define AGP_BRIDGE_ALI_M5247 0x10b95247 #define AGP_BRIDGE_INTEL_440LX 0x80867181 @@ -85,6 +87,14 @@ pci_bridge_set_ctl(void *priv, uint8_t ctl) dev->ctl = ctl; } +uint8_t +pci_bridge_get_bus_index(void *priv) +{ + pci_bridge_t *dev = (pci_bridge_t *) priv; + + return dev->bus_index; +} + static void pci_bridge_write(int func, int addr, uint8_t val, void *priv) { @@ -242,12 +252,15 @@ pci_bridge_write(int func, int addr, uint8_t val, void *priv) case 0x40: if (dev->local == PCI_BRIDGE_DEC_21150) val &= 0x32; + else if (dev->local == PCI_BRIDGE_DEC_21152) + val &= 0x12; break; case 0x41: if (AGP_BRIDGE_VIA(dev->local)) val &= 0x7e; - else if (dev->local == PCI_BRIDGE_DEC_21150) + else if ((dev->local == PCI_BRIDGE_DEC_21150) || + (dev->local == PCI_BRIDGE_DEC_21152)) val &= 0x07; break; @@ -257,18 +270,22 @@ pci_bridge_write(int func, int addr, uint8_t val, void *priv) break; case 0x43: - if (dev->local == PCI_BRIDGE_DEC_21150) + if ((dev->local == PCI_BRIDGE_DEC_21150) || + (dev->local == PCI_BRIDGE_DEC_21152)) val &= 0x03; break; case 0x64: - if (dev->local == PCI_BRIDGE_DEC_21150) + if ((dev->local == PCI_BRIDGE_DEC_21150) || + (dev->local == PCI_BRIDGE_DEC_21152)) val &= 0x7e; break; case 0x69: if (dev->local == PCI_BRIDGE_DEC_21150) val &= 0x3f; + else if (dev->local == PCI_BRIDGE_DEC_21152) + val = (val & 0x01) | 0x3e; break; case 0x86: @@ -302,6 +319,15 @@ pci_bridge_write(int func, int addr, uint8_t val, void *priv) break; case 0xe0: + if (AGP_BRIDGE_ALI(dev->local)) { + if (!(dev->ctl & 0x20)) + return; + } else if (dev->local == PCI_BRIDGE_DEC_21152) + val &= 0x03; + else + return; + break; + case 0xe1: if (AGP_BRIDGE_ALI(dev->local)) { if (!(dev->ctl & 0x20)) @@ -399,6 +425,14 @@ pci_bridge_reset(void *priv) /* command and status */ switch (dev->local) { + case PCI_BRIDGE_DEC_21152: + dev->regs[0x08] = 0x03; + dev->regs[0x34] = 0xdc; + dev->regs[0x69] = 0x3e; + dev->regs[0xdc] = 0x01; + dev->regs[0xde] = 0x01; + dev->regs[0xe2] = 0x80; + fallthrough; case PCI_BRIDGE_DEC_21150: dev->regs[0x06] = 0x80; dev->regs[0x07] = 0x02; @@ -487,12 +521,11 @@ static void * pci_bridge_init(const device_t *info) { uint8_t interrupts[4]; - uint8_t interrupt_count; uint8_t interrupt_mask; + uint8_t add_type; uint8_t slot_count; - pci_bridge_t *dev = (pci_bridge_t *) malloc(sizeof(pci_bridge_t)); - memset(dev, 0, sizeof(pci_bridge_t)); + pci_bridge_t *dev = (pci_bridge_t *) calloc(1, sizeof(pci_bridge_t)); dev->local = info->local; dev->bus_index = pci_register_bus(); @@ -500,22 +533,27 @@ pci_bridge_init(const device_t *info) pci_bridge_reset(dev); - pci_add_bridge(AGP_BRIDGE(dev->local), pci_bridge_read, pci_bridge_write, dev, &dev->slot); - - interrupt_count = sizeof(interrupts); - interrupt_mask = interrupt_count - 1; + interrupt_mask = sizeof(interrupts) - 1; if (dev->slot < 32) { - for (uint8_t i = 0; i < interrupt_count; i++) + for (uint8_t i = 0; i <= interrupt_mask; 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]); - if (info->local == PCI_BRIDGE_DEC_21150) + if (info->local == PCI_BRIDGE_DEC_21150) { slot_count = 9; /* 9 bus masters */ - else + add_type = PCI_ADD_NORMAL; + } else if (info->local == PCI_BRIDGE_DEC_21152) { + slot_count = 0; /* 4 bus masters, but slots are added by the Dell machines */ + add_type = PCI_ADD_BRIDGE; + } else { slot_count = 1; /* AGP bridges always have 1 slot */ + add_type = PCI_ADD_AGPBRIDGE; + } + + pci_add_bridge(add_type, pci_bridge_read, pci_bridge_write, dev, &dev->slot); for (uint8_t i = 0; i < slot_count; i++) { /* Interrupts for bridge slots are assigned in round-robin: ABCD, BCDA, CDAB and so on. */ @@ -542,7 +580,21 @@ const device_t dec21150_device = { .init = pci_bridge_init, .close = NULL, .reset = pci_bridge_reset, - { .available = NULL }, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t dec21152_device = { + .name = "DEC 21152 PCI Bridge", + .internal_name = "dec21152", + .flags = DEVICE_PCI, + .local = PCI_BRIDGE_DEC_21152, + .init = pci_bridge_init, + .close = NULL, + .reset = pci_bridge_reset, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -557,7 +609,7 @@ const device_t ali5243_agp_device = { .init = pci_bridge_init, .close = NULL, .reset = pci_bridge_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -572,7 +624,7 @@ const device_t ali5247_agp_device = { .init = pci_bridge_init, .close = NULL, .reset = pci_bridge_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -586,7 +638,7 @@ const device_t i440lx_agp_device = { .init = pci_bridge_init, .close = NULL, .reset = pci_bridge_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -600,7 +652,7 @@ const device_t i440bx_agp_device = { .init = pci_bridge_init, .close = NULL, .reset = pci_bridge_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -614,7 +666,7 @@ const device_t i440gx_agp_device = { .init = pci_bridge_init, .close = NULL, .reset = pci_bridge_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -628,7 +680,7 @@ const device_t via_vp3_agp_device = { .init = pci_bridge_init, .close = NULL, .reset = pci_bridge_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -642,7 +694,7 @@ const device_t via_mvp3_agp_device = { .init = pci_bridge_init, .close = NULL, .reset = pci_bridge_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -656,7 +708,7 @@ const device_t via_apro_agp_device = { .init = pci_bridge_init, .close = NULL, .reset = pci_bridge_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -670,7 +722,7 @@ const device_t via_vt8601_agp_device = { .init = pci_bridge_init, .close = NULL, .reset = pci_bridge_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -684,7 +736,7 @@ const device_t sis_5xxx_agp_device = { .init = pci_bridge_init, .close = NULL, .reset = pci_bridge_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/phoenix_486_jumper.c b/src/device/phoenix_486_jumper.c index a3c891c90..a3e2f0e7e 100644 --- a/src/device/phoenix_486_jumper.c +++ b/src/device/phoenix_486_jumper.c @@ -110,8 +110,7 @@ phoenix_486_jumper_close(void *priv) 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)); + phoenix_486_jumper_t *dev = (phoenix_486_jumper_t *) calloc(1, sizeof(phoenix_486_jumper_t)); dev->type = info->local; @@ -130,7 +129,7 @@ const device_t phoenix_486_jumper_device = { .init = phoenix_486_jumper_init, .close = phoenix_486_jumper_close, .reset = phoenix_486_jumper_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -144,7 +143,7 @@ const device_t phoenix_486_jumper_pci_device = { .init = phoenix_486_jumper_init, .close = phoenix_486_jumper_close, .reset = phoenix_486_jumper_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/postcard.c b/src/device/postcard.c index dbae3232a..ec031c2b8 100644 --- a/src/device/postcard.c +++ b/src/device/postcard.c @@ -30,11 +30,14 @@ #include "cpu.h" uint8_t postcard_codes[POSTCARDS_NUM]; +char postcard_diags[5] = { 0 }; static uint16_t postcard_port; static uint8_t postcard_written[POSTCARDS_NUM]; static uint8_t postcard_ports_num = 1; static uint8_t postcard_prev_codes[POSTCARDS_NUM]; +static uint8_t postcard_dell_mode = 0; +static char postcard_prev_diags[5] = { 0 }; #define UISTR_LEN 32 static char postcard_str[UISTR_LEN]; /* UI output string */ @@ -98,12 +101,22 @@ postcard_setui(void) break; } } else { + char dell_diags[11] = { 0 }; + if (postcard_dell_mode) { + if (!postcard_written[1]) + snprintf(dell_diags, sizeof(dell_diags), " ---- ----"); + else if (postcard_written[1] == 1) + snprintf(dell_diags, sizeof(dell_diags), " %s ----", postcard_diags); + else + snprintf(dell_diags, sizeof(dell_diags), " %s %s", postcard_diags, postcard_prev_diags); + } + if (!postcard_written[0]) - snprintf(postcard_str, sizeof(postcard_str), "POST: -- --"); + snprintf(postcard_str, sizeof(postcard_str), "POST: -- --%s", dell_diags); else if (postcard_written[0] == 1) - snprintf(postcard_str, sizeof(postcard_str), "POST: %02X --", postcard_codes[0]); + snprintf(postcard_str, sizeof(postcard_str), "POST: %02X --%s", postcard_codes[0], dell_diags); else - snprintf(postcard_str, sizeof(postcard_str), "POST: %02X %02X", postcard_codes[0], postcard_prev_codes[0]); + snprintf(postcard_str, sizeof(postcard_str), "POST: %02X %02X%s", postcard_codes[0], postcard_prev_codes[0], dell_diags); } ui_sb_bugui(postcard_str); @@ -122,6 +135,9 @@ postcard_reset(void) memset(postcard_codes, 0x00, POSTCARDS_NUM * sizeof(uint8_t)); memset(postcard_prev_codes, 0x00, POSTCARDS_NUM * sizeof(uint8_t)); + memset(postcard_diags, 0x00, 5 * sizeof(char)); + memset(postcard_prev_diags, 0x00, 5 * sizeof(char)); + postcard_setui(); } @@ -140,6 +156,35 @@ postcard_write(uint16_t port, uint8_t val, UNUSED(void *priv)) postcard_setui(); } +static int +postcard_cmp_diags(uint32_t val) +{ + int ret = 0; + char *pv = (char *) &val; + + for (int i = 0; i < 4; i++) + ret = ret || (pv[i] != postcard_diags[3 - i]); + + return ret; +} + +static void +postcard_writel(uint16_t port, uint32_t val, UNUSED(void *priv)) +{ + char *pv = (char *) &val; + + if (postcard_written[1] && !postcard_cmp_diags(val)) + return; + + *(uint32_t *) postcard_prev_diags = *(uint32_t *) postcard_diags; + for (int i = 0; i < 4; i++) + postcard_diags[i] = pv[3 - i]; + if (postcard_written[1] < 2) + postcard_written[1]++; + + postcard_setui(); +} + static void * postcard_init(UNUSED(const device_t *info)) { @@ -147,17 +192,22 @@ postcard_init(UNUSED(const device_t *info)) if (machine_has_bus(machine, MACHINE_BUS_MCA)) postcard_port = 0x680; /* MCA machines */ - else if (strstr(machines[machine].name, " PS/2 ") || strstr(machine_getname_ex(machine), " PS/1 ")) + else if (strstr(machines[machine].name, " PS/2 ") || + strstr(machine_getname_ex(machine), " PS/1 ")) postcard_port = 0x190; /* ISA PS/2 machines */ else if (strstr(machines[machine].name, " IBM XT ")) postcard_port = 0x60; /* IBM XT */ else if (strstr(machines[machine].name, " IBM PCjr")) { postcard_port = 0x10; /* IBM PCjr */ postcard_ports_num = 3; /* IBM PCjr error ports 11h and 12h */ - } else if (strstr(machines[machine].name, " Compaq ") && !machine_has_bus(machine, MACHINE_BUS_PCI)) + } else if (strstr(machines[machine].name, " Compaq ") && + !strstr(machines[machine].name, " Presario ") && + !strstr(machines[machine].name, " ProSignia ")) postcard_port = 0x84; /* ISA Compaq machines */ else if (strstr(machines[machine].name, "Olivetti")) postcard_port = 0x378; /* Olivetti machines */ + else if (!strcmp(machines[machine].internal_name, "isa486c")) + postcard_port = 0x5080; /* ASUS ISA-486C */ else postcard_port = 0x80; /* AT and clone machines */ postcard_log("POST card initializing on port %04Xh\n", postcard_port); @@ -168,6 +218,12 @@ postcard_init(UNUSED(const device_t *info)) io_sethandler(postcard_port, postcard_ports_num, NULL, NULL, NULL, postcard_write, NULL, NULL, NULL); + postcard_dell_mode = strstr(machines[machine].name, " Dell ") && + (machine_get_chipset(machine) >= MACHINE_CHIPSET_INTEL_430FX); + if (postcard_dell_mode) + io_sethandler(is486 ? 0x00e0 : 0x00e4, 0x0001, + NULL, NULL, NULL, NULL, NULL, postcard_writel, NULL); + return postcard_write; } @@ -187,7 +243,7 @@ const device_t postcard_device = { .init = postcard_init, .close = postcard_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/serial.c b/src/device/serial.c index dcaff0f7f..71be924c1 100644 --- a/src/device/serial.c +++ b/src/device/serial.c @@ -15,7 +15,7 @@ * Authors: Miran Grca, * Fred N. van Kempen, * - * Copyright 2016-2020 Miran Grca. + * Copyright 2016-2025 Miran Grca. * Copyright 2017-2020 Fred N. van Kempen. */ #include @@ -27,6 +27,7 @@ #define HAVE_STDARG_H #include <86box/86box.h> #include <86box/device.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/machine.h> #include <86box/io.h> @@ -782,6 +783,20 @@ serial_setup(serial_t *dev, uint16_t addr, uint8_t irq) dev->irq = irq; } +void +serial_irq(serial_t *dev, const uint8_t irq) +{ + if (dev == NULL) + return; + + if (com_ports[dev->inst].enabled) + dev->irq = irq; + else + dev->irq = 0xff; + + serial_log("Port %i IRQ = %02X\n", dev->inst, irq); +} + static void serial_rcvr_d_empty_evt(void *priv) { @@ -869,10 +884,10 @@ serial_close(void *priv) { serial_t *dev = (serial_t *) priv; - next_inst--; - - if (com_ports[dev->inst].enabled) + if (dev->sd) { + memset(dev->sd, 0, sizeof(serial_device_t)); fifo_close(dev->rcvr_fifo); + } free(dev); } @@ -882,7 +897,7 @@ serial_reset(void *priv) { serial_t *dev = (serial_t *) priv; - if (com_ports[dev->inst].enabled) { + if (dev->sd) { timer_disable(&dev->transmit_timer); timer_disable(&dev->timeout_timer); timer_disable(&dev->receive_timer); @@ -914,18 +929,27 @@ serial_reset(void *priv) static void * serial_init(const device_t *info) { - serial_t *dev = (serial_t *) malloc(sizeof(serial_t)); - memset(dev, 0, sizeof(serial_t)); + serial_t *dev = (serial_t *) calloc(1, sizeof(serial_t)); + int orig_inst = next_inst; + + if (info->local & 0xFFF00000) + next_inst = SERIAL_MAX - 1; dev->inst = next_inst; - if (com_ports[next_inst].enabled) { + if (com_ports[next_inst].enabled || (info->local & 0xFFF00000)) { serial_log("Adding serial port %i...\n", next_inst); dev->type = info->local; memset(&(serial_devices[next_inst]), 0, sizeof(serial_device_t)); dev->sd = &(serial_devices[next_inst]); dev->sd->serial = dev; - if (next_inst == 6) + + if (info->local & 0xfff00000) { + dev->base_address = info->local >> 20; + dev->irq = (info->local >> 16) & 0xF; + io_sethandler(dev->base_address, 0x0008, serial_read, NULL, NULL, serial_write, NULL, NULL, dev); + next_inst = orig_inst; + } else if (next_inst == 6) serial_setup(dev, COM7_ADDR, COM7_IRQ); else if (next_inst == 5) serial_setup(dev, COM6_ADDR, COM6_IRQ); @@ -935,7 +959,7 @@ serial_init(const device_t *info) serial_setup(dev, COM4_ADDR, COM4_IRQ); else if (next_inst == 2) serial_setup(dev, COM3_ADDR, COM3_IRQ); - else if ((next_inst == 1) || (info->flags & DEVICE_PCJR)) + else if ((next_inst == 1) || (info->local == SERIAL_8250_PCJR)) serial_setup(dev, COM2_ADDR, COM2_IRQ); else if (next_inst == 0) serial_setup(dev, COM1_ADDR, COM1_IRQ); @@ -970,7 +994,8 @@ serial_init(const device_t *info) serial_reset_port(dev); } - next_inst++; + if (!(info->local & 0xfff00000)) + next_inst++; return dev; } @@ -984,7 +1009,7 @@ serial_set_next_inst(int ni) void serial_standalone_init(void) { - while (next_inst < SERIAL_MAX) + while (next_inst < (SERIAL_MAX - 1)) device_add_inst(&ns8250_device, next_inst + 1); }; @@ -996,7 +1021,7 @@ const device_t ns8250_device = { .init = serial_init, .close = serial_close, .reset = serial_reset, - { .available = NULL }, + .available = NULL, .speed_changed = serial_speed_changed, .force_redraw = NULL, .config = NULL @@ -1005,12 +1030,12 @@ const device_t ns8250_device = { const device_t ns8250_pcjr_device = { .name = "National Semiconductor 8250(-compatible) UART for PCjr", .internal_name = "ns8250_pcjr", - .flags = DEVICE_PCJR, + .flags = 0, .local = SERIAL_8250_PCJR, .init = serial_init, .close = serial_close, .reset = serial_reset, - { .available = NULL }, + .available = NULL, .speed_changed = serial_speed_changed, .force_redraw = NULL, .config = NULL @@ -1024,7 +1049,7 @@ const device_t ns16450_device = { .init = serial_init, .close = serial_close, .reset = serial_reset, - { .available = NULL }, + .available = NULL, .speed_changed = serial_speed_changed, .force_redraw = NULL, .config = NULL @@ -1038,7 +1063,7 @@ const device_t ns16550_device = { .init = serial_init, .close = serial_close, .reset = serial_reset, - { .available = NULL }, + .available = NULL, .speed_changed = serial_speed_changed, .force_redraw = NULL, .config = NULL @@ -1052,7 +1077,7 @@ const device_t ns16650_device = { .init = serial_init, .close = serial_close, .reset = serial_reset, - { .available = NULL }, + .available = NULL, .speed_changed = serial_speed_changed, .force_redraw = NULL, .config = NULL @@ -1066,7 +1091,7 @@ const device_t ns16750_device = { .init = serial_init, .close = serial_close, .reset = serial_reset, - { .available = NULL }, + .available = NULL, .speed_changed = serial_speed_changed, .force_redraw = NULL, .config = NULL @@ -1080,7 +1105,7 @@ const device_t ns16850_device = { .init = serial_init, .close = serial_close, .reset = serial_reset, - { .available = NULL }, + .available = NULL, .speed_changed = serial_speed_changed, .force_redraw = NULL, .config = NULL @@ -1094,7 +1119,7 @@ const device_t ns16950_device = { .init = serial_init, .close = serial_close, .reset = serial_reset, - { .available = NULL }, + .available = NULL, .speed_changed = serial_speed_changed, .force_redraw = NULL, .config = NULL diff --git a/src/device/serial_passthrough.c b/src/device/serial_passthrough.c index eec9fa62a..25db29096 100644 --- a/src/device/serial_passthrough.c +++ b/src/device/serial_passthrough.c @@ -54,7 +54,7 @@ serial_passthrough_log(const char *fmt, ...) void serial_passthrough_init(void) { - for (uint8_t c = 0; c < SERIAL_MAX; c++) { + for (uint8_t c = 0; c < (SERIAL_MAX - 1); c++) { if (serial_passthrough_enabled[c]) { /* Instance n for COM n */ device_add_inst(&serial_passthrough_device, c + 1); @@ -178,8 +178,7 @@ serial_passthrough_dev_init(const device_t *info) { serial_passthrough_t *dev; - dev = (serial_passthrough_t *) malloc(sizeof(serial_passthrough_t)); - memset(dev, 0, sizeof(serial_passthrough_t)); + dev = (serial_passthrough_t *) calloc(1, sizeof(serial_passthrough_t)); dev->mode = device_get_config_int("mode"); dev->port = device_get_instance() - 1; @@ -232,151 +231,142 @@ const char *serpt_mode_names[SERPT_MODES_MAX] = { // clang-format off static const device_config_t serial_passthrough_config[] = { { - .name = "mode", - .description = "Passthrough Mode", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "mode", + .description = "Passthrough Mode", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { #ifdef _WIN32 - { - .description = "Named Pipe (Server)", - .value = SERPT_MODE_VCON - }, + { .description = "Named Pipe (Server)", .value = SERPT_MODE_VCON }, #if 0 /* TODO */ - { - .description = "Named Pipe (Client)", - .value = SERPT_MODE_VCON - }, -#endif -#else - { - .description = "Pseudo Terminal/Virtual Console", - .value = SERPT_MODE_VCON - }, + { .description = "Named Pipe (Client)", .value = SERPT_MODE_VCON }, #endif +#else /* _WIN32 */ + { .description = "Pseudo Terminal/Virtual Console", .value = SERPT_MODE_VCON }, +#endif /* _WIN32 */ #if 0 /* TODO */ - { - .description = "TCP Server", - .value = SERPT_MODE_TCPSRV - }, - { - .description = "TCP Client", - .value = SERPT_MODE_TCPCLNT - }, + { .description = "TCP Server", .value = SERPT_MODE_TCPSRV }, + { .description = "TCP Client", .value = SERPT_MODE_TCPCLNT }, #endif - { - .description = "Host Serial Passthrough", - .value = SERPT_MODE_HOSTSER - }, - { - .description = "" - } - } + { .description = "Host Serial Passthrough", .value = SERPT_MODE_HOSTSER }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "host_serial_path", - .description = "Host Serial Device", - .type = CONFIG_SERPORT, - .default_string = "", - .file_filter = NULL, - .spinner = {}, - .selection = {} + .name = "host_serial_path", + .description = "Host Serial Device", + .type = CONFIG_SERPORT, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, #ifdef _WIN32 { - .name = "named_pipe", - .description = "Name of pipe", - .type = CONFIG_STRING, + .name = "named_pipe", + .description = "Name of pipe", + .type = CONFIG_STRING, .default_string = "\\\\.\\pipe\\86Box\\test", - .file_filter = NULL, - .spinner = {}, - .selection = {} + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, -#endif +#endif /* _WIN32 */ { - .name = "data_bits", - .description = "Data bits", - .type = CONFIG_SELECTION, - .default_string = "8", - .default_int = 8, - .file_filter = NULL, - .spinner = { 0 }, - .selection = { + .name = "data_bits", + .description = "Data bits", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 8, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { #if 0 /* Mentioned by WFW 3.1x, not supported, atleast on Linux */ { .description = "4", .value = 4 }, #endif { .description = "5", .value = 5 }, { .description = "6", .value = 6 }, { .description = "7", .value = 7 }, - { .description = "8", .value = 8 } - } + { .description = "8", .value = 8 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "stop_bits", - .description = "Stop bits", - .type = CONFIG_SELECTION, - .default_string = "1", - .default_int = 1, - .file_filter = NULL, - .spinner = { 0 }, - .selection = { + .name = "stop_bits", + .description = "Stop bits", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "1", .value = 1 }, #if 0 { .description = "1.5", .value = 1.5 }, #endif - { .description = "2", .value = 2 } - } + { .description = "2", .value = 2 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "baudrate", - .description = "Baud Rate of Passthrough", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 115200, - .file_filter = NULL, - .spinner = { 0 }, - .selection = { + .name = "baudrate", + .description = "Baud Rate of Passthrough", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 115200, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { #if 0 - { .description = "256000", .value = 256000 }, - { .description = "128000", .value = 128000 }, + { .description = "256000", .value = 256000 }, + { .description = "128000", .value = 128000 }, #endif - { .description = "115200", .value = 115200 }, - { .description = "57600", .value = 57600 }, - { .description = "56000", .value = 56000 }, - { .description = "38400", .value = 38400 }, - { .description = "19200", .value = 19200 }, - { .description = "14400", .value = 14400 }, - { .description = "9600", .value = 9600 }, - { .description = "7200", .value = 7200 }, - { .description = "4800", .value = 4800 }, - { .description = "2400", .value = 2400 }, - { .description = "1800", .value = 1800 }, - { .description = "1200", .value = 1200 }, - { .description = "600", .value = 600 }, - { .description = "300", .value = 300 }, - { .description = "150", .value = 150 }, + { .description = "115200", .value = 115200 }, + { .description = "57600", .value = 57600 }, + { .description = "56000", .value = 56000 }, + { .description = "38400", .value = 38400 }, + { .description = "19200", .value = 19200 }, + { .description = "14400", .value = 14400 }, + { .description = "9600", .value = 9600 }, + { .description = "7200", .value = 7200 }, + { .description = "4800", .value = 4800 }, + { .description = "2400", .value = 2400 }, + { .description = "1800", .value = 1800 }, + { .description = "1200", .value = 1200 }, + { .description = "600", .value = 600 }, + { .description = "300", .value = 300 }, + { .description = "150", .value = 150 }, #if 0 { .description = "134.5", .value = 134.5 }, #endif - { .description = "110", .value = 110 }, - { .description = "75", .value = 75 } - } + { .description = "110", .value = 110 }, + { .description = "75", .value = 75 }, + { .description = "" } + }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; // 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, - { .poll = NULL }, + .name = "Serial Passthrough Device", + .flags = 0, + .local = 0, + .init = serial_passthrough_dev_init, + .close = serial_passthrough_dev_close, + .reset = NULL, + .available = NULL, .speed_changed = serial_passthrough_speed_changed, .force_redraw = NULL, .config = serial_passthrough_config diff --git a/src/device/smbus_ali7101.c b/src/device/smbus_ali7101.c index 349de470d..49eb44bc6 100644 --- a/src/device/smbus_ali7101.c +++ b/src/device/smbus_ali7101.c @@ -273,7 +273,7 @@ smbus_ali7101_reset(void *priv) static void * smbus_ali7101_init(const device_t *info) { - smbus_ali7101_t *dev = (smbus_ali7101_t *) malloc(sizeof(smbus_ali7101_t)); + smbus_ali7101_t *dev = (smbus_ali7101_t *) calloc(1, sizeof(smbus_ali7101_t)); memset(dev, 0, sizeof(smbus_ali7101_t)); dev->local = info->local; @@ -302,12 +302,12 @@ smbus_ali7101_close(void *priv) const device_t ali7101_smbus_device = { .name = "ALi M7101-compatible SMBus Host Controller", .internal_name = "ali7101_smbus", - .flags = DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0, .init = smbus_ali7101_init, .close = smbus_ali7101_close, .reset = smbus_ali7101_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/smbus_piix4.c b/src/device/smbus_piix4.c index 6f2b1632e..ae37c72c4 100644 --- a/src/device/smbus_piix4.c +++ b/src/device/smbus_piix4.c @@ -357,8 +357,7 @@ smbus_piix4_setclock(smbus_piix4_t *dev, int clock) static void * smbus_piix4_init(const device_t *info) { - smbus_piix4_t *dev = (smbus_piix4_t *) malloc(sizeof(smbus_piix4_t)); - memset(dev, 0, sizeof(smbus_piix4_t)); + smbus_piix4_t *dev = (smbus_piix4_t *) calloc(1, sizeof(smbus_piix4_t)); dev->local = info->local; /* We save the I2C bus handle on dev but use i2c_smbus for all operations because @@ -387,12 +386,12 @@ smbus_piix4_close(void *priv) const device_t piix4_smbus_device = { .name = "PIIX4-compatible SMBus Host Controller", .internal_name = "piix4_smbus", - .flags = DEVICE_AT, + .flags = DEVICE_ISA16, .local = SMBUS_PIIX4, .init = smbus_piix4_init, .close = smbus_piix4_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -401,12 +400,12 @@ const device_t piix4_smbus_device = { const device_t via_smbus_device = { .name = "VIA VT82C686B SMBus Host Controller", .internal_name = "via_smbus", - .flags = DEVICE_AT, + .flags = DEVICE_ISA16, .local = SMBUS_VIA, .init = smbus_piix4_init, .close = smbus_piix4_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/smbus_sis5595.c b/src/device/smbus_sis5595.c index 191e7a6a5..42d1452ad 100644 --- a/src/device/smbus_sis5595.c +++ b/src/device/smbus_sis5595.c @@ -343,8 +343,7 @@ smbus_sis5595_reset(void *priv) static void * smbus_sis5595_init(const device_t *info) { - smbus_sis5595_t *dev = (smbus_sis5595_t *) malloc(sizeof(smbus_sis5595_t)); - memset(dev, 0, sizeof(smbus_sis5595_t)); + smbus_sis5595_t *dev = (smbus_sis5595_t *) calloc(1, sizeof(smbus_sis5595_t)); dev->local = info->local; @@ -374,12 +373,12 @@ smbus_sis5595_close(void *priv) const device_t sis5595_smbus_device = { .name = "SiS 5595-compatible SMBus Host Controller", .internal_name = "sis5595_smbus", - .flags = DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0, .init = smbus_sis5595_init, .close = smbus_sis5595_close, .reset = smbus_sis5595_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/device/tulip_jumper.c b/src/device/tulip_jumper.c new file mode 100644 index 000000000..1974129e3 --- /dev/null +++ b/src/device/tulip_jumper.c @@ -0,0 +1,103 @@ +/* + * 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 Tulip Jumper Readout. + * + * Bits 7-5 = board number, 0-5 valid, 6, 7 invalid. + * + * Authors: Miran Grca, + * + * Copyright 2025 Miran Grca. + */ +#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/machine.h> +#include <86box/sound.h> +#include <86box/chipset.h> +#include <86box/plat.h> +#include <86box/plat_unused.h> + +typedef struct tulip_jumper_t { + uint8_t jumper; +} tulip_jumper_t; + +#ifdef ENABLE_TULIP_JUMPER_LOG +int tulip_jumper_do_log = ENABLE_TULIP_JUMPER_LOG; + +static void +tulip_jumper_log(const char *fmt, ...) +{ + va_list ap; + + if (tulip_jumper_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define tulip_jumper_log(fmt, ...) +#endif + +static uint8_t +tulip_jumper_read(uint16_t addr, void *priv) +{ + const tulip_jumper_t *dev = (tulip_jumper_t *) priv; + uint8_t ret = 0xff; + + tulip_jumper_log("Tulip Jumper: Read %02x\n", dev->jumper); + + ret = dev->jumper; + + return ret; +} + +static void +tulip_jumper_close(void *priv) +{ + tulip_jumper_t *dev = (tulip_jumper_t *) priv; + + free(dev); +} + +static void * +tulip_jumper_init(const device_t *info) +{ + tulip_jumper_t *dev = (tulip_jumper_t *) calloc(1, sizeof(tulip_jumper_t)); + + /* Return board number 05. */ + dev->jumper = 0xbf; + + io_sethandler(0x0d80, 0x0001, tulip_jumper_read, NULL, NULL, NULL, NULL, NULL, dev); + + return dev; +} + +const device_t tulip_jumper_device = { + .name = "Tulip Jumper Readout", + .internal_name = "tulip_jumper", + .flags = 0, + .local = 0, + .init = tulip_jumper_init, + .close = tulip_jumper_close, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; diff --git a/src/device/unittester.c b/src/device/unittester.c index e52f3b56f..0e864aa0b 100644 --- a/src/device/unittester.c +++ b/src/device/unittester.c @@ -104,8 +104,8 @@ struct unittester_state { /* 0x04: Exit */ uint8_t exit_code; }; -static struct unittester_state unittester; -static const struct unittester_state unittester_defaults = { +static struct unittester_state unittester; +static struct unittester_state unittester_defaults = { .trigger_port = 0x0080, .iobase_port = 0xFFFF, .fsm1 = UT_FSM1_WAIT_8, @@ -114,15 +114,6 @@ static const struct unittester_state unittester_defaults = { .cmd_id = UT_CMD_NOOP, }; -static const device_config_t unittester_config[] = { - { .name = "exit_enabled", - .description = "Enable 0x04 \"Exit 86Box\" command", - .type = CONFIG_BINARY, - .default_int = 1, - .default_string = "" }, - { .type = CONFIG_END } -}; - /* Kept separate, as we will be reusing this object */ static bitmap_t *unittester_screen_buffer = NULL; @@ -589,7 +580,7 @@ unittester_trigger_write(UNUSED(uint16_t port), uint8_t val, UNUSED(void *priv)) static void * unittester_init(UNUSED(const device_t *info)) { - unittester = (struct unittester_state) unittester_defaults; + unittester = unittester_defaults; unittester_exit_enabled = !!device_get_config_int("exit_enabled"); @@ -620,6 +611,23 @@ unittester_close(UNUSED(void *priv)) unittester_log("[UT] 86Box Unit Tester closed\n"); } +static const device_config_t unittester_config[] = { + // clang-format off + { + .name = "exit_enabled", + .description = "Enable 0x04 \"Exit 86Box\" command", + .type = CONFIG_BINARY, + .default_int = 1, + .default_string = NULL, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on +}; + const device_t unittester_device = { .name = "86Box Unit Tester", .internal_name = "unittester", @@ -628,7 +636,7 @@ const device_t unittester_device = { .init = unittester_init, .close = unittester_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = unittester_config, diff --git a/src/disk/CMakeLists.txt b/src/disk/CMakeLists.txt index 3f6a4d018..bdbb9e74c 100644 --- a/src/disk/CMakeLists.txt +++ b/src/disk/CMakeLists.txt @@ -31,6 +31,7 @@ add_library(hdd OBJECT hdc_ide_opti611.c hdc_ide_cmd640.c hdc_ide_cmd646.c + hdc_ide_rz1000.c hdc_ide_sff8038i.c hdc_ide_um8673f.c hdc_ide_w83769f.c diff --git a/src/disk/hdc.c b/src/disk/hdc.c index 908cbce07..ecd609476 100644 --- a/src/disk/hdc.c +++ b/src/disk/hdc.c @@ -56,32 +56,40 @@ static const struct { // clang-format off { &device_none }, { &device_internal }, - { &st506_xt_xebec_device }, - { &st506_xt_wdxt_gen_device }, + /* ISA */ + { &xtide_acculogic_device }, { &st506_xt_dtc5150x_device }, + { &st506_xt_xebec_device }, + { &xtide_device }, { &st506_xt_st11_m_device }, - { &st506_xt_wd1002a_wx1_device }, - { &st506_xt_wd1004a_wx1_device }, - { &st506_at_wd1003_device }, { &st506_xt_st11_r_device }, + { &st506_xt_victor_v86p_device }, { &st506_xt_wd1002a_27x_device }, + { &st506_xt_wd1002a_wx1_device }, { &st506_xt_wd1004_27x_device }, { &st506_xt_wd1004a_27x_device }, - { &st506_xt_victor_v86p_device }, - { &esdi_at_wd1007vse1_device }, + { &st506_xt_wd1004a_wx1_device }, + { &xta_wdxt150_device }, + { &st506_xt_wdxt_gen_device }, + /* ISA16 */ { &ide_isa_device }, { &ide_isa_2ch_device }, { &xtide_at_device }, + { &xtide_at_2ch_device }, { &xtide_at_ps2_device }, - { &xta_wdxt150_device }, - { &xtide_acculogic_device }, - { &xtide_device }, + { &xtide_at_ps2_2ch_device }, + { &st506_at_wd1003_device }, + { &esdi_at_wd1007vse1_device }, + /* MCA */ { &esdi_ps2_device }, - { &ide_pci_device }, - { &ide_pci_2ch_device }, + { &esdi_integrated_device }, + { &mcide_device }, + /* VLB */ { &ide_vlb_device }, { &ide_vlb_2ch_device }, - { &mcide_device }, + /* PCI */ + { &ide_pci_device }, + { &ide_pci_2ch_device }, { NULL } // clang-format on }; diff --git a/src/disk/hdc_esdi_at.c b/src/disk/hdc_esdi_at.c index 7228cba62..64d292250 100644 --- a/src/disk/hdc_esdi_at.c +++ b/src/disk/hdc_esdi_at.c @@ -395,7 +395,7 @@ esdi_write(uint16_t port, uint8_t val, void *priv) fatal("Write with ECC\n"); esdi->status = STAT_READY | STAT_DRQ | STAT_DSC; esdi->pos = 0; - ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 1); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_ESDI, 1); break; case CMD_VERIFY: @@ -412,7 +412,7 @@ esdi_write(uint16_t port, uint8_t val, void *priv) case CMD_FORMAT: esdi->status = STAT_DRQ; esdi->pos = 0; - ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 1); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_ESDI, 1); break; case CMD_SET_PARAMETERS: /* Initialize Drive Parameters */ @@ -593,6 +593,7 @@ esdi_callback(void *priv) esdi->reset = 0; ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_ESDI, 0); return; } @@ -650,7 +651,7 @@ read_error: esdi->status = STAT_READY | STAT_ERR | STAT_DSC; esdi->error = ERR_ABRT; irq_raise(esdi); - ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_ESDI, 0); break; } else { if (get_sector(esdi, &addr)) { @@ -658,7 +659,7 @@ read_error: write_error: esdi->status = STAT_READY | STAT_DSC | STAT_ERR; irq_raise(esdi); - ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_ESDI, 0); break; } @@ -672,10 +673,10 @@ write_error: esdi->status = STAT_DRQ | STAT_READY | STAT_DSC; esdi->pos = 0; next_sector(esdi); - ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 1); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_ESDI, 1); } else { esdi->status = STAT_READY | STAT_DSC; - ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_ESDI, 0); } } break; @@ -718,7 +719,7 @@ verify_error: break; case CMD_FORMAT: - ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_ESDI, 0); if (!drive->present) { esdi->status = STAT_READY | STAT_ERR | STAT_DSC; esdi->error = ERR_ABRT; @@ -752,10 +753,12 @@ format_error: esdi->status = STAT_READY | STAT_DSC; irq_raise(esdi); ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_ESDI, 0); break; case CMD_SET_PARAMETERS: /* Initialize Drive Parameters */ ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_ESDI, 0); if (!drive->present) { esdi->status = STAT_READY | STAT_ERR | STAT_DSC; esdi->error = ERR_ABRT; @@ -778,10 +781,12 @@ format_error: esdi->error = ERR_ABRT; irq_raise(esdi); ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_ESDI, 0); break; case 0xe0: ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_ESDI, 0); if (!drive->present) { esdi->status = STAT_READY | STAT_ERR | STAT_DSC; esdi->error = ERR_ABRT; @@ -825,6 +830,7 @@ format_error: } irq_raise(esdi); ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_ESDI, 0); break; case CMD_READ_PARAMETERS: @@ -869,6 +875,7 @@ format_error: irq_raise(esdi); } ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_ESDI, 0); break; default: @@ -880,6 +887,7 @@ format_error: esdi->error = ERR_ABRT; irq_raise(esdi); ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_ESDI, 0); break; } } @@ -920,12 +928,11 @@ wd1007vse1_init(UNUSED(const device_t *info)) { int c; - esdi_t *esdi = malloc(sizeof(esdi_t)); - memset(esdi, 0x00, sizeof(esdi_t)); + esdi_t *esdi = calloc(1, sizeof(esdi_t)); c = 0; for (uint8_t d = 0; d < HDD_NUM; d++) { - if ((hdd[d].bus == HDD_BUS_ESDI) && (hdd[d].esdi_channel < ESDI_NUM)) { + if ((hdd[d].bus_type == HDD_BUS_ESDI) && (hdd[d].esdi_channel < ESDI_NUM)) { loadhd(esdi, hdd[d].esdi_channel, d, hdd[d].fn); if (++c >= ESDI_NUM) @@ -955,6 +962,7 @@ wd1007vse1_init(UNUSED(const device_t *info)) timer_add(&esdi->callback_timer, esdi_callback, esdi, 0); ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_ESDI, 0); return esdi; } @@ -974,6 +982,7 @@ wd1007vse1_close(void *priv) free(esdi); ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_ESDI, 0); } static int @@ -985,12 +994,12 @@ wd1007vse1_available(void) const device_t esdi_at_wd1007vse1_device = { .name = "Western Digital WD1007V-SE1 (ESDI)", .internal_name = "esdi_at", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0, .init = wd1007vse1_init, .close = wd1007vse1_close, .reset = NULL, - { .available = wd1007vse1_available }, + .available = wd1007vse1_available, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/disk/hdc_esdi_mca.c b/src/disk/hdc_esdi_mca.c index c63c80721..e59ae981d 100644 --- a/src/disk/hdc_esdi_mca.c +++ b/src/disk/hdc_esdi_mca.c @@ -150,6 +150,11 @@ typedef struct esdi_t { uint8_t pos_regs[8]; } esdi_t; +enum { + ESDI_IS_ADAPTER, + ESDI_IS_INTEGRATED +}; + #define STATUS_DMA_ENA (1 << 7) #define STATUS_IRQ_PENDING (1 << 6) #define STATUS_CMD_IN_PROGRESS (1 << 5) @@ -283,6 +288,7 @@ cmd_unsupported(esdi_t *dev) dev->irq_in_progress = 1; set_irq(dev); ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_ESDI, 0); } static void @@ -304,6 +310,7 @@ device_not_present(esdi_t *dev) dev->irq_in_progress = 1; set_irq(dev); ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_ESDI, 0); } static void @@ -325,6 +332,7 @@ rba_out_of_range(esdi_t *dev) dev->irq_in_progress = 1; set_irq(dev); ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_ESDI, 0); } static void @@ -346,6 +354,7 @@ defective_block(esdi_t *dev) dev->irq_in_progress = 1; set_irq(dev); ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_ESDI, 0); } static void @@ -363,6 +372,7 @@ complete_command_status(esdi_t *dev) dev->status_data[5] = (dev->rba - 1) >> 8; dev->status_data[6] = 0; /*Number of blocks requiring error recovery*/ ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_ESDI, 0); } #define ESDI_ADAPTER_ONLY() \ @@ -691,38 +701,56 @@ esdi_callback(void *priv) dev->irq_in_progress = 1; set_irq(dev); ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_ESDI, 0); break; case CMD_GET_DEV_CONFIG: - ESDI_DRIVE_ONLY(); - - if (!drive->present) { - device_not_present(dev); - return; + if (dev->cmd_dev == ATTN_HOST_ADAPTER) + { + if ((dev->status & STATUS_IRQ) || dev->irq_in_progress) + fatal("IRQ in progress %02x %i\n", dev->status, dev->irq_in_progress); + /* INT 13, AX=1C0B - ESDI FIXED DISK - GET ADAPTER CONFIGURATION */ + /* The PS/55 will test sector buffer after this request is done. */ + dev->status_len = 6; + dev->status_data[0] = CMD_GET_DEV_CONFIG | STATUS_LEN(6) | STATUS_DEVICE_HOST_ADAPTER; + dev->status_data[1] = 0; + dev->status_data[2] = 0; + /* bit 15-12: chip revision = 0011b, bit 11-8: sector buffer size = n * 256 bytes (n must be < 6) */ + dev->status_data[3] = 0x3200; + dev->status_data[4] = 0; + dev->status_data[5] = 0; } + else + { + ESDI_DRIVE_ONLY(); + if (!drive->present) { + device_not_present(dev); + return; + } - if ((dev->status & STATUS_IRQ) || dev->irq_in_progress) - fatal("IRQ in progress %02x %i\n", dev->status, dev->irq_in_progress); - - dev->status_len = 6; - dev->status_data[0] = CMD_GET_DEV_CONFIG | STATUS_LEN(6) | STATUS_DEVICE_HOST_ADAPTER; - dev->status_data[1] = 0x10; /*Zero defect*/ - dev->status_data[2] = drive->sectors & 0xffff; - dev->status_data[3] = drive->sectors >> 16; - dev->status_data[4] = drive->tracks; - dev->status_data[5] = drive->hpc | (drive->spt << 16); + if ((dev->status & STATUS_IRQ) || dev->irq_in_progress) + fatal("IRQ in progress %02x %i\n", dev->status, dev->irq_in_progress); + dev->status_len = 6; + dev->status_data[0] = CMD_GET_DEV_CONFIG | STATUS_LEN(6) | STATUS_DEVICE_HOST_ADAPTER; + dev->status_data[1] = 0x10; /*Zero defect*/ + dev->status_data[2] = drive->sectors & 0xffff; + dev->status_data[3] = drive->sectors >> 16; + dev->status_data[4] = drive->tracks; + dev->status_data[5] = drive->hpc | (drive->spt << 16); + } esdi_mca_log("CMD_GET_DEV_CONFIG %i %04x %04x %04x %04x %04x %04x\n", - drive->sectors, - dev->status_data[0], dev->status_data[1], - dev->status_data[2], dev->status_data[3], - dev->status_data[4], dev->status_data[5]); + drive->sectors, + dev->status_data[0], dev->status_data[1], + dev->status_data[2], dev->status_data[3], + dev->status_data[4], dev->status_data[5]); - dev->status = STATUS_IRQ | STATUS_STATUS_OUT_FULL; - dev->irq_status = dev->cmd_dev | IRQ_CMD_COMPLETE_SUCCESS; + dev->status = STATUS_IRQ | STATUS_STATUS_OUT_FULL; + dev->irq_status = dev->cmd_dev | IRQ_CMD_COMPLETE_SUCCESS; dev->irq_in_progress = 1; set_irq(dev); ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_ESDI, 0); break; case CMD_GET_POS_INFO: @@ -733,7 +761,7 @@ esdi_callback(void *priv) dev->status_len = 5; dev->status_data[0] = CMD_GET_POS_INFO | STATUS_LEN(5) | STATUS_DEVICE_HOST_ADAPTER; - dev->status_data[1] = 0xffdd; /*MCA ID*/ + dev->status_data[1] = dev->pos_regs[1] | (dev->pos_regs[0] << 8); /*MCA ID*/ dev->status_data[2] = dev->pos_regs[3] | (dev->pos_regs[2] << 8); dev->status_data[3] = 0xff; dev->status_data[4] = 0xff; @@ -743,6 +771,7 @@ esdi_callback(void *priv) dev->irq_in_progress = 1; set_irq(dev); ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_ESDI, 0); break; case 0x10: @@ -796,6 +825,7 @@ esdi_callback(void *priv) dev->irq_in_progress = 1; set_irq(dev); ui_sb_update_icon(SB_HDD | HDD_BUS_ESDI, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_ESDI, 0); break; default: @@ -1233,6 +1263,62 @@ esdi_mca_write(int port, uint8_t val, void *priv) } } +static void +esdi_integrated_mca_write(int port, uint8_t val, void* priv) +{ + esdi_t* dev = (esdi_t*)priv; + + esdi_mca_log("ESDI: mcawr(%04x, %02x) pos[2]=%02x pos[3]=%02x\n", + port, val, dev->pos_regs[2], dev->pos_regs[3]); + + if (port < 0x102) + return; + + /* Save the new value. */ + dev->pos_regs[port & 7] = val; + + io_removehandler(ESDI_IOADDR_PRI, 8, + esdi_read, esdi_readw, NULL, + esdi_write, esdi_writew, NULL, dev); + + switch (dev->pos_regs[2] & 0x3c) { + case 0x14: + dev->dma = 5; + break; + case 0x18: + dev->dma = 6; + break; + case 0x1c: + dev->dma = 7; + break; + case 0x00: + dev->dma = 0; + break; + case 0x04: + dev->dma = 1; + break; + case 0x0c: + dev->dma = 3; + break; + case 0x10: + dev->dma = 4; + break; + + default: + break; + } + + if (dev->pos_regs[2] & 1) { + io_sethandler(ESDI_IOADDR_PRI, 8, + esdi_read, esdi_readw, NULL, + esdi_write, esdi_writew, NULL, dev); + + /* Say hello. */ + esdi_mca_log("ESDI: I/O=3510, IRQ=14, DMA=%d\n", + dev->dma); + } +} + static uint8_t esdi_mca_feedb(void *priv) { @@ -1241,6 +1327,16 @@ esdi_mca_feedb(void *priv) return (dev->pos_regs[2] & 1); } +static void esdi_reset(void* priv) +{ + esdi_t* dev = (esdi_t*)priv; + if (!dev->in_reset) { + dev->in_reset = 1; + esdi_mca_set_callback(dev, ESDI_TIME * 50); + dev->status = STATUS_BUSY; + } +} + static void * esdi_init(UNUSED(const device_t *info)) { @@ -1249,23 +1345,24 @@ esdi_init(UNUSED(const device_t *info)) uint8_t c; uint8_t i; - dev = malloc(sizeof(esdi_t)); + dev = calloc(1, sizeof(esdi_t)); if (dev == NULL) return (NULL); - memset(dev, 0x00, sizeof(esdi_t)); /* Mark as unconfigured. */ dev->irq_status = 0xff; - rom_init_interleaved(&dev->bios_rom, - BIOS_FILE_H, BIOS_FILE_L, - 0xc8000, 0x4000, 0x3fff, 0, MEM_MAPPING_EXTERNAL); - mem_mapping_disable(&dev->bios_rom.mapping); + if (info->local == ESDI_IS_ADAPTER) { + rom_init_interleaved(&dev->bios_rom, + BIOS_FILE_H, BIOS_FILE_L, + 0xc8000, 0x4000, 0x3fff, 0, MEM_MAPPING_EXTERNAL); + mem_mapping_disable(&dev->bios_rom.mapping); + } dev->drives[0].present = dev->drives[1].present = 0; for (c = 0, i = 0; i < HDD_NUM; i++) { - if ((hdd[i].bus == HDD_BUS_ESDI) && (hdd[i].esdi_channel < ESDI_NUM)) { + if ((hdd[i].bus_type == HDD_BUS_ESDI) && (hdd[i].esdi_channel < ESDI_NUM)) { /* This is an ESDI drive. */ drive = &dev->drives[hdd[i].esdi_channel]; @@ -1293,12 +1390,25 @@ esdi_init(UNUSED(const device_t *info)) break; } - /* Set the MCA ID for this controller, 0xFFDD. */ - dev->pos_regs[0] = 0xff; - dev->pos_regs[1] = 0xdd; + /* Set the MCA ID for this controller. */ + if (info->local == ESDI_IS_ADAPTER) { + dev->pos_regs[0] = 0xff; + dev->pos_regs[1] = 0xdd; + } else if (info->local == ESDI_IS_INTEGRATED) { + dev->pos_regs[0] = 0x9f; + dev->pos_regs[1] = 0xdf; + } /* Enable the device. */ - mca_add(esdi_mca_read, esdi_mca_write, esdi_mca_feedb, NULL, dev); + if (info->local == ESDI_IS_INTEGRATED) { + /* The slot number of this controller is fixed by the planar. IBM PS/55 5551-T assigns it #5. */ + int slotno = device_get_config_int("in_esdi_slot"); + if (slotno) + mca_add_to_slot(esdi_mca_read, esdi_integrated_mca_write, esdi_mca_feedb, esdi_reset, dev, slotno - 1); + else + mca_add(esdi_mca_read, esdi_integrated_mca_write, esdi_mca_feedb, esdi_reset, dev); + } else + mca_add(esdi_mca_read, esdi_mca_write, esdi_mca_feedb, NULL, dev); /* Mark for a reset. */ dev->in_reset = 1; @@ -1338,12 +1448,61 @@ const device_t esdi_ps2_device = { .name = "IBM PS/2 ESDI Fixed Disk Adapter (MCA)", .internal_name = "esdi_mca", .flags = DEVICE_MCA, - .local = 0, + .local = ESDI_IS_ADAPTER, .init = esdi_init, .close = esdi_close, .reset = NULL, - { .available = esdi_available }, + .available = esdi_available, .speed_changed = NULL, .force_redraw = NULL, .config = NULL }; + +static device_config_t + esdi_integrated_config[] = { + { + .name = "in_esdi_slot", + .description = "Slot #", + .type = CONFIG_SELECTION, + .selection = { + { .description = "Auto", .value = 0 }, + { .description = "1", .value = 1 }, + { .description = "2", .value = 2 }, + { .description = "3", .value = 3 }, + { .description = "4", .value = 4 }, + { .description = "5", .value = 5 }, + { .description = "6", .value = 6 }, + { .description = "7", .value = 7 }, + { .description = "8", .value = 8 } + }, + .default_int = 0 + }, + { .type = -1 } +}; + +/* +Device for an IBM DBA (Direct Bus Attachment) hard disk. +The Disk BIOS is included in the System ROM. +Some models have an exclusive channel slot for the DBA hard disk. +Following IBM machines are supported: + * PS/2 model 55SX + * PS/2 model 65SX + * PS/2 model 70 type 3 (Slot #4) + * PS/2 model 70 type 4 (Slot #4) + * PS/55 model 5550-T (Slot #5) + * PS/55 model 5550-V (Slot #5) +*/ +const device_t +esdi_integrated_device = { + .name = "IBM Integrated Fixed Disk and Controller (MCA)", + .internal_name = "esdi_integrated_mca", + .flags = DEVICE_MCA, + .local = ESDI_IS_INTEGRATED, + .init = esdi_init, + .close = esdi_close, + .reset = esdi_reset, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = esdi_integrated_config +}; diff --git a/src/disk/hdc_ide.c b/src/disk/hdc_ide.c index a212361dc..d725b2ace 100644 --- a/src/disk/hdc_ide.c +++ b/src/disk/hdc_ide.c @@ -117,7 +117,7 @@ #define ROM_PATH_MCIDE "roms/hdd/xtide/ide_ps2 R1.1.bin" typedef struct ide_bm_t { - int (*dma)(uint8_t *data, int transfer_length, int out, void *priv); + int (*dma)(uint8_t *data, int transfer_length, int total_length, int out, void *priv); void (*set_irq)(uint8_t status, void *priv); void *priv; } ide_bm_t; @@ -386,7 +386,7 @@ ide_atapi_get_period(uint8_t channel) } static void -ide_irq_update(ide_board_t *dev, int log) +ide_irq_update(ide_board_t *dev, UNUSED(int log)) { ide_t *ide; uint8_t set; @@ -486,7 +486,7 @@ ide_get_max(const ide_t *ide, const int type) int ret; if (ide->type == IDE_ATAPI) - ret = ide->get_max(!IDE_ATAPI_IS_EARLY && ata_4, type); + ret = ide->get_max(ide, !IDE_ATAPI_IS_EARLY && ata_4, type); else ret = max[ata_4][type]; @@ -501,7 +501,7 @@ ide_get_timings(const ide_t *ide, const int type) int ret; if (ide->type == IDE_ATAPI) - ret = ide->get_timings(!IDE_ATAPI_IS_EARLY && ata_4, type); + ret = ide->get_timings(ide, !IDE_ATAPI_IS_EARLY && ata_4, type); else ret = timings[ata_4][type]; @@ -643,7 +643,7 @@ ide_identify(ide_t *ide) memset(ide->buffer, 0, 512); if (ide->type == IDE_ATAPI) - ide->identify(ide, !IDE_ATAPI_IS_EARLY && !ide_boards[ide->board]->force_ata3 && (bm != NULL)); + ide->identify((const ide_t *) ide, !IDE_ATAPI_IS_EARLY && !ide_boards[ide->board]->force_ata3 && (bm != NULL)); else if (ide->type == IDE_HDD) ide_hd_identify(ide); else { @@ -973,7 +973,7 @@ ide_atapi_attach(ide_t *ide) ide->type = IDE_ATAPI; ide_allocate_buffer(ide); ide_set_signature(ide); - ide->mdma_mode = (1 << ide->get_max(!IDE_ATAPI_IS_EARLY && + ide->mdma_mode = (1 << ide->get_max((const ide_t *) ide, !IDE_ATAPI_IS_EARLY && !ide_boards[ide->board]->force_ata3 && (bm != NULL), TYPE_PIO)); ide->tf->error = 1; ide->cfg_spt = ide->cfg_hpc = 0; @@ -1028,9 +1028,8 @@ ide_atapi_command_bus(ide_t *ide) static void ide_atapi_callback(ide_t *ide) { - int out; - int ret = 0; - ide_bm_t *bm = ide_boards[ide->board]->bm; + static int ret = 0; + ide_bm_t *bm = ide_boards[ide->board]->bm; #ifdef ENABLE_IDE_LOG char *phases[7] = { "Idle", "Command", "Data in", "Data out", "Data in DMA", "Data out DMA", "Complete" }; @@ -1056,14 +1055,17 @@ ide_atapi_callback(ide_t *ide) switch (ide->sc->packet_status) { default: + ret = 0; break; case PHASE_IDLE: + ret = 0; ide->tf->pos = 0; ide->tf->phase = 1; ide->tf->atastat = READY_STAT | DRQ_STAT | (ide->tf->atastat & ERR_STAT); break; case PHASE_COMMAND: + ret = 1; ide->tf->atastat = BUSY_STAT | (ide->tf->atastat & ERR_STAT); if (ide->packet_command) { ide->packet_command(ide->sc, ide->sc->atapi_cdb); @@ -1073,6 +1075,7 @@ ide_atapi_callback(ide_t *ide) break; case PHASE_COMPLETE: case PHASE_ERROR: + ret = 0; ide->tf->atastat = READY_STAT; if (ide->sc->packet_status == PHASE_ERROR) ide->tf->atastat |= ERR_STAT; @@ -1082,19 +1085,35 @@ ide_atapi_callback(ide_t *ide) break; case PHASE_DATA_IN: case PHASE_DATA_OUT: + ret = 0; ide->tf->atastat = READY_STAT | DRQ_STAT | (ide->tf->atastat & ERR_STAT); ide->tf->phase = !(ide->sc->packet_status & 0x01) << 1; ide_irq_raise(ide); break; case PHASE_DATA_IN_DMA: - case PHASE_DATA_OUT_DMA: - out = (ide->sc->packet_status & 0x01); - if (!IDE_ATAPI_IS_EARLY && !ide_boards[ide->board]->force_ata3 && (bm != NULL) && bm->dma) { - ret = bm->dma(ide->sc->temp_buffer, ide->sc->packet_len, out, bm->priv); - } - /* Else, DMA command without a bus master, ret = 0 (default). */ + if (ide->sc->block_len == 0) { + ret = bm->dma(ide->sc->temp_buffer, ide->sc->packet_len, 0, 0, bm->priv); + + /* Underrun. */ + if (ret == 1) + ret = 3; + } else { + ret = bm->dma(ide->sc->temp_buffer + ide->sc->buffer_pos - + ide->sc->block_len, ide->sc->block_len, + ide->sc->sector_len * ide->sc->block_len, + 0, bm->priv); + + if (ret == 1) { + if (ide->sc->sector_len == 0) + ret = 3; + else if (ide->read != NULL) + ide->read(ide->sc); + } + } + } else + ret = 0; switch (ret) { default: @@ -1103,18 +1122,75 @@ ide_atapi_callback(ide_t *ide) if (ide->bus_master_error) ide->bus_master_error(ide->sc); break; - case 1: - if (out && ide->phase_data_out) - (void) ide->phase_data_out(ide->sc); - else if (!out && ide->command_stop) - ide->command_stop(ide->sc); + case 2: + ide_atapi_command_bus(ide); + break; + case 3: + /* Reached EOT - terminate the command as there's nothing + more to transfer. */ + ide->sc->packet_status = PHASE_COMPLETE; + ide->sc->callback = 0.0; - if ((ide->sc->packet_status == PHASE_COMPLETE) && (ide->sc->callback == 0.0)) + if (ide->command_stop != NULL) + ide->command_stop(ide->sc); + fallthrough; + case 1: + if ((ide->sc->packet_status == PHASE_COMPLETE) && + (ide->sc->callback == 0.0)) ide_atapi_callback(ide); break; + } + break; + case PHASE_DATA_OUT_DMA: + if (!IDE_ATAPI_IS_EARLY && !ide_boards[ide->board]->force_ata3 && + (bm != NULL) && bm->dma) { + if (ide->sc->block_len == 0) { + ret = bm->dma(ide->sc->temp_buffer, ide->sc->packet_len, 0, 1, bm->priv); + + /* Underrun. */ + if (ret == 1) + ret = 3; + } else { + ret = bm->dma(ide->sc->temp_buffer + ide->sc->buffer_pos, + ide->sc->block_len, + ide->sc->sector_len * ide->sc->block_len, + 1, bm->priv); + + if (ret & 1) { + if (ide->write != NULL) + ide->write(ide->sc); + + if ((ret == 1) && (ide->sc->sector_len == 0)) + ret = 3; + } + } + } else + ret = 0; + + switch (ret) { + default: + break; + case 0: + if (ide->bus_master_error) + ide->bus_master_error(ide->sc); + break; case 2: ide_atapi_command_bus(ide); break; + case 3: + /* Reached EOT - terminate the command as there's nothing + more to transfer. */ + ide->sc->packet_status = PHASE_COMPLETE; + ide->sc->callback = 0.0; + + if (ide->phase_data_out != NULL) + (void) ide->phase_data_out(ide->sc); + fallthrough; + case 1: + if ((ide->sc->packet_status == PHASE_COMPLETE) && + (ide->sc->callback == 0.0)) + ide_atapi_callback(ide); + break; } break; } @@ -1124,32 +1200,45 @@ ide_atapi_callback(ide_t *ide) static void ide_atapi_pio_request(ide_t *ide, uint8_t out) { - scsi_common_t *dev = ide->sc; + scsi_common_t *dev = ide->sc; + int left = 0; ide_irq_lower(ide); - ide->tf->atastat = BSY_STAT; + ide->tf->atastat = BSY_STAT; if (ide->tf->pos >= dev->packet_len) { - ide_log("%i bytes %s, command done\n", ide->tf->pos, out ? "written" : "read"); + // ide_log("%i bytes %s, command done\n", ide->tf->pos, out ? "written" : "read"); + ide_log("%i bytes %s, command done, %i sectors left\n", ide->tf->pos, out ? "written" : "read", + dev->sector_len); ide->tf->pos = dev->request_pos = 0; - if (out && ide->phase_data_out) - ide->phase_data_out(dev); - else if (!out && ide->command_stop) - ide->command_stop(dev); - if ((ide->sc->packet_status == PHASE_COMPLETE) && (ide->sc->callback == 0.0)) - ide_atapi_callback(ide); + if (dev->block_len == 0) { + if (out && (ide->phase_data_out != NULL)) + ide->phase_data_out(dev); + else if (!out && (ide->command_stop != NULL)) + ide->command_stop(dev); + + if ((ide->sc->packet_status == PHASE_COMPLETE) && (ide->sc->callback == 0.0)) + ide_atapi_callback(ide); + } } else { ide_log("%i bytes %s, %i bytes are still left\n", ide->tf->pos, out ? "written" : "read", dev->packet_len - ide->tf->pos); - /* If less than (packet length) bytes are remaining, update packet length - accordingly. */ + left = 1; + + /* + If less than (packet length) bytes are remaining, update packet length + accordingly. + */ if ((dev->packet_len - ide->tf->pos) < (dev->max_transfer_len)) { dev->max_transfer_len = dev->packet_len - ide->tf->pos; - /* Also update the request length so the host knows how many bytes to transfer. */ + /* + Also update the request length so the host knows how many bytes to + transfer. + */ ide->tf->request_length = dev->max_transfer_len; } ide_log("CD-ROM %i: Packet length %i, request length %i\n", dev->id, dev->packet_len, @@ -1157,12 +1246,48 @@ ide_atapi_pio_request(ide_t *ide, uint8_t out) dev->packet_status = PHASE_DATA_IN | out; - ide->tf->atastat = BSY_STAT; - ide->tf->phase = 1; - ide_atapi_callback(ide); - ide_set_callback(ide, 0.0); + if (dev->block_len == 0) { + ide_atapi_callback(ide); + ide_set_callback(ide, 0.0); + } - dev->request_pos = 0; + dev->request_pos = 0; + } + + if (dev->block_len != 0) { + if (out) { + if (ide->write != NULL) + ide->write(dev); + + if (dev->sector_len == 0) { + if (left) { + ide_atapi_callback(ide); + ide_set_callback(ide, 0.0); + } else { + if (ide->phase_data_out != NULL) + (void) ide->phase_data_out(dev); + + if ((ide->sc->packet_status == PHASE_COMPLETE) && + (ide->sc->callback == 0.0)) + ide_atapi_callback(ide); + } + } + } else { + if (dev->sector_len == 0) { + if (left) { + ide_atapi_callback(ide); + ide_set_callback(ide, 0.0); + } else { + if (ide->command_stop != NULL) + ide->command_stop(dev); + + if ((ide->sc->packet_status == PHASE_COMPLETE) && + (ide->sc->callback == 0.0)) + ide_atapi_callback(ide); + } + } else if (ide->read != NULL) + ide->read(dev); + } } } @@ -1174,21 +1299,24 @@ ide_atapi_packet_read(ide_t *ide) uint16_t ret = 0; if (dev && dev->temp_buffer && (dev->packet_status == PHASE_DATA_IN)) { - ide_log("PHASE_DATA_IN read: %i, %i, %i, %i\n", - dev->request_pos, dev->max_transfer_len, ide->tf->pos, dev->packet_len); + /* ide_log("PHASE_DATA_IN read: %i, %i, %i, %i\n", + dev->request_pos, dev->max_transfer_len, ide->tf->pos, dev->packet_len); */ bufferw = (uint16_t *) dev->temp_buffer; - /* Make sure we return a 0 and don't attempt to read from the buffer if + /* + Make sure we return a 0 and don't attempt to read from the buffer if we're transferring bytes beyond it, which can happen when issuing media access commands with an allocated length below minimum request length - (which is 1 sector = 2048 bytes). */ + (which is 1 sector = 2048 bytes). + */ ret = (ide->tf->pos < dev->packet_len) ? bufferw[ide->tf->pos >> 1] : 0; ide->tf->pos += 2; dev->request_pos += 2; - if ((dev->request_pos >= dev->max_transfer_len) || (ide->tf->pos >= dev->packet_len)) { + if ((dev->request_pos >= dev->max_transfer_len) || + (ide->tf->pos >= dev->packet_len)) { /* Time for a DRQ. */ ide_atapi_pio_request(ide, 0); } @@ -1221,7 +1349,8 @@ ide_atapi_packet_write(ide_t *ide, const uint16_t val) dev->request_pos += 2; if (dev->packet_status == PHASE_DATA_OUT) { - if ((dev->request_pos >= dev->max_transfer_len) || (ide->tf->pos >= dev->packet_len)) { + if ((dev->request_pos >= dev->max_transfer_len) || + (ide->tf->pos >= dev->packet_len)) { /* Time for a DRQ. */ ide_atapi_pio_request(ide, 1); } @@ -1287,7 +1416,7 @@ ide_writew(uint16_t addr, uint16_t val, void *priv) ide = ide_drives[ch]; #if defined(ENABLE_IDE_LOG) && (ENABLE_IDE_LOG == 2) - ide_log("ide_writew(%04X, %04X, %08X)\n", addr, val, priv); + ide_log("[%04X:%08X] ide_writew(%04X, %04X, %08X)\n", CS, cpu_state.pc, addr, val, priv); #endif addr &= 0x7; @@ -1321,7 +1450,7 @@ ide_writel(uint16_t addr, uint32_t val, void *priv) ide = ide_drives[ch]; #if defined(ENABLE_IDE_LOG) && (ENABLE_IDE_LOG == 2) - ide_log("ide_writel(%04X, %08X, %08X)\n", addr, val, priv); + ide_log("[%04X:%08X] ide_writel(%04X, %08X, %08X)\n", CS, cpu_state.pc, addr, val, priv); #endif addr &= 0x7; @@ -1371,9 +1500,9 @@ ide_write_devctl(UNUSED(uint16_t addr), uint8_t val, void *priv) ide = ide_drives[ch]; ide_other = ide_drives[ch ^ 1]; - ide_log("ide_write_devctl(%04X, %02X, %08X)\n", addr, val, priv); + ide_log("[%04X:%08X] ide_write_devctl(%04X, %02X, %08X)\n", CS, cpu_state.pc, addr, val, priv); - if ((ide->type == IDE_NONE) && (ide_other->type == IDE_NONE)) + if ((addr & 0x0001) || ((ide->type == IDE_NONE) && (ide_other->type == IDE_NONE))) return; dev->diag = 0; @@ -1481,7 +1610,7 @@ ide_writeb(uint16_t addr, uint8_t val, void *priv) ide = ide_drives[ch]; ide_other = ide_drives[ch ^ 1]; - ide_log("ide_writeb(%04X, %02X, %08X)\n", addr, val, priv); + ide_log("[%04X:%08X] ide_writeb(%04X, %02X, %08X)\n", CS, cpu_state.pc, addr, val, priv); addr &= 0x7; @@ -1593,7 +1722,8 @@ ide_writeb(uint16_t addr, uint8_t val, void *priv) break; case 0x7: /* Command register */ - if (ide->tf->atastat & (BSY_STAT | DRQ_STAT)) + if ((ide->tf->atastat & (BSY_STAT | DRQ_STAT)) && + ((val != WIN_SRST) || (ide->type != IDE_ATAPI))) break; if ((ide->type == IDE_NONE) || ((ide->type & IDE_SHADOW) && (val != WIN_DRIVE_DIAGNOSTICS))) @@ -1655,7 +1785,7 @@ ide_writeb(uint16_t addr, uint8_t val, void *priv) ide->sc->callback = 200.0 * IDE_TIME; if (ide->type == IDE_HDD) { - ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 1); + ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus_type, 1); uint32_t sec_count; double wait_time; if ((val == WIN_READ_DMA) || (val == WIN_READ_DMA_ALT)) { @@ -1697,7 +1827,7 @@ ide_writeb(uint16_t addr, uint8_t val, void *priv) ide->blockcount = 0; /* 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); + ui_sb_update_icon_write(SB_HDD | hdd[ide->hdd_num].bus_type, 1); fallthrough; case WIN_WRITE: @@ -1831,7 +1961,7 @@ ide_read_data(ide_t *ide) const uint16_t *idebufferw = ide->buffer; uint16_t ret = 0x0000; -#if defined(ENABLE_IDE_LOG) && (ENABLE_IDE_LOG == 2) +#if defined(ENABLE_IDE_LOG) && (ENABLE_IDE_LOG == 3) ide_log("ide_read_data(): ch = %i, board = %i, type = %i\n", ide->channel, ide->board, ide->type); #endif @@ -1885,7 +2015,7 @@ ide_read_data(ide_t *ide) ide_set_callback(ide, seek_us + xfer_us); } } else - ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 0); + ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus_type, 0); } } } @@ -1894,7 +2024,7 @@ ide_read_data(ide_t *ide) } static uint8_t -ide_status(ide_t *ide, ide_t *ide_other, int ch) +ide_status(ide_t *ide, UNUSED(ide_t *ide_other), UNUSED(int ch)) { uint8_t ret; @@ -2010,7 +2140,7 @@ ide_readb(uint16_t addr, void *priv) break; } - ide_log("ide_readb(%04X, %08X) = %02X\n", addr, priv, ret); + ide_log("[%04X:%08X] ide_readb(%04X, %08X) = %02X\n", CS, cpu_state.pc, addr, priv, ret); return ret; } @@ -2022,12 +2152,15 @@ ide_read_alt_status(UNUSED(const uint16_t addr), void *priv) const int ch = dev->cur_dev; ide_t * ide = ide_drives[ch]; + uint8_t ret = 0xff; /* Per the Seagate ATA-3 specification: Reading the alternate status does *NOT* clear the IRQ. */ - const uint8_t ret = ide_status(ide, ide_drives[ch ^ 1], ch); + if (!(addr & 0x0001)) + ret = ide_status(ide, ide_drives[ch ^ 1], ch); - ide_log("ide_read_alt_status(%04X, %08X) = %02X\n", addr, priv, ret); + // ide_log("[%04X:%08X] ide_read_alt_status(%04X, %08X) = %02X\n", CS, cpu_state.pc, addr, priv, ret); + // ide_log("ide_read_alt_status(%04X, %08X) = %02X\n", CS, cpu_state.pc, addr, priv, ret); return ret; } @@ -2053,7 +2186,7 @@ ide_readw(uint16_t addr, void *priv) } #if defined(ENABLE_IDE_LOG) && (ENABLE_IDE_LOG == 2) - ide_log("ide_readw(%04X, %08X) = %04X\n", addr, priv, ret); + ide_log("[%04X:%08X] ide_readw(%04X, %08X) = %04X\n", CS, cpu_state.pc, addr, priv, ret); #endif return ret; } @@ -2084,7 +2217,7 @@ ide_readl(uint16_t addr, void *priv) } #if defined(ENABLE_IDE_LOG) && (ENABLE_IDE_LOG == 2) - ide_log("ide_readl(%04X, %08X) = %04X\n", addr, priv, ret); + ide_log("[%04X:%08X] ide_readl(%04X, %08X) = %04X\n", CS, cpu_state.pc, addr, priv, ret); #endif return ret; } @@ -2238,7 +2371,7 @@ ide_callback(void *priv) ide_irq_raise(ide); - ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 1); + ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus_type, 1); } break; @@ -2264,20 +2397,20 @@ ide_callback(void *priv) err = UNC_ERR; } else if (!ide_boards[ide->board]->force_ata3 && bm->dma) { /* We should not abort - we should simply wait for the host to start DMA. */ - ret = bm->dma(ide->sector_buffer, ide->sector_pos * 512, 0, bm->priv); + ret = bm->dma(ide->sector_buffer, ide->sector_pos * 512, 0, 0, bm->priv); if (ret == 2) { /* Bus master DMA disabled, simply wait for the host to enable DMA. */ ide->tf->atastat = DRQ_STAT | DRDY_STAT | DSC_STAT; ide_set_callback(ide, 6.0 * IDE_TIME); return; - } else if (ret == 1) { + } else if (ret & 1) { /* DMA successful */ ide_log("IDE %i: DMA read successful\n", ide->channel); ide->tf->atastat = DRDY_STAT | DSC_STAT; ide_irq_raise(ide); - ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 0); + ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus_type, 0); } else { /* Bus master DMAS error, abort the command. */ ide_log("IDE %i: DMA read aborted (failed)\n", ide->channel); @@ -2339,6 +2472,7 @@ ide_callback(void *priv) else if (!ide->tf->lba && (ide->cfg_spt == 0)) err = IDNF_ERR; else { + ui_sb_update_icon_write(SB_HDD | hdd[ide->hdd_num].bus_type, 1); ret = hdd_image_write(ide->hdd_num, ide_get_sector(ide), 1, (uint8_t *) ide->buffer); ide_irq_raise(ide); ide->tf->secount--; @@ -2346,10 +2480,8 @@ ide_callback(void *priv) ide->tf->atastat = DRQ_STAT | DRDY_STAT | DSC_STAT; ide->tf->pos = 0; ide_next_sector(ide); - ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 1); } else { ide->tf->atastat = DRDY_STAT | DSC_STAT; - ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 0); } if (ret < 0) err = UNC_ERR; @@ -2372,15 +2504,16 @@ ide_callback(void *priv) else ide->sector_pos = 256; - ret = bm->dma(ide->sector_buffer, ide->sector_pos * 512, 1, bm->priv); + ret = bm->dma(ide->sector_buffer, ide->sector_pos * 512, 0, 1, bm->priv); if (ret == 2) { /* Bus master DMA disabled, simply wait for the host to enable DMA. */ ide->tf->atastat = DRQ_STAT | DRDY_STAT | DSC_STAT; ide_set_callback(ide, 6.0 * IDE_TIME); return; - } else if (ret == 1) { + } else if (ret & 1) { /* DMA successful */ + ui_sb_update_icon_write(SB_HDD | hdd[ide->hdd_num].bus_type, 1); ret = hdd_image_write(ide->hdd_num, ide_get_sector(ide), ide->sector_pos, ide->sector_buffer); @@ -2391,7 +2524,6 @@ ide_callback(void *priv) err = UNC_ERR; ide_irq_raise(ide); - ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 0); } else { /* Bus master DMA error, abort the command. */ ide_log("IDE %i: DMA read aborted (failed)\n", ide->channel); @@ -2429,7 +2561,7 @@ ide_callback(void *priv) ide_next_sector(ide); } else { ide->tf->atastat = DRDY_STAT | DSC_STAT; - ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 0); + ui_sb_update_icon_write(SB_HDD | hdd[ide->hdd_num].bus_type, 0); } if (ret < 0) err = UNC_ERR; @@ -2446,7 +2578,7 @@ ide_callback(void *priv) ide->tf->pos = 0; ide->tf->atastat = DRDY_STAT | DSC_STAT; ide_irq_raise(ide); - ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 1); + ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus_type, 1); } break; @@ -2463,7 +2595,7 @@ ide_callback(void *priv) err = UNC_ERR; ide_irq_raise(ide); - ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 1); + ui_sb_update_icon_write(SB_HDD | hdd[ide->hdd_num].bus_type, 1); } break; @@ -2637,7 +2769,7 @@ ide_handlers(uint8_t board, int set) } if (ide_boards[board]->base[1]) { - io_handler(set, ide_boards[board]->base[1], 1, + io_handler(set, ide_boards[board]->base[1], 2, ide_read_alt_status, NULL, NULL, ide_write_devctl, NULL, NULL, ide_boards[board]); @@ -2759,7 +2891,7 @@ ide_board_setup(const int board) c = 0; for (d = 0; d < HDD_NUM; d++) { - const int is_ide = (hdd[d].bus == HDD_BUS_IDE); + const int is_ide = (hdd[d].bus_type == HDD_BUS_IDE); const int ch = hdd[d].ide_channel; const int valid_ch = ((ch >= min_ch) && (ch <= max_ch)); @@ -2902,6 +3034,25 @@ ide_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *priv) } } +static void * +ide_sec_init(const device_t *info) +{ + /* Don't claim this channel again if it was already claimed. */ + if (ide_boards[1]) + return (NULL); + + ide_board_init(1, HDC_SECONDARY_IRQ, HDC_SECONDARY_BASE, HDC_SECONDARY_SIDE, info->local, info->flags); + + return (ide_boards[1]); +} + +/* Close a standalone IDE unit. */ +static void +ide_sec_close(UNUSED(void *priv)) +{ + ide_board_close(1); +} + static void * ide_ter_init(const device_t *info) { @@ -2920,9 +3071,8 @@ ide_ter_init(const device_t *info) if (irq == -1) isapnp_add_card(ide_ter_pnp_rom, sizeof(ide_ter_pnp_rom), ide_pnp_config_changed, NULL, NULL, NULL, (void *) 2); - } else { + } else ide_board_init(2, irq, HDC_TERTIARY_BASE, HDC_TERTIARY_SIDE, 0, 0); - } return (ide_boards[2]); } @@ -2981,7 +3131,7 @@ ide_xtide_close(void) void ide_set_bus_master(int board, - int (*dma)(uint8_t *data, int transfer_length, int out, void *priv), + int (*dma)(uint8_t *data, int transfer_length, int total_length, int out, void *priv), void (*set_irq)(uint8_t status, void *priv), void *priv) { ide_bm_t *bm; @@ -3004,10 +3154,17 @@ ide_init(const device_t *info) switch (info->local) { case 0 ... 5: - ide_board_init(0, 14, 0x1f0, 0x3f6, info->local, info->flags); + ide_board_init(0, HDC_PRIMARY_IRQ, HDC_PRIMARY_BASE, HDC_PRIMARY_SIDE, info->local, info->flags); if (info->local & 1) - ide_board_init(1, 15, 0x170, 0x376, info->local, info->flags); + ide_board_init(1, HDC_SECONDARY_IRQ, HDC_SECONDARY_BASE, HDC_SECONDARY_SIDE, info->local, info->flags); + break; + + case 8 ... 0x0d: + ide_board_init(2, -1, 0, 0, info->local, info->flags); + + if (info->local & 1) + ide_board_init(3, -1, 0, 0, info->local, info->flags); break; default: @@ -3122,8 +3279,8 @@ static void mcide_mca_write(const int port, const uint8_t val, void *priv) { mcide_t *dev = (mcide_t *) priv; - uint16_t bases[4] = { 0x01f0, 0x0170, 0x01e8, 0x0168 }; - int irqs[4] = { 10, 11, 14, 15 }; + uint16_t bases[4] = { HDC_PRIMARY_BASE, HDC_SECONDARY_BASE, HDC_TERTIARY_BASE, HDC_QUATERNARY_BASE }; + int irqs[4] = { HDC_QUATERNARY_IRQ, HDC_TERTIARY_IRQ, HDC_PRIMARY_IRQ, HDC_SECONDARY_IRQ }; if ((port >= 0x102) && (dev->pos_regs[port & 7] != val)) { ide_log("IDE: mcawr(%04x, %02x) pos[2]=%02x pos[3]=%02x\n", @@ -3207,7 +3364,7 @@ mcide_mca_reset(void *priv) } static void -mcide_reset(void *priv) +mcide_reset(UNUSED(void *priv)) { for (uint8_t i = 0; i < 2; i++) { if (ide_boards[i] != NULL) @@ -3264,12 +3421,26 @@ mcide_close(void *priv) const device_t ide_isa_device = { .name = "ISA PC/AT IDE Controller", .internal_name = "ide_isa", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0, .init = ide_init, .close = ide_close, .reset = ide_reset, - { .available = NULL }, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t ide_isa_sec_device = { + .name = "ISA PC/AT IDE Controller (Secondary)", + .internal_name = "ide_isa_sec", + .flags = DEVICE_ISA16, + .local = 0, + .init = ide_sec_init, + .close = ide_sec_close, + .reset = ide_reset, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -3278,12 +3449,12 @@ const device_t ide_isa_device = { const device_t ide_isa_2ch_device = { .name = "ISA PC/AT IDE Controller (Dual-Channel)", .internal_name = "ide_isa_2ch", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 1, .init = ide_init, .close = ide_close, .reset = ide_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -3292,12 +3463,26 @@ const device_t ide_isa_2ch_device = { const device_t ide_vlb_device = { .name = "VLB IDE Controller", .internal_name = "ide_vlb", - .flags = DEVICE_VLB | DEVICE_AT, + .flags = DEVICE_VLB, .local = 2, .init = ide_init, .close = ide_close, .reset = ide_reset, - { .available = NULL }, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t ide_vlb_sec_device = { + .name = "VLB IDE Controller (Secondary)", + .internal_name = "ide_vlb_sec", + .flags = DEVICE_VLB, + .local = 2, + .init = ide_sec_init, + .close = ide_sec_close, + .reset = ide_reset, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -3306,12 +3491,12 @@ const device_t ide_vlb_device = { const device_t ide_vlb_2ch_device = { .name = "VLB IDE Controller (Dual-Channel)", .internal_name = "ide_vlb_2ch", - .flags = DEVICE_VLB | DEVICE_AT, + .flags = DEVICE_VLB, .local = 3, .init = ide_init, .close = ide_close, .reset = ide_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -3320,12 +3505,26 @@ const device_t ide_vlb_2ch_device = { const device_t ide_pci_device = { .name = "PCI IDE Controller", .internal_name = "ide_pci", - .flags = DEVICE_PCI | DEVICE_AT, + .flags = DEVICE_PCI, .local = 4, .init = ide_init, .close = ide_close, .reset = ide_reset, - { .available = NULL }, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t ide_pci_sec_device = { + .name = "PCI IDE Controller (Secondary)", + .internal_name = "ide_pci_sec", + .flags = DEVICE_PCI, + .local = 4, + .init = ide_sec_init, + .close = ide_sec_close, + .reset = ide_reset, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -3334,12 +3533,12 @@ const device_t ide_pci_device = { const device_t ide_pci_2ch_device = { .name = "PCI IDE Controller (Dual-Channel)", .internal_name = "ide_pci_2ch", - .flags = DEVICE_PCI | DEVICE_AT, + .flags = DEVICE_PCI, .local = 5, .init = ide_init, .close = ide_close, .reset = ide_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -3349,28 +3548,27 @@ const device_t mcide_device = { .name = "MCA McIDE Controller", .internal_name = "ide_mcide", .flags = DEVICE_MCA, - .local = 3, + .local = 1, .init = mcide_init, .close = mcide_close, .reset = mcide_reset, - { .available = mcide_available }, + .available = mcide_available, .speed_changed = NULL, .force_redraw = NULL, .config = NULL }; - // clang-format off static const device_config_t ide_ter_config[] = { { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = HDC_TERTIARY_IRQ, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = HDC_TERTIARY_IRQ, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Plug and Play", .value = -1 }, { .description = "IRQ 2", .value = 2 }, { .description = "IRQ 3", .value = 3 }, @@ -3382,21 +3580,22 @@ static const device_config_t ide_ter_config[] = { { .description = "IRQ 11", .value = 11 }, { .description = "IRQ 12", .value = 12 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t ide_qua_config[] = { { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = HDC_QUATERNARY_IRQ, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = HDC_QUATERNARY_IRQ, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Plug and Play", .value = -1 }, { .description = "IRQ 2", .value = 2 }, { .description = "IRQ 3", .value = 3 }, @@ -3408,7 +3607,8 @@ static const device_config_t ide_qua_config[] = { { .description = "IRQ 11", .value = 11 }, { .description = "IRQ 12", .value = 12 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; @@ -3417,12 +3617,12 @@ static const device_config_t ide_qua_config[] = { const device_t ide_ter_device = { .name = "Tertiary IDE Controller", .internal_name = "ide_ter", - .flags = DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0, .init = ide_ter_init, .close = ide_ter_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ide_ter_config @@ -3431,12 +3631,12 @@ const device_t ide_ter_device = { const device_t ide_ter_pnp_device = { .name = "Tertiary IDE Controller (Plug and Play only)", .internal_name = "ide_ter_pnp", - .flags = DEVICE_AT, + .flags = DEVICE_ISA16, .local = 1, .init = ide_ter_init, .close = ide_ter_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -3445,12 +3645,12 @@ const device_t ide_ter_pnp_device = { const device_t ide_qua_device = { .name = "Quaternary IDE Controller", .internal_name = "ide_qua", - .flags = DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0, .init = ide_qua_init, .close = ide_qua_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ide_qua_config @@ -3459,12 +3659,26 @@ const device_t ide_qua_device = { const device_t ide_qua_pnp_device = { .name = "Quaternary IDE Controller (Plug and Play only)", .internal_name = "ide_qua_pnp", - .flags = DEVICE_AT, + .flags = DEVICE_ISA16, .local = 1, .init = ide_qua_init, .close = ide_qua_close, .reset = NULL, - { .available = NULL }, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t ide_pci_ter_qua_2ch_device = { + .name = "PCI IDE Controller (Dual-Channel Tertiary/Quaternary)", + .internal_name = "ide_pci_ter_qua_2ch", + .flags = DEVICE_PCI, + .local = 0x0d, + .init = ide_init, + .close = ide_close, + .reset = ide_reset, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/disk/hdc_ide_ali5213.c b/src/disk/hdc_ide_ali5213.c index 8ff3d392c..67f959e1a 100644 --- a/src/disk/hdc_ide_ali5213.c +++ b/src/disk/hdc_ide_ali5213.c @@ -246,7 +246,7 @@ const device_t ide_ali1489_device = { .init = ali5213_init, .close = ali5213_close, .reset = ali5213_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -260,7 +260,7 @@ const device_t ide_ali5213_device = { .init = ali5213_init, .close = ali5213_close, .reset = ali5213_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/disk/hdc_ide_cmd640.c b/src/disk/hdc_ide_cmd640.c index 3e77730a2..84a40efa4 100644 --- a/src/disk/hdc_ide_cmd640.c +++ b/src/disk/hdc_ide_cmd640.c @@ -504,8 +504,7 @@ cmd640_close(void *priv) static void * cmd640_init(const device_t *info) { - cmd640_t *dev = (cmd640_t *) malloc(sizeof(cmd640_t)); - memset(dev, 0x00, sizeof(cmd640_t)); + cmd640_t *dev = (cmd640_t *) calloc(1, sizeof(cmd640_t)); dev->id = next_id | 0x60; @@ -563,7 +562,7 @@ const device_t ide_cmd640_vlb_device = { .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -577,7 +576,7 @@ const device_t ide_cmd640_vlb_178_device = { .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -591,7 +590,7 @@ const device_t ide_cmd640_vlb_pri_device = { .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -605,7 +604,7 @@ const device_t ide_cmd640_vlb_pri_178_device = { .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -619,7 +618,7 @@ const device_t ide_cmd640_vlb_sec_device = { .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -633,7 +632,7 @@ const device_t ide_cmd640_vlb_sec_178_device = { .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -647,7 +646,7 @@ const device_t ide_cmd640_pci_device = { .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -661,7 +660,7 @@ const device_t ide_cmd640_pci_legacy_only_device = { .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -675,7 +674,7 @@ const device_t ide_cmd640_pci_single_channel_device = { .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -689,7 +688,7 @@ const device_t ide_cmd640_pci_single_channel_sec_device = { .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, - { .available = NULL }, + .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 8367b9a41..a60962ba8 100644 --- a/src/disk/hdc_ide_cmd646.c +++ b/src/disk/hdc_ide_cmd646.c @@ -95,19 +95,19 @@ cmd646_set_irq_1(uint8_t status, void *priv) } static int -cmd646_bus_master_dma_0(uint8_t *data, int transfer_length, int out, void *priv) +cmd646_bus_master_dma_0(uint8_t *data, int transfer_length, int total_length, int out, void *priv) { const cmd646_t *dev = (cmd646_t *) priv; - return sff_bus_master_dma(data, transfer_length, out, dev->bm[0]); + return sff_bus_master_dma(data, transfer_length, total_length, out, dev->bm[0]); } static int -cmd646_bus_master_dma_1(uint8_t *data, int transfer_length, int out, void *priv) +cmd646_bus_master_dma_1(uint8_t *data, int transfer_length, int total_length, int out, void *priv) { const cmd646_t *dev = (cmd646_t *) priv; - return sff_bus_master_dma(data, transfer_length, out, dev->bm[1]); + return sff_bus_master_dma(data, transfer_length, total_length, out, dev->bm[1]); } static void @@ -391,8 +391,7 @@ cmd646_close(void *priv) static void * cmd646_init(const device_t *info) { - cmd646_t *dev = (cmd646_t *) malloc(sizeof(cmd646_t)); - memset(dev, 0x00, sizeof(cmd646_t)); + cmd646_t *dev = (cmd646_t *) calloc(1, sizeof(cmd646_t)); dev->local = info->local; @@ -431,7 +430,7 @@ const device_t ide_cmd646_device = { .init = cmd646_init, .close = cmd646_close, .reset = cmd646_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -445,7 +444,7 @@ const device_t ide_cmd646_legacy_only_device = { .init = cmd646_init, .close = cmd646_close, .reset = cmd646_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -459,7 +458,7 @@ const device_t ide_cmd646_single_channel_device = { .init = cmd646_init, .close = cmd646_close, .reset = cmd646_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/disk/hdc_ide_opti611.c b/src/disk/hdc_ide_opti611.c index 480331201..4927b5fe3 100644 --- a/src/disk/hdc_ide_opti611.c +++ b/src/disk/hdc_ide_opti611.c @@ -317,8 +317,7 @@ opti611_close(void *priv) static void * opti611_init(UNUSED(const device_t *info)) { - opti611_t *dev = (opti611_t *) malloc(sizeof(opti611_t)); - memset(dev, 0, sizeof(opti611_t)); + opti611_t *dev = (opti611_t *) calloc(1, sizeof(opti611_t)); dev->is_sec = info->local; @@ -341,7 +340,7 @@ const device_t ide_opti611_vlb_device = { .init = opti611_init, .close = opti611_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -355,7 +354,7 @@ const device_t ide_opti611_vlb_sec_device = { .init = opti611_init, .close = opti611_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/disk/hdc_ide_rz1000.c b/src/disk/hdc_ide_rz1000.c new file mode 100644 index 000000000..06586b267 --- /dev/null +++ b/src/disk/hdc_ide_rz1000.c @@ -0,0 +1,289 @@ +/* + * 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 PC Technology RZ-1000 controller. + * + * Authors: Miran Grca, + * + * Copyright 2025 Miran Grca. + */ +#include +#include +#include +#include +#include +#include +#define HAVE_STDARG_H +#include <86box/86box.h> +#include <86box/cdrom.h> +#include <86box/scsi_device.h> +#include <86box/scsi_cdrom.h> +#include <86box/dma.h> +#include <86box/io.h> +#include <86box/device.h> +#include <86box/keyboard.h> +#include <86box/mem.h> +#include <86box/pci.h> +#include <86box/pic.h> +#include <86box/timer.h> +#include <86box/hdc.h> +#include <86box/hdc_ide.h> +#include <86box/hdc_ide_sff8038i.h> +#include <86box/zip.h> +#include <86box/mo.h> + +typedef struct rz1000_t { + uint8_t vlb_idx; + uint8_t id; + uint8_t in_cfg; + uint8_t channels; + uint8_t pci; + uint8_t irq_state; + uint8_t pci_slot; + uint8_t pad0; + uint8_t regs[256]; + uint32_t local; + int irq_mode[2]; + int irq_pin; + int irq_line; +} rz1000_t; + +static int next_id = 0; + +#ifdef ENABLE_RZ1000_LOG +int rz1000_do_log = ENABLE_RZ1000_LOG; + +static void +rz1000_log(const char *fmt, ...) +{ + va_list ap; + + if (rz1000_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define rz1000_log(fmt, ...) +#endif + +static void +rz1000_ide_handlers(rz1000_t *dev) +{ + uint16_t main; + uint16_t side; + + if (dev->channels & 0x01) { + ide_pri_disable(); + + main = 0x1f0; + side = 0x3f6; + + ide_set_base(0, main); + ide_set_side(0, side); + + if (dev->regs[0x04] & 0x01) + ide_pri_enable(); + } + + if (dev->channels & 0x02) { + ide_sec_disable(); + + main = 0x170; + side = 0x376; + + ide_set_base(1, main); + ide_set_side(1, side); + + if (dev->regs[0x04] & 0x01) + ide_sec_enable(); + } +} + +static void +rz1000_pci_write(int func, int addr, uint8_t val, void *priv) +{ + rz1000_t *dev = (rz1000_t *) priv; + + rz1000_log("rz1000_pci_write(%i, %02X, %02X)\n", func, addr, val); + + if (func == 0x00) + switch (addr) { + case 0x04: + dev->regs[addr] = (val & 0x41); + rz1000_ide_handlers(dev); + break; + case 0x07: + dev->regs[addr] &= ~(val & 0x80); + break; + case 0x09: + if ((dev->regs[addr] & 0x0a) == 0x0a) { + dev->regs[addr] = (dev->regs[addr] & 0x0a) | (val & 0x05); + dev->irq_mode[0] = !!(val & 0x01); + dev->irq_mode[1] = !!(val & 0x04); + rz1000_ide_handlers(dev); + } + break; + case 0x40 ... 0x4f: + dev->regs[addr] = val; + break; + } +} + +static uint8_t +rz1000_pci_read(int func, int addr, void *priv) +{ + rz1000_t *dev = (rz1000_t *) priv; + uint8_t ret = 0xff; + + if (func == 0x00) + ret = dev->regs[addr]; + + rz1000_log("rz1000_pci_read(%i, %02X, %02X)\n", func, addr, ret); + + return ret; +} + +static void +rz1000_reset(void *priv) +{ + rz1000_t *dev = (rz1000_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 >= 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 >= 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 >= min_channel) && + (mo_drives[i].ide_channel <= max_channel) && mo_drives[i].priv) + mo_reset((scsi_common_t *) mo_drives[i].priv); + } + + memset(dev->regs, 0x00, sizeof(dev->regs)); + + rz1000_log("dev->local = %08X\n", dev->local); + + dev->regs[0x00] = 0x42; /* PC Technology */ + dev->regs[0x01] = 0x10; + dev->regs[0x02] = 0x00; /* RZ-1000 */ + dev->regs[0x03] = 0x10; + dev->regs[0x04] = 0x00; + dev->regs[0x07] = 0x02; /* DEVSEL timing: 01 medium */ + dev->regs[0x08] = 0x02; /* Revision 02 */ + dev->regs[0x09] = dev->local; /* Programming interface */ + dev->regs[0x0a] = 0x01; /* IDE controller */ + dev->regs[0x0b] = 0x01; /* Mass storage controller */ + + dev->irq_mode[0] = dev->irq_mode[1] = 0; + dev->irq_pin = PCI_INTA; + dev->irq_line = 14; + + rz1000_ide_handlers(dev); +} + +static void +rz1000_close(void *priv) +{ + rz1000_t *dev = (rz1000_t *) priv; + + free(dev); + + next_id = 0; +} + +static void * +rz1000_init(const device_t *info) +{ + rz1000_t *dev = (rz1000_t *) calloc(1, sizeof(rz1000_t)); + + dev->id = next_id | 0x60; + + dev->pci = !!(info->flags & DEVICE_PCI); + dev->local = info->local; + + dev->channels = ((info->local & 0x60000) >> 17) & 0x03; + + if (dev->channels & 0x02) + device_add(&ide_pci_2ch_device); + else + device_add(&ide_pci_device); + + if (info->local & 0x80000) + pci_add_card(PCI_ADD_NORMAL, rz1000_pci_read, rz1000_pci_write, dev, &dev->pci_slot); + else + pci_add_card(PCI_ADD_IDE, rz1000_pci_read, rz1000_pci_write, dev, &dev->pci_slot); + + if (dev->channels & 0x01) + ide_board_set_force_ata3(0, 1); + + if (dev->channels & 0x02) + ide_board_set_force_ata3(1, 1); + + next_id++; + + rz1000_reset(dev); + + return dev; +} + +const device_t ide_rz1000_pci_device = { + .name = "PC Technology RZ-1000 PCI", + .internal_name = "ide_rz1000_pci", + .flags = DEVICE_PCI, + .local = 0x60000, + .init = rz1000_init, + .close = rz1000_close, + .reset = rz1000_reset, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t ide_rz1000_pci_single_channel_device = { + .name = "PC Technology RZ-1000 PCI", + .internal_name = "ide_rz1000_pci_single_channel", + .flags = DEVICE_PCI, + .local = 0x20000, + .init = rz1000_init, + .close = rz1000_close, + .reset = rz1000_reset, + .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 631afa931..7ded4372f 100644 --- a/src/disk/hdc_ide_sff8038i.c +++ b/src/disk/hdc_ide_sff8038i.c @@ -316,14 +316,14 @@ sff_bus_master_readl(uint16_t port, void *priv) } int -sff_bus_master_dma(uint8_t *data, int transfer_length, int out, void *priv) +sff_bus_master_dma(uint8_t *data, int transfer_length, int total_length, int out, void *priv) { sff8038i_t *dev = (sff8038i_t *) priv; #ifdef ENABLE_SFF_LOG char *sop; #endif - int force_end = 0; + int force_end = 0; int buffer_pos = 0; #ifdef ENABLE_SFF_LOG @@ -365,9 +365,15 @@ sff_bus_master_dma(uint8_t *data, int transfer_length, int out, void *priv) return 1; /* This block has exhausted the data to transfer and it was smaller than the count, break. */ } else { if (!transfer_length && !dev->eot) { - sff_log("Total transfer length smaller than sum of all blocks, full block\n"); - dev->status &= ~2; - return 1; /* We have exhausted the data to transfer but there's more blocks left, break. */ + if (total_length) { + sff_log("Total transfer length smaller than sum of all blocks, partial transfer\n"); + sff_bus_master_next_addr(dev); + return 1; /* We have exhausted the data to transfer but there's more blocks left, break. */ + } else { + sff_log("Total transfer length smaller than sum of all blocks, full block\n"); + dev->status &= ~2; + return 1; /* We have exhausted the data to transfer but there's more blocks left, break. */ + } } else if (transfer_length && dev->eot) { sff_log("Total transfer length greater than sum of all blocks\n"); dev->status |= 2; @@ -375,7 +381,7 @@ sff_bus_master_dma(uint8_t *data, int transfer_length, int out, void *priv) } else if (dev->eot) { sff_log("Regular EOT\n"); dev->status &= ~3; - return 1; /* We have regularly reached EOT - clear status and break. */ + return 3; /* We have regularly reached EOT - clear status and break. */ } else { /* We have more to transfer and there are blocks left, get next block. */ sff_bus_master_next_addr(dev); @@ -475,19 +481,22 @@ sff_reset(void *priv) #endif for (uint8_t i = 0; i < HDD_NUM; i++) { - if ((hdd[i].bus == HDD_BUS_ATAPI) && (hdd[i].ide_channel < 4) && hdd[i].priv) + if ((hdd[i].bus_type == HDD_BUS_ATAPI) && (hdd[i].ide_channel < 4) && hdd[i].priv) scsi_disk_reset((scsi_common_t *) hdd[i].priv); } 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) + 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 (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) + 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 (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) + 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); } @@ -575,8 +584,7 @@ sff_close(void *priv) static void * sff_init(UNUSED(const device_t *info)) { - sff8038i_t *dev = (sff8038i_t *) malloc(sizeof(sff8038i_t)); - memset(dev, 0, sizeof(sff8038i_t)); + sff8038i_t *dev = (sff8038i_t *) calloc(1, sizeof(sff8038i_t)); /* Make sure to only add IDE once. */ if (next_id == 0) @@ -608,7 +616,7 @@ const device_t sff8038i_device = { .init = sff_init, .close = sff_close, .reset = sff_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/disk/hdc_ide_um8673f.c b/src/disk/hdc_ide_um8673f.c index bc046dd26..b40595750 100644 --- a/src/disk/hdc_ide_um8673f.c +++ b/src/disk/hdc_ide_um8673f.c @@ -191,7 +191,7 @@ const device_t ide_um8886af_device = { .init = um8673f_init, .close = um8673f_close, .reset = um8673f_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -205,7 +205,7 @@ const device_t ide_um8673f_device = { .init = um8673f_init, .close = um8673f_close, .reset = um8673f_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/disk/hdc_ide_w83769f.c b/src/disk/hdc_ide_w83769f.c index 608d7a8a7..7829c5b92 100644 --- a/src/disk/hdc_ide_w83769f.c +++ b/src/disk/hdc_ide_w83769f.c @@ -10,7 +10,7 @@ * * Authors: Miran Grca, * - * Copyright 2020 Miran Grca. + * Copyright 2020-2025 Miran Grca. */ #include #include @@ -353,8 +353,7 @@ w83769f_close(void *priv) static void * w83769f_init(const device_t *info) { - w83769f_t *dev = (w83769f_t *) malloc(sizeof(w83769f_t)); - memset(dev, 0x00, sizeof(w83769f_t)); + w83769f_t *dev = (w83769f_t *) calloc(1, sizeof(w83769f_t)); dev->id = next_id | 0x60; @@ -410,7 +409,7 @@ const device_t ide_w83769f_vlb_device = { .init = w83769f_init, .close = w83769f_close, .reset = w83769f_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -424,7 +423,7 @@ const device_t ide_w83769f_vlb_34_device = { .init = w83769f_init, .close = w83769f_close, .reset = w83769f_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -438,7 +437,7 @@ const device_t ide_w83769f_pci_device = { .init = w83769f_init, .close = w83769f_close, .reset = w83769f_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -452,7 +451,7 @@ const device_t ide_w83769f_pci_34_device = { .init = w83769f_init, .close = w83769f_close, .reset = w83769f_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -466,9 +465,8 @@ const device_t ide_w83769f_pci_single_channel_device = { .init = w83769f_init, .close = w83769f_close, .reset = w83769f_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL }; - diff --git a/src/disk/hdc_st506_at.c b/src/disk/hdc_st506_at.c index 9e5b82336..ed7b29d1f 100644 --- a/src/disk/hdc_st506_at.c +++ b/src/disk/hdc_st506_at.c @@ -557,6 +557,7 @@ do_callback(void *priv) mfm->reset = 0; ui_sb_update_icon(SB_HDD | HDD_BUS_MFM, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_MFM, 0); return; } @@ -627,9 +628,9 @@ write_error: mfm->status |= STAT_DRQ; mfm->pos = 0; next_sector(mfm); - ui_sb_update_icon(SB_HDD | HDD_BUS_MFM, 1); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_MFM, 1); } else - ui_sb_update_icon(SB_HDD | HDD_BUS_MFM, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_MFM, 0); break; case CMD_VERIFY: @@ -657,7 +658,7 @@ write_error: mfm->status = STAT_READY | STAT_DSC; irq_raise(mfm); - ui_sb_update_icon(SB_HDD | HDD_BUS_MFM, 1); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_MFM, 1); break; case CMD_DIAGNOSE: @@ -744,12 +745,11 @@ mfm_init(UNUSED(const device_t *info)) 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)); + mfm = calloc(1, sizeof(mfm_t)); c = 0; for (uint8_t d = 0; d < HDD_NUM; d++) { - if ((hdd[d].bus == HDD_BUS_MFM) && (hdd[d].mfm_channel < MFM_NUM)) { + if ((hdd[d].bus_type == HDD_BUS_MFM) && (hdd[d].mfm_channel < MFM_NUM)) { loadhd(mfm, hdd[d].mfm_channel, d, hdd[d].fn); st506_at_log("WD1003(%d): (%s) geometry %d/%d/%d\n", c, hdd[d].fn, @@ -773,6 +773,7 @@ mfm_init(UNUSED(const device_t *info)) timer_add(&mfm->callback_timer, do_callback, mfm, 0); ui_sb_update_icon(SB_HDD | HDD_BUS_MFM, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_MFM, 0); return mfm; } @@ -791,17 +792,18 @@ mfm_close(void *priv) free(mfm); ui_sb_update_icon(SB_HDD | HDD_BUS_MFM, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_MFM, 0); } const device_t st506_at_wd1003_device = { .name = "WD1003 AT MFM/RLL Controller", .internal_name = "st506_at", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0, .init = mfm_init, .close = mfm_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/disk/hdc_st506_xt.c b/src/disk/hdc_st506_xt.c index 766b28086..b3a07fa5a 100644 --- a/src/disk/hdc_st506_xt.c +++ b/src/disk/hdc_st506_xt.c @@ -580,14 +580,14 @@ st506_callback(void *priv) (void) get_chs(dev, drive); st506_xt_log("ST506: FORMAT_DRIVE(%i) interleave=%i\n", dev->drive_sel, dev->command[4]); - ui_sb_update_icon(SB_HDD | HDD_BUS_MFM, 1); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_MFM, 1); timer_advance_u64(&dev->timer, ST506_TIME); dev->state = STATE_SEND_DATA; break; case STATE_SEND_DATA: /* wrong, but works */ if (!get_sector(dev, drive, &addr)) { - ui_sb_update_icon(SB_HDD | HDD_BUS_MFM, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_MFM, 0); st506_error(dev, dev->error); st506_complete(dev); return; @@ -604,7 +604,7 @@ st506_callback(void *priv) break; case STATE_SENT_DATA: - ui_sb_update_icon(SB_HDD | HDD_BUS_MFM, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_MFM, 0); st506_complete(dev); break; @@ -663,14 +663,14 @@ st506_callback(void *priv) st506_xt_log("ST506: FORMAT_%sTRACK(%i, %i/%i)\n", (dev->command[0] == CMD_FORMAT_BAD_TRACK) ? "BAD_" : "", dev->drive_sel, dev->cylinder, dev->head); - ui_sb_update_icon(SB_HDD | HDD_BUS_MFM, 1); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_MFM, 1); timer_advance_u64(&dev->timer, ST506_TIME); dev->state = STATE_SEND_DATA; break; case STATE_SEND_DATA: /* wrong, but works */ if (!get_sector(dev, drive, &addr)) { - ui_sb_update_icon(SB_HDD | HDD_BUS_MFM, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_MFM, 0); st506_error(dev, dev->error); st506_complete(dev); return; @@ -686,7 +686,7 @@ st506_callback(void *priv) break; case STATE_SENT_DATA: - ui_sb_update_icon(SB_HDD | HDD_BUS_MFM, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_MFM, 0); st506_complete(dev); break; @@ -828,7 +828,7 @@ read_error_sent: return; } - ui_sb_update_icon(SB_HDD | HDD_BUS_MFM, 1); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_MFM, 1); /* Set up the data transfer. */ dev->buff_pos = 0; @@ -865,7 +865,7 @@ read_error_sent: case STATE_RECEIVED_DATA: if (!get_sector(dev, drive, &addr)) { write_error: - ui_sb_update_icon(SB_HDD | HDD_BUS_MFM, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_MFM, 0); st506_error(dev, dev->error); st506_complete(dev); return; @@ -879,7 +879,7 @@ write_error: } if (--dev->count == 0) { - ui_sb_update_icon(SB_HDD | HDD_BUS_MFM, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_MFM, 0); st506_complete(dev); break; } @@ -1627,8 +1627,7 @@ st506_init(const device_t *info) int i; int c; - dev = (hdc_t *) malloc(sizeof(hdc_t)); - memset(dev, 0x00, sizeof(hdc_t)); + dev = (hdc_t *) calloc(1, sizeof(hdc_t)); dev->type = info->local & 255; /* Set defaults for the controller. */ @@ -1799,7 +1798,7 @@ st506_init(const device_t *info) st506_xt_log("ST506: looking for disks...\n"); #endif for (c = 0, i = 0; i < HDD_NUM; i++) { - if ((hdd[i].bus == HDD_BUS_MFM) && (hdd[i].mfm_channel < MFM_NUM)) { + if ((hdd[i].bus_type == HDD_BUS_MFM) && (hdd[i].mfm_channel < MFM_NUM)) { st506_xt_log("ST506: disk '%s' on channel %i\n", hdd[i].fn, hdd[i].mfm_channel); loadhd(dev, hdd[i].mfm_channel, i, hdd[i].fn); @@ -1915,335 +1914,356 @@ victor_v86p_available(void) // clang-format off static const device_config_t dtc_config[] = { { - .name = "bios_addr", - .description = "BIOS Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0xc8000, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "bios_addr", + .description = "BIOS Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0xc8000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Disabled", .value = 0x00000 }, { .description = "C800H", .value = 0xc8000 }, { .description = "CA00H", .value = 0xca000 }, { .description = "D800H", .value = 0xd8000 }, { .description = "F400H", .value = 0xf4000 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t st11_config[] = { { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x0320, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x0320, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "320H", .value = 0x0320 }, { .description = "324H", .value = 0x0324 }, { .description = "328H", .value = 0x0328 }, { .description = "32CH", .value = 0x032c }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 5, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 5, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "IRQ 2", .value = 2 }, { .description = "IRQ 5", .value = 5 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "bios_addr", - .description = "BIOS Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0xc8000, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "bios_addr", + .description = "BIOS Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0xc8000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Disabled", .value = 0x00000 }, { .description = "C800H", .value = 0xc8000 }, { .description = "D000H", .value = 0xd0000 }, { .description = "D800H", .value = 0xd8000 }, { .description = "E000H", .value = 0xe0000 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "revision", - .description = "BIOS Revision", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 19, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "revision", + .description = "BIOS Revision", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 19, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "v1.7", .value = 5 }, { .description = "v2.0", .value = 19 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t wd_config[] = { { - .name = "bios_addr", - .description = "BIOS Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0xc8000, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "bios_addr", + .description = "BIOS Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0xc8000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Disabled", .value = 0x00000 }, { .description = "C800H", .value = 0xc8000 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x0320, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x0320, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "320H", .value = 0x0320 }, { .description = "324H", .value = 0x0324 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 5, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 5, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "IRQ 2", .value = 2 }, { .description = "IRQ 5", .value = 5 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t wd_nobios_config[] = { { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x0320, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x0320, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "320H", .value = 0x0320 }, { .description = "324H", .value = 0x0324 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 5, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 5, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "IRQ 2", .value = 2 }, { .description = "IRQ 5", .value = 5 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t wd_rll_config[] = { { - .name = "bios_addr", - .description = "BIOS Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0xc8000, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "bios_addr", + .description = "BIOS Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0xc8000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Disabled", .value = 0x00000 }, { .description = "C800H", .value = 0xc8000 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x0320, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x0320, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "320H", .value = 0x0320 }, { .description = "324H", .value = 0x0324 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 5, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 5, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "IRQ 2", .value = 2 }, { .description = "IRQ 5", .value = 5 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "translate", - .description = "Translate 26 -> 17", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "translate", + .description = "Translate 26 -> 17", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Off", .value = 0 }, { .description = "On", .value = 1 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t wd1004a_config[] = { { - .name = "bios_addr", - .description = "BIOS Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0xc8000, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "bios_addr", + .description = "BIOS Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0xc8000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Disabled", .value = 0x00000 }, { .description = "C800H", .value = 0xc8000 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x0320, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x0320, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "320H", .value = 0x0320 }, { .description = "324H", .value = 0x0324 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 5, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 5, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "IRQ 2", .value = 2 }, { .description = "IRQ 5", .value = 5 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t wd1004_rll_config[] = { { - .name = "bios_addr", - .description = "BIOS Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0xc8000, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "bios_addr", + .description = "BIOS Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0xc8000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Disabled", .value = 0x00000 }, { .description = "C800H", .value = 0xc8000 }, { .description = "CA00H", .value = 0xca000 }, { .description = "CC00H", .value = 0xcc000 }, { .description = "CE00H", .value = 0xce000 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x0320, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x0320, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "320H", .value = 0x0320 }, { .description = "324H", .value = 0x0324 }, { .description = "328H", .value = 0x0328 }, { .description = "32CH", .value = 0x032c }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 5, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 5, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "IRQ 2", .value = 2 }, { .description = "IRQ 5", .value = 5 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "translate", - .description = "Translate 26 -> 17", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "translate", + .description = "Translate 26 -> 17", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Off", .value = 0 }, { .description = "On", .value = 1 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; @@ -2258,7 +2278,7 @@ const device_t st506_xt_xebec_device = { .init = st506_init, .close = st506_close, .reset = NULL, - { .available = xebec_available }, + .available = xebec_available, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2272,7 +2292,7 @@ const device_t st506_xt_wdxt_gen_device = { .init = st506_init, .close = st506_close, .reset = NULL, - { .available = wdxt_available }, + .available = wdxt_available, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2286,7 +2306,7 @@ const device_t st506_xt_dtc5150x_device = { .init = st506_init, .close = st506_close, .reset = NULL, - { .available = dtc5150x_available }, + .available = dtc5150x_available, .speed_changed = NULL, .force_redraw = NULL, .config = dtc_config @@ -2300,7 +2320,7 @@ const device_t st506_xt_st11_m_device = { .init = st506_init, .close = st506_close, .reset = NULL, - { .available = st11_m_available }, + .available = st11_m_available, .speed_changed = NULL, .force_redraw = NULL, .config = st11_config @@ -2314,7 +2334,7 @@ const device_t st506_xt_st11_r_device = { .init = st506_init, .close = st506_close, .reset = NULL, - { .available = st11_r_available }, + .available = st11_r_available, .speed_changed = NULL, .force_redraw = NULL, .config = st11_config @@ -2328,7 +2348,7 @@ const device_t st506_xt_wd1002a_wx1_device = { .init = st506_init, .close = st506_close, .reset = NULL, - { .available = wd1002a_wx1_available }, + .available = wd1002a_wx1_available, .speed_changed = NULL, .force_redraw = NULL, .config = wd_config @@ -2342,7 +2362,7 @@ const device_t st506_xt_wd1002a_wx1_nobios_device = { .init = st506_init, .close = st506_close, .reset = NULL, - { .available = wd1002a_wx1_available }, + .available = wd1002a_wx1_available, .speed_changed = NULL, .force_redraw = NULL, .config = wd_nobios_config @@ -2356,7 +2376,7 @@ const device_t st506_xt_wd1002a_27x_device = { .init = st506_init, .close = st506_close, .reset = NULL, - { .available = wd1002a_27x_available }, + .available = wd1002a_27x_available, .speed_changed = NULL, .force_redraw = NULL, .config = wd_rll_config @@ -2370,7 +2390,7 @@ const device_t st506_xt_wd1004a_wx1_device = { .init = st506_init, .close = st506_close, .reset = NULL, - { .available = wd1004a_wx1_available }, + .available = wd1004a_wx1_available, .speed_changed = NULL, .force_redraw = NULL, .config = wd1004a_config @@ -2384,7 +2404,7 @@ const device_t st506_xt_wd1004_27x_device = { .init = st506_init, .close = st506_close, .reset = NULL, - { .available = wd1004_27x_available }, + .available = wd1004_27x_available, .speed_changed = NULL, .force_redraw = NULL, .config = wd1004_rll_config @@ -2398,7 +2418,7 @@ const device_t st506_xt_wd1004a_27x_device = { .init = st506_init, .close = st506_close, .reset = NULL, - { .available = wd1004a_27x_available }, + .available = wd1004a_27x_available, .speed_changed = NULL, .force_redraw = NULL, .config = wd_rll_config @@ -2412,7 +2432,7 @@ const device_t st506_xt_victor_v86p_device = { .init = st506_init, .close = st506_close, .reset = NULL, - { .available = victor_v86p_available }, + .available = victor_v86p_available, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2426,7 +2446,7 @@ const device_t st506_xt_toshiba_t1200_device = { .init = st506_init, .close = st506_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/disk/hdc_xta.c b/src/disk/hdc_xta.c index a4ef45c43..d54f6ab0c 100644 --- a/src/disk/hdc_xta.c +++ b/src/disk/hdc_xta.c @@ -385,7 +385,7 @@ do_format(hdc_t *dev, drive_t *drive, dcb_t *dcb) dev->sector = 0; /* Activate the status icon. */ - ui_sb_update_icon(SB_HDD | HDD_BUS_XTA, 1); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_XTA, 1); do_fmt: /* @@ -426,7 +426,7 @@ do_fmt: } /* De-activate the status icon. */ - ui_sb_update_icon(SB_HDD | HDD_BUS_XTA, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_XTA, 0); } /* Execute the DCB we just received. */ @@ -631,7 +631,7 @@ read_error: case STATE_RECV: /* Activate the status icon. */ - ui_sb_update_icon(SB_HDD | HDD_BUS_XTA, 1); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_XTA, 1); do_recv: /* Ready to transfer the data in. */ dev->state = STATE_RDATA; @@ -680,7 +680,7 @@ do_recv: if (get_sector(dev, drive, &addr)) { write_error: /* De-activate the status icon. */ - ui_sb_update_icon(SB_HDD | HDD_BUS_XTA, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_XTA, 0); dev->comp |= COMP_ERR; set_intr(dev); @@ -697,7 +697,7 @@ write_error: dev->buf_idx = 0; if (--dev->count == 0) { /* De-activate the status icon. */ - ui_sb_update_icon(SB_HDD | HDD_BUS_XTA, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_XTA, 0); set_intr(dev); return; @@ -1000,8 +1000,7 @@ xta_init(const device_t *info) int max = XTA_NUM; /* Allocate and initialize device block. */ - dev = malloc(sizeof(hdc_t)); - memset(dev, 0x00, sizeof(hdc_t)); + dev = calloc(1, sizeof(hdc_t)); dev->type = info->local; /* Do per-controller-type setup. */ @@ -1038,7 +1037,7 @@ xta_init(const device_t *info) /* Load any disks for this device class. */ c = 0; for (uint8_t i = 0; i < HDD_NUM; i++) { - if ((hdd[i].bus == HDD_BUS_XTA) && (hdd[i].xta_channel < max)) { + if ((hdd[i].bus_type == HDD_BUS_XTA) && (hdd[i].xta_channel < max)) { drive = &dev->drives[hdd[i].xta_channel]; if (!hdd_image_load(i)) { @@ -1108,91 +1107,108 @@ xta_close(void *priv) static const device_config_t wdxt150_config[] = { // clang-format off { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x0320, - .file_filter = "", - .spinner = { 0 }, /*W2*/ - .selection = { + .name = "bios_rev", + .description = "BIOS Revision", + .type = CONFIG_BIOS, + .default_string = "rev_1", + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .bios = { + { + .name = "Revision 1.0", + .internal_name = "rev_1", + .bios_type = BIOS_NORMAL, + .files_no = 1, + .local = 0, + .size = 8192, + .files = { WD_REV_1_BIOS_FILE, "" } + }, + { + .name = "Revision 2.0", + .internal_name = "rev_2", + .bios_type = BIOS_NORMAL, + .files_no = 1, + .local = 0, + .size = 8192, + .files = { WD_REV_2_BIOS_FILE, "" } + }, + { .files_no = 0 } + }, + }, + { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x0320, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "320H", .value = 0x0320 }, { .description = "324H", .value = 0x0324 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 5, - .file_filter = "", - .spinner = { 0 }, /*W3*/ - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 5, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "IRQ 5", .value = 5 }, { .description = "IRQ 4", .value = 4 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "bios_addr", - .description = "BIOS Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0xc8000, - .file_filter = "", - .spinner = { 0 }, /*W1*/ - .selection = { + .name = "bios_addr", + .description = "BIOS Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0xc8000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "C800H", .value = 0xc8000 }, { .description = "CA00H", .value = 0xca000 }, { .description = "" } }, - }, - { - .name = "bios_rev", - .description = "BIOS Revision", - .type = CONFIG_BIOS, - .default_string = "rev_1", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, /*W1*/ - .bios = { - { .name = "Revision 1.0", .internal_name = "rev_1", .bios_type = BIOS_NORMAL, - .files_no = 1, .local = 0, .size = 8192, .files = { WD_REV_1_BIOS_FILE, "" } }, - { .name = "Revision 2.0", .internal_name = "rev_2", .bios_type = BIOS_NORMAL, - .files_no = 1, .local = 0, .size = 8192, .files = { WD_REV_2_BIOS_FILE, "" } }, - { .files_no = 0 } - }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format off }; const device_t xta_wdxt150_device = { - .name = "WDXT-150 XTA Fixed Disk Controller", + .name = "WDXT-150 XTA Fixed Disk Controller", .internal_name = "xta_wdxt150", - .flags = DEVICE_ISA, - .local = 0, - .init = xta_init, - .close = xta_close, - .reset = NULL, - { .available = NULL /*xta_available*/ }, + .flags = DEVICE_ISA, + .local = 0, + .init = xta_init, + .close = xta_close, + .reset = NULL, + .available = NULL /*xta_available*/, .speed_changed = NULL, - .force_redraw = NULL, - .config = wdxt150_config + .force_redraw = NULL, + .config = wdxt150_config }; const device_t xta_hd20_device = { - .name = "EuroPC HD20 Fixed Disk Controller", + .name = "EuroPC HD20 Fixed Disk Controller", .internal_name = "xta_hd20", - .flags = DEVICE_ISA, - .local = 1, - .init = xta_init, - .close = xta_close, - .reset = NULL, - { .available = NULL }, + .flags = DEVICE_ISA, + .local = 1, + .init = xta_init, + .close = xta_close, + .reset = NULL, + .available = NULL, .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL + .force_redraw = NULL, + .config = NULL }; diff --git a/src/disk/hdc_xtide.c b/src/disk/hdc_xtide.c index 9899e2a0f..1c8e2c8da 100644 --- a/src/disk/hdc_xtide.c +++ b/src/disk/hdc_xtide.c @@ -41,11 +41,13 @@ #include <86box/mem.h> #include <86box/rom.h> #include <86box/timer.h> +#include <86box/nvr.h> #include <86box/device.h> #include <86box/hdc.h> #include <86box/hdc_ide.h> #include <86box/plat_unused.h> +#define ROM_PATH_TINY "roms/hdd/xtide/ide_tiny.bin" #define ROM_PATH_XT "roms/hdd/xtide/ide_xt.bin" #define ROM_PATH_XTP "roms/hdd/xtide/ide_xtp.bin" #define ROM_PATH_AT "roms/hdd/xtide/ide_at.bin" @@ -57,6 +59,7 @@ typedef struct xtide_t { void *ide_board; uint8_t data_high; rom_t bios_rom; + char nvr_path[64]; } xtide_t; static void @@ -132,35 +135,46 @@ xtide_read(uint16_t port, void *priv) static void * xtide_init(const device_t *info) { - xtide_t *xtide = malloc(sizeof(xtide_t)); + xtide_t *xtide = calloc(1, sizeof(xtide_t)); - memset(xtide, 0x00, sizeof(xtide_t)); - - rom_init(&xtide->bios_rom, - device_get_bios_file(info, device_get_config_bios("bios"), 0), - 0xc8000, 0x2000, 0x1fff, 0, MEM_MAPPING_EXTERNAL); + rom_init(&xtide->bios_rom, + device_get_bios_file(info, device_get_config_bios("bios"), 0), + device_get_config_hex20("bios_addr"), 0x2000, 0x1fff, 0, MEM_MAPPING_EXTERNAL); xtide->ide_board = ide_xtide_init(); - io_sethandler(0x0300, 16, + io_sethandler(device_get_config_hex16("base"), 16, xtide_read, NULL, NULL, xtide_write, NULL, NULL, xtide); + uint8_t rom_writes_enabled = device_get_config_int("rom_writes_enabled"); + + if (rom_writes_enabled) { + mem_mapping_set_write_handler(&xtide->bios_rom.mapping, rom_write, rom_writew, rom_writel); + sprintf(xtide->nvr_path, "xtide_%i.nvr", device_get_instance()); + FILE *fp = nvr_fopen(xtide->nvr_path, "rb"); + if (fp != NULL) { + fread(xtide->bios_rom.rom, 1, 0x2000, fp); + fclose(fp); + } + } + return xtide; } static void * xtide_at_init(const device_t *info) { - xtide_t *xtide = malloc(sizeof(xtide_t)); + xtide_t *xtide = calloc(1, sizeof(xtide_t)); - memset(xtide, 0x00, sizeof(xtide_t)); + rom_init(&xtide->bios_rom, + device_get_bios_file(info, device_get_config_bios("bios"), 0), + 0xc8000, 0x2000, 0x1fff, 0, MEM_MAPPING_EXTERNAL); - rom_init(&xtide->bios_rom, - device_get_bios_file(info, device_get_config_bios("bios"), 0), - 0xc8000, 0x2000, 0x1fff, 0, MEM_MAPPING_EXTERNAL); - - device_add(&ide_isa_2ch_device); + if (info->local == 1) + device_add(&ide_isa_2ch_device); + else + device_add(&ide_isa_device); return xtide; } @@ -168,9 +182,7 @@ xtide_at_init(const device_t *info) static void * xtide_acculogic_init(UNUSED(const device_t *info)) { - xtide_t *xtide = malloc(sizeof(xtide_t)); - - memset(xtide, 0x00, sizeof(xtide_t)); + xtide_t *xtide = calloc(1, sizeof(xtide_t)); rom_init(&xtide->bios_rom, ROM_PATH_PS2, 0xc8000, 0x2000, 0x1fff, 0, MEM_MAPPING_EXTERNAL); @@ -195,6 +207,14 @@ xtide_close(void *priv) { xtide_t *xtide = (xtide_t *) priv; + if (xtide->nvr_path[0] != 0x00) { + FILE *fp = nvr_fopen(xtide->nvr_path, "wb"); + if (fp != NULL) { + fwrite(xtide->bios_rom.rom, 1, 0x2000, fp); + fclose(fp); + } + } + free(xtide); ide_xtide_close(); @@ -203,14 +223,15 @@ xtide_close(void *priv) static void * xtide_at_ps2_init(UNUSED(const device_t *info)) { - xtide_t *xtide = malloc(sizeof(xtide_t)); - - memset(xtide, 0x00, sizeof(xtide_t)); + xtide_t *xtide = calloc(1, sizeof(xtide_t)); rom_init(&xtide->bios_rom, ROM_PATH_PS2AT, 0xc8000, 0x2000, 0x1fff, 0, MEM_MAPPING_EXTERNAL); - device_add(&ide_isa_2ch_device); + if (info->local == 1) + device_add(&ide_isa_2ch_device); + else + device_add(&ide_isa_device); return xtide; } @@ -229,49 +250,173 @@ xtide_at_close(void *priv) free(xtide); } +// clang-format off static const device_config_t xtide_config[] = { - // clang-format off { - .name = "bios", - .description = "BIOS Revision", - .type = CONFIG_BIOS, + .name = "bios", + .description = "BIOS Revision", + .type = CONFIG_BIOS, .default_string = "xt", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, /*W1*/ - .bios = { - { .name = "Regular XT", .internal_name = "xt", .bios_type = BIOS_NORMAL, - .files_no = 1, .local = 0, .size = 8192, .files = { ROM_PATH_XT, "" } }, - { .name = "XT+ (V20/V30/8018x)", .internal_name = "xt_plus", .bios_type = BIOS_NORMAL, - .files_no = 1, .local = 0, .size = 8192, .files = { ROM_PATH_XTP, "" } }, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { + { + .name = "Regular XT", + .internal_name = "xt", + .bios_type = BIOS_NORMAL, + .files_no = 1, + .local = 0, + .size = 8192, + .files = { ROM_PATH_XT, "" } + }, + { + .name = "XT+ (V20/V30/8018x)", + .internal_name = "xt_plus", + .bios_type = BIOS_NORMAL, + .files_no = 1, + .local = 0, + .size = 8192, + .files = { ROM_PATH_XTP, "" } + }, { .files_no = 0 } }, }, + { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x300, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "200H", .value = 0x200 }, + { .description = "210H", .value = 0x210 }, + { .description = "220H", .value = 0x220 }, + { .description = "230H", .value = 0x230 }, + { .description = "240H", .value = 0x240 }, + { .description = "250H", .value = 0x250 }, + { .description = "260H", .value = 0x260 }, + { .description = "270H", .value = 0x270 }, + { .description = "280H", .value = 0x280 }, + { .description = "290H", .value = 0x290 }, + { .description = "2A0H", .value = 0x2a0 }, + { .description = "2B0H", .value = 0x2b0 }, + { .description = "2C0H", .value = 0x2c0 }, + { .description = "2D0H", .value = 0x2d0 }, + { .description = "2E0H", .value = 0x2e0 }, + { .description = "2F0H", .value = 0x2f0 }, + { .description = "300H", .value = 0x300 }, + { .description = "310H", .value = 0x310 }, + { .description = "320H", .value = 0x320 }, + { .description = "330H", .value = 0x330 }, + { .description = "340H", .value = 0x340 }, + { .description = "350H", .value = 0x350 }, + { .description = "360H", .value = 0x360 }, + { .description = "370H", .value = 0x370 }, + { .description = "380H", .value = 0x380 }, + { .description = "390H", .value = 0x390 }, + { .description = "3A0H", .value = 0x3a0 }, + { .description = "3B0H", .value = 0x3b0 }, + { .description = "3C0H", .value = 0x3c0 }, + { .description = "3D0H", .value = 0x3d0 }, + { .description = "3E0H", .value = 0x3e0 }, + { .description = "3F0H", .value = 0x3f0 }, + { NULL } + }, + .bios = { { 0 } } + }, + { + .name = "rom_writes_enabled", + .description = "Enable BIOS extension ROM Writes", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { + .name = "bios_addr", + .description = "BIOS Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0xd0000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Disabled", .value = 0x00000 }, +#if 0 + // Supported on XT IDE Deluxe By Monotech + { .description = "C000H", .value = 0xc0000 }, + { .description = "C200H", .value = 0xc2000 }, + { .description = "C400H", .value = 0xc4000 }, + { .description = "C600H", .value = 0xc6000 }, +#endif + { .description = "C800H", .value = 0xc8000 }, + { .description = "CA00H", .value = 0xca000 }, + { .description = "CC00H", .value = 0xcc000 }, + { .description = "CE00H", .value = 0xce000 }, + { .description = "D000H", .value = 0xd0000 }, + { .description = "D200H", .value = 0xd2000 }, + { .description = "D400H", .value = 0xd4000 }, + { .description = "D600H", .value = 0xd6000 }, + { .description = "D800H", .value = 0xd8000 }, + { .description = "DA00H", .value = 0xda000 }, + { .description = "DC00H", .value = 0xdc000 }, + { .description = "DE00H", .value = 0xde000 }, +#if 0 + // Supported on VCFed rev 2 + { .description = "E000H", .value = 0xe0000 }, + { .description = "E400H", .value = 0xe4000 }, + { .description = "E800H", .value = 0xe8000 }, + { .description = "EC00H", .value = 0xec000 }, +#endif + { .description = "" } + }, + .bios = { { 0 } } + }, { .name = "", .description = "", .type = CONFIG_END } - // clang-format on }; static const device_config_t xtide_at_config[] = { - // clang-format off { - .name = "bios", - .description = "BIOS Revision", - .type = CONFIG_BIOS, + .name = "bios", + .description = "BIOS Revision", + .type = CONFIG_BIOS, .default_string = "at", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, /*W1*/ - .bios = { - { .name = "Regular AT", .internal_name = "at", .bios_type = BIOS_NORMAL, - .files_no = 1, .local = 0, .size = 8192, .files = { ROM_PATH_AT, "" } }, - { .name = "386", .internal_name = "at_386", .bios_type = BIOS_NORMAL, - .files_no = 1, .local = 0, .size = 8192, .files = { ROM_PATH_AT_386, "" } }, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { + { + .name = "Regular AT", + .internal_name = "at", + .bios_type = BIOS_NORMAL, + .files_no = 1, + .local = 0, + .size = 8192, + .files = { ROM_PATH_AT, "" } + }, + { + .name = "386", + .internal_name = "at_386", + .bios_type = BIOS_NORMAL, + .files_no = 1, + .local = 0, + .size = 8192, + .files = { ROM_PATH_AT_386, "" } + }, { .files_no = 0 } }, }, { .name = "", .description = "", .type = CONFIG_END } - // clang-format on }; +// clang-format on const device_t xtide_device = { .name = "PC/XT XTIDE", @@ -281,21 +426,35 @@ const device_t xtide_device = { .init = xtide_init, .close = xtide_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = xtide_config }; const device_t xtide_at_device = { - .name = "PC/AT XTIDE", - .internal_name = "xtide_at", - .flags = DEVICE_ISA | DEVICE_AT, + .name = "PC/AT XTIDE (Primary Only)", + .internal_name = "xtide_at_1ch", + .flags = DEVICE_ISA16, .local = 0, .init = xtide_at_init, .close = xtide_at_close, .reset = NULL, - { .available = NULL }, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = xtide_at_config +}; + +const device_t xtide_at_2ch_device = { + .name = "PC/AT XTIDE", + .internal_name = "xtide_at", + .flags = DEVICE_ISA16, + .local = 1, + .init = xtide_at_init, + .close = xtide_at_close, + .reset = NULL, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = xtide_at_config @@ -309,21 +468,35 @@ const device_t xtide_acculogic_device = { .init = xtide_acculogic_init, .close = xtide_close, .reset = NULL, - { .available = xtide_acculogic_available }, + .available = xtide_acculogic_available, .speed_changed = NULL, .force_redraw = NULL, .config = NULL }; const device_t xtide_at_ps2_device = { - .name = "PS/2 AT XTIDE (1.1.5)", - .internal_name = "xtide_at_ps2", - .flags = DEVICE_ISA | DEVICE_AT, + .name = "PS/2 AT XTIDE (1.1.5) (Primary Only)", + .internal_name = "xtide_at_ps2_1ch", + .flags = DEVICE_ISA16, .local = 0, .init = xtide_at_ps2_init, .close = xtide_at_close, .reset = NULL, - { .available = xtide_at_ps2_available }, + .available = xtide_at_ps2_available, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t xtide_at_ps2_2ch_device = { + .name = "PS/2 AT XTIDE (1.1.5)", + .internal_name = "xtide_at_ps2", + .flags = DEVICE_ISA16, + .local = 1, + .init = xtide_at_ps2_init, + .close = xtide_at_close, + .reset = NULL, + .available = xtide_at_ps2_available, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/disk/hdd.c b/src/disk/hdd.c index b861b5e50..e051cc841 100644 --- a/src/disk/hdd.c +++ b/src/disk/hdd.c @@ -123,7 +123,7 @@ hdd_bus_to_string(int bus, UNUSED(int cdrom)) int hdd_is_valid(int c) { - if (hdd[c].bus == HDD_BUS_DISABLED) + if (hdd[c].bus_type == HDD_BUS_DISABLED) return 0; if (strlen(hdd[c].fn) == 0) @@ -407,50 +407,48 @@ hdd_zones_init(hard_disk_t *hdd) static hdd_preset_t hdd_speed_presets[] = { // clang-format off - { .name = "RAM Disk (max. speed)", .internal_name = "ramdisk", .rcache_num_seg = 16, .rcache_seg_size = 128, .max_multiple = 32 }, - { .name = "[1989] 3500 RPM", .internal_name = "1989_3500rpm", .zones = 1, .avg_spt = 35, .heads = 2, .rpm = 3500, .full_stroke_ms = 40, .track_seek_ms = 8, .rcache_num_seg = 1, .rcache_seg_size = 16, .max_multiple = 8 }, - { .name = "[1992] 3600 RPM", .internal_name = "1992_3600rpm", .zones = 1, .avg_spt = 45, .heads = 2, .rpm = 3600, .full_stroke_ms = 30, .track_seek_ms = 6, .rcache_num_seg = 4, .rcache_seg_size = 16, .max_multiple = 8 }, - { .name = "[1994] 4500 RPM", .internal_name = "1994_4500rpm", .zones = 8, .avg_spt = 80, .heads = 4, .rpm = 4500, .full_stroke_ms = 26, .track_seek_ms = 5, .rcache_num_seg = 4, .rcache_seg_size = 32, .max_multiple = 16 }, - { .name = "[1996] 5400 RPM", .internal_name = "1996_5400rpm", .zones = 16, .avg_spt = 135, .heads = 4, .rpm = 5400, .full_stroke_ms = 24, .track_seek_ms = 3, .rcache_num_seg = 4, .rcache_seg_size = 64, .max_multiple = 16 }, - { .name = "[1997] 5400 RPM", .internal_name = "1997_5400rpm", .zones = 16, .avg_spt = 185, .heads = 6, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 2.5, .rcache_num_seg = 8, .rcache_seg_size = 64, .max_multiple = 32 }, - { .name = "[1998] 5400 RPM", .internal_name = "1998_5400rpm", .zones = 16, .avg_spt = 300, .heads = 8, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 32 }, - { .name = "[2000] 7200 RPM", .internal_name = "2000_7200rpm", .zones = 16, .avg_spt = 350, .heads = 6, .rpm = 7200, .full_stroke_ms = 15, .track_seek_ms = 2, .rcache_num_seg = 16, .rcache_seg_size = 128, .max_multiple = 32 }, - { .name = "[PIO IDE] IBM WDA-L42", .internal_name = "WDAL42", .model = "IBM-WDA-L42", .zones = 1, .avg_spt = 85, .heads = 2, .rpm = 3600, .full_stroke_ms = 33, .track_seek_ms = 2.5, .rcache_num_seg = 1, .rcache_seg_size = 32, .max_multiple = 1 }, + { .name = "[Generic] RAM Disk (max. speed)", .internal_name = "ramdisk", .rcache_num_seg = 16, .rcache_seg_size = 128, .max_multiple = 32 }, + { .name = "[Generic] 1989 (3500 RPM)", .internal_name = "1989_3500rpm", .zones = 1, .avg_spt = 35, .heads = 2, .rpm = 3500, .full_stroke_ms = 40, .track_seek_ms = 8, .rcache_num_seg = 1, .rcache_seg_size = 16, .max_multiple = 8 }, + { .name = "[Generic] 1992 (3600 RPM)", .internal_name = "1992_3600rpm", .zones = 1, .avg_spt = 45, .heads = 2, .rpm = 3600, .full_stroke_ms = 30, .track_seek_ms = 6, .rcache_num_seg = 4, .rcache_seg_size = 16, .max_multiple = 8 }, + { .name = "[Generic] 1994 (4500 RPM)", .internal_name = "1994_4500rpm", .zones = 8, .avg_spt = 80, .heads = 4, .rpm = 4500, .full_stroke_ms = 26, .track_seek_ms = 5, .rcache_num_seg = 4, .rcache_seg_size = 32, .max_multiple = 16 }, + { .name = "[Generic] 1996 (5400 RPM)", .internal_name = "1996_5400rpm", .zones = 16, .avg_spt = 135, .heads = 4, .rpm = 5400, .full_stroke_ms = 24, .track_seek_ms = 3, .rcache_num_seg = 4, .rcache_seg_size = 64, .max_multiple = 16 }, + { .name = "[Generic] 1997 (5400 RPM)", .internal_name = "1997_5400rpm", .zones = 16, .avg_spt = 185, .heads = 6, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 2.5, .rcache_num_seg = 8, .rcache_seg_size = 64, .max_multiple = 32 }, + { .name = "[Generic] 1998 (5400 RPM)", .internal_name = "1998_5400rpm", .zones = 16, .avg_spt = 300, .heads = 8, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 32 }, + { .name = "[Generic] 2000 (7200 RPM)", .internal_name = "2000_7200rpm", .zones = 16, .avg_spt = 350, .heads = 6, .rpm = 7200, .full_stroke_ms = 15, .track_seek_ms = 2, .rcache_num_seg = 16, .rcache_seg_size = 128, .max_multiple = 32 }, + { .name = "[PIO IDE] IBM WDA-L42", .internal_name = "WDAL42", .model = "WDA-L42", .zones = 1, .avg_spt = 85, .heads = 2, .rpm = 3600, .full_stroke_ms = 33, .track_seek_ms = 2.5, .rcache_num_seg = 1, .rcache_seg_size = 32, .max_multiple = 1 }, { .name = "[ATA-1] Conner CP3024", .internal_name = "CP3024", .model = "Conner Peripherals 20MB - CP3024", .zones = 1, .avg_spt = 33, .heads = 2, .rpm = 3500, .full_stroke_ms = 50, .track_seek_ms = 8, .rcache_num_seg = 1, .rcache_seg_size = 8, .max_multiple = 8 }, // Needed for GRiDcase 1520 to work { .name = "[ATA-1] Conner CP3044", .internal_name = "CP3044", .model = "Conner Peripherals 40MB - CP3044", .zones = 1, .avg_spt = 40, .heads = 2, .rpm = 3500, .full_stroke_ms = 50, .track_seek_ms = 8, .rcache_num_seg = 1, .rcache_seg_size = 8, .max_multiple = 8 }, // Needed for GRiDcase 1520 to work { .name = "[ATA-1] Conner CP3104", .internal_name = "CP3104", .model = "Conner Peripherals 104MB - CP3104", .zones = 1, .avg_spt = 33, .heads = 8, .rpm = 3500, .full_stroke_ms = 45, .track_seek_ms = 8, .rcache_num_seg = 4, .rcache_seg_size = 8, .max_multiple = 8 }, // Needed for GRiDcase 1520 to work - { .name = "[ATA-1] HP Kittyhawk", .internal_name = "C3014A", .model = "HP C3014A", .zones = 6, .avg_spt = 180, .heads = 3, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 3, .rcache_num_seg = 4, .rcache_seg_size = 16, .max_multiple = 8 }, - { .name = "[ATA-1] IBM H3256-A3", .internal_name = "H3256A3", .model = "IBM-H3256-A3", .zones = 1, .avg_spt = 140, .heads = 2, .rpm = 3600, .full_stroke_ms = 32, .track_seek_ms = 4, .rcache_num_seg = 4, .rcache_seg_size = 96, .max_multiple = 8 }, - { .name = "[ATA-1] IBM H3342-A4", .internal_name = "H3342A4", .model = "IBM-H3342-A4", .zones = 1, .avg_spt = 140, .heads = 2, .rpm = 3600, .full_stroke_ms = 30, .track_seek_ms = 4, .rcache_num_seg = 4, .rcache_seg_size = 96, .max_multiple = 8 }, - { .name = "[ATA-1] Kalok KL343", .internal_name = "KL343", .model = "KALOK KL-343", .zones = 1, .avg_spt = 280, .heads = 6, .rpm = 3600, .full_stroke_ms = 50, .track_seek_ms = 2, .rcache_num_seg = 1, .rcache_seg_size = 8, .max_multiple = 8 }, - { .name = "[ATA-1] Kalok KL3100", .internal_name = "KL3100", .model = "KALOK KL-3100", .zones = 1, .avg_spt = 200, .heads = 6, .rpm = 3662, .full_stroke_ms = 50, .track_seek_ms = 2, .rcache_num_seg = 1, .rcache_seg_size = 32, .max_multiple = 8 }, - { .name = "[ATA-1] Maxtor 7060AT", .internal_name = "7060AT", .model = "Maxtor 7060AT", .zones = 1, .avg_spt = 162, .heads = 2, .rpm = 3524, .full_stroke_ms = 30, .track_seek_ms = 3.6, .rcache_num_seg = 1, .rcache_seg_size = 64, .max_multiple = 8 }, - { .name = "[ATA-1] Maxtor 7131AT", .internal_name = "7131AT", .model = "Maxtor 7131AT", .zones = 2, .avg_spt = 154, .heads = 2, .rpm = 3551, .full_stroke_ms = 27, .track_seek_ms = 4.5, .rcache_num_seg = 1, .rcache_seg_size = 64, .max_multiple = 8 }, - { .name = "[ATA-1] Maxtor 7213AT", .internal_name = "7213AT", .model = "Maxtor 7213AT", .zones = 4, .avg_spt = 155, .heads = 4, .rpm = 3551, .full_stroke_ms = 28, .track_seek_ms = 6.5, .rcache_num_seg = 1, .rcache_seg_size = 64, .max_multiple = 8 }, - { .name = "[ATA-1] Maxtor 7245AT", .internal_name = "7245AT", .model = "Maxtor 7245AT", .zones = 4, .avg_spt = 149, .heads = 4, .rpm = 3551, .full_stroke_ms = 27, .track_seek_ms = 4.4, .rcache_num_seg = 8, .rcache_seg_size = 64, .max_multiple = 8 }, - { .name = "[ATA-1] Quantum ProDrive LPS 105", .internal_name = "LPS105AT", .model = "QUANTUM PRODRIVE 105", .zones = 1, .avg_spt = 170, .heads = 2, .rpm = 3662, .full_stroke_ms = 45, .track_seek_ms = 5, .rcache_num_seg = 1, .rcache_seg_size = 64, .max_multiple = 8 }, - { .name = "[ATA-1] Quantum ProDrive LPS 120AT", .internal_name = "GM12A012", .model = "QUANTUM PRODRIVE 120AT", .zones = 1, .avg_spt = 150, .heads = 2, .rpm = 3605, .full_stroke_ms = 45, .track_seek_ms = 4, .rcache_num_seg = 1, .rcache_seg_size = 64, .max_multiple = 8 }, - { .name = "[ATA-1] Seagate ST3243A", .internal_name = "ST3243A", .model = "ST3243A", .zones = 1, .avg_spt = 140, .heads = 4, .rpm = 3811, .full_stroke_ms = 32, .track_seek_ms = 4, .rcache_num_seg = 4, .rcache_seg_size = 32, .max_multiple = 8 }, - { .name = "[ATA-1] Western Digital Caviar 140", .internal_name = "WDAC140", .model = "WDC WDAC140-50", .zones = 4, .avg_spt = 170, .heads = 2, .rpm = 3551, .full_stroke_ms = 28, .track_seek_ms = 6, .rcache_num_seg = 8, .rcache_seg_size = 8, .max_multiple = 8 }, - { .name = "[ATA-1] Western Digital Caviar 280", .internal_name = "WDAC280", .model = "WDC WDAC280-00", .zones = 4, .avg_spt = 170, .heads = 4, .rpm = 3595, .full_stroke_ms = 28, .track_seek_ms = 6, .rcache_num_seg = 8, .rcache_seg_size = 32, .max_multiple = 8 }, - { .name = "[ATA-1] Western Digital Caviar 1210", .internal_name = "WDAC1210", .model = "WDC WDAC1210-21F", .zones = 4, .avg_spt = 130, .heads = 2, .rpm = 3314, .full_stroke_ms = 33, .track_seek_ms = 4, .rcache_num_seg = 4, .rcache_seg_size = 128, .max_multiple = 8 }, - { .name = "[ATA-1] Western Digital Caviar 2120", .internal_name = "WDAC2120", .model = "WDC WDAC2120-00M", .zones = 4, .avg_spt = 140, .heads = 2, .rpm = 3605, .full_stroke_ms = 28, .track_seek_ms = 2.8, .rcache_num_seg = 8, .rcache_seg_size = 32, .max_multiple = 8 }, - { .name = "[ATA-2] IBM DBOA-2720", .internal_name = "DBOA2720", .model = "IBM-DBOA-2720", .zones = 2, .avg_spt = 135, .heads = 2, .rpm = 4000, .full_stroke_ms = 30, .track_seek_ms = 5, .rcache_num_seg = 4, .rcache_seg_size = 64, .max_multiple = 8 }, - { .name = "[ATA-2] IBM DeskStar 4 (DCAA-32880)", .internal_name = "DCAA32880", .model = "IBM-DCAA-32880", .zones = 8, .avg_spt = 85, .heads = 2, .rpm = 5400, .full_stroke_ms = 19, .track_seek_ms = 1.7, .rcache_num_seg = 4, .rcache_seg_size = 96, .max_multiple = 16 }, - { .name = "[ATA-2] IBM DeskStar 4 (DCAA-33610)", .internal_name = "DCAA33610", .model = "IBM-DCAA-33610", .zones = 8, .avg_spt = 85, .heads = 3, .rpm = 5400, .full_stroke_ms = 19, .track_seek_ms = 1.7, .rcache_num_seg = 4, .rcache_seg_size = 96, .max_multiple = 16 }, - { .name = "[ATA-2] IBM DeskStar 4 (DCAA-34330)", .internal_name = "DCAA34330", .model = "IBM-DCAA-34330", .zones = 8, .avg_spt = 85, .heads = 3, .rpm = 5400, .full_stroke_ms = 19, .track_seek_ms = 1.7, .rcache_num_seg = 4, .rcache_seg_size = 96, .max_multiple = 16 }, - { .name = "[ATA-2] Maxtor 7540AV", .internal_name = "7540AV", .model = "Maxtor 7540AV", .zones = 2, .avg_spt = 120, .heads = 4, .rpm = 3551, .full_stroke_ms = 31, .track_seek_ms = 4.3, .rcache_num_seg = 4, .rcache_seg_size = 32, .max_multiple = 8 }, - { .name = "[ATA-2] Maxtor 7546AT", .internal_name = "7546AT", .model = "Maxtor 7546AT", .zones = 2, .avg_spt = 100, .heads = 4, .rpm = 4500, .full_stroke_ms = 28, .track_seek_ms = 2.3, .rcache_num_seg = 4, .rcache_seg_size = 256, .max_multiple = 8 }, - { .name = "[ATA-2] Maxtor 7850AV", .internal_name = "7850AV", .model = "Maxtor 7850AV", .zones = 4, .avg_spt = 120, .heads = 4, .rpm = 3551, .full_stroke_ms = 31, .track_seek_ms = 3.7, .rcache_num_seg = 4, .rcache_seg_size = 64, .max_multiple = 8 }, - { .name = "[ATA-2] Maxtor 71336AP", .internal_name = "71336AP", .model = "Maxtor 71336AP", .zones = 4, .avg_spt = 105, .heads = 4, .rpm = 4480, .full_stroke_ms = 12, .track_seek_ms = 3.4, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-1] Conner CFS420A", .internal_name = "CFS420A", .model = "Conner Peripherals 420MB - CFS420A", .zones = 1, .avg_spt = 40, .heads = 2, .rpm = 3600, .full_stroke_ms = 33, .track_seek_ms = 3, .rcache_num_seg = 4, .rcache_seg_size = 32, .max_multiple = 8 }, + { .name = "[ATA-1] HP Kittyhawk", .internal_name = "C3014A", .model = "HP C3014A", .zones = 6, .avg_spt = 80, .heads = 3, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 3, .rcache_num_seg = 4, .rcache_seg_size = 16, .max_multiple = 8 }, + { .name = "[ATA-1] IBM H3256-A3", .internal_name = "H3256A3", .model = "H3256-A3", .zones = 1, .avg_spt = 40, .heads = 2, .rpm = 3600, .full_stroke_ms = 32, .track_seek_ms = 4, .rcache_num_seg = 4, .rcache_seg_size = 96, .max_multiple = 8 }, + { .name = "[ATA-1] IBM H3342-A4", .internal_name = "H3342A4", .model = "H3342-A4", .zones = 1, .avg_spt = 40, .heads = 2, .rpm = 3600, .full_stroke_ms = 30, .track_seek_ms = 4, .rcache_num_seg = 4, .rcache_seg_size = 96, .max_multiple = 8 }, + { .name = "[ATA-1] Kalok KL343", .internal_name = "KL343", .model = "KALOK KL-343", .zones = 1, .avg_spt = 80, .heads = 6, .rpm = 3600, .full_stroke_ms = 50, .track_seek_ms = 2, .rcache_num_seg = 1, .rcache_seg_size = 8, .max_multiple = 8 }, + { .name = "[ATA-1] Kalok KL3100", .internal_name = "KL3100", .model = "KALOK KL-3100", .zones = 1, .avg_spt = 100, .heads = 6, .rpm = 3662, .full_stroke_ms = 50, .track_seek_ms = 2, .rcache_num_seg = 1, .rcache_seg_size = 32, .max_multiple = 8 }, + { .name = "[ATA-1] Maxtor 7060AT", .internal_name = "7060AT", .model = "Maxtor 7060 AT", .zones = 1, .avg_spt = 62, .heads = 2, .rpm = 3524, .full_stroke_ms = 30, .track_seek_ms = 3.6, .rcache_num_seg = 1, .rcache_seg_size = 64, .max_multiple = 8 }, + { .name = "[ATA-1] Maxtor 7131AT", .internal_name = "7131AT", .model = "Maxtor 7131 AT", .zones = 2, .avg_spt = 54, .heads = 2, .rpm = 3551, .full_stroke_ms = 27, .track_seek_ms = 4.5, .rcache_num_seg = 1, .rcache_seg_size = 64, .max_multiple = 8 }, + { .name = "[ATA-1] Maxtor 7213AT", .internal_name = "7213AT", .model = "Maxtor 7213 AT", .zones = 4, .avg_spt = 55, .heads = 4, .rpm = 3551, .full_stroke_ms = 28, .track_seek_ms = 6.5, .rcache_num_seg = 1, .rcache_seg_size = 64, .max_multiple = 8 }, + { .name = "[ATA-1] Maxtor 7245AT", .internal_name = "7245AT", .model = "Maxtor 7245 AT", .zones = 4, .avg_spt = 49, .heads = 4, .rpm = 3551, .full_stroke_ms = 27, .track_seek_ms = 4.4, .rcache_num_seg = 8, .rcache_seg_size = 64, .max_multiple = 8 }, + { .name = "[ATA-1] Quantum ProDrive LPS 105", .internal_name = "LPS105AT", .model = "QUANTUM PRODRIVE 105", .zones = 1, .avg_spt = 70, .heads = 2, .rpm = 3662, .full_stroke_ms = 45, .track_seek_ms = 5, .rcache_num_seg = 1, .rcache_seg_size = 64, .max_multiple = 8 }, + { .name = "[ATA-1] Quantum ProDrive LPS 120AT", .internal_name = "GM12A012", .model = "QUANTUM PRODRIVE 120AT", .zones = 1, .avg_spt = 50, .heads = 2, .rpm = 3605, .full_stroke_ms = 45, .track_seek_ms = 4, .rcache_num_seg = 1, .rcache_seg_size = 64, .max_multiple = 8 }, + { .name = "[ATA-1] Seagate ST3243A", .internal_name = "ST3243A", .model = "ST3243A", .zones = 1, .avg_spt = 40, .heads = 4, .rpm = 3811, .full_stroke_ms = 32, .track_seek_ms = 4, .rcache_num_seg = 4, .rcache_seg_size = 32, .max_multiple = 8 }, + { .name = "[ATA-1] Western Digital Caviar 140", .internal_name = "AC140", .model = "WDC AC140", .zones = 4, .avg_spt = 70, .heads = 2, .rpm = 3551, .full_stroke_ms = 28, .track_seek_ms = 6, .rcache_num_seg = 8, .rcache_seg_size = 8, .max_multiple = 8 }, + { .name = "[ATA-1] Western Digital Caviar 280", .internal_name = "AC280", .model = "WDC AC280", .zones = 4, .avg_spt = 70, .heads = 4, .rpm = 3595, .full_stroke_ms = 28, .track_seek_ms = 6, .rcache_num_seg = 8, .rcache_seg_size = 32, .max_multiple = 8 }, + { .name = "[ATA-1] Western Digital Caviar 1210", .internal_name = "AC1210", .model = "WDC AC1210F", .zones = 4, .avg_spt = 30, .heads = 2, .rpm = 3314, .full_stroke_ms = 33, .track_seek_ms = 4, .rcache_num_seg = 4, .rcache_seg_size = 128, .max_multiple = 8 }, + { .name = "[ATA-1] Western Digital Caviar 2120", .internal_name = "AC2120", .model = "WDC AC2120M", .zones = 4, .avg_spt = 40, .heads = 2, .rpm = 3605, .full_stroke_ms = 28, .track_seek_ms = 2.8, .rcache_num_seg = 8, .rcache_seg_size = 32, .max_multiple = 8 }, + { .name = "[ATA-2] IBM DBOA-2720", .internal_name = "DBOA2720", .model = "DBOA-2720", .zones = 2, .avg_spt = 135, .heads = 2, .rpm = 4000, .full_stroke_ms = 30, .track_seek_ms = 5, .rcache_num_seg = 4, .rcache_seg_size = 64, .max_multiple = 8 }, + { .name = "[ATA-2] IBM DeskStar 4 (DCAA-32880)", .internal_name = "DCAA32880", .model = "IBM-DCAA-32880", .zones = 8, .avg_spt = 185, .heads = 2, .rpm = 5400, .full_stroke_ms = 19, .track_seek_ms = 1.7, .rcache_num_seg = 4, .rcache_seg_size = 96, .max_multiple = 16 }, + { .name = "[ATA-2] IBM DeskStar 4 (DCAA-33610)", .internal_name = "DCAA33610", .model = "IBM-DCAA-33610", .zones = 8, .avg_spt = 185, .heads = 3, .rpm = 5400, .full_stroke_ms = 19, .track_seek_ms = 1.7, .rcache_num_seg = 4, .rcache_seg_size = 96, .max_multiple = 16 }, + { .name = "[ATA-2] IBM DeskStar 4 (DCAA-34330)", .internal_name = "DCAA34330", .model = "IBM-DCAA-34330", .zones = 8, .avg_spt = 185, .heads = 3, .rpm = 5400, .full_stroke_ms = 19, .track_seek_ms = 1.7, .rcache_num_seg = 4, .rcache_seg_size = 96, .max_multiple = 16 }, + { .name = "[ATA-2] Maxtor 7540AV", .internal_name = "7540AV", .model = "Maxtor 7540 AV", .zones = 2, .avg_spt = 120, .heads = 4, .rpm = 3551, .full_stroke_ms = 31, .track_seek_ms = 4.3, .rcache_num_seg = 4, .rcache_seg_size = 32, .max_multiple = 8 }, + { .name = "[ATA-2] Maxtor 7546AT", .internal_name = "7546AT", .model = "Maxtor 7546 AT", .zones = 2, .avg_spt = 100, .heads = 4, .rpm = 4500, .full_stroke_ms = 28, .track_seek_ms = 2.3, .rcache_num_seg = 4, .rcache_seg_size = 256, .max_multiple = 8 }, + { .name = "[ATA-2] Maxtor 7850AV", .internal_name = "7850AV", .model = "Maxtor 7850 AV", .zones = 4, .avg_spt = 120, .heads = 4, .rpm = 3551, .full_stroke_ms = 31, .track_seek_ms = 3.7, .rcache_num_seg = 4, .rcache_seg_size = 64, .max_multiple = 8 }, + { .name = "[ATA-2] Maxtor 71336AP", .internal_name = "71336AP", .model = "Maxtor 71336 AP", .zones = 4, .avg_spt = 105, .heads = 4, .rpm = 4480, .full_stroke_ms = 12, .track_seek_ms = 3.4, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, { .name = "[ATA-2] Quantum Bigfoot 1.2AT", .internal_name = "BF12A011", .model = "QUANTUM BIGFOOT BF1.2A", .zones = 2, .avg_spt = 155, .heads = 2, .rpm = 3600, .full_stroke_ms = 30, .track_seek_ms = 3.5, .rcache_num_seg = 4, .rcache_seg_size = 128, .max_multiple = 16 }, { .name = "[ATA-2] Quantum Bigfoot (CY4320A)", .internal_name = "CY4320A", .model = "QUANTUM BIGFOOT_CY4320A", .zones = 2, .avg_spt = 130, .heads = 2, .rpm = 4000, .full_stroke_ms = 29, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, // from Hardcore Windows NT Final Segment by Kugee { .name = "[ATA-2] Quantum Fireball 640AT", .internal_name = "FB64A341", .model = "QUANTUM FIREBALL 640AT", .zones = 2, .avg_spt = 120, .heads = 2, .rpm = 5400, .full_stroke_ms = 24, .track_seek_ms = 3.1, .rcache_num_seg = 4, .rcache_seg_size = 128, .max_multiple = 8 }, { .name = "[ATA-2] Quantum Fireball TM1080AT", .internal_name = "TM10A462", .model = "QUANTUM FIREBALL TM1.0A", .zones = 2, .avg_spt = 120, .heads = 2, .rpm = 4500, .full_stroke_ms = 21, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 8 }, { .name = "[ATA-2] Quantum Fireball TM1.2AT", .internal_name = "TM12A012", .model = "QUANTUM FIREBALL TM1.2A", .zones = 4, .avg_spt = 120, .heads = 2, .rpm = 4500, .full_stroke_ms = 21, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 8 }, - { .name = "[ATA-2] Quantum Fireball ST3.2AT", .internal_name = "ST32A461", .model = "QUANTUM FIREBALL ST3.2A", .zones = 4, .avg_spt = 100, .heads = 4, .rpm = 5400, .full_stroke_ms = 21, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-2] Quantum Fireball CR4.3AT", .internal_name = "CR43A013", .model = "QUANTUM FIREBALL CR4.3A", .zones = 2, .avg_spt = 110, .heads = 2, .rpm = 5400, .full_stroke_ms = 22, .track_seek_ms = 2.5, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, - { .name = "[ATA-2] Quantum Fireball EX5.1AT", .internal_name = "EX51A012", .model = "QUANTUM FIREBALL EX5.1A", .zones = 8, .avg_spt = 110, .heads = 4, .rpm = 5400, .full_stroke_ms = 22, .track_seek_ms = 2.5, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, { .name = "[ATA-2] Samsung PLS-31274A", .internal_name = "PLS31274A", .model = "SAMSUNG PLS-31274A", .zones = 4, .avg_spt = 110, .heads = 4, .rpm = 4500, .full_stroke_ms = 45, .track_seek_ms = 4.5, .rcache_num_seg = 4, .rcache_seg_size = 256, .max_multiple = 8 }, { .name = "[ATA-2] Samsung Winner-1", .internal_name = "WNR31601A", .model = "SAMSUNG WNR-31601A", .zones = 8, .avg_spt = 110, .heads = 4, .rpm = 5400, .full_stroke_ms = 22, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, { .name = "[ATA-2] Seagate Medalist (ST3780A)", .internal_name = "ST3780A", .model = "ST3780A", .zones = 8, .avg_spt = 120, .heads = 4, .rpm = 4500, .full_stroke_ms = 25, .track_seek_ms = 3.5, .rcache_num_seg = 4, .rcache_seg_size = 256, .max_multiple = 16 }, @@ -460,63 +458,89 @@ static hdd_preset_t hdd_speed_presets[] = { { .name = "[ATA-2] Seagate Medalist 545xe", .internal_name = "ST3660A", .model = "ST3660A", .zones = 4, .avg_spt = 130, .heads = 4, .rpm = 3811, .full_stroke_ms = 34, .track_seek_ms = 3.4, .rcache_num_seg = 8, .rcache_seg_size = 120, .max_multiple = 8 }, { .name = "[ATA-2] Seagate Medalist 640xe", .internal_name = "ST3630A", .model = "ST3630A", .zones = 4, .avg_spt = 130, .heads = 4, .rpm = 3811, .full_stroke_ms = 34, .track_seek_ms = 3.5, .rcache_num_seg = 8, .rcache_seg_size = 120, .max_multiple = 8 }, { .name = "[ATA-2] Seagate Medalist 850xe", .internal_name = "ST3850A", .model = "ST3850A", .zones = 8, .avg_spt = 150, .heads = 4, .rpm = 3811, .full_stroke_ms = 34, .track_seek_ms = 3.8, .rcache_num_seg = 8, .rcache_seg_size = 120, .max_multiple = 8 }, - { .name = "[ATA-2] Seagate Medalist 1270SL", .internal_name = "ST51270A", .model = "ST51270A", .zones = 8, .avg_spt = 105, .heads = 3, .rpm = 5736, .full_stroke_ms = 25, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-2] Seagate Medalist 3240", .internal_name = "ST33240A", .model = "ST33240A", .zones = 16, .avg_spt = 125, .heads = 8, .rpm = 4500, .full_stroke_ms = 25, .track_seek_ms = 2.5, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-2] Seagate Medalist 1270SL", .internal_name = "ST51270A", .model = "ST51270A", .zones = 8, .avg_spt = 205, .heads = 3, .rpm = 5736, .full_stroke_ms = 25, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-2] Seagate Medalist 3240", .internal_name = "ST33240A", .model = "ST33240A", .zones = 16, .avg_spt = 225, .heads = 8, .rpm = 4500, .full_stroke_ms = 25, .track_seek_ms = 2.5, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, { .name = "[ATA-2] Toshiba MK2101MAN (HDD2616)", .internal_name = "HDD2616", .model = "TOSHIBA MK2101MAN", .zones = 8, .avg_spt = 130, .heads = 10, .rpm = 4200, .full_stroke_ms = 36, .track_seek_ms = 3, .rcache_num_seg = 4, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-2] Western Digital Caviar 2540", .internal_name = "WDAC2540", .model = "WDC WDAC2540-00H", .zones = 4, .avg_spt = 250, .heads = 2, .rpm = 4500, .full_stroke_ms = 12, .track_seek_ms = 4, .rcache_num_seg = 4, .rcache_seg_size = 128, .max_multiple = 8 }, - { .name = "[ATA-2] Western Digital Caviar 2850", .internal_name = "WDAC2850", .model = "WDC WDAC2850-00F", .zones = 4, .avg_spt = 230, .heads = 2, .rpm = 5200, .full_stroke_ms = 12, .track_seek_ms = 4, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 8 }, - { .name = "[ATA-2] Western Digital Caviar 11000", .internal_name = "WDAC11000", .model = "WDC WDAC11000-00H", .zones = 4, .avg_spt = 120, .heads = 2, .rpm = 5200, .full_stroke_ms = 12, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 8 }, - { .name = "[ATA-2] Western Digital Caviar 21200", .internal_name = "WDAC21200", .model = "WDC WDAC21200-00H", .zones = 4, .avg_spt = 110, .heads = 4, .rpm = 5200, .full_stroke_ms = 39, .track_seek_ms = 3, .rcache_num_seg = 4, .rcache_seg_size = 128, .max_multiple = 8 }, - { .name = "[ATA-2] Western Digital Caviar 21600", .internal_name = "WDAC21600", .model = "WDC WDAC21600-00H", .zones = 8, .avg_spt = 140, .heads = 4, .rpm = 5200, .full_stroke_ms = 30, .track_seek_ms = 3, .rcache_num_seg = 4, .rcache_seg_size = 128, .max_multiple = 8 }, - { .name = "[ATA-2] Western Digital Caviar 22000", .internal_name = "AC22000", .model = "WDC AC22000-32LA", .zones = 8, .avg_spt = 130, .heads = 3, .rpm = 5200, .full_stroke_ms = 33, .track_seek_ms = 3.5, .rcache_num_seg = 4, .rcache_seg_size = 128, .max_multiple = 8 }, - { .name = "[ATA-2] Western Digital Caviar 22100", .internal_name = "WDAC22100", .model = "WDC WDAC22100-18H", .zones = 8, .avg_spt = 140, .heads = 4, .rpm = 5200, .full_stroke_ms = 30, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-2] Western Digital Caviar 31200", .internal_name = "WDAC31200", .model = "WDC WDAC31200-00F", .zones = 8, .avg_spt = 110, .heads = 4, .rpm = 4500, .full_stroke_ms = 12, .track_seek_ms = 4, .rcache_num_seg = 8, .rcache_seg_size = 64, .max_multiple = 16 }, - { .name = "[ATA-3] Fujitsu MPA3017AT", .internal_name = "MPA3017AT", .model = "FUJITSU MPA3017AT", .zones = 5, .avg_spt = 95, .heads = 2, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 3.2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-3] Fujitsu MPA3026AT", .internal_name = "MPA3026AT", .model = "FUJITSU MPA3026AT", .zones = 8, .avg_spt = 95, .heads = 3, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 3.2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-3] Fujitsu MPA3035AT", .internal_name = "MPA3035AT", .model = "FUJITSU MPA3035AT", .zones = 11, .avg_spt = 95, .heads = 4, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 3.2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-3] Fujitsu MPA3043AT", .internal_name = "MPA3043AT", .model = "FUJITSU MPA3043AT", .zones = 15, .avg_spt = 95, .heads = 5, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 3.2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-3] Fujitsu MPA3052AT", .internal_name = "MPA3052AT", .model = "FUJITSU MPA3052AT", .zones = 16, .avg_spt = 95, .heads = 6, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 3.2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-3] Samsung Voyager 6", .internal_name = "SV0844A", .model = "SAMSUNG SV0844A", .zones = 8, .avg_spt = 105, .heads = 4, .rpm = 5400, .full_stroke_ms = 22, .track_seek_ms = 2, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-3] Samsung Winner 5X", .internal_name = "WU33205A", .model = "SAMSUNG WU33205A", .zones = 16, .avg_spt = 100, .heads = 4, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-2] Western Digital Caviar 2540", .internal_name = "AC2540", .model = "WDC AC2540H", .zones = 4, .avg_spt = 150, .heads = 2, .rpm = 4500, .full_stroke_ms = 12, .track_seek_ms = 4, .rcache_num_seg = 4, .rcache_seg_size = 128, .max_multiple = 8 }, + { .name = "[ATA-2] Western Digital Caviar 2850", .internal_name = "AC2850", .model = "WDC AC2850F", .zones = 4, .avg_spt = 130, .heads = 2, .rpm = 5200, .full_stroke_ms = 12, .track_seek_ms = 4, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 8 }, + { .name = "[ATA-2] Western Digital Caviar 11000", .internal_name = "AC11000", .model = "WDC AC11000H", .zones = 4, .avg_spt = 120, .heads = 2, .rpm = 5200, .full_stroke_ms = 12, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 8 }, + { .name = "[ATA-2] Western Digital Caviar 21200", .internal_name = "AC21200", .model = "WDC AC21200H", .zones = 4, .avg_spt = 110, .heads = 4, .rpm = 5200, .full_stroke_ms = 39, .track_seek_ms = 3, .rcache_num_seg = 4, .rcache_seg_size = 128, .max_multiple = 8 }, + { .name = "[ATA-2] Western Digital Caviar 21600", .internal_name = "AC21600", .model = "WDC AC21600H", .zones = 8, .avg_spt = 140, .heads = 4, .rpm = 5200, .full_stroke_ms = 30, .track_seek_ms = 3, .rcache_num_seg = 4, .rcache_seg_size = 128, .max_multiple = 8 }, + { .name = "[ATA-2] Western Digital Caviar 22000", .internal_name = "AC22000", .model = "WDC AC22000LA", .zones = 8, .avg_spt = 130, .heads = 3, .rpm = 5200, .full_stroke_ms = 33, .track_seek_ms = 3.5, .rcache_num_seg = 4, .rcache_seg_size = 128, .max_multiple = 8 }, + { .name = "[ATA-2] Western Digital Caviar 22100", .internal_name = "AC22100", .model = "WDC AC22100H", .zones = 8, .avg_spt = 140, .heads = 4, .rpm = 5200, .full_stroke_ms = 30, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-2] Western Digital Caviar 31200", .internal_name = "AC31200", .model = "WDC AC31200F", .zones = 8, .avg_spt = 210, .heads = 4, .rpm = 4500, .full_stroke_ms = 12, .track_seek_ms = 4, .rcache_num_seg = 8, .rcache_seg_size = 64, .max_multiple = 16 }, + { .name = "[ATA-3] Conner CFS1275A", .internal_name = "CFS1275A", .model = "Conner Peripherals 1275MB - CFS1275A", .zones = 4, .avg_spt = 130, .heads = 2, .rpm = 4500, .full_stroke_ms = 25, .track_seek_ms = 3.8, .rcache_num_seg = 4, .rcache_seg_size = 64, .max_multiple = 16 }, // Either ATA-2 or ATA-3 + { .name = "[ATA-3] Fujitsu MPA3017AT", .internal_name = "MPA3017AT", .model = "FUJITSU MPA3017AT", .zones = 5, .avg_spt = 195, .heads = 2, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 3.2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-3] Fujitsu MPA3026AT", .internal_name = "MPA3026AT", .model = "FUJITSU MPA3026AT", .zones = 8, .avg_spt = 195, .heads = 3, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 3.2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-3] Fujitsu MPA3035AT", .internal_name = "MPA3035AT", .model = "FUJITSU MPA3035AT", .zones = 11, .avg_spt = 195, .heads = 4, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 3.2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-3] Fujitsu MPA3043AT", .internal_name = "MPA3043AT", .model = "FUJITSU MPA3043AT", .zones = 15, .avg_spt = 195, .heads = 5, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 3.2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-3] Fujitsu MPA3052AT", .internal_name = "MPA3052AT", .model = "FUJITSU MPA3052AT", .zones = 16, .avg_spt = 195, .heads = 6, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 3.2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-3] Samsung Voyager 6", .internal_name = "SV0844A", .model = "SAMSUNG SV0844A", .zones = 8, .avg_spt = 205, .heads = 4, .rpm = 5400, .full_stroke_ms = 22, .track_seek_ms = 2, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-3] Samsung Winner 5X", .internal_name = "WU33205A", .model = "SAMSUNG WU33205A", .zones = 16, .avg_spt = 200, .heads = 4, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-3] Seagate Medalist 636", .internal_name = "ST3636A", .model = "Seagate Technology 636MB - ST3636A", .zones = 2, .avg_spt = 130, .heads = 2, .rpm = 4500, .full_stroke_ms = 25, .track_seek_ms = 3.8, .rcache_num_seg = 4, .rcache_seg_size = 64, .max_multiple = 8 }, + { .name = "[ATA-3] Seagate Medalist 1082", .internal_name = "ST31082A", .model = "Seagate Technology 1082MB - ST31082A", .zones = 4, .avg_spt = 130, .heads = 3, .rpm = 4500, .full_stroke_ms = 25, .track_seek_ms = 3.8, .rcache_num_seg = 4, .rcache_seg_size = 64, .max_multiple = 8 }, + { .name = "[ATA-3] Seagate Medalist 1276", .internal_name = "ST31276A", .model = "Seagate Technology 1275MB - ST31276A", .zones = 4, .avg_spt = 130, .heads = 3, .rpm = 4500, .full_stroke_ms = 25, .track_seek_ms = 3.8, .rcache_num_seg = 4, .rcache_seg_size = 64, .max_multiple = 16 }, { .name = "[ATA-3] Seagate Medalist 1720", .internal_name = "ST31720A", .model = "ST31720A", .zones = 4, .avg_spt = 120, .heads = 4, .rpm = 4500, .full_stroke_ms = 25, .track_seek_ms = 2, .rcache_num_seg = 4, .rcache_seg_size = 128, .max_multiple = 16 }, { .name = "[ATA-3] Seagate Medalist 2132", .internal_name = "ST32132A", .model = "ST32132A", .zones = 8, .avg_spt = 125, .heads = 6, .rpm = 4500, .full_stroke_ms = 30, .track_seek_ms = 2.3, .rcache_num_seg = 8, .rcache_seg_size = 120, .max_multiple = 16 }, - { .name = "[ATA-3] Western Digital Caviar 21700", .internal_name = "WDAC21700", .model = "WDC WDAC21700-40H", .zones = 8, .avg_spt = 85, .heads = 3, .rpm = 5200, .full_stroke_ms = 21, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, // Apple Computer OEM only, not retail version - { .name = "[ATA-4] Fujitsu MPB3021AT", .internal_name = "MPB3021AT", .model = "FUJITSU MPB3021AT", .zones = 7, .avg_spt = 100, .heads = 3, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 2.5, .rcache_num_seg = 8, .rcache_seg_size = 256, .max_multiple = 16 }, - { .name = "[ATA-4] Fujitsu MPD3043AT", .internal_name = "MPD3043AT", .model = "FUJITSU MPD3043AT", .zones = 5, .avg_spt = 95, .heads = 2, .rpm = 5400, .full_stroke_ms = 29, .track_seek_ms = 1.5, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, - { .name = "[ATA-4] Fujitsu MPD3064AT", .internal_name = "MPD3064AT", .model = "FUJITSU MPD3064AT", .zones = 7, .avg_spt = 95, .heads = 3, .rpm = 5400, .full_stroke_ms = 30, .track_seek_ms = 1.5, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, - { .name = "[ATA-4] Fujitsu MPD3084AT", .internal_name = "MPD3084AT", .model = "FUJITSU MPD3084AT", .zones = 7, .avg_spt = 95, .heads = 4, .rpm = 5400, .full_stroke_ms = 19, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 16 }, - { .name = "[ATA-4] Fujitsu MPE3064AT", .internal_name = "MPE3064AT", .model = "FUJITSU MPE3064AT", .zones = 7, .avg_spt = 95, .heads = 2, .rpm = 5400, .full_stroke_ms = 30, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-4] Maxtor DiamondMax 2160", .internal_name = "86480D6", .model = "Maxtor 86480D6", .zones = 8, .avg_spt = 97, .heads = 4, .rpm = 5200, .full_stroke_ms = 18, .track_seek_ms = 1, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-4] Maxtor DiamondMax 2880", .internal_name = "90432D3", .model = "Maxtor 90432D3", .zones = 16, .avg_spt = 90, .heads = 3, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 1, .rcache_num_seg = 8, .rcache_seg_size = 256, .max_multiple = 32 }, - { .name = "[ATA-4] Maxtor DiamondMax 3400", .internal_name = "90644D3", .model = "Maxtor 90644D3", .zones = 16, .avg_spt = 90, .heads = 3, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 0.9, .rcache_num_seg = 8, .rcache_seg_size = 256, .max_multiple = 32 }, - { .name = "[ATA-4] Maxtor DiamondMax 4320 (90432D2)", .internal_name = "90432D2", .model = "Maxtor 90432D2", .zones = 16, .avg_spt = 90, .heads = 2, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 0.9, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, - { .name = "[ATA-4] Maxtor DiamondMax 4320 (90845D4)", .internal_name = "90845D4", .model = "Maxtor 90845D4", .zones = 16, .avg_spt = 90, .heads = 3, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 0.9, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, - { .name = "[ATA-4] Maxtor DiamondMax Plus 6800 (90683U2)", .internal_name = "90683U2", .model = "Maxtor 90683U2", .zones = 16, .avg_spt = 90, .heads = 2, .rpm = 7200, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, - { .name = "[ATA-4] Maxtor DiamondMax Plus 6800 (91024U3)", .internal_name = "91024U3", .model = "Maxtor 91024U3", .zones = 16, .avg_spt = 90, .heads = 3, .rpm = 7200, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, - { .name = "[ATA-4] Maxtor DiamondMax Plus 6800 (91366U4)", .internal_name = "91366U4", .model = "Maxtor 91366U4", .zones = 16, .avg_spt = 90, .heads = 4, .rpm = 7200, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, - { .name = "[ATA-4] Maxtor DiamondMax Plus 6800 (92049U6)", .internal_name = "92049U6", .model = "Maxtor 92049U6", .zones = 16, .avg_spt = 90, .heads = 6, .rpm = 7200, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, - { .name = "[ATA-4] Maxtor DiamondMax Plus 6800 (92732U8)", .internal_name = "92732U8", .model = "Maxtor 92732U8", .zones = 16, .avg_spt = 90, .heads = 8, .rpm = 7200, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, - { .name = "[ATA-4] Quantum Bigfoot TX4.3AT", .internal_name = "TX043A011", .model = "QUANTUM BIGFOOT TX4.3A", .zones = 2, .avg_spt = 120, .heads = 2, .rpm = 4000, .full_stroke_ms = 30, .track_seek_ms = 2.5, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 32 }, - { .name = "[ATA-4] Seagate Medalist 2122", .internal_name = "ST32122A", .model = "ST32122A", .zones = 16, .avg_spt = 115, .heads = 2, .rpm = 4500, .full_stroke_ms = 23, .track_seek_ms = 3.8, .rcache_num_seg = 16, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-4] Seagate Medalist 3321", .internal_name = "ST33221A", .model = "ST33221A", .zones = 16, .avg_spt = 110, .heads = 4, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 1.7, .rcache_num_seg = 16, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-4] Seagate Medalist 4321", .internal_name = "ST34321A", .model = "ST34321A", .zones = 16, .avg_spt = 110, .heads = 4, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 2.2, .rcache_num_seg = 16, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-4] Seagate Medalist 6531", .internal_name = "ST36531A", .model = "ST36531A", .zones = 16, .avg_spt = 115, .heads = 6, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 1.7, .rcache_num_seg = 16, .rcache_seg_size = 128, .max_multiple = 16 }, - { .name = "[ATA-4] Seagate Medalist 8420", .internal_name = "ST38420A", .model = "ST38420A", .zones = 16, .avg_spt = 90, .heads = 2, .rpm = 5400, .full_stroke_ms = 16, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-4] Toshiba MK4006MAV", .internal_name = "MK4006MAV", .model = "TOSHIBA MK4006MAV", .zones = 8, .avg_spt = 130, .heads = 6, .rpm = 4200, .full_stroke_ms = 25, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-4] Western Digital Caviar 14300", .internal_name = "AC14300", .model = "WDC AC14300-00RT", .zones = 16, .avg_spt = 95, .heads = 2, .rpm = 5400, .full_stroke_ms = 21, .track_seek_ms = 5.5, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, - { .name = "[ATA-4] Western Digital Caviar 23200", .internal_name = "AC23200", .model = "WDC AC23200-00LB", .zones = 16, .avg_spt = 110, .heads = 4, .rpm = 5400, .full_stroke_ms = 21, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 256, .max_multiple = 32 }, - { .name = "[ATA-4] Western Digital Caviar 26400", .internal_name = "AC26400", .model = "WDC AC26400-00RN", .zones = 16, .avg_spt = 95, .heads = 5, .rpm = 5400, .full_stroke_ms = 21, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-4] Western Digital Caviar 33200", .internal_name = "AC33200", .model = "WDC AC33200-00LA", .zones = 16, .avg_spt = 110, .heads = 5, .rpm = 5200, .full_stroke_ms = 40, .track_seek_ms = 3, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, - { .name = "[ATA-5] IBM Travelstar 6GN", .internal_name = "DARA206000", .model = "IBM-DARA-206000", .zones = 12, .avg_spt = 92, .heads = 2, .rpm = 4200, .full_stroke_ms = 31, .track_seek_ms = 4, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-5] IBM Travelstar 9GN", .internal_name = "DARA209000", .model = "IBM-DARA-209000", .zones = 12, .avg_spt = 92, .heads = 3, .rpm = 4200, .full_stroke_ms = 31, .track_seek_ms = 4, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-5] IBM/Hitachi Travelstar 12GN", .internal_name = "DARA212000", .model = "IBM-DARA-212000", .zones = 12, .avg_spt = 92, .heads = 4, .rpm = 4200, .full_stroke_ms = 31, .track_seek_ms = 4, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, // Either Hitachi or IBM OEM - { .name = "[ATA-5] Maxtor DiamondMax VL 17", .internal_name = "90871U2", .model = "Maxtor 90871U2", .zones = 16, .avg_spt = 90, .heads = 3, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 0.9, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, - { .name = "[ATA-5] Maxtor DiamondMax VL 20", .internal_name = "91021U2", .model = "Maxtor 91021U2", .zones = 16, .avg_spt = 95, .heads = 2, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-5] Samsung SpinPoint V6800 (SV0682D)", .internal_name = "SV0682D", .model = "SAMSUNG SV0682D", .zones = 8, .avg_spt = 95, .heads = 2, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 1.3, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-5] Samsung SpinPoint V6800 (SV1023D)", .internal_name = "SV1023D", .model = "SAMSUNG SV1023D", .zones = 8, .avg_spt = 95, .heads = 3, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 1.3, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-5] Seagate U8 - 4.3gb", .internal_name = "ST34313A", .model = "ST34313A", .zones = 16, .avg_spt = 89, .heads = 1, .rpm = 5400, .full_stroke_ms = 25, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-5] Seagate U8 - 8.4gb", .internal_name = "ST38410A", .model = "ST38410A", .zones = 16, .avg_spt = 89, .heads = 2, .rpm = 5400, .full_stroke_ms = 25, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, - { .name = "[ATA-5] Western Digital Caviar 102AA", .internal_name = "WD102AA", .model = "WDC WD102AA-00ANA0", .zones = 16, .avg_spt = 95, .heads = 8, .rpm = 5400, .full_stroke_ms = 12, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-3] Western Digital Caviar 21700", .internal_name = "AC21700", .model = "WDC AC21700H", .zones = 8, .avg_spt = 185, .heads = 3, .rpm = 5200, .full_stroke_ms = 21, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, // Apple Computer OEM only, not retail version + { .name = "[ATA-4] Fujitsu MPB3021AT", .internal_name = "MPB3021AT", .model = "FUJITSU MPB3021AT", .zones = 7, .avg_spt = 200, .heads = 3, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 2.5, .rcache_num_seg = 8, .rcache_seg_size = 256, .max_multiple = 16 }, + { .name = "[ATA-4] Fujitsu MPD3043AT", .internal_name = "MPD3043AT", .model = "FUJITSU MPD3043AT", .zones = 5, .avg_spt = 195, .heads = 2, .rpm = 5400, .full_stroke_ms = 29, .track_seek_ms = 1.5, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, + { .name = "[ATA-4] Fujitsu MPD3064AT", .internal_name = "MPD3064AT", .model = "FUJITSU MPD3064AT", .zones = 7, .avg_spt = 195, .heads = 3, .rpm = 5400, .full_stroke_ms = 30, .track_seek_ms = 1.5, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, + { .name = "[ATA-4] Fujitsu MPD3084AT", .internal_name = "MPD3084AT", .model = "FUJITSU MPD3084AT", .zones = 7, .avg_spt = 195, .heads = 4, .rpm = 5400, .full_stroke_ms = 19, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 16 }, + { .name = "[ATA-4] Fujitsu MPE3064AT", .internal_name = "MPE3064AT", .model = "FUJITSU MPE3064AT", .zones = 7, .avg_spt = 295, .heads = 2, .rpm = 5400, .full_stroke_ms = 30, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-4] Maxtor DiamondMax 2160", .internal_name = "86480D6", .model = "Maxtor 86480D6", .zones = 8, .avg_spt = 197, .heads = 4, .rpm = 5200, .full_stroke_ms = 18, .track_seek_ms = 1, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-4] Maxtor DiamondMax 2880", .internal_name = "90432D3", .model = "Maxtor 90432D3", .zones = 16, .avg_spt = 190, .heads = 3, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 1, .rcache_num_seg = 8, .rcache_seg_size = 256, .max_multiple = 32 }, + { .name = "[ATA-4] Maxtor DiamondMax 3400", .internal_name = "90644D3", .model = "Maxtor 90644D3", .zones = 16, .avg_spt = 290, .heads = 3, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 0.9, .rcache_num_seg = 8, .rcache_seg_size = 256, .max_multiple = 32 }, + { .name = "[ATA-4] Maxtor DiamondMax 4320 (90432D2)", .internal_name = "90432D2", .model = "Maxtor 90432D2", .zones = 16, .avg_spt = 290, .heads = 2, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 0.9, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, + { .name = "[ATA-4] Maxtor DiamondMax 4320 (90845D4)", .internal_name = "90845D4", .model = "Maxtor 90845D4", .zones = 16, .avg_spt = 290, .heads = 3, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 0.9, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, + { .name = "[ATA-4] Maxtor DiamondMax Plus 6800 (90683U2)", .internal_name = "90683U2", .model = "Maxtor 90683U2", .zones = 16, .avg_spt = 290, .heads = 2, .rpm = 7200, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, + { .name = "[ATA-4] Maxtor DiamondMax Plus 6800 (91024U3)", .internal_name = "91024U3", .model = "Maxtor 91024U3", .zones = 16, .avg_spt = 290, .heads = 3, .rpm = 7200, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, + { .name = "[ATA-4] Maxtor DiamondMax Plus 6800 (91366U4)", .internal_name = "91366U4", .model = "Maxtor 91366U4", .zones = 16, .avg_spt = 290, .heads = 4, .rpm = 7200, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, + { .name = "[ATA-4] Maxtor DiamondMax Plus 6800 (92049U6)", .internal_name = "92049U6", .model = "Maxtor 92049U6", .zones = 16, .avg_spt = 290, .heads = 6, .rpm = 7200, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, + { .name = "[ATA-4] Maxtor DiamondMax Plus 6800 (92732U8)", .internal_name = "92732U8", .model = "Maxtor 92732U8", .zones = 16, .avg_spt = 290, .heads = 8, .rpm = 7200, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, + { .name = "[ATA-4] Quantum Bigfoot TX4.3AT", .internal_name = "TX043A011", .model = "QUANTUM BIGFOOT TX4.3A", .zones = 2, .avg_spt = 220, .heads = 2, .rpm = 4000, .full_stroke_ms = 30, .track_seek_ms = 2.5, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 32 }, + { .name = "[ATA-4] Quantum Fireball ST3.2AT", .internal_name = "ST32A461", .model = "QUANTUM FIREBALL ST3.2A", .zones = 4, .avg_spt = 200, .heads = 4, .rpm = 5400, .full_stroke_ms = 21, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-4] Quantum Fireball SE4.3A", .internal_name = "SE43A011", .model = "QUANTUM FIREBALL SE4.3A", .zones = 2, .avg_spt = 200, .heads = 4, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-4] Quantum Fireball SE6.4A", .internal_name = "SE64A011", .model = "QUANTUM FIREBALL SE6.4A", .zones = 3, .avg_spt = 200, .heads = 6, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-4] Quantum Fireball SE8.4A", .internal_name = "SE84A011", .model = "QUANTUM FIREBALL SE8.4A", .zones = 4, .avg_spt = 200, .heads = 8, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-4] Seagate Medalist 2122", .internal_name = "ST32122A", .model = "ST32122A", .zones = 16, .avg_spt = 215, .heads = 2, .rpm = 4500, .full_stroke_ms = 23, .track_seek_ms = 3.8, .rcache_num_seg = 16, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-4] Seagate Medalist 3321", .internal_name = "ST33221A", .model = "ST33221A", .zones = 16, .avg_spt = 210, .heads = 4, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 1.7, .rcache_num_seg = 16, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-4] Seagate Medalist 4321", .internal_name = "ST34321A", .model = "ST34321A", .zones = 16, .avg_spt = 210, .heads = 4, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 2.2, .rcache_num_seg = 16, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-4] Seagate Medalist 6531", .internal_name = "ST36531A", .model = "ST36531A", .zones = 16, .avg_spt = 215, .heads = 6, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 1.7, .rcache_num_seg = 16, .rcache_seg_size = 128, .max_multiple = 16 }, + { .name = "[ATA-4] Seagate Medalist 8420", .internal_name = "ST38420A", .model = "ST38420A", .zones = 16, .avg_spt = 290, .heads = 4, .rpm = 5400, .full_stroke_ms = 16, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-4] Seagate Medalist 13030", .internal_name = "ST313030A", .model = "ST313030A", .zones = 16, .avg_spt = 290, .heads = 6, .rpm = 5400, .full_stroke_ms = 16, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-4] Seagate Medalist 17240", .internal_name = "ST317240A", .model = "ST317240A", .zones = 16, .avg_spt = 290, .heads = 8, .rpm = 5400, .full_stroke_ms = 16, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-4] Toshiba MK4006MAV", .internal_name = "MK4006MAV", .model = "TOSHIBA MK4006MAV", .zones = 8, .avg_spt = 230, .heads = 6, .rpm = 4200, .full_stroke_ms = 25, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-4] Western Digital Caviar 14300", .internal_name = "AC14300", .model = "WDC AC14300RT", .zones = 16, .avg_spt = 195, .heads = 2, .rpm = 5400, .full_stroke_ms = 21, .track_seek_ms = 5.5, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, + { .name = "[ATA-4] Western Digital Caviar 23200", .internal_name = "AC23200", .model = "WDC AC23200LB", .zones = 16, .avg_spt = 210, .heads = 4, .rpm = 5400, .full_stroke_ms = 21, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 256, .max_multiple = 32 }, + { .name = "[ATA-4] Western Digital Caviar 26400", .internal_name = "AC26400", .model = "WDC AC26400RN", .zones = 16, .avg_spt = 295, .heads = 5, .rpm = 5400, .full_stroke_ms = 21, .track_seek_ms = 3, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-4] Western Digital Caviar 33200", .internal_name = "AC33200", .model = "WDC AC33200LA", .zones = 16, .avg_spt = 310, .heads = 5, .rpm = 5200, .full_stroke_ms = 40, .track_seek_ms = 3, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, + { .name = "[ATA-5] IBM Travelstar 6GN", .internal_name = "DARA206000", .model = "IBM-DARA-206000", .zones = 12, .avg_spt = 292, .heads = 2, .rpm = 4200, .full_stroke_ms = 31, .track_seek_ms = 4, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] IBM Travelstar 9GN", .internal_name = "DARA209000", .model = "IBM-DARA-209000", .zones = 12, .avg_spt = 292, .heads = 3, .rpm = 4200, .full_stroke_ms = 31, .track_seek_ms = 4, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] IBM/Hitachi Travelstar 12GN", .internal_name = "DARA212000", .model = "IBM-DARA-212000", .zones = 12, .avg_spt = 292, .heads = 4, .rpm = 4200, .full_stroke_ms = 31, .track_seek_ms = 4, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, // Either Hitachi or IBM OEM + { .name = "[ATA-5] Maxtor DiamondMax VL 17", .internal_name = "90871U2", .model = "Maxtor 90871U2", .zones = 16, .avg_spt = 290, .heads = 3, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 0.9, .rcache_num_seg = 16, .rcache_seg_size = 256, .max_multiple = 32 }, + { .name = "[ATA-5] Maxtor DiamondMax VL 20 (91021U2)", .internal_name = "91021U2", .model = "Maxtor 91021U2", .zones = 16, .avg_spt = 295, .heads = 2, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] Maxtor DiamondMax VL 20 (91531U3)", .internal_name = "91531U3", .model = "Maxtor 91531U3", .zones = 16, .avg_spt = 295, .heads = 3, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] Maxtor DiamondMax VL 20 (92041U4)", .internal_name = "92041U4", .model = "Maxtor 92041U4", .zones = 16, .avg_spt = 295, .heads = 4, .rpm = 5400, .full_stroke_ms = 20, .track_seek_ms = 1, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] Quantum Fireball EX3.2A", .internal_name = "EX32A012", .model = "QUANTUM FIREBALL EX3.2A", .zones = 1, .avg_spt = 210, .heads = 2, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, + { .name = "[ATA-5] Quantum Fireball EX5.1A", .internal_name = "EX51A012", .model = "QUANTUM FIREBALL EX5.1A", .zones = 2, .avg_spt = 210, .heads = 3, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, + { .name = "[ATA-5] Quantum Fireball EX6.4A", .internal_name = "EX64A012", .model = "QUANTUM FIREBALL EX6.4A", .zones = 2, .avg_spt = 210, .heads = 4, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, + { .name = "[ATA-5] Quantum Fireball EX10.2A", .internal_name = "EX10A011", .model = "QUANTUM FIREBALL EX10.2A", .zones = 3, .avg_spt = 210, .heads = 6, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, + { .name = "[ATA-5] Quantum Fireball EX12.7A", .internal_name = "EX12A011", .model = "QUANTUM FIREBALL EX12.7A", .zones = 4, .avg_spt = 210, .heads = 8, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, + { .name = "[ATA-5] Quantum Fireball CR4.3A", .internal_name = "CR43A013", .model = "QUANTUM FIREBALL CR4.3A", .zones = 2, .avg_spt = 310, .heads = 3, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, + { .name = "[ATA-5] Quantum Fireball CR6.4A", .internal_name = "CR64A011", .model = "QUANTUM FIREBALL CR6.4A", .zones = 2, .avg_spt = 310, .heads = 4, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, + { .name = "[ATA-5] Quantum Fireball CR8.4A", .internal_name = "CR84A011", .model = "QUANTUM FIREBALL CR8.4A", .zones = 3, .avg_spt = 310, .heads = 6, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, + { .name = "[ATA-5] Quantum Fireball CR13.0A", .internal_name = "CR13A011", .model = "QUANTUM FIREBALL CR13.0A", .zones = 4, .avg_spt = 310, .heads = 8, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 2, .rcache_num_seg = 8, .rcache_seg_size = 512, .max_multiple = 16 }, + { .name = "[ATA-5] Samsung SpinPoint V6800 (SV0682D)", .internal_name = "SV0682D", .model = "SAMSUNG SV0682D", .zones = 8, .avg_spt = 295, .heads = 2, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 1.3, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] Samsung SpinPoint V6800 (SV1023D)", .internal_name = "SV1023D", .model = "SAMSUNG SV1023D", .zones = 8, .avg_spt = 295, .heads = 3, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 1.3, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] Samsung SpinPoint V6800 (SV1364D)", .internal_name = "SV1364D", .model = "SAMSUNG SV1364D", .zones = 8, .avg_spt = 295, .heads = 4, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 1.3, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] Samsung SpinPoint V6800 (SV1705D)", .internal_name = "SV1705D", .model = "SAMSUNG SV1705D", .zones = 8, .avg_spt = 295, .heads = 5, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 1.3, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] Samsung SpinPoint V6800 (SV2046D)", .internal_name = "SV2046D", .model = "SAMSUNG SV2046D", .zones = 8, .avg_spt = 295, .heads = 6, .rpm = 5400, .full_stroke_ms = 18, .track_seek_ms = 1.3, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] Seagate U8 - 4.3gb", .internal_name = "ST34313A", .model = "ST34313A", .zones = 16, .avg_spt = 289, .heads = 1, .rpm = 5400, .full_stroke_ms = 25, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] Seagate U8 - 8.4gb", .internal_name = "ST38410A", .model = "ST38410A", .zones = 16, .avg_spt = 289, .heads = 2, .rpm = 5400, .full_stroke_ms = 25, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] Seagate U8 - 13gb", .internal_name = "ST313021A", .model = "ST313021A", .zones = 16, .avg_spt = 289, .heads = 4, .rpm = 5400, .full_stroke_ms = 25, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] Seagate U8 - 17.2gb", .internal_name = "ST317221A", .model = "ST317221A", .zones = 16, .avg_spt = 289, .heads = 3, .rpm = 5400, .full_stroke_ms = 25, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, + { .name = "[ATA-5] Western Digital Caviar 102AA", .internal_name = "WD102AA", .model = "WDC WD102AA-00ANA0", .zones = 16, .avg_spt = 295, .heads = 8, .rpm = 5400, .full_stroke_ms = 12, .track_seek_ms = 1.5, .rcache_num_seg = 16, .rcache_seg_size = 512, .max_multiple = 32 }, { .name = "[ATA-5] Western Digital Expert", .internal_name = "WD135BA", .model = "WDC WD135BA-60AK", .zones = 16, .avg_spt = 350, .heads = 6, .rpm = 7200, .full_stroke_ms = 15, .track_seek_ms = 2, .rcache_num_seg = 16, .rcache_seg_size = 1920, .max_multiple = 32 }, // clang-format on }; diff --git a/src/disk/lba_enhancer.c b/src/disk/lba_enhancer.c index 35c845c16..ef9e167d3 100644 --- a/src/disk/lba_enhancer.c +++ b/src/disk/lba_enhancer.c @@ -44,7 +44,7 @@ lba_enhancer_close(void* priv) } void * -lba_enhancer_init(const device_t *info) +lba_enhancer_init(UNUSED(const device_t *info)) { lba_enhancer_t *dev = (lba_enhancer_t *) calloc(1, sizeof(lba_enhancer_t)); @@ -63,22 +63,23 @@ lba_enhancer_available(void) // clang-format off static const device_config_t lba_enhancer_config[] = { { - .name = "bios_addr", - .description = "BIOS Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0xc8000, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { .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 = "bios_addr", + .description = "BIOS Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0xc8000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .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 = "" } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; @@ -87,12 +88,12 @@ static const device_config_t lba_enhancer_config[] = { const device_t lba_enhancer_device = { .name = "Vision Systems LBA Enhancer", .internal_name = "lba_enhancer", - .flags = DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0, .init = lba_enhancer_init, .close = lba_enhancer_close, .reset = NULL, - { .available = lba_enhancer_available }, + .available = lba_enhancer_available, .speed_changed = NULL, .force_redraw = NULL, .config = lba_enhancer_config diff --git a/src/disk/mo.c b/src/disk/mo.c index 5f757c8af..1a2db0443 100644 --- a/src/disk/mo.c +++ b/src/disk/mo.c @@ -9,35 +9,33 @@ * Implementation of a generic Magneto-Optical Disk drive * commands, for both ATAPI and SCSI usage. * - * - * * Authors: Natalia Portillo * Miran Grca, * Fred N. van Kempen, * - * Copyright 2020-2021 Natalia Portillo. - * Copyright 2020-2021 Miran Grca. - * Copyright 2020-2021 Fred N. van Kempen + * Copyright 2020-2025 Natalia Portillo. + * Copyright 2020-2025 Miran Grca. + * Copyright 2020-2025 Fred N. van Kempen */ -#include -#include -#include -#include +#define _GNU_SOURCE +#include +#ifdef ENABLE_MO_LOG #include -#include -#define HAVE_STDARG_H +#endif +#include +#include +#include +#include #include <86box/86box.h> #include <86box/timer.h> -#include <86box/config.h> -#include <86box/timer.h> #include <86box/device.h> +#include <86box/log.h> #include <86box/scsi.h> #include <86box/scsi_device.h> #include <86box/nvr.h> #include <86box/path.h> #include <86box/plat.h> #include <86box/ui.h> -#include <86box/hdc.h> #include <86box/hdc_ide.h> #include <86box/mo.h> #include <86box/version.h> @@ -53,235 +51,49 @@ mo_drive_t mo_drives[MO_NUM]; -/* Table of all SCSI commands and their flags, needed for the new disc change / not ready handler. */ +// clang-format off +/* + Table of all SCSI commands and their flags, needed for the new disc change / + not ready handler. + */ const uint8_t mo_command_flags[0x100] = { - IMPLEMENTED | CHECK_READY | NONDATA, /* 0x00 */ - IMPLEMENTED | ALLOW_UA | NONDATA | SCSI_ONLY, /* 0x01 */ - 0, - IMPLEMENTED | ALLOW_UA, /* 0x03 */ - IMPLEMENTED | CHECK_READY | ALLOW_UA | NONDATA | SCSI_ONLY, /* 0x04 */ - 0, 0, 0, - IMPLEMENTED | CHECK_READY, /* 0x08 */ - 0, - IMPLEMENTED | CHECK_READY, /* 0x0A */ - IMPLEMENTED | CHECK_READY | NONDATA, /* 0x0B */ - 0, 0, 0, 0, 0, 0, - IMPLEMENTED | ALLOW_UA, /* 0x12 */ - IMPLEMENTED | CHECK_READY | NONDATA | SCSI_ONLY, /* 0x13 */ - 0, - IMPLEMENTED, /* 0x15 */ - IMPLEMENTED | SCSI_ONLY, /* 0x16 */ - IMPLEMENTED | SCSI_ONLY, /* 0x17 */ - 0, 0, - IMPLEMENTED, /* 0x1A */ - IMPLEMENTED | CHECK_READY, /* 0x1B */ - 0, - IMPLEMENTED, /* 0x1D */ - IMPLEMENTED | CHECK_READY, /* 0x1E */ - 0, 0, 0, 0, 0, 0, - IMPLEMENTED | CHECK_READY, /* 0x25 */ - 0, 0, - IMPLEMENTED | CHECK_READY, /* 0x28 */ - 0, - IMPLEMENTED | CHECK_READY, /* 0x2A */ - IMPLEMENTED | CHECK_READY | NONDATA, /* 0x2B */ - IMPLEMENTED | CHECK_READY | NONDATA, /* 0x2C */ - 0, - IMPLEMENTED | CHECK_READY, /* 0x2E */ - IMPLEMENTED | CHECK_READY | NONDATA | SCSI_ONLY, /* 0x2F */ - 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, - IMPLEMENTED, /* 0x55 */ - 0, 0, 0, 0, - IMPLEMENTED, /* 0x5A */ - 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, - IMPLEMENTED | CHECK_READY, /* 0xA8 */ - 0, - IMPLEMENTED | CHECK_READY, /* 0xAA */ - 0, - IMPLEMENTED | CHECK_READY | NONDATA, /* 0xAC */ - 0, - IMPLEMENTED | CHECK_READY, /* 0xAE */ - IMPLEMENTED | CHECK_READY | NONDATA | SCSI_ONLY, /* 0xAF */ - 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 + [0x00] = IMPLEMENTED | CHECK_READY, + [0x01] = IMPLEMENTED | ALLOW_UA | SCSI_ONLY, + [0x03] = IMPLEMENTED | ALLOW_UA, + [0x04] = IMPLEMENTED | CHECK_READY | ALLOW_UA | SCSI_ONLY, + [0x08] = IMPLEMENTED | CHECK_READY, + [0x0a] = IMPLEMENTED | CHECK_READY, + [0x0b] = IMPLEMENTED | CHECK_READY, + [0x12] = IMPLEMENTED | ALLOW_UA, + [0x13] = IMPLEMENTED | CHECK_READY, + [0x15] = IMPLEMENTED, + [0x16] = IMPLEMENTED | SCSI_ONLY, + [0x17] = IMPLEMENTED | SCSI_ONLY, + [0x1a] = IMPLEMENTED, + [0x1b] = IMPLEMENTED | CHECK_READY, + [0x1d] = IMPLEMENTED, + [0x1e] = IMPLEMENTED | CHECK_READY, + [0x25] = IMPLEMENTED | CHECK_READY, + [0x28] = IMPLEMENTED | CHECK_READY, + [0x2a ... 0x2c] = IMPLEMENTED | CHECK_READY, + [0x2e ... 0x2f] = IMPLEMENTED | CHECK_READY, + [0x41] = IMPLEMENTED | CHECK_READY, + [0x55] = IMPLEMENTED, + [0x5a] = IMPLEMENTED, + [0xa8] = IMPLEMENTED | CHECK_READY, + [0xaa] = IMPLEMENTED | CHECK_READY, + [0xac] = IMPLEMENTED | CHECK_READY, + [0xae] = IMPLEMENTED | CHECK_READY, + [0xaf] = IMPLEMENTED | CHECK_READY | SCSI_ONLY }; 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 -{ { - { 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 } -} }; -// clang-format on +static const mode_sense_pages_t mo_mode_sense_pages_default = { 0 }; -static const mode_sense_pages_t mo_mode_sense_pages_default_scsi = - // clang-format off -{ { - { 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 } -} }; -// clang-format on +static const mode_sense_pages_t mo_mode_sense_pages_default_scsi = { 0 }; -static const mode_sense_pages_t mo_mode_sense_pages_changeable = - // clang-format off -{ { - { 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 } -} }; +static const mode_sense_pages_t mo_mode_sense_pages_changeable = { 0 }; // clang-format on static void mo_command_complete(mo_t *dev); @@ -291,32 +103,22 @@ static void mo_init(mo_t *dev); int mo_do_log = ENABLE_MO_LOG; static void -mo_log(const char *fmt, ...) +mo_log(void *priv, const char *fmt, ...) { va_list ap; if (mo_do_log) { va_start(ap, fmt); - pclog_ex(fmt, ap); + log_out(priv, fmt, ap); va_end(ap); } } #else -# define mo_log(fmt, ...) +# define mo_log(priv, fmt, ...) #endif -int -find_mo_for_channel(uint8_t channel) -{ - 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; - } - return 0xff; -} - static int -mo_load_abort(mo_t *dev) +mo_load_abort(const mo_t *dev) { if (dev->drv->fp) fclose(dev->drv->fp); @@ -330,105 +132,128 @@ mo_load_abort(mo_t *dev) int image_is_mdi(const char *s) { - if (!strcasecmp(path_get_extension((char *) s), "MDI")) - return 1; - else - return 0; + return !strcasecmp(path_get_extension((char *) s), "MDI"); } int -mo_load(mo_t *dev, char *fn) +mo_is_empty(const uint8_t id) { - int is_mdi; - uint32_t size = 0; - unsigned int found = 0; + const mo_t *dev = (const mo_t *) mo_drives[id].priv; + int ret = 0; - if (!dev->drv) { + if ((dev->drv == NULL) || (dev->drv->fp == NULL)) + ret = 1; + + return ret; +} + +void +mo_load(const mo_t *dev, const char *fn, const int skip_insert) +{ + const int was_empty = mo_is_empty(dev->id); + int ret = 0; + + if (dev->drv == NULL) mo_eject(dev->id); - return 0; - } + else { + const int is_mdi = image_is_mdi(fn); - is_mdi = image_is_mdi(fn); + dev->drv->fp = plat_fopen(fn, dev->drv->read_only ? "rb" : "rb+"); + ret = 1; - dev->drv->fp = plat_fopen(fn, dev->drv->read_only ? "rb" : "rb+"); - if (!dev->drv->fp) { - if (!dev->drv->read_only) { - dev->drv->fp = plat_fopen(fn, "rb"); - if (dev->drv->fp) - dev->drv->read_only = 1; - else - return mo_load_abort(dev); - } else - return mo_load_abort(dev); - } + if (dev->drv->fp == NULL) { + if (!dev->drv->read_only) { + dev->drv->fp = plat_fopen(fn, "rb"); + if (dev->drv->fp == NULL) + ret = mo_load_abort(dev); + else + dev->drv->read_only = 1; + } else + ret = mo_load_abort(dev); + } - fseek(dev->drv->fp, 0, SEEK_END); - size = (uint32_t) ftell(dev->drv->fp); + if (ret) { + fseeko64(dev->drv->fp, 0, SEEK_END); - if (is_mdi) { - /* This is a MDI image. */ - size -= 0x1000LL; - dev->drv->base = 0x1000; - } + uint64_t size = (uint64_t) ftello64(dev->drv->fp); + unsigned int found = 0; - 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; - dev->drv->sector_size = mo_types[i].bytes_per_sector; - break; + if (is_mdi) { + /* This is a MDI image. */ + size -= 0x1000LL; + dev->drv->base = 0x1000; + } else + dev->drv->base = 0; + + dev->drv->supported = 0; + + for (uint8_t i = 0; i < KNOWN_MO_TYPES; i++) { + if (size == ((uint64_t) mo_types[i].sectors * mo_types[i].bytes_per_sector)) { + found = 1; + dev->drv->medium_size = mo_types[i].sectors; + dev->drv->sector_size = mo_types[i].bytes_per_sector; + dev->drv->supported = mo_drive_types[dev->drv->type].supported_media[i]; + break; + } + } + + if (found) { + if (fseeko64(dev->drv->fp, (uint64_t) dev->drv->base, SEEK_SET) == -1) + log_fatal(dev->log, "mo_load(): Error seeking to the beginning of " + "the file\n"); + + strncpy(dev->drv->image_path, fn, sizeof(dev->drv->image_path) - 1); + + ret = 1; + } else + ret = mo_load_abort(dev); } } - if (!found) - return mo_load_abort(dev); + if (ret && !skip_insert) { + /* Signal media change to the emulated machine. */ + mo_insert((mo_t *) dev); - if (fseek(dev->drv->fp, dev->drv->base, SEEK_SET) == -1) - fatal("mo_load(): Error seeking to the beginning of the file\n"); - - strncpy(dev->drv->image_path, fn, sizeof(dev->drv->image_path) - 1); - - return 1; + /* The drive was previously empty, transition directly to UNIT ATTENTION. */ + if (was_empty) + mo_insert((mo_t *) dev); + } } void -mo_disk_reload(mo_t *dev) +mo_disk_reload(const mo_t *dev) { - int ret = 0; - - if (strlen(dev->drv->prev_image_path) == 0) - return; - else - ret = mo_load(dev, dev->drv->prev_image_path); - - if (ret) - dev->unit_attention = 1; + if (strlen(dev->drv->prev_image_path) != 0) + (void) mo_load(dev, dev->drv->prev_image_path, 0); } -void -mo_disk_unload(mo_t *dev) +static void +mo_disk_unload(const mo_t *dev) { - if (dev->drv && dev->drv->fp) { + if ((dev->drv != NULL) && (dev->drv->fp != NULL)) { fclose(dev->drv->fp); dev->drv->fp = NULL; } } void -mo_disk_close(mo_t *dev) +mo_disk_close(const mo_t *dev) { - if (dev->drv && dev->drv->fp) { + if ((dev->drv != NULL) && (dev->drv->fp != NULL)) { mo_disk_unload(dev); - memcpy(dev->drv->prev_image_path, dev->drv->image_path, sizeof(dev->drv->prev_image_path)); + memcpy(dev->drv->prev_image_path, dev->drv->image_path, + sizeof(dev->drv->prev_image_path)); memset(dev->drv->image_path, 0, sizeof(dev->drv->image_path)); dev->drv->medium_size = 0; + + mo_insert((mo_t *) dev); } } static void -mo_set_callback(mo_t *dev) +mo_set_callback(const mo_t *dev) { if (dev->drv->bus_type != MO_BUS_SCSI) ide_set_callback(ide_drives[dev->drv->ide_channel], dev->callback); @@ -437,55 +262,55 @@ mo_set_callback(mo_t *dev) static void mo_init(mo_t *dev) { - if (dev->id >= MO_NUM) - return; - - dev->requested_blocks = 1; - dev->sense[0] = 0xf0; - dev->sense[7] = 10; - dev->drv->bus_mode = 0; - if (dev->drv->bus_type >= MO_BUS_ATAPI) - dev->drv->bus_mode |= 2; - if (dev->drv->bus_type < MO_BUS_SCSI) - dev->drv->bus_mode |= 1; - mo_log("MO %i: Bus type %i, bus mode %i\n", dev->id, dev->drv->bus_type, dev->drv->bus_mode); - if (dev->drv->bus_type < MO_BUS_SCSI) { - dev->tf->phase = 1; - dev->tf->request_length = 0xEB14; + if (dev->id < MO_NUM) { + dev->requested_blocks = 1; + dev->sense[0] = 0xf0; + dev->sense[7] = 10; + dev->drv->bus_mode = 0; + if (dev->drv->bus_type >= MO_BUS_ATAPI) + dev->drv->bus_mode |= 2; + if (dev->drv->bus_type < MO_BUS_SCSI) + dev->drv->bus_mode |= 1; + mo_log(dev->log, "Bus type %i, bus mode %i\n", dev->drv->bus_type, dev->drv->bus_mode); + if (dev->drv->bus_type < MO_BUS_SCSI) { + dev->tf->phase = 1; + dev->tf->request_length = 0xEB14; + } + dev->tf->status = READY_STAT | DSC_STAT; + dev->tf->pos = 0; + dev->packet_status = PHASE_NONE; + mo_sense_key = mo_asc = mo_ascq = dev->unit_attention = dev->transition = 0; + mo_info = 0x00000000; } - dev->tf->status = READY_STAT | DSC_STAT; - dev->tf->pos = 0; - dev->packet_status = PHASE_NONE; - mo_sense_key = mo_asc = mo_ascq = dev->unit_attention = 0; } static int -mo_supports_pio(mo_t *dev) +mo_supports_pio(const mo_t *dev) { return (dev->drv->bus_mode & 1); } static int -mo_supports_dma(mo_t *dev) +mo_supports_dma(const mo_t *dev) { return (dev->drv->bus_mode & 2); } /* Returns: 0 for none, 1 for PIO, 2 for DMA. */ static int -mo_current_mode(mo_t *dev) +mo_current_mode(const mo_t *dev) { if (!mo_supports_pio(dev) && !mo_supports_dma(dev)) return 0; if (mo_supports_pio(dev) && !mo_supports_dma(dev)) { - mo_log("MO %i: Drive does not support DMA, setting to PIO\n", dev->id); + mo_log(dev->log, "Drive does not support DMA, setting to PIO\n"); return 1; } if (!mo_supports_pio(dev) && mo_supports_dma(dev)) return 2; if (mo_supports_pio(dev) && mo_supports_dma(dev)) { - mo_log("MO %i: Drive supports both, setting to %s\n", dev->id, - (dev->tf->features & 1) ? "DMA" : "PIO"); + mo_log(dev->log, "Drive supports both, setting to %s\n", (dev->tf->features & 1) ? + "DMA" : "PIO"); return (dev->tf->features & 1) ? 2 : 1; } @@ -495,21 +320,21 @@ mo_current_mode(mo_t *dev) static void mo_mode_sense_load(mo_t *dev) { - FILE *fp; - char fn[512]; + char fn[512] = { 0 }; memset(&dev->ms_pages_saved, 0, sizeof(mode_sense_pages_t)); if (mo_drives[dev->id].bus_type == MO_BUS_SCSI) - memcpy(&dev->ms_pages_saved, &mo_mode_sense_pages_default_scsi, sizeof(mode_sense_pages_t)); + memcpy(&dev->ms_pages_saved, &mo_mode_sense_pages_default_scsi, + sizeof(mode_sense_pages_t)); else - memcpy(&dev->ms_pages_saved, &mo_mode_sense_pages_default, sizeof(mode_sense_pages_t)); + memcpy(&dev->ms_pages_saved, &mo_mode_sense_pages_default, + sizeof(mode_sense_pages_t)); - memset(fn, 0, 512); if (dev->drv->bus_type == MO_BUS_SCSI) sprintf(fn, "scsi_mo_%02i_mode_sense_bin", dev->id); else sprintf(fn, "mo_%02i_mode_sense_bin", dev->id); - fp = plat_fopen(nvr_path(fn), "rb"); + FILE *fp = plat_fopen(nvr_path(fn), "rb"); if (fp) { /* Nothing to read, not used by MO. */ fclose(fp); @@ -517,28 +342,27 @@ mo_mode_sense_load(mo_t *dev) } static void -mo_mode_sense_save(mo_t *dev) +mo_mode_sense_save(const mo_t *dev) { - FILE *fp; - char fn[512]; + char fn[512] = { 0 }; - memset(fn, 0, 512); if (dev->drv->bus_type == MO_BUS_SCSI) sprintf(fn, "scsi_mo_%02i_mode_sense_bin", dev->id); else sprintf(fn, "mo_%02i_mode_sense_bin", dev->id); - fp = plat_fopen(nvr_path(fn), "wb"); + FILE *fp = plat_fopen(nvr_path(fn), "wb"); if (fp) { /* Nothing to write, not used by MO. */ fclose(fp); } } -/*SCSI Mode Sense 6/10*/ +/* SCSI Mode Sense 6/10. */ static uint8_t -mo_mode_sense_read(mo_t *dev, uint8_t page_control, uint8_t page, uint8_t pos) +mo_mode_sense_read(const mo_t *dev, const uint8_t pgctl, + const uint8_t page, const uint8_t pos) { - switch (page_control) { + switch (pgctl) { case 0: case 3: return dev->ms_pages_saved.pages[page][pos]; @@ -558,14 +382,11 @@ mo_mode_sense_read(mo_t *dev, uint8_t page_control, uint8_t page, uint8_t pos) } static uint32_t -mo_mode_sense(mo_t *dev, uint8_t *buf, uint32_t pos, uint8_t page, uint8_t block_descriptor_len) +mo_mode_sense(const mo_t *dev, uint8_t *buf, uint32_t pos, + uint8_t page, const uint8_t block_descriptor_len) { - uint64_t pf; - uint8_t page_control = (page >> 6) & 3; - - pf = mo_mode_sense_page_flags; - - uint8_t msplen; + const uint64_t pf = mo_mode_sense_page_flags; + const uint8_t pgctl = (page >> 6) & 3; page &= 0x3f; @@ -583,12 +404,12 @@ mo_mode_sense(mo_t *dev, uint8_t *buf, uint32_t pos, uint8_t page, uint8_t block 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); + const uint8_t msplen = mo_mode_sense_read(dev, pgctl, i, 1); + buf[pos++] = mo_mode_sense_read(dev, pgctl, i, 0); + buf[pos++] = msplen; + mo_log(dev->log, "MODE SENSE: Page [%02X] length %i\n", i, msplen); for (uint8_t j = 0; j < msplen; j++) - buf[pos++] = mo_mode_sense_read(dev, page_control, i, 2 + j); + buf[pos++] = mo_mode_sense_read(dev, pgctl, i, 2 + j); } } } @@ -604,7 +425,10 @@ mo_update_request_length(mo_t *dev, int len, int block_len) dev->max_transfer_len = dev->tf->request_length; - /* For media access commands, make sure the requested DRQ length matches the block length. */ + /* + For media access commands, make sure the requested DRQ length + matches the block length. + */ switch (dev->current_cdb[0]) { case 0x08: case 0x0a: @@ -613,10 +437,13 @@ mo_update_request_length(mo_t *dev, int len, int block_len) case 0xa8: case 0xaa: /* Round it to the nearest 2048 bytes. */ - dev->max_transfer_len = (dev->max_transfer_len >> 9) << 9; + dev->max_transfer_len = (dev->max_transfer_len / dev->drv->sector_size) * + dev->drv->sector_size; - /* Make sure total length is not bigger than sum of the lengths of - all the requested blocks. */ + /* + Make sure total length is not bigger than sum of the lengths of + all the requested blocks. + */ bt = (dev->requested_blocks * block_len); if (len > bt) len = bt; @@ -641,7 +468,10 @@ mo_update_request_length(mo_t *dev, int len, int block_len) /* If the DRQ length is odd, and the total remaining length is bigger, make sure it's even. */ if ((dev->max_transfer_len & 1) && (dev->max_transfer_len < len)) dev->max_transfer_len &= 0xfffe; - /* If the DRQ length is smaller or equal in size to the total remaining length, set it to that. */ + /* + If the DRQ length is smaller or equal in size to the total remaining length, + set it to that. + */ if (!dev->max_transfer_len) dev->max_transfer_len = 65534; @@ -649,8 +479,6 @@ mo_update_request_length(mo_t *dev, int len, int block_len) dev->tf->request_length = dev->max_transfer_len = len; else if (len > dev->max_transfer_len) dev->tf->request_length = dev->max_transfer_len; - - return; } static double @@ -658,42 +486,30 @@ mo_bus_speed(mo_t *dev) { double ret = -1.0; - if (dev && dev->drv && (dev->drv->bus_type == MO_BUS_SCSI)) { - dev->callback = -1.0; /* Speed depends on SCSI controller */ - return 0.0; - } else { - if (dev && dev->drv) - ret = ide_atapi_get_period(dev->drv->ide_channel); - if (ret == -1.0) { - if (dev) - dev->callback = -1.0; - return 0.0; - } else - return ret * 1000000.0; + if (dev && dev->drv) + ret = ide_atapi_get_period(dev->drv->ide_channel); + + if (ret == -1.0) { + if (dev) + dev->callback = -1.0; + ret = 0.0; } + + return ret; } static void mo_command_common(mo_t *dev) { - double bytes_per_second; - double period; - dev->tf->status = BUSY_STAT; dev->tf->phase = 1; dev->tf->pos = 0; if (dev->packet_status == PHASE_COMPLETE) dev->callback = 0.0; - else { - if (dev->drv->bus_type == MO_BUS_SCSI) { - dev->callback = -1.0; /* Speed depends on SCSI controller */ - return; - } else - bytes_per_second = mo_bus_speed(dev); - - period = 1000000.0 / bytes_per_second; - dev->callback = period * (double) (dev->packet_len); - } + else if (dev->drv->bus_type == MO_BUS_SCSI) + dev->callback = -1.0; /* Speed depends on SCSI controller */ + else + dev->callback = mo_bus_speed(dev) * (double) (dev->packet_len); mo_set_callback(dev); } @@ -733,16 +549,20 @@ mo_command_write_dma(mo_t *dev) mo_command_common(dev); } -/* id = Current MO device ID; +/* + dev = Pointer to current MO device; len = Total transfer length; block_len = Length of a single block (why does it matter?!); alloc_len = Allocated transfer length; - direction = Transfer direction (0 = read from host, 1 = write to host). */ + direction = Transfer direction (0 = read from host, 1 = write to host). + */ static void -mo_data_command_finish(mo_t *dev, int len, int block_len, int alloc_len, int direction) +mo_data_command_finish(mo_t *dev, int len, const int block_len, + const int alloc_len, const int direction) { - mo_log("MO %i: Finishing command (%02X): %i, %i, %i, %i, %i\n", - dev->id, dev->current_cdb[0], len, block_len, alloc_len, direction, dev->tf->request_length); + mo_log(dev->log, "Finishing command (%02X): %i, %i, %i, %i, %i\n", + dev->current_cdb[0], len, block_len, alloc_len, + direction, dev->tf->request_length); dev->tf->pos = 0; if (alloc_len >= 0) { if (alloc_len < len) @@ -764,34 +584,36 @@ mo_data_command_finish(mo_t *dev, int len, int block_len, int alloc_len, int dir mo_command_write_dma(dev); } else { mo_update_request_length(dev, len, block_len); - if (direction == 0) + if ((dev->drv->bus_type != MO_BUS_SCSI) && + (dev->tf->request_length == 0)) + mo_command_complete(dev); + else if (direction == 0) mo_command_read(dev); else mo_command_write(dev); } } - mo_log("MO %i: Status: %i, cylinder %i, packet length: %i, position: %i, phase: %i\n", - dev->id, dev->packet_status, dev->tf->request_length, dev->packet_len, dev->tf->pos, - dev->tf->phase); + mo_log(dev->log, "Status: %i, cylinder %i, packet length: %i, position: %i, phase: %i\n", + dev->packet_status, dev->tf->request_length, dev->packet_len, + dev->tf->pos, dev->tf->phase); } static void mo_sense_clear(mo_t *dev, UNUSED(int command)) { mo_sense_key = mo_asc = mo_ascq = 0; + mo_info = 0x00000000; } static void -mo_set_phase(mo_t *dev, uint8_t phase) +mo_set_phase(const mo_t *dev, const uint8_t phase) { - uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; - uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; + const uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; + const uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; - if (dev->drv->bus_type != MO_BUS_SCSI) - return; - - scsi_devices[scsi_bus][scsi_id].phase = phase; + if (dev->drv->bus_type == MO_BUS_SCSI) + scsi_devices[scsi_bus][scsi_id].phase = phase; } static void @@ -799,8 +621,6 @@ mo_cmd_error(mo_t *dev) { mo_set_phase(dev, SCSI_PHASE_STATUS); dev->tf->error = ((mo_sense_key & 0xf) << 4) | ABRT_ERR; - if (dev->unit_attention) - dev->tf->error |= MCR_ERR; dev->tf->status = READY_STAT | ERR_STAT; dev->tf->phase = 3; dev->tf->pos = 0; @@ -808,31 +628,32 @@ mo_cmd_error(mo_t *dev) dev->callback = 50.0 * MO_TIME; mo_set_callback(dev); ui_sb_update_icon(SB_MO | dev->id, 0); - mo_log("MO %i: [%02X] ERROR: %02X/%02X/%02X\n", dev->id, dev->current_cdb[0], mo_sense_key, mo_asc, mo_ascq); + ui_sb_update_icon_write(SB_MO | dev->id, 0); + mo_log(dev->log, "[%02X] ERROR: %02X/%02X/%02X\n", dev->current_cdb[0], mo_sense_key, + mo_asc, mo_ascq); } static void mo_unit_attention(mo_t *dev) { mo_set_phase(dev, SCSI_PHASE_STATUS); - dev->tf->error = (SENSE_UNIT_ATTENTION << 4) | ABRT_ERR; - if (dev->unit_attention) - dev->tf->error |= MCR_ERR; - dev->tf->status = READY_STAT | ERR_STAT; - dev->tf->phase = 3; - dev->tf->pos = 0; - dev->packet_status = PHASE_ERROR; - dev->callback = 50.0 * MO_TIME; + dev->tf->error = (SENSE_UNIT_ATTENTION << 4) | ABRT_ERR; + dev->tf->status = READY_STAT | ERR_STAT; + dev->tf->phase = 3; + dev->tf->pos = 0; + dev->packet_status = PHASE_ERROR; + dev->callback = 50.0 * MO_TIME; mo_set_callback(dev); ui_sb_update_icon(SB_MO | dev->id, 0); - mo_log("MO %i: UNIT ATTENTION\n", dev->id); + ui_sb_update_icon_write(SB_MO | dev->id, 0); + mo_log(dev->log, "UNIT ATTENTION\n"); } static void mo_buf_alloc(mo_t *dev, uint32_t len) { - mo_log("MO %i: Allocated buffer length: %i\n", dev->id, len); - if (!dev->buffer) + mo_log(dev->log, "Allocated buffer length: %i\n", len); + if (dev->buffer == NULL) dev->buffer = (uint8_t *) malloc(len); } @@ -840,7 +661,7 @@ static void mo_buf_free(mo_t *dev) { if (dev->buffer) { - mo_log("MO %i: Freeing buffer...\n", dev->id); + mo_log(dev->log, "Freeing buffer...\n"); free(dev->buffer); dev->buffer = NULL; } @@ -853,6 +674,10 @@ mo_bus_master_error(scsi_common_t *sc) mo_buf_free(dev); mo_sense_key = mo_asc = mo_ascq = 0; + mo_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); mo_cmd_error(dev); } @@ -862,6 +687,7 @@ mo_not_ready(mo_t *dev) mo_sense_key = SENSE_NOT_READY; mo_asc = ASC_MEDIUM_NOT_PRESENT; mo_ascq = 0; + mo_info = 0x00000000; mo_cmd_error(dev); } @@ -871,6 +697,10 @@ mo_write_protected(mo_t *dev) mo_sense_key = SENSE_UNIT_ATTENTION; mo_asc = ASC_WRITE_PROTECTED; mo_ascq = 0; + mo_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); mo_cmd_error(dev); } @@ -880,6 +710,10 @@ mo_write_error(mo_t *dev) mo_sense_key = SENSE_MEDIUM_ERROR; mo_asc = ASC_WRITE_ERROR; mo_ascq = 0; + mo_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); mo_cmd_error(dev); } @@ -889,24 +723,30 @@ mo_read_error(mo_t *dev) mo_sense_key = SENSE_MEDIUM_ERROR; mo_asc = ASC_UNRECOVERED_READ_ERROR; mo_ascq = 0; + mo_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); mo_cmd_error(dev); } static void -mo_invalid_lun(mo_t *dev) +mo_invalid_lun(mo_t *dev, const uint8_t lun) { mo_sense_key = SENSE_ILLEGAL_REQUEST; mo_asc = ASC_INV_LUN; mo_ascq = 0; + mo_info = lun << 24; mo_cmd_error(dev); } static void -mo_illegal_opcode(mo_t *dev) +mo_illegal_opcode(mo_t *dev, const uint8_t opcode) { mo_sense_key = SENSE_ILLEGAL_REQUEST; mo_asc = ASC_ILLEGAL_OPCODE; mo_ascq = 0; + mo_info = opcode << 24; mo_cmd_error(dev); } @@ -916,140 +756,177 @@ mo_lba_out_of_range(mo_t *dev) mo_sense_key = SENSE_ILLEGAL_REQUEST; mo_asc = ASC_LBA_OUT_OF_RANGE; mo_ascq = 0; + mo_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); mo_cmd_error(dev); } static void -mo_invalid_field(mo_t *dev) +mo_invalid_field(mo_t *dev, const uint32_t field) { mo_sense_key = SENSE_ILLEGAL_REQUEST; mo_asc = ASC_INV_FIELD_IN_CMD_PACKET; mo_ascq = 0; + mo_info = (field >> 24) | + ((field >> 16) << 8) | + ((field >> 8) << 16) | + ( field << 24); mo_cmd_error(dev); dev->tf->status = 0x53; } static void -mo_invalid_field_pl(mo_t *dev) +mo_invalid_field_pl(mo_t *dev, const uint32_t field) { mo_sense_key = SENSE_ILLEGAL_REQUEST; mo_asc = ASC_INV_FIELD_IN_PARAMETER_LIST; mo_ascq = 0; + mo_info = (field >> 24) | + ((field >> 16) << 8) | + ((field >> 8) << 16) | + ( field << 24); mo_cmd_error(dev); dev->tf->status = 0x53; } static int -mo_blocks(mo_t *dev, int32_t *len, UNUSED(int first_batch), int out) +mo_blocks(mo_t *dev, int32_t *len, const int out) { - *len = 0; + int ret = 1; + *len = 0; - if (!dev->sector_len) { - mo_command_complete(dev); - return 0; - } + if (dev->sector_len > 0) { + mo_log(dev->log, "%sing %i blocks starting from %i...\n", out ? "Writ" : "Read", + dev->requested_blocks, dev->sector_pos); - mo_log("%sing %i blocks starting from %i...\n", out ? "Writ" : "Read", dev->requested_blocks, dev->sector_pos); - - if (dev->sector_pos >= dev->drv->medium_size) { - mo_log("MO %i: Trying to %s beyond the end of disk\n", dev->id, out ? "write" : "read"); - mo_lba_out_of_range(dev); - return 0; - } - - *len = dev->requested_blocks * dev->drv->sector_size; - - for (int i = 0; i < dev->requested_blocks; i++) { - if (fseek(dev->drv->fp, dev->drv->base + (dev->sector_pos * dev->drv->sector_size) + (i * dev->drv->sector_size), SEEK_SET) == -1) { - if (out) - mo_write_error(dev); - else - mo_read_error(dev); - return -1; - } - - if (feof(dev->drv->fp)) - break; - - if (out) { - if (fwrite(dev->buffer + (i * dev->drv->sector_size), 1, dev->drv->sector_size, dev->drv->fp) != dev->drv->sector_size) { - mo_log("mo_blocks(): Error writing data\n"); - mo_write_error(dev); - return -1; - } - - fflush(dev->drv->fp); + if (!dev->drv->supported) { + mo_log(dev->log, "Trying to %s an unsupported medium\n", + out ? "write" : "read"); + out ? mo_write_error(dev) : mo_read_error(dev); + ret = 0; + } else if (dev->sector_pos >= dev->drv->medium_size) { + mo_log(dev->log, "Trying to %s beyond the end of disk\n", + out ? "write" : "read"); + mo_lba_out_of_range(dev); + ret = 0; } else { - if (fread(dev->buffer + (i * dev->drv->sector_size), 1, dev->drv->sector_size, dev->drv->fp) != dev->drv->sector_size) { - mo_log("mo_blocks(): Error reading data\n"); - mo_read_error(dev); - return -1; + *len = dev->requested_blocks * dev->drv->sector_size; + + for (int i = 0; i < dev->requested_blocks; i++) { + if (fseeko64(dev->drv->fp, (uint64_t) dev->drv->base + + (uint64_t) (dev->sector_pos * dev->drv->sector_size), + SEEK_SET) == -1) { + if (out) + mo_write_error(dev); + else + mo_read_error(dev); + ret = -1; + } else { + if (feof(dev->drv->fp)) + break; + + if (out) { + if (fwrite(dev->buffer + (i * dev->drv->sector_size), 1, + dev->drv->sector_size, dev->drv->fp) != dev->drv->sector_size) { + mo_log(dev->log, "mo_blocks(): Error writing data\n"); + mo_write_error(dev); + ret = -1; + } else + fflush(dev->drv->fp); + } else if (fread(dev->buffer + (i * dev->drv->sector_size), 1, + dev->drv->sector_size, dev->drv->fp) != dev->drv->sector_size) { + mo_log(dev->log, "mo_blocks(): Error reading data\n"); + mo_read_error(dev); + ret = -1; + } + } + + if (ret == -1) + break; + + dev->sector_pos++; + } + + if (ret == 1) { + mo_log(dev->log, "%s %i bytes of blocks...\n", out ? "Written" : + "Read", *len); + + dev->sector_len -= dev->requested_blocks; } } + } else { + mo_command_complete(dev); + ret = 0; } - mo_log("%s %i bytes of blocks...\n", out ? "Written" : "Read", *len); - - dev->sector_pos += dev->requested_blocks; - dev->sector_len -= dev->requested_blocks; - - return 1; + return ret; } void mo_insert(mo_t *dev) { - dev->unit_attention = 1; + if ((dev != NULL) && (dev->drv != NULL)) { + if (dev->drv->fp == NULL) { + dev->unit_attention = 0; + dev->transition = 0; + mo_log(dev->log, "Media removal\n"); + } else if (dev->transition) { + dev->unit_attention = 1; + /* Turn off the medium changed status. */ + dev->transition = 0; + mo_log(dev->log, "Media insert\n"); + } else { + dev->unit_attention = 0; + dev->transition = 1; + mo_log(dev->log, "Media transition\n"); + } + } } void mo_format(mo_t *dev) { - long size; int ret; int fd; - mo_log("MO %i: Formatting media...\n", dev->id); + mo_log(dev->log, "Formatting media...\n"); - fseek(dev->drv->fp, 0, SEEK_END); - size = ftell(dev->drv->fp); + fseeko64(dev->drv->fp, 0, SEEK_END); + int64_t size = ftello64(dev->drv->fp); #ifdef _WIN32 - HANDLE fh; LARGE_INTEGER liSize; - fd = _fileno(dev->drv->fp); - fh = (HANDLE) _get_osfhandle(fd); + fd = _fileno(dev->drv->fp); + const HANDLE fh = (HANDLE) _get_osfhandle(fd); liSize.QuadPart = 0; ret = (int) SetFilePointerEx(fh, liSize, NULL, FILE_BEGIN); - if (!ret) { - mo_log("MO %i: Failed seek to start of image file\n", dev->id); - return; - } + if (ret) { + ret = (int) SetEndOfFile(fh); - ret = (int) SetEndOfFile(fh); + if (ret) { + liSize.QuadPart = size; + ret = (int) SetFilePointerEx(fh, liSize, NULL, FILE_BEGIN); - if (!ret) { - mo_log("MO %i: Failed to truncate image file to 0\n", dev->id); - return; - } + if (ret) { + ret = (int) SetEndOfFile(fh); - liSize.QuadPart = size; - ret = (int) SetFilePointerEx(fh, liSize, NULL, FILE_BEGIN); - - if (!ret) { - mo_log("MO %i: Failed seek to end of image file\n", dev->id); - return; - } - - ret = (int) SetEndOfFile(fh); - - if (!ret) { - mo_log("MO %i: Failed to truncate image file to %llu\n", dev->id, size); - return; + if (!ret) { + mo_log(dev->log, "Failed to truncate image file to %llu\n", size); + } + } else { + mo_log(dev->log, "Failed seek to end of image file\n"); + } + } else { + mo_log(dev->log, "Failed to truncate image file to 0\n"); + } + } else { + mo_log(dev->log, "Failed seek to start of image file\n"); } #else fd = fileno(dev->drv->fp); @@ -1057,15 +934,13 @@ mo_format(mo_t *dev) ret = ftruncate(fd, 0); if (ret) { - mo_log("MO %i: Failed to truncate image file to 0\n", dev->id); - return; - } + mo_log(dev->log, "Failed to truncate image file to 0\n"); + } else { + ret = ftruncate(fd, size); - ret = ftruncate(fd, size); - - if (ret) { - mo_log("MO %i: Failed to truncate image file to %llu", dev->id, size); - return; + if (ret) { + mo_log(dev->log, "Failed to truncate image file to %llu", size); + } } #endif } @@ -1080,10 +955,15 @@ mo_erase(mo_t *dev) return -1; } - mo_log("MO %i: Erasing %i blocks starting from %i...\n", dev->id, dev->sector_len, dev->sector_pos); + mo_log(dev->log, "Erasing %i blocks starting from %i...\n", + dev->sector_len, dev->sector_pos); - if (dev->sector_pos >= dev->drv->medium_size) { - mo_log("MO %i: Trying to erase beyond the end of disk\n", dev->id); + if (!dev->drv->supported) { + mo_log(dev->log, "Trying to erase an unsupported medium\n"); + mo_write_error(dev); + return 0; + } else if (dev->sector_pos >= dev->drv->medium_size) { + mo_log(dev->log, "Trying to erase beyond the end of disk\n"); mo_lba_out_of_range(dev); return 0; } @@ -1091,7 +971,9 @@ mo_erase(mo_t *dev) mo_buf_alloc(dev, dev->drv->sector_size); memset(dev->buffer, 0, dev->drv->sector_size); - fseek(dev->drv->fp, dev->drv->base + (dev->sector_pos * dev->drv->sector_size), SEEK_SET); + fseeko64(dev->drv->fp, dev->drv->base + + ((uint64_t) dev->sector_pos * dev->drv->sector_size), + SEEK_SET); for (i = 0; i < dev->requested_blocks; i++) { if (feof(dev->drv->fp)) @@ -1102,7 +984,7 @@ mo_erase(mo_t *dev) fflush(dev->drv->fp); - mo_log("MO %i: Erased %i bytes of blocks...\n", dev->id, i * dev->drv->sector_size); + mo_log(dev->log, "Erased %i bytes of blocks...\n", i * dev->drv->sector_size); dev->sector_pos += i; dev->sector_len -= i; @@ -1110,96 +992,110 @@ mo_erase(mo_t *dev) return 1; } -/*SCSI Sense Initialization*/ -void -mo_sense_code_ok(mo_t *dev) -{ - mo_sense_key = SENSE_NONE; - mo_asc = 0; - mo_ascq = 0; -} - static int -mo_pre_execution_check(mo_t *dev, uint8_t *cdb) +mo_pre_execution_check(mo_t *dev, const uint8_t *cdb) { - int ready = 0; + int ready; - if ((cdb[0] != GPCMD_REQUEST_SENSE) && (dev->cur_lun == SCSI_LUN_USE_CDB) && (cdb[1] & 0xe0)) { - mo_log("MO %i: Attempting to execute a unknown command targeted at SCSI LUN %i\n", dev->id, + if ((cdb[0] != GPCMD_REQUEST_SENSE) && (dev->cur_lun == SCSI_LUN_USE_CDB) && + (cdb[1] & 0xe0)) { + mo_log(dev->log, "Attempting to execute a unknown command targeted at SCSI LUN %i\n", ((dev->tf->request_length >> 5) & 7)); - mo_invalid_lun(dev); + mo_invalid_lun(dev, cdb[1] >> 5); return 0; } if (!(mo_command_flags[cdb[0]] & IMPLEMENTED)) { - mo_log("MO %i: Attempting to execute unknown command %02X over %s\n", dev->id, cdb[0], - (dev->drv->bus_type == MO_BUS_SCSI) ? "SCSI" : "ATAPI"); + mo_log(dev->log, "Attempting to execute unknown command %02X over %s\n", + cdb[0], (dev->drv->bus_type == MO_BUS_SCSI) ? + "SCSI" : "ATAPI"); - mo_illegal_opcode(dev); + mo_illegal_opcode(dev, cdb[0]); return 0; } - if ((dev->drv->bus_type < MO_BUS_SCSI) && (mo_command_flags[cdb[0]] & SCSI_ONLY)) { - mo_log("MO %i: Attempting to execute SCSI-only command %02X over ATAPI\n", dev->id, cdb[0]); - mo_illegal_opcode(dev); + if ((dev->drv->bus_type < MO_BUS_SCSI) && + (mo_command_flags[cdb[0]] & SCSI_ONLY)) { + mo_log(dev->log, "Attempting to execute SCSI-only command %02X " + "over ATAPI\n", cdb[0]); + mo_illegal_opcode(dev, cdb[0]); return 0; } - if ((dev->drv->bus_type == MO_BUS_SCSI) && (mo_command_flags[cdb[0]] & ATAPI_ONLY)) { - mo_log("MO %i: Attempting to execute ATAPI-only command %02X over SCSI\n", dev->id, cdb[0]); - mo_illegal_opcode(dev); + if ((dev->drv->bus_type == MO_BUS_SCSI) && + (mo_command_flags[cdb[0]] & ATAPI_ONLY)) { + mo_log(dev->log, "Attempting to execute ATAPI-only command %02X " + "over SCSI\n", cdb[0]); + mo_illegal_opcode(dev, cdb[0]); return 0; } - ready = (dev->drv->fp != NULL); + if (dev->transition) { + if ((cdb[0] == GPCMD_TEST_UNIT_READY) || (cdb[0] == GPCMD_REQUEST_SENSE)) + ready = 0; + else { + if (!(mo_command_flags[cdb[0]] & ALLOW_UA)) { + mo_log(dev->log, "(ext_medium_changed != 0): mo_insert()\n"); + mo_insert((void *) dev); + } - /* If the drive is not ready, there is no reason to keep the + ready = (dev->drv->fp != NULL); + } + } else + ready = (dev->drv->fp != NULL); + + /* + If the drive is not ready, there is no reason to keep the UNIT ATTENTION condition present, as we only use it to mark - disc changes. */ - if (!ready && dev->unit_attention) + disc changes. + */ + if (!ready && (dev->unit_attention > 0)) dev->unit_attention = 0; - /* If the UNIT ATTENTION condition is set and the command does not allow - execution under it, error out and report the condition. */ + /* + If the UNIT ATTENTION condition is set and the command does not allow + execution under it, error out and report the condition. + */ if (dev->unit_attention == 1) { - /* Only increment the unit attention phase if the command can not pass through it. */ + /* + Only increment the unit attention phase if the command can + not pass through it. + */ if (!(mo_command_flags[cdb[0]] & ALLOW_UA)) { - /* mo_log("MO %i: Unit attention now 2\n", dev->id); */ - dev->unit_attention = 2; - mo_log("MO %i: UNIT ATTENTION: Command %02X not allowed to pass through\n", dev->id, cdb[0]); + mo_log(dev->log, "Unit attention now 2\n"); + dev->unit_attention++; + mo_log(dev->log, "UNIT ATTENTION: Command %02X not allowed to " + "pass through\n", cdb[0]); mo_unit_attention(dev); return 0; } } else if (dev->unit_attention == 2) { if (cdb[0] != GPCMD_REQUEST_SENSE) { - /* mo_log("MO %i: Unit attention now 0\n", dev->id); */ + mo_log(dev->log, "MO %i: Unit attention now 0\n"); dev->unit_attention = 0; } } - /* Unless the command is REQUEST SENSE, clear the sense. This will *NOT* - the UNIT ATTENTION condition if it's set. */ + /* + Unless the command is REQUEST SENSE, clear the sense. This will *NOT* clear + the UNIT ATTENTION condition if it's set. + */ if (cdb[0] != GPCMD_REQUEST_SENSE) mo_sense_clear(dev, cdb[0]); - /* Next it's time for NOT READY. */ - if ((mo_command_flags[cdb[0]] & CHECK_READY) && !ready) { - mo_log("MO %i: Not ready (%02X)\n", dev->id, cdb[0]); + if (!ready && (mo_command_flags[cdb[0]] & CHECK_READY)) { + mo_log(dev->log, "Not ready (%02X)\n", cdb[0]); mo_not_ready(dev); return 0; } - mo_log("MO %i: Continuing with command %02X\n", dev->id, cdb[0]); - + mo_log(dev->log, "Continuing with command %02X\n", cdb[0]); return 1; } static void mo_seek(mo_t *dev, uint32_t pos) { -#if 0 - mo_log("MO %i: Seek %08X\n", dev->id, pos); -#endif dev->sector_pos = pos; } @@ -1220,28 +1116,30 @@ mo_reset(scsi_common_t *sc) dev->callback = 0.0; mo_set_callback(dev); dev->tf->phase = 1; - dev->tf->request_length = 0xEB14; + dev->tf->request_length = 0xeb14; dev->packet_status = PHASE_NONE; - dev->unit_attention = 0; dev->cur_lun = SCSI_LUN_USE_CDB; + mo_sense_key = mo_asc = mo_ascq = dev->unit_attention = dev->transition = 0; + mo_info = 0x00000000; } static void -mo_request_sense(mo_t *dev, uint8_t *buffer, uint8_t alloc_length, int desc) +mo_request_sense(mo_t *dev, uint8_t *buffer, const uint8_t alloc_length, const int desc) { - /*Will return 18 bytes of 0*/ + /* Will return 18 bytes of 0. */ if (alloc_length != 0) { - memset(buffer, 0, alloc_length); - if (!desc) - memcpy(buffer, dev->sense, alloc_length); - else { + memset(buffer, 0x00, alloc_length); + if (desc) { buffer[1] = mo_sense_key; buffer[2] = mo_asc; buffer[3] = mo_ascq; - } + } else + memcpy(buffer, dev->sense, alloc_length); } - buffer[0] = desc ? 0x72 : 0x70; + buffer[0] = desc ? 0x72 : 0xf0; + if (!desc) + buffer[7] = 10; if (dev->unit_attention && (mo_sense_key == 0)) { buffer[desc ? 1 : 2] = SENSE_UNIT_ATTENTION; @@ -1249,25 +1147,27 @@ mo_request_sense(mo_t *dev, uint8_t *buffer, uint8_t alloc_length, int desc) buffer[desc ? 3 : 13] = 0; } - mo_log("MO %i: Reporting sense: %02X %02X %02X\n", dev->id, buffer[2], buffer[12], buffer[13]); + mo_log(dev->log, "Reporting sense: %02X %02X %02X\n", buffer[2], buffer[12], buffer[13]); if (buffer[desc ? 1 : 2] == SENSE_UNIT_ATTENTION) { - /* If the last remaining sense is unit attention, clear - that condition. */ + /* If the last remaining sense is unit attention, clear that condition. */ dev->unit_attention = 0; } /* Clear the sense stuff as per the spec. */ mo_sense_clear(dev, GPCMD_REQUEST_SENSE); + + if (dev->transition) { + mo_log(dev->log, "MO_TRANSITION: mo_insert()\n"); + mo_insert((void *) dev); + } } static void mo_request_sense_for_scsi(scsi_common_t *sc, uint8_t *buffer, uint8_t alloc_length) { - mo_t *dev = (mo_t *) sc; - int ready = 0; - - ready = (dev->drv->fp != NULL); + mo_t *dev = (mo_t *) sc; + const int ready = (dev->drv->fp != NULL); if (!ready && dev->unit_attention) { /* If the drive is not ready, there is no reason to keep the @@ -1277,12 +1177,11 @@ mo_request_sense_for_scsi(scsi_common_t *sc, uint8_t *buffer, uint8_t alloc_leng } /* Do *NOT* advance the unit attention phase. */ - mo_request_sense(dev, buffer, alloc_length, 0); } static void -mo_set_buf_len(mo_t *dev, int32_t *BufLen, int32_t *src_len) +mo_set_buf_len(const mo_t *dev, int32_t *BufLen, int32_t *src_len) { if (dev->drv->bus_type == MO_BUS_SCSI) { if (*BufLen == -1) @@ -1291,29 +1190,28 @@ mo_set_buf_len(mo_t *dev, int32_t *BufLen, int32_t *src_len) *BufLen = MIN(*src_len, *BufLen); *src_len = *BufLen; } - mo_log("MO %i: Actual transfer length: %i\n", dev->id, *BufLen); + mo_log(dev->log, "Actual transfer length: %i\n", *BufLen); } } static void -mo_command(scsi_common_t *sc, uint8_t *cdb) +mo_command(scsi_common_t *sc, const uint8_t *cdb) { - mo_t *dev = (mo_t *) sc; - int pos = 0; - int block_desc = 0; - int ret; - int32_t len; - int32_t max_len; - int32_t alloc_length; - 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; - int32_t *BufLen; - uint32_t previous_pos = 0; - uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; - uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; + mo_t * dev = (mo_t *) sc; + char device_identify[9] = { '8', '6', 'B', '_', 'M', 'O', '0', '0', 0 }; + uint32_t previous_pos = 0; + int32_t blen = 0; + const uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; + const uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; + int pos = 0; + int idx = 0; + int32_t len; + int32_t max_len; + int32_t alloc_length; + unsigned preamble_len; + int block_desc; + int size_idx; + int32_t * BufLen; if (dev->drv->bus_type == MO_BUS_SCSI) { BufLen = &scsi_devices[scsi_bus][scsi_id].buffer_length; @@ -1331,11 +1229,13 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) memcpy(dev->current_cdb, cdb, 12); if (cdb[0] != 0) { - mo_log("MO %i: Command 0x%02X, Sense Key %02X, Asc %02X, Ascq %02X, Unit attention: %i\n", - dev->id, cdb[0], mo_sense_key, mo_asc, mo_ascq, dev->unit_attention); - mo_log("MO %i: Request length: %04X\n", dev->id, dev->tf->request_length); + mo_log(dev->log, "Command 0x%02X, Sense Key %02X, Asc %02X, Ascq %02X, " + "Unit attention: %i\n", + cdb[0], mo_sense_key, mo_asc, mo_ascq, dev->unit_attention); + mo_log(dev->log, "Request length: %04X\n", dev->tf->request_length); - mo_log("MO %i: CDB: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n", dev->id, + mo_log(dev->log, "CDB: %02X %02X %02X %02X %02X %02X %02X %02X " + "%02X %02X %02X %02X\n", cdb[0], cdb[1], cdb[2], cdb[3], cdb[4], cdb[5], cdb[6], cdb[7], cdb[8], cdb[9], cdb[10], cdb[11]); } @@ -1344,14 +1244,17 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) mo_set_phase(dev, SCSI_PHASE_STATUS); - /* This handles the Not Ready/Unit Attention check if it has to be handled at this point. */ + /* + This handles the Not Ready/Unit Attention check if it has to be + handled at this point. + */ if (mo_pre_execution_check(dev, cdb) == 0) return; switch (cdb[0]) { case GPCMD_SEND_DIAGNOSTIC: if (!(cdb[1] & (1 << 2))) { - mo_invalid_field(dev); + mo_invalid_field(dev, cdb[1]); return; } fallthrough; @@ -1380,8 +1283,6 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) break; case GPCMD_REQUEST_SENSE: - /* If there's a unit attention condition and there's a buffered not ready, a standalone REQUEST SENSE - should forget about the not ready, and report unit attention straight away. */ mo_set_phase(dev, SCSI_PHASE_DATA_IN); max_len = cdb[4]; @@ -1422,83 +1323,82 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) switch (cdb[0]) { case GPCMD_READ_6: dev->sector_len = cdb[4]; - dev->sector_pos = ((((uint32_t) cdb[1]) & 0x1f) << 16) | (((uint32_t) cdb[2]) << 8) | ((uint32_t) cdb[3]); + dev->sector_pos = ((((uint32_t) cdb[1]) & 0x1f) << 16) | + (((uint32_t) cdb[2]) << 8) | ((uint32_t) cdb[3]); if (dev->sector_len == 0) dev->sector_len = 256; - mo_log("MO %i: Length: %i, LBA: %i\n", dev->id, dev->sector_len, dev->sector_pos); + mo_log(dev->log, "Length: %i, LBA: %i\n", dev->sector_len, dev->sector_pos); break; case GPCMD_READ_10: dev->sector_len = (cdb[7] << 8) | cdb[8]; - dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; - mo_log("MO %i: Length: %i, LBA: %i\n", dev->id, dev->sector_len, dev->sector_pos); + dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | + (cdb[4] << 8) | cdb[5]; + mo_log(dev->log, "Length: %i, LBA: %i\n", dev->sector_len, dev->sector_pos); break; case GPCMD_READ_12: - 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]); - mo_log("MO %i: Length: %i, LBA: %i\n", dev->id, dev->sector_len, dev->sector_pos); + 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]); + mo_log(dev->log, "Length: %i, LBA: %i\n", dev->sector_len, dev->sector_pos); break; default: break; } - if (!dev->sector_len) { + if (dev->sector_len) { + max_len = dev->sector_len; + dev->requested_blocks = max_len; + + dev->packet_len = max_len * alloc_length; + mo_buf_alloc(dev, dev->packet_len); + + const int ret = mo_blocks(dev, &alloc_length, 0); + alloc_length = dev->requested_blocks * dev->drv->sector_size; + + if (ret > 0) { + dev->requested_blocks = max_len; + dev->packet_len = alloc_length; + + mo_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); + + mo_data_command_finish(dev, alloc_length, dev->drv->sector_size, alloc_length, 0); + + if (dev->packet_status != PHASE_COMPLETE) + ui_sb_update_icon(SB_MO | dev->id, 1); + else + ui_sb_update_icon(SB_MO | dev->id, 0); + } else { + mo_set_phase(dev, SCSI_PHASE_STATUS); + dev->packet_status = (ret < 0) ? PHASE_ERROR : PHASE_COMPLETE; + dev->callback = 20.0 * MO_TIME; + mo_set_callback(dev); + mo_buf_free(dev); + } + } else { mo_set_phase(dev, SCSI_PHASE_STATUS); - /* mo_log("MO %i: All done - callback set\n", dev->id); */ + /* mo_log(dev->log, "All done - callback set\n"); */ dev->packet_status = PHASE_COMPLETE; dev->callback = 20.0 * MO_TIME; mo_set_callback(dev); - break; } - - max_len = dev->sector_len; - dev->requested_blocks = max_len; /* If we're reading all blocks in one go for DMA, why not also for PIO, it should NOT - matter anyway, this step should be identical and only the way the read dat is - transferred to the host should be different. */ - - dev->packet_len = max_len * alloc_length; - mo_buf_alloc(dev, dev->packet_len); - - ret = mo_blocks(dev, &alloc_length, 1, 0); - if (ret <= 0) { - mo_set_phase(dev, SCSI_PHASE_STATUS); - dev->packet_status = (ret < 0) ? PHASE_ERROR : PHASE_COMPLETE; - dev->callback = 20.0 * MO_TIME; - mo_set_callback(dev); - mo_buf_free(dev); - return; - } - - dev->requested_blocks = max_len; - dev->packet_len = alloc_length; - - mo_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); - - mo_data_command_finish(dev, alloc_length, dev->drv->sector_size, alloc_length, 0); - - if (dev->packet_status != PHASE_COMPLETE) - ui_sb_update_icon(SB_MO | dev->id, 1); - else - ui_sb_update_icon(SB_MO | dev->id, 0); - return; + break; case GPCMD_VERIFY_6: case GPCMD_VERIFY_10: case GPCMD_VERIFY_12: - /* Data and blank verification cannot be set at the same time */ - if ((cdb[1] & 2) && (cdb[1] & 4)) { - mo_invalid_field(dev); - return; - } - if (!(cdb[1] & 2) || (cdb[1] & 4)) { + if (!(cdb[1] & 2)) { mo_set_phase(dev, SCSI_PHASE_STATUS); mo_command_complete(dev); break; + } else if (!dev->drv->supported) { + mo_read_error(dev); + break; } - /*TODO: Implement*/ - mo_invalid_field(dev); - return; - + fallthrough; case GPCMD_WRITE_6: case GPCMD_WRITE_10: case GPCMD_WRITE_AND_VERIFY_10: @@ -1507,73 +1407,113 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) mo_set_phase(dev, SCSI_PHASE_DATA_OUT); alloc_length = dev->drv->sector_size; - if (dev->drv->read_only) { - mo_write_protected(dev); - return; - } - switch (cdb[0]) { case GPCMD_VERIFY_6: case GPCMD_WRITE_6: dev->sector_len = cdb[4]; + /* + For READ (6) and WRITE (6), a length of 0 indicates a + transfer of 256 sectors. + */ if (dev->sector_len == 0) - dev->sector_len = 256; /* For READ (6) and WRITE (6), a length of 0 indicates a transfer of 256 sector. */ - dev->sector_pos = ((((uint32_t) cdb[1]) & 0x1f) << 16) | (((uint32_t) cdb[2]) << 8) | ((uint32_t) cdb[3]); + dev->sector_len = 256; + dev->sector_pos = ((((uint32_t) cdb[1]) & 0x1f) << 16) | + (((uint32_t) cdb[2]) << 8) | ((uint32_t) cdb[3]); + mo_log(dev->log, "Length: %i, LBA: %i\n", dev->sector_len, dev->sector_pos); break; case GPCMD_VERIFY_10: case GPCMD_WRITE_10: case GPCMD_WRITE_AND_VERIFY_10: dev->sector_len = (cdb[7] << 8) | cdb[8]; - dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; - mo_log("MO %i: Length: %i, LBA: %i\n", dev->id, dev->sector_len, dev->sector_pos); + dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | + (cdb[4] << 8) | cdb[5]; + mo_log(dev->log, "Length: %i, LBA: %i\n", dev->sector_len, dev->sector_pos); break; case GPCMD_VERIFY_12: case GPCMD_WRITE_12: case GPCMD_WRITE_AND_VERIFY_12: - 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]); + 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) /* || - ((dev->sector_pos + dev->sector_len - 1) >= dev->drv->medium_size)*/ - ) { + if (!dev->drv->supported) + mo_write_error(dev); + else if (dev->sector_pos >= dev->drv->medium_size) mo_lba_out_of_range(dev); - return; + else { + if (dev->sector_len) { + max_len = dev->sector_len; + dev->requested_blocks = max_len; + + dev->packet_len = max_len * alloc_length; + mo_buf_alloc(dev, dev->packet_len); + + dev->requested_blocks = max_len; + dev->packet_len = max_len * dev->drv->sector_size; + + mo_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); + + mo_data_command_finish(dev, dev->packet_len, dev->drv->sector_size, + dev->packet_len, 1); + + ui_sb_update_icon_write(SB_MO | dev->id, + dev->packet_status != PHASE_COMPLETE); + } else { + mo_set_phase(dev, SCSI_PHASE_STATUS); + mo_log(dev->log, "All done - callback set\n"); + dev->packet_status = PHASE_COMPLETE; + dev->callback = 20.0 * SCSI_TIME; + mo_set_callback(dev); + } } + break; - if (!dev->sector_len) { - mo_set_phase(dev, SCSI_PHASE_STATUS); - /* mo_log("MO %i: All done - callback set\n", dev->id); */ - dev->packet_status = PHASE_COMPLETE; - dev->callback = 20.0 * MO_TIME; - mo_set_callback(dev); - break; + case GPCMD_WRITE_SAME_10: + mo_set_phase(dev, SCSI_PHASE_DATA_OUT); + alloc_length = dev->drv->sector_size; + + if ((cdb[1] & 6) == 6) + mo_invalid_field(dev, cdb[1]); + else { + dev->sector_len = (cdb[7] << 8) | cdb[8]; + dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; + + if (!dev->drv->supported) + mo_write_error(dev); + else if (dev->sector_pos >= dev->drv->medium_size) + mo_lba_out_of_range(dev); + else if (dev->sector_len) { + mo_buf_alloc(dev, alloc_length); + mo_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); + + dev->requested_blocks = 1; + dev->packet_len = alloc_length; + + mo_set_phase(dev, SCSI_PHASE_DATA_OUT); + + mo_data_command_finish(dev, dev->drv->sector_size, + dev->drv->sector_size, + alloc_length, 1); + + ui_sb_update_icon_write(SB_MO | dev->id, + dev->packet_status != PHASE_COMPLETE); + } else { + mo_set_phase(dev, SCSI_PHASE_STATUS); + mo_log(dev->log, "All done - callback set\n"); + dev->packet_status = PHASE_COMPLETE; + dev->callback = 20.0 * SCSI_TIME; + mo_set_callback(dev); + } } - - max_len = dev->sector_len; - dev->requested_blocks = max_len; /* If we're writing all blocks in one go for DMA, why not also for PIO, it should NOT - matter anyway, this step should be identical and only the way the read dat is - transferred to the host should be different. */ - - dev->packet_len = max_len * alloc_length; - mo_buf_alloc(dev, dev->packet_len); - - dev->requested_blocks = max_len; - dev->packet_len = max_len << 9; - - mo_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); - - mo_data_command_finish(dev, dev->packet_len, dev->drv->sector_size, dev->packet_len, 1); - - if (dev->packet_status != PHASE_COMPLETE) - ui_sb_update_icon(SB_MO | dev->id, 1); - else - ui_sb_update_icon(SB_MO | dev->id, 0); - return; + break; case GPCMD_MODE_SENSE_6: case GPCMD_MODE_SENSE_10: @@ -1593,7 +1533,7 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) } if (!(mo_mode_sense_page_flags & (1LL << (uint64_t) (cdb[2] & 0x3f)))) { - mo_invalid_field(dev); + mo_invalid_field(dev, cdb[2]); mo_buf_free(dev); return; } @@ -1602,14 +1542,16 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) alloc_length = len; if (cdb[0] == GPCMD_MODE_SENSE_6) { - len = mo_mode_sense(dev, dev->buffer, 4, cdb[2], block_desc); + len = mo_mode_sense(dev, dev->buffer, 4, + cdb[2], block_desc); len = MIN(len, alloc_length); dev->buffer[0] = len - 1; dev->buffer[1] = 0; if (block_desc) dev->buffer[3] = 8; } else { - len = mo_mode_sense(dev, dev->buffer, 8, cdb[2], block_desc); + len = mo_mode_sense(dev, dev->buffer, 8, + cdb[2], block_desc); len = MIN(len, alloc_length); dev->buffer[0] = (len - 2) >> 8; dev->buffer[1] = (len - 2) & 255; @@ -1622,7 +1564,7 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) mo_set_buf_len(dev, BufLen, &len); - mo_log("MO %i: Reading mode page: %02X...\n", dev->id, cdb[2]); + mo_log(dev->log, "Reading mode page: %02X...\n", cdb[2]); mo_data_command_finish(dev, len, len, alloc_length, 0); return; @@ -1682,7 +1624,7 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) preamble_len = 4; size_idx = 3; - dev->buffer[idx++] = 7; /*Optical disk*/ + dev->buffer[idx++] = 7; /* Optical disk */ dev->buffer[idx++] = cdb[2]; dev->buffer[idx++] = 0; @@ -1693,14 +1635,15 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) dev->buffer[idx++] = 0x00; dev->buffer[idx++] = 0x80; break; - case 0x80: /*Unit serial number page*/ + case 0x80: /*Unit serial number page*/ dev->buffer[idx++] = strlen("VCM!10") + 1; - ide_padstr8(dev->buffer + idx, 20, "VCM!10"); /* Serial */ + /* Serial */ + ide_padstr8(dev->buffer + idx, 20, "VCM!10"); idx += strlen("VCM!10"); break; default: - mo_log("INQUIRY: Invalid page: %02X\n", cdb[2]); - mo_invalid_field(dev); + mo_log(dev->log, "INQUIRY: Invalid page: %02X\n", cdb[2]); + mo_invalid_field(dev, cdb[2]); mo_buf_free(dev); return; } @@ -1710,30 +1653,34 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) memset(dev->buffer, 0, 8); if ((cdb[1] & 0xe0) || ((dev->cur_lun > 0x00) && (dev->cur_lun < 0xff))) - dev->buffer[0] = 0x7f; /*No physical device on this LUN*/ + dev->buffer[0] = 0x7f; /* No physical device on this LUN */ else - dev->buffer[0] = 0x07; /*Optical disk*/ - dev->buffer[1] = 0x80; /*Removable*/ - dev->buffer[2] = (dev->drv->bus_type == MO_BUS_SCSI) ? 0x02 : 0x00; /*SCSI-2 compliant*/ + dev->buffer[0] = 0x07; /* Optical disk */ + dev->buffer[1] = 0x80; /* Removable */ + /* SCSI-2 compliant */ + dev->buffer[2] = (dev->drv->bus_type == MO_BUS_SCSI) ? 0x02 : 0x00; dev->buffer[3] = (dev->drv->bus_type == MO_BUS_SCSI) ? 0x02 : 0x21; -#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 */ - dev->buffer[7] = 0x20; /* Wide bus supported */ + dev->buffer[6] = 1; /* 16-bit transfers supported */ + dev->buffer[7] = 0x20; /* Wide bus supported */ } dev->buffer[7] |= 0x02; if (dev->drv->type > 0) { - ide_padstr8(dev->buffer + 8, 8, mo_drive_types[dev->drv->type].vendor); /* Vendor */ - ide_padstr8(dev->buffer + 16, 16, mo_drive_types[dev->drv->type].model); /* Product */ - ide_padstr8(dev->buffer + 32, 4, mo_drive_types[dev->drv->type].revision); /* Revision */ + ide_padstr8(dev->buffer + 8, 8, + mo_drive_types[dev->drv->type].vendor); /* Vendor */ + ide_padstr8(dev->buffer + 16, 16, + mo_drive_types[dev->drv->type].model); /* Product */ + ide_padstr8(dev->buffer + 32, 4, + mo_drive_types[dev->drv->type].revision); /* Revision */ } else { - 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 */ + 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 */ } idx = 36; @@ -1784,7 +1731,8 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) mo_buf_alloc(dev, 8); - max_len = dev->drv->medium_size - 1; /* IMPORTANT: What's returned is the last LBA block. */ + /* IMPORTANT: What's returned is the last LBA block. */ + max_len = dev->drv->medium_size - 1; memset(dev->buffer, 0, 8); dev->buffer[0] = (max_len >> 24) & 0xff; dev->buffer[1] = (max_len >> 16) & 0xff; @@ -1801,7 +1749,7 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) case GPCMD_ERASE_10: case GPCMD_ERASE_12: - /*Relative address*/ + /* Relative address. */ if (cdb[1] & 1) previous_pos = dev->sector_pos; @@ -1810,18 +1758,20 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) dev->sector_len = (cdb[7] << 8) | cdb[8]; break; 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]); + 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*/ + /* Erase all remaining sectors. */ if (cdb[1] & 4) { - /* Cannot have a sector number when erase all*/ + /* Cannot have a sector number when erase all. */ if (dev->sector_len) { - mo_invalid_field(dev); + mo_invalid_field(dev, dev->sector_len); return; } mo_format(dev); @@ -1832,10 +1782,13 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) switch (cdb[0]) { case GPCMD_ERASE_10: - dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; + dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | + (cdb[4] << 8) | cdb[5]; break; 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]); + dev->sector_pos = (((uint32_t) cdb[2]) << 24) | + (((uint32_t) cdb[3]) << 16) | + (((uint32_t) cdb[4]) << 8) | ((uint32_t) cdb[5]); break; default: @@ -1849,7 +1802,10 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) mo_command_complete(dev); break; - /*Never seen media that supports generations but it's interesting to know if any implementation calls this commmand*/ + /* + Never seen media that supports generations but it's interesting to know if any + implementation calls this commmand. + */ case GPCMD_READ_GENERATION: mo_set_phase(dev, SCSI_PHASE_DATA_IN); @@ -1866,12 +1822,13 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) break; default: - mo_illegal_opcode(dev); + mo_illegal_opcode(dev, cdb[0]); break; } #if 0 - mo_log("MO %i: Phase: %02X, request length: %i\n", dev->id, dev->tf->phase, dev->tf->request_length); + mo_log(dev->log, "Phase: %02X, request length: %i\n", + dev->tf->phase, dev->tf->request_length); #endif if ((dev->packet_status == PHASE_COMPLETE) || (dev->packet_status == PHASE_ERROR)) @@ -1891,22 +1848,16 @@ mo_command_stop(scsi_common_t *sc) static uint8_t mo_phase_data_out(scsi_common_t *sc) { - mo_t *dev = (mo_t *) sc; - - uint16_t block_desc_len; - uint16_t pos; - uint16_t param_list_len; - - uint8_t error = 0; - uint8_t page; - uint8_t page_len; - - uint8_t hdr_len; - uint8_t val; - uint8_t old_val; - uint8_t ch; - - int len = 0; + mo_t * dev = (mo_t *) sc; + const uint32_t last_sector = dev->drv->medium_size - 1; + int len = 0; + uint8_t error = 0; + uint32_t last_to_write; + uint16_t block_desc_len; + uint16_t pos; + uint16_t param_list_len; + uint8_t hdr_len; + uint8_t val; switch (dev->current_cdb[0]) { case GPCMD_VERIFY_6: @@ -1919,7 +1870,41 @@ mo_phase_data_out(scsi_common_t *sc) case GPCMD_WRITE_12: case GPCMD_WRITE_AND_VERIFY_12: if (dev->requested_blocks > 0) - mo_blocks(dev, &len, 1, 1); + mo_blocks(dev, &len, 1); + break; + case GPCMD_WRITE_SAME_10: + if (!dev->current_cdb[7] && !dev->current_cdb[8]) + last_to_write = last_sector; + else + last_to_write = dev->sector_pos + dev->sector_len - 1; + + for (int i = dev->sector_pos; i <= (int) last_to_write; i++) { + if (dev->current_cdb[1] & 2) { + dev->buffer[0] = (i >> 24) & 0xff; + dev->buffer[1] = (i >> 16) & 0xff; + dev->buffer[2] = (i >> 8) & 0xff; + dev->buffer[3] = i & 0xff; + } else if (dev->current_cdb[1] & 4) { + uint32_t s = (i % 63); + uint32_t h = ((i - s) / 63) % 16; + uint32_t c = ((i - s) / 63) / 16; + dev->buffer[0] = (c >> 16) & 0xff; + dev->buffer[1] = (c >> 8) & 0xff; + dev->buffer[2] = c & 0xff; + dev->buffer[3] = h & 0xff; + dev->buffer[4] = (s >> 24) & 0xff; + dev->buffer[5] = (s >> 16) & 0xff; + dev->buffer[6] = (s >> 8) & 0xff; + dev->buffer[7] = s & 0xff; + } + if (fseeko64(dev->drv->fp, + ((uint64_t) i * dev->drv->sector_size), SEEK_SET) == -1) + mo_write_error(dev); + if (feof(dev->drv->fp)) + break; + if (fwrite(dev->buffer, 1, dev->drv->sector_size, dev->drv->fp) != dev->drv->sector_size) + mo_write_error(dev); + } break; case GPCMD_MODE_SELECT_6: case GPCMD_MODE_SELECT_10: @@ -1947,30 +1932,33 @@ mo_phase_data_out(scsi_common_t *sc) block_desc_len = 0; pos = hdr_len + block_desc_len; + mo_log(dev->log, "Block descriptor: %08X %08X %08X %08X %08X %08X %08X %08X\n", + dev->buffer[hdr_len], dev->buffer[hdr_len + 1], dev->buffer[hdr_len + 2], dev->buffer[hdr_len + 3], + dev->buffer[hdr_len + 4], dev->buffer[hdr_len + 5], dev->buffer[hdr_len + 6], dev->buffer[hdr_len + 7]); while (1) { if (pos >= param_list_len) { - mo_log("MO %i: Buffer has only block descriptor\n", dev->id); + mo_log(dev->log, "Buffer has only block descriptor\n"); break; } - page = dev->buffer[pos] & 0x3F; - page_len = dev->buffer[pos + 1]; + const uint8_t page = dev->buffer[pos] & 0x3F; + const uint8_t page_len = dev->buffer[pos + 1]; pos += 2; if (!(mo_mode_sense_page_flags & (1LL << ((uint64_t) page)))) error |= 1; - else { - 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]; - if (val != old_val) { - if (ch) - dev->ms_pages_saved.pages[page][i + 2] = val; - else - error |= 1; + else for (uint8_t i = 0; i < page_len; i++) { + const uint8_t ch = mo_mode_sense_pages_changeable.pages[page][i + 2]; + const uint8_t old_val = dev->ms_pages_saved.pages[page][i + 2]; + val = dev->buffer[pos + i]; + if (val != old_val) { + if (ch) + dev->ms_pages_saved.pages[page][i + 2] = val; + else { + error |= 1; + mo_invalid_field_pl(dev, val); } } } @@ -1990,7 +1978,6 @@ mo_phase_data_out(scsi_common_t *sc) if (error) { mo_buf_free(dev); - mo_invalid_field_pl(dev); return 0; } break; @@ -2012,7 +1999,7 @@ mo_global_init(void) } static int -mo_get_max(int ide_has_dma, int type) +mo_get_max(UNUSED(const ide_t *ide), const int ide_has_dma, const int type) { int ret; @@ -2036,7 +2023,7 @@ mo_get_max(int ide_has_dma, int type) } static int -mo_get_timings(int ide_has_dma, int type) +mo_get_timings(UNUSED(const ide_t *ide), const int ide_has_dma, const int type) { int ret; @@ -2059,7 +2046,7 @@ mo_get_timings(int ide_has_dma, int type) } static void -mo_do_identify(ide_t *ide, int ide_has_dma) +mo_do_identify(const ide_t *ide, const int ide_has_dma) { char model[40]; @@ -2068,56 +2055,65 @@ mo_do_identify(ide_t *ide, int ide_has_dma) memset(model, 0, 40); if (mo_drives[mo->id].type > 0) { - snprintf(model, 40, "%s %s", mo_drive_types[mo_drives[mo->id].type].vendor, mo_drive_types[mo_drives[mo->id].type].model); - ide_padstr((char *) (ide->buffer + 23), mo_drive_types[mo_drives[mo->id].type].revision, 8); /* Firmware */ + snprintf(model, 40, "%s %s", mo_drive_types[mo_drives[mo->id].type].vendor, + mo_drive_types[mo_drives[mo->id].type].model); + /* Firmware */ + ide_padstr((char *) (ide->buffer + 23), + mo_drive_types[mo_drives[mo->id].type].revision, 8); ide_padstr((char *) (ide->buffer + 27), model, 40); /* Model */ } else { snprintf(model, 40, "%s %s%02i", EMU_NAME, "86B_MO", mo->id); - ide_padstr((char *) (ide->buffer + 23), EMU_VERSION_EX, 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), model, 40); /* Model */ + ide_padstr((char *) (ide->buffer + 23), EMU_VERSION_EX, 8); /* Firmware */ + ide_padstr((char *) (ide->buffer + 27), model, 40); /* Model */ } if (ide_has_dma) { - ide->buffer[80] = 0x70; /*Supported ATA versions : ATA/ATAPI-4 ATA/ATAPI-6*/ - ide->buffer[81] = 0x19; /*Maximum ATA revision supported : ATA/ATAPI-6 T13 1410D revision 3a*/ + /* Supported ATA versions : ATA/ATAPI-4 ATA/ATAPI-6 */ + ide->buffer[80] = 0x70; + /* Maximum ATA revision supported : ATA/ATAPI-6 T13 1410D revision 3a */ + ide->buffer[81] = 0x19; } } static void -mo_identify(ide_t *ide, int ide_has_dma) +mo_identify(const ide_t *ide, const int ide_has_dma) { - ide->buffer[0] = 0x8000 | (0 << 8) | 0x80 | (1 << 5); /* ATAPI device, direct-access device, removable media, interrupt DRQ */ - ide_padstr((char *) (ide->buffer + 10), "", 20); /* Serial Number */ - ide->buffer[49] = 0x200; /* LBA supported */ - ide->buffer[126] = 0xfffe; /* Interpret zero byte count limit as maximum length */ + /* ATAPI device, direct-access device, removable media, interrupt DRQ */ + ide->buffer[0] = 0x8000 | (0 << 8) | 0x80 | (1 << 5); + ide_padstr((char *) (ide->buffer + 10), "", 20); /* Serial Number */ + ide->buffer[49] = 0x200; /* LBA supported */ + /* Interpret zero byte count limit as maximum length */ + ide->buffer[126] = 0xfffe; mo_do_identify(ide, ide_has_dma); } static void -mo_drive_reset(int c) +mo_drive_reset(const int c) { - mo_t *dev; - scsi_device_t *sd; - ide_t *id; - uint8_t scsi_bus = (mo_drives[c].scsi_device_id >> 4) & 0x0f; - uint8_t scsi_id = mo_drives[c].scsi_device_id & 0x0f; + const uint8_t scsi_bus = (mo_drives[c].scsi_device_id >> 4) & 0x0f; + const uint8_t scsi_id = mo_drives[c].scsi_device_id & 0x0f; - if (!mo_drives[c].priv) { - mo_drives[c].priv = (mo_t *) malloc(sizeof(mo_t)); - memset(mo_drives[c].priv, 0, sizeof(mo_t)); + if (mo_drives[c].priv == NULL) { + mo_drives[c].priv = (mo_t *) calloc(1, sizeof(mo_t)); + mo_t *dev = (mo_t *) mo_drives[c].priv; + + char n[1024] = { 0 }; + + sprintf(n, "MO %i", c + 1); + dev->log = log_open(n); } - dev = (mo_t *) mo_drives[c].priv; + mo_t *dev = (mo_t *) mo_drives[c].priv; dev->id = c; dev->cur_lun = SCSI_LUN_USE_CDB; if (mo_drives[c].bus_type == MO_BUS_SCSI) { - if (!dev->tf) + if (dev->tf == NULL) dev->tf = (ide_tf_t *) calloc(1, sizeof(ide_tf_t)); /* SCSI MO, attach to the SCSI bus. */ - sd = &scsi_devices[scsi_bus][scsi_id]; + scsi_device_t *sd = &scsi_devices[scsi_bus][scsi_id]; sd->sc = (scsi_common_t *) dev; sd->command = mo_command; @@ -2128,7 +2124,7 @@ mo_drive_reset(int c) sd->type = SCSI_REMOVABLE_DISK; } else if (mo_drives[c].bus_type == MO_BUS_ATAPI) { /* ATAPI MO, attach to the IDE bus. */ - id = ide_get_drive(mo_drives[c].ide_channel); + ide_t *id = ide_get_drive(mo_drives[c].ide_channel); /* If the IDE channel is initialized, we attach to it, otherwise, we do nothing - it's going to be a drive that's not attached to anything. */ @@ -2155,17 +2151,11 @@ mo_drive_reset(int c) void mo_hard_reset(void) { - mo_t *dev; - uint8_t scsi_id; - uint8_t scsi_bus; - 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); - 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; + const uint8_t scsi_bus = (mo_drives[c].scsi_device_id >> 4) & 0x0f; + const uint8_t scsi_id = mo_drives[c].scsi_device_id & 0x0f; /* Make sure to ignore any SCSI MO drive that has an out of range SCSI Bus. */ if (scsi_bus >= SCSI_BUS_MAX) @@ -2182,7 +2172,9 @@ mo_hard_reset(void) mo_drive_reset(c); - dev = (mo_t *) mo_drives[c].priv; + mo_t *dev = (mo_t *) mo_drives[c].priv; + + mo_log(dev->log, "MO hard_reset drive=%d\n", c); if (dev->tf == NULL) continue; @@ -2193,14 +2185,16 @@ mo_hard_reset(void) mo_init(dev); if (strlen(mo_drives[c].image_path)) - mo_load(dev, mo_drives[c].image_path); + mo_load(dev, mo_drives[c].image_path, 0); mo_mode_sense_load(dev); if (mo_drives[c].bus_type == MO_BUS_SCSI) - mo_log("SCSI MO drive %i attached to SCSI ID %i\n", c, mo_drives[c].scsi_device_id); + mo_log(dev->log, "SCSI MO drive %i attached to SCSI ID %i\n", + c, mo_drives[c].scsi_device_id); else if (mo_drives[c].bus_type == MO_BUS_ATAPI) - mo_log("ATAPI MO drive %i attached to IDE channel %i\n", c, mo_drives[c].ide_channel); + mo_log(dev->log, "ATAPI MO drive %i attached to IDE channel %i\n", + c, mo_drives[c].ide_channel); } } } @@ -2208,19 +2202,15 @@ mo_hard_reset(void) void mo_close(void) { - mo_t *dev; - uint8_t scsi_id; - uint8_t scsi_bus; - 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; + const uint8_t scsi_bus = (mo_drives[c].scsi_device_id >> 4) & 0x0f; + const uint8_t scsi_id = mo_drives[c].scsi_device_id & 0x0f; memset(&scsi_devices[scsi_bus][scsi_id], 0x00, sizeof(scsi_device_t)); } - dev = (mo_t *) mo_drives[c].priv; + mo_t *dev = (mo_t *) mo_drives[c].priv; if (dev) { mo_disk_unload(dev); @@ -2228,6 +2218,13 @@ mo_close(void) if (dev->tf) free(dev->tf); + if (dev->log != NULL) { + mo_log(dev->log, "Log closed\n"); + + log_close(dev->log); + dev->log = NULL; + } + free(dev); mo_drives[c].priv = NULL; } diff --git a/src/disk/zip.c b/src/disk/zip.c index 4a5a9b968..55cf901a4 100644 --- a/src/disk/zip.c +++ b/src/disk/zip.c @@ -9,30 +9,27 @@ * Implementation of the Iomega ZIP drive with SCSI(-like) * commands, for both ATAPI and SCSI usage. * - * - * * Authors: Miran Grca, * - * Copyright 2018-2019 Miran Grca. + * Copyright 2018-2025 Miran Grca. */ -#include -#include -#include -#include +#ifdef ENABLE_ZIP_LOG #include -#include -#define HAVE_STDARG_H +#endif +#include +#include +#include +#include #include <86box/86box.h> #include <86box/timer.h> -#include <86box/config.h> -#include <86box/timer.h> #include <86box/device.h> +#include <86box/log.h> #include <86box/scsi.h> #include <86box/scsi_device.h> #include <86box/nvr.h> +#include <86box/path.h> #include <86box/plat.h> #include <86box/ui.h> -#include <86box/hdc.h> #include <86box/hdc_ide.h> #include <86box/zip.h> @@ -40,402 +37,106 @@ zip_drive_t zip_drives[ZIP_NUM]; -/* Table of all SCSI commands and their flags, needed for the new disc change / not ready handler. */ +// clang-format off +/* + Table of all SCSI commands and their flags, needed for the new disc change / + not ready handler. + */ const uint8_t zip_command_flags[0x100] = { - IMPLEMENTED | CHECK_READY | NONDATA, /* 0x00 */ - IMPLEMENTED | ALLOW_UA | NONDATA | SCSI_ONLY, /* 0x01 */ - 0, - IMPLEMENTED | ALLOW_UA, /* 0x03 */ - IMPLEMENTED | CHECK_READY | ALLOW_UA | NONDATA | SCSI_ONLY, /* 0x04 */ - 0, - IMPLEMENTED, /* 0x06 */ - 0, - IMPLEMENTED | CHECK_READY, /* 0x08 */ - 0, - IMPLEMENTED | CHECK_READY, /* 0x0A */ - IMPLEMENTED | CHECK_READY | NONDATA, /* 0x0B */ - IMPLEMENTED, /* 0x0C */ - IMPLEMENTED | ATAPI_ONLY, /* 0x0D */ - 0, 0, 0, 0, - IMPLEMENTED | ALLOW_UA, /* 0x12 */ - IMPLEMENTED | CHECK_READY | NONDATA | SCSI_ONLY, /* 0x13 */ - 0, - IMPLEMENTED, /* 0x15 */ - IMPLEMENTED | SCSI_ONLY, /* 0x16 */ - IMPLEMENTED | SCSI_ONLY, /* 0x17 */ - 0, 0, - IMPLEMENTED, /* 0x1A */ - IMPLEMENTED | CHECK_READY, /* 0x1B */ - 0, - IMPLEMENTED, /* 0x1D */ - IMPLEMENTED | CHECK_READY, /* 0x1E */ - 0, 0, 0, 0, - IMPLEMENTED | ATAPI_ONLY, /* 0x23 */ - 0, - IMPLEMENTED | CHECK_READY, /* 0x25 */ - 0, 0, - IMPLEMENTED | CHECK_READY, /* 0x28 */ - 0, - IMPLEMENTED | CHECK_READY, /* 0x2A */ - IMPLEMENTED | CHECK_READY | NONDATA, /* 0x2B */ - 0, 0, - IMPLEMENTED | CHECK_READY, /* 0x2E */ - IMPLEMENTED | CHECK_READY | NONDATA | SCSI_ONLY, /* 0x2F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, - IMPLEMENTED | CHECK_READY, /* 0x41 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, - IMPLEMENTED, /* 0x55 */ - 0, 0, 0, 0, - IMPLEMENTED, /* 0x5A */ - 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, - IMPLEMENTED | CHECK_READY, /* 0xA8 */ - 0, - IMPLEMENTED | CHECK_READY, /* 0xAA */ - 0, 0, 0, - IMPLEMENTED | CHECK_READY, /* 0xAE */ - IMPLEMENTED | CHECK_READY | NONDATA | SCSI_ONLY, /* 0xAF */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - IMPLEMENTED, /* 0xBD */ - 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 + [0x00] = IMPLEMENTED | CHECK_READY, + [0x01] = IMPLEMENTED | ALLOW_UA | SCSI_ONLY, + [0x03] = IMPLEMENTED | ALLOW_UA, + [0x04] = IMPLEMENTED | CHECK_READY | ALLOW_UA | SCSI_ONLY, + [0x06] = IMPLEMENTED, + [0x08] = IMPLEMENTED | CHECK_READY, + [0x0a ... 0x0b] = IMPLEMENTED | CHECK_READY, + [0x0c] = IMPLEMENTED, + [0x0d] = IMPLEMENTED | ATAPI_ONLY, + [0x12] = IMPLEMENTED | ALLOW_UA, + [0x13] = IMPLEMENTED | CHECK_READY, + [0x15] = IMPLEMENTED, + [0x16 ... 0x17] = IMPLEMENTED | SCSI_ONLY, + [0x1a] = IMPLEMENTED, + [0x1b] = IMPLEMENTED | CHECK_READY, + [0x1d] = IMPLEMENTED, + [0x1e] = IMPLEMENTED | CHECK_READY, + [0x23] = IMPLEMENTED | ATAPI_ONLY, + [0x25] = IMPLEMENTED | CHECK_READY, + [0x28] = IMPLEMENTED | CHECK_READY, + [0x2a ... 0x2b] = IMPLEMENTED | CHECK_READY, + [0x2e ... 0x2f] = IMPLEMENTED | CHECK_READY, + [0x41] = IMPLEMENTED | CHECK_READY, + [0x55] = IMPLEMENTED, + [0x5a] = IMPLEMENTED, + [0xa8] = IMPLEMENTED | CHECK_READY, + [0xaa] = IMPLEMENTED | CHECK_READY, + [0xae] = IMPLEMENTED | CHECK_READY, + [0xaf] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0xbd] = IMPLEMENTED }; -static uint64_t zip_mode_sense_page_flags = (GPMODEP_R_W_ERROR_PAGE | GPMODEP_DISCONNECT_PAGE | GPMODEP_IOMEGA_PAGE | GPMODEP_ALL_PAGES); -static uint64_t zip_250_mode_sense_page_flags = (GPMODEP_R_W_ERROR_PAGE | GPMODEP_FLEXIBLE_DISK_PAGE | GPMODEP_CACHING_PAGE | GPMODEP_IOMEGA_PAGE | GPMODEP_ALL_PAGES); +static uint64_t zip_mode_sense_page_flags = (GPMODEP_R_W_ERROR_PAGE | GPMODEP_DISCONNECT_PAGE | + GPMODEP_IOMEGA_PAGE | GPMODEP_ALL_PAGES); +static uint64_t zip_250_mode_sense_page_flags = (GPMODEP_R_W_ERROR_PAGE | GPMODEP_FLEXIBLE_DISK_PAGE | + GPMODEP_CACHING_PAGE | GPMODEP_IOMEGA_PAGE | + GPMODEP_ALL_PAGES); -static const mode_sense_pages_t zip_mode_sense_pages_default = - // clang-format off -{ { - { 0, 0 }, - { GPMODE_R_W_ERROR_PAGE, 0x0a, 0xc8, 22, 0, 0, 0, 0, 90, 0, 0x50, 0x20 }, - { GPMODE_DISCONNECT_PAGE, 0x0e, 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 }, - { GPMODE_IOMEGA_PAGE, 0x04, 0x5c, 0x0f, 0xff, 0x0f } -} }; -// clang-format on +static const mode_sense_pages_t zip_mode_sense_pages_default = { + { [0x01] = { GPMODE_R_W_ERROR_PAGE, 0x0a, 0xc8, 0x16, 0x00, 0x00, 0x00, 0x00, + 0x5a, 0x00, 0x50, 0x20 }, + [0x02] = { GPMODE_DISCONNECT_PAGE, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x2f] = { GPMODE_IOMEGA_PAGE, 0x04, 0x5c, 0x0f, 0xff, 0x0f } } +}; -static const mode_sense_pages_t zip_250_mode_sense_pages_default = - // clang-format off -{ { - { 0, 0 }, - { GPMODE_R_W_ERROR_PAGE, 0x06, 0xc8, 0x64, 0, 0, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - {GPMODE_FLEXIBLE_DISK_PAGE, 0x1e, 0x80, 0, 0x40, 0x20, 2, 0, 0, 0xef, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0b, 0x7d, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_CACHING_PAGE, 0x0a, 4, 0, 0xff, 0xff, 0, 0, 0xff, 0xff, 0xff, 0xff }, - { 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 }, - { GPMODE_IOMEGA_PAGE, 0x04, 0x5c, 0x0f, 0x3c, 0x0f } -} }; -// clang-format on +static const mode_sense_pages_t zip_250_mode_sense_pages_default = { + { [0x01] = { GPMODE_R_W_ERROR_PAGE, 0x06, 0xc8, 0x64, 0x00, 0x00, 0x00, 0x00 }, + [0x05] = { GPMODE_FLEXIBLE_DISK_PAGE, 0x1e, 0x80, 0x00, 0x40, 0x20, 0x02, 0x00, + 0x00, 0xef, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0b, 0x7d, 0x00, 0x00 }, + [0x08] = { GPMODE_CACHING_PAGE, 0x0a, 0x04, 0x00, 0xff, 0xff, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff }, + [0x2f] = { GPMODE_IOMEGA_PAGE, 0x04, 0x5c, 0x0f, 0x3c, 0x0f } } +}; -static const mode_sense_pages_t zip_mode_sense_pages_default_scsi = - // clang-format off -{ { - { 0, 0 }, - { GPMODE_R_W_ERROR_PAGE, 0x0a, 0xc8, 22, 0, 0, 0, 0, 90, 0, 0x50, 0x20 }, - { GPMODE_DISCONNECT_PAGE, 0x0e, 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 }, - { GPMODE_IOMEGA_PAGE, 0x04, 0x5c, 0x0f, 0xff, 0x0f } -} }; -// clang-format on +static const mode_sense_pages_t zip_mode_sense_pages_default_scsi = { + { [0x01] = { GPMODE_R_W_ERROR_PAGE, 0x0a, 0xc8, 0x16, 0x00, 0x00, 0x00, 0x00, + 0x5a, 0x00, 0x50, 0x20 }, + [0x02] = { GPMODE_DISCONNECT_PAGE, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x2f] = { GPMODE_IOMEGA_PAGE, 0x04, 0x5c, 0x0f, 0xff, 0x0f } } +}; -static const mode_sense_pages_t zip_250_mode_sense_pages_default_scsi = - // clang-format off -{ { - { 0, 0 }, - { GPMODE_R_W_ERROR_PAGE, 0x06, 0xc8, 0x64, 0, 0, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - {GPMODE_FLEXIBLE_DISK_PAGE, 0x1e, 0x80, 0, 0x40, 0x20, 2, 0, 0, 0xef, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0b, 0x7d, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_CACHING_PAGE, 0x0a, 4, 0, 0xff, 0xff, 0, 0, 0xff, 0xff, 0xff, 0xff }, - { 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 }, - { GPMODE_IOMEGA_PAGE, 0x04, 0x5c, 0x0f, 0x3c, 0x0f } -} }; -// clang-format on +static const mode_sense_pages_t zip_250_mode_sense_pages_default_scsi = { + { [0x01] = { GPMODE_R_W_ERROR_PAGE, 0x06, 0xc8, 0x64, 0x00, 0x00, 0x00, 0x00 }, + [0x05] = { GPMODE_FLEXIBLE_DISK_PAGE, 0x1e, 0x80, 0x00, 0x40, 0x20, 0x02, 0x00, + 0x00, 0xef, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0b, 0x7d, 0x00, 0x00 }, + [0x08] = { GPMODE_CACHING_PAGE, 0x0a, 0x04, 0x00, 0xff, 0xff, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff }, + [0x2f] = { GPMODE_IOMEGA_PAGE, 0x04, 0x5c, 0x0f, 0x3c, 0x0f } } +}; -static const mode_sense_pages_t zip_mode_sense_pages_changeable = - // clang-format off -{ { - { 0, 0 }, +static const mode_sense_pages_t zip_mode_sense_pages_changeable = { + { [0x01] = { GPMODE_R_W_ERROR_PAGE, 0x0a, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, + 0x5a, 0xff, 0xff, 0xff }, + [0x02] = { GPMODE_DISCONNECT_PAGE, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x2f] = { GPMODE_IOMEGA_PAGE, 0x04, 0xff, 0xff, 0xff, 0xff } } +}; - { GPMODE_R_W_ERROR_PAGE, 0x0a, 0xFF, 0xFF, 0, 0, 0, 0, 0xFF, 0xFF, 0xFF, 0xFF }, - { GPMODE_DISCONNECT_PAGE, 0x0e, 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 }, - { GPMODE_IOMEGA_PAGE, 0x04, 0xff, 0xff, 0xff, 0xff } -} }; -// clang-format on - -static const mode_sense_pages_t zip_250_mode_sense_pages_changeable = - // clang-format off -{ { - { 0, 0 }, - { GPMODE_R_W_ERROR_PAGE, 0x06, 0xFF, 0xFF, 0, 0, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - {GPMODE_FLEXIBLE_DISK_PAGE, 0x1e, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_CACHING_PAGE, 0x0a, 4, 0, 0xff, 0xff, 0, 0, 0xff, 0xff, 0xff, 0xff }, - { 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 }, - { GPMODE_IOMEGA_PAGE, 0x04, 0xff, 0xff, 0xff, 0xff } -} }; +static const mode_sense_pages_t zip_250_mode_sense_pages_changeable = { + { [0x01] = { GPMODE_R_W_ERROR_PAGE, 0x06, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }, + [0x05] = { GPMODE_FLEXIBLE_DISK_PAGE, 0x1e, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00 }, + [0x08] = { GPMODE_CACHING_PAGE, 0x0a, 0x04, 0x00, 0xff, 0xff, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff }, + [0x2f] = { GPMODE_IOMEGA_PAGE, 0x04, 0xff, 0xff, 0xff, 0xff } } +}; // clang-format on static void zip_command_complete(zip_t *dev); @@ -445,32 +146,22 @@ static void zip_init(zip_t *dev); int zip_do_log = ENABLE_ZIP_LOG; static void -zip_log(const char *fmt, ...) +zip_log(void *priv, const char *fmt, ...) { va_list ap; if (zip_do_log) { va_start(ap, fmt); - pclog_ex(fmt, ap); + log_out(priv, fmt, ap); va_end(ap); } } #else -# define zip_log(fmt, ...) +# define zip_log(priv, fmt, ...) #endif -int -find_zip_for_channel(uint8_t channel) -{ - 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; - } - return 0xff; -} - static int -zip_load_abort(zip_t *dev) +zip_load_abort(const zip_t *dev) { if (dev->drv->fp) fclose(dev->drv->fp); @@ -481,104 +172,140 @@ zip_load_abort(zip_t *dev) } int -zip_load(zip_t *dev, char *fn) +image_is_zdi(const char *s) { - int size = 0; + return !strcasecmp(path_get_extension((char *) s), "ZDI"); +} - if (!dev->drv) { +int +zip_is_empty(const uint8_t id) +{ + const zip_t *dev = (const zip_t *) zip_drives[id].priv; + int ret = 0; + + if ((dev->drv == NULL) || (dev->drv->fp == NULL)) + ret = 1; + + return ret; +} + +void +zip_load(const zip_t *dev, const char *fn, const int skip_insert) +{ + const int was_empty = zip_is_empty(dev->id); + int ret = 0; + + if (dev->drv == NULL) zip_eject(dev->id); - return 0; - } + else { + const int is_zdi = image_is_zdi(fn); - dev->drv->fp = plat_fopen(fn, dev->drv->read_only ? "rb" : "rb+"); - if (!dev->drv->fp) { - if (!dev->drv->read_only) { - dev->drv->fp = plat_fopen(fn, "rb"); - if (dev->drv->fp) - dev->drv->read_only = 1; - else - return zip_load_abort(dev); - } else - return zip_load_abort(dev); - } + dev->drv->fp = plat_fopen(fn, dev->drv->read_only ? "rb" : "rb+"); + ret = 1; - fseek(dev->drv->fp, 0, SEEK_END); - size = ftell(dev->drv->fp); - - if ((size == ((ZIP_250_SECTORS << 9) + 0x1000)) || (size == ((ZIP_SECTORS << 9) + 0x1000))) { - /* This is a ZDI image. */ - size -= 0x1000; - dev->drv->base = 0x1000; - } else - dev->drv->base = 0; - - if (dev->drv->is_250) { - if ((size != (ZIP_250_SECTORS << 9)) && (size != (ZIP_SECTORS << 9))) { - zip_log("File is incorrect size for a ZIP image\nMust be exactly %i or %i bytes\n", - ZIP_250_SECTORS << 9, ZIP_SECTORS << 9); - return zip_load_abort(dev); + if (dev->drv->fp == NULL) { + if (!dev->drv->read_only) { + dev->drv->fp = plat_fopen(fn, "rb"); + if (dev->drv->fp == NULL) + ret = zip_load_abort(dev); + else + dev->drv->read_only = 1; + } else + ret = zip_load_abort(dev); } - } else { - if (size != (ZIP_SECTORS << 9)) { - zip_log("File is incorrect size for a ZIP image\nMust be exactly %i bytes\n", - ZIP_SECTORS << 9); - return zip_load_abort(dev); + + if (ret) { + fseek(dev->drv->fp, 0, SEEK_END); + int size = ftell(dev->drv->fp); + + if (is_zdi) { + /* This is a ZDI image. */ + size -= 0x1000; + dev->drv->base = 0x1000; + } else + dev->drv->base = 0; + + if (dev->drv->is_250) { + if ((size != (ZIP_250_SECTORS << 9)) && (size != (ZIP_SECTORS << 9))) { + zip_log(dev->log, "File is incorrect size for a ZIP image\n"); + zip_log(dev->log, "Must be exactly %i or %i bytes\n", + ZIP_250_SECTORS << 9, ZIP_SECTORS << 9); + ret = zip_load_abort(dev); + } + } else if (size != (ZIP_SECTORS << 9)) { + zip_log(dev->log, "File is incorrect size for a ZIP image\n"); + zip_log(dev->log, "Must be exactly %i bytes\n", ZIP_SECTORS << 9); + ret = zip_load_abort(dev); + } + + if (ret) + dev->drv->medium_size = size >> 9; + } + + if (ret) { + if (fseek(dev->drv->fp, dev->drv->base, SEEK_SET) == -1) + log_fatal(dev->log, "zip_load(): Error seeking to the beginning of " + "the file\n"); + + strncpy(dev->drv->image_path, fn, sizeof(dev->drv->image_path) - 1); + /* + After using strncpy, dev->drv->image_path needs to be explicitly null + terminated to make gcc happy. + In the event strlen(dev->drv->image_path) == sizeof(dev->drv->image_path) + (no null terminator) it is placed at the very end. Otherwise, it is placed + right after the string. + */ + const size_t term = strlen(dev->drv->image_path) == + sizeof(dev->drv->image_path) ? sizeof(dev->drv->image_path) - 1 : + strlen(dev->drv->image_path); + dev->drv->image_path[term] = '\0'; } } - dev->drv->medium_size = size >> 9; + if (ret && !skip_insert) { + /* Signal media change to the emulated machine. */ + zip_insert((zip_t *) dev); - if (fseek(dev->drv->fp, dev->drv->base, SEEK_SET) == -1) - fatal("zip_load(): Error seeking to the beginning of the file\n"); - - strncpy(dev->drv->image_path, fn, sizeof(dev->drv->image_path) - 1); - // After using strncpy, dev->drv->image_path needs to be explicitly null terminated to make gcc happy. - // In the event strlen(dev->drv->image_path) == sizeof(dev->drv->image_path) (no null terminator) - // it is placed at the very end. Otherwise, it is placed right after the string. - const size_t term = strlen(dev->drv->image_path) == sizeof(dev->drv->image_path) ? sizeof(dev->drv->image_path) - 1 : strlen(dev->drv->image_path); - dev->drv->image_path[term] = '\0'; - - return 1; + /* The drive was previously empty, transition directly to UNIT ATTENTION. */ + if (was_empty) + zip_insert((zip_t *) dev); + } } void -zip_disk_reload(zip_t *dev) +zip_disk_reload(const zip_t *dev) { - int ret = 0; - - if (strlen(dev->drv->prev_image_path) == 0) - return; - else - ret = zip_load(dev, dev->drv->prev_image_path); - - if (ret) - dev->unit_attention = 1; + if (strlen(dev->drv->prev_image_path) != 0) + (void) zip_load(dev, dev->drv->prev_image_path, 0); } -void -zip_disk_unload(zip_t *dev) +static void +zip_disk_unload(const zip_t *dev) { - if (dev->drv && dev->drv->fp) { + if ((dev->drv != NULL) && (dev->drv->fp != NULL)) { fclose(dev->drv->fp); dev->drv->fp = NULL; } } void -zip_disk_close(zip_t *dev) +zip_disk_close(const zip_t *dev) { - if (dev->drv && dev->drv->fp) { + if ((dev->drv != NULL) && (dev->drv->fp != NULL)) { zip_disk_unload(dev); - memcpy(dev->drv->prev_image_path, dev->drv->image_path, sizeof(dev->drv->prev_image_path)); + memcpy(dev->drv->prev_image_path, dev->drv->image_path, + sizeof(dev->drv->prev_image_path)); memset(dev->drv->image_path, 0, sizeof(dev->drv->image_path)); dev->drv->medium_size = 0; + + zip_insert((zip_t *) dev); } } static void -zip_set_callback(zip_t *dev) +zip_set_callback(const zip_t *dev) { if (dev->drv->bus_type != ZIP_BUS_SCSI) ide_set_callback(ide_drives[dev->drv->ide_channel], dev->callback); @@ -587,54 +314,54 @@ zip_set_callback(zip_t *dev) static void zip_init(zip_t *dev) { - if (dev->id >= ZIP_NUM) - return; - - dev->requested_blocks = 1; - dev->sense[0] = 0xf0; - dev->sense[7] = 10; - dev->drv->bus_mode = 0; - if (dev->drv->bus_type >= ZIP_BUS_ATAPI) - dev->drv->bus_mode |= 2; - if (dev->drv->bus_type < ZIP_BUS_SCSI) - dev->drv->bus_mode |= 1; - zip_log("ZIP %i: Bus type %i, bus mode %i\n", dev->id, dev->drv->bus_type, dev->drv->bus_mode); - if (dev->drv->bus_type < ZIP_BUS_SCSI) { - dev->tf->phase = 1; - dev->tf->request_length = 0xEB14; + if (dev->id < ZIP_NUM) { + dev->requested_blocks = 1; + dev->sense[0] = 0xf0; + dev->sense[7] = 10; + dev->drv->bus_mode = 0; + if (dev->drv->bus_type >= ZIP_BUS_ATAPI) + dev->drv->bus_mode |= 2; + if (dev->drv->bus_type < ZIP_BUS_SCSI) + dev->drv->bus_mode |= 1; + zip_log(dev->log, "Bus type %i, bus mode %i\n", dev->drv->bus_type, dev->drv->bus_mode); + if (dev->drv->bus_type < ZIP_BUS_SCSI) { + dev->tf->phase = 1; + dev->tf->request_length = 0xEB14; + } + dev->tf->status = READY_STAT | DSC_STAT; + dev->tf->pos = 0; + dev->packet_status = PHASE_NONE; + zip_sense_key = zip_asc = zip_ascq = dev->unit_attention = dev->transition = 0; + zip_info = 0x00000000; } - dev->tf->status = READY_STAT | DSC_STAT; - dev->tf->pos = 0; - dev->packet_status = PHASE_NONE; - zip_sense_key = zip_asc = zip_ascq = dev->unit_attention = 0; } static int -zip_supports_pio(zip_t *dev) +zip_supports_pio(const zip_t *dev) { return (dev->drv->bus_mode & 1); } static int -zip_supports_dma(zip_t *dev) +zip_supports_dma(const zip_t *dev) { return (dev->drv->bus_mode & 2); } /* Returns: 0 for none, 1 for PIO, 2 for DMA. */ static int -zip_current_mode(zip_t *dev) +zip_current_mode(const zip_t *dev) { if (!zip_supports_pio(dev) && !zip_supports_dma(dev)) return 0; if (zip_supports_pio(dev) && !zip_supports_dma(dev)) { - zip_log("ZIP %i: Drive does not support DMA, setting to PIO\n", dev->id); + zip_log(dev->log, "Drive does not support DMA, setting to PIO\n"); return 1; } if (!zip_supports_pio(dev) && zip_supports_dma(dev)) return 2; if (zip_supports_pio(dev) && zip_supports_dma(dev)) { - zip_log("ZIP %i: Drive supports both, setting to %s\n", dev->id, + zip_log(dev->log, "Drive supports both, setting to %s\n", (dev->tf->features & 1) ? "DMA" : "PIO"); return (dev->tf->features & 1) ? 2 : 1; } @@ -645,8 +372,7 @@ zip_current_mode(zip_t *dev) static void zip_mode_sense_load(zip_t *dev) { - FILE *fp; - char fn[512]; + char fn[512] = { 0 }; memset(&dev->ms_pages_saved, 0, sizeof(mode_sense_pages_t)); if (dev->drv->is_250) { @@ -661,12 +387,11 @@ zip_mode_sense_load(zip_t *dev) memcpy(&dev->ms_pages_saved, &zip_mode_sense_pages_default, sizeof(mode_sense_pages_t)); } - memset(fn, 0, 512); if (dev->drv->bus_type == ZIP_BUS_SCSI) sprintf(fn, "scsi_zip_%02i_mode_sense_bin", dev->id); else sprintf(fn, "zip_%02i_mode_sense_bin", dev->id); - fp = plat_fopen(nvr_path(fn), "rb"); + FILE *fp = plat_fopen(nvr_path(fn), "rb"); if (fp) { /* Nothing to read, not used by ZIP. */ fclose(fp); @@ -674,31 +399,31 @@ zip_mode_sense_load(zip_t *dev) } static void -zip_mode_sense_save(zip_t *dev) +zip_mode_sense_save(const zip_t *dev) { - FILE *fp; - char fn[512]; + char fn[512] = { 0 }; - memset(fn, 0, 512); if (dev->drv->bus_type == ZIP_BUS_SCSI) sprintf(fn, "scsi_zip_%02i_mode_sense_bin", dev->id); else sprintf(fn, "zip_%02i_mode_sense_bin", dev->id); - fp = plat_fopen(nvr_path(fn), "wb"); + FILE *fp = plat_fopen(nvr_path(fn), "wb"); if (fp) { /* Nothing to write, not used by ZIP. */ fclose(fp); } } -/*SCSI Mode Sense 6/10*/ +/* SCSI Mode Sense 6/10. */ static uint8_t -zip_mode_sense_read(zip_t *dev, uint8_t page_control, uint8_t page, uint8_t pos) +zip_mode_sense_read(const zip_t *dev, const uint8_t pgctl, + const uint8_t page, const uint8_t pos) { - switch (page_control) { + switch (pgctl) { case 0: case 3: - if (dev->drv->is_250 && (page == 5) && (pos == 9) && (dev->drv->medium_size == ZIP_SECTORS)) + 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]; case 1: @@ -729,18 +454,17 @@ zip_mode_sense_read(zip_t *dev, uint8_t page_control, uint8_t page, uint8_t pos) } static uint32_t -zip_mode_sense(zip_t *dev, uint8_t *buf, uint32_t pos, uint8_t page, uint8_t block_descriptor_len) +zip_mode_sense(const zip_t *dev, uint8_t *buf, uint32_t pos, + uint8_t page, const uint8_t block_descriptor_len) { - uint64_t pf; - uint8_t page_control = (page >> 6) & 3; + uint64_t pf; + const uint8_t pgctl = (page >> 6) & 3; if (dev->drv->is_250) pf = zip_250_mode_sense_page_flags; else pf = zip_mode_sense_page_flags; - uint8_t msplen; - page &= 0x3f; if (block_descriptor_len) { @@ -757,12 +481,12 @@ zip_mode_sense(zip_t *dev, uint8_t *buf, uint32_t pos, uint8_t page, uint8_t blo 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); + const uint8_t msplen = zip_mode_sense_read(dev, pgctl, i, 1); + buf[pos++] = zip_mode_sense_read(dev, pgctl, i, 0); + buf[pos++] = msplen; + zip_log(dev->log, "MODE SENSE: Page [%02X] length %i\n", i, msplen); for (uint8_t j = 0; j < msplen; j++) - buf[pos++] = zip_mode_sense_read(dev, page_control, i, 2 + j); + buf[pos++] = zip_mode_sense_read(dev, pgctl, i, 2 + j); } } } @@ -778,7 +502,10 @@ zip_update_request_length(zip_t *dev, int len, int block_len) dev->max_transfer_len = dev->tf->request_length; - /* For media access commands, make sure the requested DRQ length matches the block length. */ + /* + For media access commands, make sure the requested DRQ length matches the + block length. + */ switch (dev->current_cdb[0]) { case 0x08: case 0x0a: @@ -789,8 +516,10 @@ zip_update_request_length(zip_t *dev, int len, int block_len) /* Round it to the nearest 2048 bytes. */ dev->max_transfer_len = (dev->max_transfer_len >> 9) << 9; - /* Make sure total length is not bigger than sum of the lengths of - all the requested blocks. */ + /* + Make sure total length is not bigger than sum of the lengths of + all the requested blocks. + */ bt = (dev->requested_blocks * block_len); if (len > bt) len = bt; @@ -812,10 +541,16 @@ zip_update_request_length(zip_t *dev, int len, int block_len) dev->packet_len = len; break; } - /* If the DRQ length is odd, and the total remaining length is bigger, make sure it's even. */ + /* + If the DRQ length is odd, and the total remaining length is bigger, + make sure it's even. + */ if ((dev->max_transfer_len & 1) && (dev->max_transfer_len < len)) dev->max_transfer_len &= 0xfffe; - /* If the DRQ length is smaller or equal in size to the total remaining length, set it to that. */ + /* + If the DRQ length is smaller or equal in size to the total remaining length, + set it to that. + */ if (!dev->max_transfer_len) dev->max_transfer_len = 65534; @@ -832,42 +567,30 @@ zip_bus_speed(zip_t *dev) { double ret = -1.0; - if (dev && dev->drv && (dev->drv->bus_type == ZIP_BUS_SCSI)) { - dev->callback = -1.0; /* Speed depends on SCSI controller */ - return 0.0; - } else { - if (dev && dev->drv) - ret = ide_atapi_get_period(dev->drv->ide_channel); - if (ret == -1.0) { - if (dev) - dev->callback = -1.0; - return 0.0; - } else - return ret * 1000000.0; + if (dev && dev->drv) + ret = ide_atapi_get_period(dev->drv->ide_channel); + + if (ret == -1.0) { + if (dev) + dev->callback = -1.0; + ret = 0.0; } + + return ret; } static void zip_command_common(zip_t *dev) { - double bytes_per_second; - double period; - dev->tf->status = BUSY_STAT; dev->tf->phase = 1; dev->tf->pos = 0; if (dev->packet_status == PHASE_COMPLETE) dev->callback = 0.0; - else { - if (dev->drv->bus_type == ZIP_BUS_SCSI) { - dev->callback = -1.0; /* Speed depends on SCSI controller */ - return; - } else - bytes_per_second = zip_bus_speed(dev); - - period = 1000000.0 / bytes_per_second; - dev->callback = period * (double) (dev->packet_len); - } + else if (dev->drv->bus_type == ZIP_BUS_SCSI) + dev->callback = -1.0; /* Speed depends on SCSI controller */ + else + dev->callback = zip_bus_speed(dev) * (double) (dev->packet_len); zip_set_callback(dev); } @@ -907,16 +630,20 @@ zip_command_write_dma(zip_t *dev) zip_command_common(dev); } -/* id = Current ZIP device ID; +/* + dev = Pointer to current ZIP device; len = Total transfer length; block_len = Length of a single block (why does it matter?!); alloc_len = Allocated transfer length; - direction = Transfer direction (0 = read from host, 1 = write to host). */ + direction = Transfer direction (0 = read from host, 1 = write to host). + */ static void -zip_data_command_finish(zip_t *dev, int len, int block_len, int alloc_len, int direction) +zip_data_command_finish(zip_t *dev, int len, const int block_len, + const int alloc_len, const int direction) { - zip_log("ZIP %i: Finishing command (%02X): %i, %i, %i, %i, %i\n", - dev->id, dev->current_cdb[0], len, block_len, alloc_len, direction, dev->tf->request_length); + zip_log(dev->log, "Finishing command (%02X): %i, %i, %i, %i, %i\n", + dev->current_cdb[0], len, block_len, alloc_len, + direction, dev->tf->request_length); dev->tf->pos = 0; if (alloc_len >= 0) { if (alloc_len < len) @@ -938,34 +665,36 @@ zip_data_command_finish(zip_t *dev, int len, int block_len, int alloc_len, int d zip_command_write_dma(dev); } else { zip_update_request_length(dev, len, block_len); - if (direction == 0) + if ((dev->drv->bus_type != ZIP_BUS_SCSI) && + (dev->tf->request_length == 0)) + zip_command_complete(dev); + else if (direction == 0) zip_command_read(dev); else zip_command_write(dev); } } - zip_log("ZIP %i: Status: %i, cylinder %i, packet length: %i, position: %i, phase: %i\n", - dev->id, dev->packet_status, dev->tf->request_length, dev->packet_len, dev->tf->pos, - dev->tf->phase); + zip_log(dev->log, "Status: %i, cylinder %i, packet length: %i, position: %i, phase: %i\n", + dev->packet_status, dev->tf->request_length, dev->packet_len, + dev->tf->pos, dev->tf->phase); } static void zip_sense_clear(zip_t *dev, UNUSED(int command)) { zip_sense_key = zip_asc = zip_ascq = 0; + zip_info = 0x00000000; } static void -zip_set_phase(zip_t *dev, uint8_t phase) +zip_set_phase(const zip_t *dev, const uint8_t phase) { - uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; - uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; + const uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; + const uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; - if (dev->drv->bus_type != ZIP_BUS_SCSI) - return; - - scsi_devices[scsi_bus][scsi_id].phase = phase; + if (dev->drv->bus_type == ZIP_BUS_SCSI) + scsi_devices[scsi_bus][scsi_id].phase = phase; } static void @@ -973,8 +702,6 @@ zip_cmd_error(zip_t *dev) { zip_set_phase(dev, SCSI_PHASE_STATUS); dev->tf->error = ((zip_sense_key & 0xf) << 4) | ABRT_ERR; - if (dev->unit_attention) - dev->tf->error |= MCR_ERR; dev->tf->status = READY_STAT | ERR_STAT; dev->tf->phase = 3; dev->tf->pos = 0; @@ -982,7 +709,9 @@ zip_cmd_error(zip_t *dev) dev->callback = 50.0 * ZIP_TIME; zip_set_callback(dev); ui_sb_update_icon(SB_ZIP | dev->id, 0); - zip_log("ZIP %i: [%02X] ERROR: %02X/%02X/%02X\n", dev->id, dev->current_cdb[0], zip_sense_key, zip_asc, zip_ascq); + ui_sb_update_icon_write(SB_ZIP | dev->id, 0); + zip_log(dev->log, "[%02X] ERROR: %02X/%02X/%02X\n", dev->current_cdb[0], zip_sense_key, + zip_asc, zip_ascq); } static void @@ -990,8 +719,6 @@ zip_unit_attention(zip_t *dev) { zip_set_phase(dev, SCSI_PHASE_STATUS); dev->tf->error = (SENSE_UNIT_ATTENTION << 4) | ABRT_ERR; - if (dev->unit_attention) - dev->tf->error |= MCR_ERR; dev->tf->status = READY_STAT | ERR_STAT; dev->tf->phase = 3; dev->tf->pos = 0; @@ -999,22 +726,23 @@ zip_unit_attention(zip_t *dev) dev->callback = 50.0 * ZIP_TIME; zip_set_callback(dev); ui_sb_update_icon(SB_ZIP | dev->id, 0); - zip_log("ZIP %i: UNIT ATTENTION\n", dev->id); + ui_sb_update_icon_write(SB_ZIP | dev->id, 0); + zip_log(dev->log, "UNIT ATTENTION\n", dev->id); } static void -zip_buf_alloc(zip_t *dev, uint32_t len) +zip_buf_alloc(zip_t *dev, const uint32_t len) { - zip_log("ZIP %i: Allocated buffer length: %i\n", dev->id, len); - if (!dev->buffer) + zip_log(dev->log, "Allocated buffer length: %i\n", len); + if (dev->buffer == NULL) dev->buffer = (uint8_t *) malloc(len); } static void zip_buf_free(zip_t *dev) { - if (dev->buffer) { - zip_log("ZIP %i: Freeing buffer...\n", dev->id); + if (dev->buffer != NULL) { + zip_log(dev->log, "ZIP %i: Freeing buffer...\n"); free(dev->buffer); dev->buffer = NULL; } @@ -1027,6 +755,10 @@ zip_bus_master_error(scsi_common_t *sc) zip_buf_free(dev); zip_sense_key = zip_asc = zip_ascq = 0; + zip_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); zip_cmd_error(dev); } @@ -1036,6 +768,7 @@ zip_not_ready(zip_t *dev) zip_sense_key = SENSE_NOT_READY; zip_asc = ASC_MEDIUM_NOT_PRESENT; zip_ascq = 0; + zip_info = 0x00000000; zip_cmd_error(dev); } @@ -1045,6 +778,10 @@ zip_write_protected(zip_t *dev) zip_sense_key = SENSE_UNIT_ATTENTION; zip_asc = ASC_WRITE_PROTECTED; zip_ascq = 0; + zip_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); zip_cmd_error(dev); } @@ -1054,6 +791,10 @@ zip_write_error(zip_t *dev) zip_sense_key = SENSE_MEDIUM_ERROR; zip_asc = ASC_WRITE_ERROR; zip_ascq = 0; + zip_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); zip_cmd_error(dev); } @@ -1063,24 +804,30 @@ zip_read_error(zip_t *dev) zip_sense_key = SENSE_MEDIUM_ERROR; zip_asc = ASC_UNRECOVERED_READ_ERROR; zip_ascq = 0; + zip_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); zip_cmd_error(dev); } static void -zip_invalid_lun(zip_t *dev) +zip_invalid_lun(zip_t *dev, const uint8_t lun) { zip_sense_key = SENSE_ILLEGAL_REQUEST; zip_asc = ASC_INV_LUN; zip_ascq = 0; + zip_info = lun << 24; zip_cmd_error(dev); } static void -zip_illegal_opcode(zip_t *dev) +zip_illegal_opcode(zip_t *dev, const uint8_t opcode) { zip_sense_key = SENSE_ILLEGAL_REQUEST; zip_asc = ASC_ILLEGAL_OPCODE; zip_ascq = 0; + zip_info = opcode << 24; zip_cmd_error(dev); } @@ -1090,191 +837,246 @@ zip_lba_out_of_range(zip_t *dev) zip_sense_key = SENSE_ILLEGAL_REQUEST; zip_asc = ASC_LBA_OUT_OF_RANGE; zip_ascq = 0; + zip_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); zip_cmd_error(dev); } static void -zip_invalid_field(zip_t *dev) +zip_invalid_field(zip_t *dev, const uint32_t field) { zip_sense_key = SENSE_ILLEGAL_REQUEST; zip_asc = ASC_INV_FIELD_IN_CMD_PACKET; zip_ascq = 0; + zip_info = (field >> 24) | + ((field >> 16) << 8) | + ((field >> 8) << 16) | + ( field << 24); zip_cmd_error(dev); dev->tf->status = 0x53; } static void -zip_invalid_field_pl(zip_t *dev) +zip_invalid_field_pl(zip_t *dev, const uint32_t field) { zip_sense_key = SENSE_ILLEGAL_REQUEST; zip_asc = ASC_INV_FIELD_IN_PARAMETER_LIST; zip_ascq = 0; + zip_info = (field >> 24) | + ((field >> 16) << 8) | + ((field >> 8) << 16) | + ( field << 24); zip_cmd_error(dev); dev->tf->status = 0x53; } static void -zip_data_phase_error(zip_t *dev) +zip_data_phase_error(zip_t *dev, const uint32_t info) { zip_sense_key = SENSE_ILLEGAL_REQUEST; zip_asc = ASC_DATA_PHASE_ERROR; zip_ascq = 0; + zip_info = (info >> 24) | + ((info >> 16) << 8) | + ((info >> 8) << 16) | + ( info << 24); zip_cmd_error(dev); } static int -zip_blocks(zip_t *dev, int32_t *len, UNUSED(int first_batch), int out) +zip_blocks(zip_t *dev, int32_t *len, const int out) { - *len = 0; + int ret = 1; + *len = 0; - if (!dev->sector_len) { - zip_command_complete(dev); - return 0; - } + if (dev->sector_len > 0) { + zip_log(dev->log, "%sing %i blocks starting from %i...\n", out ? "Writ" : "Read", + dev->requested_blocks, dev->sector_pos); - zip_log("%sing %i blocks starting from %i...\n", out ? "Writ" : "Read", dev->requested_blocks, dev->sector_pos); - - if (dev->sector_pos >= dev->drv->medium_size) { - zip_log("ZIP %i: Trying to %s beyond the end of disk\n", dev->id, out ? "write" : "read"); - zip_lba_out_of_range(dev); - return 0; - } - - *len = dev->requested_blocks << 9; - - for (int i = 0; i < dev->requested_blocks; i++) { - if (fseek(dev->drv->fp, dev->drv->base + (dev->sector_pos << 9) + (i << 9), SEEK_SET) == -1) { - if (out) - zip_write_error(dev); - else - zip_read_error(dev); - return -1; - } - - if (feof(dev->drv->fp)) - break; - - if (out) { - if (fwrite(dev->buffer + (i << 9), 1, 512, dev->drv->fp) != 512) { - zip_log("zip_blocks(): Error writing data\n"); - zip_write_error(dev); - return -1; - } - - fflush(dev->drv->fp); + if (dev->sector_pos >= dev->drv->medium_size) { + zip_log(dev->log, "Trying to %s beyond the end of disk\n", + out ? "write" : "read"); + zip_lba_out_of_range(dev); + ret = 0; } else { - if (fread(dev->buffer + (i << 9), 1, 512, dev->drv->fp) != 512) { - zip_log("zip_blocks(): Error reading data\n"); - zip_read_error(dev); - return -1; + *len = dev->requested_blocks << 9; + + for (int i = 0; i < dev->requested_blocks; i++) { + if (fseek(dev->drv->fp, dev->drv->base + (dev->sector_pos << 9), + SEEK_SET) == -1) { + if (out) + zip_write_error(dev); + else + zip_read_error(dev); + ret = -1; + } else { + if (feof(dev->drv->fp)) + break; + + if (out) { + if (fwrite(dev->buffer + (i << 9), 1, + 512, dev->drv->fp) != 512) { + zip_log(dev->log, "zip_blocks(): Error writing data\n"); + zip_write_error(dev); + ret = -1; + } else + fflush(dev->drv->fp); + } else if (fread(dev->buffer + (i << 9), 1, + 512, dev->drv->fp) != 512) { + zip_log(dev->log, "zip_blocks(): Error reading data\n"); + zip_read_error(dev); + ret = -1; + } + } + + if (ret == -1) + break; + + dev->sector_pos++; + } + + if (ret == 1) { + zip_log(dev->log, "%s %i bytes of blocks...\n", out ? "Written" : + "Read", *len); + + dev->sector_len -= dev->requested_blocks; } } + } else { + zip_command_complete(dev); + ret = 0; } - zip_log("%s %i bytes of blocks...\n", out ? "Written" : "Read", *len); - - dev->sector_pos += dev->requested_blocks; - dev->sector_len -= dev->requested_blocks; - - return 1; + return ret; } void zip_insert(zip_t *dev) { - dev->unit_attention = 1; -} - -/*SCSI Sense Initialization*/ -void -zip_sense_code_ok(zip_t *dev) -{ - zip_sense_key = SENSE_NONE; - zip_asc = 0; - zip_ascq = 0; + if ((dev != NULL) && (dev->drv != NULL)) { + if (dev->drv->fp == NULL) { + dev->unit_attention = 0; + dev->transition = 0; + zip_log(dev->log, "Media removal\n"); + } else if (dev->transition) { + dev->unit_attention = 1; + /* Turn off the medium changed status. */ + dev->transition = 0; + zip_log(dev->log, "Media insert\n"); + } else { + dev->unit_attention = 0; + dev->transition = 1; + zip_log(dev->log, "Media transition\n"); + } + } } static int -zip_pre_execution_check(zip_t *dev, uint8_t *cdb) +zip_pre_execution_check(zip_t *dev, const uint8_t *cdb) { - int ready = 0; + int ready; - if ((cdb[0] != GPCMD_REQUEST_SENSE) && (dev->cur_lun == SCSI_LUN_USE_CDB) && (cdb[1] & 0xe0)) { - zip_log("ZIP %i: Attempting to execute a unknown command targeted at SCSI LUN %i\n", dev->id, + if ((cdb[0] != GPCMD_REQUEST_SENSE) && (dev->cur_lun == SCSI_LUN_USE_CDB) && + (cdb[1] & 0xe0)) { + zip_log(dev->log, "Attempting to execute a unknown command targeted at SCSI LUN %i\n", ((dev->tf->request_length >> 5) & 7)); - zip_invalid_lun(dev); + zip_invalid_lun(dev, cdb[1] >> 5); return 0; } if (!(zip_command_flags[cdb[0]] & IMPLEMENTED)) { - zip_log("ZIP %i: Attempting to execute unknown command %02X over %s\n", dev->id, cdb[0], - (dev->drv->bus_type == ZIP_BUS_SCSI) ? "SCSI" : "ATAPI"); + zip_log(dev->log, "Attempting to execute unknown command %02X over %s\n", + cdb[0], (dev->drv->bus_type == ZIP_BUS_SCSI) ? + "SCSI" : "ATAPI"); - zip_illegal_opcode(dev); + zip_illegal_opcode(dev, cdb[0]); return 0; } - if ((dev->drv->bus_type < ZIP_BUS_SCSI) && (zip_command_flags[cdb[0]] & SCSI_ONLY)) { - zip_log("ZIP %i: Attempting to execute SCSI-only command %02X over ATAPI\n", dev->id, cdb[0]); - zip_illegal_opcode(dev); + if ((dev->drv->bus_type < ZIP_BUS_SCSI) && + (zip_command_flags[cdb[0]] & SCSI_ONLY)) { + zip_log(dev->log, "Attempting to execute SCSI-only command %02X " + "over ATAPI\n", cdb[0]); + zip_illegal_opcode(dev, cdb[0]); return 0; } - if ((dev->drv->bus_type == ZIP_BUS_SCSI) && (zip_command_flags[cdb[0]] & ATAPI_ONLY)) { - zip_log("ZIP %i: Attempting to execute ATAPI-only command %02X over SCSI\n", dev->id, cdb[0]); - zip_illegal_opcode(dev); + if ((dev->drv->bus_type == ZIP_BUS_SCSI) && + (zip_command_flags[cdb[0]] & ATAPI_ONLY)) { + zip_log(dev->log, "Attempting to execute ATAPI-only command %02X " + "over SCSI\n", cdb[0]); + zip_illegal_opcode(dev, cdb[0]); return 0; } - ready = (dev->drv->fp != NULL); + if (dev->transition) { + if ((cdb[0] == GPCMD_TEST_UNIT_READY) || (cdb[0] == GPCMD_REQUEST_SENSE)) + ready = 0; + else { + if (!(zip_command_flags[cdb[0]] & ALLOW_UA)) { + zip_log(dev->log, "(ext_medium_changed != 0): zip_insert()\n"); + zip_insert((void *) dev); + } - /* If the drive is not ready, there is no reason to keep the + ready = (dev->drv->fp != NULL); + } + } else + ready = (dev->drv->fp != NULL); + + /* + If the drive is not ready, there is no reason to keep the UNIT ATTENTION condition present, as we only use it to mark - disc changes. */ - if (!ready && dev->unit_attention) + disc changes. + */ + if (!ready && (dev->unit_attention > 0)) dev->unit_attention = 0; - /* If the UNIT ATTENTION condition is set and the command does not allow - execution under it, error out and report the condition. */ + /* + If the UNIT ATTENTION condition is set and the command does not allow + execution under it, error out and report the condition. + */ if (dev->unit_attention == 1) { - /* Only increment the unit attention phase if the command can not pass through it. */ + /* + Only increment the unit attention phase if the command can + not pass through it. + */ if (!(zip_command_flags[cdb[0]] & ALLOW_UA)) { - /* zip_log("ZIP %i: Unit attention now 2\n", dev->id); */ - dev->unit_attention = 2; - zip_log("ZIP %i: UNIT ATTENTION: Command %02X not allowed to pass through\n", dev->id, cdb[0]); + zip_log(dev->log, "Unit attention now 2\n"); + dev->unit_attention++; + zip_log(dev->log, "UNIT ATTENTION: Command %02X not allowed to pass through\n", + cdb[0]); zip_unit_attention(dev); return 0; } } else if (dev->unit_attention == 2) { if (cdb[0] != GPCMD_REQUEST_SENSE) { - /* zip_log("ZIP %i: Unit attention now 0\n", dev->id); */ + zip_log(dev->log, "Unit attention now 0\n"); dev->unit_attention = 0; } } - /* Unless the command is REQUEST SENSE, clear the sense. This will *NOT* - the UNIT ATTENTION condition if it's set. */ + /* + Unless the command is REQUEST SENSE, clear the sense. This will *NOT* clear + the UNIT ATTENTION condition if it's set. + */ if (cdb[0] != GPCMD_REQUEST_SENSE) zip_sense_clear(dev, cdb[0]); - /* Next it's time for NOT READY. */ - if ((zip_command_flags[cdb[0]] & CHECK_READY) && !ready) { - zip_log("ZIP %i: Not ready (%02X)\n", dev->id, cdb[0]); + if (!ready && (zip_command_flags[cdb[0]] & CHECK_READY)) { + zip_log(dev->log, "Not ready (%02X)\n", cdb[0]); zip_not_ready(dev); return 0; } - zip_log("ZIP %i: Continuing with command %02X\n", dev->id, cdb[0]); - + zip_log(dev->log, "Continuing with command %02X\n", cdb[0]); return 1; } static void -zip_seek(zip_t *dev, uint32_t pos) +zip_seek(zip_t *dev, const uint32_t pos) { -#if 0 - zip_log("ZIP %i: Seek %08X\n", dev->id, pos); -#endif dev->sector_pos = pos; } @@ -1299,10 +1101,12 @@ zip_reset(scsi_common_t *sc) dev->packet_status = PHASE_NONE; dev->unit_attention = 0; dev->cur_lun = SCSI_LUN_USE_CDB; + zip_sense_key = zip_asc = zip_ascq = dev->unit_attention = dev->transition = 0; + zip_info = 0x00000000; } static void -zip_request_sense(zip_t *dev, uint8_t *buffer, uint8_t alloc_length, int desc) +zip_request_sense(zip_t *dev, uint8_t *buffer, const uint8_t alloc_length, const int desc) { /*Will return 18 bytes of 0*/ if (alloc_length != 0) { @@ -1316,7 +1120,9 @@ zip_request_sense(zip_t *dev, uint8_t *buffer, uint8_t alloc_length, int desc) } } - buffer[0] = desc ? 0x72 : 0x70; + buffer[0] = desc ? 0x72 : 0xf0; + if (!desc) + buffer[7] = 10; if (dev->unit_attention && (zip_sense_key == 0)) { buffer[desc ? 1 : 2] = SENSE_UNIT_ATTENTION; @@ -1324,7 +1130,8 @@ zip_request_sense(zip_t *dev, uint8_t *buffer, uint8_t alloc_length, int desc) buffer[desc ? 3 : 13] = 0; } - zip_log("ZIP %i: Reporting sense: %02X %02X %02X\n", dev->id, buffer[2], buffer[12], buffer[13]); + zip_log(dev->log, "Reporting sense: %02X %02X %02X\n", buffer[2], + buffer[12], buffer[13]); if (buffer[desc ? 1 : 2] == SENSE_UNIT_ATTENTION) { /* If the last remaining sense is unit attention, clear @@ -1334,30 +1141,33 @@ zip_request_sense(zip_t *dev, uint8_t *buffer, uint8_t alloc_length, int desc) /* Clear the sense stuff as per the spec. */ zip_sense_clear(dev, GPCMD_REQUEST_SENSE); + + if (dev->transition) { + zip_log(dev->log, "ZIP_TRANSITION: zip_insert()\n"); + zip_insert((void *) dev); + } } static void -zip_request_sense_for_scsi(scsi_common_t *sc, uint8_t *buffer, uint8_t alloc_length) +zip_request_sense_for_scsi(scsi_common_t *sc, uint8_t *buffer, const uint8_t alloc_length) { - zip_t *dev = (zip_t *) sc; - int ready = 0; - - ready = (dev->drv->fp != NULL); + zip_t *dev = (zip_t *) sc; + const int ready = (dev->drv->fp != NULL); if (!ready && dev->unit_attention) { - /* If the drive is not ready, there is no reason to keep the - UNIT ATTENTION condition present, as we only use it to mark - disc changes. */ + /* + If the drive is not ready, there is no reason to keep the UNIT ATTENTION + condition present, as we only use it to mark disc changes. + */ dev->unit_attention = 0; } /* Do *NOT* advance the unit attention phase. */ - zip_request_sense(dev, buffer, alloc_length, 0); } static void -zip_set_buf_len(zip_t *dev, int32_t *BufLen, int32_t *src_len) +zip_set_buf_len(const zip_t *dev, int32_t *BufLen, int32_t *src_len) { if (dev->drv->bus_type == ZIP_BUS_SCSI) { if (*BufLen == -1) @@ -1366,28 +1176,27 @@ zip_set_buf_len(zip_t *dev, int32_t *BufLen, int32_t *src_len) *BufLen = MIN(*src_len, *BufLen); *src_len = *BufLen; } - zip_log("ZIP %i: Actual transfer length: %i\n", dev->id, *BufLen); + zip_log(dev->log, "Actual transfer length: %i\n", *BufLen); } } static void -zip_command(scsi_common_t *sc, uint8_t *cdb) +zip_command(scsi_common_t *sc, const uint8_t *cdb) { - zip_t *dev = (zip_t *) sc; - int pos = 0; - int block_desc = 0; - int ret; - int32_t len; - int32_t max_len; - int32_t alloc_length; - uint32_t i = 0; - int size_idx; - int idx = 0; - unsigned preamble_len; - int32_t blen = 0; - int32_t *BufLen; - uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; - uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; + zip_t *dev = (zip_t *) sc; + const uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; + const uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; + int pos = 0; + int idx = 0; + int32_t blen = 0; + uint32_t i; + unsigned preamble_len; + int32_t len; + int32_t max_len; + int32_t alloc_length; + int block_desc; + int size_idx; + int32_t * BufLen; if (dev->drv->bus_type == ZIP_BUS_SCSI) { BufLen = &scsi_devices[scsi_bus][scsi_id].buffer_length; @@ -1403,11 +1212,13 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) memcpy(dev->current_cdb, cdb, 12); if (cdb[0] != 0) { - zip_log("ZIP %i: Command 0x%02X, Sense Key %02X, Asc %02X, Ascq %02X, Unit attention: %i\n", - dev->id, cdb[0], zip_sense_key, zip_asc, zip_ascq, dev->unit_attention); - zip_log("ZIP %i: Request length: %04X\n", dev->id, dev->tf->request_length); + zip_log(dev->log, "Command 0x%02X, Sense Key %02X, Asc %02X, Ascq %02X, " + "Unit attention: %i\n", + cdb[0], zip_sense_key, zip_asc, zip_ascq, dev->unit_attention); + zip_log(dev->log, "Request length: %04X\n", dev->tf->request_length); - zip_log("ZIP %i: CDB: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n", dev->id, + zip_log(dev->log, "CDB: %02X %02X %02X %02X %02X %02X %02X %02X " + "%02X %02X %02X %02X\n", cdb[0], cdb[1], cdb[2], cdb[3], cdb[4], cdb[5], cdb[6], cdb[7], cdb[8], cdb[9], cdb[10], cdb[11]); } @@ -1416,14 +1227,17 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) zip_set_phase(dev, SCSI_PHASE_STATUS); - /* This handles the Not Ready/Unit Attention check if it has to be handled at this point. */ + /* + This handles the Not Ready/Unit Attention check if it has to be handled at + this point. + */ if (zip_pre_execution_check(dev, cdb) == 0) return; switch (cdb[0]) { case GPCMD_SEND_DIAGNOSTIC: if (!(cdb[1] & (1 << 2))) { - zip_invalid_field(dev); + zip_invalid_field(dev, cdb[1]); return; } fallthrough; @@ -1435,13 +1249,12 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) break; case GPCMD_FORMAT_UNIT: - if (dev->drv->read_only) { + if (dev->drv->read_only) zip_write_protected(dev); - return; + else { + zip_set_phase(dev, SCSI_PHASE_STATUS); + zip_command_complete(dev); } - - zip_set_phase(dev, SCSI_PHASE_STATUS); - zip_command_complete(dev); break; case GPCMD_IOMEGA_SENSE: @@ -1451,8 +1264,10 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) zip_set_buf_len(dev, BufLen, &max_len); memset(dev->buffer, 0, 256); if (cdb[2] == 1) { - /* This page is related to disk health status - setting - this page to 0 makes disk health read as "marginal". */ + /* + This page is related to disk health status - setting + this page to 0 makes disk health read as "marginal". + */ dev->buffer[0] = 0x58; dev->buffer[1] = 0x00; for (i = 0x00; i < 0x58; i++) @@ -1468,7 +1283,7 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) for (i = 0x00; i < 0x27; i++) dev->buffer[i + 0x16] = 0x00; } else { - zip_invalid_field(dev); + zip_invalid_field(dev, cdb[2]); zip_buf_free(dev); return; } @@ -1482,9 +1297,11 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) break; case GPCMD_REQUEST_SENSE: - /* If there's a unit attention condition and there's a buffered not - ready, a standalone REQUEST SENSE should forget about the not - ready, and report unit attention straight away. */ + /* + If there's a unit attention condition and there's a buffered not ready, a + standalone REQUEST SENSE should forget about the not ready, and report unit + attention straight away. + */ zip_set_phase(dev, SCSI_PHASE_DATA_IN); max_len = cdb[4]; @@ -1533,17 +1350,20 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) dev->sector_len = 256; dev->sector_pos = ((((uint32_t) cdb[1]) & 0x1f) << 16) | (((uint32_t) cdb[2]) << 8) | ((uint32_t) cdb[3]); - zip_log("ZIP %i: Length: %i, LBA: %i\n", dev->id, dev->sector_len, dev->sector_pos); + zip_log(dev->log, "Length: %i, LBA: %i\n", dev->sector_len, dev->sector_pos); break; case GPCMD_READ_10: dev->sector_len = (cdb[7] << 8) | cdb[8]; - dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; - zip_log("ZIP %i: Length: %i, LBA: %i\n", dev->id, dev->sector_len, dev->sector_pos); + dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | + (cdb[4] << 8) | cdb[5]; + zip_log(dev->log, "Length: %i, LBA: %i\n", dev->sector_len, dev->sector_pos); break; case GPCMD_READ_12: - dev->sector_len = (((uint32_t) cdb[6]) << 24) | (((uint32_t) cdb[7]) << 16) | + 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) | + dev->sector_pos = (((uint32_t) cdb[2]) << 24) | + (((uint32_t) cdb[3]) << 16) | (((uint32_t) cdb[4]) << 8) | ((uint32_t) cdb[5]); break; @@ -1551,51 +1371,45 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) break; } - if (dev->sector_pos >= dev->drv->medium_size) { + if (dev->sector_pos >= dev->drv->medium_size) zip_lba_out_of_range(dev); - return; - } + else if (dev->sector_len) { + max_len = dev->sector_len; + dev->requested_blocks = max_len; - if (!dev->sector_len) { + dev->packet_len = max_len * alloc_length; + zip_buf_alloc(dev, dev->packet_len); + + const int ret = zip_blocks(dev, &alloc_length, 0); + alloc_length = dev->requested_blocks * 512; + + if (ret > 0) { + dev->requested_blocks = max_len; + dev->packet_len = alloc_length; + + zip_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); + + zip_data_command_finish(dev, alloc_length, 512, + alloc_length, 0); + + ui_sb_update_icon(SB_ZIP | dev->id, + dev->packet_status != PHASE_COMPLETE); + } else { + zip_set_phase(dev, SCSI_PHASE_STATUS); + dev->packet_status = (ret < 0) ? PHASE_ERROR : PHASE_COMPLETE; + dev->callback = 20.0 * ZIP_TIME; + zip_set_callback(dev); + zip_buf_free(dev); + } + } else { zip_set_phase(dev, SCSI_PHASE_STATUS); - /* zip_log("ZIP %i: All done - callback set\n", dev->id); */ + /* zip_log(dev->log, "All done - callback set\n"); */ dev->packet_status = PHASE_COMPLETE; dev->callback = 20.0 * ZIP_TIME; zip_set_callback(dev); break; } - - max_len = dev->sector_len; - /* - If we're reading all blocks in one go for DMA, why not also for - PIO, it should NOT matter anyway, this step should be identical - and only the way the read dat is transferred to the host should - be different. - */ - dev->requested_blocks = max_len; - - dev->packet_len = max_len * alloc_length; - zip_buf_alloc(dev, dev->packet_len); - - ret = zip_blocks(dev, &alloc_length, 1, 0); - if (ret <= 0) { - zip_set_phase(dev, SCSI_PHASE_STATUS); - dev->packet_status = (ret < 0) ? PHASE_ERROR : PHASE_COMPLETE; - dev->callback = 20.0 * ZIP_TIME; - zip_set_callback(dev); - zip_buf_free(dev); - return; - } - - dev->requested_blocks = max_len; - dev->packet_len = alloc_length; - - zip_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); - - zip_data_command_finish(dev, alloc_length, 512, alloc_length, 0); - - ui_sb_update_icon(SB_ZIP | dev->id, dev->packet_status != PHASE_COMPLETE); - return; + break; case GPCMD_VERIFY_6: case GPCMD_VERIFY_10: @@ -1616,7 +1430,7 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) if (dev->drv->read_only) { zip_write_protected(dev); - return; + break; } switch (cdb[0]) { @@ -1636,15 +1450,19 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) case GPCMD_WRITE_10: case GPCMD_WRITE_AND_VERIFY_10: dev->sector_len = (cdb[7] << 8) | cdb[8]; - dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; - zip_log("ZIP %i: Length: %i, LBA: %i\n", dev->id, dev->sector_len, dev->sector_pos); + dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | + (cdb[4] << 8) | cdb[5]; + zip_log(dev->log, "Length: %i, LBA: %i\n", + dev->sector_len, dev->sector_pos); break; case GPCMD_VERIFY_12: case GPCMD_WRITE_12: case GPCMD_WRITE_AND_VERIFY_12: - dev->sector_len = (((uint32_t) cdb[6]) << 24) | (((uint32_t) cdb[7]) << 16) | + 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) | + dev->sector_pos = (((uint32_t) cdb[2]) << 24) | + (((uint32_t) cdb[3]) << 16) | (((uint32_t) cdb[4]) << 8) | ((uint32_t) cdb[5]); break; @@ -1652,86 +1470,76 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) break; } - if (dev->sector_pos >= dev->drv->medium_size) { + if (dev->sector_pos >= dev->drv->medium_size) zip_lba_out_of_range(dev); - return; - } + if (dev->sector_len) { + max_len = dev->sector_len; + dev->requested_blocks = max_len; - if (!dev->sector_len) { + dev->packet_len = max_len * alloc_length; + zip_buf_alloc(dev, dev->packet_len); + + dev->requested_blocks = max_len; + dev->packet_len = max_len << 9; + + zip_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); + + zip_data_command_finish(dev, dev->packet_len, 512, + dev->packet_len, 1); + + ui_sb_update_icon_write(SB_ZIP | dev->id, + dev->packet_status != PHASE_COMPLETE); + } else { zip_set_phase(dev, SCSI_PHASE_STATUS); - /* zip_log("ZIP %i: All done - callback set\n", dev->id); */ + /* zip_log(dev->log, "All done - callback set\n"); */ dev->packet_status = PHASE_COMPLETE; dev->callback = 20.0 * ZIP_TIME; zip_set_callback(dev); - break; } - - max_len = dev->sector_len; - /* - If we're writing all blocks in one go for DMA, why not also for - PIO, it should NOT matter anyway, this step should be identical - and only the way the read dat is transferred to the host should - be different. - */ - dev->requested_blocks = max_len; - - dev->packet_len = max_len * alloc_length; - zip_buf_alloc(dev, dev->packet_len); - - dev->requested_blocks = max_len; - dev->packet_len = max_len << 9; - - zip_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); - - zip_data_command_finish(dev, dev->packet_len, 512, dev->packet_len, 1); - - ui_sb_update_icon(SB_ZIP | dev->id, dev->packet_status != PHASE_COMPLETE); - return; + break; case GPCMD_WRITE_SAME_10: + zip_set_phase(dev, SCSI_PHASE_DATA_OUT); alloc_length = 512; - if ((cdb[1] & 6) == 6) { - zip_invalid_field(dev); - return; + if ((cdb[1] & 6) == 6) + zip_invalid_field(dev, cdb[1]); + else { + if (dev->drv->read_only) + zip_write_protected(dev); + else { + dev->sector_len = (cdb[7] << 8) | cdb[8]; + dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | + (cdb[4] << 8) | cdb[5]; + + if (dev->sector_pos >= dev->drv->medium_size) + zip_lba_out_of_range(dev); + else if (dev->sector_len) { + zip_buf_alloc(dev, alloc_length); + zip_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); + + max_len = 1; + dev->requested_blocks = 1; + + dev->packet_len = alloc_length; + + zip_set_phase(dev, SCSI_PHASE_DATA_OUT); + + zip_data_command_finish(dev, 512, 512, + alloc_length, 1); + + ui_sb_update_icon_write(SB_ZIP | dev->id, + dev->packet_status != PHASE_COMPLETE); + } else { + zip_set_phase(dev, SCSI_PHASE_STATUS); + /* zip_log(dev->log, "All done - callback set\n"); */ + dev->packet_status = PHASE_COMPLETE; + dev->callback = 20.0 * ZIP_TIME; + zip_set_callback(dev); + } + } } - - if (dev->drv->read_only) { - zip_write_protected(dev); - return; - } - - dev->sector_len = (cdb[7] << 8) | cdb[8]; - dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; - - if (dev->sector_pos >= dev->drv->medium_size) { - zip_lba_out_of_range(dev); - return; - } - - if (!dev->sector_len) { - zip_set_phase(dev, SCSI_PHASE_STATUS); - /* zip_log("ZIP %i: All done - callback set\n", dev->id); */ - dev->packet_status = PHASE_COMPLETE; - dev->callback = 20.0 * ZIP_TIME; - zip_set_callback(dev); - break; - } - - zip_buf_alloc(dev, alloc_length); - zip_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); - - max_len = 1; - dev->requested_blocks = 1; - - dev->packet_len = alloc_length; - - zip_set_phase(dev, SCSI_PHASE_DATA_OUT); - - zip_data_command_finish(dev, 512, 512, alloc_length, 1); - - ui_sb_update_icon(SB_ZIP | dev->id, dev->packet_status != PHASE_COMPLETE); - return; + break; case GPCMD_MODE_SENSE_6: case GPCMD_MODE_SENSE_10: @@ -1750,40 +1558,41 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) zip_buf_alloc(dev, 65536); } - if (!(zip_mode_sense_page_flags & (1LL << (uint64_t) (cdb[2] & 0x3f)))) { - zip_invalid_field(dev); - zip_buf_free(dev); - return; - } + if (zip_mode_sense_page_flags & (1LL << (uint64_t) (cdb[2] & 0x3f))) { + memset(dev->buffer, 0, len); + alloc_length = len; - memset(dev->buffer, 0, len); - alloc_length = len; - - if (cdb[0] == GPCMD_MODE_SENSE_6) { - len = zip_mode_sense(dev, dev->buffer, 4, cdb[2], block_desc); - len = MIN(len, alloc_length); - dev->buffer[0] = len - 1; - dev->buffer[1] = 0; - if (block_desc) - dev->buffer[3] = 8; - } else { - len = zip_mode_sense(dev, dev->buffer, 8, cdb[2], block_desc); - len = MIN(len, alloc_length); - dev->buffer[0] = (len - 2) >> 8; - dev->buffer[1] = (len - 2) & 255; - dev->buffer[2] = 0; - if (block_desc) { - dev->buffer[6] = 0; - dev->buffer[7] = 8; + if (cdb[0] == GPCMD_MODE_SENSE_6) { + len = zip_mode_sense(dev, dev->buffer, 4, cdb[2], + block_desc); + len = MIN(len, alloc_length); + dev->buffer[0] = len - 1; + dev->buffer[1] = 0; + if (block_desc) + dev->buffer[3] = 8; + } else { + len = zip_mode_sense(dev, dev->buffer, 8, cdb[2], + block_desc); + len = MIN(len, alloc_length); + dev->buffer[0] = (len - 2) >> 8; + dev->buffer[1] = (len - 2) & 255; + dev->buffer[2] = 0; + if (block_desc) { + dev->buffer[6] = 0; + dev->buffer[7] = 8; + } } + + zip_set_buf_len(dev, BufLen, &len); + + zip_log(dev->log, "Reading mode page: %02X...\n", cdb[2]); + + zip_data_command_finish(dev, len, len, alloc_length, 0); + } else { + zip_invalid_field(dev, cdb[2]); + zip_buf_free(dev); } - - zip_set_buf_len(dev, BufLen, &len); - - zip_log("ZIP %i: Reading mode page: %02X...\n", dev->id, cdb[2]); - - zip_data_command_finish(dev, len, len, alloc_length, 0); - return; + break; case GPCMD_MODE_SELECT_6: case GPCMD_MODE_SELECT_10: @@ -1856,7 +1665,7 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) break; case 0x83: if (idx + 24 > max_len) { - zip_data_phase_error(dev); + zip_data_phase_error(dev, cdb[2]); zip_buf_free(dev); return; } @@ -1874,19 +1683,21 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) dev->buffer[idx++] = 0x01; dev->buffer[idx++] = 0x00; dev->buffer[idx++] = 68; - ide_padstr8(dev->buffer + idx, 8, "IOMEGA "); /* Vendor */ + /* Vendor */ + ide_padstr8(dev->buffer + idx, 8, "IOMEGA "); idx += 8; + /* Product */ if (dev->drv->is_250) - ide_padstr8(dev->buffer + idx, 40, "ZIP 250 "); /* Product */ + ide_padstr8(dev->buffer + idx, 40, "ZIP 250 "); else - ide_padstr8(dev->buffer + idx, 40, "ZIP 100 "); /* Product */ + ide_padstr8(dev->buffer + idx, 40, "ZIP 100 "); idx += 40; - ide_padstr8(dev->buffer + idx, 20, "53R141"); /* Product */ + ide_padstr8(dev->buffer + idx, 20, "53R141"); idx += 20; break; default: - zip_log("INQUIRY: Invalid page: %02X\n", cdb[2]); - zip_invalid_field(dev); + zip_log(dev->log, "INQUIRY: Invalid page: %02X\n", cdb[2]); + zip_invalid_field(dev, cdb[2]); zip_buf_free(dev); return; } @@ -1896,33 +1707,39 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) memset(dev->buffer, 0, 8); if ((cdb[1] & 0xe0) || ((dev->cur_lun > 0x00) && (dev->cur_lun < 0xff))) - dev->buffer[0] = 0x7f; /*No physical device on this LUN*/ + dev->buffer[0] = 0x7f; /* No physical device on this LUN */ else - dev->buffer[0] = 0x00; /*Hard disk*/ - dev->buffer[1] = 0x80; /*Removable*/ - dev->buffer[2] = (dev->drv->bus_type == ZIP_BUS_SCSI) ? 0x02 : 0x00; /*SCSI-2 compliant*/ + dev->buffer[0] = 0x00; /* Hard disk */ + dev->buffer[1] = 0x80; /* Removable */ + /* SCSI-2 compliant */ + dev->buffer[2] = (dev->drv->bus_type == ZIP_BUS_SCSI) ? 0x02 : 0x00; dev->buffer[3] = (dev->drv->bus_type == ZIP_BUS_SCSI) ? 0x02 : 0x21; #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 */ - dev->buffer[7] = 0x20; /* Wide bus supported */ + dev->buffer[6] = 1; /* 16-bit transfers supported */ + dev->buffer[7] = 0x20; /* Wide bus supported */ } dev->buffer[7] |= 0x02; - ide_padstr8(dev->buffer + 8, 8, "IOMEGA "); /* Vendor */ + ide_padstr8(dev->buffer + 8, 8, "IOMEGA "); /* Vendor */ if (dev->drv->is_250) { - ide_padstr8(dev->buffer + 16, 16, "ZIP 250 "); /* Product */ - ide_padstr8(dev->buffer + 32, 4, "42.S"); /* Revision */ + /* Product */ + ide_padstr8(dev->buffer + 16, 16, "ZIP 250 "); + /* Revision */ + ide_padstr8(dev->buffer + 32, 4, "42.S"); + /* Date? */ if (max_len >= 44) - ide_padstr8(dev->buffer + 36, 8, "08/08/01"); /* Date? */ + ide_padstr8(dev->buffer + 36, 8, "08/08/01"); if (max_len >= 122) ide_padstr8(dev->buffer + 96, 26, "(c) Copyright IOMEGA 2000 "); /* Copyright string */ } else { - ide_padstr8(dev->buffer + 16, 16, "ZIP 100 "); /* Product */ - ide_padstr8(dev->buffer + 32, 4, "E.08"); /* Revision */ + /* Product */ + ide_padstr8(dev->buffer + 16, 16, "ZIP 100 "); + /* Revision */ + ide_padstr8(dev->buffer + 32, 4, "E.08"); } idx = 36; @@ -1974,7 +1791,8 @@ atapi_out: zip_buf_alloc(dev, 8); - max_len = dev->drv->medium_size - 1; /* IMPORTANT: What's returned is the last LBA block. */ + /* IMPORTANT: What's returned is the last LBA block. */ + max_len = dev->drv->medium_size - 1; memset(dev->buffer, 0, 8); dev->buffer[0] = (max_len >> 24) & 0xff; dev->buffer[1] = (max_len >> 16) & 0xff; @@ -2063,12 +1881,13 @@ atapi_out: break; default: - zip_illegal_opcode(dev); + zip_illegal_opcode(dev, cdb[0]); break; } #if 0 - zip_log("ZIP %i: Phase: %02X, request length: %i\n", dev->id, dev->tf->phase, dev->tf->request_length); + zip_log(dev->log, "Phase: %02X, request length: %i\n", + dev->tf->phase, dev->tf->request_length); #endif if ((dev->packet_status == PHASE_COMPLETE) || (dev->packet_status == PHASE_ERROR)) @@ -2088,29 +1907,16 @@ zip_command_stop(scsi_common_t *sc) static uint8_t zip_phase_data_out(scsi_common_t *sc) { - zip_t *dev = (zip_t *) sc; - + zip_t *dev = (zip_t *) sc; + int len = 0; + uint8_t error = 0; + uint32_t last_to_write; + uint32_t i; uint16_t block_desc_len; uint16_t pos; uint16_t param_list_len; - - uint8_t error = 0; - uint8_t page; - uint8_t page_len; - - uint32_t i = 0; - - uint8_t hdr_len; - uint8_t val; - uint8_t old_val; - uint8_t ch; - - uint32_t last_to_write = 0; - uint32_t c; - uint32_t h; - uint32_t s; - - int len = 0; + uint8_t hdr_len; + uint8_t val; switch (dev->current_cdb[0]) { case GPCMD_VERIFY_6: @@ -2123,7 +1929,7 @@ zip_phase_data_out(scsi_common_t *sc) case GPCMD_WRITE_12: case GPCMD_WRITE_AND_VERIFY_12: if (dev->requested_blocks > 0) - zip_blocks(dev, &len, 1, 1); + zip_blocks(dev, &len, 1); break; case GPCMD_WRITE_SAME_10: if (!dev->current_cdb[7] && !dev->current_cdb[8]) { @@ -2139,22 +1945,23 @@ zip_phase_data_out(scsi_common_t *sc) dev->buffer[3] = i & 0xff; } else if (dev->current_cdb[1] & 4) { /* CHS are 96, 1, 2048 (ZIP 100) and 239, 1, 2048 (ZIP 250) */ - s = (i % 2048); - h = ((i - s) / 2048) % 1; - c = ((i - s) / 2048) / 1; - dev->buffer[0] = (c >> 16) & 0xff; - dev->buffer[1] = (c >> 8) & 0xff; - dev->buffer[2] = c & 0xff; - dev->buffer[3] = h & 0xff; - dev->buffer[4] = (s >> 24) & 0xff; - dev->buffer[5] = (s >> 16) & 0xff; - dev->buffer[6] = (s >> 8) & 0xff; - dev->buffer[7] = s & 0xff; + const uint32_t s = (i % 2048); + const uint32_t h = ((i - s) / 2048) % 1; + const uint32_t c = ((i - s) / 2048) / 1; + dev->buffer[0] = (c >> 16) & 0xff; + dev->buffer[1] = (c >> 8) & 0xff; + dev->buffer[2] = c & 0xff; + dev->buffer[3] = h & 0xff; + dev->buffer[4] = (s >> 24) & 0xff; + dev->buffer[5] = (s >> 16) & 0xff; + dev->buffer[6] = (s >> 8) & 0xff; + dev->buffer[7] = s & 0xff; } - if (fseek(dev->drv->fp, dev->drv->base + (i << 9), SEEK_SET) == -1) - fatal("zip_phase_data_out(): Error seeking\n"); + if (fseek(dev->drv->fp, dev->drv->base + (i << 9), + SEEK_SET) == -1) + log_fatal(dev->log, "zip_phase_data_out(): Error seeking\n"); if (fwrite(dev->buffer, 1, 512, dev->drv->fp) != 512) - fatal("zip_phase_data_out(): Error writing data\n"); + log_fatal(dev->log, "zip_phase_data_out(): Error writing data\n"); } fflush(dev->drv->fp); @@ -2188,27 +1995,27 @@ zip_phase_data_out(scsi_common_t *sc) while (1) { if (pos >= param_list_len) { - zip_log("ZIP %i: Buffer has only block descriptor\n", dev->id); + zip_log(dev->log, "Buffer has only block descriptor\n"); break; } - page = dev->buffer[pos] & 0x3F; - page_len = dev->buffer[pos + 1]; + const uint8_t page = dev->buffer[pos] & 0x3f; + const uint8_t page_len = dev->buffer[pos + 1]; pos += 2; if (!(zip_mode_sense_page_flags & (1LL << ((uint64_t) page)))) error |= 1; - else { - for (i = 0; i < page_len; i++) { - ch = zip_mode_sense_pages_changeable.pages[page][i + 2]; - val = dev->buffer[pos + i]; - old_val = dev->ms_pages_saved.pages[page][i + 2]; - if (val != old_val) { - if (ch) - dev->ms_pages_saved.pages[page][i + 2] = val; - else - error |= 1; + else for (i = 0; i < page_len; i++) { + const uint8_t old_val = dev->ms_pages_saved.pages[page][i + 2]; + const uint8_t ch = zip_mode_sense_pages_changeable.pages[page][i + 2]; + val = dev->buffer[pos + i]; + if (val != old_val) { + if (ch) + dev->ms_pages_saved.pages[page][i + 2] = val; + else { + error |= 1; + zip_invalid_field_pl(dev, val); } } } @@ -2228,7 +2035,6 @@ zip_phase_data_out(scsi_common_t *sc) if (error) { zip_buf_free(dev); - zip_invalid_field_pl(dev); return 0; } break; @@ -2250,7 +2056,7 @@ zip_global_init(void) } static int -zip_get_max(int ide_has_dma, int type) +zip_get_max(UNUSED(const ide_t *ide), const int ide_has_dma, const int type) { int ret; @@ -2274,7 +2080,7 @@ zip_get_max(int ide_has_dma, int type) } static int -zip_get_timings(int ide_has_dma, int type) +zip_get_timings(UNUSED(const ide_t *ide), const int ide_has_dma, const int type) { int ret; @@ -2297,39 +2103,43 @@ zip_get_timings(int ide_has_dma, int type) } static void -zip_100_identify(ide_t *ide) +zip_100_identify(const ide_t *ide) { ide_padstr((char *) (ide->buffer + 23), "E.08", 8); /* Firmware */ ide_padstr((char *) (ide->buffer + 27), "IOMEGA ZIP 100 ATAPI", 40); /* Model */ } static void -zip_250_identify(ide_t *ide, int ide_has_dma) +zip_250_identify(const ide_t *ide, const int ide_has_dma) { - ide_padstr((char *) (ide->buffer + 23), "42.S", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "IOMEGA ZIP 250 ATAPI", 40); /* Model */ + /* Firmware */ + ide_padstr((char *) (ide->buffer + 23), "42.S", 8); + /* Model */ + ide_padstr((char *) (ide->buffer + 27), "IOMEGA ZIP 250 ATAPI", 40); if (ide_has_dma) { - ide->buffer[80] = 0x70; /*Supported ATA versions : ATA/ATAPI-4 ATA/ATAPI-6*/ - ide->buffer[81] = 0x19; /*Maximum ATA revision supported : ATA/ATAPI-6 T13 1410D revision 3a*/ + ide->buffer[80] = 0x70; /* Supported ATA versions : ATA/ATAPI-4 ATA/ATAPI-6 */ + /* Maximum ATA revision supported : ATA/ATAPI-6 T13 1410D revision 3a */ + ide->buffer[81] = 0x19; } } static void -zip_identify(ide_t *ide, int ide_has_dma) +zip_identify(const ide_t *ide, const int ide_has_dma) { - const zip_t *zip; + const zip_t *zip = (zip_t *) ide->sc; - zip = (zip_t *) ide->sc; - - /* ATAPI device, direct-access device, removable media, interrupt DRQ: + /* + ATAPI device, direct-access device, removable media, interrupt DRQ: Using (2 << 5) below makes the ASUS P/I-P54TP4XE misdentify the ZIP drive - as a LS-120. */ + as a LS-120. + */ ide->buffer[0] = 0x8000 | (0 << 8) | 0x80 | (1 << 5); - ide_padstr((char *) (ide->buffer + 10), "", 20); /* Serial Number */ - ide->buffer[49] = 0x200; /* LBA supported */ - ide->buffer[126] = 0xfffe; /* Interpret zero byte count limit as maximum length */ + ide_padstr((char *) (ide->buffer + 10), "", 20); /* Serial Number */ + ide->buffer[49] = 0x200; /* LBA supported */ + /* Interpret zero byte count limit as maximum length */ + ide->buffer[126] = 0xfffe; if (zip_drives[zip->id].is_250) zip_250_identify(ide, ide_has_dma); @@ -2338,30 +2148,32 @@ zip_identify(ide_t *ide, int ide_has_dma) } static void -zip_drive_reset(int c) +zip_drive_reset(const int c) { - zip_t *dev; - scsi_device_t *sd; - ide_t *id; - uint8_t scsi_bus = (zip_drives[c].scsi_device_id >> 4) & 0x0f; - uint8_t scsi_id = zip_drives[c].scsi_device_id & 0x0f; + const uint8_t scsi_bus = (zip_drives[c].scsi_device_id >> 4) & 0x0f; + const uint8_t scsi_id = zip_drives[c].scsi_device_id & 0x0f; - if (!zip_drives[c].priv) { - zip_drives[c].priv = (zip_t *) malloc(sizeof(zip_t)); - memset(zip_drives[c].priv, 0, sizeof(zip_t)); + if (zip_drives[c].priv == NULL) { + zip_drives[c].priv = (zip_t *) calloc(1, sizeof(zip_t)); + zip_t *dev = (zip_t *) zip_drives[c].priv; + + char n[1024] = { 0 }; + + sprintf(n, "ZIP %i", c + 1); + dev->log = log_open(n); } - dev = (zip_t *) zip_drives[c].priv; + zip_t *dev = (zip_t *) zip_drives[c].priv; dev->id = c; dev->cur_lun = SCSI_LUN_USE_CDB; if (zip_drives[c].bus_type == ZIP_BUS_SCSI) { - if (!dev->tf) + if (dev->tf == NULL) dev->tf = (ide_tf_t *) calloc(1, sizeof(ide_tf_t)); /* SCSI ZIP, attach to the SCSI bus. */ - sd = &scsi_devices[scsi_bus][scsi_id]; + scsi_device_t *sd = &scsi_devices[scsi_bus][scsi_id]; sd->sc = (scsi_common_t *) dev; sd->command = zip_command; @@ -2372,7 +2184,7 @@ zip_drive_reset(int c) sd->type = SCSI_REMOVABLE_DISK; } else if (zip_drives[c].bus_type == ZIP_BUS_ATAPI) { /* ATAPI CD-ROM, attach to the IDE bus. */ - id = ide_get_drive(zip_drives[c].ide_channel); + ide_t *id = ide_get_drive(zip_drives[c].ide_channel); /* If the IDE channel is initialized, we attach to it, otherwise, we do nothing - it's going to be a drive that's not attached to anything. */ @@ -2399,17 +2211,12 @@ zip_drive_reset(int c) void zip_hard_reset(void) { - zip_t *dev; - uint8_t scsi_id; - uint8_t scsi_bus; - 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); 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; + const uint8_t scsi_bus = (zip_drives[c].scsi_device_id >> 4) & 0x0f; + const uint8_t scsi_id = zip_drives[c].scsi_device_id & 0x0f; /* Make sure to ignore any SCSI ZIP drive that has an out of range SCSI bus. */ if (scsi_bus >= SCSI_BUS_MAX) @@ -2426,7 +2233,9 @@ zip_hard_reset(void) zip_drive_reset(c); - dev = (zip_t *) zip_drives[c].priv; + zip_t *dev = (zip_t *) zip_drives[c].priv; + + zip_log(dev->log, "ZIP hard_reset drive=%d\n", c); if (dev->tf == NULL) continue; @@ -2437,14 +2246,16 @@ zip_hard_reset(void) zip_init(dev); if (strlen(zip_drives[c].image_path)) - zip_load(dev, zip_drives[c].image_path); + zip_load(dev, zip_drives[c].image_path, 0); zip_mode_sense_load(dev); if (zip_drives[c].bus_type == ZIP_BUS_SCSI) - zip_log("SCSI ZIP drive %i attached to SCSI ID %i\n", c, zip_drives[c].scsi_device_id); + zip_log(dev->log, "SCSI ZIP drive %i attached to SCSI ID %i\n", + c, zip_drives[c].scsi_device_id); else if (zip_drives[c].bus_type == ZIP_BUS_ATAPI) - zip_log("ATAPI ZIP drive %i attached to IDE channel %i\n", c, zip_drives[c].ide_channel); + zip_log(dev->log, "ATAPI ZIP drive %i attached to IDE channel %i\n", + c, zip_drives[c].ide_channel); } } } @@ -2452,19 +2263,15 @@ zip_hard_reset(void) void zip_close(void) { - zip_t *dev; - uint8_t scsi_bus; - uint8_t scsi_id; - 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; + const uint8_t scsi_bus = (zip_drives[c].scsi_device_id >> 4) & 0x0f; + const uint8_t scsi_id = zip_drives[c].scsi_device_id & 0x0f; memset(&scsi_devices[scsi_bus][scsi_id], 0x00, sizeof(scsi_device_t)); } - dev = (zip_t *) zip_drives[c].priv; + zip_t *dev = (zip_t *) zip_drives[c].priv; if (dev) { zip_disk_unload(dev); @@ -2472,6 +2279,13 @@ zip_close(void) if (dev->tf) free(dev->tf); + if (dev->log != NULL) { + zip_log(dev->log, "Log closed\n"); + + log_close(dev->log); + dev->log = NULL; + } + free(dev); zip_drives[c].priv = NULL; } diff --git a/src/dma.c b/src/dma.c index 4edeb39f8..2265947b9 100644 --- a/src/dma.c +++ b/src/dma.c @@ -856,7 +856,7 @@ dma16_read(uint16_t addr, UNUSED(void *priv)) break; } - dma_log("dma16_read(%08X) = %02X\n", port, ret); + dma_log("dma16_read(%08X) = %02X\n", addr, ret); return ret; } diff --git a/src/floppy/CMakeLists.txt b/src/floppy/CMakeLists.txt index d86ff4bc2..c16ca06f4 100644 --- a/src/floppy/CMakeLists.txt +++ b/src/floppy/CMakeLists.txt @@ -18,6 +18,7 @@ add_library(fdd OBJECT fdd.c fdc.c + fdc_compaticard.c fdc_magitronic.c fdc_monster.c fdc_pii15xb.c diff --git a/src/floppy/fdc.c b/src/floppy/fdc.c index 546174c57..523ae6948 100644 --- a/src/floppy/fdc.c +++ b/src/floppy/fdc.c @@ -79,6 +79,8 @@ int floppyrate[4]; int fdc_current[FDC_MAX] = { 0, 0 }; +volatile int fdcinited = 0; + #ifdef ENABLE_FDC_LOG int fdc_do_log = ENABLE_FDC_LOG; @@ -103,15 +105,20 @@ typedef const struct { static fdc_cards_t fdc_cards[] = { // clang-format off - { &device_none }, - { &device_internal }, - { &fdc_xt_device }, - { &fdc_at_device }, - { &fdc_b215_device }, - { &fdc_pii151b_device }, - { &fdc_pii158b_device }, - { &fdc_monster_device }, - { NULL } + { &device_none }, + { &device_internal }, + { &fdc_xt_device }, + { &fdc_at_device }, + { &fdc_b215_device }, + { &fdc_pii151b_device }, + { &fdc_pii158b_device }, + { &fdc_compaticard_i_device }, + { &fdc_compaticard_ii_device }, +#if 0 + { &fdc_compaticard_iv_device }, +#endif + { &fdc_monster_device }, + { NULL } // clang-format on }; @@ -180,10 +187,18 @@ fdc_ctrl_reset(void *priv) fdc->stat = 0x80; fdc->pnum = fdc->ptot = 0; fdc->st0 = 0; - fdc->lock = 0; fdc->head = 0; fdc->step = 0; fdc->power_down = 0; + + if (!fdc->lock && !fdc->fifointest) { + fdc->fifo = 0; + fdc->tfifo = 1; + + fifo_reset(fdc->fifo_p); + fifo_set_len(fdc->fifo_p, fdc->tfifo + 1); + fifo_set_trigger_len(fdc->fifo_p, fdc->tfifo + 1); + } } sector_id_t @@ -271,6 +286,15 @@ fdc_is_mfm(fdc_t *fdc) return fdc->mfm ? 1 : 0; } +int +fdc_is_dma(fdc_t *fdc) +{ + if ((fdc->flags & FDC_FLAG_PCJR) || !fdc->dma) + return 0; + else + return 1; +} + void fdc_request_next_sector_id(fdc_t *fdc) { @@ -361,6 +385,15 @@ fdc_set_power_down(fdc_t *fdc, uint8_t power_down) fdc->power_down = power_down; } +void +fdc_toggle_flag(fdc_t *fdc, int flag, int on) +{ + if (on) + fdc->flags |= flag; + else + fdc->flags &= ~flag; +} + void fdc_update_max_track(fdc_t *fdc, int max_track) { @@ -388,6 +421,20 @@ fdc_update_rwc(fdc_t *fdc, int drive, int rwc) fdc_rate(fdc, drive); } +uint8_t +fdc_get_media_id(fdc_t *fdc, int id) +{ + uint8_t ret = fdc->media_id & (1 << id); + + return ret; +} + +void +fdc_set_media_id(fdc_t *fdc, int id, int set) +{ + fdc->media_id = (fdc->media_id & ~(1 << id)) | (set << id); +} + int fdc_get_boot_drive(fdc_t *fdc) { @@ -439,9 +486,11 @@ fdc_update_drv2en(fdc_t *fdc, int drv2en) void fdc_update_rate(fdc_t *fdc, int drive) { - if (((fdc->rwc[drive] == 1) || (fdc->rwc[drive] == 2)) && fdc->enh_mode) + if (((fdc->rwc[drive] == 1) || (fdc->rwc[drive] == 2)) && + fdc->enh_mode && !(fdc->flags & FDC_FLAG_SMC661)) fdc->bit_rate = 500; - else if ((fdc->rwc[drive] == 3) && fdc->enh_mode) + else if ((fdc->rwc[drive] == 3) && fdc->enh_mode && + !(fdc->flags & FDC_FLAG_SMC661)) fdc->bit_rate = 250; else switch (fdc->rate) { default: @@ -505,7 +554,7 @@ fdc_get_bitcell_period(fdc_t *fdc) static int fdc_get_densel(fdc_t *fdc, int drive) { - if (fdc->enh_mode) { + if (fdc->enh_mode && !(fdc->flags & FDC_FLAG_SMC661)) { switch (fdc->rwc[drive]) { case 1: case 3: @@ -608,7 +657,10 @@ fdc_io_command_phase1(fdc_t *fdc, int out) } } - ui_sb_update_icon(SB_FLOPPY | real_drive(fdc, fdc->drive), 1); + if (fdc->processed_cmd == 0x05 || fdc->processed_cmd == 0x09) + ui_sb_update_icon_write(SB_FLOPPY | real_drive(fdc, fdc->drive), 1); + else + ui_sb_update_icon(SB_FLOPPY | real_drive(fdc, fdc->drive), 1); fdc->stat = out ? 0x10 : 0x50; if ((fdc->flags & FDC_FLAG_PCJR) || !fdc->dma) { fdc->stat |= 0x20; @@ -664,8 +716,10 @@ fdc_soft_reset(fdc_t *fdc) fdc->perp &= 0xfc; - for (int i = 0; i < FDD_NUM; i++) - ui_sb_update_icon(SB_FLOPPY | i, 0); + for (int i = 0; i < FDD_NUM; i++) { + ui_sb_update_icon(SB_FLOPPY | i, 0); + ui_sb_update_icon_write(SB_FLOPPY | i, 0); + } fdc_ctrl_reset(fdc); } @@ -699,6 +753,7 @@ fdc_write(uint16_t addr, uint8_t val, void *priv) timer_set_delay_u64(&fdc->timer, 8 * TIMER_USEC); fdc->interrupt = -1; ui_sb_update_icon(SB_FLOPPY | 0, 0); + ui_sb_update_icon_write(SB_FLOPPY | 0, 0); fdc_ctrl_reset(fdc); } if (!fdd_get_flags(0)) @@ -734,8 +789,28 @@ fdc_write(uint16_t addr, uint8_t val, void *priv) return; case 3: /* TDR */ if (fdc->enh_mode) { - drive = real_drive(fdc, fdc->dor & 3); - fdc_update_rwc(fdc, drive, (val & 0x30) >> 4); + if (fdc->flags & FDC_FLAG_SMC661) { + fdc_set_swap(fdc, !!(val & 0x20)); + fdc_update_densel_force(fdc, (val & 0x18) >> 3); + } else { + drive = real_drive(fdc, fdc->dor & 3); + fdc_update_rwc(fdc, drive, (val & 0x30) >> 4); + } + } + /* Bit 2: FIFO test mode (PS/55 5550-S,T only. Undocumented) + The Power-on Self Test of PS/55 writes and verifies 8 bytes of FIFO buffer through I/O 3F5h. + If it fails, then floppy drives will be treated as DD drives. */ + if (fdc->flags & FDC_FLAG_PS2_MCA) { + if (val & 0x04) { + fdc->tfifo = 8; + fdc->fifointest = 1; + } else { + fdc->tfifo = 1; + fdc->fifointest = 0; + } + fifo_reset(fdc->fifo_p); + fifo_set_len(fdc->fifo_p, fdc->tfifo + 1); + fifo_set_trigger_len(fdc->fifo_p, fdc->tfifo + 1); } return; case 4: /* DSR */ @@ -750,6 +825,14 @@ fdc_write(uint16_t addr, uint8_t val, void *priv) fdc->dsr = val; return; case 5: /*Command register*/ + if (fdc->fifointest) { + /* Write FIFO buffer in the test mode (PS/55) */ + fdc_log("FIFO buffer position = %X\n", ((fifo_t *) fdc->fifo_p)->end); + fifo_write(val, fdc->fifo_p); + if (fifo_get_full(fdc->fifo_p)) + fdc->stat &= ~0x80; + break; + } if ((fdc->stat & 0xf0) == 0xb0) { if ((fdc->flags & FDC_FLAG_PCJR) || !fdc->fifo) { fdc->dat = val; @@ -1332,15 +1415,23 @@ fdc_read(uint16_t addr, void *priv) ret = 0x10; else ret = 0x00; + /* PS/55 POST throws an error and halt if ret = 1 or 2, somehow. */ } else if (!fdc->enh_mode) ret = 0x20; + else if (fdc->flags & FDC_FLAG_SMC661) + ret = (fdc->densel_force << 3) | ((!!fdc->swap) << 5) | (fdc->media_id << 6); else - ret = fdc->rwc[drive] << 4; + ret = (fdc->rwc[drive] << 4) | (fdc->media_id << 6); break; case 4: /*Status*/ ret = fdc->stat; break; case 5: /*Data*/ + if (fdc->fifointest) { + /* Read FIFO buffer in the test mode (PS/55) */ + ret = fifo_read(fdc->fifo_p); + break; + } if ((fdc->stat & 0xf0) == 0xf0) { fdc->stat &= ~0x80; if ((fdc->flags & FDC_FLAG_PCJR) || !fdc->fifo) { @@ -1413,7 +1504,7 @@ fdc_read(uint16_t addr, void *priv) fdc->step = 0; break; default: - ret = 0xFF; + ret = 0xff; } fdc_log("[%04X:%08X] Read FDC %04X %02X [%i:%02X]\n", CS, cpu_state.pc, addr, ret, drive, fdc->dor & (0x10 << drive)); return ret; @@ -1469,6 +1560,7 @@ fdc_poll_common_finish(fdc_t *fdc, int compare, int st5) fdc->res[10] = fdc->params[4]; fdc_log("Read/write finish (%02X %02X %02X %02X %02X %02X %02X)\n", fdc->res[4], fdc->res[5], fdc->res[6], fdc->res[7], fdc->res[8], fdc->res[9], fdc->res[10]); ui_sb_update_icon(SB_FLOPPY | real_drive(fdc, fdc->drive), 0); + ui_sb_update_icon_write(SB_FLOPPY | real_drive(fdc, fdc->drive), 0); fdc->paramstogo = 7; dma_set_drq(fdc->dma_ch, 0); } @@ -1512,8 +1604,10 @@ fdc_callback(void *priv) case -5: /*Reset in power down mode */ fdc->perp &= 0xfc; - for (uint8_t i = 0; i < FDD_NUM; i++) + for (uint8_t i = 0; i < FDD_NUM; i++) { ui_sb_update_icon(SB_FLOPPY | i, 0); + ui_sb_update_icon_write(SB_FLOPPY | i, 0); + } fdc_ctrl_reset(fdc); @@ -1570,8 +1664,8 @@ fdc_callback(void *priv) case 0x06: /* Read data */ case 0x0c: /* Read deleted data */ case 0x11: /* Scan equal */ + case 0x16: /* Verify */ case 0x19: /* Scan low or equal */ - case 0x1c: /* Verify */ case 0x1d: /* Scan high or equal */ if ((fdc->interrupt == 0x11) || (fdc->interrupt == 0x19) || (fdc->interrupt == 0x1D)) compare = 1; @@ -1661,7 +1755,10 @@ fdc_callback(void *priv) fdc->sector++; else if (fdc->params[5] == 0) fdc->sector++; - ui_sb_update_icon(SB_FLOPPY | real_drive(fdc, fdc->drive), 1); + if (fdc->interrupt == 0x05 || fdc->interrupt == 0x09) + ui_sb_update_icon_write(SB_FLOPPY | real_drive(fdc, fdc->drive), 1); + else + ui_sb_update_icon(SB_FLOPPY | real_drive(fdc, fdc->drive), 1); switch (fdc->interrupt) { case 5: case 9: @@ -1852,6 +1949,7 @@ fdc_error(fdc_t *fdc, int st5, int st6) break; } ui_sb_update_icon(SB_FLOPPY | real_drive(fdc, fdc->drive), 0); + ui_sb_update_icon_write(SB_FLOPPY | real_drive(fdc, fdc->drive), 0); fdc->paramstogo = 7; } @@ -2157,9 +2255,13 @@ fdc_set_base(fdc_t *fdc, int base) { int super_io = (fdc->flags & FDC_FLAG_SUPERIO); + if (base == 0x0000) { + fdc->base_address = base; + return; + } + if (fdc->flags & FDC_FLAG_NSC) { - io_sethandler(base + 2, 0x0001, fdc_read, NULL, NULL, fdc_write, NULL, NULL, fdc); - io_sethandler(base + 4, 0x0002, fdc_read, NULL, NULL, fdc_write, NULL, NULL, fdc); + io_sethandler(base + 2, 0x0004, fdc_read, NULL, NULL, fdc_write, NULL, NULL, fdc); io_sethandler(base + 7, 0x0001, fdc_read, NULL, NULL, fdc_write, NULL, NULL, fdc); } else { if ((fdc->flags & FDC_FLAG_AT) || (fdc->flags & FDC_FLAG_AMSTRAD)) { @@ -2188,10 +2290,12 @@ fdc_remove(fdc_t *fdc) { int super_io = (fdc->flags & FDC_FLAG_SUPERIO); + if (fdc->base_address == 0x0000) + return; + fdc_log("FDC Removed (%04X)\n", fdc->base_address); if (fdc->flags & FDC_FLAG_NSC) { - io_removehandler(fdc->base_address + 2, 0x0001, fdc_read, NULL, NULL, fdc_write, NULL, NULL, fdc); - io_removehandler(fdc->base_address + 4, 0x0002, fdc_read, NULL, NULL, fdc_write, NULL, NULL, fdc); + io_removehandler(fdc->base_address + 2, 0x0004, fdc_read, NULL, NULL, fdc_write, NULL, NULL, fdc); io_removehandler(fdc->base_address + 7, 0x0001, fdc_read, NULL, NULL, fdc_write, NULL, NULL, fdc); } else { if ((fdc->flags & FDC_FLAG_AT) || (fdc->flags & FDC_FLAG_AMSTRAD)) { @@ -2237,15 +2341,27 @@ fdc_reset(void *priv) fdc_update_rwc(fdc, 1, default_rwc); fdc_update_rwc(fdc, 2, default_rwc); fdc_update_rwc(fdc, 3, default_rwc); - fdc_update_drvrate(fdc, 0, 0); - fdc_update_drvrate(fdc, 1, 0); - fdc_update_drvrate(fdc, 2, 0); - fdc_update_drvrate(fdc, 3, 0); + /* + The OKI IF386SX natively supports the Japanese 1.25 MB floppy format, + since it can read such images just fine, it also attempts to use data + rate 01 on a 3.5" MB drive (which is the only kind it can physically + take, anyway), and rate 01 on a 3.5" MB drive is usually used by 3-mode + drives to switch to 360 RPM. Hence why I'm switching DRVDEN to 1, so + rate 01 becomes 500 kbps, so on a 3-mode 3.5" drive, 1.25 MB floppies + can be read. The side effect is that to read 5.25" 360k drives, you + need to use a dual-RPM 5.25" drive - but hey, that finally gets those + drives some usage as well. + */ + fdc_update_drvrate(fdc, 0, !strcmp(machine_get_internal_name(), "if386sx")); + fdc_update_drvrate(fdc, 1, !strcmp(machine_get_internal_name(), "if386sx")); + fdc_update_drvrate(fdc, 2, !strcmp(machine_get_internal_name(), "if386sx")); + fdc_update_drvrate(fdc, 3, !strcmp(machine_get_internal_name(), "if386sx")); fdc_update_drv2en(fdc, 1); fdc_update_rates(fdc); fdc->fifo = 0; fdc->tfifo = 1; + fdc->fifointest = 0; if (fdc->flags & FDC_FLAG_PCJR) { fdc->dma = 0; @@ -2269,6 +2385,8 @@ fdc_reset(void *priv) fdc->swwp = 0; fdc->disable_write = 0; + fdc->lock = 0; + fdc_ctrl_reset(fdc); if (!(fdc->flags & FDC_FLAG_AT)) @@ -2288,10 +2406,14 @@ fdc_reset(void *priv) current_drive = 0; - for (uint8_t i = 0; i < FDD_NUM; i++) + for (uint8_t i = 0; i < FDD_NUM; i++) { ui_sb_update_icon(SB_FLOPPY | i, 0); + ui_sb_update_icon_write(SB_FLOPPY | i, 0); + } fdc->power_down = 0; + + fdc->media_id = 0; } static void @@ -2305,14 +2427,15 @@ fdc_close(void *priv) fifo_close(fdc->fifo_p); + fdcinited = 0; + free(fdc); } static void * fdc_init(const device_t *info) { - fdc_t *fdc = (fdc_t *) malloc(sizeof(fdc_t)); - memset(fdc, 0, sizeof(fdc_t)); + fdc_t *fdc = (fdc_t *) calloc(1, sizeof(fdc_t)); fdc->flags = info->local; @@ -2351,6 +2474,8 @@ fdc_init(const device_t *info) fdc_reset(fdc); + fdcinited = 1; + return fdc; } @@ -2368,7 +2493,7 @@ const device_t fdc_xt_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2382,7 +2507,7 @@ const device_t fdc_xt_sec_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2396,7 +2521,7 @@ const device_t fdc_xt_ter_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2410,7 +2535,7 @@ const device_t fdc_xt_qua_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2424,7 +2549,7 @@ const device_t fdc_xt_t1x00_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2438,7 +2563,7 @@ const device_t fdc_xt_amstrad_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2452,7 +2577,7 @@ const device_t fdc_xt_tandy_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2466,7 +2591,7 @@ const device_t fdc_xt_umc_um8398_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2480,7 +2605,7 @@ const device_t fdc_pcjr_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2494,7 +2619,7 @@ const device_t fdc_at_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2508,7 +2633,7 @@ const device_t fdc_at_sec_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2522,7 +2647,7 @@ const device_t fdc_at_ter_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2536,7 +2661,7 @@ const device_t fdc_at_qua_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2550,7 +2675,21 @@ const device_t fdc_at_actlow_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t fdc_at_smc_661_device = { + .name = "PC/AT Floppy Drive Controller (SM(s)C FDC37C661/2)", + .internal_name = "fdc_at_smc", + .flags = 0, + .local = FDC_FLAG_AT | FDC_FLAG_SUPERIO | FDC_FLAG_SMC661, + .init = fdc_init, + .close = fdc_close, + .reset = fdc_reset, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2564,7 +2703,7 @@ const device_t fdc_at_smc_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2578,7 +2717,7 @@ const device_t fdc_at_ali_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2592,7 +2731,7 @@ const device_t fdc_at_winbond_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2606,7 +2745,7 @@ const device_t fdc_at_nsc_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2620,7 +2759,7 @@ const device_t fdc_at_nsc_dp8473_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2635,7 +2774,7 @@ const device_t fdc_ps2_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2650,7 +2789,7 @@ const device_t fdc_ps2_mca_device = { .init = fdc_init, .close = fdc_close, .reset = fdc_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/floppy/fdc_compaticard.c b/src/floppy/fdc_compaticard.c new file mode 100644 index 000000000..741105927 --- /dev/null +++ b/src/floppy/fdc_compaticard.c @@ -0,0 +1,368 @@ +/* + * 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 Micro Solutions CompatiCard I/II/IV. + * + * Authors: Jasmine Iwanek, + * + * Copyright 2022-2025 Jasmine Iwanek. + */ + +#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/rom.h> +#include <86box/machine.h> +#include <86box/timer.h> +#include <86box/fdd.h> +#include <86box/fdc.h> +#include <86box/fdc_ext.h> +#include <86box/plat_unused.h> + +#define DEVICE_COMPATICARD_I 0 +#define DEVICE_COMPATICARD_II 1 +#define DEVICE_COMPATICARD_IV 2 + +#define BIOS_ADDR (uint32_t)(device_get_config_hex20("bios_addr") & 0x000fffff) +#define ROM_COMPATICARD_IV "roms/floppy/compaticard/ccivbios1.05.bin" + +#define CR_2_MASK 0x2f /* 00101111b */ + +typedef struct compaticard_s { + rom_t bios_rom; + fdc_t *fdc; + /* + * 7 - Reserved - Set to 0 + * 6 - Reserved - Set to 0 + * 5 - Programmable Pin 2 Logic I sets Pin 2 low (TODO) + * 4 - Reserved - Set to 0 + * 3-0 - Data Transfer Rate Select (TODO) + * 0000---250 Kbps + * 0001-300 Kbps + * 1111-500 Kbps + */ + uint8_t cr_2; +} compaticard_t; + +static void +compaticard_out(UNUSED(uint16_t port), uint8_t val, void *priv) +{ + compaticard_t *dev = (compaticard_t *) priv; + + dev->cr_2 = (val & CR_2_MASK); +} + +static uint8_t +compaticard_in(UNUSED(uint16_t port), void *priv) +{ + compaticard_t *dev = (compaticard_t *) priv; + uint8_t ret = (dev->cr_2 &CR_2_MASK); + + return ret; +} + +static void +compaticard_close(void *priv) +{ + compaticard_t *dev = (compaticard_t *) priv; + + free(dev); +} + +static void * +compaticard_init(const device_t *info) +{ + compaticard_t *dev = calloc(1, sizeof(compaticard_t)); + uint16_t base_addr = device_get_config_hex16("base"); + uint8_t irq = 6; + uint8_t dma = 2; + uint16_t cr2_addr = 0x7f2; // Control Register 2 + + // CompatiCard II & IV have configurable IRQ and DMA + if (info->local >= DEVICE_COMPATICARD_II) { + irq = device_get_config_int("irq"); + dma = device_get_config_int("dma"); + } + + // Only on CompatiCard IV + if ((info->local == DEVICE_COMPATICARD_IV) && (BIOS_ADDR != 0)) + rom_init(&dev->bios_rom, ROM_COMPATICARD_IV, BIOS_ADDR, 0x2000, 0x1ffff, 0, MEM_MAPPING_EXTERNAL); + + // TODO: Make this neater + switch (base_addr) { + case FDC_SECONDARY_ADDR: + cr2_addr = 0x772; + if (info->local == DEVICE_COMPATICARD_IV) + dev->fdc = device_add(&fdc_at_sec_device); + else + dev->fdc = device_add(&fdc_xt_sec_device); + break; + + case FDC_TERTIARY_ADDR: + cr2_addr = 0x762; + if (info->local == DEVICE_COMPATICARD_IV) + dev->fdc = device_add(&fdc_at_ter_device); + else + dev->fdc = device_add(&fdc_xt_ter_device); + break; + + case FDC_QUATERNARY_ADDR: + cr2_addr = 0x7e2; + if (info->local == DEVICE_COMPATICARD_IV) + dev->fdc = device_add(&fdc_at_qua_device); + else + dev->fdc = device_add(&fdc_xt_qua_device); + break; + + default: + if (info->local == DEVICE_COMPATICARD_IV) + dev->fdc = device_add(&fdc_at_device); + else + dev->fdc = device_add(&fdc_xt_device); + break; + } + + fdc_set_irq(dev->fdc, irq); + fdc_set_dma_ch(dev->fdc, dma); + + io_sethandler(cr2_addr, 0x0001, + compaticard_in, NULL, NULL, + compaticard_out, NULL, NULL, + dev); + + return dev; +} + +static int compaticard_iv_available(void) +{ + return rom_present(ROM_COMPATICARD_IV); +} + +static const device_config_t compaticard_i_config[] = { +// clang-format off + { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x3f0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "0x3f0", .value = 0x3f0 }, + { .description = "0x370", .value = 0x370 }, + { .description = "0x360", .value = 0x360 }, + { .description = "0x3e0", .value = 0x3e0 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } +// clang-format on +}; + +static const device_config_t compaticard_ii_config[] = { +// clang-format off + { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x3f0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "0x3f0", .value = 0x3f0 }, + { .description = "0x370", .value = 0x370 }, + { .description = "0x360", .value = 0x360 }, + { .description = "0x3e0", .value = 0x3e0 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 6, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "IRQ 2", .value = 2 }, + { .description = "IRQ 3", .value = 3 }, + { .description = "IRQ 4", .value = 4 }, + { .description = "IRQ 5", .value = 5 }, + { .description = "IRQ 6", .value = 6 }, + { .description = "IRQ 7", .value = 7 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { + .name = "dma", + .description = "DMA channel", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "DMA 1", .value = 1 }, + { .description = "DMA 2", .value = 2 }, + { .description = "DMA 3", .value = 3 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } +// clang-format on +}; + +static const device_config_t compaticard_iv_config[] = { +// clang-format off + { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x3f0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "0x3f0", .value = 0x3f0 }, + { .description = "0x370", .value = 0x370 }, + { .description = "0x360", .value = 0x360 }, + { .description = "0x3e0", .value = 0x3e0 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 6, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "IRQ 2", .value = 2 }, + { .description = "IRQ 3", .value = 3 }, + { .description = "IRQ 4", .value = 4 }, + { .description = "IRQ 5", .value = 5 }, + { .description = "IRQ 6", .value = 6 }, + { .description = "IRQ 7", .value = 7 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { + .name = "dma", + .description = "DMA channel", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "DMA 1", .value = 1 }, + { .description = "DMA 2", .value = 2 }, + { .description = "DMA 3", .value = 3 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { + .name = "bios_addr", + .description = "BIOS Address:", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0xce000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Disabled", .value = 0 }, + { .description = "CC00H", .value = 0xcc000 }, + { .description = "CE00H", .value = 0xce000 }, + { .description = "D000H", .value = 0xd0000 }, + { .description = "D800H", .value = 0xd8000 }, + { .description = "DE00H", .value = 0xde000 }, + { .description = "E000H", .value = 0xe0000 }, + { .description = "E800H", .value = 0xe8000 }, + { .description = "EE00H", .value = 0xee000 }, + { .description = "" } + }, + .bios = { { 0 } } + }, +#if 0 + { + .name = "autoboot_enabled", + .description = "Enable Autoboot", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, +#endif + { .name = "", .description = "", .type = CONFIG_END } +// clang-format on +}; + +const device_t fdc_compaticard_i_device = { + .name = "Micro Solutions CompatiCard I", + .internal_name = "compaticard_i", + .flags = DEVICE_ISA, + .local = 0, + .init = compaticard_init, + .close = compaticard_close, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = compaticard_i_config +}; + +const device_t fdc_compaticard_ii_device = { + .name = "Micro Solutions CompatiCard II", + .internal_name = "compaticard_ii", + .flags = DEVICE_ISA, + .local = 1, + .init = compaticard_init, + .close = compaticard_close, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = compaticard_ii_config +}; + +const device_t fdc_compaticard_iv_device = { + .name = "Micro Solutions CompatiCard IV", + .internal_name = "compaticard_iv", + .flags = DEVICE_ISA, + .local = 2, + .init = compaticard_init, + .close = compaticard_close, + .reset = NULL, + .available = compaticard_iv_available, + .speed_changed = NULL, + .force_redraw = NULL, + .config = compaticard_iv_config +}; diff --git a/src/floppy/fdc_magitronic.c b/src/floppy/fdc_magitronic.c index 306440b9c..17e556e0f 100644 --- a/src/floppy/fdc_magitronic.c +++ b/src/floppy/fdc_magitronic.c @@ -90,8 +90,7 @@ b215_close(void *priv) static void * b215_init(UNUSED(const device_t *info)) { - b215_t *dev = (b215_t *) malloc(sizeof(b215_t)); - memset(dev, 0, sizeof(b215_t)); + b215_t *dev = (b215_t *) calloc(1, sizeof(b215_t)); rom_init(&dev->rom, ROM_B215, ROM_ADDR, 0x2000, 0x1fff, 0, MEM_MAPPING_EXTERNAL); @@ -110,18 +109,19 @@ b215_available(void) static const device_config_t b215_config[] = { // clang-format off { - .name = "bios_addr", - .description = "BIOS Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0xca000, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "bios_addr", + .description = "BIOS Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0xca000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "CA00H", .value = 0xca000 }, { .description = "CC00H", .value = 0xcc000 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -135,7 +135,7 @@ const device_t fdc_b215_device = { .init = b215_init, .close = b215_close, .reset = NULL, - { .available = b215_available }, + .available = b215_available, .speed_changed = NULL, .force_redraw = NULL, .config = b215_config diff --git a/src/floppy/fdc_monster.c b/src/floppy/fdc_monster.c index 00b6d37f5..04536520f 100644 --- a/src/floppy/fdc_monster.c +++ b/src/floppy/fdc_monster.c @@ -13,7 +13,7 @@ * Authors: Jasmine Iwanek, * Miran Grca, * - * Copyright 2022-2024 Jasmine Iwanek. + * Copyright 2022-2025 Jasmine Iwanek. * Copyright 2024 Miran Grca. */ #include @@ -47,57 +47,6 @@ typedef struct monster_fdc_t { char nvr_path[64]; } monster_fdc_t; -static void -rom_write(uint32_t addr, uint8_t val, void *priv) -{ - const rom_t *rom = (rom_t *) priv; - -#ifdef ROM_TRACE - if (rom->mapping.base == ROM_TRACE) - rom_log("ROM: read byte from BIOS at %06lX\n", addr); -#endif - - if (addr < rom->mapping.base) - return; - if (addr >= (rom->mapping.base + rom->sz)) - return; - rom->rom[(addr - rom->mapping.base) & rom->mask] = val; -} - -static void -rom_writew(uint32_t addr, uint16_t val, void *priv) -{ - rom_t *rom = (rom_t *) priv; - -#ifdef ROM_TRACE - if (rom->mapping.base == ROM_TRACE) - rom_log("ROM: read word from BIOS at %06lX\n", addr); -#endif - - if (addr < (rom->mapping.base - 1)) - return; - if (addr >= (rom->mapping.base + rom->sz)) - return; - *(uint16_t *) &rom->rom[(addr - rom->mapping.base) & rom->mask] = val; -} - -static void -rom_writel(uint32_t addr, uint32_t val, void *priv) -{ - rom_t *rom = (rom_t *) priv; - -#ifdef ROM_TRACE - if (rom->mapping.base == ROM_TRACE) - rom_log("ROM: read long from BIOS at %06lX\n", addr); -#endif - - if (addr < (rom->mapping.base - 3)) - return; - if (addr >= (rom->mapping.base + rom->sz)) - return; - *(uint32_t *) &rom->rom[(addr - rom->mapping.base) & rom->mask] = val; -} - static void monster_fdc_close(void *priv) { @@ -165,82 +114,61 @@ static const device_config_t monster_fdc_config[] = { // clang-format off #if 0 { - .name = "sec_enabled", - .description = "Enable Secondary Controller", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "sec_enabled", + .description = "Enable Secondary Controller", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "sec_irq", - .description = "Secondary Controller IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 6, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "IRQ 2", - .value = 2 - }, - { - .description = "IRQ 3", - .value = 3 - }, - { - .description = "IRQ 4", - .value = 4 - }, - { - .description = "IRQ 5", - .value = 5 - }, - { - .description = "IRQ 6", - .value = 6 - }, - { - .description = "IRQ 7", - .value = 7 - }, - { .description = "" } - } + .name = "sec_irq", + .description = "Secondary Controller IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 6, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "IRQ 2", .value = 2 }, + { .description = "IRQ 3", .value = 3 }, + { .description = "IRQ 4", .value = 4 }, + { .description = "IRQ 5", .value = 5 }, + { .description = "IRQ 6", .value = 6 }, + { .description = "IRQ 7", .value = 7 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "sec_dma", - .description = "Secondary Controller DMA", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 2, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "DMA 1", - .value = 1 - }, - { - .description = "DMA 2", - .value = 2 - }, - { - .description = "DMA 3", - .value = 3 - }, - { .description = "" } - } + .name = "sec_dma", + .description = "Secondary Controller DMA", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "DMA 1", .value = 1 }, + { .description = "DMA 2", .value = 2 }, + { .description = "DMA 3", .value = 3 }, + { .description = "" } + }, + .bios = { { 0 } } }, #endif { - .name = "bios_addr", - .description = "BIOS Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0xc8000, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "bios_addr", + .description = "BIOS Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0xc8000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Disabled", .value = 0 }, { .description = "C000H", .value = 0xc0000 }, { .description = "C800H", .value = 0xc8000 }, @@ -249,30 +177,36 @@ static const device_config_t monster_fdc_config[] = { { .description = "E000H", .value = 0xe0000 }, { .description = "E800H", .value = 0xe8000 }, { .description = "" } - } + }, + .bios = { { 0 } } }, #if 0 { - .name = "bios_size", - .description = "BIOS Size:", - .type = CONFIG_HEX20, - .default_string = "32", - .default_int = 0xc8000, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "bios_size", + .description = "BIOS size", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 32, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "8K", .value = 8 }, { .description = "32K", .value = 32 }, { .description = "" } - } + }, + .bios = { { 0 } } }, #endif { - .name = "rom_writes_enabled", - .description = "Enable BIOS extension ROM Writes", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "rom_writes_enabled", + .description = "Enable BIOS extension ROM Writes", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -286,7 +220,7 @@ const device_t fdc_monster_device = { .init = monster_fdc_init, .close = monster_fdc_close, .reset = NULL, - { .available = monster_fdc_available }, + .available = monster_fdc_available, .speed_changed = NULL, .force_redraw = NULL, .config = monster_fdc_config diff --git a/src/floppy/fdc_pii15xb.c b/src/floppy/fdc_pii15xb.c index 013d6d39b..4e6a8367c 100644 --- a/src/floppy/fdc_pii15xb.c +++ b/src/floppy/fdc_pii15xb.c @@ -97,8 +97,7 @@ pii_init(const device_t *info) { pii_t *dev; - dev = (pii_t *) malloc(sizeof(pii_t)); - memset(dev, 0, sizeof(pii_t)); + dev = (pii_t *) calloc(1, sizeof(pii_t)); if (BIOS_ADDR != 0) rom_init(&dev->bios_rom, DTK_VARIANT, BIOS_ADDR, 0x2000, 0x1ffff, 0, MEM_MAPPING_EXTERNAL); @@ -123,20 +122,21 @@ pii_158_available(void) static const device_config_t pii_config[] = { // clang-format off { - .name = "bios_addr", - .description = "BIOS Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0xce000, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "bios_addr", + .description = "BIOS Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0xce000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Disabled", .value = 0 }, { .description = "CA00H", .value = 0xca000 }, { .description = "CC00H", .value = 0xcc000 }, { .description = "CE00H", .value = 0xce000 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -150,7 +150,7 @@ const device_t fdc_pii151b_device = { .init = pii_init, .close = pii_close, .reset = NULL, - { .available = pii_151b_available }, + .available = pii_151b_available, .speed_changed = NULL, .force_redraw = NULL, .config = pii_config @@ -164,7 +164,7 @@ const device_t fdc_pii158b_device = { .init = pii_init, .close = pii_close, .reset = NULL, - { .available = pii_158_available }, + .available = pii_158_available, .speed_changed = NULL, .force_redraw = NULL, .config = pii_config diff --git a/src/floppy/fdd.c b/src/floppy/fdd.c index a381f67f1..31811069f 100644 --- a/src/floppy/fdd.c +++ b/src/floppy/fdd.c @@ -100,10 +100,10 @@ d86f_handler_t d86f_handler[FDD_NUM]; static const struct { - char *ext; - void (*load)(int drive, char *fn); - void (*close)(int drive); - int size; + const char *ext; + void (*load)(int drive, char *fn); + void (*close)(int drive); + int size; } loaders[] = { { "001", img_load, img_close, -1}, { "002", img_load, img_close, -1}, @@ -294,7 +294,7 @@ fdd_type_invert_densel(int type) int ret; if (drive_types[type].flags & FLAG_PS2) - ret = (!!strstr(machine_getname(), "PS/1")) || (!!strstr(machine_getname(), "PS/2")); + ret = (!!strstr(machine_getname(), "PS/1")) || (!!strstr(machine_getname(), "PS/2")) || (!!strstr(machine_getname(), "PS/55")); else ret = drive_types[type].flags & FLAG_INVERT_DENSEL; @@ -467,7 +467,7 @@ fdd_load(int drive, char *fn) int c = 0; int size; const char *p; - FILE * fp; + FILE *fp; fdd_log("FDD: loading drive %d with '%s'\n", drive, fn); diff --git a/src/floppy/fdd_86f.c b/src/floppy/fdd_86f.c index 0e8a6590a..24fde57b1 100644 --- a/src/floppy/fdd_86f.c +++ b/src/floppy/fdd_86f.c @@ -28,6 +28,7 @@ #define HAVE_STDARG_H #include <86box/86box.h> #include <86box/timer.h> +#include <86box/crc.h> #include <86box/dma.h> #include <86box/nvr.h> #include <86box/random.h> @@ -223,6 +224,7 @@ typedef struct d86f_t { uint8_t *filebuf; uint8_t *outbuf; sector_t *last_side_sector[2]; + uint16_t crc_table[256]; } d86f_t; static const uint8_t encoded_fm[64] = { @@ -247,7 +249,6 @@ 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 */ @@ -276,28 +277,6 @@ d86f_log(const char *fmt, ...) # define d86f_log(fmt, ...) #endif -static void -setup_crc(uint16_t poly) -{ - int c = 256; - int bc; - uint16_t temp; - - while (c--) { - temp = c << 8; - bc = 8; - - while (bc--) { - if (temp & 0x8000) - temp = (temp << 1) ^ poly; - else - temp <<= 1; - - CRCTable[c] = temp; - } - } -} - void d86f_destroy_linked_lists(int drive, int side) { @@ -1237,16 +1216,10 @@ decodefm(UNUSED(int drive), uint16_t dat) return temp; } -void -fdd_calccrc(uint8_t byte, crc_t *crc_var) -{ - crc_var->word = (crc_var->word << 8) ^ CRCTable[(crc_var->word >> 8) ^ byte]; -} - static void d86f_calccrc(d86f_t *dev, uint8_t byte) { - fdd_calccrc(byte, &(dev->calc_crc)); + crc16_calc(dev->crc_table, byte, &(dev->calc_crc)); } int @@ -1274,7 +1247,9 @@ d86f_word_is_aligned(int drive, int side, uint32_t base_pos) /* State 1: Find sector ID */ void -d86f_find_address_mark_fm(int drive, int side, find_t *find, uint16_t req_am, uint16_t other_am, uint16_t wrong_am, uint16_t ignore_other_am) +d86f_find_address_mark_fm(int drive, int side, find_t *find, uint16_t req_am, + uint16_t other_am, uint16_t wrong_am, + uint16_t ignore_other_am) { d86f_t *dev = d86f[drive]; @@ -1282,7 +1257,8 @@ d86f_find_address_mark_fm(int drive, int side, find_t *find, uint16_t req_am, ui if (dev->last_word[side] == req_am) { dev->calc_crc.word = 0xFFFF; - fdd_calccrc(decodefm(drive, dev->last_word[side]), &(dev->calc_crc)); + crc16_calc(dev->crc_table, decodefm(drive, dev->last_word[side]), + &(dev->calc_crc)); find->sync_marks = find->bits_obtained = find->bytes_obtained = 0; find->sync_pos = 0xFFFFFFFF; @@ -1302,7 +1278,8 @@ d86f_find_address_mark_fm(int drive, int side, find_t *find, uint16_t req_am, ui if ((ignore_other_am & 2) && (dev->last_word[side] == other_am)) { dev->calc_crc.word = 0xFFFF; - fdd_calccrc(decodefm(drive, dev->last_word[side]), &(dev->calc_crc)); + crc16_calc(dev->crc_table, decodefm(drive, dev->last_word[side]), + &(dev->calc_crc)); find->sync_marks = find->bits_obtained = find->bytes_obtained = 0; find->sync_pos = 0xFFFFFFFF; if (ignore_other_am & 1) { @@ -1378,7 +1355,8 @@ d86f_find_address_mark_mfm(int drive, int side, find_t *find, uint16_t req_am, u if ((dev->last_word[side] == req_am) && (find->sync_marks >= 3)) { if (d86f_word_is_aligned(drive, side, find->sync_pos)) { dev->calc_crc.word = 0xCDB4; - fdd_calccrc(decodefm(drive, dev->last_word[side]), &(dev->calc_crc)); + crc16_calc(dev->crc_table, decodefm(drive, dev->last_word[side]), + &(dev->calc_crc)); find->sync_marks = find->bits_obtained = find->bytes_obtained = 0; find->sync_pos = 0xFFFFFFFF; dev->preceding_bit[side] = dev->last_word[side] & 1; @@ -1390,7 +1368,8 @@ d86f_find_address_mark_mfm(int drive, int side, find_t *find, uint16_t req_am, u if ((ignore_other_am & 2) && (dev->last_word[side] == other_am) && (find->sync_marks >= 3)) { if (d86f_word_is_aligned(drive, side, find->sync_pos)) { dev->calc_crc.word = 0xCDB4; - fdd_calccrc(decodefm(drive, dev->last_word[side]), &(dev->calc_crc)); + crc16_calc(dev->crc_table, decodefm(drive, dev->last_word[side]), + &(dev->calc_crc)); find->sync_marks = find->bits_obtained = find->bytes_obtained = 0; find->sync_pos = 0xFFFFFFFF; if (ignore_other_am & 1) { @@ -1464,8 +1443,11 @@ d86f_read_sector_id(int drive, int side, int match) if (dev->id_find.bytes_obtained < 4) { dev->last_sector.byte_array[dev->id_find.bytes_obtained] = decodefm(drive, dev->last_word[side]); - fdd_calccrc(dev->last_sector.byte_array[dev->id_find.bytes_obtained], &(dev->calc_crc)); - } else if ((dev->id_find.bytes_obtained >= 4) && (dev->id_find.bytes_obtained < 6)) { + crc16_calc(dev->crc_table, + dev->last_sector.byte_array[dev->id_find.bytes_obtained], + &(dev->calc_crc)); + } else if ((dev->id_find.bytes_obtained >= 4) && + (dev->id_find.bytes_obtained < 6)) { dev->track_crc.bytes[(dev->id_find.bytes_obtained & 1) ^ 1] = decodefm(drive, dev->last_word[side]); } @@ -1643,7 +1625,7 @@ d86f_read_sector_data(int drive, int side) } } } - fdd_calccrc(data, &(dev->calc_crc)); + crc16_calc(dev->crc_table, data, &(dev->calc_crc)); } else if (dev->data_find.bytes_obtained < crc_pos) dev->track_crc.bytes[(dev->data_find.bytes_obtained - sector_len) ^ 1] = decodefm(drive, dev->last_word[side]); @@ -1730,11 +1712,12 @@ d86f_write_sector_data(int drive, int side, int mfm, uint16_t am) if (dev->data_find.bytes_obtained < sector_len) { /* This is a data byte, so CRC it. */ - if (!dev->data_find.bytes_obtained) { - fdd_calccrc(decodefm(drive, am), &(dev->calc_crc)); - } else { - fdd_calccrc(dev->current_byte[side], &(dev->calc_crc)); - } + if (!dev->data_find.bytes_obtained) + crc16_calc(dev->crc_table, decodefm(drive, am), + &(dev->calc_crc)); + else + crc16_calc(dev->crc_table, dev->current_byte[side], + &(dev->calc_crc)); } } } else { @@ -2431,16 +2414,28 @@ d86f_turbo_poll(int drive, int side) case STATE_0C_READ_DATA: case STATE_11_SCAN_DATA: case STATE_16_VERIFY_DATA: - d86f_turbo_read(drive, side); + if (fdc_is_dma(d86f_fdc)) + for (int i = 0; i < (128 << dev->last_sector.id.n); i++) + d86f_turbo_read(drive, side); + else + d86f_turbo_read(drive, side); break; case STATE_05_WRITE_DATA: case STATE_09_WRITE_DATA: - d86f_turbo_write(drive, side); + if (fdc_is_dma(d86f_fdc)) + for (int i = 0; i < (128 << dev->last_sector.id.n); i++) + d86f_turbo_write(drive, side); + else + d86f_turbo_write(drive, side); break; case STATE_0D_FORMAT_TRACK: - d86f_turbo_format(drive, side, (side && (d86f_get_sides(drive) != 2))); + if (fdc_is_dma(d86f_fdc)) + while (dev->state == STATE_0D_FORMAT_TRACK) + d86f_turbo_format(drive, side, (side && (d86f_get_sides(drive) != 2))); + else + d86f_turbo_format(drive, side, (side && (d86f_get_sides(drive) != 2))); return; case STATE_IDLE: @@ -2731,8 +2726,7 @@ d86f_prepare_sector(int drive, int side, int prev_pos, uint8_t *id_buf, uint8_t uint16_t datadam_mfm = 0x4A55; if (fdd_get_turbo(drive) && (dev->version == 0x0063)) { - s = (sector_t *) malloc(sizeof(sector_t)); - memset(s, 0, sizeof(sector_t)); + s = (sector_t *) calloc(1, sizeof(sector_t)); s->c = id_buf[0]; s->h = id_buf[1]; s->r = id_buf[2]; @@ -3470,6 +3464,7 @@ d86f_common_handlers(int drive) drives[drive].poll = d86f_poll; drives[drive].format = d86f_proxy_format; drives[drive].stop = d86f_stop; + drives[drive].hole = d86f_hole; } int @@ -3862,8 +3857,6 @@ d86f_load(int drive, char *fn) void d86f_init(void) { - setup_crc(0x1021); - for (uint8_t i = 0; i < FDD_NUM; i++) d86f[i] = NULL; } @@ -3921,13 +3914,14 @@ d86f_setup(int drive) d86f_t *dev; /* Allocate a drive structure. */ - dev = (d86f_t *) malloc(sizeof(d86f_t)); - memset(dev, 0x00, sizeof(d86f_t)); + dev = (d86f_t *) calloc(1, sizeof(d86f_t)); dev->state = STATE_IDLE; dev->last_side_sector[0] = NULL; dev->last_side_sector[1] = NULL; + crc16_setup(dev->crc_table, 0x1021); + /* Set the drive as active. */ d86f[drive] = dev; } diff --git a/src/floppy/fdd_fdi.c b/src/floppy/fdd_fdi.c index f14bf2cd4..97b6441a0 100644 --- a/src/floppy/fdd_fdi.c +++ b/src/floppy/fdd_fdi.c @@ -316,15 +316,13 @@ fdi_load(int drive, char *fn) writeprot[drive] = fwriteprot[drive] = 1; /* Allocate a drive block. */ - dev = (fdi_t *) malloc(sizeof(fdi_t)); + dev = (fdi_t *) calloc(1, sizeof(fdi_t)); if (dev == NULL) { memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); return; } - memset(dev, 0x00, sizeof(fdi_t)); - d86f_unregister(drive); dev->fp = plat_fopen(fn, "rb"); diff --git a/src/floppy/fdd_imd.c b/src/floppy/fdd_imd.c index 0839c2900..7994530ed 100644 --- a/src/floppy/fdd_imd.c +++ b/src/floppy/fdd_imd.c @@ -635,8 +635,7 @@ imd_load(int drive, char *fn) writeprot[drive] = 0; /* Allocate a drive block. */ - dev = (imd_t *) malloc(sizeof(imd_t)); - memset(dev, 0x00, sizeof(imd_t)); + dev = (imd_t *) calloc(1, sizeof(imd_t)); dev->fp = plat_fopen(fn, "rb+"); if (dev->fp == NULL) { diff --git a/src/floppy/fdd_img.c b/src/floppy/fdd_img.c index 69a753ef5..30e0212cd 100644 --- a/src/floppy/fdd_img.c +++ b/src/floppy/fdd_img.c @@ -681,8 +681,7 @@ img_load(int drive, char *fn) writeprot[drive] = 0; /* Allocate a drive block. */ - dev = (img_t *) malloc(sizeof(img_t)); - memset(dev, 0x00, sizeof(img_t)); + dev = (img_t *) calloc(1, sizeof(img_t)); dev->fp = plat_fopen(fn, "rb+"); if (dev->fp == NULL) { diff --git a/src/floppy/fdd_mfm.c b/src/floppy/fdd_mfm.c index a332d25c9..87da4e08b 100644 --- a/src/floppy/fdd_mfm.c +++ b/src/floppy/fdd_mfm.c @@ -396,8 +396,7 @@ mfm_load(int drive, char *fn) writeprot[drive] = fwriteprot[drive] = 1; /* Allocate a drive block. */ - dev = (mfm_t *) malloc(sizeof(mfm_t)); - memset(dev, 0x00, sizeof(mfm_t)); + dev = (mfm_t *) calloc(1, sizeof(mfm_t)); dev->fp = plat_fopen(fn, "rb"); if (dev->fp == NULL) { diff --git a/src/floppy/fdd_pcjs.c b/src/floppy/fdd_pcjs.c index b7b3cc69d..6f69042b0 100644 --- a/src/floppy/fdd_pcjs.c +++ b/src/floppy/fdd_pcjs.c @@ -20,7 +20,11 @@ #include #include #include +#ifndef _MSC_VER #include +#else +#include +#endif #define HAVE_STDARG_H #include <86box/86box.h> #include <86box/timer.h> @@ -465,7 +469,7 @@ track_flags(int drive) } static void -set_sector(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n) +set_sector(int drive, int side, uint8_t c, UNUSED(uint8_t h), uint8_t r, UNUSED(uint8_t n)) { pcjs_t *dev = images[drive]; @@ -613,8 +617,7 @@ pcjs_load(int drive, char *fn) d86f_unregister(drive); /* Allocate a drive block */ - dev = (pcjs_t *) malloc(sizeof(pcjs_t)); - memset(dev, 0x00, sizeof(pcjs_t)); + dev = (pcjs_t *) calloc(1, sizeof(pcjs_t)); /* Open the image file, read-only */ dev->fp = plat_fopen(fn, "rb"); diff --git a/src/floppy/fdd_td0.c b/src/floppy/fdd_td0.c index 0bf4b1c71..f5882158b 100644 --- a/src/floppy/fdd_td0.c +++ b/src/floppy/fdd_td0.c @@ -1214,8 +1214,7 @@ td0_load(int drive, char *fn) writeprot[drive] = 1; - dev = (td0_t *) malloc(sizeof(td0_t)); - memset(dev, 0x00, sizeof(td0_t)); + dev = (td0_t *) calloc(1, sizeof(td0_t)); td0[drive] = dev; dev->fp = plat_fopen(fn, "rb"); diff --git a/src/game/gameport.c b/src/game/gameport.c index 8d2a684fc..8ae1c7d25 100644 --- a/src/game/gameport.c +++ b/src/game/gameport.c @@ -8,8 +8,6 @@ * * Implementation of a generic Game Port. * - * - * * Authors: Miran Grca, * Sarah Walker, * RichardG, @@ -18,7 +16,7 @@ * Copyright 2016-2022 Miran Grca. * Copyright 2008-2018 Sarah Walker. * Copyright 2021 RichardG. - * Copyright 2021-2024 Jasmine Iwanek. + * Copyright 2021-2025 Jasmine Iwanek. */ #include #include @@ -35,6 +33,12 @@ #include <86box/gameport.h> #include <86box/plat_unused.h> +device_t game_ports[GAMEPORT_MAX]; + +typedef struct { + const device_t *device; +} GAMEPORT; + typedef struct g_axis_t { pc_timer_t timer; int axis_nr; @@ -48,6 +52,11 @@ typedef struct _gameport_ { struct _gameport_ *next; } gameport_t; +typedef struct _tmacm_ { + struct gameport_t *port1; + struct gameport_t *port2; +} tmacm_t; + typedef struct _joystick_instance_ { uint8_t state; g_axis_t axis[4]; @@ -79,21 +88,23 @@ static const joystick_if_t joystick_none = { static const struct { const joystick_if_t *joystick; } joysticks[] = { - { &joystick_none }, - { &joystick_2axis_2button }, - { &joystick_2axis_4button }, - { &joystick_2axis_6button }, - { &joystick_2axis_8button }, - { &joystick_3axis_2button }, - { &joystick_3axis_4button }, - { &joystick_4axis_4button }, - { &joystick_ch_flightstick_pro }, - { &joystick_sw_pad }, - { &joystick_tm_fcs }, - { NULL } + { &joystick_none }, + { &joystick_2axis_2button }, + { &joystick_2axis_4button }, + { &joystick_2axis_6button }, + { &joystick_2axis_8button }, + { &joystick_3axis_2button }, + { &joystick_3axis_4button }, + { &joystick_4axis_4button }, + { &joystick_ch_flightstick_pro }, + { &joystick_ch_flightstick_pro_ch_pedals }, + { &joystick_sw_pad }, + { &joystick_tm_fcs }, + { &joystick_tm_fcs_rcs }, + { NULL } }; -static joystick_instance_t *joystick_instance = NULL; +static joystick_instance_t *joystick_instance[GAMEPORT_MAX] = { NULL, NULL }; static uint8_t gameport_pnp_rom[] = { 0x09, 0xf8, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, /* BOX0002, dummy checksum (filled in by isapnp_add_card) */ @@ -275,10 +286,10 @@ gameport_update_joystick_type(void) gameport_add(standalone_gameport_type); /* Reset the joystick interface. */ - if (joystick_instance) { - joystick_instance->intf->close(joystick_instance->dat); - joystick_instance->intf = joysticks[joystick_type].joystick; - joystick_instance->dat = joystick_instance->intf->init(); + if (joystick_instance[0]) { + joystick_instance[0]->intf->close(joystick_instance[0]->dat); + joystick_instance[0]->intf = joysticks[joystick_type].joystick; + joystick_instance[0]->dat = joystick_instance[0]->intf->init(); } } @@ -357,36 +368,32 @@ gameport_add(const device_t *gameport_type) static void * gameport_init(const device_t *info) { - gameport_t *dev = NULL; - - dev = malloc(sizeof(gameport_t)); - memset(dev, 0x00, sizeof(gameport_t)); + gameport_t *dev = calloc(1, sizeof(gameport_t)); /* Allocate global instance. */ - if (!joystick_instance && joystick_type) { - joystick_instance = malloc(sizeof(joystick_instance_t)); - memset(joystick_instance, 0x00, sizeof(joystick_instance_t)); + if (!joystick_instance[0] && joystick_type) { + joystick_instance[0] = calloc(1, sizeof(joystick_instance_t)); - joystick_instance->axis[0].joystick = joystick_instance; - joystick_instance->axis[1].joystick = joystick_instance; - joystick_instance->axis[2].joystick = joystick_instance; - joystick_instance->axis[3].joystick = joystick_instance; + joystick_instance[0]->axis[0].joystick = joystick_instance[0]; + joystick_instance[0]->axis[1].joystick = joystick_instance[0]; + joystick_instance[0]->axis[2].joystick = joystick_instance[0]; + joystick_instance[0]->axis[3].joystick = joystick_instance[0]; - joystick_instance->axis[0].axis_nr = 0; - joystick_instance->axis[1].axis_nr = 1; - joystick_instance->axis[2].axis_nr = 2; - joystick_instance->axis[3].axis_nr = 3; + joystick_instance[0]->axis[0].axis_nr = 0; + joystick_instance[0]->axis[1].axis_nr = 1; + joystick_instance[0]->axis[2].axis_nr = 2; + joystick_instance[0]->axis[3].axis_nr = 3; - timer_add(&joystick_instance->axis[0].timer, timer_over, &joystick_instance->axis[0], 0); - timer_add(&joystick_instance->axis[1].timer, timer_over, &joystick_instance->axis[1], 0); - timer_add(&joystick_instance->axis[2].timer, timer_over, &joystick_instance->axis[2], 0); - timer_add(&joystick_instance->axis[3].timer, timer_over, &joystick_instance->axis[3], 0); + timer_add(&joystick_instance[0]->axis[0].timer, timer_over, &joystick_instance[0]->axis[0], 0); + timer_add(&joystick_instance[0]->axis[1].timer, timer_over, &joystick_instance[0]->axis[1], 0); + timer_add(&joystick_instance[0]->axis[2].timer, timer_over, &joystick_instance[0]->axis[2], 0); + timer_add(&joystick_instance[0]->axis[3].timer, timer_over, &joystick_instance[0]->axis[3], 0); - joystick_instance->intf = joysticks[joystick_type].joystick; - joystick_instance->dat = joystick_instance->intf->init(); + joystick_instance[0]->intf = joysticks[joystick_type].joystick; + joystick_instance[0]->dat = joystick_instance[0]->intf->init(); } - dev->joystick = joystick_instance; + dev->joystick = joystick_instance[0]; /* Map game port to the default address. Not applicable on PnP-only ports. */ dev->len = (info->local >> 16) & 0xff; @@ -402,25 +409,24 @@ gameport_init(const device_t *info) static void * tmacm_init(UNUSED(const device_t *info)) { - uint16_t port = 0x0000; - gameport_t *dev = NULL; + uint16_t port = 0x0000; + tmacm_t *dev = NULL; - dev = malloc(sizeof(gameport_t)); - memset(dev, 0x00, sizeof(gameport_t)); + dev = calloc(1, sizeof(tmacm_t)); port = (uint16_t) device_get_config_hex16("port1_addr"); switch (port) { case 0x201: - dev = gameport_add(&gameport_201_device); + dev->port1 = gameport_add(&gameport_201_device); break; case 0x203: - dev = gameport_add(&gameport_203_device); + dev->port1 = gameport_add(&gameport_203_device); break; case 0x205: - dev = gameport_add(&gameport_205_device); + dev->port1 = gameport_add(&gameport_205_device); break; case 0x207: - dev = gameport_add(&gameport_207_device); + dev->port1 = gameport_add(&gameport_207_device); break; default: break; @@ -429,16 +435,16 @@ tmacm_init(UNUSED(const device_t *info)) port = (uint16_t) device_get_config_hex16("port2_addr"); switch (port) { case 0x209: - dev = gameport_add(&gameport_209_device); + dev->port2 = gameport_add(&gameport_209_device); break; case 0x20b: - dev = gameport_add(&gameport_20b_device); + dev->port2 = gameport_add(&gameport_20b_device); break; case 0x20d: - dev = gameport_add(&gameport_20d_device); + dev->port2 = gameport_add(&gameport_20d_device); break; case 0x20f: - dev = gameport_add(&gameport_20f_device); + dev->port2 = gameport_add(&gameport_20f_device); break; default: break; @@ -456,11 +462,11 @@ gameport_close(void *priv) gameport_remap(dev, 0); /* Free the global instance here, if it wasn't already freed. */ - if (joystick_instance) { - joystick_instance->intf->close(joystick_instance->dat); + if (joystick_instance[0]) { + joystick_instance[0]->intf->close(joystick_instance[0]->dat); - free(joystick_instance); - joystick_instance = NULL; + free(joystick_instance[0]); + joystick_instance[0] = NULL; } free(dev); @@ -474,7 +480,7 @@ const device_t gameport_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -488,7 +494,7 @@ const device_t gameport_201_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -502,7 +508,7 @@ const device_t gameport_203_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -516,7 +522,7 @@ const device_t gameport_205_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -530,7 +536,7 @@ const device_t gameport_207_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -544,7 +550,7 @@ const device_t gameport_208_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -558,7 +564,7 @@ const device_t gameport_209_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -572,7 +578,7 @@ const device_t gameport_20b_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -586,7 +592,7 @@ const device_t gameport_20d_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -600,7 +606,7 @@ const device_t gameport_20f_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -609,40 +615,42 @@ const device_t gameport_20f_device = { static const device_config_t tmacm_config[] = { // clang-format off { - .name = "port1_addr", - .description = "Port 1 Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x0201, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "port1_addr", + .description = "Port 1 Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x0201, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "201h", .value = 0x0201 }, { .description = "203h", .value = 0x0203 }, { .description = "205h", .value = 0x0205 }, { .description = "207h", .value = 0x0207 }, { .description = "Disabled", .value = 0x0000 }, - { "" } - } + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "port2_addr", - .description = "Port 2 Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x0209, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "port2_addr", + .description = "Port 2 Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x0209, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "209h", .value = 0x0209 }, { .description = "20Bh", .value = 0x020B }, { .description = "20Dh", .value = 0x020D }, { .description = "20Fh", .value = 0x020F }, { .description = "Disabled", .value = 0x0000 }, - { "" } - } + { .description = "" } + }, + .bios = { { 0 } } }, - { "", "", -1 } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -654,7 +662,7 @@ const device_t gameport_tm_acm_device = { .init = tmacm_init, .close = NULL, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = tmacm_config @@ -668,7 +676,7 @@ const device_t gameport_pnp_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -682,7 +690,7 @@ const device_t gameport_pnp_1io_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -696,7 +704,7 @@ const device_t gameport_pnp_6io_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -710,7 +718,7 @@ const device_t gameport_sio_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -724,8 +732,68 @@ const device_t gameport_sio_1io_device = { .init = gameport_init, .close = gameport_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL }; + +static const GAMEPORT gameports[] = { + { &device_none }, + { &device_internal }, + { &gameport_device }, + { &gameport_208_device }, + { &gameport_pnp_device }, + { &gameport_tm_acm_device }, + { NULL } + // clang-format on +}; + +/* UI */ +int +gameport_available(int port) +{ + if (gameports[port].device) + return (device_available(gameports[port].device)); + + return 1; +} + +/* UI */ +const device_t * +gameports_getdevice(int port) +{ + return (gameports[port].device); +} + +/* UI */ +int +gameport_has_config(int port) +{ + if (!gameports[port].device) + return 0; + + return (device_has_config(gameports[port].device) ? 1 : 0); +} + +/* UI */ +const char * +gameport_get_internal_name(int port) +{ + return device_get_internal_name(gameports[port].device); +} + +/* UI */ +int +gameport_get_from_internal_name(const char *str) +{ + int c = 0; + + while (gameports[c].device != NULL) { + if (!strcmp(gameports[c].device->internal_name, str)) + return c; + c++; + } + + return 0; +} diff --git a/src/game/joystick_ch_flightstick_pro.c b/src/game/joystick_ch_flightstick_pro.c index 8ca51d531..5b240f3f4 100644 --- a/src/game/joystick_ch_flightstick_pro.c +++ b/src/game/joystick_ch_flightstick_pro.c @@ -62,23 +62,23 @@ ch_flightstick_pro_read(UNUSED(void *priv)) { uint8_t ret = 0xf0; - if (JOYSTICK_PRESENT(0)) { - if (joystick_state[0].button[0]) + if (JOYSTICK_PRESENT(0, 0)) { + if (joystick_state[0][0].button[0]) ret &= ~0x10; - if (joystick_state[0].button[1]) + if (joystick_state[0][0].button[1]) ret &= ~0x20; - if (joystick_state[0].button[2]) + if (joystick_state[0][0].button[2]) ret &= ~0x40; - if (joystick_state[0].button[3]) + if (joystick_state[0][0].button[3]) ret &= ~0x80; - if (joystick_state[0].pov[0] != -1) { - if (joystick_state[0].pov[0] > 315 || joystick_state[0].pov[0] < 45) + if (joystick_state[0][0].pov[0] != -1) { + if (joystick_state[0][0].pov[0] > 315 || joystick_state[0][0].pov[0] < 45) ret &= ~0xf0; - else if (joystick_state[0].pov[0] >= 45 && joystick_state[0].pov[0] < 135) + else if (joystick_state[0][0].pov[0] >= 45 && joystick_state[0][0].pov[0] < 135) ret &= ~0xb0; - else if (joystick_state[0].pov[0] >= 135 && joystick_state[0].pov[0] < 225) + else if (joystick_state[0][0].pov[0] >= 135 && joystick_state[0][0].pov[0] < 225) ret &= ~0x70; - else if (joystick_state[0].pov[0] >= 225 && joystick_state[0].pov[0] < 315) + else if (joystick_state[0][0].pov[0] >= 225 && joystick_state[0][0].pov[0] < 315) ret &= ~0x30; } } @@ -95,18 +95,38 @@ ch_flightstick_pro_write(UNUSED(void *priv)) static int ch_flightstick_pro_read_axis(UNUSED(void *priv), int axis) { - if (!JOYSTICK_PRESENT(0)) + if (!JOYSTICK_PRESENT(0, 0)) return AXIS_NOT_PRESENT; switch (axis) { case 0: - return joystick_state[0].axis[0]; + return joystick_state[0][0].axis[0]; case 1: - return joystick_state[0].axis[1]; + return joystick_state[0][0].axis[1]; case 2: return 0; case 3: - return joystick_state[0].axis[2]; + return joystick_state[0][0].axis[2]; + default: + return 0; + } +} + +static int +ch_flightstick_pro_ch_pedals_read_axis(UNUSED(void *priv), int axis) +{ + if (!JOYSTICK_PRESENT(0, 0)) + return AXIS_NOT_PRESENT; + + switch (axis) { + case 0: + return joystick_state[0][0].axis[0]; + case 1: + return joystick_state[0][0].axis[1]; + case 2: + return joystick_state[0][0].axis[3]; + case 3: + return joystick_state[0][0].axis[2]; default: return 0; } @@ -135,3 +155,21 @@ const joystick_if_t joystick_ch_flightstick_pro = { .button_names = { "Button 1", "Button 2", "Button 3", "Button 4" }, .pov_names = { "POV" } }; + +const joystick_if_t joystick_ch_flightstick_pro_ch_pedals = { + .name = "CH Flightstick Pro + CH Pedals", + .internal_name = "ch_flightstick_pro_ch_pedals", + .init = ch_flightstick_pro_init, + .close = ch_flightstick_pro_close, + .read = ch_flightstick_pro_read, + .write = ch_flightstick_pro_write, + .read_axis = ch_flightstick_pro_ch_pedals_read_axis, + .a0_over = ch_flightstick_pro_a0_over, + .axis_count = 4, + .button_count = 4, + .pov_count = 1, + .max_joysticks = 1, + .axis_names = { "X axis", "Y axis", "Throttle", "Rudder" }, + .button_names = { "Button 1", "Button 2", "Button 3", "Button 4" }, + .pov_names = { "POV" } +}; diff --git a/src/game/joystick_standard.c b/src/game/joystick_standard.c index 1d1568738..5f200cb98 100644 --- a/src/game/joystick_standard.c +++ b/src/game/joystick_standard.c @@ -62,16 +62,17 @@ joystick_standard_read(UNUSED(void *priv)) { uint8_t ret = 0xf0; - if (JOYSTICK_PRESENT(0)) { - if (joystick_state[0].button[0]) + if (JOYSTICK_PRESENT(0, 0)) { + if (joystick_state[0][0].button[0]) ret &= ~0x10; - if (joystick_state[0].button[1]) + if (joystick_state[0][0].button[1]) ret &= ~0x20; } - if (JOYSTICK_PRESENT(1)) { - if (joystick_state[1].button[0]) + + if (JOYSTICK_PRESENT(0, 1)) { + if (joystick_state[0][1].button[0]) ret &= ~0x40; - if (joystick_state[1].button[1]) + if (joystick_state[0][1].button[1]) ret &= ~0x80; } @@ -83,14 +84,14 @@ joystick_standard_read_4button(UNUSED(void *priv)) { uint8_t ret = 0xf0; - if (JOYSTICK_PRESENT(0)) { - if (joystick_state[0].button[0]) + if (JOYSTICK_PRESENT(0, 0)) { + if (joystick_state[0][0].button[0]) ret &= ~0x10; - if (joystick_state[0].button[1]) + if (joystick_state[0][0].button[1]) ret &= ~0x20; - if (joystick_state[0].button[2]) + if (joystick_state[0][0].button[2]) ret &= ~0x40; - if (joystick_state[0].button[3]) + if (joystick_state[0][0].button[3]) ret &= ~0x80; } @@ -108,21 +109,21 @@ joystick_standard_read_axis(UNUSED(void *priv), int axis) { switch (axis) { case 0: - if (!JOYSTICK_PRESENT(0)) + if (!JOYSTICK_PRESENT(0, 0)) return AXIS_NOT_PRESENT; - return joystick_state[0].axis[0]; + return joystick_state[0][0].axis[0]; case 1: - if (!JOYSTICK_PRESENT(0)) + if (!JOYSTICK_PRESENT(0, 0)) return AXIS_NOT_PRESENT; - return joystick_state[0].axis[1]; + return joystick_state[0][0].axis[1]; case 2: - if (!JOYSTICK_PRESENT(1)) + if (!JOYSTICK_PRESENT(0, 1)) return AXIS_NOT_PRESENT; - return joystick_state[1].axis[0]; + return joystick_state[0][1].axis[0]; case 3: - if (!JOYSTICK_PRESENT(1)) + if (!JOYSTICK_PRESENT(0, 1)) return AXIS_NOT_PRESENT; - return joystick_state[1].axis[1]; + return joystick_state[0][1].axis[1]; default: return 0; } @@ -131,18 +132,16 @@ joystick_standard_read_axis(UNUSED(void *priv), int axis) static int joystick_standard_read_axis_4button(UNUSED(void *priv), int axis) { - if (!JOYSTICK_PRESENT(0)) + if (!JOYSTICK_PRESENT(0, 0)) return AXIS_NOT_PRESENT; switch (axis) { case 0: - return joystick_state[0].axis[0]; + return joystick_state[0][0].axis[0]; case 1: - return joystick_state[0].axis[1]; + return joystick_state[0][0].axis[1]; case 2: - return 0; case 3: - return 0; default: return 0; } @@ -151,18 +150,17 @@ joystick_standard_read_axis_4button(UNUSED(void *priv), int axis) static int joystick_standard_read_axis_3axis(UNUSED(void *priv), int axis) { - if (!JOYSTICK_PRESENT(0)) + if (!JOYSTICK_PRESENT(0, 0)) return AXIS_NOT_PRESENT; switch (axis) { case 0: - return joystick_state[0].axis[0]; + return joystick_state[0][0].axis[0]; case 1: - return joystick_state[0].axis[1]; + return joystick_state[0][0].axis[1]; case 2: - return joystick_state[0].axis[2]; + return joystick_state[0][0].axis[2]; case 3: - return 0; default: return 0; } @@ -171,18 +169,18 @@ joystick_standard_read_axis_3axis(UNUSED(void *priv), int axis) static int joystick_standard_read_axis_4axis(UNUSED(void *priv), int axis) { - if (!JOYSTICK_PRESENT(0)) + if (!JOYSTICK_PRESENT(0, 0)) return AXIS_NOT_PRESENT; switch (axis) { case 0: - return joystick_state[0].axis[0]; + return joystick_state[0][0].axis[0]; case 1: - return joystick_state[0].axis[1]; + return joystick_state[0][0].axis[1]; case 2: - return joystick_state[0].axis[2]; + return joystick_state[0][0].axis[2]; case 3: - return joystick_state[0].axis[3]; + return joystick_state[0][0].axis[3]; default: return 0; } @@ -191,18 +189,18 @@ joystick_standard_read_axis_4axis(UNUSED(void *priv), int axis) static int joystick_standard_read_axis_6button(UNUSED(void *priv), int axis) { - if (!JOYSTICK_PRESENT(0)) + if (!JOYSTICK_PRESENT(0, 0)) return AXIS_NOT_PRESENT; switch (axis) { case 0: - return joystick_state[0].axis[0]; + return joystick_state[0][0].axis[0]; case 1: - return joystick_state[0].axis[1]; + return joystick_state[0][0].axis[1]; case 2: - return joystick_state[0].button[4] ? -32767 : 32768; + return joystick_state[0][0].button[4] ? -32767 : 32768; case 3: - return joystick_state[0].button[5] ? -32767 : 32768; + return joystick_state[0][0].button[5] ? -32767 : 32768; default: return 0; } @@ -210,24 +208,24 @@ joystick_standard_read_axis_6button(UNUSED(void *priv), int axis) static int joystick_standard_read_axis_8button(UNUSED(void *priv), int axis) { - if (!JOYSTICK_PRESENT(0)) + if (!JOYSTICK_PRESENT(0, 0)) return AXIS_NOT_PRESENT; switch (axis) { case 0: - return joystick_state[0].axis[0]; + return joystick_state[0][0].axis[0]; case 1: - return joystick_state[0].axis[1]; + return joystick_state[0][0].axis[1]; case 2: - if (joystick_state[0].button[4]) + if (joystick_state[0][0].button[4]) return -32767; - if (joystick_state[0].button[6]) + if (joystick_state[0][0].button[6]) return 32768; return 0; case 3: - if (joystick_state[0].button[5]) + if (joystick_state[0][0].button[5]) return -32767; - if (joystick_state[0].button[7]) + if (joystick_state[0][0].button[7]) return 32768; return 0; default: diff --git a/src/game/joystick_sw_pad.c b/src/game/joystick_sw_pad.c index cab008d0a..bfdc0e025 100644 --- a/src/game/joystick_sw_pad.c +++ b/src/game/joystick_sw_pad.c @@ -119,8 +119,7 @@ sw_parity(uint16_t data) static void * sw_init(void) { - sw_data *sw = (sw_data *) malloc(sizeof(sw_data)); - memset(sw, 0, sizeof(sw_data)); + sw_data *sw = (sw_data *) calloc(1, sizeof(sw_data)); timer_add(&sw->poll_timer, sw_timer_over, sw, 0); timer_add(&sw->trigger_timer, sw_trigger_timer_over, sw, 0); @@ -142,7 +141,7 @@ sw_read(void *priv) sw_data *sw = (sw_data *) priv; uint8_t temp = 0; - if (!JOYSTICK_PRESENT(0)) + if (!JOYSTICK_PRESENT(0, 0)) return 0xff; if (timer_is_enabled(&sw->poll_timer)) { @@ -168,7 +167,7 @@ sw_write(void *priv) sw_data *sw = (sw_data *) priv; int64_t time_since_last = timer_get_remaining_us(&sw->trigger_timer); - if (!JOYSTICK_PRESENT(0)) + if (!JOYSTICK_PRESENT(0, 0)) return; if (!sw->poll_left) { @@ -191,24 +190,24 @@ sw_write(void *priv) sw->poll_data = 1; } - for (uint8_t c = 0; c < 4; c++) { + for (uint8_t js = 0; js < 4; js++) { uint16_t data = 0x3fff; - if (!JOYSTICK_PRESENT(c)) + if (!JOYSTICK_PRESENT(0, js)) break; - if (joystick_state[c].axis[1] < -16383) + if (joystick_state[0][js].axis[1] < -16383) data &= ~1; - if (joystick_state[c].axis[1] > 16383) + if (joystick_state[0][js].axis[1] > 16383) data &= ~2; - if (joystick_state[c].axis[0] > 16383) + if (joystick_state[0][js].axis[0] > 16383) data &= ~4; - if (joystick_state[c].axis[0] < -16383) + if (joystick_state[0][js].axis[0] < -16383) data &= ~8; - for (uint8_t b = 0; b < 10; b++) { - if (joystick_state[c].button[b]) - data &= ~(1 << (b + 4)); + for (uint8_t button_nr = 0; button_nr < 10; button_nr++) { + if (joystick_state[0][js].button[button_nr]) + data &= ~(1 << (button_nr + 4)); } if (sw_parity(data)) @@ -216,10 +215,10 @@ sw_write(void *priv) if (sw->poll_mode) { sw->poll_left += 5; - sw->poll_data |= (data << (c * 15 + 3)); + sw->poll_data |= (data << (js * 15 + 3)); } else { sw->poll_left += 15; - sw->poll_data |= (data << (c * 15 + 1)); + sw->poll_data |= (data << (js * 15 + 1)); } } } @@ -231,7 +230,7 @@ sw_write(void *priv) static int sw_read_axis(UNUSED(void *priv), UNUSED(int axis)) { - if (!JOYSTICK_PRESENT(0)) + if (!JOYSTICK_PRESENT(0, 0)) return AXIS_NOT_PRESENT; return 0; /*No analogue support on Sidewinder game pad*/ diff --git a/src/game/joystick_tm_fcs.c b/src/game/joystick_tm_fcs.c index f5c1e64e6..52d77d8fb 100644 --- a/src/game/joystick_tm_fcs.c +++ b/src/game/joystick_tm_fcs.c @@ -62,14 +62,14 @@ tm_fcs_read(UNUSED(void *priv)) { uint8_t ret = 0xf0; - if (JOYSTICK_PRESENT(0)) { - if (joystick_state[0].button[0]) + if (JOYSTICK_PRESENT(0, 0)) { + if (joystick_state[0][0].button[0]) ret &= ~0x10; - if (joystick_state[0].button[1]) + if (joystick_state[0][0].button[1]) ret &= ~0x20; - if (joystick_state[0].button[2]) + if (joystick_state[0][0].button[2]) ret &= ~0x40; - if (joystick_state[0].button[3]) + if (joystick_state[0][0].button[3]) ret &= ~0x80; } @@ -85,26 +85,56 @@ tm_fcs_write(UNUSED(void *priv)) static int tm_fcs_read_axis(UNUSED(void *priv), int axis) { - if (!JOYSTICK_PRESENT(0)) + if (!JOYSTICK_PRESENT(0, 0)) return AXIS_NOT_PRESENT; switch (axis) { case 0: - return joystick_state[0].axis[0]; + return joystick_state[0][0].axis[0]; case 1: - return joystick_state[0].axis[1]; + return joystick_state[0][0].axis[1]; case 2: return 0; case 3: - if (joystick_state[0].pov[0] == -1) + if (joystick_state[0][0].pov[0] == -1) return 32767; - if (joystick_state[0].pov[0] > 315 || joystick_state[0].pov[0] < 45) + if (joystick_state[0][0].pov[0] > 315 || joystick_state[0][0].pov[0] < 45) return -32768; - if (joystick_state[0].pov[0] >= 45 && joystick_state[0].pov[0] < 135) + if (joystick_state[0][0].pov[0] >= 45 && joystick_state[0][0].pov[0] < 135) return -16384; - if (joystick_state[0].pov[0] >= 135 && joystick_state[0].pov[0] < 225) + if (joystick_state[0][0].pov[0] >= 135 && joystick_state[0][0].pov[0] < 225) return 0; - if (joystick_state[0].pov[0] >= 225 && joystick_state[0].pov[0] < 315) + if (joystick_state[0][0].pov[0] >= 225 && joystick_state[0][0].pov[0] < 315) + return 16384; + return 0; + default: + return 0; + } +} + +static int +tm_fcs_rcs_read_axis(UNUSED(void *priv), int axis) +{ + if (!JOYSTICK_PRESENT(0, 0)) + return AXIS_NOT_PRESENT; + + switch (axis) { + case 0: + return joystick_state[0][0].axis[0]; + case 1: + return joystick_state[0][0].axis[1]; + case 2: + return joystick_state[0][0].axis[2]; + case 3: + if (joystick_state[0][0].pov[0] == -1) + return 32767; + if (joystick_state[0][0].pov[0] > 315 || joystick_state[0][0].pov[0] < 45) + return -32768; + if (joystick_state[0][0].pov[0] >= 45 && joystick_state[0][0].pov[0] < 135) + return -16384; + if (joystick_state[0][0].pov[0] >= 135 && joystick_state[0][0].pov[0] < 225) + return 0; + if (joystick_state[0][0].pov[0] >= 225 && joystick_state[0][0].pov[0] < 315) return 16384; return 0; default: @@ -135,3 +165,21 @@ const joystick_if_t joystick_tm_fcs = { .button_names = { "Button 1", "Button 2", "Button 3", "Button 4" }, .pov_names = { "POV" } }; + +const joystick_if_t joystick_tm_fcs_rcs = { + .name = "Thrustmaster FCS + Rudder Control System", + .internal_name = "thrustmaster_fcs_rcs", + .init = tm_fcs_init, + .close = tm_fcs_close, + .read = tm_fcs_read, + .write = tm_fcs_write, + .read_axis = tm_fcs_rcs_read_axis, + .a0_over = tm_fcs_a0_over, + .axis_count = 3, + .button_count = 4, + .pov_count = 1, + .max_joysticks = 1, + .axis_names = { "X axis", "Y axis", "Rudder" }, + .button_names = { "Button 1", "Button 2", "Button 3", "Button 4" }, + .pov_names = { "POV" } +}; diff --git a/src/include/86box/86box.h b/src/include/86box/86box.h index ffa670b7e..e572d670b 100644 --- a/src/include/86box/86box.h +++ b/src/include/86box/86box.h @@ -8,21 +8,26 @@ * * Main include file for the application. * - * - * * Authors: Miran Grca, * Fred N. van Kempen, + * Jasmine Iwanek, * * Copyright 2016-2020 Miran Grca. * Copyright 2017-2020 Fred N. van Kempen. * Copyright 2021 Laci bá' + * Copyright 2021-2025 Jasmine Iwanek. */ #ifndef EMU_86BOX_H #define EMU_86BOX_H +#if defined(__NetBSD__) || defined(__OpenBSD__) +/* Doesn't compile on NetBSD/OpenBSD without this include */ +#include +#endif + /* Configuration values. */ #define GFXCARD_MAX 2 -#define SERIAL_MAX 7 +#define SERIAL_MAX 8 #define PARALLEL_MAX 4 #define SCREEN_RES_X 640 #define SCREEN_RES_Y 480 @@ -33,14 +38,14 @@ #define SCREENSHOT_PATH "screenshots" /* Recently used images */ -#define MAX_PREV_IMAGES 4 +#define MAX_PREV_IMAGES 10 #define MAX_IMAGE_PATH_LEN 2048 /* Max UUID Length */ #define MAX_UUID_LEN 64 -/* Default language 0xFFFF = from system, 0x409 = en-US */ -#define DEFAULT_LANGUAGE 0x0409 +/* Default language code */ +#define DEFAULT_LANGUAGE "system" #define POSTCARDS_NUM 4 #define POSTCARD_MASK (POSTCARDS_NUM - 1) @@ -79,8 +84,6 @@ extern "C" { #endif /* Global variables. */ -extern uint32_t lang_sys; /* (-) system language code */ - extern int dump_on_exit; /* (O) dump regs on exit*/ extern int start_in_fullscreen; /* (O) start in fullscreen */ #ifdef _WIN32 @@ -107,18 +110,17 @@ 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 inhibit_multimedia_keys; /* (C) Inhibit multimedia keys on Windows. */ 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 lang_id; /* (C) language id */ 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 */ 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 */ @@ -126,17 +128,19 @@ extern int video_filter_method; /* (C) video */ extern int video_vsync; /* (C) video */ extern int video_framerate; /* (C) video */ extern int gfxcard[GFXCARD_MAX]; /* (C) graphics/video card */ -extern char video_shader[512]; /* (C) video */ extern int bugger_enabled; /* (C) enable ISAbugger */ extern int novell_keycard_enabled; /* (C) enable Novell NetWare 2.x key card emulation. */ extern int postcard_enabled; /* (C) enable POST card */ extern int unittester_enabled; /* (C) enable unit tester device */ +extern int gameport_type[]; /* (C) enable gameports */ extern int isamem_type[]; /* (C) enable ISA mem cards */ +extern int isarom_type[]; /* (C) enable ISA ROM 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_standalone_enabled; /* (C) video option */ extern int xga_standalone_enabled; /* (C) video option */ +extern int da2_standalone_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 */ @@ -156,6 +160,7 @@ extern int other_scsi_present; /* SCSI controllers from non-SCSI ca extern int hard_reset_pending; extern int fixed_size_x; extern int fixed_size_y; +extern int sound_muted; /* (C) Is sound muted? */ extern int do_auto_pause; /* (C) Auto-pause the emulator on focus loss */ extern int auto_paused; extern double mouse_sensitivity; /* (C) Mouse sensitivity scale */ @@ -167,32 +172,30 @@ extern int pit_mode; /* (C) force setting PIT mode */ extern int fm_driver; /* (C) select FM sound driver */ extern int hook_enabled; /* (C) Keyboard hook is enabled */ -/* Keyboard variables for future key combination redefinition. */ -extern uint16_t key_prefix_1_1; -extern uint16_t key_prefix_1_2; -extern uint16_t key_prefix_2_1; -extern uint16_t key_prefix_2_2; -extern uint16_t key_uncapture_1; -extern uint16_t key_uncapture_2; - extern char exe_path[2048]; /* path (dir) of executable */ extern char usr_path[1024]; /* path (dir) of user data */ extern char cfg_path[1024]; /* full path of config file */ extern int open_dir_usr_path; /* default file open dialog directory of usr_path */ extern char uuid[MAX_UUID_LEN]; /* UUID or machine identifier */ +extern char vmm_path[1024]; /* VM Manager path to scan (temporary) */ +extern int vmm_enabled; #ifndef USE_NEW_DYNAREC extern FILE *stdlog; /* file to log output to */ #endif extern int config_changed; /* config has changed */ +extern __thread int is_cpu_thread; /* Is this the CPU thread? */ + /* Function prototypes. */ #ifdef HAVE_STDARG_H -extern void pclog_ex(const char *fmt, va_list); -extern void fatal_ex(const char *fmt, va_list); +extern void pclog_ex(const char *fmt, va_list ap); +extern void fatal_ex(const char *fmt, va_list ap); +extern void warning_ex(const char *fmt, va_list ap); #endif extern void pclog_toggle_suppr(void); extern void pclog(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); extern void fatal(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); +extern void warning(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); @@ -235,6 +238,17 @@ extern int framecountx; extern volatile int cpu_thread_run; extern uint8_t postcard_codes[POSTCARDS_NUM]; +// Accelerator key structure, defines, helper functions +struct accelKey { + char name[64]; + char desc[64]; + char seq[64]; +}; +#define NUM_ACCELS 8 +extern struct accelKey acc_keys[NUM_ACCELS]; +extern struct accelKey def_acc_keys[NUM_ACCELS]; +extern int FindAccelerator(const char *name); + #ifdef __cplusplus } #endif diff --git a/src/include/86box/access_bus.h b/src/include/86box/access_bus.h new file mode 100644 index 000000000..333a1d4a5 --- /dev/null +++ b/src/include/86box/access_bus.h @@ -0,0 +1,37 @@ +/* + * 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 ACPI emulation. + * + * + * + * Authors: Miran Grca, + * + * Copyright 2020-2025 Miran Grca. + */ +#ifndef ACCESS_BUS_H +#define ACCESS_BUS_H + +#define AB_RST 0x80 + +typedef struct access_bus_t { + uint8_t control; + uint8_t status; + uint8_t own_addr; + uint8_t data; + uint8_t clock; + uint8_t enable; + uint16_t base; +} access_bus_t; + +extern const device_t access_bus_device; + +/* Functions */ +extern void access_bus_handler(access_bus_t *dev, uint8_t enable, uint16_t base); + +#endif /*ACCESS_BUS_H*/ diff --git a/src/include/86box/bswap.h b/src/include/86box/bswap.h index f7d3a3d0e..61a6a46a2 100644 --- a/src/include/86box/bswap.h +++ b/src/include/86box/bswap.h @@ -35,13 +35,12 @@ * USA. */ -#ifndef __NetBSD__ - #ifndef BSWAP_H #define BSWAP_H #include +#ifndef __NetBSD__ #define bswap_16(x) \ ((uint16_t)((((x) & 0x00ffu) << 8) | \ (((x) & 0xff00u) >> 8))) @@ -91,6 +90,7 @@ bswap64(uint64_t x) return bswap_16(x); #endif } +#endif static __inline void bswap16s(uint16_t *s) @@ -133,12 +133,12 @@ bswap64s(uint64_t *s) return endian##_bswap(v, size); \ } \ \ - static __inline void endian##size##_to_cpus(type *p) \ + static __inline void endian##size##_to_cpus(UNUSED(type *p)) \ { \ endian##_bswaps(p, size) \ } \ \ - static __inline void cpu_to_##endian##size##s(type *p) \ + static __inline void cpu_to_##endian##size##s(UNUSED(type *p)) \ { \ endian##_bswaps(p, size) \ } \ @@ -241,5 +241,3 @@ cpu_to_be32wu(uint32_t *p, uint32_t v) #undef be_bswaps #endif /*BSWAP_H*/ - -#endif diff --git a/src/include/86box/cartridge.h b/src/include/86box/cartridge.h index 2ea7ec734..2b0662703 100644 --- a/src/include/86box/cartridge.h +++ b/src/include/86box/cartridge.h @@ -21,7 +21,7 @@ extern "C" { #endif -#define CART_IMAGE_HISTORY 4 +#define CART_IMAGE_HISTORY 10 extern char cart_fns[2][512]; extern char *cart_image_history[2][CART_IMAGE_HISTORY]; diff --git a/src/include/86box/cassette.h b/src/include/86box/cassette.h index bb0899e24..168d82099 100644 --- a/src/include/86box/cassette.h +++ b/src/include/86box/cassette.h @@ -153,7 +153,7 @@ void pc_cas_print_state(const pc_cassette_t *cas); void pc_cas_clock(pc_cassette_t *cas, unsigned long cnt); void pc_cas_advance(pc_cassette_t *cas); -#define CASSETTE_IMAGE_HISTORY 4 +#define CASSETTE_IMAGE_HISTORY 10 extern pc_cassette_t *cassette; diff --git a/src/include/86box/cdrom.h b/src/include/86box/cdrom.h index efb45ecfb..a962a8635 100644 --- a/src/include/86box/cdrom.h +++ b/src/include/86box/cdrom.h @@ -15,40 +15,76 @@ #ifndef EMU_CDROM_H #define EMU_CDROM_H +#ifndef EMU_VERSION_H +#include <86box/version.h> +#endif + #define CDROM_NUM 8 #define CD_STATUS_EMPTY 0 #define CD_STATUS_DATA_ONLY 1 -#define CD_STATUS_PAUSED 2 -#define CD_STATUS_PLAYING 3 -#define CD_STATUS_STOPPED 4 -#define CD_STATUS_PLAYING_COMPLETED 5 +#define CD_STATUS_DVD 2 +#define CD_STATUS_PAUSED 4 +#define CD_STATUS_PLAYING 5 +#define CD_STATUS_STOPPED 6 +#define CD_STATUS_PLAYING_COMPLETED 7 +#define CD_STATUS_HOLD 8 +#define CD_STATUS_HAS_AUDIO 0xc +#define CD_STATUS_MASK 0xf /* Medium changed flag. */ #define CD_STATUS_TRANSITION 0x40 #define CD_STATUS_MEDIUM_CHANGED 0x80 -#define CD_TRACK_UNK_DATA 0x10 +#define CD_TRACK_UNK_DATA 0x04 +#define CD_TRACK_NORMAL 0x00 #define CD_TRACK_AUDIO 0x08 +#define CD_TRACK_CDI 0x10 +#define CD_TRACK_XA 0x20 +#define CD_TRACK_MODE_MASK 0x30 #define CD_TRACK_MODE2 0x04 - -#define CD_READ_DATA 0 -#define CD_READ_AUDIO 1 -#define CD_READ_RAW 2 +#define CD_TRACK_MODE2_MASK 0x07 #define CD_TOC_NORMAL 0 #define CD_TOC_SESSION 1 #define CD_TOC_RAW 2 -#define CD_IMAGE_HISTORY 4 - -#define BUF_SIZE 32768 +#define CD_IMAGE_HISTORY 10 #define CDROM_IMAGE 200 /* This is so that if/when this is changed to something else, changing this one define will be enough. */ -#define CDROM_EMPTY !dev->host_drive +#define CDROM_EMPTY !dev->host_drive + +#define DVD_LAYER_0_SECTORS 0x00210558ULL + +#define RAW_SECTOR_SIZE 2352 +#define COOKED_SECTOR_SIZE 2048 + +#define CD_BUF_SIZE (16 * RAW_SECTOR_SIZE) + +#define DATA_TRACK 0x14 +#define AUDIO_TRACK 0x10 + +#define CD_FPS 75 + +#define FRAMES_TO_MSF(f, M, S, F) \ + { \ + uint64_t value = f; \ + *(F) = (value % CD_FPS) & 0xff; \ + value /= CD_FPS; \ + *(S) = (value % 60) & 0xff; \ + value /= 60; \ + *(M) = value & 0xff; \ + } +#define MSF_TO_FRAMES(M, S, F) ((M) *60 * CD_FPS + (S) *CD_FPS + (F)) + +typedef struct SMSF { + uint16_t min; + uint8_t sec; + uint8_t fr; +} TMSF; #ifdef __cplusplus extern "C" { @@ -62,121 +98,125 @@ enum { CDROM_BUS_USB = 8 }; -enum -{ - CDROM_TYPE_86BOX_100, - CDROM_TYPE_AZT_CDA46802I_115, - CDROM_TYPE_BTC_BCD36XH_U10, - CDROM_TYPE_GOLDSTAR_CRD_8160B_314, - CDROM_TYPE_HITACHI_CDR_8130_0020, - CDROM_TYPE_KENWOOD_UCR_421_208E, - CDROM_TYPE_MATSHITA_587_7S13, - CDROM_TYPE_MATSHITA_588_LS15, - CDROM_TYPE_MATSHITA_571_10e, - CDROM_TYPE_MATSHITA_572_10j, - CDROM_TYPE_MITSUMI_FX4820T_D02A, - CDROM_TYPE_NEC_260_100, - CDROM_TYPE_NEC_260_101, - CDROM_TYPE_NEC_273_420, - CDROM_TYPE_NEC_280_105, - CDROM_TYPE_NEC_280_308, - CDROM_TYPE_PHILIPS_PCA403CD_U31P, - CDROM_TYPE_SONY_CDU76_10i, - CDROM_TYPE_SONY_CDU311_30h, - CDROM_TYPE_TOSHIBA_5302TA_0305, - CDROM_TYPE_TOSHIBA_5702B_TA70, - CDROM_TYPE_CHINON_CDS431_H42, - CDROM_TYPE_CHINON_CDX435_M62, - CDROM_TYPE_DEC_RRD45_0436, - CDROM_TYPE_MATSHITA_501_10b, - CDROM_TYPE_NEC_25_10a, - CDROM_TYPE_NEC_38_103, - CDROM_TYPE_NEC_75_103, - CDROM_TYPE_NEC_77_106, - CDROM_TYPE_NEC_211_100, - CDROM_TYPE_NEC_464_105, - CDROM_TYPE_ShinaKen_DM3x1S_104, - CDROM_TYPE_SONY_CDU541_10i, - CDROM_TYPE_SONY_CDU561_18k, - CDROM_TYPE_SONY_CDU76S_100, - CDROM_TYPE_PHILIPS_CDD2600_107, - CDROM_TYPE_PIONEER_DRM604X_2403, - CDROM_TYPE_PLEXTOR_PX32TS_103, - CDROM_TYPE_TEAC_CD50_100, - CDROM_TYPE_TEAC_R55S_10R, - CDROM_TYPE_TEXEL_DM3024_100, - CDROM_TYPE_TEXEL_DM3028_106, - CDROM_TYPE_TOSHIBA_XM_3433, - CDROM_TYPE_TOSHIBA_XM3201B_3232, - CDROM_TYPE_TOSHIBA_XM3301TA_0272, - CDROM_TYPE_TOSHIBA_XM5701TA_3136, - CDROM_TYPE_TOSHIBA_SDM1401_1008, - CDROM_TYPES_NUM -}; - -#define KNOWN_CDROM_DRIVE_TYPES CDROM_TYPES_NUM #define BUS_TYPE_IDE CDROM_BUS_ATAPI #define BUS_TYPE_SCSI CDROM_BUS_SCSI #define BUS_TYPE_BOTH -2 #define BUS_TYPE_NONE -1 -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; +#define CDV EMU_VERSION_EX + +static const struct cdrom_drive_types_s { + const char *vendor; + const char *model; + const char *revision; + const char *internal_name; + const int bus_type; + /* SCSI standard for SCSI (or both) devices, early for IDE. */ + const int scsi_std; + const int speed; + const int inquiry_len; + const int caddy; + const int transfer_max[4]; } cdrom_drive_types[] = { - { "86BOX", "CD-ROM", "1.00", "86BOX CD-ROM 1.00", "86BOX_CD-ROM_1.00", BUS_TYPE_BOTH }, - { "AZT", "CDA46802I", "1.15", "AZT CDA46802I 1.15", "AZT_CDA46802I_1.15", BUS_TYPE_IDE }, - { "BTC", "CD-ROM BCD36XH", "U1.0", "BTC CD-ROM BCD36XH U1.0", "BTC_CD-ROM_BCD36XH_U1.0", BUS_TYPE_IDE }, - { "GOLDSTAR", "CRD-8160B", "3.14", "GOLDSTAR CRD-8160B 3.14", "GOLDSTAR_CRD-8160B_3.14", BUS_TYPE_IDE }, - { "HITACHI", "CDR-8130", "0020", "HITACHI CDR-8130 0020", "HITACHI_CDR-8130_0020", BUS_TYPE_IDE }, - { "KENWOOD", "CD-ROM UCR-421", "208E", "KENWOOD CD-ROM UCR-421 208E", "KENWOOD_CD-ROM_UCR-421_208E", BUS_TYPE_IDE }, - { "MATSHITA", "CD-ROM CR-587", "7S13", "MATSHITA CD-ROM CR-587 7S13", "MATSHITA_CD-ROM_CR-587_7S13", BUS_TYPE_IDE }, - { "MATSHITA", "CD-ROM CR-588", "LS15", "MATSHITA CD-ROM CR-588 LS15", "MATSHITA_CD-ROM_CR-588_LS15", BUS_TYPE_IDE }, - { "MATSHITA", "CR-571", "1.0e", "MATSHITA CR-571 1.0e", "MATSHITA_CR-571_1.0e", BUS_TYPE_IDE }, - { "MATSHITA", "CR-572", "1.0j", "MATSHITA CR-572 1.0j", "MATSHITA_CR-572_1.0j", BUS_TYPE_IDE }, - { "MITSUMI", "CRMC-FX4820T", "D02A", "MITSUMI CRMC-FX4820T D02A", "MITSUMI_CRMC-FX4820T_D02A", BUS_TYPE_IDE }, - { "NEC", "CD-ROM DRIVE:260", "1.00", "NEC CD-ROM DRIVE:260 1.00", "NEC_CD-ROM_DRIVE260_1.00", BUS_TYPE_IDE }, - { "NEC", "CD-ROM DRIVE:260", "1.01", "NEC CD-ROM DRIVE:260 1.01", "NEC_CD-ROM_DRIVE260_1.01", BUS_TYPE_IDE }, - { "NEC", "CD-ROM DRIVE:273", "4.20", "NEC CD-ROM DRIVE:273 4.20", "NEC_CD-ROM_DRIVE273_4.20", BUS_TYPE_IDE }, - { "NEC", "CD-ROM DRIVE:280", "1.05", "NEC CD-ROM DRIVE:280 1.05", "NEC_CD-ROM_DRIVE280_1.05", BUS_TYPE_IDE }, - { "NEC", "CD-ROM DRIVE:280", "3.08", "NEC CD-ROM DRIVE:280 3.08", "NEC_CD-ROM_DRIVE280_3.08", BUS_TYPE_IDE }, - { "PHILIPS", "CD-ROM PCA403CD", "U31P", "PHILIPS CD-ROM PCA403CD U31P", "PHILIPS_CD-ROM_PCA403CD_U31P", BUS_TYPE_IDE }, - { "SONY", "CD-ROM CDU76", "1.0i", "SONY CD-ROM CDU76 1.0i", "SONY_CD-ROM_CDU76_1.0i", BUS_TYPE_IDE }, - { "SONY", "CD-ROM CDU311", "3.0h", "SONY CD-ROM CDU311 3.0h", "SONY_CD-ROM_CDU311_3.0h", BUS_TYPE_IDE }, - { "TOSHIBA", "CD-ROM XM-5302TA", "0305", "TOSHIBA CD-ROM XM-5302TA 0305", "TOSHIBA_CD-ROM_XM-5302TA_0305", BUS_TYPE_IDE }, - { "TOSHIBA", "CD-ROM XM-5702B", "TA70", "TOSHIBA CD-ROM XM-5702B TA70", "TOSHIBA_CD-ROM_XM-5702B_TA70", BUS_TYPE_IDE }, - { "CHINON", "CD-ROM CDS-431", "H42 ", "[SCSI-1] CHINON CD-ROM CDS-431 H42", "CHINON_CD-ROM_CDS-431_H42", BUS_TYPE_SCSI }, - { "CHINON", "CD-ROM CDX-435", "M62 ", "[SCSI-1] CHINON CD-ROM CDX-435 M62", "CHINON_CD-ROM_CDX-435_M62", BUS_TYPE_SCSI }, - { "DEC", "RRD45 (C) DEC", "0436", "[SCSI-1] DEC RRD45 0436", "DEC_RRD45_0436", BUS_TYPE_SCSI }, - { "MATSHITA", "CD-ROM CR-501", "1.0b", "[SCSI-1] MATSHITA CD-ROM CR-501 1.0b", "MATSHITA_CD-ROM_CR-501_1.0b", BUS_TYPE_SCSI }, - { "NEC", "CD-ROM DRIVE:25", "1.0a", "[SCSI-1] NEC CD-ROM DRIVE:25 1.0a", "NEC_CD-ROM_DRIVE25_1.0a", BUS_TYPE_SCSI }, - { "NEC", "CD-ROM DRIVE:38", "1.00", "[SCSI-2] NEC CD-ROM DRIVE:38 1.00", "NEC_CD-ROM_DRIVE38_1.00", BUS_TYPE_SCSI }, - { "NEC", "CD-ROM DRIVE:75", "1.03", "[SCSI-1] NEC CD-ROM DRIVE:75 1.03", "NEC_CD-ROM_DRIVE75_1.03", BUS_TYPE_SCSI }, - { "NEC", "CD-ROM DRIVE:77", "1.06", "[SCSI-1] NEC CD-ROM DRIVE:77 1.06", "NEC_CD-ROM_DRIVE77_1.06", BUS_TYPE_SCSI }, - { "NEC", "CD-ROM DRIVE:211", "1.00", "[SCSI-2] NEC CD-ROM DRIVE:211 1.00", "NEC_CD-ROM_DRIVE211_1.00", BUS_TYPE_SCSI }, - { "NEC", "CD-ROM DRIVE:464", "1.05", "[SCSI-2] NEC CD-ROM DRIVE:464 1.05", "NEC_CD-ROM_DRIVE464_1.05", BUS_TYPE_SCSI }, - { "ShinaKen", "CD-ROM DM-3x1S", "1.04", "[SCSI-1] ShinaKen CD-ROM DM-3x1S 1.04", "ShinaKen_CD-ROM_DM-3x1S_1.04", BUS_TYPE_SCSI }, - { "SONY", "CD-ROM CDU-541", "1.0i", "[SCSI-1] SONY CD-ROM CDU-541 1.0i", "SONY_CD-ROM_CDU-541_1.0i", BUS_TYPE_SCSI }, - { "SONY", "CD-ROM CDU-561", "1.8k", "[SCSI-2] SONY CD-ROM CDU-561 1.8k", "SONY_CD-ROM_CDU-561_1.8k", BUS_TYPE_SCSI }, - { "SONY", "CD-ROM CDU-76S", "1.00", "[SCSI-2] SONY CD-ROM CDU-76S 1.00", "SONY_CD-ROM_CDU-76S_1.00", BUS_TYPE_SCSI }, - { "PHILIPS", "CDD2600", "1.07", "[SCSI-2] PHILIPS CDD2600 1.07", "PHILIPS_CDD2600_1.07", BUS_TYPE_SCSI }, - { "PIONEER", "CD-ROM DRM-604X", "2403", "[SCSI-2] PIONEER CD-ROM DRM-604X 2403", "PIONEER_CD-ROM_DRM-604X_2403", BUS_TYPE_SCSI }, - { "PLEXTOR", "CD-ROM PX-32TS", "1.03", "[SCSI-2] PLEXTOR CD-ROM PX-32TS 1.03", "PLEXTOR_CD-ROM_PX-32TS_1.03", BUS_TYPE_SCSI }, - { "TEAC", "CD 50", "1.00", "[SCSI-2] TEAC CD 50 1.00", "TEAC_CD_50_1.00", BUS_TYPE_SCSI }, - { "TEAC", "CD-ROM R55S", "1.0R", "[SCSI-2] TEAC CD-ROM R55S 1.0R", "TEAC_CD-ROM_R55S_1.0R", BUS_TYPE_SCSI }, - { "TEXEL", "CD-ROM DM-3024", "1.00", "[SCSI-1] TEXEL CD-ROM DM-3024 1.00", "TEXEL_CD-ROM_DM-3024_1.00", BUS_TYPE_SCSI }, - { "TEXEL", "CD-ROM DM-3028", "1.06", "[SCSI-2] TEXEL CD-ROM DM-3028 1.06", "TEXEL_CD-ROM_DM-3028_1.06", BUS_TYPE_SCSI }, - { "TOSHIBA", "CD-ROM DRIVE:XM", "3433", "[SCSI-2] TOSHIBA CD-ROM DRIVE:XM 3433", "TOSHIBA_CD-ROM_DRIVEXM_3433", BUS_TYPE_SCSI }, - { "TOSHIBA", "CD-ROM XM-3201B", "3232", "[SCSI-1] TOSHIBA CD-ROM XM-3201B 3232", "TOSHIBA_CD-ROM_XM-3201B_3232", BUS_TYPE_SCSI }, - { "TOSHIBA", "CD-ROM XM-3301TA", "0272", "[SCSI-2] TOSHIBA CD-ROM XM-3301TA 0272", "TOSHIBA_CD-ROM_XM-3301TA_0272", BUS_TYPE_SCSI }, - { "TOSHIBA", "CD-ROM XM-5701TA", "3136", "[SCSI-2] TOSHIBA CD-ROM XM-5701TA 3136", "TOSHIBA_CD-ROM_XM-5701TA_3136", BUS_TYPE_SCSI }, - { "TOSHIBA", "DVD-ROM SD-M1401", "1008", "[SCSI-2] TOSHIBA DVD-ROM SD-M1401 1008", "TOSHIBA_DVD-ROM_SD-M1401_1008", BUS_TYPE_SCSI }, - { "", "", "", "", "", BUS_TYPE_NONE }, + { EMU_NAME, "86B_CD", CDV, "86cd", BUS_TYPE_BOTH, 2, -1, 36, 0, { 4, 2, 2, 5 } }, + /* SCSI-1 / early ATAPI generic - second on purpose so the later variant is the default. */ + { EMU_NAME, "86B_CD", "1.00", "86cd100", BUS_TYPE_BOTH, 1, -1, 36, 1, { 0, -1, -1, -1 } }, + /* No difference from 86BOX CD-ROM, other than name - but enough people have requested such a name to warrant it. */ + { EMU_NAME, "86B_DVD", "4.30", "86dvd", BUS_TYPE_BOTH, 2, -1, 36, 0, { 4, 2, 2, 5 } }, + { "ASUS", "CD-S500/A", "1.41", "asus_500", BUS_TYPE_IDE, 0, 50, 36, 0, { 4, 2, 2, 2 } }, + { "ASUS", "CD-S520/A4", "1.32", "asus_520", BUS_TYPE_IDE, 0, 52, 36, 0, { 4, 2, 2, 2 } }, + { "AZT", "CDA46802I", "1.15", "azt_cda", BUS_TYPE_IDE, 0, 4, 36, 0, { 3, 0, 0, 0 } }, + { "BTC", "CD-ROM BCD36XH", "U1.0", "btc_36xh", BUS_TYPE_IDE, 0, 36, 36, 0, { 4, 2, 2, -1 } }, + { "GOLDSTAR", "CRD-8160B", "3.14", "goldstar", BUS_TYPE_IDE, 0, 16, 36, 0, { 4, 2, 2, -1 } }, + /* TODO: Find an IDENTIFY and/or INQUIRY dump. */ + { "GOLDSTAR", "GCD-R560B", "1.00", "goldstar", BUS_TYPE_IDE, 0, 6, 36, 0, { 4, 2, 2, -1 } }, + { "HITACHI", "CDR-8130", "0020", "hitachi_r8130", BUS_TYPE_IDE, 0, 16, 36, 0, { 4, 2, 2, -1 } }, + { "HITACHI", "GD-7500", "A1 ", "hitachi_7500", BUS_TYPE_IDE, 0, 40, 36, 0, { 4, 2, 2, 2 } }, /* DVD. */ + { "HL-DT-ST", "CD-ROM GCR-8526B", "1.01", "hldtst_8526b", BUS_TYPE_IDE, 0, 52, 36, 0, { 4, 2, 2, 2 } }, + { "HL-DT-ST", "DVDRAM GSA-4160", "A302", "hldtst_4160", BUS_TYPE_IDE, 0, 40, 36, 0, { 4, 2, 2, 2 } }, + { "KENWOOD", "CD-ROM UCR-421", "208E", "kenwood_421", BUS_TYPE_IDE, 0, 72, 36, 0, { 4, 2, 2, 4 } }, + /* + This is a laptop/notebook drive, as is also evident from the name: + CRN = Notebook, CRD = Desktop. + */ + { "LG", "CD-ROM CRN-8245B", "1.30", "lg_8245b", BUS_TYPE_IDE, 0, 24, 36, 0, { 4, 2, 2, -1 } }, + { "LG", "CD-ROM CRD-8322B", "1.06", "lg_8322b", BUS_TYPE_IDE, 0, 32, 36, 0, { 4, 2, 2, -1 } }, + /* Nothing on Google, deduced 48x from the name. */ + { "LITE-ON", "LTN48125S", "1S07", "liteon_48125s", BUS_TYPE_IDE, 0, 48, 36, 0, { 4, 2, 2, 2 } }, + /* Confirmed to be 52x, was the basis for deducing the other one's speed. */ + { "LITE-ON", "LTN526D", "YSR5", "liteon_526d", BUS_TYPE_IDE, 0, 52, 36, 0, { 4, 2, 2, 2 } }, + { "MATSHITA", "CD-ROM CR-583", "1.07", "matshita_583", BUS_TYPE_IDE, 0, 8, 36, 0, { 4, 2, 2, -1 } }, + { "MATSHITA", "CD-ROM CR-585", "Z18P", "matshita_585", BUS_TYPE_IDE, 0, 24, 36, 0, { 4, 2, 2, -1 } }, + { "MATSHITA", "CD-ROM CR-587", "7S13", "matshita_587", BUS_TYPE_IDE, 0, 24, 36, 0, { 4, 2, 2, -1 } }, + { "MATSHITA", "CD-ROM CR-588", "LS15", "matshita_588", BUS_TYPE_IDE, 0, 32, 36, 0, { 4, 2, 2, -1 } }, + { "MATSHITA", "CR-571", "1.0e", "matshita_571", BUS_TYPE_IDE, 0, 2, 36, 0, { 0, -1, -1, -1 } }, + { "MATSHITA", "CR-572", "1.0j", "matshita_572", BUS_TYPE_IDE, 0, 4, 36, 0, { 0, -1, -1, -1 } }, + { "MITSUMI", "CRMC-FX4820T", "D02A", "mitsumi_4820t", BUS_TYPE_IDE, 0, 48, 36, 0, { 4, 2, 2, 2 } }, + /* TODO: Find an IDENTIFY and/or INQUIRY dump. */ + { "MITSUMI", "CRMC-FX810T4", "????", "mitsumi_810t4", BUS_TYPE_IDE, 0, 8, 36, 0, { 4, 2, 2, -1 } }, + { "NEC", "CD-ROM DRIVE:260", "1.00", "nec_260_early", BUS_TYPE_IDE, 1, 2, 36, 1, { 0, -1, -1, -1 } }, + { "NEC", "CD-ROM DRIVE:260", "1.01", "nec_260", BUS_TYPE_IDE, 1, 4, 36, 1, { 0, -1, -1, -1 } }, + { "NEC", "CD-ROM DRIVE:273", "4.20", "nec_273", BUS_TYPE_IDE, 0, 4, 36, 0, { 0, -1, -1, -1 } }, + { "NEC", "CD-ROM DRIVE:280", "1.05", "nec_280_early", BUS_TYPE_IDE, 0, 6, 36, 1, { 4, 2, 2, -1 } }, + { "NEC", "CD-ROM DRIVE:280", "3.08", "nec_280", BUS_TYPE_IDE, 0, 8, 36, 1, { 4, 2, 2, -1 } }, + { "NEC", "CDR-1300A", "1.05", "nec_1300a", BUS_TYPE_IDE, 0, 6, 36, 0, { 4, 2, 2, -1 } }, + { "NEC", "CDR-1900A", "1.00", "nec_1900a", BUS_TYPE_IDE, 0, 32, 36, 0, { 4, 2, 2, -1 } }, + { "PHILIPS", "CD-ROM PCA403CD", "U31P", "philips_403", BUS_TYPE_IDE, 0, 40, 36, 0, { 4, 2, 2, -1 } }, + { "SONY", "CD-ROM CDU76", "1.0i", "sony_76", BUS_TYPE_IDE, 0, 4, 36, 0, { 2, -1, -1, -1 } }, + { "SONY", "CD-ROM CDU311", "3.0h", "sony_311", BUS_TYPE_IDE, 0, 8, 36, 0, { 3, 2, 1, -1 } }, + { "SONY", "CD-ROM CDU5225", "NYS4", "sony_5225", BUS_TYPE_IDE, 0, 52, 36, 0, { 4, 2, 2, 4 } }, + { "TEAC", "CD-516E", "1.0G", "teac_516e", BUS_TYPE_IDE, 0, 16, 36, 0, { 3, 2, 2, -1 } }, + { "TEAC", "CD-524EA", "3.0D", "teac_524ea", BUS_TYPE_IDE, 0, 24, 36, 0, { 3, 2, 2, -1 } }, + { "TEAC", "CD-532E", "2.0A", "teac_532e", BUS_TYPE_IDE, 0, 32, 36, 0, { 3, 2, 2, -1 } }, + { "TOSHIBA", "CD-ROM XM-5302TA", "0305", "toshiba_5302ta", BUS_TYPE_IDE, 0, 4, 96, 0, { 0, -1, -1, -1 } }, + { "TOSHIBA", "CD-ROM XM-5702B", "TA70", "toshiba_5702b", BUS_TYPE_IDE, 0, 12, 96, 0, { 3, 2, 1, -1 } }, + { "TOSHIBA", "CD-ROM XM-6202B", "1512", "toshiba_6202b", BUS_TYPE_IDE, 0, 32, 96, 0, { 4, 2, 2, -1 } }, + { "TOSHIBA", "CD-ROM XM-6402B", "1008", "toshiba_6402b", BUS_TYPE_IDE, 0, 32, 96, 0, { 4, 2, 2, 2 } }, + { "TOSHIBA", "CD-ROM XM-6702B", "1007", "toshiba_6720b", BUS_TYPE_IDE, 0, 48, 96, 0, { 4, 2, 2, 2 } }, + { "TOSHIBA", "DVD-ROM SD-M1802", "1051", "toshiba_m1802", BUS_TYPE_IDE, 0, 48, 96, 0, { 4, 2, 2, 2 } }, + { "CHINON", "CD-ROM CDS-431", "H42 ", "chinon_431", BUS_TYPE_SCSI, 1, 1, 36, 1, { -1, -1, -1, -1 } }, + { "CHINON", "CD-ROM CDX-435", "M62 ", "chinon_435", BUS_TYPE_SCSI, 1, 2, 36, 1, { -1, -1, -1, -1 } }, + { "DEC", "RRD45 (C) DEC", "0436", "dec_45", BUS_TYPE_SCSI, 1, 4, 36, 0, { -1, -1, -1, -1 } }, + { "MATSHITA", "CD-ROM CR-501", "1.0b", "matshita_501", BUS_TYPE_SCSI, 1, 1, 36, 1, { -1, -1, -1, -1 } }, + { "NEC", "CD-ROM DRIVE:25", "1.0a", "nec_25", BUS_TYPE_SCSI, 1, 2, 36, 0, { -1, -1, -1, -1 } }, + { "NEC", "CD-ROM DRIVE:38", "1.00", "nec_38", BUS_TYPE_SCSI, 2, 1, 36, 0, { -1, -1, -1, -1 } }, + /* The speed of the following two is guesswork based on the CDR-74. */ + { "NEC", "CD-ROM DRIVE:75", "1.03", "nec_75", BUS_TYPE_SCSI, 1, 1, 36, 1, { -1, -1, -1, -1 } }, + { "NEC", "CD-ROM DRIVE:77", "1.06", "nec_77", BUS_TYPE_SCSI, 1, 1, 36, 1, { -1, -1, -1, -1 } }, + { "NEC", "CD-ROM DRIVE:211", "1.00", "nec_211", BUS_TYPE_SCSI, 2, 3, 36, 0, { -1, -1, -1, -1 } }, + /* The speed of the following two is guesswork based on the CDR-400. */ + { "NEC", "CD-ROM DRIVE:464", "1.05", "nec_464", BUS_TYPE_SCSI, 2, 3, 36, 0, { -1, -1, -1, -1 } }, + /* The speed of the following two is guesswork based on the name. */ + { "ShinaKen", "CD-ROM DM-3x1S", "1.04", "shinaken_3x1s", BUS_TYPE_SCSI, 1, 3, 36, 0, { -1, -1, -1, -1 } }, + { "SONY", "CD-ROM CDU-541", "1.0i", "sony_541", BUS_TYPE_SCSI, 1, 1, 36, 1, { -1, -1, -1, -1 } }, + { "SONY", "CD-ROM CDU-561", "1.8k", "sony_561", BUS_TYPE_SCSI, 2, 2, 36, 1, { -1, -1, -1, -1 } }, + { "SONY", "CD-ROM CDU-76S", "1.00", "sony_76s", BUS_TYPE_SCSI, 2, 4, 36, 0, { -1, -1, -1, -1 } }, + { "PHILIPS", "CDD2600", "1.07", "philips_2600", BUS_TYPE_SCSI, 2, 6, 36, 0, { -1, -1, -1, -1 } }, + /* NOTE: The real thing is a CD changer drive! */ + { "PIONEER", "CD-ROM DRM-604X", "2403", "pioneer_604x", BUS_TYPE_SCSI, 2, 4, 47, 0, { -1, -1, -1, -1 } }, + { "PLEXTOR", "CD-ROM PX-32TS", "1.03", "plextor_32ts", BUS_TYPE_SCSI, 2, 32, 36, 0, { -1, -1, -1, -1 } }, + /* The speed of the following two is guesswork based on the R55S. */ + { "TEAC", "CD 50", "1.00", "teac_50", BUS_TYPE_SCSI, 2, 4, 36, 1, { -1, -1, -1, -1 } }, + { "TEAC", "CD-ROM R55S", "1.0R", "teac_55s", BUS_TYPE_SCSI, 2, 4, 36, 0, { -1, -1, -1, -1 } }, + /* Texel is Plextor according to Plextor's own EU website. */ + { "TEXEL", "CD-ROM DM-3024", "1.00", "texel_3024", BUS_TYPE_SCSI, 2, 2, 36, 1, { -1, -1, -1, -1 } }, + /* + Unusual 2.23x according to Google, I'm rounding it upwards to 3x. + Assumed caddy based on the DM-3024. + */ + { "TEXEL", "CD-ROM DM-3028", "1.06", "texel_3028", BUS_TYPE_SCSI, 2, 3, 36, 1, { -1, -1, -1, -1 } }, /* Caddy. */ + /* + The characteristics are a complete guesswork because I can't find + this one on Google. + + Also, INQUIRY length is always 96 on these Toshiba drives. + */ + { "TOSHIBA", "CD-ROM DRIVE:XM", "3433", "toshiba_xm", BUS_TYPE_SCSI, 2, 2, 96, 0, { -1, -1, -1, -1 } }, /* Tray. */ + { "TOSHIBA", "CD-ROM XM-3201B", "3232", "toshiba_3201b", BUS_TYPE_SCSI, 1, 1, 96, 1, { -1, -1, -1, -1 } }, /* Caddy. */ + { "TOSHIBA", "CD-ROM XM-3301TA", "0272", "toshiba_3301ta", BUS_TYPE_SCSI, 2, 2, 96, 0, { -1, -1, -1, -1 } }, /* Tray. */ + { "TOSHIBA", "CD-ROM XM-5701TA", "3136", "toshiba_5701a", BUS_TYPE_SCSI, 2, 12, 96, 0, { -1, -1, -1, -1 } }, /* Tray. */ + { "TOSHIBA", "DVD-ROM SD-M1401", "1008", "toshiba_m1401", BUS_TYPE_SCSI, 2, 40, 96, 0, { -1, -1, -1, -1 } }, /* Tray. */ + { "", "", "", "", BUS_TYPE_NONE, 0, -1, 0, 0, { -1, -1, -1, -1 } } }; /* To shut up the GCC compilers. */ @@ -218,133 +258,197 @@ typedef struct raw_track_info_t { /* Define the various CD-ROM drive operations (ops). */ typedef struct cdrom_ops_t { - void (*get_track_info)(struct cdrom *dev, uint32_t track, int end, track_info_t *ti); - void (*get_raw_track_info)(struct cdrom *dev, int *num, raw_track_info_t *rti); - void (*get_subchannel)(struct cdrom *dev, uint32_t lba, subchannel_t *subc); - int (*is_track_pre)(struct cdrom *dev, uint32_t lba); - int (*sector_size)(struct cdrom *dev, uint32_t lba); - int (*read_sector)(struct cdrom *dev, uint8_t *b, uint32_t lba); - int (*track_type)(struct cdrom *dev, uint32_t lba); - int (*ext_medium_changed)(struct cdrom *dev); - void (*exit)(struct cdrom *dev); + int (*get_track_info)(const void *local, const uint32_t track, + const int end, track_info_t *ti); + void (*get_raw_track_info)(const void *local, int *num, + uint8_t *rti); + int (*is_track_pre)(const void *local, const uint32_t sector); + int (*read_sector)(const void *local, uint8_t *buffer, + const uint32_t sector); + uint8_t (*get_track_type)(const void *local, const uint32_t sector); + uint32_t (*get_last_block)(const void *local); + int (*read_dvd_structure)(const void *local, const uint8_t layer, + const uint8_t format, uint8_t *buffer, + uint32_t *info); + int (*is_dvd)(const void *local); + int (*has_audio)(const void *local); + int (*is_empty)(const void *local); + void (*close)(void *local); + void (*load)(const void *local); } cdrom_ops_t; typedef struct cdrom { - uint8_t id; + uint8_t id; union { - 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 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 */ - 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; + 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; - void *priv; + void *priv; - char image_path[1024]; - char prev_image_path[1024]; + char image_path[1024]; + char prev_image_path[1280]; - char *image_history[CD_IMAGE_HISTORY]; + uint32_t sound_on; + uint32_t cdrom_capacity; + uint32_t seek_pos; + uint32_t seek_diff; + uint32_t cd_end; + uint32_t type; + uint32_t sector_size; - uint32_t sound_on; - uint32_t cdrom_capacity; - uint32_t seek_pos; - uint32_t seek_diff; - uint32_t cd_end; - uint32_t type; - uint32_t sector_size; + uint32_t inv_field; + int32_t cached_sector; + int32_t cd_buflen; + int32_t sony_msf; + int32_t real_speed; + int32_t is_early; + int32_t is_nec; + int32_t is_bcd; - int cd_buflen; - int audio_op; - int audio_muted_soft; - int sony_msf; + int32_t cdrom_sector_size; const cdrom_ops_t *ops; - void *local; + char *image_history[CD_IMAGE_HISTORY]; - void (*insert)(void *priv); - void (*close)(void *priv); - uint32_t (*get_volume)(void *p, int channel); - uint32_t (*get_channel)(void *p, int channel); + void *local; + void *log; - int16_t cd_buffer[BUF_SIZE]; + void (*insert)(void *priv); + void (*close)(void *priv); + uint32_t (*get_volume)(void *p, int channel); + uint32_t (*get_channel)(void *p, int channel); - uint8_t subch_buffer[96]; + int16_t cd_buffer[CD_BUF_SIZE]; + + uint8_t subch_buffer[96]; + + /* Needs some extra breathing space in case of overflows. */ + uint8_t raw_buffer[2][4096]; + uint8_t extra_buffer[296]; + + int32_t is_chinon; + int32_t is_pioneer; + int32_t is_plextor; + int32_t is_sony; + int32_t is_toshiba; + + int32_t c2_first; + int32_t cur_buf; + + /* Only used on Windows hosts for disc change notifications. */ + uint8_t host_letter; } cdrom_t; extern cdrom_t cdrom[CDROM_NUM]; -extern char *cdrom_getname(int type); +#define MSFtoLBA(m, s, f) ((((m * 60) + s) * 75) + f) -extern char *cdrom_get_internal_name(int type); -extern int cdrom_get_from_internal_name(char *s); -extern void cdrom_set_type(int model, int type); -extern int cdrom_get_type(int model); +static __inline int +bin2bcd(int x) +{ + return (x % 10) | ((x / 10) << 4); +} -extern int cdrom_lba_to_msf_accurate(int lba); -extern double cdrom_seek_time(cdrom_t *dev); -extern void cdrom_stop(cdrom_t *dev); -extern int cdrom_is_pre(cdrom_t *dev, uint32_t lba); -extern int cdrom_audio_callback(cdrom_t *dev, int16_t *output, int len); -extern uint8_t cdrom_audio_play(cdrom_t *dev, uint32_t pos, uint32_t len, int ismsf); -extern uint8_t cdrom_audio_track_search(cdrom_t *dev, uint32_t pos, int type, uint8_t playbit); -extern uint8_t cdrom_audio_track_search_pioneer(cdrom_t *dev, uint32_t pos, uint8_t playbit); -extern uint8_t cdrom_audio_play_pioneer(cdrom_t *dev, uint32_t pos); -extern uint8_t cdrom_audio_play_toshiba(cdrom_t *dev, uint32_t pos, int type); -extern void cdrom_audio_pause_resume(cdrom_t *dev, uint8_t resume); -extern uint8_t cdrom_audio_scan(cdrom_t *dev, uint32_t pos, int type); -extern uint8_t cdrom_get_audio_status_pioneer(cdrom_t *dev, uint8_t *b); -extern uint8_t cdrom_get_audio_status_sony(cdrom_t *dev, uint8_t *b, int msf); -extern uint8_t cdrom_get_current_status(cdrom_t *dev); -extern void cdrom_get_current_subchannel(cdrom_t *dev, uint8_t *b, int msf); -extern void cdrom_get_current_subchannel_sony(cdrom_t *dev, uint8_t *b, int msf); -extern void cdrom_get_current_subcodeq(cdrom_t *dev, uint8_t *b); -extern uint8_t cdrom_get_current_subcodeq_playstatus(cdrom_t *dev, uint8_t *b); -extern int cdrom_read_toc(cdrom_t *dev, unsigned char *b, int type, - unsigned char start_track, int msf, int max_len); -extern int cdrom_read_toc_sony(cdrom_t *dev, unsigned char *b, unsigned char start_track, int msf, int max_len); -extern void cdrom_get_track_buffer(cdrom_t *dev, uint8_t *buf); -extern void cdrom_get_q(cdrom_t *dev, uint8_t *buf, int *curtoctrk, uint8_t mode); -extern uint8_t cdrom_mitsumi_audio_play(cdrom_t *dev, uint32_t pos, uint32_t len); -extern 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); -extern uint8_t cdrom_read_disc_info_toc(cdrom_t *dev, unsigned char *b, unsigned char track, int type); +static __inline int +bcd2bin(int x) +{ + return (x >> 4) * 10 + (x & 0x0f); +} -extern void cdrom_seek(cdrom_t *dev, uint32_t pos, uint8_t vendor_type); +extern char *cdrom_get_vendor(const int type); +extern void cdrom_get_model(const int type, char *name, const int id); +extern char *cdrom_get_revision(const int type); +extern int cdrom_get_scsi_std(const int type); +extern int cdrom_is_early(const int type); +extern int cdrom_is_generic(const int type); +extern int cdrom_is_caddy(const int type); +extern int cdrom_get_speed(const int type); +extern int cdrom_get_inquiry_len(const int type); +extern int cdrom_has_dma(const int type); +extern int cdrom_get_transfer_max(const int type, const int mode); +extern int cdrom_get_type_count(void); +extern void cdrom_get_identify_model(const int type, char *name, const int id); +extern void cdrom_get_name(const int type, char *name); +extern char *cdrom_get_internal_name(const int type); +extern int cdrom_get_from_internal_name(const char *s); +/* TODO: Configuration migration, remove when no longer needed. */ +extern int cdrom_get_from_name(const char *s); +extern void cdrom_set_type(const int model, const int type); +extern int cdrom_get_type(const int model); -extern void cdrom_close_handler(uint8_t id); -extern void cdrom_insert(uint8_t id); -extern void cdrom_exit(uint8_t id); -extern int cdrom_is_empty(uint8_t id); -extern void cdrom_eject(uint8_t id); -extern void cdrom_reload(uint8_t id); +extern int cdrom_lba_to_msf_accurate(const int lba); +extern void cdrom_interleave_subch(uint8_t *d, const uint8_t *s); +extern double cdrom_seek_time(const cdrom_t *dev); +extern void cdrom_stop(cdrom_t *dev); +extern void cdrom_seek(cdrom_t *dev, const uint32_t pos, const uint8_t vendor_type); +extern int cdrom_is_pre(const cdrom_t *dev, const uint32_t lba); -extern int cdrom_image_open(cdrom_t *dev, const char *fn); -extern void cdrom_image_close(cdrom_t *dev); +extern int cdrom_audio_callback(cdrom_t *dev, int16_t *output, const int len); +extern uint8_t cdrom_audio_play(cdrom_t *dev, const uint32_t pos, const uint32_t len, const int ismsf); +extern uint8_t cdrom_audio_track_search(cdrom_t *dev, const uint32_t pos, + const int type, const uint8_t playbit); +extern uint8_t cdrom_audio_track_search_pioneer(cdrom_t *dev, const uint32_t pos, const uint8_t playbit); +extern uint8_t cdrom_audio_play_pioneer(cdrom_t *dev, const uint32_t pos); +extern uint8_t cdrom_audio_play_toshiba(cdrom_t *dev, const uint32_t pos, const int type); +extern uint8_t cdrom_audio_scan(cdrom_t *dev, const uint32_t pos); +extern void cdrom_audio_pause_resume(cdrom_t *dev, const uint8_t resume); -extern int cdrom_ioctl_open(cdrom_t *dev, const char *drv); -extern void cdrom_ioctl_close(cdrom_t *dev); +extern uint8_t cdrom_get_current_status(const cdrom_t *dev); +extern void cdrom_get_current_subchannel(cdrom_t *dev, uint8_t *b, const int msf); +extern void cdrom_get_current_subchannel_sony(cdrom_t *dev, uint8_t *b, const int msf); +extern uint8_t cdrom_get_audio_status_pioneer(cdrom_t *dev, uint8_t *b); +extern uint8_t cdrom_get_audio_status_sony(cdrom_t *dev, uint8_t *b, const int msf); +extern void cdrom_get_current_subcodeq(cdrom_t *dev, uint8_t *b); +extern uint8_t cdrom_get_current_subcodeq_playstatus(cdrom_t *dev, uint8_t *b); +extern int cdrom_read_toc(const cdrom_t *dev, uint8_t *b, const int type, + const uint8_t start_track, const int msf, const int max_len); +extern int cdrom_read_toc_sony(const cdrom_t *dev, uint8_t *b, const uint8_t start_track, + const int msf, const int max_len); +#ifdef USE_CDROM_MITSUMI +extern void cdrom_get_track_buffer(cdrom_t *dev, uint8_t *buf); +extern void cdrom_get_q(cdrom_t *dev, uint8_t *buf, int *curtoctrk, uint8_t mode); +extern uint8_t cdrom_mitsumi_audio_play(cdrom_t *dev, uint32_t pos, uint32_t len); +#endif +extern uint8_t cdrom_read_disc_info_toc(cdrom_t *dev, uint8_t *b, + const uint8_t track, const int type); +extern int cdrom_is_track_audio(cdrom_t *dev, const int sector, const int ismsf, + int cdrom_sector_type, const uint8_t vendor_type); +extern int cdrom_readsector_raw(cdrom_t *dev, uint8_t *buffer, const int sector, const int ismsf, + int cdrom_sector_type, const int cdrom_sector_flags, + int *len, const uint8_t vendor_type); +extern int cdrom_read_dvd_structure(const cdrom_t *dev, const uint8_t layer, const uint8_t format, + uint8_t *buffer, uint32_t *info); +extern void cdrom_read_disc_information(const cdrom_t *dev, uint8_t *buffer); +extern int cdrom_read_track_information(cdrom_t *dev, const uint8_t *cdb, uint8_t *buffer); +extern uint8_t cdrom_get_current_mode(cdrom_t *dev); +extern void cdrom_set_empty(cdrom_t *dev); +extern void cdrom_update_status(cdrom_t *dev); +extern int cdrom_load(cdrom_t *dev, const char *fn, const int skip_insert); -extern void cdrom_update_cdb(uint8_t *cdb, int lba_pos, - int number_of_blocks); +extern void cdrom_global_init(void); +extern void cdrom_hard_reset(void); +extern void cdrom_close(void); +extern void cdrom_insert(const uint8_t id); +extern void cdrom_exit(const uint8_t id); +extern int cdrom_is_empty(const uint8_t id); +extern void cdrom_eject(const uint8_t id); +extern void cdrom_reload(const uint8_t id); -extern int find_cdrom_for_scsi_id(uint8_t scsi_id); - -extern void cdrom_close(void); -extern void cdrom_global_init(void); -extern void cdrom_global_reset(void); -extern void cdrom_hard_reset(void); -extern void scsi_cdrom_drive_reset(int c); +extern int cdrom_assigned_letters; #ifdef __cplusplus } diff --git a/src/include/86box/cdrom_image.h b/src/include/86box/cdrom_image.h index c848af50d..e0760ff7e 100644 --- a/src/include/86box/cdrom_image.h +++ b/src/include/86box/cdrom_image.h @@ -6,35 +6,33 @@ * * This file is part of the 86Box distribution. * - * CD-ROM image file handling module header, translated to C - * from cdrom_dosbox.h. + * CD-ROM image file handling module header. * - * Authors: RichardG, - * Miran Grca, + * Authors: Miran Grca, + * RichardG, + * Cacodemon345 * - * Copyright 2016-2022 RichardG. - * Copyright 2016-2022 Miran Grca. + * Copyright 2016-2025 Miran Grca. + * Copyright 2016-2025 RichardG. + * Copyright 2024-2025 Cacodemon345. */ #ifndef CDROM_IMAGE_H #define CDROM_IMAGE_H -/* this header file lists the functions provided by - various platform specific cdrom-ioctl files */ +/* Track file struct. */ +typedef struct track_file_t { + int (*read)(void *priv, uint8_t *buffer, uint64_t seek, size_t count); + uint64_t (*get_length)(void *priv); + void (*close)(void *priv); -#ifdef __cplusplus -extern "C" { -#endif + char fn[260]; + FILE *fp; + void *priv; + void *log; -extern int image_open(uint8_t id, wchar_t *fn); -extern void image_reset(uint8_t id); + int motorola; +} track_file_t; -extern void image_close(uint8_t id); - -void update_status_bar_icon_state(int tag, int state); -extern void cdrom_set_null_handler(uint8_t id); - -#ifdef __cplusplus -} -#endif +extern void *image_open(cdrom_t *dev, const char *path); #endif /*CDROM_IMAGE_H*/ diff --git a/src/include/86box/cdrom_image_backend.h b/src/include/86box/cdrom_image_backend.h deleted file mode 100644 index 64ce88d83..000000000 --- a/src/include/86box/cdrom_image_backend.h +++ /dev/null @@ -1,119 +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. - * - * CD-ROM image file handling module header. - * - * Authors: Miran Grca, - * RichardG, - * Cacodemon345 - * - * Copyright 2016-2025 Miran Grca. - * Copyright 2016-2025 Miran Grca. - * Copyright 2024-2025 Cacodemon345. - */ -#ifndef CDROM_IMAGE_BACKEND_H -#define CDROM_IMAGE_BACKEND_H - -#define RAW_SECTOR_SIZE 2352 -#define COOKED_SECTOR_SIZE 2048 - -#define DATA_TRACK 0x14 -#define AUDIO_TRACK 0x10 - -#define CD_FPS 75 -#define FRAMES_TO_MSF(f, M, S, F) \ - { \ - uint64_t value = f; \ - *(F) = (value % CD_FPS) & 0xff; \ - value /= CD_FPS; \ - *(S) = (value % 60) & 0xff; \ - value /= 60; \ - *(M) = value & 0xff; \ - } -#define MSF_TO_FRAMES(M, S, F) ((M) *60 * CD_FPS + (S) *CD_FPS + (F)) - -typedef struct SMSF { - uint16_t min; - uint8_t sec; - uint8_t fr; -} TMSF; - -/* Track file struct. */ -typedef struct track_file_t { - int (*read)(void *priv, uint8_t *buffer, uint64_t seek, size_t count); - uint64_t (*get_length)(void *priv); - void (*close)(void *priv); - - char fn[260]; - FILE *fp; - void *priv; - - int motorola; -} track_file_t; - -#define INDEX_SPECIAL -2 /* Track A0h onwards. */ -#define INDEX_NONE -1 /* Empty block. */ -#define INDEX_ZERO 0 /* Block not in the file, return all 0x00's. */ -#define INDEX_NORMAL 1 /* Block in the file. */ - -typedef struct track_index_t { - /* Is the current block in the file? If not, return all 0x00's. -1 means not yet loaded. */ - int32_t type; - /* The amount of bytes to skip at the beginning of each sector. */ - int32_t skip; - /* Starting and ending sector LBA - negative in order to accomodate LBA -150 to -1 - to read the pregap of track 1. */ - uint64_t start; - uint64_t length; - uint64_t file_start; - uint64_t file_length; - track_file_t *file; -} track_index_t; - -typedef struct track_t { - uint8_t session; - uint8_t attr; - uint8_t tno; - uint8_t point; - uint8_t extra[4]; - uint8_t mode; - uint8_t form; - uint8_t pad; - uint8_t skip; - uint32_t sector_size; - track_index_t idx[3]; -} track_t; - -typedef struct cd_img_t { - int32_t tracks_num; - track_t *tracks; -} cd_img_t; - -/* Binary file functions. */ -extern void cdi_get_raw_track_info(cd_img_t *cdi, int *num, uint8_t *buffer); -extern 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); -extern int cdi_read_sector(cd_img_t *cdi, uint8_t *buffer, int raw, uint32_t sector); -extern int cdi_read_sector_sub(cd_img_t *cdi, uint8_t *buffer, uint32_t sector); -extern int cdi_get_sector_size(cd_img_t *cdi, uint32_t sector); -extern int cdi_is_audio(cd_img_t *cdi, uint32_t sector); -extern int cdi_is_pre(cd_img_t *cdi, uint32_t sector); -extern int cdi_is_mode2(cd_img_t *cdi, uint32_t sector); -extern int cdi_get_mode2_form(cd_img_t *cdi, uint32_t sector); -extern int cdi_load_iso(cd_img_t *cdi, const char *filename); -extern int cdi_load_cue(cd_img_t *cdi, const char *cuefile); -extern void cdi_close(cd_img_t *cdi); -extern int cdi_set_device(cd_img_t *cdi, const char *path); - -/* Virtual ISO functions. */ -extern int viso_read(void *priv, uint8_t *buffer, uint64_t seek, size_t count); -extern uint64_t viso_get_length(void *priv); -extern void viso_close(void *priv); -extern track_file_t *viso_init(const char *dirname, int *error); - -#endif /*CDROM_IMAGE_BACKEND_H*/ diff --git a/src/include/86box/cdrom_image_viso.h b/src/include/86box/cdrom_image_viso.h new file mode 100644 index 000000000..19f0e1de0 --- /dev/null +++ b/src/include/86box/cdrom_image_viso.h @@ -0,0 +1,26 @@ +/* + * 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. + * + * CD-ROM image file handling module header. + * + * Authors: RichardG, + * Miran Grca, + * + * Copyright 2016-2025 RichardG. + * Copyright 2016-2025 Miran Grca. + */ +#ifndef CDROM_IMAGE_VISO_H +#define CDROM_IMAGE_VISO_H + +/* Virtual ISO functions. */ +extern int viso_read(void *priv, uint8_t *buffer, uint64_t seek, size_t count); +extern uint64_t viso_get_length(void *priv); +extern void viso_close(void *priv); +extern track_file_t *viso_init(const uint8_t id, const char *dirname, int *error); + +#endif /*CDROM_IMAGE_VISO_H*/ diff --git a/src/include/86box/cdrom_interface.h b/src/include/86box/cdrom_interface.h index 081f758f6..ba4d0581b 100644 --- a/src/include/86box/cdrom_interface.h +++ b/src/include/86box/cdrom_interface.h @@ -21,11 +21,13 @@ extern int cdrom_interface_current; extern void cdrom_interface_reset(void); -extern const char *cdrom_interface_get_internal_name(int cdinterface); -extern int cdrom_interface_get_from_internal_name(char *s); -extern int cdrom_interface_has_config(int cdinterface); -extern const device_t *cdrom_interface_get_device(int cdinterface); -extern int cdrom_interface_get_flags(int cdinterface); -extern int cdrom_interface_available(int cdinterface); +const char *cdrom_interface_get_internal_name(const int cdinterface); +extern int cdrom_interface_get_from_internal_name(const char *s); +#ifdef EMU_DEVICE_H +extern const device_t *cdrom_interface_get_device(const int cdinterface); +#endif +extern int cdrom_interface_has_config(const int cdinterface); +extern int cdrom_interface_get_flags(const int cdinterface); +extern int cdrom_interface_available(const int cdinterface); #endif /*EMU_CDROM_INTERFACE_H*/ diff --git a/src/include/86box/cdrom_ioctl.h b/src/include/86box/cdrom_ioctl.h deleted file mode 100644 index 5fc157615..000000000 --- a/src/include/86box/cdrom_ioctl.h +++ /dev/null @@ -1,32 +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. - * - * CD-ROM image file handling module header, translated to C - * from cdrom_dosbox.h. - * - * Authors: RichardG, - * Miran Grca, - * - * Copyright 2016-2022 RichardG. - * Copyright 2016-2022 Miran Grca. - */ -#ifndef CDROM_IOCTL_H -#define CDROM_IOCTL_H - -/* this header file lists the functions provided by - various platform specific cdrom-ioctl files */ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif /*CDROM_IOCTL_H*/ diff --git a/src/include/86box/chipset.h b/src/include/86box/chipset.h index e47bb489f..7ee8182ea 100644 --- a/src/include/86box/chipset.h +++ b/src/include/86box/chipset.h @@ -18,6 +18,7 @@ #define EMU_CHIPSET_H /* ACC */ +extern const device_t acc2036_device; extern const device_t acc2168_device; /* ALi */ @@ -37,6 +38,9 @@ extern const device_t ali6117d_device; /* AMD */ extern const device_t amd640_device; +/* ASUS */ +extern const device_t isa486c_device; + /* Compaq */ extern const device_t compaq_386_device; extern const device_t compaq_genoa_device; @@ -48,9 +52,11 @@ extern const device_t contaq_82c597_device; /* C&T */ extern const device_t ct_82c100_device; extern const device_t neat_device; +extern const device_t neat_sx_device; extern const device_t scat_device; extern const device_t scat_4_device; extern const device_t scat_sx_device; +extern const device_t cs8220_device; extern const device_t cs8230_device; extern const device_t cs4031_device; @@ -108,6 +114,9 @@ extern const device_t slc90e66_device; extern const device_t ioapic_device; +/* Olivetti */ +extern const device_t olivetti_eva_device; + /* OPTi */ extern const device_t opti283_device; extern const device_t opti291_device; @@ -115,7 +124,9 @@ extern const device_t opti381_device; extern const device_t opti391_device; extern const device_t opti481_device; extern const device_t opti493_device; -extern const device_t opti495_device; +extern const device_t opti495slc_device; +extern const device_t opti495sx_device; +extern const device_t opti498_device; extern const device_t opti499_device; extern const device_t opti601_device; extern const device_t opti602_device; @@ -155,6 +166,9 @@ extern const device_t stpc_atlas_device; extern const device_t stpc_serial_device; extern const device_t stpc_lpt_device; +/* Symphony */ +extern const device_t sl82c461_device; + /* UMC */ extern const device_t umc_8886f_device; extern const device_t umc_8886af_device; @@ -190,12 +204,12 @@ extern const device_t vlsi_scamp_device; extern const device_t wd76c10_device; /* Miscellaneous Hardware */ +extern const device_t tulip_jumper_device; + +extern const device_t dell_jumper_device; + extern const device_t nec_mate_unk_device; extern const device_t phoenix_486_jumper_device; extern const device_t phoenix_486_jumper_pci_device; - -#ifdef USE_OLIVETTI -extern const device_t olivetti_eva_device; -#endif /* USE_OLIVETTI */ #endif /*EMU_CHIPSET_H*/ diff --git a/src/include/86box/config.h b/src/include/86box/config.h index a043fb22a..34447266b 100644 --- a/src/include/86box/config.h +++ b/src/include/86box/config.h @@ -8,16 +8,16 @@ * * Configuration file handler header. * - * - * * Authors: Sarah Walker, * Miran Grca, * Fred N. van Kempen, * Overdoze, + * Jasmine Iwanek, * * Copyright 2008-2017 Sarah Walker. * Copyright 2016-2017 Miran Grca. * Copyright 2017 Fred N. van Kempen. + * Copyright 2021-2025 Jasmine Iwanek. */ #ifndef EMU_CONFIG_H #define EMU_CONFIG_H @@ -111,6 +111,7 @@ typedef struct config_t { # ifdef USE_SERIAL_DEVICES char serial_devices[SERIAL_MAX][32]; /* Serial device names */ # endif + char gameport_devices[GAMEPORT_MAX][32]; /* gameport device names */ /* Other peripherals category */ int fdc_current[FDC_MAX]; /* Floppy disk controller type */ @@ -121,6 +122,7 @@ typedef struct config_t { int ide_qua_enabled; /* Quaternary IDE controller enabled */ int bugger_enabled; /* ISA bugger device enabled */ int isa_rtc_type; /* ISA RTC card */ + int isa_rom_type[ISAROM_MAX]; /* ISA ROM boards */ int isa_mem_type[ISAMEM_MAX]; /* ISA memory boards */ /* Hard disks category */ diff --git a/src/include/86box/crc.h b/src/include/86box/crc.h new file mode 100644 index 000000000..1a6e76dab --- /dev/null +++ b/src/include/86box/crc.h @@ -0,0 +1,34 @@ +/* + * 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 CRC code. + * + * Authors: Miran Grca, + * + * Copyright 2016-2025 Miran Grca. + */ +#ifndef EMU_CRC_H +#define EMU_CRC_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef union { + uint16_t word; + uint8_t bytes[2]; +} crc_t; + +extern void crc16_setup(uint16_t *crc_table, uint16_t poly); +extern void crc16_calc(uint16_t *crc_table, uint8_t byte, crc_t *crc_var); + +#ifdef __cplusplus +} +#endif + +#endif /*EMU_CRC_H*/ diff --git a/src/include/86box/device.h b/src/include/86box/device.h index 67a30b1c8..76f12a0c5 100644 --- a/src/include/86box/device.h +++ b/src/include/86box/device.h @@ -18,7 +18,7 @@ * Copyright 2016-2019 Miran Grca. * Copyright 2008-2019 Sarah Walker. * Copyright 2021 Andreas J. Reichel. - * Copyright 2021-2022 Jasmine Iwanek. + * Copyright 2021-2025 Jasmine Iwanek. * * 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 @@ -79,29 +79,34 @@ // #define CONFIG_STANDALONE 257 /* not available on the on-board variant */ enum { - DEVICE_PCJR = 2, /* requires an IBM PCjr */ - DEVICE_XTKBC = 4, /* requires an XT-compatible keyboard controller */ - DEVICE_AT = 8, /* requires an AT-compatible system */ - DEVICE_ATKBC = 0x10, /* requires an AT-compatible keyboard controller */ - DEVICE_PS2 = 0x20, /* requires a PS/1 or PS/2 system */ - DEVICE_ISA = 0x40, /* requires the ISA bus */ - DEVICE_CBUS = 0x80, /* requires the C-BUS bus */ - DEVICE_PCMCIA = 0x100, /* requires the PCMCIA bus */ - DEVICE_MCA = 0x200, /* requires the MCA bus */ - DEVICE_HIL = 0x400, /* requires the HP HIL bus */ - DEVICE_EISA = 0x800, /* requires the EISA bus */ - DEVICE_AT32 = 0x1000, /* requires the Mylex AT/32 local bus */ - DEVICE_OLB = 0x2000, /* requires the OPTi local bus */ - DEVICE_VLB = 0x4000, /* requires the VLB bus */ - DEVICE_PCI = 0x8000, /* requires the PCI bus */ - DEVICE_CARDBUS = 0x10000, /* requires the CardBus bus */ - DEVICE_USB = 0x20000, /* requires the USB bus */ - DEVICE_AGP = 0x40000, /* requires the AGP bus */ - DEVICE_AC97 = 0x80000, /* requires the AC'97 bus */ - DEVICE_COM = 0x100000, /* requires a serial port */ - DEVICE_LPT = 0x200000, /* requires a parallel port */ - DEVICE_KBC = 0x400000, /* is a keyboard controller */ - DEVICE_SOFTRESET = 0x800000, /* requires to be reset on soft reset */ + DEVICE_CASETTE = 1, /* requires a Casette Port */ + DEVICE_SIDECAR = 2, /* requires an IBM PCjr */ + DEVICE_ISA = 4, /* requires the ISA bus */ + DEVICE_XT_KBC = 8, /* requires an XT-compatible keyboard controller */ + DEVICE_CBUS = 0x10, /* requires the C-BUS bus */ + DEVICE_ISA16 = 0x20, /* requires an AT-compatible system */ + DEVICE_AT_KBC = 0x40, /* requires an AT-compatible keyboard controller */ + DEVICE_MCA = 0x80, /* requires the MCA bus */ + DEVICE_MCA32 = 0x100, /* requires the MCA bus */ + DEVICE_PS2_KBC = 0x200, /* requires a PS/1 or PS/2 system */ + DEVICE_PCMCIA = 0x400, /* requires the PCMCIA bus */ + DEVICE_HIL = 0x800, /* requires the HP HIL bus */ + DEVICE_EISA = 0x1000, /* requires the EISA bus */ + DEVICE_AT32 = 0x2000, /* requires the Mylex AT/32 local bus */ + DEVICE_OLB = 0x4000, /* requires the OPTi local bus */ + DEVICE_VLB = 0x8000, /* requires the VLB bus */ + DEVICE_PCI = 0x10000, /* requires the PCI bus */ + DEVICE_CARDBUS = 0x20000, /* requires the CardBus bus */ + DEVICE_USB = 0x40000, /* requires the USB bus */ + DEVICE_AGP = 0x80000, /* requires the AGP bus */ + DEVICE_AC97 = 0x100000, /* requires the AC'97 bus */ + DEVICE_BUS = 0x1fffff, /* requires a machine bus */ + + DEVICE_COM = 0x200000, /* requires a serial port */ + DEVICE_LPT = 0x400000, /* requires a parallel port */ + + DEVICE_KBC = 0x800000, /* is a keyboard controller */ + DEVICE_SOFTRESET = 0x1000000, /* requires to be reset on soft reset */ DEVICE_ONBOARD = 0x40000000, /* is on-board */ DEVICE_PIT = 0x80000000, /* device is a PIT */ @@ -118,16 +123,6 @@ enum { #define BIOS_INTERLEAVED_INVERT 8 #define BIOS_HIGH_BIT_INVERT 16 -#define device_common_config_t \ - const char *name; \ - const char *description; \ - int type; \ - const char *default_string; \ - int default_int; \ - const char *file_filter; \ - const device_config_spinner_t spinner; \ - const device_config_selection_t selection[32] - typedef struct device_config_selection_t { const char *description; int value; @@ -139,29 +134,27 @@ typedef struct device_config_spinner_t { int16_t step; } device_config_spinner_t; -typedef struct _device_dep_config_ { - device_common_config_t; -} device_dep_config_t; - typedef struct device_config_bios_t { const char *name; const char *internal_name; - int bios_type; - int files_no; + uint8_t bios_type; + uint8_t files_no; uint32_t local; uint32_t size; - void *dev1; - void *dev2; + void *dev[2]; const char *files[9]; - /* Configuration options that depend on the device variant. - To prevent excessive nesting, there is no CONFIG_BIOS - option a dep_config struct */ - const device_dep_config_t *dep_config; } device_config_bios_t; typedef struct _device_config_ { - device_common_config_t; - const device_config_bios_t bios[32]; + const char *name; + const char *description; + int type; + const char *default_string; + int default_int; + const char *file_filter; + const device_config_spinner_t spinner; + const device_config_selection_t selection[64]; + const device_config_bios_t bios[32]; } device_config_t; typedef struct _device_ { @@ -176,10 +169,7 @@ typedef struct _device_ { }; void (*close)(void *priv); void (*reset)(void *priv); - union { - int (*available)(void); - int (*poll)(void *priv); - }; + int (*available)(void); void (*speed_changed)(void *priv); void (*force_redraw)(void *priv); @@ -197,12 +187,12 @@ extern "C" { #endif extern void device_init(void); -extern void device_set_context(device_context_t *c, const device_t *dev, int inst); +extern void device_set_context(device_context_t *ctx, const device_t *dev, int inst); extern void device_context(const device_t *dev); extern void device_context_inst(const device_t *dev, int inst); extern void device_context_restore(void); -extern void *device_add(const device_t *d); -extern void *device_add_linked(const device_t *d, void *priv); +extern void *device_add(const device_t *dev); +extern void *device_add_linked(const device_t *dev, void *priv); extern void *device_add_params(const device_t *dev, void *params); extern void device_add_ex(const device_t *dev, void *priv); extern void device_add_ex_params(const device_t *dev, void *priv, void *params); @@ -216,34 +206,40 @@ extern void device_reset_all(uint32_t match_flags); extern void *device_find_first_priv(uint32_t match_flags); extern void *device_get_priv(const device_t *dev); extern int device_available(const device_t *dev); -extern int device_poll(const device_t *dev); extern void device_speed_changed(void); extern void device_force_redraw(void); extern void device_get_name(const device_t *dev, int bus, char *name); extern int device_has_config(const device_t *dev); + +extern uint8_t device_get_bios_type(const device_t *dev, const char *internal_name); +extern uint8_t device_get_bios_num_files(const device_t *dev, const char *internal_name); +extern uint32_t device_get_bios_local(const device_t *dev, const char *internal_name); +extern uint32_t device_get_bios_file_size(const device_t *dev, const char *internal_name); extern const char *device_get_bios_file(const device_t *dev, const char *internal_name, int file_no); -extern int device_is_valid(const device_t *, int m); +extern int device_is_valid(const device_t *, int mch); extern const device_t* device_context_get_device(void); extern int device_get_config_int(const char *name); -extern int device_get_config_int_ex(const char *s, int dflt_int); +extern int device_get_config_int_ex(const char *str, int def); extern int device_get_config_hex16(const char *name); extern int device_get_config_hex20(const char *name); -extern int device_get_config_mac(const char *name, int dflt_int); -extern void device_set_config_int(const char *s, int val); -extern void device_set_config_hex16(const char *s, int val); -extern void device_set_config_hex20(const char *s, int val); -extern void device_set_config_mac(const char *s, int val); +extern int device_get_config_mac(const char *name, int def); +extern void device_set_config_int(const char *str, int val); +extern void device_set_config_hex16(const char *str, int val); +extern void device_set_config_hex20(const char *str, int val); +extern void device_set_config_mac(const char *str, int val); extern const char *device_get_config_string(const char *name); extern int device_get_instance(void); #define device_get_config_bios device_get_config_string extern const char *device_get_internal_name(const device_t *dev); -extern int machine_get_config_int(char *s); -extern char *machine_get_config_string(char *s); +extern int machine_get_config_int(char *str); +extern const char *machine_get_config_string(char *str); + +extern int machine_device_available(const device_t *dev); extern const device_t device_none; extern const device_t device_internal; diff --git a/src/include/86box/fdc.h b/src/include/86box/fdc.h index 9e8006650..c98a03f67 100644 --- a/src/include/86box/fdc.h +++ b/src/include/86box/fdc.h @@ -38,26 +38,27 @@ #define FDC_QUATERNARY_IRQ 6 #define FDC_QUATERNARY_DMA 2 -#define FDC_FLAG_PCJR 0x01 /* PCjr */ -#define FDC_FLAG_DISKCHG_ACTLOW 0x02 /* Amstrad, PS/1, PS/2 ISA */ -#define FDC_FLAG_AT 0x04 /* AT+, PS/x */ -#define FDC_FLAG_PS2 0x08 /* PS/1, PS/2 ISA */ -#define FDC_FLAG_PS2_MCA 0x10 /* PS/2 MCA */ -#define FDC_FLAG_SUPERIO 0x20 /* Super I/O chips */ -#define FDC_FLAG_START_RWC_1 0x40 /* W83877F, W83977F */ -#define FDC_FLAG_MORE_TRACKS 0x80 /* W83877F, W83977F, PC87306, PC87309 */ -#define FDC_FLAG_NSC 0x100 /* PC87306, PC87309 */ -#define FDC_FLAG_TOSHIBA 0x200 /* T1000, T1200 */ -#define FDC_FLAG_AMSTRAD 0x400 /* Non-AT Amstrad machines */ -#define FDC_FLAG_UMC 0x800 /* UMC UM8398 */ -#define FDC_FLAG_ALI 0x1000 /* ALi M512x / M1543C */ -#define FDC_FLAG_NO_DSR_RESET 0x2000 /* Has no DSR reset */ -#define FDC_FLAG_DENSEL_INVERT 0x4000 /* Invert DENSEL polarity */ -#define FDC_FLAG_FINTR 0x8000 /* Raise FINTR on data command finish */ -#define FDC_FLAG_NEC 0x10000 /* Is NEC upd765-compatible */ -#define FDC_FLAG_SEC 0x20000 /* Is Secondary */ -#define FDC_FLAG_TER 0x40000 /* Is Tertiary */ -#define FDC_FLAG_QUA 0x80000 /* Is Quaternary */ +#define FDC_FLAG_PCJR 0x01 /* PCjr */ +#define FDC_FLAG_DISKCHG_ACTLOW 0x02 /* Amstrad, PS/1, PS/2 ISA */ +#define FDC_FLAG_AT 0x04 /* AT+, PS/x */ +#define FDC_FLAG_PS2 0x08 /* PS/1, PS/2 ISA */ +#define FDC_FLAG_PS2_MCA 0x10 /* PS/2 MCA */ +#define FDC_FLAG_SUPERIO 0x20 /* Super I/O chips */ +#define FDC_FLAG_START_RWC_1 0x40 /* W83877F, W83977F */ +#define FDC_FLAG_MORE_TRACKS 0x80 /* W83877F, W83977F, PC87306, PC87309 */ +#define FDC_FLAG_NSC 0x100 /* PC87306, PC87309 */ +#define FDC_FLAG_TOSHIBA 0x200 /* T1000, T1200 */ +#define FDC_FLAG_AMSTRAD 0x400 /* Non-AT Amstrad machines */ +#define FDC_FLAG_UMC 0x800 /* UMC UM8398 */ +#define FDC_FLAG_ALI 0x1000 /* ALi M512x / M1543C */ +#define FDC_FLAG_NO_DSR_RESET 0x2000 /* Has no DSR reset */ +#define FDC_FLAG_DENSEL_INVERT 0x4000 /* Invert DENSEL polarity */ +#define FDC_FLAG_FINTR 0x8000 /* Raise FINTR on data command finish */ +#define FDC_FLAG_NEC 0x10000 /* Is NEC upd765-compatible */ +#define FDC_FLAG_SEC 0x20000 /* Is Secondary */ +#define FDC_FLAG_TER 0x40000 /* Is Tertiary */ +#define FDC_FLAG_QUA 0x80000 /* Is Quaternary */ +#define FDC_FLAG_SMC661 0x100000 /* SM(s)C FDC37C661 - different TDR enhanced mode */ typedef struct fdc_t { uint8_t dor; @@ -103,7 +104,6 @@ typedef struct fdc_t { uint8_t densel_force; uint8_t fifo; uint8_t tfifo; - uint8_t fifobufpos; uint8_t drv2en; uint8_t gap; @@ -120,6 +120,8 @@ typedef struct fdc_t { uint8_t lock; uint8_t dsr; + uint8_t media_id; + uint8_t params[15]; uint8_t specify[2]; uint8_t res[11]; @@ -148,6 +150,7 @@ typedef struct fdc_t { int drvrate[4]; void *fifo_p; + int fifointest; sector_id_t read_track_sector; sector_id_t format_sector_id; @@ -166,6 +169,9 @@ extern void fdc_3f1_enable(fdc_t *fdc, int enable); extern int fdc_get_bit_rate(fdc_t *fdc); extern int fdc_get_bitcell_period(fdc_t *fdc); +extern uint8_t fdc_get_media_id(fdc_t *fdc, int id); +extern void fdc_set_media_id(fdc_t *fdc, int id, int set); + /* A few functions to communicate between Super I/O chips and the FDC. */ extern void fdc_update_enh_mode(fdc_t *fdc, int enh_mode); extern int fdc_get_rwc(fdc_t *fdc, int drive); @@ -177,6 +183,7 @@ extern uint8_t fdc_get_densel_polarity(fdc_t *fdc); extern void fdc_update_densel_force(fdc_t *fdc, int densel_force); extern void fdc_update_drvrate(fdc_t *fdc, int drive, int drvrate); extern void fdc_update_drv2en(fdc_t *fdc, int drv2en); +extern void fdc_toggle_flag(fdc_t *fdc, int flag, int on); extern void fdc_noidam(fdc_t *fdc); extern void fdc_nosector(fdc_t *fdc); @@ -201,6 +208,7 @@ extern int fdc_get_drive(fdc_t *fdc); extern int fdc_get_perp(fdc_t *fdc); extern int fdc_get_format_n(fdc_t *fdc); extern int fdc_is_mfm(fdc_t *fdc); +extern int fdc_is_dma(fdc_t *fdc); extern double fdc_get_hut(fdc_t *fdc); extern double fdc_get_hlt(fdc_t *fdc); extern void fdc_request_next_sector_id(fdc_t *fdc); @@ -254,6 +262,7 @@ extern const device_t fdc_at_sec_device; extern const device_t fdc_at_ter_device; extern const device_t fdc_at_qua_device; extern const device_t fdc_at_actlow_device; +extern const device_t fdc_at_smc_661_device; extern const device_t fdc_at_smc_device; extern const device_t fdc_at_ali_device; extern const device_t fdc_at_winbond_device; diff --git a/src/include/86box/fdc_ext.h b/src/include/86box/fdc_ext.h index 4b33ed7a1..e6348139b 100644 --- a/src/include/86box/fdc_ext.h +++ b/src/include/86box/fdc_ext.h @@ -34,6 +34,10 @@ extern const device_t fdc_b215_device; extern const device_t fdc_pii151b_device; extern const device_t fdc_pii158b_device; +extern const device_t fdc_compaticard_i_device; +extern const device_t fdc_compaticard_ii_device; +extern const device_t fdc_compaticard_iv_device; + extern const device_t fdc_monster_device; extern void fdc_card_init(void); diff --git a/src/include/86box/fdd.h b/src/include/86box/fdd.h index 0331f4fcc..d6ade3bc6 100644 --- a/src/include/86box/fdd.h +++ b/src/include/86box/fdd.h @@ -8,21 +8,19 @@ * * Definitions for the floppy drive emulation. * - * - * * Authors: Sarah Walker, * Miran Grca, * Fred N. van Kempen, * - * Copyright 2008-2018 Sarah Walker. - * Copyright 2016-2018 Miran Grca. - * Copyright 2018 Fred N. van Kempen. + * Copyright 2008-2025 Sarah Walker. + * Copyright 2016-2025 Miran Grca. + * Copyright 2018-2025 Fred N. van Kempen. */ #ifndef EMU_FDD_H #define EMU_FDD_H #define FDD_NUM 4 -#define FLOPPY_IMAGE_HISTORY 4 +#define FLOPPY_IMAGE_HISTORY 10 #define SEEK_RECALIBRATE -999 #ifdef __cplusplus @@ -129,13 +127,6 @@ extern int drive_empty[FDD_NUM]; #define SECTOR_FIRST -2 #define SECTOR_NEXT -1 -typedef union { - uint16_t word; - uint8_t bytes[2]; -} crc_t; - -void fdd_calccrc(uint8_t byte, crc_t *crc_var); - typedef struct d86f_handler_t { uint16_t (*disk_flags)(int drive); uint16_t (*side_flags)(int drive); diff --git a/src/include/86box/fdd_86f.h b/src/include/86box/fdd_86f.h index cc8035965..de7bb7dcb 100644 --- a/src/include/86box/fdd_86f.h +++ b/src/include/86box/fdd_86f.h @@ -8,13 +8,11 @@ * * Definitions for the 86F floppy image format. * - * - * * Authors: Miran Grca, * Fred N. van Kempen, * - * Copyright 2016-2019 Miran Grca. - * Copyright 2018-2019 Fred N. van Kempen. + * Copyright 2016-2025 Miran Grca. + * Copyright 2018-2025 Fred N. van Kempen. */ #ifndef EMU_FLOPPY_86F_H #define EMU_FLOPPY_86F_H diff --git a/src/include/86box/fifo.h b/src/include/86box/fifo.h index f87f932e0..f8f07d9b5 100644 --- a/src/include/86box/fifo.h +++ b/src/include/86box/fifo.h @@ -1,6 +1,3 @@ -#ifndef FIFO_H -#define FIFO_H - /* * 86Box A hypervisor and IBM PC system emulator that specializes in * running old operating systems and software designed for IBM @@ -13,8 +10,11 @@ * * Authors: Miran Grca, * - * Copyright 2023 Miran Grca. + * Copyright 2023-2025 Miran Grca. */ +#ifndef FIFO_H +#define FIFO_H + #define FIFO(size) \ typedef struct { \ int start; \ @@ -37,6 +37,7 @@ void (*d_full_evt)(void *); \ void (*d_ready_evt)(void *); \ \ + uint8_t tag[64]; \ uint8_t buf[size]; \ } fifo## size ##_t; @@ -50,9 +51,13 @@ FIFO(64) extern int fifo_get_count(void *priv); extern void fifo_write(uint8_t val, void *priv); +extern void fifo_write_tagged(uint8_t tag, uint8_t val, void *priv); extern void fifo_write_evt(uint8_t val, void *priv); +extern void fifo_write_evt_tagged(uint8_t tag, uint8_t val, void *priv); extern uint8_t fifo_read(void *priv); +extern uint8_t fifo_read_tagged(uint8_t *tag, void *priv); extern uint8_t fifo_read_evt(void *priv); +extern uint8_t fifo_read_evt_tagged(uint8_t *tag, void *priv); extern void fifo_clear_overrun(void *priv); extern int fifo_get_full(void *priv); extern int fifo_get_d_full(void *priv); diff --git a/src/include/86box/flash.h b/src/include/86box/flash.h index 6f0e1ff15..bd9b7e505 100644 --- a/src/include/86box/flash.h +++ b/src/include/86box/flash.h @@ -20,6 +20,7 @@ #ifndef EMU_FLASH_H #define EMU_FLASH_H +extern const device_t amd_am28f010_flash_device; extern const device_t catalyst_flash_device; extern const device_t intel_flash_bxt_ami_device; diff --git a/src/include/86box/gameport.h b/src/include/86box/gameport.h index 3d3a253e8..7928cdd30 100644 --- a/src/include/86box/gameport.h +++ b/src/include/86box/gameport.h @@ -8,8 +8,6 @@ * * Definitions for the generic game port handlers. * - * - * * Authors: Miran Grca, * Sarah Walker, * RichardG, @@ -18,11 +16,13 @@ * Copyright 2016-2022 Miran Grca. * Copyright 2008-2018 Sarah Walker. * Copyright 2021 RichardG. - * Copyright 2021-2024 Jasmine Iwanek. + * Copyright 2021-2025 Jasmine Iwanek. */ #ifndef EMU_GAMEPORT_H #define EMU_GAMEPORT_H +#define GAMEPORT_MAX 2 + #define MAX_PLAT_JOYSTICKS 8 #define MAX_JOYSTICKS 4 @@ -45,7 +45,7 @@ #define AXIS_NOT_PRESENT -99999 -#define JOYSTICK_PRESENT(n) (joystick_state[n].plat_joystick_nr != 0) +#define JOYSTICK_PRESENT(gp, js) (joystick_state[gp][js].plat_joystick_nr != 0) #define GAMEPORT_1ADDR 0x010000 #define GAMEPORT_6ADDR 0x060000 @@ -110,10 +110,20 @@ typedef struct joystick_if_t { const char *pov_names[MAX_JOY_POVS]; } joystick_if_t; +extern device_t game_ports[GAMEPORT_MAX]; + #ifdef __cplusplus extern "C" { #endif +extern int gameport_available(int port); +#ifdef EMU_DEVICE_H +extern const device_t *gameport_getdevice(int port); +#endif +extern int gameport_has_config(int port); +extern const char *gameport_get_internal_name(int port); +extern int gameport_get_from_internal_name(const char *str); + #ifdef EMU_DEVICE_H extern const device_t gameport_device; extern const device_t gameport_201_device; @@ -136,7 +146,7 @@ extern const device_t *standalone_gameport_type; #endif extern int gameport_instance_id; extern plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS]; -extern joystick_t joystick_state[MAX_JOYSTICKS]; +extern joystick_t joystick_state[GAMEPORT_MAX][MAX_JOYSTICKS]; extern int joysticks_present; extern int joystick_type; @@ -169,10 +179,21 @@ extern const joystick_if_t joystick_2axis_6button; extern const joystick_if_t joystick_2axis_8button; extern const joystick_if_t joystick_ch_flightstick_pro; +extern const joystick_if_t joystick_ch_flightstick_pro_ch_pedals; extern const joystick_if_t joystick_sw_pad; extern const joystick_if_t joystick_tm_fcs; +extern const joystick_if_t joystick_tm_fcs_rcs; + +extern int gameport_available(int); +extern int gameport_has_config(int); +extern const char *gameport_get_internal_name(int); +extern int gampeport_get_from_internal_name(char *); +#ifdef EMU_DEVICE_H +extern const device_t *gameport_getdevice(int); +#endif + #ifdef __cplusplus } #endif diff --git a/src/include/86box/hdc.h b/src/include/86box/hdc.h index a3b667e2e..0a5985370 100644 --- a/src/include/86box/hdc.h +++ b/src/include/86box/hdc.h @@ -13,7 +13,7 @@ * Authors: Miran Grca, * Fred N. van Kempen, * - * Copyright 2016-2020 Miran Grca. + * Copyright 2016-2025 Miran Grca. * Copyright 2017-2020 Fred N. van Kempen. */ #ifndef EMU_HDC_H @@ -22,11 +22,6 @@ #define MFM_NUM 2 /* 2 drives per controller supported */ #define ESDI_NUM 2 /* 2 drives per controller supported */ #define XTA_NUM 2 /* 2 drives per controller supported */ -#define IDE_NUM 10 /* 8 drives per AT IDE + 2 for XT IDE */ -#define ATAPI_NUM 8 /* 8 drives per AT IDE */ -#define SCSI_NUM 16 /* theoretically the controller can have at \ - * least 7 devices, with each device being \ - * able to support 8 units, but hey... */ /* Controller types. */ #define HDC_NONE 0 @@ -53,15 +48,20 @@ extern const device_t st506_xt_toshiba_t1200_device; /* st506_xt_toshiba_t1 extern const device_t esdi_at_wd1007vse1_device; /* esdi_at */ extern const device_t esdi_ps2_device; /* esdi_mca */ +extern const device_t esdi_integrated_device; /* esdi_mca */ extern const device_t ide_isa_device; /* isa_ide */ +extern const device_t ide_isa_sec_device; /* isa_ide sec*/ extern const device_t ide_isa_2ch_device; /* isa_ide_2ch */ -extern const device_t ide_isa_2ch_opt_device; /* isa_ide_2ch_opt */ extern const device_t ide_vlb_device; /* vlb_ide */ +extern const device_t ide_vlb_sec_device; /* vlb_ide sec */ 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_sec_device; /* pci_ide sec */ extern const device_t ide_pci_2ch_device; /* pci_ide_2ch */ +extern const device_t ide_pci_ter_qua_2ch_device; /* pci_ide_ter_qua_2ch */ + extern const device_t ide_ali1489_device; /* ALi M1489 */ extern const device_t ide_ali5213_device; /* ALi M5213 */ @@ -78,10 +78,14 @@ extern const device_t ide_cmd640_pci_single_channel_sec_device; /* CMD PCI-640B 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_cmd646_ter_qua_device; /* CMD PCI-646 (Tertiary and quaternary channels) */ 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_rz1000_pci_device; /* PC Technology RZ-1000 PCI */ +extern const device_t ide_rz1000_pci_single_channel_device; /* PC Technology RZ-1000 PCI (Only primary channel) */ + extern const device_t ide_um8673f_device; /* UMC UM8673F */ extern const device_t ide_um8886af_device; /* UMC UM8886AF */ @@ -101,10 +105,12 @@ extern const device_t mcide_device; extern const device_t xta_wdxt150_device; /* xta_wdxt150 */ extern const device_t xta_hd20_device; /* EuroPC internal */ -extern const device_t xtide_device; /* xtide_xt */ -extern const device_t xtide_at_device; /* xtide_at */ -extern const device_t xtide_acculogic_device; /* xtide_ps2 */ -extern const device_t xtide_at_ps2_device; /* xtide_at_ps2 */ +extern const device_t xtide_device; /* xtide_xt */ +extern const device_t xtide_at_device; /* xtide_at */ +extern const device_t xtide_at_2ch_device; /* xtide_at_2ch */ +extern const device_t xtide_acculogic_device; /* xtide_ps2 */ +extern const device_t xtide_at_ps2_device; /* xtide_at_ps2 */ +extern const device_t xtide_at_ps2_2ch_device; /* xtide_at_ps2_2ch */ /* Miscellaneous */ extern const device_t lba_enhancer_device; diff --git a/src/include/86box/hdc_ide.h b/src/include/86box/hdc_ide.h index 9094f7f00..41fb7703e 100644 --- a/src/include/86box/hdc_ide.h +++ b/src/include/86box/hdc_ide.h @@ -19,20 +19,23 @@ #ifndef EMU_IDE_H #define EMU_IDE_H +#define IDE_NUM 10 /* 8 drives per AT IDE + 2 for XT IDE */ +#define ATAPI_NUM 10 /* 8 drives per AT IDE + 2 for XT IDE */ + #define IDE_BUS_MAX 4 #define IDE_CHAN_MAX 2 -#define HDC_PRIMARY_BASE 0x01F0 -#define HDC_PRIMARY_SIDE 0x03F6 +#define HDC_PRIMARY_BASE 0x01f0 +#define HDC_PRIMARY_SIDE 0x03f6 #define HDC_PRIMARY_IRQ 14 #define HDC_SECONDARY_BASE 0x0170 #define HDC_SECONDARY_SIDE 0x0376 #define HDC_SECONDARY_IRQ 15 -#define HDC_TERTIARY_BASE 0x01E8 -#define HDC_TERTIARY_SIDE 0x03EE +#define HDC_TERTIARY_BASE 0x01e8 +#define HDC_TERTIARY_SIDE 0x03ee #define HDC_TERTIARY_IRQ 11 #define HDC_QUATERNARY_BASE 0x0168 -#define HDC_QUATERNARY_SIDE 0x036E +#define HDC_QUATERNARY_SIDE 0x036e #define HDC_QUATERNARY_IRQ 10 enum { @@ -121,15 +124,17 @@ typedef struct ide_s { double pending_delay; #ifdef SCSI_DEVICE_H - int (*get_max)(int ide_has_dma, int type); - int (*get_timings)(int ide_has_dma, int type); - void (*identify)(struct ide_s *ide, int ide_has_dma); - void (*stop)(scsi_common_t *sc); - void (*packet_command)(scsi_common_t *sc, uint8_t *cdb); + int (*get_max)(const struct ide_s *ide, const int ide_has_dma, const int type); + int (*get_timings)(const struct ide_s *ide, const int ide_has_dma, const int type); + void (*identify)(const struct ide_s *ide, const int ide_has_dma); + void (*stop)(const scsi_common_t *sc); + void (*packet_command)(scsi_common_t *sc, const uint8_t *cdb); void (*device_reset)(scsi_common_t *sc); uint8_t (*phase_data_out)(scsi_common_t *sc); void (*command_stop)(scsi_common_t *sc); void (*bus_master_error)(scsi_common_t *sc); + void (*read)(scsi_common_t *sc); + void (*write)(scsi_common_t *sc); #else void * get_max; void * get_timings; @@ -142,10 +147,8 @@ typedef struct ide_s { #endif } ide_t; -#ifdef EMU_HDC_H extern ide_t *ide_drives[IDE_NUM]; #endif -#endif /* Type: 0 = PIO, @@ -198,7 +201,7 @@ extern uint8_t ide_read_alt_status(uint16_t addr, void *priv); extern uint16_t ide_readw(uint16_t addr, void *priv); extern void ide_set_bus_master(int board, - int (*dma)(uint8_t *data, int transfer_length, int out, void *priv), + int (*dma)(uint8_t *data, int transfer_length, int total_length, int out, void *priv), void (*set_irq)(uint8_t status, void *priv), void *priv); extern void win_cdrom_eject(uint8_t id); diff --git a/src/include/86box/hdc_ide_sff8038i.h b/src/include/86box/hdc_ide_sff8038i.h index 3a69fdfac..79075b8b2 100644 --- a/src/include/86box/hdc_ide_sff8038i.h +++ b/src/include/86box/hdc_ide_sff8038i.h @@ -63,7 +63,7 @@ extern const device_t sff8038i_device; extern void sff_bus_master_handler(sff8038i_t *dev, int enabled, uint16_t base); extern void sff_bus_master_set_irq(uint8_t status, void *priv); -extern int sff_bus_master_dma(uint8_t *data, int transfer_length, int out, void *priv); +extern int sff_bus_master_dma(uint8_t *data, int transfer_length, int total_length, int out, void *priv); extern void sff_bus_master_write(uint16_t port, uint8_t val, void *priv); extern uint8_t sff_bus_master_read(uint16_t port, void *priv); diff --git a/src/include/86box/hdd.h b/src/include/86box/hdd.h index a4bded58f..53514740d 100644 --- a/src/include/86box/hdd.h +++ b/src/include/86box/hdd.h @@ -138,55 +138,63 @@ typedef struct hdd_zone_t { /* Define the virtual Hard Disk. */ typedef struct hard_disk_t { - uint8_t id; + uint8_t id; + union { - uint8_t channel; /* Needed for Settings to reduce the number of if's */ + /* Needed for Settings to reduce the number of if's */ + uint8_t channel; - uint8_t mfm_channel; /* Should rename and/or unionize */ - uint8_t esdi_channel; - uint8_t xta_channel; - uint8_t ide_channel; - uint8_t scsi_id; + uint8_t mfm_channel; + uint8_t esdi_channel; + uint8_t xta_channel; + uint8_t ide_channel; + uint8_t scsi_id; }; - uint8_t bus; - uint8_t bus_mode; /* Bit 0 = PIO suported; - Bit 1 = DMA supportd. */ - uint8_t wp; /* Disk has been mounted READ-ONLY */ - uint8_t pad; - uint8_t pad0; - void *priv; + uint8_t bus_type; + uint8_t bus_mode; /* Bit 0 = PIO suported; + Bit 1 = DMA supportd. */ + uint8_t wp; /* Disk has been mounted + READ-ONLY */ + uint8_t pad; + uint8_t pad0; - char fn[1024]; /* Name of current image file */ - char vhd_parent[1041]; /* Differential VHD parent file */ + void *priv; - uint32_t seek_pos; - uint32_t seek_len; - uint32_t base; - uint32_t spt; - uint32_t hpc; /* Physical geometry parameters */ - uint32_t tracks; - const char *model; + char fn[1024]; /* Name of current image file */ + /* Differential VHD parent file */ + char vhd_parent[1280]; - hdd_zone_t zones[HDD_MAX_ZONES]; - uint32_t num_zones; - hdd_cache_t cache; - uint32_t phy_cyl; - uint32_t phy_heads; - uint32_t rpm; - uint8_t max_multiple_block; + uint32_t seek_pos; + uint32_t seek_len; + uint32_t base; + uint32_t spt; /* Physical geometry parameters */ + uint32_t hpc; + uint32_t tracks; + uint32_t speed_preset; - uint32_t cur_cylinder; - uint32_t cur_track; - uint32_t cur_addr; + uint32_t num_zones; + uint32_t phy_cyl; + uint32_t phy_heads; + uint32_t rpm; + uint32_t cur_cylinder; + uint32_t cur_track; + uint32_t cur_addr; + uint32_t vhd_blocksize; - uint32_t speed_preset; - uint32_t vhd_blocksize; + uint8_t max_multiple_block; + uint8_t pad1[3]; - double avg_rotation_lat_usec; - double full_stroke_usec; - double head_switch_usec; - double cyl_switch_usec; + const char *model; + + hdd_zone_t zones[HDD_MAX_ZONES]; + + hdd_cache_t cache; + + double avg_rotation_lat_usec; + double full_stroke_usec; + double head_switch_usec; + double cyl_switch_usec; } hard_disk_t; extern hard_disk_t hdd[HDD_NUM]; diff --git a/src/include/86box/i8080.h b/src/include/86box/i8080.h deleted file mode 100644 index 9a25b5d1b..000000000 --- a/src/include/86box/i8080.h +++ /dev/null @@ -1,69 +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. - * - * 8080 CPU emulation (header). - * - * - * - * Authors: Cacodemon345 - * - * Copyright 2022 Cacodemon345 - */ - -#include - -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; - uint8_t flags; - }; - }; - union { - uint16_t bc; - struct { - uint8_t b; - uint8_t c; - }; - }; - union { - uint16_t de; - struct { - uint8_t d; - uint8_t e; - }; - }; - union { - uint16_t hl; - struct { - uint8_t h; - uint8_t l; - }; - }; - 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); - void (*startclock)(void); - void (*endclock)(void); - void (*checkinterrupts)(void); - uint8_t (*fetchinstruction)(void *); -} i8080; - -#define C_FLAG_I8080 (1 << 0) -#define P_FLAG_I8080 (1 << 2) -#define AC_FLAG_I8080 (1 << 4) -#define Z_FLAG_I8080 (1 << 6) -#define S_FLAG_I8080 (1 << 7) diff --git a/src/include/86box/ini.h b/src/include/86box/ini.h index d52620f69..bb250e697 100644 --- a/src/include/86box/ini.h +++ b/src/include/86box/ini.h @@ -31,6 +31,7 @@ typedef void *ini_section_t; extern ini_t ini_new(void); extern ini_t ini_read(const char *fn); +extern void ini_strip_quotes(ini_t ini); extern void ini_write(ini_t ini, const char *fn); extern void ini_dump(ini_t ini); extern void ini_close(ini_t ini); @@ -58,6 +59,7 @@ extern void ini_section_set_hex20(ini_section_t section, const char *name, i 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, const char *name, wchar_t *val); +extern int ini_has_entry(ini_section_t self, const char *name); #define ini_delete_var(ini, head, name) ini_section_delete_var(ini_find_section(ini, head), name) diff --git a/src/include/86box/isamem.h b/src/include/86box/isamem.h index 51fe50e33..93f417e3e 100644 --- a/src/include/86box/isamem.h +++ b/src/include/86box/isamem.h @@ -42,7 +42,6 @@ * (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 EMU_ISAMEM_H #define EMU_ISAMEM_H @@ -52,17 +51,12 @@ extern "C" { #endif -/* Global variables. */ -extern const device_t isamem_device; -extern const device_t isamem_brat80_device; -extern const device_t isamem_ev159_device; - /* Functions. */ extern void isamem_reset(void); extern const char *isamem_get_name(int t); extern const char *isamem_get_internal_name(int t); -extern int isamem_get_from_internal_name(const char *s); +extern int isamem_get_from_internal_name(const char *str); extern const device_t *isamem_get_device(int t); extern int isamem_has_config(int board); diff --git a/src/include/86box/isarom.h b/src/include/86box/isarom.h new file mode 100644 index 000000000..91cfa15a9 --- /dev/null +++ b/src/include/86box/isarom.h @@ -0,0 +1,37 @@ +/* + * 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 ISA ROM card Expansions. + * + * Authors: Jasmine Iwanek, + * + * Copyright 2025 Jasmine Iwanek. + */ +#ifndef EMU_ISAROM_H +#define EMU_ISAROM_H + +#define ISAROM_MAX 4 /* max #cards in system */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Functions. */ +extern void isarom_reset(void); + +extern const char *isarom_get_name(int t); +extern const char *isarom_get_internal_name(int t); +extern int isarom_get_from_internal_name(const char *str); +extern const device_t *isarom_get_device(int t); +extern int isarom_has_config(int board); + +#ifdef __cplusplus +} +#endif + +#endif /*EMU_ISAROM_H*/ diff --git a/src/include/86box/isartc.h b/src/include/86box/isartc.h index 0224180b3..815daa5d6 100644 --- a/src/include/86box/isartc.h +++ b/src/include/86box/isartc.h @@ -42,7 +42,6 @@ * (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 EMU_ISARTC_H #define EMU_ISARTC_H @@ -50,13 +49,11 @@ extern "C" { #endif -/* Global variables. */ - /* Functions. */ extern void isartc_reset(void); extern const char *isartc_get_internal_name(int t); -extern int isartc_get_from_internal_name(char *s); +extern int isartc_get_from_internal_name(const char *str); extern const device_t *isartc_get_device(int t); extern int isartc_has_config(int board); diff --git a/src/include/86box/keyboard.h b/src/include/86box/keyboard.h index 225ab3936..62938fae4 100644 --- a/src/include/86box/keyboard.h +++ b/src/include/86box/keyboard.h @@ -15,7 +15,7 @@ * Fred N. van Kempen, * * Copyright 2008-2019 Sarah Walker. - * Copyright 2016-2019 Miran Grca. + * Copyright 2016-2025 Miran Grca. * Copyright 2017-2019 Fred N. van Kempen. */ @@ -54,16 +54,16 @@ typedef struct kbc_at_port_t { 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; + 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; @@ -194,8 +194,8 @@ typedef struct scancode { extern "C" { #endif -extern uint8_t keyboard_mode; -extern int keyboard_scan; +extern uint8_t keyboard_mode; +extern int keyboard_scan; extern uint16_t scancode_map[768]; @@ -224,39 +224,41 @@ extern const device_t keyboard_xt86_device; extern const device_t keyboard_xt_compaq_device; extern const device_t keyboard_xt_t1x00_device; extern const device_t keyboard_tandy_device; -# ifdef USE_LASERXT extern const device_t keyboard_xt_lxt3_device; -# endif /* USE_LASERXT */ extern const device_t keyboard_xt_olivetti_device; extern const device_t keyboard_xt_zenith_device; extern const device_t keyboard_xt_hyundai_device; +extern const device_t keyboard_xt_fe2010_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_compaq_device; +extern const device_t keyboard_at_phoenix_device; +extern const device_t keyboard_at_ncr_device; +extern const device_t keyboard_at_olivetti_device; +extern const device_t keyboard_at_siemens_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_compaq_device; extern const device_t keyboard_ps2_holtek_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_phoenix_device; extern const device_t keyboard_ps2_mca_1_device; extern const device_t keyboard_ps2_mca_2_device; +extern const device_t keyboard_ps2_olivetti_device; +extern const device_t keyboard_ps2_phoenix_device; extern const device_t keyboard_ps2_quadtel_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_pci_device; 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_phoenix_pci_device; extern const device_t keyboard_ps2_tg_ami_pci_device; extern const device_t keyboard_at_generic_device; @@ -269,9 +271,12 @@ extern void keyboard_poll_host(void); extern void keyboard_process(void); extern uint16_t keyboard_convert(int ch); extern void keyboard_input(int down, uint16_t scan); -extern void keyboard_update_states(uint8_t cl, uint8_t nl, uint8_t sl); +extern void keyboard_all_up(void); +extern void keyboard_update_states(uint8_t cl, uint8_t nl, uint8_t sl, uint8_t kl); 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_in_reset(uint8_t in_reset); +extern uint8_t keyboard_get_in_reset(void); +extern void keyboard_get_states(uint8_t *cl, uint8_t *nl, uint8_t *sl, uint8_t *kl); extern void keyboard_set_states(uint8_t cl, uint8_t nl, uint8_t sl); extern int keyboard_recv(uint16_t key); extern int keyboard_recv_ui(uint16_t key); @@ -279,13 +284,17 @@ 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 kbc_at_set_ps2(void *priv, uint8_t ps2); +extern uint8_t kbc_at_read_p(void *priv, uint8_t port, uint8_t mask); +extern void kbc_at_write_p(void *priv, uint8_t port, uint8_t mask, uint8_t val); extern void kbc_at_set_fast_reset(uint8_t new_fast_reset); -extern void kbc_at_handler(int set, void *priv); +extern void kbc_at_port_handler(int num, int set, uint16_t port, void *priv); +extern void kbc_at_handler(int set, uint16_t port, void *priv); +extern void kbc_at_set_irq(int num, uint16_t irq, void *priv); +extern void kbc_at_dev_queue_reset(atkbc_dev_t *dev, uint8_t reset_main); 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); diff --git a/src/include/86box/log.h b/src/include/86box/log.h index 9d3568069..80ed6d108 100644 --- a/src/include/86box/log.h +++ b/src/include/86box/log.h @@ -6,42 +6,48 @@ * * This file is part of the 86Box distribution. * - * Main include file for the application. - * - * + * New logging system handler header. * * Authors: Miran Grca, * Fred N. van Kempen, + * Connor Hyde, * - * Copyright 2021 Miran Grca. - * Copyright 2021 Fred N. van Kempen. + * Copyright 2021-25 Miran Grca. + * Copyright 2021-25 Fred N. van Kempen. + * Copyright 2025 Connor Hyde. */ #ifndef EMU_LOG_H #define EMU_LOG_H -#ifndef RELEASE_BUILD - # ifdef __cplusplus extern "C" { # endif +#ifdef __NetBSD__ +/* Doesn't compile on NetBSD without this include */ +#include +#endif + +#define LOG_SIZE_BUFFER 1024 /* Log size buffer */ +#define LOG_SIZE_BUFFER_CYCLIC_LINES 32 /* Cyclic log size buffer (number of lines that should be cehcked) */ +#define LOG_MINIMUM_REPEAT_ORDER 4 /* Minimum repeat size */ + /* Function prototypes. */ extern void log_set_suppr_seen(void *priv, int suppr_seen); extern void log_set_dev_name(void *priv, char *dev_name); -# ifdef HAVE_STDARG_H +#ifndef RELEASE_BUILD extern void log_out(void *priv, const char *fmt, va_list); +extern void log_out_cyclic(void* priv, const char *fmt, va_list); +#endif /*RELEASE_BUILD*/ extern void log_fatal(void *priv, const char *fmt, ...); -# endif -extern void *log_open(char *dev_name); +extern void log_warning(void *priv, const char *fmt, ...); +extern void *log_open(const char *dev_name); +extern void *log_open_cyclic(const char *dev_name); extern void log_close(void *priv); # ifdef __cplusplus } # endif -#else -# define log_fatal(priv, fmt, ...) fatal(fmt, ...) -#endif /*RELEASE_BUILD*/ - #endif /*EMU_LOG_H*/ diff --git a/src/include/86box/lpt.h b/src/include/86box/lpt.h index 4e95b64c3..c13d70291 100644 --- a/src/include/86box/lpt.h +++ b/src/include/86box/lpt.h @@ -25,39 +25,49 @@ typedef struct lpt_device_t { void (*close)(void *priv); void (*write_data)(uint8_t val, void *priv); void (*write_ctrl)(uint8_t val, void *priv); - uint8_t (*read_data)(void *priv); + void (*autofeed)(uint8_t val,void *priv); + void (*strobe)(uint8_t old, uint8_t val,void *priv); uint8_t (*read_status)(void *priv); uint8_t (*read_ctrl)(void *priv); + void (*epp_write_data)(uint8_t is_addr, uint8_t val, void *priv); + void (*epp_request_read)(uint8_t is_addr, void *priv); } lpt_device_t; +extern void lpt_set_ext(int port, uint8_t ext); +extern void lpt_set_ecp(int port, uint8_t ecp); +extern void lpt_set_epp(int port, uint8_t epp); +extern void lpt_set_lv2(int port, uint8_t lv2); +extern void lpt_reset(void); +extern void lpt_close(void); extern void lpt_init(void); -extern void lpt_port_init(int i, uint16_t port); +extern void lpt_port_setup(int i, uint16_t port); extern void lpt_port_irq(int i, uint8_t irq); +extern void lpt_port_dma(int i, uint8_t dma); extern void lpt_port_remove(int i); extern void lpt1_remove_ams(void); -#define lpt1_init(a) lpt_port_init(0, a) +#define lpt1_setup(a) lpt_port_setup(0, a) #define lpt1_irq(a) lpt_port_irq(0, a) #define lpt1_remove() lpt_port_remove(0) -#define lpt2_init(a) lpt_port_init(1, a) +#define lpt2_setup(a) lpt_port_setup(1, a) #define lpt2_irq(a) lpt_port_irq(1, a) #define lpt2_remove() lpt_port_remove(1) -#define lpt3_init(a) lpt_port_init(2, a) +#define lpt3_setup(a) lpt_port_setup(2, a) #define lpt3_irq(a) lpt_port_irq(2, a) #define lpt3_remove() lpt_port_remove(2) -#define lpt4_init(a) lpt_port_init(3, a) +#define lpt4_setup(a) lpt_port_setup(3, a) #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_setup(a) lpt_port_setup(4, a) #define lpt5_irq(a) lpt_port_irq(4, a) #define lpt5_remove() lpt_port_remove(4) -#define lpt6_init(a) lpt_port_init(5, a) +#define lpt6_setup(a) lpt_port_setup(5, a) #define lpt6_irq(a) lpt_port_irq(5, a) #define lpt6_remove() lpt_port_remove(5) #endif @@ -68,31 +78,62 @@ void lpt_devices_close(void); typedef struct lpt_port_t { uint8_t enabled; uint8_t irq; + uint8_t irq_state; + uint8_t dma; uint8_t dat; uint8_t ctrl; + uint8_t ext; + uint8_t epp; + uint8_t ecp; + uint8_t ecr; + uint8_t in_dat; + uint8_t fifo_stat; + uint8_t dma_stat; + uint8_t state; + uint8_t autofeed; + uint8_t strobe; + uint8_t lv2; + uint8_t pad[7]; uint16_t addr; - uint16_t pad0; + uint16_t id; + uint16_t pad0[2]; int device; int enable_irq; lpt_device_t *dt; +#ifdef FIFO_H + fifo16_t *fifo; +#else + void *fifo; +#endif void *priv; + + pc_timer_t fifo_out_timer; } lpt_port_t; +typedef enum { + LPT_STATE_IDLE = 0, + LPT_STATE_READ_DMA, + LPT_STATE_WRITE_FIFO +} lpt_state_t; + extern lpt_port_t lpt_ports[PARALLEL_MAX]; -extern void lpt_write(uint16_t port, uint8_t val, void *priv); -extern uint8_t lpt_read(uint16_t port, void *priv); +extern void lpt_write(uint16_t port, uint8_t val, void *priv); -extern uint8_t lpt_read_port(int port, uint16_t reg); +extern void lpt_write_to_fifo(void *priv, uint8_t val); -extern uint8_t lpt_read_status(int port); -extern void lpt_irq(void *priv, int raise); +extern uint8_t lpt_read(uint16_t port, void *priv); + +extern uint8_t lpt_read_port(int port, uint16_t reg); + +extern uint8_t lpt_read_status(int port); +extern void lpt_irq(void *priv, int raise); + +extern int lpt_device_get_from_internal_name(const char *s); extern const char *lpt_device_get_name(int id); extern const char *lpt_device_get_internal_name(int id); -extern int lpt_device_get_from_internal_name(char *s); - extern const lpt_device_t lpt_dac_device; extern const lpt_device_t lpt_dac_stereo_device; diff --git a/src/include/86box/m_pcjr.h b/src/include/86box/m_pcjr.h new file mode 100644 index 000000000..c6cb33588 --- /dev/null +++ b/src/include/86box/m_pcjr.h @@ -0,0 +1,74 @@ +/* + * 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. + * + * Header files for the PCjr keyboard and video subsystems. + * + * + * + * Authors: Connor Hyde, + * + * Copyright 2025 starfrost + */ + +#pragma once + +#define PCJR_RGB 0 +#define PCJR_COMPOSITE 1 +#define PCJR_RGB_NO_BROWN 4 +#define PCJR_RGB_IBM_5153 5 + +typedef struct pcjr_s +{ + /* Video Controller stuff. */ + mem_mapping_t mapping; + uint8_t crtc[32]; + int crtcreg; + int array_index; + uint8_t array[32]; + int array_ff; + int memctrl; + uint8_t status; + int addr_mode; + uint8_t *vram; + uint8_t *b8000; + int linepos; + int displine; + int scanline; + int vc; + int dispon; + int cursorvisible; // Is the cursor visible on the current scanline? + int cursoron; + int blink; + int vsynctime; + int fullchange; + int vadj; + uint16_t memaddr; + uint16_t memaddr_backup; + uint64_t dispontime; + uint64_t dispofftime; + pc_timer_t timer; + int firstline; + int lastline; + int composite; + int apply_hd; + + /* Keyboard Controller stuff. */ + int latched; + int data; + int serial_data[44]; + int serial_pos; + uint8_t pa; + uint8_t pb; + pc_timer_t send_delay_timer; + +} pcjr_t; + +void pcjr_recalc_timings(pcjr_t *pcjr); + +// Note: This is a temporary solution until the pcjr video is made its own gfx card +void pcjr_vid_init(pcjr_t *pcjr); \ No newline at end of file diff --git a/src/include/86box/m_tandy.h b/src/include/86box/m_tandy.h new file mode 100644 index 000000000..2d0100c1a --- /dev/null +++ b/src/include/86box/m_tandy.h @@ -0,0 +1,95 @@ +/* + * 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. + * + * Header files for the Tandy keyboard and video subsystems. + * + * + * + * Authors: Connor Hyde, + * + * Copyright 2025 starfrost + */ + +typedef struct t1kvid_t { + mem_mapping_t mapping; + mem_mapping_t vram_mapping; + + uint8_t crtc[32]; + int crtcreg; + + int array_index; + uint8_t array[256]; + int memctrl; + uint8_t mode; + uint8_t col; + uint8_t status; + + uint8_t *vram; + uint8_t *b8000; + uint32_t b8000_mask; + uint32_t b8000_limit; + uint8_t planar_ctrl; + uint8_t lp_strobe; + + int linepos; + int displine; + int scanline; + int vc; + int dispon; + int cursorvisible; + int cursoron; + int blink; + int fullchange; + int vsynctime; + int vadj; + uint16_t memaddr; + uint16_t memaddr_backup; + + uint64_t dispontime; + uint64_t dispofftime; + pc_timer_t timer; + int firstline; + int lastline; + + int composite; +} t1kvid_t; + +typedef struct t1keep_t { + char *path; + + int state; + int count; + int addr; + int clk; + uint16_t data; + uint16_t store[64]; +} t1keep_t; + +typedef struct tandy_t { + mem_mapping_t ram_mapping; + mem_mapping_t rom_mapping; /* SL2 */ + + uint8_t *rom; /* SL2 */ + uint8_t ram_bank; + uint8_t rom_bank; /* SL2 */ + int rom_offset; /* SL2 */ + + uint32_t base; + uint32_t mask; + int is_hx; + int is_sl2; + + t1kvid_t *vid; +} tandy_t; + +void tandy_vid_init(tandy_t* dev); +uint8_t tandy_vid_in(uint16_t addr, void* priv); +void tandy_vid_out(uint16_t addr, uint8_t val, void *priv); + +void tandy_vid_close(void* priv); +void tandy_recalc_address_sl(tandy_t* dev); //this function is needed by both m_ and vid_tandy.c diff --git a/src/include/86box/machine.h b/src/include/86box/machine.h index ad8b47638..39fb1a933 100644 --- a/src/include/86box/machine.h +++ b/src/include/86box/machine.h @@ -23,34 +23,32 @@ #define EMU_MACHINE_H /* Machine feature flags. */ -#define MACHINE_BUS_NONE 0x00000000 /* sys has no bus */ +#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_CASSETTE 0x00000002 /* sys has cassette port */ -#define MACHINE_BUS_CARTRIDGE 0x00000004 /* sys has two cartridge bays */ -#define MACHINE_BUS_PCJR 0x00000008 /* sys has PCjr sidecar bus */ -#define MACHINE_BUS_DM_KBC 0x00000010 /* system has keyboard controller that supports - both XT and AT keyboards */ +#define MACHINE_BUS_CASSETTE 0x00000001 /* sys has cassette port */ +#define MACHINE_BUS_SIDECAR 0x00000002 /* sys has PCjr sidecar bus */ +#define MACHINE_BUS_ISA 0x00000004 /* sys has ISA bus */ +#define MACHINE_BUS_XT_KBD 0x00000008 /* sys has an XT keyboard port */ +#define MACHINE_BUS_CBUS 0x00000010 /* sys has C-BUS bus */ #define MACHINE_BUS_ISA16 0x00000020 /* sys has ISA16 bus - PC/AT architecture */ -#define MACHINE_BUS_CBUS 0x00000040 /* sys has C-BUS bus */ -#define MACHINE_BUS_PCMCIA 0x00000080 /* sys has PCMCIA bus */ -#define MACHINE_BUS_PS2_LATCH 0x00000100 /* system has PS/2 keyboard controller IRQ latch */ +#define MACHINE_BUS_AT_KBD 0x00000040 /* sys has an AT keyboard port */ +#define MACHINE_BUS_MCA 0x00000080 /* sys has MCA bus */ +#define MACHINE_BUS_MCA32 0x00000100 /* sys has MCA32 bus */ #define MACHINE_BUS_PS2_PORTS 0x00000200 /* system has PS/2 keyboard and mouse ports */ -#define MACHINE_BUS_PS2 (MACHINE_BUS_PS2_LATCH | MACHINE_BUS_PS2_PORTS) -#define MACHINE_BUS_HIL 0x00000400 /* system has HP HIL keyboard and mouse ports */ -#define MACHINE_BUS_EISA 0x00000800 /* sys has EISA bus */ -#define MACHINE_BUS_AT32 0x00001000 /* sys has Mylex AT/32 local bus */ -#define MACHINE_BUS_OLB 0x00002000 /* sys has OPTi local bus */ -#define MACHINE_BUS_VLB 0x00004000 /* sys has VL bus */ -#define MACHINE_BUS_MCA 0x00008000 /* sys has MCA bus */ +#define MACHINE_BUS_PS2 MACHINE_BUS_PS2_PORTS +#define MACHINE_BUS_PCMCIA 0x00000400 /* sys has PCMCIA bus */ +#define MACHINE_BUS_HIL 0x00000800 /* system has HP HIL keyboard and mouse ports */ +#define MACHINE_BUS_EISA 0x00001000 /* sys has EISA bus */ +#define MACHINE_BUS_AT32 0x00002000 /* sys has Mylex AT/32 local bus */ +#define MACHINE_BUS_OLB 0x00004000 /* sys has OPTi local bus */ +#define MACHINE_BUS_VLB 0x00008000 /* sys has VL bus */ #define MACHINE_BUS_PCI 0x00010000 /* sys has PCI bus */ #define MACHINE_BUS_CARDBUS 0x00020000 /* sys has CardBus bus */ #define MACHINE_BUS_USB 0x00040000 /* sys has USB bus */ #define MACHINE_BUS_AGP 0x00080000 /* sys has AGP bus */ #define MACHINE_BUS_AC97 0x00100000 /* 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 */ +#define MACHINE_CASSETTE (MACHINE_BUS_CASSETTE) /* sys has cassette port */ /* Combined flags. */ #define MACHINE_PC (MACHINE_BUS_ISA) /* sys is PC/XT-compatible (ISA) */ #define MACHINE_AT (MACHINE_BUS_ISA | MACHINE_BUS_ISA16) /* sys is AT-compatible (ISA + ISA16) */ @@ -69,18 +67,19 @@ #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_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_PCIONLY (MACHINE_PS2_NOISA & ~MACHINE_BUS_AGP) /* sys is PCI 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_CASSETTE | MACHINE_PC) /* sys is IBM PC 5150 */ +#define MACHINE_PCJR (MACHINE_CASSETTE | MACHINE_BUS_SIDECAR) /* 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_PCIONLY (MACHINE_PS2_NOISA & ~MACHINE_BUS_AGP) /* sys is PCI 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_SOFTFLOAT_ONLY 0x00000001 /* sys requires SoftFloat FPU */ @@ -93,7 +92,8 @@ #define MACHINE_LPT_PRI 0x00000080 /* sys has int pri LPT */ #define MACHINE_LPT_SEC 0x00000100 /* sys has int sec LPT */ #define MACHINE_LPT_TER 0x00000200 /* sys has int ter LPT */ -#define MACHINE_LPT_QUA 0x00000400 /* sys has int qua LPT */ +#define MACHINE_PS2_KBC 0x00000400 /* sys has a PS/2 keyboard controller */ + /* this is separate from having PS/2 ports */ #define MACHINE_UART_PRI 0x00000800 /* sys has int pri UART */ #define MACHINE_UART_SEC 0x00001000 /* sys has int sec UART */ #define MACHINE_UART_TER 0x00002000 /* sys has int ter UART */ @@ -101,12 +101,12 @@ #define MACHINE_GAMEPORT 0x00008000 /* sys has int game port */ #define MACHINE_SOUND 0x00010000 /* sys has int sound */ #define MACHINE_NIC 0x00020000 /* sys has int NIC */ -#define MACHINE_MODEM 0x00040000 /* sys has int modem */ +#define MACHINE_AX 0x00040000 /* sys adheres to Japanese AX standard */ /* Feature flags for advanced devices. */ #define MACHINE_APM 0x00080000 /* sys has APM */ #define MACHINE_ACPI 0x00100000 /* sys has ACPI */ -#define MACHINE_HWM 0x00200000 /* sys has hw monitor */ -#define MACHINE_COREBOOT 0x00400000 /* sys has coreboot BIOS */ +#define MACHINE_PCI_INTERNAL 0x00200000 /* sys has only internal PCI */ +#define MACHINE_CARTRIDGE 0x00400000 /* sys has cartridge bays */ /* Feature flags for internal storage controllers. */ #define MACHINE_MFM 0x00800000 /* sys has int MFM/RLL */ #define MACHINE_XTA 0x01000000 /* sys has int XTA */ @@ -173,20 +173,21 @@ enum { 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 + MACHINE_TYPE_486_S3_PCI = 11, + MACHINE_TYPE_486_MISC = 12, + MACHINE_TYPE_SOCKET4 = 13, + MACHINE_TYPE_SOCKET5 = 14, + MACHINE_TYPE_SOCKET7_3V = 15, + MACHINE_TYPE_SOCKET7 = 16, + MACHINE_TYPE_SOCKETS7 = 17, + MACHINE_TYPE_SOCKET8 = 18, + MACHINE_TYPE_SLOT1 = 19, + MACHINE_TYPE_SLOT1_2 = 20, + MACHINE_TYPE_SLOT1_370 = 21, + MACHINE_TYPE_SLOT2 = 22, + MACHINE_TYPE_SOCKET370 = 23, + MACHINE_TYPE_MISC = 24, + MACHINE_TYPE_MAX = 25 }; enum { @@ -196,6 +197,7 @@ enum { MACHINE_CHIPSET_GC100A, MACHINE_CHIPSET_GC103, MACHINE_CHIPSET_HT18, + MACHINE_CHIPSET_ACC_2036, MACHINE_CHIPSET_ACC_2168, MACHINE_CHIPSET_ALI_M1217, MACHINE_CHIPSET_ALI_M6117, @@ -207,7 +209,10 @@ enum { MACHINE_CHIPSET_ALI_ALADDIN_V, MACHINE_CHIPSET_ALI_ALADDIN_PRO_II, MACHINE_CHIPSET_SCAT, + MACHINE_CHIPSET_SCAT_SX, MACHINE_CHIPSET_NEAT, + MACHINE_CHIPSET_NEAT_SX, + MACHINE_CHIPSET_CT_AT, MACHINE_CHIPSET_CT_386, MACHINE_CHIPSET_CT_CS4031, MACHINE_CHIPSET_CONTAQ_82C596, @@ -236,7 +241,9 @@ enum { MACHINE_CHIPSET_OPTI_391, MACHINE_CHIPSET_OPTI_481, MACHINE_CHIPSET_OPTI_493, - MACHINE_CHIPSET_OPTI_495, + MACHINE_CHIPSET_OPTI_495SLC, + MACHINE_CHIPSET_OPTI_495SX, + MACHINE_CHIPSET_OPTI_498, MACHINE_CHIPSET_OPTI_499, MACHINE_CHIPSET_OPTI_895_802G, MACHINE_CHIPSET_OPTI_547_597, @@ -320,27 +327,29 @@ typedef struct _machine_ { int ram_granularity; int nvrmask; #ifdef EMU_DEVICE_H - const device_t *kbc_device; + const device_t *kbc_device; #else - void *kbc_device; + void *kbc_device; #endif /* EMU_DEVICE_H */ - uint8_t kbc_p1; - uint32_t gpio; - uint32_t gpio_acpi; + uintptr_t kbc_params; + /* Bits 23-16: XOR mask, bits 15-8: OR mask, bits 7-0: AND mask. */ + uint32_t kbc_p1; + uint32_t gpio; + uint32_t gpio_acpi; #ifdef EMU_DEVICE_H - const device_t *device; - const device_t *fdc_device; - const device_t *sio_device; - const device_t *vid_device; - const device_t *snd_device; - const device_t *net_device; + const device_t *device; + const device_t *fdc_device; + const device_t *sio_device; + const device_t *vid_device; + const device_t *snd_device; + const device_t *net_device; #else - void *device; - void *fdc_device; - void *sio_device; - void *vid_device; - void *snd_device; - void *net_device; + void *device; + void *fdc_device; + void *sio_device; + void *vid_device; + void *snd_device; + void *net_device; #endif } machine_t; @@ -358,6 +367,7 @@ extern int machine_available(int m); extern const char *machine_getname(void); extern const char *machine_getname_ex(int m); extern const char *machine_get_internal_name(void); +extern const char *machine_get_nvr_name(void); extern int machine_get_machine_from_internal_name(const char *s); extern void machine_init(void); #ifdef EMU_DEVICE_H @@ -370,6 +380,7 @@ extern const device_t *machine_get_snd_device(int m); extern const device_t *machine_get_net_device(int m); #endif extern const char *machine_get_internal_name_ex(int m); +extern const char *machine_get_nvr_name_ex(int m); extern int machine_get_nvrmask(int m); extern int machine_has_flags(int m, int flags); extern int machine_has_bus(int m, int bus_flags); @@ -378,6 +389,7 @@ extern int machine_get_min_ram(int m); extern int machine_get_max_ram(int m); extern int machine_get_ram_granularity(int m); extern int machine_get_type(int m); +extern int machine_get_chipset(int m); extern void machine_close(void); extern int machine_has_mouse(void); extern int machine_is_sony(void); @@ -434,12 +446,11 @@ extern int machine_at_ibmatquadtel_init(const machine_t *); // IBM AT with Quadt extern int machine_at_ibmxt286_init(const machine_t *); +extern int machine_at_pb286_init(const machine_t *); + extern int machine_at_siemens_init(const machine_t *); // Siemens PCD-2L. N82330 discrete machine. It segfaults in some places extern int machine_at_wellamerastar_init(const machine_t *); // Wells American A*Star with custom award BIOS -#ifdef USE_OPEN_AT -extern int machine_at_openat_init(const machine_t *); -#endif /* USE_OPEN_AT */ /* m_at_286_386sx.c */ extern int machine_at_tg286m_init(const machine_t *); @@ -448,6 +459,7 @@ extern int machine_at_px286_init(const machine_t *); extern int machine_at_quadt286_init(const machine_t *); extern int machine_at_mr286_init(const machine_t *); +extern int machine_at_pbl300sx_init(const machine_t *); extern int machine_at_neat_init(const machine_t *); extern int machine_at_neat_ami_init(const machine_t *); extern int machine_at_ataripc4_init(const machine_t *); @@ -466,18 +478,22 @@ extern int machine_at_spc4620p_init(const machine_t *); extern int machine_at_kmxc02_init(const machine_t *); extern int machine_at_deskmaster286_init(const machine_t *); +extern int machine_at_dells200_init(const machine_t *); +extern int machine_at_at122_init(const machine_t *); +extern int machine_at_tuliptc7_init(const machine_t *); + extern int machine_at_pc8_init(const machine_t *); extern int machine_at_3302_init(const machine_t *); -#ifdef USE_OLIVETTI extern int machine_at_m290_init(const machine_t *); -#endif /* USE_OLIVETTI */ extern int machine_at_shuttle386sx_init(const machine_t *); extern int machine_at_adi386sx_init(const machine_t *); extern int machine_at_cmdsl386sx16_init(const machine_t *); extern int machine_at_cmdsl386sx25_init(const machine_t *); extern int machine_at_dataexpert386sx_init(const machine_t *); +extern int machine_at_dells333sl_init(const machine_t *); +extern int machine_at_if386sx_init(const machine_t *); extern int machine_at_spc6033p_init(const machine_t *); extern int machine_at_wd76c10_init(const machine_t *); extern int machine_at_arb1374_init(const machine_t *); @@ -498,15 +514,19 @@ extern int machine_at_pc916sx_init(const machine_t *); sure this appear here (and in the .c file) in the order and position in which they appear in the machine table. */ extern int machine_at_dataexpert386wb_init(const machine_t *); +extern int machine_at_isa486c_init(const machine_t *); extern int machine_at_genoa486_init(const machine_t *); extern int machine_at_ga486l_init(const machine_t *); +extern int machine_at_cobalt_init(const machine_t *); extern int machine_at_cougar_init(const machine_t *); extern int machine_at_acc386_init(const machine_t *); +extern int machine_at_asus3863364k_init(const machine_t *); extern int machine_at_asus386_init(const machine_t *); extern int machine_at_ecs386_init(const machine_t *); extern int machine_at_spc6000a_init(const machine_t *); extern int machine_at_micronics386_init(const machine_t *); +extern int machine_at_micronics386px_init(const machine_t *); extern int machine_at_ecs386v_init(const machine_t *); extern int machine_at_tandy4000_init(const machine_t *); @@ -519,6 +539,8 @@ extern int machine_at_cs4031_init(const machine_t *); extern int machine_at_pb410a_init(const machine_t *); extern int machine_at_decpclpv_init(const machine_t *); +extern int machine_at_dell466np_init(const machine_t *); + extern int machine_at_acerv10_init(const machine_t *); extern int machine_at_acera1g_init(const machine_t *); @@ -528,10 +550,13 @@ extern int machine_at_winbios1429_init(const machine_t *); extern int machine_at_opti495_init(const machine_t *); extern int machine_at_opti495_ami_init(const machine_t *); extern int machine_at_opti495_mr_init(const machine_t *); +extern int machine_at_c747_init(const machine_t *); extern int machine_at_exp4349_init(const machine_t *); extern int machine_at_vect486vl_init(const machine_t *); extern int machine_at_d824_init(const machine_t *); +extern int machine_at_tuliptc38_init(const machine_t *); +extern int machine_at_martin_init(const machine_t *); extern int machine_at_403tg_init(const machine_t *); extern int machine_at_403tg_d_init(const machine_t *); @@ -542,9 +567,11 @@ extern int machine_at_aptiva510_init(const machine_t *); extern int machine_at_pc330_6573_init(const machine_t *); extern int machine_at_mvi486_init(const machine_t *); +extern int machine_at_dtk461_init(const machine_t *); extern int machine_at_sis401_init(const machine_t *); extern int machine_at_isa486_init(const machine_t *); extern int machine_at_av4_init(const machine_t *); +extern int machine_at_advantage40xxd_init(const machine_t *); extern int machine_at_valuepoint433_init(const machine_t *); extern int machine_at_vli486sv2g_init(const machine_t *); @@ -561,6 +588,7 @@ extern int machine_at_r418_init(const machine_t *); extern int machine_at_ls486e_init(const machine_t *); extern int machine_at_4dps_init(const machine_t *); extern int machine_at_ms4144_init(const machine_t *); +extern int machine_at_acerp3_init(const machine_t *); extern int machine_at_4saw2_init(const machine_t *); extern int machine_at_m4li_init(const machine_t *); extern int machine_at_alfredo_init(const machine_t *); @@ -572,6 +600,7 @@ extern int machine_at_sb486p_init(const machine_t *); extern int machine_at_486sp3_init(const machine_t *); extern int machine_at_486sp3c_init(const machine_t *); extern int machine_at_486sp3g_init(const machine_t *); +extern int machine_at_sb486pv_init(const machine_t *); extern int machine_at_486ap4_init(const machine_t *); extern int machine_at_g486vpa_init(const machine_t *); extern int machine_at_486vipio2_init(const machine_t *); @@ -592,6 +621,7 @@ extern int machine_at_iach488_init(const machine_t *); extern int machine_at_pcm9340_init(const machine_t *); extern int machine_at_pcm5330_init(const machine_t *); +extern int machine_at_84xxuuda_init(const machine_t *); extern int machine_at_ecs486_init(const machine_t *); extern int machine_at_hot433a_init(const machine_t *); extern int machine_at_pl4600c_init(const machine_t *); @@ -637,6 +667,7 @@ extern int machine_at_m5pi_init(const machine_t *); extern int machine_at_excalibur_init(const machine_t *); +extern int machine_at_globalyst330_p5_init(const machine_t *); extern int machine_at_p5vl_init(const machine_t *); extern int machine_at_excaliburpci2_init(const machine_t *); @@ -645,6 +676,7 @@ extern int machine_at_p5sp4_init(const machine_t *); /* m_at_socket5.c */ extern int machine_at_plato_init(const machine_t *); extern int machine_at_dellplato_init(const machine_t *); +extern int machine_at_d842_init(const machine_t *); extern int machine_at_ambradp90_init(const machine_t *); extern int machine_at_p54np4_init(const machine_t *); extern int machine_at_586ip_init(const machine_t *); @@ -652,6 +684,7 @@ extern int machine_at_tek932_init(const machine_t *); extern int machine_at_acerv30_init(const machine_t *); extern int machine_at_apollo_init(const machine_t *); +extern int machine_at_optiplexgxl_init(const machine_t *); extern int machine_at_zappa_init(const machine_t *); extern int machine_at_powermatev_init(const machine_t *); extern int machine_at_hawk_init(const machine_t *); @@ -688,6 +721,7 @@ extern int machine_at_fmb_init(const machine_t *); extern int machine_at_acerm3a_init(const machine_t *); extern int machine_at_ap53_init(const machine_t *); extern int machine_at_8500tuc_init(const machine_t *); +extern int machine_at_d943_init(const machine_t *); extern int machine_at_p55t2s_init(const machine_t *); extern int machine_at_p5vxb_init(const machine_t *); @@ -702,6 +736,8 @@ extern int machine_at_vectra54_init(const machine_t *); extern int machine_at_5sbm2_init(const machine_t *); /* m_at_socket7.c */ +extern void machine_at_optiplex_21152_init(void); + extern int machine_at_acerv35n_init(const machine_t *); extern int machine_at_p55t2p4_init(const machine_t *); extern int machine_at_m7shi_init(const machine_t *); @@ -731,11 +767,10 @@ extern int machine_at_gw2kte_init(const machine_t *); extern int machine_at_ma23c_init(const machine_t *); extern int machine_at_nupro592_init(const machine_t *); extern int machine_at_tx97_init(const machine_t *); -#ifdef USE_AN430TX -extern int machine_at_an430tx_init(const machine_t *); -#endif /* USE_AN430TX */ +extern int machine_at_optiplexgn_init(const machine_t *); extern int machine_at_ym430tx_init(const machine_t *); extern int machine_at_thunderbolt_init(const machine_t *); +extern int machine_at_an430tx_init(const machine_t *); extern int machine_at_mb540n_init(const machine_t *); extern int machine_at_56a5_init(const machine_t *); extern int machine_at_p5mms98_init(const machine_t *); @@ -745,6 +780,7 @@ extern int machine_at_tomahawk_init(const machine_t *); extern int machine_at_ficva502_init(const machine_t *); extern int machine_at_ficpa2012_init(const machine_t *); +extern int machine_at_via809ds_init(const machine_t *); extern int machine_at_r534f_init(const machine_t *); extern int machine_at_ms5146_init(const machine_t *); @@ -769,6 +805,7 @@ extern int machine_at_ax59pro_init(const machine_t *); extern int machine_at_mvp3_init(const machine_t *); extern int machine_at_ficva503a_init(const machine_t *); extern int machine_at_5emapro_init(const machine_t *); +extern int machine_at_delhi3_init(const machine_t *); extern int machine_at_5sg100_init(const machine_t *); @@ -780,6 +817,7 @@ extern int machine_at_686nx_init(const machine_t *); extern int machine_at_acerv60n_init(const machine_t *); extern int machine_at_lgibmx61_init(const machine_t *); extern int machine_at_vs440fx_init(const machine_t *); +extern int machine_at_dellvenus_init(const machine_t *); extern int machine_at_gw2kvenus_init(const machine_t *); extern int machine_at_ap440fx_init(const machine_t *); extern int machine_at_mb600n_init(const machine_t *); @@ -793,12 +831,13 @@ extern int machine_at_p65up5_cp6nd_init(const machine_t *); /* m_at_slot1.c */ extern int machine_at_m729_init(const machine_t *); +extern int machine_at_acerv62x_init(const machine_t *); extern int machine_at_p65up5_cpknd_init(const machine_t *); extern int machine_at_kn97_init(const machine_t *); extern int machine_at_lx6_init(const machine_t *); +extern int machine_at_optiplexgxa_init(const machine_t *); extern int machine_at_spitfire_init(const machine_t *); - extern int machine_at_ma30d_init(const machine_t *); extern int machine_at_p6i440e2_init(const machine_t *); @@ -807,6 +846,7 @@ extern int machine_at_p2bls_init(const machine_t *); extern int machine_at_lgibmx7g_init(const machine_t *); extern int machine_at_p3bf_init(const machine_t *); extern int machine_at_bf6_init(const machine_t *); +extern int machine_at_bx6_init(const machine_t *); extern int machine_at_ax6bc_init(const machine_t *); extern int machine_at_atc6310bxii_init(const machine_t *); extern int machine_at_686bx_init(const machine_t *); @@ -847,6 +887,7 @@ extern int machine_at_s1857_init(const machine_t *); extern int machine_at_p6bap_init(const machine_t *); extern int machine_at_p6bat_init(const machine_t *); extern int machine_at_prosignias31x_bx_init(const machine_t *); +extern int machine_at_7sbb_init(const machine_t *); /* m_at_misc.c */ extern int machine_at_vpc2007_init(const machine_t *); @@ -896,6 +937,8 @@ 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 *); +extern int machine_ps55_model_50t_init(const machine_t*); +extern int machine_ps55_model_50v_init(const machine_t*); /* m_tandy.c */ extern int tandy1k_eeprom_read(void); @@ -938,6 +981,7 @@ extern int machine_xt_kaypropc_init(const machine_t *); extern int machine_xt_sansx16_init(const machine_t *); extern int machine_xt_bw230_init(const machine_t *); extern int machine_xt_pb8810_init(const machine_t *); +extern int machine_xt_tuliptc8_init(const machine_t *); extern int machine_xt_v20xt_init(const machine_t *); @@ -952,10 +996,14 @@ extern int machine_xt_compaq_deskpro_init(const machine_t *); extern int machine_xt_compaq_portable_init(const machine_t *); /* m_xt_laserxt.c */ -#ifdef USE_LASERXT extern int machine_xt_laserxt_init(const machine_t *); +#ifdef EMU_DEVICE_H +extern const device_t laserxt_device; +#endif extern int machine_xt_lxt3_init(const machine_t *); -#endif /* USE_LASERXT */ +#ifdef EMU_DEVICE_H +extern const device_t lxt3_device; +#endif /* m_xt_philips.c */ extern int machine_xt_p3105_init(const machine_t *); diff --git a/src/include/86box/machine_status.h b/src/include/86box/machine_status.h index e7c57881b..e6e9e6acd 100644 --- a/src/include/86box/machine_status.h +++ b/src/include/86box/machine_status.h @@ -4,10 +4,12 @@ typedef struct dev_status_empty_active_t { atomic_bool_t empty; atomic_bool_t active; + atomic_bool_t write_active; } dev_status_empty_active_t; typedef struct dev_status_active_t { atomic_bool_t active; + atomic_bool_t write_active; } dev_status_active_t; typedef struct dev_status_empty_t { diff --git a/src/include/86box/mca.h b/src/include/86box/mca.h index e048a6131..2d31fe33d 100644 --- a/src/include/86box/mca.h +++ b/src/include/86box/mca.h @@ -3,6 +3,7 @@ extern void mca_init(int nr_cards); extern 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); +extern void mca_add_to_slot(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); extern void mca_set_index(int index); extern uint8_t mca_read(uint16_t port); extern uint8_t mca_read_index(uint16_t port, int index); diff --git a/src/include/86box/mem.h b/src/include/86box/mem.h index 87be14d5b..53001b8db 100644 --- a/src/include/86box/mem.h +++ b/src/include/86box/mem.h @@ -265,12 +265,16 @@ extern uint32_t biosmask; extern uint32_t biosaddr; extern int readlookup[256]; +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) extern uintptr_t *readlookup2; +#endif extern uintptr_t old_rl2; extern uint8_t uncached; extern int readlnext; extern int writelookup[256]; +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) extern uintptr_t *writelookup2; +#endif extern int writelnext; extern uint32_t ram_mapped_addr[64]; extern uint8_t page_ff[4096]; @@ -288,7 +292,16 @@ extern mem_mapping_t bios_high_mapping; extern uint32_t mem_logical_addr; extern page_t *pages; +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) extern page_t **page_lookup; +#endif + +#if (defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64) +/* The lookup tables. */ +extern page_t *page_lookup[1048576]; +extern uintptr_t readlookup2[1048576]; +extern uintptr_t writelookup2[1048576]; +#endif extern uint32_t get_phys_virt; extern uint32_t get_phys_phys; @@ -300,7 +313,6 @@ extern int writelnum; extern int memspeed[11]; -extern int mmu_perm; extern uint8_t high_page; /* if a high (> 4 gb) page was detected */ extern uint8_t *_mem_exec[MEM_MAPPINGS_NO]; @@ -448,6 +460,7 @@ 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_write(void); extern void flushmmucache_pc(void); extern void flushmmucache_nopc(void); @@ -457,10 +470,16 @@ extern void mem_a20_init(void); extern void mem_a20_recalc(void); extern void mem_init(void); +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) +extern void mem_free(void); +#endif extern void mem_close(void); +extern void mem_zero(void); extern void mem_reset(void); extern void mem_remap_top_ex(int kb, uint32_t start); +extern void mem_remap_top_ex_nomid(int kb, uint32_t start); extern void mem_remap_top(int kb); +extern void mem_remap_top_nomid(int kb); extern void umc_smram_recalc(uint32_t start, int set); diff --git a/src/include/86box/mo.h b/src/include/86box/mo.h index 4ab567aca..fc297ffbb 100644 --- a/src/include/86box/mo.h +++ b/src/include/86box/mo.h @@ -9,13 +9,13 @@ * Implementation of a generic Magneto-Optical Disk drive * commands, for both ATAPI and SCSI usage. * - * - * * Authors: Natalia Portillo - * Fred N. van Kempen, * Miran Grca, + * Fred N. van Kempen, * - * Copyright 2020 Miran Grca. + * Copyright 2020-2025 Natalia Portillo. + * Copyright 2020-2025 Miran Grca. + * Copyright 2020-2025 Fred N. van Kempen */ #ifndef EMU_MO_H @@ -27,7 +27,7 @@ #define MO_TIME 10.0 -#define MO_IMAGE_HISTORY 4 +#define MO_IMAGE_HISTORY 10 typedef struct mo_type_t { uint32_t sectors; @@ -51,10 +51,10 @@ static const mo_type_t mo_types[KNOWN_MO_TYPES] = { }; typedef struct mo_drive_type_t { - const char vendor[9]; - const char model[16]; - const char revision[5]; - int8_t supported_media[KNOWN_MO_TYPES]; + const char *vendor; + const char *model; + const char *revision; + int8_t supported_media[KNOWN_MO_TYPES]; } mo_drive_type_t; #define KNOWN_MO_DRIVE_TYPES 22 @@ -91,88 +91,90 @@ enum { }; typedef struct mo_drive_t { - uint8_t id; + uint8_t id; union { - 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 res; + /* Reserved for other ID's. */ + uint8_t res0; + uint8_t res1; + uint8_t ide_channel; + uint8_t scsi_device_id; }; - 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; + 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 *fp; - void *priv; + FILE *fp; + void *priv; - char image_path[1024]; - char prev_image_path[1024]; + char image_path[1024]; + char prev_image_path[1024]; - char *image_history[MO_IMAGE_HISTORY]; + char *image_history[MO_IMAGE_HISTORY]; - uint32_t type; - uint32_t medium_size; - uint32_t base; - uint16_t sector_size; + uint32_t type; + uint32_t medium_size; + uint32_t base; + uint16_t sector_size; + + int supported; } mo_drive_t; typedef struct mo_t { mode_sense_pages_t ms_pages_saved; - mo_drive_t *drv; + mo_drive_t *drv; #ifdef EMU_IDE_H - ide_tf_t * tf; + ide_tf_t *tf; #else - void * tf; + void *tf; #endif - uint8_t *buffer; - uint8_t atapi_cdb[16]; - uint8_t current_cdb[16]; - uint8_t sense[256]; + void * log; - uint8_t id; - uint8_t cur_lun; - uint8_t pad0; - uint8_t pad1; + uint8_t *buffer; + uint8_t atapi_cdb[16]; + uint8_t current_cdb[16]; + uint8_t sense[256]; - uint16_t max_transfer_len; - uint16_t pad2; + uint8_t id; + uint8_t cur_lun; + uint8_t pad0; + uint8_t pad1; - int requested_blocks; - int packet_status; - int total_length; - int do_page_save; - int unit_attention; - int request_pos; - int old_len; - int pad3; + uint16_t max_transfer_len; + uint16_t pad2; - uint32_t sector_pos; - uint32_t sector_len; - uint32_t packet_len; + int requested_blocks; + int packet_status; + int total_length; + int do_page_save; + int unit_attention; + int request_pos; + int old_len; + int transition; - double callback; + uint32_t sector_pos; + uint32_t sector_len; + uint32_t packet_len; + uint32_t block_len; - uint8_t (*ven_cmd)(void *sc, uint8_t *cdb, int32_t *BufLen); + double callback; + + uint8_t (*ven_cmd)(void *sc, uint8_t *cdb, int32_t *BufLen); } mo_t; -extern mo_t *mo[MO_NUM]; -extern mo_drive_t mo_drives[MO_NUM]; -#if 0 -extern uint8_t atapi_mo_drives[8]; -extern uint8_t scsi_mo_drives[16]; -#endif +extern mo_drive_t mo_drives[MO_NUM]; #define mo_sense_error dev->sense[0] #define mo_sense_key dev->sense[2] +#define mo_info *(uint32_t *) &(dev->sense[3]) #define mo_asc dev->sense[12] #define mo_ascq dev->sense[13] @@ -180,15 +182,16 @@ extern uint8_t scsi_mo_drives[16]; extern "C" { #endif -extern void mo_disk_close(mo_t *dev); -extern void mo_disk_reload(mo_t *dev); +extern void mo_disk_close(const mo_t *dev); +extern void mo_disk_reload(const mo_t *dev); extern void mo_insert(mo_t *dev); extern void mo_global_init(void); extern void mo_hard_reset(void); extern void mo_reset(scsi_common_t *sc); -extern int mo_load(mo_t *dev, char *fn); +extern int mo_is_empty(const uint8_t id); +extern void mo_load(const mo_t *dev, const char *fn, const int skip_insert); extern void mo_close(void); #ifdef __cplusplus diff --git a/src/include/86box/mouse.h b/src/include/86box/mouse.h index bbe78413b..8dd3bad2d 100644 --- a/src/include/86box/mouse.h +++ b/src/include/86box/mouse.h @@ -41,6 +41,7 @@ #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_MSYSTEMSB 14 /* Mouse Systems bus mouse */ #define MOUSE_TYPE_ONBOARD 0x80 /* Mouse is an on-board version of one of the above. */ @@ -68,6 +69,7 @@ extern const device_t mouse_msinport_device; extern const device_t mouse_genibus_device; # endif extern const device_t mouse_mssystems_device; +extern const device_t mouse_mssystems_bus_device; extern const device_t mouse_msserial_device; extern const device_t mouse_ltserial_device; extern const device_t mouse_ps2_device; @@ -100,6 +102,9 @@ extern void mouse_scale_axis(int axis, int val); extern void mouse_set_z(int z); extern void mouse_clear_z(void); extern void mouse_subtract_z(int *delta_z, int min, int max, int invert); +extern void mouse_set_w(int w); +extern void mouse_clear_w(void); +extern void mouse_subtract_w(int *delta_w, int min, int max, int invert); extern void mouse_set_buttons_ex(int b); extern int mouse_get_buttons_ex(void); extern void mouse_set_sample_rate(double new_rate); diff --git a/src/include/86box/net_ne2000.h b/src/include/86box/net_ne2000.h index cb17ef8b1..ecf2612b5 100644 --- a/src/include/86box/net_ne2000.h +++ b/src/include/86box/net_ne2000.h @@ -44,7 +44,7 @@ enum { NE2K_NE2000_COMPAT = 4, /* 16-bit ISA NE2000-Compatible */ NE2K_NE2000_COMPAT_8BIT = 5, /* 8-bit ISA NE2000-Compatible, like: https://github.com/skiselev/isa8_eth */ NE2K_ETHERNEXT_MC = 6, /* 16-bit MCA EtherNext/MC */ - NE2K_RTL8019AS = 7, /* 16-bit ISA PnP Realtek 8019AS */ + NE2K_RTL8019AS_PNP = 7, /* 16-bit ISA PnP Realtek 8019AS */ NE2K_DE220P = 8, /* 16-bit ISA PnP D-Link DE-220P */ NE2K_RTL8029AS = 9, /* 32-bit PCI Realtek 8029AS */ /* Check nic_init() if adding items after this point. */ diff --git a/src/include/86box/network.h b/src/include/86box/network.h index ec8c70abb..a0d1bc3cb 100644 --- a/src/include/86box/network.h +++ b/src/include/86box/network.h @@ -58,7 +58,7 @@ /* 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_QUEUE_COUNT 4 #define NET_CARD_MAX 4 #define NET_HOST_INTF_MAX 64 @@ -85,9 +85,10 @@ enum { }; enum { - NET_QUEUE_RX = 0, - NET_QUEUE_TX_VM = 1, - NET_QUEUE_TX_HOST = 2 + NET_QUEUE_RX = 0, + NET_QUEUE_TX_VM = 1, + NET_QUEUE_TX_HOST = 2, + NET_QUEUE_RX_ON_TX = 3 }; typedef struct netcard_conf_t { @@ -202,7 +203,10 @@ extern const device_t *network_card_getdevice(int); extern int network_tx_pop(netcard_t *card, netpkt_t *out_pkt); extern int network_tx_popv(netcard_t *card, netpkt_t *pkt_vec, int vec_size); extern int network_rx_put(netcard_t *card, uint8_t *bufp, int len); +extern int network_rx_on_tx_popv(netcard_t *card, netpkt_t *pkt_vec, int vec_size); +extern int network_rx_on_tx_put(netcard_t *card, uint8_t *bufp, int len); extern int network_rx_put_pkt(netcard_t *card, netpkt_t *pkt); +extern int network_rx_on_tx_put_pkt(netcard_t *card, netpkt_t *pkt); #ifdef EMU_DEVICE_H /* 3Com Etherlink */ @@ -216,7 +220,7 @@ extern const device_t ne2000_device; extern const device_t ne2000_compat_device; extern const device_t ne2000_compat_8bit_device; extern const device_t ethernext_mc_device; -extern const device_t rtl8019as_device; +extern const device_t rtl8019as_pnp_device; extern const device_t de220p_device; extern const device_t rtl8029as_device; diff --git a/src/include/86box/nv/vid_nv_rivatimer.h b/src/include/86box/nv/vid_nv_rivatimer.h new file mode 100644 index 000000000..59f6cfebf --- /dev/null +++ b/src/include/86box/nv/vid_nv_rivatimer.h @@ -0,0 +1,84 @@ +/* + * 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. + * + * Fast, high-frequency, guest CPU-independent timer for Riva emulation. + * + * + * Authors: Connor Hyde, I need a better email address ;^) + * + * Copyright 2024-2025 starfrost + */ + +/* +RivaTimer + +This is a fast, high-frequency, guest CPU-independent timer. + +The main 86box timer is dependent on the TSC (time-stamp counter) register of the emulated CPU core. +This is fine for most purposes and has advantages in the fields of synchronisation and integrates neatly with +the clock dividers of the PC architecture, but in the case of the RIVA 128 it does not particularly suffice +(although it can be made to work with various techniques) since the clock source on the RIVA 128 is on the board itself +and the GPU has several different clocks that control different parts of the GPU (e.g., PTIMER runs on the memory clock but the core gpu is using the pixel clock). + +As faster graphics cards that offload more and more of the 3D graphics pipeline are emulated in the future, more and more work needs to be done by the emulator and +issues of synchronisation with a host CPU will simply make that work harder. Some features that are required for + +Architecture Brand Name 3D Features +NV1 (1995) NV1 Some weird URBS rectangle crap but feature set generally similar to nv3 but a bit worse +NV3 (1997) RIVA 128 (ZX) Triangle setup, edge-slope calculations, edge interpolation, span-slope calculations, span interpolation (Color-buffer, z-buffer, texture mapping, filtering) +NV4 (1998) RIVA TNT NV3 + 2x1 pixel pipelines + 32-bit colour + larger textures + trilinear + more ram (16mb) +NV5 (1999) RIVA TNT2 NV4 + higher clock speed +NV10 (1999) GeForce 256 NV5 + initial geometry transformation + lighting (8x lights) + MPEG-2 motion compensation + 4x1 pixel pipelines +NV15 (2000) GeForce 2 NV10 + First attempt at programmability + 4x2 pixel pipelines +NV20 (2001) GeForce 3 Programmable shaders! + +As you can see, the performance basically exponentially increases over a period of only 4 years. + +So I decided to create this timer that is completely separate from the CPU Core. +*/ + +#pragma once +#include +#include +#include +#include +#include <86box/86box.h> + +#ifdef _WIN32 +#include +// Linux & MacOS should have the same API since OSX 10.12 +#else +#include +#endif + +typedef struct rivatimer_s +{ + struct rivatimer_s* prev; // Previous Rivatimer + double period; // Period in uS before firing + double value; // The current value of the rivatimer + bool running; // Is this RivaTimer running? + struct rivatimer_s* next; // Next RivaTimer + void (*callback)(double real_time); // Callback to call on fire + #ifdef _WIN32 + LARGE_INTEGER starting_time; // Starting time. + #else + struct timespec starting_time; // Starting time. + #endif + double time; // Accumulated time in uS. +} rivatimer_t; + +void rivatimer_init(void); // Initialise the Rivatimer. +rivatimer_t* rivatimer_create(double period, void (*callback)(double real_time)); +void rivatimer_destroy(rivatimer_t* rivatimer_ptr); + +void rivatimer_update_all(void); +void rivatimer_start(rivatimer_t* rivatimer_ptr); +void rivatimer_stop(rivatimer_t* rivatimer_ptr); +double rivatimer_get_time(rivatimer_t* rivatimer_ptr); +void rivatimer_set_callback(rivatimer_t* rivatimer_ptr, void (*callback)(double real_time)); +void rivatimer_set_period(rivatimer_t* rivatimer_ptr, double period); diff --git a/src/include/86box/nvr.h b/src/include/86box/nvr.h index 85e0954f0..273fc0a37 100644 --- a/src/include/86box/nvr.h +++ b/src/include/86box/nvr.h @@ -60,6 +60,7 @@ #define TIME_SYNC_ENABLED 1 #define TIME_SYNC_UTC 2 +#ifdef _TIMER_H_ /* Define a generic RTC/NVRAM device. */ typedef struct _nvr_ { char *fn; /* pathname of image file */ @@ -98,14 +99,13 @@ extern const device_t ami_1994_nvr_device; extern const device_t ami_1995_nvr_device; extern const device_t via_nvr_device; extern const device_t p6rp4_nvr_device; +extern const device_t martin_nvr_device; extern const device_t elt_nvr_device; #endif extern void rtc_tick(void); extern void nvr_init(nvr_t *); -extern char *nvr_path(char *str); -extern FILE *nvr_fopen(char *str, char *mode); extern int nvr_load(void); extern void nvr_close(void); extern void nvr_set_ven_save(void (*ven_save)(void)); @@ -114,8 +114,8 @@ extern int nvr_save(void); extern int nvr_is_leap(int year); extern int nvr_get_days(int month, int year); extern void nvr_time_sync(void); -extern void nvr_time_get(struct tm *); -extern void nvr_time_set(struct tm *); +extern void nvr_time_get(void *priv); +extern void nvr_time_set(void *priv); extern void nvr_reg_write(uint16_t reg, uint8_t val, void *priv); extern void nvr_at_handler(int set, uint16_t base, nvr_t *nvr); @@ -132,5 +132,9 @@ extern void nvr_irq_set(int irq, nvr_t *nvr); extern void nvr_smi_enable(int enable, nvr_t *nvr); extern uint8_t nvr_smi_status(nvr_t *nvr); extern void nvr_smi_status_clear(nvr_t *nvr); +#endif + +extern char *nvr_path(char *str); +extern FILE *nvr_fopen(char *str, char *mode); #endif /*EMU_NVR_H*/ diff --git a/src/include/86box/pci.h b/src/include/86box/pci.h index 097fcf502..8887f89f4 100644 --- a/src/include/86box/pci.h +++ b/src/include/86box/pci.h @@ -283,9 +283,11 @@ extern void pci_init(int flags); /* PCI bridge stuff. */ extern void pci_bridge_set_ctl(void *priv, uint8_t ctl); +extern uint8_t pci_bridge_get_bus_index(void *priv); #ifdef EMU_DEVICE_H extern const device_t dec21150_device; +extern const device_t dec21152_device; extern const device_t ali5243_agp_device; extern const device_t ali5247_agp_device; diff --git a/src/include/86box/pic.h b/src/include/86box/pic.h index 798cc3357..f6dc9af64 100644 --- a/src/include/86box/pic.h +++ b/src/include/86box/pic.h @@ -102,4 +102,6 @@ extern int picinterrupt(void); extern uint8_t pic_irq_ack(void); +extern void pic_toggle_latch(int is_ps2); + #endif /*EMU_PIC_H*/ diff --git a/src/include/86box/plat.h b/src/include/86box/plat.h index 4a310ab44..e6a366f4c 100644 --- a/src/include/86box/plat.h +++ b/src/include/86box/plat.h @@ -32,8 +32,8 @@ /* String ID numbers. */ enum { STRING_MOUSE_CAPTURE, /* "Click to capture mouse" */ - STRING_MOUSE_RELEASE, /* "Press F8+F12/Ctrl+End to release mouse" */ - STRING_MOUSE_RELEASE_MMB, /* "Press F8+F12/Ctrl+End or middle button to release mouse" */ + STRING_MOUSE_RELEASE, /* "Press %1 to release mouse" */ + STRING_MOUSE_RELEASE_MMB, /* "Press %1 or middle button to release mouse" */ STRING_INVALID_CONFIG, /* "Invalid configuration" */ STRING_NO_ST506_ESDI_CDROM, /* "MFM/RLL or ESDI CD-ROM drives never existed" */ STRING_NET_ERROR, /* "Failed to initialize network driver" */ @@ -47,9 +47,12 @@ enum { STRING_HW_NOT_AVAILABLE_MACHINE, /* "Machine \"%hs\" is not available..." */ STRING_HW_NOT_AVAILABLE_VIDEO, /* "Video card \"%hs\" is not available..." */ STRING_HW_NOT_AVAILABLE_VIDEO2, /* "Video card #2 \"%hs\" is not available..." */ + STRING_HW_NOT_AVAILABLE_DEVICE, /* "Device \"%hs\" is not available..." */ STRING_MONITOR_SLEEP, /* "Monitor in sleep mode" */ STRING_GHOSTPCL_ERROR_TITLE, /* "Unable to initialize GhostPCL" */ - STRING_GHOSTPCL_ERROR_DESC /* "gpcl6dll32.dll/gpcl6dll64.dll/libgpcl6 is required..." */ + STRING_GHOSTPCL_ERROR_DESC, /* "gpcl6dll32.dll/gpcl6dll64.dll/libgpcl6 is required..." */ + STRING_ESCP_ERROR_TITLE, /* "Unable to find Dot-Matrix fonts" */ + STRING_ESCP_ERROR_DESC /* "TrueType fonts in the \"roms/printer/fonts\" directory..." */ }; /* The Win32 API uses _wcsicmp. */ @@ -157,10 +160,11 @@ extern int plat_vidapi(const char *name); extern char *plat_vidapi_name(int api); extern void plat_resize(int x, int y, int monitor_index); extern void plat_resize_request(int x, int y, int monitor_index); -extern uint32_t plat_language_code(char *langcode); -extern void plat_language_code_r(uint32_t lcid, char *outbuf, int len); +extern int plat_language_code(char *langcode); +extern void plat_language_code_r(int id, char *outbuf, int len); extern void plat_get_cpu_string(char *outbuf, uint8_t len); extern void plat_set_thread_name(void *thread, const char *name); +extern void plat_break(void); /* Resource management. */ extern wchar_t *plat_get_string(int id); @@ -187,9 +191,6 @@ extern void zip_reload(uint8_t id); extern void mo_eject(uint8_t id); extern void mo_mount(uint8_t id, char *fn, uint8_t wp); extern void mo_reload(uint8_t id); -extern int ioctl_open(uint8_t id, char d); -extern void ioctl_reset(uint8_t id); -extern void ioctl_close(uint8_t id); /* Other stuff. */ extern void startblit(void); diff --git a/src/include/86box/plat_cdrom.h b/src/include/86box/plat_cdrom.h deleted file mode 100644 index 643013a08..000000000 --- a/src/include/86box/plat_cdrom.h +++ /dev/null @@ -1,73 +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. - * - * Definitions for platform specific serial to host passthrough. - * - * - * Authors: Andreas J. Reichel , - * Jasmine Iwanek - * - * Copyright 2021 Andreas J. Reichel. - * Copyright 2021-2022 Jasmine Iwanek. - */ - -#ifndef PLAT_CDROM_H -#define PLAT_CDROM_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define RAW_SECTOR_SIZE 2352 -#define COOKED_SECTOR_SIZE 2048 - -#define DATA_TRACK 0x14 -#define AUDIO_TRACK 0x10 - -#define CD_FPS 75 -#define FRAMES_TO_MSF(f, M, S, F) \ - { \ - uint64_t value = f; \ - *(F) = (value % CD_FPS) & 0xff; \ - value /= CD_FPS; \ - *(S) = (value % 60) & 0xff; \ - value /= 60; \ - *(M) = value & 0xff; \ - } -#define MSF_TO_FRAMES(M, S, F) ((M) *60 * CD_FPS + (S) *CD_FPS + (F)) - -typedef struct SMSF { - uint16_t min; - uint8_t sec; - uint8_t fr; -} TMSF; - -extern void plat_cdrom_get_raw_track_info(void *local, int *num, raw_track_info_t *rti); -extern int plat_cdrom_is_track_audio(void *local, uint32_t sector); -extern int plat_cdrom_is_track_pre(void *local, uint32_t sector); -extern uint32_t plat_cdrom_get_last_block(void *local); -extern int plat_cdrom_get_audio_track_info(void *local, int end, int track, int *track_num, TMSF *start, - uint8_t *attr); -extern int plat_cdrom_get_audio_sub(void *local, uint32_t sector, uint8_t *attr, uint8_t *track, - uint8_t *index, TMSF *rel_pos, TMSF *abs_pos); -extern int plat_cdrom_get_sector_size(void *local, uint32_t sector); -extern int plat_cdrom_read_sector(void *local, uint8_t *buffer, uint32_t sector); -extern void plat_cdrom_eject(void *local); -extern void plat_cdrom_close(void *local); -extern int plat_cdrom_set_drive(void *local, const char *drv); -extern int plat_cdrom_ext_medium_changed(void *local); -extern uint32_t plat_cdrom_get_track_start(void *local, uint32_t sector, uint8_t *attr, uint8_t *track); -extern int plat_cdrom_get_local_size(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/include/86box/plat_cdrom_ioctl.h b/src/include/86box/plat_cdrom_ioctl.h new file mode 100644 index 000000000..471222134 --- /dev/null +++ b/src/include/86box/plat_cdrom_ioctl.h @@ -0,0 +1,34 @@ +/* + * 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 platform specific serial to host passthrough. + * + * + * Authors: Andreas J. Reichel , + * Jasmine Iwanek + * + * Copyright 2021 Andreas J. Reichel. + * Copyright 2021-2022 Jasmine Iwanek. + */ + +#ifndef PLAT_CDROM_IOCTL_H +#define PLAT_CDROM_IOCTL_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern void * ioctl_open(cdrom_t *dev, const char *drv); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/include/86box/qt-glsl.h b/src/include/86box/qt-glsl.h new file mode 100644 index 000000000..0cd8e27cd --- /dev/null +++ b/src/include/86box/qt-glsl.h @@ -0,0 +1,158 @@ +#ifndef SRC_WX_GLSL_H_ +#define SRC_WX_GLSL_H_ + +#define MAX_PREV 7 + +#define MAX_SHADERS 20 +#define MAX_TEXTURES 20 +#define MAX_PARAMETERS 100 + +#define MAX_USER_SHADERS 20 +//#define SDL2_SHADER_DEBUG + +struct shader_scale { + int mode[2]; + float value[2]; +}; + +struct shader_state { + float input_size[2]; + float input_texture_size[2]; + float output_texture_size[2]; + float output_size[2]; + float tex_coords[8]; +}; + +struct shader_vbo { + int vertex_coord; + int tex_coord; + int color; +}; + +struct shader_texture { + int id; + int width; + int height; + int type; + int internal_format; + int format; + int min_filter; + int mag_filter; + int wrap_mode; + void *data; + int mipmap; +}; + +struct shader_lut_texture { + char name[50]; + struct shader_texture texture; +}; + +struct shader_fbo { + int id; + struct shader_texture texture; + int srgb; + int mipmap_input; +}; + +struct shader_prev { + struct shader_fbo fbo; + struct shader_vbo vbo; +}; + +struct shader_input { + int texture; + int input_size; + int texture_size; + int tex_coord; +}; + +struct shader_uniforms { + int mvp_matrix; + int vertex_coord; + int tex_coord; + int color; + + int texture; + int input_size; + int texture_size; + int output_size; + + int frame_count; + int frame_direction; + + struct shader_input orig; + struct shader_input pass[MAX_SHADERS]; + struct shader_input prev_pass[MAX_SHADERS]; + struct shader_input prev[MAX_PREV]; + + int parameters[MAX_PARAMETERS]; + int lut_textures[MAX_TEXTURES]; +}; + +struct shader_program { + int vertex_shader; + int fragment_shader; + int id; +}; + +struct shader_parameter { + char id[64]; + char description[64]; + float default_value; + float value; + float min; + float max; + float step; +}; + +struct shader_pass { + int active; + char alias[64]; + int vertex_array; + int frame_count_mod; + struct shader_program program; + struct shader_uniforms uniforms; + struct shader_fbo fbo; + struct shader_vbo vbo; + struct shader_state state; + struct shader_scale scale; +}; + +struct glsl_shader { + int active; + char name[64]; + + int num_passes; + struct shader_pass passes[MAX_SHADERS]; + + int num_lut_textures; + struct shader_lut_texture lut_textures[MAX_TEXTURES]; + + int num_parameters; + struct shader_parameter parameters[MAX_PARAMETERS]; + + struct shader_pass prev_scene; + struct shader_prev prev[MAX_PREV + 1]; + + int last_prev_update; + int has_prev; + + float shader_refresh_rate; + + int input_filter_linear; +}; + +typedef struct glsl_t { + int num_shaders; + struct glsl_shader shaders[MAX_USER_SHADERS]; + struct shader_pass scene; + struct shader_pass final_pass; + struct shader_pass fs_color; +#ifdef SDL2_SHADER_DEBUG + struct shader_pass debug; +#endif + int srgb; +} glsl_t; + +#endif \ No newline at end of file diff --git a/src/include/86box/qt-glslp-parser.h b/src/include/86box/qt-glslp-parser.h new file mode 100644 index 000000000..853e50e66 --- /dev/null +++ b/src/include/86box/qt-glslp-parser.h @@ -0,0 +1,59 @@ +#ifndef SRC_WX_GLSLP_PARSER_H_ +#define SRC_WX_GLSLP_PARSER_H_ + +#include "qt-glsl.h" + +struct parameter { + char id[64]; + char description[64]; + float default_value; + float value; + float min; + float max; + float step; +}; + +struct texture { + char path[256]; + char name[50]; + int linear; + int mipmap; + char wrap_mode[50]; +}; + +struct shader { + char shader_fn[1024]; + char *shader_program; + char alias[64]; + int filter_linear; + int float_framebuffer; + int srgb_framebuffer; + int mipmap_input; + int frame_count_mod; + char wrap_mode[50]; + char scale_type_x[9], scale_type_y[9]; + float scale_x, scale_y; +}; + +typedef struct glslp_t { + char name[64]; + int num_shaders; + struct shader shaders[MAX_SHADERS]; + + int num_textures; + struct texture textures[MAX_TEXTURES]; + + int num_parameters; + struct parameter parameters[MAX_PARAMETERS]; + + int input_filter_linear; +} glslp_t; + +void get_glslp_name(const char *f, char *s, int size); +glslp_t *glslp_parse(const char *f); +void glslp_free(glslp_t *p); + +void glslp_read_shader_config(glslp_t *shader); +void glslp_write_shader_config(glslp_t *shader); + +#endif /* SRC_WX_GLSLP_PARSER_H_ */ diff --git a/src/include/86box/rom.h b/src/include/86box/rom.h index 1f6e611b1..331d78526 100644 --- a/src/include/86box/rom.h +++ b/src/include/86box/rom.h @@ -52,6 +52,12 @@ extern uint8_t rom_read(uint32_t addr, void *priv); extern uint16_t rom_readw(uint32_t addr, void *priv); extern uint32_t rom_readl(uint32_t addr, void *priv); +extern void rom_write(uint32_t addr, uint8_t val, void *priv); +extern void rom_writew(uint32_t addr, uint16_t val, void *priv); +extern void rom_writel(uint32_t addr, uint32_t val, void *priv); + +extern void rom_get_full_path(char *dest, const char *fn); + extern FILE *rom_fopen(const char *fn, char *mode); extern int rom_getfile(char *fn, char *s, int size); extern int rom_present(const char *fn); diff --git a/src/include/86box/scsi.h b/src/include/86box/scsi.h index 32ad1f912..84a4a608e 100644 --- a/src/include/86box/scsi.h +++ b/src/include/86box/scsi.h @@ -29,15 +29,21 @@ #define SCSI_ID_MAX 16 /* 16 on wide buses */ #define SCSI_LUN_MAX 8 /* always 8 */ -extern int scsi_card_current[SCSI_CARD_MAX]; +extern int scsi_card_current[SCSI_CARD_MAX]; -extern int scsi_card_available(int card); +extern void scsi_reset(void); +extern uint8_t scsi_get_bus(void); + +extern int scsi_card_available(int card); #ifdef EMU_DEVICE_H extern const device_t *scsi_card_getdevice(int card); #endif -extern int scsi_card_has_config(int card); -extern const char *scsi_card_get_internal_name(int card); -extern int scsi_card_get_from_internal_name(char *s); -extern void scsi_card_init(void); +extern int scsi_card_has_config(int card); +extern const char *scsi_card_get_internal_name(int card); +extern int scsi_card_get_from_internal_name(char *s); +extern void scsi_card_init(void); + +extern void scsi_bus_set_speed(uint8_t bus, double speed); +extern double scsi_bus_get_speed(uint8_t bus); #endif /*EMU_SCSI_H*/ diff --git a/src/include/86box/scsi_cdrom.h b/src/include/86box/scsi_cdrom.h index 684a9d589..c01f347a8 100644 --- a/src/include/86box/scsi_cdrom.h +++ b/src/include/86box/scsi_cdrom.h @@ -26,47 +26,61 @@ typedef struct scsi_cdrom_t { /* Common block. */ mode_sense_pages_t ms_pages_saved; - cdrom_t * drv; + cdrom_t * drv; #ifdef EMU_IDE_H - ide_tf_t *tf; + ide_tf_t * tf; #else - void * tf; + void * tf; #endif - uint8_t *buffer; - uint8_t atapi_cdb[16]; - uint8_t current_cdb[16]; - uint8_t sense[256]; + void * log; - uint8_t id; - uint8_t cur_lun; - uint8_t early; - uint8_t pad1; + uint8_t * buffer; + uint8_t atapi_cdb[16]; + uint8_t current_cdb[16]; + uint8_t sense[256]; - uint16_t max_transfer_len; - uint16_t pad2; + uint8_t id; + uint8_t cur_lun; + uint8_t early; + uint8_t sector_type; - 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; + uint16_t max_transfer_len; + uint16_t sector_flags; - uint32_t sector_pos; - uint32_t sector_len; - uint32_t packet_len; + int requested_blocks; + int packet_status; + int total_length; + int do_page_save; + int unit_attention; + int request_pos; + int wait; + int buffer_pos; - double callback; + uint32_t sector_pos; + uint32_t sector_len; + uint32_t packet_len; + uint32_t block_len; - uint8_t (*ven_cmd)(void *sc, uint8_t *cdb, int32_t *BufLen); + double callback; - int sony_vendor; + uint8_t (*ven_cmd)(void *sc, const uint8_t *cdb, int32_t *BufLen); + + int use_cdb_9; + int was_cached; + int toc_cached; + int media_access; + int sectors_num; + + uint8_t vendor_type; + uint8_t ven_cmd_is_data[256]; - mode_sense_pages_t ms_pages_saved_sony; mode_sense_pages_t ms_drive_status_pages_saved; + + uint64_t ms_page_flags; + + mode_sense_pages_t ms_pages_default; + mode_sense_pages_t ms_pages_changeable; } scsi_cdrom_t; #endif @@ -74,10 +88,12 @@ extern scsi_cdrom_t *scsi_cdrom[CDROM_NUM]; #define scsi_cdrom_sense_error dev->sense[0] #define scsi_cdrom_sense_key dev->sense[2] +#define scsi_cdrom_info *(uint32_t *) &(dev->sense[3]) #define scsi_cdrom_asc dev->sense[12] #define scsi_cdrom_ascq dev->sense[13] #define scsi_cdrom_drive cdrom_drives[id].host_drive extern void scsi_cdrom_reset(scsi_common_t *sc); +extern void scsi_cdrom_drive_reset(const int c); #endif /*EMU_SCSI_CDROM_H*/ diff --git a/src/include/86box/scsi_device.h b/src/include/86box/scsi_device.h index 6fdac5ebd..289201b04 100644 --- a/src/include/86box/scsi_device.h +++ b/src/include/86box/scsi_device.h @@ -21,6 +21,7 @@ #define SCSI_DEVICE_H /* Configuration. */ +#define SCSI_NUM (SCSI_BUS_MAX * SCSI_ID_MAX) #define SCSI_LUN_USE_CDB 0xff @@ -53,8 +54,8 @@ #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_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 @@ -66,7 +67,7 @@ #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_UNKNOWN_CHINON 0x26 /* Chinon Vendor Unique command. */ #define GPCMD_READ_10 0x28 #define GPCMD_READ_GENERATION 0x29 #define GPCMD_WRITE_10 0x2a @@ -109,39 +110,40 @@ #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_SET_ADDRESS_FORMAT_SONY 0xc0 /* Sony Vendor Unique command */ +#define GPCMD_EJECT_CHINON 0xc0 /* Chinon Vendor Unique command */ #define GPCMD_MAGAZINE_EJECT_PIONEER 0xc0 /* Pioneer Vendor Unique command */ +#define GPCMD_SET_ADDRESS_FORMAT_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_READ_TOC_PIONEER 0xc1 /* Pioneer 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_SUBCODEQ_PIONEER 0xc2 /* Pioneer 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_SUBCODEQ_PIONEER 0xc2 /* Pioneer 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_SONY 0xc4 /* Sony Vendor Unique command */ #define GPCMD_CADDY_EJECT_TOSHIBA 0xc4 /* Toshiba Vendor Unique command */ +#define GPCMD_PLAYBACK_STATUS_SONY 0xc4 /* Sony Vendor Unique command */ +#define GPCMD_READ_HEADER_MATSUSHITA 0xc4 /* Matsushita Vendor Unique command */ #define GPCMD_PAUSE_SONY 0xc5 /* Sony Vendor Unique command */ #define GPCMD_PLAY_AUDIO_MATSUSHITA 0xc5 /* Matsushita Vendor Unique command */ #define GPCMD_UNKNOWN_SCSI2_NEC 0xc5 /* NEC Vendor Unique Command */ -#define GPCMD_STOP_CHINON 0xc6 /* Chinon Vendor Unique command */ #define GPCMD_PLAY_TRACK_SONY 0xc6 /* Sony Vendor Unique command */ #define GPCMD_READ_SUBCODEQ_PLAYING_STATUS_TOSHIBA 0xc6 /* Toshiba Vendor Unique command */ +#define GPCMD_STOP_CHINON 0xc6 /* Chinon 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_AUDIO_TRACK_SEARCH_PIONEER 0xc8 /* Pioneer Vendor Unique command */ +#define GPCMD_PLAY_AUDIO_SONY 0xc8 /* Sony Vendor Unique command */ +#define GPCMD_PLAY_AUDIO_TRACK_INDEX_MATSUSHITA 0xc8 /* Matsushita Vendor Unique command */ +#define GPCMD_READ_CDROM_MODE_TOSHIBA 0xc8 /* Toshiba Vendor Unique command */ +#define GPCMD_PLAY_AUDIO_PIONEER 0xc9 /* Pioneer 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_PLAY_AUDIO_PIONEER 0xc9 /* Pioneer Vendor Unique command */ #define GPCMD_PAUSE_PIONEER 0xca /* Pioneer Vendor Unique command */ #define GPCMD_PAUSE_RESUME_MATSUSHITA 0xcb /* Matsushita Vendor Unique command */ #define GPCMD_STOP_PIONEER 0xcb /* Pioneer Vendor Unique command */ @@ -150,8 +152,8 @@ #define GPCMD_READ_CD_MSF_OLD 0xd5 /* Should be equivalent to 0xb9 */ #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_STILL_NEC 0xda /* NEC Vendor Unique command */ #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 */ @@ -218,7 +220,7 @@ #define ASC_INV_FIELD_IN_PARAMETER_LIST 0x26 #define ASC_WRITE_PROTECTED 0x27 #define ASC_MEDIUM_MAY_HAVE_CHANGED 0x28 -#define ASC_CAPACITY_DATA_CHANGED 0x2A +#define ASC_CAPACITY_DATA_CHANGED 0x2a #define ASC_INCOMPATIBLE_FORMAT 0x30 #define ASC_MEDIUM_NOT_PRESENT 0x3a #define ASC_DATA_PHASE_ERROR 0x4b @@ -233,16 +235,12 @@ #define ASCQ_AUDIO_PLAY_OPERATION_PAUSED 0x12 #define ASCQ_AUDIO_PLAY_OPERATION_COMPLETED 0x13 -/* Tell RISC OS that we have a 4x CD-ROM drive (600kb/sec data, 706kb/sec raw). - Not that it means anything */ -#define CDROM_SPEED 706 /* 0x2C2 */ - -#define BUFFER_SIZE (256 * 1024) - -#define RW_DELAY (TIMER_USEC * 500) - /* Some generally useful CD-ROM information */ +#ifdef CONSERVATIVE_MAXIMUM #define CD_MINS 90 /* max. minutes per CD */ +#else +#define CD_MINS 100 /* max. minutes per CD - yes, 100-minute CD's in fact existed */ +#endif #define CD_SECS 60 /* seconds per minute */ #define CD_FRAMES 75 /* frames per second */ #define CD_FRAMESIZE 2048 /* bytes per frame, "cooked" mode */ @@ -276,6 +274,10 @@ /* Profile list from MMC-6 revision 1 table 91 */ #define MMC_PROFILE_NONE 0x0000 +#define MMC_PROFILE_REMOVABLE_DISK 0x0002 +#define MMC_PROFILE_MO 0x0003 +#define MMC_PROFILE_MO_WORM 0x0004 +#define MMC_PROFILE_AS_MO 0x0005 #define MMC_PROFILE_CD_ROM 0x0008 #define MMC_PROFILE_CD_R 0x0009 #define MMC_PROFILE_CD_RW 0x000A @@ -304,7 +306,6 @@ #define MMC_PROFILE_HDDVD_RW_DL 0x005A #define MMC_PROFILE_INVALID 0xFFFF -#define EARLY_ONLY 64 #define SCSI_ONLY 32 #define ATAPI_ONLY 16 #define IMPLEMENTED 8 @@ -312,8 +313,6 @@ #define CHECK_READY 2 #define ALLOW_UA 1 -#define MSFtoLBA(m, s, f) ((((m * 60) + s) * 75) + f) - #define MSG_COMMAND_COMPLETE 0x00 #define BUS_DBP 0x01 @@ -333,6 +332,20 @@ #define BUS_IDLE (1 << 31) +#define STATE_IDLE 0 +#define STATE_COMMAND 1 +#define STATE_DATAIN 2 +#define STATE_DATAOUT 3 +#define STATE_STATUS 4 +#define STATE_MESSAGEIN 5 +#define STATE_SELECT 6 +#define STATE_MESSAGEOUT 7 +#define STATE_MESSAGE_ID 8 + +#define PIO_TX_BUS 0 +#define DMA_IN_TX_BUS 1 +#define DMA_OUT_TX_BUS 2 + #define PHASE_IDLE 0x00 #define PHASE_COMMAND 0x01 #define PHASE_DATA_IN 0x02 @@ -357,7 +370,7 @@ #define MODE_SELECT_PHASE_PAGE 4 typedef struct mode_sense_pages_t { - uint8_t pages[0x40][0x40]; + uint8_t pages[0x40][0x40]; } mode_sense_pages_t; /* This is so we can access the common elements to all SCSI device structs @@ -365,61 +378,109 @@ typedef struct mode_sense_pages_t { typedef struct scsi_common_s { mode_sense_pages_t ms_pages_saved; - void * priv; + void * priv; #ifdef EMU_IDE_H - ide_tf_t *tf; + ide_tf_t * tf; #else - void * tf; + void * tf; #endif - 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]; + void * log; - uint8_t id; - uint8_t cur_lun; - uint8_t pad0; - uint8_t pad1; + uint8_t * temp_buffer; + /* + This is atapi_cdb in ATAPI-supporting devices, + and pad in SCSI-only devices. + */ + uint8_t atapi_cdb[16]; + uint8_t current_cdb[16]; + uint8_t sense[256]; - uint16_t max_transfer_len; - uint16_t pad2; + uint8_t id; + uint8_t cur_lun; + uint8_t pad0; + uint8_t pad1; - 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; + uint16_t max_transfer_len; + uint16_t pad2; - uint32_t sector_pos; - uint32_t sector_len; - uint32_t packet_len; + int requested_blocks; + int packet_status; + int total_length; + int do_page_save; + int unit_attention; + int request_pos; + int wait; + int buffer_pos; - double callback; + uint32_t sector_pos; + uint32_t sector_len; + uint32_t packet_len; + uint32_t block_len; - uint8_t (*ven_cmd)(void *sc, uint8_t *cdb, int32_t *BufLen); + double callback; + + uint8_t (*ven_cmd)(void *sc, uint8_t *cdb, int32_t *BufLen); } scsi_common_t; typedef struct scsi_device_t { - int32_t buffer_length; + int32_t buffer_length; - uint8_t status; - uint8_t phase; - uint16_t type; + uint8_t status; + uint8_t phase; - scsi_common_t *sc; + uint16_t type; - void (*command)(scsi_common_t *sc, uint8_t *cdb); - void (*request_sense)(scsi_common_t *sc, uint8_t *buffer, uint8_t alloc_length); - void (*reset)(scsi_common_t *sc); - uint8_t (*phase_data_out)(scsi_common_t *sc); - void (*command_stop)(scsi_common_t *sc); + scsi_common_t * sc; + + void (*command)(scsi_common_t *sc, const uint8_t *cdb); + void (*request_sense)(scsi_common_t *sc, uint8_t *buffer, + uint8_t alloc_length); + void (*reset)(scsi_common_t *sc); + uint8_t (*phase_data_out)(scsi_common_t *sc); + void (*command_stop)(scsi_common_t *sc); } scsi_device_t; +typedef struct scsi_bus_t { + uint8_t data; + uint8_t msglun; + uint8_t data_wait; + uint8_t target_id; + uint8_t bus_device; + uint8_t pad; + uint8_t pad0; + uint8_t pad1; + + uint8_t command[16]; + uint8_t msgout[4]; + uint8_t pad2[4]; + + int tx_mode; + int clear_req; + int wait_data; + int wait_complete; + int bus_out; + int bus_in; + int command_pos; + int command_issued; + int data_pos; + int msgout_pos; + int is_msgout; + int state; + + uint32_t bus_phase; + uint32_t total_len; + uint32_t data_repeat; + + double period; + double speed; + double divider; + double multi; + + void *priv; + void (*timer)(void *priv, double period); +} scsi_bus_t; + /* These are based on the INQUIRY values. */ #define SCSI_NONE 0x0060 #define SCSI_FIXED_DISK 0x0000 @@ -430,15 +491,8 @@ typedef struct scsi_device_t { extern scsi_device_t scsi_devices[SCSI_BUS_MAX][SCSI_ID_MAX]; #endif /* EMU_SCSI_H */ -extern int cdrom_add_error_and_subchannel(uint8_t *b, int real_sector_type); -extern int cdrom_LBAtoMSF_accurate(void); - -extern int mode_select_init(uint8_t command, uint16_t pl_length, uint8_t do_save); -extern int mode_select_terminate(int force); -extern int mode_select_write(uint8_t val); - -extern uint8_t *scsi_device_sense(scsi_device_t *dev); extern double scsi_device_get_callback(scsi_device_t *dev); +extern uint8_t *scsi_device_sense(scsi_device_t *dev); extern void scsi_device_request_sense(scsi_device_t *dev, uint8_t *buffer, uint8_t alloc_length); extern void scsi_device_reset(scsi_device_t *dev); @@ -446,14 +500,16 @@ extern int scsi_device_present(scsi_device_t *dev); extern int scsi_device_valid(scsi_device_t *dev); extern int scsi_device_cdb_length(scsi_device_t *dev); extern void scsi_device_command_phase0(scsi_device_t *dev, uint8_t *cdb); -extern void scsi_device_command_phase1(scsi_device_t *dev); extern void scsi_device_command_stop(scsi_device_t *dev); +extern void scsi_device_command_phase1(scsi_device_t *dev); extern void scsi_device_identify(scsi_device_t *dev, uint8_t lun); extern void scsi_device_close_all(void); extern void scsi_device_init(void); extern void scsi_reset(void); extern uint8_t scsi_get_bus(void); +extern int scsi_bus_read(scsi_bus_t *scsi_bus); +extern void scsi_bus_update(scsi_bus_t *scsi_bus, int bus); extern void scsi_bus_set_speed(uint8_t bus, double speed); extern double scsi_bus_get_speed(uint8_t bus); diff --git a/src/include/86box/scsi_disk.h b/src/include/86box/scsi_disk.h index 8c7e045fb..293cc35e6 100644 --- a/src/include/86box/scsi_disk.h +++ b/src/include/86box/scsi_disk.h @@ -19,42 +19,45 @@ typedef struct scsi_disk_t { mode_sense_pages_t ms_pages_saved; - hard_disk_t *drv; + hard_disk_t * drv; #ifdef EMU_IDE_H - ide_tf_t * tf; + ide_tf_t * tf; #else - void * tf; + void * tf; #endif - uint8_t *temp_buffer; - uint8_t atapi_cdb[16]; - uint8_t current_cdb[16]; - uint8_t sense[256]; + void * log; - uint8_t id; - uint8_t cur_lun; - uint8_t pad0; - uint8_t pad1; + uint8_t * temp_buffer; + uint8_t atapi_cdb[16]; + uint8_t current_cdb[16]; + uint8_t sense[256]; - uint16_t max_transfer_len; - uint16_t pad2; + uint8_t id; + uint8_t cur_lun; + uint8_t pad0; + uint8_t pad1; - int requested_blocks; - int packet_status; - int total_length; - int do_page_save; - int unit_attention; - int request_pos; - int pad6; - int pad7; + uint16_t max_transfer_len; + uint16_t pad2; - uint32_t sector_pos; - uint32_t sector_len; - uint32_t packet_len; + int requested_blocks; + int packet_status; + int total_length; + int do_page_save; + int unit_attention; + int request_pos; + int pad6; + int pad7; - double callback; + uint32_t sector_pos; + uint32_t sector_len; + uint32_t packet_len; + uint32_t block_len; - uint8_t (*ven_cmd)(void *sc, uint8_t *cdb, int32_t *BufLen); + double callback; + + uint8_t (*ven_cmd)(void *sc, uint8_t *cdb, int32_t *BufLen); } scsi_disk_t; extern scsi_disk_t *scsi_disk[HDD_NUM]; diff --git a/src/include/86box/scsi_ncr5380.h b/src/include/86box/scsi_ncr5380.h index 55692075b..5a43ba76a 100644 --- a/src/include/86box/scsi_ncr5380.h +++ b/src/include/86box/scsi_ncr5380.h @@ -44,6 +44,9 @@ #define ICR_ACK 0x10 #define ICR_ARB_LOST 0x20 #define ICR_ARB_IN_PROGRESS 0x40 +#define ICR_RST 0x80 +#define ICR_PHASE 0x9e +#define ICR_WRITE 0x9f #define MODE_ARBITRATE 0x01 #define MODE_DMA 0x02 @@ -63,69 +66,34 @@ #define TCR_REQ 0x08 #define TCR_LAST_BYTE_SENT 0x80 - -#define STATE_IDLE 0 -#define STATE_COMMAND 1 -#define STATE_DATAIN 2 -#define STATE_DATAOUT 3 -#define STATE_STATUS 4 -#define STATE_MESSAGEIN 5 -#define STATE_SELECT 6 -#define STATE_MESSAGEOUT 7 -#define STATE_MESSAGE_ID 8 - -#define DMA_IDLE 0 -#define DMA_SEND 1 -#define DMA_INITIATOR_RECEIVE 2 - 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 irq_state; + uint8_t isr_reg; - uint8_t command[20]; - uint8_t msgout[4]; uint8_t bus; - int msgout_pos; - int is_msgout; - - 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; - int irq; double period; void *priv; - void (*dma_mode_ext)(void *priv, void *ext_priv); + void (*dma_mode_ext)(void *priv, void *ext_priv, uint8_t val); int (*dma_send_ext)(void *priv, void *ext_priv); int (*dma_initiator_receive_ext)(void *priv, void *ext_priv); void (*timer)(void *ext_priv, double period); + + scsi_bus_t scsibus; } ncr_t; -extern int ncr5380_cmd_len[8]; - extern void ncr5380_irq(ncr_t *ncr, int set_irq); -extern void ncr5380_set_irq(ncr_t *ncr, int irq); +extern void ncr5380_set_irq(ncr_t *ncr, int irq); extern uint32_t ncr5380_get_bus_host(ncr_t *ncr); -extern void ncr5380_bus_read(ncr_t *ncr); -extern void ncr5380_bus_update(ncr_t *ncr, int bus); extern void ncr5380_write(uint16_t port, uint8_t val, ncr_t *ncr); extern uint8_t ncr5380_read(uint16_t port, ncr_t *ncr); diff --git a/src/include/86box/scsi_t128.h b/src/include/86box/scsi_t128.h index 65148a5d1..a3bc79335 100644 --- a/src/include/86box/scsi_t128.h +++ b/src/include/86box/scsi_t128.h @@ -30,7 +30,7 @@ typedef struct t128_t { uint8_t status; uint8_t buffer[512]; uint8_t ext_ram[0x80]; - uint8_t block_count; + uint32_t block_count; int block_loaded; int pos, host_pos; @@ -39,6 +39,7 @@ typedef struct t128_t { int bios_enabled; uint8_t pos_regs[8]; + int type; pc_timer_t timer; } t128_t; diff --git a/src/include/86box/serial.h b/src/include/86box/serial.h index a205c7cec..31c77ce5a 100644 --- a/src/include/86box/serial.h +++ b/src/include/86box/serial.h @@ -16,7 +16,7 @@ * Fred N. van Kempen, * * Copyright 2008-2020 Sarah Walker. - * Copyright 2016-2020 Miran Grca. + * Copyright 2016-2025 Miran Grca. * Copyright 2017-2020 Fred N. van Kempen. */ @@ -137,6 +137,7 @@ extern serial_t *serial_attach_ex_2(int port, extern void serial_remove(serial_t *dev); extern void serial_set_type(serial_t *dev, int type); extern void serial_setup(serial_t *dev, uint16_t addr, uint8_t irq); +extern void serial_irq(serial_t *dev, uint8_t irq); extern void serial_clear_fifo(serial_t *dev); extern void serial_write_fifo(serial_t *dev, uint8_t dat); extern void serial_set_next_inst(int ni); diff --git a/src/include/86box/serial_passthrough.h b/src/include/86box/serial_passthrough.h index 7ca6479d6..c5454194a 100644 --- a/src/include/86box/serial_passthrough.h +++ b/src/include/86box/serial_passthrough.h @@ -55,7 +55,7 @@ typedef struct serial_passthrough_s { void *backend_priv; /* Private platform backend data */ } serial_passthrough_t; -extern bool serial_passthrough_enabled[SERIAL_MAX]; +extern bool serial_passthrough_enabled[SERIAL_MAX - 1]; extern const device_t serial_passthrough_device; extern void serial_passthrough_init(void); diff --git a/src/include/86box/sio.h b/src/include/86box/sio.h index 2dbe97ab0..0b07d7a13 100644 --- a/src/include/86box/sio.h +++ b/src/include/86box/sio.h @@ -16,13 +16,20 @@ #ifndef EMU_SIO_H #define EMU_SIO_H -extern void vt82c686_sio_write(uint8_t addr, uint8_t val, void *priv); - +/* ACC Micro */ extern const device_t acc3221_device; + +/* Acer / ALi */ extern const device_t ali5105_device; + extern const device_t ali5123_device; -extern const device_t f82c710_device; + +/* Chips & Technologies */ extern const device_t f82c606_device; + +extern const device_t f82c710_device; + +/* SM(S)C */ extern const device_t fdc37c651_device; extern const device_t fdc37c651_ide_device; extern const device_t fdc37c661_device; @@ -35,33 +42,48 @@ extern const device_t fdc37c665_ide_device; extern const device_t fdc37c665_ide_pri_device; extern const device_t fdc37c665_ide_sec_device; extern const device_t fdc37c666_device; -extern const device_t fdc37c67x_device; + extern const device_t fdc37c669_device; extern const device_t fdc37c669_370_device; -extern const device_t fdc37c931apm_device; -extern const device_t fdc37c931apm_compaq_device; -extern const device_t fdc37c932fr_device; -extern const device_t fdc37c932qf_device; -extern const device_t fdc37c932_device; -extern const device_t fdc37c935_device; -extern const device_t fdc37c935_370_device; -extern const device_t fdc37c935_no_nvr_device; + +extern const device_t fdc37c67x_device; + +#define FDC37C93X_NORMAL 0x0002 +#define FDC37C93X_FR 0x0003 +#define FDC37C93X_APM 0x0030 +#define FDC37C93X_CHIP_ID 0x00ff + +#define FDC37C931 0x0100 /* Compaq KBC firmware and configuration registers on GPIO ports. */ +#define FDC37C932 0x0200 /* AMI '5' Megakey KBC firmware. */ +#define FDC37C933 0x0300 /* IBM KBC firmware. */ +#define FDC37C935 0x0500 /* Phoenix Multikey/42 1.38 KBC firmware. */ +#define FDC37C937 0x0700 /* Phoenix Multikey/42i 4.16 KBC firmware. */ +#define FDC37C93X_KBC 0x0f00 + +#define FDC37C93X_NO_NVR 0x1000 +#define FDC37C93X_370 0x2000 + +extern const device_t fdc37c93x_device; + extern const device_t fdc37m60x_device; extern const device_t fdc37m60x_370_device; + +/* ITE */ extern const device_t it8661f_device; extern const device_t it8671f_device; + +/* Intel */ extern const device_t i82091aa_device; +extern const device_t i82091aa_26e_device; extern const device_t i82091aa_398_device; extern const device_t i82091aa_ide_pri_device; extern const device_t i82091aa_ide_device; -extern const device_t pc87306_device; -extern const device_t pc87307_device; -extern const device_t pc87307_15c_device; -extern const device_t pc87307_both_device; -extern const device_t pc87309_device; -extern const device_t pc87309_15c_device; + +/* National Semiconductors */ extern const device_t pc87310_device; extern const device_t pc87310_ide_device; + +extern const device_t pc87306_device; extern const device_t pc87311_device; extern const device_t pc87311_ide_device; extern const device_t pc87332_device; @@ -69,35 +91,80 @@ extern const device_t pc87332_398_device; extern const device_t pc87332_398_ide_device; extern const device_t pc87332_398_ide_sec_device; extern const device_t pc87332_398_ide_fdcon_device; -extern const device_t pc97307_device; + +#define PCX7307_PC87307 0x00c0 +#define PCX7307_PC97307 0x00cf + +#define PC87309_PC87309 0x00e0 + +#define PCX730X_CHIP_ID 0x00ff + +#define PCX730X_AMI 0x0200 /* AMI '5' Megakey KBC firmware. */ +#define PCX730X_PHOENIX_42 0x0500 /* Phoenix Multikey/42 1.37 KBC firmware. */ +#define PCX730X_PHOENIX_42I 0x0700 /* Phoenix Multikey/42i 4.16 KBC firmware. */ +#define PCX730X_KBC 0x0f00 + +#define PCX730X_15C 0x2000 + +extern const device_t pc87307_device; + +extern const device_t pc87309_device; + +/* LG Prime */ extern const device_t prime3b_device; extern const device_t prime3b_ide_device; extern const device_t prime3c_device; extern const device_t prime3c_ide_device; + +/* IBM PS/1 */ extern const device_t ps1_m2133_sio; + +/* Super I/O Detect */ #ifdef USE_SIO_DETECT extern const device_t sio_detect_device; #endif /* USE_SIO_DETECT */ + +/* UMC */ +extern const device_t um82c862f_device; +extern const device_t um82c862f_ide_device; +extern const device_t um82c863f_device; +extern const device_t um82c863f_ide_device; extern const device_t um8663af_device; extern const device_t um8663af_ide_device; extern const device_t um8663af_sec_device; extern const device_t um8663bf_device; extern const device_t um8663bf_ide_device; extern const device_t um8663bf_sec_device; + extern const device_t um8669f_device; extern const device_t um8669f_ide_device; extern const device_t um8669f_ide_sec_device; + +/* VIA */ +extern void vt82c686_sio_write(uint8_t addr, uint8_t val, void *priv); + extern const device_t via_vt82c686_sio_device; + +/* VLSI */ extern const device_t vl82c113_device; + +/* Winbond */ extern const device_t w83787f_88h_device; extern const device_t w83787f_device; extern const device_t w83787f_ide_device; extern const device_t w83787f_ide_en_device; extern const device_t w83787f_ide_sec_device; + extern const device_t w83877f_device; extern const device_t w83877f_president_device; extern const device_t w83877tf_device; extern const device_t w83877tf_acorp_device; + +#define TYPE_W83977EF 0x52F0 +#define TYPE_W83977F 0x9771 +#define TYPE_W83977TF 0x9773 +#define TYPE_W83977ATF 0x9774 + extern const device_t w83977f_device; extern const device_t w83977f_370_device; extern const device_t w83977tf_device; diff --git a/src/include/86box/snd_ac97.h b/src/include/86box/snd_ac97.h index 45a921863..a365f5afa 100644 --- a/src/include/86box/snd_ac97.h +++ b/src/include/86box/snd_ac97.h @@ -100,6 +100,7 @@ #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_W83971D AC97_VENDOR_ID('W', 'E', 'C', 0x01) #define AC97_CODEC_WM9701A AC97_VENDOR_ID('W', 'M', 'L', 0x00) typedef struct ac97_vendor_reg_t { @@ -150,6 +151,7 @@ extern const device_t cs4297a_device; extern const device_t stac9708_device; extern const device_t stac9721_device; extern const device_t tr28023_device; +extern const device_t w83971d_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 319f9bf24..a7e38a6f8 100644 --- a/src/include/86box/snd_ad1848.h +++ b/src/include/86box/snd_ad1848.h @@ -16,7 +16,7 @@ * * Copyright 2008-2020 Sarah Walker. * Copyright 2018-2020 TheCollector1995. - * Copyright 2021 RichardG. + * Copyright 2021-2025 RichardG. */ #ifndef SOUND_AD1848_H @@ -26,8 +26,10 @@ enum { AD1848_TYPE_DEFAULT = 0, AD1848_TYPE_CS4248 = 1, AD1848_TYPE_CS4231 = 2, - AD1848_TYPE_CS4235 = 3, - AD1848_TYPE_CS4236 = 4 + AD1848_TYPE_CS4232 = 3, + AD1848_TYPE_CS4236 = 4, + AD1848_TYPE_CS4236B = 5, + AD1848_TYPE_CS4235 = 6 }; typedef struct ad1848_t { diff --git a/src/include/86box/snd_mmb.h b/src/include/86box/snd_mmb.h new file mode 100644 index 000000000..6e5f7d3a8 --- /dev/null +++ b/src/include/86box/snd_mmb.h @@ -0,0 +1,42 @@ +/* + * 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. + * + * Mindscape Music Board emulation. + * + * Authors: Roy Baer, + * Jasmine Iwanek, + * + * Copyright 2025 Roy Baer. + * Copyright 2025 Jasmine Iwanek. + */ +#ifndef _SOUND_SND_MMB_H_ +#define _SOUND_SND_MMB_H_ + +#define MMB_FREQ FREQ_48000 + +/* NOTE: + * The constant clock rate is a deviation from the real hardware which has + * the design flaw that the clock rate is always half the ISA bus clock. + */ +#define MMB_CLOCK 2386364 + +typedef struct ay_3_891x_s { + uint8_t index; + uint8_t regs[16]; + struct ayumi chip; +} ay_3_891x_t; + +typedef struct mmb_s { + ay_3_891x_t first; + ay_3_891x_t second; + + int16_t buffer[SOUNDBUFLEN * 2]; + int pos; +} mmb_t; + +#endif /* _SOUND_SND_MMB_H_ */ diff --git a/src/include/86box/sound.h b/src/include/86box/sound.h index 645d974dd..985abe777 100644 --- a/src/include/86box/sound.h +++ b/src/include/86box/sound.h @@ -170,7 +170,9 @@ extern const device_t sb_awe64_gold_device; /* Crystal CS423x */ extern const device_t cs4235_device; extern const device_t cs4235_onboard_device; +extern const device_t cs4236_onboard_device; extern const device_t cs4236b_device; +extern const device_t cs4236b_onboard_device; extern const device_t cs4237b_device; extern const device_t cs4238b_device; @@ -195,6 +197,7 @@ extern const device_t ct5880_onboard_device; /* Gravis UltraSound and UltraSound Max */ extern const device_t gus_device; +extern const device_t gus_max_device; /* IBM PS/1 Audio Card */ extern const device_t ps1snd_device; @@ -203,6 +206,9 @@ extern const device_t ps1snd_device; extern const device_t ssi2001_device; extern const device_t entertainer_device; +/* Mindscape Music Board */ +extern const device_t mmb_device; + /* Pro Audio Spectrum Plus, 16, and 16D */ extern const device_t pasplus_device; extern const device_t pas16_device; diff --git a/src/include/86box/timer.h b/src/include/86box/timer.h index 25aff6b2f..37a03d9ca 100644 --- a/src/include/86box/timer.h +++ b/src/include/86box/timer.h @@ -1,7 +1,7 @@ #ifndef _TIMER_H_ #define _TIMER_H_ -#include "cpu.h" +extern uint64_t tsc; /* Maximum period, currently 1 second. */ #define MAX_USEC64 1000000ULL diff --git a/src/include/86box/ui.h b/src/include/86box/ui.h index c12eb73a0..783400ebc 100644 --- a/src/include/86box/ui.h +++ b/src/include/86box/ui.h @@ -65,6 +65,7 @@ extern void ui_sb_update_panes(void); extern void ui_sb_update_text(void); extern void ui_sb_update_tip(int meaning); extern void ui_sb_update_icon(int tag, int active); +extern void ui_sb_update_icon_write(int tag, int write); extern void ui_sb_update_icon_state(int tag, int state); extern void ui_sb_set_text_w(wchar_t *wstr); extern void ui_sb_set_text(char *str); diff --git a/src/include/86box/version.h.in b/src/include/86box/version.h.in index 5ebf7dba9..17c5b3068 100644 --- a/src/include/86box/version.h.in +++ b/src/include/86box/version.h.in @@ -14,6 +14,8 @@ * * Copyright 2020 Miran Grca. */ +#ifndef EMU_VERSION_H +#define EMU_VERSION_H #define _LSTR(s) L ## s #define LSTR(s) _LSTR(s) @@ -58,3 +60,5 @@ # define EMU_DOCS_URL "https://86box.readthedocs.io" #endif #define EMU_DOCS_URL_W LSTR(EMU_DOCS_URL) + +#endif /*EMU_VERSION_H*/ diff --git a/src/include/86box/vid_8514a.h b/src/include/86box/vid_8514a.h index 57e98cc44..9d19d916c 100644 --- a/src/include/86box/vid_8514a.h +++ b/src/include/86box/vid_8514a.h @@ -18,6 +18,25 @@ #ifndef VIDEO_8514A_H #define VIDEO_8514A_H +#define INT_VSY (1 << 0) +#define INT_GE_BSY (1 << 1) +#define INT_FIFO_OVR (1 << 2) +#define INT_FIFO_EMP (1 << 3) +#define INT_MASK 0xf + +typedef enum { + IBM_8514A_TYPE = 0, + ATI_38800_TYPE, + ATI_68800_TYPE, + TYPE_MAX +} ibm8514_card_type; + +typedef enum { + IBM = 0, + ATI, + EXTENSIONS_MAX +} ibm8514_extensions_t; + typedef struct hwcursor8514_t { int ena; int x; @@ -52,7 +71,7 @@ typedef struct ibm8514_t { int force_old_addr; int type; - int local; + ibm8514_card_type local; int bpp; int on; int accel_bpp; @@ -61,6 +80,7 @@ typedef struct ibm8514_t { uint32_t vram_mask; uint32_t pallook[512]; uint32_t bios_addr; + uint32_t memaddr_latch; PALETTE vgapal; uint8_t hwcursor_oddeven; @@ -83,6 +103,7 @@ typedef struct ibm8514_t { uint16_t subsys_cntl; uint16_t setup_md; uint16_t advfunc_cntl; + uint16_t advfunc_cntl_old; uint16_t cur_y; uint16_t cur_x; int16_t destx; @@ -100,8 +121,10 @@ typedef struct ibm8514_t { uint16_t wrt_mask; uint16_t rd_mask; uint16_t color_cmp; - uint16_t bkgd_mix; - uint16_t frgd_mix; + uint8_t bkgd_mix; + uint8_t frgd_mix; + uint8_t bkgd_sel; + uint8_t frgd_sel; uint16_t multifunc_cntl; uint16_t multifunc[16]; uint16_t clip_right; @@ -117,6 +140,8 @@ typedef struct ibm8514_t { int y1; int y2; int temp_cnt; + int16_t dx_ibm; + int16_t dy_ibm; int16_t cx; int16_t cx_back; int16_t cy; @@ -150,6 +175,14 @@ typedef struct ibm8514_t { int ydir; int linedraw; uint32_t ge_offset; + uint32_t src_ge_offset; + uint32_t dst_ge_offset; + uint16_t src_pitch; + uint16_t dst_pitch; + int64_t cur_x_24bpp; + int64_t cur_y_24bpp; + int64_t dest_x_24bpp; + int64_t dest_y_24bpp; } accel; uint16_t test; @@ -187,8 +220,8 @@ typedef struct ibm8514_t { int lastline_draw; int displine; int fullchange; - uint32_t ma; - uint32_t maback; + uint32_t memaddr; + uint32_t memaddr_backup; uint8_t *vram; uint8_t *changedvram; @@ -203,7 +236,7 @@ typedef struct ibm8514_t { int hdisp; int hdisp2; int hdisped; - int sc; + int scanline; int vsyncstart; int vsyncwidth; int vtotal; @@ -213,13 +246,12 @@ typedef struct ibm8514_t { int vdisp2; int disp_cntl; int interlace; - uint8_t subsys_cntl; + uint16_t subsys_cntl; uint8_t subsys_stat; - atomic_int fifo_idx; - atomic_int ext_fifo_idx; atomic_int force_busy; atomic_int force_busy2; + atomic_int fifo_idx; int blitter_busy; uint64_t blitter_time; @@ -227,14 +259,27 @@ typedef struct ibm8514_t { int pitch; int ext_pitch; int ext_crt_pitch; - int extensions; + ibm8514_extensions_t extensions; + int onboard; int linear; uint32_t vram_amount; int vram_512k_8514; int vendor_mode; + int _8514on; + int _8514crt; PALETTE _8514pal; latch8514_t latch; + + void (*vblank_start)(void *priv); + void (*accel_out_fifo)(void *priv, uint16_t port, uint16_t val, int len); + void (*update_irqs)(void *priv); + } ibm8514_t; +#define IBM_8514A (((dev->local & 0xff) == IBM_8514A_TYPE) && (dev->extensions == IBM)) +#define ATI_8514A_ULTRA (((dev->local & 0xff) == IBM_8514A_TYPE) && (dev->extensions == ATI)) +#define ATI_GRAPHICS_ULTRA ((dev->local & 0xff) == ATI_38800_TYPE) +#define ATI_MACH32 ((dev->local & 0xff) == ATI_68800_TYPE) + #endif /*VIDEO_8514A_H*/ diff --git a/src/include/86box/vid_ati_mach8.h b/src/include/86box/vid_ati_mach8.h index 849446def..ad5281ac3 100644 --- a/src/include/86box/vid_ati_mach8.h +++ b/src/include/86box/vid_ati_mach8.h @@ -18,6 +18,12 @@ #ifndef VIDEO_ATI_MACH8_H #define VIDEO_ATI_MACH8_H +typedef enum { + ATI_68875 = 0, + ATI_68860, + RAMDAC_MAX +} mach_ramdac_type; + typedef struct mach_t { ati_eeprom_t eeprom; svga_t svga; @@ -25,6 +31,7 @@ typedef struct mach_t { rom_t bios_rom; rom_t bios_rom2; mem_mapping_t mmio_linear_mapping; + mem_mapping_t banked_mapping; int mca_bus; int pci_bus; @@ -38,7 +45,7 @@ typedef struct mach_t { uint8_t irq_state; int index; - int ramdac_type; + mach_ramdac_type ramdac_type; int old_mode; uint16_t config1; @@ -71,7 +78,14 @@ typedef struct mach_t { uint8_t bank_r; uint16_t shadow_set; uint16_t shadow_cntl; - int override_resolution; + uint8_t overscan_col_8; + uint8_t overscan_b_col_24; + uint8_t overscan_g_col_24; + uint8_t overscan_r_col_24; + uint16_t fifo_test_data[17]; + uint8_t old_on1; + uint8_t old_on2; + int crt_resolution; struct { uint8_t line_idx; @@ -79,9 +93,9 @@ typedef struct mach_t { uint8_t patt_idx; uint8_t patt_len; uint8_t pix_trans[2]; - uint8_t eeprom_control; uint8_t alu_bg_fn; uint8_t alu_fg_fn; + uint16_t eeprom_control; uint16_t clip_left; uint16_t clip_right; uint16_t clip_top; @@ -97,9 +111,13 @@ typedef struct mach_t { uint16_t clock_sel; uint16_t crt_pitch; uint16_t ge_pitch; + uint16_t src_pitch; + uint16_t dst_pitch; uint16_t dest_cmp_fn; uint16_t dp_config; uint16_t ext_ge_config; + uint16_t crt_offset_lo; + uint16_t crt_offset_hi; uint16_t ge_offset_lo; uint16_t ge_offset_hi; uint16_t linedraw_opt; @@ -125,6 +143,7 @@ typedef struct mach_t { int16_t dx_end; int16_t dy; int16_t dy_end; + int16_t dx_first_row_start; int16_t dx_start; int16_t dy_start; int16_t cy; @@ -148,17 +167,22 @@ typedef struct mach_t { int src_stepx; uint8_t mono_pattern_normal[16]; uint8_t color_pattern[32]; + uint16_t color_pattern_hicol[8]; int mono_pattern[8][8]; - uint32_t ge_offset; + uint32_t src_ge_offset; + uint32_t dst_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; + int64_t src_x_scan; + int64_t src_y_scan; } accel; atomic_int force_busy; + atomic_int fifo_test_idx; } mach_t; #endif /*VIDEO_ATI_MACH8_H*/ diff --git a/src/include/86box/vid_cga.h b/src/include/86box/vid_cga.h index a503d12ba..04616431e 100644 --- a/src/include/86box/vid_cga.h +++ b/src/include/86box/vid_cga.h @@ -11,20 +11,71 @@ * * * Authors: Sarah Walker, - * Miran Grca, + * Miran Grca, , + * Connor Hyde / starfrost, * * Copyright 2008-2018 Sarah Walker. * Copyright 2016-2018 Miran Grca. + * Copyright 2025 starfrost (refactoring) */ #ifndef VIDEO_CGA_H #define VIDEO_CGA_H +// Mode flags for the CGA. +// Set by writing to 3D8 +typedef enum cga_mode_flags_e +{ + CGA_MODE_FLAG_HIGHRES = 1 << 0, // 80-column text mode + CGA_MODE_FLAG_GRAPHICS = 1 << 1, // Graphics mode + CGA_MODE_FLAG_BW = 1 << 2, // Black and white + CGA_MODE_FLAG_VIDEO_ENABLE = 1 << 3, // 0 = no video (as if the video was 0) + CGA_MODE_FLAG_HIGHRES_GRAPHICS = 1 << 4, // 640*200 mode. Corrupts text mode if CGA_MODE_FLAG_GRAPHICS not set. + CGA_MODE_FLAG_BLINK = 1 << 5, // If this is set, bit 5 of textmode characters blinks. Otherwise it is a high-intensity bg mode. +} cga_mode_flags; + +// Motorola MC6845 CRTC registers +typedef enum cga_crtc_registers_e +{ + CGA_CRTC_HTOTAL = 0x0, // Horizontal total (total number of characters incl. hsync) + CGA_CRTC_HDISP = 0x1, // Horizontal display + CGA_CRTC_HSYNC_POS = 0x2, // Horizontal position of horizontal ysnc + CGA_CRTC_HSYNC_WIDTH = 0x3, // Width of horizontal sync + CGA_CRTC_VTOTAL = 0x4, // Vertical total (total number of scanlines incl. vsync) + CGA_CRTC_VTOTAL_ADJUST = 0x5, // Vertical total adjust value + CGA_CRTC_VDISP = 0x6, // Vertical display (total number of displayed scanline) + CGA_CRTC_VSYNC = 0x7, // Vertical sync scanline number + CGA_CRTC_INTERLACE = 0x8, // Interlacing mode + CGA_CRTC_MAX_SCANLINE_ADDR = 0x9, // Maximum scanline address + CGA_CRTC_CURSOR_START = 0xA, // Cursor start scanline + CGA_CRTC_CURSOR_END = 0xB, // Cursor end scanline + CGA_CRTC_START_ADDR_HIGH = 0xC, // Screen start address high 8 bits + CGA_CRTC_START_ADDR_LOW = 0xD, // Screen start address low 8 bits + CGA_CRTC_CURSOR_ADDR_HIGH = 0xE, // Cursor address high 8 bits + CGA_CRTC_CURSOR_ADDR_LOW = 0xF, // Cursor address low 8 bits + CGA_CRTC_LIGHT_PEN_ADDR_HIGH = 0x10, // Light pen address high 8 bits (not currently supported) + CGA_CRTC_LIGHT_PEN_ADDR_LOW = 0x11, // Light pen address low 8 bits (not currently supported) +} cga_crtc_registers; + +// Registers for the CGA +typedef enum cga_registers_e +{ + CGA_REGISTER_CRTC_INDEX = 0x3D4, + CGA_REGISTER_CRTC_DATA = 0x3D5, + CGA_REGISTER_MODE_CONTROL = 0x3D8, + CGA_REGISTER_COLOR_SELECT = 0x3D9, + CGA_REGISTER_STATUS = 0x3DA, + CGA_REGISTER_CLEAR_LIGHT_PEN_LATCH = 0x3DB, + CGA_REGISTER_SET_LIGHT_PEN_LATCH = 0x3DC, +} cga_registers; + +#define CGA_NUM_CRTC_REGS 32 + typedef struct cga_t { mem_mapping_t mapping; int crtcreg; - uint8_t crtc[32]; + uint8_t crtc[CGA_NUM_CRTC_REGS]; uint8_t cgastat; @@ -36,17 +87,16 @@ typedef struct cga_t { int fontbase; int linepos; int displine; - int sc; + int scanline; int vc; int cgadispon; - int con; - int coff; + int cursorvisible; // Determines if the cursor is visible FOR THE CURRENT SCANLINE. int cursoron; int cgablink; int vsynctime; int vadj; - uint16_t ma; - uint16_t maback; + uint16_t memaddr; + uint16_t memaddr_backup; int oddeven; uint64_t dispontime; diff --git a/src/include/86box/vid_ega.h b/src/include/86box/vid_ega.h index 0bccd607e..beef6f98d 100644 --- a/src/include/86box/vid_ega.h +++ b/src/include/86box/vid_ega.h @@ -39,7 +39,7 @@ typedef struct ega_t { uint8_t lb; uint8_t lc; uint8_t ld; - uint8_t stat; + uint8_t status; uint8_t colourcompare; uint8_t colournocare; uint8_t scrblank; @@ -47,13 +47,12 @@ typedef struct ega_t { uint8_t ctl_mode; uint8_t color_mux; uint8_t dot; - uint8_t crtc[32]; - uint8_t gdcreg[16]; + uint8_t crtc[256]; + uint8_t gdcreg[256]; uint8_t attrregs[32]; uint8_t seqregs[64]; uint8_t egapal[16]; uint8_t regs[256]; - uint8_t *vram; uint16_t light_pen; @@ -69,11 +68,12 @@ typedef struct ega_t { int chain4; int chain2_read; int chain2_write; - int con; + int cursorvisible; int oddeven_page; int oddeven_chain; int vc; - int sc; + int real_vc; + int scanline; int dispon; int hdisp_on; int cursoron; @@ -113,13 +113,16 @@ typedef struct ega_t { int remap_required; int actual_type; int chipset; + int mono_display; + + int mda_attr_to_color_table[256][2][2]; uint32_t charseta; uint32_t charsetb; - uint32_t ma_latch; - uint32_t ma; - uint32_t maback; - uint32_t ca; + uint32_t memaddr_latch; + uint32_t memaddr; + uint32_t memaddr_backup; + uint32_t cursoraddr; uint32_t vram_limit; uint32_t overscan_color; uint32_t cca; @@ -140,6 +143,13 @@ typedef struct ega_t { uint32_t (*remap_func)(struct ega_t *ega, uint32_t in_addr); void (*render)(struct ega_t *svga); + + /* If set then another device is driving the monitor output and the EGA + card should not attempt to display anything. */ + void (*render_override)(void *priv); + void * priv_parent; + + uint8_t alt_addr; /* 0 for 0x3XX range, 1 for 0x2XX range */ } ega_t; #endif @@ -150,6 +160,8 @@ extern const device_t sega_device; extern const device_t atiega800p_device; extern const device_t iskra_ega_device; extern const device_t et2000_device; +extern const device_t jega_device; +extern const device_t jvga_device; #endif extern int update_overscan; @@ -172,15 +184,16 @@ 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 void ega_set_type(void *priv, uint32_t local); extern int firstline_draw; extern int lastline_draw; extern int displine; -extern int sc; +extern int scanline; -extern uint32_t ma; -extern uint32_t ca; -extern int con; +extern uint32_t memaddr; +extern uint32_t cursoraddr; +extern int cursorvisible; extern int cursoron; extern int cgablink; @@ -199,4 +212,19 @@ void ega_render_text(ega_t *ega); void ega_render_graphics(ega_t *ega); #endif +enum { + EGA_IBM = 0, + EGA_COMPAQ, + EGA_SUPEREGA, + EGA_ATI800P, + EGA_ISKRA, + EGA_TSENG +}; + +enum { + EGA_TYPE_IBM = 0, + EGA_TYPE_OTHER = 1, + EGA_TYPE_COMPAQ = 2 +}; + #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 b01bb2b0e..1b0f7676c 100644 --- a/src/include/86box/vid_ega_render_remap.h +++ b/src/include/86box/vid_ega_render_remap.h @@ -33,9 +33,9 @@ } \ \ if (nr & VAR_ROW0_MA13) \ - out_addr = (out_addr & ~0x8000) | ((ega->sc & 1) ? 0x8000 : 0); \ + out_addr = (out_addr & ~0x8000) | ((ega->scanline & 1) ? 0x8000 : 0); \ if (nr & VAR_ROW1_MA14) \ - out_addr = (out_addr & ~0x10000) | ((ega->sc & 2) ? 0x10000 : 0); \ + out_addr = (out_addr & ~0x10000) | ((ega->scanline & 2) ? 0x10000 : 0); \ \ return out_addr; \ } diff --git a/src/include/86box/vid_hercules.h b/src/include/86box/vid_hercules.h index c58a50aa3..1d62bee67 100644 --- a/src/include/86box/vid_hercules.h +++ b/src/include/86box/vid_hercules.h @@ -13,10 +13,12 @@ * Authors: Sarah Walker, * Miran Grca, * Jasmine Iwanek, - * + * Connor Hyde / starfrost, + */ #ifndef VIDEO_MDA_H #define VIDEO_MDA_H +// Defines +#define MDA_CRTC_NUM_REGISTERS 32 + +// Enums & structures + +typedef enum mda_registers_e +{ + MDA_REGISTER_START = 0x3B0, + + MDA_REGISTER_CRTC_INDEX = 0x3B4, + MDA_REGISTER_CRTC_DATA = 0x3B5, + MDA_REGISTER_MODE_CONTROL = 0x3B8, + MDA_REGISTER_CRT_STATUS = 0x3BA, + MDA_REGISTER_PARALLEL_DATA = 0x3BC, + MDA_REGISTER_PRINTER_STATUS = 0x3BD, + MDA_REGISTER_PRINTER_CONTROL = 0x3BE, + + MDA_REGISTER_END = 0x3BF, +} mda_registers; + +// Motorola MC6845 CRTC registers (without light pen for some reason) +typedef enum mda_crtc_registers_e +{ + MDA_CRTC_HTOTAL = 0x0, // Horizontal total (total number of characters incl. hsync) + MDA_CRTC_HDISP = 0x1, // Horizontal display + MDA_CRTC_HSYNC_POS = 0x2, // Horizontal position of horizontal ysnc + MDA_CRTC_HSYNC_WIDTH = 0x3, // Width of horizontal sync + MDA_CRTC_VTOTAL = 0x4, // Vertical total (total number of scanlines incl. vsync) + MDA_CRTC_VTOTAL_ADJUST = 0x5, // Vertical total adjust value + MDA_CRTC_VDISP = 0x6, // Vertical display (total number of displayed scanline) + MDA_CRTC_VSYNC = 0x7, // Vertical sync scanline number + MDA_CRTC_INTERLACE = 0x8, // Interlacing mode + MDA_CRTC_MAX_SCANLINE_ADDR = 0x9, // Maximum scanline address + MDA_CRTC_CURSOR_START = 0xA, // Cursor start scanline + MDA_CRTC_CURSOR_END = 0xB, // Cursor end scanline + MDA_CRTC_START_ADDR_HIGH = 0xC, // Screen start address high 8 bits + MDA_CRTC_START_ADDR_LOW = 0xD, // Screen start address low 8 bits + MDA_CRTC_CURSOR_ADDR_HIGH = 0xE, // Cursor address high 8 bits + MDA_CRTC_CURSOR_ADDR_LOW = 0xF, // Cursor address low 8 bits +} mda_crtc_registers; + +typedef enum mda_mode_flags_e +{ + MDA_MODE_HIGHRES = 1 << 0, // MUST be enabled for sane operation + MDA_MODE_BW = 1 << 1, // UNUSED in most cases. Not present on Hercules + MDA_MODE_VIDEO_ENABLE = 1 << 3, + MDA_MODE_BLINK = 1 << 5, +} mda_mode_flags; + +typedef enum mda_colors_e +{ + MDA_COLOR_BLACK = 0, + MDA_COLOR_BLUE = 1, + MDA_COLOR_GREEN = 2, + MDA_COLOR_CYAN = 3, + MDA_COLOR_RED = 4, + MDA_COLOR_MAGENTA = 5, + MDA_COLOR_BROWN = 6, + MDA_COLOR_WHITE = 7, + MDA_COLOR_GREY = 8, + MDA_COLOR_BRIGHT_BLUE = 9, + MDA_COLOR_BRIGHT_GREEN = 10, + MDA_COLOR_BRIGHT_CYAN = 11, + MDA_COLOR_BRIGHT_RED = 12, + MDA_COLOR_BRIGHT_MAGENTA = 13, + MDA_COLOR_BRIGHT_YELLOW = 14, + MDA_COLOR_BRIGHT_WHITE = 15, +} mda_colors; + typedef struct mda_t { mem_mapping_t mapping; - uint8_t crtc[32]; - int crtcreg; + uint8_t crtc[MDA_CRTC_NUM_REGISTERS]; + int32_t crtcreg; - uint8_t ctrl; - uint8_t stat; + uint8_t mode; + uint8_t status; - uint64_t dispontime; - uint64_t dispofftime; - pc_timer_t timer; + uint64_t dispontime; + uint64_t dispofftime; + pc_timer_t timer; - int firstline; - int lastline; + int32_t firstline; + int32_t lastline; - int fontbase; - 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; - int prev_monitor_index; + int32_t fontbase; + int32_t linepos; + int32_t displine; + int32_t vc; + int32_t scanline; + uint16_t memaddr; + uint16_t memaddr_backup; + int32_t cursorvisible; + int32_t cursoron; + int32_t dispon; + int32_t blink; + int32_t vsynctime; + int32_t vadj; + int32_t monitor_index; + int32_t prev_monitor_index; + int32_t monitor_type; // Used for MDA Colour support (REV0 u64) uint8_t *vram; } mda_t; diff --git a/src/include/86box/vid_pgc.h b/src/include/86box/vid_pgc.h index 35e2d9e42..dd6a45b98 100644 --- a/src/include/86box/vid_pgc.h +++ b/src/include/86box/vid_pgc.h @@ -115,14 +115,13 @@ typedef struct pgc { int displine; int vc; int cgadispon; - int con; - int coff; + int cursorvisible; int cursoron; int cgablink; int vsynctime; int vadj; - uint16_t ma; - uint16_t maback; + uint16_t memaddr; + uint16_t memaddr_backup; int oddeven; uint64_t dispontime; diff --git a/src/include/86box/vid_ps55da2.h b/src/include/86box/vid_ps55da2.h new file mode 100644 index 000000000..f029b5751 --- /dev/null +++ b/src/include/86box/vid_ps55da2.h @@ -0,0 +1,24 @@ +/* + * 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. + * + * IBM PS/55 Display Adapter II emulation. + * + * + * + * Authors: Akamaki. + * + * Copyright 2024 Akamaki. + */ + +#ifndef VIDEO_DA2_DEVICE_H +#define VIDEO_DA2_DEVICE_H + +#ifdef EMU_DEVICE_H +extern const device_t ps55da2_device; +#endif +#endif /*VIDEO_DA2_DEVICE_H*/ diff --git a/src/include/86box/vid_svga.h b/src/include/86box/vid_svga.h index d38b7614b..cc67e70bc 100644 --- a/src/include/86box/vid_svga.h +++ b/src/include/86box/vid_svga.h @@ -100,12 +100,12 @@ typedef struct svga_t { int dispon; int hdisp_on; int vc; - int sc; + int scanline; int linepos; int vslines; int linecountff; int oddeven; - int con; + int cursorvisible; int cursoron; int blink; int scrollcache; @@ -116,6 +116,7 @@ typedef struct svga_t { int lastline_draw; int displine; int fullchange; + int left_overscan; int x_add; int y_add; int pan; @@ -135,6 +136,7 @@ typedef struct svga_t { int packed_4bpp; int ps_bit_bug; int ati_4color; + int vblankend; /*The three variables below allow us to implement memory maps like that seen on a 1MB Trio64 : 0MB-1MB - VRAM @@ -151,15 +153,15 @@ typedef struct svga_t { uint32_t charseta; uint32_t charsetb; uint32_t adv_flags; - uint32_t ma_latch; + uint32_t memaddr_latch; uint32_t ca_adj; - uint32_t ma; - uint32_t maback; + uint32_t memaddr; + uint32_t memaddr_backup; uint32_t write_bank; uint32_t read_bank; uint32_t extra_banks[2]; uint32_t banked_mask; - uint32_t ca; + uint32_t cursoraddr; uint32_t overscan_color; uint32_t *map8; uint32_t pallook[512]; @@ -171,11 +173,11 @@ typedef struct svga_t { latch_t latch; pc_timer_t timer; - pc_timer_t timer8514; + pc_timer_t timer_8514; pc_timer_t timer_xga; double clock; - double clock8514; + double clock_8514; double clock_xga; double multiplier; @@ -189,6 +191,7 @@ typedef struct svga_t { void (*render)(struct svga_t *svga); void (*render8514)(struct svga_t *svga); + void (*render_xga)(struct svga_t *svga); void (*recalctimings_ex)(struct svga_t *svga); void (*video_out)(uint16_t addr, uint8_t val, void *priv); @@ -202,6 +205,14 @@ typedef struct svga_t { void (*vblank_start)(struct svga_t *svga); + void (*write)(uint32_t addr, uint8_t val, void *priv); + void (*writew)(uint32_t addr, uint16_t val, void *priv); + void (*writel)(uint32_t addr, uint32_t val, void *priv); + + uint8_t (*read)(uint32_t addr, void *priv); + uint16_t (*readw)(uint32_t addr, void *priv); + uint32_t (*readl)(uint32_t addr, void *priv); + void (*ven_write)(struct svga_t *svga, uint8_t val, uint32_t addr); float (*getclock)(int clock, void *priv); float (*getclock8514)(int clock, void *priv); @@ -220,6 +231,11 @@ typedef struct svga_t { int override; void *priv; + int vga_enabled; + /* The PS/55 POST BIOS has a special monitor detection for its internal VGA + when the monitor is connected to the Display Adapter. */ + int cable_connected; + uint8_t crtc[256]; uint8_t gdcreg[256]; uint8_t attrregs[32]; @@ -296,8 +312,16 @@ typedef struct svga_t { void * ext8514; void * clock_gen8514; void * xga; + + /* If set then another device is driving the monitor output and the EGA + card should not attempt to display anything. */ + void (*render_override)(void *priv); + void * priv_parent; + + void * local; } svga_t; +extern void ibm8514_set_poll(svga_t *svga); extern void ibm8514_poll(void *priv); extern void ibm8514_recalctimings(svga_t *svga); extern uint8_t ibm8514_ramdac_in(uint16_t port, void *priv); @@ -320,10 +344,11 @@ extern void ati8514_mca_write(int port, uint8_t val, void *priv); extern void ati8514_pos_write(uint16_t port, uint8_t val, void *priv); extern void ati8514_init(svga_t *svga, void *ext8514, void *dev8514); -extern void xga_write_test(uint32_t addr, uint8_t val, void *priv); -extern uint8_t xga_read_test(uint32_t addr, void *priv); -extern void xga_poll(void *priv); -extern void xga_recalctimings(svga_t *svga); +extern void xga_write_test(uint32_t addr, uint8_t val, void *priv); +extern uint8_t xga_read_test(uint32_t addr, void *priv); +extern void xga_set_poll(svga_t *svga); +extern void xga_poll(void *priv); +extern void xga_recalctimings(svga_t *svga); extern uint32_t svga_decode_addr(svga_t *svga, uint32_t addr, int write); @@ -368,6 +393,7 @@ uint32_t svga_mask_addr(uint32_t addr, svga_t *svga); uint32_t svga_mask_changedaddr(uint32_t addr, svga_t *svga); void svga_doblit(int wx, int wy, svga_t *svga); +void svga_set_poll(svga_t *svga); void svga_poll(void *priv); enum { @@ -379,15 +405,15 @@ uint32_t svga_lookup_lut_ram(svga_t* svga, uint32_t val); /* 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 *priv, svga_t *svga); -extern uint8_t ati68860_ramdac_in(uint16_t addr, void *priv, svga_t *svga); +extern void ati68860_ramdac_out(uint16_t addr, uint8_t val, int is_8514, void *priv, svga_t *svga); +extern uint8_t ati68860_ramdac_in(uint16_t addr, int is_8514, 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 ati68875_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, void *priv, svga_t *svga); -extern uint8_t ati68875_ramdac_in(uint16_t addr, int rs2, int rs3, void *priv, svga_t *svga); +extern void ati68875_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, int is_8514, void *priv, svga_t *svga); +extern uint8_t ati68875_ramdac_in(uint16_t addr, int rs2, int rs3, int is_8514, void *priv, 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); diff --git a/src/include/86box/vid_svga_render.h b/src/include/86box/vid_svga_render.h index babac7592..097bb4509 100644 --- a/src/include/86box/vid_svga_render.h +++ b/src/include/86box/vid_svga_render.h @@ -23,11 +23,11 @@ extern int firstline_draw; extern int lastline_draw; extern int displine; -extern int sc; +extern int scanline; -extern uint32_t ma; -extern uint32_t ca; -extern int con; +extern uint32_t memaddr; +extern uint32_t cursoraddr; +extern int cursorvisible; extern int cursoron; extern int cgablink; diff --git a/src/include/86box/vid_svga_render_remap.h b/src/include/86box/vid_svga_render_remap.h index ff9151c3c..d6c9fa5a6 100644 --- a/src/include/86box/vid_svga_render_remap.h +++ b/src/include/86box/vid_svga_render_remap.h @@ -47,9 +47,9 @@ } \ \ if (nr & VAR_ROW0_MA13) \ - out_addr = (out_addr & ~0x8000) | ((svga->sc & 1) ? 0x8000 : 0); \ + out_addr = (out_addr & ~0x8000) | ((svga->scanline & 1) ? 0x8000 : 0); \ if (nr & VAR_ROW1_MA14) \ - out_addr = (out_addr & ~0x10000) | ((svga->sc & 2) ? 0x10000 : 0); \ + out_addr = (out_addr & ~0x10000) | ((svga->scanline & 2) ? 0x10000 : 0); \ \ return out_addr; \ } diff --git a/src/include/86box/vid_vga.h b/src/include/86box/vid_vga.h index 0ffbeb4cd..54a1d0690 100644 --- a/src/include/86box/vid_vga.h +++ b/src/include/86box/vid_vga.h @@ -25,10 +25,19 @@ typedef struct vga_t { svga_t svga; - rom_t bios_rom; + rom_t bios_rom; } vga_t; -extern void vga_out(uint16_t addr, uint8_t val, void *priv); +extern void vga_out(uint16_t addr, uint8_t val, void *priv); extern uint8_t vga_in(uint16_t addr, void *priv); +extern void vga_init(const device_t *info, vga_t *vga, int enabled); + +extern void vga_disable(void* p); +extern void vga_enable(void* p); + +extern int vga_isenabled(void* p); + +extern video_timings_t timing_vga; + #endif /*VIDEO_VGA_H*/ diff --git a/src/include/86box/vid_voodoo_banshee.h b/src/include/86box/vid_voodoo_banshee.h index 89298e94e..257a549dd 100644 --- a/src/include/86box/vid_voodoo_banshee.h +++ b/src/include/86box/vid_voodoo_banshee.h @@ -18,6 +18,7 @@ #ifndef VIDEO_VOODOO_BANSHEE_H #define VIDEO_VOODOO_BANSHEE_H +void banshee_cmd_write(void *priv, uint32_t addr, uint32_t val); void banshee_set_overlay_addr(void *priv, uint32_t addr); #endif /*VIDEO_VOODOO_BANSHEE_H*/ diff --git a/src/include/86box/vid_voodoo_common.h b/src/include/86box/vid_voodoo_common.h index 5ab63ec3a..4201562c2 100644 --- a/src/include/86box/vid_voodoo_common.h +++ b/src/include/86box/vid_voodoo_common.h @@ -420,6 +420,7 @@ typedef struct voodoo_t { int cmdfifo_rp; int cmdfifo_ret_addr; int cmdfifo_in_sub; + int cmdfifo_in_agp; atomic_int cmdfifo_depth_rd; atomic_int cmdfifo_depth_wr; atomic_int cmdfifo_enabled; @@ -433,6 +434,7 @@ typedef struct voodoo_t { int cmdfifo_rp_2; int cmdfifo_ret_addr_2; int cmdfifo_in_sub_2; + int cmdfifo_in_agp_2; atomic_int cmdfifo_depth_rd_2; atomic_int cmdfifo_depth_wr_2; atomic_int cmdfifo_enabled_2; diff --git a/src/include/86box/vid_xga.h b/src/include/86box/vid_xga.h index b90b53978..e72c7af40 100644 --- a/src/include/86box/vid_xga.h +++ b/src/include/86box/vid_xga.h @@ -127,7 +127,7 @@ typedef struct xga_t { int dispon; int h_disp_on; int vc; - int sc; + int scanline; int linepos; int oddeven; int firstline; @@ -160,12 +160,12 @@ typedef struct xga_t { uint32_t hwc_color0; uint32_t hwc_color1; uint32_t disp_start_addr; - uint32_t ma_latch; + uint32_t memaddr_latch; uint32_t vram_size; uint32_t vram_mask; uint32_t rom_addr; - uint32_t ma; - uint32_t maback; + uint32_t memaddr; + uint32_t memaddr_backup; uint32_t read_bank; uint32_t write_bank; uint32_t px_map_base; @@ -240,8 +240,6 @@ typedef struct xga_t { uint16_t px_map_height[4]; uint32_t px_map_base[4]; } accel; - - int big_endian_linear; } xga_t; #endif /*VIDEO_XGA_H*/ diff --git a/src/include/86box/video.h b/src/include/86box/video.h index 9ee710592..99f00c3cc 100644 --- a/src/include/86box/video.h +++ b/src/include/86box/video.h @@ -36,6 +36,10 @@ using atomic_int = std::atomic_int; #define getcolg(color) (((color) >> 8) & 0xFF) #define getcolb(color) ((color) & 0xFF) +#ifdef __cplusplus +extern "C" { +#endif + enum { VID_NONE = 0, VID_INTERNAL @@ -49,10 +53,6 @@ enum { FULLSCR_SCALE_INT43 }; -#ifdef __cplusplus -extern "C" { -#endif - enum { VIDEO_ISA = 0, VIDEO_MCA, @@ -69,6 +69,14 @@ enum { #define VIDEO_FLAG_TYPE_NONE 5 #define VIDEO_FLAG_TYPE_MASK 7 +#define VIDEO_FLAG_TYPE_SECONDARY VIDEO_FLAG_TYPE_SPECIAL + +#define FONT_IBM_MDA_437_PATH "roms/video/mda/mda.rom" +#define FONT_IBM_MDA_437_NORDIC_PATH "roms/video/mda/4733197.bin" +#define FONT_KAM_PATH "roms/video/mda/kam.bin" +#define FONT_KAMCL16_PATH "roms/video/mda/kamcl16.bin" +#define FONT_TULIP_DGA_PATH "roms/video/mda/tulip-dga-bios.bin" + typedef struct video_timings_t { int type; int write_b; @@ -180,6 +188,10 @@ extern bitmap_t *buffer32; #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) + +#define CGAPAL_CGA_START 16 // Where the 16-color cga text/composite starts + + extern PALETTE cgapal; extern PALETTE cgapal_mono[6]; #if 0 @@ -187,16 +199,15 @@ 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 fontdat2[2048][8]; -extern uint8_t fontdatm2[2048][16]; -extern uint8_t fontdatw[512][32]; -extern uint8_t fontdat8x12[256][16]; -extern uint8_t fontdat12x18[256][36]; -extern dbcs_font_t *fontdatksc5601; -extern dbcs_font_t *fontdatksc5601_user; +extern uint8_t fontdat[2048][8]; /* IBM CGA font */ +extern uint8_t fontdatm[2048][16]; /* IBM MDA font */ +extern uint8_t fontdat2[2048][8]; /* IBM CGA 2nd instance font */ +extern uint8_t fontdatm2[2048][16]; /* IBM MDA 2nd instance font */ +extern uint8_t fontdatw[512][32]; /* Wyse700 font */ +extern uint8_t fontdat8x12[256][16]; /* MDSI Genius font */ +extern uint8_t fontdat12x18[256][36]; /* IM1024 font */ +extern dbcs_font_t *fontdatksc5601; /* Korean KSC-5601 font */ +extern dbcs_font_t *fontdatksc5601_user; /* Korean KSC-5601 user defined font */ extern uint32_t *video_6to8; extern uint32_t *video_8togs; extern uint32_t *video_8to32; @@ -276,8 +287,8 @@ extern uint8_t video_force_resize_get_monitor(int monitor_index); extern void video_force_resize_set_monitor(uint8_t res, int monitor_index); extern void video_update_timing(void); -extern void loadfont_ex(char *s, int format, int offset); -extern void loadfont(char *s, int format); +extern void loadfont_ex(char *fn, int format, int offset); +extern void loadfont(char *fn, int format); extern int get_actual_size_x(void); extern int get_actual_size_y(void); @@ -313,6 +324,9 @@ extern const device_t mach32_mca_device; extern const device_t mach32_pci_device; extern const device_t mach32_onboard_pci_device; +/* IBM Display Adapter (PS/55) */ +extern void da2_device_add(void); + /* ATi Mach64 */ extern const device_t mach64gx_isa_device; extern const device_t mach64gx_vlb_device; @@ -347,8 +361,10 @@ extern const device_t gd5401_isa_device; extern const device_t gd5402_isa_device; extern const device_t gd5402_onboard_device; extern const device_t gd5420_isa_device; +extern const device_t gd5420_onboard_device; extern const device_t gd5422_isa_device; extern const device_t gd5424_vlb_device; +extern const device_t gd5424_onboard_device; extern const device_t gd5426_isa_device; extern const device_t gd5426_diamond_speedstar_pro_a1_isa_device; extern const device_t gd5426_vlb_device; @@ -361,6 +377,7 @@ extern const device_t gd5428_boca_isa_device; extern const device_t gd5428_mca_device; extern const device_t gd5426_mca_device; extern const device_t gd5428_onboard_device; +extern const device_t gd5428_onboard_vlb_device; extern const device_t gd5429_isa_device; extern const device_t gd5429_vlb_device; extern const device_t gd5430_diamond_speedstar_pro_se_a8_vlb_device; @@ -384,6 +401,7 @@ extern const device_t gd5480_pci_device; /* Compaq CGA */ extern const device_t compaq_cga_device; extern const device_t compaq_cga_2_device; +extern const device_t compaq_plasma_device; /* Olivetti OGC */ extern const device_t ogc_device; @@ -451,8 +469,12 @@ extern const device_t millennium_ii_device; extern const device_t productiva_g100_device; #endif /* USE_G100 */ +/* JEGA */ +extern const device_t if386jega_device; + /* Oak OTI-0x7 */ extern const device_t oti037c_device; +extern const device_t oti037_pbl300sx_device; extern const device_t oti067_device; extern const device_t oti067_acer386_device; extern const device_t oti067_ama932j_device; @@ -480,6 +502,7 @@ extern const device_t s3_metheus_86c928_isa_device; extern const device_t s3_metheus_86c928_vlb_device; extern const device_t s3_spea_mercury_lite_86c928_pci_device; extern const device_t s3_spea_mirage_86c801_isa_device; +extern const device_t s3_winner1000_805_isa_device; extern const device_t s3_86c805_onboard_vlb_device; extern const device_t s3_spea_mirage_86c805_vlb_device; extern const device_t s3_mirocrystal_8s_805_vlb_device; @@ -575,6 +598,7 @@ extern const device_t ps1vga_mca_device; extern const device_t voodoo_device; extern const device_t voodoo_banshee_device; extern const device_t creative_voodoo_banshee_device; +extern const device_t quantum3d_raven_device; extern const device_t voodoo_3_1000_device; extern const device_t voodoo_3_1000_agp_device; extern const device_t voodoo_3_2000_device; @@ -593,6 +617,11 @@ extern const device_t velocity_200_agp_device; /* Wyse 700 */ extern const device_t wy700_device; +/* Tandy */ +extern const device_t tandy_1000_video_device; +extern const device_t tandy_1000hx_video_device; +extern const device_t tandy_1000sl_video_device; + #endif #endif /*EMU_VIDEO_H*/ diff --git a/src/include/86box/zip.h b/src/include/86box/zip.h index 739ba388b..969ce27f5 100644 --- a/src/include/86box/zip.h +++ b/src/include/86box/zip.h @@ -13,7 +13,7 @@ * * Authors: Miran Grca, * - * Copyright 2018-2019 Miran Grca. + * Copyright 2018-2025 Miran Grca. */ #ifndef EMU_ZIP_H @@ -29,7 +29,7 @@ #define ZIP_250_SECTORS (489532) -#define ZIP_IMAGE_HISTORY 4 +#define ZIP_IMAGE_HISTORY 10 enum { ZIP_BUS_DISABLED = 0, @@ -39,76 +39,80 @@ enum { }; typedef struct zip_drive_t { - uint8_t id; + uint8_t id; union { - 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 res; + /* Reserved for other ID's. */ + uint8_t res0; + uint8_t res1; + uint8_t ide_channel; + uint8_t scsi_device_id; }; - 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; + 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 *fp; - void *priv; + FILE *fp; + void *priv; - char image_path[1024]; - char prev_image_path[1024]; + char image_path[1024]; + char prev_image_path[1024]; - char *image_history[ZIP_IMAGE_HISTORY]; + char *image_history[ZIP_IMAGE_HISTORY]; - uint32_t is_250; - uint32_t medium_size; - uint32_t base; + uint32_t is_250; + uint32_t medium_size; + uint32_t base; } zip_drive_t; typedef struct zip_t { mode_sense_pages_t ms_pages_saved; - zip_drive_t *drv; + zip_drive_t *drv; #ifdef EMU_IDE_H - ide_tf_t * tf; + ide_tf_t *tf; #else - void * tf; + void *tf; #endif - uint8_t *buffer; - uint8_t atapi_cdb[16]; - uint8_t current_cdb[16]; - uint8_t sense[256]; + void *log; - uint8_t id; - uint8_t cur_lun; - uint8_t pad0; - uint8_t pad1; + uint8_t *buffer; + uint8_t atapi_cdb[16]; + uint8_t current_cdb[16]; + uint8_t sense[256]; - uint16_t max_transfer_len; - uint16_t pad2; + uint8_t id; + uint8_t cur_lun; + uint8_t pad0; + uint8_t pad1; - int requested_blocks; - int packet_status; - int total_length; - int do_page_save; - int unit_attention; - int request_pos; - int old_len; - int pad3; + uint16_t max_transfer_len; + uint16_t pad2; - uint32_t sector_pos; - uint32_t sector_len; - uint32_t packet_len; + int requested_blocks; + int packet_status; + int total_length; + int do_page_save; + int unit_attention; + int request_pos; + int old_len; + int transition; - double callback; + uint32_t sector_pos; + uint32_t sector_len; + uint32_t packet_len; + uint32_t block_len; - uint8_t (*ven_cmd)(void *sc, uint8_t *cdb, int32_t *BufLen); + double callback; + + uint8_t (*ven_cmd)(void *sc, uint8_t *cdb, int32_t *BufLen); } zip_t; extern zip_t *zip[ZIP_NUM]; @@ -118,6 +122,7 @@ extern uint8_t scsi_zip_drives[16]; #define zip_sense_error dev->sense[0] #define zip_sense_key dev->sense[2] +#define zip_info *(uint32_t *) &(dev->sense[3]) #define zip_asc dev->sense[12] #define zip_ascq dev->sense[13] @@ -125,15 +130,16 @@ extern uint8_t scsi_zip_drives[16]; extern "C" { #endif -extern void zip_disk_close(zip_t *dev); -extern void zip_disk_reload(zip_t *dev); +extern void zip_disk_close(const zip_t *dev); +extern void zip_disk_reload(const zip_t *dev); extern void zip_insert(zip_t *dev); extern void zip_global_init(void); extern void zip_hard_reset(void); extern void zip_reset(scsi_common_t *sc); -extern int zip_load(zip_t *dev, char *fn); +extern int zip_is_empty(const uint8_t id); +extern void zip_load(const zip_t *dev, const char *fn, const int skip_insert); extern void zip_close(void); #ifdef __cplusplus diff --git a/src/io.c b/src/io.c index fd87089d0..45dd4cb3d 100644 --- a/src/io.c +++ b/src/io.c @@ -15,7 +15,7 @@ * Fred N. van Kempen, * * Copyright 2008-2019 Sarah Walker. - * Copyright 2016-2019 Miran Grca. + * Copyright 2016-2025 Miran Grca. */ #include #include @@ -28,6 +28,7 @@ #include <86box/io.h> #include <86box/timer.h> #include "cpu.h" +#include "x86.h" #include <86box/m_amstrad.h> #include <86box/pci.h> @@ -145,6 +146,8 @@ io_sethandler_common(uint16_t base, int size, q->next = NULL; io_last[base + c] = q; + + q = NULL; } } @@ -342,6 +345,8 @@ inb(uint16_t port) int qfound = 0; #endif + io_port = port; + #ifdef USE_DEBUG_REGS_486 io_debug_check_addr(port); #endif @@ -406,6 +411,9 @@ outb(uint16_t port, uint8_t val) int qfound = 0; #endif + io_port = port; + io_val = val; + #ifdef USE_DEBUG_REGS_486 io_debug_check_addr(port); #endif @@ -437,10 +445,10 @@ outb(uint16_t port, uint8_t val) } } - if (!found) { + if (!found || (port == 0x84)) { cycles -= io_delay; #ifdef USE_DYNAREC - if (cpu_use_dynarec && ((port == 0xeb) || (port == 0xed))) + if (cpu_use_dynarec && ((port == 0x84) || (port == 0xeb) || (port == 0xed))) update_tsc(); #endif } @@ -462,6 +470,8 @@ inw(uint16_t port) #endif uint8_t ret8[2]; + io_port = port; + #ifdef USE_DEBUG_REGS_486 io_debug_check_addr(port); #endif @@ -538,6 +548,9 @@ outw(uint16_t port, uint16_t val) int qfound = 0; #endif + io_port = port; + io_val = val; + #ifdef USE_DEBUG_REGS_486 io_debug_check_addr(port); #endif @@ -610,6 +623,8 @@ inl(uint16_t port) int qfound = 0; #endif + io_port = port; + #ifdef USE_DEBUG_REGS_486 io_debug_check_addr(port); #endif @@ -718,6 +733,9 @@ outl(uint16_t port, uint32_t val) #endif int i = 0; + io_port = port; + io_val = val; + #ifdef USE_DEBUG_REGS_486 io_debug_check_addr(port); #endif diff --git a/src/ioapic.c b/src/ioapic.c index c3939f249..ea0811f91 100644 --- a/src/ioapic.c +++ b/src/ioapic.c @@ -117,12 +117,12 @@ ioapic_init(UNUSED(const device_t *info)) const device_t ioapic_device = { .name = "I/O Advanced Programmable Interrupt Controller", .internal_name = "ioapic", - .flags = DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0, .init = ioapic_init, .close = ioapic_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/log.c b/src/log.c deleted file mode 100644 index b5267d70b..000000000 --- a/src/log.c +++ /dev/null @@ -1,159 +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. - * - * The handler of the new logging system. - * - * - * - * Authors: Miran Grca, - * Fred N. van Kempen, - * - * Copyright 2021 Miran Grca. - * Copyright 2021 Fred N. van Kempen. - */ -#include -#include -#include -#include -#include -#include -#include -#include - -#define HAVE_STDARG_H -#include <86box/86box.h> -#include <86box/config.h> -#include <86box/mem.h> -#include "cpu.h" -#include <86box/plat.h> -#include <86box/version.h> -#include <86box/log.h> - -#ifndef RELEASE_BUILD -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 */ - -void -log_set_suppr_seen(void *priv, int suppr_seen) -{ - log_t *log = (log_t *) priv; - - log->suppr_seen = suppr_seen; -} - -void -log_set_dev_name(void *priv, char *dev_name) -{ - log_t *log = (log_t *) priv; - - log->dev_name = dev_name; -} - -static void -log_copy(log_t *log, char *dest, const char *src, size_t dest_size) -{ - memset(dest, 0x00, dest_size * sizeof(char)); - if (log && log->dev_name && strcmp(log->dev_name, "")) { - strcat(dest, log->dev_name); - strcat(dest, ": "); - } - strcat(dest, src); -} - -/* - * Log something to the logfile or stdout. - * - * To avoid excessively-large logfiles because some - * module repeatedly logs, we keep track of what is - * being logged, and catch repeating entries. - */ -void -log_out(void *priv, const char *fmt, va_list ap) -{ - log_t *log = (log_t *) priv; - char temp[1024]; - char fmt2[1024]; - - if (log == NULL) - return; - - if (strcmp(fmt, "") == 0) - return; - - if (stdlog == NULL) { - if (log_path[0] != '\0') { - stdlog = plat_fopen(log_path, "w"); - if (stdlog == NULL) - stdlog = stdout; - } else - stdlog = stdout; - } - - vsprintf(temp, fmt, ap); - if (log->suppr_seen && !strcmp(log->buff, temp)) - log->seen++; - else { - if (log->suppr_seen && log->seen) { - log_copy(log, fmt2, "*** %d repeats ***\n", 1024); - fprintf(stdlog, fmt2, log->seen); - } - log->seen = 0; - strcpy(log->buff, temp); - log_copy(log, fmt2, temp, 1024); - fprintf(stdlog, fmt2, ap); - } - - fflush(stdlog); -} - -void -log_fatal(void *priv, const char *fmt, ...) -{ - log_t *log = (log_t *) priv; - char temp[1024]; - char fmt2[1024]; - va_list ap; - - if (log == NULL) - return; - - va_start(ap, fmt); - log_copy(log, fmt2, fmt, 1024); - vsprintf(temp, fmt2, ap); - fatal_ex(fmt2, ap); - va_end(ap); - exit(-1); -} - -void * -log_open(char *dev_name) -{ - log_t *log = malloc(sizeof(log_t)); - - memset(log, 0, sizeof(log_t)); - - log->dev_name = dev_name; - log->suppr_seen = 1; - - return (void *) log; -} - -void -log_close(void *priv) -{ - log_t *log = (log_t *) priv; - - free(log); -} -#endif diff --git a/src/lpt.c b/src/lpt.c deleted file mode 100644 index 3f1c5eb7b..000000000 --- a/src/lpt.c +++ /dev/null @@ -1,264 +0,0 @@ -/* Copyright holders: Sarah Walker - see COPYING for more details -*/ -#include -#include -#include -#include -#include <86box/86box.h> -#include <86box/io.h> -#include <86box/lpt.h> -#include <86box/pic.h> -#include <86box/sound.h> -#include <86box/prt_devs.h> -#include <86box/thread.h> -#include <86box/timer.h> -#include <86box/device.h> -#include <86box/network.h> - -lpt_port_t lpt_ports[PARALLEL_MAX]; - -const lpt_device_t lpt_none_device = { - .name = "None", - .internal_name = "none", - .init = NULL, - .close = NULL, - .write_data = NULL, - .write_ctrl = NULL, - .read_data = NULL, - .read_status = NULL, - .read_ctrl = NULL -}; - -static const struct { - const char *internal_name; - const lpt_device_t *device; -} lpt_devices[] = { - // clang-format off - {"none", &lpt_none_device }, - {"dss", &dss_device }, - {"lpt_dac", &lpt_dac_device }, - {"lpt_dac_stereo", &lpt_dac_stereo_device }, - {"text_prt", &lpt_prt_text_device }, - {"dot_matrix", &lpt_prt_escp_device }, - {"postscript", &lpt_prt_ps_device }, -#ifdef USE_PCL - {"pcl", &lpt_prt_pcl_device }, -#endif - {"plip", &lpt_plip_device }, - {"dongle_savquest", &lpt_hasp_savquest_device }, - {"", NULL } - // clang-format on -}; - -const char * -lpt_device_get_name(int id) -{ - if (strlen(lpt_devices[id].internal_name) == 0) - return NULL; - if (!lpt_devices[id].device) - return "None"; - return lpt_devices[id].device->name; -} - -const char * -lpt_device_get_internal_name(int id) -{ - if (strlen(lpt_devices[id].internal_name) == 0) - return NULL; - return lpt_devices[id].internal_name; -} - -int -lpt_device_get_from_internal_name(char *s) -{ - int c = 0; - - while (strlen(lpt_devices[c].internal_name) != 0) { - if (strcmp(lpt_devices[c].internal_name, s) == 0) - return c; - c++; - } - - return 0; -} - -void -lpt_devices_init(void) -{ - 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) - lpt_ports[i].priv = lpt_ports[i].dt->init(&lpt_ports[i]); - } -} - -void -lpt_devices_close(void) -{ - lpt_port_t *dev; - - for (uint8_t i = 0; i < PARALLEL_MAX; i++) { - dev = &lpt_ports[i]; - - if (lpt_ports[i].dt && lpt_ports[i].dt->close) - dev->dt->close(dev->priv); - - dev->dt = NULL; - } -} - -void -lpt_write(uint16_t port, uint8_t val, void *priv) -{ - lpt_port_t *dev = (lpt_port_t *) priv; - - switch (port & 3) { - case 0: - if (dev->dt && dev->dt->write_data && dev->priv) - dev->dt->write_data(val, dev->priv); - dev->dat = val; - break; - - case 1: - break; - - case 2: - if (dev->dt && dev->dt->write_ctrl && dev->priv) - dev->dt->write_ctrl(val, dev->priv); - dev->ctrl = val; - dev->enable_irq = val & 0x10; - break; - - default: - break; - } -} - -uint8_t -lpt_read(uint16_t port, void *priv) -{ - uint8_t ret = 0xff; - lpt_port_t *dev = (lpt_port_t *) priv; - - switch (port & 3) { - case 0: - if (dev->dt && dev->dt->read_data && dev->priv) - ret = dev->dt->read_data(dev->priv); - else - ret = dev->dat; - break; - - case 1: - if (dev->dt && dev->dt->read_status && dev->priv) - ret = dev->dt->read_status(dev->priv) | 0x07; - else - ret = 0xdf; - break; - - case 2: - if (dev->dt && dev->dt->read_ctrl && dev->priv) - ret = (dev->dt->read_ctrl(dev->priv) & 0xef) | dev->enable_irq; - else - ret = 0xe0 | dev->ctrl | dev->enable_irq; - break; - - default: - break; - } - - return ret; -} - -uint8_t -lpt_read_port(int port, uint16_t reg) -{ - lpt_port_t *dev = &(lpt_ports[port]); - uint8_t ret = lpt_read(reg, dev); - - return ret; -} - -uint8_t -lpt_read_status(int port) -{ - lpt_port_t *dev = &(lpt_ports[port]); - uint8_t ret = 0xff; - - if (dev->dt && dev->dt->read_status && dev->priv) - ret = dev->dt->read_status(dev->priv) | 0x07; - else - ret = 0xdf; - - return ret; -} - -void -lpt_irq(void *priv, int raise) -{ - const lpt_port_t *dev = (lpt_port_t *) priv; - - if (dev->enable_irq && (dev->irq != 0xff)) { - if (raise) - picint(1 << dev->irq); - else - picintc(1 << dev->irq); - } -} - -void -lpt_init(void) -{ - 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 (uint8_t i = 0; i < PARALLEL_MAX; i++) { - lpt_ports[i].addr = 0xffff; - lpt_ports[i].irq = 0xff; - lpt_ports[i].enable_irq = 0x10; - - if (lpt_ports[i].enabled) { - lpt_port_init(i, default_ports[i]); - lpt_port_irq(i, default_irqs[i]); - } - } -} - -void -lpt_port_init(int i, uint16_t port) -{ - if (lpt_ports[i].enabled) { - if (lpt_ports[i].addr != 0xffff) - io_removehandler(lpt_ports[i].addr, 0x0003, lpt_read, NULL, NULL, lpt_write, NULL, NULL, &lpt_ports[i]); - if (port != 0xffff) - io_sethandler(port, 0x0003, lpt_read, NULL, NULL, lpt_write, NULL, NULL, &lpt_ports[i]); - lpt_ports[i].addr = port; - } else - lpt_ports[i].addr = 0xffff; -} - -void -lpt_port_irq(int i, uint8_t irq) -{ - if (lpt_ports[i].enabled) - lpt_ports[i].irq = irq; - else - lpt_ports[i].irq = 0xff; -} - -void -lpt_port_remove(int i) -{ - if (lpt_ports[i].enabled && (lpt_ports[i].addr != 0xffff)) { - io_removehandler(lpt_ports[i].addr, 0x0003, lpt_read, NULL, NULL, lpt_write, NULL, NULL, &lpt_ports[i]); - lpt_ports[i].addr = 0xffff; - } -} - -void -lpt1_remove_ams(void) -{ - if (lpt_ports[0].enabled) - io_removehandler(lpt_ports[0].addr + 1, 0x0002, lpt_read, NULL, NULL, lpt_write, NULL, NULL, &lpt_ports[0]); -} diff --git a/src/machine/CMakeLists.txt b/src/machine/CMakeLists.txt index ff6a66801..f91eeb17d 100644 --- a/src/machine/CMakeLists.txt +++ b/src/machine/CMakeLists.txt @@ -20,9 +20,9 @@ add_library(mch OBJECT machine_table.c m_xt.c m_xt_compaq.c + m_xt_laserxt.c m_xt_philips.c m_xt_t1000.c - m_xt_t1000_vid.c m_xt_xi8088.c m_xt_zenith.c m_pcjr.c @@ -36,7 +36,6 @@ add_library(mch OBJECT m_at_commodore.c m_at_grid.c m_at_t3100e.c - m_at_t3100e_vid.c m_ps1.c m_ps1_hdc.c m_ps2_isa.c @@ -55,24 +54,3 @@ add_library(mch OBJECT m_at_socket370.c m_at_misc.c ) - -if(AN430TX) - target_compile_definitions(mch PRIVATE USE_AN430TX) -endif() - -if(DESKPRO386) - target_compile_definitions(mch PRIVATE USE_DESKPRO386) -endif() - -if(LASERXT) - target_sources(mch PRIVATE m_xt_laserxt.c) - target_compile_definitions(mch PRIVATE USE_LASERXT) -endif() - -if(OLIVETTI) - target_compile_definitions(mch PRIVATE USE_OLIVETTI) -endif() - -if(OPEN_AT) - target_compile_definitions(mch PRIVATE USE_OPEN_AT) -endif() diff --git a/src/machine/m_amstrad.c b/src/machine/m_amstrad.c index 530362b89..d42807b4d 100644 --- a/src/machine/m_amstrad.c +++ b/src/machine/m_amstrad.c @@ -105,7 +105,7 @@ typedef struct amsvid_t { int cga_enabled; /* 1640 */ uint8_t cgacol; uint8_t cgamode; - uint8_t stat; + uint8_t status; uint8_t plane_write; /* 1512/200 */ uint8_t plane_read; /* 1512/200 */ uint8_t border; /* 1512/200 */ @@ -113,18 +113,17 @@ typedef struct amsvid_t { int fontbase; /* 1512/200 */ int linepos; int displine; - int sc; + int scanline; int vc; int cgadispon; - int con; - int coff; + int cursorvisible; int cursoron; int cgablink; int vsynctime; int fullchange; int vadj; - uint16_t ma; - uint16_t maback; + uint16_t memaddr; + uint16_t memaddr_backup; int dispon; int blink; uint64_t dispontime; /* 1512/1640 */ @@ -291,7 +290,7 @@ vid_in_1512(uint16_t addr, void *priv) break; case 0x03da: - ret = vid->stat; + ret = vid->status; break; default: @@ -340,7 +339,7 @@ static void vid_poll_1512(void *priv) { amsvid_t *vid = (amsvid_t *) priv; - uint16_t ca = (vid->crtc[15] | (vid->crtc[14] << 8)) & 0x3fff; + uint16_t cursoraddr = (vid->crtc[15] | (vid->crtc[14] << 8)) & 0x3fff; int drawcursor; int x; int c; @@ -354,13 +353,13 @@ vid_poll_1512(void *priv) uint16_t dat4; int cols[4]; int col; - int oldsc; + int scanline_old; if (!vid->linepos) { timer_advance_u64(&vid->timer, vid->dispofftime); - vid->stat |= 1; + vid->status |= 1; vid->linepos = 1; - oldsc = vid->sc; + scanline_old = vid->scanline; if (vid->dispon) { if (vid->displine < vid->firstline) { vid->firstline = vid->displine; @@ -370,26 +369,26 @@ vid_poll_1512(void *priv) 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; - if (vid->cgamode & 1) { + if (vid->cgamode & CGA_MODE_FLAG_HIGHRES) { 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; } } else { buffer32->line[vid->displine << 1][c] = buffer32->line[(vid->displine << 1) + 1][c] = (vid->cgacol & 15) + 16; - if (vid->cgamode & 1) { + if (vid->cgamode & CGA_MODE_FLAG_HIGHRES) { 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; } } } - if (vid->cgamode & 1) { + if (vid->cgamode & CGA_MODE_FLAG_HIGHRES) { for (x = 0; x < 80; x++) { - 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) { + chr = vid->vram[(vid->memaddr<< 1) & 0x3fff]; + attr = vid->vram[((vid->memaddr<< 1) + 1) & 0x3fff]; + drawcursor = ((vid->memaddr== cursoraddr) && vid->cursorvisible && vid->cursoron); + if (vid->cgamode & CGA_MODE_FLAG_BLINK) { cols[1] = (attr & 15) + 16; cols[0] = ((attr >> 4) & 7) + 16; if ((vid->blink & 16) && (attr & 0x80) && !drawcursor) @@ -400,21 +399,23 @@ 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->scanline & 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->scanline & 7] & (1 << (c ^ 7))) ? 1 : 0]; } } - vid->ma++; + vid->memaddr++; } - } else if (!(vid->cgamode & 2)) { + } else if (!(vid->cgamode & CGA_MODE_FLAG_GRAPHICS)) { for (x = 0; x < 40; x++) { - 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) { + chr = vid->vram[(vid->memaddr<< 1) & 0x3fff]; + attr = vid->vram[((vid->memaddr<< 1) + 1) & 0x3fff]; + drawcursor = ((vid->memaddr == cursoraddr) + && vid->cursorvisible && vid->cursoron); + + if (vid->cgamode & CGA_MODE_FLAG_BLINK) { cols[1] = (attr & 15) + 16; cols[0] = ((attr >> 4) & 7) + 16; if ((vid->blink & 16) && (attr & 0x80)) @@ -423,21 +424,21 @@ vid_poll_1512(void *priv) cols[1] = (attr & 15) + 16; cols[0] = (attr >> 4) + 16; } - vid->ma++; + vid->memaddr++; 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->scanline & 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->scanline & 7] & (1 << (c ^ 7))) ? 1 : 0]; } } } - } else if (!(vid->cgamode & 16)) { + } else if (!(vid->cgamode & CGA_MODE_FLAG_HIGHRES_GRAPHICS)) { cols[0] = (vid->cgacol & 15) | 16; col = (vid->cgacol & 16) ? 24 : 16; - if (vid->cgamode & 4) { + if (vid->cgamode & CGA_MODE_FLAG_BW) { cols[1] = col | 3; cols[2] = col | 4; cols[3] = col | 7; @@ -451,8 +452,8 @@ vid_poll_1512(void *priv) cols[3] = col | 6; } for (x = 0; x < 40; x++) { - 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++; + dat = (vid->vram[((vid->memaddr<< 1) & 0x1fff) + ((vid->scanline & 1) * 0x2000)] << 8) | vid->vram[((vid->memaddr<< 1) & 0x1fff) + ((vid->scanline & 1) * 0x2000) + 1]; + vid->memaddr++; 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]; dat <<= 2; @@ -460,13 +461,13 @@ vid_poll_1512(void *priv) } } else { for (x = 0; x < 40; x++) { - ca = ((vid->ma << 1) & 0x1fff) + ((vid->sc & 1) * 0x2000); - dat = (vid->vram[ca] << 8) | vid->vram[ca + 1]; - dat2 = (vid->vram[ca + 0x4000] << 8) | vid->vram[ca + 0x4001]; - dat3 = (vid->vram[ca + 0x8000] << 8) | vid->vram[ca + 0x8001]; - dat4 = (vid->vram[ca + 0xc000] << 8) | vid->vram[ca + 0xc001]; + cursoraddr = ((vid->memaddr<< 1) & 0x1fff) + ((vid->scanline & 1) * 0x2000); + dat = (vid->vram[cursoraddr] << 8) | vid->vram[cursoraddr + 1]; + dat2 = (vid->vram[cursoraddr + 0x4000] << 8) | vid->vram[cursoraddr + 0x4001]; + dat3 = (vid->vram[cursoraddr + 0x8000] << 8) | vid->vram[cursoraddr + 0x8001]; + dat4 = (vid->vram[cursoraddr + 0xc000] << 8) | vid->vram[cursoraddr + 0xc001]; - vid->ma++; + vid->memaddr++; 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; dat <<= 1; @@ -478,7 +479,7 @@ vid_poll_1512(void *priv) } } else { cols[0] = ((vid->cgamode & 0x12) == 0x12) ? 0 : (vid->cgacol & 15) + 16; - if (vid->cgamode & 1) { + if (vid->cgamode & CGA_MODE_FLAG_HIGHRES) { hline(buffer32, 0, (vid->displine << 1), (vid->crtc[1] << 3) + 16, cols[0]); hline(buffer32, 0, (vid->displine << 1) + 1, (vid->crtc[1] << 3) + 16, cols[0]); } else { @@ -487,7 +488,7 @@ vid_poll_1512(void *priv) } } - if (vid->cgamode & 1) + if (vid->cgamode & CGA_MODE_FLAG_HIGHRES) x = (vid->crtc[1] << 3) + 16; else x = (vid->crtc[1] << 4) + 16; @@ -495,9 +496,9 @@ vid_poll_1512(void *priv) video_process_8(x, vid->displine << 1); video_process_8(x, (vid->displine << 1) + 1); - vid->sc = oldsc; + vid->scanline = scanline_old; if (vid->vsynctime) - vid->stat |= 8; + vid->status |= 8; vid->displine++; if (vid->displine >= 360) vid->displine = 0; @@ -506,30 +507,29 @@ vid_poll_1512(void *priv) if ((vid->lastline - vid->firstline) == 199) vid->dispon = 0; /*Amstrad PC1512 always displays 200 lines, regardless of CRTC settings*/ if (vid->dispon) - vid->stat &= ~1; + vid->status &= ~1; vid->linepos = 0; if (vid->vsynctime) { vid->vsynctime--; if (!vid->vsynctime) - vid->stat &= ~8; + vid->status &= ~8; } - if (vid->sc == (vid->crtc[11] & 31)) { - vid->con = 0; - vid->coff = 1; + if (vid->scanline == (vid->crtc[11] & 31)) { + vid->cursorvisible = 0; } if (vid->vadj) { - vid->sc++; - vid->sc &= 31; - vid->ma = vid->maback; + vid->scanline++; + vid->scanline &= 31; + vid->memaddr= vid->memaddr_backup; vid->vadj--; if (!vid->vadj) { vid->dispon = 1; - vid->ma = vid->maback = (vid->crtc[13] | (vid->crtc[12] << 8)) & 0x3fff; - vid->sc = 0; + vid->memaddr= vid->memaddr_backup = (vid->crtc[13] | (vid->crtc[12] << 8)) & 0x3fff; + vid->scanline = 0; } - } else if (vid->sc == vid->crtc[9]) { - vid->maback = vid->ma; - vid->sc = 0; + } else if (vid->scanline == vid->crtc[9]) { + vid->memaddr_backup = vid->memaddr; + vid->scanline = 0; vid->vc++; vid->vc &= 127; @@ -547,7 +547,7 @@ vid_poll_1512(void *priv) vid->displine = 0; vid->vsynctime = 46; - if (vid->cgamode & 1) + if (vid->cgamode & CGA_MODE_FLAG_HIGHRES) x = (vid->crtc[1] << 3) + 16; else x = (vid->crtc[1] << 4) + 16; @@ -584,15 +584,15 @@ vid_poll_1512(void *priv) video_res_x = xsize; video_res_y = ysize; - if (vid->cgamode & 1) { + if (vid->cgamode & CGA_MODE_FLAG_HIGHRES) { video_res_x /= 8; video_res_y /= vid->crtc[9] + 1; video_bpp = 0; - } else if (!(vid->cgamode & 2)) { + } else if (!(vid->cgamode & CGA_MODE_FLAG_GRAPHICS)) { video_res_x /= 16; video_res_y /= vid->crtc[9] + 1; video_bpp = 0; - } else if (!(vid->cgamode & 16)) { + } else if (!(vid->cgamode & CGA_MODE_FLAG_HIGHRES_GRAPHICS)) { video_res_x /= 2; video_bpp = 2; } else { @@ -604,12 +604,12 @@ vid_poll_1512(void *priv) vid->blink++; } } else { - vid->sc++; - vid->sc &= 31; - vid->ma = vid->maback; + vid->scanline++; + vid->scanline &= 31; + vid->memaddr= vid->memaddr_backup; } - if (vid->sc == (vid->crtc[10] & 31)) - vid->con = 1; + if (vid->scanline == (vid->crtc[10] & 31)) + vid->cursorvisible = 1; } } @@ -619,8 +619,7 @@ vid_init_1512(amstrad_t *ams) amsvid_t *vid; /* Allocate a video controller block. */ - vid = (amsvid_t *) malloc(sizeof(amsvid_t)); - memset(vid, 0x00, sizeof(amsvid_t)); + vid = (amsvid_t *) calloc(1, sizeof(amsvid_t)); video_inform(VIDEO_FLAG_TYPE_CGA, &timing_pc1512); @@ -726,7 +725,7 @@ const device_t vid_1512_device = { .init = NULL, .close = vid_close_1512, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = vid_speed_change_1512, .force_redraw = NULL, .config = vid_1512_config @@ -823,8 +822,7 @@ vid_init_1640(amstrad_t *ams) amsvid_t *vid; /* Allocate a video controller block. */ - vid = (amsvid_t *) malloc(sizeof(amsvid_t)); - memset(vid, 0x00, sizeof(amsvid_t)); + vid = (amsvid_t *) calloc(1, sizeof(amsvid_t)); rom_init(&vid->bios_rom, "roms/machines/pc1640/40100", 0xc0000, 0x8000, 0x7fff, 0, 0); @@ -906,7 +904,7 @@ const device_t vid_1640_device = { .init = NULL, .close = vid_close_1640, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = vid_speed_changed_1640, .force_redraw = NULL, .config = vid_1640_config @@ -1048,7 +1046,7 @@ vid_in_200(uint16_t addr, void *priv) switch (addr) { case 0x03b8: - return (mda->ctrl); + return (mda->mode); case 0x03d8: return (cga->cgamode); @@ -1110,9 +1108,9 @@ vid_out_200(uint16_t addr, uint8_t val, void *priv) } return; case 0x3b8: - old = mda->ctrl; - mda->ctrl = val; - if ((mda->ctrl ^ old) & 3) + old = mda->mode; + mda->mode = val; + if ((mda->mode ^ old) & 3) mda_recalctimings(mda); vid->crtc_index &= 0x1F; vid->crtc_index |= 0x80; @@ -1214,11 +1212,11 @@ vid_out_200(uint16_t addr, uint8_t val, void *priv) static void lcd_draw_char_80(amsvid_t *vid, uint32_t *buffer, uint8_t chr, - uint8_t attr, int drawcursor, int blink, int sc, + uint8_t attr, int drawcursor, int blink, int scanline, int mode160, uint8_t control) { int c; - uint8_t bits = fontdat[chr + vid->cga.fontbase][sc]; + uint8_t bits = fontdat[chr + vid->cga.fontbase][scanline]; uint8_t bright = 0; uint16_t mask; @@ -1249,10 +1247,10 @@ lcd_draw_char_80(amsvid_t *vid, uint32_t *buffer, uint8_t chr, static void lcd_draw_char_40(amsvid_t *vid, uint32_t *buffer, uint8_t chr, - uint8_t attr, int drawcursor, int blink, int sc, + uint8_t attr, int drawcursor, int blink, int scanline, uint8_t control) { - uint8_t bits = fontdat[chr + vid->cga.fontbase][sc]; + uint8_t bits = fontdat[chr + vid->cga.fontbase][scanline]; uint8_t mask = 0x80; if (attr & 8) /* bright */ @@ -1273,92 +1271,91 @@ static void lcdm_poll(amsvid_t *vid) { mda_t *mda = &vid->mda; - uint16_t ca = (mda->crtc[15] | (mda->crtc[14] << 8)) & 0x3fff; + uint16_t cursoraddr = (mda->crtc[MDA_CRTC_CURSOR_ADDR_LOW] | (mda->crtc[MDA_CRTC_CURSOR_ADDR_HIGH] << 8)) & 0x3fff; int drawcursor; int x; int oldvc; uint8_t chr; uint8_t attr; - int oldsc; + int scanline_old; int blink; if (!mda->linepos) { timer_advance_u64(&vid->timer, mda->dispofftime); - mda->stat |= 1; + mda->status |= 1; mda->linepos = 1; - oldsc = mda->sc; - if ((mda->crtc[8] & 3) == 3) - mda->sc = (mda->sc << 1) & 7; + scanline_old = mda->scanline; + if ((mda->crtc[MDA_CRTC_INTERLACE] & 3) == 3) + mda->scanline = (mda->scanline << 1) & 7; if (mda->dispon) { if (mda->displine < mda->firstline) mda->firstline = mda->displine; mda->lastline = mda->displine; - for (x = 0; x < mda->crtc[1]; x++) { - chr = mda->vram[(mda->ma << 1) & 0xfff]; - attr = mda->vram[((mda->ma << 1) + 1) & 0xfff]; - drawcursor = ((mda->ma == ca) && mda->con && mda->cursoron); - blink = ((mda->blink & 16) && (mda->ctrl & 0x20) && (attr & 0x80) && !drawcursor); + for (x = 0; x < mda->crtc[MDA_CRTC_HDISP]; x++) { + chr = mda->vram[(mda->memaddr<< 1) & 0xfff]; + attr = mda->vram[((mda->memaddr<< 1) + 1) & 0xfff]; + drawcursor = ((mda->memaddr== cursoraddr) && mda->cursorvisible && mda->cursoron); + blink = ((mda->blink & 16) && (mda->mode & MDA_MODE_BLINK) && (attr & 0x80) && !drawcursor); - lcd_draw_char_80(vid, &(buffer32->line[mda->displine])[x * 8], chr, attr, drawcursor, blink, mda->sc, 0, mda->ctrl); - mda->ma++; + lcd_draw_char_80(vid, &(buffer32->line[mda->displine])[x * 8], chr, attr, drawcursor, blink, mda->scanline, 0, mda->mode); + mda->memaddr++; } } - mda->sc = oldsc; - if (mda->vc == mda->crtc[7] && !mda->sc) - mda->stat |= 8; + mda->scanline = scanline_old; + if (mda->vc == mda->crtc[MDA_CRTC_VSYNC] && !mda->scanline) + mda->status |= 8; mda->displine++; if (mda->displine >= 500) mda->displine = 0; } else { timer_advance_u64(&vid->timer, mda->dispontime); if (mda->dispon) - mda->stat &= ~1; + mda->status &= ~1; mda->linepos = 0; if (mda->vsynctime) { mda->vsynctime--; if (!mda->vsynctime) - mda->stat &= ~8; + mda->status &= ~8; } - if (mda->sc == (mda->crtc[11] & 31) || ((mda->crtc[8] & 3) == 3 && mda->sc == ((mda->crtc[11] & 31) >> 1))) { - mda->con = 0; - mda->coff = 1; + if (mda->scanline == (mda->crtc[MDA_CRTC_CURSOR_END] & 31) || ((mda->crtc[MDA_CRTC_INTERLACE] & 3) == 3 && mda->scanline == ((mda->crtc[MDA_CRTC_CURSOR_END] & 31) >> 1))) { + mda->cursorvisible = 0; } if (mda->vadj) { - mda->sc++; - mda->sc &= 31; - mda->ma = mda->maback; + mda->scanline++; + mda->scanline &= 31; + mda->memaddr= mda->memaddr_backup; mda->vadj--; if (!mda->vadj) { mda->dispon = 1; - mda->ma = mda->maback = (mda->crtc[13] | (mda->crtc[12] << 8)) & 0x3fff; - mda->sc = 0; + mda->memaddr= mda->memaddr_backup = (mda->crtc[MDA_CRTC_START_ADDR_LOW] | (mda->crtc[MDA_CRTC_START_ADDR_HIGH] << 8)) & 0x3fff; + mda->scanline = 0; } - } else if (mda->sc == mda->crtc[9] || ((mda->crtc[8] & 3) == 3 && mda->sc == (mda->crtc[9] >> 1))) { - mda->maback = mda->ma; - mda->sc = 0; + } else if (mda->scanline == mda->crtc[MDA_CRTC_MAX_SCANLINE_ADDR] || ((mda->crtc[MDA_CRTC_INTERLACE] & 3) == 3 && mda->scanline == (mda->crtc[MDA_CRTC_MAX_SCANLINE_ADDR] >> 1))) { + mda->memaddr_backup = mda->memaddr; + mda->scanline = 0; oldvc = mda->vc; mda->vc++; mda->vc &= 127; - if (mda->vc == mda->crtc[6]) + if (mda->vc == mda->crtc[MDA_CRTC_VDISP]) mda->dispon = 0; - if (oldvc == mda->crtc[4]) { + if (oldvc == mda->crtc[MDA_CRTC_VTOTAL]) { mda->vc = 0; - mda->vadj = mda->crtc[5]; + mda->vadj = mda->crtc[MDA_CRTC_VTOTAL_ADJUST]; if (!mda->vadj) mda->dispon = 1; if (!mda->vadj) - mda->ma = mda->maback = (mda->crtc[13] | (mda->crtc[12] << 8)) & 0x3fff; - if ((mda->crtc[10] & 0x60) == 0x20) + mda->memaddr= mda->memaddr_backup = (mda->crtc[MDA_CRTC_START_ADDR_LOW] | (mda->crtc[MDA_CRTC_START_ADDR_HIGH] << 8)) & 0x3fff; + if ((mda->crtc[MDA_CRTC_CURSOR_START] & 0x60) == 0x20) mda->cursoron = 0; else mda->cursoron = mda->blink & 16; } - if (mda->vc == mda->crtc[7]) { + if (mda->vc == mda->crtc[MDA_CRTC_VSYNC]) { mda->dispon = 0; mda->displine = 0; mda->vsynctime = 16; - if (mda->crtc[7]) { - x = mda->crtc[1] * 8; + if (mda->crtc[MDA_CRTC_VSYNC]) { + x = mda->crtc[MDA_CRTC_HDISP] * 8; mda->lastline++; if ((x != xsize) || ((mda->lastline - mda->firstline) != ysize) || video_force_resize_get()) { xsize = x; @@ -1374,8 +1371,8 @@ lcdm_poll(amsvid_t *vid) } video_blit_memtoscreen(0, mda->firstline, xsize, ysize); frames++; - video_res_x = mda->crtc[1]; - video_res_y = mda->crtc[6]; + video_res_x = mda->crtc[MDA_CRTC_HDISP]; + video_res_y = mda->crtc[MDA_CRTC_VDISP]; video_bpp = 0; } mda->firstline = 1000; @@ -1383,12 +1380,12 @@ lcdm_poll(amsvid_t *vid) mda->blink++; } } else { - mda->sc++; - mda->sc &= 31; - mda->ma = mda->maback; + mda->scanline++; + mda->scanline &= 31; + mda->memaddr= mda->memaddr_backup; } - if (mda->sc == (mda->crtc[10] & 31) || ((mda->crtc[8] & 3) == 3 && mda->sc == ((mda->crtc[10] & 31) >> 1))) - mda->con = 1; + if (mda->scanline == (mda->crtc[MDA_CRTC_CURSOR_START] & 31) || ((mda->crtc[MDA_CRTC_INTERLACE] & 3) == 3 && mda->scanline == ((mda->crtc[MDA_CRTC_CURSOR_START] & 31) >> 1))) + mda->cursorvisible = 1; } } @@ -1404,19 +1401,19 @@ lcdc_poll(amsvid_t *vid) uint8_t chr; uint8_t attr; uint16_t dat; - int oldsc; - uint16_t ca; + int scanline_old; + uint16_t cursoraddr; int blink; - ca = (cga->crtc[15] | (cga->crtc[14] << 8)) & 0x3fff; + cursoraddr = (cga->crtc[CGA_CRTC_CURSOR_ADDR_LOW] | (cga->crtc[CGA_CRTC_CURSOR_ADDR_HIGH] << 8)) & 0x3fff; if (!cga->linepos) { timer_advance_u64(&vid->timer, cga->dispofftime); cga->cgastat |= 1; cga->linepos = 1; - oldsc = cga->sc; - if ((cga->crtc[8] & 3) == 3) - cga->sc = ((cga->sc << 1) + cga->oddeven) & 7; + scanline_old = cga->scanline; + if ((cga->crtc[CGA_CRTC_INTERLACE] & 3) == 3) + cga->scanline = ((cga->scanline << 1) + cga->oddeven) & 7; if (cga->cgadispon) { if (cga->displine < cga->firstline) { cga->firstline = cga->displine; @@ -1424,30 +1421,30 @@ lcdc_poll(amsvid_t *vid) } cga->lastline = cga->displine; - if (cga->cgamode & 1) { - for (x = 0; x < cga->crtc[1]; x++) { + if (cga->cgamode & CGA_MODE_FLAG_HIGHRES) { + for (x = 0; x < cga->crtc[CGA_CRTC_HDISP]; x++) { chr = cga->charbuffer[x << 1]; 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) + 1])[x * 8], chr, attr, drawcursor, blink, cga->sc, cga->cgamode & 0x40, cga->cgamode); - cga->ma++; + drawcursor = ((cga->memaddr == cursoraddr) && cga->cursorvisible && cga->cursoron); + blink = ((cga->cgablink & 16) && (cga->cgamode & CGA_MODE_FLAG_BLINK) && (attr & 0x80) && !drawcursor); + lcd_draw_char_80(vid, &(buffer32->line[cga->displine << 1])[x * 8], chr, attr, drawcursor, blink, cga->scanline, cga->cgamode & 0x40, cga->cgamode); + lcd_draw_char_80(vid, &(buffer32->line[(cga->displine << 1) + 1])[x * 8], chr, attr, drawcursor, blink, cga->scanline, cga->cgamode & 0x40, cga->cgamode); + cga->memaddr++; } - } 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]; - 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) + 1])[x * 16], chr, attr, drawcursor, blink, cga->sc, cga->cgamode); - cga->ma++; + } else if (!(cga->cgamode & CGA_MODE_FLAG_GRAPHICS)) { + for (x = 0; x < cga->crtc[CGA_CRTC_HDISP]; x++) { + chr = cga->vram[(cga->memaddr << 1) & 0x3fff]; + attr = cga->vram[((cga->memaddr << 1) + 1) & 0x3fff]; + drawcursor = ((cga->memaddr == cursoraddr) && cga->cursorvisible && cga->cursoron); + blink = ((cga->cgablink & 16) && (cga->cgamode & CGA_MODE_FLAG_BLINK) && (attr & 0x80) && !drawcursor); + lcd_draw_char_40(vid, &(buffer32->line[cga->displine << 1])[x * 16], chr, attr, drawcursor, blink, cga->scanline, cga->cgamode); + lcd_draw_char_40(vid, &(buffer32->line[(cga->displine << 1) + 1])[x * 16], chr, attr, drawcursor, blink, cga->scanline, cga->cgamode); + cga->memaddr++; } } else { /* Graphics mode */ - 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 (x = 0; x < cga->crtc[CGA_CRTC_HDISP]; x++) { + dat = (cga->vram[((cga->memaddr << 1) & 0x1fff) + ((cga->scanline & 1) * 0x2000)] << 8) | cga->vram[((cga->memaddr << 1) & 0x1fff) + ((cga->scanline & 1) * 0x2000) + 1]; + cga->memaddr++; 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; @@ -1455,22 +1452,22 @@ lcdc_poll(amsvid_t *vid) } } } else { - if (cga->cgamode & 1) { - hline(buffer32, 0, (cga->displine << 1), (cga->crtc[1] << 3), green); - hline(buffer32, 0, (cga->displine << 1) + 1, (cga->crtc[1] << 3), green); + if (cga->cgamode & CGA_MODE_FLAG_HIGHRES) { + hline(buffer32, 0, (cga->displine << 1), (cga->crtc[CGA_CRTC_HDISP] << 3), green); + hline(buffer32, 0, (cga->displine << 1) + 1, (cga->crtc[CGA_CRTC_HDISP] << 3), green); } else { - hline(buffer32, 0, (cga->displine << 1), (cga->crtc[1] << 4), green); - hline(buffer32, 0, (cga->displine << 1) + 1, (cga->crtc[1] << 4), green); + hline(buffer32, 0, (cga->displine << 1), (cga->crtc[CGA_CRTC_HDISP] << 4), green); + hline(buffer32, 0, (cga->displine << 1) + 1, (cga->crtc[CGA_CRTC_HDISP] << 4), green); } } - if (cga->cgamode & 1) - x = (cga->crtc[1] << 3); + if (cga->cgamode & CGA_MODE_FLAG_HIGHRES) + x = (cga->crtc[CGA_CRTC_HDISP] << 3); else - x = (cga->crtc[1] << 4); + x = (cga->crtc[CGA_CRTC_HDISP] << 4); - cga->sc = oldsc; - if (cga->vc == cga->crtc[7] && !cga->sc) + cga->scanline = scanline_old; + if (cga->vc == cga->crtc[CGA_CRTC_VSYNC] && !cga->scanline) cga->cgastat |= 8; cga->displine++; if (cga->displine >= 360) @@ -1483,54 +1480,53 @@ lcdc_poll(amsvid_t *vid) if (!cga->vsynctime) cga->cgastat &= ~8; } - if (cga->sc == (cga->crtc[11] & 31) || ((cga->crtc[8] & 3) == 3 && cga->sc == ((cga->crtc[11] & 31) >> 1))) { - cga->con = 0; - cga->coff = 1; + if (cga->scanline == (cga->crtc[CGA_CRTC_CURSOR_END] & 31) || ((cga->crtc[CGA_CRTC_INTERLACE] & 3) == 3 && cga->scanline == ((cga->crtc[CGA_CRTC_CURSOR_END] & 31) >> 1))) { + cga->cursorvisible = 0; } - if ((cga->crtc[8] & 3) == 3 && cga->sc == (cga->crtc[9] >> 1)) - cga->maback = cga->ma; + if ((cga->crtc[CGA_CRTC_INTERLACE] & 3) == 3 && cga->scanline == (cga->crtc[CGA_CRTC_MAX_SCANLINE_ADDR] >> 1)) + cga->memaddr_backup = cga->memaddr; if (cga->vadj) { - cga->sc++; - cga->sc &= 31; - cga->ma = cga->maback; + cga->scanline++; + cga->scanline &= 31; + cga->memaddr = cga->memaddr_backup; cga->vadj--; if (!cga->vadj) { cga->cgadispon = 1; - cga->ma = cga->maback = (cga->crtc[13] | (cga->crtc[12] << 8)) & 0x3fff; - cga->sc = 0; + cga->memaddr = cga->memaddr_backup = (cga->crtc[CGA_CRTC_START_ADDR_LOW] | (cga->crtc[CGA_CRTC_START_ADDR_HIGH] << 8)) & 0x3fff; + cga->scanline = 0; } - } else if (cga->sc == cga->crtc[9]) { - cga->maback = cga->ma; - cga->sc = 0; + } else if (cga->scanline == cga->crtc[CGA_CRTC_MAX_SCANLINE_ADDR]) { + cga->memaddr_backup = cga->memaddr; + cga->scanline = 0; oldvc = cga->vc; cga->vc++; cga->vc &= 127; - if (cga->vc == cga->crtc[6]) + if (cga->vc == cga->crtc[CGA_CRTC_VDISP]) cga->cgadispon = 0; - if (oldvc == cga->crtc[4]) { + if (oldvc == cga->crtc[CGA_CRTC_VTOTAL]) { cga->vc = 0; - cga->vadj = cga->crtc[5]; + cga->vadj = cga->crtc[CGA_CRTC_VTOTAL_ADJUST]; if (!cga->vadj) cga->cgadispon = 1; if (!cga->vadj) - cga->ma = cga->maback = (cga->crtc[13] | (cga->crtc[12] << 8)) & 0x3fff; - if ((cga->crtc[10] & 0x60) == 0x20) + cga->memaddr = cga->memaddr_backup = (cga->crtc[CGA_CRTC_START_ADDR_LOW] | (cga->crtc[CGA_CRTC_START_ADDR_HIGH] << 8)) & 0x3fff; + if ((cga->crtc[CGA_CRTC_CURSOR_START] & 0x60) == 0x20) cga->cursoron = 0; else cga->cursoron = cga->cgablink & 8; } - if (cga->vc == cga->crtc[7]) { + if (cga->vc == cga->crtc[CGA_CRTC_VSYNC]) { cga->cgadispon = 0; cga->displine = 0; cga->vsynctime = 16; - if (cga->crtc[7]) { - if (cga->cgamode & 1) - x = (cga->crtc[1] << 3); + if (cga->crtc[CGA_CRTC_VSYNC]) { + if (cga->cgamode & CGA_MODE_FLAG_HIGHRES) + x = (cga->crtc[CGA_CRTC_HDISP] << 3); else - x = (cga->crtc[1] << 4); + x = (cga->crtc[CGA_CRTC_HDISP] << 4); cga->lastline++; xs_temp = x; @@ -1542,7 +1538,7 @@ lcdc_poll(amsvid_t *vid) if (ys_temp < 32) ys_temp = 400; - if ((cga->cgamode & 8) && ((xs_temp != xsize) || (ys_temp != ysize) || video_force_resize_get())) { + if ((cga->cgamode & CGA_MODE_FLAG_VIDEO_ENABLE) && ((xs_temp != xsize) || (ys_temp != ysize) || video_force_resize_get())) { xsize = xs_temp; ysize = ys_temp; set_screen_size(xsize, ysize); @@ -1559,15 +1555,15 @@ lcdc_poll(amsvid_t *vid) video_res_x = xsize; video_res_y = ysize; - if (cga->cgamode & 1) { + if (cga->cgamode & CGA_MODE_FLAG_HIGHRES) { video_res_x /= 8; - video_res_y /= cga->crtc[9] + 1; + video_res_y /= cga->crtc[CGA_CRTC_MAX_SCANLINE_ADDR] + 1; video_bpp = 0; - } else if (!(cga->cgamode & 2)) { + } else if (!(cga->cgamode & CGA_MODE_FLAG_GRAPHICS)) { video_res_x /= 16; - video_res_y /= cga->crtc[9] + 1; + video_res_y /= cga->crtc[CGA_CRTC_MAX_SCANLINE_ADDR] + 1; video_bpp = 0; - } else if (!(cga->cgamode & 16)) { + } else if (!(cga->cgamode & CGA_MODE_FLAG_HIGHRES_GRAPHICS)) { video_res_x /= 2; video_bpp = 2; } else @@ -1579,17 +1575,17 @@ lcdc_poll(amsvid_t *vid) cga->oddeven ^= 1; } } else { - cga->sc++; - cga->sc &= 31; - cga->ma = cga->maback; + cga->scanline++; + cga->scanline &= 31; + cga->memaddr = cga->memaddr_backup; } 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))) - 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]; + if (cga->scanline == (cga->crtc[CGA_CRTC_CURSOR_START] & 31) || ((cga->crtc[CGA_CRTC_INTERLACE] & 3) == 3 && cga->scanline == ((cga->crtc[CGA_CRTC_CURSOR_START] & 31) >> 1))) + cga->cursorvisible = 1; + if (cga->cgadispon && (cga->cgamode & CGA_MODE_FLAG_HIGHRES)) { + for (x = 0; x < (cga->crtc[CGA_CRTC_HDISP] << 1); x++) + cga->charbuffer[x] = cga->vram[((cga->memaddr << 1) + x) & 0x3fff]; } } } @@ -1620,8 +1616,7 @@ vid_init_200(amstrad_t *ams) mda_t *mda; /* Allocate a video controller block. */ - vid = (amsvid_t *) malloc(sizeof(amsvid_t)); - memset(vid, 0x00, sizeof(amsvid_t)); + vid = (amsvid_t *) calloc(1, sizeof(amsvid_t)); vid->emulation = device_get_config_int("video_emulation"); @@ -1831,7 +1826,7 @@ const device_t vid_200_device = { .init = NULL, .close = vid_close_200, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = vid_speed_changed_200, .force_redraw = NULL, .config = vid_200_config @@ -1931,7 +1926,7 @@ const device_t vid_ppc512_device = { .init = NULL, .close = vid_close_200, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = vid_speed_changed_200, .force_redraw = NULL, .config = vid_ppc512_config @@ -1965,7 +1960,7 @@ const device_t vid_pc2086_device = { .init = NULL, .close = NULL, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = vid_pc2086_config @@ -1999,7 +1994,7 @@ const device_t vid_pc3086_device = { .init = NULL, .close = NULL, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = vid_pc3086_config @@ -2870,8 +2865,7 @@ machine_amstrad_init(const machine_t *model, int type) { amstrad_t *ams; - ams = (amstrad_t *) malloc(sizeof(amstrad_t)); - memset(ams, 0x00, sizeof(amstrad_t)); + ams = (amstrad_t *) calloc(1, sizeof(amstrad_t)); ams->type = type; amstrad_latch = 0x80000000; @@ -2940,7 +2934,7 @@ machine_amstrad_init(const machine_t *model, int type) break; case AMS_PC1640: - loadfont("roms/video/mda/mda.rom", 0); + loadfont(FONT_IBM_MDA_437_PATH, 0); device_context(&vid_1640_device); ams->language = device_get_config_int("language"); vid_init_1640(ams); diff --git a/src/machine/m_at.c b/src/machine/m_at.c index fea87c8f6..d2c4b99a2 100644 --- a/src/machine/m_at.c +++ b/src/machine/m_at.c @@ -154,9 +154,68 @@ machine_at_ps2_ide_init(const machine_t *model) static const device_config_t ibmat_config[] = { // clang-format off { - .name = "enable_5161", + .name = "bios", + .description = "BIOS Version", + .type = CONFIG_BIOS, + .default_string = "ibm5170_111585", + .default_int = 0, + .file_filter = "", + .spinner = { 0 }, + .bios = { + { + .name = "62X082x (11/15/85)", + .internal_name = "ibm5170_111585", + .bios_type = BIOS_NORMAL, + .files_no = 2, + .local = 0, + .size = 65536, + .files = { "roms/machines/ibmat/BIOS_5170_15NOV85_U27.BIN", "roms/machines/ibmat/BIOS_5170_15NOV85_U47.BIN", "" } + }, + { + .name = "61X9266 (11/15/85) (Alt)", + .internal_name = "ibm5170_111585_alt", + .bios_type = BIOS_NORMAL, + .files_no = 2, + .local = 0, + .size = 65536, + .files = { "roms/machines/ibmat/BIOS_5170_15NOV85_U27_61X9266.BIN", "roms/machines/ibmat/BIOS_5170_15NOV85_U47_61X9265.BIN", "" } + }, + { + .name = "648009x (06/10/85)", + .internal_name = "ibm5170_061085", + .bios_type = BIOS_NORMAL, + .files_no = 2, + .local = 0, + .size = 65536, + .files = { "roms/machines/ibmat/BIOS_5170_10JUN85_U27.BIN", "roms/machines/ibmat/BIOS_5170_10JUN85_U47.BIN", "" } + }, + { + .name = "618102x (01/10/84)", + .internal_name = "ibm5170_011084", + .bios_type = BIOS_NORMAL, + .files_no = 2, + .local = 0, + .size = 65536, + .files = { "roms/machines/ibmat/BIOS_5170_10JAN84_U27.BIN", "roms/machines/ibmat/BIOS_5170_10JAN84_U47.BIN", "" } + }, + // The following are Diagnostic ROMs. + { + .name = "Supersoft Diagnostics", + .internal_name = "diag_supersoft", + .bios_type = BIOS_NORMAL, + .files_no = 2, + .local = 2, + .size = 65536, + .files = { "roms/machines/diagnostic/5170_EVEN_LOW_U27_27256.bin", "roms/machines/diagnostic/5170_ODD_HIGH_U47_27256.bin", "" } + }, + + { .files_no = 0 } + }, + }, + { + .name = "enable_5161", .description = "IBM 5161 Expansion Unit", - .type = CONFIG_BINARY, + .type = CONFIG_BINARY, .default_int = 0 }, { .name = "", .description = "", .type = CONFIG_END } @@ -164,7 +223,7 @@ static const device_config_t ibmat_config[] = { }; const device_t ibmat_device = { - .name = " IBM AT Devices", + .name = "IBM AT", .internal_name = "ibmat_device", .flags = 0, .local = 0, @@ -180,17 +239,21 @@ const device_t ibmat_device = { int machine_at_ibm_init(const machine_t *model) { - int ret; - uint8_t enable_5161; + int ret = 0; + uint8_t enable_5161; + const char *fn[2]; + + /* No ROMs available. */ + if (!device_available(model->device)) + return ret; device_context(model->device); enable_5161 = machine_get_config_int("enable_5161"); + fn[0] = device_get_bios_file(model->device, device_get_config_bios("bios"), 0); + fn[1] = device_get_bios_file(model->device, device_get_config_bios("bios"), 1); + ret = bios_load_interleaved(fn[0], fn[1], 0x000f0000, 65536, 0); device_context_restore(); - ret = bios_load_interleaved("roms/machines/ibmat/62x0820.u27", - "roms/machines/ibmat/62x0821.u47", - 0x000f0000, 65536, 0); - if (bios_only || !ret) return ret; @@ -267,7 +330,7 @@ static const device_config_t ibmxt286_config[] = { }; const device_t ibmxt286_device = { - .name = "IBM XT Model 286 Devices", + .name = "IBM XT Model 286", .internal_name = "ibmxt286_device", .flags = 0, .local = 0, @@ -305,6 +368,23 @@ machine_at_ibmxt286_init(const machine_t *model) return ret; } +int +machine_at_pb286_init(const machine_t *model) +{ + int ret; + + ret = bios_load_interleaved("roms/machines/pb286/LB_V332P.BIN", + "roms/machines/pb286/HB_V332P.BIN", + 0x000f0000, 65536, 0); + + if (bios_only || !ret) + return ret; + + machine_at_ibm_common_init(model); + + return ret; +} + int machine_at_siemens_init(const machine_t *model) { @@ -344,21 +424,3 @@ machine_at_wellamerastar_init(const machine_t *model) return ret; } - -#ifdef USE_OPEN_AT -int -machine_at_openat_init(const machine_t *model) -{ - int ret; - - ret = bios_load_linear("roms/machines/openat/bios.bin", - 0x000f0000, 65536, 0); - - if (bios_only || !ret) - return ret; - - machine_at_ibm_common_init(model); - - return ret; -} -#endif /* USE_OPEN_AT */ diff --git a/src/machine/m_at_286_386sx.c b/src/machine/m_at_286_386sx.c index ead31c21c..eb5394ba4 100644 --- a/src/machine/m_at_286_386sx.c +++ b/src/machine/m_at_286_386sx.c @@ -37,6 +37,7 @@ #include <86box/hdc.h> #include <86box/nvr.h> #include <86box/port_6x.h> +#define USE_SIO_DETECT #include <86box/sio.h> #include <86box/serial.h> #include <86box/video.h> @@ -66,7 +67,7 @@ machine_at_mr286_init(const machine_t *model) } static void -machine_at_headland_common_init(int type) +machine_at_headland_common_init(const machine_t *model, int type) { device_add(&keyboard_at_ami_device); @@ -94,7 +95,7 @@ machine_at_tg286m_init(const machine_t *model) machine_at_common_ide_init(model); - machine_at_headland_common_init(1); + machine_at_headland_common_init(model, 1); return ret; } @@ -115,7 +116,7 @@ machine_at_ama932j_init(const machine_t *model) if (gfxcard[0] == VID_INTERNAL) device_add(&oti067_ama932j_device); - machine_at_headland_common_init(2); + machine_at_headland_common_init(model, 2); device_add(&ali5105_device); @@ -168,6 +169,72 @@ machine_at_quadt386sx_init(const machine_t *model) return ret; } +static const device_config_t pbl300sx_config[] = { + // clang-format off + { + .name = "bios", + .description = "BIOS Version", + .type = CONFIG_BIOS, + .default_string = "pbl300sx", + .default_int = 0, + .file_filter = "", + .spinner = { 0 }, + .bios = { + { .name = "1991", .internal_name = "pbl300sx_1991", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/pbl300sx/V1.10_1113_910723.bin", "" } }, + { .name = "1992", .internal_name = "pbl300sx", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/pbl300sx/pb_l300sx_1992.bin", "" } }, + { .files_no = 0 } + }, + }, + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on +}; + +const device_t pbl300sx_device = { + .name = "Packard Bell Legend 300SX", + .internal_name = "pbl300sx_device", + .flags = 0, + .local = 0, + .init = NULL, + .close = NULL, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = pbl300sx_config +}; + +int +machine_at_pbl300sx_init(const machine_t *model) +{ + int ret = 0; + const char* fn; + + /* No ROMs available */ + if (!device_available(model->device)) + return ret; + + device_context(model->device); + fn = device_get_bios_file(machine_get_device(machine), device_get_config_bios("bios"), 0); + ret = bios_load_linear(fn, 0x000e0000, 131072, 0); + device_context_restore(); + + if (bios_only || !ret) + return ret; + + machine_at_common_init(model); + device_add(&acc2036_device); + + device_add(&keyboard_ps2_phoenix_device); + device_add(&um82c862f_ide_device); + + if (gfxcard[0] == VID_INTERNAL) + device_add(machine_get_vid_device(machine)); + + return ret; +} + int machine_at_neat_init(const machine_t *model) { @@ -222,10 +289,6 @@ machine_at_ataripc4_init(const machine_t *model) ret = bios_load_interleaved("roms/machines/ataripc4/AMI_PC4X_1.7_EVEN.BIN", "roms/machines/ataripc4/AMI_PC4X_1.7_ODD.BIN", -#if 0 - ret = bios_load_interleaved("roms/machines/ataripc4/ami_pc4x_1.7_even.bin", - "roms/machines/ataripc4/ami_pc4x_1.7_odd.bin", -#endif 0x000f0000, 65536, 0); if (bios_only || !ret) @@ -265,6 +328,69 @@ machine_at_px286_init(const machine_t *model) return ret; } +static void +machine_at_ctat_common_init(const machine_t *model) +{ + machine_at_common_init(model); + + device_add(&cs8220_device); + + if (fdc_current[0] == FDC_INTERNAL) + device_add(&fdc_at_device); + + device_add(&keyboard_at_phoenix_device); +} + +int +machine_at_dells200_init(const machine_t *model) +{ + int ret; + + ret = bios_load_interleaved("roms/machines/dells200/dellL200256_LO_@DIP28.BIN", + "roms/machines/dells200/Dell200256_HI_@DIP28.BIN", + 0x000f0000, 65536, 0); + + if (bios_only || !ret) + return ret; + + machine_at_ctat_common_init(model); + + return ret; +} + +int +machine_at_at122_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/at122/FINAL.BIN", + 0x000f0000, 65536, 0); + + if (bios_only || !ret) + return ret; + + machine_at_ctat_common_init(model); + + return ret; +} + +int +machine_at_tuliptc7_init(const machine_t *model) +{ + int ret; + + ret = bios_load_interleavedr("roms/machines/tuliptc7/tc7be.bin", + "roms/machines/tuliptc7/tc7bo.bin", + 0x000f8000, 65536, 0); + + if (bios_only || !ret) + return ret; + + machine_at_ctat_common_init(model); + + return ret; +} + int machine_at_micronics386_init(const machine_t *model) { @@ -285,6 +411,26 @@ machine_at_micronics386_init(const machine_t *model) return ret; } +int +machine_at_micronics386px_init(const machine_t *model) +{ + int ret; + + ret = bios_load_interleaved("roms/machines/micronics386/386-Micronics-09-00021-LO.BIN", + "roms/machines/micronics386/386-Micronics-09-00021-HI.BIN", + 0x000f0000, 65536, 0); + + if (bios_only || !ret) + return ret; + + machine_at_init(model); + + if (fdc_current[0] == FDC_INTERNAL) + device_add(&fdc_at_device); + + return ret; +} + static void machine_at_scat_init(const machine_t *model, int is_v4, int is_ami) { @@ -630,9 +776,9 @@ machine_at_cmdsl386sx16_init(const machine_t *model) if (bios_only || !ret) return ret; - machine_at_common_ide_init(model); + machine_at_common_init(model); - device_add(&keyboard_at_device); + device_add(&keyboard_ps2_device); if (fdc_current[0] == FDC_INTERNAL) device_add(&fdc_at_device); @@ -645,6 +791,39 @@ machine_at_cmdsl386sx16_init(const machine_t *model) return ret; } +int +machine_at_if386sx_init(const machine_t *model) +{ + int ret; + + ret = bios_load_interleaved("roms/machines/if386sx/OKI_IF386SX_odd.bin", + "roms/machines/if386sx/OKI_IF386SX_even.bin", + 0x000f0000, 65536, 0); + + if (bios_only || !ret) + return ret; + + machine_at_common_init_ex(model, 2); + device_add(&amstrad_megapc_nvr_device); /* NVR that is initialized to all 0x00's. */ + + device_add(&keyboard_at_phoenix_device); + + device_add(&neat_sx_device); + + device_add(&if386jega_device); + + if (fdc_current[0] == FDC_INTERNAL) + device_add(&fdc_at_device); + + /* + One serial port - on the real hardware IF386AX, it is on the VL 16C451, + alognside the bidirectional parallel port. + */ + device_add_inst(&ns16450_device, 1); + + return ret; +} + static void machine_at_scamp_common_init(const machine_t *model, int is_ps2) { @@ -675,7 +854,9 @@ machine_at_cmdsl386sx25_init(const machine_t *model) if (gfxcard[0] == VID_INTERNAL) device_add(&gd5402_onboard_device); - machine_at_common_ide_init(model); + machine_at_common_init_ex(model, 2); + + device_add(&ide_isa_device); device_add(&ali5105_device); /* The FDC is part of the ALi M5105. */ device_add(&vl82c113_device); /* The keyboard controller is part of the VL82c113. */ @@ -685,6 +866,75 @@ machine_at_cmdsl386sx25_init(const machine_t *model) return ret; } +static const device_config_t dells333sl_config[] = { + // clang-format off + { + .name = "bios", + .description = "BIOS Version", + .type = CONFIG_BIOS, + .default_string = "dells333sl", + .default_int = 0, + .file_filter = "", + .spinner = { 0 }, + .bios = { + { .name = "J01 (Jostens Learning Corporation OEM)", .internal_name = "dells333sl_j01", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/dells333sl/DELL386.BIN", "" } }, + { .name = "A02", .internal_name = "dells333sl", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/dells333sl/Dell_386SX_30807_UBIOS_B400_VLSI_VL82C311_Cirrus_Logic_GD5420.bin", "" } }, + { .files_no = 0 } + }, + }, + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on +}; + +const device_t dells333sl_device = { + .name = "Dell System 333s/L", + .internal_name = "dells333sl_device", + .flags = 0, + .local = 0, + .init = NULL, + .close = NULL, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = dells333sl_config +}; + +int +machine_at_dells333sl_init(const machine_t *model) +{ + int ret = 0; + const char* fn; + + /* No ROMs available */ + if (!device_available(model->device)) + return ret; + + device_context(model->device); + fn = device_get_bios_file(machine_get_device(machine), device_get_config_bios("bios"), 0); + ret = bios_load_linear(fn, 0x000e0000, 262144, 0); + memcpy(rom, &(rom[0x00020000]), 131072); + mem_mapping_set_addr(&bios_mapping, 0x0c0000, 0x40000); + mem_mapping_set_exec(&bios_mapping, rom); + device_context_restore(); + + if (gfxcard[0] == VID_INTERNAL) + device_add(machine_get_vid_device(machine)); + + machine_at_common_init_ex(model, 2); + + device_add(&ide_isa_device); + + device_add(&pc87311_device); + device_add(&vl82c113_device); /* The keyboard controller is part of the VL82c113. */ + + device_add(&vlsi_scamp_device); + + return ret; +} + int machine_at_dataexpert386sx_init(const machine_t *model) { @@ -746,7 +996,7 @@ machine_at_acer100t_init(const machine_t *model) { int ret; - ret = bios_load_linear("roms/machines/acer100t/acer386.bin", + ret = bios_load_linear("roms/machines/acer100t/acer386.BIN", 0x000f0000, 65536, 0); if (bios_only || !ret) @@ -754,12 +1004,9 @@ machine_at_acer100t_init(const machine_t *model) machine_at_ps2_ide_init(model); - if (fdc_current[0] == FDC_INTERNAL) - device_add(&fdc_at_device); - device_add(&ali1409_device); if (gfxcard[0] == VID_INTERNAL) - device_add(&oti077_acer100t_device); + device_add(&oti077_acer100t_device); device_add(&ali5105_device); @@ -963,7 +1210,7 @@ machine_at_3302_init(const machine_t *model) device_add(&fdc_at_device); if (gfxcard[0] == VID_INTERNAL) - device_add(¶dise_pvga1a_ncr3302_device); + device_add(machine_get_vid_device(machine)); device_add(&keyboard_at_ncr_device); @@ -997,7 +1244,6 @@ machine_at_pc916sx_init(const machine_t *model) return ret; } -#ifdef USE_OLIVETTI int machine_at_m290_init(const machine_t *model) { @@ -1009,15 +1255,16 @@ machine_at_m290_init(const machine_t *model) if (bios_only || !ret) return ret; - machine_at_common_init_ex(model, 4); - device_add(&keyboard_at_olivetti_device); + machine_at_common_init_ex(model, 6); + device_add(&amstrad_megapc_nvr_device); + + device_add(&olivetti_eva_device); device_add(&port_6x_olivetti_device); if (fdc_current[0] == FDC_INTERNAL) device_add(&fdc_at_device); - device_add(&olivetti_eva_device); + device_add(&keyboard_at_olivetti_device); return ret; } -#endif /* USE_OLIVETTI */ diff --git a/src/machine/m_at_386dx_486.c b/src/machine/m_at_386dx_486.c index 1c35d7290..09efd51bf 100644 --- a/src/machine/m_at_386dx_486.c +++ b/src/machine/m_at_386dx_486.c @@ -50,6 +50,7 @@ #include <86box/plat_unused.h> #include <86box/sound.h> +/* 386DX */ int machine_at_acc386_init(const machine_t *model) { @@ -71,6 +72,27 @@ machine_at_acc386_init(const machine_t *model) return ret; } +int +machine_at_asus3863364k_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/asus3863364k/am27c512dip28-64b53c26be3d8160533563.bin", + 0x000f0000, 65536, 0); + + if (bios_only || !ret) + return ret; + + machine_at_common_init(model); + device_add(&rabbit_device); + device_add(&keyboard_at_ami_device); + + if (fdc_current[0] == FDC_INTERNAL) + device_add(&fdc_at_device); + + return ret; +} + int machine_at_asus386_init(const machine_t *model) { @@ -112,6 +134,27 @@ machine_at_tandy4000_init(const machine_t *model) return ret; } +int +machine_at_dtk461_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/dtk461/DTK.BIO", + 0x000f0000, 65536, 0); + + if (bios_only || !ret) + return ret; + + machine_at_common_init(model); + device_add(&sl82c461_device); + device_add(&keyboard_at_ami_device); + + if (fdc_current[0] == FDC_INTERNAL) + device_add(&fdc_at_device); + + return ret; +} + static void machine_at_sis401_common_init(const machine_t *model) { @@ -252,7 +295,7 @@ machine_at_ecs386v_init(const machine_t *model) int ret; ret = bios_load_linear("roms/machines/ecs386v/PANDA_386V.BIN", - 0x000f0000, 65536, 0); + 0x000f0000, 65536, 0); if (bios_only || !ret) return ret; @@ -353,7 +396,7 @@ machine_at_pb410a_init(const machine_t *model) device_add(&phoenix_486_jumper_device); if (gfxcard[0] == VID_INTERNAL) - device_add(&ht216_32_pb410a_device); + device_add(machine_get_vid_device(machine)); return ret; } @@ -369,14 +412,16 @@ machine_at_vect486vl_init(const machine_t *model) // has HDC problems if (bios_only || !ret) return ret; - machine_at_common_ide_init(model); + if (gfxcard[0] == VID_INTERNAL) + device_add(machine_get_vid_device(machine)); + + machine_at_common_init_ex(model, 2); device_add(&vl82c480_device); - if (gfxcard[0] == VID_INTERNAL) - device_add(&gd5428_onboard_device); - device_add(&vl82c113_device); + + device_add(&ide_isa_device); device_add(&fdc37c651_ide_device); return ret; @@ -393,14 +438,18 @@ machine_at_d824_init(const machine_t *model) if (bios_only || !ret) return ret; - machine_at_common_init(model); + if (gfxcard[0] == VID_INTERNAL) + device_add(machine_get_vid_device(machine)); + + machine_at_common_init_ex(model, 2); device_add(&vl82c480_device); - if (gfxcard[0] == VID_INTERNAL) - device_add(&gd5428_onboard_device); - - device_add(&keyboard_ps2_device); + /* + Technically, it should be the VL82C114 but we do not have + a proper datasheet of it that tells us the registers. + */ + device_add(&vl82c113_device); device_add(&ide_isa_device); device_add(&fdc37c651_device); @@ -408,6 +457,65 @@ machine_at_d824_init(const machine_t *model) return ret; } +int +machine_at_tuliptc38_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/tuliptc38/TULIP1.BIN", + 0x000f0000, 262144, 0); + + if (bios_only || !ret) + return ret; + + machine_at_common_init_ex(model, 2); + + device_add(&vl82c486_device); + device_add(&tulip_jumper_device); + + device_add(&vl82c113_device); + + device_add(&ide_isa_device); + device_add(&fdc37c651_ide_device); + + if (gfxcard[0] == VID_INTERNAL) { + bios_load_aux_linear("roms/machines/tuliptc38/VBIOS.BIN", + 0x000c0000, 32768, 0); + + device_add(machine_get_vid_device(machine)); + } else 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; +} + +int +machine_at_martin_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/martin/NONSCSI.ROM", + 0x000e0000, 131072, 0); + + if (bios_only || !ret) + return ret; + + machine_at_common_init_ex(model, 2); + + device_add(&vl82c480_device); + device_add(&vl82c113_device); + + device_add(&ide_vlb_device); + device_add(&fdc37c651_ide_device); + + device_add(&intel_flash_bxt_device); + + return ret; +} + int machine_at_acera1g_init(const machine_t *model) { @@ -472,16 +580,47 @@ machine_at_decpclpv_init(const machine_t *model) device_add(&sis_85c461_device); if (gfxcard[0] == VID_INTERNAL) - device_add(&s3_86c805_onboard_vlb_device); + device_add(machine_get_vid_device(machine)); + + device_add(&keyboard_ps2_phoenix_pci_device); - /* TODO: Phoenix MultiKey KBC */ - device_add(&keyboard_ps2_ami_pci_device); device_add(&ide_isa_2ch_device); device_add(&fdc37c663_ide_device); return ret; } +int +machine_at_dell466np_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/dell466np/466np.bin", + 0x000c0000, 262144, 0); + + if (bios_only || !ret) + return ret; + + machine_at_common_init(model); + device_add(&sis_85c461_device); + + if (gfxcard[0] == VID_INTERNAL) + device_add(machine_get_vid_device(machine)); + else { + 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); + + device_add(&keyboard_ps2_phoenix_pci_device); + + device_add(&ide_isa_device); + device_add(&fdc37c661_ide_device); + + return ret; +} + static void machine_at_ali1429_common_init(const machine_t *model, int is_green) { @@ -543,7 +682,7 @@ machine_at_opti495_init(const machine_t *model) machine_at_common_init(model); - device_add(&opti495_device); + device_add(&opti495slc_device); device_add(&keyboard_at_device); @@ -558,7 +697,7 @@ machine_at_opti495_ami_common_init(const machine_t *model) { machine_at_common_init(model); - device_add(&opti495_device); + device_add(&opti495sx_device); device_add(&keyboard_at_ami_device); @@ -598,6 +737,32 @@ machine_at_opti495_mr_init(const machine_t *model) return ret; } +int +machine_at_c747_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/c747/486-C747 Tandon.BIN", + 0x000f0000, 65536, 0); + + if (bios_only || !ret) + return ret; + + machine_at_common_init(model); + + /* The EFAR chipset is a rebrand of the OPTi 495SX. */ + device_add(&opti495sx_device); + + /* + No idea what KBC it actually has but this produces the + desired behavior: command A9 does absolutely nothing. + */ + device_add(&keyboard_at_siemens_device); + device_add(&um82c862f_ide_device); + + return ret; +} + int machine_at_exp4349_init(const machine_t *model) { @@ -684,14 +849,59 @@ machine_at_403tg_d_mr_init(const machine_t *model) return ret; } +static const device_config_t pb450_config[] = { + // clang-format off + { + .name = "bios", + .description = "BIOS Version", + .type = CONFIG_BIOS, + .default_string = "pb450a", + .default_int = 0, + .file_filter = "", + .spinner = { 0 }, + .bios = { + { .name = "PCI 1.0A", .internal_name = "pb450a" /*"pci10a"*/, .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/pb450/OPTI802.bin", "" } }, + { .name = "PNP 1.1A", .internal_name = "pnp11a", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/pb450/PNP11A.bin", "" } }, + { .name = "P4HS20 (Micro Firmware/Phoenix 4.05)", .internal_name = "p4hs20", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/pb450/p4hs20.bin", "" } }, + { .files_no = 0 } + }, + }, + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on +}; + +const device_t pb450_device = { + .name = "Packard Bell PB450", + .internal_name = "pb450_device", + .flags = 0, + .local = 0, + .init = NULL, + .close = NULL, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = pb450_config +}; + int machine_at_pb450_init(const machine_t *model) { - int ret; + int ret = 0; + const char* fn; - ret = bios_load_linear("roms/machines/pb450/OPTI802.bin", - 0x000e0000, 131072, 0); + /* No ROMs available */ + if (!device_available(model->device)) + return ret; + device_context(model->device); + fn = device_get_bios_file(machine_get_device(machine), device_get_config_bios("bios"), 0); + ret = bios_load_linear(fn, 0x000e0000, 131072, 0); + device_context_restore(); + if (bios_only || !ret) return ret; @@ -791,7 +1001,8 @@ machine_at_mvi486_init(const machine_t *model) machine_at_common_init(model); - device_add(&opti895_device); + device_add(&opti498_device); + device_add(&keyboard_at_device); device_add(&pc87311_ide_device); @@ -826,6 +1037,31 @@ machine_at_ami471_init(const machine_t *model) return ret; } +int +machine_at_advantage40xxd_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/advantage40xxd/AST101.09A", + 0x000e0000, 131072, 0); + + if (bios_only || !ret) + return ret; + + machine_at_common_init(model); + device_add(&sis_85c471_device); + + if (gfxcard[0] == VID_INTERNAL) + device_add(machine_get_vid_device(machine)); + + device_add(&keyboard_ps2_phoenix_device); + device_add(&um82c863f_ide_device); + + device_add(&intel_flash_bxt_device); + + return ret; +} + int machine_at_vli486sv2g_init(const machine_t *model) { @@ -1138,6 +1374,39 @@ machine_at_ms4144_init(const machine_t *model) return ret; } +int +machine_at_acerp3_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/acerp3/Acer Mate 600 P3 BIOS U13 V2.0R02-J3 ACR8DE00-S00-950911-R02-J3.bin", + 0x000e0000, 131072, 0); + + if (bios_only || !ret) + return ret; + + machine_at_common_init_ex(model, 2); + + machine_at_sis_85c496_common_init(model); + device_add(&sis_85c496_device); + pci_register_slot(0x09, PCI_CARD_VIDEO, 0, 0, 0, 0); + pci_register_slot(0x0A, PCI_CARD_IDE, 0, 0, 0, 0); + pci_register_slot(0x12, PCI_CARD_NORMAL, 3, 4, 1, 2); + pci_register_slot(0x13, PCI_CARD_NORMAL, 2, 3, 4, 1); + pci_register_slot(0x14, PCI_CARD_NORMAL, 1, 2, 3, 4); + + device_add(&fdc37c665_ide_device); + device_add(&keyboard_ps2_acer_pci_device); + device_add(&ide_cmd640_pci_legacy_only_device); + + if (gfxcard[0] == VID_INTERNAL) + device_add(&gd5434_onboard_pci_device); + + device_add(&intel_flash_bxt_device); + + return ret; +} + int machine_at_486sp3c_init(const machine_t *model) { @@ -1204,7 +1473,9 @@ machine_at_alfredo_init(const machine_t *model) if (bios_only || !ret) return ret; - machine_at_common_init(model); + machine_at_common_init_ex(model, 2); + + device_add(&amstrad_megapc_nvr_device); device_add(&ide_pci_device); pci_init(PCI_CONFIG_TYPE_2 | PCI_NO_IRQ_STEERING); @@ -1214,7 +1485,7 @@ machine_at_alfredo_init(const machine_t *model) pci_register_slot(0x0E, PCI_CARD_NORMAL, 2, 1, 3, 4); pci_register_slot(0x0C, PCI_CARD_NORMAL, 1, 3, 2, 4); pci_register_slot(0x02, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0); - device_add(&keyboard_ps2_pci_device); + device_add(&keyboard_ps2_phoenix_device); device_add(&sio_device); device_add(&fdc37c663_device); device_add(&intel_flash_bxt_ami_device); @@ -1235,14 +1506,15 @@ machine_at_ninja_init(const machine_t *model) if (bios_only || !ret) return ret; - machine_at_common_init(model); + machine_at_common_init_ex(model, 2); + device_add(&amstrad_megapc_nvr_device); pci_init(PCI_CONFIG_TYPE_1); pci_register_slot(0x05, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); pci_register_slot(0x11, PCI_CARD_NORMAL, 1, 2, 1, 2); pci_register_slot(0x13, PCI_CARD_NORMAL, 2, 1, 2, 1); pci_register_slot(0x0B, PCI_CARD_NORMAL, 2, 1, 2, 1); - device_add(&keyboard_ps2_intel_ami_pci_device); + device_add(&keyboard_ps2_phoenix_device); device_add(&intel_flash_bxt_ami_device); device_add(&i420ex_device); @@ -1369,7 +1641,7 @@ machine_at_amis76_init(const machine_t *model) { int ret; - ret = bios_load_linear_inverted("roms/machines/s76p/S76P.ROM", + ret = bios_load_linear_inverted("roms/machines/s76p/S76P.ROM", 0x000e0000, 131072, 0); if (bios_only || !ret) @@ -1486,6 +1758,87 @@ machine_at_486sp3g_init(const machine_t *model) return ret; } +static const device_config_t sb486pv_config[] = { + // clang-format off + { + .name = "bios", + .description = "BIOS Version", + .type = CONFIG_BIOS, + .default_string = "sb486pv", + .default_int = 0, + .file_filter = "", + .spinner = { 0 }, + .bios = { + { .name = "AMI 062594 (0108)", .internal_name = "sb486pv", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/sb486pv/41-0108-062594-SATURN2.rom", "" } }, + { .name = "AMI 062594 (0301)", .internal_name = "sb486pv_94", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/sb486pv/0301-062594-SATURN2.rom", "" } }, + { .name = "AMI 071595 (1301)", .internal_name = "sb486pv_95", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/sb486pv/amiboot.rom", "" } }, + { .files_no = 0 } + }, + }, + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on +}; + +const device_t sb486pv_device = { + .name = "ICS SB486PV", + .internal_name = "sb486pv_device", + .flags = 0, + .local = 0, + .init = NULL, + .close = NULL, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = sb486pv_config +}; + +int +machine_at_sb486pv_init(const machine_t *model) +{ + int ret = 0; + const char* fn; + + /* No ROMs available */ + if (!device_available(model->device)) + return ret; + + device_context(model->device); + fn = device_get_bios_file(machine_get_device(machine), device_get_config_bios("bios"), 0); + if (!strcmp(fn, "roms/machines/sb486pv/amiboot.rom")) + ret = bios_load_linear(fn, 0x000e0000, 131072, 0); + else + ret = bios_load_linear_inverted(fn, 0x000e0000, 131072, 0); + device_context_restore(); + + machine_at_common_init(model); + + pci_init(PCI_CONFIG_TYPE_2); + pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); + pci_register_slot(0x0e, PCI_CARD_IDE, 0, 0, 0, 0); + pci_register_slot(0x0f, PCI_CARD_VIDEO, 1, 2, 3, 4); + pci_register_slot(0x02, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0); + + if (gfxcard[0] == VID_INTERNAL) + device_add(machine_get_vid_device(machine)); + + device_add(&keyboard_ps2_ami_pci_device); + device_add(&sio_zb_device); + device_add(&ide_rz1000_pci_single_channel_device); + device_add(&i82091aa_26e_device); + if (!strcmp(fn, "roms/machines/sb486pv/amiboot.rom")) + device_add(&intel_flash_bxt_device); + else + device_add(&intel_flash_bxt_ami_device); + + device_add(&i420zx_device); + + return ret; +} + int machine_at_486ap4_init(const machine_t *model) { @@ -1679,12 +2032,11 @@ machine_at_sbc490_init(const machine_t *model) pci_register_slot(0x0C, PCI_CARD_NORMAL, 1, 2, 3, 4); pci_register_slot(0x01, PCI_CARD_VIDEO, 4, 1, 2, 3); + if (gfxcard[0] == VID_INTERNAL) + device_add(machine_get_vid_device(machine)); + device_add(&ali1489_device); device_add(&fdc37c665_device); - - if (gfxcard[0] == VID_INTERNAL) - device_add(&tgui9440_onboard_pci_device); - device_add(&keyboard_ps2_ami_device); device_add(&sst_flash_29ee010_device); @@ -1933,18 +2285,66 @@ machine_at_ecs486_init(const machine_t *model) return ret; } +static const device_config_t hot433a_config[] = { + // clang-format off + { + .name = "bios", + .description = "BIOS Version", + .type = CONFIG_BIOS, + .default_string = "hot433a", + .default_int = 0, + .file_filter = "", + .spinner = { 0 }, + .bios = { + { .name = "AMI", .internal_name = "hot433a", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/hot433/433AUS33.ROM", "" } }, + { .name = "Award (eSupport update)", .internal_name = "hot433a_award", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/hot433/2A4X5H21.BIN", "" } }, + { .files_no = 0 } + }, + }, + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on +}; + +const device_t hot433a_device = { + .name = "Shuttle HOT-433A", + .internal_name = "hot433a_device", + .flags = 0, + .local = 0, + .init = NULL, + .close = NULL, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = hot433a_config +}; + int machine_at_hot433a_init(const machine_t *model) { - int ret; + int ret = 0; + const char* fn; - ret = bios_load_linear("roms/machines/hot433/433AUS33.ROM", - 0x000e0000, 131072, 0); + /* No ROMs available */ + if (!device_available(model->device)) + return ret; + + device_context(model->device); + int is_award = !strcmp(device_get_config_bios("bios"), "hot433a_award"); + fn = device_get_bios_file(machine_get_device(machine), device_get_config_bios("bios"), 0); + ret = bios_load_linear(fn, 0x000e0000, 131072, 0); + device_context_restore(); if (bios_only || !ret) return ret; - machine_at_common_init(model); + machine_at_common_init_ex(model, 2); + if (is_award) + device_add(&amstrad_megapc_nvr_device); + else + device_add(&ami_1994_nvr_device); pci_init(PCI_CONFIG_TYPE_1); pci_register_slot(0x10, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); @@ -1956,9 +2356,46 @@ machine_at_hot433a_init(const machine_t *model) device_add(&umc_hb4_device); device_add(&umc_8886bf_device); - device_add(&um8669f_device); + if (is_award) + device_add(&um8663af_device); + else + device_add(&um8669f_device); device_add(&winbond_flash_w29c010_device); - device_add(&keyboard_at_ami_device); + if (is_award) + device_add(&keyboard_ps2_ami_device); + else + device_add(&keyboard_at_ami_device); + + pic_toggle_latch(is_award); + + return ret; +} + +int +machine_at_84xxuuda_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/84xxuuda/uud0520s.bin", + 0x000e0000, 131072, 0); + + if (bios_only || !ret) + return ret; + + machine_at_common_init(model); + + pci_init(PCI_CONFIG_TYPE_1); + pci_register_slot(0x10, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); + pci_register_slot(0x12, PCI_CARD_SOUTHBRIDGE, 1, 2, 3, 4); + pci_register_slot(0x03, PCI_CARD_NORMAL, 1, 2, 3, 4); + pci_register_slot(0x04, PCI_CARD_NORMAL, 2, 3, 4, 1); + pci_register_slot(0x05, PCI_CARD_NORMAL, 3, 4, 1, 2); + + device_add(&umc_hb4_device); + device_add(&umc_8886bf_device); + device_add(&um8663bf_device); + device_add(&winbond_flash_w29c010_device); + device_add(&keyboard_ps2_ami_device); return ret; } @@ -2063,7 +2500,7 @@ machine_at_actionpc2600_init(const machine_t *model) device_add(&keyboard_ps2_tg_ami_device); if (gfxcard[0] == VID_INTERNAL) - device_add(&tgui9440_onboard_pci_device); + device_add(machine_get_vid_device(machine)); return ret; } @@ -2095,7 +2532,7 @@ machine_at_actiontower8400_init(const machine_t *model) device_add(&intel_flash_bxt_device); // The ActionPC 2600 has this so I'm gonna assume this does too. device_add(&keyboard_ps2_ami_pci_device); if (gfxcard[0] == VID_INTERNAL) - device_add(&gd5430_onboard_pci_device); + device_add(machine_get_vid_device(machine)); return ret; } @@ -2236,7 +2673,8 @@ machine_at_tg486g_init(const machine_t *model) if (bios_only || !ret) return ret; - machine_at_common_init(model); + machine_at_common_init_ex(model, 2); + device_add(&amstrad_megapc_nvr_device); device_add(&sis_85c471_device); device_add(&ide_isa_device); device_add(&fdc37c651_ide_device); @@ -2362,6 +2800,30 @@ machine_at_dataexpert386wb_init(const machine_t *model) return ret; } +int +machine_at_isa486c_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/isa486c/asus-isa-486c-401a0-040591-657e2c17a0218417632602.bin", + 0x000f0000, 65536, 0); + + if (bios_only || !ret) + return ret; + + machine_at_common_init(model); + + device_add(&isa486c_device); + device_add(&port_92_key_device); + + device_add(&keyboard_at_ami_device); + + if (fdc_current[0] == FDC_INTERNAL) + device_add(&fdc_at_device); + + return ret; +} + int machine_at_genoa486_init(const machine_t *model) { @@ -2407,6 +2869,32 @@ machine_at_ga486l_init(const machine_t *model) return ret; } +int +machine_at_cobalt_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/cobalt/Cobalt_2.3.BIN", + 0x000e0000, 131072, 0); + + if (bios_only || !ret) + return ret; + + machine_at_common_init(model); + + device_add(&opti499_device); + device_add(&ide_opti611_vlb_device); + device_add(&ide_isa_sec_device); + device_add(&fdc37c665_device); + + device_add(&keyboard_ps2_ami_device); + + if (gfxcard[0] == VID_INTERNAL) + device_add(machine_get_vid_device(machine)); + + return ret; +} + int machine_at_cougar_init(const machine_t *model) { diff --git a/src/machine/m_at_commodore.c b/src/machine/m_at_commodore.c index 0b45fe60c..b9615c064 100644 --- a/src/machine/m_at_commodore.c +++ b/src/machine/m_at_commodore.c @@ -64,13 +64,13 @@ cbm_io_write(UNUSED(uint16_t port), uint8_t val, UNUSED(void *priv)) switch (val & 3) { case 1: - lpt1_init(LPT_MDA_ADDR); + lpt1_setup(LPT_MDA_ADDR); break; case 2: - lpt1_init(LPT1_ADDR); + lpt1_setup(LPT1_ADDR); break; case 3: - lpt1_init(LPT2_ADDR); + lpt1_setup(LPT2_ADDR); break; default: diff --git a/src/machine/m_at_compaq.c b/src/machine/m_at_compaq.c index 0ac541e90..2fbfed0ff 100644 --- a/src/machine/m_at_compaq.c +++ b/src/machine/m_at_compaq.c @@ -44,9 +44,6 @@ #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, @@ -55,670 +52,11 @@ enum { COMPAQ_DESKPRO386_05_1988 }; -#define CGA_RGB 0 -#define CGA_COMPOSITE 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; -static uint32_t black; -static uint32_t blinkcols[256][2]; -static uint32_t normcols[256][2]; - -/* Video options set by the motherboard; they will be picked up by the card - * on the next poll. - * - * Bit 3: Disable built-in video (for add-on card) - * Bit 2: Thin font - * Bits 0,1: Font set (not currently implemented) - */ -static int8_t cpq_st_display_internal = -1; - -static uint8_t mdaattr[256][2][2]; - -static void -compaq_plasma_display_set(uint8_t internal) -{ - cpq_st_display_internal = internal; -} - -static uint8_t -compaq_plasma_display_get(void) -{ - return cpq_st_display_internal; -} - -typedef struct compaq_plasma_t { - cga_t cga; - uint8_t port_23c6; - uint8_t internal_monitor; - uint8_t attrmap; -} compaq_plasma_t; - static int compaq_machine_type = 0; /* Compaq Deskpro 386 remaps RAM from 0xA0000-0xFFFFF to 0xFA0000-0xFFFFFF */ static mem_mapping_t ram_mapping; -static void compaq_plasma_recalcattrs(compaq_plasma_t *self); - -static void -compaq_plasma_recalctimings(compaq_plasma_t *self) -{ - double _dispontime; - double _dispofftime; - double disptime; - - if (!self->internal_monitor && !(self->port_23c6 & 1)) { - cga_recalctimings(&self->cga); - return; - } - - disptime = 651; - _dispontime = 640; - _dispofftime = disptime - _dispontime; - 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 -compaq_plasma_write(uint32_t addr, uint8_t val, void *priv) -{ - compaq_plasma_t *self = (compaq_plasma_t *) priv; - - self->cga.vram[addr & 0x7fff] = val; - compaq_plasma_waitstates(&self->cga); -} - -static uint8_t -compaq_plasma_read(uint32_t addr, void *priv) -{ - compaq_plasma_t *self = (compaq_plasma_t *) priv; - uint8_t ret; - - compaq_plasma_waitstates(&self->cga); - ret = (self->cga.vram[addr & 0x7fff]); - - return ret; -} - -static void -compaq_plasma_out(uint16_t addr, uint8_t val, void *priv) -{ - compaq_plasma_t *self = (compaq_plasma_t *) priv; - uint8_t old; - - switch (addr) { - /* Emulated CRTC, register select */ - case 0x3d4: - cga_out(addr, val, &self->cga); - break; - - /* Emulated CRTC, value */ - case 0x3d5: - old = self->cga.crtc[self->cga.crtcreg]; - self->cga.crtc[self->cga.crtcreg] = val & cga_crtcmask[self->cga.crtcreg]; - - /* Register 0x12 controls the attribute mappings for the - * plasma screen. */ - if (self->cga.crtcreg == 0x12) { - self->attrmap = val; - compaq_plasma_recalcattrs(self); - break; - } - - if (old != val) { - if (self->cga.crtcreg < 0xe || self->cga.crtcreg > 0x10) { - self->cga.fullchange = changeframecount; - compaq_plasma_recalctimings(self); - } - } - break; - case 0x3d8: - case 0x3d9: - cga_out(addr, val, &self->cga); - break; - - case 0x13c6: - 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->cga.mapping); - else - mem_mapping_enable(&self->cga.mapping); - break; - - default: - break; - } -} - -static uint8_t -compaq_plasma_in(uint16_t addr, void *priv) -{ - compaq_plasma_t *self = (compaq_plasma_t *) priv; - uint8_t ret = 0xff; - - switch (addr) { - case 0x3d4: - case 0x3da: - ret = cga_in(addr, &self->cga); - break; - - case 0x3d5: - if (self->cga.crtcreg == 0x12) { - ret = self->attrmap & 0x0f; - if (self->internal_monitor) - ret |= 0x30; /* Plasma / CRT */ - } else - ret = cga_in(addr, &self->cga); - break; - - case 0x13c6: - 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 = 0; - break; - - default: - break; - } - - return ret; -} - -static void -compaq_plasma_poll(void *priv) -{ - 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 dat; - 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)) { - 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; - } - - /* mode 40h or text mode */ - if (!self->cga.linepos) { - timer_advance_u64(&self->cga.timer, self->cga.dispofftime); - self->cga.cgastat |= 1; - 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++) { - dat = self->cga.vram[addr & 0x7FFF]; - addr++; - - for (uint8_t c = 0; c < 8; c++) { - ink = (dat & 0x80) ? fg : bg; - if (!(self->cga.cgamode & 8)) - ink = black; - (buffer32->line[self->cga.displine])[x * 8 + c] = ink; - dat <<= 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++) { - dat = self->cga.vram[addr & 0x7fff]; - addr++; - - for (uint8_t 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->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; - dat <<= 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 - 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 */ - chr = self->cga.vram[(addr + 2 * x) & 0x7FFF]; - attr = self->cga.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); - underline = ((self->port_23c6 & 0x40) && (attr & 0x1) && !(attr & 0x6)); - /* blink active */ - if (self->cga.cgamode & 0x20) { - cols[1] = blinkcols[attr][1]; - cols[0] = blinkcols[attr][0]; - /* attribute 7 active and not cursor */ - if (blink) { - /* set blinking */ - cols[1] = cols[0]; - } - } else { - /* Set intensity bit */ - cols[1] = normcols[attr][1]; - cols[0] = normcols[attr][0]; - } - /* 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[(fontdatm2[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[(fontdatm2[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++) { - chr = self->cga.vram[(addr + 2 * x) & 0x7FFF]; - attr = self->cga.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); - underline = ((self->port_23c6 & 0x40) && (attr & 0x1) && !(attr & 0x6)); - /* blink active */ - if (self->cga.cgamode & 0x20) { - cols[1] = blinkcols[attr][1]; - cols[0] = blinkcols[attr][0]; - /* attribute 7 active and not cursor */ - if (blink) { - /* set blinking */ - cols[1] = cols[0]; - } - } else { - /* Set intensity bit */ - cols[1] = normcols[attr][1]; - cols[0] = normcols[attr][0]; - } - /* 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[(fontdatm2[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[(fontdatm2[chr][sc] & (1 << (c ^ 7))) ? 1 : 0]; - } - ++ma; - } - } - } - self->cga.displine++; - /* Hardcode a fixed refresh rate and VSYNC timing */ - if (self->cga.displine == 400) { /* Start of VSYNC */ - self->cga.cgastat |= 8; - self->cga.cgadispon = 0; - } - if (self->cga.displine == 416) { /* End of VSYNC */ - self->cga.displine = 0; - self->cga.cgastat &= ~8; - self->cga.cgadispon = 1; - } - } else { - if (self->cga.cgadispon) - self->cga.cgastat &= ~1; - - timer_advance_u64(&self->cga.timer, self->cga.dispontime); - self->cga.linepos = 0; - - if (self->cga.displine == 400) { - /* Hardcode 640x400 window size */ - if ((640 != xsize) || (400 != ysize) || video_force_resize_get()) { - xsize = 640; - ysize = 400; - if (xsize < 64) - xsize = 656; - if (ysize < 32) - ysize = 200; - set_screen_size(xsize, ysize); - - if (video_force_resize_get()) - video_force_resize_set(0); - } - video_blit_memtoscreen(0, 0, xsize, ysize); - frames++; - - /* Fixed 640x400 resolution */ - video_res_x = 640; - video_res_y = 400; - - if (self->cga.cgamode & 0x02) { - if (self->cga.cgamode & 0x10) - 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) -{ - int n; - - /* val behaves as follows: - * Bit 0: Attributes 01-06, 08-0E are inverse video - * Bit 1: Attributes 01-06, 08-0E are bold - * Bit 2: Attributes 11-16, 18-1F, 21-26, 28-2F ... F1-F6, F8-FF - * are inverse video - * Bit 3: Attributes 11-16, 18-1F, 21-26, 28-2F ... F1-F6, F8-FF - * are bold */ - - /* Set up colours */ - amber = makecol(0xff, 0x7d, 0x00); - black = makecol(0x64, 0x0c, 0x00); - - /* 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; - blinkcols[n][1] = normcols[n][1] = black; - } - - /* Colours 0x11-0xFF are controlled by bits 2 and 3 of the - * passed value. Exclude x0 and x8, which are always black on - * amber. */ - for (n = 0x11; n <= 0xFF; n++) { - if ((n & 7) == 0) - continue; - if (self->attrmap & 4) { /* Inverse */ - blinkcols[n][0] = normcols[n][0] = amber; - blinkcols[n][1] = normcols[n][1] = black; - } else { /* Normal */ - blinkcols[n][0] = normcols[n][0] = black; - blinkcols[n][1] = normcols[n][1] = amber; - } - } - /* Set up the 01-0E range, controlled by bits 0 and 1 of the - * passed value. When blinking is enabled this also affects 81-8E. */ - for (n = 0x01; n <= 0x0E; n++) { - if (n == 7) - continue; - if (self->attrmap & 1) { - blinkcols[n][0] = normcols[n][0] = amber; - blinkcols[n][1] = normcols[n][1] = black; - blinkcols[n + 128][0] = amber; - blinkcols[n + 128][1] = black; - } else { - blinkcols[n][0] = normcols[n][0] = black; - blinkcols[n][1] = normcols[n][1] = amber; - blinkcols[n + 128][0] = black; - blinkcols[n + 128][1] = amber; - } - } - /* Colours 07 and 0F are always amber on black. If blinking is - * enabled so are 87 and 8F. */ - for (n = 0x07; n <= 0x0F; n += 8) { - blinkcols[n][0] = normcols[n][0] = black; - blinkcols[n][1] = normcols[n][1] = amber; - blinkcols[n + 128][0] = black; - blinkcols[n + 128][1] = amber; - } - /* When not blinking, colours 81-8F are always amber on black. */ - for (n = 0x81; n <= 0x8F; n++) { - normcols[n][0] = black; - normcols[n][1] = amber; - } - - /* Finally do the ones which are solid black. These differ between - * the normal and blinking mappings */ - for (n = 0; n <= 0xFF; n += 0x11) - normcols[n][0] = normcols[n][1] = black; - - /* In the blinking range, 00 11 22 .. 77 and 80 91 A2 .. F7 are black */ - for (n = 0; n <= 0x77; n += 0x11) { - blinkcols[n][0] = blinkcols[n][1] = black; - blinkcols[n + 128][0] = blinkcols[n + 128][1] = black; - } -} - -static void * -compaq_plasma_init(UNUSED(const device_t *info)) -{ - compaq_plasma_t *self = malloc(sizeof(compaq_plasma_t)); - memset(self, 0, sizeof(compaq_plasma_t)); - - video_inform(VIDEO_FLAG_TYPE_CGA, &timing_compaq_plasma); - if (compaq_machine_type == COMPAQ_PORTABLEIII) - loadfont_ex("roms/machines/portableiii/K Combined.bin", 11, 0x4bb2); - else - loadfont_ex("roms/machines/portableiii/P.2 Combined.bin", 11, 0x4b49); - - 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->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; - 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 *priv) -{ - compaq_plasma_t *self = (compaq_plasma_t *) priv; - - free(self->cga.vram); - free(self); -} - -static void -compaq_plasma_speed_changed(void *priv) -{ - compaq_plasma_t *self = (compaq_plasma_t *) priv; - - compaq_plasma_recalctimings(self); -} - -const device_config_t compaq_plasma_config[] = { - // clang-format off - { - .name = "rgb_type", - .description = "RGB type", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { .description = "Color", .value = 0 }, - { .description = "Green Monochrome", .value = 1 }, - { .description = "Amber Monochrome", .value = 2 }, - { .description = "Gray Monochrome", .value = 3 }, - { .description = "" } - } - }, - { .name = "", .description = "", .type = CONFIG_END } - // clang-format on -}; - -const device_t compaq_plasma_device = { - .name = "Compaq Plasma", - .internal_name = "compaq_plasma", - .flags = 0, - .local = 0, - .init = compaq_plasma_init, - .close = compaq_plasma_close, - .reset = NULL, - { .available = NULL }, - .speed_changed = compaq_plasma_speed_changed, - .force_redraw = NULL, - .config = compaq_plasma_config -}; static uint8_t read_ram(uint32_t addr, UNUSED(void *priv)) @@ -794,7 +132,8 @@ machine_at_compaq_init(const machine_t *model, int type) switch (type) { case COMPAQ_PORTABLEII: - machine_at_init(model); + machine_at_common_init(model); + device_add(&keyboard_at_compaq_device); break; case COMPAQ_PORTABLEIII: @@ -802,7 +141,9 @@ 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); + + machine_at_common_init(model); + device_add(&keyboard_at_compaq_device); break; case COMPAQ_PORTABLEIII386: diff --git a/src/machine/m_at_grid.c b/src/machine/m_at_grid.c index 2fc757129..03b7288b9 100644 --- a/src/machine/m_at_grid.c +++ b/src/machine/m_at_grid.c @@ -38,6 +38,7 @@ #include <86box/mem.h> #include <86box/rom.h> #include <86box/vid_cga.h> +#include <86box/plat_unused.h> #define GRID_APPROM_SELECT 0x440 #define GRID_APPROM_ENABLE 0x405 @@ -263,7 +264,7 @@ static uint8_t grid_io_read(uint16_t port, void *priv) { } static void * -grid_init(const device_t *info) +grid_init(UNUSED(const device_t *info)) { grid_t *dev = calloc(1, sizeof(grid_t)); @@ -324,7 +325,7 @@ const device_t grid_device = { .init = grid_init, .close = grid_close, .reset = grid_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/machine/m_at_slot1.c b/src/machine/m_at_slot1.c index 415998364..2ac805bee 100644 --- a/src/machine/m_at_slot1.c +++ b/src/machine/m_at_slot1.c @@ -40,6 +40,36 @@ #include <86box/clock.h> #include <86box/snd_ac97.h> +int +machine_at_acerv62x_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/acerv62x/v62xc0s1.bin", + 0x000c0000, 262144, 0); + + if (bios_only || !ret) + return ret; + + machine_at_common_init_ex(model, 2); + + pci_init(PCI_CONFIG_TYPE_1); + pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); + pci_register_slot(0x07, PCI_CARD_SOUTHBRIDGE, 5, 0, 0, 4); + pci_register_slot(0x12, PCI_CARD_NORMAL, 4, 1, 2, 3); + pci_register_slot(0x10, PCI_CARD_NORMAL, 3, 4, 1, 2); + pci_register_slot(0x0E, PCI_CARD_NORMAL, 1, 2, 3, 4); + pci_register_slot(0x0F, PCI_CARD_NORMAL, 2, 3, 4, 1); + pci_register_slot(0x0D, PCI_CARD_NORMAL, 2, 3, 4, 1); + device_add(&i440fx_device); + device_add(&piix3_device); + device_add_params(&fdc37c93x_device, (void *) (FDC37C935 | FDC37C93X_APM)); + device_add(&sst_flash_29ee020_device); + spd_register(SPD_TYPE_SDRAM, 0x7, 128); + + return ret; +} + int machine_at_p65up5_cpknd_init(const machine_t *model) { @@ -120,6 +150,41 @@ machine_at_lx6_init(const machine_t *model) return ret; } +int +machine_at_optiplexgxa_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/optiplexgxa/DELL.ROM", + 0x000c0000, 262144, 0); + + if (bios_only || !ret) + return ret; + + machine_at_common_init_ex(model, 2); + + pci_init(PCI_CONFIG_TYPE_1); + pci_register_slot(0x07, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 4); + pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 1, 2, 3, 4); + pci_register_slot(0x01, PCI_CARD_AGPBRIDGE, 1, 2, 3, 4); + pci_register_slot(0x11, PCI_CARD_NETWORK, 4, 0, 0, 0); + pci_register_slot(0x0E, PCI_CARD_NORMAL, 3, 4, 2, 1); + pci_register_slot(0x0D, PCI_CARD_NORMAL, 2, 1, 3, 4); + pci_register_slot(0x0F, PCI_CARD_BRIDGE, 0, 0, 0, 0); + + if (sound_card_current[0] == SOUND_INTERNAL) + device_add(machine_get_snd_device(machine)); + + device_add(&i440lx_device); + device_add(&piix4_device); + machine_at_optiplex_21152_init(); + device_add_params(&pc87307_device, (void *) (PCX730X_PHOENIX_42 | PCX7307_PC87307)); + device_add(&intel_flash_bxt_device); + spd_register(SPD_TYPE_SDRAM, 0x7, 256); + + return ret; +} + int machine_at_spitfire_init(const machine_t *model) { @@ -131,7 +196,7 @@ machine_at_spitfire_init(const machine_t *model) if (bios_only || !ret) return ret; - machine_at_common_init_ex(model, 2); + machine_at_common_init(model); pci_init(PCI_CONFIG_TYPE_1); pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); @@ -143,7 +208,7 @@ machine_at_spitfire_init(const machine_t *model) pci_register_slot(0x01, PCI_CARD_AGPBRIDGE, 1, 2, 3, 4); device_add(&i440lx_device); device_add(&piix4e_device); - device_add(&fdc37c935_no_nvr_device); + device_add_params(&fdc37c93x_device, (void *) (FDC37C935 | FDC37C93X_NORMAL | FDC37C93X_NO_NVR)); device_add(&intel_flash_bxt_device); spd_register(SPD_TYPE_SDRAM, 0xF, 256); device_add(&lm78_device); /* no reporting in BIOS */ @@ -359,6 +424,37 @@ machine_at_bf6_init(const machine_t *model) return ret; } +int +machine_at_bx6_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/bx6/BX6_EG.BIN", + 0x000e0000, 131072, 0); + + if (bios_only || !ret) + return ret; + + machine_at_common_init_ex(model, 2); + + pci_init(PCI_CONFIG_TYPE_1); + pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); + pci_register_slot(0x07, PCI_CARD_SOUTHBRIDGE, 1, 2, 3, 4); + pci_register_slot(0x09, PCI_CARD_NORMAL, 4, 1, 2, 3); + pci_register_slot(0x0B, PCI_CARD_NORMAL, 3, 4, 1, 2); + pci_register_slot(0x0D, PCI_CARD_NORMAL, 2, 3, 4, 1); + pci_register_slot(0x0F, PCI_CARD_NORMAL, 1, 2, 3, 4); + pci_register_slot(0x01, PCI_CARD_AGPBRIDGE, 1, 2, 3, 4); + device_add(&i440bx_device); + device_add(&piix4e_device); + device_add(&keyboard_ps2_pci_device); + device_add(&w83977f_device); + device_add(&sst_flash_29ee010_device); + spd_register(SPD_TYPE_SDRAM, 0xF, 256); + + return ret; +} + int machine_at_ax6bc_init(const machine_t *model) { @@ -523,8 +619,7 @@ machine_at_s1846_init(const machine_t *model) pci_register_slot(0x01, PCI_CARD_AGPBRIDGE, 1, 2, 3, 4); device_add(&i440bx_device); device_add(&piix4e_device); - device_add(&pc87309_device); - device_add(&keyboard_ps2_ami_pci_device); + device_add_params(&pc87309_device, (void *) (PCX730X_AMI | PC87309_PC87309)); device_add(&intel_flash_bxt_device); spd_register(SPD_TYPE_SDRAM, 0x7, 256); diff --git a/src/machine/m_at_slot2.c b/src/machine/m_at_slot2.c index da160c138..7bf412823 100644 --- a/src/machine/m_at_slot2.c +++ b/src/machine/m_at_slot2.c @@ -140,8 +140,7 @@ machine_at_fw6400gx_init(const machine_t *model) device_add(&i440gx_device); device_add(&piix4e_device); - device_add(&keyboard_ps2_ami_pci_device); - device_add(&pc87309_15c_device); + device_add_params(&pc87309_device, (void *) (PCX730X_15C | PCX730X_AMI | PC87309_PC87309)); device_add(ics9xxx_get(ICS9250_08)); device_add(&sst_flash_29ee020_device); spd_register(SPD_TYPE_SDRAM, 0xF, 512); diff --git a/src/machine/m_at_socket370.c b/src/machine/m_at_socket370.c index 9be2d45b8..ff299ee50 100644 --- a/src/machine/m_at_socket370.c +++ b/src/machine/m_at_socket370.c @@ -386,7 +386,7 @@ machine_at_awo671r_init(const machine_t *model) pci_register_slot(0x0A, PCI_CARD_NORMAL, 2, 3, 4, 1); pci_register_slot(0x0B, PCI_CARD_NORMAL, 3, 4, 1, 2); pci_register_slot(0x0C, PCI_CARD_NORMAL, 4, 1, 2, 3); - pci_register_slot(0x0D, PCI_CARD_NORMAL, 2, 3, 4, 1); + pci_register_slot(0x0D, PCI_CARD_VIDEO, 2, 3, 4, 1); pci_register_slot(0x01, PCI_CARD_AGPBRIDGE, 1, 2, 3, 4); device_add(&i440bx_device); device_add(&piix4e_device); @@ -394,9 +394,8 @@ machine_at_awo671r_init(const machine_t *model) device_add_inst(&w83977ef_device, 2); device_add(&keyboard_ps2_pci_device); device_add(&sst_flash_39sf020_device); - if (gfxcard[0] == VID_INTERNAL) { - device_add(&chips_69000_onboard_device); - } + if (gfxcard[0] == VID_INTERNAL) + device_add(machine_get_vid_device(machine)); spd_register(SPD_TYPE_SDRAM, 0x3, 256); return ret; @@ -541,3 +540,31 @@ machine_at_6via90ap_init(const machine_t *model) return ret; } + +int +machine_at_7sbb_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/7sbb/sbb12aa2.bin", + 0x000c0000, 262144, 0); + + if (bios_only || !ret) + return ret; + + machine_at_common_init_ex(model, 2); + + pci_init(PCI_CONFIG_TYPE_1 | FLAG_TRC_CONTROLS_CPURST); + pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); + pci_register_slot(0x01, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0); + pci_register_slot(0x0F, PCI_CARD_NORMAL, 1, 2, 3, 4); + pci_register_slot(0x10, PCI_CARD_NORMAL, 2, 3, 4, 1); + pci_register_slot(0x11, PCI_CARD_NORMAL, 3, 4, 1, 2); + pci_register_slot(0x02, PCI_CARD_AGPBRIDGE, 1, 2, 3, 4); + device_add(&sis_5600_device); + device_add(&keyboard_ps2_ami_pci_device); + device_add(&it8661f_device); + device_add(&sst_flash_29ee020_device); /* assumed */ + + return ret; +} diff --git a/src/machine/m_at_socket4.c b/src/machine/m_at_socket4.c index c3213f1ac..2d4e1a51a 100644 --- a/src/machine/m_at_socket4.c +++ b/src/machine/m_at_socket4.c @@ -44,8 +44,10 @@ void machine_at_premiere_common_init(const machine_t *model, int pci_switch) { - machine_at_common_init(model); - device_add(&ide_pci_device); + machine_at_common_init_ex(model, 2); + + device_add(&amstrad_megapc_nvr_device); + device_add(&ide_pci_2ch_device); pci_init(PCI_CONFIG_TYPE_2 | pci_switch); pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); @@ -54,9 +56,10 @@ machine_at_premiere_common_init(const machine_t *model, int pci_switch) pci_register_slot(0x0E, PCI_CARD_NORMAL, 2, 1, 3, 4); pci_register_slot(0x0C, PCI_CARD_NORMAL, 1, 3, 2, 4); pci_register_slot(0x02, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0); - device_add(&keyboard_ps2_intel_ami_pci_device); + device_add(&keyboard_ps2_phoenix_device); device_add(&sio_zb_device); - device_add(&fdc37c665_device); + device_add(&ide_rz1000_pci_single_channel_device); + device_add(&fdc37c665_ide_sec_device); device_add(&intel_flash_bxt_ami_device); } @@ -154,7 +157,9 @@ machine_at_dellxp60_init(const machine_t *model) if (bios_only || !ret) return ret; - machine_at_common_init(model); + machine_at_common_init_ex(model, 2); + + device_add(&amstrad_megapc_nvr_device); device_add(&ide_pci_device); pci_init(PCI_CONFIG_TYPE_2); @@ -167,7 +172,7 @@ machine_at_dellxp60_init(const machine_t *model) pci_register_slot(0x06, PCI_CARD_NORMAL, 2, 1, 3, 4); pci_register_slot(0x02, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0); device_add(&i430lx_device); - device_add(&keyboard_ps2_intel_ami_pci_device); + device_add(&keyboard_ps2_phoenix_device); device_add(&sio_zb_device); device_add(&fdc37c665_device); device_add(&intel_flash_bxt_ami_device); @@ -186,8 +191,10 @@ machine_at_opti560l_init(const machine_t *model) if (bios_only || !ret) return ret; - machine_at_common_init(model); - device_add(&ide_pci_2ch_device); + machine_at_common_init_ex(model, 2); + + device_add(&amstrad_megapc_nvr_device); + device_add(&ide_pci_device); pci_init(PCI_CONFIG_TYPE_2); pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); @@ -196,7 +203,7 @@ machine_at_opti560l_init(const machine_t *model) pci_register_slot(0x08, PCI_CARD_NORMAL, 2, 1, 3, 4); pci_register_slot(0x02, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0); device_add(&i430lx_device); - device_add(&keyboard_ps2_intel_ami_pci_device); + device_add(&keyboard_ps2_phoenix_device); device_add(&sio_zb_device); device_add(&i82091aa_device); device_add(&intel_flash_bxt_ami_device); @@ -216,7 +223,22 @@ machine_at_ambradp60_init(const machine_t *model) if (bios_only || !ret) return ret; - machine_at_premiere_common_init(model, 0); + machine_at_common_init_ex(model, 2); + + device_add(&amstrad_megapc_nvr_device); + device_add(&ide_pci_device); + + pci_init(PCI_CONFIG_TYPE_2); + pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); + pci_register_slot(0x01, PCI_CARD_IDE, 0, 0, 0, 0); + pci_register_slot(0x06, PCI_CARD_NORMAL, 3, 2, 1, 4); + pci_register_slot(0x0E, PCI_CARD_NORMAL, 2, 1, 3, 4); + pci_register_slot(0x0C, PCI_CARD_NORMAL, 1, 3, 2, 4); + pci_register_slot(0x02, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0); + device_add(&keyboard_ps2_phoenix_device); + device_add(&sio_zb_device); + device_add(&fdc37c665_ide_pri_device); + device_add(&intel_flash_bxt_ami_device); device_add(&i430lx_device); @@ -236,7 +258,7 @@ machine_at_valuepointp60_init(const machine_t *model) return ret; machine_at_common_init(model); - device_add(&ide_pci_2ch_device); + device_add(&ide_pci_device); pci_init(PCI_CONFIG_TYPE_2 | PCI_NO_IRQ_STEERING); pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); @@ -248,7 +270,7 @@ machine_at_valuepointp60_init(const machine_t *model) pci_register_slot(0x02, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0); device_add(&keyboard_ps2_ps1_pci_device); device_add(&sio_device); - device_add(&fdc37c665_device); + device_add(&fdc37c665_ide_device); device_add(&intel_flash_bxt_ami_device); device_add(&i430lx_device); @@ -384,6 +406,37 @@ machine_at_m5pi_init(const machine_t *model) return ret; } +int +machine_at_globalyst330_p5_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/globalyst330_p5/MiTAC_PB5500C_v1.02_120794_ATT.BIN", + 0x000e0000, 131072, 0); + + if (bios_only || !ret) + return ret; + + machine_at_common_init(model); + + pci_init(PCI_CONFIG_TYPE_1); + pci_register_slot(0x10, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); + pci_register_slot(0x11, PCI_CARD_NORMAL, 1, 2, 3, 4); + pci_register_slot(0x12, PCI_CARD_NORMAL, 5, 6, 7, 8); + pci_register_slot(0x13, PCI_CARD_NORMAL, 9, 10, 11, 12); + pci_register_slot(0x14, PCI_CARD_NORMAL, 13, 14, 15, 16); + + device_add(&opti5x7_pci_device); + device_add(&opti822_device); + device_add(&sst_flash_29ee010_device); + device_add(&keyboard_at_ami_device); + + if (fdc_current[0] == FDC_INTERNAL) + device_add(&fdc_at_device); + + return ret; +} + int machine_at_excalibur_init(const machine_t *model) { diff --git a/src/machine/m_at_socket5.c b/src/machine/m_at_socket5.c index b6e82301b..b2d3c46f3 100644 --- a/src/machine/m_at_socket5.c +++ b/src/machine/m_at_socket5.c @@ -29,6 +29,7 @@ #include <86box/fdc_ext.h> #include <86box/hdc.h> #include <86box/hdc_ide.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/fdd.h> #include <86box/fdc.h> @@ -39,6 +40,7 @@ #include <86box/sio.h> #include <86box/video.h> #include <86box/machine.h> +#include <86box/sound.h> int machine_at_plato_init(const machine_t *model) @@ -78,6 +80,86 @@ machine_at_dellplato_init(const machine_t *model) return ret; } +int +machine_at_d842_init(const machine_t *model) + +{ + int ret = 0; + const char* fn; + + /* No ROMs available */ + if (!device_available(model->device)) + return ret; + + device_context(model->device); + fn = device_get_bios_file(machine_get_device(machine), device_get_config_bios("bios_versions"), 0); + ret = bios_load_linear(fn, 0x000e0000, 131072, 0); + device_context_restore(); + + machine_at_common_init(model); + + device_add(&ide_pci_2ch_device); + pci_init(PCI_CONFIG_TYPE_2 | PCI_NO_IRQ_STEERING); + pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); + pci_register_slot(0x01, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0); /* Onboard */ + pci_register_slot(0x03, PCI_CARD_VIDEO, 4, 0, 0, 0); /* Onboard */ + pci_register_slot(0x0C, PCI_CARD_NORMAL, 1, 3, 2, 4); /* Slot 01 */ + pci_register_slot(0x0E, PCI_CARD_NORMAL, 2, 1, 3, 4); /* Slot 02 */ + + device_add(&keyboard_ps2_pci_device); + device_add(&i430nx_device); + device_add(&sio_zb_device); + device_add(&fdc37c665_device); + device_add(&intel_flash_bxt_device); + + return ret; +} + +static const device_config_t d842_config[] = { + // clang-format off + { + .name = "bios_versions", + .description = "BIOS Versions", + .type = CONFIG_BIOS, + .default_string = "d842", + .default_int = 0, + .file_filter = "", + .spinner = { 0 }, /*W1*/ + .bios = { + { .name = "Version 1.03 Revision 1.03.842 (11/24/1994)", .internal_name = "d842", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/d842/d842.BIN", "" } }, + { .name = "Version 4.04 Revision 1.05.842 (03/15/1996)", .internal_name = "d842_mar96", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/d842/d842_mar96.bin", "" } }, + { .name = "Version 4.04 Revision 1.06.842 (04/03/1998)", .internal_name = "d842_apr98", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/d842/d842_apr98.bin", "" } }, + { .name = "Version 4.04 Revision 1.07.842 (06/02/1998)", .internal_name = "d842_jun98", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/d842/d842_jun98.BIN", "" } }, + { .name = "Version 1.03 Revision 1.09.842 (07/08/1996)", .internal_name = "d842_jul96", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/d842/d842_jul96.bin", "" } }, + { .name = "Version 1.03 Revision 1.10.842 (06/04/1998)", .internal_name = "d842_jun98_1", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/d842/d842_jun98_1.bin", "" } }, + }, + }, + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on +}; + + + +const device_t d842_device = { + .name = "Siemens-Nixdorf D842", + .internal_name = "d842", + .flags = 0, + .local = 0, + .init = NULL, + .close = NULL, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = &d842_config[0] +}; + int machine_at_ambradp90_init(const machine_t *model) { @@ -109,19 +191,19 @@ machine_at_p54np4_init(const machine_t *model) return ret; machine_at_common_init(model); + device_add(&ide_vlb_2ch_device); - pci_init(PCI_CONFIG_TYPE_2 | PCI_NO_IRQ_STEERING); + pci_init(PCI_CONFIG_TYPE_2 | PCI_CAN_SWITCH_TYPE); pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); - pci_register_slot(0x03, PCI_CARD_NORMAL, 1, 2, 3, 4); /* 03 = Slot 1 */ - pci_register_slot(0x04, PCI_CARD_NORMAL, 2, 3, 4, 1); /* 04 = Slot 2 */ - pci_register_slot(0x05, PCI_CARD_NORMAL, 3, 4, 1, 2); /* 05 = Slot 3 */ - pci_register_slot(0x06, PCI_CARD_NORMAL, 4, 1, 2, 3); /* 06 = Slot 4 */ - pci_register_slot(0x07, PCI_CARD_SCSI, 1, 2, 3, 4); /* 07 = SCSI */ + pci_register_slot(0x06, PCI_CARD_NORMAL, 1, 2, 3, 4); /* 06 = Slot 1 */ + pci_register_slot(0x05, PCI_CARD_NORMAL, 2, 3, 4, 1); /* 05 = Slot 2 */ + pci_register_slot(0x04, PCI_CARD_NORMAL, 3, 4, 1, 2); /* 04 = Slot 3 */ + pci_register_slot(0x03, PCI_CARD_NORMAL, 4, 1, 2, 3); /* 03 = Slot 4 */ pci_register_slot(0x02, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0); device_add(&i430nx_device); + device_add(&sio_zb_device); device_add(&keyboard_ps2_ami_pci_device); device_add(&fdc37c665_ide_pri_device); - device_add(&ncr53c810_onboard_pci_device); device_add(&intel_flash_bxt_device); return ret; @@ -168,8 +250,8 @@ machine_at_tek932_init(const machine_t *model) device_add(&keyboard_ps2_intel_ami_pci_device); device_add(&i430nx_device); device_add(&sio_zb_device); - device_add(&fdc37c665_ide_device); device_add(&ide_vlb_device); + device_add(&fdc37c665_ide_pri_device); device_add(&intel_flash_bxt_ami_device); return ret; @@ -235,6 +317,43 @@ machine_at_apollo_init(const machine_t *model) return ret; } +int +machine_at_optiplexgxl_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/optiplexgxl/DELL.ROM", + 0x000e0000, 131072, 0); + + if (bios_only || !ret) + return ret; + + machine_at_common_init_ex(model, 2); + device_add(&amstrad_megapc_nvr_device); + + pci_init(PCI_CONFIG_TYPE_1); + pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 1, 2, 3, 4); + pci_register_slot(0x0C, PCI_CARD_NORMAL, 1, 2, 3, 4); + pci_register_slot(0x0D, PCI_CARD_NORMAL, 3, 4, 2, 1); + pci_register_slot(0x10, PCI_CARD_VIDEO, 0, 0, 0, 0); + pci_register_slot(0x07, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0); + + if (gfxcard[0] == VID_INTERNAL) + device_add(machine_get_vid_device(machine)); + + if (sound_card_current[0] == SOUND_INTERNAL) + machine_snd = device_add(machine_get_snd_device(machine)); + + device_add(&keyboard_ps2_phoenix_pci_device); + device_add(&i430fx_device); + device_add(&piix_device); + device_add(&pc87332_device); + device_add(&dell_jumper_device); + device_add(&intel_flash_bxt_device); + + return ret; +} + static void machine_at_zappa_gpio_init(void) { @@ -355,6 +474,7 @@ machine_at_hawk_init(const machine_t *model) return ret; } + int machine_at_pt2000_init(const machine_t *model) { diff --git a/src/machine/m_at_socket7.c b/src/machine/m_at_socket7.c index f80d2d421..46c7b7623 100644 --- a/src/machine/m_at_socket7.c +++ b/src/machine/m_at_socket7.c @@ -24,7 +24,6 @@ #include <86box/mem.h> #include <86box/io.h> #include <86box/rom.h> -#include <86box/pci.h> #include <86box/device.h> #include <86box/chipset.h> #include <86box/hdc.h> @@ -45,6 +44,16 @@ #include <86box/scsi_ncr53c8xx.h> #include <86box/thread.h> #include <86box/network.h> +#include <86box/pci.h> + +void +machine_at_optiplex_21152_init(void) +{ + uint8_t bus_index = pci_bridge_get_bus_index(device_add(&dec21152_device)); + pci_register_bus_slot(bus_index, 0x09, PCI_CARD_NORMAL, 1, 2, 3, 4); + pci_register_bus_slot(bus_index, 0x0a, PCI_CARD_NORMAL, 4, 2, 1, 3); + pci_register_bus_slot(bus_index, 0x0b, PCI_CARD_NORMAL, 1, 3, 4, 2); +} int machine_at_acerv35n_init(const machine_t *model) @@ -58,10 +67,6 @@ machine_at_acerv35n_init(const machine_t *model) return ret; machine_at_common_init_ex(model, 2); - /* Yes, it's called amstrad_mega_pc_nvr_device, but it's basically the - standard AT NVR, just initialized to 0x00's (perhaps that should be the - default behavior?). */ - device_add(&amstrad_megapc_nvr_device); pci_init(PCI_CONFIG_TYPE_1); pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); @@ -73,7 +78,8 @@ machine_at_acerv35n_init(const machine_t *model) pci_register_slot(0x0D, PCI_CARD_NORMAL, 1, 2, 3, 4); device_add(&i430hx_device); device_add(&piix3_device); - device_add(&fdc37c932fr_device); + /* The chip is not marked FR but the BIOS accesses register 06h of GPIO. */ + device_add_params(&fdc37c93x_device, (void *) (FDC37C935 | FDC37C93X_FR)); device_add(&sst_flash_29ee010_device); return ret; @@ -164,7 +170,7 @@ machine_at_m7shi_init(const machine_t *model) pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); device_add(&i430hx_device); device_add(&piix3_device); - device_add(&fdc37c935_device); + device_add_params(&fdc37c93x_device, (void *) (FDC37C935 | FDC37C93X_NORMAL)); device_add(&intel_flash_bxt_device); return ret; @@ -572,7 +578,7 @@ machine_at_presario2240_init(const machine_t *model) device_add(&i430vx_device); device_add(&piix3_device); - device_add(&fdc37c932qf_device); + device_add_params(&fdc37c93x_device, (void *) (FDC37C932 | FDC37C93X_NORMAL)); device_add(&sst_flash_29ee020_device); return ret; @@ -602,7 +608,7 @@ machine_at_presario4500_init(const machine_t *model) device_add(&i430vx_device); device_add(&piix3_device); - device_add(&fdc37c931apm_compaq_device); + device_add_params(&fdc37c93x_device, (void *) (FDC37C931 | FDC37C93X_APM)); device_add(&sst_flash_29ee020_device); return ret; @@ -635,7 +641,7 @@ machine_at_dellhannibalp_init(const machine_t *model) pci_register_slot(0x07, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 4); device_add(&i430vx_device); device_add(&piix3_device); - device_add(&fdc37c932fr_device); + device_add_params(&fdc37c93x_device, (void *) (FDC37C932 | FDC37C93X_FR)); device_add(&intel_flash_bxt_ami_device); return ret; @@ -663,7 +669,7 @@ machine_at_p55va_init(const machine_t *model) pci_register_slot(0x07, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0); device_add(&i430vx_device); device_add(&piix3_device); - device_add(&fdc37c932fr_device); + device_add_params(&fdc37c93x_device, (void *) (FDC37C932 | FDC37C93X_FR)); device_add(&intel_flash_bxt_device); return ret; @@ -691,7 +697,7 @@ machine_at_brio80xx_init(const machine_t *model) pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); device_add(&i430vx_device); device_add(&piix3_device); - device_add(&fdc37c935_370_device); + device_add_params(&fdc37c93x_device, (void *) (FDC37C935 | FDC37C93X_NORMAL | FDC37C93X_370)); device_add(&sst_flash_29ee020_device); return ret; @@ -760,7 +766,7 @@ machine_at_pb810_init(const machine_t *model) device_add(&i430vx_device); device_add(&piix3_device); - device_add(&fdc37c935_370_device); + device_add_params(&fdc37c93x_device, (void *) (FDC37C935 | FDC37C93X_NORMAL | FDC37C93X_370)); device_add(&intel_flash_bxt_device); return ret; @@ -849,9 +855,13 @@ machine_at_gw2kte_init(const machine_t *model) pci_register_slot(0x0F, PCI_CARD_NORMAL, 3, 4, 1, 2); pci_register_slot(0x10, PCI_CARD_NORMAL, 4, 1, 2, 3); pci_register_slot(0x07, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 4); + + if ((sound_card_current[0] == SOUND_INTERNAL) && machine_get_snd_device(machine)->available()) + machine_snd = device_add(machine_get_snd_device(machine)); + device_add(&i430vx_device); device_add(&piix3_device); - device_add(&fdc37c932fr_device); + device_add_params(&fdc37c93x_device, (void *) (FDC37C932 | FDC37C93X_FR)); device_add(&intel_flash_bxt_ami_device); return ret; @@ -968,27 +978,55 @@ machine_at_tx97_init(const machine_t *model) return ret; } -#ifdef USE_AN430TX +int +machine_at_optiplexgn_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/optiplexgn/DELL.ROM", + 0x000c0000, 262144, 0); + + if (bios_only || !ret) + return ret; + + machine_at_common_init_ex(model, 2); + + pci_init(PCI_CONFIG_TYPE_1); + pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 1, 2, 3, 4); + pci_register_slot(0x0E, PCI_CARD_NORMAL, 3, 4, 2, 1); + pci_register_slot(0x0D, PCI_CARD_NORMAL, 2, 1, 3, 4); + pci_register_slot(0x10, PCI_CARD_VIDEO, 4, 0, 0, 0); /* Trio64V2/GX, temporarily Trio64V2/DX is given */ + pci_register_slot(0x11, PCI_CARD_NETWORK, 4, 0, 0, 0); /* 3C905, not yet emulated */ + pci_register_slot(0x07, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 4); + pci_register_slot(0x0F, PCI_CARD_BRIDGE, 0, 0, 0, 0); + + if (gfxcard[0] == VID_INTERNAL) + device_add(machine_get_vid_device(machine)); + + if ((sound_card_current[0] == SOUND_INTERNAL) && machine_get_snd_device(machine)->available()) + machine_snd = device_add(machine_get_snd_device(machine)); + + device_add(&i430tx_device); + device_add(&piix4_device); + machine_at_optiplex_21152_init(); + device_add_params(&pc87307_device, (void *) (PCX730X_PHOENIX_42 | PCX7307_PC87307)); + device_add(&intel_flash_bxt_device); + spd_register(SPD_TYPE_SDRAM, 0x3, 128); + + return ret; +} + int machine_at_an430tx_init(const machine_t *model) { int ret; -# if 1 - ret = bios_load_linear_combined2("roms/machines/an430tx/P10-0095.BIO", - "roms/machines/an430tx/P10-0095.BI1", - "roms/machines/an430tx/P10-0095.BI2", - "roms/machines/an430tx/P10-0095.BI3", - "roms/machines/an430tx/P10-0095.RCV", + ret = bios_load_linear_combined2("roms/machines/an430tx/ANP0911A.BIO", + "roms/machines/an430tx/ANP0911A.BI1", + "roms/machines/an430tx/ANP0911A.BI2", + "roms/machines/an430tx/ANP0911A.BI3", + "roms/machines/an430tx/ANP0911A.RCV", 0x3a000, 160); -# else - ret = bios_load_linear_combined2("roms/machines/an430tx/P06-0062.BIO", - "roms/machines/an430tx/P06-0062.BI1", - "roms/machines/an430tx/P06-0062.BI2", - "roms/machines/an430tx/P06-0062.BI3", - "roms/machines/an430tx/P10-0095.RCV", - 0x3a000, 160); -# endif if (bios_only || !ret) return ret; @@ -997,22 +1035,25 @@ machine_at_an430tx_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(0x07, PCI_CARD_SOUTHBRIDGE, 1, 2, 3, 4); /* PIIX4 */ - // pci_register_slot(0x08, PCI_CARD_VIDEO, 4, 0, 0, 0); + pci_register_slot(0x07, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 4); /* PIIX4 */ pci_register_slot(0x0D, PCI_CARD_NORMAL, 1, 2, 3, 4); pci_register_slot(0x0E, PCI_CARD_NORMAL, 2, 3, 4, 1); pci_register_slot(0x0F, PCI_CARD_NORMAL, 3, 4, 1, 2); pci_register_slot(0x10, PCI_CARD_NORMAL, 4, 1, 2, 3); + pci_register_slot(0x08, PCI_CARD_VIDEO, 4, 0, 0, 0); device_add(&i430tx_device); device_add(&piix4_device); - device_add(&keyboard_ps2_ami_pci_device); - device_add(&pc87307_both_device); +#ifdef FOLLOW_THE_SPECIFICATION + device_add_params(&pc87307_device, (void *) (PCX730X_PHOENIX_42I | PCX7307_PC97307)); +#else + /* The technical specification says Phoenix, a real machnine HWINFO dump says AMI '5'. */ + device_add_params(&pc87307_device, (void *) (PCX730X_AMI | PCX7307_PC97307)); +#endif device_add(&intel_flash_bxt_ami_device); spd_register(SPD_TYPE_SDRAM, 0x3, 128); return ret; } -#endif /* USE_AN430TX */ int machine_at_ym430tx_init(const machine_t *model) @@ -1275,6 +1316,38 @@ machine_at_ficpa2012_init(const machine_t *model) return ret; } +int +machine_at_via809ds_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/via809ds/v30422sg.rom", + 0x000e0000, 131072, 0); + + if (bios_only || !ret) + return ret; + + machine_at_common_init_ex(model, 2); + + pci_init(PCI_CONFIG_TYPE_1); + pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); + pci_register_slot(0x07, PCI_CARD_SOUTHBRIDGE, 1, 2, 3, 4); + pci_register_slot(0x08, PCI_CARD_NORMAL, 1, 2, 3, 4); + pci_register_slot(0x09, PCI_CARD_NORMAL, 2, 3, 4, 1); + pci_register_slot(0x0A, PCI_CARD_NORMAL, 3, 4, 1, 2); + pci_register_slot(0x0B, PCI_CARD_NORMAL, 4, 1, 2, 3); /* assumed */ + pci_register_slot(0x01, PCI_CARD_AGPBRIDGE, 1, 2, 3, 4); + + device_add(&via_vp3_device); + device_add(&via_vt82c586b_device); + device_add(&keyboard_ps2_ami_pci_device); + device_add(&fdc37c669_device); + device_add(&intel_flash_bxt_device); + spd_register(SPD_TYPE_SDRAM, 0x7, 512); + + return ret; +} + int machine_at_r534f_init(const machine_t *model) { @@ -1521,7 +1594,7 @@ machine_at_thunderbolt_init(const machine_t *model) if (bios_only || !ret) return ret; - machine_at_common_init_ex(model, 2); + machine_at_common_init(model); pci_init(PCI_CONFIG_TYPE_1); pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); @@ -1532,7 +1605,7 @@ machine_at_thunderbolt_init(const machine_t *model) pci_register_slot(0x14, PCI_CARD_NORMAL, 3, 0, 1, 2); device_add(&i430tx_device); device_add(&piix4_device); - device_add(&fdc37c935_device); + device_add_params(&fdc37c93x_device, (void *) (FDC37C935 | FDC37C93X_NORMAL | FDC37C93X_NO_NVR)); device_add(&intel_flash_bxt_device); spd_register(SPD_TYPE_SDRAM, 0x3, 128); diff --git a/src/machine/m_at_socket7_3v.c b/src/machine/m_at_socket7_3v.c index 40ae221a0..7d29a6f3a 100644 --- a/src/machine/m_at_socket7_3v.c +++ b/src/machine/m_at_socket7_3v.c @@ -455,7 +455,7 @@ machine_at_pb640_init(const machine_t *model) device_add(&piix_rev02_device); if (gfxcard[0] == VID_INTERNAL) - device_add(&gd5440_onboard_pci_device); + device_add(machine_get_vid_device(machine)); device_add(&keyboard_ps2_intel_ami_pci_device); device_add(&pc87306_device); @@ -546,7 +546,7 @@ machine_at_acerm3a_init(const machine_t *model) pci_register_slot(0x10, PCI_CARD_VIDEO, 4, 0, 0, 0); device_add(&i430hx_device); device_add(&piix3_device); - device_add(&fdc37c935_device); + device_add_params(&fdc37c93x_device, (void *) (FDC37C935 | FDC37C93X_NORMAL)); device_add(&sst_flash_29ee010_device); @@ -612,6 +612,89 @@ machine_at_8500tuc_init(const machine_t *model) return ret; } +int +machine_at_d943_init(const machine_t *model) + +{ + int ret = 0; + const char* fn; + + /* No ROMs available */ + if (!device_available(model->device)) + return ret; + + device_context(model->device); + fn = device_get_bios_file(machine_get_device(machine), device_get_config_bios("bios_versions"), 0); + ret = bios_load_linear(fn, 0x000e0000, 131072, 0); + device_context_restore(); + + machine_at_common_init_ex(model, 2); + device_add(&amstrad_megapc_nvr_device); + + pci_init(PCI_CONFIG_TYPE_1); + pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); + pci_register_slot(0x07, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0); + pci_register_slot(0x08, PCI_CARD_VIDEO, 4, 0, 0, 0); + pci_register_slot(0x11, PCI_CARD_NORMAL, 3, 2, 4, 1); + pci_register_slot(0x12, PCI_CARD_NORMAL, 2, 1, 3, 4); + pci_register_slot(0x13, PCI_CARD_NORMAL, 1, 3, 2, 4); + device_add(&i430hx_device); + device_add(&piix3_device); + device_add(&keyboard_ps2_pci_device); + device_add(&fdc37c665_device); + device_add(&intel_flash_bxt_device); + spd_register(SPD_TYPE_EDO, 0x7, 256); + + if (gfxcard[0] == VID_INTERNAL) + device_add(machine_get_vid_device(machine)); + + if (sound_card_current[0] == SOUND_INTERNAL) + machine_snd = device_add(machine_get_snd_device(machine)); + + return ret; +} + +static const device_config_t d943_config[] = { + // clang-format off + { + .name = "bios_versions", + .description = "BIOS Versions", + .type = CONFIG_BIOS, + .default_string = "d943_oct96", + .default_int = 0, + .file_filter = "", + .spinner = { 0 }, /*W1*/ + .bios = { + { .name = "Version 4.05 Revision 1.02.943 (10/28/1996)", .internal_name = "d943_oct96", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/d943/d943_oct96.bin", "" } }, + { .name = "Version 4.05 Revision 1.03.943 (12/12/1996)", .internal_name = "d943_dec96", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/d943/d943_dec96.bin", "" } }, + { .name = "Version 4.05 Revision 1.05.943 (09/04/1997)", .internal_name = "d943_sept97", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/d943/d943_sept97.bin", "" } }, + { .name = "Version 4.05 Revision 1.06.943 (10/29/1997)", .internal_name = "d943_oct97", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/d943/d943_oct97.bin", "" } }, + }, + }, + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on +}; + + + +const device_t d943_device = { + .name = "Siemens-Nixdorf D943", + .internal_name = "d943", + .flags = 0, + .local = 0, + .init = NULL, + .close = NULL, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = &d943_config[0] +}; + int machine_at_p55t2s_init(const machine_t *model) { @@ -694,25 +777,71 @@ machine_at_gw2kma_init(const machine_t *model) pci_register_slot(0x0F, PCI_CARD_NORMAL, 3, 4, 1, 2); pci_register_slot(0x10, PCI_CARD_NORMAL, 4, 1, 2, 3); pci_register_slot(0x07, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 4); + + if ((sound_card_current[0] == SOUND_INTERNAL) && machine_get_snd_device(machine)->available()) + machine_snd = device_add(machine_get_snd_device(machine)); + device_add(&i430vx_device); device_add(&piix3_device); - device_add(&fdc37c932fr_device); + device_add_params(&fdc37c93x_device, (void *) (FDC37C932 | FDC37C93X_FR)); device_add(&intel_flash_bxt_ami_device); return ret; } +static const device_config_t ap5s_config[] = { + // clang-format off + { + .name = "bios", + .description = "BIOS Version", + .type = CONFIG_BIOS, + .default_string = "ap5s", + .default_int = 0, + .file_filter = "", + .spinner = { 0 }, + .bios = { + { .name = "04/22/96 1.20 4.50PG", .internal_name = "ap5s_450pg", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/ap5s/ap5s120.bin", "" } }, + { .name = "11/13/96 1.50 4.51PG", .internal_name = "ap5s", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/ap5s/AP5S150.BIN", "" } }, + { .name = "06/25/97 1.60 4.51PG", .internal_name = "ap5s_latest", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/ap5s/ap5s160.bin", "" } }, + { .files_no = 0 } + }, + }, + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on +}; + +const device_t ap5s_device = { + .name = "AOpen AP5S", + .internal_name = "ap5s_device", + .flags = 0, + .local = 0, + .init = NULL, + .close = NULL, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = ap5s_config +}; + int machine_at_ap5s_init(const machine_t *model) { - int ret; + int ret = 0; + const char* fn; - ret = bios_load_linear("roms/machines/ap5s/AP5S150.BIN", - 0x000e0000, 131072, 0); - - if (bios_only || !ret) + /* No ROMs available */ + if (!device_available(model->device)) return ret; + device_context(model->device); + fn = device_get_bios_file(machine_get_device(machine), device_get_config_bios("bios"), 0); + ret = bios_load_linear(fn, 0x000e0000, 131072, 0); + device_context_restore(); + machine_at_common_init_ex(model, 2); pci_init(PCI_CONFIG_TYPE_1 | FLAG_TRC_CONTROLS_CPURST); @@ -815,19 +944,64 @@ machine_at_vectra54_init(const machine_t *model) device_add(&i430fx_device); device_add(&piix_device); - device_add(&fdc37c932_device); + device_add_params(&fdc37c93x_device, (void *) (FDC37C932 | FDC37C93X_NORMAL)); device_add(&sst_flash_29ee010_device); return ret; } +static const device_config_t c5sbm2_config[] = { + // clang-format off + { + .name = "bios", + .description = "BIOS Version", + .type = CONFIG_BIOS, + .default_string = "5sbm2", + .default_int = 0, + .file_filter = "", + .spinner = { 0 }, + .bios = { + { .name = "4.50GP (07/17/1995)", .internal_name = "5sbm2", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/5sbm2/5SBM0717.BIN", "" } }, + { .name = "4.50PG (03/21/1996)", .internal_name = "5sbm2_450pg", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/5sbm2/5SBM0326.BIN", "" } }, + { .name = "4.51PG (03/15/2000 Unicore Upgrade)", .internal_name = "5sbm2_451pg", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/5sbm2/2A5ICC3A.BIN", "" } }, + { .files_no = 0 } + }, + }, + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on +}; + +const device_t c5sbm2_device = { + .name = "Chaintech 5SBM/5SBM2 (M103)", + .internal_name = "5sbm2_device", + .flags = 0, + .local = 0, + .init = NULL, + .close = NULL, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = c5sbm2_config +}; + int machine_at_5sbm2_init(const machine_t *model) { - int ret; + int ret = 0; + const char* fn; - ret = bios_load_linear("roms/machines/5sbm2/5SBM0717.BIN", - 0x000e0000, 131072, 0); + /* No ROMs available */ + if (!device_available(model->device)) + return ret; + + device_context(model->device); + fn = device_get_bios_file(machine_get_device(machine), device_get_config_bios("bios"), 0); + ret = bios_load_linear(fn, 0x000e0000, 131072, 0); + device_context_restore(); if (bios_only || !ret) return ret; diff --git a/src/machine/m_at_socket8.c b/src/machine/m_at_socket8.c index e6f78f6a2..d81b41502 100644 --- a/src/machine/m_at_socket8.c +++ b/src/machine/m_at_socket8.c @@ -188,8 +188,9 @@ machine_at_acerv60n_init(const machine_t *model) pci_register_slot(0x0C, PCI_CARD_NORMAL, 2, 3, 4, 1); device_add(&i440fx_device); device_add(&piix3_device); - device_add(&fdc37c935_device); + device_add_params(&fdc37c93x_device, (void *) (FDC37C935 | FDC37C93X_NORMAL)); device_add(&sst_flash_29ee010_device); + spd_register(SPD_TYPE_SDRAM, 0x7, 128); return ret; } @@ -216,9 +217,7 @@ machine_at_lgibmx61_init(const machine_t *model) pci_register_slot(0x0F, PCI_CARD_NORMAL, 4, 1, 2, 3); device_add(&i440fx_device); device_add(&piix3_device); - // device_add(&keyboard_ps2_ami_pci_device); device_add(&keyboard_ps2_ami_device); - // device_add(&w83787f_device); device_add(&w83877f_president_device); device_add(&sst_flash_29ee010_device); @@ -251,11 +250,49 @@ machine_at_vs440fx_init(const machine_t *model) pci_register_slot(0x07, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0); device_add(&i440fx_device); device_add(&piix3_device); - device_add(&keyboard_ps2_intel_ami_pci_device); - device_add(&pc87307_device); + device_add_params(&pc87307_device, (void *) (PCX730X_AMI | PCX7307_PC87307)); device_add(&intel_flash_bxt_ami_device); + if (sound_card_current[0] == SOUND_INTERNAL) + device_add(machine_get_snd_device(machine)); + + return ret; +} + +int +machine_at_dellvenus_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear_combined2("roms/machines/dellvenus/1006CS1J.BIO", + "roms/machines/dellvenus/1006CS1J.BI1", + "roms/machines/dellvenus/1006CS1J.BI2", + "roms/machines/dellvenus/1006CS1J.BI3", + "roms/machines/dellvenus/1006CS1J.RCV", + 0x3a000, 128); + + if (bios_only || !ret) + return ret; + + machine_at_common_init(model); + + pci_init(PCI_CONFIG_TYPE_1); + pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); + pci_register_slot(0x0B, PCI_CARD_NORMAL, 1, 2, 3, 4); + pci_register_slot(0x0F, PCI_CARD_NORMAL, 4, 1, 2, 3); + pci_register_slot(0x11, PCI_CARD_NORMAL, 3, 4, 1, 2); + pci_register_slot(0x13, PCI_CARD_NORMAL, 2, 3, 4, 1); + pci_register_slot(0x07, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0); + device_add(&i440fx_device); + device_add(&piix3_device); + device_add_params(&pc87307_device, (void *) (PCX730X_AMI | PCX7307_PC87307)); + + device_add(&intel_flash_bxt_ami_device); + + if (sound_card_current[0] == SOUND_INTERNAL) + device_add(machine_get_snd_device(machine)); + return ret; } @@ -285,11 +322,13 @@ machine_at_gw2kvenus_init(const machine_t *model) pci_register_slot(0x07, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0); device_add(&i440fx_device); device_add(&piix3_device); - device_add(&keyboard_ps2_intel_ami_pci_device); - device_add(&pc87307_device); + device_add_params(&pc87307_device, (void *) (PCX730X_AMI | PCX7307_PC87307)); device_add(&intel_flash_bxt_ami_device); + if (sound_card_current[0] == SOUND_INTERNAL) + device_add(machine_get_snd_device(machine)); + return ret; } @@ -319,8 +358,7 @@ machine_at_ap440fx_init(const machine_t *model) pci_register_slot(0x07, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 4); device_add(&i440fx_device); device_add(&piix3_device); - device_add(&keyboard_ps2_ami_pci_device); - device_add(&pc87307_device); + device_add_params(&pc87307_device, (void *) (PCX730X_AMI | PCX7307_PC87307)); device_add(&intel_flash_bxt_ami_device); if (sound_card_current[0] == SOUND_INTERNAL) @@ -383,7 +421,7 @@ machine_at_m6mi_init(const machine_t *model) pci_register_slot(0x0F, PCI_CARD_NORMAL, 4, 1, 2, 3); device_add(&i440fx_device); device_add(&piix3_device); - device_add(&fdc37c935_device); + device_add_params(&fdc37c93x_device, (void *) (FDC37C935 | FDC37C93X_NORMAL)); device_add(&intel_flash_bxt_device); return ret; diff --git a/src/machine/m_at_sockets7.c b/src/machine/m_at_sockets7.c index 0360b5650..b7ffc03b3 100644 --- a/src/machine/m_at_sockets7.c +++ b/src/machine/m_at_sockets7.c @@ -343,6 +343,38 @@ machine_at_5emapro_init(const machine_t *model) return ret; } +int +machine_at_delhi3_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/delhi3/DELHI3.ROM", + 0x000c0000, 262144, 0); + + if (bios_only || !ret) + return ret; + + machine_at_common_init_ex(model, 2); + + pci_init(PCI_CONFIG_TYPE_1); + pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); + pci_register_slot(0x07, PCI_CARD_SOUTHBRIDGE, 1, 2, 3, 4); + pci_register_slot(0x13, PCI_CARD_NORMAL, 1, 2, 3, 4); + pci_register_slot(0x12, PCI_CARD_NORMAL, 2, 3, 4, 1); + + device_add(&via_mvp3_device); + device_add(&via_vt82c596a_device); + device_add(&keyboard_ps2_ami_pci_device); + device_add(&w83877tf_device); + device_add(&sst_flash_39sf020_device); + spd_register(SPD_TYPE_SDRAM, 0x3, 256); + + if ((sound_card_current[0] == SOUND_INTERNAL) && machine_get_snd_device(machine)) + device_add(machine_get_snd_device(machine)); + + return ret; +} + int machine_at_5sg100_init(const machine_t *model) { diff --git a/src/machine/m_elt.c b/src/machine/m_elt.c index 812755898..628333aba 100644 --- a/src/machine/m_elt.c +++ b/src/machine/m_elt.c @@ -58,13 +58,13 @@ static void elt_vid_off_poll(void *priv) { cga_t *cga = priv; - uint8_t hdisp = cga->crtc[1]; + uint8_t hdisp = cga->crtc[CGA_CRTC_HDISP]; /* Don't display anything. * TODO: Do something less stupid to emulate backlight off. */ - cga->crtc[1] = 0; + cga->crtc[CGA_CRTC_HDISP] = 0; cga_poll(cga); - cga->crtc[1] = hdisp; + cga->crtc[CGA_CRTC_HDISP] = hdisp; } static void diff --git a/src/machine/m_europc.c b/src/machine/m_europc.c index 42034e2f6..7fc990a45 100644 --- a/src/machine/m_europc.c +++ b/src/machine/m_europc.c @@ -646,6 +646,7 @@ europc_boot(UNUSED(const device_t *info)) * (JS9) can be used to "move" it to 0x0350, to get it out of * the way of other cards that need this range. */ + sys->jim = device_get_config_hex16("js9"); io_sethandler(sys->jim, 16, jim_read, NULL, NULL, jim_write, NULL, NULL, sys); @@ -680,14 +681,14 @@ static const device_config_t europc_config[] = { { .name = "js9", .description = "JS9 Jumper (JIM)", - .type = CONFIG_INT, + .type = CONFIG_HEX16, .default_string = "", - .default_int = 0, + .default_int = 0x0250, .file_filter = "", .spinner = { 0 }, .selection = { - { .description = "Disabled (250h)", .value = 0 }, - { .description = "Enabled (350h)", .value = 1 }, + { .description = "Disabled (250h)", .value = 0x0250 }, + { .description = "Enabled (350h)", .value = 0x0350 }, { .description = "" } }, }, @@ -703,7 +704,7 @@ const device_t europc_device = { .init = europc_boot, .close = europc_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = europc_config diff --git a/src/machine/m_pcjr.c b/src/machine/m_pcjr.c index 16020826d..30a5e609a 100644 --- a/src/machine/m_pcjr.c +++ b/src/machine/m_pcjr.c @@ -48,11 +48,10 @@ #include <86box/snd_sn76489.h> #include <86box/video.h> #include <86box/vid_cga_comp.h> +#include <86box/m_pcjr.h> #include <86box/machine.h> #include <86box/plat_unused.h> -#define PCJR_RGB 0 -#define PCJR_COMPOSITE 1 #define STAT_PARITY 0x80 #define STAT_RTIMEOUT 0x40 @@ -63,50 +62,10 @@ #define STAT_IFULL 0x02 #define STAT_OFULL 0x01 -typedef struct pcjr_t { - /* Video Controller stuff. */ - mem_mapping_t mapping; - uint8_t crtc[32]; - int crtcreg; - int array_index; - uint8_t array[32]; - int array_ff; - int memctrl; - uint8_t stat; - int addr_mode; - 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; - int apply_hd; - /* Keyboard Controller stuff. */ - int latched; - int data; - int serial_data[44]; - int serial_pos; - uint8_t pa; - uint8_t pb; - pc_timer_t send_delay_timer; -} pcjr_t; +static uint8_t key_queue[16]; +static int key_queue_start = 0; +static int key_queue_end = 0; /*PCjr keyboard has no escape scancodes, and no scancodes beyond 54 Map right alt to 54h (FN) */ @@ -627,644 +586,6 @@ const scancode scancode_pcjr[512] = { // clang-format on }; -static video_timings_t timing_dram = { VIDEO_BUS, 0, 0, 0, 0, 0, 0 }; /*No additional waitstates*/ - -static uint8_t 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 uint8_t key_queue[16]; -static int key_queue_start = 0; -static int key_queue_end = 0; - -static void -recalc_address(pcjr_t *pcjr) -{ - uint8_t masked_memctrl = pcjr->memctrl; - - /* According to the Technical Reference, bits 2 and 5 are - ignored if there is only 64k of RAM and there are only - 4 pages. */ - if (mem_size < 128) - masked_memctrl &= ~0x24; - - if ((pcjr->memctrl & 0xc0) == 0xc0) { - pcjr->vram = &ram[(masked_memctrl & 0x06) << 14]; - pcjr->b8000 = &ram[(masked_memctrl & 0x30) << 11]; - } else { - pcjr->vram = &ram[(masked_memctrl & 0x07) << 14]; - pcjr->b8000 = &ram[(masked_memctrl & 0x38) << 11]; - } -} - -static void -recalc_timings(pcjr_t *pcjr) -{ - double _dispontime; - double _dispofftime; - double disptime; - - if (pcjr->array[0] & 1) { - disptime = pcjr->crtc[0] + 1; - _dispontime = pcjr->crtc[1]; - } else { - disptime = (pcjr->crtc[0] + 1) << 1; - _dispontime = pcjr->crtc[1] << 1; - } - - _dispofftime = disptime - _dispontime; - _dispontime *= CGACONST; - _dispofftime *= CGACONST; - pcjr->dispontime = (uint64_t) (_dispontime); - pcjr->dispofftime = (uint64_t) (_dispofftime); -} - -static int -vid_get_h_overscan_size(pcjr_t *pcjr) -{ - int ret; - - if (pcjr->array[0] & 1) - ret = 128; - else - ret = 256; - - return ret; -} - -static void -vid_out(uint16_t addr, uint8_t val, void *priv) -{ - pcjr_t *pcjr = (pcjr_t *) priv; - uint8_t old; - - switch (addr) { - case 0x3d0: - case 0x3d2: - case 0x3d4: - case 0x3d6: - pcjr->crtcreg = val & 0x1f; - return; - - case 0x3d1: - case 0x3d3: - case 0x3d5: - case 0x3d7: - old = pcjr->crtc[pcjr->crtcreg]; - pcjr->crtc[pcjr->crtcreg] = val & crtcmask[pcjr->crtcreg]; - if (pcjr->crtcreg == 2) - overscan_x = vid_get_h_overscan_size(pcjr); - if (old != val) { - if (pcjr->crtcreg < 0xe || pcjr->crtcreg > 0x10) { - pcjr->fullchange = changeframecount; - recalc_timings(pcjr); - } - } - return; - - case 0x3da: - if (!pcjr->array_ff) - pcjr->array_index = val & 0x1f; - else { - if (pcjr->array_index & 0x10) - val &= 0x0f; - pcjr->array[pcjr->array_index & 0x1f] = val; - if (!(pcjr->array_index & 0x1f)) - update_cga16_color(val); - } - pcjr->array_ff = !pcjr->array_ff; - break; - - case 0x3df: - pcjr->memctrl = val; - pcjr->pa = val; /* The PCjr BIOS expects the value written to 3DF to - then be readable from port 60, others it errors out - with only 64k RAM set (but somehow, still works with - 128k or more RAM). */ - pcjr->addr_mode = val >> 6; - recalc_address(pcjr); - break; - - default: - break; - } -} - -static uint8_t -vid_in(uint16_t addr, void *priv) -{ - pcjr_t *pcjr = (pcjr_t *) priv; - uint8_t ret = 0xff; - - switch (addr) { - case 0x3d0: - case 0x3d2: - case 0x3d4: - case 0x3d6: - ret = pcjr->crtcreg; - break; - - case 0x3d1: - case 0x3d3: - case 0x3d5: - case 0x3d7: - ret = pcjr->crtc[pcjr->crtcreg]; - break; - - case 0x3da: - pcjr->array_ff = 0; - pcjr->stat ^= 0x10; - ret = pcjr->stat; - break; - - default: - break; - } - - return ret; -} - -static void -vid_write(uint32_t addr, uint8_t val, void *priv) -{ - pcjr_t *pcjr = (pcjr_t *) priv; - - if (pcjr->memctrl == -1) - return; - - pcjr->b8000[addr & 0x3fff] = val; -} - -static uint8_t -vid_read(uint32_t addr, void *priv) -{ - const pcjr_t *pcjr = (pcjr_t *) priv; - - if (pcjr->memctrl == -1) - return 0xff; - - return (pcjr->b8000[addr & 0x3fff]); -} - -static int -vid_get_h_overscan_delta(pcjr_t *pcjr) -{ - int def; - int coef; - int ret; - - switch ((pcjr->array[0] & 0x13) | ((pcjr->array[3] & 0x08) << 5)) { - case 0x13: /*320x200x16*/ - def = 0x56; - coef = 8; - break; - case 0x12: /*160x200x16*/ - def = 0x2c; /* I'm going to assume a datasheet erratum here. */ - coef = 16; - break; - case 0x03: /*640x200x4*/ - def = 0x56; - coef = 8; - break; - case 0x01: /*80 column text*/ - def = 0x5a; - coef = 8; - break; - case 0x00: /*40 column text*/ - default: - def = 0x2c; - coef = 16; - break; - case 0x02: /*320x200x4*/ - def = 0x2b; - coef = 16; - break; - case 0x102: /*640x200x2*/ - def = 0x2b; - coef = 16; - break; - } - - ret = pcjr->crtc[0x02] - def; - - if (ret < -8) - ret = -8; - - if (ret > 8) - ret = 8; - - return ret * coef; -} - -static void -vid_blit_h_overscan(pcjr_t *pcjr) -{ - int cols = (pcjr->array[2] & 0xf) + 16;; - int y0 = pcjr->firstline << 1; - int y = (pcjr->lastline << 1) + 16; - int ho_s = vid_get_h_overscan_size(pcjr); - int i; - int x; - - if (pcjr->array[0] & 1) - x = (pcjr->crtc[1] << 3) + ho_s; - else - x = (pcjr->crtc[1] << 4) + ho_s; - - for (i = 0; i < 16; i++) { - hline(buffer32, 0, y0 + i, x, cols); - hline(buffer32, 0, y + i, x, cols); - - if (pcjr->composite) { - Composite_Process(pcjr->array[0], 0, x >> 2, buffer32->line[y0 + i]); - Composite_Process(pcjr->array[0], 0, x >> 2, buffer32->line[y + i]); - } else { - video_process_8(x, y0 + i); - video_process_8(x, y + i); - } - } -} - -static void -vid_poll(void *priv) -{ - pcjr_t *pcjr = (pcjr_t *) priv; - uint16_t ca = (pcjr->crtc[15] | (pcjr->crtc[14] << 8)) & 0x3fff; - int drawcursor; - int x; - int xs_temp; - int ys_temp; - int oldvc; - uint8_t chr; - uint8_t attr; - uint16_t dat; - int cols[4]; - int oldsc; - int l = (pcjr->displine << 1) + 16; - int ho_s = vid_get_h_overscan_size(pcjr); - int ho_d = vid_get_h_overscan_delta(pcjr) + (ho_s / 2); - - if (!pcjr->linepos) { - timer_advance_u64(&pcjr->timer, pcjr->dispofftime); - pcjr->stat &= ~1; - pcjr->linepos = 1; - oldsc = pcjr->sc; - if ((pcjr->crtc[8] & 3) == 3) - pcjr->sc = (pcjr->sc << 1) & 7; - if (pcjr->dispon) { - uint16_t offset = 0; - uint16_t mask = 0x1fff; - - if (pcjr->displine < pcjr->firstline) { - pcjr->firstline = pcjr->displine; - video_wait_for_buffer(); - } - pcjr->lastline = pcjr->displine; - cols[0] = (pcjr->array[2] & 0xf) + 16; - - if (pcjr->array[0] & 1) { - hline(buffer32, 0, l, (pcjr->crtc[1] << 3) + ho_s, cols[0]); - hline(buffer32, 0, l + 1, (pcjr->crtc[1] << 3) + ho_s, cols[0]); - } else { - hline(buffer32, 0, l, (pcjr->crtc[1] << 4) + ho_s, cols[0]); - hline(buffer32, 0, l + 1, (pcjr->crtc[1] << 4) + ho_s, cols[0]); - } - - switch (pcjr->addr_mode) { - case 0: /*Alpha*/ - offset = 0; - mask = 0x3fff; - break; - case 1: /*Low resolution graphics*/ - offset = (pcjr->sc & 1) * 0x2000; - break; - 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++) { - int ef_x = (x << 3) + ho_d; - dat = (pcjr->vram[((pcjr->ma << 1) & mask) + offset] << 8) | - pcjr->vram[((pcjr->ma << 1) & mask) + offset + 1]; - pcjr->ma++; - buffer32->line[l][ef_x] = buffer32->line[l][ef_x + 1] = - buffer32->line[l + 1][ef_x] = buffer32->line[l + 1][ef_x + 1] = - pcjr->array[((dat >> 12) & pcjr->array[1] & 0x0f) + 16] + 16; - buffer32->line[l][ef_x + 2] = buffer32->line[l][ef_x + 3] = - buffer32->line[l + 1][ef_x + 2] = buffer32->line[l + 1][ef_x + 3] = - pcjr->array[((dat >> 8) & pcjr->array[1] & 0x0f) + 16] + 16; - buffer32->line[l][ef_x + 4] = buffer32->line[l][ef_x + 5] = - buffer32->line[l + 1][ef_x + 4] = buffer32->line[l + 1][ef_x + 5] = - pcjr->array[((dat >> 4) & pcjr->array[1] & 0x0f) + 16] + 16; - buffer32->line[l][ef_x + 6] = buffer32->line[l][ef_x + 7] = - buffer32->line[l + 1][ef_x + 6] = buffer32->line[l + 1][ef_x + 7] = - pcjr->array[(dat & pcjr->array[1] & 0x0f) + 16] + 16; - } - break; - case 0x12: /*160x200x16*/ - for (x = 0; x < pcjr->crtc[1]; x++) { - int ef_x = (x << 4) + ho_d; - dat = (pcjr->vram[((pcjr->ma << 1) & mask) + offset] << 8) | - pcjr->vram[((pcjr->ma << 1) & mask) + offset + 1]; - pcjr->ma++; - buffer32->line[l][ef_x] = buffer32->line[l][ef_x + 1] = - buffer32->line[l][ef_x + 2] = buffer32->line[l][ef_x + 3] = - buffer32->line[l + 1][ef_x] = buffer32->line[l + 1][ef_x + 1] = - buffer32->line[l + 1][ef_x + 2] = buffer32->line[l + 1][ef_x + 3] = - pcjr->array[((dat >> 12) & pcjr->array[1] & 0x0f) + 16] + 16; - buffer32->line[l][ef_x + 4] = buffer32->line[l][ef_x + 5] = - buffer32->line[l][ef_x + 6] = buffer32->line[l][ef_x + 7] = - buffer32->line[l + 1][ef_x + 4] = buffer32->line[l + 1][ef_x + 5] = - buffer32->line[l + 1][ef_x + 6] = buffer32->line[l + 1][ef_x + 7] = - pcjr->array[((dat >> 8) & pcjr->array[1] & 0x0f) + 16] + 16; - buffer32->line[l][ef_x + 8] = buffer32->line[l][ef_x + 9] = - buffer32->line[l][ef_x + 10] = buffer32->line[l][ef_x + 11] = - buffer32->line[l + 1][ef_x + 8] = buffer32->line[l + 1][ef_x + 9] = - buffer32->line[l + 1][ef_x + 10] = buffer32->line[l + 1][ef_x + 11] = - pcjr->array[((dat >> 4) & pcjr->array[1] & 0x0f) + 16] + 16; - buffer32->line[l][ef_x + 12] = buffer32->line[l][ef_x + 13] = - buffer32->line[l][ef_x + 14] = buffer32->line[l][ef_x + 15] = - buffer32->line[l + 1][ef_x + 12] = buffer32->line[l + 1][ef_x + 13] = - buffer32->line[l + 1][ef_x + 14] = buffer32->line[l + 1][ef_x + 15] = - pcjr->array[(dat & pcjr->array[1] & 0x0f) + 16] + 16; - } - break; - case 0x03: /*640x200x4*/ - for (x = 0; x < pcjr->crtc[1]; x++) { - int ef_x = (x << 3) + ho_d; - dat = (pcjr->vram[((pcjr->ma << 1) & mask) + offset + 1] << 8) | - pcjr->vram[((pcjr->ma << 1) & mask) + offset]; - pcjr->ma++; - for (uint8_t c = 0; c < 8; c++) { - chr = (dat >> 7) & 1; - chr |= ((dat >> 14) & 2); - buffer32->line[l][ef_x + c] = buffer32->line[l + 1][ef_x + c] = - pcjr->array[(chr & pcjr->array[1] & 0x0f) + 16] + 16; - dat <<= 1; - } - } - break; - case 0x01: /*80 column text*/ - for (x = 0; x < pcjr->crtc[1]; x++) { - int ef_x = (x << 3) + ho_d; - chr = pcjr->vram[((pcjr->ma << 1) & mask) + offset]; - attr = pcjr->vram[((pcjr->ma << 1) & mask) + offset + 1]; - drawcursor = ((pcjr->ma == ca) && pcjr->con && pcjr->cursoron); - if (pcjr->array[3] & 4) { - cols[1] = pcjr->array[((attr & 15) & pcjr->array[1] & 0x0f) + 16] + 16; - cols[0] = pcjr->array[(((attr >> 4) & 7) & pcjr->array[1] & 0x0f) + 16] + 16; - if ((pcjr->blink & 16) && (attr & 0x80) && !drawcursor) - cols[1] = cols[0]; - } else { - cols[1] = pcjr->array[((attr & 15) & pcjr->array[1] & 0x0f) + 16] + 16; - cols[0] = pcjr->array[((attr >> 4) & pcjr->array[1] & 0x0f) + 16] + 16; - } - if (pcjr->sc & 8) - for (uint8_t c = 0; c < 8; c++) - buffer32->line[l][ef_x + c] = - buffer32->line[l + 1][ef_x + c] = cols[0]; - else - for (uint8_t c = 0; c < 8; c++) - buffer32->line[l][ef_x + c] = - buffer32->line[l + 1][ef_x + c] = - cols[(fontdat[chr][pcjr->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; - if (drawcursor) - for (uint8_t c = 0; c < 8; c++) { - buffer32->line[l][ef_x + c] ^= 15; - buffer32->line[l + 1][ef_x + c] ^= 15; - } - pcjr->ma++; - } - break; - case 0x00: /*40 column text*/ - for (x = 0; x < pcjr->crtc[1]; x++) { - int ef_x = (x << 4) + ho_d; - chr = pcjr->vram[((pcjr->ma << 1) & mask) + offset]; - attr = pcjr->vram[((pcjr->ma << 1) & mask) + offset + 1]; - drawcursor = ((pcjr->ma == ca) && pcjr->con && pcjr->cursoron); - if (pcjr->array[3] & 4) { - cols[1] = pcjr->array[((attr & 15) & pcjr->array[1] & 0x0f) + 16] + 16; - cols[0] = pcjr->array[(((attr >> 4) & 7) & pcjr->array[1] & 0x0f) + 16] + 16; - if ((pcjr->blink & 16) && (attr & 0x80) && !drawcursor) - cols[1] = cols[0]; - } else { - cols[1] = pcjr->array[((attr & 15) & pcjr->array[1] & 0x0f) + 16] + 16; - cols[0] = pcjr->array[((attr >> 4) & pcjr->array[1] & 0x0f) + 16] + 16; - } - pcjr->ma++; - if (pcjr->sc & 8) - for (uint8_t c = 0; c < 8; c++) - buffer32->line[l][ef_x + (c << 1)] = - buffer32->line[l][ef_x + (c << 1) + 1] = - buffer32->line[l + 1][ef_x + (c << 1)] = - buffer32->line[l + 1][ef_x + (c << 1) + 1] = cols[0]; - else - for (uint8_t c = 0; c < 8; c++) - buffer32->line[l][ef_x + (c << 1)] = - buffer32->line[l][ef_x + (c << 1) + 1] = - buffer32->line[l + 1][ef_x + (c << 1)] = - buffer32->line[l + 1][ef_x + (c << 1) + 1] = - cols[(fontdat[chr][pcjr->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; - if (drawcursor) - for (uint8_t c = 0; c < 16; c++) { - buffer32->line[l][ef_x + c] ^= 15; - buffer32->line[l + 1][ef_x + c] ^= 15; - } - } - break; - case 0x02: /*320x200x4*/ - cols[0] = pcjr->array[0 + 16] + 16; - cols[1] = pcjr->array[1 + 16] + 16; - cols[2] = pcjr->array[2 + 16] + 16; - cols[3] = pcjr->array[3 + 16] + 16; - for (x = 0; x < pcjr->crtc[1]; x++) { - int ef_x = (x << 4) + ho_d; - dat = (pcjr->vram[((pcjr->ma << 1) & mask) + offset] << 8) | - pcjr->vram[((pcjr->ma << 1) & mask) + offset + 1]; - pcjr->ma++; - for (uint8_t c = 0; c < 8; c++) { - buffer32->line[l][ef_x + (c << 1)] = - buffer32->line[l][ef_x + (c << 1) + 1] = - buffer32->line[l + 1][ef_x + (c << 1)] = - buffer32->line[l + 1][ef_x + (c << 1) + 1] = cols[dat >> 14]; - dat <<= 2; - } - } - break; - case 0x102: /*640x200x2*/ - cols[0] = pcjr->array[0 + 16] + 16; - cols[1] = pcjr->array[1 + 16] + 16; - for (x = 0; x < pcjr->crtc[1]; x++) { - int ef_x = (x << 4) + ho_d; - dat = (pcjr->vram[((pcjr->ma << 1) & mask) + offset] << 8) | - pcjr->vram[((pcjr->ma << 1) & mask) + offset + 1]; - pcjr->ma++; - for (uint8_t c = 0; c < 16; c++) { - buffer32->line[l][ef_x + c] = buffer32->line[l + 1][ef_x + c] = - cols[dat >> 15]; - dat <<= 1; - } - } - break; - - default: - break; - } - } else { - if (pcjr->array[3] & 4) { - if (pcjr->array[0] & 1) { - hline(buffer32, 0, l, (pcjr->crtc[1] << 3) + ho_s, (pcjr->array[2] & 0xf) + 16); - hline(buffer32, 0, l + 1, (pcjr->crtc[1] << 3) + ho_s, (pcjr->array[2] & 0xf) + 16); - } else { - hline(buffer32, 0, l, (pcjr->crtc[1] << 4) + ho_s, (pcjr->array[2] & 0xf) + 16); - hline(buffer32, 0, l + 1, (pcjr->crtc[1] << 4) + ho_s, (pcjr->array[2] & 0xf) + 16); - } - } else { - cols[0] = pcjr->array[0 + 16] + 16; - if (pcjr->array[0] & 1) { - hline(buffer32, 0, l, (pcjr->crtc[1] << 3) + ho_s, cols[0]); - hline(buffer32, 0, l + 1, (pcjr->crtc[1] << 3) + ho_s, cols[0]); - } else { - hline(buffer32, 0, l, (pcjr->crtc[1] << 4) + ho_s, cols[0]); - hline(buffer32, 0, l + 1, (pcjr->crtc[1] << 4) + ho_s, cols[0]); - } - } - } - if (pcjr->array[0] & 1) - x = (pcjr->crtc[1] << 3) + ho_s; - else - x = (pcjr->crtc[1] << 4) + ho_s; - if (pcjr->composite) { - Composite_Process(pcjr->array[0], 0, x >> 2, buffer32->line[l]); - Composite_Process(pcjr->array[0], 0, x >> 2, buffer32->line[l + 1]); - } else { - video_process_8(x, l); - video_process_8(x, l + 1); - } - pcjr->sc = oldsc; - if (pcjr->vc == pcjr->crtc[7] && !pcjr->sc) { - pcjr->stat |= 8; - } - pcjr->displine++; - if (pcjr->displine >= 360) - pcjr->displine = 0; - } else { - timer_advance_u64(&pcjr->timer, pcjr->dispontime); - if (pcjr->dispon) - pcjr->stat |= 1; - pcjr->linepos = 0; - if (pcjr->vsynctime) { - pcjr->vsynctime--; - if (!pcjr->vsynctime) { - pcjr->stat &= ~8; - } - } - if (pcjr->sc == (pcjr->crtc[11] & 31) || ((pcjr->crtc[8] & 3) == 3 && pcjr->sc == ((pcjr->crtc[11] & 31) >> 1))) { - pcjr->con = 0; - pcjr->coff = 1; - } - if (pcjr->vadj) { - pcjr->sc++; - pcjr->sc &= 31; - pcjr->ma = pcjr->maback; - pcjr->vadj--; - if (!pcjr->vadj) { - pcjr->dispon = 1; - pcjr->ma = pcjr->maback = (pcjr->crtc[13] | (pcjr->crtc[12] << 8)) & 0x3fff; - pcjr->sc = 0; - } - } else if (pcjr->sc == pcjr->crtc[9] || ((pcjr->crtc[8] & 3) == 3 && pcjr->sc == (pcjr->crtc[9] >> 1))) { - pcjr->maback = pcjr->ma; - pcjr->sc = 0; - oldvc = pcjr->vc; - pcjr->vc++; - pcjr->vc &= 127; - if (pcjr->vc == pcjr->crtc[6]) - pcjr->dispon = 0; - if (oldvc == pcjr->crtc[4]) { - pcjr->vc = 0; - pcjr->vadj = pcjr->crtc[5]; - if (!pcjr->vadj) - pcjr->dispon = 1; - if (!pcjr->vadj) - pcjr->ma = pcjr->maback = (pcjr->crtc[13] | (pcjr->crtc[12] << 8)) & 0x3fff; - if ((pcjr->crtc[10] & 0x60) == 0x20) - pcjr->cursoron = 0; - else - pcjr->cursoron = pcjr->blink & 16; - } - if (pcjr->vc == pcjr->crtc[7]) { - pcjr->dispon = 0; - pcjr->displine = 0; - pcjr->vsynctime = 16; - picint(1 << 5); - if (pcjr->crtc[7]) { - if (pcjr->array[0] & 1) - x = (pcjr->crtc[1] << 3) + ho_s; - else - x = (pcjr->crtc[1] << 4) + ho_s; - pcjr->lastline++; - - xs_temp = x; - ys_temp = (pcjr->lastline - pcjr->firstline) << 1; - - if ((xs_temp > 0) && (ys_temp > 0)) { - int actual_ys = ys_temp; - - if (xs_temp < 64) - xs_temp = 656; - if (ys_temp < 32) - ys_temp = 400; - if (!enable_overscan) - xs_temp -= ho_s; - - if ((xs_temp != xsize) || (ys_temp != ysize) || video_force_resize_get()) { - xsize = xs_temp; - ysize = ys_temp; - - set_screen_size(xsize, ysize + (enable_overscan ? 32 : 0)); - - if (video_force_resize_get()) - video_force_resize_set(0); - } - - vid_blit_h_overscan(pcjr); - - if (enable_overscan) { - video_blit_memtoscreen(0, pcjr->firstline << 1, - xsize, actual_ys + 32); - } else if (pcjr->apply_hd) { - video_blit_memtoscreen(ho_s / 2, (pcjr->firstline << 1) + 16, - xsize, actual_ys); - } else { - video_blit_memtoscreen(ho_d, (pcjr->firstline << 1) + 16, - xsize, actual_ys); - } - } - - frames++; - video_res_x = xsize; - video_res_y = ysize; - } - pcjr->firstline = 1000; - pcjr->lastline = 0; - pcjr->blink++; - } - } else { - pcjr->sc++; - 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))) - pcjr->con = 1; - } -} static void kbd_write(uint16_t port, uint8_t val, void *priv) @@ -1435,35 +756,7 @@ speed_changed(void *priv) { pcjr_t *pcjr = (pcjr_t *) priv; - recalc_timings(pcjr); -} - -static void -pcjr_vid_init(pcjr_t *pcjr) -{ - int display_type; - - video_inform(VIDEO_FLAG_TYPE_CGA, &timing_dram); - - pcjr->memctrl = -1; - if (mem_size < 128) - pcjr->memctrl &= ~0x24; - - display_type = device_get_config_int("display_type"); - pcjr->composite = (display_type != PCJR_RGB); - pcjr->apply_hd = device_get_config_int("apply_hd"); - overscan_x = 256; - overscan_y = 32; - - mem_mapping_add(&pcjr->mapping, 0xb8000, 0x08000, - vid_read, NULL, NULL, - vid_write, NULL, NULL, NULL, 0, pcjr); - io_sethandler(0x03d0, 16, - vid_in, NULL, NULL, vid_out, NULL, NULL, pcjr); - timer_add(&pcjr->timer, vid_poll, pcjr, 1); - - cga_palette = 0; - cgapal_rebuild(); + pcjr_recalc_timings(pcjr); } void @@ -1489,9 +782,11 @@ static const device_config_t pcjr_config[] = { .file_filter = "", .spinner = { 0 }, .selection = { - { .description = "RGB", .value = PCJR_RGB }, - { .description = "Composite", .value = PCJR_COMPOSITE }, - { .description = "" } + { .description = "RGB", .value = PCJR_RGB }, + { .description = "Composite", .value = PCJR_COMPOSITE }, + { .description = "RGB (no brown)", .value = PCJR_RGB_NO_BROWN }, + { .description = "RGB (IBM 5153)", .value = PCJR_RGB_IBM_5153 }, + { .description = "" } } }, { @@ -1513,7 +808,7 @@ const device_t pcjr_device = { .init = NULL, .close = NULL, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = speed_changed, .force_redraw = NULL, .config = pcjr_config @@ -1532,8 +827,7 @@ machine_pcjr_init(UNUSED(const machine_t *model)) if (bios_only || !ret) return ret; - pcjr = malloc(sizeof(pcjr_t)); - memset(pcjr, 0x00, sizeof(pcjr_t)); + pcjr = calloc(1, sizeof(pcjr_t)); pic_init_pcjr(); pit_common_init(0, pit_irq0_timer_pcjr, NULL); @@ -1542,7 +836,7 @@ machine_pcjr_init(UNUSED(const machine_t *model)) /* Initialize the video controller. */ video_reset(gfxcard[0]); - loadfont("roms/video/mda/mda.rom", 0); + loadfont(FONT_IBM_MDA_437_PATH, 0); device_context(&pcjr_device); pcjr_vid_init(pcjr); device_context_restore(); @@ -1567,7 +861,8 @@ machine_pcjr_init(UNUSED(const machine_t *model)) device_add(&fdc_pcjr_device); device_add(&ns8250_pcjr_device); - serial_set_next_inst(SERIAL_MAX); /* So that serial_standalone_init() won't do anything. */ + /* So that serial_standalone_init() won't do anything. */ + serial_set_next_inst(SERIAL_MAX - 1); /* "All the inputs are 'read' with one 'IN' from address hex 201." - PCjr Technical Reference (Nov. 83), p.2-119 diff --git a/src/machine/m_ps1.c b/src/machine/m_ps1.c index 42bc49de2..c22463de4 100644 --- a/src/machine/m_ps1.c +++ b/src/machine/m_ps1.c @@ -146,13 +146,13 @@ ps1_write(uint16_t port, uint8_t val, void *priv) if (val & 0x10) { switch ((val >> 5) & 3) { case 0: - lpt1_init(LPT_MDA_ADDR); + lpt1_setup(LPT_MDA_ADDR); break; case 1: - lpt1_init(LPT1_ADDR); + lpt1_setup(LPT1_ADDR); break; case 2: - lpt1_init(LPT2_ADDR); + lpt1_setup(LPT2_ADDR); break; default: @@ -252,7 +252,7 @@ static const device_config_t ps1_2011_config[] = { .default_string = "english_us", .default_int = 0, .file_filter = "", - .spinner = { 0 }, /*W1*/ + .spinner = { 0 }, .bios = { { .name = "English (US)", .internal_name = "english_us", .bios_type = BIOS_NORMAL, .files_no = 1, .local = 0, .size = 262144, .files = { "roms/machines/ibmps1es/FC0000_US.BIN", "" } }, @@ -287,10 +287,10 @@ const device_t ps1_2011_device = { .init = NULL, .close = NULL, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, - .config = &ps1_2011_config[0] + .config = ps1_2011_config }; static void @@ -299,8 +299,7 @@ ps1_setup(int model) ps1_t *ps; void *priv; - ps = (ps1_t *) malloc(sizeof(ps1_t)); - memset(ps, 0x00, sizeof(ps1_t)); + ps = (ps1_t *) calloc(1, sizeof(ps1_t)); ps->model = model; io_sethandler(0x0091, 1, @@ -317,34 +316,32 @@ ps1_setup(int model) ps->uart = device_add_inst(&ns16450_device, 1); lpt1_remove(); - lpt1_init(LPT_MDA_ADDR); + lpt1_setup(LPT_MDA_ADDR); mem_remap_top(384); - device_add(&ps_nvr_device); - device_add(&fdc_ps2_device); if (model == 2011) { - if (!strcmp("english_us", device_get_config_bios("bios_language"))) { - /* US English */ - rom_init(&ps->high_rom, - device_get_bios_file(device_context_get_device(), device_get_config_bios("bios_language"), 0), - 0xfc0000, 0x40000, 0x3ffff, 0, MEM_MAPPING_EXTERNAL); + const device_t *d = device_context_get_device(); + const char * bios = device_get_config_bios("bios_language"); + const char * first = device_get_bios_file(d, bios, 0); + const char * second = device_get_bios_file(d, bios, 1); - } else if ((device_get_bios_file(device_context_get_device(), device_get_config_bios("bios_language"), 1)) == NULL) { + if (!strcmp(bios, "english_us")) { + /* US English */ + rom_init(&ps->high_rom, first, + 0xfc0000, 0x40000, 0x3ffff, 0, MEM_MAPPING_EXTERNAL); + } else if (second == NULL) { /* Combined ROM. */ - rom_init(&ps->high_rom, - device_get_bios_file(device_context_get_device(), device_get_config_bios("bios_language"), 0), + rom_init(&ps->high_rom, first, 0xf80000, 0x80000, 0x7ffff, 0, MEM_MAPPING_EXTERNAL); } else { /* Split ROM. */ - rom_init(&ps->mid_rom, - device_get_bios_file(device_context_get_device(), device_get_config_bios("bios_language"), 0), + rom_init(&ps->mid_rom, first, 0xf80000, 0x40000, 0x3ffff, 0, MEM_MAPPING_EXTERNAL); - rom_init(&ps->high_rom, - device_get_bios_file(device_context_get_device(), device_get_config_bios("bios_language"), 1), + rom_init(&ps->high_rom, second, 0xfc0000, 0x40000, 0x3ffff, 0, MEM_MAPPING_EXTERNAL); } @@ -382,6 +379,8 @@ ps1_setup(int model) device_add(&ps1snd_device); } + + device_add(&ps_nvr_device); } static void diff --git a/src/machine/m_ps1_hdc.c b/src/machine/m_ps1_hdc.c index e1bacad6c..ea71c918b 100644 --- a/src/machine/m_ps1_hdc.c +++ b/src/machine/m_ps1_hdc.c @@ -653,7 +653,7 @@ do_format(hdc_t *dev, drive_t *drive, ccb_t *ccb) case STATE_FINIT: do_fmt: /* Activate the status icon. */ - ui_sb_update_icon(SB_HDD | HDD_BUS_XTA, 1); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_XTA, 1); /* Seek to cylinder. */ if (do_seek(dev, drive, start_cyl)) { @@ -691,7 +691,7 @@ do_fmt: } /* De-activate the status icon. */ - ui_sb_update_icon(SB_HDD | HDD_BUS_XTA, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_XTA, 0); /* This saves us a LOT of code. */ dev->state = STATE_FINIT; @@ -705,6 +705,7 @@ do_fmt: if (intr) { /* De-activate the status icon. */ ui_sb_update_icon(SB_HDD | HDD_BUS_XTA, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_XTA, 0); do_finish(dev); } @@ -970,7 +971,7 @@ do_send: case STATE_RECV: /* Activate the status icon. */ - ui_sb_update_icon(SB_HDD | HDD_BUS_XTA, 1); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_XTA, 1); do_recv: /* Ready to transfer the data in. */ dev->state = STATE_RDATA; @@ -1000,7 +1001,7 @@ do_recv: ps1_hdc_log("HDC: CMD_WRITE_SECTORS out of data (idx=%d, len=%d)!\n", dev->buf_idx, dev->buf_len); /* De-activate the status icon. */ - ui_sb_update_icon(SB_HDD | HDD_BUS_XTA, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_XTA, 0); dev->intstat |= ISR_EQUIP_CHECK; dev->ssb.need_reset = 1; @@ -1025,7 +1026,7 @@ do_recv: /* Get address of sector to write. */ if (get_sector(dev, drive, &addr)) { /* De-activate the status icon. */ - ui_sb_update_icon(SB_HDD | HDD_BUS_XTA, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_XTA, 0); do_finish(dev); return; @@ -1038,7 +1039,7 @@ do_recv: dev->buf_idx = 0; if (--dev->count == 0) { /* De-activate the status icon. */ - ui_sb_update_icon(SB_HDD | HDD_BUS_XTA, 0); + ui_sb_update_icon_write(SB_HDD | HDD_BUS_XTA, 0); if (!(dev->ctrl & ACR_DMA_EN)) dev->status &= ~ASR_DATA_REQ; @@ -1297,8 +1298,7 @@ ps1_hdc_init(UNUSED(const device_t *info)) int c; /* Allocate and initialize device block. */ - dev = malloc(sizeof(hdc_t)); - memset(dev, 0x00, sizeof(hdc_t)); + dev = calloc(1, sizeof(hdc_t)); /* Set up controller parameters for PS/1 2011. */ dev->base = 0x0320; @@ -1311,7 +1311,7 @@ ps1_hdc_init(UNUSED(const device_t *info)) /* Load any disks for this device class. */ c = 0; for (uint8_t i = 0; i < HDD_NUM; i++) { - if ((hdd[i].bus == HDD_BUS_XTA) && (hdd[i].xta_channel < 1)) { + if ((hdd[i].bus_type == HDD_BUS_XTA) && (hdd[i].xta_channel < 1)) { drive = &dev->drives[hdd[i].xta_channel]; if (!hdd_image_load(i)) { @@ -1381,12 +1381,12 @@ ps1_hdc_close(void *priv) const device_t ps1_hdc_device = { .name = "PS/1 2011 Fixed Disk Controller", .internal_name = "ps1_hdc", - .flags = DEVICE_ISA | DEVICE_PS2, + .flags = DEVICE_ISA, .local = 0, .init = ps1_hdc_init, .close = ps1_hdc_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/machine/m_ps2_isa.c b/src/machine/m_ps2_isa.c index c0c4f7c79..8a2760f15 100644 --- a/src/machine/m_ps2_isa.c +++ b/src/machine/m_ps2_isa.c @@ -64,13 +64,13 @@ ps2_write(uint16_t port, uint8_t val, void *priv) if (val & 0x10) { switch ((val >> 5) & 3) { case 0: - lpt1_init(LPT_MDA_ADDR); + lpt1_setup(LPT_MDA_ADDR); break; case 1: - lpt1_init(LPT1_ADDR); + lpt1_setup(LPT1_ADDR); break; case 2: - lpt1_init(LPT2_ADDR); + lpt1_setup(LPT2_ADDR); break; default: @@ -151,8 +151,7 @@ ps2_isa_setup(int model, int cpu_type) ps2_isa_t *ps2; void *priv; - ps2 = (ps2_isa_t *) malloc(sizeof(ps2_isa_t)); - memset(ps2, 0x00, sizeof(ps2_isa_t)); + ps2 = (ps2_isa_t *) calloc(1, sizeof(ps2_isa_t)); ps2->model = model; ps2->cpu_type = cpu_type; @@ -168,7 +167,7 @@ ps2_isa_setup(int model, int cpu_type) ps2->uart = device_add_inst(&ns16450_device, 1); lpt1_remove(); - lpt1_init(LPT_MDA_ADDR); + lpt1_setup(LPT_MDA_ADDR); device_add(&port_92_device); diff --git a/src/machine/m_ps2_mca.c b/src/machine/m_ps2_mca.c index 632381ca1..d3f881b24 100644 --- a/src/machine/m_ps2_mca.c +++ b/src/machine/m_ps2_mca.c @@ -67,6 +67,8 @@ #include <86box/port_92.h> #include <86box/serial.h> #include <86box/video.h> +#include <86box/vid_svga.h> +#include <86box/vid_vga.h> #include <86box/machine.h> #include <86box/plat_unused.h> @@ -103,6 +105,9 @@ static struct ps2_t { int pending_cache_miss; serial_t *uart; + + vga_t* mb_vga; + int has_e0000_hole; } ps2; /*The model 70 type 3/4 BIOS performs cache testing. Since 86Box doesn't have any @@ -140,7 +145,8 @@ static struct ps2_t { static uint8_t ps2_cache[65536]; static int ps2_cache_valid[65536 / 8]; - +static void mem_encoding_update(void); +// #define ENABLE_PS2_MCA_LOG 1 #ifdef ENABLE_PS2_MCA_LOG int ps2_mca_do_log = ENABLE_PS2_MCA_LOG; @@ -358,6 +364,114 @@ model_80_read(uint16_t port) return 0xff; } +static uint8_t +ps55_model_50t_read(uint16_t port) +{ + ps2_mca_log(" Read SysBrd %04X xx %04X:%04X\n", port, cs >> 4, cpu_state.pc); + switch (port) { + case 0x100: + return ps2.planar_id & 0xff; + case 0x101: + return ps2.planar_id >> 8; + case 0x102: + return ps2.option[0]; + case 0x103: { + uint8_t val = 0xff; + /* + I/O 103h - Bit 7-4: Memory Card ID (Connector 1 or 3) + Bit 3-0: Memory Card ID (Connector 2) + + Memory Card ID: 7h = 2 MB Memory Card 2 or 3 Installed + 5h = 4 MB Memory Card 2 Installed + */ + switch (mem_size / 1024) { + case 2: + if (ps2.option[1] & 0x04) + val = 0xff; + else + val = 0x7f; + break; + case 4: + if (ps2.option[1] & 0x04) + val = 0xff; + else + val = 0x77; + break; + case 6: + if (ps2.option[1] & 0x04) + val = 0x7f; + else + val = 0x77; + break; + case 8: + default: + if (ps2.option[1] & 0x04) + val = 0x5f; + else + val = 0x77; + break; + } + ps2_mca_log(" Read MCA %04X %02X %04X:%04X mem_size = %d, ps2option1 = %2X\n", port, val, cs >> 4, cpu_state.pc, mem_size, ps2.option[1]); + return val; + } case 0x104: + return ps2.option[2]; + case 0x105: + return ps2.option[3]; + case 0x106: + return ps2.subaddr_lo; + case 0x107: + return ps2.subaddr_hi; + } + return 0xff; +} + +static uint8_t +ps55_model_50v_read(uint16_t port) +{ + switch (port) { + case 0x100: + return ps2.planar_id & 0xff; + case 0x101: + return ps2.planar_id >> 8; + case 0x102: + return ps2.option[0]; + case 0x103: { + uint8_t val = 0xff; + /* + I/O 103h - Bit 7-4: Reserved + Bit 3-0: Memory Card ID (Connector 3 or 1) + + Memory Card ID: 8h = 4 MB Memory Card IV Installed + Fh = No Card Installed + */ + switch (mem_size / 1024) { + case 4: + if (ps2.option[1] & 0x04) + val = 0xff; + else + val = 0xf8; + break; + case 8: + default: + if (ps2.option[1] & 0x04) + val = 0xf8; + else + val = 0xf8; + break; + } + return val; + } case 0x104: + /* Reading cache ID (bit 3-2) always returns zero */ + return ps2.option[2] & 0xf3; + case 0x105: + return ps2.option[3]; + case 0x106: + return ps2.subaddr_lo; + case 0x107: + return ps2.subaddr_hi; + } + return 0xff; +} static void model_50_write(uint16_t port, uint8_t val) { @@ -374,13 +488,13 @@ model_50_write(uint16_t port, uint8_t val) if (val & 0x10) { switch ((val >> 5) & 3) { case 0: - lpt1_init(LPT_MDA_ADDR); + lpt1_setup(LPT_MDA_ADDR); break; case 1: - lpt1_init(LPT1_ADDR); + lpt1_setup(LPT1_ADDR); break; case 2: - lpt1_init(LPT2_ADDR); + lpt1_setup(LPT2_ADDR); break; default: @@ -506,13 +620,13 @@ model_55sx_write(uint16_t port, uint8_t val) if (val & 0x10) { switch ((val >> 5) & 3) { case 0: - lpt1_init(LPT_MDA_ADDR); + lpt1_setup(LPT_MDA_ADDR); break; case 1: - lpt1_init(LPT1_ADDR); + lpt1_setup(LPT1_ADDR); break; case 2: - lpt1_init(LPT2_ADDR); + lpt1_setup(LPT2_ADDR); break; default: @@ -565,13 +679,13 @@ model_70_type3_write(uint16_t port, uint8_t val) if (val & 0x10) { switch ((val >> 5) & 3) { case 0: - lpt1_init(LPT_MDA_ADDR); + lpt1_setup(LPT_MDA_ADDR); break; case 1: - lpt1_init(LPT1_ADDR); + lpt1_setup(LPT1_ADDR); break; case 2: - lpt1_init(LPT2_ADDR); + lpt1_setup(LPT2_ADDR); break; default: @@ -619,13 +733,13 @@ model_80_write(uint16_t port, uint8_t val) if (val & 0x10) { switch ((val >> 5) & 3) { case 0: - lpt1_init(LPT_MDA_ADDR); + lpt1_setup(LPT_MDA_ADDR); break; case 1: - lpt1_init(LPT1_ADDR); + lpt1_setup(LPT1_ADDR); break; case 2: - lpt1_init(LPT2_ADDR); + lpt1_setup(LPT2_ADDR); break; default: @@ -655,6 +769,62 @@ model_80_write(uint16_t port, uint8_t val) } } +static void +ps55_model_50tv_write(uint16_t port, uint8_t val) +{ + ps2_mca_log(" Write SysBrd %04X %02X %04X:%04X\n", port, val, cs >> 4, cpu_state.pc); + switch (port) { + case 0x102: + lpt1_remove(); + serial_remove(ps2.uart); + if (val & 0x04) { + if (val & 0x08) + serial_setup(ps2.uart, COM1_ADDR, COM1_IRQ); + else + serial_setup(ps2.uart, COM2_ADDR, COM2_IRQ); + } + if (val & 0x10) { + switch ((val >> 5) & 3) { + case 0: + lpt1_setup(LPT_MDA_ADDR); + break; + case 1: + lpt1_setup(LPT1_ADDR); + break; + case 2: + lpt1_setup(LPT2_ADDR); + break; + default: + break; + } + } + ps2.option[0] = val; + break; + case 0x103: + ps2.option[1] = val; + break; + case 0x104: + if ((ps2.option[2] ^ val) & 1) { + /* Disable/Enable E0000 - E0FFF (Make 2 KB hole for Display Adapter) */ + ps2.option[2] = val; + mem_encoding_update(); + } + ps2.option[2] = val; + break; + case 0x105: + ps2.option[3] = val; + break; + case 0x106: + ps2.subaddr_lo = val; + break; + case 0x107: + ps2.subaddr_hi = val; + break; + default: + break; + } +} + uint8_t ps2_mca_read(uint16_t port, UNUSED(void *priv)) { @@ -772,8 +942,15 @@ ps2_mca_write(uint16_t port, uint8_t val, UNUSED(void *priv)) ps2.setup = val; break; case 0x96: - if ((val & 0x80) && !(ps2.adapter_setup & 0x80)) + if ((val & 0x80) && !(ps2.adapter_setup & 0x80)) { mca_reset(); + if (ps2.has_e0000_hole) { + /* Reset memstate for E0000 - E0FFFh hole (for PS/55 5550-V) + 5550-T does this in POST, but 5550-V doesn't. */ + ps2.option[2] &= 0xFE; + mem_encoding_update(); + } + } ps2.adapter_setup = val; mca_set_index(val & 7); break; @@ -793,7 +970,16 @@ ps2_mca_write(uint16_t port, uint8_t val, UNUSED(void *priv)) if (!(ps2.setup & PS2_SETUP_IO)) ps2.planar_write(port, val); else if (!(ps2.setup & PS2_SETUP_VGA)) + { + if (ps2.mb_vga) + { + if (vga_isenabled(ps2.mb_vga)) + vga_disable(ps2.mb_vga); + if (val & 1) + vga_enable(ps2.mb_vga); + } ps2.pos_vga = val; + } else if (ps2.adapter_setup & PS2_ADAPTER_SETUP) mca_write(port, val); break; @@ -846,7 +1032,7 @@ ps2_mca_board_common_init(void) ps2.setup = 0xff; - lpt1_init(LPT_MDA_ADDR); + lpt1_setup(LPT_MDA_ADDR); } static uint8_t @@ -1117,6 +1303,11 @@ mem_encoding_update(void) ps2_mca_log("PS/2 Model 80-111: Split memory block disabled\n"); } + if (ps2.has_e0000_hole && (ps2.option[2] & 1)) { + /* Set memstate for E0000 - E0FFFh hole (PS/55 only) */ + mem_set_mem_state(0xe0000, 0x1000, MEM_READ_EXTERNAL | MEM_WRITE_EXTERNAL); + } + flushmmucache_nopc(); } @@ -1311,7 +1502,7 @@ ps2_mca_board_model_70_type34_init(int is_type4, int slots) } if (gfxcard[0] == VID_INTERNAL) - device_add(&ps1vga_mca_device); + ps2.mb_vga = device_add(&ps1vga_mca_device); } static void @@ -1385,7 +1576,7 @@ ps2_mca_board_model_80_type2_init(void) } if (gfxcard[0] == VID_INTERNAL) - device_add(&ps1vga_mca_device); + ps2.mb_vga = device_add(&ps1vga_mca_device); ps2.split_size = 0; } @@ -1409,6 +1600,8 @@ machine_ps2_common_init(const machine_t *model) nmi_mask = 0x80; ps2.uart = device_add_inst(&ns16550_device, 1); + + ps2.has_e0000_hole = 0; } int @@ -1576,3 +1769,160 @@ machine_ps2_model_70_type4_init(const machine_t *model) return ret; } + +static void +ps55_mca_board_model_50t_init(void) +{ + ps2_mca_board_common_init(); + + ps2.split_addr = mem_size * 1024; + /* The slot 5 is reserved for the Integrated Fixed Disk II (an internal ESDI hard drive). */ + mca_init(5); + device_add(&keyboard_ps2_mca_1_device); + + ps2.planar_read = ps55_model_50t_read; + ps2.planar_write = ps55_model_50tv_write; + + device_add(&ps2_nvr_device); + + io_sethandler(0x00e0, 0x0002, mem_encoding_read, NULL, NULL, mem_encoding_write, NULL, NULL, NULL); + + ps2.mem_regs[1] = 2; + ps2.option[2] &= 0xfe; /* Bit 0: Disable E0000-E0FFFh (4 KB) */ + ps2.has_e0000_hole = 1; + + mem_mapping_add(&ps2.split_mapping, + (mem_size + 256) * 1024, + 256 * 1024, + ps2_read_split_ram, + ps2_read_split_ramw, + ps2_read_split_raml, + ps2_write_split_ram, + ps2_write_split_ramw, + ps2_write_split_raml, + &ram[0xa0000], + MEM_MAPPING_INTERNAL, + NULL); + mem_mapping_disable(&ps2.split_mapping); + + if (mem_size > 8192) { + /* Only 8 MB supported on planar, create a memory expansion card for the rest */ + ps2_mca_mem_fffc_init(8); + } + + if (gfxcard[0] == VID_INTERNAL) + ps2.mb_vga = (vga_t *)device_add(&ps1vga_mca_device); +} + +static void +ps55_mca_board_model_50v_init(void) +{ + ps2_mca_board_common_init(); + + ps2.split_addr = mem_size * 1024; + /* The slot 5 is reserved for the Integrated Fixed Disk II (an internal ESDI hard drive). */ + mca_init(5); + device_add(&keyboard_ps2_mca_1_device); + + ps2.planar_read = ps55_model_50v_read; + ps2.planar_write = ps55_model_50tv_write; + + device_add(&ps2_nvr_device); + + io_sethandler(0x00e0, 0x0003, mem_encoding_read_cached, NULL, NULL, mem_encoding_write_cached, NULL, NULL, NULL); + + ps2.mem_regs[1] = 2; + ps2.option[2] &= 0xf2; /* Bit 3-2: -Cache IDs, Bit 1: Reserved + Bit 0: Disable E0000-E0FFFh (4 KB) */ + ps2.has_e0000_hole = 1; + + mem_mapping_add(&ps2.split_mapping, + (mem_size + 256) * 1024, + 256 * 1024, + ps2_read_split_ram, + ps2_read_split_ramw, + ps2_read_split_raml, + ps2_write_split_ram, + ps2_write_split_ramw, + ps2_write_split_raml, + &ram[0xa0000], + MEM_MAPPING_INTERNAL, + NULL); + mem_mapping_disable(&ps2.split_mapping); + + mem_mapping_add(&ps2.cache_mapping, + 0, + 64 * 1024, + ps2_read_cache_ram, + ps2_read_cache_ramw, + ps2_read_cache_raml, + ps2_write_cache_ram, + NULL, + NULL, + ps2_cache, + MEM_MAPPING_INTERNAL, + NULL); + mem_mapping_disable(&ps2.cache_mapping); + + if (mem_size > 8192) { + /* Only 8 MB supported on planar, create a memory expansion card for the rest */ + ps2_mca_mem_fffc_init(8); + } + + if (gfxcard[0] == VID_INTERNAL) + ps2.mb_vga = (vga_t *)device_add(&ps1vga_mca_device); +} + +int +machine_ps55_model_50t_init(const machine_t* model) +{ + int ret; + + ret = bios_load_linear("roms/machines/ibmps55_m50t/38F6933.BIN", + 0x000e0000, 131072, 0); + + if (bios_only || !ret) + return ret; + + machine_ps2_common_init(model); + + /* + * Planar ID + * FFFAh - PS/55 model 5551-S0x, T0x (stage 1?) + * FFEEh - PS/55 model 5551-S1x, T1x (stage 2?) + * Verification in BIOS P/N 38F6933: FBxx -> 4 slots (error), xxEE -> 5 slots (ok), others -> 8 (error) + * + * The only difference between S and T models is the CPU speed (16 MHz vs 20 MHz). + * The POST measures the speed, and sets a flag in the BIOS Data Area to indicate the sub model. + * The VM in 86Box runs faster than the real, so the POST always determines it as the T model. + */ + ps2.planar_id = 0xffee; + ps55_mca_board_model_50t_init(); + + return ret; +} + +int +machine_ps55_model_50v_init(const machine_t* model) +{ + int ret; + + ret = bios_load_interleaved("roms/machines/ibmps55_m50v/56F7416.BIN", + "roms/machines/ibmps55_m50v/56F7417.BIN", + 0x000e0000, 131072, 0); + + if (bios_only || !ret) + return ret; + + machine_ps2_common_init(model); + + /* + * Planar ID + * F1FFh - PS/55 model 5551-V0x, V1x + * Verification in BIOS P/N 56F7416,56F7417: FBxx -> 5 slots (ok), F1xx -> 5 slots (ok), others -> 8 (error) + */ + ps2.planar_id = 0xf1ff; + ps55_mca_board_model_50v_init(); + + return ret; +} diff --git a/src/machine/m_tandy.c b/src/machine/m_tandy.c index 11bd41a66..69200febe 100644 --- a/src/machine/m_tandy.c +++ b/src/machine/m_tandy.c @@ -44,12 +44,9 @@ #include <86box/video.h> #include <86box/vid_cga_comp.h> #include <86box/machine.h> +#include <86box/m_tandy.h> #include <86box/plat_unused.h> -enum { - TANDY_RGB = 0, - TANDY_COMPOSITE -}; enum { TYPE_TANDY = 0, @@ -65,80 +62,6 @@ enum { EEPROM_WRITE }; -typedef struct t1kvid_t { - mem_mapping_t mapping; - mem_mapping_t vram_mapping; - - uint8_t crtc[32]; - int crtcreg; - - int array_index; - uint8_t array[256]; - int memctrl; - uint8_t mode; - uint8_t col; - uint8_t stat; - - uint8_t *vram; - uint8_t *b8000; - uint32_t b8000_mask; - uint32_t b8000_limit; - uint8_t planar_ctrl; - uint8_t lp_strobe; - - 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; - uint16_t maback; - - uint64_t dispontime; - uint64_t dispofftime; - pc_timer_t timer; - int firstline; - int lastline; - - int composite; -} t1kvid_t; - -typedef struct t1keep_t { - char *path; - - int state; - int count; - int addr; - int clk; - uint16_t data; - uint16_t store[64]; -} t1keep_t; - -typedef struct tandy_t { - mem_mapping_t ram_mapping; - mem_mapping_t rom_mapping; /* SL2 */ - - uint8_t *rom; /* SL2 */ - uint8_t ram_bank; - uint8_t rom_bank; /* SL2 */ - int rom_offset; /* SL2 */ - - uint32_t base; - uint32_t mask; - int is_hx; - int is_sl2; - - t1kvid_t *vid; -} tandy_t; - -static video_timings_t timing_dram = { VIDEO_BUS, 0, 0, 0, 0, 0, 0 }; /*No additional waitstates*/ static const scancode scancode_tandy[512] = { // clang-format off @@ -656,22 +579,8 @@ static const scancode scancode_tandy[512] = { { .mk = { 0 }, .brk = { 0 } } /* 1ff */ // clang-format on }; -static uint8_t 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 uint8_t crtcmask_sl[32] = { - 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, - 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 eep_data_out; -static uint8_t vid_in(uint16_t addr, void *priv); -static void vid_out(uint16_t addr, uint8_t val, void *priv); +static int eep_data_out; #ifdef ENABLE_TANDY_LOG int tandy_do_log = ENABLE_TANDY_LOG; @@ -691,764 +600,7 @@ tandy_log(const char *fmt, ...) # define tandy_log(fmt, ...) #endif -static void -recalc_mapping(tandy_t *dev) -{ - t1kvid_t *vid = dev->vid; - mem_mapping_disable(&vid->mapping); - io_removehandler(0x03d0, 16, - vid_in, NULL, NULL, vid_out, NULL, NULL, dev); - - if (vid->planar_ctrl & 4) { - mem_mapping_enable(&vid->mapping); - if (vid->array[5] & 1) - mem_mapping_set_addr(&vid->mapping, 0xa0000, 0x10000); - else - mem_mapping_set_addr(&vid->mapping, 0xb8000, 0x8000); - io_sethandler(0x03d0, 16, vid_in, NULL, NULL, vid_out, NULL, NULL, dev); - } -} - -static void -recalc_timings(tandy_t *dev) -{ - t1kvid_t *vid = dev->vid; - - double _dispontime; - double _dispofftime; - double disptime; - - if (vid->mode & 1) { - disptime = vid->crtc[0] + 1; - _dispontime = vid->crtc[1]; - } else { - disptime = (vid->crtc[0] + 1) << 1; - _dispontime = vid->crtc[1] << 1; - } - - _dispofftime = disptime - _dispontime; - _dispontime *= CGACONST; - _dispofftime *= CGACONST; - vid->dispontime = (uint64_t) (_dispontime); - vid->dispofftime = (uint64_t) (_dispofftime); -} - -static void -recalc_address(tandy_t *dev) -{ - t1kvid_t *vid = dev->vid; - - if ((vid->memctrl & 0xc0) == 0xc0) { - vid->vram = &ram[((vid->memctrl & 0x06) << 14) + dev->base]; - vid->b8000 = &ram[((vid->memctrl & 0x30) << 11) + dev->base]; - vid->b8000_mask = 0x7fff; - } else { - vid->vram = &ram[((vid->memctrl & 0x07) << 14) + dev->base]; - vid->b8000 = &ram[((vid->memctrl & 0x38) << 11) + dev->base]; - vid->b8000_mask = 0x3fff; - } -} - -static void -recalc_address_sl(tandy_t *dev) -{ - t1kvid_t *vid = dev->vid; - - vid->b8000_limit = 0x8000; - - if (vid->array[5] & 1) { - vid->vram = &ram[((vid->memctrl & 0x04) << 14) + dev->base]; - vid->b8000 = &ram[((vid->memctrl & 0x20) << 11) + dev->base]; - } else if ((vid->memctrl & 0xc0) == 0xc0) { - vid->vram = &ram[((vid->memctrl & 0x06) << 14) + dev->base]; - vid->b8000 = &ram[((vid->memctrl & 0x30) << 11) + dev->base]; - } else { - vid->vram = &ram[((vid->memctrl & 0x07) << 14) + dev->base]; - vid->b8000 = &ram[((vid->memctrl & 0x38) << 11) + dev->base]; - if ((vid->memctrl & 0x38) == 0x38) - vid->b8000_limit = 0x4000; - } -} - -static void -vid_update_latch(t1kvid_t *vid) -{ - uint32_t lp_latch = vid->displine * vid->crtc[1]; - - vid->crtc[0x10] = (lp_latch >> 8) & 0x3f; - vid->crtc[0x11] = lp_latch & 0xff; -} - -static void -vid_out(uint16_t addr, uint8_t val, void *priv) -{ - tandy_t *dev = (tandy_t *) priv; - t1kvid_t *vid = dev->vid; - uint8_t old; - - if ((addr >= 0x3d0) && (addr <= 0x3d7)) - addr = (addr & 0xff9) | 0x004; - - switch (addr) { - case 0x03d4: - vid->crtcreg = val & 0x1f; - break; - - case 0x03d5: - old = vid->crtc[vid->crtcreg]; - if (dev->is_sl2) - vid->crtc[vid->crtcreg] = val & crtcmask_sl[vid->crtcreg]; - else - vid->crtc[vid->crtcreg] = val & crtcmask[vid->crtcreg]; - if (old != val) { - if (vid->crtcreg < 0xe || vid->crtcreg > 0x10) { - vid->fullchange = changeframecount; - recalc_timings(dev); - } - } - break; - - case 0x03d8: - old = vid->mode; - vid->mode = val; - if ((old ^ val) & 0x01) - recalc_timings(dev); - if (!dev->is_sl2) - update_cga16_color(vid->mode); - break; - - case 0x03d9: - vid->col = val; - break; - - case 0x03da: - vid->array_index = val & 0x1f; - break; - - case 0x3db: - if (!dev->is_sl2 && (vid->lp_strobe == 1)) - vid->lp_strobe = 0; - break; - - case 0x3dc: - if (!dev->is_sl2 && (vid->lp_strobe == 0)) { - vid->lp_strobe = 1; - vid_update_latch(vid); - } - break; - - case 0x03de: - if (vid->array_index & 16) - val &= 0xf; - vid->array[vid->array_index & 0x1f] = val; - if (dev->is_sl2) { - if ((vid->array_index & 0x1f) == 5) { - recalc_mapping(dev); - recalc_address_sl(dev); - } - } - break; - - case 0x03df: - vid->memctrl = val; - if (dev->is_sl2) - recalc_address_sl(dev); - else - recalc_address(dev); - break; - - case 0x0065: - if (val == 8) - return; /*Hack*/ - vid->planar_ctrl = val; - recalc_mapping(dev); - break; - - default: - break; - } -} - -static uint8_t -vid_in(uint16_t addr, void *priv) -{ - const tandy_t *dev = (tandy_t *) priv; - t1kvid_t *vid = dev->vid; - uint8_t ret = 0xff; - - if ((addr >= 0x3d0) && (addr <= 0x3d7)) - addr = (addr & 0xff9) | 0x004; - - switch (addr) { - case 0x03d4: - ret = vid->crtcreg; - break; - - case 0x03d5: - ret = vid->crtc[vid->crtcreg]; - break; - - case 0x03da: - ret = vid->stat; - break; - - case 0x3db: - if (!dev->is_sl2 && (vid->lp_strobe == 1)) - vid->lp_strobe = 0; - break; - - case 0x3dc: - if (!dev->is_sl2 && (vid->lp_strobe == 0)) { - vid->lp_strobe = 1; - vid_update_latch(vid); - } - break; - - default: - break; - } - - return ret; -} - -static void -vid_write(uint32_t addr, uint8_t val, void *priv) -{ - tandy_t *dev = (tandy_t *) priv; - t1kvid_t *vid = dev->vid; - - if (vid->memctrl == -1) - return; - - if (dev->is_sl2) { - if (vid->array[5] & 1) - vid->b8000[addr & 0xffff] = val; - else { - if ((addr & 0x7fff) < vid->b8000_limit) - vid->b8000[addr & 0x7fff] = val; - } - } else { - vid->b8000[addr & vid->b8000_mask] = val; - } -} - -static uint8_t -vid_read(uint32_t addr, void *priv) -{ - const tandy_t *dev = (tandy_t *) priv; - const t1kvid_t *vid = dev->vid; - - if (vid->memctrl == -1) - return 0xff; - - if (dev->is_sl2) { - if (vid->array[5] & 1) - return (vid->b8000[addr & 0xffff]); - if ((addr & 0x7fff) < vid->b8000_limit) - return (vid->b8000[addr & 0x7fff]); - else - return 0xff; - } else { - return (vid->b8000[addr & vid->b8000_mask]); - } -} - -static void -vid_poll(void *priv) -{ - tandy_t *dev = (tandy_t *) priv; - t1kvid_t *vid = dev->vid; - uint16_t ca = (vid->crtc[15] | (vid->crtc[14] << 8)) & 0x3fff; - int drawcursor; - int x; - int c; - int xs_temp; - int ys_temp; - int oldvc; - uint8_t chr; - uint8_t attr; - uint16_t dat; - int cols[4]; - int col; - int oldsc; - - if (!vid->linepos) { - timer_advance_u64(&vid->timer, vid->dispofftime); - vid->stat |= 1; - vid->linepos = 1; - oldsc = vid->sc; - if ((vid->crtc[8] & 3) == 3) - vid->sc = (vid->sc << 1) & 7; - if (vid->dispon) { - if (vid->displine < vid->firstline) { - vid->firstline = vid->displine; - video_wait_for_buffer(); - } - vid->lastline = vid->displine; - 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]; - 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]; - } 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]; - } - } else if ((vid->mode & 0x12) == 0x12) { - 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; - } 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; - } - } else { - 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; - } 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; - } - } - } - if (dev->is_sl2 && (vid->array[5] & 1)) { /*640x200x16*/ - 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; - } - } 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] & 0x0f) + 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] & 0x0f) + 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] & 0x0f) + 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] & 0x0f) + 16] + 16; - } - } else if (vid->array[3] & 0x10) { /*160x200x16*/ - for (x = 0; x < vid->crtc[1]; x++) { - if (dev->is_sl2) { - dat = (vid->vram[((vid->ma << 1) & 0x1fff) + ((vid->sc & 1) * 0x2000)] << 8) | vid->vram[((vid->ma << 1) & 0x1fff) + ((vid->sc & 1) * 0x2000) + 1]; - } else { - 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] & 0x0f) + 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] & 0x0f) + 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] & 0x0f) + 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] & 0x0f) + 16] + 16; - } - } else if (vid->array[3] & 0x08) { /*640x200x4 - this implementation is a complete guess!*/ - 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++; - 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; - dat <<= 1; - } - } - } else if (vid->mode & 1) { - for (x = 0; x < vid->crtc[1]; x++) { - 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->mode & 0x20) { - cols[1] = vid->array[((attr & 15) & vid->array[1]) + 16] + 16; - cols[0] = vid->array[(((attr >> 4) & 7) & vid->array[1]) + 16] + 16; - if ((vid->blink & 16) && (attr & 0x80) && !drawcursor) - cols[1] = cols[0]; - } else { - cols[1] = vid->array[((attr & 15) & vid->array[1]) + 16] + 16; - cols[0] = vid->array[((attr >> 4) & vid->array[1]) + 16] + 16; - } - 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]; - } - } 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]; - } 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]; - } - } - } - if (drawcursor) { - for (c = 0; c < 8; c++) { - buffer32->line[vid->displine << 1][(x << 3) + c + 8] ^= 15; - buffer32->line[(vid->displine << 1) + 1][(x << 3) + c + 8] ^= 15; - } - } - vid->ma++; - } - } else if (!(vid->mode & 2)) { - for (x = 0; x < vid->crtc[1]; x++) { - 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->mode & 0x20) { - cols[1] = vid->array[((attr & 15) & vid->array[1]) + 16] + 16; - cols[0] = vid->array[(((attr >> 4) & 7) & vid->array[1]) + 16] + 16; - if ((vid->blink & 16) && (attr & 0x80) && !drawcursor) - cols[1] = cols[0]; - } else { - cols[1] = vid->array[((attr & 15) & vid->array[1]) + 16] + 16; - cols[0] = vid->array[((attr >> 4) & vid->array[1]) + 16] + 16; - } - 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]; - } 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]; - } 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]; - } - } - } - if (drawcursor) { - for (c = 0; c < 16; c++) { - buffer32->line[vid->displine << 1][(x << 4) + c + 8] ^= 15; - buffer32->line[(vid->displine << 1) + 1][(x << 4) + c + 8] ^= 15; - } - } - } - } else if (!(vid->mode & 16)) { - cols[0] = (vid->col & 15); - col = (vid->col & 16) ? 8 : 0; - if (vid->mode & 4) { - cols[1] = col | 3; - cols[2] = col | 4; - cols[3] = col | 7; - } else if (vid->col & 32) { - cols[1] = col | 3; - cols[2] = col | 5; - cols[3] = col | 7; - } else { - cols[1] = col | 2; - cols[2] = col | 4; - cols[3] = col | 6; - } - cols[0] = vid->array[(cols[0] & vid->array[1]) + 16] + 16; - cols[1] = vid->array[(cols[1] & vid->array[1]) + 16] + 16; - cols[2] = vid->array[(cols[2] & vid->array[1]) + 16] + 16; - cols[3] = vid->array[(cols[3] & vid->array[1]) + 16] + 16; - for (x = 0; x < vid->crtc[1]; x++) { - 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]; - dat <<= 2; - } - } - } else { - cols[0] = 0; - cols[1] = vid->array[(vid->col & vid->array[1]) + 16] + 16; - for (x = 0; x < vid->crtc[1]; x++) { - 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]; - dat <<= 1; - } - } - } - } else { - if (vid->array[3] & 4) { - if (vid->mode & 1) { - hline(buffer32, 0, (vid->displine << 1), (vid->crtc[1] << 3) + 16, (vid->array[2] & 0xf) + 16); - hline(buffer32, 0, (vid->displine << 1) + 1, (vid->crtc[1] << 3) + 16, (vid->array[2] & 0xf) + 16); - } else { - hline(buffer32, 0, (vid->displine << 1), (vid->crtc[1] << 4) + 16, (vid->array[2] & 0xf) + 16); - hline(buffer32, 0, (vid->displine << 1) + 1, (vid->crtc[1] << 4) + 16, (vid->array[2] & 0xf) + 16); - } - } else { - cols[0] = ((vid->mode & 0x12) == 0x12) ? 0 : (vid->col & 0xf) + 16; - if (vid->mode & 1) { - hline(buffer32, 0, (vid->displine << 1), (vid->crtc[1] << 3) + 16, cols[0]); - hline(buffer32, 0, (vid->displine << 1) + 1, (vid->crtc[1] << 3) + 16, cols[0]); - } else { - hline(buffer32, 0, (vid->displine << 1), (vid->crtc[1] << 4) + 16, cols[0]); - hline(buffer32, 0, (vid->displine << 1) + 1, (vid->crtc[1] << 4) + 16, cols[0]); - } - } - } - - if (vid->mode & 1) - x = (vid->crtc[1] << 3) + 16; - 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) + 1]); - } else { - video_process_8(x, vid->displine << 1); - video_process_8(x, (vid->displine << 1) + 1); - } - vid->sc = oldsc; - if (vid->vc == vid->crtc[7] && !vid->sc) - vid->stat |= 8; - vid->displine++; - if (vid->displine >= 360) - vid->displine = 0; - } else { - timer_advance_u64(&vid->timer, vid->dispontime); - if (vid->dispon) - vid->stat &= ~1; - vid->linepos = 0; - if (vid->vsynctime) { - vid->vsynctime--; - if (!vid->vsynctime) - vid->stat &= ~8; - } - if (vid->sc == (vid->crtc[11] & 31) || ((vid->crtc[8] & 3) == 3 && vid->sc == ((vid->crtc[11] & 31) >> 1))) { - vid->con = 0; - vid->coff = 1; - } - if (vid->vadj) { - vid->sc++; - vid->sc &= 31; - vid->ma = vid->maback; - vid->vadj--; - if (!vid->vadj) { - vid->dispon = 1; - if (dev->is_sl2 && (vid->array[5] & 1)) - vid->ma = vid->maback = vid->crtc[13] | (vid->crtc[12] << 8); - else - vid->ma = vid->maback = (vid->crtc[13] | (vid->crtc[12] << 8)) & 0x3fff; - vid->sc = 0; - } - } else if (vid->sc == vid->crtc[9] || ((vid->crtc[8] & 3) == 3 && vid->sc == (vid->crtc[9] >> 1))) { - vid->maback = vid->ma; - vid->sc = 0; - oldvc = vid->vc; - vid->vc++; - if (dev->is_sl2) - vid->vc &= 255; - else - vid->vc &= 127; - if (vid->vc == vid->crtc[6]) - vid->dispon = 0; - if (oldvc == vid->crtc[4]) { - vid->vc = 0; - vid->vadj = vid->crtc[5]; - if (!vid->vadj) - vid->dispon = 1; - if (!vid->vadj) { - if (dev->is_sl2 && (vid->array[5] & 1)) - vid->ma = vid->maback = vid->crtc[13] | (vid->crtc[12] << 8); - else - vid->ma = vid->maback = (vid->crtc[13] | (vid->crtc[12] << 8)) & 0x3fff; - } - if ((vid->crtc[10] & 0x60) == 0x20) - vid->cursoron = 0; - else - vid->cursoron = vid->blink & 16; - } - if (vid->vc == vid->crtc[7]) { - vid->dispon = 0; - vid->displine = 0; - vid->vsynctime = 16; - picint(1 << 5); - if (vid->crtc[7]) { - if (vid->mode & 1) - x = (vid->crtc[1] << 3) + 16; - else - x = (vid->crtc[1] << 4) + 16; - vid->lastline++; - - xs_temp = x; - ys_temp = (vid->lastline - vid->firstline) << 1; - - if ((xs_temp > 0) && (ys_temp > 0)) { - if (xs_temp < 64) - xs_temp = 656; - if (ys_temp < 32) - ys_temp = 400; - if (!enable_overscan) - xs_temp -= 16; - - 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)); - - if (video_force_resize_get()) - video_force_resize_set(0); - } - - if (enable_overscan) { - video_blit_memtoscreen(0, (vid->firstline - 4) << 1, - xsize, ((vid->lastline - vid->firstline) + 8) << 1); - } else { - video_blit_memtoscreen(8, vid->firstline << 1, - xsize, (vid->lastline - vid->firstline) << 1); - } - } - - frames++; - - video_res_x = xsize; - video_res_y = ysize; - if ((vid->array[3] & 0x10) && (vid->mode & 1)) { /*320x200x16*/ - video_res_x /= 2; - video_bpp = 4; - } else if (vid->array[3] & 0x10) { /*160x200x16*/ - video_res_x /= 4; - video_bpp = 4; - } else if (vid->array[3] & 0x08) { /*640x200x4 - this implementation is a complete guess!*/ - video_bpp = 2; - } else if (vid->mode & 1) { - video_res_x /= 8; - video_res_y /= vid->crtc[9] + 1; - video_bpp = 0; - } else if (!(vid->mode & 2)) { - video_res_x /= 16; - video_res_y /= vid->crtc[9] + 1; - video_bpp = 0; - } else if (!(vid->mode & 16)) { - video_res_x /= 2; - video_bpp = 2; - } else { - video_bpp = 1; - } - } - vid->firstline = 1000; - vid->lastline = 0; - vid->blink++; - } - } else { - vid->sc++; - 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))) - vid->con = 1; - } -} - -static void -vid_speed_changed(void *priv) -{ - tandy_t *dev = (tandy_t *) priv; - - recalc_timings(dev); -} - -static void -vid_close(void *priv) -{ - tandy_t *dev = (tandy_t *) priv; - - free(dev->vid); - dev->vid = NULL; -} - -static void -vid_init(tandy_t *dev) -{ - int display_type; - t1kvid_t *vid; - - vid = malloc(sizeof(t1kvid_t)); - memset(vid, 0x00, sizeof(t1kvid_t)); - vid->memctrl = -1; - - video_inform(VIDEO_FLAG_TYPE_CGA, &timing_dram); - - display_type = device_get_config_int("display_type"); - vid->composite = (display_type != TANDY_RGB); - - cga_comp_init(1); - - if (dev->is_sl2) { - vid->b8000_limit = 0x8000; - vid->planar_ctrl = 4; - overscan_x = overscan_y = 16; - - io_sethandler(0x0065, 1, vid_in, NULL, NULL, vid_out, NULL, NULL, dev); - } else - vid->b8000_mask = 0x3fff; - - timer_add(&vid->timer, vid_poll, dev, 1); - mem_mapping_add(&vid->mapping, 0xb8000, 0x08000, - vid_read, NULL, NULL, vid_write, NULL, NULL, NULL, 0, dev); - io_sethandler(0x03d0, 16, - vid_in, NULL, NULL, vid_out, NULL, NULL, dev); - - dev->vid = vid; -} - -const device_config_t vid_config[] = { - // clang-format off - { - .name = "display_type", - .description = "Display type", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = TANDY_RGB, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { .description = "RGB", .value = TANDY_RGB }, - { .description = "Composite", .value = TANDY_COMPOSITE }, - { .description = "" } - } - }, - { .name = "", .description = "", .type = CONFIG_END } - // clang-format on -}; - -const device_t vid_device = { - .name = "Tandy 1000", - .internal_name = "tandy1000_video", - .flags = 0, - .local = 0, - .init = NULL, - .close = vid_close, - .reset = NULL, - { .available = NULL }, - .speed_changed = vid_speed_changed, - .force_redraw = NULL, - .config = vid_config -}; - -const device_t vid_device_hx = { - .name = "Tandy 1000 HX", - .internal_name = "tandy1000_hx_video", - .flags = 0, - .local = 0, - .init = NULL, - .close = vid_close, - .reset = NULL, - { .available = NULL }, - .speed_changed = vid_speed_changed, - .force_redraw = NULL, - .config = vid_config -}; - -const device_t vid_device_sl = { - .name = "Tandy 1000SL2", - .internal_name = "tandy1000_sl_video", - .flags = 0, - .local = 1, - .init = NULL, - .close = vid_close, - .reset = NULL, - { .available = NULL }, - .speed_changed = vid_speed_changed, - .force_redraw = NULL, - .config = NULL -}; static void eep_write(UNUSED(uint16_t addr), uint8_t val, void *priv) @@ -1540,8 +692,7 @@ eep_init(const device_t *info) t1keep_t *eep; FILE *fp = NULL; - eep = (t1keep_t *) malloc(sizeof(t1keep_t)); - memset(eep, 0x00, sizeof(t1keep_t)); + eep = (t1keep_t *) calloc(1, sizeof(t1keep_t)); switch (info->local) { case TYPE_TANDY1000HX: @@ -1592,7 +743,7 @@ static const device_t eep_1000hx_device = { .init = eep_init, .close = eep_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1606,7 +757,7 @@ static const device_t eep_1000sl2_device = { .init = eep_init, .close = eep_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1634,12 +785,12 @@ tandy_write(uint16_t addr, uint8_t val, void *priv) } if (dev->is_hx) { io_removehandler(0x03d0, 16, - vid_in, NULL, NULL, vid_out, NULL, NULL, dev); + tandy_vid_in, NULL, NULL, tandy_vid_out, NULL, NULL, dev); if (val & 0x01) mem_mapping_disable(&dev->vid->mapping); else { io_sethandler(0x03d0, 16, - vid_in, NULL, NULL, vid_out, NULL, NULL, dev); + tandy_vid_in, NULL, NULL, tandy_vid_out, NULL, NULL, dev); mem_mapping_set_addr(&dev->vid->mapping, 0xb8000, 0x8000); } } else { @@ -1658,7 +809,7 @@ tandy_write(uint16_t addr, uint8_t val, void *priv) mem_mapping_set_addr(&dev->ram_mapping, ((val >> 1) & 7) * 128 * 1024, 0x20000); - recalc_address_sl(dev); + tandy_recalc_address_sl(dev); dev->ram_bank = val; break; @@ -1807,10 +958,10 @@ machine_tandy1k_init(const machine_t *model, int type) keyboard_set_table(scancode_tandy); io_sethandler(0x00a0, 1, tandy_read, NULL, NULL, tandy_write, NULL, NULL, dev); - device_context(&vid_device); - vid_init(dev); + device_context(&tandy_1000_video_device); + tandy_vid_init(dev); device_context_restore(); - device_add_ex(&vid_device, dev); + device_add_ex(&tandy_1000_video_device, dev); device_add((type == TYPE_TANDY1000SX) ? &ncr8496_device : &sn76489_device); break; @@ -1819,10 +970,10 @@ machine_tandy1k_init(const machine_t *model, int type) keyboard_set_table(scancode_tandy); io_sethandler(0x00a0, 1, tandy_read, NULL, NULL, tandy_write, NULL, NULL, dev); - device_context(&vid_device_hx); - vid_init(dev); + device_context(&tandy_1000hx_video_device); + tandy_vid_init(dev); device_context_restore(); - device_add_ex(&vid_device_hx, dev); + device_add_ex(&tandy_1000hx_video_device, dev); device_add(&ncr8496_device); device_add(&eep_1000hx_device); break; @@ -1832,10 +983,10 @@ machine_tandy1k_init(const machine_t *model, int type) init_rom(dev); io_sethandler(0xffe8, 8, tandy_read, NULL, NULL, tandy_write, NULL, NULL, dev); - device_context(&vid_device_sl); - vid_init(dev); + device_context(&tandy_1000sl_video_device); + tandy_vid_init(dev); device_context_restore(); - device_add_ex(&vid_device_sl, dev); + device_add_ex(&tandy_1000sl_video_device, dev); device_add(&pssj_device); device_add(&eep_1000sl2_device); break; diff --git a/src/machine/m_xt.c b/src/machine/m_xt.c index db511c332..c94549463 100644 --- a/src/machine/m_xt.c +++ b/src/machine/m_xt.c @@ -39,6 +39,7 @@ #include <86box/keyboard.h> #include <86box/rom.h> #include <86box/machine.h> +#include <86box/nvr.h> #include <86box/chipset.h> #include <86box/port_6x.h> #include <86box/video.h> @@ -61,6 +62,36 @@ machine_xt_common_init(const machine_t *model, int fixed_floppy) static const device_config_t ibmpc_config[] = { // clang-format off + { + .name = "bios", + .description = "BIOS Version", + .type = CONFIG_BIOS, + .default_string = "ibm5150_5700671", + .default_int = 0, + .file_filter = "", + .spinner = { 0 }, + .bios = { + { .name = "5700671 (10/19/81)", .internal_name = "ibm5150_5700671", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 40960, .files = { "roms/machines/ibmpc/BIOS_IBM5150_19OCT81_5700671_U33.BIN", "" } }, + { .name = "5700051 (04/24/81)", .internal_name = "ibm5150_5700051", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 40960, .files = { "roms/machines/ibmpc/BIOS_IBM5150_24APR81_5700051_U33.BIN", "" } }, + + // GlaBIOS for IBM PC + { .name = "GlaBIOS 0.2.5 (8088)", .internal_name = "glabios_025_8088", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 40960, .files = { "roms/machines/glabios/GLABIOS_0.2.5_8P.ROM", "" } }, + { .name = "GlaBIOS 0.2.5 (V20)", .internal_name = "glabios_025_v20", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 40960, .files = { "roms/machines/glabios/GLABIOS_0.2.5_VP.ROM", "" } }, + + // The following are Diagnostic ROMs. + { .name = "Supersoft Diagnostics", .internal_name = "diag_supersoft", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 40960, .files = { "roms/machines/diagnostic/Supersoft_PCXT_8KB.bin", "" } }, + { .name = "Ruud's Diagnostic Rom", .internal_name = "diag_ruuds", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 40960, .files = { "roms/machines/diagnostic/ruuds_diagnostic_rom_v5.4_8kb.bin", "" } }, + { .name = "XT RAM Test", .internal_name = "diag_xtramtest", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 40960, .files = { "roms/machines/diagnostic/xtramtest_8k.bin", "" } }, + { .files_no = 0 } + }, + }, { .name = "enable_5161", .description = "IBM 5161 Expansion Unit", @@ -78,7 +109,7 @@ static const device_config_t ibmpc_config[] = { }; const device_t ibmpc_device = { - .name = "IBM PC (1981) Device", + .name = "IBM PC (1981)", .internal_name = "ibmpc_device", .flags = 0, .local = 0, @@ -94,27 +125,36 @@ const device_t ibmpc_device = { int machine_pc_init(const machine_t *model) { - int ret; - uint8_t enable_5161; - uint8_t enable_basic; + int ret = 0; + int ret2; + uint8_t enable_5161; + uint8_t enable_basic; + const char *fn; + + /* No ROMs available. */ + if (!device_available(model->device)) + return ret; device_context(model->device); enable_5161 = machine_get_config_int("enable_5161"); enable_basic = machine_get_config_int("enable_basic"); + fn = device_get_bios_file(model->device, device_get_config_bios("bios"), 0); + ret = bios_load_linear(fn, 0x000fe000, 40960, 0); device_context_restore(); - ret = bios_load_linear("roms/machines/ibmpc/BIOS_5150_24APR81_U33.BIN", - 0x000fe000, 40960, 0); - if (enable_basic && ret) { - bios_load_aux_linear("roms/machines/ibmpc/IBM 5150 - Cassette BASIC version C1.00 - U29 - 5700019.bin", - 0x000f6000, 8192, 0); - bios_load_aux_linear("roms/machines/ibmpc/IBM 5150 - Cassette BASIC version C1.00 - U30 - 5700027.bin", - 0x000f8000, 8192, 0); - bios_load_aux_linear("roms/machines/ibmpc/IBM 5150 - Cassette BASIC version C1.00 - U31 - 5700035.bin", - 0x000fa000, 8192, 0); - bios_load_aux_linear("roms/machines/ibmpc/IBM 5150 - Cassette BASIC version C1.00 - U32 - 5700043.bin", - 0x000fc000, 8192, 0); + ret2 = bios_load_aux_linear("roms/machines/ibmpc/ibm-basic-1.00.rom", + 0x000f6000, 32768, 0); + if (!ret2) { + bios_load_aux_linear("roms/machines/ibmpc/IBM 5150 - Cassette BASIC version C1.00 - U29 - 5700019.bin", + 0x000f6000, 8192, 0); + bios_load_aux_linear("roms/machines/ibmpc/IBM 5150 - Cassette BASIC version C1.00 - U30 - 5700027.bin", + 0x000f8000, 8192, 0); + bios_load_aux_linear("roms/machines/ibmpc/IBM 5150 - Cassette BASIC version C1.00 - U31 - 5700035.bin", + 0x000fa000, 8192, 0); + bios_load_aux_linear("roms/machines/ibmpc/IBM 5150 - Cassette BASIC version C1.00 - U32 - 5700043.bin", + 0x000fc000, 8192, 0); + } } if (bios_only || !ret) @@ -145,11 +185,18 @@ static const device_config_t ibmpc82_config[] = { .files_no = 1, .local = 0, .size = 40960, .files = { "roms/machines/ibmpc82/BIOS_5150_27OCT82_1501476_U33.BIN", "" } }, { .name = "5000024 (08/16/82)", .internal_name = "ibm5150_5000024", .bios_type = BIOS_NORMAL, .files_no = 1, .local = 0, .size = 40960, .files = { "roms/machines/ibmpc82/BIOS_5150_16AUG82_5000024_U33.BIN", "" } }, + + // GlaBIOS for IBM PC + { .name = "GlaBIOS 0.2.5 (8088)", .internal_name = "glabios_025_8088", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 40960, .files = { "roms/machines/glabios/GLABIOS_0.2.5_8P.ROM", "" } }, + { .name = "GlaBIOS 0.2.5 (V20)", .internal_name = "glabios_025_v20", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 40960, .files = { "roms/machines/glabios/GLABIOS_0.2.5_VP.ROM", "" } }, + // The following are Diagnostic ROMs. { .name = "Supersoft Diagnostics", .internal_name = "diag_supersoft", .bios_type = BIOS_NORMAL, .files_no = 1, .local = 0, .size = 40960, .files = { "roms/machines/diagnostic/Supersoft_PCXT_8KB.bin", "" } }, { .name = "Ruud's Diagnostic Rom", .internal_name = "diag_ruuds", .bios_type = BIOS_NORMAL, - .files_no = 1, .local = 0, .size = 40960, .files = { "roms/machines/diagnostic/ruuds_diagnostic_rom_v5.3_8kb.bin", "" } }, + .files_no = 1, .local = 0, .size = 40960, .files = { "roms/machines/diagnostic/ruuds_diagnostic_rom_v5.4_8kb.bin", "" } }, { .name = "XT RAM Test", .internal_name = "diag_xtramtest", .bios_type = BIOS_NORMAL, .files_no = 1, .local = 0, .size = 40960, .files = { "roms/machines/diagnostic/xtramtest_8k.bin", "" } }, { .files_no = 0 } @@ -172,7 +219,7 @@ static const device_config_t ibmpc82_config[] = { }; const device_t ibmpc82_device = { - .name = "IBM PC (1982) Devices", + .name = "IBM PC (1982)", .internal_name = "ibmpc82_device", .flags = 0, .local = 0, @@ -192,7 +239,7 @@ machine_pc82_init(const machine_t *model) int ret2; uint8_t enable_5161; uint8_t enable_basic; - const char* fn; + const char *fn; /* No ROMs available. */ if (!device_available(model->device)) @@ -209,13 +256,13 @@ machine_pc82_init(const machine_t *model) ret2 = bios_load_aux_linear("roms/machines/ibmpc82/ibm-basic-1.10.rom", 0x000f6000, 32768, 0); if (!ret2) { - bios_load_aux_linear("roms/machines/ibmpc82/basicc11.f6", + bios_load_aux_linear("roms/machines/ibmpc82/IBM 5150 - Cassette BASIC version C1.10 - U29 - 5000019.bin", 0x000f6000, 8192, 0); - bios_load_aux_linear("roms/machines/ibmpc82/basicc11.f8", + bios_load_aux_linear("roms/machines/ibmpc82/IBM 5150 - Cassette BASIC version C1.10 - U30 - 5000021.bin", 0x000f8000, 8192, 0); - bios_load_aux_linear("roms/machines/ibmpc82/basicc11.fa", + bios_load_aux_linear("roms/machines/ibmpc82/IBM 5150 - Cassette BASIC version C1.10 - U31 - 5000022.bin", 0x000fa000, 8192, 0); - bios_load_aux_linear("roms/machines/ibmpc82/basicc11.fc", + bios_load_aux_linear("roms/machines/ibmpc82/IBM 5150 - Cassette BASIC version C1.10 - U32 - 5000023.bin", 0x000fc000, 8192, 0); } } @@ -236,9 +283,103 @@ machine_pc82_init(const machine_t *model) static const device_config_t ibmxt_config[] = { // clang-format off { - .name = "enable_5161", + .name = "bios", + .description = "BIOS Version", + .type = CONFIG_BIOS, + .default_string = "ibm5160_1501512_5000027", + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .bios = { + { + .name = "1501512 (11/08/82)", + .internal_name = "ibm5160_1501512_5000027", + .bios_type = BIOS_NORMAL, + .files_no = 2, + .local = 0, + .size = 65536, + .files = { "roms/machines/ibmxt/BIOS_5160_08NOV82_U18_1501512.BIN", "roms/machines/ibmxt/BIOS_5160_08NOV82_U19_5000027.BIN", "" } + }, + { + .name = "1501512 (11/08/82) (Alt)", + .internal_name = "ibm5160_1501512_6359116", + .bios_type = BIOS_NORMAL, + .files_no = 2, + .local = 0, + .size = 65536, + .files = { "roms/machines/ibmxt/BIOS_5160_08NOV82_U18_1501512.BIN", "roms/machines/ibmxt/BIOS_5160_08NOV82_U19_6359116.BIN", "" } + }, + { + .name = "5000026 (08/16/82)", + .internal_name = "ibm5160_5000026_5000027", + .bios_type = BIOS_NORMAL, + .files_no = 2, + .local = 0, + .size = 65536, + .files = { "roms/machines/ibmxt/BIOS_5160_16AUG82_U18_5000026.BIN", "roms/machines/ibmxt/BIOS_5160_16AUG82_U19_5000027.BIN", "" } + }, + + // GlaBIOS for IBM XT + { + .name = "GlaBIOS 0.2.5 (8088)", + .internal_name = "glabios_025_8088", + .bios_type = BIOS_NORMAL, + .files_no = 2, + .local = 1, + .size = 40960, + .files = { "roms/machines/glabios/GLABIOS_0.2.5_8X.ROM", "roms/machines/ibmxt/BIOS_5160_08NOV82_U19_5000027.BIN", "" } + }, + { + .name = "GlaBIOS 0.2.5 (V20)", + .internal_name = "glabios_025_v20", + .bios_type = BIOS_NORMAL, + .files_no = 2, + .local = 1, + .size = 40960, + .files = { "roms/machines/glabios/GLABIOS_0.2.5_VX.ROM", "roms/machines/ibmxt/BIOS_5160_08NOV82_U19_5000027.BIN", "" } + }, + + // The following are Diagnostic ROMs. + { + .name = "Supersoft Diagnostics", + .internal_name = "diag_supersoft", + .bios_type = BIOS_NORMAL, + .files_no = 2, + .local = 2, + .size = 65536, + .files = { "roms/machines/diagnostic/Supersoft_PCXT_32KB.bin", "roms/machines/ibmxt/BIOS_5160_08NOV82_U19_5000027.BIN", "" } + }, + { + .name = "Ruud's Diagnostic Rom", + .internal_name = "diag_ruuds", + .bios_type = BIOS_NORMAL, + .files_no = 2, + .local = 2, + .size = 65536, + .files = { "roms/machines/diagnostic/ruuds_diagnostic_rom_v5.4_32kb.bin", "roms/machines/ibmxt/BIOS_5160_08NOV82_U19_5000027.BIN", "" } + }, + { + .name = "XT RAM Test", + .internal_name = "diag_xtramtest", + .bios_type = BIOS_NORMAL, + .files_no = 2, + .local = 2, + .size = 65536, + .files = { "roms/machines/diagnostic/xtramtest_32k.bin", "roms/machines/ibmxt/BIOS_5160_08NOV82_U19_5000027.BIN", "" } + }, + { .files_no = 0 } + }, + }, + { + .name = "enable_5161", .description = "IBM 5161 Expansion Unit", - .type = CONFIG_BINARY, + .type = CONFIG_BINARY, + .default_int = 1 + }, + { + .name = "enable_basic", + .description = "IBM Cassette Basic", + .type = CONFIG_BINARY, .default_int = 1 }, { .name = "", .description = "", .type = CONFIG_END } @@ -246,7 +387,7 @@ static const device_config_t ibmxt_config[] = { }; const device_t ibmxt_device = { - .name = "IBM XT (1982) Device", + .name = "IBM XT (1982)", .internal_name = "ibmxt_device", .flags = 0, .local = 0, @@ -262,26 +403,40 @@ const device_t ibmxt_device = { int machine_xt_init(const machine_t *model) { - int ret; - uint8_t enable_5161; - uint8_t enable_basic; + int ret = 0; + uint8_t enable_5161; + uint8_t enable_basic; + const char *fn; + uint16_t offset = 0; + uint32_t local = 0; + + /* No ROMs available. */ + if (!device_available(model->device)) + return ret; device_context(model->device); enable_5161 = machine_get_config_int("enable_5161"); - device_context_restore(); + enable_basic = machine_get_config_int("enable_basic"); + fn = device_get_bios_file(model->device, device_get_config_bios("bios"), 0); + local = device_get_bios_local(model->device, device_get_config_bios("bios")); + + if (local == 0) // Offset for stock roms + offset = 0x6000; + ret = bios_load_linear(fn, 0x000fe000, 65536, offset); - ret = bios_load_linear("roms/machines/ibmxt/xt.rom", - 0x000f0000, 65536, 0); - if (!ret) { - ret = bios_load_linear("roms/machines/ibmxt/1501512.u18", - 0x000fe000, 65536, 0x6000); - if (ret) { - bios_load_aux_linear("roms/machines/ibmxt/1501512.u18", - 0x000f8000, 24576, 0); - bios_load_aux_linear("roms/machines/ibmxt/5000027.u19", - 0x000f0000, 32768, 0); + if (enable_basic && ret) { + if (local == 0) { // needed for stock roms + fn = device_get_bios_file(model->device, device_get_config_bios("bios"), 0); + (void) bios_load_aux_linear(fn, 0x000f8000, 24576, 0); } + fn = device_get_bios_file(model->device, device_get_config_bios("bios"), 1); + /* On the real machine, the BASIC is repeated. */ + (void) bios_load_aux_linear(fn, 0x000f0000, 8192, 0); + (void) bios_load_aux_linear(fn, 0x000f2000, 8192, 0); + (void) bios_load_aux_linear(fn, 0x000f4000, 8192, 0); + (void) bios_load_aux_linear(fn, 0x000f6000, 8192, 0); } + device_context_restore(); if (bios_only || !ret) return ret; @@ -317,9 +472,98 @@ machine_genxt_init(const machine_t *model) static const device_config_t ibmxt86_config[] = { // clang-format off { - .name = "enable_5161", + .name = "bios", + .description = "BIOS Version", + .type = CONFIG_BIOS, + .default_string = "ibm5160_050986", + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .bios = { + { + .name = "1501512 (05/09/86)", + .internal_name = "ibm5160_050986", + .bios_type = BIOS_NORMAL, + .files_no = 2, + .local = 0, + .size = 65536, + .files = { "roms/machines/ibmxt86/BIOS_5160_09MAY86_U18_59X7268_62X0890_27256_F800.BIN", "roms/machines/ibmxt86/BIOS_5160_09MAY86_U19_62X0819_68X4370_27256_F000.BIN", "" } + }, + { + .name = "5000026 (01/10/86)", + .internal_name = "ibm5160_011086", + .bios_type = BIOS_NORMAL, + .files_no = 2, + .local = 0, + .size = 65536, + .files = { "roms/machines/ibmxt86/BIOS_5160_10JAN86_U18_62X0851_27256_F800.BIN", "roms/machines/ibmxt86/BIOS_5160_10JAN86_U19_62X0854_27256_F000.BIN", "" } + }, + { + .name = "1501512 (01/10/86) (Alt)", + .internal_name = "ibm5160_011086_alt", + .bios_type = BIOS_NORMAL, + .files_no = 2, + .local = 0, + .size = 65536, + .files = { "roms/machines/ibmxt86/BIOS_5160_10JAN86_U18_62X0852_27256_F800.BIN", "roms/machines/ibmxt86/BIOS_5160_10JAN86_U19_62X0853_27256_F000.BIN", "" } + }, + + // GlaBIOS for IBM XT + { + .name = "GlaBIOS 0.2.5 (8088)", + .internal_name = "glabios_025_8088", + .bios_type = BIOS_NORMAL, + .files_no = 2, + .local = 1, + .size = 65536, + .files = { "roms/machines/glabios/GLABIOS_0.2.5_8X.ROM", "roms/machines/ibmxt86/BIOS_5160_09MAY86_U19_62X0819_68X4370_27256_F000.BIN", "" } + }, + { + .name = "GlaBIOS 0.2.5 (V20)", + .internal_name = "glabios_025_v20", + .bios_type = BIOS_NORMAL, + .files_no = 2, + .local = 1, + .size = 65536, + .files = { "roms/machines/glabios/GLABIOS_0.2.5_VX.ROM", "roms/machines/ibmxt86/BIOS_5160_09MAY86_U19_62X0819_68X4370_27256_F000.BIN", "" } + }, + + // The following are Diagnostic ROMs. + { + .name = "Supersoft Diagnostics", + .internal_name = "diag_supersoft", + .bios_type = BIOS_NORMAL, + .files_no = 2, + .local = 2, + .size = 65536, + .files = { "roms/machines/diagnostic/Supersoft_PCXT_32KB.bin", "roms/machines/ibmxt86/BIOS_5160_09MAY86_U19_62X0819_68X4370_27256_F000.BIN", "" } + }, + { + .name = "Ruud's Diagnostic Rom", + .internal_name = "diag_ruuds", + .bios_type = BIOS_NORMAL, + .files_no = 2, + .local = 2, + .size = 65536, + .files = { "roms/machines/diagnostic/ruuds_diagnostic_rom_v5.4_32kb.bin", "roms/machines/ibmxt86/BIOS_5160_09MAY86_U19_62X0819_68X4370_27256_F000.BIN", "" } + }, + { + .name = "XT RAM Test", + .internal_name = "diag_xtramtest", + .bios_type = BIOS_NORMAL, + .files_no = 2, + .local = 2, + .size = 65536, + .files = { "roms/machines/diagnostic/xtramtest_32k.bin", "roms/machines/ibmxt86/BIOS_5160_09MAY86_U19_62X0819_68X4370_27256_F000.BIN", "" } + }, + + { .files_no = 0 } + }, + }, + { + .name = "enable_5161", .description = "IBM 5161 Expansion Unit", - .type = CONFIG_BINARY, + .type = CONFIG_BINARY, .default_int = 1 }, { .name = "", .description = "", .type = CONFIG_END } @@ -327,7 +571,7 @@ static const device_config_t ibmxt86_config[] = { }; const device_t ibmxt86_device = { - .name = "IBM XT (1986) Device", + .name = "IBM XT (1986)", .internal_name = "ibmxt86_device", .flags = 0, .local = 0, @@ -343,21 +587,34 @@ const device_t ibmxt86_device = { int machine_xt86_init(const machine_t *model) { - int ret; - uint8_t enable_5161; + int ret = 0; + uint8_t enable_5161; + const char *fn; + uint16_t offset = 0; + uint32_t local = 0; + + /* No ROMs available. */ + if (!device_available(model->device)) + return ret; device_context(model->device); enable_5161 = machine_get_config_int("enable_5161"); - device_context_restore(); + fn = device_get_bios_file(model->device, device_get_config_bios("bios"), 0); + local = device_get_bios_local(model->device, device_get_config_bios("bios")); + + if (local == 0) // Offset for stock roms + offset = 0x6000; + ret = bios_load_linear(fn, 0x000fe000, 65536, offset); - ret = bios_load_linear("roms/machines/ibmxt86/BIOS_5160_09MAY86_U18_59X7268_62X0890_27256_F800.BIN", - 0x000fe000, 65536, 0x6000); if (ret) { - (void) bios_load_aux_linear("roms/machines/ibmxt86/BIOS_5160_09MAY86_U18_59X7268_62X0890_27256_F800.BIN", - 0x000f8000, 24576, 0); - (void) bios_load_aux_linear("roms/machines/ibmxt86/BIOS_5160_09MAY86_U19_62X0819_68X4370_27256_F000.BIN", - 0x000f0000, 32768, 0); + if (local == 0) { // needed for stock roms + fn = device_get_bios_file(model->device, device_get_config_bios("bios"), 0); + (void) bios_load_aux_linear(fn, 0x000f8000, 24576, 0); + } + fn = device_get_bios_file(model->device, device_get_config_bios("bios"), 1); + (void) bios_load_aux_linear(fn, 0x000f0000, 32768, 0); } + device_context_restore(); if (bios_only || !ret) return ret; @@ -412,6 +669,34 @@ machine_xt_amixt_init(const machine_t *model) return ret; } +int +machine_xt_tuliptc8_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/tuliptc8/tulip-bios_xt_compact_2.bin", + 0x000fc000, 16384, 0); + + if (bios_only || !ret) + return ret; + + device_add(&keyboard_xt_fe2010_device); + + if (fdc_current[0] == FDC_INTERNAL) + device_add(&fdc_at_device); + + machine_common_init(model); + + pit_devs[0].set_out_func(pit_devs[0].data, 1, pit_refresh_timer_xt); + + nmi_init(); + standalone_gameport_type = &gameport_device; + + device_add(&amstrad_megapc_nvr_device); + + return ret; +} + // TODO // Onboard EGA Graphics (NSI Logic EVC315-S on early boards STMicroelectronics EGA on later revisions) // RTC @@ -469,13 +754,59 @@ machine_xt_dtk_init(const machine_t *model) return ret; } +static const device_config_t jukopc_config[] = { + // clang-format off + { + .name = "bios", + .description = "BIOS Version", + .type = CONFIG_BIOS, + .default_string = "jukost", + .default_int = 0, + .file_filter = "", + .spinner = { 0 }, + .bios = { + { .name = "Bios 2.30", .internal_name = "jukost", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 8192, .files = { "roms/machines/jukopc/000o001.bin", "" } }, + // GlaBIOS for Juko ST + { .name = "GlaBIOS 0.2.5 (8088)", .internal_name = "glabios_025_8088", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 8192, .files = { "roms/machines/glabios/GLABIOS_0.2.5_8S_2.ROM", "" } }, + { .name = "GlaBIOS 0.2.5 (V20)", .internal_name = "glabios_025_v20", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 8192, .files = { "roms/machines/glabios/GLABIOS_0.2.5_VS_2.ROM", "" } }, + { .files_no = 0 } + }, + }, + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on +}; + +const device_t jukopc_device = { + .name = "Juko ST", + .internal_name = "jukopc_device", + .flags = 0, + .local = 0, + .init = NULL, + .close = NULL, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = jukopc_config +}; + int machine_xt_jukopc_init(const machine_t *model) { - int ret; + int ret = 0; + const char *fn; - ret = bios_load_linear("roms/machines/jukopc/000o001.bin", - 0x000fe000, 8192, 0); + /* No ROMs available. */ + if (!device_available(model->device)) + return ret; + + device_context(model->device); + fn = device_get_bios_file(model->device, device_get_config_bios("bios"), 0); + ret = bios_load_linear(fn, 0x000fe000, 8192, 0); + device_context_restore(); if (bios_only || !ret) return ret; @@ -748,18 +1079,63 @@ machine_xt_pc500_init(const machine_t *model) return ret; } +static const device_config_t vendex_config[] = { + // clang-format off + { + .name = "bios", + .description = "BIOS Version", + .type = CONFIG_BIOS, + .default_string = "vendex", + .default_int = 0, + .file_filter = "", + .spinner = { 0 }, + .bios = { + { .name = "Bios 2.03C", .internal_name = "vendex", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 16384, .files = { "roms/machines/vendex/Vendex Turbo 888 XT - ROM BIOS - VER 2.03C.bin", "" } }, + // GlaBIOS for Juko ST + { .name = "GlaBIOS 0.2.5 (8088)", .internal_name = "glabios_025_8088", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 16384, .files = { "roms/machines/glabios/GLABIOS_0.2.5_8TV.ROM", "" } }, + { .name = "GlaBIOS 0.2.5 (V20)", .internal_name = "glabios_025_v20", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 16384, .files = { "roms/machines/glabios/GLABIOS_0.2.5_VTV.ROM", "" } }, + { .files_no = 0 } + }, + }, + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on +}; + +const device_t vendex_device = { + .name = "Vendex 888T", + .internal_name = "vendex_device", + .flags = 0, + .local = 0, + .init = NULL, + .close = NULL, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = vendex_config +}; + int machine_xt_vendex_init(const machine_t *model) { - int ret; + int ret = 0; + const char *fn; - ret = bios_load_linear("roms/machines/vendex/Vendex Turbo 888 XT - ROM BIOS - VER 2.03C.bin", - 0x000fc000, 16384, 0); + /* No ROMs available. */ + if (!device_available(model->device)) + return ret; + + device_context(model->device); + fn = device_get_bios_file(model->device, device_get_config_bios("bios"), 0); + ret = bios_load_linear(fn, 0x000fc000, 16384, 0); + device_context_restore(); if (bios_only || !ret) return ret; - /* On-board FDC cannot be disabled */ machine_xt_clone_init(model, 1); device_add(&vendex_xt_rtc_onboard_device); diff --git a/src/machine/m_xt_compaq.c b/src/machine/m_xt_compaq.c index ed1b3e26c..f8c0b6a19 100644 --- a/src/machine/m_xt_compaq.c +++ b/src/machine/m_xt_compaq.c @@ -59,7 +59,7 @@ machine_xt_compaq_deskpro_init(const machine_t *model) standalone_gameport_type = &gameport_device; lpt1_remove(); - lpt1_init(LPT_MDA_ADDR); + lpt1_setup(LPT_MDA_ADDR); return ret; } @@ -87,7 +87,7 @@ machine_xt_compaq_portable_init(const machine_t *model) device_add(&gameport_device); lpt1_remove(); - lpt1_init(LPT_MDA_ADDR); + lpt1_setup(LPT_MDA_ADDR); return ret; } diff --git a/src/machine/m_xt_laserxt.c b/src/machine/m_xt_laserxt.c index 877d26ff5..7a6cab5e3 100644 --- a/src/machine/m_xt_laserxt.c +++ b/src/machine/m_xt_laserxt.c @@ -1,6 +1,7 @@ /*This is the chipset used in the LaserXT series model*/ #include #include +#include #include #include #include <86box/86box.h> @@ -21,125 +22,437 @@ #include <86box/keyboard.h> #include <86box/plat_unused.h> -static int laserxt_emspage[4]; -static int laserxt_emscontrol[4]; -static mem_mapping_t laserxt_ems_mapping[4]; -static int laserxt_ems_baseaddr_index = 0; -static int laserxt_is_lxt3 = 0; +#define EMS_TOTAL_MAX 0x00100000 -static uint32_t -get_laserxt_ems_addr(uint32_t addr) +typedef struct { - if (laserxt_emspage[(addr >> 14) & 3] & 0x80) { - addr = (!laserxt_is_lxt3 ? 0x70000 + (((mem_size + 64) & 255) << 10) : 0x30000 + (((mem_size + 320) & 511) << 10)) + ((laserxt_emspage[(addr >> 14) & 3] & 0x0F) << 14) + ((laserxt_emspage[(addr >> 14) & 3] & 0x40) << 12) + (addr & 0x3FFF); - } + uint8_t page; + uint8_t ctrl; - return addr; + uint32_t phys; + uint32_t virt; + + mem_mapping_t mapping; + + uint8_t *ram; + + void *parent; +} lxt_ems_t; + +typedef struct +{ + int ems_base_idx; + + lxt_ems_t ems[4]; + + uint16_t io_base; + uint32_t base; + + uint32_t mem_size; + + uint8_t *ram; + + void *parent; +} lxt_ems_board_t; + +typedef struct +{ + int is_lxt3; + + lxt_ems_board_t *ems_boards[2]; +} lxt_t; + +static void +ems_update_virt(lxt_ems_t *dev, uint8_t new_page) +{ + lxt_ems_board_t *board = (lxt_ems_board_t *) dev->parent; + lxt_t *lxt = (lxt_t *) board->parent; + + dev->page = new_page; + + if (new_page & 0x80) { + if (lxt->is_lxt3) { + /* Point invalid pages at 1 MB which is outside the maximum. */ + if ((new_page & 0x7f) >= 0x40) + dev->virt = EMS_TOTAL_MAX; + else + dev->virt = ((new_page & 0x7f) << 14); + } else + dev->virt = ((new_page & 0x0f) << 14) + ((new_page & 0x40) << 12); + + if (dev->virt >= board->mem_size) + dev->virt = EMS_TOTAL_MAX; + } else + dev->virt = EMS_TOTAL_MAX; + + dev->ram = board->ram + dev->virt; + + if ((new_page & 0x80) && (dev->virt != EMS_TOTAL_MAX)) { + mem_mapping_enable(&dev->mapping); + + mem_mapping_set_exec(&dev->mapping, dev->ram); + mem_mapping_set_p(&dev->mapping, dev->ram); + } else + mem_mapping_disable(&dev->mapping); + + flushmmucache(); } static void -laserxt_write(uint16_t port, uint8_t val, UNUSED(void *priv)) +lxt_ems_out(uint16_t port, uint8_t val, void *priv) { - uint32_t paddr; - uint32_t vaddr; - switch (port) { - case 0x0208: - case 0x4208: - case 0x8208: - case 0xC208: - laserxt_emspage[port >> 14] = val; - paddr = 0xC0000 + (port & 0xC000) + (((laserxt_ems_baseaddr_index + (4 - (port >> 14))) & 0x0C) << 14); - if (val & 0x80) { - mem_mapping_enable(&laserxt_ems_mapping[port >> 14]); - vaddr = get_laserxt_ems_addr(paddr); - mem_mapping_set_exec(&laserxt_ems_mapping[port >> 14], ram + vaddr); - } else { - mem_mapping_disable(&laserxt_ems_mapping[port >> 14]); - } - flushmmucache(); - break; - case 0x0209: - case 0x4209: - case 0x8209: - case 0xC209: - laserxt_emscontrol[port >> 14] = val; - laserxt_ems_baseaddr_index = 0; + lxt_ems_board_t *dev = (lxt_ems_board_t *) priv; + uint8_t reg = port >> 14; + uint32_t saddrs[8] = { 0xc4000, 0xc8000, 0xcc000, 0xd0000, + 0xd4000, 0xd8000, 0xdc000, 0xe0000 }; + uint32_t saddr; + + if (port & 0x0001) { + dev->ems[reg].ctrl = val; + + if (reg < 0x03) { + dev->ems_base_idx = (dev->ems_base_idx & ~(0x04 >> (2 - reg))) | + ((dev->ems[reg].ctrl & 0x80) >> (7 - reg)); + + saddr = saddrs[dev->ems_base_idx]; + for (uint8_t i = 0; i < 4; i++) { - laserxt_ems_baseaddr_index |= (laserxt_emscontrol[i] & 0x80) >> (7 - i); + uint32_t base = saddr + (i * 0x4000); + mem_mapping_set_addr(&dev->ems[i].mapping, base, 0x4000); + if (!(dev->ems[i].page & 0x80) || (dev->ems[i].virt == EMS_TOTAL_MAX)) + mem_mapping_disable(&dev->ems[i].mapping); } + } - mem_mapping_set_addr(&laserxt_ems_mapping[0], 0xC0000 + (((laserxt_ems_baseaddr_index + 4) & 0x0C) << 14), 0x4000); - mem_mapping_set_addr(&laserxt_ems_mapping[1], 0xC4000 + (((laserxt_ems_baseaddr_index + 3) & 0x0C) << 14), 0x4000); - mem_mapping_set_addr(&laserxt_ems_mapping[2], 0xC8000 + (((laserxt_ems_baseaddr_index + 2) & 0x0C) << 14), 0x4000); - mem_mapping_set_addr(&laserxt_ems_mapping[3], 0xCC000 + (((laserxt_ems_baseaddr_index + 1) & 0x0C) << 14), 0x4000); - flushmmucache(); - break; - - default: - break; + flushmmucache(); + } else if (!(port & 0x0001)) { + dev->ems[reg].page = val; + ems_update_virt(&dev->ems[reg], val); } } static uint8_t -laserxt_read(uint16_t port, UNUSED(void *priv)) +lxt_ems_in(uint16_t port, void *priv) { - switch (port) { - case 0x0208: - case 0x4208: - case 0x8208: - case 0xC208: - return laserxt_emspage[port >> 14]; - case 0x0209: - case 0x4209: - case 0x8209: - case 0xC209: - return laserxt_emscontrol[port >> 14]; + lxt_ems_board_t *dev = (lxt_ems_board_t *) priv; + uint8_t reg = port >> 14; + uint8_t ret = 0xff; - default: - break; - } - return 0xff; + if (port & 0x0001) + ret = dev->ems[reg].ctrl; + else + ret = dev->ems[reg].page; + + return ret; } static void -mem_write_laserxtems(uint32_t addr, uint8_t val, UNUSED(void *priv)) +lxt_ems_write(uint32_t addr, uint8_t val, void *priv) { - addr = get_laserxt_ems_addr(addr); - if (addr < (mem_size << 10)) - ram[addr] = val; + uint8_t *mem = (uint8_t *) priv; + + mem[addr & 0x3fff] = val; +} + +static void +lxt_ems_writew(uint32_t addr, uint16_t val, void *priv) +{ + uint8_t *mem = (uint8_t *) priv; + + *(uint16_t *) &(mem[addr & 0x3fff]) = val; } static uint8_t -mem_read_laserxtems(uint32_t addr, UNUSED(void *priv)) +lxt_ems_read(uint32_t addr, void *priv) { - uint8_t val = 0xFF; - addr = get_laserxt_ems_addr(addr); - if (addr < (mem_size << 10)) - val = ram[addr]; - return val; + uint8_t *mem = (uint8_t *) priv; + uint8_t ret = 0xff; + + ret = mem[addr & 0x3fff]; + + return ret; +} + +static uint16_t +lxt_ems_readw(uint32_t addr, void *priv) +{ + uint8_t *mem = (uint8_t *) priv; + uint16_t ret = 0xff; + + ret = *(uint16_t *) &(mem[addr & 0x3fff]); + + return ret; +} + +static lxt_ems_board_t * +lxt_ems_init(lxt_t *parent, int en, uint16_t io, uint32_t mem) +{ + lxt_ems_board_t *dev = (lxt_ems_board_t *) calloc(1, sizeof(lxt_ems_board_t)); + + if (en) { + dev->parent = parent; + + if (io != 0x0000) { + io_sethandler(io , 0x0002, lxt_ems_in, NULL, NULL, lxt_ems_out, NULL, NULL, dev); + io_sethandler(io | 0x4000, 0x0002, lxt_ems_in, NULL, NULL, lxt_ems_out, NULL, NULL, dev); + io_sethandler(io | 0x8000, 0x0002, lxt_ems_in, NULL, NULL, lxt_ems_out, NULL, NULL, dev); + io_sethandler(io | 0xc000, 0x0002, lxt_ems_in, NULL, NULL, lxt_ems_out, NULL, NULL, dev); + } + + dev->ram = (uint8_t *) calloc(mem, sizeof(uint8_t)); + dev->mem_size = mem; + + for (uint8_t i = 0; i < 4; i++) { + uint8_t *ptr = dev->ram + (i << 14); + + if (parent->is_lxt3) + mem_mapping_add(&dev->ems[i].mapping, 0xe0000 + (i << 14), 0x4000, + lxt_ems_read, lxt_ems_readw, NULL, + lxt_ems_write, lxt_ems_writew, NULL, + ptr, 0, ptr); + else + mem_mapping_add(&dev->ems[i].mapping, 0xe0000 + (i << 14), 0x4000, + lxt_ems_read, NULL, NULL, + lxt_ems_write, NULL, NULL, + ptr, 0, ptr); + + mem_mapping_disable(&dev->ems[i].mapping); + + dev->ems[i].page = 0x7f; + dev->ems[i].ctrl = (i == 3) ? 0x00 : 0x80; + + dev->ems[i].parent = dev; + + ems_update_virt(&(dev->ems[i]), dev->ems[i].page); + } + } + + return dev; } static void -laserxt_init(int is_lxt3) +lxt_close(void *priv) { - 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); - io_sethandler(0x8208, 0x0002, laserxt_read, NULL, NULL, laserxt_write, NULL, NULL, NULL); - io_sethandler(0xc208, 0x0002, laserxt_read, NULL, NULL, laserxt_write, NULL, NULL, NULL); - mem_mapping_set_addr(&ram_low_mapping, 0, !is_lxt3 ? 0x70000 + (((mem_size + 64) & 255) << 10) : 0x30000 + (((mem_size + 320) & 511) << 10)); + lxt_t *dev = (lxt_t *) priv; + int ems_boards = (1 - dev->is_lxt3) + 1; + + for (int i = 0; i < ems_boards; i++) + if (dev->ems_boards[i] != NULL) { + if (dev->ems_boards[i]->ram != NULL) + free(dev->ems_boards[i]->ram); + free(dev->ems_boards[i]); + } + + free(dev); +} + +static void * +lxt_init(const device_t *info) +{ + lxt_t * dev = (lxt_t *) calloc(1, sizeof(lxt_t)); + int ems_boards = (1 - info->local) + 1; + int ems_en[2] = { 0 }; + uint16_t ems_io[2] = { 0 }; + uint32_t ems_mem[2] = { 0 }; + char conf_str[512] = { 0 }; + + dev->is_lxt3 = info->local; + + for (int i = 0; i < ems_boards; i++) { + sprintf(conf_str, "ems_%i_enable", i + 1); + ems_en[i] = device_get_config_int(conf_str); + + sprintf(conf_str, "ems_%i_base", i + 1); + ems_io[i] = device_get_config_hex16(conf_str); + + sprintf(conf_str, "ems_%i_mem_size", i + 1); + ems_mem[i] = device_get_config_int(conf_str) << 10; + + dev->ems_boards[i] = lxt_ems_init(dev, ems_en[i], ems_io[i], ems_mem[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); - mem_mapping_disable(&laserxt_ems_mapping[i]); - } mem_set_mem_state(0x0c0000, 0x40000, MEM_READ_EXTANY | MEM_WRITE_EXTANY); - laserxt_is_lxt3 = is_lxt3; + + return dev; } +static const device_config_t laserxt_config[] = { + { + .name = "ems_1_base", + .description = "EMS 1 Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Disabled", .value = 0 }, + { .description = "0x208", .value = 0x208 }, + { .description = "0x218", .value = 0x218 }, + { .description = "0x258", .value = 0x258 }, + { .description = "0x268", .value = 0x268 }, + { .description = "0x2A8", .value = 0x2a8 }, + { .description = "0x2B8", .value = 0x2b8 }, + { .description = "0x2E8", .value = 0x2e8 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { + .name = "ems_2_base", + .description = "EMS 2 Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Disabled", .value = 0 }, + { .description = "0x208", .value = 0x208 }, + { .description = "0x218", .value = 0x218 }, + { .description = "0x258", .value = 0x258 }, + { .description = "0x268", .value = 0x268 }, + { .description = "0x2A8", .value = 0x2a8 }, + { .description = "0x2B8", .value = 0x2b8 }, + { .description = "0x2E8", .value = 0x2e8 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { + .name = "ems_1_mem_size", + .description = "EMS 1 Memory Size", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 512, + .step = 32 + }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { + .name = "ems_2_mem_size", + .description = "EMS 2 Memory Size", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 512, + .step = 32 + }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { + .name = "ems_1_enable", + .description = "Enable EMS 1", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { + .name = "ems_2_enable", + .description = "Enable EMS 2", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } +}; + +const device_t laserxt_device = { + .name = "VTech Laser Turbo XT", + .internal_name = "laserxt", + .flags = 0, + .local = 0, + .init = lxt_init, + .close = lxt_close, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = laserxt_config +}; + +static const device_config_t lxt3_config[] = { + { + .name = "ems_1_base", + .description = "EMS Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Disabled", .value = 0 }, + { .description = "0x208", .value = 0x208 }, + { .description = "0x218", .value = 0x218 }, + { .description = "0x258", .value = 0x258 }, + { .description = "0x268", .value = 0x268 }, + { .description = "0x2A8", .value = 0x2a8 }, + { .description = "0x2B8", .value = 0x2b8 }, + { .description = "0x2E8", .value = 0x2e8 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { + .name = "ems_1_mem_size", + .description = "EMS Memory Size", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 1024, + .step = 32 + }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { + .name = "ems_1_enable", + .description = "Enable EMS", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } +}; + +const device_t lxt3_device = { + .name = "VTech Laser Turbo XT", + .internal_name = "laserxt", + .flags = 0, + .local = 1, + .init = lxt_init, + .close = lxt_close, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = lxt3_config +}; + static void machine_xt_laserxt_common_init(const machine_t *model,int is_lxt3) { @@ -153,7 +466,9 @@ machine_xt_laserxt_common_init(const machine_t *model,int is_lxt3) nmi_init(); standalone_gameport_type = &gameport_device; - laserxt_init(is_lxt3); + device_add(is_lxt3 ? &lxt3_device : &laserxt_device); + + device_add(&keyboard_xt_lxt3_device); } int @@ -167,8 +482,6 @@ machine_xt_laserxt_init(const machine_t *model) if (bios_only || !ret) return ret; - device_add(&keyboard_xt_device); - machine_xt_laserxt_common_init(model, 0); return ret; @@ -185,8 +498,6 @@ machine_xt_lxt3_init(const machine_t *model) if (bios_only || !ret) return ret; - device_add(&keyboard_xt_lxt3_device); - machine_xt_laserxt_common_init(model, 1); return ret; diff --git a/src/machine/m_xt_olivetti.c b/src/machine/m_xt_olivetti.c index 817b0d0cc..8e37dce1f 100644 --- a/src/machine/m_xt_olivetti.c +++ b/src/machine/m_xt_olivetti.c @@ -30,6 +30,7 @@ #include #define HAVE_STDARG_H #include <86box/86box.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/io.h> #include <86box/pic.h> @@ -1917,7 +1918,7 @@ m19_vid_out(uint16_t addr, uint8_t val, void *priv) /* activating plantronics mode */ if (addr == 0x3dd) { /* already in graphics mode */ - if ((val & 0x30) && (vid->ogc.cga.cgamode & 0x2)) + if ((val & 0x30) && (vid->ogc.cga.cgamode & CGA_MODE_FLAG_GRAPHICS)) vid->mode = PLANTRONICS_MODE; else vid->mode = OLIVETTI_OGC_MODE; @@ -2075,7 +2076,7 @@ const device_t m24_kbd_device = { .init = NULL, .close = m24_kbd_close, .reset = m24_kbd_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2119,7 +2120,7 @@ const device_t m19_vid_device = { .init = NULL, .close = m19_vid_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = m19_vid_speed_changed, .force_redraw = NULL, .config = m19_vid_config @@ -2313,8 +2314,7 @@ machine_xt_m24_init(const machine_t *model) if (bios_only || !ret) return ret; - m24_kbd = (m24_kbd_t *) malloc(sizeof(m24_kbd_t)); - memset(m24_kbd, 0x00, sizeof(m24_kbd_t)); + m24_kbd = (m24_kbd_t *) calloc(1, sizeof(m24_kbd_t)); machine_common_init(model); @@ -2330,10 +2330,9 @@ machine_xt_m24_init(const machine_t *model) nmi_init(); /* Allocate an NVR for this machine. */ - nvr = (nvr_t *) malloc(sizeof(nvr_t)); + nvr = (nvr_t *) calloc(1, sizeof(nvr_t)); if (nvr == NULL) return 0; - memset(nvr, 0x00, sizeof(nvr_t)); mm58174_init(nvr, model->nvrmask + 1); @@ -2367,15 +2366,14 @@ machine_xt_m240_init(const machine_t *model) m24_kbd_t *m24_kbd; nvr_t *nvr; - ret = bios_load_interleaved("roms/machines/m240/olivetti_m240_pchj_2.11_low.bin", - "roms/machines/m240/olivetti_m240_pchk_2.11_high.bin", + ret = bios_load_interleaved("roms/machines/m240/olivetti_m240_pchm_2.12_low.bin", + "roms/machines/m240/olivetti_m240_pchl_2.12_high.bin", 0x000f8000, 32768, 0); if (bios_only || !ret) return ret; - m24_kbd = (m24_kbd_t *) malloc(sizeof(m24_kbd_t)); - memset(m24_kbd, 0x00, sizeof(m24_kbd_t)); + m24_kbd = (m24_kbd_t *) calloc(1, sizeof(m24_kbd_t)); machine_common_init(model); @@ -2404,10 +2402,9 @@ machine_xt_m240_init(const machine_t *model) nmi_init(); /* Allocate an NVR for this machine. */ - nvr = (nvr_t *) malloc(sizeof(nvr_t)); + nvr = (nvr_t *) calloc(1, sizeof(nvr_t)); if (nvr == NULL) return 0; - memset(nvr, 0x00, sizeof(nvr_t)); mm58274_init(nvr, model->nvrmask + 1); @@ -2438,8 +2435,7 @@ machine_xt_m19_init(const machine_t *model) m19_vid_t *vid; /* Do not move memory allocation elsewhere. */ - vid = (m19_vid_t *) malloc(sizeof(m19_vid_t)); - memset(vid, 0x00, sizeof(m19_vid_t)); + vid = (m19_vid_t *) calloc(1, sizeof(m19_vid_t)); machine_common_init(model); diff --git a/src/machine/m_xt_philips.c b/src/machine/m_xt_philips.c index 1fc284a46..eed54e07f 100644 --- a/src/machine/m_xt_philips.c +++ b/src/machine/m_xt_philips.c @@ -23,6 +23,7 @@ #define HAVE_STDARG_H #include <86box/86box.h> #include <86box/nmi.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/pit.h> #include <86box/mem.h> @@ -142,7 +143,7 @@ const device_t philips_device = { .init = philips_init, .close = philips_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/machine/m_xt_xi8088.c b/src/machine/m_xt_xi8088.c index 9b55dc021..886c1be6e 100644 --- a/src/machine/m_xt_xi8088.c +++ b/src/machine/m_xt_xi8088.c @@ -168,7 +168,7 @@ const device_t xi8088_device = { .init = xi8088_init, .close = NULL, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = xi8088_config diff --git a/src/machine/m_xt_zenith.c b/src/machine/m_xt_zenith.c index f5e231772..62c6496d1 100644 --- a/src/machine/m_xt_zenith.c +++ b/src/machine/m_xt_zenith.c @@ -73,8 +73,7 @@ zenith_scratchpad_init(UNUSED(const device_t *info)) { zenith_t *dev; - dev = (zenith_t *) malloc(sizeof(zenith_t)); - memset(dev, 0x00, sizeof(zenith_t)); + dev = (zenith_t *) calloc(1, sizeof(zenith_t)); dev->scratchpad_ram = malloc(0x4000); @@ -103,7 +102,7 @@ static const device_t zenith_scratchpad_device = { .init = zenith_scratchpad_init, .close = zenith_scratchpad_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -145,9 +144,10 @@ machine_xt_z184_init(const machine_t *model) lpt1_remove(); /* only one parallel port */ lpt2_remove(); - lpt1_init(0x278); + lpt1_setup(LPT2_ADDR); device_add(&ns8250_device); - serial_set_next_inst(SERIAL_MAX); /* So that serial_standalone_init() won't do anything. */ + /* So that serial_standalone_init() won't do anything. */ + serial_set_next_inst(SERIAL_MAX - 1); device_add(&cga_device); @@ -199,7 +199,7 @@ machine_xt_z159_init(const machine_t *model) /* parallel port is on the memory board */ lpt1_remove(); /* only one parallel port */ lpt2_remove(); - lpt1_init(0x278); + lpt1_setup(LPT2_ADDR); return ret; } diff --git a/src/machine/machine.c b/src/machine/machine.c index b171dd505..6a86b785f 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -39,6 +39,7 @@ #include <86box/video.h> #include <86box/machine.h> #include <86box/isamem.h> +#include <86box/isarom.h> #include <86box/pci.h> #include <86box/plat_unused.h> @@ -111,6 +112,11 @@ machine_init_ex(int m) /* Reset any ISA memory cards. */ isamem_reset(); +#if 0 + /* Reset any ISA ROM cards. */ + isarom_reset(); +#endif + /* Reset the fast off stuff. */ cpu_fast_off_reset(); @@ -139,18 +145,24 @@ machine_init(void) int machine_available(int m) { - int ret; + int ret = 0; const device_t *dev = machine_get_device(m); - bios_only = 1; + if (dev != NULL) + ret = machine_device_available(dev); + /* + Only via machine_init_ex() if the device is NULL or + it lacks a CONFIG_BIOS field (or the CONFIG_BIOS field + is not the first in list. + */ + if (ret == 0) { + bios_only = 1; - 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 ((dev == NULL) || (ret != -1)) ret = machine_init_ex(m); - bios_only = 0; + bios_only = 0; + } else if (ret == -2) + ret = 0; return !!ret; } diff --git a/src/machine/machine_table.c b/src/machine/machine_table.c index 3fc3bcc8a..24b950ad7 100644 --- a/src/machine/machine_table.c +++ b/src/machine/machine_table.c @@ -8,17 +8,12 @@ * * Handling of the emulated machines. * - * NOTES: OpenAT wip for 286-class machine with open BIOS. - * PS2_M80-486 wip, pending receipt of TRM's for machine. - * - * - * * Authors: Miran Grca, * Fred N. van Kempen, * Jasmine Iwanek, * - * Copyright 2016-2020 Miran Grca. - * Copyright 2017-2020 Fred N. van Kempen. + * Copyright 2016-2025 Miran Grca. + * Copyright 2017-2025 Fred N. van Kempen. * Copyright 2025 Jasmine Iwanek. */ #include @@ -31,19 +26,23 @@ #include <86box/rom.h> #include <86box/device.h> #include <86box/machine.h> +#include <86box/timer.h> +#include <86box/fdd.h> +#include <86box/fdc.h> #include <86box/keyboard.h> #include <86box/sound.h> #include <86box/video.h> #include <86box/plat_unused.h> #include <86box/thread.h> -#include <86box/timer.h> #include <86box/network.h> // Temporarily here till we move everything out into the right files extern const device_t pcjr_device; extern const device_t m19_vid_device; -extern const device_t vid_device; -extern const device_t vid_device_hx; +extern const device_t tandy_1000_video_device; +extern const device_t tandy_1000hx_video_device; +extern const device_t tandy_1000sl_video_device; + extern const device_t t1000_video_device; extern const device_t xi8088_device; extern const device_t cga_device; @@ -53,7 +52,6 @@ extern const device_t vid_pc2086_device; extern const device_t vid_pc3086_device; extern const device_t vid_200_device; extern const device_t vid_ppc512_device; -extern const device_t vid_device_sl; extern const device_t t1200_video_device; extern const device_t compaq_plasma_device; extern const device_t ps1_2011_device; @@ -63,6 +61,17 @@ extern const device_t ibmxt_device; extern const device_t ibmxt86_device; extern const device_t ibmat_device; extern const device_t ibmxt286_device; +extern const device_t pb450_device; +extern const device_t jukopc_device; +extern const device_t vendex_device; +extern const device_t c5sbm2_device; +extern const device_t sb486pv_device; +extern const device_t ap5s_device; +extern const device_t d842_device; +extern const device_t d943_device; +extern const device_t dells333sl_device; +extern const device_t hot433a_device; +extern const device_t pbl300sx_device; const machine_filter_t machine_types[] = { { "None", MACHINE_TYPE_NONE }, @@ -76,6 +85,7 @@ const machine_filter_t machine_types[] = { { "[1992] i486 (Socket 168 and 1)", MACHINE_TYPE_486 }, { "[1992] i486 (Socket 2)", MACHINE_TYPE_486_S2 }, { "[1994] i486 (Socket 3)", MACHINE_TYPE_486_S3 }, + { "[1994] i486 (Socket 3 PCI)", MACHINE_TYPE_486_S3_PCI }, { "[1992] i486 (Miscellaneous)", MACHINE_TYPE_486_MISC }, { "[1993] Socket 4", MACHINE_TYPE_SOCKET4 }, { "[1994] Socket 5", MACHINE_TYPE_SOCKET5 }, @@ -98,6 +108,7 @@ const machine_filter_t machine_chipsets[] = { { "Headland GC100A", MACHINE_CHIPSET_GC100A }, { "Headland GC103", MACHINE_CHIPSET_GC103 }, { "Headland HT18", MACHINE_CHIPSET_HT18 }, + { "ACC 2036", MACHINE_CHIPSET_ACC_2036 }, { "ACC 2168", MACHINE_CHIPSET_ACC_2168 }, { "ALi M1217", MACHINE_CHIPSET_ALI_M1217 }, { "ALi M6117", MACHINE_CHIPSET_ALI_M6117 }, @@ -108,9 +119,12 @@ const machine_filter_t machine_chipsets[] = { { "ALi ALADDiN IV+", MACHINE_CHIPSET_ALI_ALADDIN_IV_PLUS }, { "ALi ALADDiN V", MACHINE_CHIPSET_ALI_ALADDIN_V }, { "ALi ALADDiN-PRO II", MACHINE_CHIPSET_ALI_ALADDIN_PRO_II }, + { "C&T PC/AT", MACHINE_CHIPSET_CT_AT }, + { "C&T 386/AT", MACHINE_CHIPSET_CT_386 }, { "C&T 82C235 SCAT", MACHINE_CHIPSET_SCAT }, - { "C&T CS8121 NEAT", MACHINE_CHIPSET_NEAT }, - { "C&T 386", MACHINE_CHIPSET_CT_386 }, + { "C&T 82C236 SCATsx", MACHINE_CHIPSET_SCAT_SX }, + { "C&T CS8221 NEAT", MACHINE_CHIPSET_NEAT }, + { "C&T CS8281 NEATsx", MACHINE_CHIPSET_NEAT_SX }, { "C&T CS4031", MACHINE_CHIPSET_CT_CS4031 }, { "Contaq 82C596", MACHINE_CHIPSET_CONTAQ_82C596 }, { "Contaq 82C597", MACHINE_CHIPSET_CONTAQ_82C597 }, @@ -138,7 +152,9 @@ const machine_filter_t machine_chipsets[] = { { "OPTi 391", MACHINE_CHIPSET_OPTI_391 }, { "OPTi 481", MACHINE_CHIPSET_OPTI_481 }, { "OPTi 493", MACHINE_CHIPSET_OPTI_493 }, - { "OPTi 495", MACHINE_CHIPSET_OPTI_495 }, + { "OPTi 495SLC", MACHINE_CHIPSET_OPTI_495SLC }, + { "OPTi 495SX", MACHINE_CHIPSET_OPTI_495SX }, + { "OPTi 498", MACHINE_CHIPSET_OPTI_498 }, { "OPTi 499", MACHINE_CHIPSET_OPTI_499 }, { "OPTi 895/802G", MACHINE_CHIPSET_OPTI_895_802G }, { "OPTi 547/597", MACHINE_CHIPSET_OPTI_547_597 }, @@ -318,7 +334,7 @@ const machine_t machines[] = { .max_multi = 0 }, .bus_flags = MACHINE_PCJR, - .flags = MACHINE_VIDEO_FIXED, + .flags = MACHINE_VIDEO_FIXED | MACHINE_CARTRIDGE, .ram = { .min = 64, .max = 640, @@ -953,7 +969,7 @@ const machine_t machines[] = { .kbc_p1 = 0xff, .gpio = 0xffffffff, .gpio_acpi = 0xffffffff, - .device = NULL, + .device = &jukopc_device, .fdc_device = NULL, .sio_device = NULL, .vid_device = NULL, @@ -1580,7 +1596,7 @@ const machine_t machines[] = { .device = NULL, .fdc_device = NULL, .sio_device = NULL, - .vid_device = &vid_device, + .vid_device = &tandy_1000_video_device, .snd_device = NULL, .net_device = NULL }, @@ -1619,7 +1635,7 @@ const machine_t machines[] = { .device = NULL, .fdc_device = NULL, .sio_device = NULL, - .vid_device = &vid_device_hx, + .vid_device = &tandy_1000hx_video_device, .snd_device = NULL, .net_device = NULL }, @@ -1694,14 +1710,13 @@ const machine_t machines[] = { .kbc_p1 = 0xff, .gpio = 0xffffffff, .gpio_acpi = 0xffffffff, - .device = NULL, + .device = &vendex_device, .fdc_device = NULL, .sio_device = NULL, .vid_device = NULL, .snd_device = NULL, .net_device = NULL }, -#ifdef USE_LASERXT { .name = "[8088] VTech Laser Turbo XT", .internal_name = "ltxt", @@ -1713,7 +1728,7 @@ const machine_t machines[] = { .available_flag = MACHINE_AVAILABLE, .gpio_acpi_handler = NULL, .cpu = { - .package = CPU_PKG_8088, + .package = CPU_PKG_8088_VTECH, .block = CPU_BLOCK_NONE, .min_bus = 0, .max_bus = 0, @@ -1727,21 +1742,20 @@ const machine_t machines[] = { .ram = { .min = 256, .max = 640, - .step = 256 + .step = 64 }, .nvrmask = 0, .kbc_device = &keyboard_xt_device, .kbc_p1 = 0xff, .gpio = 0xffffffff, .gpio_acpi = 0xffffffff, - .device = NULL, + .device = &laserxt_device, .fdc_device = NULL, .sio_device = NULL, .vid_device = NULL, .snd_device = NULL, .net_device = NULL }, -#endif /* USE_LASERXT */ /* Has a standard PS/2 KBC (so, use IBM PS/2 Type 1). */ { .name = "[8088] Xi8088", @@ -2016,6 +2030,45 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + { + .name = "[V20] Tulip PC Compact 2", + .internal_name = "tuliptc8", + .type = MACHINE_TYPE_8088, + .chipset = MACHINE_CHIPSET_DISCRETE, + .init = machine_xt_tuliptc8_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_8088, + .block = CPU_BLOCK(CPU_8088), + .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 = 63, + .kbc_device = &keyboard_xtclone_device, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, /* 8086 Machines */ { @@ -2370,7 +2423,7 @@ const machine_t machines[] = { .net_device = NULL }, { - .name = "[8086] Olivetti M21/24/24SP", + .name = "[8086] Olivetti M21/24/24SP/AT&T PC 6300", .internal_name = "m24", .type = MACHINE_TYPE_8086, .chipset = MACHINE_CHIPSET_PROPRIETARY, @@ -2410,7 +2463,7 @@ const machine_t machines[] = { }, /* Has Olivetti KBC firmware. */ { - .name = "[8086] Olivetti M240", + .name = "[8086] Olivetti M240/AT&T PC 6300 WGS", .internal_name = "m240", .type = MACHINE_TYPE_8086, .chipset = MACHINE_CHIPSET_PROPRIETARY, @@ -2522,7 +2575,7 @@ const machine_t machines[] = { .device = NULL, .fdc_device = NULL, .sio_device = NULL, - .vid_device = &vid_device_sl, + .vid_device = &tandy_1000sl_video_device, .snd_device = NULL, .net_device = NULL }, @@ -2604,8 +2657,6 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, - -#ifdef USE_LASERXT { .name = "[8086] VTech Laser XT3", .internal_name = "lxt3", @@ -2617,7 +2668,7 @@ const machine_t machines[] = { .available_flag = MACHINE_AVAILABLE, .gpio_acpi_handler = NULL, .cpu = { - .package = CPU_PKG_8086, + .package = CPU_PKG_8086_VTECH, .block = CPU_BLOCK_NONE, .min_bus = 0, .max_bus = 0, @@ -2629,23 +2680,22 @@ const machine_t machines[] = { .bus_flags = MACHINE_PC, .flags = MACHINE_FLAGS_NONE, .ram = { - .min = 256, + .min = 512, .max = 640, - .step = 256 + .step = 64 }, .nvrmask = 0, .kbc_device = &keyboard_xt_lxt3_device, .kbc_p1 = 0xff, .gpio = 0xffffffff, .gpio_acpi = 0xffffffff, - .device = NULL, + .device = &lxt3_device, .fdc_device = NULL, .sio_device = NULL, .vid_device = NULL, .snd_device = NULL, .net_device = NULL }, -#endif /* USE_LASERXT */ /* 286 AT machines */ /* Has IBM AT KBC firmware. */ @@ -2752,9 +2802,9 @@ const machine_t machines[] = { .bus_flags = MACHINE_PS2, .flags = MACHINE_XTA | MACHINE_VIDEO_FIXED, .ram = { - .min = 1024, + .min = 512, .max = 16384, - .step = 1024 + .step = 512 }, .nvrmask = 127, .kbc_device = NULL, @@ -3089,10 +3139,9 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, -#ifdef USE_OLIVETTI /* Has Olivetti KBC firmware. */ { - .name = "[ISA] Olivetti M290", + .name = "[ISA] Olivetti M290/AT&T 6286 WGS", .internal_name = "m290", .type = MACHINE_TYPE_286, .chipset = MACHINE_CHIPSET_PROPRIETARY, @@ -3114,7 +3163,7 @@ const machine_t machines[] = { .bus_flags = MACHINE_AT, .flags = MACHINE_FLAGS_NONE, .ram = { - .min = 640, + .min = 1024, .max = 16384, .step = 128 }, @@ -3130,49 +3179,6 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, -#endif /* USE_OLIVETTI */ -#ifdef USE_OPEN_AT - /* Has IBM AT KBC firmware. */ - { - .name = "[ISA] OpenAT", - .internal_name = "openat", - .type = MACHINE_TYPE_286, - .chipset = MACHINE_CHIPSET_DISCRETE, - .init = machine_at_openat_init, - .p1_handler = NULL, - .gpio_handler = NULL, - .available_flag = MACHINE_AVAILABLE, - .gpio_acpi_handler = NULL, - .cpu = { - .package = CPU_PKG_286, - .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_FLAGS_NONE, - .ram = { - .min = 256, - .max = 15872, - .step = 128 - }, - .nvrmask = 63, - .kbc_device = NULL, - .kbc_p1 = 0xff, - .gpio = 0xffffffff, - .gpio_acpi = 0xffffffff, - .device = NULL, - .fdc_device = NULL, - .sio_device = NULL, - .vid_device = NULL, - .snd_device = NULL, - .net_device = NULL - }, -#endif /* USE_OPEN_AT */ /* Has IBM AT KBC firmware. */ { .name = "[ISA] Phoenix IBM AT", @@ -3253,6 +3259,47 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + /* Has IBM AT KBC firmware. */ + /* To configure the BIOS, use PB_2330a_diag.IMA from MS-DOS 3.30 Packard Bell OEM, GSETUP might work too*/ + { + .name = "[ISA] Packard Bell PB286", + .internal_name = "pb286", + .type = MACHINE_TYPE_286, + .chipset = MACHINE_CHIPSET_DISCRETE, + .init = machine_at_pb286_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_286, + .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_FLAGS_NONE, + .ram = { + .min = 256, + .max = 1024, + .step = 128 + }, + .nvrmask = 63, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, /* This has a Siemens proprietary KBC which is completely undocumented. */ { .name = "[ISA] Siemens PCD-2L", @@ -3372,6 +3419,129 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + /* No proper pictures of the KBC exist, though it seems to have the IBM AT KBC + firmware. */ + { + .name = "[C&T PC/AT] Dell System 200", + .internal_name = "dells200", + .type = MACHINE_TYPE_286, + .chipset = MACHINE_CHIPSET_CT_AT, + .init = machine_at_dells200_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_286, + .block = CPU_BLOCK_NONE, + .min_bus = 6000000, + .max_bus = 12000000, + .min_voltage = 0, + .max_voltage = 0, + .min_multi = 0, + .max_multi = 0 + }, + .bus_flags = MACHINE_AT, + .flags = MACHINE_FLAGS_NONE, + .ram = { + .min = 640, + .max = 16384, + .step = 128 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, + /* No proper pictures of the KBC exist, though it seems to have the IBM AT KBC + firmware. */ + { + .name = "[C&T PC/AT] PC's Limited (Dell) 28608L/AT122", + .internal_name = "at122", + .type = MACHINE_TYPE_286, + .chipset = MACHINE_CHIPSET_CT_AT, + .init = machine_at_at122_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_286, + .block = CPU_BLOCK_NONE, + .min_bus = 6000000, + .max_bus = 12000000, + .min_voltage = 0, + .max_voltage = 0, + .min_multi = 0, + .max_multi = 0 + }, + .bus_flags = MACHINE_AT, + .flags = MACHINE_FLAGS_NONE, + .ram = { + .min = 640, + .max = 16384, + .step = 128 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, + /* No proper pictures of the KBC exist, though it seems to have the IBM AT KBC + firmware. */ + { + .name = "[C&T PC/AT] Tulip AT Compact", + .internal_name = "tuliptc7", + .type = MACHINE_TYPE_286, + .chipset = MACHINE_CHIPSET_CT_AT, + .init = machine_at_tuliptc7_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_286, + .block = CPU_BLOCK_NONE, + .min_bus = 6000000, + .max_bus = 12000000, + .min_voltage = 0, + .max_voltage = 0, + .min_multi = 0, + .max_multi = 0 + }, + .bus_flags = MACHINE_AT, + .flags = MACHINE_FLAGS_NONE, + .ram = { + .min = 640, + .max = 16384, + .step = 128 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, /* Has Quadtel KBC firmware. */ { .name = "[GC103] Quadtel 286 clone", @@ -3596,7 +3766,7 @@ const machine_t machines[] = { .flags = MACHINE_IDE | MACHINE_VIDEO, .ram = { .min = 512, - .max = 16384, + .max = 5120, .step = 128 }, .nvrmask = 127, @@ -3607,7 +3777,7 @@ const machine_t machines[] = { .device = NULL, .fdc_device = NULL, .sio_device = NULL, - .vid_device = NULL, + .vid_device = ¶dise_pvga1a_ncr3302_device, .snd_device = NULL, .net_device = NULL }, @@ -3636,7 +3806,7 @@ const machine_t machines[] = { .flags = MACHINE_FLAGS_NONE, .ram = { .min = 512, - .max = 16384, + .max = 8192, .step = 128 }, .nvrmask = 127, @@ -4215,6 +4385,46 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + /* Most likely has Phonenix KBC firmware. */ + { + .name = "[ACC 2036] Packard Bell Legend 300SX", + .internal_name = "pbl300sx", + .type = MACHINE_TYPE_386SX, + .chipset = MACHINE_CHIPSET_ACC_2036, + .init = machine_at_pbl300sx_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_386SX, + .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, + .flags = MACHINE_IDE | MACHINE_VIDEO, + .ram = { + .min = 1024, + .max = 16384, + .step = 1024 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = &pbl300sx_device, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = &oti037_pbl300sx_device, + .snd_device = NULL, + .net_device = NULL + }, /* This has an AMIKey-2, which is an updated version of type 'H'. */ { .name = "[ALi M1217] Acrosser AR-B1374", @@ -4416,7 +4626,7 @@ const machine_t machines[] = { .net_device = NULL }, { - .name = "[ALI M1409] Acer 100T", + .name = "[ALi M1409] Acer 100T", .internal_name = "acer100t", .type = MACHINE_TYPE_386SX, .chipset = MACHINE_CHIPSET_ALI_M1409, @@ -4682,7 +4892,7 @@ const machine_t machines[] = { .max_multi = 0 }, .bus_flags = MACHINE_PS2, - .flags = MACHINE_IDE, + .flags = MACHINE_FLAGS_NONE, .ram = { .min = 1024, .max = 8192, @@ -4740,6 +4950,44 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + { .name = "[NEATsx] OKI if386AX30L", + .internal_name = "if386sx", + .type = MACHINE_TYPE_386SX, + .chipset = MACHINE_CHIPSET_NEAT_SX, + .init = machine_at_if386sx_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_386SX, + .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_VIDEO_FIXED | MACHINE_AX, + .ram = { + .min = 1024, + .max = 4096, + .step = 1024 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, /* Has IBM AT KBC firmware. */ { .name = "[OPTi 291] DTK PPM-3333P", @@ -4864,6 +5112,47 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + /* No proper pictures of the KBC exist, though it seems to have the IBM AT KBC + firmware. */ + { + .name = "[SCAMP] Dell System 333s/L", + .internal_name = "dells333sl", + .type = MACHINE_TYPE_386SX, + .chipset = MACHINE_CHIPSET_VLSI_SCAMP, + .init = machine_at_dells333sl_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_386SX, + .block = CPU_BLOCK_NONE, + .min_bus = 10000000, + .max_bus = 33333333, + .min_voltage = 0, + .max_voltage = 0, + .min_multi = 0, + .max_multi = 0 + }, + .bus_flags = MACHINE_PS2, + .flags = MACHINE_IDE | MACHINE_VIDEO, + .ram = { + .min = 1024, + .max = 16384, + .step = 128 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = &dells333sl_device, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = &gd5420_onboard_device, + .snd_device = NULL, + .net_device = NULL + }, /* Has IBM PS/2 Type 1 KBC firmware. */ { .name = "[SCAMP] Samsung SPC-6033P", @@ -4907,10 +5196,10 @@ const machine_t machines[] = { /* Has an unknown AMI KBC firmware, I'm going to assume 'F' until a photo or real hardware BIOS string is found. */ { - .name = "[SCAT] Kaimei KMX-C-02", + .name = "[SCATsx] Kaimei KMX-C-02", .internal_name = "kmxc02", .type = MACHINE_TYPE_386SX, - .chipset = MACHINE_CHIPSET_SCAT, + .chipset = MACHINE_CHIPSET_SCAT_SX, .init = machine_at_kmxc02_init, .p1_handler = NULL, .gpio_handler = NULL, @@ -5154,7 +5443,7 @@ const machine_t machines[] = { }, /* Has an AMI Keyboard BIOS PLUS KBC firmware ('8'). */ { - .name = "[C&T 386] ECS 386/32", + .name = "[C&T 386/AT] ECS 386/32", .internal_name = "ecs386", .type = MACHINE_TYPE_386DX, .chipset = MACHINE_CHIPSET_CT_386, @@ -5194,7 +5483,7 @@ const machine_t machines[] = { }, /* Has IBM AT KBC firmware. */ { - .name = "[C&T 386] Samsung SPC-6000A", + .name = "[C&T 386/AT] Samsung SPC-6000A", .internal_name = "spc6000a", .type = MACHINE_TYPE_386DX, .chipset = MACHINE_CHIPSET_CT_386, @@ -5352,7 +5641,7 @@ const machine_t machines[] = { }, /* Has IBM AT KBC firmware. */ { - .name = "[ISA] Micronics 09-00021", + .name = "[ISA] Micronics 09-00021 (Tandon BIOS)", .internal_name = "micronics386", .type = MACHINE_TYPE_386DX, .chipset = MACHINE_CHIPSET_DISCRETE, @@ -5391,6 +5680,46 @@ const machine_t machines[] = { .net_device = NULL }, /* Has IBM AT KBC firmware. */ + { + .name = "[ISA] Micronics 09-00021 (Phoenix BIOS)", + .internal_name = "micronics386px", + .type = MACHINE_TYPE_386DX, + .chipset = MACHINE_CHIPSET_DISCRETE, + .init = machine_at_micronics386px_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .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_APM, + .ram = { + .min = 512, + .max = 8192, + .step = 128 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, + /* Has IBM AT KBC firmware. */ { .name = "[ISA] Tandy 4000", .internal_name = "tandy4000", @@ -5512,10 +5841,10 @@ const machine_t machines[] = { but the BIOS sends commands C9 without a parameter and D5, both of which are Phoenix MultiKey commands. */ { - .name = "[OPTi 495] U-Board OPTi 495SLC", + .name = "[OPTi 495SLC] U-Board OPTi 495SLC", .internal_name = "award495", .type = MACHINE_TYPE_386DX, - .chipset = MACHINE_CHIPSET_OPTI_495, + .chipset = MACHINE_CHIPSET_OPTI_495SLC, .init = machine_at_opti495_init, .p1_handler = NULL, .gpio_handler = NULL, @@ -5550,6 +5879,46 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + /* Has Award KBC firmware. */ + { + .name = "[SiS 310] ASUS 386/33-64K", + .internal_name = "asus3863364k", + .type = MACHINE_TYPE_386DX, + .chipset = MACHINE_CHIPSET_SIS_310, + .init = machine_at_asus3863364k_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .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_APM, + .ram = { + .min = 1024, + .max = 16384, + .step = 1024 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, /* Has AMIKey F KBC firmware. */ { .name = "[SiS 310] ASUS ISA-386C", @@ -5632,14 +6001,134 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + /* Has IBM PS/55 5551-Sxx, Txx stage 2 firmware. */ + { + .name = "[MCA] IBM PS/55 model 5550-T", + .internal_name = "ibmps55_m50t", + .type = MACHINE_TYPE_386DX, + .chipset = MACHINE_CHIPSET_PROPRIETARY, + .init = machine_ps55_model_50t_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_386DX | CPU_PKG_486BL, + .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_APM, + .ram = { + .min = 2048, + .max = 16384, + .step = 2048 + }, + .nvrmask = 63, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, + /* Has IBM PS/55 5551-V0x, V1x firmware. */ + { + .name = "[MCA] IBM PS/55 model 5550-V", + .internal_name = "ibmps55_m50v", + .type = MACHINE_TYPE_386DX, + .chipset = MACHINE_CHIPSET_PROPRIETARY, + .init = machine_ps55_model_50v_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_386DX | CPU_PKG_486BL, + .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_APM, + .ram = { + .min = 4096, + .max = 16384, + .step = 4096 + }, + .nvrmask = 63, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, /* 386DX/486 machines */ + /* Has AMIKey F KBC firmware. The EFAR chipst is a rebrand of OPTi 495SX. */ + { + .name = "[OPTi 495SX] CAF Technology C747", + .internal_name = "c747", + .type = MACHINE_TYPE_386DX_486, + .chipset = MACHINE_CHIPSET_OPTI_495SX, + .init = machine_at_c747_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_386DX | 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_AT, + .flags = MACHINE_APM | MACHINE_IDE, + .ram = { + .min = 1024, + .max = 32768, + .step = 1024 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, /* Has AMIKey F KBC firmware. */ { - .name = "[OPTi 495] DataExpert SX495", + .name = "[OPTi 495SX] DataExpert SX495", .internal_name = "ami495", .type = MACHINE_TYPE_386DX_486, - .chipset = MACHINE_CHIPSET_OPTI_495, + .chipset = MACHINE_CHIPSET_OPTI_495SX, .init = machine_at_opti495_ami_init, .p1_handler = NULL, .gpio_handler = NULL, @@ -5676,10 +6165,10 @@ const machine_t machines[] = { }, /* Has AMIKey F KBC firmware (it's just the MR BIOS for the above machine). */ { - .name = "[OPTi 495] DataExpert SX495 (MR BIOS)", + .name = "[OPTi 495SX] DataExpert SX495 (MR BIOS)", .internal_name = "mr495", .type = MACHINE_TYPE_386DX_486, - .chipset = MACHINE_CHIPSET_OPTI_495, + .chipset = MACHINE_CHIPSET_OPTI_495SX, .init = machine_at_opti495_mr_init, .p1_handler = NULL, .gpio_handler = NULL, @@ -5836,6 +6325,46 @@ const machine_t machines[] = { }, /* 486 machines - Socket 1 */ + /* Has Award KBC firmware. */ + { + .name = "[ZyMOS Poach] ASUS ISA-486C", + .internal_name = "isa486c", + .type = MACHINE_TYPE_486, + .chipset = MACHINE_CHIPSET_ZYMOS_POACH, + .init = machine_at_isa486c_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .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_AT, + .flags = MACHINE_APM, + .ram = { + .min = 1024, + .max = 16384, + .step = 1024 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, /* Has AMI KF KBC firmware. */ { .name = "[ZyMOS Poach] Genoa Unknown 486", @@ -5961,10 +6490,10 @@ const machine_t machines[] = { /* Uses some variant of Phoenix MultiKey/42 as the Intel 8242 chip has a Phoenix copyright. */ { - .name = "[OPTi 895] Mylex MVI486", + .name = "[OPTi 498] Mylex MVI486", .internal_name = "mvi486", .type = MACHINE_TYPE_486, - .chipset = MACHINE_CHIPSET_OPTI_895_802G, + .chipset = MACHINE_CHIPSET_OPTI_498, .init = machine_at_mvi486_init, .p1_handler = NULL, .gpio_handler = NULL, @@ -6120,6 +6649,86 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + /* Has Phoenix KBC firmware. */ + { + .name = "[SiS 471] AST Advantage! 40xxd", + .internal_name = "advantage40xxd", + .type = MACHINE_TYPE_486, + .chipset = MACHINE_CHIPSET_SIS_471, + .init = machine_at_advantage40xxd_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .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 = 2 + }, + .bus_flags = MACHINE_PS2_VLB, + .flags = MACHINE_IDE | MACHINE_VIDEO | MACHINE_APM, + .ram = { + .min = 4096, + .max = 36864, + .step = 4096 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = &gd5424_onboard_device, + .snd_device = NULL, + .net_device = NULL + }, + /* Has AMIKey F KBC firmware. */ + { + .name = "[Symphony SL42C460] DTK PKM-0031Y", + .internal_name = "dtk461", + .type = MACHINE_TYPE_486, + .chipset = MACHINE_CHIPSET_SYMPHONY_SL82C460, + .init = machine_at_dtk461_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .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_AT, + .flags = MACHINE_APM, + .ram = { + .min = 1024, + .max = 32768, + .step = 1024 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, /* The chip is a Lance LT38C41, a clone of the Intel 8041, and the BIOS sends commands BC, BD, and C9 which exist on both AMIKey and Phoenix MultiKey/42, but it does not write a byte after C9, which is consistent with AMIKey, so @@ -6203,7 +6812,7 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, - /* Has a standard IBM PS/2 KBC firmware or a clone thereof. */ + /* Has a VLSI VL82C114 Combination I/O which holds the KBC. */ { .name = "[VLSI 82C481] Siemens Nixdorf D824", .internal_name = "d824", @@ -6231,7 +6840,7 @@ const machine_t machines[] = { .max = 32768, .step = 2048 }, - .nvrmask = 127, + .nvrmask = 255, .kbc_device = NULL, .kbc_p1 = 0xff, .gpio = 0xffffffff, @@ -6243,6 +6852,46 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + /* Has a VLSI VL82C113A SCAMP Combination I/O which holds the KBC. */ + { + .name = "[VLSI 82C486] Tulip 486 DC/DT", + .internal_name = "tuliptc38", + .type = MACHINE_TYPE_486, + .chipset = MACHINE_CHIPSET_VLSI_VL82C486, + .init = machine_at_tuliptc38_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .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_AT, + .flags = MACHINE_IDE | MACHINE_VIDEO | MACHINE_APM, + .ram = { + .min = 2048, + .max = 32768, + .step = 2048 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, /*Has SIO (sorta): VLSI VL82C113A SCAMP Combination I/O*/ + .vid_device = &gd5426_onboard_device, + .snd_device = NULL, + .net_device = NULL + }, /* Has IBM PS/2 Type 1 KBC firmware. */ { .name = "[MCA] IBM PS/2 model 70 (type 4)", @@ -6322,7 +6971,7 @@ const machine_t machines[] = { .device = NULL, .fdc_device = NULL, .sio_device = NULL, - .vid_device = NULL, + .vid_device = &ht216_32_pb410a_device, .snd_device = NULL, .net_device = NULL }, @@ -6450,6 +7099,46 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + /* Has AMI MegaKey KBC. */ + { + .name = "[i420TX] J-Bond PCI400C-A", + .internal_name = "pci400ca", + .type = MACHINE_TYPE_486_S2, + .chipset = MACHINE_CHIPSET_INTEL_420TX, + .init = machine_at_pci400ca_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_SOCKET3, + .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_PCI, + .flags = MACHINE_SCSI, + .ram = { + .min = 1024, + .max = 65536, + .step = 1024 + }, + .nvrmask = 127, + .kbc_device = &keyboard_at_ami_device, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, /* This has a standalone AMI Megakey 1993, which is type 'P'. */ { .name = "[IMS 8848] Tekram G486IP", @@ -6490,6 +7179,45 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + { + .name = "[OPTi 499] Alaris Cobalt LPX", + .internal_name = "cobalt", + .type = MACHINE_TYPE_486_S2, + .chipset = MACHINE_CHIPSET_OPTI_499, + .init = machine_at_cobalt_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_SOCKET3 | CPU_PKG_486BL, + .block = CPU_BLOCK(CPU_P24T), + .min_bus = 0, + .max_bus = 0, + .min_voltage = 0, + .max_voltage = 0, + .min_multi = 0, + .max_multi = 0 + }, + .bus_flags = MACHINE_PS2_VLB, + .flags = MACHINE_APM | MACHINE_VIDEO | MACHINE_IDE_DUAL, + .ram = { + .min = 1024, + .max = 65536, + .step = 1024 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = &gd5428_vlb_onboard_device, + .snd_device = NULL, + .net_device = NULL + }, /* Has AMIKey-2 'H' KBC firmware. */ { .name = "[OPTi 499] Alaris COUGAR 486BL", @@ -6570,6 +7298,46 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + /* Uses a ???? KBC. */ + { + .name = "[SiS 461] Dell 466/NP", + .internal_name = "dell466np", + .type = MACHINE_TYPE_486_S2, + .chipset = MACHINE_CHIPSET_SIS_461, + .init = machine_at_dell466np_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_SOCKET3, + .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, + .flags = MACHINE_IDE | MACHINE_VIDEO | MACHINE_APM, + .ram = { + .min = 1024, + .max = 32768, + .step = 1024 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = &gd5428_onboard_vlb_device, + .snd_device = NULL, + .net_device = NULL + }, /* The BIOS does not send any non-standard keyboard controller commands and wants a PS/2 mouse, so it's an IBM PS/2 KBC (Type 1) firmware. */ { @@ -6611,13 +7379,13 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, - /* Has AMI MegaKey KBC. */ + /* Has a VLSI VL82C113A SCAMP Combination I/O which holds the KBC. */ { - .name = "[i420TX] J-Bond PCI400C-A", - .internal_name = "pci400ca", + .name = "[VLSI 82C480] ZEOS Martin", + .internal_name = "martin", .type = MACHINE_TYPE_486_S2, - .chipset = MACHINE_CHIPSET_INTEL_420TX, - .init = machine_at_pci400ca_init, + .chipset = MACHINE_CHIPSET_VLSI_VL82C480, + .init = machine_at_martin_init, .p1_handler = NULL, .gpio_handler = NULL, .available_flag = MACHINE_AVAILABLE, @@ -6632,15 +7400,15 @@ const machine_t machines[] = { .min_multi = 0, .max_multi = 0 }, - .bus_flags = MACHINE_PCI, - .flags = MACHINE_SCSI, + .bus_flags = MACHINE_PS2_VLB, + .flags = MACHINE_IDE | MACHINE_APM, .ram = { - .min = 1024, + .min = 2048, .max = 65536, - .step = 1024 + .step = 2048 }, .nvrmask = 127, - .kbc_device = &keyboard_at_ami_device, + .kbc_device = NULL, .kbc_p1 = 0xff, .gpio = 0xffffffff, .gpio_acpi = 0xffffffff, @@ -6652,7 +7420,6 @@ const machine_t machines[] = { .net_device = NULL }, - /* 486 machines - Socket 3 */ /* 486 machines with just the ISA slot */ /* Has a Fujitsu MBL8042H KBC. */ @@ -6855,46 +7622,6 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, - /* has a Phoenix PLCC Multikey copyrighted 1993, version unknown. */ - { - .name = "[OPTi 895] Packard Bell PB450", - .internal_name = "pb450", - .type = MACHINE_TYPE_486_S3, - .chipset = MACHINE_CHIPSET_OPTI_895_802G, - .init = machine_at_pb450_init, - .p1_handler = NULL, - .gpio_handler = NULL, - .available_flag = MACHINE_AVAILABLE, - .gpio_acpi_handler = NULL, - .cpu = { - .package = CPU_PKG_SOCKET3, - .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_PCI, - .flags = MACHINE_SUPER_IO | MACHINE_IDE_DUAL | MACHINE_VIDEO, - .ram = { - .min = 1024, - .max = 65536, - .step = 1024 - }, - .nvrmask = 255, - .kbc_device = NULL, - .kbc_p1 = 0xff, - .gpio = 0xffffffff, - .gpio_acpi = 0xffffffff, - .device = NULL, - .fdc_device = NULL, - .sio_device = NULL, - .vid_device = &gd5428_vlb_onboard_device, - .snd_device = NULL, - .net_device = NULL - }, /* Uses an NEC 90M002A (UPD82C42C, 8042 clone) with unknown firmware. */ { .name = "[SiS 461] Acer V10", @@ -6962,7 +7689,7 @@ const machine_t machines[] = { .flags = MACHINE_APM, .ram = { .min = 1024, - .max = 65536, + .max = 131072, .step = 1024 }, .nvrmask = 127, @@ -7002,7 +7729,7 @@ const machine_t machines[] = { .flags = MACHINE_APM, .ram = { .min = 1024, - .max = 65536, + .max = 131072, .step = 1024 }, .nvrmask = 127, @@ -7082,7 +7809,7 @@ const machine_t machines[] = { .flags = MACHINE_APM, .ram = { .min = 1024, - .max = 65536, + .max = 131072, .step = 1024 }, .nvrmask = 127, @@ -7122,7 +7849,7 @@ const machine_t machines[] = { .flags = MACHINE_APM, .ram = { .min = 1024, - .max = 65536, + .max = 131072, .step = 1024 }, .nvrmask = 127, @@ -7201,9 +7928,9 @@ const machine_t machines[] = { .bus_flags = MACHINE_PS2_VLB, .flags = MACHINE_IDE | MACHINE_APM, /* Has internal video: Western Digital WD90C33-ZZ */ .ram = { - .min = 1024, - .max = 65536, - .step = 1024 + .min = 4096, + .max = 40960, + .step = 4096 }, .nvrmask = 127, .kbc_device = NULL, @@ -7241,9 +7968,9 @@ const machine_t machines[] = { .bus_flags = MACHINE_PS2, .flags = MACHINE_IDE_DUAL | MACHINE_SUPER_IO | MACHINE_APM | MACHINE_VIDEO, .ram = { - .min = 1024, - .max = 65536, - .step = 1024 + .min = 4096, + .max = 69632, + .step = 4096 }, .nvrmask = 127, .kbc_device = NULL, @@ -7384,7 +8111,7 @@ const machine_t machines[] = { { .name = "[ALi M1429G] MSI MS-4134", .internal_name = "ms4134", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_ALI_M1429G, .init = machine_at_ms4134_init, .p1_handler = NULL, @@ -7424,7 +8151,7 @@ const machine_t machines[] = { { .name = "[ALi M1429G] TriGem 486GP", .internal_name = "tg486gp", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_ALI_M1429G, .init = machine_at_tg486gp_init, .p1_handler = NULL, @@ -7464,7 +8191,7 @@ const machine_t machines[] = { { .name = "[ALi M1489] AAEON SBC-490", .internal_name = "sbc490", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_ALI_M1489, .init = machine_at_sbc490_init, .p1_handler = NULL, @@ -7493,10 +8220,10 @@ const machine_t machines[] = { .kbc_p1 = 0xff, .gpio = 0xffffffff, .gpio_acpi = 0xffffffff, - .device = &tgui9440_onboard_pci_device, + .device = NULL, .fdc_device = NULL, .sio_device = NULL, - .vid_device = NULL, + .vid_device = &tgui9440_onboard_pci_device, .snd_device = NULL, .net_device = NULL }, @@ -7505,7 +8232,7 @@ const machine_t machines[] = { { .name = "[ALi M1489] ABIT AB-PB4", .internal_name = "abpb4", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_ALI_M1489, .init = machine_at_abpb4_init, .p1_handler = NULL, @@ -7549,7 +8276,7 @@ const machine_t machines[] = { { .name = "[ALi M1489] AMI WinBIOS 486 PCI", .internal_name = "win486pci", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_ALI_M1489, .init = machine_at_win486pci_init, .p1_handler = NULL, @@ -7593,7 +8320,7 @@ const machine_t machines[] = { { .name = "[ALi M1489] MSI MS-4145", .internal_name = "ms4145", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_ALI_M1489, .init = machine_at_ms4145_init, .p1_handler = NULL, @@ -7633,7 +8360,7 @@ const machine_t machines[] = { { .name = "[ALi M1489] ESA TF-486", .internal_name = "tf486", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_ALI_M1489, .init = machine_at_tf486_init, .p1_handler = NULL, @@ -7673,7 +8400,7 @@ const machine_t machines[] = { { .name = "[ALi M1489] Acrosser AR-B1476", .internal_name = "arb1476", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_ALI_M1489, .init = machine_at_arb1476_init, .p1_handler = NULL, @@ -7713,7 +8440,7 @@ const machine_t machines[] = { { .name = "[OPTi 802G] IBM Aptiva 510/710/Vision", .internal_name = "aptiva510", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_OPTI_895_802G, .init = machine_at_aptiva510_init, .p1_handler = NULL, @@ -7753,7 +8480,7 @@ const machine_t machines[] = { { .name = "[OPTi 802G] IBM PC 330 (type 6573)", .internal_name = "pc330_6573", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_OPTI_895_802G, .init = machine_at_pc330_6573_init, .p1_handler = NULL, @@ -7789,11 +8516,51 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + /* has a Phoenix PLCC Multikey copyrighted 1993, version unknown. */ + { + .name = "[OPTi 895] Packard Bell PB450", + .internal_name = "pb450", + .type = MACHINE_TYPE_486_S3_PCI, + .chipset = MACHINE_CHIPSET_OPTI_895_802G, + .init = machine_at_pb450_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_SOCKET3, + .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_PCI, + .flags = MACHINE_SUPER_IO | MACHINE_IDE_DUAL | MACHINE_VIDEO, + .ram = { + .min = 1024, + .max = 65536, + .step = 1024 + }, + .nvrmask = 255, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = &pb450_device, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = &gd5428_vlb_onboard_device, + .snd_device = NULL, + .net_device = NULL + }, /* This has an AMIKey-2, which is an updated version of type 'H'. */ { .name = "[i420EX] ASUS PVI-486AP4", .internal_name = "486ap4", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_INTEL_420EX, .init = machine_at_486ap4_init, .p1_handler = NULL, @@ -7833,7 +8600,7 @@ const machine_t machines[] = { { .name = "[i420EX] Intel Classic/PCI ED", .internal_name = "ninja", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_INTEL_420EX, .init = machine_at_ninja_init, .p1_handler = NULL, @@ -7873,7 +8640,7 @@ const machine_t machines[] = { { .name = "[i420EX] Anigma BAT4IP3e", .internal_name = "bat4ip3e", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_INTEL_420EX, .init = machine_at_bat4ip3e_init, .p1_handler = NULL, @@ -7913,7 +8680,7 @@ const machine_t machines[] = { { .name = "[i420EX] Advanced Integration Research 486PI", .internal_name = "486pi", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_INTEL_420EX, .init = machine_at_486pi_init, .p1_handler = NULL, @@ -7953,7 +8720,7 @@ const machine_t machines[] = { { .name = "[i420EX] ICS SB486P", .internal_name = "sb486p", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_INTEL_420EX, .init = machine_at_sb486p_init, .p1_handler = NULL, @@ -7989,11 +8756,14 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, - /* I'm going to assume this as an AMIKey-2 like the other two 486SP3's. */ + /* + This has an AMIKey (and an on-board NCR 53C810 PCI SCSI controller), thanks, eBay! + The keyboard port is AT. + */ { .name = "[i420TX] ASUS PCI/I-486SP3", .internal_name = "486sp3", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_INTEL_420TX, .init = machine_at_486sp3_init, .p1_handler = NULL, @@ -8033,7 +8803,7 @@ const machine_t machines[] = { { .name = "[i420TX] Intel Classic/PCI", .internal_name = "alfredo", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_INTEL_420TX, .init = machine_at_alfredo_init, .p1_handler = NULL, @@ -8073,7 +8843,7 @@ const machine_t machines[] = { { .name = "[i420TX] AMI Super Voyager PCI", .internal_name = "amis76", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_INTEL_420TX, .init = machine_at_amis76_init, .p1_handler = NULL, @@ -8114,7 +8884,7 @@ const machine_t machines[] = { { .name = "[i420ZX] ASUS PCI/I-486SP3G", .internal_name = "486sp3g", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_INTEL_420ZX, .init = machine_at_486sp3g_init, .p1_handler = NULL, @@ -8150,11 +8920,52 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + /* This has an AMI MEGAKey 'P' or 'R' keyboard controller. */ + { + .name = "[i420ZX] ICS SB486PV", + .internal_name = "sb486pv", + .type = MACHINE_TYPE_486_S3_PCI, + .chipset = MACHINE_CHIPSET_INTEL_420ZX, + .init = machine_at_sb486pv_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_SOCKET3, + .block = CPU_BLOCK_NONE, + .min_bus = 0, + .max_bus = 0, + .min_voltage = 0, + .max_voltage = 0, + .min_multi = 0, + .max_multi = 0 + }, + /* Has PCI but no user-facing slots. */ + .bus_flags = MACHINE_PCI, + .flags = MACHINE_PS2_KBC | MACHINE_IDE | MACHINE_VIDEO | MACHINE_APM | MACHINE_PCI_INTERNAL, + .ram = { + .min = 2048, + .max = 65536, + .step = 2048 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = &sb486pv_device, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = &gd5436_onboard_pci_device, + .snd_device = NULL, + .net_device = NULL + }, /* This most likely has a standalone AMI Megakey 1993, which is type 'P', like the below Tekram board. */ { .name = "[IMS 8848] J-Bond PCI400C-B", .internal_name = "pci400cb", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_IMS_8848, .init = machine_at_pci400cb_init, .p1_handler = NULL, @@ -8190,11 +9001,50 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + { + .name = "[SiS 496] Acer P3", + .internal_name = "acerp3", + .type = MACHINE_TYPE_486_S3_PCI, + .chipset = MACHINE_CHIPSET_SIS_496, + .init = machine_at_acerp3_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_SOCKET3, + .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_PCI, + .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_VIDEO, + .ram = { + .min = 2048, + .max = 131072, + .step = 1024 + }, + .nvrmask = 255, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = &gd5434_onboard_pci_device, + .snd_device = NULL, + .net_device = NULL + }, /* This has an AMIKey-2, which is an updated version of type 'H'. */ { .name = "[SiS 496] ASUS PVI-486SP3C", .internal_name = "486sp3c", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_SIS_496, .init = machine_at_486sp3c_init, .p1_handler = NULL, @@ -8234,7 +9084,7 @@ const machine_t machines[] = { { .name = "[SiS 496] Lucky Star LS-486E", .internal_name = "ls486e", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_SIS_496, .init = machine_at_ls486e_init, .p1_handler = NULL, @@ -8251,8 +9101,8 @@ const machine_t machines[] = { .min_multi = 0, .max_multi = 0 }, - .bus_flags = MACHINE_BUS_PS2_LATCH | MACHINE_PCI, - .flags = MACHINE_IDE_DUAL | MACHINE_APM, + .bus_flags = MACHINE_PCI, + .flags = MACHINE_PS2_KBC | MACHINE_IDE_DUAL | MACHINE_APM, .ram = { .min = 1024, .max = 131072, @@ -8274,7 +9124,7 @@ const machine_t machines[] = { { .name = "[SiS 496] Micronics M4Li", .internal_name = "m4li", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_SIS_496, .init = machine_at_m4li_init, .p1_handler = NULL, @@ -8314,7 +9164,7 @@ const machine_t machines[] = { { .name = "[SiS 496] Rise Computer R418", .internal_name = "r418", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_SIS_496, .init = machine_at_r418_init, .p1_handler = NULL, @@ -8331,8 +9181,8 @@ const machine_t machines[] = { .min_multi = 0, .max_multi = 0 }, - .bus_flags = MACHINE_BUS_PS2_LATCH | MACHINE_PCI, - .flags = MACHINE_IDE_DUAL | MACHINE_APM, + .bus_flags = MACHINE_PCI, + .flags = MACHINE_PS2_KBC | MACHINE_IDE_DUAL | MACHINE_APM, .ram = { .min = 1024, .max = 261120, @@ -8355,7 +9205,7 @@ const machine_t machines[] = { { .name = "[SiS 496] Soyo 4SAW2", .internal_name = "4saw2", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_SIS_496, .init = machine_at_4saw2_init, .p1_handler = NULL, @@ -8396,7 +9246,7 @@ const machine_t machines[] = { { .name = "[SiS 496] Zida Tomato 4DP", .internal_name = "4dps", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_SIS_496, .init = machine_at_4dps_init, .p1_handler = NULL, @@ -8436,7 +9286,7 @@ const machine_t machines[] = { { .name = "[SiS 496] MSI MS-4144", .internal_name = "ms4144", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_SIS_496, .init = machine_at_ms4144_init, .p1_handler = NULL, @@ -8476,7 +9326,7 @@ const machine_t machines[] = { { .name = "[UMC 8881] A-Trend ATC-1415", .internal_name = "atc1415", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_UMC_UM8881, .init = machine_at_atc1415_init, .p1_handler = NULL, @@ -8512,11 +9362,52 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + /* This has the UMC 88xx on-chip KBC. All the copies of the BIOS string I can find, end in + in -H, so the UMC on-chip KBC likely emulates the AMI 'H' KBC firmware. */ + { + .name = "[UMC 8881] Biostar MB-84xxUUD-A", + .internal_name = "84xxuuda", + .type = MACHINE_TYPE_486_S3_PCI, + .chipset = MACHINE_CHIPSET_UMC_UM8881, + .init = machine_at_84xxuuda_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_SOCKET3, + .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_PCI, + .flags = MACHINE_IDE_DUAL | MACHINE_APM, + .ram = { + .min = 1024, + .max = 131072, + .step = 1024 + }, + .nvrmask = 255, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, /* This has an AMIKey-2, which is an updated version of type 'H'. */ { .name = "[UMC 8881] ECS Elite UM8810P-AIO", .internal_name = "ecs486", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_UMC_UM8881, .init = machine_at_ecs486_init, .p1_handler = NULL, @@ -8533,8 +9424,8 @@ const machine_t machines[] = { .min_multi = 0, .max_multi = 0 }, - .bus_flags = MACHINE_PCI | MACHINE_BUS_PS2_LATCH, - .flags = MACHINE_IDE_DUAL | MACHINE_APM, + .bus_flags = MACHINE_PCI, + .flags = MACHINE_PS2_KBC | MACHINE_IDE_DUAL | MACHINE_APM, .ram = { .min = 1024, .max = 131072, @@ -8556,7 +9447,7 @@ const machine_t machines[] = { { .name = "[UMC 8881] Epson ActionPC 2600", .internal_name = "actionpc2600", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_UMC_UM8881, .init = machine_at_actionpc2600_init, .p1_handler = NULL, @@ -8588,7 +9479,7 @@ const machine_t machines[] = { .device = NULL, .fdc_device = NULL, .sio_device = NULL, - .vid_device = NULL, + .vid_device = &tgui9440_onboard_pci_device, .snd_device = NULL, .net_device = NULL }, @@ -8597,7 +9488,7 @@ const machine_t machines[] = { { .name = "[UMC 8881] Epson ActionTower 8400", .internal_name = "actiontower8400", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_UMC_UM8881, .init = machine_at_actiontower8400_init, .p1_handler = NULL, @@ -8629,7 +9520,7 @@ const machine_t machines[] = { .device = NULL, .fdc_device = NULL, .sio_device = NULL, - .vid_device = NULL, + .vid_device = &gd5430_onboard_pci_device, .snd_device = NULL, .net_device = NULL }, @@ -8638,7 +9529,7 @@ const machine_t machines[] = { { .name = "[UMC 8881] PC Chips M919", .internal_name = "m919", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_UMC_UM8881, .init = machine_at_m919_init, .p1_handler = NULL, @@ -8678,7 +9569,7 @@ const machine_t machines[] = { { .name = "[UMC 8881] Samsung SPC7700P-LW", .internal_name = "spc7700plw", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_UMC_UM8881, .init = machine_at_spc7700plw_init, .p1_handler = NULL, @@ -8718,7 +9609,7 @@ const machine_t machines[] = { { .name = "[UMC 8881] Shuttle HOT-433A", .internal_name = "hot433a", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_UMC_UM8881, .init = machine_at_hot433a_init, .p1_handler = NULL, @@ -8735,7 +9626,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, @@ -8747,7 +9638,7 @@ const machine_t machines[] = { .kbc_p1 = 0xff, .gpio = 0xffffffff, .gpio_acpi = 0xffffffff, - .device = NULL, + .device = &hot433a_device, .fdc_device = NULL, .sio_device = NULL, .vid_device = NULL, @@ -8759,7 +9650,7 @@ const machine_t machines[] = { { .name = "[UMC 8881] Compaq Presario 7100/7200 Series 486", .internal_name = "pl4600c", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_UMC_UM8881, .init = machine_at_pl4600c_init, .p1_handler = NULL, @@ -8776,7 +9667,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_VIDEO | MACHINE_SOUND | MACHINE_APM, .ram = { .min = 1024, @@ -8799,7 +9690,7 @@ const machine_t machines[] = { { .name = "[VIA VT82C496G] DFI G486VPA", .internal_name = "g486vpa", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_VIA_VT82C496G, .init = machine_at_g486vpa_init, .p1_handler = NULL, @@ -8839,7 +9730,7 @@ const machine_t machines[] = { { .name = "[VIA VT82C496G] FIC VIP-IO2", .internal_name = "486vipio2", - .type = MACHINE_TYPE_486_S3, + .type = MACHINE_TYPE_486_S3_PCI, .chipset = MACHINE_CHIPSET_VIA_VT82C496G, .init = machine_at_486vipio2_init, .p1_handler = NULL, @@ -8942,7 +9833,7 @@ const machine_t machines[] = { .max_multi = 2.0 }, .bus_flags = MACHINE_PS2_PCI, - .flags = MACHINE_IDE_DUAL | MACHINE_APM, /* Machine has internal video: ST STPC Atlas */ + .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_PCI_INTERNAL, /* Machine has internal video: ST STPC Atlas */ .ram = { .min = 32768, .max = 163840, @@ -8983,7 +9874,7 @@ const machine_t machines[] = { .max_multi = 2.0 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, - .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_USB, /* Machine has internal video: ST STPC Atlas */ + .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_PCI_INTERNAL | MACHINE_USB, /* Machine has internal video: ST STPC Atlas */ .ram = { .min = 32768, .max = 163840, @@ -9024,7 +9915,7 @@ const machine_t machines[] = { .max_multi = 2.0 }, .bus_flags = MACHINE_PS2, - .flags = MACHINE_IDE | MACHINE_APM, /* Machine has internal video: ST STPC Atlas and NIC: Realtek RTL8139C+ */ + .flags = MACHINE_IDE | MACHINE_APM | MACHINE_PCI_INTERNAL, /* Machine has internal video: ST STPC Atlas and NIC: Realtek RTL8139C+ */ .ram = { .min = 32768, .max = 131072, @@ -9065,7 +9956,7 @@ const machine_t machines[] = { .max_multi = 2.0 }, .bus_flags = MACHINE_PS2_PCI, - .flags = MACHINE_IDE_DUAL | MACHINE_APM, + .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_PCI_INTERNAL, .ram = { .min = 32768, .max = 98304, @@ -9106,7 +9997,7 @@ const machine_t machines[] = { .max_multi = 2.0 }, .bus_flags = MACHINE_PS2_PCI, - .flags = MACHINE_IDE_DUAL | MACHINE_APM, + .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_PCI_INTERNAL, .ram = { .min = 32768, .max = 131072, @@ -9192,8 +10083,8 @@ const machine_t machines[] = { .min_multi = MACHINE_MULTIPLIER_FIXED, .max_multi = MACHINE_MULTIPLIER_FIXED }, - .bus_flags = MACHINE_BUS_PS2_LATCH | MACHINE_PCI, - .flags = MACHINE_APM, + .bus_flags = MACHINE_PCI, + .flags = MACHINE_PS2_KBC | MACHINE_APM, .ram = { .min = 2048, .max = 196608, @@ -9232,7 +10123,7 @@ const machine_t machines[] = { .min_multi = MACHINE_MULTIPLIER_FIXED, .max_multi = MACHINE_MULTIPLIER_FIXED }, - .bus_flags = MACHINE_PCI, + .bus_flags = MACHINE_PS2_PCI, .flags = MACHINE_IDE | MACHINE_APM, .ram = { .min = 2048, @@ -9579,6 +10470,46 @@ const machine_t machines[] = { }, /* OPTi 596/597/822 */ + /* Has a VIA VT82C42N KBC with AMI 'F' firmware */ + { + .name = "[OPTi 597] AT&T Globalyst 330 (Pentium)", + .internal_name = "globalyst330_p5", + .type = MACHINE_TYPE_SOCKET4, + .chipset = MACHINE_CHIPSET_OPTI_547_597, + .init = machine_at_globalyst330_p5_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_SOCKET4, + .block = CPU_BLOCK_NONE, + .min_bus = 60000000, + .max_bus = 66666667, + .min_voltage = 5000, + .max_voltage = 5000, + .min_multi = MACHINE_MULTIPLIER_FIXED, + .max_multi = MACHINE_MULTIPLIER_FIXED + }, + .bus_flags = MACHINE_PCIV, + .flags = MACHINE_APM, + .ram = { + .min = 8192, + .max = 65536, + .step = 8192 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, /* This has AMIKey 'F' KBC firmware. */ { .name = "[OPTi 597] Supermicro P5VL-PCI", @@ -9716,7 +10647,7 @@ const machine_t machines[] = { .gpio_acpi_handler = NULL, .cpu = { .package = CPU_PKG_SOCKET5_7, - .block = CPU_BLOCK_NONE, + .block = CPU_BLOCK(CPU_K5, CPU_5K86, CPU_Cx6x86), .min_bus = 50000000, .max_bus = 66666667, .min_voltage = 3520, @@ -9756,7 +10687,7 @@ const machine_t machines[] = { .gpio_acpi_handler = NULL, .cpu = { .package = CPU_PKG_SOCKET5_7, - .block = CPU_BLOCK_NONE, + .block = CPU_BLOCK(CPU_K5, CPU_5K86, CPU_Cx6x86), .min_bus = 50000000, .max_bus = 66666667, .min_voltage = 3520, @@ -9783,6 +10714,46 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + + { + .name = "[i430NX] Siemens-Nixdorf D842", + .internal_name = "d842", + .type = MACHINE_TYPE_SOCKET5, + .chipset = MACHINE_CHIPSET_INTEL_430NX, + .init = machine_at_d842_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_SOCKET5_7, + .block = CPU_BLOCK_NONE, + .min_bus = 50000000, + .max_bus = 66666667, + .min_voltage = 3380, + .max_voltage = 3520, + .min_multi = 1.5, + .max_multi = 2.0 + }, + .bus_flags = MACHINE_PS2_PCI, + .flags = MACHINE_IDE_DUAL | MACHINE_APM, + .ram = { + .min = 2048, + .max = 131072, + .step = 2048 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = &d842_device, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, /* This has the Phoenix MultiKey KBC firmware. This is basically an Intel Premiere/PCI II with a fancier POST screen. */ { @@ -9797,7 +10768,7 @@ const machine_t machines[] = { .gpio_acpi_handler = NULL, .cpu = { .package = CPU_PKG_SOCKET5_7, - .block = CPU_BLOCK_NONE, + .block = CPU_BLOCK(CPU_K5, CPU_5K86, CPU_Cx6x86), .min_bus = 50000000, .max_bus = 66666667, .min_voltage = 3380, @@ -9846,7 +10817,7 @@ const machine_t machines[] = { .max_multi = 1.5 }, .bus_flags = MACHINE_PS2_PCI, - .flags = MACHINE_IDE | MACHINE_SCSI | MACHINE_APM, + .flags = MACHINE_IDE /*| MACHINE_SCSI */ | MACHINE_APM, .ram = { .min = 2048, .max = 524288, @@ -10026,6 +10997,46 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + /* Has a National Semiconductor PC87332VLJ Super I/O with AMIKey 'F' KBC firmware. */ + { + .name = "[i430FX] Dell OptiPlex GXL/GXM", + .internal_name = "optiplexgxl", + .type = MACHINE_TYPE_SOCKET5, + .chipset = MACHINE_CHIPSET_INTEL_430FX, + .init = machine_at_optiplexgxl_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_SOCKET5_7, + .block = CPU_BLOCK(CPU_Cx6x86), + .min_bus = 60000000, + .max_bus = 66666667, + .min_voltage = 3380, + .max_voltage = 3520, + .min_multi = 1.5, + .max_multi = 3.0 + }, + .bus_flags = MACHINE_PS2_PCI, + .flags = MACHINE_IDE_DUAL | MACHINE_VIDEO | MACHINE_SOUND | MACHINE_APM, /* Video: S3 Trio64V+ (86C765), Sound: Creative ViBRA 16S (CT2504), Network: 3Com ETHERLINK III (3C509B) */ + .ram = { + .min = 8192, + .max = 131072, + .step = 8192 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = &s3_phoenix_trio64vplus_onboard_pci_device, + .snd_device = &sb_vibra16s_onboard_device, + .net_device = NULL /* not yet emulated */ + }, /* According to tests from real hardware: This has AMI MegaKey KBC firmware on the PC87306 Super I/O chip, command 0xA1 returns '5'. Command 0xA0 copyright string: (C)1994 AMI . */ @@ -10041,7 +11052,7 @@ const machine_t machines[] = { .gpio_acpi_handler = NULL, .cpu = { .package = CPU_PKG_SOCKET5_7, - .block = CPU_BLOCK_NONE, + .block = CPU_BLOCK(CPU_K5, CPU_5K86, CPU_Cx6x86), .min_bus = 50000000, .max_bus = 66666667, .min_voltage = 3380, @@ -10695,7 +11706,7 @@ const machine_t machines[] = { .gpio_acpi_handler = NULL, .cpu = { .package = CPU_PKG_SOCKET5_7, - .block = CPU_BLOCK_NONE, + .block = CPU_BLOCK(CPU_K5, CPU_5K86, CPU_Cx6x86), .min_bus = 50000000, .max_bus = 66666667, .min_voltage = 3380, @@ -10778,7 +11789,7 @@ const machine_t machines[] = { .gpio_acpi_handler = NULL, .cpu = { .package = CPU_PKG_SOCKET5_7, - .block = CPU_BLOCK_NONE, + .block = CPU_BLOCK(CPU_K5, CPU_5K86, CPU_Cx6x86), .min_bus = 50000000, .max_bus = 66666667, .min_voltage = 3380, @@ -10862,7 +11873,7 @@ const machine_t machines[] = { .gpio_acpi_handler = NULL, .cpu = { .package = CPU_PKG_SOCKET5_7, - .block = CPU_BLOCK_NONE, + .block = CPU_BLOCK(CPU_K5, CPU_5K86, CPU_Cx6x86), .min_bus = 50000000, .max_bus = 66666667, .min_voltage = 3380, @@ -10943,7 +11954,7 @@ const machine_t machines[] = { .gpio_acpi_handler = NULL, .cpu = { .package = CPU_PKG_SOCKET5_7, - .block = CPU_BLOCK_NONE, + .block = CPU_BLOCK(CPU_K5, CPU_5K86, CPU_Cx6x86), .min_bus = 50000000, .max_bus = 66666667, .min_voltage = 3380, @@ -11078,9 +12089,9 @@ const machine_t machines[] = { .bus_flags = MACHINE_PS2_PCI, .flags = MACHINE_IDE_DUAL | MACHINE_APM, .ram = { - .min = 8192, - .max = 196608, - .step = 8192 + .min = 4096, + .max = 524288, + .step = 4096 }, .nvrmask = 511, .kbc_device = NULL, @@ -11113,14 +12124,14 @@ const machine_t machines[] = { .min_voltage = 3450, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 2.5 }, .bus_flags = MACHINE_PS2_PCI, .flags = MACHINE_IDE_DUAL | MACHINE_APM, .ram = { - .min = 8192, + .min = 4096, .max = 524288, - .step = 8192 + .step = 4096 }, .nvrmask = 127, .kbc_device = NULL, @@ -11158,9 +12169,9 @@ const machine_t machines[] = { .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 524288, - .step = 8192 + .step = 4096 }, .nvrmask = 127, .kbc_device = NULL, @@ -11175,6 +12186,46 @@ const machine_t machines[] = { .net_device = NULL }, + { + .name = "[i430HX] Siemens-Nixdorf D943", + .internal_name = "d943", + .type = MACHINE_TYPE_SOCKET7_3V, + .chipset = MACHINE_CHIPSET_INTEL_430HX, + .init = machine_at_d943_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_SOCKET5_7, + .block = CPU_BLOCK_NONE, + .min_bus = 50000000, + .max_bus = 66666667, + .min_voltage = 2800, + .max_voltage = 3520, + .min_multi = 1.5, + .max_multi = 3.0 + }, + .bus_flags = MACHINE_PS2_PCI, + .flags = MACHINE_IDE_DUAL | MACHINE_AV | MACHINE_GAMEPORT | MACHINE_APM, + .ram = { + .min = 8192, + .max = 131072, + .step = 8192 + }, + .nvrmask = 511, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = &d943_device, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = &gd5436_onboard_pci_device, + .snd_device = &sb_vibra16c_onboard_device, + .net_device = NULL + }, + /* 430VX */ /* Has a SM(S)C FDC37C932FR Super I/O chip with on-chip KBC with AMI MegaKey (revision '5') KBC firmware. */ @@ -11190,7 +12241,7 @@ const machine_t machines[] = { .gpio_acpi_handler = NULL, .cpu = { .package = CPU_PKG_SOCKET5_7, - .block = CPU_BLOCK_NONE, + .block = CPU_BLOCK(CPU_K5, CPU_5K86, CPU_Cx6x86), .min_bus = 50000000, .max_bus = 66666667, .min_voltage = 3380, @@ -11199,11 +12250,11 @@ const machine_t machines[] = { .max_multi = 3.0 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, - .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_GAMEPORT | MACHINE_USB, + .flags = MACHINE_IDE_DUAL | MACHINE_SOUND | MACHINE_APM | MACHINE_GAMEPORT | MACHINE_USB, .ram = { .min = 8192, .max = 131072, - .step = 8192 + .step = 4096 }, .nvrmask = 511, .kbc_device = NULL, @@ -11214,14 +12265,14 @@ const machine_t machines[] = { .fdc_device = NULL, .sio_device = NULL, .vid_device = NULL, - .snd_device = NULL, + .snd_device = &sb_vibra16c_onboard_device, .net_device = NULL }, /* SiS 5501 */ /* Has the Lance LT38C41 KBC. */ { - .name = "[SiS 5501] Chaintech 5SBM2 (M103)", + .name = "[SiS 5501] Chaintech 5SBM/5SBM2 (M103)", .internal_name = "5sbm2", .type = MACHINE_TYPE_SOCKET7_3V, .chipset = MACHINE_CHIPSET_SIS_5501, @@ -11244,7 +12295,7 @@ const machine_t machines[] = { .flags = MACHINE_IDE_DUAL | MACHINE_APM, .ram = { .min = 8192, - .max = 262144, + .max = 131072, .step = 8192 }, .nvrmask = 255, @@ -11252,7 +12303,7 @@ const machine_t machines[] = { .kbc_p1 = 0xff, .gpio = 0xffffffff, .gpio_acpi = 0xffffffff, - .device = NULL, + .device = &c5sbm2_device, .fdc_device = NULL, .sio_device = NULL, .vid_device = NULL, @@ -11294,7 +12345,7 @@ const machine_t machines[] = { .kbc_p1 = 0xff, .gpio = 0xffffffff, .gpio_acpi = 0xffffffff, - .device = NULL, + .device = &ap5s_device, .fdc_device = NULL, .sio_device = NULL, .vid_device = NULL, @@ -11427,7 +12478,7 @@ const machine_t machines[] = { /* Has a SM(S)C FDC37C935 Super I/O chip with on-chip KBC with Phoenix MultiKey/42 (version 1.38) KBC firmware. */ { - .name = "[i430HX] Acer M3A", + .name = "[i430HX] Acer AcerPower Ultima", .internal_name = "acerm3a", .type = MACHINE_TYPE_SOCKET7, .chipset = MACHINE_CHIPSET_INTEL_430HX, @@ -11449,9 +12500,9 @@ const machine_t machines[] = { .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_GAMEPORT | MACHINE_USB, /* Machine has internal SCSI */ .ram = { - .min = 8192, - .max = 196608, - .step = 8192 + .min = 4096, + .max = 524288, + .step = 4096 }, .nvrmask = 511, .kbc_device = NULL, @@ -11480,18 +12531,18 @@ const machine_t machines[] = { .package = CPU_PKG_SOCKET5_7, .block = CPU_BLOCK_NONE, .min_bus = 50000000, - .max_bus = 83333333, + .max_bus = 75000000, .min_voltage = 2500, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 4.0 }, .bus_flags = MACHINE_PS2_PCI, .flags = MACHINE_IDE_DUAL | MACHINE_APM, .ram = { - .min = 8192, - .max = 262144, - .step = 8192 + .min = 4096, + .max = 524288, + .step = 4096 }, .nvrmask = 127, .kbc_device = NULL, @@ -11524,14 +12575,14 @@ const machine_t machines[] = { .min_voltage = 2500, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, /* Machine has AMB */ .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 524288, - .step = 8192 + .step = 4096 }, .nvrmask = 127, .kbc_device = NULL, @@ -11560,7 +12611,7 @@ const machine_t machines[] = { .cpu = { .package = CPU_PKG_SOCKET5_7, .block = CPU_BLOCK_NONE, - .min_bus = 50000000, + .min_bus = 60000000, .max_bus = 66666667, .min_voltage = 2800, .max_voltage = 3520, @@ -11570,9 +12621,9 @@ const machine_t machines[] = { .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_GAMEPORT | MACHINE_USB, .ram = { - .min = 8192, - .max = 131072, - .step = 8192 + .min = 4096, + .max = 524288, + .step = 4096 }, .nvrmask = 511, .kbc_device = NULL, @@ -11590,7 +12641,7 @@ const machine_t machines[] = { PC87306 Super I/O chip, command 0xA1 returns '5'. Command 0xA0 copyright string: (C)1994 AMI . */ { - .name = "[i430HX] Intel TC430HX", + .name = "[i430HX] Intel TC430HX (Tucson)", .internal_name = "tc430hx", .type = MACHINE_TYPE_SOCKET7, .chipset = MACHINE_CHIPSET_INTEL_430HX, @@ -11601,20 +12652,21 @@ const machine_t machines[] = { .gpio_acpi_handler = NULL, .cpu = { .package = CPU_PKG_SOCKET5_7, - .block = CPU_BLOCK_NONE, + .block = CPU_BLOCK(CPU_K5, CPU_5K86, CPU_K6, CPU_K6_2, CPU_K6_2C, CPU_K6_3, CPU_K6_2P, + CPU_K6_3P, CPU_Cx6x86, CPU_Cx6x86MX, CPU_Cx6x86L), .min_bus = 50000000, .max_bus = 66666667, .min_voltage = 2800, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_VIDEO | MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_GAMEPORT | MACHINE_USB, /* Has internal sound: Yamaha YMF701-S */ .ram = { .min = 8192, - .max = 131072, - .step = 8192 + .max = 524288, + .step = 4096 }, .nvrmask = 255, .kbc_device = NULL, @@ -11630,7 +12682,7 @@ const machine_t machines[] = { }, /* OEM version of Intel TC430HX, has AMI MegaKey KBC firmware on the PC87306 Super I/O chip. */ { - .name = "[i430HX] Toshiba Infinia 7200", + .name = "[i430HX] Toshiba Infinia 7201", .internal_name = "infinia7200", .type = MACHINE_TYPE_SOCKET7, .chipset = MACHINE_CHIPSET_INTEL_430HX, @@ -11641,20 +12693,21 @@ const machine_t machines[] = { .gpio_acpi_handler = NULL, .cpu = { .package = CPU_PKG_SOCKET5_7, - .block = CPU_BLOCK_NONE, + .block = CPU_BLOCK(CPU_K5, CPU_5K86, CPU_K6, CPU_K6_2, CPU_K6_2C, CPU_K6_3, CPU_K6_2P, + CPU_K6_3P, CPU_Cx6x86, CPU_Cx6x86MX, CPU_Cx6x86L), .min_bus = 50000000, .max_bus = 66666667, .min_voltage = 2800, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_VIDEO | MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_GAMEPORT | MACHINE_USB, /* Has internal sound: Yamaha YMF701-S */ .ram = { .min = 8192, - .max = 131072, - .step = 8192 + .max = 524288, + .step = 4096 }, .nvrmask = 255, .kbc_device = NULL, @@ -11670,7 +12723,7 @@ const machine_t machines[] = { }, /* OEM-only Intel CU430HX, has AMI MegaKey KBC firmware on the PC87306 Super I/O chip. */ { - .name = "[i430HX] Intel CU430HX", + .name = "[i430HX] Intel CU430HX (Cumberland)", .internal_name = "cu430hx", .type = MACHINE_TYPE_SOCKET7, .chipset = MACHINE_CHIPSET_INTEL_430HX, @@ -11681,20 +12734,21 @@ const machine_t machines[] = { .gpio_acpi_handler = NULL, .cpu = { .package = CPU_PKG_SOCKET5_7, - .block = CPU_BLOCK_NONE, + .block = CPU_BLOCK(CPU_K5, CPU_5K86, CPU_K6, CPU_K6_2, CPU_K6_2C, CPU_K6_3, CPU_K6_2P, + CPU_K6_3P, CPU_Cx6x86, CPU_Cx6x86MX, CPU_Cx6x86L), .min_bus = 50000000, .max_bus = 66666667, .min_voltage = 2800, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_SOUND | MACHINE_APM | MACHINE_USB, .ram = { .min = 8192, - .max = 196608, - .step = 8192 + .max = 524288, + .step = 4096 }, .nvrmask = 255, .kbc_device = NULL, @@ -11721,20 +12775,21 @@ const machine_t machines[] = { .gpio_acpi_handler = NULL, .cpu = { .package = CPU_PKG_SOCKET5_7, - .block = CPU_BLOCK_NONE, + .block = CPU_BLOCK(CPU_K5, CPU_5K86, CPU_K6, CPU_K6_2, CPU_K6_2C, CPU_K6_3, CPU_K6_2P, + CPU_K6_3P, CPU_Cx6x86, CPU_Cx6x86MX, CPU_Cx6x86L), .min_bus = 50000000, .max_bus = 66666667, .min_voltage = 2800, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_SOUND | MACHINE_APM | MACHINE_USB, .ram = { .min = 8192, - .max = 196608, - .step = 8192 + .max = 524288, + .step = 4096 }, .nvrmask = 255, .kbc_device = NULL, @@ -11748,6 +12803,46 @@ const machine_t machines[] = { .snd_device = &sb_vibra16c_onboard_device, .net_device = NULL }, + /* Unknown PS/2 KBC. */ + { + .name = "[i430HX] Radisys EPC-2102", + .internal_name = "epc2102", + .type = MACHINE_TYPE_SOCKET7, + .chipset = MACHINE_CHIPSET_INTEL_430HX, + .init = machine_at_epc2102_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_SOCKET5_7, + .block = CPU_BLOCK_NONE, + .min_bus = 50000000, + .max_bus = 66666667, + .min_voltage = 2500, + .max_voltage = 3520, + .min_multi = 1.5, + .max_multi = 3.5 + }, + .bus_flags = MACHINE_PS2_PCI, + .flags = MACHINE_IDE_DUAL | MACHINE_APM, + .ram = { + .min = 4096, + .max = 524288, + .step = 4096 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, /* According to tests from real hardware: This has AMI MegaKey KBC firmware on the PC87306 Super I/O chip, command 0xA1 returns '5'. Command 0xA0 copyright string: (C)1994 AMI . @@ -11764,7 +12859,8 @@ const machine_t machines[] = { .gpio_acpi_handler = NULL, .cpu = { .package = CPU_PKG_SOCKET5_7, - .block = CPU_BLOCK_NONE, + .block = CPU_BLOCK(CPU_K5, CPU_5K86, CPU_K6, CPU_K6_2, CPU_K6_2C, CPU_K6_3, CPU_K6_2P, + CPU_K6_3P, CPU_Cx6x86, CPU_Cx6x86MX, CPU_Cx6x86L), .min_bus = 50000000, .max_bus = 66666667, .min_voltage = 2800, @@ -11776,8 +12872,8 @@ const machine_t machines[] = { .flags = MACHINE_IDE_DUAL | MACHINE_APM, .ram = { .min = 8192, - .max = 196608, - .step = 8192 + .max = 524288, + .step = 4096 }, .nvrmask = 255, .kbc_device = NULL, @@ -11816,9 +12912,9 @@ const machine_t machines[] = { .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_USB, .ram = { - .min = 8192, - .max = 786432, - .step = 8192 + .min = 4096, + .max = 524288, + .step = 4096 }, .nvrmask = 255, .kbc_device = NULL, @@ -11858,9 +12954,9 @@ const machine_t machines[] = { .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_SCSI | MACHINE_APM | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 131072, - .step = 8192 + .step = 4096 }, .nvrmask = 127, .kbc_device = NULL, @@ -11893,14 +12989,14 @@ const machine_t machines[] = { .min_voltage = 2500, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, /* Machine has AMB */ .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 131072, - .step = 8192 + .step = 4096 }, .nvrmask = 127, .kbc_device = NULL, @@ -11934,14 +13030,14 @@ const machine_t machines[] = { .min_voltage = 2500, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 131072, - .step = 8192 + .step = 4096 }, .nvrmask = 127, .kbc_device = NULL, @@ -11979,9 +13075,9 @@ const machine_t machines[] = { .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 131072, - .step = 8192 + .step = 4096 }, .nvrmask = 127, .kbc_device = NULL, @@ -11998,7 +13094,7 @@ const machine_t machines[] = { /* Has a SM(S)C FDC37C932QF Super I/O chip with on-chip KBC with AMI MegaKey (revision '5') KBC firmware. */ { - .name = "[i430VX] Compaq Presario 2240", + .name = "[i430VX] Compaq Presario 224x", .internal_name = "presario2240", .type = MACHINE_TYPE_SOCKET7, .chipset = MACHINE_CHIPSET_INTEL_430VX, @@ -12010,19 +13106,19 @@ const machine_t machines[] = { .cpu = { .package = CPU_PKG_SOCKET5_7, .block = CPU_BLOCK_NONE, - .min_bus = 50000000, + .min_bus = 66666667, .max_bus = 66666667, .min_voltage = 2800, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI, .flags = MACHINE_IDE_DUAL | MACHINE_VIDEO | MACHINE_APM | MACHINE_ACPI, .ram = { - .min = 8192, - .max = 131072, - .step = 8192 + .min = 16384, + .max = 49152, + .step = 4096 }, .nvrmask = 511, .kbc_device = NULL, @@ -12039,7 +13135,7 @@ const machine_t machines[] = { /* Has a SM(S)C FDC37C931APM Super I/O chip with on-chip KBC with Compaq KBC firmware. */ { - .name = "[i430VX] Compaq Presario 4500", + .name = "[i430VX] Compaq Presario 45xx", .internal_name = "presario4500", .type = MACHINE_TYPE_SOCKET7, .chipset = MACHINE_CHIPSET_INTEL_430VX, @@ -12051,19 +13147,19 @@ const machine_t machines[] = { .cpu = { .package = CPU_PKG_SOCKET5_7, .block = CPU_BLOCK_NONE, - .min_bus = 50000000, + .min_bus = 66666667, .max_bus = 66666667, .min_voltage = 2800, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI, .flags = MACHINE_IDE_DUAL | MACHINE_VIDEO | MACHINE_APM | MACHINE_ACPI, .ram = { - .min = 8192, - .max = 131072, - .step = 8192 + .min = 16384, + .max = 49152, + .step = 4096 }, .nvrmask = 511, .kbc_device = NULL, @@ -12080,7 +13176,7 @@ const machine_t machines[] = { /* Has a SM(S)C FDC37C932FR Super I/O chip with on-chip KBC with AMI MegaKey (revision '5') KBC firmware. */ { - .name = "[i430VX] Dell Hannibal+", + .name = "[i430VX] Dell Dimension XPS Pxxxa/Mxxxa", .internal_name = "dellhannibalp", .type = MACHINE_TYPE_SOCKET7, .chipset = MACHINE_CHIPSET_INTEL_430VX, @@ -12091,20 +13187,21 @@ const machine_t machines[] = { .gpio_acpi_handler = NULL, .cpu = { .package = CPU_PKG_SOCKET5_7, - .block = CPU_BLOCK_NONE, + .block = CPU_BLOCK(CPU_K5, CPU_5K86, CPU_K6, CPU_K6_2, CPU_K6_2C, CPU_K6_3, CPU_K6_2P, + CPU_K6_3P, CPU_Cx6x86, CPU_Cx6x86MX, CPU_Cx6x86L), .min_bus = 50000000, .max_bus = 66666667, .min_voltage = 2500, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_USB, .ram = { .min = 8192, .max = 131072, - .step = 8192 + .step = 4096 }, .nvrmask = 511, .kbc_device = NULL, @@ -12142,9 +13239,9 @@ const machine_t machines[] = { .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 131072, - .step = 8192 + .step = 4096 }, .nvrmask = 127, .kbc_device = NULL, @@ -12174,7 +13271,7 @@ const machine_t machines[] = { .package = CPU_PKG_SOCKET5_7, .block = CPU_BLOCK_NONE, .min_bus = 50000000, - .max_bus = 66666667, + .max_bus = 75000000, .min_voltage = 2500, .max_voltage = 3520, .min_multi = 1.5, @@ -12183,9 +13280,9 @@ const machine_t machines[] = { .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 131072, - .step = 8192 + .step = 4096 }, .nvrmask = 511, .kbc_device = NULL, @@ -12213,7 +13310,8 @@ const machine_t machines[] = { .gpio_acpi_handler = NULL, .cpu = { .package = CPU_PKG_SOCKET5_7, - .block = CPU_BLOCK_NONE, + .block = CPU_BLOCK(CPU_K5, CPU_5K86, CPU_K6, CPU_K6_2, CPU_K6_2C, CPU_K6_3, CPU_K6_2P, + CPU_K6_3P, CPU_Cx6x86, CPU_Cx6x86MX, CPU_Cx6x86L), .min_bus = 50000000, .max_bus = 66666667, .min_voltage = 2200, @@ -12222,11 +13320,11 @@ const machine_t machines[] = { .max_multi = 3.0 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, - .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_GAMEPORT | MACHINE_USB, + .flags = MACHINE_IDE_DUAL | MACHINE_SOUND | MACHINE_APM | MACHINE_GAMEPORT | MACHINE_USB, .ram = { .min = 8192, .max = 131072, - .step = 8192 + .step = 4096 }, .nvrmask = 511, .kbc_device = NULL, @@ -12237,7 +13335,7 @@ const machine_t machines[] = { .fdc_device = NULL, .sio_device = NULL, .vid_device = NULL, - .snd_device = NULL, + .snd_device = &sb_vibra16c_onboard_device, .net_device = NULL }, /* Has a SM(S)C FDC37C935 Super I/O chip with on-chip KBC with Phoenix @@ -12260,14 +13358,14 @@ const machine_t machines[] = { .min_voltage = 2200, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI, .flags = MACHINE_IDE_DUAL | MACHINE_APM, .ram = { - .min = 16384, + .min = 8192, .max = 131072, - .step = 8192 + .step = 4096 }, .nvrmask = 511, .kbc_device = NULL, @@ -12285,7 +13383,7 @@ const machine_t machines[] = { PC87306 Super I/O chip, command 0xA1 returns '5'. Command 0xA0 copyright string: (C)1994 AMI . */ { - .name = "[i430VX] Packard Bell PB680", + .name = "[i430VX] Packard Bell Multimedia C110", .internal_name = "pb680", .type = MACHINE_TYPE_SOCKET7, .chipset = MACHINE_CHIPSET_INTEL_430VX, @@ -12296,7 +13394,8 @@ const machine_t machines[] = { .gpio_acpi_handler = NULL, .cpu = { .package = CPU_PKG_SOCKET5_7, - .block = CPU_BLOCK_NONE, + .block = CPU_BLOCK(CPU_K5, CPU_5K86, CPU_K6, CPU_K6_2, CPU_K6_2C, CPU_K6_3, CPU_K6_2P, + CPU_K6_3P, CPU_Cx6x86, CPU_Cx6x86MX, CPU_Cx6x86L), .min_bus = 50000000, .max_bus = 66666667, .min_voltage = 2800, @@ -12309,7 +13408,7 @@ const machine_t machines[] = { .ram = { .min = 8192, .max = 131072, - .step = 8192 + .step = 4096 }, .nvrmask = 255, .kbc_device = NULL, @@ -12326,7 +13425,7 @@ const machine_t machines[] = { /* Has a SM(S)C FDC37C935 Super I/O chip with on-chip KBC with Phoenix MultiKey/42 (version 1.38) KBC firmware. */ { - .name = "[i430VX] Packard Bell PB810", + .name = "[i430VX] Packard Bell Multimedia M415", .internal_name = "pb810", .type = MACHINE_TYPE_SOCKET7, .chipset = MACHINE_CHIPSET_INTEL_430VX, @@ -12343,14 +13442,14 @@ const machine_t machines[] = { .min_voltage = 2500, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 4.0 }, .bus_flags = MACHINE_PS2_PCI, .flags = MACHINE_IDE_DUAL | MACHINE_SOUND | MACHINE_APM, .ram = { - .min = 8192, + .min = 4096, .max = 131072, - .step = 8192 + .step = 4096 }, .nvrmask = 511, .kbc_device = NULL, @@ -12384,54 +13483,14 @@ const machine_t machines[] = { .min_voltage = 2600, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 131072, - .step = 8192 - }, - .nvrmask = 127, - .kbc_device = NULL, - .kbc_p1 = 0xff, - .gpio = 0xffffffff, - .gpio_acpi = 0xffffffff, - .device = NULL, - .fdc_device = NULL, - .sio_device = NULL, - .vid_device = NULL, - .snd_device = NULL, - .net_device = NULL - }, - /* Unknown PS/2 KBC. */ - { - .name = "[i430HX] Radisys EPC-2102", - .internal_name = "epc2102", - .type = MACHINE_TYPE_SOCKET7, - .chipset = MACHINE_CHIPSET_INTEL_430HX, - .init = machine_at_epc2102_init, - .p1_handler = NULL, - .gpio_handler = NULL, - .available_flag = MACHINE_AVAILABLE, - .gpio_acpi_handler = NULL, - .cpu = { - .package = CPU_PKG_SOCKET5_7, - .block = CPU_BLOCK_NONE, - .min_bus = 50000000, - .max_bus = 83333333, - .min_voltage = 2500, - .max_voltage = 3520, - .min_multi = 1.5, - .max_multi = 3.0 - }, - .bus_flags = MACHINE_PS2_PCI, - .flags = MACHINE_IDE_DUAL | MACHINE_APM, - .ram = { - .min = 8192, - .max = 262144, - .step = 8192 + .step = 4096 }, .nvrmask = 127, .kbc_device = NULL, @@ -12470,9 +13529,9 @@ const machine_t machines[] = { .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_GAMEPORT | MACHINE_APM | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 131072, - .step = 8192 + .step = 4096 }, .nvrmask = 127, .kbc_device = NULL, @@ -12547,7 +13606,7 @@ const machine_t machines[] = { .min_voltage = 2500, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_USB, @@ -12568,9 +13627,59 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + /* + According to Dell specifications, it can have either National Semiconductor + PC87307 or PC87309 Super I/O. All known instances have the former, although + other similar Dells of the era have pinouts for accompanying either so this + likely also does. + + The KBC is either an AMI '5' MegaKey, Phoenix MultiKey/42 1.37, or Phoenix + MultiKey/42i 4.16. + */ + { + .name = "[i430TX] Dell OptiPlex GN+", + .internal_name = "optiplexgn", + .type = MACHINE_TYPE_SOCKET7, + .chipset = MACHINE_CHIPSET_INTEL_430TX, + .init = machine_at_optiplexgn_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_SOCKET5_7, + .block = CPU_BLOCK_NONE, + .min_bus = 50000000, + .max_bus = 66666667, + .min_voltage = 2500, + .max_voltage = 3520, + .min_multi = 1.5, + .max_multi = 3.5 + }, + .bus_flags = MACHINE_PS2_PCI, + /* Video: S3 86C785 (Trio64V2/GX), ethernet: 3C905. */ + .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_VIDEO | MACHINE_SOUND, + .ram = { + .min = 8192, + .max = 262144, + .step = 8192 + }, + .nvrmask = 255, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + /* Stop-gap measure until the Trio64V2/GX is emulated, as both use the same VBIOS. */ + .vid_device = &s3_trio64v2_dx_onboard_pci_device, + .snd_device = &sb_vibra16xv_onboard_device, + .net_device = NULL + }, /* [TEST] Has AMI Megakey '5' KBC firmware on the SM(S)C FDC37C67x Super I/O chip. */ { - .name = "[i430TX] Gateway Tomahawk", + .name = "[i430TX] Gateway E-1000", .internal_name = "tomahawk", .type = MACHINE_TYPE_SOCKET7, .chipset = MACHINE_CHIPSET_INTEL_430TX, @@ -12582,12 +13691,12 @@ const machine_t machines[] = { .cpu = { .package = CPU_PKG_SOCKET5_7, .block = CPU_BLOCK_NONE, - .min_bus = 50000000, + .min_bus = 60000000, .max_bus = 66666667, .min_voltage = 2100, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 5.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_VIDEO | MACHINE_SOUND | MACHINE_NIC | MACHINE_USB, @@ -12608,51 +13717,9 @@ const machine_t machines[] = { .snd_device = &cs4236b_device, .net_device = &pcnet_am79c973_onboard_device }, -#ifdef USE_AN430TX - /* This has the Phoenix MultiKey KBC firmware. */ - { - .name = "[i430TX] Intel AN430TX", - .internal_name = "an430tx", - .type = MACHINE_TYPE_SOCKET7, - .chipset = MACHINE_CHIPSET_INTEL_430TX, - .init = machine_at_an430tx_init, - .p1_handler = NULL, - .gpio_handler = NULL, - .available_flag = MACHINE_AVAILABLE, - .gpio_acpi_handler = NULL, - .cpu = { - .package = CPU_PKG_SOCKET5_7, - .block = CPU_BLOCK_NONE, - .min_bus = 60000000, - .max_bus = 66666667, - .min_voltage = 2800, - .max_voltage = 3520, - .min_multi = 1.5, - .max_multi = 3.0 - }, - .bus_flags = MACHINE_PS2_PCI, - .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI, - .ram = { - .min = 8192, - .max = 262144, - .step = 8192 - }, - .nvrmask = 255, - .kbc_device = NULL, - .kbc_p1 = 0xff, - .gpio = 0xffffffff, - .gpio_acpi = 0xffffffff, - .device = NULL, - .fdc_device = NULL, - .sio_device = NULL, - .vid_device = NULL, - .snd_device = NULL, - .net_device = NULL - }, -#endif /* USE_AN430TX */ /* This has the AMIKey KBC firmware, which is an updated 'F' type. */ { - .name = "[i430TX] Intel YM430TX", + .name = "[i430TX] Intel YM430TX (Yamamoto)", .internal_name = "ym430tx", .type = MACHINE_TYPE_SOCKET7, .chipset = MACHINE_CHIPSET_INTEL_430TX, @@ -12663,20 +13730,21 @@ const machine_t machines[] = { .gpio_acpi_handler = NULL, .cpu = { .package = CPU_PKG_SOCKET5_7, - .block = CPU_BLOCK_NONE, + .block = CPU_BLOCK(CPU_K5, CPU_5K86, CPU_K6, CPU_K6_2, CPU_K6_2C, CPU_K6_3, CPU_K6_2P, + CPU_K6_3P, CPU_Cx6x86, CPU_Cx6x86MX, CPU_Cx6x86L), .min_bus = 60000000, .max_bus = 66666667, .min_voltage = 2800, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 262144, - .step = 8192 + .step = 4096 }, .nvrmask = 255, .kbc_device = NULL, @@ -12690,9 +13758,13 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, - /* PhoenixBIOS 4.0 Rel 6.0 for 430TX, most likely has AMI KBC of some sort. Also has onboard Yamaha YMF701 which can't be emulated yet. */ - /* Has a SM(S)C FDC37C935 Super I/O chip with on-chip KBC with Phoenix - MultiKey/42 (version 1.38) KBC firmware. */ + /* + PhoenixBIOS 4.0 Rel 6.0 for 430TX, has onboard Yamaha YMF701 which + is not emulated yet. + + Has a SM(S)C FDC37C935 Super I/O chip with on-chip KBC with Phoenix + MultiKey/42 (version 1.38) KBC firmware. + */ { .name = "[i430TX] Micronics Thunderbolt", .internal_name = "thunderbolt", @@ -12706,15 +13778,16 @@ const machine_t machines[] = { .cpu = { .package = CPU_PKG_SOCKET5_7, .block = CPU_BLOCK(CPU_WINCHIP, CPU_WINCHIP2), - .min_bus = 50000000, + .min_bus = 60000000, .max_bus = 66666667, .min_voltage = 2500, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, - .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_GAMEPORT | MACHINE_USB, /* Machine has internal sound: Yamaha YMF701-S */ + /* Machine has internal sound: Yamaha YMF701-S */ + .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_GAMEPORT | MACHINE_USB, .ram = { .min = 8192, .max = 262144, @@ -12752,13 +13825,54 @@ const machine_t machines[] = { .min_voltage = 2700, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_USB, .ram = { .min = 8192, - .max = 786432, + .max = 262144, + .step = 8192 + }, + .nvrmask = 255, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, + /* This has the Phoenix MultiKey KBC firmware. */ + { + .name = "[i430TX] Packard Bell PB790", + .internal_name = "an430tx", + .type = MACHINE_TYPE_SOCKET7, + .chipset = MACHINE_CHIPSET_INTEL_430TX, + .init = machine_at_an430tx_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_SOCKET5_7, + .block = CPU_BLOCK(CPU_K5, CPU_5K86, CPU_K6, CPU_K6_2, CPU_K6_2C, CPU_K6_3, CPU_K6_2P, + CPU_K6_3P, CPU_Cx6x86, CPU_Cx6x86MX, CPU_Cx6x86L), + .min_bus = 60000000, + .max_bus = 66666667, + .min_voltage = 2800, + .max_voltage = 3520, + .min_multi = 1.5, + .max_multi = 3.5 + }, + .bus_flags = MACHINE_PS2_PCI, + .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI, + .ram = { + .min = 8192, + .max = 262144, .step = 8192 }, .nvrmask = 255, @@ -12793,14 +13907,14 @@ const machine_t machines[] = { .min_voltage = 2700, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 262144, - .step = 8192 + .step = 4096 }, .nvrmask = 255, .kbc_device = NULL, @@ -12828,8 +13942,8 @@ const machine_t machines[] = { .cpu = { .package = CPU_PKG_SOCKET5_7, .block = CPU_BLOCK_NONE, - .min_bus = 55000000, - .max_bus = 75000000, + .min_bus = 60000000, + .max_bus = 66666667, .min_voltage = 2800, .max_voltage = 3520, .min_multi = 1.5, @@ -12838,9 +13952,9 @@ const machine_t machines[] = { .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 262144, - .step = 8192 + .step = 4096 }, .nvrmask = 255, .kbc_device = NULL, @@ -12869,18 +13983,18 @@ const machine_t machines[] = { .package = CPU_PKG_SOCKET5_7, .block = CPU_BLOCK_NONE, .min_bus = 50000000, - .max_bus = 66666667, + .max_bus = 75000000, .min_voltage = 2100, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_USB, .ram = { - .min = 8192, + .min = 4096, .max = 262144, - .step = 8192 + .step = 4096 }, .nvrmask = 255, .kbc_device = NULL, @@ -12896,7 +14010,7 @@ const machine_t machines[] = { }, /* [TEST] Has AMIKey 'H' KBC firmware. */ { - .name = "[i430TX] TriGem Richmond", + .name = "[i430TX] TriGem RD535 (Richmond)", .internal_name = "richmond", .type = MACHINE_TYPE_SOCKET7, .chipset = MACHINE_CHIPSET_INTEL_430TX, @@ -12908,12 +14022,12 @@ const machine_t machines[] = { .cpu = { .package = CPU_PKG_SOCKET5_7, .block = CPU_BLOCK_NONE, - .min_bus = 50000000, + .min_bus = 60000000, .max_bus = 66666667, .min_voltage = 2100, .max_voltage = 3520, .min_multi = 1.5, - .max_multi = 3.0 + .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_USB, @@ -13020,11 +14134,52 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, - + /* Has the VIA VT82C586B southbridge with on-chip KBC identical to the VIA + VT82C42N. */ + { + .name = "[VIA VP3] PC Partner VIA809DS", + .internal_name = "via809ds", + .type = MACHINE_TYPE_SOCKET7, + .chipset = MACHINE_CHIPSET_VIA_APOLLO_VP3, + .init = machine_at_via809ds_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_SOCKET5_7, + .block = CPU_BLOCK_NONE, + .min_bus = 50000000, + .max_bus = 75000000, + .min_voltage = 2100, + .max_voltage = 3520, + .min_multi = 1.5, + .max_multi = 5.5 + }, + .bus_flags = MACHINE_PS2_AGP | MACHINE_BUS_USB, + .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_USB, + .ram = { + .min = 8192, + .max = 1048576, + .step = 8192 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, + /* SiS 5571 */ /* Has the SiS 5571 chipset with on-chip KBC. */ { - .name = "[SiS 5571] Daewoo CB52X-SI", + .name = "[SiS 5571] Daewoo CD520", .internal_name = "cb52xsi", .type = MACHINE_TYPE_SOCKET7, .chipset = MACHINE_CHIPSET_SIS_5571, @@ -13170,7 +14325,7 @@ const machine_t machines[] = { .ram = { .min = 8192, .max = 1572864, - .step = 1024 + .step = 8192 }, .nvrmask = 255, .kbc_device = NULL, @@ -13210,7 +14365,7 @@ const machine_t machines[] = { .ram = { .min = 8192, .max = 1572864, - .step = 1024 + .step = 8192 }, .nvrmask = 255, .kbc_device = NULL, @@ -13252,7 +14407,7 @@ const machine_t machines[] = { .ram = { .min = 8192, .max = 786432, - .step = 1024 + .step = 8192 }, .nvrmask = 255, .kbc_device = NULL, @@ -13416,7 +14571,7 @@ const machine_t machines[] = { .bus_flags = MACHINE_PS2_AGP | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_USB, .ram = { - .min = 1024, + .min = 8192, .max = 1572864, .step = 8192 }, @@ -13718,6 +14873,47 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + /* Has the VIA VT82C596A southbridge with on-chip KBC identical to the VIA + VT82C42N. */ + { + .name = "[VIA MVP3] eMachines eTower 3xxc", + .internal_name = "delhi3", + .type = MACHINE_TYPE_SOCKETS7, + .chipset = MACHINE_CHIPSET_VIA_APOLLO_MVP3, + .init = machine_at_delhi3_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_SOCKET5_7, + .block = CPU_BLOCK_NONE, + .min_bus = 66666667, + .max_bus = 124242424, + .min_voltage = 2000, + .max_voltage = 3520, + .min_multi = 1.5, + .max_multi = 5.5 + }, + .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, /* Has internal video: ATI 3D Rage IIc AGP (Rage 2) */ + .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_SOUND | MACHINE_USB, + .ram = { + .min = 8192, + .max = 524288, + .step = 8192 + }, + .nvrmask = 255, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = &cs4235_onboard_device, + .net_device = NULL + }, /* SiS 5591 */ /* Has the SiS 5591 chipset with on-chip KBC. */ @@ -13734,7 +14930,7 @@ const machine_t machines[] = { .cpu = { .package = CPU_PKG_SOCKET5_7, .block = CPU_BLOCK_NONE, - .min_bus = 66666667, + .min_bus = 60000000, .max_bus = 100000000, .min_voltage = 2000, .max_voltage = 3520, @@ -13746,7 +14942,7 @@ const machine_t machines[] = { .ram = { .min = 8192, .max = 786432, - .step = 1024 + .step = 8192 }, .nvrmask = 255, .kbc_device = NULL, @@ -13871,7 +15067,7 @@ const machine_t machines[] = { .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_USB, .ram = { .min = 8192, - .max = 786432, + .max = 393216, .step = 8192 }, .nvrmask = 511, @@ -13966,7 +15162,47 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, - /* It's a Intel VS440FX with a Gateway 2000 OEM BIOS */ + /* It's an Intel VS440FX with a Dell OEM BIOS */ + { + .name = "[i440FX] Dell Dimension XPS Pro___n", + .internal_name = "dellvenus", + .type = MACHINE_TYPE_SOCKET8, + .chipset = MACHINE_CHIPSET_INTEL_440FX, + .init = machine_at_dellvenus_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_SOCKET8, + .block = CPU_BLOCK_NONE, + .min_bus = 60000000, + .max_bus = 66666667, + .min_voltage = 2100, + .max_voltage = 3500, + .min_multi = 2.0, + .max_multi = 3.5 + }, + .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, + .flags = MACHINE_IDE_DUAL | MACHINE_SOUND | MACHINE_APM | MACHINE_GAMEPORT | MACHINE_USB, + .ram = { + .min = 8192, + .max = 524288, + .step = 8192 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = &cs4236_onboard_device, + .net_device = NULL + }, + /* It's an Intel VS440FX with a Gateway 2000 OEM BIOS */ { .name = "[i440FX] Gateway 2000 Venus", .internal_name = "gw2kvenus", @@ -13988,7 +15224,7 @@ const machine_t machines[] = { .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, - .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_GAMEPORT | MACHINE_USB, + .flags = MACHINE_IDE_DUAL | MACHINE_SOUND | MACHINE_APM | MACHINE_GAMEPORT | MACHINE_USB, .ram = { .min = 8192, .max = 524288, @@ -14003,7 +15239,7 @@ const machine_t machines[] = { .fdc_device = NULL, .sio_device = NULL, .vid_device = NULL, - .snd_device = NULL, + .snd_device = &cs4236_onboard_device, .net_device = NULL }, /* Has the AMIKey-2 (updated 'H') KBC firmware. */ @@ -14085,7 +15321,7 @@ const machine_t machines[] = { .fdc_device = NULL, .sio_device = NULL, .vid_device = &s3_virge_325_onboard_pci_device, - .snd_device = &cs4236b_device, + .snd_device = &cs4236b_onboard_device, .net_device = NULL }, /* According to tests from real hardware: This has AMI MegaKey KBC firmware on the @@ -14112,7 +15348,7 @@ const machine_t machines[] = { .max_multi = 3.5 }, .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, - .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_GAMEPORT | MACHINE_USB, + .flags = MACHINE_IDE_DUAL | MACHINE_SOUND | MACHINE_APM | MACHINE_GAMEPORT | MACHINE_USB, .ram = { .min = 8192, .max = 524288, @@ -14127,7 +15363,7 @@ const machine_t machines[] = { .fdc_device = NULL, .sio_device = NULL, .vid_device = NULL, - .snd_device = NULL, + .snd_device = &cs4236_onboard_device, .net_device = NULL }, /* Has the AMIKey-2 (updated 'H') KBC firmware. */ @@ -14278,7 +15514,7 @@ const machine_t machines[] = { .bus_flags = MACHINE_PS2_AGP | MACHINE_BUS_USB, .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_GAMEPORT | MACHINE_USB, /* Machine has internal sound: C-Media CMI8330 */ .ram = { - .min = 1024, + .min = 8192, .max = 1572864, .step = 8192 }, @@ -14296,6 +15532,47 @@ const machine_t machines[] = { }, /* 440FX */ + /* Has a SM(S)C FDC37C935 Super I/O chip with on-chip KBC with Phoenix + MultiKey/42 (version 1.38) KBC firmware. */ + { + .name = "[i440FX] Acer V62X", + .internal_name = "acerv62x", + .type = MACHINE_TYPE_SLOT1, + .chipset = MACHINE_CHIPSET_INTEL_440FX, + .init = machine_at_acerv62x_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_SLOT1, + .block = CPU_BLOCK_NONE, + .min_bus = 60000000, + .max_bus = 83333333, + .min_voltage = 1800, + .max_voltage = 3500, + .min_multi = 1.5, + .max_multi = 8.0 + }, + .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, + .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_USB, + .ram = { + .min = 8192, + .max = 393216, + .step = 8192 + }, + .nvrmask = 511, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, /* The base board has a Holtek HT6542B KBC with AMIKey-2 (updated 'H') KBC firmware. */ { .name = "[i440FX] ASUS P/I-P65UP5 (C-PKND)", @@ -14353,7 +15630,7 @@ const machine_t machines[] = { .block = CPU_BLOCK_NONE, .min_bus = 60000000, .max_bus = 83333333, - .min_voltage = 1800, + .min_voltage = 2800, .max_voltage = 3500, .min_multi = 1.5, .max_multi = 8.0 @@ -14420,6 +15697,47 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + /* Has a National Semiconductor PC87307 Super I/O with on-chip KBC, which has one of these + firmwares: AMI '5' MegaKey, Phoenix MultiKey/42 1.37, or Phoenix MultiKey/42i 4.16. */ + { + .name = "[i440LX] Dell OptiPlex GXa", + .internal_name = "optiplexgxa", + .type = MACHINE_TYPE_SLOT1, + .chipset = MACHINE_CHIPSET_INTEL_440LX, + .init = machine_at_optiplexgxa_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_SLOT1, + .block = CPU_BLOCK(CPU_PENTIUMPRO, CPU_CYRIX3S), + .min_bus = 66666667, + .max_bus = 66666667, + .min_voltage = 1800, + .max_voltage = 3500, + .min_multi = 1.5, + .max_multi = 5.0 + }, + .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, + .flags = MACHINE_IDE_DUAL | MACHINE_SOUND | MACHINE_APM | MACHINE_ACPI | MACHINE_USB, /* Video: ATi 3D Rage Pro, Network: 3Com 3C905, Sound: Crystal CS4236B */ + .ram = { + .min = 8192, + .max = 786432, + .step = 8192 + }, + .nvrmask = 255, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, /* not yet emulated */ + .snd_device = &cs4236b_device, + .net_device = NULL /* not yet emulated */ + }, /* Has a SM(S)C FDC37C935 Super I/O chip with on-chip KBC with Phoenix MultiKey/42 (version 1.38) KBC firmware. */ { @@ -14483,7 +15801,7 @@ const machine_t machines[] = { .min_multi = 1.5, .max_multi = 8.0 }, - .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, + .bus_flags = MACHINE_PS2_PCI | MACHINE_BUS_USB, /* Has internal video: SGS Thompson Riva 128 AGP, network: NEC PK-UG-X006 (Intel 82558B chip) and sound: OAK Audia 3D (OTI-610) */ .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_USB, .ram = { .min = 8192, @@ -14631,6 +15949,47 @@ const machine_t machines[] = { }, /* Has a Winbond W83977EF Super I/O chip with on-chip KBC with AMIKey-2 KBC firmware. */ + +{ + .name = "[i440BX] ABIT BX6", + .internal_name = "bx6", + .type = MACHINE_TYPE_SLOT1, + .chipset = MACHINE_CHIPSET_INTEL_440BX, + .init = machine_at_bx6_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_SLOT1, + .block = CPU_BLOCK_NONE, + .min_bus = 66666667, + .max_bus = 133333333, + .min_voltage = 1500, + .max_voltage = 3500, + .min_multi = 2.0, + .max_multi = 5.5 + }, + .bus_flags = MACHINE_PS2_AGP | MACHINE_BUS_USB, + .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_USB, + .ram = { + .min = 8192, + .max = 524288, + .step = 8192 + }, + .nvrmask = 255, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, + { .name = "[i440BX] ABIT BF6", .internal_name = "bf6", @@ -15140,7 +16499,7 @@ const machine_t machines[] = { .gpio_acpi_handler = NULL, .cpu = { .package = CPU_PKG_SLOT1, - .block = CPU_BLOCK_NONE, + .block = CPU_BLOCK(CPU_PENTIUMPRO), .min_bus = 66666667, .max_bus = 150000000, .min_voltage = 1300, @@ -15236,7 +16595,7 @@ const machine_t machines[] = { .ram = { .min = 8192, .max = 1572864, - .step = 1024 + .step = 8192 }, .nvrmask = 255, .kbc_device = NULL, @@ -15276,7 +16635,7 @@ const machine_t machines[] = { .ram = { .min = 8192, .max = 1572864, - .step = 1024 + .step = 8192 }, .nvrmask = 255, .kbc_device = NULL, @@ -15630,7 +16989,7 @@ const machine_t machines[] = { .device = NULL, .fdc_device = NULL, .sio_device = NULL, - .vid_device = NULL, + .vid_device = &chips_69000_onboard_device, .snd_device = NULL, .net_device = NULL }, @@ -16009,6 +17368,48 @@ const machine_t machines[] = { .snd_device = &cmi8738_onboard_device, .net_device = NULL }, + /* SiS (5)600 */ + /* Has the SiS 600 chipset, which is a re-brand of the 5600, with + on-chip KBC. */ + { + .name = "[SiS 600] Soyo SY-7SBB", + .internal_name = "7sbb", + .type = MACHINE_TYPE_SOCKET370, + .chipset = MACHINE_CHIPSET_SIS_5600, + .init = machine_at_7sbb_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_SOCKET370, + .block = CPU_BLOCK(CPU_CYRIX3S), + .min_bus = 60000000, + .max_bus = 100000000, + .min_voltage = 1800, + .max_voltage = 3500, + .min_multi = 1.5, + .max_multi = 8.0 + }, + .bus_flags = MACHINE_PS2_AGP | MACHINE_BUS_USB, + .flags = MACHINE_IDE_DUAL | MACHINE_APM | MACHINE_ACPI | MACHINE_USB, + .ram = { + .min = 8192, + .max = 1572864, + .step = 8192 + }, + .nvrmask = 255, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, /* Miscellaneous/Fake/Hypervisor machines */ /* Has a Winbond W83977F Super I/O chip with on-chip KBC with AMIKey-2 KBC @@ -16025,7 +17426,7 @@ const machine_t machines[] = { .gpio_acpi_handler = NULL, .cpu = { .package = CPU_PKG_SLOT1, - .block = CPU_BLOCK(CPU_PENTIUM2, CPU_CYRIX3S), + .block = CPU_BLOCK(CPU_PENTIUMPRO, CPU_PENTIUM2, CPU_CYRIX3S), .min_bus = 0, .max_bus = 66666667, .min_voltage = 0, @@ -16097,8 +17498,8 @@ const machine_t machines[] = { /* Saved copies - jumpers get applied to these. We use also machine_gpio to store IBM PC/XT jumpers as they need more than one byte. */ -static uint8_t machine_p1_default; -static uint8_t machine_p1; +static uint32_t machine_p1_default; +static uint32_t machine_p1; static uint32_t machine_gpio_default; static uint32_t machine_gpio; @@ -16369,19 +17770,39 @@ machine_get_nvrmask(int m) int machine_has_flags(int m, int flags) { - return (machines[m].flags & flags); + int ret = machines[m].flags & flags; + + /* Can't have PS/2 ports with an AT KBC. */ + if ((flags & MACHINE_PS2_KBC) && + (machines[m].bus_flags & MACHINE_BUS_PS2_PORTS)) + ret |= MACHINE_PS2_KBC; + + return ret; } int machine_has_bus(int m, int bus_flags) { - return (machines[m].bus_flags & bus_flags); + int ret = machines[m].bus_flags & bus_flags; + + /* TODO: Move the KBD flags to the machine table! */ + if ((bus_flags & MACHINE_BUS_XT_KBD) && + !(machines[m].bus_flags & MACHINE_BUS_ISA16) && + !(machines[m].bus_flags & MACHINE_BUS_PS2_PORTS)) + ret |= MACHINE_BUS_XT_KBD; + + if ((bus_flags & MACHINE_BUS_AT_KBD) && + (IS_AT(m)) && + !(machines[m].bus_flags & MACHINE_BUS_PS2_PORTS)) + ret |= MACHINE_BUS_AT_KBD; + + return ret; } int machine_has_cartridge(int m) { - return (machine_has_bus(m, MACHINE_CARTRIDGE) ? 1 : 0); + return (machine_has_flags(m, MACHINE_CARTRIDGE) ? 1 : 0); } int @@ -16412,6 +17833,12 @@ machine_get_type(int m) return (machines[m].type); } +int +machine_get_chipset(int m) +{ + return (machines[m].chipset); +} + int machine_get_machine_from_internal_name(const char *s) { @@ -16437,3 +17864,26 @@ machine_is_sony(void) { return (!strcmp(machines[machine].internal_name, "pcv90")); } + +const char * +machine_get_nvr_name_ex(int m) +{ + const char *ret = machines[m].internal_name; + const device_t *dev = machine_get_device(m); + + if (dev != NULL) { + device_context(dev); + const char *bios = device_get_config_string("bios"); + if ((bios != NULL) && (strcmp(bios, "") != 0)) + ret = bios; + device_context_restore(); + } + + return ret; +} + +const char * +machine_get_nvr_name(void) +{ + return machine_get_nvr_name_ex(machine); +} diff --git a/src/machine_status.c b/src/machine_status.c index 16976fa83..3eb2762bc 100644 --- a/src/machine_status.c +++ b/src/machine_status.c @@ -45,11 +45,13 @@ machine_status_init(void) machine_status.mo[i].active = false; } + for (size_t i = 0; i < 2; i++) + machine_status.cartridge[i].empty = (strlen(cart_fns[i]) == 0); + machine_status.cassette.empty = (strlen(cassette_fname) == 0); - for (size_t i = 0; i < HDD_BUS_USB; i++) { + for (size_t i = 0; i < HDD_BUS_USB; i++) machine_status.hdd[i].active = false; - } for (size_t i = 0; i < NET_CARD_MAX; i++) { machine_status.net[i].active = false; diff --git a/src/mca.c b/src/mca.c index 871060bb4..a14fea6fa 100644 --- a/src/mca.c +++ b/src/mca.c @@ -101,3 +101,19 @@ mca_add(uint8_t (*read)(int addr, void *priv), void (*write)(int addr, uint8_t v } } } + +void +mca_add_to_slot(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) +{ + if (mca_card_read[c] || mca_card_write[c]) + { + //pclog("cannot add the device to slot %d\n", num); + return; + } + mca_card_read[c] = read; + mca_card_write[c] = write; + mca_card_feedb[c] = feedb; + mca_card_reset[c] = reset; + mca_priv[c] = priv; + return; +} diff --git a/src/mem/catalyst_flash.c b/src/mem/catalyst_flash.c index 7cd40e9d7..5c8812464 100644 --- a/src/mem/catalyst_flash.c +++ b/src/mem/catalyst_flash.c @@ -29,6 +29,7 @@ #include <86box/timer.h> #include <86box/nvr.h> #include <86box/plat.h> +#include <86box/plat_fallthrough.h> #define FLAG_WORD 4 #define FLAG_BXB 2 @@ -44,21 +45,22 @@ enum { }; enum { - CMD_SET_READ = 0x00, - CMD_READ_SIGNATURE = 0x90, - CMD_ERASE = 0x20, - CMD_ERASE_CONFIRM = 0x20, - CMD_ERASE_VERIFY = 0xA0, - CMD_PROGRAM = 0x40, - CMD_PROGRAM_VERIFY = 0xC0, - CMD_RESET = 0xFF + CMD_SET_READ = 0x00, + CMD_READ_AUTO_SELECT = 0x80, + CMD_READ_SIGNATURE = 0x90, + CMD_ERASE = 0x20, + CMD_ERASE_CONFIRM = 0x20, + CMD_ERASE_VERIFY = 0xA0, + CMD_PROGRAM = 0x40, + CMD_PROGRAM_VERIFY = 0xC0, + CMD_RESET = 0xFF }; typedef struct flash_t { uint8_t command; + uint8_t is_amd; uint8_t pad; uint8_t pad0; - uint8_t pad1; uint8_t *array; mem_mapping_t mapping; @@ -83,11 +85,22 @@ flash_read(uint32_t addr, void *priv) ret = dev->array[addr]; break; + case CMD_READ_AUTO_SELECT: + if (!dev->is_amd) + break; + fallthrough; case CMD_READ_SIGNATURE: - if (addr == 0x00000) - ret = 0x31; /* CATALYST */ - else if (addr == 0x00001) - ret = 0xB4; /* 28F010 */ + if (dev->is_amd) { + if (addr == 0x00000) + ret = 0x01; /* AMD */ + else if (addr == 0x00001) + ret = 0xa7; /* Am28F010 */ + } else { + if (addr == 0x00000) + ret = 0x31; /* CATALYST */ + else if (addr == 0x00001) + ret = 0xb4; /* 28F010 */ + } break; default: @@ -192,10 +205,9 @@ catalyst_flash_init(UNUSED(const device_t *info)) FILE *fp; flash_t *dev; - dev = malloc(sizeof(flash_t)); - memset(dev, 0, sizeof(flash_t)); + dev = calloc(1, sizeof(flash_t)); - sprintf(flash_path, "%s.bin", machine_get_internal_name_ex(machine)); + sprintf(flash_path, "%s.bin", machine_get_nvr_name_ex(machine)); mem_mapping_disable(&bios_mapping); mem_mapping_disable(&bios_high_mapping); @@ -206,6 +218,7 @@ catalyst_flash_init(UNUSED(const device_t *info)) catalyst_flash_add_mappings(dev); dev->command = CMD_RESET; + dev->is_amd = info->local; fp = nvr_fopen(flash_path, "rb"); if (fp) { @@ -240,7 +253,21 @@ const device_t catalyst_flash_device = { .init = catalyst_flash_init, .close = catalyst_flash_close, .reset = catalyst_flash_reset, - { .available = NULL }, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t amd_am28f010_flash_device = { + .name = "AMD Am28F010-D Flash BIOS", + .internal_name = "amd_am28f010_flash", + .flags = DEVICE_PCI, + .local = 1, + .init = catalyst_flash_init, + .close = catalyst_flash_close, + .reset = catalyst_flash_reset, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/mem/i2c_eeprom.c b/src/mem/i2c_eeprom.c index 8e4a6cc14..a8ae7ed04 100644 --- a/src/mem/i2c_eeprom.c +++ b/src/mem/i2c_eeprom.c @@ -128,8 +128,7 @@ log2i(uint32_t i) void * i2c_eeprom_init(void *i2c, uint8_t addr, uint8_t *data, uint32_t size, uint8_t writable) { - i2c_eeprom_t *dev = (i2c_eeprom_t *) malloc(sizeof(i2c_eeprom_t)); - memset(dev, 0, sizeof(i2c_eeprom_t)); + i2c_eeprom_t *dev = (i2c_eeprom_t *) calloc(1, sizeof(i2c_eeprom_t)); /* Round size up to the next power of 2. */ uint32_t pow_size = 1 << log2i(size); diff --git a/src/mem/intel_flash.c b/src/mem/intel_flash.c index 7949f302a..e193f3545 100644 --- a/src/mem/intel_flash.c +++ b/src/mem/intel_flash.c @@ -351,10 +351,9 @@ intel_flash_init(const device_t *info) flash_t *dev; uint8_t type = info->local & 0xff; - dev = malloc(sizeof(flash_t)); - memset(dev, 0, sizeof(flash_t)); + dev = calloc(1, sizeof(flash_t)); - sprintf(flash_path, "%s.bin", machine_get_internal_name_ex(machine)); + sprintf(flash_path, "%s.bin", machine_get_nvr_name_ex(machine)); dev->flags = info->local & 0xff; @@ -564,7 +563,7 @@ const device_t intel_flash_bxt_ami_device = { .init = intel_flash_init, .close = intel_flash_close, .reset = intel_flash_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -578,7 +577,7 @@ const device_t intel_flash_bxt_device = { .init = intel_flash_init, .close = intel_flash_close, .reset = intel_flash_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -592,7 +591,7 @@ const device_t intel_flash_bxb_device = { .init = intel_flash_init, .close = intel_flash_close, .reset = intel_flash_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/mem/mem.c b/src/mem/mem.c index aafd6223c..fa749002c 100644 --- a/src/mem/mem.c +++ b/src/mem/mem.c @@ -67,7 +67,9 @@ mem_mapping_t bios_mapping; mem_mapping_t bios_high_mapping; page_t *pages; /* RAM page table */ +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) page_t **page_lookup; /* pagetable lookup */ +#endif uint32_t pages_sz; /* #pages in table */ uint8_t *ram; /* the virtual RAM */ @@ -85,12 +87,23 @@ uint8_t *pccache2; int readlnext; int readlookup[256]; +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) uintptr_t *readlookup2; +#endif uintptr_t old_rl2; uint8_t uncached = 0; int writelnext; int writelookup[256]; +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) uintptr_t *writelookup2; +#endif + +#if (defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64) +/* The lookup tables. */ +page_t *page_lookup[1048576] = { 0 }; +uintptr_t readlookup2[1048576] = { 0 }; +uintptr_t writelookup2[1048576] = { 0 }; +#endif uint32_t mem_logical_addr; @@ -108,7 +121,6 @@ int mem_a20_alt = 0; int mem_a20_state = 0; int mmuflush = 0; -int mmu_perm = 4; #ifdef USE_NEW_DYNAREC uint64_t *byte_dirty_mask; @@ -125,10 +137,6 @@ mem_mapping_t *write_mapping[MEM_MAPPINGS_NO]; uint8_t *_mem_exec[MEM_MAPPINGS_NO]; -/* FIXME: re-do this with a 'mem_ops' struct. */ -static uint8_t *page_lookupp; /* pagetable mmu_perm lookup */ -static uint8_t *readlookupp; -static uint8_t *writelookupp; static mem_mapping_t *base_mapping; static mem_mapping_t *last_mapping; static mem_mapping_t *read_mapping_bus[MEM_MAPPINGS_NO]; @@ -187,10 +195,8 @@ resetreadlookup(void) /* Initialize the tables for high (> 1024K) RAM. */ memset(readlookup2, 0xff, (1 << 20) * sizeof(uintptr_t)); - memset(readlookupp, 0x04, (1 << 20) * sizeof(uint8_t)); memset(writelookup2, 0xff, (1 << 20) * sizeof(uintptr_t)); - memset(writelookupp, 0x04, (1 << 20) * sizeof(uint8_t)); readlnext = 0; writelnext = 0; @@ -204,14 +210,11 @@ flushmmucache(void) for (uint16_t c = 0; c < 256; c++) { if (readlookup[c] != (int) 0xffffffff) { readlookup2[readlookup[c]] = LOOKUP_INV; - readlookupp[readlookup[c]] = 4; readlookup[c] = 0xffffffff; } if (writelookup[c] != (int) 0xffffffff) { page_lookup[writelookup[c]] = NULL; - page_lookupp[writelookup[c]] = 4; writelookup2[writelookup[c]] = LOOKUP_INV; - writelookupp[writelookup[c]] = 4; writelookup[c] = 0xffffffff; } } @@ -225,6 +228,19 @@ flushmmucache(void) #endif } +void +flushmmucache_write(void) +{ + for (uint16_t c = 0; c < 256; c++) { + if (writelookup[c] != (int) 0xffffffff) { + page_lookup[writelookup[c]] = NULL; + writelookup2[writelookup[c]] = LOOKUP_INV; + writelookup[c] = 0xffffffff; + } + } + mmuflush++; +} + void flushmmucache_pc(void) { @@ -244,14 +260,11 @@ flushmmucache_nopc(void) for (uint16_t c = 0; c < 256; c++) { if (readlookup[c] != (int) 0xffffffff) { readlookup2[readlookup[c]] = LOOKUP_INV; - readlookupp[readlookup[c]] = 4; readlookup[c] = 0xffffffff; } if (writelookup[c] != (int) 0xffffffff) { page_lookup[writelookup[c]] = NULL; - page_lookupp[writelookup[c]] = 4; writelookup2[writelookup[c]] = LOOKUP_INV; - writelookupp[writelookup[c]] = 4; writelookup[c] = 0xffffffff; } } @@ -333,7 +346,6 @@ mmutranslatereal_normal(uint32_t addr, int rw) return 0xffffffffffffffffULL; } - mmu_perm = temp & 4; rammap(addr2) |= (rw ? 0x60 : 0x20); uint64_t page = temp & ~0x3fffff; @@ -356,7 +368,6 @@ mmutranslatereal_normal(uint32_t addr, int rw) return 0xffffffffffffffffULL; } - mmu_perm = temp & 4; rammap(addr2) |= 0x20; rammap((temp2 & ~0xfff) + ((addr >> 10) & 0xffc)) |= (rw ? 0x60 : 0x20); @@ -420,7 +431,6 @@ mmutranslatereal_pae(uint32_t addr, int rw) return 0xffffffffffffffffULL; } - mmu_perm = temp & 4; rammap64(addr3) |= (rw ? 0x60 : 0x20); return ((temp & ~0x1fffffULL) + (addr & 0x1fffffULL)) & 0x000000ffffffffffULL; @@ -441,7 +451,6 @@ mmutranslatereal_pae(uint32_t addr, int rw) return 0xffffffffffffffffULL; } - mmu_perm = temp & 4; rammap64(addr3) |= 0x20; rammap64(addr4) |= (rw ? 0x60 : 0x20); @@ -616,7 +625,6 @@ addreadlookup(uint32_t virt, uint32_t phys) else readlookup2[virt >> 12] = (uintptr_t) &ram[a]; #endif - readlookupp[virt >> 12] = mmu_perm; readlookup[readlnext++] = virt >> 12; readlnext &= (cachesize - 1); @@ -656,7 +664,6 @@ addwritelookup(uint32_t virt, uint32_t phys) # endif #endif page_lookup[virt >> 12] = &pages[phys >> 12]; - page_lookupp[virt >> 12] = mmu_perm; } else { #if (defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64) writelookup2[virt >> 12] = (uintptr_t) &ram[(uintptr_t) (phys & ~0xFFF) - (uintptr_t) (virt & ~0xfff)]; @@ -669,7 +676,6 @@ addwritelookup(uint32_t virt, uint32_t phys) writelookup2[virt >> 12] = (uintptr_t) &ram[a]; #endif } - writelookupp[virt >> 12] = mmu_perm; writelookup[writelnext++] = virt >> 12; writelnext &= (cachesize - 1); @@ -958,10 +964,8 @@ readmemwl(uint32_t addr) } return readmembl_no_mmut(addr, addr64a[0]) | (((uint16_t) readmembl_no_mmut(addr + 1, addr64a[1])) << 8); - } else if (readlookup2[addr >> 12] != (uintptr_t) LOOKUP_INV) { - mmu_perm = readlookupp[addr >> 12]; + } else if (readlookup2[addr >> 12] != (uintptr_t) LOOKUP_INV) return *(uint16_t *) (readlookup2[addr >> 12] + addr); - } } if (cr0 >> 31) { @@ -1029,7 +1033,6 @@ writememwl(uint32_t addr, uint16_t val) writemembl_no_mmut(addr + 1, addr64a[1], val >> 8); return; } else if (writelookup2[addr >> 12] != (uintptr_t) LOOKUP_INV) { - mmu_perm = writelookupp[addr >> 12]; *(uint16_t *) (writelookup2[addr >> 12] + addr) = val; return; } @@ -1037,7 +1040,6 @@ writememwl(uint32_t addr, uint16_t val) if (page_lookup[addr >> 12] && page_lookup[addr >> 12]->write_w) { page_lookup[addr >> 12]->write_w(addr, val, page_lookup[addr >> 12]); - mmu_perm = page_lookupp[addr >> 12]; return; } @@ -1085,10 +1087,8 @@ readmemwl_no_mmut(uint32_t addr, uint32_t *a64) } return readmembl_no_mmut(addr, a64[0]) | (((uint16_t) readmembl_no_mmut(addr + 1, a64[1])) << 8); - } else if (readlookup2[addr >> 12] != (uintptr_t) LOOKUP_INV) { - mmu_perm = readlookupp[addr >> 12]; + } else if (readlookup2[addr >> 12] != (uintptr_t) LOOKUP_INV) return *(uint16_t *) (readlookup2[addr >> 12] + addr); - } } if (cr0 >> 31) { @@ -1134,14 +1134,12 @@ writememwl_no_mmut(uint32_t addr, uint32_t *a64, uint16_t val) writemembl_no_mmut(addr + 1, a64[1], val >> 8); return; } else if (writelookup2[addr >> 12] != (uintptr_t) LOOKUP_INV) { - mmu_perm = writelookupp[addr >> 12]; *(uint16_t *) (writelookup2[addr >> 12] + addr) = val; return; } } if (page_lookup[addr >> 12] && page_lookup[addr >> 12]->write_w) { - mmu_perm = page_lookupp[addr >> 12]; page_lookup[addr >> 12]->write_w(addr, val, page_lookup[addr >> 12]); return; } @@ -1216,10 +1214,8 @@ readmemll(uint32_t addr) /* No need to waste precious CPU host cycles on mmutranslate's that were already done, just pass their result as a parameter to be used if needed. */ return readmemwl_no_mmut(addr, addr64a) | (((uint32_t) readmemwl_no_mmut(addr + 2, &(addr64a[2]))) << 16); - } else if (readlookup2[addr >> 12] != (uintptr_t) LOOKUP_INV) { - mmu_perm = readlookupp[addr >> 12]; + } else if (readlookup2[addr >> 12] != (uintptr_t) LOOKUP_INV) return *(uint32_t *) (readlookup2[addr >> 12] + addr); - } } if (cr0 >> 31) { @@ -1301,14 +1297,12 @@ writememll(uint32_t addr, uint32_t val) writememwl_no_mmut(addr + 2, &(addr64a[2]), val >> 16); return; } else if (writelookup2[addr >> 12] != (uintptr_t) LOOKUP_INV) { - mmu_perm = writelookupp[addr >> 12]; *(uint32_t *) (writelookup2[addr >> 12] + addr) = val; return; } } if (page_lookup[addr >> 12] && page_lookup[addr >> 12]->write_l) { - mmu_perm = page_lookupp[addr >> 12]; page_lookup[addr >> 12]->write_l(addr, val, page_lookup[addr >> 12]); return; } @@ -1363,10 +1357,8 @@ readmemll_no_mmut(uint32_t addr, uint32_t *a64) } return readmemwl_no_mmut(addr, a64) | ((uint32_t) (readmemwl_no_mmut(addr + 2, &(a64[2]))) << 16); - } else if (readlookup2[addr >> 12] != (uintptr_t) LOOKUP_INV) { - mmu_perm = readlookupp[addr >> 12]; + } else if (readlookup2[addr >> 12] != (uintptr_t) LOOKUP_INV) return *(uint32_t *) (readlookup2[addr >> 12] + addr); - } } if (cr0 >> 31) { @@ -1414,14 +1406,12 @@ writememll_no_mmut(uint32_t addr, uint32_t *a64, uint32_t val) writememwl_no_mmut(addr + 2, &(a64[2]), val >> 16); return; } else if (writelookup2[addr >> 12] != (uintptr_t) LOOKUP_INV) { - mmu_perm = writelookupp[addr >> 12]; *(uint32_t *) (writelookup2[addr >> 12] + addr) = val; return; } } if (page_lookup[addr >> 12] && page_lookup[addr >> 12]->write_l) { - mmu_perm = page_lookupp[addr >> 12]; page_lookup[addr >> 12]->write_l(addr, val, page_lookup[addr >> 12]); return; } @@ -1501,10 +1491,8 @@ readmemql(uint32_t addr) /* No need to waste precious CPU host cycles on mmutranslate's that were already done, just pass their result as a parameter to be used if needed. */ return readmemll_no_mmut(addr, addr64a) | (((uint64_t) readmemll_no_mmut(addr + 4, &(addr64a[4]))) << 32); - } else if (readlookup2[addr >> 12] != (uintptr_t) LOOKUP_INV) { - mmu_perm = readlookupp[addr >> 12]; + } else if (readlookup2[addr >> 12] != (uintptr_t) LOOKUP_INV) return *(uint64_t *) (readlookup2[addr >> 12] + addr); - } } if (cr0 >> 31) { @@ -1518,10 +1506,28 @@ readmemql(uint32_t addr) addr = addr64a[0] & rammask; map = read_mapping[addr >> MEM_GRANULARITY_BITS]; - if (map && map->read_l) - 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); + if (map && map->read_l) + return map->read_l(addr, map->priv) | + ((uint64_t) map->read_l(addr + 4, map->priv) << 32); + + if (map && map->read_w) + return map->read_w(addr, map->priv) | + ((uint64_t) map->read_w(addr + 2, map->priv) << 16) | + ((uint64_t) map->read_w(addr + 4, map->priv) << 32) | + ((uint64_t) map->read_w(addr + 6, map->priv) << 48); + + if (map && map->read_b) + return map->read_b(addr, map->priv) | + ((uint64_t) map->read_b(addr + 1, map->priv) << 8) | + ((uint64_t) map->read_b(addr + 2, map->priv) << 16) | + ((uint64_t) map->read_b(addr + 3, map->priv) << 24) | + ((uint64_t) map->read_b(addr + 4, map->priv) << 32) | + ((uint64_t) map->read_b(addr + 5, map->priv) << 40) | + ((uint64_t) map->read_b(addr + 6, map->priv) << 48) | + ((uint64_t) map->read_b(addr + 7, map->priv) << 56); + + return 0xffffffffffffffffULL; } void @@ -1578,14 +1584,12 @@ writememql(uint32_t addr, uint64_t val) writememll_no_mmut(addr + 4, &(addr64a[4]), val >> 32); return; } else if (writelookup2[addr >> 12] != (uintptr_t) LOOKUP_INV) { - mmu_perm = writelookupp[addr >> 12]; *(uint64_t *) (writelookup2[addr >> 12] + addr) = val; return; } } if (page_lookup[addr >> 12] && page_lookup[addr >> 12]->write_l) { - mmu_perm = page_lookupp[addr >> 12]; page_lookup[addr >> 12]->write_l(addr, val, page_lookup[addr >> 12]); page_lookup[addr >> 12]->write_l(addr + 4, val >> 32, page_lookup[addr >> 12]); return; @@ -1669,8 +1673,7 @@ do_mmutranslate(uint32_t addr, uint32_t *a64, int num, int write) a = (a & 0xfffffffffffff000ULL) | ((uint64_t) (addr & 0xfff)); a64[i] = (uint32_t) a; } - } else - mmu_perm = page_lookupp[addr >> 12]; + } addr++; } @@ -2370,7 +2373,7 @@ mem_mapping_recalc(uint64_t base, uint64_t size) for (i_c = i_s; i_c <= i_e; i_c += i_a) { for (c = (start + i_c); c < (end + i_c); c += MEM_GRANULARITY_SIZE) { /* CPU */ - n = !!in_smm; + n = (!!in_smm) || (is_cxsmm && (ccr1 & CCR1_SMAC)); wp = _mem_wp[c >> MEM_GRANULARITY_BITS]; if (map->exec && mem_mapping_access_allowed(map->flags, @@ -2759,6 +2762,17 @@ mem_init_ram_mapping(mem_mapping_t *mapping, uint32_t base, uint32_t size) mem_add_ram_mapping(mapping, base, size); } +void +mem_zero(void) +{ +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) + if (mem_size > 1048576) + memset(ram2, 0x00, ram2_size + 16); +#endif + + memset(ram, 0x00, ram_size + 16); +} + /* Reset the memory state. */ void mem_reset(void) @@ -2834,8 +2848,10 @@ mem_reset(void) return; } memset(ram, 0x00, ram_size + 16); +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) if (mem_size > 1048576) ram2 = &(ram[1 << 30]); +#endif } /* @@ -2868,7 +2884,6 @@ mem_reset(void) pages = (page_t *) malloc(m * sizeof(page_t)); memset(page_lookup, 0x00, (1 << 20) * sizeof(page_t *)); - memset(page_lookupp, 0x04, (1 << 20) * sizeof(uint8_t)); memset(pages, 0x00, pages_sz * sizeof(page_t)); @@ -2930,6 +2945,7 @@ mem_reset(void) else if (cpu_16bitbus && is6117 && mem_size > 65408) mem_init_ram_mapping(&ram_high_mapping, 0x100000, (65408 - 1024) * 1024); else { +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) if (mem_size > 1048576) { mem_init_ram_mapping(&ram_high_mapping, 0x100000, (1048576 - 1024) * 1024); @@ -2942,6 +2958,9 @@ mem_reset(void) ram2, MEM_MAPPING_INTERNAL, NULL); } else mem_init_ram_mapping(&ram_high_mapping, 0x100000, (mem_size - 1024) * 1024); +#else + mem_init_ram_mapping(&ram_high_mapping, 0x100000, (mem_size - 1024) * 1024); +#endif } } @@ -2981,20 +3000,32 @@ mem_init(void) ram2 = NULL; pages = NULL; +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) /* Allocate the lookup tables. */ page_lookup = (page_t **) malloc((1 << 20) * sizeof(page_t *)); - page_lookupp = (uint8_t *) malloc((1 << 20) * sizeof(uint8_t)); readlookup2 = malloc((1 << 20) * sizeof(uintptr_t)); - readlookupp = malloc((1 << 20) * sizeof(uint8_t)); writelookup2 = malloc((1 << 20) * sizeof(uintptr_t)); - writelookupp = malloc((1 << 20) * sizeof(uint8_t)); +#endif } -static void -umc_page_recalc(uint32_t c, int set) +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) +void +mem_free(void) { + free(page_lookup); + free(readlookup2); + free(writelookup2); +} +#endif + + +static void +umc_page_recalc(uint32_t c, uint32_t phys, int set) +{ + uint32_t target = set ? phys : c; + if (set) { - pages[c].mem = &ram[(c & 0xff) << 12]; + pages[c].mem = &ram[(target & 0xff) << 12]; pages[c].write_b = mem_write_ramb_page; pages[c].write_w = mem_write_ramw_page; pages[c].write_l = mem_write_raml_page; @@ -3007,8 +3038,8 @@ umc_page_recalc(uint32_t c, int set) #ifdef USE_NEW_DYNAREC pages[c].evict_prev = EVICT_NOT_IN_LIST; - pages[c].byte_dirty_mask = &byte_dirty_mask[(c & 0xff) * 64]; - pages[c].byte_code_present_mask = &byte_code_present_mask[(c & 0xff) * 64]; + pages[c].byte_dirty_mask = &byte_dirty_mask[(target & 0xff) * 64]; + pages[c].byte_code_present_mask = &byte_code_present_mask[(target & 0xff) * 64]; #endif } @@ -3016,11 +3047,11 @@ void umc_smram_recalc(uint32_t start, int set) { for (uint32_t c = start; c < (start + 0x0020); c++) - umc_page_recalc(c, set); + umc_page_recalc(c, c - start + 0x000a0000, set); } -void -mem_remap_top_ex(int kb, uint32_t start) +static void +mem_remap_top_ex_common(int kb, uint32_t start, int mid) { uint32_t c; int offset; @@ -3123,37 +3154,61 @@ mem_remap_top_ex(int kb, uint32_t start) mem_mapping_set_addr(&ram_remapped_mapping2, (start * 1024) + 0x00020000, 0x00020000); mem_mapping_set_exec(&ram_remapped_mapping2, ram + 0x000d0000); - mem_mapping_set_addr(&ram_mid_mapping, 0x000c0000, 0x00010000); - mem_mapping_set_exec(&ram_mid_mapping, ram + 0x000c0000); - mem_mapping_set_addr(&ram_mid_mapping2, 0x000f0000, 0x00010000); - mem_mapping_set_exec(&ram_mid_mapping2, ram + 0x000f0000); + if (mid) { + mem_mapping_set_addr(&ram_mid_mapping, 0x000c0000, 0x00010000); + mem_mapping_set_exec(&ram_mid_mapping, ram + 0x000c0000); + mem_mapping_set_addr(&ram_mid_mapping2, 0x000f0000, 0x00010000); + mem_mapping_set_exec(&ram_mid_mapping2, ram + 0x000f0000); + } } else { mem_mapping_set_addr(&ram_remapped_mapping, start * 1024, size * 1024); mem_mapping_set_exec(&ram_remapped_mapping, ram + start_addr); mem_mapping_disable(&ram_remapped_mapping2); - mem_mapping_set_addr(&ram_mid_mapping, 0x000a0000, 0x00060000); - mem_mapping_set_exec(&ram_mid_mapping, ram + 0x000a0000); - mem_mapping_disable(&ram_mid_mapping2); + if (mid) { + mem_mapping_set_addr(&ram_mid_mapping, 0x000a0000, 0x00060000); + mem_mapping_set_exec(&ram_mid_mapping, ram + 0x000a0000); + mem_mapping_disable(&ram_mid_mapping2); + } } } else { mem_mapping_disable(&ram_remapped_mapping); mem_mapping_disable(&ram_remapped_mapping2); - mem_mapping_set_addr(&ram_mid_mapping, 0x000a0000, 0x00060000); - mem_mapping_set_exec(&ram_mid_mapping, ram + 0x000a0000); - mem_mapping_disable(&ram_mid_mapping2); + if (mid) { + mem_mapping_set_addr(&ram_mid_mapping, 0x000a0000, 0x00060000); + mem_mapping_set_exec(&ram_mid_mapping, ram + 0x000a0000); + mem_mapping_disable(&ram_mid_mapping2); + } } flushmmucache(); } +void +mem_remap_top_ex(int kb, uint32_t start) +{ + mem_remap_top_ex_common(kb, start, 1); +} + +void +mem_remap_top_ex_nomid(int kb, uint32_t start) +{ + mem_remap_top_ex_common(kb, start, 0); +} + void mem_remap_top(int kb) { mem_remap_top_ex(kb, (mem_size >= 1024) ? mem_size : 1024); } +void +mem_remap_top_nomid(int kb) +{ + mem_remap_top_ex_nomid(kb, (mem_size >= 1024) ? mem_size : 1024); +} + void mem_reset_page_blocks(void) { diff --git a/src/mem/mmu_2386.c b/src/mem/mmu_2386.c index 7418a88d8..ebf062d95 100644 --- a/src/mem/mmu_2386.c +++ b/src/mem/mmu_2386.c @@ -102,8 +102,8 @@ mem_readw_map(uint32_t addr) if (((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_HBOUND) && (map && map->read_w)) ret = map->read_w(addr, map->priv); else { - ret = mem_readb_phys(addr + 1) << 8; - ret |= mem_readb_phys(addr); + ret = mem_readb_map(addr); + ret |= ((uint16_t) mem_readb_map(addr + 1)) << 8; } return ret; @@ -120,8 +120,8 @@ mem_readl_map(uint32_t addr) if (!cpu_16bitbus && ((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_QBOUND) && (map && map->read_l)) ret = map->read_l(addr, map->priv); else { - ret = mem_readw_phys(addr + 2) << 16; - ret |= mem_readw_phys(addr); + ret = mem_readw_map(addr); + ret |= ((uint32_t) mem_readw_map(addr + 2)) << 16; } return ret; @@ -148,8 +148,8 @@ mem_writew_map(uint32_t addr, uint16_t val) if (((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_HBOUND) && (map && map->write_w)) map->write_w(addr, val, map->priv); else { - mem_writeb_phys(addr, val & 0xff); - mem_writeb_phys(addr + 1, val >> 8); + mem_writeb_map(addr, val & 0xff); + mem_writeb_map(addr + 1, val >> 8); } } @@ -161,10 +161,10 @@ mem_writel_map(uint32_t addr, uint32_t val) mem_logical_addr = 0xffffffff; if (!cpu_16bitbus && ((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_QBOUND) && (map && map->write_l)) - map->write_l(addr, val, map->priv); + map->write_l(addr, val, map->priv); else { - mem_writew_phys(addr, val & 0xffff); - mem_writew_phys(addr + 2, val >> 16); + mem_writew_map(addr, val & 0xffff); + mem_writew_map(addr + 2, val >> 16); } } @@ -211,7 +211,6 @@ mmutranslatereal_2386(uint32_t addr, int rw) return 0xffffffffffffffffULL; } - mmu_perm = temp & 4; mem_writel_map(addr2, mem_readl_map(addr2) | (rw ? 0x60 : 0x20)); return (temp & ~0x3fffff) + (addr & 0x3fffff); @@ -231,7 +230,6 @@ mmutranslatereal_2386(uint32_t addr, int rw) return 0xffffffffffffffffULL; } - mmu_perm = temp & 4; mem_writel_map(addr2, mem_readl_map(addr2) | 0x20); mem_writel_map((temp2 & ~0xfff) + ((addr >> 10) & 0xffc), mem_readl_map((temp2 & ~0xfff) + ((addr >> 10) & 0xffc)) | (rw ? 0x60 : 0x20)); @@ -649,7 +647,7 @@ readmemll_2386(uint32_t addr) /* No need to waste precious CPU host cycles on mmutranslate's that were already done, just pass their result as a parameter to be used if needed. */ return readmemwl_no_mmut_2386(addr, addr64a) | - (((uint32_t) readmemwl_no_mmut(addr + 2, &(addr64a[2]))) << 16); + (((uint32_t) readmemwl_no_mmut_2386(addr + 2, &(addr64a[2]))) << 16); } } @@ -925,10 +923,28 @@ readmemql_2386(uint32_t addr) addr = addr64a[0] & rammask; map = read_mapping[addr >> MEM_GRANULARITY_BITS]; - if (map && map->read_l) - 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); + if (map && map->read_l) + return map->read_l(addr, map->priv) | + ((uint64_t) map->read_l(addr + 4, map->priv) << 32); + + if (map && map->read_w) + return map->read_w(addr, map->priv) | + ((uint64_t) map->read_w(addr + 2, map->priv) << 16) | + ((uint64_t) map->read_w(addr + 4, map->priv) << 32) | + ((uint64_t) map->read_w(addr + 6, map->priv) << 48); + + if (map && map->read_b) + return map->read_b(addr, map->priv) | + ((uint64_t) map->read_b(addr + 1, map->priv) << 8) | + ((uint64_t) map->read_b(addr + 2, map->priv) << 16) | + ((uint64_t) map->read_b(addr + 3, map->priv) << 24) | + ((uint64_t) map->read_b(addr + 4, map->priv) << 32) | + ((uint64_t) map->read_b(addr + 5, map->priv) << 40) | + ((uint64_t) map->read_b(addr + 6, map->priv) << 48) | + ((uint64_t) map->read_b(addr + 7, map->priv) << 56); + + return 0xffffffffffffffffULL; } void diff --git a/src/mem/rom.c b/src/mem/rom.c index f9718b7ce..f7b2b2b0d 100644 --- a/src/mem/rom.c +++ b/src/mem/rom.c @@ -86,12 +86,58 @@ rom_add_path(const char *path) path_slash(rom_path->path); } +static int +rom_check(const char *fn) +{ + FILE *fp = NULL; + int ret = 0; + + if ((fn[strlen(fn) - 1] == '/') || (fn[strlen(fn) - 1] == '\\')) + ret = plat_dir_check((char *) fn); + else { + fp = fopen(fn, "rb"); + ret = (fp != NULL); + if (fp != NULL) + fclose(fp); + } + + return ret; +} + +void +rom_get_full_path(char *dest, const char *fn) +{ + char temp[1024] = { 0 }; + + dest[0] = 0x00; + + if (strstr(fn, "roms/") == fn) { + /* Relative path */ + 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_check(temp)) { + strcpy(dest, temp); + return; + } + } + + return; + } else { + /* Absolute path */ + strcpy(dest, fn); + } +} + FILE * rom_fopen(const char *fn, char *mode) { char temp[1024]; FILE *fp = NULL; + if ((fn == NULL) || (mode == NULL)) + return NULL; + if (strstr(fn, "roms/") == fn) { /* Relative path */ for (rom_path_t *rom_path = &rom_paths; rom_path != NULL; rom_path = rom_path->next) { @@ -202,6 +248,57 @@ rom_readl(uint32_t addr, void *priv) return (*(uint32_t *) &rom->rom[(addr - rom->mapping.base) & rom->mask]); } +void +rom_write(uint32_t addr, uint8_t val, void *priv) +{ + const rom_t *rom = (rom_t *) priv; + +#ifdef ROM_TRACE + if (rom->mapping.base == ROM_TRACE) + rom_log("ROM: write byte from BIOS at %06lX\n", addr); +#endif + + if (addr < rom->mapping.base) + return; + if (addr >= (rom->mapping.base + rom->sz)) + return; + rom->rom[(addr - rom->mapping.base) & rom->mask] = val; +} + +void +rom_writew(uint32_t addr, uint16_t val, void *priv) +{ + rom_t *rom = (rom_t *) priv; + +#ifdef ROM_TRACE + if (rom->mapping.base == ROM_TRACE) + rom_log("ROM: write word from BIOS at %06lX\n", addr); +#endif + + if (addr < (rom->mapping.base - 1)) + return; + if (addr >= (rom->mapping.base + rom->sz)) + return; + *(uint16_t *) &rom->rom[(addr - rom->mapping.base) & rom->mask] = val; +} + +void +rom_writel(uint32_t addr, uint32_t val, void *priv) +{ + rom_t *rom = (rom_t *) priv; + +#ifdef ROM_TRACE + if (rom->mapping.base == ROM_TRACE) + rom_log("ROM: write long from BIOS at %06lX\n", addr); +#endif + + if (addr < (rom->mapping.base - 3)) + return; + if (addr >= (rom->mapping.base + rom->sz)) + return; + *(uint32_t *) &rom->rom[(addr - rom->mapping.base) & rom->mask] = val; +} + int rom_load_linear_oddeven(const char *fn, uint32_t addr, int sz, int off, uint8_t *ptr) { @@ -227,11 +324,12 @@ rom_load_linear_oddeven(const char *fn, uint32_t addr, int sz, int off, uint8_t } 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"); + fatal("rom_load_linear(): Error reading odd data\n"); } } - (void) fclose(fp); + if (fp != NULL) + (void) fclose(fp); return 1; } @@ -260,7 +358,8 @@ rom_load_linear(const char *fn, uint32_t addr, int sz, int off, uint8_t *ptr) fatal("rom_load_linear(): Error reading data\n"); } - (void) fclose(fp); + if (fp != NULL) + (void) fclose(fp); return 1; } @@ -304,7 +403,8 @@ rom_load_linear_inverted(const char *fn, uint32_t addr, int sz, int off, uint8_t } } - (void) fclose(fp); + if (fp != NULL) + (void) fclose(fp); return 1; } @@ -345,8 +445,10 @@ rom_load_interleaved(const char *fnl, const char *fnh, uint32_t addr, int sz, in } } - (void) fclose(fph); - (void) fclose(fpl); + if (fph != NULL) + (void) fclose(fph); + if (fpl != NULL) + (void) fclose(fpl); return 1; } diff --git a/src/mem/row.c b/src/mem/row.c index ccd0325a4..c3e10841f 100644 --- a/src/mem/row.c +++ b/src/mem/row.c @@ -334,15 +334,15 @@ row_init(const device_t *info) /* NOTE: NOT const, so that we can patch it at init. */ device_t row_device = { - .name = "DRAM Rows", + .name = "DRAM Rows", .internal_name = "dram_rows", - .flags = DEVICE_AT, - .local = 0x0000, - .init = row_init, - .close = row_close, - .reset = row_reset, - { .available = NULL }, + .flags = DEVICE_ISA16, + .local = 0x0000, + .init = row_init, + .close = row_close, + .reset = row_reset, + .available = NULL, .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL + .force_redraw = NULL, + .config = NULL }; diff --git a/src/mem/smram.c b/src/mem/smram.c index 0532e2dd5..928760f3a 100644 --- a/src/mem/smram.c +++ b/src/mem/smram.c @@ -59,9 +59,12 @@ smram_read(uint32_t addr, void *priv) const smram_t *dev = (smram_t *) priv; uint32_t new_addr = addr - dev->host_base + dev->ram_base; +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) if (new_addr >= (1 << 30)) return mem_read_ram_2gb(new_addr, priv); - else if (!use_separate_smram || (new_addr >= 0xa0000)) + else +#endif + if (!use_separate_smram || (new_addr >= 0xa0000)) return mem_read_ram(new_addr, priv); else return dev->mapping.exec[addr - dev->host_base]; @@ -73,9 +76,12 @@ smram_readw(uint32_t addr, void *priv) smram_t *dev = (smram_t *) priv; uint32_t new_addr = addr - dev->host_base + dev->ram_base; +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) if (new_addr >= (1 << 30)) return mem_read_ram_2gbw(new_addr, priv); - else if (!use_separate_smram || (new_addr >= 0xa0000)) + else +#endif + if (!use_separate_smram || (new_addr >= 0xa0000)) return mem_read_ramw(new_addr, priv); else return *(uint16_t *) &(dev->mapping.exec[addr - dev->host_base]); @@ -87,9 +93,12 @@ smram_readl(uint32_t addr, void *priv) smram_t *dev = (smram_t *) priv; uint32_t new_addr = addr - dev->host_base + dev->ram_base; +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) if (new_addr >= (1 << 30)) return mem_read_ram_2gbl(new_addr, priv); - else if (!use_separate_smram || (new_addr >= 0xa0000)) + else +#endif + if (!use_separate_smram || (new_addr >= 0xa0000)) return mem_read_raml(new_addr, priv); else return *(uint32_t *) &(dev->mapping.exec[addr - dev->host_base]); @@ -245,12 +254,11 @@ smram_add(void) return NULL; } - temp_smram = (smram_t *) malloc(sizeof(smram_t)); + temp_smram = (smram_t *) calloc(1, sizeof(smram_t)); if (temp_smram == NULL) { - fatal("smram_add(): temp_smram malloc failed\n"); + fatal("smram_add(): temp_smram calloc failed\n"); return NULL; } - memset(temp_smram, 0x00, sizeof(smram_t)); memset(&(temp_smram->mapping), 0x00, sizeof(mem_mapping_t)); /* Add struct to the beginning of the list if necessary.*/ diff --git a/src/mem/spd.c b/src/mem/spd.c index a0896a05a..01cd7b464 100644 --- a/src/mem/spd.c +++ b/src/mem/spd.c @@ -221,8 +221,7 @@ spd_register(uint8_t ram_type, uint8_t slot_mask, uint16_t max_module_size) if (!(slot_mask & (1 << slot))) continue; /* slot disabled */ - spd_modules[slot] = (spd_t *) malloc(sizeof(spd_t)); - memset(spd_modules[slot], 0, sizeof(spd_t)); + spd_modules[slot] = (spd_t *) calloc(1, sizeof(spd_t)); spd_modules[slot]->slot = slot; spd_modules[slot]->size = rows[row]; @@ -595,7 +594,7 @@ static const device_t spd_device = { .init = spd_init, .close = spd_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/mem/sst_flash.c b/src/mem/sst_flash.c index cd6ec7cd9..34bfae83a 100644 --- a/src/mem/sst_flash.c +++ b/src/mem/sst_flash.c @@ -25,6 +25,7 @@ #include <86box/device.h> #include <86box/mem.h> #include <86box/machine.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/nvr.h> #include <86box/plat.h> @@ -505,10 +506,9 @@ static void * sst_init(const device_t *info) { FILE *fp; - sst_t *dev = malloc(sizeof(sst_t)); - memset(dev, 0, sizeof(sst_t)); + sst_t *dev = calloc(1, sizeof(sst_t)); - sprintf(flash_path, "%s.bin", machine_get_internal_name_ex(machine)); + sprintf(flash_path, "%s.bin", machine_get_nvr_name_ex(machine)); mem_mapping_disable(&bios_mapping); mem_mapping_disable(&bios_high_mapping); @@ -576,7 +576,7 @@ const device_t sst_flash_29ee010_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -590,7 +590,7 @@ const device_t sst_flash_29ee020_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -604,7 +604,7 @@ const device_t winbond_flash_w29c512_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -618,7 +618,7 @@ const device_t winbond_flash_w29c010_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -632,7 +632,7 @@ const device_t winbond_flash_w29c020_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -646,7 +646,7 @@ const device_t winbond_flash_w29c040_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -660,7 +660,7 @@ const device_t sst_flash_39sf512_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -674,7 +674,7 @@ const device_t sst_flash_39sf010_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -688,7 +688,7 @@ const device_t sst_flash_39sf020_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -702,7 +702,7 @@ const device_t sst_flash_39sf040_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -716,7 +716,7 @@ const device_t sst_flash_39lf512_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -730,7 +730,7 @@ const device_t sst_flash_39lf010_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -744,7 +744,7 @@ const device_t sst_flash_39lf020_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -758,7 +758,7 @@ const device_t sst_flash_39lf040_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -772,7 +772,7 @@ const device_t sst_flash_39lf080_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -786,7 +786,7 @@ const device_t sst_flash_39lf016_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -808,7 +808,7 @@ const device_t sst_flash_49lf002_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -822,7 +822,7 @@ const device_t sst_flash_49lf020_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -836,7 +836,7 @@ const device_t sst_flash_49lf020a_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -850,7 +850,7 @@ const device_t sst_flash_49lf003_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -864,7 +864,7 @@ const device_t sst_flash_49lf030_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -878,7 +878,7 @@ const device_t sst_flash_49lf004_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -892,7 +892,7 @@ const device_t sst_flash_49lf004c_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -906,7 +906,7 @@ const device_t sst_flash_49lf040_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -920,7 +920,7 @@ const device_t sst_flash_49lf008_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -934,7 +934,7 @@ const device_t sst_flash_49lf008c_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -948,7 +948,7 @@ const device_t sst_flash_49lf080_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -962,7 +962,7 @@ const device_t sst_flash_49lf016_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -977,7 +977,7 @@ const device_t sst_flash_49lf160_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -991,7 +991,7 @@ const device_t amd_flash_29f020a_device = { .init = sst_init, .close = sst_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/network/CMakeLists.txt b/src/network/CMakeLists.txt index cbdff7b1d..9d6b2efeb 100644 --- a/src/network/CMakeLists.txt +++ b/src/network/CMakeLists.txt @@ -41,7 +41,10 @@ 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) + target_link_libraries(PkgConfig::SLIRP INTERFACE wsock32 ws2_32 iphlpapi) + if (NOT MSVC) + target_link_libraries(PkgConfig::SLIRP INTERFACE iconv) + endif() if(STATIC_BUILD) add_compile_definitions(LIBSLIRP_STATIC) endif() diff --git a/src/network/net_3c501.c b/src/network/net_3c501.c index 2cafb1d46..f5809afb1 100644 --- a/src/network/net_3c501.c +++ b/src/network/net_3c501.c @@ -56,7 +56,6 @@ #include <86box/thread.h> #include <86box/timer.h> #include <86box/network.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) */ @@ -1080,8 +1079,7 @@ threec501_nic_init(UNUSED(const device_t *info)) uint32_t mac; threec501_t *dev; - dev = malloc(sizeof(threec501_t)); - memset(dev, 0x00, sizeof(threec501_t)); + dev = calloc(1, sizeof(threec501_t)); dev->maclocal[0] = 0x02; /* 02:60:8C (3Com OID) */ dev->maclocal[1] = 0x60; dev->maclocal[2] = 0x8C; @@ -1156,30 +1154,31 @@ threec501_nic_close(void *priv) static const device_config_t threec501_config[] = { { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x300, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x300, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "0x280", .value = 0x280 }, { .description = "0x300", .value = 0x300 }, { .description = "0x310", .value = 0x310 }, { .description = "0x320", .value = 0x320 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 3, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 3, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "IRQ 2/9", .value = 9 }, { .description = "IRQ 3", .value = 3 }, { .description = "IRQ 4", .value = 4 }, @@ -1188,28 +1187,34 @@ static const device_config_t threec501_config[] = { { .description = "IRQ 7", .value = 7 }, { .description = "" } }, + .bios = { { 0 } } }, { .name = "dma", .description = "DMA", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 3, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 3, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "DMA 1", .value = 1 }, { .description = "DMA 2", .value = 2 }, { .description = "DMA 3", .value = 3 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "mac", - .description = "MAC Address", - .type = CONFIG_MAC, - .default_string = "", - .default_int = -1 + .name = "mac", + .description = "MAC Address", + .type = CONFIG_MAC, + .default_string = NULL, + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; @@ -1222,7 +1227,7 @@ const device_t threec501_device = { .init = threec501_nic_init, .close = threec501_nic_close, .reset = elnkR3Reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = threec501_config diff --git a/src/network/net_3c503.c b/src/network/net_3c503.c index 6191c02bf..b35e0d453 100644 --- a/src/network/net_3c503.c +++ b/src/network/net_3c503.c @@ -60,7 +60,6 @@ #include <86box/timer.h> #include <86box/network.h> #include <86box/net_dp8390.h> -#include <86box/bswap.h> #include <86box/plat_unused.h> typedef struct threec503_t { @@ -573,8 +572,7 @@ threec503_nic_init(UNUSED(const device_t *info)) uint32_t mac; threec503_t *dev; - dev = malloc(sizeof(threec503_t)); - memset(dev, 0x00, sizeof(threec503_t)); + dev = calloc(1, sizeof(threec503_t)); dev->maclocal[0] = 0x02; /* 02:60:8C (3Com OID) */ dev->maclocal[1] = 0x60; dev->maclocal[2] = 0x8C; @@ -656,14 +654,14 @@ threec503_nic_close(void *priv) static const device_config_t threec503_config[] = { // clang-format off { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x300, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x300, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "0x250", .value = 0x250 }, { .description = "0x280", .value = 0x280 }, { .description = "0x2a0", .value = 0x2a0 }, @@ -674,80 +672,83 @@ static const device_config_t threec503_config[] = { { .description = "0x350", .value = 0x350 }, { .description = "", .value = 0 } }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 3, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 3, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "IRQ 2", .value = 2 }, { .description = "IRQ 3", .value = 3 }, { .description = "IRQ 4", .value = 4 }, { .description = "IRQ 5", .value = 5 }, { .description = "", .value = 0 } }, + .bios = { { 0 } } }, { - .name = "dma", - .description = "DMA", - .type = CONFIG_SELECTION, + .name = "dma", + .description = "DMA", + .type = CONFIG_SELECTION, .default_string = "", - .default_int = 3, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .default_int = 3, + .file_filter = "", + .spinner = { 0 }, + .selection = { { .description = "DMA 1", .value = 1 }, { .description = "DMA 2", .value = 2 }, { .description = "DMA 3", .value = 3 }, { .description = "", .value = 0 } }, + .bios = { { 0 } } }, { - .name = "mac", - .description = "MAC Address", - .type = CONFIG_MAC, - .default_string = "", - .default_int = -1, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { .description = "", .value = 0 } - }, + .name = "mac", + .description = "MAC Address", + .type = CONFIG_MAC, + .default_string = NULL, + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "bios_addr", - .description = "BIOS Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0xCC000, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "bios_addr", + .description = "BIOS Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0xCC000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "DC00", .value = 0xDC000 }, { .description = "D800", .value = 0xD8000 }, { .description = "C800", .value = 0xC8000 }, { .description = "CC00", .value = 0xCC000 }, - { .description = "", .value = 0 } + { .description = "", .value = 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format off }; const device_t threec503_device = { - .name = "3Com EtherLink II", + .name = "3Com EtherLink II", .internal_name = "3c503", - .flags = DEVICE_ISA, - .local = 0, - .init = threec503_nic_init, - .close = threec503_nic_close, - .reset = NULL, - { .available = NULL }, + .flags = DEVICE_ISA, + .local = 0, + .init = threec503_nic_init, + .close = threec503_nic_close, + .reset = NULL, + .available = NULL, .speed_changed = NULL, - .force_redraw = NULL, - .config = threec503_config + .force_redraw = NULL, + .config = threec503_config }; diff --git a/src/network/net_dp8390.c b/src/network/net_dp8390.c index d6062604f..623dec56c 100644 --- a/src/network/net_dp8390.c +++ b/src/network/net_dp8390.c @@ -918,8 +918,7 @@ dp8390_set_defaults(dp8390_t *dev, uint8_t flags) void dp8390_mem_alloc(dp8390_t *dev, uint32_t start, uint32_t size) { - dev->mem = (uint8_t *) malloc(size * sizeof(uint8_t)); - memset(dev->mem, 0, size * sizeof(uint8_t)); + dev->mem = (uint8_t *) calloc(size, sizeof(uint8_t)); dev->mem_start = start; dev->mem_end = start + size; dev->mem_size = size; @@ -1007,8 +1006,7 @@ dp8390_soft_reset(dp8390_t *dev) static void * dp8390_init(UNUSED(const device_t *info)) { - dp8390_t *dp8390 = (dp8390_t *) malloc(sizeof(dp8390_t)); - memset(dp8390, 0, sizeof(dp8390_t)); + dp8390_t *dp8390 = (dp8390_t *) calloc(1, sizeof(dp8390_t)); /* Set values assuming WORD and only the clear IRQ flag - - the NIC can then call dp8390_set_defaults() again to @@ -1047,7 +1045,7 @@ const device_t dp8390_device = { .init = dp8390_init, .close = dp8390_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/network/net_eeprom_nmc93cxx.c b/src/network/net_eeprom_nmc93cxx.c index 3ad6bd030..b4fdce1e6 100644 --- a/src/network/net_eeprom_nmc93cxx.c +++ b/src/network/net_eeprom_nmc93cxx.c @@ -277,7 +277,7 @@ const device_t nmc93cxx_device = { .init = nmc93cxx_eeprom_init, .close = nmc93cxx_eeprom_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/network/net_modem.c b/src/network/net_modem.c index bb312ec31..af97a16db 100644 --- a/src/network/net_modem.c +++ b/src/network/net_modem.c @@ -1133,7 +1133,7 @@ modem_dtr_callback_timer(void *priv) } void -modem_dtr_callback(serial_t *serial, int status, void *priv) +modem_dtr_callback(UNUSED(serial_t *serial), int status, void *priv) { modem_t *dev = (modem_t *) priv; dev->dtrstate = !!status; @@ -1177,9 +1177,15 @@ modem_process_telnet(modem_t *modem, uint8_t *data, uint32_t size) uint8_t c = data[i]; if (modem->telClient.inIAC) { if (modem->telClient.recCommand) { + modem_log("modem_process_telnet: received command %i, option %i\n", modem->telClient.command, c); + if ((c != 0) && (c != 1) && (c != 3)) { - if (modem->telClient.command > 250) { - /* Reject anything we don't recognize */ + /* Reject anything we don't recognize */ + if (modem->telClient.command == 251 || modem->telClient.command == 252) { + modem_data_mode_process_byte(modem, 0xff); + modem_data_mode_process_byte(modem, 254); + modem_data_mode_process_byte(modem, c); /* Don't do crap! */ + } else if (modem->telClient.command == 253 || modem->telClient.command == 254) { modem_data_mode_process_byte(modem, 0xff); modem_data_mode_process_byte(modem, 252); modem_data_mode_process_byte(modem, c); /* We won't do crap! */ @@ -1483,7 +1489,7 @@ modem_cmdpause_timer_callback(void *priv) /* Initialize the device for use by the user. */ static void * -modem_init(const device_t *info) +modem_init(UNUSED(const device_t *info)) { modem_t *modem = (modem_t *) calloc(1, sizeof(modem_t)); const char *phonebook_file = NULL; @@ -1531,30 +1537,31 @@ modem_close(void *priv) // clang-format off static const device_config_t modem_config[] = { { - .name = "port", - .description = "Serial Port", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "port", + .description = "Serial Port", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "COM1", .value = 0 }, { .description = "COM2", .value = 1 }, { .description = "COM3", .value = 2 }, { .description = "COM4", .value = 3 }, { .description = "" } - } + }, + .bios = { { 0 } } }, { - .name = "baudrate", - .description = "Baud Rate", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 115200, - .file_filter = NULL, - .spinner = { 0 }, - .selection = { + .name = "baudrate", + .description = "Baud Rate", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 115200, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "115200", .value = 115200 }, { .description = "57600", .value = 57600 }, { .description = "56000", .value = 56000 }, @@ -1569,32 +1576,44 @@ static const device_config_t modem_config[] = { { .description = "1200", .value = 1200 }, { .description = "600", .value = 600 }, { .description = "300", .value = 300 }, - } + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "listen_port", - .description = "TCP/IP listening port", - .type = CONFIG_SPINNER, - .spinner = - { - .min = 0, + .name = "listen_port", + .description = "TCP/IP listening port", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { + .min = 0, .max = 32767 }, - .default_int = 0 + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "phonebook_file", - .description = "Phonebook File", - .type = CONFIG_FNAME, - .default_string = "", - .file_filter = "Text files (*.txt)|*.txt" + .name = "phonebook_file", + .description = "Phonebook File", + .type = CONFIG_FNAME, + .default_string = NULL, + .file_filter = "Text files (*.txt)|*.txt", + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "telnet_mode", - .description = "Telnet emulation", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "telnet_mode", + .description = "Telnet emulation", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; @@ -1608,7 +1627,7 @@ const device_t modem_device = { .init = modem_init, .close = modem_close, .reset = NULL, - { .poll = NULL }, + .available = NULL, .speed_changed = modem_speed_changed, .force_redraw = NULL, .config = modem_config diff --git a/src/network/net_ne2000.c b/src/network/net_ne2000.c index 324154947..e45b55b22 100644 --- a/src/network/net_ne2000.c +++ b/src/network/net_ne2000.c @@ -66,7 +66,6 @@ #include <86box/network.h> #include <86box/net_dp8390.h> #include <86box/net_ne2000.h> -#include <86box/bswap.h> #include <86box/isapnp.h> #include <86box/plat_fallthrough.h> #include <86box/plat_unused.h> @@ -313,7 +312,7 @@ asic_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) static uint32_t page3_read(nic_t *dev, uint32_t off, UNUSED(unsigned int len)) { - if (dev->board >= NE2K_RTL8019AS) + if (dev->board >= NE2K_RTL8019AS_PNP) switch (off) { case 0x1: /* 9346CR */ return (dev->_9346cr); @@ -328,7 +327,7 @@ page3_read(nic_t *dev, uint32_t off, UNUSED(unsigned int len)) return (dev->config3 & 0x46); case 0x8: /* CSNSAV */ - return ((dev->board == NE2K_RTL8019AS) ? dev->pnp_csnsav : 0x00); + return ((dev->board == NE2K_RTL8019AS_PNP) ? dev->pnp_csnsav : 0x00); case 0xe: /* 8029ASID0 */ if (dev->board == NE2K_RTL8029AS) @@ -351,7 +350,7 @@ page3_read(nic_t *dev, uint32_t off, UNUSED(unsigned int len)) static void page3_write(nic_t *dev, uint32_t off, uint32_t val, UNUSED(unsigned len)) { - if (dev->board >= NE2K_RTL8019AS) { + if (dev->board >= NE2K_RTL8019AS_PNP) { nelog(3, "%s: Page2 write to register 0x%02x, len=%u, value=0x%04x\n", dev->name, off, len, val); @@ -912,17 +911,15 @@ nic_init(const device_t *info) { uint32_t mac; uint32_t mac_oui; - char *rom; + char *rom = NULL; nic_t *dev; int set_oui = 0; - dev = malloc(sizeof(nic_t)); - memset(dev, 0x00, sizeof(nic_t)); + dev = calloc(1, sizeof(nic_t)); dev->name = info->name; dev->board = info->local; - rom = NULL; - if (dev->board >= NE2K_RTL8019AS) { + if (dev->board >= NE2K_RTL8019AS_PNP) { dev->base_address = 0x340; dev->base_irq = 12; if (dev->board == NE2K_RTL8029AS) { @@ -1045,18 +1042,18 @@ nic_init(const device_t *info) dp8390_mem_alloc(dev->dp8390, 0x4000, 0x8000); break; - case NE2K_RTL8019AS: + case NE2K_RTL8019AS_PNP: case NE2K_RTL8029AS: dev->is_pci = (dev->board == NE2K_RTL8029AS) ? 1 : 0; dev->maclocal[0] = 0x00; /* 00:E0:4C (Realtek OID) */ dev->maclocal[1] = 0xE0; dev->maclocal[2] = 0x4C; - rom = (dev->board == NE2K_RTL8019AS) ? ROM_PATH_RTL8019 : ROM_PATH_RTL8029; + rom = (dev->board == NE2K_RTL8019AS_PNP) ? ROM_PATH_RTL8019 : ROM_PATH_RTL8029; if (dev->is_pci) dp8390_set_defaults(dev->dp8390, DP8390_FLAG_EVEN_MAC); else dp8390_set_defaults(dev->dp8390, DP8390_FLAG_EVEN_MAC | DP8390_FLAG_CLEAR_IRQ); - dp8390_set_id(dev->dp8390, 0x50, (dev->board == NE2K_RTL8019AS) ? 0x70 : 0x43); + dp8390_set_id(dev->dp8390, 0x50, (dev->board == NE2K_RTL8019AS_PNP) ? 0x70 : 0x43); dp8390_mem_alloc(dev->dp8390, 0x4000, 0x8000); break; @@ -1074,7 +1071,7 @@ nic_init(const device_t *info) mac_oui = (((int) dev->maclocal[0]) << 16); mac_oui |= (((int) dev->maclocal[1]) << 8); mac_oui |= ((int) dev->maclocal[2]); - device_set_config_mac("mac", mac); + device_set_config_mac("mac_oui", mac_oui); } else { dev->maclocal[0] = (mac_oui >> 16) & 0xff; dev->maclocal[1] = (mac_oui >> 8) & 0xff; @@ -1093,13 +1090,13 @@ nic_init(const device_t *info) * Make this device known to the I/O system. * PnP and PCI devices start with address spaces inactive. */ - if ((dev->board < NE2K_RTL8019AS) && (dev->board != NE2K_ETHERNEXT_MC)) + if ((dev->board < NE2K_RTL8019AS_PNP) && (dev->board != NE2K_ETHERNEXT_MC)) nic_ioset(dev, dev->base_address); /* Set up our BIOS ROM space, if any. */ nic_rom_init(dev, rom); - if (dev->board >= NE2K_RTL8019AS) { + if (dev->board >= NE2K_RTL8019AS_PNP) { if (dev->is_pci) { /* * Configure the PCI space registers. @@ -1147,7 +1144,7 @@ nic_init(const device_t *info) pci_add_card(PCI_ADD_NORMAL, nic_pci_read, nic_pci_write, dev, &dev->pci_slot); } - /* Initialize the RTL8029 EEPROM. */ + /* Initialize the RTL80x9 EEPROM. */ memset(dev->eeprom, 0x00, sizeof(dev->eeprom)); if (dev->board == NE2K_RTL8029AS) { @@ -1161,7 +1158,7 @@ nic_init(const device_t *info) const char *pnp_rom_file = NULL; int pnp_rom_len = 0x4a; switch (dev->board) { - case NE2K_RTL8019AS: + case NE2K_RTL8019AS_PNP: pnp_rom_file = "roms/network/rtl8019as/RTL8019A.BIN"; break; @@ -1185,7 +1182,7 @@ nic_init(const device_t *info) } switch (info->local) { - case NE2K_RTL8019AS: + case NE2K_RTL8019AS_PNP: case NE2K_DE220P: dev->pnp_card = isapnp_add_card(pnp_rom, pnp_rom_len, nic_pnp_config_changed, nic_pnp_csn_changed, @@ -1237,14 +1234,14 @@ de220p_available(void) // clang-format off static const device_config_t ne1000_config[] = { { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x300, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x300, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { /* Source: Windows 95 .INF file. */ { .description = "0x300", .value = 0x300 }, { .description = "0x320", .value = 0x320 }, @@ -1252,16 +1249,17 @@ static const device_config_t ne1000_config[] = { { .description = "0x360", .value = 0x360 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 3, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 3, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { /* Source: Windows 95 .INF file. */ { .description = "IRQ 2", .value = 2 }, { .description = "IRQ 3", .value = 3 }, @@ -1270,27 +1268,32 @@ static const device_config_t ne1000_config[] = { { .description = "IRQ 9", .value = 9 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "mac", - .description = "MAC Address", - .type = CONFIG_MAC, - .default_string = "", - .default_int = -1 + .name = "mac", + .description = "MAC Address", + .type = CONFIG_MAC, + .default_string = NULL, + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t ne1000_compat_config[] = { { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x300, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x300, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { /* Source: Windows 95 .INF file. */ { .description = "0x200", .value = 0x200 }, { .description = "0x220", .value = 0x220 }, @@ -1310,16 +1313,17 @@ static const device_config_t ne1000_compat_config[] = { { .description = "0x3e0", .value = 0x3e0 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 3, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 3, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { /* Source: Windows 95 .INF file. */ { .description = "IRQ 2", .value = 2 }, { .description = "IRQ 3", .value = 3 }, @@ -1329,34 +1333,43 @@ static const device_config_t ne1000_compat_config[] = { { .description = "IRQ 9", .value = 9 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "mac", - .description = "MAC Address", - .type = CONFIG_MAC, - .default_string = "", - .default_int = -1 + .name = "mac", + .description = "MAC Address", + .type = CONFIG_MAC, + .default_string = NULL, + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "mac_oui", - .description = "MAC Address OUI", - .type = CONFIG_MAC, - .default_string = "", - .default_int = -1 + .name = "mac_oui", + .description = "MAC Address OUI", + .type = CONFIG_MAC, + .default_string = NULL, + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t ne2000_config[] = { { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x300, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x300, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { /* Source: Windows 95 .INF file. */ { .description = "0x300", .value = 0x300 }, { .description = "0x320", .value = 0x320 }, @@ -1364,16 +1377,17 @@ static const device_config_t ne2000_config[] = { { .description = "0x360", .value = 0x360 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 3, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 3, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { /* Source: Windows 95 .INF file. */ { .description = "IRQ 2", .value = 2 }, { .description = "IRQ 3", .value = 3 }, @@ -1382,43 +1396,49 @@ static const device_config_t ne2000_config[] = { { .description = "IRQ 9", .value = 9 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "mac", - .description = "MAC Address", - .type = CONFIG_MAC, - .default_string = "", - .default_int = -1 + .name = "mac", + .description = "MAC Address", + .type = CONFIG_MAC, + .default_string = NULL, + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "bios_addr", .description = "BIOS Address", .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Disabled", .value = 0x00000 }, { .description = "D000", .value = 0xD0000 }, { .description = "D800", .value = 0xD8000 }, { .description = "C800", .value = 0xC8000 }, { .description = "" } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t ne2000_compat_config[] = { { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x300, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x300, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { /* Source: Windows 95 .INF file. */ { .description = "0x200", .value = 0x200 }, { .description = "0x220", .value = 0x220 }, @@ -1438,16 +1458,17 @@ static const device_config_t ne2000_compat_config[] = { { .description = "0x3e0", .value = 0x3e0 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 10, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 10, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { /* Source: Windows 95 .INF file - not giving impossible IRQ's such as 6, 8, or 13. */ { .description = "IRQ 3", .value = 3 }, @@ -1462,50 +1483,60 @@ static const device_config_t ne2000_compat_config[] = { { .description = "IRQ 15", .value = 15 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "mac", - .description = "MAC Address", - .type = CONFIG_MAC, - .default_string = "", - .default_int = -1 + .name = "mac", + .description = "MAC Address", + .type = CONFIG_MAC, + .default_string = NULL, + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "mac_oui", - .description = "MAC Address OUI", - .type = CONFIG_MAC, - .default_string = "", - .default_int = -1 + .name = "mac_oui", + .description = "MAC Address OUI", + .type = CONFIG_MAC, + .default_string = NULL, + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "bios_addr", - .description = "BIOS Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "bios_addr", + .description = "BIOS Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Disabled", .value = 0x00000 }, { .description = "D000", .value = 0xD0000 }, { .description = "D800", .value = 0xD8000 }, { .description = "C800", .value = 0xC8000 }, { .description = "" } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t ne2000_compat_8bit_config[] = { { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x320, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x320, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { /* Source: board docs, https://github.com/skiselev/isa8_eth */ { .description = "0x200", .value = 0x200 }, { .description = "0x220", .value = 0x220 }, @@ -1525,16 +1556,17 @@ static const device_config_t ne2000_compat_8bit_config[] = { { .description = "0x3e0", .value = 0x3e0 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 3, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 3, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { /* Source: board docs, https://github.com/skiselev/isa8_eth */ { .description = "IRQ 2", .value = 2 }, { .description = "IRQ 3", .value = 3 }, @@ -1543,30 +1575,39 @@ static const device_config_t ne2000_compat_8bit_config[] = { { .description = "IRQ 9", .value = 9 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "mac", - .description = "MAC Address", - .type = CONFIG_MAC, - .default_string = "", - .default_int = -1 + .name = "mac", + .description = "MAC Address", + .type = CONFIG_MAC, + .default_string = NULL, + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "mac_oui", - .description = "MAC Address OUI", - .type = CONFIG_MAC, - .default_string = "", - .default_int = -1 + .name = "mac_oui", + .description = "MAC Address OUI", + .type = CONFIG_MAC, + .default_string = NULL, + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "bios_addr", - .description = "BIOS Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "bios_addr", + .description = "BIOS Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { /* Source: board docs, https://github.com/skiselev/isa8_eth */ { .description = "Disabled", .value = 0x00000 }, { .description = "C000", .value = 0xC0000 }, @@ -1579,6 +1620,7 @@ static const device_config_t ne2000_compat_8bit_config[] = { { .description = "DC00", .value = 0xDC000 }, { .description = "" } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; @@ -1586,40 +1628,56 @@ static const device_config_t ne2000_compat_8bit_config[] = { static const device_config_t rtl8019as_config[] = { { - .name = "mac", - .description = "MAC Address", - .type = CONFIG_MAC, - .default_string = "", - .default_int = -1 + .name = "mac", + .description = "MAC Address", + .type = CONFIG_MAC, + .default_string = NULL, + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t rtl8029as_config[] = { { - .name = "bios", - .description = "Enable BIOS", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "bios", + .description = "Enable BIOS", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "mac", - .description = "MAC Address", - .type = CONFIG_MAC, - .default_string = "", - .default_int = -1 + .name = "mac", + .description = "MAC Address", + .type = CONFIG_MAC, + .default_string = NULL, + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t mca_mac_config[] = { { - .name = "mac", - .description = "MAC Address", - .type = CONFIG_MAC, - .default_string = "", - .default_int = -1 + .name = "mac", + .description = "MAC Address", + .type = CONFIG_MAC, + .default_string = NULL, + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; @@ -1633,7 +1691,7 @@ const device_t ne1000_device = { .init = nic_init, .close = nic_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ne1000_config @@ -1647,7 +1705,7 @@ const device_t ne1000_compat_device = { .init = nic_init, .close = nic_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ne1000_compat_config @@ -1656,12 +1714,12 @@ const device_t ne1000_compat_device = { const device_t ne2000_device = { .name = "Novell NE2000", .internal_name = "novell_ne2k", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = NE2K_NE2000, .init = nic_init, .close = nic_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ne2000_config @@ -1670,12 +1728,12 @@ const device_t ne2000_device = { const device_t ne2000_compat_device = { .name = "NE2000 Compatible", .internal_name = "ne2k", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = NE2K_NE2000_COMPAT, .init = nic_init, .close = nic_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ne2000_compat_config @@ -1689,7 +1747,7 @@ const device_t ne2000_compat_8bit_device = { .init = nic_init, .close = nic_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ne2000_compat_8bit_config @@ -1703,21 +1761,21 @@ const device_t ethernext_mc_device = { .init = nic_init, .close = nic_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = mca_mac_config }; -const device_t rtl8019as_device = { +const device_t rtl8019as_pnp_device = { .name = "Realtek RTL8019AS", .internal_name = "ne2kpnp", - .flags = DEVICE_ISA | DEVICE_AT, - .local = NE2K_RTL8019AS, + .flags = DEVICE_ISA16, + .local = NE2K_RTL8019AS_PNP, .init = nic_init, .close = nic_close, .reset = NULL, - { .available = rtl8019as_available }, + .available = rtl8019as_available, .speed_changed = NULL, .force_redraw = NULL, .config = rtl8019as_config @@ -1726,12 +1784,12 @@ const device_t rtl8019as_device = { const device_t de220p_device = { .name = "D-Link DE-220P", .internal_name = "de220p", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = NE2K_DE220P, .init = nic_init, .close = nic_close, .reset = NULL, - { .available = de220p_available }, + .available = de220p_available, .speed_changed = NULL, .force_redraw = NULL, .config = rtl8019as_config @@ -1745,7 +1803,7 @@ const device_t rtl8029as_device = { .init = nic_init, .close = nic_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = rtl8029as_config diff --git a/src/network/net_null.c b/src/network/net_null.c index 6fb3f3440..6d5f68e46 100644 --- a/src/network/net_null.c +++ b/src/network/net_null.c @@ -218,8 +218,8 @@ net_null_close(void *priv) } const netdrv_t net_null_drv = { - &net_null_in_available, - &net_null_init, - &net_null_close, - NULL + .notify_in = &net_null_in_available, + .init = &net_null_init, + .close = &net_null_close, + .priv = NULL }; diff --git a/src/network/net_pcap.c b/src/network/net_pcap.c index 852191c55..2af34d786 100644 --- a/src/network/net_pcap.c +++ b/src/network/net_pcap.c @@ -572,8 +572,8 @@ net_pcap_close(void *priv) } const netdrv_t net_pcap_drv = { - &net_pcap_in_available, - &net_pcap_init, - &net_pcap_close, - NULL + .notify_in = &net_pcap_in_available, + .init = &net_pcap_init, + .close = &net_pcap_close, + .priv = NULL }; diff --git a/src/network/net_pcnet.c b/src/network/net_pcnet.c index b1fca8feb..16fd7c65c 100644 --- a/src/network/net_pcnet.c +++ b/src/network/net_pcnet.c @@ -46,9 +46,9 @@ #include <86box/thread.h> #include <86box/network.h> #include <86box/net_pcnet.h> -#include <86box/bswap.h> #include <86box/plat_fallthrough.h> #include <86box/plat_unused.h> +#include <86box/bswap.h> /* PCI info. */ #define PCI_VENDID 0x1022 /* AMD */ @@ -2916,14 +2916,13 @@ pcnet_init(const device_t *info) int c; uint16_t checksum; - dev = malloc(sizeof(nic_t)); - memset(dev, 0x00, sizeof(nic_t)); + dev = calloc(1, sizeof(nic_t)); dev->name = info->name; dev->board = info->local & 0xff; dev->is_pci = !!(info->flags & DEVICE_PCI); dev->is_vlb = !!(info->flags & DEVICE_VLB); - dev->is_isa = !!(info->flags & (DEVICE_ISA | DEVICE_AT)); + dev->is_isa = !!(info->flags & (DEVICE_ISA16)); if (dev->is_pci || dev->is_vlb) dev->transfer_size = 4; @@ -3089,62 +3088,68 @@ pcnet_close(void *priv) // clang-format off static const device_config_t pcnet_pci_config[] = { { - .name = "mac", - .description = "MAC Address", - .type = CONFIG_MAC, - .default_string = "", - .default_int = -1 + .name = "mac", + .description = "MAC Address", + .type = CONFIG_MAC, + .default_string = NULL, + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t pcnet_isa_config[] = { { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x300, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x300, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "0x300", .value = 0x300 }, { .description = "0x320", .value = 0x320 }, { .description = "0x340", .value = 0x340 }, { .description = "0x360", .value = 0x360 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 3, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { .description = "IRQ 3", .value = 3 }, - { .description = "IRQ 4", .value = 4 }, - { .description = "IRQ 5", .value = 5 }, - { .description = "IRQ 7", .value = 7 }, - { .description = "IRQ 9", .value = 9 }, + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 3, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "IRQ 3", .value = 3 }, + { .description = "IRQ 4", .value = 4 }, + { .description = "IRQ 5", .value = 5 }, + { .description = "IRQ 7", .value = 7 }, + { .description = "IRQ 9", .value = 9 }, { .description = "IRQ 10", .value = 10 }, { .description = "IRQ 11", .value = 11 }, { .description = "IRQ 12", .value = 12 }, { .description = "IRQ 15", .value = 15 }, - { .description = "" } + { .description = "" } }, + .bios = { { 0 } } }, { - .name = "dma", - .description = "DMA", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 5, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "dma", + .description = "DMA", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 5, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "DMA 0", .value = 0 }, { .description = "DMA 3", .value = 3 }, { .description = "DMA 5", .value = 5 }, @@ -3152,61 +3157,72 @@ static const device_config_t pcnet_isa_config[] = { { .description = "DMA 7", .value = 7 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "mac", - .description = "MAC Address", - .type = CONFIG_MAC, - .default_string = "", - .default_int = -1 + .name = "mac", + .description = "MAC Address", + .type = CONFIG_MAC, + .default_string = NULL, + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t pcnet_vlb_config[] = { { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x300, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x300, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "0x300", .value = 0x300 }, { .description = "0x320", .value = 0x320 }, { .description = "0x340", .value = 0x340 }, { .description = "0x360", .value = 0x360 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 3, - .file_filter = "", - .spinner = { 0 }, + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 3, + .file_filter = NULL, + .spinner = { 0 }, .selection = { - { .description = "IRQ 3", .value = 3 }, - { .description = "IRQ 4", .value = 4 }, - { .description = "IRQ 5", .value = 5 }, - { .description = "IRQ 7", .value = 7 }, - { .description = "IRQ 9", .value = 9 }, + { .description = "IRQ 3", .value = 3 }, + { .description = "IRQ 4", .value = 4 }, + { .description = "IRQ 5", .value = 5 }, + { .description = "IRQ 7", .value = 7 }, + { .description = "IRQ 9", .value = 9 }, { .description = "IRQ 10", .value = 10 }, { .description = "IRQ 11", .value = 11 }, { .description = "IRQ 12", .value = 12 }, { .description = "IRQ 15", .value = 15 }, - { .description = "" } + { .description = "" } }, + .bios = { { 0 } } }, { - .name = "mac", - .description = "MAC Address", - .type = CONFIG_MAC, + .name = "mac", + .description = "MAC Address", + .type = CONFIG_MAC, .default_string = "", - .default_int = -1 + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; @@ -3215,12 +3231,12 @@ static const device_config_t pcnet_vlb_config[] = { const device_t pcnet_am79c960_device = { .name = "AMD PCnet-ISA", .internal_name = "pcnetisa", - .flags = DEVICE_AT | DEVICE_ISA, + .flags = DEVICE_ISA16, .local = DEV_AM79C960, .init = pcnet_init, .close = pcnet_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = pcnet_isa_config @@ -3229,26 +3245,30 @@ const device_t pcnet_am79c960_device = { const device_t pcnet_am79c960_eb_device = { .name = "Racal Interlan EtherBlaster", .internal_name = "pcnetracal", - .flags = DEVICE_AT | DEVICE_ISA, + .flags = DEVICE_ISA16, .local = DEV_AM79C960_EB, .init = pcnet_init, .close = pcnet_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = pcnet_isa_config }; +/* + Used to be incorrectly called "AMD PCnet-VL" but the real name of the chip is "AMD PCnet-32" per the relevant datasheet. + https://theretroweb.com/chip/documentation/am79c965-66c24a7e6969d347126123.pdf +*/ const device_t pcnet_am79c960_vlb_device = { - .name = "AMD PCnet-VL", + .name = "AMD PCnet-32", .internal_name = "pcnetvlb", .flags = DEVICE_VLB, .local = DEV_AM79C960_VLB, .init = pcnet_init, .close = pcnet_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = pcnet_vlb_config @@ -3257,12 +3277,12 @@ const device_t pcnet_am79c960_vlb_device = { const device_t pcnet_am79c961_device = { .name = "AMD PCnet-ISA+", .internal_name = "pcnetisaplus", - .flags = DEVICE_AT | DEVICE_ISA, + .flags = DEVICE_ISA16, .local = DEV_AM79C961, .init = pcnet_init, .close = pcnet_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = pcnet_pci_config @@ -3276,7 +3296,7 @@ const device_t pcnet_am79c970a_device = { .init = pcnet_init, .close = pcnet_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = pcnet_pci_config @@ -3290,7 +3310,7 @@ const device_t pcnet_am79c973_device = { .init = pcnet_init, .close = pcnet_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = pcnet_pci_config @@ -3304,7 +3324,7 @@ const device_t pcnet_am79c973_onboard_device = { .init = pcnet_init, .close = pcnet_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = pcnet_pci_config diff --git a/src/network/net_plip.c b/src/network/net_plip.c index 8b0bf460c..ac8ab2850 100644 --- a/src/network/net_plip.c +++ b/src/network/net_plip.c @@ -26,12 +26,12 @@ #include #define HAVE_STDARG_H #include <86box/86box.h> +#include <86box/timer.h> #include <86box/lpt.h> #include <86box/timer.h> #include <86box/pit.h> #include <86box/device.h> #include <86box/thread.h> -#include <86box/timer.h> #include <86box/network.h> #include <86box/plat_unused.h> @@ -445,8 +445,7 @@ plip_rx(void *priv, uint8_t *buf, int io_len) static void * plip_lpt_init(void *lpt) { - plip_t *dev = (plip_t *) malloc(sizeof(plip_t)); - memset(dev, 0, sizeof(plip_t)); + plip_t *dev = (plip_t *) calloc(1, sizeof(plip_t)); plip_log(1, "PLIP: lpt_init()\n"); @@ -489,15 +488,18 @@ plip_close(void *priv) } const lpt_device_t lpt_plip_device = { - .name = "Parallel Line Internet Protocol", - .internal_name = "plip", - .init = plip_lpt_init, - .close = plip_close, - .write_data = plip_write_data, - .write_ctrl = plip_write_ctrl, - .read_data = NULL, - .read_status = plip_read_status, - .read_ctrl = NULL + .name = "Parallel Line Internet Protocol", + .internal_name = "plip", + .init = plip_lpt_init, + .close = plip_close, + .write_data = plip_write_data, + .write_ctrl = plip_write_ctrl, + .autofeed = NULL, + .strobe = NULL, + .read_status = plip_read_status, + .read_ctrl = NULL, + .epp_write_data = NULL, + .epp_request_read = NULL }; const device_t plip_device = { @@ -508,7 +510,7 @@ const device_t plip_device = { .init = plip_net_init, .close = NULL, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/network/net_rtl8139.c b/src/network/net_rtl8139.c index f04f9b7a3..0d07a8f83 100644 --- a/src/network/net_rtl8139.c +++ b/src/network/net_rtl8139.c @@ -28,6 +28,9 @@ #include #include #include +#ifdef _MVC_VER +#include +#endif #include #define HAVE_STDARG_H #include <86box/86box.h> @@ -41,10 +44,10 @@ #include <86box/thread.h> #include <86box/network.h> #include <86box/net_eeprom_nmc93cxx.h> -#include <86box/bswap.h> #include <86box/nvr.h> #include "cpu.h" #include <86box/plat_unused.h> +#include <86box/bswap.h> #define PCI_PERIOD 30 /* 30 ns period = 33.333333 Mhz frequency */ @@ -531,14 +534,14 @@ rtl8139_write_buffer(RTL8139State *s, const void *buf, int size) if (size > wrapped) { dma_bm_write(s->RxBuf + s->RxBufAddr, - buf, size - wrapped, 1); + (uint8_t *) buf, size - wrapped, 1); } /* reset buffer pointer */ s->RxBufAddr = 0; dma_bm_write(s->RxBuf + s->RxBufAddr, - buf + (size - wrapped), wrapped, 1); + (uint8_t *) buf + (size - wrapped), wrapped, 1); s->RxBufAddr = wrapped; @@ -1207,7 +1210,7 @@ rtl8139_CpCmd_read(RTL8139State *s) } static void -rtl8139_IntrMitigate_write(UNUSED(RTL8139State *s), uint32_t val) +rtl8139_IntrMitigate_write(UNUSED(RTL8139State *s), UNUSED(uint32_t val)) { rtl8139_log("C+ IntrMitigate register write(w) val=0x%04x\n", val); } @@ -2546,6 +2549,12 @@ rtl8139_io_writeb(uint32_t addr, uint8_t val, void *priv) break; + case RxConfig: + rtl8139_log("RxConfig write(b) val=0x%02x\n", val); + rtl8139_RxConfig_write(s, + (rtl8139_RxConfig_read(s) & 0xFFFFFF00) | val); + break; + default: rtl8139_log("not implemented write(b) addr=0x%x val=0x%02x\n", addr, val); break; @@ -3148,7 +3157,7 @@ rtl8139_pci_read(UNUSED(int func), int addr, void *priv) } static void -rtl8139_pci_write(int func, int addr, uint8_t val, void *priv) +rtl8139_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) { RTL8139State *s = (RTL8139State *) priv; @@ -3312,11 +3321,15 @@ nic_close(void *priv) // clang-format off static const device_config_t rtl8139c_config[] = { { - .name = "mac", - .description = "MAC Address", - .type = CONFIG_MAC, - .default_string = "", - .default_int = -1 + .name = "mac", + .description = "MAC Address", + .type = CONFIG_MAC, + .default_string = NULL, + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; @@ -3330,7 +3343,7 @@ const device_t rtl8139c_plus_device = { .init = nic_init, .close = nic_close, .reset = rtl8139_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = rtl8139c_config diff --git a/src/network/net_slirp.c b/src/network/net_slirp.c index 92434973d..e8cfd6cd7 100644 --- a/src/network/net_slirp.c +++ b/src/network/net_slirp.c @@ -60,16 +60,19 @@ enum { }; typedef struct net_slirp_t { - Slirp *slirp; - uint8_t mac_addr[6]; - netcard_t *card; /* netcard attached to us */ - thread_t *poll_tid; - net_evt_t tx_event; - net_evt_t stop_event; - netpkt_t pkt; - netpkt_t pkt_tx_v[SLIRP_PKT_BATCH]; + Slirp * slirp; + uint8_t mac_addr[6]; + netcard_t * card; /* netcard attached to us */ + thread_t * poll_tid; + net_evt_t rx_event; + net_evt_t tx_event; + net_evt_t stop_event; + netpkt_t pkt; + netpkt_t pkt_tx_v[SLIRP_PKT_BATCH]; + int during_tx; + int recv_on_tx; #ifdef _WIN32 - HANDLE sock_event; + HANDLE sock_event; #else uint32_t pfd_len; uint32_t pfd_size; @@ -133,7 +136,7 @@ net_slirp_clock_get_ns(UNUSED(void *opaque)) static void * net_slirp_timer_new(SlirpTimerCb cb, void *cb_opaque, UNUSED(void *opaque)) { - pc_timer_t *timer = malloc(sizeof(pc_timer_t)); + pc_timer_t *timer = calloc(1, sizeof(pc_timer_t)); timer_add(timer, cb, cb_opaque, 0); return timer; } @@ -152,14 +155,22 @@ net_slirp_timer_mod(void *timer, int64_t expire_timer, UNUSED(void *opaque)) } static void +#if SLIRP_CHECK_VERSION(4, 9, 0) +net_slirp_register_poll_socket(slirp_os_socket fd, void *opaque) +#else net_slirp_register_poll_fd(int fd, void *opaque) +#endif { (void) fd; (void) opaque; } static void +#if SLIRP_CHECK_VERSION(4, 9, 0) +net_slirp_unregister_poll_socket(slirp_os_socket fd, void *opaque) +#else net_slirp_unregister_poll_fd(int fd, void *opaque) +#endif { (void) fd; (void) opaque; @@ -184,14 +195,22 @@ net_slirp_send_packet(const void *qp, size_t pkt_len, void *opaque) memcpy(slirp->pkt.data, (uint8_t *) qp, pkt_len); slirp->pkt.len = pkt_len; - network_rx_put_pkt(slirp->card, &slirp->pkt); + if (slirp->during_tx) { + network_rx_on_tx_put_pkt(slirp->card, &slirp->pkt); + slirp->recv_on_tx = 1; + } else + network_rx_put_pkt(slirp->card, &slirp->pkt); return pkt_len; } #ifdef _WIN32 static int +# if SLIRP_CHECK_VERSION(4, 9, 0) +net_slirp_add_poll(slirp_os_socket fd, int events, void *opaque) +# else net_slirp_add_poll(int fd, int events, void *opaque) +# endif { net_slirp_t *slirp = (net_slirp_t *) opaque; long bitmask = 0; @@ -209,7 +228,11 @@ net_slirp_add_poll(int fd, int events, void *opaque) } #else static int +# if SLIRP_CHECK_VERSION(4, 9, 0) +net_slirp_add_poll(slirp_os_socket fd, int events, void *opaque) +# else net_slirp_add_poll(int fd, int events, void *opaque) +# endif { net_slirp_t *slirp = (net_slirp_t *) opaque; @@ -268,8 +291,12 @@ net_slirp_get_revents(int idx, void *opaque) WSA_TO_POLL(FD_WRITE, SLIRP_POLL_OUT); WSA_TO_POLL(FD_CONNECT, SLIRP_POLL_OUT); WSA_TO_POLL(FD_OOB, SLIRP_POLL_PRI); + WSA_TO_POLL(FD_CLOSE, SLIRP_POLL_IN); WSA_TO_POLL(FD_CLOSE, SLIRP_POLL_HUP); + if (ret == 0) + ret |= SLIRP_POLL_IN; + return ret; } #else @@ -300,8 +327,13 @@ static const SlirpCb slirp_cb = { .timer_new = net_slirp_timer_new, .timer_free = net_slirp_timer_free, .timer_mod = net_slirp_timer_mod, +#if SLIRP_CHECK_VERSION(4, 9, 0) + .register_poll_socket = net_slirp_register_poll_socket, + .unregister_poll_socket = net_slirp_unregister_poll_socket, +#else .register_poll_fd = net_slirp_register_poll_fd, .unregister_poll_fd = net_slirp_unregister_poll_fd, +#endif .notify = net_slirp_notify }; @@ -324,6 +356,21 @@ net_slirp_in_available(void *priv) net_event_set(&slirp->tx_event); } +static void +net_slirp_rx_deferred_packets(net_slirp_t *slirp) +{ + int packets = 0; + + if (slirp->recv_on_tx) { + do { + packets = network_rx_on_tx_popv(slirp->card, slirp->pkt_tx_v, SLIRP_PKT_BATCH); + for (int i = 0; i < packets; i++) + network_rx_put_pkt(slirp->card, &(slirp->pkt_tx_v[i])); + } while (packets > 0); + slirp->recv_on_tx = 0; + } +} + #ifdef _WIN32 static void net_slirp_thread(void *priv) @@ -340,7 +387,11 @@ net_slirp_thread(void *priv) bool run = true; while (run) { uint32_t timeout = -1; +# if SLIRP_CHECK_VERSION(4, 9, 0) + slirp_pollfds_fill_socket(slirp->slirp, &timeout, net_slirp_add_poll, slirp); +# else slirp_pollfds_fill(slirp->slirp, &timeout, net_slirp_add_poll, slirp); +# endif if (timeout < 0) timeout = INFINITE; @@ -352,10 +403,13 @@ net_slirp_thread(void *priv) case NET_EVENT_TX: { + slirp->during_tx = 1; int packets = network_tx_popv(slirp->card, slirp->pkt_tx_v, SLIRP_PKT_BATCH); - for (int i = 0; i < packets; i++) { + for (int i = 0; i < packets; i++) net_slirp_in(slirp, slirp->pkt_tx_v[i].data, slirp->pkt_tx_v[i].len); - } + slirp->during_tx = 0; + + net_slirp_rx_deferred_packets(slirp); } break; @@ -384,7 +438,11 @@ net_slirp_thread(void *priv) net_slirp_add_poll(net_event_get_fd(&slirp->stop_event), SLIRP_POLL_IN, slirp); net_slirp_add_poll(net_event_get_fd(&slirp->tx_event), SLIRP_POLL_IN, slirp); +# if SLIRP_CHECK_VERSION(4, 9, 0) + slirp_pollfds_fill_socket(slirp->slirp, &timeout, net_slirp_add_poll, slirp); +# else slirp_pollfds_fill(slirp->slirp, &timeout, net_slirp_add_poll, slirp); +# endif int ret = poll(slirp->pfd, slirp->pfd_len, timeout); @@ -398,10 +456,13 @@ net_slirp_thread(void *priv) if (slirp->pfd[NET_EVENT_TX].revents & POLLIN) { net_event_clear(&slirp->tx_event); + slirp->during_tx = 1; int packets = network_tx_popv(slirp->card, slirp->pkt_tx_v, SLIRP_PKT_BATCH); - for (int i = 0; i < packets; i++) { + for (int i = 0; i < packets; i++) net_slirp_in(slirp, slirp->pkt_tx_v[i].data, slirp->pkt_tx_v[i].len); - } + slirp->during_tx = 0; + + net_slirp_rx_deferred_packets(slirp); } } @@ -422,8 +483,7 @@ net_slirp_init(const netcard_t *card, const uint8_t *mac_addr, UNUSED(void *priv #ifndef _WIN32 slirp->pfd_size = 16 * sizeof(struct pollfd); - slirp->pfd = malloc(slirp->pfd_size); - memset(slirp->pfd, 0, slirp->pfd_size); + slirp->pfd = calloc(1, slirp->pfd_size); #endif /* Set the IP addresses to use. */ @@ -433,10 +493,47 @@ net_slirp_init(const netcard_t *card, const uint8_t *mac_addr, UNUSED(void *priv struct in_addr dhcp = { .s_addr = htonl(0x0a00000f | (slirp_card_num << 8)) }; /* 10.0.x.15 */ struct in_addr dns = { .s_addr = htonl(0x0a000003 | (slirp_card_num << 8)) }; /* 10.0.x.3 */ struct in_addr bind = { .s_addr = htonl(0x00000000) }; /* 0.0.0.0 */ - struct in6_addr ipv6_dummy = { 0 }; /* contents don't matter; we're not using IPv6 */ + + const SlirpConfig slirp_config = { +#if SLIRP_CHECK_VERSION(4, 9, 0) + .version = 6, +#else + .version = 1, +#endif + .restricted = 0, + .in_enabled = 1, + .vnetwork = net, + .vnetmask = mask, + .vhost = host, + .in6_enabled = 0, + .vprefix_addr6 = { .s6_addr = { 0xfe, 0xc0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, /* fec0:: - unused */ + .vprefix_len = 64, + .vhost6 = { .s6_addr = { 0xfe, 0xc0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x02 } }, /* fec0::2 - unused */ + .vhostname = "86Box", + .tftp_server_name = NULL, + .tftp_path = NULL, + .bootfile = NULL, + .vdhcp_start = dhcp, + .vnameserver = dns, + .vnameserver6 = { .s6_addr = { 0xfe, 0xc0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x03 } }, /* fec0::3 - unused */ + .vdnssearch = NULL, + .vdomainname = NULL, + .if_mtu = 0, + .if_mru = 0, + .disable_host_loopback = 0, + .enable_emu = 0, +#if SLIRP_CHECK_VERSION(4, 9, 0) + .outbound_addr = NULL, + .outbound_addr6 = NULL, + .disable_dns = 0, + .disable_dhcp = 0, + .mfr_id = 0, + .oob_eth_addr = { 0, 0, 0, 0, 0, 0 } +#endif + }; /* Initialize SLiRP. */ - 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); + slirp->slirp = slirp_new(&slirp_config, &slirp_cb, slirp); if (!slirp->slirp) { slirp_log("SLiRP: initialization failed\n"); snprintf(netdrv_errbuf, NET_DRV_ERRBUF_SIZE, "SLiRP initialization failed"); @@ -478,6 +575,7 @@ net_slirp_init(const netcard_t *card, const uint8_t *mac_addr, UNUSED(void *priv slirp->pkt_tx_v[i].data = calloc(1, NET_MAX_FRAME); } slirp->pkt.data = calloc(1, NET_MAX_FRAME); + net_event_init(&slirp->rx_event); net_event_init(&slirp->tx_event); net_event_init(&slirp->stop_event); #ifdef _WIN32 @@ -532,8 +630,9 @@ net_slirp_close(void *priv) slirp_log("SLiRP: waiting for thread to end...\n"); thread_wait(slirp->poll_tid); - net_event_close(&slirp->tx_event); net_event_close(&slirp->stop_event); + net_event_close(&slirp->tx_event); + net_event_close(&slirp->rx_event); slirp_cleanup(slirp->slirp); for (int i = 0; i < SLIRP_PKT_BATCH; i++) { free(slirp->pkt_tx_v[i].data); @@ -544,7 +643,8 @@ net_slirp_close(void *priv) } const netdrv_t net_slirp_drv = { - &net_slirp_in_available, - &net_slirp_init, - &net_slirp_close + .notify_in = &net_slirp_in_available, + .init = &net_slirp_init, + .close = &net_slirp_close, + .priv = NULL }; diff --git a/src/network/net_tulip.c b/src/network/net_tulip.c index ca43b0844..685873c93 100644 --- a/src/network/net_tulip.c +++ b/src/network/net_tulip.c @@ -32,9 +32,9 @@ #include <86box/thread.h> #include <86box/network.h> #include <86box/net_eeprom_nmc93cxx.h> -#include <86box/bswap.h> #include <86box/plat_fallthrough.h> #include <86box/plat_unused.h> +#include <86box/bswap.h> #define ROM_PATH_DEC21140 "roms/network/dec21140/BIOS13502.BIN" @@ -971,7 +971,8 @@ tulip_write(uint32_t addr, uint32_t data, void *opaque) case CSR(7): s->csr[7] = data; - tulip_update_int(s); + if (s->device_info->local) + tulip_update_int(s); break; case CSR(8): @@ -1006,7 +1007,7 @@ tulip_write(uint32_t addr, uint32_t data, void *opaque) case CSR(13): s->csr[13] = data; - if (s->device_info->local == 3 && (data & 0x4)) { + if ((s->device_info->local == 3) && (data & 0x4)) { s->csr[13] = 0x8f01; s->csr[14] = 0xfffd; s->csr[15] = 0; @@ -1407,7 +1408,7 @@ nic_init(const device_t *info) if (!s) return NULL; - if (info->local && info->local != 3) { + if (info->local && (info->local != 3)) { s->bios_addr = 0xD0000; s->has_bios = device_get_config_int("bios"); } else { @@ -1434,7 +1435,7 @@ nic_init(const device_t *info) s->eeprom_data[2] = 0x14; s->eeprom_data[3] = 0x21; } else { - /*Subsystem Vendor ID*/ + /*Subsystem Vendor ID*/ s->eeprom_data[0] = info->local ? 0x25 : 0x11; s->eeprom_data[1] = 0x10; @@ -1549,23 +1550,40 @@ nic_init(const device_t *info) /*Block Count*/ s->eeprom_data[32] = 0x01; - /*Extended Format - Block Type 2 for 21142/21143*/ + /*Extended Format - Block Type 3 for 21142/21143*/ /*Length (0:6) and Format Indicator (7)*/ - s->eeprom_data[33] = 0x86; + s->eeprom_data[33] = 0x8d; /*Block Type*/ - s->eeprom_data[34] = 0x02; + s->eeprom_data[34] = 0x03; - /*Media Code (0:5), EXT (6), Reserved (7)*/ - s->eeprom_data[35] = 0x01; + /*PHY Number*/ + s->eeprom_data[35] = 0x00; - /*General Purpose Control*/ - s->eeprom_data[36] = 0xff; - s->eeprom_data[37] = 0xff; + /*GPR Length*/ + s->eeprom_data[36] = 0x00; - /*General Purpose Data*/ + /*Reset Length*/ + s->eeprom_data[37] = 0x00; + + /*Media Capabilities*/ s->eeprom_data[38] = 0x00; - s->eeprom_data[39] = 0x00; + s->eeprom_data[39] = 0x78; + + /*Nway Advertisement*/ + s->eeprom_data[40] = 0xe0; + s->eeprom_data[41] = 0x01; + + /*FDX Bit Map*/ + s->eeprom_data[42] = 0x00; + s->eeprom_data[43] = 0x50; + + /*TTM Bit Map*/ + s->eeprom_data[44] = 0x00; + s->eeprom_data[45] = 0x18; + + /*MII PHY Insertion/removal Indication*/ + s->eeprom_data[46] = 0x00; } s->eeprom_data[126] = tulip_srom_crc(s->eeprom_data) & 0xff; @@ -1608,7 +1626,7 @@ nic_init(const device_t *info) checksum *= 2; if (checksum > 65535) checksum = checksum % 65535; - + /* 3rd pair. */ checksum += (s->eeprom_data[4] * 256) | s->eeprom_data[5]; if (checksum > 65535) @@ -1616,7 +1634,7 @@ nic_init(const device_t *info) if (checksum >= 65535) checksum = 0; - + s->eeprom_data[6] = (checksum >> 8) & 0xFF; s->eeprom_data[7] = checksum & 0xFF; } @@ -1664,29 +1682,41 @@ nic_close(void *priv) // clang-format off static const device_config_t dec_tulip_21143_config[] = { { - .name = "mac", - .description = "MAC Address", - .type = CONFIG_MAC, - .default_string = "", - .default_int = -1 + .name = "mac", + .description = "MAC Address", + .type = CONFIG_MAC, + .default_string = NULL, + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t dec_tulip_21140_config[] = { { - .name = "bios", - .description = "Enable BIOS", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "bios", + .description = "Enable BIOS", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "mac", - .description = "MAC Address", - .type = CONFIG_MAC, - .default_string = "", - .default_int = -1 + .name = "mac", + .description = "MAC Address", + .type = CONFIG_MAC, + .default_string = NULL, + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; @@ -1700,7 +1730,7 @@ const device_t dec_tulip_device = { .init = nic_init, .close = nic_close, .reset = tulip_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = dec_tulip_21143_config @@ -1714,7 +1744,7 @@ const device_t dec_tulip_21140_device = { .init = nic_init, .close = nic_close, .reset = tulip_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = dec_tulip_21140_config @@ -1728,7 +1758,7 @@ const device_t dec_tulip_21140_vpc_device = { .init = nic_init, .close = nic_close, .reset = tulip_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = dec_tulip_21140_config @@ -1742,7 +1772,7 @@ const device_t dec_tulip_21040_device = { .init = nic_init, .close = nic_close, .reset = tulip_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = dec_tulip_21143_config diff --git a/src/network/net_vde.c b/src/network/net_vde.c index d783c9c9d..4f8d5c21f 100644 --- a/src/network/net_vde.c +++ b/src/network/net_vde.c @@ -302,9 +302,9 @@ void *net_vde_init(const netcard_t *card, const uint8_t *mac_addr, void *priv, c // VDE Driver structure //- const netdrv_t net_vde_drv = { - &net_vde_in_available, - &net_vde_init, - &net_vde_close, - NULL + .notify_in = &net_vde_in_available, + .init = &net_vde_init, + .close = &net_vde_close, + .priv = NULL }; diff --git a/src/network/net_wd8003.c b/src/network/net_wd8003.c index 72a4b7fd0..1ca8d8697 100644 --- a/src/network/net_wd8003.c +++ b/src/network/net_wd8003.c @@ -63,7 +63,6 @@ #include <86box/network.h> #include <86box/net_dp8390.h> #include <86box/net_wd8003.h> -#include <86box/bswap.h> #include <86box/plat_fallthrough.h> #include <86box/plat_unused.h> @@ -651,8 +650,7 @@ wd_init(const device_t *info) uint32_t mac; wd_t *dev; - dev = malloc(sizeof(wd_t)); - memset(dev, 0x00, sizeof(wd_t)); + dev = calloc(1, sizeof(wd_t)); dev->name = info->name; dev->board = info->local; @@ -808,46 +806,48 @@ wd_close(void *priv) // clang-format off static const device_config_t wd8003_config[] = { { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x300, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x300, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "0x240", .value = 0x240 }, { .description = "0x280", .value = 0x280 }, { .description = "0x300", .value = 0x300 }, { .description = "0x380", .value = 0x380 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 3, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 3, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "IRQ 2", .value = 2 }, { .description = "IRQ 3", .value = 3 }, { .description = "IRQ 5", .value = 5 }, { .description = "IRQ 7", .value = 7 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "ram_addr", - .description = "RAM Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0xD0000, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "ram_addr", + .description = "RAM Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0xD0000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "C800", .value = 0xC8000 }, { .description = "CC00", .value = 0xCC000 }, { .description = "D000", .value = 0xD0000 }, @@ -856,27 +856,32 @@ static const device_config_t wd8003_config[] = { { .description = "DC00", .value = 0xDC000 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "mac", - .description = "MAC Address", - .type = CONFIG_MAC, - .default_string = "", - .default_int = -1 + .name = "mac", + .description = "MAC Address", + .type = CONFIG_MAC, + .default_string = NULL, + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t wd8003eb_config[] = { { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x280, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x280, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "0x200", .value = 0x200 }, { .description = "0x220", .value = 0x220 }, { .description = "0x240", .value = 0x240 }, @@ -889,32 +894,34 @@ static const device_config_t wd8003eb_config[] = { { .description = "0x380", .value = 0x380 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 3, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 3, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "IRQ 2/9", .value = 9 }, { .description = "IRQ 3", .value = 3 }, { .description = "IRQ 4", .value = 4 }, { .description = "IRQ 7", .value = 7 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "ram_addr", - .description = "RAM Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0xD0000, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "ram_addr", + .description = "RAM Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0xD0000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "C000", .value = 0xC0000 }, { .description = "C400", .value = 0xC4000 }, { .description = "C800", .value = 0xC8000 }, @@ -925,27 +932,33 @@ static const device_config_t wd8003eb_config[] = { { .description = "DC00", .value = 0xDC000 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "ram_size", - .description = "RAM size", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 8192, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "ram_size", + .description = "RAM size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 8192, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "8 KB", .value = 8192 }, { .description = "32 KB", .value = 32768 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "mac", - .description = "MAC Address", - .type = CONFIG_MAC, - .default_string = "", - .default_int = -1 + .name = "mac", + .description = "MAC Address", + .type = CONFIG_MAC, + .default_string = NULL, + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; @@ -954,14 +967,14 @@ static const device_config_t wd8003eb_config[] = { http://www.stack.nl/~marcolz/network/wd80x3.html#WD8013EBT */ static const device_config_t wd8013_config[] = { { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x280, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x280, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "0x200", .value = 0x200 }, { .description = "0x220", .value = 0x220 }, { .description = "0x240", .value = 0x240 }, @@ -974,16 +987,17 @@ static const device_config_t wd8013_config[] = { { .description = "0x380", .value = 0x380 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 3, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 3, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "IRQ 2/9", .value = 9 }, { .description = "IRQ 3", .value = 3 }, { .description = "IRQ 4", .value = 4 }, @@ -994,16 +1008,17 @@ static const device_config_t wd8013_config[] = { { .description = "IRQ 15", .value = 15 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "ram_addr", - .description = "RAM Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0xD0000, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "ram_addr", + .description = "RAM Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0xD0000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "C000", .value = 0xC0000 }, { .description = "C400", .value = 0xC4000 }, { .description = "C800", .value = 0xC8000 }, @@ -1014,63 +1029,78 @@ static const device_config_t wd8013_config[] = { { .description = "DC00", .value = 0xDC000 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "ram_size", - .description = "RAM size", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 16384, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "ram_size", + .description = "RAM size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 16384, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "16 KB", .value = 16384 }, { .description = "64 KB", .value = 65536 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "mac", - .description = "MAC Address", - .type = CONFIG_MAC, - .default_string = "", - .default_int = -1 + .name = "mac", + .description = "MAC Address", + .type = CONFIG_MAC, + .default_string = NULL, + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t wd8013epa_config[] = { { - .name = "ram_size", - .description = "Initial RAM size", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 16384, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "ram_size", + .description = "Initial RAM size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 16384, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "8 KB", .value = 8192 }, { .description = "16 KB", .value = 16384 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "mac", - .description = "MAC Address", - .type = CONFIG_MAC, - .default_string = "", - .default_int = -1 + .name = "mac", + .description = "MAC Address", + .type = CONFIG_MAC, + .default_string = NULL, + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t mca_mac_config[] = { { - .name = "mac", - .description = "MAC Address", - .type = CONFIG_MAC, - .default_string = "", - .default_int = -1 + .name = "mac", + .description = "MAC Address", + .type = CONFIG_MAC, + .default_string = NULL, + .default_int = -1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; @@ -1084,7 +1114,7 @@ const device_t wd8003e_device = { .init = wd_init, .close = wd_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = wd8003_config @@ -1098,7 +1128,7 @@ const device_t wd8003eb_device = { .init = wd_init, .close = wd_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = wd8003eb_config @@ -1112,7 +1142,7 @@ const device_t wd8013ebt_device = { .init = wd_init, .close = wd_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = wd8013_config @@ -1126,7 +1156,7 @@ const device_t wd8003eta_device = { .init = wd_init, .close = wd_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = mca_mac_config @@ -1140,7 +1170,7 @@ const device_t wd8003ea_device = { .init = wd_init, .close = wd_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = mca_mac_config @@ -1154,7 +1184,7 @@ const device_t wd8013epa_device = { .init = wd_init, .close = wd_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = wd8013epa_config diff --git a/src/network/network.c b/src/network/network.c index c722849bf..0372a57fc 100644 --- a/src/network/network.c +++ b/src/network/network.c @@ -54,7 +54,9 @@ #include #include #include +#ifndef _MSC_VER #include +#endif #include #define HAVE_STDARG_H #include <86box/86box.h> @@ -83,36 +85,43 @@ static const NETWORK_CARD net_cards[] = { // clang-format off { &device_none }, { &device_internal }, + /* ISA */ { &threec501_device }, { &threec503_device }, - { &pcnet_am79c960_device }, - { &pcnet_am79c961_device }, - { &de220p_device }, { &ne1000_compat_device }, - { &ne2000_compat_device }, { &ne2000_compat_8bit_device }, { &ne1000_device }, - { &ne2000_device }, - { &pcnet_am79c960_eb_device }, - { &rtl8019as_device }, { &wd8003e_device }, { &wd8003eb_device }, { &wd8013ebt_device }, + /* COM */ + { &modem_device }, + /* LPT */ { &plip_device }, + /* ISA16 */ + { &pcnet_am79c960_device }, + { &pcnet_am79c961_device }, + { &de220p_device }, + { &ne2000_compat_device }, + { &ne2000_device }, + { &pcnet_am79c960_eb_device }, + { &rtl8019as_pnp_device }, + /* MCA */ { ðernext_mc_device }, { &wd8003eta_device }, { &wd8003ea_device }, { &wd8013epa_device }, + /* VLB */ + { &pcnet_am79c960_vlb_device }, + /* PCI */ { &pcnet_am79c973_device }, { &pcnet_am79c970a_device }, + { &dec_tulip_21140_device }, + { &dec_tulip_21040_device }, { &dec_tulip_device }, + { &dec_tulip_21140_vpc_device }, { &rtl8029as_device }, { &rtl8139c_plus_device }, - { &dec_tulip_21140_device }, - { &dec_tulip_21140_vpc_device }, - { &dec_tulip_21040_device }, - { &pcnet_am79c960_vlb_device }, - { &modem_device }, { NULL } // clang-format on }; @@ -430,7 +439,8 @@ network_rx_queue(void *priv) bool activity = rx_bytes || tx_bytes; bool led_on = card->led_timer & 0x80000000; if ((activity && !led_on) || (card->led_timer & 0x7fffffff) >= 150000) { - ui_sb_update_icon(SB_NETWORK | card->card_num, activity); + ui_sb_update_icon(SB_NETWORK | card->card_num, !!(rx_bytes)); + ui_sb_update_icon_write(SB_NETWORK | card->card_num, !!(tx_bytes)); card->led_timer = 0 | (activity << 31); } @@ -505,7 +515,7 @@ network_attach(void *card_drv, uint8_t *mac, NETRXCB rx, NETSETLINKSTATE set_lin 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(STRING_NET_ERROR), net_drv_error, plat_get_string(STRING_NET_ERROR_DESC)); + swprintf(tempmsg, sizeof_w(tempmsg), L"%ls:\n\n%s\n\n%ls", plat_get_string(STRING_NET_ERROR), net_drv_error, plat_get_string(STRING_NET_ERROR_DESC)); ui_msgbox(MBX_ERROR, tempmsg); net_cards_conf[net_card_current].net_type = NET_TYPE_NONE; } @@ -581,6 +591,7 @@ void network_reset(void) { ui_sb_update_icon(SB_NETWORK, 0); + ui_sb_update_icon_write(SB_NETWORK, 0); #ifdef ENABLE_NETWORK_LOG network_dump_mutex = thread_create_mutex(); @@ -647,6 +658,43 @@ network_rx_put(netcard_t *card, uint8_t *bufp, int len) return ret; } +int +network_rx_on_tx_popv(netcard_t *card, netpkt_t *pkt_vec, int vec_size) +{ + int pkt_count = 0; + + netqueue_t *queue = &card->queues[NET_QUEUE_RX_ON_TX]; + for (int i = 0; i < vec_size; i++) { + if (!network_queue_get_swap(queue, pkt_vec)) + break; + network_dump_packet(pkt_vec); + pkt_count++; + pkt_vec++; + } + + return pkt_count; +} + +int +network_rx_on_tx_put(netcard_t *card, uint8_t *bufp, int len) +{ + int ret = 0; + + ret = network_queue_put(&card->queues[NET_QUEUE_RX_ON_TX], bufp, len); + + return ret; +} + +int +network_rx_on_tx_put_pkt(netcard_t *card, netpkt_t *pkt) +{ + int ret = 0; + + ret = network_queue_put_swap(&card->queues[NET_QUEUE_RX_ON_TX], pkt); + + return ret; +} + int network_rx_put_pkt(netcard_t *card, netpkt_t *pkt) { diff --git a/src/nvr.c b/src/nvr.c index d833618d0..7f43a76c1 100644 --- a/src/nvr.c +++ b/src/nvr.c @@ -161,9 +161,9 @@ nvr_init(nvr_t *nvr) int c; /* Set up the NVR file's name. */ - c = strlen(machine_get_internal_name()) + 5; + c = strlen(machine_get_nvr_name()) + 5; nvr->fn = (char *) malloc(c + 1); - sprintf(nvr->fn, "%s.nvr", machine_get_internal_name()); + sprintf(nvr->fn, "%s.nvr", machine_get_nvr_name()); /* Initialize the internal clock as needed. */ memset(&intclk, 0x00, sizeof(intclk)); @@ -326,14 +326,15 @@ nvr_time_sync(void) /* Get current time from internal clock. */ void -nvr_time_get(struct tm *tm) +nvr_time_get(void *priv) { - uint8_t dom; - uint8_t mon; - uint8_t sum; - uint8_t wd; - uint16_t cent; - uint16_t yr; + struct tm *tm = (struct tm *) priv; + 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; @@ -352,8 +353,10 @@ nvr_time_get(struct tm *tm) /* Set internal clock time. */ void -nvr_time_set(struct tm *tm) +nvr_time_set(void *priv) { + struct tm *tm = (struct tm *) priv; + intclk.tm_sec = tm->tm_sec; intclk.tm_min = tm->tm_min; intclk.tm_hour = tm->tm_hour; diff --git a/src/nvr_at.c b/src/nvr_at.c index 9465839a7..4deda98be 100644 --- a/src/nvr_at.c +++ b/src/nvr_at.c @@ -296,6 +296,7 @@ #define FLAG_P6RP4_HACK 0x10 #define FLAG_PIIX4 0x20 #define FLAG_MULTI_BANK 0x40 +#define FLAG_MARTIN_HACK 0x80 typedef struct local_t { int8_t stat; @@ -733,6 +734,13 @@ nvr_read(uint16_t addr, void *priv) ret = REGD_VRT; break; + case 0x11: + if (local->flags & FLAG_MARTIN_HACK) + ret = nvr->regs[local->addr[addr_id]] | 0x02; + else + ret = nvr->regs[local->addr[addr_id]]; + break; + case 0x2c: if (!nvr->is_new && (local->flags & FLAG_AMI_1994_HACK)) ret = nvr->regs[local->addr[addr_id]] & 0x7f; @@ -771,6 +779,17 @@ nvr_read(uint16_t addr, void *priv) ret = checksum >> 8; else ret = checksum & 0xff; + } else if (!nvr->is_new && (local->flags & FLAG_MARTIN_HACK)) { + for (i = 0x10; i <= 0x2d; i++) { + if (i == 0x11) + checksum += (nvr->regs[i] | 0x02); + 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; @@ -1088,9 +1107,10 @@ nvr_at_init(const device_t *info) case 1: /* standard AT */ case 5: /* AMI WinBIOS 1994 */ case 6: /* AMI BIOS 1995 */ - if ((info->local & 0x1f) == 0x11) + if ((info->local & 0x1f) == 0x11) { local->flags |= FLAG_PIIX4; - else { + local->def = 0x00; + } else { local->def = 0x00; if ((info->local & 0x1f) == 0x15) local->flags |= FLAG_AMI_1994_HACK; @@ -1123,9 +1143,11 @@ nvr_at_init(const device_t *info) if (info->local & 0x10) { local->def = 0x00; local->flags |= FLAG_AMI_1992_HACK; - } else if (info->local == 36) + } else if ((info->local == 36) || (info->local == 68)) { local->def = 0x00; - else + if (info->local == 68) + local->flags |= FLAG_MARTIN_HACK; + } else local->def = 0xff; nvr->irq = 8; local->cent = RTC_CENTURY_AT; @@ -1160,6 +1182,9 @@ nvr_at_init(const device_t *info) /* Initialize the generic NVR. */ nvr_init(nvr); + if (nvr->is_new && (local->flags & FLAG_MARTIN_HACK)) + nvr->regs[0x11] = nvr->regs[0x2f] = 0x02; + if (nvr_at_inited == 0) { /* Start the timers. */ timer_add(&local->update_timer, timer_update, nvr, 0); @@ -1219,12 +1244,12 @@ nvr_at_close(void *priv) const device_t at_nvr_old_device = { .name = "PC/AT NVRAM (No century)", .internal_name = "at_nvr_old", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0, .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1233,12 +1258,12 @@ const device_t at_nvr_old_device = { const device_t at_nvr_device = { .name = "PC/AT NVRAM", .internal_name = "at_nvr", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 1, .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1247,12 +1272,12 @@ const device_t at_nvr_device = { const device_t at_mb_nvr_device = { .name = "PC/AT NVRAM", .internal_name = "at_nvr", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0x40 | 0x20 | 1, .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1261,12 +1286,12 @@ const device_t at_mb_nvr_device = { const device_t ps_nvr_device = { .name = "PS/1 or PS/2 NVRAM", .internal_name = "ps_nvr", - .flags = DEVICE_PS2, + .flags = DEVICE_ISA16, .local = 2, .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1275,12 +1300,12 @@ const device_t ps_nvr_device = { const device_t amstrad_nvr_device = { .name = "Amstrad NVRAM", .internal_name = "amstrad_nvr", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 3, .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1289,12 +1314,12 @@ const device_t amstrad_nvr_device = { const device_t ibmat_nvr_device = { .name = "IBM AT NVRAM", .internal_name = "ibmat_nvr", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 4, .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1303,12 +1328,12 @@ const device_t ibmat_nvr_device = { const device_t piix4_nvr_device = { .name = "Intel PIIX4 PC/AT NVRAM", .internal_name = "piix4_nvr", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0x10 | 1, .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1317,12 +1342,12 @@ const device_t piix4_nvr_device = { const device_t ps_no_nmi_nvr_device = { .name = "PS/1 or PS/2 NVRAM (No NMI)", .internal_name = "ps1_nvr", - .flags = DEVICE_PS2, + .flags = DEVICE_ISA16, .local = 0x10 | 2, .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1331,12 +1356,12 @@ const device_t ps_no_nmi_nvr_device = { const device_t amstrad_no_nmi_nvr_device = { .name = "Amstrad NVRAM (No NMI)", .internal_name = "amstrad_nvr", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0x10 | 3, .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1345,12 +1370,12 @@ const device_t amstrad_no_nmi_nvr_device = { const device_t ami_1992_nvr_device = { .name = "AMI Color 1992 PC/AT NVRAM", .internal_name = "ami_1992_nvr", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0x10 | 4, .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1359,12 +1384,12 @@ const device_t ami_1992_nvr_device = { const device_t ami_1994_nvr_device = { .name = "AMI WinBIOS 1994 PC/AT NVRAM", .internal_name = "ami_1994_nvr", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0x10 | 5, .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1373,12 +1398,12 @@ const device_t ami_1994_nvr_device = { const device_t ami_1995_nvr_device = { .name = "AMI WinBIOS 1995 PC/AT NVRAM", .internal_name = "ami_1995_nvr", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0x10 | 6, .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1387,12 +1412,12 @@ const device_t ami_1995_nvr_device = { const device_t via_nvr_device = { .name = "VIA PC/AT NVRAM", .internal_name = "via_nvr", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0x10 | 7, .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1401,12 +1426,12 @@ const device_t via_nvr_device = { const device_t p6rp4_nvr_device = { .name = "ASUS P/I-P6RP4 PC/AT NVRAM", .internal_name = "p6rp4_nvr", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 32, .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, .speed_changed = nvr_at_speed_changed, .force_redraw = NULL, .config = NULL @@ -1415,12 +1440,26 @@ const device_t p6rp4_nvr_device = { const device_t amstrad_megapc_nvr_device = { .name = "Amstrad MegaPC NVRAM", .internal_name = "amstrad_megapc_nvr", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 36, .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .available = NULL, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t martin_nvr_device = { + .name = "Zeos Martin NVRAM", + .internal_name = "martin_nvr", + .flags = DEVICE_ISA16, + .local = 68, + .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 @@ -1434,7 +1473,7 @@ const device_t elt_nvr_device = { .init = nvr_at_init, .close = nvr_at_close, .reset = nvr_at_reset, - { .available = NULL }, + .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 67eaccc38..febf6c165 100644 --- a/src/nvr_ps2.c +++ b/src/nvr_ps2.c @@ -114,8 +114,7 @@ ps2_nvr_init(const device_t *info) FILE *fp = NULL; int c; - nvr = (ps2_nvr_t *) malloc(sizeof(ps2_nvr_t)); - memset(nvr, 0x00, sizeof(ps2_nvr_t)); + nvr = (ps2_nvr_t *) calloc(1, sizeof(ps2_nvr_t)); if (info->local) nvr->size = 2048; @@ -123,9 +122,9 @@ ps2_nvr_init(const device_t *info) nvr->size = 8192; /* Set up the NVR file's name. */ - c = strlen(machine_get_internal_name()) + 9; + c = strlen(machine_get_nvr_name()) + 9; nvr->fn = (char *) malloc(c + 1); - sprintf(nvr->fn, "%s_sec.nvr", machine_get_internal_name()); + sprintf(nvr->fn, "%s_sec.nvr", machine_get_nvr_name()); io_sethandler(0x0074, 3, ps2_nvr_read, NULL, NULL, ps2_nvr_write, NULL, NULL, nvr); @@ -170,7 +169,7 @@ const device_t ps2_nvr_device = { .init = ps2_nvr_init, .close = ps2_nvr_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -184,7 +183,7 @@ const device_t ps2_nvr_55ls_device = { .init = ps2_nvr_init, .close = ps2_nvr_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/pci.c b/src/pci.c index ab585c456..94ab9d5f2 100644 --- a/src/pci.c +++ b/src/pci.c @@ -419,6 +419,9 @@ pci_trc_reset(uint8_t val) mem_a20_recalc(); flushmmucache(); + + if (is_p6) + mem_zero(); } #ifdef USE_DYNAREC @@ -852,10 +855,10 @@ pci_register_card(int pci_card) /* Add an instance of the PCI bridge. */ void -pci_add_bridge(uint8_t agp, uint8_t (*read)(int func, int addr, void *priv), void (*write)(int func, int addr, uint8_t val, void *priv), void *priv, uint8_t *slot) +pci_add_bridge(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, uint8_t *slot) { pci_card_t *card; - uint8_t bridge_slot = agp ? pci_find_slot(PCI_ADD_AGPBRIDGE, 0xff) : last_normal_pci_card_id; + uint8_t bridge_slot = (add_type == PCI_ADD_NORMAL) ? last_normal_pci_card_id : pci_find_slot(add_type, 0xff); if (bridge_slot != PCI_CARD_INVALID) { card = &pci_cards[bridge_slot]; diff --git a/src/pci_dummy.c b/src/pci_dummy.c index 704f85d8c..bceb58c22 100644 --- a/src/pci_dummy.c +++ b/src/pci_dummy.c @@ -278,7 +278,7 @@ pci_dummy_card_init(UNUSED(const device_t *info)) { pci_dummy_t *dev = (pci_dummy_t *) calloc(1, sizeof(pci_dummy_t)); - pci_add_card(PCI_ADD_NORMAL, pci_dummy_pci_read, pci_dummy_pci_write, dev, &dev->pci_slot); + pci_add_card(PCI_ADD_NORMAL, pci_dummy_pci_read, pci_dummy_pci_write, dev, &dev->pci_slot); return dev; } @@ -291,7 +291,7 @@ const device_t pci_dummy_device = { .init = pci_dummy_card_init, .close = pci_dummy_close, .reset = pci_dummy_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/pic.c b/src/pic.c index 82905261a..4b8993322 100644 --- a/src/pic.c +++ b/src/pic.c @@ -17,6 +17,7 @@ * Copyright 2015-2020 Andrew Jenner. * Copyright 2016-2020 Miran Grca. */ +#include #include #include #include @@ -244,7 +245,7 @@ pic_update_pending_at(void) } static void -pic_callback(void *priv) +pic_callback(UNUSED(void *priv)) { update_pending(); } @@ -496,7 +497,7 @@ pic_read(uint16_t addr, void *priv) simply read whatever is currently on the data bus. */ } - pic_log("pic_read(%04X, %08X) = %02X\n", addr, priv, dev->data_bus); + pic_log("pic_read(%04X) = %02X\n", addr, dev->data_bus); return dev->data_bus; } @@ -628,7 +629,7 @@ pic_reset_hard(void) /* 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)) { + if (machine_has_flags(machine, MACHINE_PS2_KBC)) { pic_kbd_latch(0x01); pic_mouse_latch(0x01); } else { @@ -637,6 +638,25 @@ pic_reset_hard(void) } } +void +pic_toggle_latch(int is_ps2) +{ + pic_kbd_latch(0x00); + pic_mouse_latch(0x00); + + /* 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 (is_ps2) { + pic_kbd_latch(0x01); + pic_mouse_latch(0x01); + } +} + void pic_init(void) { diff --git a/src/pit.c b/src/pit.c index 8b9f23a79..a283d1205 100644 --- a/src/pit.c +++ b/src/pit.c @@ -960,7 +960,7 @@ const device_t i8253_device = { .init = pit_init, .close = pit_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = pit_speed_changed, .force_redraw = NULL, .config = NULL @@ -974,7 +974,7 @@ const device_t i8253_ext_io_device = { .init = pit_init, .close = pit_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -988,7 +988,7 @@ const device_t i8254_device = { .init = pit_init, .close = pit_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = pit_speed_changed, .force_redraw = NULL, .config = NULL @@ -1002,7 +1002,7 @@ const device_t i8254_sec_device = { .init = pit_init, .close = pit_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = pit_speed_changed, .force_redraw = NULL, .config = NULL @@ -1016,7 +1016,7 @@ const device_t i8254_ext_io_device = { .init = pit_init, .close = pit_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1030,7 +1030,7 @@ const device_t i8254_ps2_device = { .init = pit_init, .close = pit_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = pit_speed_changed, .force_redraw = NULL, .config = NULL @@ -1250,14 +1250,14 @@ pit_set_clock(uint32_t clock) } const pit_intf_t pit_classic_intf = { - &pit_read, - &pit_write, - &pit_ctr_get_count, - &pit_ctr_set_gate, - &pit_ctr_set_using_timer, - &pit_ctr_set_out_func, - &pit_ctr_set_load_func, - &ctr_clock, - &pit_set_pit_const, - NULL, + .read = &pit_read, + .write = &pit_write, + .get_count = &pit_ctr_get_count, + .set_gate = &pit_ctr_set_gate, + .set_using_timer = &pit_ctr_set_using_timer, + .set_out_func = &pit_ctr_set_out_func, + .set_load_func = &pit_ctr_set_load_func, + .ctr_clock = &ctr_clock, + .set_pit_const = &pit_set_pit_const, + .data = NULL, }; diff --git a/src/pit_fast.c b/src/pit_fast.c index 0d56a6616..b92b59f3c 100644 --- a/src/pit_fast.c +++ b/src/pit_fast.c @@ -751,7 +751,7 @@ const device_t i8253_fast_device = { .init = pitf_init, .close = pitf_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = pitf_speed_changed, .force_redraw = NULL, .config = NULL @@ -765,7 +765,7 @@ const device_t i8254_fast_device = { .init = pitf_init, .close = pitf_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = pitf_speed_changed, .force_redraw = NULL, .config = NULL @@ -779,7 +779,7 @@ const device_t i8254_sec_fast_device = { .init = pitf_init, .close = pitf_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = pitf_speed_changed, .force_redraw = NULL, .config = NULL @@ -793,7 +793,7 @@ const device_t i8254_ext_io_fast_device = { .init = pitf_init, .close = pitf_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -807,21 +807,21 @@ const device_t i8254_ps2_fast_device = { .init = pitf_init, .close = pitf_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = pitf_speed_changed, .force_redraw = NULL, .config = NULL }; const pit_intf_t pit_fast_intf = { - &pitf_read, - &pitf_write, - &pitf_ctr_get_count, - &pitf_ctr_set_gate, - &pitf_ctr_set_using_timer, - &pitf_ctr_set_out_func, - &pitf_ctr_set_load_func, - &pitf_ctr_clock, - &pitf_set_pit_const, - NULL, + .read = &pitf_read, + .write = &pitf_write, + .get_count = &pitf_ctr_get_count, + .set_gate = &pitf_ctr_set_gate, + .set_using_timer = &pitf_ctr_set_using_timer, + .set_out_func = &pitf_ctr_set_out_func, + .set_load_func = &pitf_ctr_set_load_func, + .ctr_clock = &pitf_ctr_clock, + .set_pit_const = &pitf_set_pit_const, + .data = NULL, }; diff --git a/src/port_6x.c b/src/port_6x.c index 971b92d28..b8183d651 100644 --- a/src/port_6x.c +++ b/src/port_6x.c @@ -212,7 +212,7 @@ const device_t port_6x_device = { .init = port_6x_init, .close = port_6x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -226,7 +226,7 @@ const device_t port_6x_xi8088_device = { .init = port_6x_init, .close = port_6x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -240,7 +240,7 @@ const device_t port_6x_ps2_device = { .init = port_6x_init, .close = port_6x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -254,7 +254,7 @@ const device_t port_6x_olivetti_device = { .init = port_6x_init, .close = port_6x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/port_92.c b/src/port_92.c index 18e60326c..d1a53a321 100644 --- a/src/port_92.c +++ b/src/port_92.c @@ -235,7 +235,7 @@ const device_t port_92_device = { .init = port_92_init, .close = port_92_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -249,7 +249,7 @@ const device_t port_92_key_device = { .init = port_92_init, .close = port_92_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -263,7 +263,7 @@ const device_t port_92_inv_device = { .init = port_92_init, .close = port_92_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -277,7 +277,7 @@ const device_t port_92_word_device = { .init = port_92_init, .close = port_92_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -291,7 +291,7 @@ const device_t port_92_pci_device = { .init = port_92_init, .close = port_92_close, .reset = port_92_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/printer/prt_escp.c b/src/printer/prt_escp.c index 0b40bec90..41c81e696 100644 --- a/src/printer/prt_escp.c +++ b/src/printer/prt_escp.c @@ -1881,6 +1881,39 @@ write_data(uint8_t val, void *priv) dev->data = val; } +static void +autofeed(uint8_t val, void *priv) +{ + escp_t *dev = (escp_t *) priv; + + if (dev == NULL) + return; + + dev->autofeed = ((val & 0x02) > 0); +} + +static void +strobe(uint8_t old, uint8_t val, void *priv) +{ + escp_t *dev = (escp_t *) priv; + + if (dev == NULL) + return; + + /* Data is strobed to the parallel printer on the falling edge of the + strobe bit. */ + if (!(val & 0x01) && (old & 0x01)) { + /* Process incoming character. */ + handle_char(dev, dev->data); + + /* ACK it, will be read on next READ STATUS. */ + dev->ack = 1; + timer_set_delay_u64(&dev->pulse_timer, ISACONST); + + timer_set_delay_u64(&dev->timeout_timer, 5000000 * TIMER_USEC); + } +} + static void write_ctrl(uint8_t val, void *priv) { @@ -1919,14 +1952,6 @@ write_ctrl(uint8_t val, void *priv) dev->autofeed = ((val & 0x02) > 0); } -static uint8_t -read_data(void *priv) -{ - const escp_t *dev = (escp_t *) priv; - - return dev->data; -} - static uint8_t read_ctrl(void *priv) { @@ -1952,7 +1977,7 @@ read_status(void *priv) static void * escp_init(void *lpt) { - escp_t *dev; + escp_t *dev = NULL; /* Initialize FreeType. */ if (ft_lib == NULL) { @@ -1964,21 +1989,20 @@ escp_init(void *lpt) } /* Initialize a device instance. */ - dev = (escp_t *) malloc(sizeof(escp_t)); - memset(dev, 0x00, sizeof(escp_t)); + dev = (escp_t *) calloc(1, sizeof(escp_t)); dev->ctrl = 0x04; dev->lpt = lpt; + rom_get_full_path(dev->fontpath, "roms/printer/fonts/"); + /* Create a full pathname for the font files. */ - if (strlen(exe_path) >= sizeof(dev->fontpath)) { + if (strlen(dev->fontpath) == 0) { + ui_msgbox_header(MBX_ERROR, plat_get_string(STRING_ESCP_ERROR_TITLE), + plat_get_string(STRING_ESCP_ERROR_DESC)); free(dev); return (NULL); } - strcpy(dev->fontpath, exe_path); - path_slash(dev->fontpath); - strcat(dev->fontpath, "roms/printer/fonts/"); - /* Create the full path for the page images. */ path_append_filename(dev->pagepath, usr_path, "printer"); if (!plat_dir_check(dev->pagepath)) @@ -2054,17 +2078,21 @@ escp_close(void *priv) free(dev->page); } + FT_Done_Face(dev->fontface); free(dev); } const lpt_device_t lpt_prt_escp_device = { - .name = "Generic ESC/P Dot-Matrix Printer", - .internal_name = "dot_matrix", - .init = escp_init, - .close = escp_close, - .write_data = write_data, - .write_ctrl = write_ctrl, - .read_data = read_data, - .read_status = read_status, - .read_ctrl = read_ctrl + .name = "Generic ESC/P Dot-Matrix", + .internal_name = "dot_matrix", + .init = escp_init, + .close = escp_close, + .write_data = write_data, + .write_ctrl = write_ctrl, + .autofeed = autofeed, + .strobe = strobe, + .read_status = read_status, + .read_ctrl = read_ctrl, + .epp_write_data = NULL, + .epp_request_read = NULL }; diff --git a/src/printer/prt_ps.c b/src/printer/prt_ps.c index dcd018881..904ff34ad 100644 --- a/src/printer/prt_ps.c +++ b/src/printer/prt_ps.c @@ -26,8 +26,8 @@ #include #include #include <86box/86box.h> -#include <86box/lpt.h> #include <86box/timer.h> +#include <86box/lpt.h> #include <86box/pit.h> #include <86box/path.h> #include <86box/plat.h> @@ -319,6 +319,35 @@ process_data(ps_t *dev) dev->buffer[dev->buffer_pos] = 0; } +static void +ps_autofeed(uint8_t val, void *priv) +{ + ps_t *dev = (ps_t *) priv; + + if (dev == NULL) + return; + + dev->autofeed = val & 0x02 ? true : false; +} + +static void +ps_strobe(uint8_t old, uint8_t val, void *priv) +{ + ps_t *dev = (ps_t *) priv; + + if (dev == NULL) + return; + + if (!(val & 0x01) && (old & 0x01)) { + process_data(dev); + + dev->ack = true; + + timer_set_delay_u64(&dev->pulse_timer, ISACONST); + timer_set_delay_u64(&dev->timeout_timer, 5000000 * TIMER_USEC); + } +} + static void ps_write_ctrl(uint8_t val, void *priv) { @@ -366,13 +395,12 @@ ps_read_status(void *priv) static void * ps_init(void *lpt) { - ps_t *dev; + ps_t *dev = (ps_t *) calloc(1, sizeof(ps_t)); gsapi_revision_t rev; - dev = (ps_t *) malloc(sizeof(ps_t)); - memset(dev, 0x00, sizeof(ps_t)); dev->ctrl = 0x04; dev->lpt = lpt; + dev->pcl = false; /* Try loading the DLL. */ ghostscript_handle = dynld_module(PATH_GHOSTSCRIPT_DLL, ghostscript_imports); @@ -415,11 +443,9 @@ ps_init(void *lpt) static void * pcl_init(void *lpt) { - ps_t *dev; + ps_t *dev = (ps_t *) calloc(1, sizeof(ps_t)); gsapi_revision_t rev; - dev = (ps_t *) malloc(sizeof(ps_t)); - memset(dev, 0x00, sizeof(ps_t)); dev->ctrl = 0x04; dev->lpt = lpt; dev->pcl = true; @@ -482,27 +508,33 @@ ps_close(void *priv) } const lpt_device_t lpt_prt_ps_device = { - .name = "Generic PostScript Printer", - .internal_name = "postscript", - .init = ps_init, - .close = ps_close, - .write_data = ps_write_data, - .write_ctrl = ps_write_ctrl, - .read_data = NULL, - .read_status = ps_read_status, - .read_ctrl = NULL + .name = "Generic PostScript Printer", + .internal_name = "postscript", + .init = ps_init, + .close = ps_close, + .write_data = ps_write_data, + .write_ctrl = ps_write_ctrl, + .autofeed = ps_autofeed, + .strobe = ps_strobe, + .read_status = ps_read_status, + .read_ctrl = NULL, + .epp_write_data = NULL, + .epp_request_read = NULL }; #ifdef USE_PCL const lpt_device_t lpt_prt_pcl_device = { - .name = "Generic PCL5e Printer", - .internal_name = "pcl", - .init = pcl_init, - .close = ps_close, - .write_data = ps_write_data, - .write_ctrl = ps_write_ctrl, - .read_data = NULL, - .read_status = ps_read_status, - .read_ctrl = NULL + .name = "Generic PCL5e Printer", + .internal_name = "pcl", + .init = pcl_init, + .close = ps_close, + .write_data = ps_write_data, + .write_ctrl = ps_write_ctrl, + .autofeed = ps_autofeed, + .strobe = ps_strobe, + .read_status = ps_read_status, + .read_ctrl = NULL, + .epp_write_data = NULL, + .epp_request_read = NULL }; #endif diff --git a/src/printer/prt_text.c b/src/printer/prt_text.c index ddf9faf53..7604d023e 100644 --- a/src/printer/prt_text.c +++ b/src/printer/prt_text.c @@ -367,6 +367,38 @@ write_data(uint8_t val, void *priv) dev->data = val; } +static void +autofeed(uint8_t val, void *priv) +{ + prnt_t *dev = (prnt_t *) priv; + + if (dev == NULL) + return; + + /* set autofeed value */ + dev->autofeed = val & 0x02 ? 1 : 0; +} + +static void +strobe(uint8_t old, uint8_t val, void *priv) +{ + prnt_t *dev = (prnt_t *) priv; + + if (dev == NULL) + return; + + if (!(val & 0x01) && (old & 0x01)) { /* STROBE */ + /* Process incoming character. */ + handle_char(dev); + + /* ACK it, will be read on next READ STATUS. */ + dev->ack = 1; + + timer_set_delay_u64(&dev->pulse_timer, ISACONST); + timer_set_delay_u64(&dev->timeout_timer, 5000000 * TIMER_USEC); + } +} + static void write_ctrl(uint8_t val, void *priv) { @@ -421,11 +453,9 @@ read_status(void *priv) static void * prnt_init(void *lpt) { - prnt_t *dev; - /* Initialize a device instance. */ - dev = (prnt_t *) malloc(sizeof(prnt_t)); - memset(dev, 0x00, sizeof(prnt_t)); + prnt_t *dev = (prnt_t *) calloc(1, sizeof(prnt_t)); + dev->ctrl = 0x04; dev->lpt = lpt; @@ -467,13 +497,16 @@ prnt_close(void *priv) } const lpt_device_t lpt_prt_text_device = { - .name = "Generic Text Printer", - .internal_name = "text_prt", - .init = prnt_init, - .close = prnt_close, - .write_data = write_data, - .write_ctrl = write_ctrl, - .read_data = NULL, - .read_status = read_status, - .read_ctrl = NULL + .name = "Generic Text Printer", + .internal_name = "text_prt", + .init = prnt_init, + .close = prnt_close, + .write_data = write_data, + .write_ctrl = write_ctrl, + .autofeed = autofeed, + .strobe = strobe, + .read_status = read_status, + .read_ctrl = NULL, + .epp_write_data = NULL, + .epp_request_read = NULL }; diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt index d7ea91f70..bed9d27c0 100644 --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -89,11 +89,7 @@ add_library(ui STATIC qt_hardwarerenderer.hpp qt_openglrenderer.cpp qt_openglrenderer.hpp - qt_opengloptions.cpp - qt_opengloptions.hpp - qt_opengloptionsdialog.cpp - qt_opengloptionsdialog.hpp - qt_opengloptionsdialog.ui + qt_glsl_parser.cpp qt_settings.cpp qt_settings.hpp @@ -141,6 +137,11 @@ add_library(ui STATIC qt_joystickconfiguration.cpp qt_joystickconfiguration.hpp qt_joystickconfiguration.ui + qt_keybind.cpp + qt_keybind.hpp + qt_keybind.ui + qt_singlekeyseqedit.cpp + qt_singlekeyseqedit.hpp qt_filefield.cpp qt_filefield.hpp @@ -188,7 +189,62 @@ add_library(ui STATIC qt_mediahistorymanager.cpp qt_mediahistorymanager.hpp + qt_updatecheck.cpp + qt_updatecheck.hpp + qt_updatecheckdialog.cpp + qt_updatecheckdialog.hpp + qt_updatecheckdialog.ui + qt_updatedetails.cpp + qt_updatedetails.hpp + qt_updatedetails.ui + qt_downloader.cpp + qt_downloader.hpp + + qt_vmmanager_clientsocket.cpp + qt_vmmanager_clientsocket.hpp + qt_vmmanager_serversocket.cpp + qt_vmmanager_serversocket.hpp + qt_vmmanager_protocol.cpp + qt_vmmanager_protocol.hpp + qt_vmmanager_details.hpp + qt_vmmanager_details.cpp + qt_vmmanager_details.ui + qt_vmmanager_addmachine.cpp + qt_vmmanager_addmachine.hpp + qt_vmmanager_detailsection.cpp + qt_vmmanager_detailsection.hpp + qt_vmmanager_detailsection.ui + qt_vmmanager_listviewdelegate.hpp + qt_vmmanager_listviewdelegate.cpp + qt_vmmanager_preferences.cpp + qt_vmmanager_preferences.hpp + qt_vmmanager_preferences.ui + qt_vmmanager_main.hpp + qt_vmmanager_main.cpp + qt_vmmanager_main.ui + qt_vmmanager_model.cpp + qt_vmmanager_model.hpp + qt_vmmanager_system.cpp + qt_vmmanager_system.hpp + qt_vmmanager_config.cpp + qt_vmmanager_config.hpp + qt_vmmanager_mainwindow.cpp + qt_vmmanager_mainwindow.hpp + qt_vmmanager_mainwindow.ui + ../qt_resources.qrc + ./qdarkstyle/dark/darkstyle.qrc + + qt_openglshadermanagerdialog.hpp + qt_openglshadermanagerdialog.cpp + qt_openglshadermanagerdialog.ui + + qt_openglshaderconfig.hpp + qt_openglshaderconfig.cpp + qt_openglshaderconfig.ui + + qt_iconindicators.hpp + qt_iconindicators.cpp ) if(RTMIDI) @@ -199,10 +255,15 @@ if(WACOM) target_compile_definitions(ui PRIVATE USE_WACOM) endif() +if(CDROM_MITSUMI) + target_compile_definitions(ui PRIVATE USE_CDROM_MITSUMI) +endif() + if(WIN32) enable_language(RC) target_sources(86Box PUBLIC 86Box-qt.rc) target_sources(plat PRIVATE win_dynld.c) + target_link_libraries(86Box dwmapi) # CMake 3.22 messed this up for clang/clang++ # See https://gitlab.kitware.com/cmake/cmake/-/issues/22611 @@ -435,6 +496,7 @@ if (UNIX AND NOT APPLE AND NOT HAIKU) set(WL_SOURCE_VAR) ecm_add_wayland_client_protocol(WL_SOURCE_VAR PROTOCOL ${CMAKE_SOURCE_DIR}/wl_protocols/relative-pointer-unstable-v1.xml BASENAME relative-pointer-unstable-v1) ecm_add_wayland_client_protocol(WL_SOURCE_VAR PROTOCOL ${CMAKE_SOURCE_DIR}/wl_protocols/pointer-constraints-unstable-v1.xml BASENAME pointer-constraints-unstable-v1) + ecm_add_wayland_client_protocol(WL_SOURCE_VAR PROTOCOL ${CMAKE_SOURCE_DIR}/wl_protocols/keyboard-shortcuts-inhibit-unstable-v1.xml BASENAME keyboard-shortcuts-inhibit-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) diff --git a/src/qt/assets/86box-wizard.png b/src/qt/assets/86box-wizard.png new file mode 100644 index 000000000..19ecda8c7 Binary files /dev/null and b/src/qt/assets/86box-wizard.png differ diff --git a/src/qt/assets/systemicons/cpq_deskpro.png b/src/qt/assets/systemicons/cpq_deskpro.png new file mode 100644 index 000000000..1bbca68a3 Binary files /dev/null and b/src/qt/assets/systemicons/cpq_deskpro.png differ diff --git a/src/qt/assets/systemicons/cpq_port_386.png b/src/qt/assets/systemicons/cpq_port_386.png new file mode 100644 index 000000000..4c55b3559 Binary files /dev/null and b/src/qt/assets/systemicons/cpq_port_386.png differ diff --git a/src/qt/assets/systemicons/cpq_port_II.png b/src/qt/assets/systemicons/cpq_port_II.png new file mode 100644 index 000000000..3254d9b5e Binary files /dev/null and b/src/qt/assets/systemicons/cpq_port_II.png differ diff --git a/src/qt/assets/systemicons/cpq_port_III.png b/src/qt/assets/systemicons/cpq_port_III.png new file mode 100644 index 000000000..65d2f714e Binary files /dev/null and b/src/qt/assets/systemicons/cpq_port_III.png differ diff --git a/src/qt/assets/systemicons/cpq_portable.png b/src/qt/assets/systemicons/cpq_portable.png new file mode 100644 index 000000000..d3dc381e4 Binary files /dev/null and b/src/qt/assets/systemicons/cpq_portable.png differ diff --git a/src/qt/assets/systemicons/cpq_pres_2240.png b/src/qt/assets/systemicons/cpq_pres_2240.png new file mode 100644 index 000000000..c50043cdd Binary files /dev/null and b/src/qt/assets/systemicons/cpq_pres_2240.png differ diff --git a/src/qt/assets/systemicons/cpq_pres_4500.png b/src/qt/assets/systemicons/cpq_pres_4500.png new file mode 100644 index 000000000..edd955b5a Binary files /dev/null and b/src/qt/assets/systemicons/cpq_pres_4500.png differ diff --git a/src/qt/assets/systemicons/ibm330.png b/src/qt/assets/systemicons/ibm330.png new file mode 100644 index 000000000..90637dc4c Binary files /dev/null and b/src/qt/assets/systemicons/ibm330.png differ diff --git a/src/qt/assets/systemicons/ibm_at.png b/src/qt/assets/systemicons/ibm_at.png new file mode 100644 index 000000000..e6710180e Binary files /dev/null and b/src/qt/assets/systemicons/ibm_at.png differ diff --git a/src/qt/assets/systemicons/ibm_pc_81.png b/src/qt/assets/systemicons/ibm_pc_81.png new file mode 100644 index 000000000..4f398d468 Binary files /dev/null and b/src/qt/assets/systemicons/ibm_pc_81.png differ diff --git a/src/qt/assets/systemicons/ibm_pc_82.png b/src/qt/assets/systemicons/ibm_pc_82.png new file mode 100644 index 000000000..4f398d468 Binary files /dev/null and b/src/qt/assets/systemicons/ibm_pc_82.png differ diff --git a/src/qt/assets/systemicons/ibm_pcjr.png b/src/qt/assets/systemicons/ibm_pcjr.png new file mode 100644 index 000000000..1f3014bb4 Binary files /dev/null and b/src/qt/assets/systemicons/ibm_pcjr.png differ diff --git a/src/qt/assets/systemicons/ibm_ps2_m70.png b/src/qt/assets/systemicons/ibm_ps2_m70.png new file mode 100644 index 000000000..af433ebb3 Binary files /dev/null and b/src/qt/assets/systemicons/ibm_ps2_m70.png differ diff --git a/src/qt/assets/systemicons/ibm_ps2_m80.png b/src/qt/assets/systemicons/ibm_ps2_m80.png new file mode 100644 index 000000000..9df02adff Binary files /dev/null and b/src/qt/assets/systemicons/ibm_ps2_m80.png differ diff --git a/src/qt/assets/systemicons/ibm_psvp_486.png b/src/qt/assets/systemicons/ibm_psvp_486.png new file mode 100644 index 000000000..af5a95675 Binary files /dev/null and b/src/qt/assets/systemicons/ibm_psvp_486.png differ diff --git a/src/qt/assets/systemicons/ibm_psvp_p60.png b/src/qt/assets/systemicons/ibm_psvp_p60.png new file mode 100644 index 000000000..af5a95675 Binary files /dev/null and b/src/qt/assets/systemicons/ibm_psvp_p60.png differ diff --git a/src/qt/assets/systemicons/ibm_xt_82.png b/src/qt/assets/systemicons/ibm_xt_82.png new file mode 100644 index 000000000..4f398d468 Binary files /dev/null and b/src/qt/assets/systemicons/ibm_xt_82.png differ diff --git a/src/qt/assets/systemicons/ibm_xt_86.png b/src/qt/assets/systemicons/ibm_xt_86.png new file mode 100644 index 000000000..4f398d468 Binary files /dev/null and b/src/qt/assets/systemicons/ibm_xt_86.png differ diff --git a/src/qt/assets/systemicons/olivetti_m19.png b/src/qt/assets/systemicons/olivetti_m19.png new file mode 100644 index 000000000..766e335f7 Binary files /dev/null and b/src/qt/assets/systemicons/olivetti_m19.png differ diff --git a/src/qt/assets/systemicons/olivetti_m21.png b/src/qt/assets/systemicons/olivetti_m21.png new file mode 100644 index 000000000..5e0ee4b52 Binary files /dev/null and b/src/qt/assets/systemicons/olivetti_m21.png differ diff --git a/src/qt/assets/systemicons/olivetti_m24.png b/src/qt/assets/systemicons/olivetti_m24.png new file mode 100644 index 000000000..e48356c32 Binary files /dev/null and b/src/qt/assets/systemicons/olivetti_m24.png differ diff --git a/src/qt/assets/systemicons/olivetti_m24sp.png b/src/qt/assets/systemicons/olivetti_m24sp.png new file mode 100644 index 000000000..e48356c32 Binary files /dev/null and b/src/qt/assets/systemicons/olivetti_m24sp.png differ diff --git a/src/qt/assets/systemicons/os_archlinux_x2.png b/src/qt/assets/systemicons/os_archlinux_x2.png new file mode 100644 index 000000000..1b218a76f Binary files /dev/null and b/src/qt/assets/systemicons/os_archlinux_x2.png differ diff --git a/src/qt/assets/systemicons/os_cloud_x2.png b/src/qt/assets/systemicons/os_cloud_x2.png new file mode 100644 index 000000000..9bd42f9ac Binary files /dev/null and b/src/qt/assets/systemicons/os_cloud_x2.png differ diff --git a/src/qt/assets/systemicons/os_debian_x2.png b/src/qt/assets/systemicons/os_debian_x2.png new file mode 100644 index 000000000..a6644c33d Binary files /dev/null and b/src/qt/assets/systemicons/os_debian_x2.png differ diff --git a/src/qt/assets/systemicons/os_dos_x2.png b/src/qt/assets/systemicons/os_dos_x2.png new file mode 100644 index 000000000..b6df56ef5 Binary files /dev/null and b/src/qt/assets/systemicons/os_dos_x2.png differ diff --git a/src/qt/assets/systemicons/os_fedora_x2.png b/src/qt/assets/systemicons/os_fedora_x2.png new file mode 100644 index 000000000..120d247a8 Binary files /dev/null and b/src/qt/assets/systemicons/os_fedora_x2.png differ diff --git a/src/qt/assets/systemicons/os_freebsd_x2.png b/src/qt/assets/systemicons/os_freebsd_x2.png new file mode 100644 index 000000000..dd6f88d41 Binary files /dev/null and b/src/qt/assets/systemicons/os_freebsd_x2.png differ diff --git a/src/qt/assets/systemicons/os_gentoo_x2.png b/src/qt/assets/systemicons/os_gentoo_x2.png new file mode 100644 index 000000000..f27afa5fc Binary files /dev/null and b/src/qt/assets/systemicons/os_gentoo_x2.png differ diff --git a/src/qt/assets/systemicons/os_jrockitve_x2.png b/src/qt/assets/systemicons/os_jrockitve_x2.png new file mode 100644 index 000000000..4283cad5e Binary files /dev/null and b/src/qt/assets/systemicons/os_jrockitve_x2.png differ diff --git a/src/qt/assets/systemicons/os_l4_x2.png b/src/qt/assets/systemicons/os_l4_x2.png new file mode 100644 index 000000000..9fbbaa183 Binary files /dev/null and b/src/qt/assets/systemicons/os_l4_x2.png differ diff --git a/src/qt/assets/systemicons/os_linux22_x2.png b/src/qt/assets/systemicons/os_linux22_x2.png new file mode 100644 index 000000000..0de56653a Binary files /dev/null and b/src/qt/assets/systemicons/os_linux22_x2.png differ diff --git a/src/qt/assets/systemicons/os_linux24_x2.png b/src/qt/assets/systemicons/os_linux24_x2.png new file mode 100644 index 000000000..b3df83b7f Binary files /dev/null and b/src/qt/assets/systemicons/os_linux24_x2.png differ diff --git a/src/qt/assets/systemicons/os_linux26_x2.png b/src/qt/assets/systemicons/os_linux26_x2.png new file mode 100644 index 000000000..8fdf52df7 Binary files /dev/null and b/src/qt/assets/systemicons/os_linux26_x2.png differ diff --git a/src/qt/assets/systemicons/os_linux_x2.png b/src/qt/assets/systemicons/os_linux_x2.png new file mode 100644 index 000000000..d4c2eeebe Binary files /dev/null and b/src/qt/assets/systemicons/os_linux_x2.png differ diff --git a/src/qt/assets/systemicons/os_macosx_x2.png b/src/qt/assets/systemicons/os_macosx_x2.png new file mode 100644 index 000000000..38eb2e5a7 Binary files /dev/null and b/src/qt/assets/systemicons/os_macosx_x2.png differ diff --git a/src/qt/assets/systemicons/os_mandriva_x2.png b/src/qt/assets/systemicons/os_mandriva_x2.png new file mode 100644 index 000000000..a09e9c170 Binary files /dev/null and b/src/qt/assets/systemicons/os_mandriva_x2.png differ diff --git a/src/qt/assets/systemicons/os_netbsd_x2.png b/src/qt/assets/systemicons/os_netbsd_x2.png new file mode 100644 index 000000000..9fa38a7a6 Binary files /dev/null and b/src/qt/assets/systemicons/os_netbsd_x2.png differ diff --git a/src/qt/assets/systemicons/os_netware_x2.png b/src/qt/assets/systemicons/os_netware_x2.png new file mode 100644 index 000000000..4bcc96521 Binary files /dev/null and b/src/qt/assets/systemicons/os_netware_x2.png differ diff --git a/src/qt/assets/systemicons/os_openbsd_x2.png b/src/qt/assets/systemicons/os_openbsd_x2.png new file mode 100644 index 000000000..13ae3a0db Binary files /dev/null and b/src/qt/assets/systemicons/os_openbsd_x2.png differ diff --git a/src/qt/assets/systemicons/os_opensuse_x2.png b/src/qt/assets/systemicons/os_opensuse_x2.png new file mode 100644 index 000000000..4d1696d9b Binary files /dev/null and b/src/qt/assets/systemicons/os_opensuse_x2.png differ diff --git a/src/qt/assets/systemicons/os_oracle_x2.png b/src/qt/assets/systemicons/os_oracle_x2.png new file mode 100644 index 000000000..545e885cb Binary files /dev/null and b/src/qt/assets/systemicons/os_oracle_x2.png differ diff --git a/src/qt/assets/systemicons/os_oraclesolaris_x2.png b/src/qt/assets/systemicons/os_oraclesolaris_x2.png new file mode 100644 index 000000000..8db66abe3 Binary files /dev/null and b/src/qt/assets/systemicons/os_oraclesolaris_x2.png differ diff --git a/src/qt/assets/systemicons/os_os2_other_x2.png b/src/qt/assets/systemicons/os_os2_other_x2.png new file mode 100644 index 000000000..2d37846a0 Binary files /dev/null and b/src/qt/assets/systemicons/os_os2_other_x2.png differ diff --git a/src/qt/assets/systemicons/os_os2ecs_x2.png b/src/qt/assets/systemicons/os_os2ecs_x2.png new file mode 100644 index 000000000..261f9f56c Binary files /dev/null and b/src/qt/assets/systemicons/os_os2ecs_x2.png differ diff --git a/src/qt/assets/systemicons/os_os2warp3_x2.png b/src/qt/assets/systemicons/os_os2warp3_x2.png new file mode 100644 index 000000000..1be5a696c Binary files /dev/null and b/src/qt/assets/systemicons/os_os2warp3_x2.png differ diff --git a/src/qt/assets/systemicons/os_os2warp45_x2.png b/src/qt/assets/systemicons/os_os2warp45_x2.png new file mode 100644 index 000000000..d1a4df0c2 Binary files /dev/null and b/src/qt/assets/systemicons/os_os2warp45_x2.png differ diff --git a/src/qt/assets/systemicons/os_os2warp4_x2.png b/src/qt/assets/systemicons/os_os2warp4_x2.png new file mode 100644 index 000000000..0a81c8759 Binary files /dev/null and b/src/qt/assets/systemicons/os_os2warp4_x2.png differ diff --git a/src/qt/assets/systemicons/os_other_x2.png b/src/qt/assets/systemicons/os_other_x2.png new file mode 100644 index 000000000..9602353c0 Binary files /dev/null and b/src/qt/assets/systemicons/os_other_x2.png differ diff --git a/src/qt/assets/systemicons/os_qnx_x2.png b/src/qt/assets/systemicons/os_qnx_x2.png new file mode 100644 index 000000000..b124cfa6e Binary files /dev/null and b/src/qt/assets/systemicons/os_qnx_x2.png differ diff --git a/src/qt/assets/systemicons/os_redhat_x2.png b/src/qt/assets/systemicons/os_redhat_x2.png new file mode 100644 index 000000000..a756e8aac Binary files /dev/null and b/src/qt/assets/systemicons/os_redhat_x2.png differ diff --git a/src/qt/assets/systemicons/os_solaris_x2.png b/src/qt/assets/systemicons/os_solaris_x2.png new file mode 100644 index 000000000..2dfd2ac74 Binary files /dev/null and b/src/qt/assets/systemicons/os_solaris_x2.png differ diff --git a/src/qt/assets/systemicons/os_turbolinux_x2.png b/src/qt/assets/systemicons/os_turbolinux_x2.png new file mode 100644 index 000000000..4d5ee4ab1 Binary files /dev/null and b/src/qt/assets/systemicons/os_turbolinux_x2.png differ diff --git a/src/qt/assets/systemicons/os_ubuntu_x2.png b/src/qt/assets/systemicons/os_ubuntu_x2.png new file mode 100644 index 000000000..9b6302b37 Binary files /dev/null and b/src/qt/assets/systemicons/os_ubuntu_x2.png differ diff --git a/src/qt/assets/systemicons/os_win10_x2.png b/src/qt/assets/systemicons/os_win10_x2.png new file mode 100644 index 000000000..1d6e81392 Binary files /dev/null and b/src/qt/assets/systemicons/os_win10_x2.png differ diff --git a/src/qt/assets/systemicons/os_win2k3_x2.png b/src/qt/assets/systemicons/os_win2k3_x2.png new file mode 100644 index 000000000..45bec005d Binary files /dev/null and b/src/qt/assets/systemicons/os_win2k3_x2.png differ diff --git a/src/qt/assets/systemicons/os_win2k8_x2.png b/src/qt/assets/systemicons/os_win2k8_x2.png new file mode 100644 index 000000000..d97a2789d Binary files /dev/null and b/src/qt/assets/systemicons/os_win2k8_x2.png differ diff --git a/src/qt/assets/systemicons/os_win2k_x2.png b/src/qt/assets/systemicons/os_win2k_x2.png new file mode 100644 index 000000000..a773288ed Binary files /dev/null and b/src/qt/assets/systemicons/os_win2k_x2.png differ diff --git a/src/qt/assets/systemicons/os_win31_x2.png b/src/qt/assets/systemicons/os_win31_x2.png new file mode 100644 index 000000000..5ca2005d6 Binary files /dev/null and b/src/qt/assets/systemicons/os_win31_x2.png differ diff --git a/src/qt/assets/systemicons/os_win7_x2.png b/src/qt/assets/systemicons/os_win7_x2.png new file mode 100644 index 000000000..c8ce57a2b Binary files /dev/null and b/src/qt/assets/systemicons/os_win7_x2.png differ diff --git a/src/qt/assets/systemicons/os_win81_x2.png b/src/qt/assets/systemicons/os_win81_x2.png new file mode 100644 index 000000000..07131ed6c Binary files /dev/null and b/src/qt/assets/systemicons/os_win81_x2.png differ diff --git a/src/qt/assets/systemicons/os_win8_x2.png b/src/qt/assets/systemicons/os_win8_x2.png new file mode 100644 index 000000000..ff94c2dd1 Binary files /dev/null and b/src/qt/assets/systemicons/os_win8_x2.png differ diff --git a/src/qt/assets/systemicons/os_win95_x2.png b/src/qt/assets/systemicons/os_win95_x2.png new file mode 100644 index 000000000..efd62799e Binary files /dev/null and b/src/qt/assets/systemicons/os_win95_x2.png differ diff --git a/src/qt/assets/systemicons/os_win98_x2.png b/src/qt/assets/systemicons/os_win98_x2.png new file mode 100644 index 000000000..c8fa4e7bb Binary files /dev/null and b/src/qt/assets/systemicons/os_win98_x2.png differ diff --git a/src/qt/assets/systemicons/os_win_other_x2.png b/src/qt/assets/systemicons/os_win_other_x2.png new file mode 100644 index 000000000..fac95889f Binary files /dev/null and b/src/qt/assets/systemicons/os_win_other_x2.png differ diff --git a/src/qt/assets/systemicons/os_winme_x2.png b/src/qt/assets/systemicons/os_winme_x2.png new file mode 100644 index 000000000..1c268c84b Binary files /dev/null and b/src/qt/assets/systemicons/os_winme_x2.png differ diff --git a/src/qt/assets/systemicons/os_winnt4_x2.png b/src/qt/assets/systemicons/os_winnt4_x2.png new file mode 100644 index 000000000..c3352abcd Binary files /dev/null and b/src/qt/assets/systemicons/os_winnt4_x2.png differ diff --git a/src/qt/assets/systemicons/os_winvista_x2.png b/src/qt/assets/systemicons/os_winvista_x2.png new file mode 100644 index 000000000..7b633b79f Binary files /dev/null and b/src/qt/assets/systemicons/os_winvista_x2.png differ diff --git a/src/qt/assets/systemicons/os_winxp_x2.png b/src/qt/assets/systemicons/os_winxp_x2.png new file mode 100644 index 000000000..b97e6b51d Binary files /dev/null and b/src/qt/assets/systemicons/os_winxp_x2.png differ diff --git a/src/qt/assets/systemicons/os_xandros_x2.png b/src/qt/assets/systemicons/os_xandros_x2.png new file mode 100644 index 000000000..23de5ca91 Binary files /dev/null and b/src/qt/assets/systemicons/os_xandros_x2.png differ diff --git a/src/qt/assets/systemicons/pb_bora_pro.png b/src/qt/assets/systemicons/pb_bora_pro.png new file mode 100644 index 000000000..6aaaf9d26 Binary files /dev/null and b/src/qt/assets/systemicons/pb_bora_pro.png differ diff --git a/src/qt/assets/systemicons/pb_pb410.png b/src/qt/assets/systemicons/pb_pb410.png new file mode 100644 index 000000000..c78c0496b Binary files /dev/null and b/src/qt/assets/systemicons/pb_pb410.png differ diff --git a/src/qt/assets/systemicons/pb_pb640.png b/src/qt/assets/systemicons/pb_pb640.png new file mode 100644 index 000000000..d0be550f1 Binary files /dev/null and b/src/qt/assets/systemicons/pb_pb640.png differ diff --git a/src/qt/assets/systemicons/pb_pb680.png b/src/qt/assets/systemicons/pb_pb680.png new file mode 100644 index 000000000..a697d5dd0 Binary files /dev/null and b/src/qt/assets/systemicons/pb_pb680.png differ diff --git a/src/qt/assets/systemicons/tandy_1000.png b/src/qt/assets/systemicons/tandy_1000.png new file mode 100644 index 000000000..b50f2c1e6 Binary files /dev/null and b/src/qt/assets/systemicons/tandy_1000.png differ diff --git a/src/qt/assets/systemicons/tandy_1000_hx.png b/src/qt/assets/systemicons/tandy_1000_hx.png new file mode 100644 index 000000000..b770a6b7c Binary files /dev/null and b/src/qt/assets/systemicons/tandy_1000_hx.png differ diff --git a/src/qt/assets/systemicons/tandy_1000_sl2.png b/src/qt/assets/systemicons/tandy_1000_sl2.png new file mode 100644 index 000000000..b7feae92a Binary files /dev/null and b/src/qt/assets/systemicons/tandy_1000_sl2.png differ diff --git a/src/qt/assets/systemicons/toshiba_t1000.png b/src/qt/assets/systemicons/toshiba_t1000.png new file mode 100644 index 000000000..a2dbfc382 Binary files /dev/null and b/src/qt/assets/systemicons/toshiba_t1000.png differ diff --git a/src/qt/assets/systemicons/toshiba_t1200.png b/src/qt/assets/systemicons/toshiba_t1200.png new file mode 100644 index 000000000..8c3cf0c37 Binary files /dev/null and b/src/qt/assets/systemicons/toshiba_t1200.png differ diff --git a/src/qt/assets/systemicons/toshiba_t1200_hdd.png b/src/qt/assets/systemicons/toshiba_t1200_hdd.png new file mode 100644 index 000000000..8c3cf0c37 Binary files /dev/null and b/src/qt/assets/systemicons/toshiba_t1200_hdd.png differ diff --git a/src/qt/dummy_cdrom_ioctl.c b/src/qt/dummy_cdrom_ioctl.c index 4ed0333a7..bddfabb5b 100644 --- a/src/qt/dummy_cdrom_ioctl.c +++ b/src/qt/dummy_cdrom_ioctl.c @@ -17,236 +17,226 @@ * Copyright 2023 Miran Grca. */ #include +#ifdef ENABLE_IOCTL_LOG #include +#endif #include #include #include #include #include #define HAVE_STDARG_H -#include <86box/86box.h> #include <86box/scsi_device.h> #include <86box/cdrom.h> +#include <86box/log.h> #include <86box/plat_unused.h> -#include <86box/plat_cdrom.h> +#include <86box/plat_cdrom_ioctl.h> /* 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. */ #define MSFtoLBA(m, s, f) ((((m * 60) + s) * 75) + f) -typedef struct dummy_cdrom_ioctl_t { - int toc_valid; -} dummy_cdrom_ioctl_t; +typedef struct ioctl_t { + cdrom_t *dev; + void *log; + void *handle; + char path[256]; +} ioctl_t; -#ifdef ENABLE_DUMMY_CDROM_IOCTL_LOG -int dummy_cdrom_ioctl_do_log = ENABLE_DUMMY_CDROM_IOCTL_LOG; +#ifdef ENABLE_IOCTL_LOG +int ioctl_do_log = ENABLE_IOCTL_LOG; void -dummy_cdrom_ioctl_log(const char *fmt, ...) +ioctl_log(void *priv, const char *fmt, ...) { - va_list ap; - - if (dummy_cdrom_ioctl_do_log) { + if (ioctl_do_log) { + va_list ap; va_start(ap, fmt); - pclog_ex(fmt, ap); + log_out(priv, fmt, ap); va_end(ap); } } #else -# define dummy_cdrom_ioctl_log(fmt, ...) +# define ioctl_log(priv, fmt, ...) #endif -static int -plat_cdrom_open(void *local) +/* Internal functions. */ +static void +ioctl_close_handle(UNUSED(const ioctl_t *ioctl)) { - return 0; } static int -plat_cdrom_load(void *local) +ioctl_open_handle(UNUSED(ioctl_t *ioctl)) { return 0; } static void -plat_cdrom_read_toc(void *local) +ioctl_read_toc(ioctl_t *ioctl) { - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - - if (!ioctl->toc_valid) - ioctl->toc_valid = 1; } -void -plat_cdrom_get_raw_track_info(UNUSED(void *local), int *num, raw_track_info_t *rti) +/* Shared functions. */ +static int +ioctl_get_track_info(UNUSED(const void *local), UNUSED(const uint32_t track), + UNUSED(int end), UNUSED(track_info_t *ti)) +{ + return 0; +} + +static void +ioctl_get_raw_track_info(UNUSED(const void *local), int *num, uint8_t *rti) { *num = 1; memset(rti, 0x00, 11); } -int -plat_cdrom_is_track_audio(void *local, uint32_t sector) +static int +ioctl_is_track_pre(const void *local, UNUSED(const uint32_t sector)) { - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; + ioctl_t *ioctl = (ioctl_t *) local; - plat_cdrom_read_toc(ioctl); - - const int ret = 0; - - dummy_cdrom_ioctl_log("plat_cdrom_is_track_audio(%08X): %i\n", sector, ret); - - return ret; -} - -int -plat_cdrom_is_track_pre(void *local, uint32_t sector) -{ - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - - plat_cdrom_read_toc(ioctl); + ioctl_read_toc(ioctl); const int ret = 0; - dummy_cdrom_ioctl_log("plat_cdrom_is_track_audio(%08X): %i\n", sector, ret); + ioctl_log("ioctl_is_track_audio(%08X): %i\n", sector, ret); return ret; } -uint32_t -plat_cdrom_get_track_start(void *local, uint32_t sector, uint8_t *attr, uint8_t *track) +static int +ioctl_read_sector(const void *local, UNUSED(uint8_t *buffer), UNUSED(uint32_t const sector)) { - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; + ioctl_t *ioctl = (ioctl_t *) local; - plat_cdrom_read_toc(ioctl); + ioctl_open_handle(ioctl); - return 0x00000000; -} + ioctl_close_handle(ioctl); -uint32_t -plat_cdrom_get_last_block(void *local) -{ - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - - plat_cdrom_read_toc(ioctl); - - return 0x00000000; -} - -int -plat_cdrom_ext_medium_changed(void *local) -{ - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - int ret = 0; - - dummy_cdrom_ioctl_log("plat_cdrom_ext_medium_changed(): %i\n", ret); - - return ret; -} - -/* This replaces both Info and EndInfo, they are specified by a variable. */ -int -plat_cdrom_get_audio_track_info(void *local, UNUSED(int end), int track, int *track_num, TMSF *start, uint8_t *attr) -{ - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - - plat_cdrom_read_toc(ioctl); - - if ((track < 1) || (track == 0xaa)) { - dummy_cdrom_ioctl_log("plat_cdrom_get_audio_track_info(%02i)\n", track); - return 0; - } - - start->min = 0; - start->sec = 0; - start->fr = 2; - - *track_num = 1; - *attr = 0x14; - - dummy_cdrom_ioctl_log("plat_cdrom_get_audio_track_info(%02i): %02i:%02i:%02i, %02i, %02X\n", - track, start->min, start->sec, start->fr, *track_num, *attr); - - return 1; -} - -/* TODO: See if track start is adjusted by 150 or not. */ -int -plat_cdrom_get_audio_sub(UNUSED(void *local), UNUSED(uint32_t sector), uint8_t *attr, uint8_t *track, uint8_t *index, - TMSF *rel_pos, TMSF *abs_pos) -{ - *track = 1; - *attr = 0x14; - *index = 1; - - rel_pos->min = 0; - rel_pos->sec = 0; - rel_pos->fr = 0; - abs_pos->min = 0; - abs_pos->sec = 0; - abs_pos->fr = 2; - - dummy_cdrom_ioctl_log("plat_cdrom_get_audio_sub(): %02i, %02X, %02i, %02i:%02i:%02i, %02i:%02i:%02i\n", - *track, *attr, *index, rel_pos->min, rel_pos->sec, rel_pos->fr, abs_pos->min, abs_pos->sec, abs_pos->fr); - - return 1; -} - -int -plat_cdrom_get_sector_size(UNUSED(void *local), UNUSED(uint32_t sector)) -{ - dummy_cdrom_ioctl_log("BytesPerSector=2048\n"); - - return 2048; -} - -int -plat_cdrom_read_sector(void *local, uint8_t *buffer, uint32_t sector) -{ - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - - plat_cdrom_open(ioctl); - - /* Raw */ - dummy_cdrom_ioctl_log("Raw\n"); - - plat_cdrom_close(ioctl); - - dummy_cdrom_ioctl_log("ReadSector sector=%d.\n", sector); + ioctl_log("ReadSector sector=%d.\n", sector); return 0; } -void -plat_cdrom_eject(void *local) +static uint8_t +ioctl_get_track_type(UNUSED(const void *local), UNUSED(const uint32_t sector)) { - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - - plat_cdrom_open(ioctl); - plat_cdrom_close(ioctl); + return 0x00; } -void -plat_cdrom_close(UNUSED(void *local)) +static uint32_t +ioctl_get_last_block(const void *local) { + ioctl_t *ioctl = (ioctl_t *) local; + + ioctl_read_toc(ioctl); + + return 0x00000000; } -int -plat_cdrom_set_drive(void *local, const char *drv) +static int +ioctl_read_dvd_structure(UNUSED(const void *local), UNUSED(const uint8_t layer), UNUSED(const uint8_t format), + UNUSED(uint8_t *buffer), UNUSED(uint32_t *info)) { - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; + return -0x00052100; +} - plat_cdrom_close(ioctl); +static int +ioctl_is_dvd(UNUSED(const void *local)) +{ + return 0; +} - ioctl->toc_valid = 0; - - plat_cdrom_load(ioctl); +static int +ioctl_has_audio(UNUSED(const void *local)) +{ + return 0; +} +static int +ioctl_is_empty(const void *local) +{ return 1; } -int -plat_cdrom_get_local_size(void) +static int +ioctl_ext_medium_changed(UNUSED(void *local)) { - return sizeof(dummy_cdrom_ioctl_t); +#if 0 + ioctl_t *ioctl = (ioctl_t *) local; +#endif + int ret = 0; + + ioctl_log("ioctl_ext_medium_changed(): %i\n", ret); + + return ret; +} + +static void +ioctl_close(void *local) +{ + ioctl_t *ioctl = (ioctl_t *) local; + + ioctl_close_handle(ioctl); + ioctl->handle = NULL; + + ioctl_log(ioctl->log, "Log closed\n"); + + log_close(ioctl->log); + ioctl->log = NULL; +} + +static void +ioctl_load(const void *local) +{ + const ioctl_t *ioctl = (const ioctl_t *) local; + + if (ioctl_open_handle((ioctl_t *) ioctl)) { + ioctl_close_handle((ioctl_t *) ioctl); + + ioctl_read_toc((ioctl_t *) ioctl); + } +} + +static const cdrom_ops_t ioctl_ops = { + ioctl_get_track_info, + ioctl_get_raw_track_info, + ioctl_is_track_pre, + ioctl_read_sector, + ioctl_get_track_type, + ioctl_get_last_block, + ioctl_read_dvd_structure, + ioctl_is_dvd, + ioctl_has_audio, + ioctl_is_empty, + ioctl_close, + ioctl_load +}; + +/* Public functions. */ +void * +ioctl_open(cdrom_t *dev, const char *drv) +{ + ioctl_t *ioctl = (ioctl_t *) calloc(1, sizeof(ioctl_t)); + + if (ioctl != NULL) { + char n[1024] = { 0 }; + + sprintf(n, "CD-ROM %i IOCtl", dev->id + 1); + ioctl->log = log_open(n); + + memset(ioctl->path, 0x00, sizeof(ioctl->path)); + + sprintf(ioctl->path, "%s", drv); + ioctl_log(ioctl->log, "Path is %s\n", ioctl->path); + + ioctl->dev = dev; + + dev->ops = &ioctl_ops; + } + + return ioctl; } diff --git a/src/qt/icons/active.ico b/src/qt/icons/active.ico new file mode 100644 index 000000000..9569a3962 Binary files /dev/null and b/src/qt/icons/active.ico differ diff --git a/src/qt/icons/caps_lock_off.ico b/src/qt/icons/caps_lock_off.ico new file mode 100644 index 000000000..6895c735c Binary files /dev/null and b/src/qt/icons/caps_lock_off.ico differ diff --git a/src/qt/icons/caps_lock_on.ico b/src/qt/icons/caps_lock_on.ico new file mode 100644 index 000000000..2cfd48aad Binary files /dev/null and b/src/qt/icons/caps_lock_on.ico differ diff --git a/src/qt/icons/cartridge_empty.ico b/src/qt/icons/cartridge_empty.ico deleted file mode 100644 index 9ff90846e..000000000 Binary files a/src/qt/icons/cartridge_empty.ico and /dev/null differ diff --git a/src/qt/icons/cassette_active.ico b/src/qt/icons/cassette_active.ico deleted file mode 100644 index 32fca20b4..000000000 Binary files a/src/qt/icons/cassette_active.ico and /dev/null differ diff --git a/src/qt/icons/cassette_empty.ico b/src/qt/icons/cassette_empty.ico deleted file mode 100644 index 16c6e8457..000000000 Binary files a/src/qt/icons/cassette_empty.ico and /dev/null differ diff --git a/src/qt/icons/cassette_empty_active.ico b/src/qt/icons/cassette_empty_active.ico deleted file mode 100644 index e1bf61f61..000000000 Binary files a/src/qt/icons/cassette_empty_active.ico and /dev/null differ diff --git a/src/qt/icons/cdrom_active.ico b/src/qt/icons/cdrom_active.ico deleted file mode 100644 index 6f2ef197c..000000000 Binary files a/src/qt/icons/cdrom_active.ico and /dev/null differ diff --git a/src/qt/icons/cdrom_empty.ico b/src/qt/icons/cdrom_empty.ico deleted file mode 100644 index 45580999c..000000000 Binary files a/src/qt/icons/cdrom_empty.ico and /dev/null differ diff --git a/src/qt/icons/cdrom_empty_active.ico b/src/qt/icons/cdrom_empty_active.ico deleted file mode 100644 index a48371bd7..000000000 Binary files a/src/qt/icons/cdrom_empty_active.ico and /dev/null differ diff --git a/src/qt/icons/disabled.ico b/src/qt/icons/disabled.ico new file mode 100644 index 000000000..e2114db54 Binary files /dev/null and b/src/qt/icons/disabled.ico differ diff --git a/src/qt/icons/floppy_35_active.ico b/src/qt/icons/floppy_35_active.ico deleted file mode 100644 index 9600a3af0..000000000 Binary files a/src/qt/icons/floppy_35_active.ico and /dev/null differ diff --git a/src/qt/icons/floppy_35_empty.ico b/src/qt/icons/floppy_35_empty.ico deleted file mode 100644 index ac47b4c55..000000000 Binary files a/src/qt/icons/floppy_35_empty.ico and /dev/null differ diff --git a/src/qt/icons/floppy_35_empty_active.ico b/src/qt/icons/floppy_35_empty_active.ico deleted file mode 100644 index 4f0c928d6..000000000 Binary files a/src/qt/icons/floppy_35_empty_active.ico and /dev/null differ diff --git a/src/qt/icons/floppy_525_active.ico b/src/qt/icons/floppy_525_active.ico deleted file mode 100644 index e19baa8a2..000000000 Binary files a/src/qt/icons/floppy_525_active.ico and /dev/null differ diff --git a/src/qt/icons/floppy_525_empty.ico b/src/qt/icons/floppy_525_empty.ico deleted file mode 100644 index 8fa6c6b87..000000000 Binary files a/src/qt/icons/floppy_525_empty.ico and /dev/null differ diff --git a/src/qt/icons/floppy_525_empty_active.ico b/src/qt/icons/floppy_525_empty_active.ico deleted file mode 100644 index 703d2a64f..000000000 Binary files a/src/qt/icons/floppy_525_empty_active.ico and /dev/null differ diff --git a/src/qt/icons/green-square-16.png b/src/qt/icons/green-square-16.png new file mode 100644 index 000000000..cb42c38eb Binary files /dev/null and b/src/qt/icons/green-square-16.png differ diff --git a/src/qt/icons/hard_disk_active.ico b/src/qt/icons/hard_disk_active.ico deleted file mode 100644 index 9946a7f2e..000000000 Binary files a/src/qt/icons/hard_disk_active.ico and /dev/null differ diff --git a/src/qt/icons/kana_lock_off.ico b/src/qt/icons/kana_lock_off.ico new file mode 100644 index 000000000..27c9b88c2 Binary files /dev/null and b/src/qt/icons/kana_lock_off.ico differ diff --git a/src/qt/icons/kana_lock_on.ico b/src/qt/icons/kana_lock_on.ico new file mode 100644 index 000000000..ec171b52b Binary files /dev/null and b/src/qt/icons/kana_lock_on.ico differ diff --git a/src/qt/icons/mo_active.ico b/src/qt/icons/mo_active.ico deleted file mode 100644 index 06b788b4d..000000000 Binary files a/src/qt/icons/mo_active.ico and /dev/null differ diff --git a/src/qt/icons/mo_empty.ico b/src/qt/icons/mo_empty.ico deleted file mode 100644 index 30481522a..000000000 Binary files a/src/qt/icons/mo_empty.ico and /dev/null differ diff --git a/src/qt/icons/mo_empty_active.ico b/src/qt/icons/mo_empty_active.ico deleted file mode 100644 index 29c82845b..000000000 Binary files a/src/qt/icons/mo_empty_active.ico and /dev/null differ diff --git a/src/qt/icons/network_active.ico b/src/qt/icons/network_active.ico deleted file mode 100644 index 25caaadfa..000000000 Binary files a/src/qt/icons/network_active.ico and /dev/null differ diff --git a/src/qt/icons/num_lock_off.ico b/src/qt/icons/num_lock_off.ico new file mode 100644 index 000000000..5b14da1d4 Binary files /dev/null and b/src/qt/icons/num_lock_off.ico differ diff --git a/src/qt/icons/num_lock_on.ico b/src/qt/icons/num_lock_on.ico new file mode 100644 index 000000000..0dd08d7ae Binary files /dev/null and b/src/qt/icons/num_lock_on.ico differ diff --git a/src/qt/icons/pause-16.png b/src/qt/icons/pause-16.png new file mode 100644 index 000000000..375780232 Binary files /dev/null and b/src/qt/icons/pause-16.png differ diff --git a/src/qt/icons/play-16.png b/src/qt/icons/play-16.png new file mode 100644 index 000000000..bde40f503 Binary files /dev/null and b/src/qt/icons/play-16.png differ diff --git a/src/qt/icons/red-power-16.png b/src/qt/icons/red-power-16.png new file mode 100644 index 000000000..c90ef491f Binary files /dev/null and b/src/qt/icons/red-power-16.png differ diff --git a/src/qt/icons/red-square-16.png b/src/qt/icons/red-square-16.png new file mode 100644 index 000000000..32faa7cdc Binary files /dev/null and b/src/qt/icons/red-square-16.png differ diff --git a/src/qt/icons/scroll_lock_off.ico b/src/qt/icons/scroll_lock_off.ico new file mode 100644 index 000000000..85cb09ec6 Binary files /dev/null and b/src/qt/icons/scroll_lock_off.ico differ diff --git a/src/qt/icons/scroll_lock_on.ico b/src/qt/icons/scroll_lock_on.ico new file mode 100644 index 000000000..33476406a Binary files /dev/null and b/src/qt/icons/scroll_lock_on.ico differ diff --git a/src/qt/icons/stop-16.png b/src/qt/icons/stop-16.png new file mode 100644 index 000000000..d73cad140 Binary files /dev/null and b/src/qt/icons/stop-16.png differ diff --git a/src/qt/icons/network_empty.ico b/src/qt/icons/write_active.ico similarity index 50% rename from src/qt/icons/network_empty.ico rename to src/qt/icons/write_active.ico index 4a1a10284..babf8c86c 100644 Binary files a/src/qt/icons/network_empty.ico and b/src/qt/icons/write_active.ico differ diff --git a/src/qt/icons/yellow-square-16.png b/src/qt/icons/yellow-square-16.png new file mode 100644 index 000000000..197cf394e Binary files /dev/null and b/src/qt/icons/yellow-square-16.png differ diff --git a/src/qt/icons/zip_active.ico b/src/qt/icons/zip_active.ico deleted file mode 100644 index 40b3a5930..000000000 Binary files a/src/qt/icons/zip_active.ico and /dev/null differ diff --git a/src/qt/icons/zip_empty.ico b/src/qt/icons/zip_empty.ico deleted file mode 100644 index 4123c7cc2..000000000 Binary files a/src/qt/icons/zip_empty.ico and /dev/null differ diff --git a/src/qt/icons/zip_empty_active.ico b/src/qt/icons/zip_empty_active.ico deleted file mode 100644 index d57860b10..000000000 Binary files a/src/qt/icons/zip_empty_active.ico and /dev/null differ diff --git a/src/qt/languages/86box.pot b/src/qt/languages/86box.pot index c427d1300..ac379b171 100644 --- a/src/qt/languages/86box.pot +++ b/src/qt/languages/86box.pot @@ -18,7 +18,7 @@ msgstr "" msgid "&Hard Reset..." msgstr "" -msgid "&Ctrl+Alt+Del\tCtrl+F12" +msgid "&Ctrl+Alt+Del" msgstr "" msgid "Ctrl+Alt+&Esc" @@ -111,7 +111,7 @@ msgstr "" msgid "Hi&DPI scaling" msgstr "" -msgid "&Fullscreen\tCtrl+Alt+PgUp" +msgid "&Fullscreen" msgstr "" msgid "Fullscreen &stretch mode" @@ -186,7 +186,10 @@ msgstr "" msgid "&Update status bar icons" msgstr "" -msgid "Take s&creenshot\tCtrl+F11" +msgid "Take s&creenshot" +msgstr "" + +msgid "S&ound" msgstr "" msgid "&Preferences..." @@ -198,10 +201,10 @@ msgstr "" msgid "Sound &gain..." msgstr "" -msgid "Begin trace\tCtrl+T" +msgid "Begin trace" msgstr "" -msgid "End trace\tCtrl+T" +msgid "End trace" msgstr "" msgid "&Help" @@ -249,7 +252,7 @@ msgstr "" msgid "E&mpty" msgstr "" -msgid "&Reload previous image" +msgid "Reload previous image" msgstr "" msgid "&Folder..." @@ -306,18 +309,12 @@ msgstr "" msgid "Cancel" msgstr "" -msgid "Save these settings as &global defaults" -msgstr "" - msgid "&Default" msgstr "" msgid "Language:" msgstr "" -msgid "Icon set:" -msgstr "" - msgid "Gain" msgstr "" @@ -453,15 +450,6 @@ msgstr "" msgid "YMFM (faster)" msgstr "" -msgid "Network type:" -msgstr "" - -msgid "PCap device:" -msgstr "" - -msgid "Network adapter:" -msgstr "" - msgid "COM1 Device:" msgstr "" @@ -642,13 +630,10 @@ msgstr "" msgid " - PAUSED" msgstr "" -msgid "Press Ctrl+Alt+PgDn to return to windowed mode." -msgstr "" - msgid "Speed" msgstr "" -msgid "ZIP %03i %i (%s): %ls" +msgid "ZIP %1 %2 (%3): %4" msgstr "" msgid "ZIP images" @@ -687,7 +672,10 @@ msgstr "" msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "" -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "" + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." msgstr "" msgid "Machine" @@ -750,13 +738,10 @@ msgstr "" msgid "KB" msgstr "" -msgid "Could not initialize the video renderer." -msgstr "" - msgid "Default" msgstr "" -msgid "%i estat(s) d'espera" +msgid "%1 Wait state(s)" msgstr "" msgid "Type" @@ -801,10 +786,10 @@ msgstr "" msgid "None" msgstr "" -msgid "%u MB (CHS: %i, %i, %i)" +msgid "%1 MB (CHS: %2, %3, %4)" msgstr "" -msgid "Floppy %i (%s): %ls" +msgid "Floppy %1 (%2): %3" msgstr "" msgid "Advanced sector images" @@ -825,7 +810,7 @@ msgstr "" msgid "Unable to initialize GhostPCL" msgstr "" -msgid "MO %i (%ls): %ls" +msgid "MO %1 (%2): %3" msgstr "" msgid "MO images" @@ -876,9 +861,6 @@ msgstr "" msgid "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PCL printer will be saved as Printer Command Language (.pcl) files." msgstr "" -msgid "Entering fullscreen mode" -msgstr "" - msgid "Don't show this message again" msgstr "" @@ -900,10 +882,7 @@ msgstr "" msgid "Monitor in sleep mode" msgstr "" -msgid "OpenGL Shaders" -msgstr "" - -msgid "OpenGL options" +msgid "GLSL shaders" msgstr "" msgid "You are loading an unsupported configuration" @@ -915,24 +894,18 @@ msgstr "" msgid "Continue" msgstr "" -msgid "Cassette: %s" +msgid "Cassette: %1" msgstr "" msgid "Cassette images" msgstr "" -msgid "Cartridge %i: %ls" +msgid "Cartridge %1: %2" msgstr "" msgid "Cartridge images" msgstr "" -msgid "Error initializing renderer" -msgstr "" - -msgid "OpenGL (3.0 Core) renderer could not be initialized. Use another renderer." -msgstr "" - msgid "Resume execution" msgstr "" @@ -1095,7 +1068,7 @@ msgstr "" msgid "ATAPI" msgstr "" -msgid "CD-ROM %i (%s): %s" +msgid "CD-ROM %1 (%2): %3" msgstr "" msgid "160 KB" @@ -1275,9 +1248,6 @@ msgstr "" msgid "Create..." msgstr "" -msgid "previous image" -msgstr "" - msgid "Host CD/DVD Drive (%1)" msgstr "" @@ -1287,22 +1257,7 @@ msgstr "" msgid "Null Driver" msgstr "" -msgid "NIC %02i (%ls) %ls" -msgstr "" - -msgid "Error opening \"%1\": %2" -msgstr "" - -msgid "Error compiling vertex shader in file \"%1\"" -msgstr "" - -msgid "Error compiling fragment shader in file \"%1\"" -msgstr "" - -msgid "Error linking shader program in file \"%1\"" -msgstr "" - -msgid "OpenGL 3.0 renderer options" +msgid "NIC %1 (%2) %3" msgstr "" msgid "Render behavior" @@ -1317,9 +1272,6 @@ msgstr "" msgid "VSync" msgstr "" -msgid "<html><head/><body><p>Render each frame immediately, in sync with the emulated display.</p><p><span style=" font-style:italic;">This is the recommended option if the shaders in use don't utilize frametime for animated effects.</span></p></body></html>" -msgstr "" - msgid "Synchronize with video" msgstr "" @@ -1329,21 +1281,9 @@ msgstr "" msgid "Remove" msgstr "" -msgid "No shader selected" -msgstr "" - msgid "Browse..." msgstr "" -msgid "Shader error" -msgstr "" - -msgid "Could not load shaders." -msgstr "" - -msgid "More information in details." -msgstr "" - msgid "Couldn't create OpenGL context." msgstr "" @@ -1353,19 +1293,13 @@ msgstr "" msgid "OpenGL version 3.0 or greater is required. Current version is %1.%2" msgstr "" -msgid "OpenGL initialization failed. Error %1." -msgstr "" - msgid "Error initializing OpenGL" msgstr "" -msgid "Falling back to software rendering.\n" +msgid "\nFalling back to software rendering." msgstr "" -msgid "Allocating memory for unpack buffer failed.\n" -msgstr "" - -msgid "<html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html>" +msgid "

When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" msgstr "" msgid "This machine might have been moved or copied." @@ -1401,16 +1335,16 @@ msgstr "" msgid "Network Card #4" msgstr "" -msgid "Mode" +msgid "Mode:" msgstr "" -msgid "Interface" +msgid "Interface:" msgstr "" -msgid "Adapter" +msgid "Adapter:" msgstr "" -msgid "VDE Socket" +msgid "VDE Socket:" msgstr "" msgid "86Box Unit Tester" @@ -1431,9 +1365,6 @@ msgstr "" msgid "Serial port passthrough 4" msgstr "" -msgid "Vision Systems LBA Enhancer" -msgstr "" - msgid "Renderer options..." msgstr "" @@ -1872,6 +1803,9 @@ msgstr "" msgid "Five + Wheel" msgstr "" +msgid "Five + 2 Wheels" +msgstr "" + msgid "A3 - SMT2 Serial / SMT3(R)V" msgstr "" @@ -2100,7 +2034,7 @@ msgstr "" msgid "Host Serial Passthrough" msgstr "" -msgid "Eject %s" +msgid "E&ject %1" msgstr "" msgid "&Unmute" @@ -2112,7 +2046,28 @@ msgstr "" msgid "High performance impact" msgstr "" -msgid "RAM Disk (max. speed)" +msgid "[Generic] RAM Disk (max. speed)" +msgstr "" + +msgid "[Generic] 1989 (3500 RPM)" +msgstr "" + +msgid "[Generic] 1992 (3600 RPM)" +msgstr "" + +msgid "[Generic] 1994 (4500 RPM)" +msgstr "" + +msgid "[Generic] 1996 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1997 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1998 (5400 RPM)" +msgstr "" + +msgid "[Generic] 2000 (7200 RPM)" msgstr "" msgid "IBM 8514/A clone (ISA)" @@ -2132,3 +2087,69 @@ msgstr "" msgid "Generic PC/AT Memory Expansion" msgstr "" + +msgid "Unable to find Dot-Matrix fonts" +msgstr "" + +msgid "TrueType fonts in the \"roms/printer/fonts\" directory are required for the emulation of the Generic ESC/P Dot-Matrix Printer." +msgstr "" + +msgid "Inhibit multimedia keys" +msgstr "" + +msgid "Ask for confirmation before saving settings" +msgstr "" + +msgid "Ask for confirmation before hard resetting" +msgstr "" + +msgid "Ask for confirmation before quitting" +msgstr "" + +msgid "Options" +msgstr "" + +msgid "Model" +msgstr "" + +msgid "Model:" +msgstr "" + +msgid "Failed to initialize Vulkan renderer." +msgstr "" + +msgid "GLSL Error" +msgstr "" + +msgid "Could not load shader: %1" +msgstr "" + +msgid "OpenGL version 3.0 or greater is required. Current GLSL version is %1.%2" +msgstr "" + +msgid "Could not load texture: %1" +msgstr "" + +msgid "Could not compile shader:\n\n%1" +msgstr "" + +msgid "Program not linked:\n\n%1" +msgstr "" + +msgid "Shader Manager" +msgstr "" + +msgid "Shader Configuration" +msgstr "" + +msgid "Add" +msgstr "" + +msgid "Move up" +msgstr "" + +msgid "Move down" +msgstr "" + +msgid "Could not load file %1" +msgstr "" diff --git a/src/qt/languages/ca-ES.po b/src/qt/languages/ca-ES.po index cf0556c36..c9fc9bd82 100644 --- a/src/qt/languages/ca-ES.po +++ b/src/qt/languages/ca-ES.po @@ -18,8 +18,8 @@ msgstr "CTRL &dret és ALT esquerre" msgid "&Hard Reset..." msgstr "&Reinicialització completa ..." -msgid "&Ctrl+Alt+Del\tCtrl+F12" -msgstr "&Ctrl+Alt+Del\tCtrl+F12" +msgid "&Ctrl+Alt+Del" +msgstr "&Ctrl+Alt+Del" msgid "Ctrl+Alt+&Esc" msgstr "Ctrl+Alt+&Esc" @@ -111,8 +111,8 @@ msgstr "&Lineal" msgid "Hi&DPI scaling" msgstr "&Escalat alta densitat" -msgid "&Fullscreen\tCtrl+Alt+PgUp" -msgstr "&Pantalla completa\tCtrl+Alt+PgUp" +msgid "&Fullscreen" +msgstr "&Pantalla completa" msgid "Fullscreen &stretch mode" msgstr "Escalat pantalla completa" @@ -186,8 +186,11 @@ msgstr "&Ajustaments ..." msgid "&Update status bar icons" msgstr "&Actualitzar icones a la barra d'estat" -msgid "Take s&creenshot\tCtrl+F11" -msgstr "Prendre c&aptura\tCtrl+F11" +msgid "Take s&creenshot" +msgstr "Prendre c&aptura" + +msgid "S&ound" +msgstr "S&o" msgid "&Preferences..." msgstr "&Preferències ..." @@ -198,11 +201,11 @@ msgstr "Activar la integració amb el &Discord" msgid "Sound &gain..." msgstr "&Guany de so ..." -msgid "Begin trace\tCtrl+T" -msgstr "Començar traça\tCtrl+T" +msgid "Begin trace" +msgstr "Començar traça" -msgid "End trace\tCtrl+T" -msgstr "Acabar traça\tCtrl+T" +msgid "End trace" +msgstr "Acabar traça" msgid "&Help" msgstr "&Ajuda" @@ -249,8 +252,8 @@ msgstr "&Silenciar" msgid "E&mpty" msgstr "E&xtreure disc" -msgid "&Reload previous image" -msgstr "&Recarregar imatge anterior" +msgid "Reload previous image" +msgstr "Recarregar imatge anterior" msgid "&Folder..." msgstr "&Carpeta ..." @@ -306,18 +309,12 @@ msgstr "D'acord" msgid "Cancel" msgstr "Anuŀlació" -msgid "Save these settings as &global defaults" -msgstr "Salvar aquests paràmetres com per &defecte globalment" - msgid "&Default" msgstr "&Per defecte" msgid "Language:" msgstr "Idioma:" -msgid "Icon set:" -msgstr "Conjunt d'icones:" - msgid "Gain" msgstr "Guany" @@ -376,7 +373,7 @@ msgid "Time synchronization" msgstr "Sincronització horària" msgid "Disabled" -msgstr "Desactuvat" +msgstr "Deshabilitat" msgid "Enabled (local time)" msgstr "Activat (hora local)" @@ -453,15 +450,6 @@ msgstr "Nuked (més acurat)" msgid "YMFM (faster)" msgstr "YMFM (més ràpid)" -msgid "Network type:" -msgstr "Tipus de xarxa:" - -msgid "PCap device:" -msgstr "Dispositiu PCap:" - -msgid "Network adapter:" -msgstr "Adaptador de xarxa:" - msgid "COM1 Device:" msgstr "Dispositiu COM1:" @@ -642,14 +630,11 @@ msgstr "Error fatal" msgid " - PAUSED" msgstr " - EN PAUSA" -msgid "Press Ctrl+Alt+PgDn to return to windowed mode." -msgstr "Premeu Ctrl+Alt+PgDn per tornar al mode de finestra." - msgid "Speed" msgstr "Velocitat" -msgid "ZIP %03i %i (%s): %ls" -msgstr "ZIP %03i %i (%s): %ls" +msgid "ZIP %1 %2 (%3): %4" +msgstr "ZIP %1 %2 (%3): %4" msgid "ZIP images" msgstr "Imatges ZIP" @@ -687,8 +672,11 @@ msgstr "La màquina \"%hs\" no està disponible perquè falten ROM al directori msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "La targeta de vídeo \"%hs\" no està disponible perquè falten ROM al directori roms/video. Canvi a una targeta de vídeo disponible." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "La targeta de vídeo 2 \"%hs\" no està disponible perquè falten ROM al directori roms/video. Canvi a una targeta de vídeo disponible." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "La targeta de vídeo 2 \"%hs\" no està disponible perquè falten ROM al directori roms/video. Deshabilitant la segona targeta de vídeo." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "El dispositiu \"%hs\" no està disponible perquè falten ROM. Ignorant el dispositiu." msgid "Machine" msgstr "Màquina" @@ -750,14 +738,11 @@ msgstr "S" msgid "KB" msgstr "KB" -msgid "Could not initialize the video renderer." -msgstr "No has estat possible inicialitzar el renderitzador de vídeo." - msgid "Default" msgstr "Per defecte" -msgid "%i estat(s) d'espera" -msgstr "%i estado(s) de Espera" +msgid "%1 Wait state(s)" +msgstr "%1 estado(s) de Espera" msgid "Type" msgstr "Tipus" @@ -801,11 +786,11 @@ msgstr "Thrustmaster Flight Control System" msgid "None" msgstr "Cap" -msgid "%u MB (CHS: %i, %i, %i)" -msgstr "%u MB (CHS: %i, %i, %i)" +msgid "%1 MB (CHS: %2, %3, %4)" +msgstr "%1 MB (CHS: %2, %3, %4)" -msgid "Floppy %i (%s): %ls" -msgstr "Disquet %i (%s): %ls" +msgid "Floppy %1 (%2): %3" +msgstr "Disquet %1 (%2): %3" msgid "Advanced sector images" msgstr "Imatges avançates del sector" @@ -825,8 +810,8 @@ msgstr "No es pot inicialitzar Ghostscript" msgid "Unable to initialize GhostPCL" msgstr "No es pot inicialitzar GhostPCL" -msgid "MO %i (%ls): %ls" -msgstr "MO %i (%ls): %ls" +msgid "MO %1 (%2): %3" +msgstr "MO %1 (%2): %3" msgid "MO images" msgstr "Imatges MO" @@ -876,9 +861,6 @@ msgstr "%1 és necessària per a la conversió automàtica de fitxers PostScript msgid "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PCL printer will be saved as Printer Command Language (.pcl) files." msgstr "%1 és necessària per a la conversió automàtica de fitxers PCL a PDF.\n\nQualsevol document enviat a la impressora genèrica PCL es desarà com a fitxer Printer Command Language (.pcl)." -msgid "Entering fullscreen mode" -msgstr "Entrant en mode pantalla completa" - msgid "Don't show this message again" msgstr "No mostreu més aquest missatge" @@ -900,11 +882,8 @@ msgstr "Configuració de Dispositiu %1" msgid "Monitor in sleep mode" msgstr "Monitor en mode estalvi" -msgid "OpenGL Shaders" -msgstr "Shaders OpenGL" - -msgid "OpenGL options" -msgstr "Opcions OpenGL" +msgid "GLSL shaders" +msgstr "Shaders GLSL" msgid "You are loading an unsupported configuration" msgstr "S'està carregant una configuració no suportada" @@ -915,24 +894,18 @@ msgstr "El Filtratge de tipus de CPU basat en màquina seleccionada està deshab msgid "Continue" msgstr "Continuar" -msgid "Cassette: %s" -msgstr "Casset: %s" +msgid "Cassette: %1" +msgstr "Casset: %1" msgid "Cassette images" msgstr "Imatges de casset" -msgid "Cartridge %i: %ls" -msgstr "Cartutx %i: %ls" +msgid "Cartridge %1: %2" +msgstr "Cartutx %1: %2" msgid "Cartridge images" msgstr "Imatges de cartutx" -msgid "Error initializing renderer" -msgstr "Error en inicialitzar el renderitzador" - -msgid "OpenGL (3.0 Core) renderer could not be initialized. Use another renderer." -msgstr "No has estat possible inicialitzar el renderitzador OpenGL (3.0 Core). Utilitzar un altre renderitzador." - msgid "Resume execution" msgstr "Reprendre l'execució" @@ -1095,8 +1068,8 @@ msgstr "IDE" msgid "ATAPI" msgstr "ATAPI" -msgid "CD-ROM %i (%s): %s" -msgstr "CD-ROM %i (%s): %s" +msgid "CD-ROM %1 (%2): %3" +msgstr "CD-ROM %1 (%2): %3" msgid "160 KB" msgstr "160 KB" @@ -1275,9 +1248,6 @@ msgstr "Esborrar la història de imatges" msgid "Create..." msgstr "Crear ..." -msgid "previous image" -msgstr "imatge anterior" - msgid "Host CD/DVD Drive (%1)" msgstr "Unitat CD/DVD d'amfitrió (%1)" @@ -1287,23 +1257,8 @@ msgstr "Bus desconegut" msgid "Null Driver" msgstr "Controlador nul" -msgid "NIC %02i (%ls) %ls" -msgstr "NIC %02i (%ls) %ls" - -msgid "Error opening \"%1\": %2" -msgstr "Error d'obertura \"%1\": %2" - -msgid "Error compiling vertex shader in file \"%1\"" -msgstr "Error en recopilar el vertex shader al fitxer \"%1\"" - -msgid "Error compiling fragment shader in file \"%1\"" -msgstr "Error en recopilar el fragment shader al fitxer \"%1\"" - -msgid "Error linking shader program in file \"%1\"" -msgstr "Error en enllaçar el programa de shader al fitxer \"%1\"" - -msgid "OpenGL 3.0 renderer options" -msgstr "Opcions del renderitzador OpenGL 3.0" +msgid "NIC %1 (%2) %3" +msgstr "NIC %1 (%2) %3" msgid "Render behavior" msgstr "Comportament del renderitzador" @@ -1317,9 +1272,6 @@ msgstr " fotogrames/s" msgid "VSync" msgstr "VSync" -msgid "<html><head/><body><p>Render each frame immediately, in sync with the emulated display.</p><p><span style=" font-style:italic;">This is the recommended option if the shaders in use don't utilize frametime for animated effects.</span></p></body></html>" -msgstr "<html><head/><body><p>Feu que cada fotograma sigui immediatament, en sincronització amb la pantalla emulada.</p><p><span style=" font-style:italic;">Aquesta és l’opció recomanada si els shaders en ús no utilitzen FrameTime per a efectes animats.</span></p></body></html>" - msgid "Synchronize with video" msgstr "Sincronitzar amb vídeo" @@ -1329,21 +1281,9 @@ msgstr "Shaders" msgid "Remove" msgstr "Supressió" -msgid "No shader selected" -msgstr "Cap shader seleccionat" - msgid "Browse..." msgstr "Navegació..." -msgid "Shader error" -msgstr "Error del shader" - -msgid "Could not load shaders." -msgstr "No has estat possible carregar els shaders." - -msgid "More information in details." -msgstr "Més informació en els detalls." - msgid "Couldn't create OpenGL context." msgstr "No has estat possible crear un context d'OpenGL." @@ -1353,20 +1293,14 @@ msgstr "No has estat possible canviar al context d'OpenGL." msgid "OpenGL version 3.0 or greater is required. Current version is %1.%2" msgstr "Es requereix la versió 3.0 o superior d'OpenGL. La versió actual és %1.%2" -msgid "OpenGL initialization failed. Error %1." -msgstr "No has estat possible inicialitzar OpenGL. Error %1." - msgid "Error initializing OpenGL" msgstr "Error en inicialitzar OpenGL" -msgid "Falling back to software rendering.\n" -msgstr "Tornant al renderitzador software.\n" +msgid "\nFalling back to software rendering." +msgstr "\nTornant al renderitzador software." -msgid "Allocating memory for unpack buffer failed.\n" -msgstr "No has estat possible assignar la memòria per a un buffer de desempaquetament.\n" - -msgid "<html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html>" -msgstr "<html><head/><body><p>Quan seleccioneu imatges de suports (CD-ROM, disquet, etc.), el diàleg obert s’iniciarà al mateix directori que el fitxer de configuració 86Box. Aquesta configuració només farà una diferència en les macOS.</p></body></html>" +msgid "

When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" +msgstr "

Quan seleccioneu imatges de suports (CD-ROM, disquet, etc.), el diàleg obert s’iniciarà al mateix directori que el fitxer de configuració 86Box. Aquesta configuració només farà una diferència en les macOS.

" msgid "This machine might have been moved or copied." msgstr "Aquesta màquina podria haver estat moguda o copiada." @@ -1401,17 +1335,17 @@ msgstr "Targeta de xarxa 3" msgid "Network Card #4" msgstr "Targeta de xarxa 4" -msgid "Mode" -msgstr "Mode" +msgid "Mode:" +msgstr "Mode:" -msgid "Interface" -msgstr "Interfície" +msgid "Interface:" +msgstr "Interfície:" -msgid "Adapter" -msgstr "Adaptador" +msgid "Adapter:" +msgstr "Adaptador:" -msgid "VDE Socket" -msgstr "Socket de VDE" +msgid "VDE Socket:" +msgstr "Socket de VDE:" msgid "86Box Unit Tester" msgstr "Test de la unitat de 86 Box" @@ -1431,9 +1365,6 @@ msgstr "Pas del port sèrie 3" msgid "Serial port passthrough 4" msgstr "Pas del port sèrie 4" -msgid "Vision Systems LBA Enhancer" -msgstr "Vision Systems LBA Enhancer" - msgid "Renderer options..." msgstr "Opcions del renderitzador ..." @@ -1872,6 +1803,9 @@ msgstr "Roda" msgid "Five + Wheel" msgstr "Cinc + roda" +msgid "Five + 2 Wheels" +msgstr "" + msgid "A3 - SMT2 Serial / SMT3(R)V" msgstr "A3 - SMT2 sèrie / SMT3(R)V" @@ -1900,7 +1834,7 @@ msgid "2 MB" msgstr "2 MB" msgid "8 MB" -msgstr " 8 MB" +msgstr "8 MB" msgid "28 MB" msgstr "28 MB" @@ -2100,8 +2034,8 @@ msgstr "Pipe anomenat (servidor)" msgid "Host Serial Passthrough" msgstr "Pas del port sèrie amfitrió" -msgid "Eject %s" -msgstr "Extreure %s" +msgid "E&ject %1" +msgstr "E&xtreure %1" msgid "&Unmute" msgstr "&Saver" @@ -2112,11 +2046,104 @@ msgstr "FPU Softfloat" msgid "High performance impact" msgstr "Alt impact en el rendiment" -msgid "RAM Disk (max. speed)" -msgstr "Disc RAM (velocitat màxima)" +msgid "[Generic] RAM Disk (max. speed)" +msgstr "[Generic] Disc RAM (velocitat màxima)" + +msgid "[Generic] 1989 (3500 RPM)" +msgstr "" + +msgid "[Generic] 1992 (3600 RPM)" +msgstr "" + +msgid "[Generic] 1994 (4500 RPM)" +msgstr "" + +msgid "[Generic] 1996 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1997 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1998 (5400 RPM)" +msgstr "" + +msgid "[Generic] 2000 (7200 RPM)" +msgstr "" msgid "IBM 8514/A clone (ISA)" msgstr "Clon IBM 8514/A (ISA)" msgid "Vendor" msgstr "Frabricant" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Expansió de memòria genèrica PC/XT" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Expansió de memòria genèrica PC/AT" + +msgid "Unable to find Dot-Matrix fonts" +msgstr "No es pot trobar tipus de lletra de matriu de punts" + +msgid "TrueType fonts in the \"roms/printer/fonts\" directory are required for the emulation of the Generic ESC/P Dot-Matrix Printer." +msgstr "Els tipus de lletra TrueType al directori \"roms/printer/fonts\" són necessaris per a l'emulació de la impressora de matriu de punts ESC/P genèrica." + +msgid "Inhibit multimedia keys" +msgstr "" + +msgid "Ask for confirmation before saving settings" +msgstr "" + +msgid "Ask for confirmation before hard resetting" +msgstr "" + +msgid "Ask for confirmation before quitting" +msgstr "" + +msgid "Options" +msgstr "" + +msgid "Model" +msgstr "" + +msgid "Model:" +msgstr "" + +msgid "Failed to initialize Vulkan renderer." +msgstr "" + +msgid "GLSL Error" +msgstr "" + +msgid "Could not load shader: %1" +msgstr "" + +msgid "OpenGL version 3.0 or greater is required. Current GLSL version is %1.%2" +msgstr "" + +msgid "Could not load texture: %1" +msgstr "" + +msgid "Could not compile shader:\n\n%1" +msgstr "" + +msgid "Program not linked:\n\n%1" +msgstr "" + +msgid "Shader Manager" +msgstr "" + +msgid "Shader Configuration" +msgstr "" + +msgid "Add" +msgstr "" + +msgid "Move up" +msgstr "" + +msgid "Move down" +msgstr "" + +msgid "Could not load file %1" +msgstr "" diff --git a/src/qt/languages/cs-CZ.po b/src/qt/languages/cs-CZ.po index 070c8a0df..cd726832d 100644 --- a/src/qt/languages/cs-CZ.po +++ b/src/qt/languages/cs-CZ.po @@ -18,8 +18,8 @@ msgstr "&Pravý Ctrl je levý Alt" msgid "&Hard Reset..." msgstr "&Resetovat" -msgid "&Ctrl+Alt+Del\tCtrl+F12" -msgstr "&Ctrl+Alt+Del\tCtrl+F12" +msgid "&Ctrl+Alt+Del" +msgstr "&Ctrl+Alt+Del" msgid "Ctrl+Alt+&Esc" msgstr "Ctrl+Alt+&Esc" @@ -111,8 +111,8 @@ msgstr "&Lineární" msgid "Hi&DPI scaling" msgstr "Š&kálování HiDPI" -msgid "&Fullscreen\tCtrl+Alt+PgUp" -msgstr "&Celá obrazovka\tCtrl+Alt+PgUp" +msgid "&Fullscreen" +msgstr "&Celá obrazovka" msgid "Fullscreen &stretch mode" msgstr "Režím roztá&hnutí při celé obrazovce" @@ -186,8 +186,11 @@ msgstr "&Nastavení..." msgid "&Update status bar icons" msgstr "&Aktualizovat ikony stavového řádku" -msgid "Take s&creenshot\tCtrl+F11" -msgstr "Pořídit &screenshot\tCtrl+F11" +msgid "Take s&creenshot" +msgstr "Pořídit &screenshot" + +msgid "S&ound" +msgstr "&Zvuk" msgid "&Preferences..." msgstr "&Předvolby..." @@ -198,11 +201,11 @@ msgstr "Povolit integraci s &Discordem" msgid "Sound &gain..." msgstr "&Zesílení zvuku" -msgid "Begin trace\tCtrl+T" -msgstr "Začít trace\tCtrl+T" +msgid "Begin trace" +msgstr "Začít trace" -msgid "End trace\tCtrl+T" -msgstr "Zastavit trace\tCtrl+T" +msgid "End trace" +msgstr "Zastavit trace" msgid "&Help" msgstr "Ná&pověda" @@ -249,8 +252,8 @@ msgstr "&Ztišit" msgid "E&mpty" msgstr "&Vyjmout" -msgid "&Reload previous image" -msgstr "&Načíst znova předchozí obraz" +msgid "Reload previous image" +msgstr "Načíst znova předchozí obraz" msgid "&Folder..." msgstr "&Složka..." @@ -306,18 +309,12 @@ msgstr "OK" msgid "Cancel" msgstr "Storno" -msgid "Save these settings as &global defaults" -msgstr "Uložit toto nastavení jako &globální výchozí stav" - msgid "&Default" msgstr "&Výchozí" msgid "Language:" msgstr "Jazyk:" -msgid "Icon set:" -msgstr "Sada ikon:" - msgid "Gain" msgstr "Zesílení" @@ -453,15 +450,6 @@ msgstr "Nuked (přesnější)" msgid "YMFM (faster)" msgstr "YMFM (rychlejší)" -msgid "Network type:" -msgstr "Druh sítě:" - -msgid "PCap device:" -msgstr "PCap zařízení:" - -msgid "Network adapter:" -msgstr "Síťový adaptér:" - msgid "COM1 Device:" msgstr "Zařízení na COM1:" @@ -642,14 +630,11 @@ msgstr "Kritická chyba" msgid " - PAUSED" msgstr " - POZASTAVENO" -msgid "Press Ctrl+Alt+PgDn to return to windowed mode." -msgstr "Stiskněte Ctrl+Alt+PgDn pro návrat z režimu celé obrazovky." - msgid "Speed" msgstr "Rychlost" -msgid "ZIP %03i %i (%s): %ls" -msgstr "ZIP %03i %i (%s): %ls" +msgid "ZIP %1 %2 (%3): %4" +msgstr "ZIP %1 %2 (%3): %4" msgid "ZIP images" msgstr "Obrazy ZIP disků" @@ -687,8 +672,11 @@ msgstr "Počítač \"%hs\" není dostupný, jelikož chybí obraz jeho paměti R msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "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." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Video adaptér 2 \"%hs\" není dostupný, jelikož chybí obraz jeho paměti ROM ve složce \"roms/video\". Konfigurace se přepne na jiný dostupný adaptér." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "Video adaptér 2 \"%hs\" není dostupný, jelikož chybí obraz jeho paměti ROM ve složce \"roms/video\". Druhá grafická karta se zakáže." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Zařízení \"%hs\" není dostupné, jelikož chybí obraz jeho paměti ROM. Zařízení je ignorováno." msgid "Machine" msgstr "Počítač" @@ -750,14 +738,11 @@ msgstr "S" msgid "KB" msgstr "KB" -msgid "Could not initialize the video renderer." -msgstr "Nastala chyba při inicializaci video rendereru." - msgid "Default" msgstr "Výchozí" -msgid "%i Wait state(s)" -msgstr "%i čekací stav(y)" +msgid "%1 Wait state(s)" +msgstr "%1 čekací stav(y)" msgid "Type" msgstr "Typ" @@ -801,11 +786,11 @@ msgstr "Thrustmaster Flight Control System" msgid "None" msgstr "Žadné" -msgid "%u MB (CHS: %i, %i, %i)" -msgstr "%u MB (CHS: %i, %i, %i)" +msgid "%1 MB (CHS: %2, %3, %4)" +msgstr "%1 MB (CHS: %2, %3, %4)" -msgid "Floppy %i (%s): %ls" -msgstr "Disketová mechanika %i (%s): %ls" +msgid "Floppy %1 (%2): %3" +msgstr "Disketová mechanika %1 (%2): %3" msgid "Advanced sector images" msgstr "Rozšířené sektorové obrazy" @@ -825,8 +810,8 @@ msgstr "Nastala chyba při inicializaci knihovny Ghostscript" msgid "Unable to initialize GhostPCL" msgstr "Nastala chyba při inicializaci knihovny GhostPCL" -msgid "MO %i (%ls): %ls" -msgstr "MO %i (%ls): %ls" +msgid "MO %1 (%2): %3" +msgstr "MO %1 (%2): %3" msgid "MO images" msgstr "Obrazy MO" @@ -876,9 +861,6 @@ msgstr "%1 je potřeba pro automatický převod PostScript dokumentů do PDF.\n\ msgid "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PCL printer will be saved as Printer Command Language (.pcl) files." msgstr "%1 je potřeba pro automatický převod PCL dokumentů do PDF.\n\nJakékoliv dokumenty vytisknuté přes obecnou PCL-ovou tiskárnu budou uloženy jako Printer Command Language (.pcl) soubory." -msgid "Entering fullscreen mode" -msgstr "Vstup do režimu celé obrazovky" - msgid "Don't show this message again" msgstr "Nezobrazovat dále tuto zprávu" @@ -900,11 +882,8 @@ msgstr "Nastavení zařízení %1" msgid "Monitor in sleep mode" msgstr "Monitor je v režimu spánku" -msgid "OpenGL Shaders" -msgstr "Shadery OpenGL" - -msgid "OpenGL options" -msgstr "Možnosti OpenGL" +msgid "GLSL shaders" +msgstr "Shadery GLSL" msgid "You are loading an unsupported configuration" msgstr "Pokoušíte se spustit nepodporovanou konfiguraci" @@ -915,24 +894,18 @@ msgstr "Pro tuto konfiguraci bylo vypnuto filtrování procesorů podle zvolené msgid "Continue" msgstr "Pokračovat" -msgid "Cassette: %s" -msgstr "Kazeta: %s" +msgid "Cassette: %1" +msgstr "Kazeta: %1" msgid "Cassette images" msgstr "Kazetové nahrávky" -msgid "Cartridge %i: %ls" -msgstr "Cartridge %i: %ls" +msgid "Cartridge %1: %2" +msgstr "Cartridge %1: %2" msgid "Cartridge images" msgstr "Obrazy cartridge" -msgid "Error initializing renderer" -msgstr "Chyba při inicializaci vykreslovače" - -msgid "OpenGL (3.0 Core) renderer could not be initialized. Use another renderer." -msgstr "Vykreslovač OpenGL (3.0 Core) se nepodařilo inicializovat. Použijte jiný renderer." - msgid "Resume execution" msgstr "Obnovit" @@ -1095,8 +1068,8 @@ msgstr "IDE" msgid "ATAPI" msgstr "ATAPI" -msgid "CD-ROM %i (%s): %s" -msgstr "CD-ROM %i (%s): %s" +msgid "CD-ROM %1 (%2): %3" +msgstr "CD-ROM %1 (%2): %3" msgid "160 KB" msgstr "160 KB" @@ -1275,9 +1248,6 @@ msgstr "Vymaž historie snímků" msgid "Create..." msgstr "Vytvoř..." -msgid "previous image" -msgstr "předchozí obraz" - msgid "Host CD/DVD Drive (%1)" msgstr "Jednotka CD/DVD hostitele (%1)" @@ -1287,23 +1257,8 @@ msgstr "Neznámá sběrnice" msgid "Null Driver" msgstr "Nulový ovladač" -msgid "NIC %02i (%ls) %ls" -msgstr "NIC %02i (%ls) %ls" - -msgid "Error opening \"%1\": %2" -msgstr "Chyba při otevírání \"%1\": %2" - -msgid "Error compiling vertex shader in file \"%1\"" -msgstr "Chyba při kompilaci vertex shaderu v souboru \"%1\"" - -msgid "Error compiling fragment shader in file \"%1\"" -msgstr "Chyba při kompilaci fragment shaderu v souboru \"%1\"" - -msgid "Error linking shader program in file \"%1\"" -msgstr "Chyba při linkování shader programu v souboru \"%1\"" - -msgid "OpenGL 3.0 renderer options" -msgstr "Možnosti vykreslovače OpenGL 3.0" +msgid "NIC %1 (%2) %3" +msgstr "NIC %1 (%2) %3" msgid "Render behavior" msgstr "Chování vykreslování" @@ -1317,9 +1272,6 @@ msgstr " fps" msgid "VSync" msgstr "VSync" -msgid "<html><head/><body><p>Render each frame immediately, in sync with the emulated display.</p><p><span style=" font-style:italic;">This is the recommended option if the shaders in use don't utilize frametime for animated effects.</span></p></body></html>" -msgstr "<html><head/><body><p>Každý snímek se vykreslí okamžitě, synchronizovaně s emulovaným displejem.</p><p><span style=" font-style:italic;">Tuto možnost doporučujeme, pokud používané shadery nevyužívají frametime pro animované efekty.</span></p></body></html>" - msgid "Synchronize with video" msgstr "Synchronizovat s obrazem" @@ -1329,21 +1281,9 @@ msgstr "Shadery" msgid "Remove" msgstr "Odstraň" -msgid "No shader selected" -msgstr "Není vybrán žádný shader" - msgid "Browse..." msgstr "Prohlížejte..." -msgid "Shader error" -msgstr "Chyba shaderu" - -msgid "Could not load shaders." -msgstr "Nepodařilo se načíst shadery." - -msgid "More information in details." -msgstr "Více informací v podrobnostech." - msgid "Couldn't create OpenGL context." msgstr "Nepodařilo se vytvořit kontext OpenGL." @@ -1353,20 +1293,14 @@ msgstr "Nepodařilo se přepnout na kontext OpenGL." msgid "OpenGL version 3.0 or greater is required. Current version is %1.%2" msgstr "Je vyžadována verze OpenGL 3.0 nebo vyšší. Aktuální verze je %1.%2" -msgid "OpenGL initialization failed. Error %1." -msgstr "Inicializace OpenGL se nezdařila. Chyba %1." - msgid "Error initializing OpenGL" msgstr "Chyba při inicializaci OpenGL" -msgid "Falling back to software rendering.\n" -msgstr "Návrat k softwarovému vykreslování.\n" +msgid "\nFalling back to software rendering." +msgstr "\nNávrat k softwarovému vykreslování." -msgid "Allocating memory for unpack buffer failed.\n" -msgstr "Alokace paměti pro rozbalovací vyrovnávací paměť se nezdařila.\n" - -msgid "<html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html>" -msgstr "<html><head/><body><p>Při výběru obrazů médií (CD-ROM, disketa atd.) se otevřené dialogové okno spustí ve stejném adresáři jako konfigurační soubor 86Box. Toto nastavení bude mít pravděpodobně význam pouze v systému MacOS.</p></body></html>" +msgid "

When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" +msgstr "

Při výběru obrazů médií (CD-ROM, disketa atd.) se otevřené dialogové okno spustí ve stejném adresáři jako konfigurační soubor 86Box. Toto nastavení bude mít pravděpodobně význam pouze v systému MacOS.

" msgid "This machine might have been moved or copied." msgstr "Tento počítač mohl být přemístěn nebo zkopírován." @@ -1401,17 +1335,17 @@ msgstr "Síťová karta 3" msgid "Network Card #4" msgstr "Síťová karta 4" -msgid "Mode" -msgstr "Režim" +msgid "Mode:" +msgstr "Režim:" -msgid "Interface" -msgstr "Rozhraní" +msgid "Interface:" +msgstr "Rozhraní:" -msgid "Adapter" -msgstr "Adaptér" +msgid "Adapter:" +msgstr "Adaptér:" -msgid "VDE Socket" -msgstr "Zásuvka VDE" +msgid "VDE Socket:" +msgstr "Zásuvka VDE:" msgid "86Box Unit Tester" msgstr "86Box Unit Tester" @@ -1431,9 +1365,6 @@ msgstr "Průchod sériového portu 3" msgid "Serial port passthrough 4" msgstr "Průchod sériového portu 4" -msgid "Vision Systems LBA Enhancer" -msgstr "Vision Systems LBA Enhancer" - msgid "Renderer options..." msgstr "Možnosti vykreslovače..." @@ -1872,6 +1803,9 @@ msgstr "Kolečko" msgid "Five + Wheel" msgstr "Pět + kolečko" +msgid "Five + 2 Wheels" +msgstr "" + msgid "A3 - SMT2 Serial / SMT3(R)V" msgstr "A3 - SMT2 sériová / SMT3(R)V" @@ -1900,7 +1834,7 @@ msgid "2 MB" msgstr "2 MB" msgid "8 MB" -msgstr " 8 MB" +msgstr "8 MB" msgid "28 MB" msgstr "28 MB" @@ -2100,8 +2034,8 @@ msgstr "Pojmenované potrubí (server)" msgid "Host Serial Passthrough" msgstr "Průchod sériového portu hostitele" -msgid "Eject %s" -msgstr "Vyjmout %s" +msgid "E&ject %1" +msgstr "&Vyjmout %1" msgid "&Unmute" msgstr "&Roztišit" @@ -2112,11 +2046,104 @@ msgstr "Softfloat FPU" msgid "High performance impact" msgstr "Vysoký dopad na výkon" -msgid "RAM Disk (max. speed)" -msgstr "Disk RAM (max. rychlost)" +msgid "[Generic] RAM Disk (max. speed)" +msgstr "[Generic] Disk RAM (max. rychlost)" + +msgid "[Generic] 1989 (3500 RPM)" +msgstr "" + +msgid "[Generic] 1992 (3600 RPM)" +msgstr "" + +msgid "[Generic] 1994 (4500 RPM)" +msgstr "" + +msgid "[Generic] 1996 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1997 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1998 (5400 RPM)" +msgstr "" + +msgid "[Generic] 2000 (7200 RPM)" +msgstr "" msgid "IBM 8514/A clone (ISA)" msgstr "Klon IBM 8514/A (ISA)" msgid "Vendor" msgstr "Výrobce" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Obecné rozšíření paměti PC/XT" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Obecné rozšíření paměti PC/AT" + +msgid "Unable to find Dot-Matrix fonts" +msgstr "Nastala chyba při nachození jehličkových písem" + +msgid "TrueType fonts in the \"roms/printer/fonts\" directory are required for the emulation of the Generic ESC/P Dot-Matrix Printer." +msgstr "Pro emulaci obecné jehličkové tiskárny ESC/P jsou vyžadována písma TrueType ve složce \"roms/printer/fonts\"." + +msgid "Inhibit multimedia keys" +msgstr "" + +msgid "Ask for confirmation before saving settings" +msgstr "" + +msgid "Ask for confirmation before hard resetting" +msgstr "" + +msgid "Ask for confirmation before quitting" +msgstr "" + +msgid "Options" +msgstr "" + +msgid "Model" +msgstr "" + +msgid "Model:" +msgstr "" + +msgid "Failed to initialize Vulkan renderer." +msgstr "" + +msgid "GLSL Error" +msgstr "" + +msgid "Could not load shader: %1" +msgstr "" + +msgid "OpenGL version 3.0 or greater is required. Current GLSL version is %1.%2" +msgstr "" + +msgid "Could not load texture: %1" +msgstr "" + +msgid "Could not compile shader:\n\n%1" +msgstr "" + +msgid "Program not linked:\n\n%1" +msgstr "" + +msgid "Shader Manager" +msgstr "" + +msgid "Shader Configuration" +msgstr "" + +msgid "Add" +msgstr "" + +msgid "Move up" +msgstr "" + +msgid "Move down" +msgstr "" + +msgid "Could not load file %1" +msgstr "" diff --git a/src/qt/languages/de-DE.po b/src/qt/languages/de-DE.po index e94b8ebf4..267e4b13e 100644 --- a/src/qt/languages/de-DE.po +++ b/src/qt/languages/de-DE.po @@ -18,8 +18,8 @@ msgstr "&Die rechte Strg-Taste ist die Linke Alt-Taste" msgid "&Hard Reset..." msgstr "&Kaltstart..." -msgid "&Ctrl+Alt+Del\tCtrl+F12" -msgstr "&Strg+Alt+Entf\tStrg+F12" +msgid "&Ctrl+Alt+Del" +msgstr "&Strg+Alt+Entf" msgid "Ctrl+Alt+&Esc" msgstr "Strg+Alt+&Esc" @@ -111,8 +111,8 @@ msgstr "&Linear" msgid "Hi&DPI scaling" msgstr "Hi&DPI-Skalierung" -msgid "&Fullscreen\tCtrl+Alt+PgUp" -msgstr "&Vollbild\tStrg+Alt+Bild auf" +msgid "&Fullscreen" +msgstr "&Vollbild" msgid "Fullscreen &stretch mode" msgstr "&Vollbild-Skalierungsmodus" @@ -186,8 +186,11 @@ msgstr "&Optionen..." msgid "&Update status bar icons" msgstr "&Statusleistenicons aktualisieren" -msgid "Take s&creenshot\tCtrl+F11" -msgstr "S&creenshot aufnehmen\tStrg+F11" +msgid "Take s&creenshot" +msgstr "S&creenshot aufnehmen" + +msgid "S&ound" +msgstr "S&ound" msgid "&Preferences..." msgstr "&Einstellungen..." @@ -198,11 +201,11 @@ msgstr "&Discord-Integration einschalten" msgid "Sound &gain..." msgstr "&Klangverstärkung..." -msgid "Begin trace\tCtrl+T" -msgstr "Tracing starten\tStrg+T" +msgid "Begin trace" +msgstr "Tracing starten" -msgid "End trace\tCtrl+T" -msgstr "Tracing beenden\tStrg+T" +msgid "End trace" +msgstr "Tracing beenden" msgid "&Help" msgstr "&Hilfe" @@ -249,8 +252,8 @@ msgstr "&Stummschalten" msgid "E&mpty" msgstr "L&eer" -msgid "&Reload previous image" -msgstr "&Voriges Abbild neu laden" +msgid "Reload previous image" +msgstr "Voriges Abbild neu laden" msgid "&Folder..." msgstr "&Verzeichnis..." @@ -306,18 +309,12 @@ msgstr "OK" msgid "Cancel" msgstr "Abbrechen" -msgid "Save these settings as &global defaults" -msgstr "Einstellungen als &globalen Standard speichern" - msgid "&Default" msgstr "&Standard" msgid "Language:" msgstr "Sprache:" -msgid "Icon set:" -msgstr "Icon-Satz:" - msgid "Gain" msgstr "Verstärkung" @@ -453,15 +450,6 @@ msgstr "Nuked (genauer)" msgid "YMFM (faster)" msgstr "YMFM (schneller)" -msgid "Network type:" -msgstr "Netzwerktyp:" - -msgid "PCap device:" -msgstr "PCap-Gerät:" - -msgid "Network adapter:" -msgstr "Netzwerkadapter:" - msgid "COM1 Device:" msgstr "COM1-Gerät:" @@ -642,14 +630,11 @@ msgstr "Fataler Fehler" msgid " - PAUSED" msgstr " - PAUSIERT" -msgid "Press Ctrl+Alt+PgDn to return to windowed mode." -msgstr "Strg+Alt+Bild ab, zur Rückkehr in den Fenstermodus." - msgid "Speed" msgstr "Geschwindigkeit" -msgid "ZIP %03i %i (%s): %ls" -msgstr "ZIP %03i %i (%s): %ls" +msgid "ZIP %1 %2 (%3): %4" +msgstr "ZIP %1 %2 (%3): %4" msgid "ZIP images" msgstr "ZIP-Abbilder" @@ -687,8 +672,11 @@ msgstr "Das System \"%hs\" ist aufgrund von fehlenden ROMs im Verzeichnis roms/m msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "Die Videokarte \"%hs\" ist aufgrund von fehlenden ROMs im Verzeichnis roms/video nicht verfügbar. Es wird auf eine verfügbare Videokarte gewechselt." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Die Videokarte 2 \"%hs\" ist aufgrund von fehlenden ROMs im Verzeichnis roms/video nicht verfügbar. Es wird auf eine verfügbare Videokarte gewechselt." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "Das Gerät \"%hs\" ist aufgrund von fehlenden ROMs nicht verfügbar. Es wird ignoriert." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Die Videokarte 2 \"%hs\" ist aufgrund von fehlenden ROMs im Verzeichnis roms/video nicht verfügbar. Es wird deaktiviert." msgid "Machine" msgstr "System" @@ -732,9 +720,6 @@ msgstr "Drücke %1 zur Mausfreigabe" msgid "Press %1 or middle button to release mouse" msgstr "Drücke %1 oder die mittlere Maustaste zur Mausfreigabe" -msgid "Ctrl+End" -msgstr "Strg+Ende" - msgid "Bus" msgstr "Bus" @@ -753,14 +738,11 @@ msgstr "S" msgid "KB" msgstr "KB" -msgid "Could not initialize the video renderer." -msgstr "Der Videorenderer konnte nicht initialisiert werden." - msgid "Default" msgstr "Standard" -msgid "%i Wait state(s)" -msgstr "%i Wartezustände" +msgid "%1 Wait state(s)" +msgstr "%1 Wartezustände" msgid "Type" msgstr "Typ" @@ -804,11 +786,11 @@ msgstr "Thrustmaster Flight Control System" msgid "None" msgstr "Ohne" -msgid "%u MB (CHS: %i, %i, %i)" -msgstr "%u MB (CHS: %i, %i, %i)" +msgid "%1 MB (CHS: %2, %3, %4)" +msgstr "%1 MB (CHS: %2, %3, %4)" -msgid "Floppy %i (%s): %ls" -msgstr "Diskette %i (%s): %ls" +msgid "Floppy %1 (%2): %3" +msgstr "Diskette %1 (%2): %3" msgid "Advanced sector images" msgstr "Fortgeschrittene Sektorabbilder" @@ -828,8 +810,8 @@ msgstr "Ghostscript konnte nicht initialisiert werden" msgid "Unable to initialize GhostPCL" msgstr "GhostPCL konnte nicht initialisiert werden" -msgid "MO %i (%ls): %ls" -msgstr "MO %i (%ls): %ls" +msgid "MO %1 (%2): %3" +msgstr "MO %1 (%2): %3" msgid "MO images" msgstr "MO-Abbilder" @@ -879,9 +861,6 @@ msgstr "%1 wird zur automatischen Konvertierung von PostScript-Dateien ins PDF-F msgid "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PCL printer will be saved as Printer Command Language (.pcl) files." msgstr "%1 wird zur automatischen Konvertierung von PCL-Dateien ins PDF-Format benötigt.\n\nSämtliche an den generischen PCL-Drucker gesendete Dateien werden als Printer Command Language (*.pcl) Dateien gesichert." -msgid "Entering fullscreen mode" -msgstr "Vollbildmodus wird aktiviert" - msgid "Don't show this message again" msgstr "Diese Nachricht nicht mehr anzeigen" @@ -903,11 +882,8 @@ msgstr "%1-Gerätekonfiguration" msgid "Monitor in sleep mode" msgstr "Monitor im Standbymodus" -msgid "OpenGL Shaders" -msgstr "OpenGL-Shader" - -msgid "OpenGL options" -msgstr "OpenGL-Optionen" +msgid "GLSL shaders" +msgstr "GLSL-Shader" msgid "You are loading an unsupported configuration" msgstr "Zur Zeit wird eine nicht unterstützte Konfiguration geladen" @@ -918,24 +894,18 @@ msgstr "Das Filtern der CPU-Typen basierend auf dem ausgewählten System ist fü msgid "Continue" msgstr "Fortfahren" -msgid "Cassette: %s" -msgstr "Kassette: %s" +msgid "Cassette: %1" +msgstr "Kassette: %1" msgid "Cassette images" msgstr "Kassettenabbilder" -msgid "Cartridge %i: %ls" -msgstr "Cartridge %i: %ls" +msgid "Cartridge %1: %2" +msgstr "Cartridge %1: %2" msgid "Cartridge images" msgstr "Cartridgeabbilder" -msgid "Error initializing renderer" -msgstr "Fehler bei der Initialisierung des Renderer" - -msgid "OpenGL (3.0 Core) renderer could not be initialized. Use another renderer." -msgstr "Der OpenGL (3.0-Kern)-Renderer konnte nicht initialisiert werden. Benutze einen anderen Renderer." - msgid "Resume execution" msgstr "Fortsetzen" @@ -1098,8 +1068,8 @@ msgstr "IDE" msgid "ATAPI" msgstr "ATAPI" -msgid "CD-ROM %i (%s): %s" -msgstr "CD-ROM %i (%s): %s" +msgid "CD-ROM %1 (%2): %3" +msgstr "CD-ROM %1 (%2): %3" msgid "160 KB" msgstr "160 KB" @@ -1278,9 +1248,6 @@ msgstr "Abbildverlauf löschen" msgid "Create..." msgstr "Erstellen..." -msgid "previous image" -msgstr "Vorheriges Abbild" - msgid "Host CD/DVD Drive (%1)" msgstr "Host-CD/DVD-Laufwerk (%1)" @@ -1290,23 +1257,8 @@ msgstr "Unbekannter Bus" msgid "Null Driver" msgstr "Nulltreiber" -msgid "NIC %02i (%ls) %ls" -msgstr "NIC %02i (%ls) %ls" - -msgid "Error opening \"%1\": %2" -msgstr "Fehler beim Öffnen \"%1\": %2" - -msgid "Error compiling vertex shader in file \"%1\"" -msgstr "Fehler beim Kompilieren des Vertex-Shaders in der Datei \"%1\"" - -msgid "Error compiling fragment shader in file \"%1\"" -msgstr "Fehler beim Kompilieren des Fragment-Shaders in der Datei \"%1\"" - -msgid "Error linking shader program in file \"%1\"" -msgstr "Fehler beim Linken des Shader-Programms in der Datei \"%1\"" - -msgid "OpenGL 3.0 renderer options" -msgstr "OpenGL 3.0 Renderer-Optionen" +msgid "NIC %1 (%2) %3" +msgstr "NIC %1 (%2) %3" msgid "Render behavior" msgstr "Rendering-Verhalten" @@ -1320,9 +1272,6 @@ msgstr " fps" msgid "VSync" msgstr "VSync" -msgid "<html><head/><body><p>Render each frame immediately, in sync with the emulated display.</p><p><span style=" font-style:italic;">This is the recommended option if the shaders in use don't utilize frametime for animated effects.</span></p></body></html>" -msgstr "<html><head/><body><p>Jedes Bild sofort rendern, synchron mit der emulierten Monitor.</p><p><span style=" font-style:italic;">Dies ist die empfohlene Option, wenn die verwendeten Shader die Bildzeit für animierte Effekte nicht nutzen.</span></p></body></html>" - msgid "Synchronize with video" msgstr "Mit Videoausgabe synchronisieren" @@ -1332,21 +1281,9 @@ msgstr "Shader" msgid "Remove" msgstr "Entfernen" -msgid "No shader selected" -msgstr "Kein Shader ausgewählt" - msgid "Browse..." msgstr "Durchsuchen..." -msgid "Shader error" -msgstr "Shader-Fehler" - -msgid "Could not load shaders." -msgstr "Shader konnten nicht geladen werden." - -msgid "More information in details." -msgstr "Weitere Informationen im Einzelnen." - msgid "Couldn't create OpenGL context." msgstr "OpenGL-Kontext konnte nicht erstellt werden." @@ -1356,20 +1293,14 @@ msgstr "Konnte nicht in den OpenGL-Kontext wechseln." msgid "OpenGL version 3.0 or greater is required. Current version is %1.%2" msgstr "OpenGL-Version 3.0 oder höher ist erforderlich. Die aktuelle Version ist %1.%2" -msgid "OpenGL initialization failed. Error %1." -msgstr "OpenGL-Initialisierung fehlgeschlagen. Fehler %1." - msgid "Error initializing OpenGL" msgstr "Fehler beim Initialisieren von OpenGL" -msgid "Falling back to software rendering.\n" -msgstr "Rückgriff auf Software-Rendering.\n" +msgid "\nFalling back to software rendering." +msgstr "\nRückgriff auf Software-Rendering." -msgid "Allocating memory for unpack buffer failed.\n" -msgstr "Nicht genug Speicher zum Entpacken.\n" - -msgid "<html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html>" -msgstr "<html><head/><body><p>Bei der Auswahl von Medien-Abbildern (CD-ROM, Diskette usw.) wird der Öffnungsdialog im selben Verzeichnis wie die 86Box-Konfigurationsdatei gestartet. Diese Einstellung macht wahrscheinlich nur unter macOS einen Unterschied.</p></body></html>" +msgid "

When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" +msgstr "

Bei der Auswahl von Medien-Abbildern (CD-ROM, Diskette usw.) wird der Öffnungsdialog im selben Verzeichnis wie die 86Box-Konfigurationsdatei gestartet. Diese Einstellung macht wahrscheinlich nur unter macOS einen Unterschied.

" msgid "This machine might have been moved or copied." msgstr "Dieses System wurde möglicherweise verschoben oder kopiert." @@ -1404,17 +1335,17 @@ msgstr "Netzwerkkarte 3" msgid "Network Card #4" msgstr "Netzwerkkarte 4" -msgid "Mode" -msgstr "Modus" +msgid "Mode:" +msgstr "Modus:" -msgid "Interface" -msgstr "Schnittstelle" +msgid "Interface:" +msgstr "Schnittstelle:" -msgid "Adapter" -msgstr "Adapter" +msgid "Adapter:" +msgstr "Adapter:" -msgid "VDE Socket" -msgstr "VDE Port" +msgid "VDE Socket:" +msgstr "VDE Port:" msgid "86Box Unit Tester" msgstr "86Box-Gerätetester" @@ -1434,9 +1365,6 @@ msgstr "Durchreichung der Serielle Schnittstelle 3" msgid "Serial port passthrough 4" msgstr "Durchreichung der Serielle Schnittstelle 4" -msgid "Vision Systems LBA Enhancer" -msgstr "Vision Systems LBA Enhancer" - msgid "Renderer options..." msgstr "Renderer-Optionen..." @@ -1875,6 +1803,9 @@ msgstr "Rad" msgid "Five + Wheel" msgstr "Fünf + Rad" +msgid "Five + 2 Wheels" +msgstr "" + msgid "A3 - SMT2 Serial / SMT3(R)V" msgstr "A3 - SMT2 Seriell / SMT3(R)V" @@ -1903,7 +1834,7 @@ msgid "2 MB" msgstr "2 MB" msgid "8 MB" -msgstr " 8 MB" +msgstr "8 MB" msgid "28 MB" msgstr "28 MB" @@ -2103,8 +2034,8 @@ msgstr "Benanntes Pipe (Server)" msgid "Host Serial Passthrough" msgstr "Durchreichung der seriellen Schnittstelle des Hosts" -msgid "Eject %s" -msgstr "Auswerfen %s" +msgid "E&ject %1" +msgstr "A&uswerfen %1" msgid "&Unmute" msgstr "&Ton einschalten" @@ -2115,11 +2046,104 @@ msgstr "Softfloat-FPU" msgid "High performance impact" msgstr "Hohe Auswirkung auf die Leistung" -msgid "RAM Disk (max. speed)" -msgstr "RAM-Diskette (maximale Geschwindigkeit)" +msgid "[Generic] RAM Disk (max. speed)" +msgstr "[Generic] RAM-Diskette (maximale Geschwindigkeit)" + +msgid "[Generic] 1989 (3500 RPM)" +msgstr "" + +msgid "[Generic] 1992 (3600 RPM)" +msgstr "" + +msgid "[Generic] 1994 (4500 RPM)" +msgstr "" + +msgid "[Generic] 1996 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1997 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1998 (5400 RPM)" +msgstr "" + +msgid "[Generic] 2000 (7200 RPM)" +msgstr "" msgid "IBM 8514/A clone (ISA)" msgstr "IBM 8514/A-Klon (ISA)" msgid "Vendor" msgstr "Hersteller" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Generische PC/XT-Speichererweiterung" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Generische PC/AT-Speichererweiterung" + +msgid "Unable to find Dot-Matrix fonts" +msgstr "Nadel-Schriften konnten nicht gefunden werden" + +msgid "TrueType fonts in the \"roms/printer/fonts\" directory are required for the emulation of the Generic ESC/P Dot-Matrix Printer." +msgstr "TrueType-Schriften in das \"roms/printer/fonts\"-Verzeichnis sind für die Allgemeines ESC/P Nadel-Druckers erforderlich." + +msgid "Inhibit multimedia keys" +msgstr "" + +msgid "Ask for confirmation before saving settings" +msgstr "" + +msgid "Ask for confirmation before hard resetting" +msgstr "" + +msgid "Ask for confirmation before quitting" +msgstr "" + +msgid "Options" +msgstr "" + +msgid "Model" +msgstr "" + +msgid "Model:" +msgstr "" + +msgid "Failed to initialize Vulkan renderer." +msgstr "" + +msgid "GLSL Error" +msgstr "" + +msgid "Could not load shader: %1" +msgstr "" + +msgid "OpenGL version 3.0 or greater is required. Current GLSL version is %1.%2" +msgstr "" + +msgid "Could not load texture: %1" +msgstr "" + +msgid "Could not compile shader:\n\n%1" +msgstr "" + +msgid "Program not linked:\n\n%1" +msgstr "" + +msgid "Shader Manager" +msgstr "" + +msgid "Shader Configuration" +msgstr "" + +msgid "Add" +msgstr "" + +msgid "Move up" +msgstr "" + +msgid "Move down" +msgstr "" + +msgid "Could not load file %1" +msgstr "" diff --git a/src/qt/languages/en-GB.po b/src/qt/languages/en-GB.po index bd3a5ba99..550bc3ab4 100644 --- a/src/qt/languages/en-GB.po +++ b/src/qt/languages/en-GB.po @@ -15,14 +15,11 @@ msgstr "&RGB Greyscale" msgid "Time synchronization" msgstr "Time synchronisation" -msgid "Could not initialize the video renderer." -msgstr "Could not initialise the video renderer." +msgid "Unable to initialize Ghostscript" +msgstr "Unable to initialise Ghostscript" -msgid "Error initializing renderer" -msgstr "Error initialising renderer" - -msgid "OpenGL (3.0 Core) renderer could not be initialized. Use another renderer." -msgstr "OpenGL (3.0 Core) renderer could not be initialised. Use another renderer." +msgid "Unable to initialize GhostPCL" +msgstr "Unable to initialise GhostPCL" msgid "Development of the WinBox manager stopped in 2022 due to a lack of maintainers. As we direct our efforts towards making 86Box even better, we have made the decision to no longer support WinBox as a manager.\n\nNo further updates will be provided through WinBox, and you may encounter incorrect behavior should you continue using it with newer versions of 86Box. Any bug reports related to WinBox behavior will be closed as invalid.\n\nGo to 86box.net for a list of other managers you can use." msgstr "Development of the WinBox manager stopped in 2022 due to a lack of maintainers. As we direct our efforts towards making 86Box even better, we have made the decision to no longer support WinBox as a manager.\n\nNo further updates will be provided through WinBox, and you may encounter incorrect behavior should you continue using it with newer versions of 86Box. Any bug reports related to WinBox behaviour will be closed as invalid.\n\nGo to 86box.net for a list of other managers you can use." @@ -30,17 +27,20 @@ msgstr "Development of the WinBox manager stopped in 2022 due to a lack of maint msgid "Apply fullscreen stretch mode when maximized" msgstr "Apply fullscreen stretch mode when maximised" +msgid "Failed to initialize network driver" +msgstr "Failed to initialise network driver" + msgid "Render behavior" msgstr "Render behaviour" -msgid "<html><head/><body><p>Render each frame immediately, in sync with the emulated display.</p><p><span style=" font-style:italic;">This is the recommended option if the shaders in use don't utilize frametime for animated effects.</span></p></body></html>" -msgstr "<html><head/><body><p>Render each frame immediately, in sync with the emulated display.</p><p><span style=" font-style:italic;">This is the recommended option if the shaders in use don't utilise frametime for animated effects.</span></p></body></html>" - msgid "Synchronize with video" msgstr "Synchronise with video" -msgid "<html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html>" -msgstr "<html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialogue will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html>" +msgid "Error initializing OpenGL" +msgstr "Error initialising OpenGL" + +msgid "

When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" +msgstr "

When selecting media images (CD-ROM, floppy, etc.) the open dialogue will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" msgid "Color (generic)" msgstr "Colour (generic)" @@ -71,3 +71,6 @@ msgstr "Grey" msgid "Color" msgstr "Colour" + +msgid "Failed to initialize Vulkan renderer." +msgstr "Failed to initialise Vulkan renderer." diff --git a/src/qt/languages/es-ES.po b/src/qt/languages/es-ES.po index 7a457b225..5454ab1de 100644 --- a/src/qt/languages/es-ES.po +++ b/src/qt/languages/es-ES.po @@ -18,8 +18,8 @@ msgstr "CTRL &derecho es ALT izquierdo" msgid "&Hard Reset..." msgstr "&Hard Reset..." -msgid "&Ctrl+Alt+Del\tCtrl+F12" -msgstr "&Ctrl+Alt+Del\tCtrl+F12" +msgid "&Ctrl+Alt+Del" +msgstr "&Ctrl+Alt+Del" msgid "Ctrl+Alt+&Esc" msgstr "Ctrl+Alt+&Esc" @@ -111,8 +111,8 @@ msgstr "&Lineal" msgid "Hi&DPI scaling" msgstr "&Escalado alta densidad" -msgid "&Fullscreen\tCtrl+Alt+PgUp" -msgstr "&Pantalla completa\tCtrl+Alt+PgUp" +msgid "&Fullscreen" +msgstr "&Pantalla completa" msgid "Fullscreen &stretch mode" msgstr "Escalado pantalla completa" @@ -186,8 +186,11 @@ msgstr "&Configuraciones..." msgid "&Update status bar icons" msgstr "&Actualizar iconos en barra de estado" -msgid "Take s&creenshot\tCtrl+F11" -msgstr "Tomar c&aptura\tCtrl+F11" +msgid "Take s&creenshot" +msgstr "Tomar c&aptura" + +msgid "S&ound" +msgstr "S&onido" msgid "&Preferences..." msgstr "&Preferencias..." @@ -198,11 +201,11 @@ msgstr "Habilitar integración con &Discord" msgid "Sound &gain..." msgstr "&Ganancia de sonido..." -msgid "Begin trace\tCtrl+T" -msgstr "Comenzar traza\tCtrl+T" +msgid "Begin trace" +msgstr "Comenzar traza" -msgid "End trace\tCtrl+T" -msgstr "Terminar traza\tCtrl+T" +msgid "End trace" +msgstr "Terminar traza" msgid "&Help" msgstr "&Ayuda" @@ -249,8 +252,8 @@ msgstr "&Silenciar" msgid "E&mpty" msgstr "E&xtraer disco" -msgid "&Reload previous image" -msgstr "&Recargar imagen previa" +msgid "Reload previous image" +msgstr "Recargar imagen previa" msgid "&Folder..." msgstr "&Carpeta..." @@ -306,18 +309,12 @@ msgstr "Aceptar" msgid "Cancel" msgstr "Cancelar" -msgid "Save these settings as &global defaults" -msgstr "Salvar estos configuraciones como por &defecto globalmente" - msgid "&Default" msgstr "&Por defecto" msgid "Language:" msgstr "Idioma:" -msgid "Icon set:" -msgstr "Juego de iconos:" - msgid "Gain" msgstr "Ganancia" @@ -453,15 +450,6 @@ msgstr "Nuked (más preciso)" msgid "YMFM (faster)" msgstr "YMFM (más rápido)" -msgid "Network type:" -msgstr "Tipo de red:" - -msgid "PCap device:" -msgstr "Dispositivo PCap:" - -msgid "Network adapter:" -msgstr "Adaptador de red:" - msgid "COM1 Device:" msgstr "Dispositivo COM1:" @@ -642,14 +630,11 @@ msgstr "Error fatal" msgid " - PAUSED" msgstr " - EN PAUSA" -msgid "Press Ctrl+Alt+PgDn to return to windowed mode." -msgstr "Pulsa Ctrl+Alt+PgDn para volver a modo ventana." - msgid "Speed" msgstr "Velocidad" -msgid "ZIP %03i %i (%s): %ls" -msgstr "ZIP %03i %i (%s): %ls" +msgid "ZIP %1 %2 (%3): %4" +msgstr "ZIP %1 %2 (%3): %4" msgid "ZIP images" msgstr "Imagenes ZIP" @@ -687,8 +672,11 @@ msgstr "La máquina \"%hs\" no está disponible debido a ROMs faltantes en el di msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "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." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "La tarjeta de vídeo 2 \"%hs\" no está disponible debido a ROMs faltantes en el directorio roms/machines. Cambiando a una tarjeta de vídeo disponible." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "La tarjeta de vídeo 2 \"%hs\" no está disponible debido a ROMs faltantes en el directorio roms/machines. Deshabilitanto la segunda tarjeta de vídeo." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "El dispositivo \"%hs\" no está disponible debido a ROMs faltantes. Ignorando el dispositivo." msgid "Machine" msgstr "Máquina" @@ -750,14 +738,11 @@ msgstr "S" msgid "KB" msgstr "KB" -msgid "Could not initialize the video renderer." -msgstr "No fué posible inicializar el renderizador de vídeo." - msgid "Default" msgstr "Por defecto" -msgid "%i Wait state(s)" -msgstr "%i estado(s) de Espera" +msgid "%1 Wait state(s)" +msgstr "%1 estado(s) de Espera" msgid "Type" msgstr "Tipo" @@ -801,11 +786,11 @@ msgstr "Thrustmaster Flight Control System" msgid "None" msgstr "Ninguno" -msgid "%u MB (CHS: %i, %i, %i)" -msgstr "%u MB (CHS: %i, %i, %i)" +msgid "%1 MB (CHS: %2, %3, %4)" +msgstr "%1 MB (CHS: %2, %3, %4)" -msgid "Floppy %i (%s): %ls" -msgstr "Disquete %i (%s): %ls" +msgid "Floppy %1 (%2): %3" +msgstr "Disquete %1 (%2): %3" msgid "Advanced sector images" msgstr "Imágenes avanzadas de sector" @@ -825,8 +810,8 @@ msgstr "No fué posible inicializar Ghostscript" msgid "Unable to initialize GhostPCL" msgstr "No fué posible inicializar GhostPCL" -msgid "MO %i (%ls): %ls" -msgstr "MO %i (%ls): %ls" +msgid "MO %1 (%2): %3" +msgstr "MO %1 (%2): %3" msgid "MO images" msgstr "Imágenes de MO" @@ -876,9 +861,6 @@ msgstr "%1 es necesaria para la conversión automática de archivos PostScript a msgid "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PCL printer will be saved as Printer Command Language (.pcl) files." msgstr "%1 es necesaria para la conversión automática de archivos PCL a PDF.\n\nCualquier documento enviado a la impresora genérica PCL se guardará como archivo Printer Command Language (.pcl)." -msgid "Entering fullscreen mode" -msgstr "Entrando en modo pantalla completa" - msgid "Don't show this message again" msgstr "No mostrar más este mensaje" @@ -900,11 +882,8 @@ msgstr "%1 Configuración de Dispositivo" msgid "Monitor in sleep mode" msgstr "Monitor en modo ahorro" -msgid "OpenGL Shaders" -msgstr "Shaders OpenGL" - -msgid "OpenGL options" -msgstr "Opciones OpenGL" +msgid "GLSL shaders" +msgstr "Shaders GLSL" msgid "You are loading an unsupported configuration" msgstr "Está cargando una configuración no soportada" @@ -915,24 +894,18 @@ msgstr "El Filtrado de tipo de CPU basado en máquina seleccionada está deshabi msgid "Continue" msgstr "Continuar" -msgid "Cassette: %s" -msgstr "Cassette: %s" +msgid "Cassette: %1" +msgstr "Cassette: %1" msgid "Cassette images" msgstr "Imágenes de Cassette" -msgid "Cartridge %i: %ls" -msgstr "Cartucho %i: %ls" +msgid "Cartridge %1: %2" +msgstr "Cartucho %1: %2" msgid "Cartridge images" msgstr "Imágenes de Cartucho" -msgid "Error initializing renderer" -msgstr "Error al inicializar el renderizador" - -msgid "OpenGL (3.0 Core) renderer could not be initialized. Use another renderer." -msgstr "No fué posible inicializar el renderizador OpenGL (3.0 Core). Utilice otro renderizador." - msgid "Resume execution" msgstr "Retomar la ejecución" @@ -1095,8 +1068,8 @@ msgstr "IDE" msgid "ATAPI" msgstr "ATAPI" -msgid "CD-ROM %i (%s): %s" -msgstr "CD-ROM %i (%s): %s" +msgid "CD-ROM %1 (%2): %3" +msgstr "CD-ROM %1 (%2): %3" msgid "160 KB" msgstr "160 KB" @@ -1274,9 +1247,6 @@ msgstr "Eliminar historia de imágenes" msgid "Create..." msgstr "Crear..." -msgid "previous image" -msgstr "imagen previa" - msgid "Host CD/DVD Drive (%1)" msgstr "Unidad de CD/DVD anfitriona (%1)" @@ -1286,23 +1256,8 @@ msgstr "Bus desconocido" msgid "Null Driver" msgstr "Controlador nulo" -msgid "NIC %02i (%ls) %ls" -msgstr "NIC %02i (%ls) %ls" - -msgid "Error opening \"%1\": %2" -msgstr "Error al abrir \"%1\": %2" - -msgid "Error compiling vertex shader in file \"%1\"" -msgstr "Error al compilar el vertex shader en el archivo \"%1\"" - -msgid "Error compiling fragment shader in file \"%1\"" -msgstr "Error al compilar el fragmentshader en el archivo \"%1\"" - -msgid "Error linking shader program in file \"%1\"" -msgstr "Error al enlazar el programa shader en el archivo \"%1\"" - -msgid "OpenGL 3.0 renderer options" -msgstr "Opciones del renderizador OpenGL 3.0" +msgid "NIC %1 (%2) %3" +msgstr "NIC %1 (%2) %3" msgid "Render behavior" msgstr "Comportamiento del renderizador" @@ -1316,9 +1271,6 @@ msgstr " fps" msgid "VSync" msgstr "VSync" -msgid "<html><head/><body><p>Render each frame immediately, in sync with the emulated display.</p><p><span style=" font-style:italic;">This is the recommended option if the shaders in use don't utilize frametime for animated effects.</span></p></body></html>" -msgstr "<html><head/><body><p>Renderiza cada fotograma inmediatamente, en sincronía con la pantalla emulada.</p><p><span style=" font-style:italic;">Esta es la opción recomendada si los shaders en uso no utilizan frametime para efectos animados.</span></p></body></html>" - msgid "Synchronize with video" msgstr "Sincronizar con los gráficos" @@ -1328,21 +1280,9 @@ msgstr "Shaders" msgid "Remove" msgstr "Eliminar" -msgid "No shader selected" -msgstr "Ningun shader seleccionado" - msgid "Browse..." msgstr "Buscar..." -msgid "Shader error" -msgstr "Error del shader" - -msgid "Could not load shaders." -msgstr "No ha sido posible carregar los shaders." - -msgid "More information in details." -msgstr "Más informaciones en los detalles." - msgid "Couldn't create OpenGL context." msgstr "No ha sido posible crear el contexto OpenGL." @@ -1352,20 +1292,14 @@ msgstr "No ha sido posible cambiar al contexto OpenGL." msgid "OpenGL version 3.0 or greater is required. Current version is %1.%2" msgstr "Es requerida la versión 3.0 o más alta de OpenGL. La versión actual es %1.%2" -msgid "OpenGL initialization failed. Error %1." -msgstr "La inicialización de OpenGL no tuvo éxito. Error %1." - msgid "Error initializing OpenGL" msgstr "Error al inicializar OpenGL" -msgid "Falling back to software rendering.\n" -msgstr "Recurrir al renderizado por software.\n" +msgid "\nFalling back to software rendering." +msgstr "\nRecurrir al renderizado por software." -msgid "Allocating memory for unpack buffer failed.\n" -msgstr "La allocación de memoria para el búfer de desempaquetado no tuvo éxito.\n" - -msgid "<html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html>" -msgstr "<html><head/><body><p>Al seleccionar imágenes multimedia (CD-ROM, disquete, etc.), el diálogo de apertura se iniciará en el mismo directorio que el archivo de configuración de 86Box. Es probable que este ajuste sólo suponga una diferencia en macOS.</p></body></html>" +msgid "

When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" +msgstr "

Al seleccionar imágenes multimedia (CD-ROM, disquete, etc.), el diálogo de apertura se iniciará en el mismo directorio que el archivo de configuración de 86Box. Es probable que este ajuste sólo suponga una diferencia en macOS.

" msgid "This machine might have been moved or copied." msgstr "Esta máquina puede haber sido movida o copiado." @@ -1400,17 +1334,17 @@ msgstr "Tarjeta de red 3" msgid "Network Card #4" msgstr "Tarjeta de red 4" -msgid "Mode" -msgstr "Modalidad" +msgid "Mode:" +msgstr "Modalidad:" -msgid "Interface" -msgstr "Interfaz" +msgid "Interface:" +msgstr "Interfaz:" -msgid "Adapter" -msgstr "Adaptador" +msgid "Adapter:" +msgstr "Adaptador:" -msgid "VDE Socket" -msgstr "Toma VDE" +msgid "VDE Socket:" +msgstr "Toma VDE:" msgid "86Box Unit Tester" msgstr "Comprobador de unidad 86Box" @@ -1430,9 +1364,6 @@ msgstr "Paso de puerto serie 3" msgid "Serial port passthrough 4" msgstr "Paso de puerto serie 4" -msgid "Vision Systems LBA Enhancer" -msgstr "Vision Systems LBA Enhancer" - msgid "Renderer options..." msgstr "Opciones del renderizador..." @@ -1871,6 +1802,9 @@ msgstr "Rueda" msgid "Five + Wheel" msgstr "Cinco + rueda" +msgid "Five + 2 Wheels" +msgstr "" + msgid "A3 - SMT2 Serial / SMT3(R)V" msgstr "A3 - SMT2 serie / SMT3(R)V" @@ -1899,7 +1833,7 @@ msgid "2 MB" msgstr "2 MB" msgid "8 MB" -msgstr " 8 MB" +msgstr "8 MB" msgid "28 MB" msgstr "28 MB" @@ -2099,8 +2033,8 @@ msgstr "Tubería con nombre (servidor)" msgid "Host Serial Passthrough" msgstr "Paso del puerto serie del host" -msgid "Eject %s" -msgstr "Extraer %s" +msgid "E&ject %1" +msgstr "E&xtraer %1" msgid "&Unmute" msgstr "&Reactivar sonido" @@ -2111,11 +2045,104 @@ msgstr "FPU Softfloat" msgid "High performance impact" msgstr "Alto impact en el rendimiento" -msgid "RAM Disk (max. speed)" -msgstr "Disco RAM (velocidad máxima)" +msgid "[Generic] RAM Disk (max. speed)" +msgstr "[Generic] Disco RAM (velocidad máxima)" + +msgid "[Generic] 1989 (3500 RPM)" +msgstr "" + +msgid "[Generic] 1992 (3600 RPM)" +msgstr "" + +msgid "[Generic] 1994 (4500 RPM)" +msgstr "" + +msgid "[Generic] 1996 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1997 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1998 (5400 RPM)" +msgstr "" + +msgid "[Generic] 2000 (7200 RPM)" +msgstr "" msgid "IBM 8514/A clone (ISA)" msgstr "Clon IBM 8514/A (ISA)" msgid "Vendor" msgstr "Fabricante" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Expansión de Memoria Generica PC/XT" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Expansión de Memoria Generica PC/AT" + +msgid "Unable to find Dot-Matrix fonts" +msgstr "No fué posible encontrar las fuentes matriciales" + +msgid "TrueType fonts in the \"roms/printer/fonts\" directory are required for the emulation of the Generic ESC/P Dot-Matrix Printer." +msgstr "Las fuentes TrueType en el directorio \"roms/printer/fonts\" son necesarias para la emulación de la impresora matricial ESC/P genérica." + +msgid "Inhibit multimedia keys" +msgstr "" + +msgid "Ask for confirmation before saving settings" +msgstr "" + +msgid "Ask for confirmation before hard resetting" +msgstr "" + +msgid "Ask for confirmation before quitting" +msgstr "" + +msgid "Options" +msgstr "" + +msgid "Model" +msgstr "" + +msgid "Model:" +msgstr "" + +msgid "Failed to initialize Vulkan renderer." +msgstr "" + +msgid "GLSL Error" +msgstr "" + +msgid "Could not load shader: %1" +msgstr "" + +msgid "OpenGL version 3.0 or greater is required. Current GLSL version is %1.%2" +msgstr "" + +msgid "Could not load texture: %1" +msgstr "" + +msgid "Could not compile shader:\n\n%1" +msgstr "" + +msgid "Program not linked:\n\n%1" +msgstr "" + +msgid "Shader Manager" +msgstr "" + +msgid "Shader Configuration" +msgstr "" + +msgid "Add" +msgstr "" + +msgid "Move up" +msgstr "" + +msgid "Move down" +msgstr "" + +msgid "Could not load file %1" +msgstr "" diff --git a/src/qt/languages/fi-FI.po b/src/qt/languages/fi-FI.po index 6aa71a867..ae4f78bb5 100644 --- a/src/qt/languages/fi-FI.po +++ b/src/qt/languages/fi-FI.po @@ -18,8 +18,8 @@ msgstr "&Oikea CTRL on vasen ALT" msgid "&Hard Reset..." msgstr "&Uudelleenkäynnistys (kylmä)..." -msgid "&Ctrl+Alt+Del\tCtrl+F12" -msgstr "&Ctrl+Alt+Del\tCtrl+F12" +msgid "&Ctrl+Alt+Del" +msgstr "&Ctrl+Alt+Del" msgid "Ctrl+Alt+&Esc" msgstr "Ctrl+Alt+&Esc" @@ -111,8 +111,8 @@ msgstr "Li&neaarinen interpolaatio" msgid "Hi&DPI scaling" msgstr "&Suuri DPI-skaalaus" -msgid "&Fullscreen\tCtrl+Alt+PgUp" -msgstr "&Koko näytön tila\tCtrl+Alt+PgUp" +msgid "&Fullscreen" +msgstr "&Koko näytön tila" msgid "Fullscreen &stretch mode" msgstr "Koko näytön &skaalaustila" @@ -186,8 +186,11 @@ msgstr "&Kokoonpano..." msgid "&Update status bar icons" msgstr "&Päivitä tilapalkin kuvakkeita" -msgid "Take s&creenshot\tCtrl+F11" -msgstr "Ota &kuvakaappaus\tCtrl+F11" +msgid "Take s&creenshot" +msgstr "Ota &kuvakaappaus" + +msgid "S&ound" +msgstr "&Ääni" msgid "&Preferences..." msgstr "&Sovellusasetukset..." @@ -198,11 +201,11 @@ msgstr "Käytä &Discord-integraatiota" msgid "Sound &gain..." msgstr "&Äänitasot..." -msgid "Begin trace\tCtrl+T" -msgstr "Aloita jäljitys\tCtrl+T" +msgid "Begin trace" +msgstr "Aloita jäljitys" -msgid "End trace\tCtrl+T" -msgstr "Lopeta jäljitys\tCtrl+T" +msgid "End trace" +msgstr "Lopeta jäljitys" msgid "&Help" msgstr "&Ohje" @@ -249,8 +252,8 @@ msgstr "&Mykistä" msgid "E&mpty" msgstr "&Tyhjä" -msgid "&Reload previous image" -msgstr "&Lataa edellinen levykuva uudelleen" +msgid "Reload previous image" +msgstr "Lataa edellinen levykuva uudelleen" msgid "&Folder..." msgstr "&Kansio..." @@ -306,18 +309,12 @@ msgstr "OK" msgid "Cancel" msgstr "Peruuta" -msgid "Save these settings as &global defaults" -msgstr "Tallenna nämä asetukset &globaaleiksi oletuksiksi" - msgid "&Default" msgstr "&Oletus" msgid "Language:" msgstr "Kieli:" -msgid "Icon set:" -msgstr "Kuvakkeet:" - msgid "Gain" msgstr "Taso" @@ -453,15 +450,6 @@ msgstr "Nuked (tarkempi)" msgid "YMFM (faster)" msgstr "YMFM (nopeampi)" -msgid "Network type:" -msgstr "Verkon tyyppi:" - -msgid "PCap device:" -msgstr "PCap-laite:" - -msgid "Network adapter:" -msgstr "Verkkokortti:" - msgid "COM1 Device:" msgstr "COM1-laite:" @@ -642,14 +630,11 @@ msgstr "Vakava virhe" msgid " - PAUSED" msgstr " - TAUKO" -msgid "Press Ctrl+Alt+PgDn to return to windowed mode." -msgstr "Paina Ctrl+Alt+PgDn palataksesi ikkunoituun tilaan." - msgid "Speed" msgstr "Nopeus" -msgid "ZIP %03i %i (%s): %ls" -msgstr "ZIP %03i %i (%s): %ls" +msgid "ZIP %1 %2 (%3): %4" +msgstr "ZIP %1 %2 (%3): %4" msgid "ZIP images" msgstr "ZIP-levykuvat" @@ -682,13 +667,16 @@ msgid "Surface images" msgstr "Pintalevykuvat" msgid "Machine \"%hs\" is not available due to missing ROMs in the roms/machines directory. Switching to an available machine." -msgstr "Konetta \"%hs\" ei voi käyttää puuttuvien ROM-tiedostojen vuoksi. Vaihdetaan käyttökelpoiseen koneeseen." +msgstr "Konetta \"%hs\" ei voi käyttää, koska roms/machines-hakemistosta puuttuvien ROM-tiedostojen vuoksi. Vaihdetaan käyttökelpoiseen koneeseen." msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Näytönohjainta \"%hs\" ei voi käyttää puuttuvien ROM-tiedostojen vuoksi. Vaihdetaan käyttökelpoiseen näytönohjaimeen." +msgstr "Näytönohjainta \"%hs\" ei voi käyttää, koska roms/machines-hakemistosta puuttuvien ROM-tiedostojen vuoksi. Vaihdetaan käyttökelpoiseen näytönohjaimeen." -msgid "Video card 2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Näytönohjainta 2 \"%hs\" ei voi käyttää puuttuvien ROM-tiedostojen vuoksi. Vaihdetaan käyttökelpoiseen näytönohjaimeen." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." +msgstr "Näytönohjainta 2 \"%hs\" ei voi käyttää, koska roms/machines-hakemistosta puuttuvien ROM-tiedostojen vuoksi. Toisen näytönohjaimen poistaminen käytöstä." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Laite \"%hs\" ei voi käyttää puuttuvien ROM-tiedostojen vuoksi. Laitteen huomiotta jättäminen." msgid "Machine" msgstr "Tietokone" @@ -750,14 +738,11 @@ msgstr "S" msgid "KB" msgstr "Kt" -msgid "Could not initialize the video renderer." -msgstr "Videorenderöijän alustus epäonnistui" - msgid "Default" msgstr "Oletus" -msgid "%i Wait state(s)" -msgstr "%i odotustilaa" +msgid "%1 Wait state(s)" +msgstr "%1 odotustilaa" msgid "Type" msgstr "Tyyppi" @@ -801,11 +786,11 @@ msgstr "Thrustmaster Flight Control System" msgid "None" msgstr "Ei mikään" -msgid "%u MB (CHS: %i, %i, %i)" -msgstr "%u Mt (CHS: %i, %i, %i)" +msgid "%1 MB (CHS: %2, %3, %4)" +msgstr "%1 Mt (CHS: %2, %3, %4)" -msgid "Floppy %i (%s): %ls" -msgstr "Levyke %i (%s): %ls" +msgid "Floppy %1 (%2): %3" +msgstr "Levyke %1 (%2): %3" msgid "Advanced sector images" msgstr "Kehittyneet sektorilevykuvat" @@ -825,8 +810,8 @@ msgstr "Ghostscriptin alustus epäonnistui" msgid "Unable to initialize GhostPCL" msgstr "GhostPCLin alustus epäonnistui" -msgid "MO %i (%ls): %ls" -msgstr "MO %i (%ls): %ls" +msgid "MO %1 (%2): %3" +msgstr "MO %1 (%2): %3" msgid "MO images" msgstr "MO-levykuvat" @@ -876,9 +861,6 @@ msgstr "%1 vaaditaan PostScript-tiedostojen automaattiseen muuntamiseen PDF-tied msgid "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PCL printer will be saved as Printer Command Language (.pcl) files." msgstr "%1 vaaditaan PCL-tiedostojen automaattiseen muuntamiseen PDF-tiedostoiksi.\n\nKaikki geneeriselle PCL-tulostimelle lähetetyt asiakirjat tallennetaan Printer Command Language (.ps) -tiedostoina." -msgid "Entering fullscreen mode" -msgstr "Siirrytään koko näytön tilaan" - msgid "Don't show this message again" msgstr "Älä näytä tätä viestiä uudelleen" @@ -900,11 +882,8 @@ msgstr "%1 - Laitteen määritykset" msgid "Monitor in sleep mode" msgstr "Näyttö lepotilassa" -msgid "OpenGL Shaders" -msgstr "OpenGL-varjostinohjelmat" - -msgid "OpenGL options" -msgstr "OpenGL-asetukset" +msgid "GLSL shaders" +msgstr "GLSL-varjostinohjelmat" msgid "You are loading an unsupported configuration" msgstr "Olet lataamassa ei-tuettuja määrittelyjä" @@ -915,24 +894,18 @@ msgstr "Valittuun tietokoneeseen perustuva suoritintyypin suodatus ei ole käyt msgid "Continue" msgstr "Jatka" -msgid "Cassette: %s" -msgstr "Kasetti: %s" +msgid "Cassette: %1" +msgstr "Kasetti: %1" msgid "Cassette images" msgstr "Kasettitiedostot" -msgid "Cartridge %i: %ls" -msgstr "ROM-moduuli %i: %ls" +msgid "Cartridge %1: %2" +msgstr "ROM-moduuli %1: %2" msgid "Cartridge images" msgstr "ROM-moduulikuvat" -msgid "Error initializing renderer" -msgstr "Virhe renderöijän alustuksessa" - -msgid "OpenGL (3.0 Core) renderer could not be initialized. Use another renderer." -msgstr "OpenGL (3.0 Core)-renderöijän alustus epäonnistui. Käytä toista renderöijää." - msgid "Resume execution" msgstr "Jatka suoritusta" @@ -1095,8 +1068,8 @@ msgstr "IDE" msgid "ATAPI" msgstr "ATAPI" -msgid "CD-ROM %i (%s): %s" -msgstr "CD-ROM %i (%s): %s" +msgid "CD-ROM %1 (%2): %3" +msgstr "CD-ROM %1 (%2): %3" msgid "160 KB" msgstr "160 Kt" @@ -1275,9 +1248,6 @@ msgstr "Tyhjennä kuvahistoria" msgid "Create..." msgstr "Luo..." -msgid "previous image" -msgstr "edellinen levykuva" - msgid "Host CD/DVD Drive (%1)" msgstr "Isäntä CD/DVD-asema (%1)" @@ -1287,23 +1257,8 @@ msgstr "Tuntematon väylä" msgid "Null Driver" msgstr "Nolla-ajuri" -msgid "NIC %02i (%ls) %ls" -msgstr "NIC %02i (%ls) %ls" - -msgid "Error opening \"%1\": %2" -msgstr "Virhe \"%1\" avaamisessa: %2" - -msgid "Error compiling vertex shader in file \"%1\"" -msgstr "Virhe vertex-shaderin kääntämisessä tiedostossa \"%1\"" - -msgid "Error compiling fragment shader in file \"%1\"" -msgstr "Virhe fragmenttivarjostimen kääntämisessä tiedostossa \"%1\"" - -msgid "Error linking shader program in file \"%1\"" -msgstr "Virhe varjostinohjelman linkittämisessä tiedostoon \"%1\"" - -msgid "OpenGL 3.0 renderer options" -msgstr "OpenGL 3.0-alustusasetukset" +msgid "NIC %1 (%2) %3" +msgstr "NIC %1 (%2) %3" msgid "Render behavior" msgstr "Renderöintikäyttäytyminen" @@ -1317,9 +1272,6 @@ msgstr " ruutua/s" msgid "VSync" msgstr "VSync" -msgid "<html><head/><body><p>Render each frame immediately, in sync with the emulated display.</p><p><span style=" font-style:italic;">This is the recommended option if the shaders in use don't utilize frametime for animated effects.</span></p></body></html>" -msgstr "<html><head/><body><p>Renderöi jokainen ruutu välittömästi synkronoidusti emuloidun näytön kanssa.</p><p><span style=" font-style:italic;">Tämä on suositeltava vaihtoehto, jos käytössä olevat varjostimet eivät käytä frametimeä animaatioefekteihin.</span></p></body></html>" - msgid "Synchronize with video" msgstr "Synkronisoi videoon" @@ -1335,15 +1287,6 @@ msgstr "Ei valittu varjostinohjelmatta" msgid "Browse..." msgstr "Selaa..." -msgid "Shader error" -msgstr "Varjostinohjelmatvirhe" - -msgid "Could not load shaders." -msgstr "Varjostinohjelmateita ei voitu ladata." - -msgid "More information in details." -msgstr "Lisätietoja yksityiskohtaisesti." - msgid "Couldn't create OpenGL context." msgstr "OpenGL-kontekstia ei voitu luoda." @@ -1353,20 +1296,14 @@ msgstr "Ei voitu siirtyä OpenGL-kontekstiin." msgid "OpenGL version 3.0 or greater is required. Current version is %1.%2" msgstr "Tarvitaan OpenGL-versio 3.0 tai uudempi. Nykyinen versio on %1.%2" -msgid "OpenGL initialization failed. Error %1." -msgstr "OpenGL:n alustaminen epäonnistui. Virhe %1." - msgid "Error initializing OpenGL" msgstr "Virhe OpenGL:n alustamisessa" -msgid "Falling back to software rendering.\n" -msgstr "Paluu ohjelmistoalustusöintiin.\n" +msgid "\nFalling back to software rendering." +msgstr "\nPaluu ohjelmistoalustusöintiin." -msgid "Allocating memory for unpack buffer failed.\n" -msgstr "Pakkauspuskurin muistin varaaminen epäonnistui.\n" - -msgid "<html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html>" -msgstr "<html><head/><body><p>Kun valitset mediakuvia (CD-ROM, levykkeet jne.), avausikkuna käynnistyy samaan hakemistoon kuin 86Boxin konfigurointitiedosto. Tällä asetuksella on todennäköisesti merkitystä vain macOS-käyttöjärjestelmässä.</p></body></html>" +msgid "

When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" +msgstr "

Kun valitset mediakuvia (CD-ROM, levykkeet jne.), avausikkuna käynnistyy samaan hakemistoon kuin 86Boxin konfigurointitiedosto. Tällä asetuksella on todennäköisesti merkitystä vain macOS-käyttöjärjestelmässä.

" msgid "This machine might have been moved or copied." msgstr "Kone on saatettu siirtää tai kopioida." @@ -1401,17 +1338,17 @@ msgstr "Verkkokortti 3" msgid "Network Card #4" msgstr "Verkkokortti 4" -msgid "Mode" -msgstr "Tila" +msgid "Mode:" +msgstr "Tila:" -msgid "Interface" -msgstr "Liitäntä" +msgid "Interface:" +msgstr "Liitäntä:" -msgid "Adapter" -msgstr "Sovitin" +msgid "Adapter:" +msgstr "Sovitin:" -msgid "VDE Socket" -msgstr "VDE-pistorasia" +msgid "VDE Socket:" +msgstr "VDE-pistorasia:" msgid "86Box Unit Tester" msgstr "86Box Unit Tester" @@ -1431,9 +1368,6 @@ msgstr "Sarjaportin läpivienti 3" msgid "Serial port passthrough 4" msgstr "Sarjaportin läpivienti 4" -msgid "Vision Systems LBA Enhancer" -msgstr "Vision Systems LBA Enhancer" - msgid "Renderer options..." msgstr "Alustusasetukset..." @@ -1872,6 +1806,9 @@ msgstr "Pyörä" msgid "Five + Wheel" msgstr "Viisi + pyörä" +msgid "Five + 2 Wheels" +msgstr "" + msgid "A3 - SMT2 Serial / SMT3(R)V" msgstr "A3 - SMT2 sarja / SMT3(R)V" @@ -2100,8 +2037,8 @@ msgstr "Nimetty putki (palvelin)" msgid "Host Serial Passthrough" msgstr "Isännän sarjaportin läpivienti" -msgid "Eject %s" -msgstr "Poista kasettipesästä %s" +msgid "E&ject %1" +msgstr "&Poista kasettipesästä %1" msgid "&Unmute" msgstr "&Poista mykistys" @@ -2112,11 +2049,104 @@ msgstr "Softfloat FPU" msgid "High performance impact" msgstr "Suuri vaikutus suorituskykyyn" -msgid "RAM Disk (max. speed)" -msgstr "RAM-levy (maksiminopeus)" +msgid "[Generic] RAM Disk (max. speed)" +msgstr "[Generic] RAM-levy (maksiminopeus)" + +msgid "[Generic] 1989 (3500 RPM)" +msgstr "" + +msgid "[Generic] 1992 (3600 RPM)" +msgstr "" + +msgid "[Generic] 1994 (4500 RPM)" +msgstr "" + +msgid "[Generic] 1996 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1997 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1998 (5400 RPM)" +msgstr "" + +msgid "[Generic] 2000 (7200 RPM)" +msgstr "" msgid "IBM 8514/A clone (ISA)" msgstr "IBM 8514/A-klooni (ISA)" msgid "Vendor" msgstr "Valmistaja" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Yleinen PC/XT-muistilaajennus" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Yleinen PC/AT-muistilaajennus" + +msgid "Unable to find Dot-Matrix fonts" +msgstr "Pistematriisifontteja ei löydy" + +msgid "TrueType fonts in the \"roms/printer/fonts\" directory are required for the emulation of the Generic ESC/P Dot-Matrix Printer." +msgstr "TrueType-fontteja kansiossa \"roms/printer/fonts\"-hakemistoon yleinen ESC/P pistematriisitulostin emulointiin." + +msgid "Inhibit multimedia keys" +msgstr "" + +msgid "Ask for confirmation before saving settings" +msgstr "" + +msgid "Ask for confirmation before hard resetting" +msgstr "" + +msgid "Ask for confirmation before quitting" +msgstr "" + +msgid "Options" +msgstr "" + +msgid "Model" +msgstr "" + +msgid "Model:" +msgstr "" + +msgid "Failed to initialize Vulkan renderer." +msgstr "" + +msgid "GLSL Error" +msgstr "" + +msgid "Could not load shader: %1" +msgstr "" + +msgid "OpenGL version 3.0 or greater is required. Current GLSL version is %1.%2" +msgstr "" + +msgid "Could not load texture: %1" +msgstr "" + +msgid "Could not compile shader:\n\n%1" +msgstr "" + +msgid "Program not linked:\n\n%1" +msgstr "" + +msgid "Shader Manager" +msgstr "" + +msgid "Shader Configuration" +msgstr "" + +msgid "Add" +msgstr "" + +msgid "Move up" +msgstr "" + +msgid "Move down" +msgstr "" + +msgid "Could not load file %1" +msgstr "" diff --git a/src/qt/languages/fr-FR.po b/src/qt/languages/fr-FR.po index c8e4aa6cd..87530590a 100644 --- a/src/qt/languages/fr-FR.po +++ b/src/qt/languages/fr-FR.po @@ -18,8 +18,8 @@ msgstr "CTRL &Droite devient ALT Gauche" msgid "&Hard Reset..." msgstr "&Hard Reset..." -msgid "&Ctrl+Alt+Del\tCtrl+F12" -msgstr "&Ctrl+Alt+Del\tCtrl+F12" +msgid "&Ctrl+Alt+Del" +msgstr "&Ctrl+Alt+Del" msgid "Ctrl+Alt+&Esc" msgstr "Ctrl+Alt+&Esc" @@ -37,10 +37,10 @@ msgid "&Hide status bar" msgstr "&Masquer la barre de status" msgid "Hide &toolbar" -msgstr "Hide &toolbar" +msgstr "Masquer la &barre d'outils" msgid "&Resizeable window" -msgstr "Fenètre &Retaillable" +msgstr "Fenêtre &Redimensionnable" msgid "R&emember size && position" msgstr "S&auvegarder taille && position" @@ -61,7 +61,7 @@ msgid "&VNC" msgstr "&VNC" msgid "Specify dimensions..." -msgstr "Specifier dimensions..." +msgstr "Spécifier dimensions..." msgid "F&orce 4:3 display ratio" msgstr "F&orcer 4:3" @@ -100,7 +100,7 @@ msgid "&8x" msgstr "&8x" msgid "Filter method" -msgstr "Methode Filtre" +msgstr "Méthode Filtre" msgid "&Nearest" msgstr "&Plus proche" @@ -111,8 +111,8 @@ msgstr "&Lineaire" msgid "Hi&DPI scaling" msgstr "Mise à l'échelle Hi&DPI" -msgid "&Fullscreen\tCtrl+Alt+PgUp" -msgstr "&Plein Ecran\tCtrl+Alt+PgUp" +msgid "&Fullscreen" +msgstr "&Plein Ecran" msgid "Fullscreen &stretch mode" msgstr "Mode &Elargi plein écran" @@ -157,7 +157,7 @@ msgid "&White monitor" msgstr "Moniteur &Blanc" msgid "Grayscale &conversion type" -msgstr "Grayscale &conversion type" +msgstr "Mode &Conversion tons de gris" msgid "BT&601 (NTSC/PAL)" msgstr "BT&601 (NTSC/PAL)" @@ -169,7 +169,7 @@ msgid "&Average" msgstr "&Moyenne" msgid "CGA/PCjr/Tandy/E&GA/(S)VGA overscan" -msgstr "CGA/PCjr/Tandy/E&GA/(S)VGA overscan" +msgstr "Overscan CGA/PCjr/Tandy/E&GA/(S)VGA" msgid "Change contrast for &monochrome display" msgstr "Modifier contraste affichage &monochrome" @@ -186,8 +186,11 @@ msgstr "&Réglages..." msgid "&Update status bar icons" msgstr "Mettre à jour la barre de stat&us" -msgid "Take s&creenshot\tCtrl+F11" -msgstr "Copie &Ecran\tCtrl+F11" +msgid "Take s&creenshot" +msgstr "Copie &Ecran" + +msgid "S&ound" +msgstr "S&on" msgid "&Preferences..." msgstr "&Préférences..." @@ -198,11 +201,11 @@ msgstr "Activer intégration &Discord" msgid "Sound &gain..." msgstr "&Gain Son..." -msgid "Begin trace\tCtrl+T" -msgstr "Démarrer traces\tCtrl+T" +msgid "Begin trace" +msgstr "Démarrer traces" -msgid "End trace\tCtrl+T" -msgstr "Finir traces\tCtrl+T" +msgid "End trace" +msgstr "Arrêter traces" msgid "&Help" msgstr "&Aide" @@ -220,7 +223,7 @@ msgid "&Existing image..." msgstr "Image &Existante..." msgid "Existing image (&Write-protected)..." -msgstr "Image Existante(&Lecture seule)..." +msgstr "Image Existante (&Lecture seule)..." msgid "&Record" msgstr "En®istrer" @@ -235,13 +238,13 @@ msgid "&Fast forward to the end" msgstr "Aller à la &Fin" msgid "E&ject" -msgstr "E&jecter" +msgstr "É&jecter" msgid "&Image..." msgstr "&Image..." msgid "E&xport to 86F..." -msgstr "E&xport vers 86F..." +msgstr "E&xporter vers 86F..." msgid "&Mute" msgstr "&Couper" @@ -249,8 +252,8 @@ msgstr "&Couper" msgid "E&mpty" msgstr "E&jecter" -msgid "&Reload previous image" -msgstr "&Recharger image précedente" +msgid "Reload previous image" +msgstr "Recharger image précedente" msgid "&Folder..." msgstr "&Dossier..." @@ -298,7 +301,7 @@ msgid "Settings" msgstr "Réglages" msgid "Specify Main Window Dimensions" -msgstr "Spécifier le détournement de la fenêtre principale" +msgstr "Spécifier les dimensions de la fenêtre principale" msgid "OK" msgstr "OK" @@ -306,18 +309,12 @@ msgstr "OK" msgid "Cancel" msgstr "Annuler" -msgid "Save these settings as &global defaults" -msgstr "Sauvegarder ces paramètres comme valeurs par défaut &globales" - msgid "&Default" msgstr "&Défaut" msgid "Language:" msgstr "Langue:" -msgid "Icon set:" -msgstr "Ensemble d'icônes:" - msgid "Gain" msgstr "Gain" @@ -352,7 +349,7 @@ msgid "Configure" msgstr "Configurer" msgid "CPU type:" -msgstr "Type du processeur:" +msgstr "Type de processeur:" msgid "Speed:" msgstr "Vitesse:" @@ -406,7 +403,7 @@ msgid "Mouse:" msgstr "Souris:" msgid "Joystick:" -msgstr "Manette de commande:" +msgstr "Manette:" msgid "Joystick 1..." msgstr "Manette 1..." @@ -453,15 +450,6 @@ msgstr "Nuked (plus précis)" msgid "YMFM (faster)" msgstr "YMFM (plus rapide)" -msgid "Network type:" -msgstr "Type de réseau:" - -msgid "PCap device:" -msgstr "Dispositif PCap:" - -msgid "Network adapter:" -msgstr "Adaptateur de réseau:" - msgid "COM1 Device:" msgstr "Dispositif COM1:" @@ -610,7 +598,7 @@ msgid "ISA RTC:" msgstr "Horloge temps réel ISA:" msgid "ISA Memory Expansion" -msgstr "Expansion de la mémoire ISA" +msgstr "Extension de mémoire ISA" msgid "Card 1:" msgstr "Carte 1:" @@ -642,14 +630,11 @@ msgstr "Erreur fatale" msgid " - PAUSED" msgstr " - EN PAUSE" -msgid "Press Ctrl+Alt+PgDn to return to windowed mode." -msgstr "Appuyez sur Ctrl+Alt+PgDn pour revenir au mode fenêtré." - msgid "Speed" msgstr "Vitesse" -msgid "ZIP %03i %i (%s): %ls" -msgstr "ZIP %03i %i (%s): %ls" +msgid "ZIP %1 %2 (%3): %4" +msgstr "ZIP %1 %2 (%3): %4" msgid "ZIP images" msgstr "Images ZIP" @@ -673,7 +658,7 @@ msgid "Off" msgstr "Désactivé" msgid "All images" -msgstr "Tous les images" +msgstr "Toutes les images" msgid "Basic sector images" msgstr "Images basiques du secteur" @@ -687,8 +672,11 @@ msgstr "La machine \"%hs\" n'est pas disponible en raison de l'absence de ROMs d msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "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." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "La carte vidéo 2 \"%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." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "La carte vidéo 2 \"%hs\" n'est pas disponible en raison de l'absence de ROMs dans le répertoire roms/video. Désactiver la deuxième carte vidéo." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Le dispositif \"%hs\" n'est pas disponible en raison de l'absence de ROMs. Ignorer le dispositif." msgid "Machine" msgstr "Machine" @@ -750,14 +738,11 @@ msgstr "S" msgid "KB" msgstr "Ko" -msgid "Could not initialize the video renderer." -msgstr "Impossible d'initialiser le moteur de rendu vidéo." - msgid "Default" msgstr "Défaut" -msgid "%i Wait state(s)" -msgstr "%i état(s) d'attente" +msgid "%1 Wait state(s)" +msgstr "%1 état(s) d'attente" msgid "Type" msgstr "Type" @@ -801,11 +786,11 @@ msgstr "Système de contrôle de vol Thrustmaster" msgid "None" msgstr "Aucun" -msgid "%u MB (CHS: %i, %i, %i)" -msgstr "%u Mo (CTS: %i, %i, %i)" +msgid "%1 MB (CHS: %2, %3, %4)" +msgstr "%1 Mo (CTS: %2, %3, %4)" -msgid "Floppy %i (%s): %ls" -msgstr "Disquette %i (%s): %ls" +msgid "Floppy %1 (%2): %3" +msgstr "Disquette %1 (%2): %3" msgid "Advanced sector images" msgstr "Images du secteur avancés" @@ -825,8 +810,8 @@ msgstr "Impossible d'initialiser Ghostscript" msgid "Unable to initialize GhostPCL" msgstr "Impossible d'initialiser GhostPCL" -msgid "MO %i (%ls): %ls" -msgstr "Magnéto-optique %i (%ls): %ls" +msgid "MO %1 (%2): %3" +msgstr "Magnéto-optique %1 (%2): %3" msgid "MO images" msgstr "Images magnéto-optiques" @@ -865,19 +850,16 @@ msgid "Hardware not available" msgstr "Matériel non disponible" msgid "Make sure %1 is installed and that you are on a %1-compatible network connection." -msgstr "Assurez-vous que %1 est installé et que vou utilisez une connexion réseau compatible avec %1." +msgstr "Assurez-vous que %1 est installé et que vous utilisez une connexion réseau compatible avec %1." msgid "Invalid configuration" msgstr "Configuration non valide" msgid "%1 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 "%1 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)." +msgstr "%1 est nécessaire pour la conversion automatique des fichiers PostScript en PDF.\n\nTous les documents envoyés à l'imprimante générique PostScript seront sauvés en tant que fichiers PostScript (.ps)." msgid "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PCL printer will be saved as Printer Command Language (.pcl) files." -msgstr "%1 est nécessair pour la conversion automatique des fichiers PCL dans PDF.\n\nTous les documents envoyés à l'imprimante générique PCL seront sauvés comme des fichiers Printer Command Language (.pcl)." - -msgid "Entering fullscreen mode" -msgstr "Entrer en mode plein écran" +msgstr "%1 est nécessaire pour la conversion automatique des fichiers PCL en PDF.\n\nTous les documents envoyés à l'imprimante générique PCL seront sauvés en tant quefichiers Printer Command Language (.pcl)." msgid "Don't show this message again" msgstr "Ne pas montrer ce message à nouveau" @@ -900,39 +882,30 @@ msgstr "Configuration du dispositif %1" msgid "Monitor in sleep mode" msgstr "Moniteur en mode veille" -msgid "OpenGL Shaders" -msgstr "Shaders OpenGL" - -msgid "OpenGL options" -msgstr "Options OpenGL" +msgid "GLSL shaders" +msgstr "Shaders GLSL" msgid "You are loading an unsupported configuration" msgstr "Vous chargez une configuration non prise en charge" 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 "La filtrage du type du processeur sur la base de la machine sélectionné est désactivé pur cette machine émulée.\n\nCela permet de sélectionner une processeur que est sinon incompatible avec la machine sélectionné. Cependant, il pourrait y avoir des incompatibilités avec le BIOS de la machine ou autres logiciels.\n\nL'activatione de cette configuration non est officiellement prise en charge et tout rapport de bogue peut être fermé comme étant invalide." +msgstr "Le filtrage du type du processeur sur la base de la machine sélectionnée est désactivé pur cette machine émulée.\n\nCela permet de sélectionner un processeur qui est sinon incompatible avec la machine sélectionné. Cependant, il pourrait y avoir des incompatibilités avec le BIOS de la machine ou autres logiciels.\n\nL'activation de cette configuration non officiellement prise en charge implique que tout rapport de bogue peut être fermé comme étant invalide." msgid "Continue" msgstr "Continuer" -msgid "Cassette: %s" -msgstr "Cassette: %s" +msgid "Cassette: %1" +msgstr "Cassette: %1" msgid "Cassette images" msgstr "Images cassette" -msgid "Cartridge %i: %ls" -msgstr "Cartouche %i: %ls" +msgid "Cartridge %1: %2" +msgstr "Cartouche %1: %2" msgid "Cartridge images" msgstr "Images cartouche" -msgid "Error initializing renderer" -msgstr "Erreur d'initialisation du moteur de rendu" - -msgid "OpenGL (3.0 Core) renderer could not be initialized. Use another renderer." -msgstr "Le moteur de rendu OpenGL (3.0 Core) n'a pas pu être initialisé. Utilisez un autre moteur de rendu." - msgid "Resume execution" msgstr "Reprendre l'exécution" @@ -940,7 +913,7 @@ msgid "Pause execution" msgstr "Pause de l'exécution" msgid "Press Ctrl+Alt+Del" -msgstr "Appuyer sur Ctrl+Alt+Suppr." +msgstr "Appuyer sur Ctrl+Alt+Suppr" msgid "Press Ctrl+Alt+Esc" msgstr "Appuyer sur Ctrl+Alt+Esc" @@ -970,13 +943,13 @@ msgid "Add Existing Hard Disk" msgstr "Ajouter un disque dur existant" msgid "HDI disk images cannot be larger than 4 GB." -msgstr "Les images de disque HDI ne peuvent pas avoir une taille supériure à Go." +msgstr "Les images de disque HDI ne peuvent pas avoir une taille supérieure à 4 Go." msgid "Disk images cannot be larger than 127 GB." -msgstr "Les images de disque ne peuvent pas avoir un taille supérieure à 127 Go." +msgstr "Les images de disque ne peuvent pas avoir une taille supérieure à 127 Go." msgid "Hard disk images" -msgstr "Images de dique dur" +msgstr "Images de disque dur" msgid "Unable to read file" msgstr "Impossible de lire le fichier" @@ -985,10 +958,10 @@ msgid "Unable to write file" msgstr "Impossible d'écrire le fichier" msgid "HDI or HDX images with a sector size other than 512 are not supported." -msgstr "Les images HDI ou HDX avec une taille de secteur différente de 512 non sont pas prises en charge." +msgstr "Les images HDI ou HDX avec une taille de secteur différente de 512 ne sont pas prises en charge." msgid "Disk image file already exists" -msgstr "Le fichier de l'image disque existe déjà." +msgstr "Le fichier de l'image disque existe déjà" msgid "Please specify a valid file name." msgstr "Veuillez spécifier un nom de fichier valide." @@ -1060,10 +1033,10 @@ msgid "Differencing VHD (.vhd)" msgstr "VHD à différenciation (.vhd)" msgid "Large blocks (2 MB)" -msgstr "Blocs grands (2 Mo)" +msgstr "Grands Blocs (2 Mo)" msgid "Small blocks (512 KB)" -msgstr "Blocs petits (512 Ko)" +msgstr "Petits Blocs (512 Ko)" msgid "VHD files" msgstr "Fichiers VHD" @@ -1072,10 +1045,10 @@ msgid "Select the parent VHD" msgstr "Sélectionnez le VHD parent" 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 "Il est possible que l'image parente a été modifié après la création de l'image à différenciation.\n\nIl est même possible que les fichiers de l'mage ont été déplacés ou copiés ou il existe un bogue dans le programme que a créé ce disque.\n\nVoulez-vous réparer l'horodatage?" +msgstr "Il est possible que l'image parente ai été modifiée après la création de l'image à différenciation.\n\nIl est même possible que les fichiers de l’image ont été déplacés ou copiés ou il existe un bogue dans le programme qui a créé ce disque.\n\nVoulez-vous réparer l'horodatage?" msgid "Parent and child disk timestamps do not match" -msgstr "Les horodatages des disques parent et enfant ne correspondent pas" +msgstr "Les horodatages des disques parents et enfants ne correspondent pas" msgid "Could not fix VHD timestamp." msgstr "Impossible de réparer l'horodatage du VHD." @@ -1095,8 +1068,8 @@ msgstr "IDE" msgid "ATAPI" msgstr "ATAPI" -msgid "CD-ROM %i (%s): %s" -msgstr "CD-ROM %i (%s): %s" +msgid "CD-ROM %1 (%2): %3" +msgstr "CD-ROM %1 (%2): %3" msgid "160 KB" msgstr "160 Ko" @@ -1186,7 +1159,7 @@ msgid "Failed to initialize network driver" msgstr "Échec de l'initialisation du pilote réseau" msgid "The network configuration will be switched to the null driver" -msgstr "La configuration du réseau passera au pilote nul" +msgstr "La configuration du réseau passera au pilote NULL" msgid "Mouse sensitivity:" msgstr "Sensibilité de la souris:" @@ -1207,7 +1180,7 @@ msgid "Fast" msgstr "Rapide" msgid "&Auto-pause on focus loss" -msgstr "&Pause automatique à perte de mise au point" +msgstr "&Pause automatique à perte de focus" msgid "WinBox is no longer supported" msgstr "WinBox n'est plus pris en charge" @@ -1237,13 +1210,13 @@ msgid "List of MCA devices:" msgstr "Liste des dispositifs MCA :" msgid "Tablet tool" -msgstr "Nástroj pro tablety" +msgstr "Outil Tablette" msgid "Qt (OpenGL &ES)" msgstr "Qt (OpenGL &ES)" msgid "About Qt" -msgstr "O programu Qt" +msgstr "A propos de Qt" msgid "MCA devices..." msgstr "Dispositifs MCA..." @@ -1275,9 +1248,6 @@ msgstr "Effacer l'historique de l'image" msgid "Create..." msgstr "Créer..." -msgid "previous image" -msgstr "image précedente" - msgid "Host CD/DVD Drive (%1)" msgstr "Lecteur CD/DVD hôte (%1)" @@ -1285,25 +1255,10 @@ msgid "Unknown Bus" msgstr "Bus inconnu" msgid "Null Driver" -msgstr "Pilote nul" +msgstr "Pilote NULL" -msgid "NIC %02i (%ls) %ls" -msgstr "NIC %02i (%ls) %ls" - -msgid "Error opening \"%1\": %2" -msgstr "Erreur d'ouverture de \"%1\" : %2" - -msgid "Error compiling vertex shader in file \"%1\"" -msgstr "Erreur de compilation du vertex shader dans le fichier \"%1\"" - -msgid "Error compiling fragment shader in file \"%1\"" -msgstr "Erreur de compilation du fragment shader dans le fichier \"%1\"" - -msgid "Error linking shader program in file \"%1\"" -msgstr "Erreur de liaison du programme shader dans le fichier \"%1\"" - -msgid "OpenGL 3.0 renderer options" -msgstr "Options de rendu OpenGL 3.0" +msgid "NIC %1 (%2) %3" +msgstr "NIC %1 (%2) %3" msgid "Render behavior" msgstr "Comportement de rendu" @@ -1312,14 +1267,11 @@ msgid "Use target framerate:" msgstr "Utiliser le taux de rafraîchissement cible:" msgid " fps" -msgstr " mages par seconde" +msgstr " Images par seconde" msgid "VSync" msgstr "VSync" -msgid "<html><head/><body><p>Render each frame immediately, in sync with the emulated display.</p><p><span style=" font-style:italic;">This is the recommended option if the shaders in use don't utilize frametime for animated effects.</span></p></body></html>" -msgstr "<html><head/><body><p>Rendre chaque image immédiatement, en synchronisation avec l'affichage émulé.</p><p><span style=" font-style:italic;">C'est l'option recommandée si les shaders utilisés n'utilisent pas le frametime pour les effets animés.</span></p></body></html>" - msgid "Synchronize with video" msgstr "Synchronisation avec la vidéo" @@ -1329,21 +1281,9 @@ msgstr "Shaders" msgid "Remove" msgstr "Retirer" -msgid "No shader selected" -msgstr "Pas de shader sélectionné" - msgid "Browse..." msgstr "Parcourir..." -msgid "Shader error" -msgstr "Erreur de shader" - -msgid "Could not load shaders." -msgstr "Impossible de charger les shaders." - -msgid "More information in details." -msgstr "Plus d'informations dans les détails." - msgid "Couldn't create OpenGL context." msgstr "Impossible de créer un contexte OpenGL." @@ -1353,20 +1293,14 @@ msgstr "Impossible de passer au contexte OpenGL." msgid "OpenGL version 3.0 or greater is required. Current version is %1.%2" msgstr "La version 3.0 ou supérieure d'OpenGL est requise. La version actuelle est %1.%2" -msgid "OpenGL initialization failed. Error %1." -msgstr "L'initialisation d'OpenGL a échoué. Erreur %1." - msgid "Error initializing OpenGL" msgstr "Erreur d'initialisation d'OpenGL" -msgid "Falling back to software rendering.\n" -msgstr "Se rabattre sur le rendu logiciel.\n" +msgid "\nFalling back to software rendering." +msgstr "\nSe rabattre sur le rendu logiciel." -msgid "Allocating memory for unpack buffer failed.\n" -msgstr "L'allocation de mémoire pour le tampon de décompression a échoué.\n" - -msgid "<html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html>" -msgstr "<html><head/><body><p>Lors de la sélection d'images multimédia (CD-ROM, disquette, etc.), la boîte de dialogue d'ouverture démarrera dans le même répertoire que le fichier de configuration de 86Box. Ce paramètre ne fera probablement une différence que sur macOS.</p></body></html>" +msgid "

When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" +msgstr "

Lors de la sélection d'images multimédia (CD-ROM, disquette, etc.), la boîte de dialogue d'ouverture démarrera dans le même répertoire que le fichier de configuration de 86Box. Ce paramètre ne fera probablement une différence que sur macOS.

" msgid "This machine might have been moved or copied." msgstr "Cette machine peut avoir été déplacée ou copiée." @@ -1381,7 +1315,7 @@ msgid "I Copied It" msgstr "Je l'ai copié" msgid "86Box Monitor #" -msgstr "Moniteur 86Box " +msgstr "Moniteur 86Box" msgid "No MCA devices." msgstr "Pas de dispositifs MCA." @@ -1401,17 +1335,17 @@ msgstr "Carte réseau 3" msgid "Network Card #4" msgstr "Carte réseau 4" -msgid "Mode" -msgstr "Mode" +msgid "Mode:" +msgstr "Mode:" -msgid "Interface" -msgstr "Interface" +msgid "Interface:" +msgstr "Interface:" -msgid "Adapter" -msgstr "Adaptateur" +msgid "Adapter:" +msgstr "Adaptateur:" -msgid "VDE Socket" -msgstr "Prise VDE" +msgid "VDE Socket:" +msgstr "Prise VDE:" msgid "86Box Unit Tester" msgstr "Testeur d'unité de 86Box" @@ -1431,9 +1365,6 @@ msgstr "Passage du port série 3" msgid "Serial port passthrough 4" msgstr "Passage du port série 4" -msgid "Vision Systems LBA Enhancer" -msgstr "Vision Systems LBA Enhancer" - msgid "Renderer options..." msgstr "Options de rendu..." @@ -1675,7 +1606,7 @@ msgid "Enable Game port" msgstr "Activer le port de jeu" msgid "Surround module" -msgstr "Module d'ambiance" +msgstr "Module Surround" msgid "CODEC" msgstr "CODEC" @@ -1872,6 +1803,9 @@ msgstr "Molette" msgid "Five + Wheel" msgstr "Cinq + molette" +msgid "Five + 2 Wheels" +msgstr "" + msgid "A3 - SMT2 Serial / SMT3(R)V" msgstr "A3 - SMT2 série / SMT3(R)V" @@ -1900,7 +1834,7 @@ msgid "2 MB" msgstr "2 Mo" msgid "8 MB" -msgstr " 8 Mo" +msgstr "8 Mo" msgid "28 MB" msgstr "28 Mo" @@ -2056,10 +1990,10 @@ msgid "Stereo LPT DAC" msgstr "Convertisseur numérique stéréo LPT" msgid "Generic Text Printer" -msgstr "Imprimante de texte générique" +msgstr "Imprimante Texte générique" msgid "Generic ESC/P Dot-Matrix Printer" -msgstr "Imprimant générique ESC/P à matrice à points" +msgstr "Imprimante matricielle générique ESC/P" msgid "Generic PostScript Printer" msgstr "Imprimante PostScript générique" @@ -2100,8 +2034,8 @@ msgstr "Tuyau nommé (serveur)" msgid "Host Serial Passthrough" msgstr "Passage du port série de l'hôte" -msgid "Eject %s" -msgstr "Éjecter %s" +msgid "E&ject %1" +msgstr "É&jecter %1" msgid "&Unmute" msgstr "&Réactiver son" @@ -2112,11 +2046,104 @@ msgstr "FPU Softfloat" msgid "High performance impact" msgstr "Impact important sur la performance" -msgid "RAM Disk (max. speed)" -msgstr "Disque RAM (vitesse maximale)" +msgid "[Generic] RAM Disk (max. speed)" +msgstr "[Generic] Disque RAM (vitesse maximale)" + +msgid "[Generic] 1989 (3500 RPM)" +msgstr "[Generic] 1989 (3500 RPM)" + +msgid "[Generic] 1992 (3600 RPM)" +msgstr "[Generic] 1992 (3600 RPM)" + +msgid "[Generic] 1994 (4500 RPM)" +msgstr "[Generic] 1994 (4500 RPM)" + +msgid "[Generic] 1996 (5400 RPM)" +msgstr "[Generic] 1996 (5400 RPM)" + +msgid "[Generic] 1997 (5400 RPM)" +msgstr "[Generic] 1997 (5400 RPM)" + +msgid "[Generic] 1998 (5400 RPM)" +msgstr "[Generic] 1998 (5400 RPM)" + +msgid "[Generic] 2000 (7200 RPM)" +msgstr "[Generic] 2000 (7200 RPM)" msgid "IBM 8514/A clone (ISA)" -msgstr "Clon IBM 8514/A (ISA)" +msgstr "Clone IBM 8514/A (ISA)" msgid "Vendor" msgstr "Fabricant" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Extension de mémoire générique PC/XT" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Extension de mémoire générique PC/AT" + +msgid "Unable to find Dot-Matrix fonts" +msgstr "Impossible de trouver les polices matricielles" + +msgid "TrueType fonts in the \"roms/printer/fonts\" directory are required for the emulation of the Generic ESC/P Dot-Matrix Printer." +msgstr "Les polices TrueType dans le répertoire \"roms/printer/fonts\" sont nécessaires à l'émulation de l'imprimante générique ESC/P matricielle." + +msgid "Inhibit multimedia keys" +msgstr "Désactiver les touches multimédia" + +msgid "Ask for confirmation before saving settings" +msgstr "Demander confirmation avant de sauvegarder les réglages" + +msgid "Ask for confirmation before hard resetting" +msgstr "Demander confirmation avant Hard Reset" + +msgid "Ask for confirmation before quitting" +msgstr "Demander confirmation avant de quitter" + +msgid "Options" +msgstr "Options" + +msgid "Model" +msgstr "Modèle" + +msgid "Model:" +msgstr "Modèle:" + +msgid "Failed to initialize Vulkan renderer." +msgstr "Impossible d’initialiser le moteur de rendu Vulkan." + +msgid "GLSL Error" +msgstr "Erreur GLSL" + +msgid "Could not load shader: %1" +msgstr "Impossible de charger le shaker %1" + +msgid "OpenGL version 3.0 or greater is required. Current GLSL version is %1.%2" +msgstr "OpenGL version 3.0 ou supérieur requis. Version installée: %1.%2" + +msgid "Could not load texture: %1" +msgstr "Impossible de charger la texture %1" + +msgid "Could not compile shader:\n\n%1" +msgstr "Impossible de compiler le shader:\n\n%1" + +msgid "Program not linked:\n\n%1" +msgstr "Programme non linké:\n\n%1" + +msgid "Shader Manager" +msgstr "Gestionnaire de shader" + +msgid "Shader Configuration" +msgstr "Configuration Shader" + +msgid "Add" +msgstr "Ajouter" + +msgid "Move up" +msgstr "Monter" + +msgid "Move down" +msgstr "Descendre" + +msgid "Could not load file %1" +msgstr "Impossible de charger le fichier %1" diff --git a/src/qt/languages/hr-HR.po b/src/qt/languages/hr-HR.po index c1c76f468..0330cd59a 100644 --- a/src/qt/languages/hr-HR.po +++ b/src/qt/languages/hr-HR.po @@ -18,8 +18,8 @@ msgstr "&Desni CTRL je lijevi ALT" msgid "&Hard Reset..." msgstr "&Ponovno pokretanje..." -msgid "&Ctrl+Alt+Del\tCtrl+F12" -msgstr "&Ctrl+Alt+Del\tCtrl+F12" +msgid "&Ctrl+Alt+Del" +msgstr "&Ctrl+Alt+Del" msgid "Ctrl+Alt+&Esc" msgstr "Ctrl+Alt+&Esc" @@ -111,8 +111,8 @@ msgstr "&Linearna" msgid "Hi&DPI scaling" msgstr "&HiDPI skaliranje" -msgid "&Fullscreen\tCtrl+Alt+PgUp" -msgstr "&Cijelozaslonski način\tCtrl+Alt+PgUp" +msgid "&Fullscreen" +msgstr "&Cijelozaslonski način" msgid "Fullscreen &stretch mode" msgstr "&Način cijelozaslonskog rastezanja" @@ -186,8 +186,11 @@ msgstr "&Opcije..." msgid "&Update status bar icons" msgstr "&Ažuriraj ikone statusnog redka" -msgid "Take s&creenshot\tCtrl+F11" -msgstr "Napravi &snimku zaslona\tCtrl+F11" +msgid "Take s&creenshot" +msgstr "Napravi &snimku zaslona" + +msgid "S&ound" +msgstr "&Zvuk" msgid "&Preferences..." msgstr "&Postavke..." @@ -198,11 +201,11 @@ msgstr "Omogući integraciju sa programom &Discord" msgid "Sound &gain..." msgstr "&Pojačavanje zvuka..." -msgid "Begin trace\tCtrl+T" -msgstr "Z&apočni praćenje\tCtrl+T" +msgid "Begin trace" +msgstr "Z&apočni praćenje" -msgid "End trace\tCtrl+T" -msgstr "&Svrši praćenje\tCtrl+T" +msgid "End trace" +msgstr "&Svrši praćenje" msgid "&Help" msgstr "&Pomoć" @@ -249,8 +252,8 @@ msgstr "&Isključi zvuk" msgid "E&mpty" msgstr "&Prazno" -msgid "&Reload previous image" -msgstr "&Ponovo učitaj prethodnu sliku" +msgid "Reload previous image" +msgstr "Ponovo učitaj prethodnu sliku" msgid "&Folder..." msgstr "&Mapa..." @@ -306,18 +309,12 @@ msgstr "U redu" msgid "Cancel" msgstr "Otkaži" -msgid "Save these settings as &global defaults" -msgstr "Spremite ove postavke kao &globalne zadane postavke" - msgid "&Default" msgstr "Zadano" msgid "Language:" msgstr "Jezik:" -msgid "Icon set:" -msgstr "Paket ikona:" - msgid "Gain" msgstr "Pojačavanje" @@ -453,15 +450,6 @@ msgstr "Nuked (precizniji)" msgid "YMFM (faster)" msgstr "YMFM (brži)" -msgid "Network type:" -msgstr "Tip mreže:" - -msgid "PCap device:" -msgstr "Uređaj PCap:" - -msgid "Network adapter:" -msgstr "Mrežna kartica:" - msgid "COM1 Device:" msgstr "Uređaj COM1:" @@ -642,20 +630,17 @@ msgstr "Fatalna greška" msgid " - PAUSED" msgstr " - ZASTAO" -msgid "Press Ctrl+Alt+PgDn to return to windowed mode." -msgstr "Pritisnite Ctrl+Alt+PgDn za povratak u prozorski način rada." - msgid "Speed" msgstr "Brzina" -msgid "ZIP %03i %i (%s): %ls" -msgstr "ZIP %03i %i (%s): %ls" +msgid "ZIP %1 %2 (%3): %4" +msgstr "ZIP %1 %2 (%3): %4" msgid "ZIP images" msgstr "ZIP slike" msgid "86Box could not find any usable ROM images.\n\nPlease download a ROM set and extract it into the \"roms\" directory." -msgstr "86Box nije mogao pronaći upotrebljive ROM datoteke.\n\nMolimte posjetite sknite paket s ROM datotekama i ekstrahirajte paket u \"roms\" mapu." +msgstr "86Box nije mogao pronaći upotrebljive ROM datoteke.\n\nMolimte posjetite sknite paket s ROM datotekama i ekstrahirajte paket u mapu \"roms\"." msgid "(empty)" msgstr "(prazno)" @@ -687,8 +672,11 @@ msgstr "Sistem \"%hs\" nije dostupan jer ne postoje potrebni ROM-ovi u mapu roms msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "Video kartica \"%hs\" nije dostupna jer ne postoje potrebni ROM-ovi u mapu roms/video. Prebacivanje na dostupnu video karticu." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Video kartica 2 \"%hs\" nije dostupna jer ne postoje potrebni ROM-ovi u mapu roms/video. Prebacivanje na dostupnu video karticu." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "Video kartica 2 \"%hs\" nije dostupna jer ne postoje potrebni ROM-ovi u mapu roms/video. Isključivanje druge video karice." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Uređaj \"%hs\" nije dostupan jer ne postoje potrebni ROM-ovi. Ignoriranje uređaja." msgid "Machine" msgstr "Sistem" @@ -750,14 +738,11 @@ msgstr "S" msgid "KB" msgstr "KB" -msgid "Could not initialize the video renderer." -msgstr "Nije moguće inicijalizirati renderer." - msgid "Default" msgstr "Standard" -msgid "%i Wait state(s)" -msgstr "%i stanje čekanja" +msgid "%1 Wait state(s)" +msgstr "%1 stanje čekanja" msgid "Type" msgstr "Tip" @@ -801,11 +786,11 @@ msgstr "Thrustmaster Flight Control System" msgid "None" msgstr "Bez" -msgid "%u MB (CHS: %i, %i, %i)" -msgstr "%u MB (CHS: %i, %i, %i)" +msgid "%1 MB (CHS: %2, %3, %4)" +msgstr "%1 MB (CHS: %2, %3, %4)" -msgid "Floppy %i (%s): %ls" -msgstr "Disketa %i (%s): %ls" +msgid "Floppy %1 (%2): %3" +msgstr "Disketa %1 (%2): %3" msgid "Advanced sector images" msgstr "Napredne sektorske slike" @@ -825,8 +810,8 @@ msgstr "Nije moguće inicijalizirati GhostScript" msgid "Unable to initialize GhostPCL" msgstr "Nije moguće inicijalizirati GhostPCL" -msgid "MO %i (%ls): %ls" -msgstr "MO %i (%ls): %ls" +msgid "MO %1 (%2): %3" +msgstr "MO %1 (%2): %3" msgid "MO images" msgstr "MO slike" @@ -876,9 +861,6 @@ msgstr "%1 je potrebno za automatsku konverziju PostScript datoteke u PDF datote msgid "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PCL printer will be saved as Printer Command Language (.pcl) files." msgstr "%1 je potrebno za automatsku konverziju PCL datoteke u PDF datoteke.\n\nSvi dokumenti poslani na generički PCL pisač bit će spremljeni kao Printer Command Language (.pcl) datoteke." -msgid "Entering fullscreen mode" -msgstr "Ulazim u cijelozaslonski način" - msgid "Don't show this message again" msgstr "Ne pokazi više ovu poruku" @@ -900,11 +882,8 @@ msgstr "Konfiguracija uređaja %1" msgid "Monitor in sleep mode" msgstr "Ekran u stanju mirovanja" -msgid "OpenGL Shaders" -msgstr "OpenGL shaderi" - -msgid "OpenGL options" -msgstr "OpenGL opcije" +msgid "GLSL shaders" +msgstr "GLSL shaderi" msgid "You are loading an unsupported configuration" msgstr "Učitavate nepodržanu konfiguraciju" @@ -915,24 +894,18 @@ msgstr "Filtriranje tipa CPU-a na temelju odabranog sistema onemogućeno je za o msgid "Continue" msgstr "Nastavi" -msgid "Cassette: %s" -msgstr "Audio kaseta: %s" +msgid "Cassette: %1" +msgstr "Audio kaseta: %1" msgid "Cassette images" msgstr "Slike audio kasete" -msgid "Cartridge %i: %ls" -msgstr "Kaseta %i: %ls" +msgid "Cartridge %1: %2" +msgstr "Kaseta %1: %2" msgid "Cartridge images" msgstr "Slike kasete" -msgid "Error initializing renderer" -msgstr "Nije moguće inicijalizirati renderer" - -msgid "OpenGL (3.0 Core) renderer could not be initialized. Use another renderer." -msgstr "Nije moguće inicijalizirati OpenGL (3.0 jezgra) renderer. Molimte koristite drugi renderer." - msgid "Resume execution" msgstr "Nastavi" @@ -1095,8 +1068,8 @@ msgstr "IDE" msgid "ATAPI" msgstr "ATAPI" -msgid "CD-ROM %i (%s): %s" -msgstr "CD-ROM %i (%s): %s" +msgid "CD-ROM %1 (%2): %3" +msgstr "CD-ROM %1 (%2): %3" msgid "160 KB" msgstr "160 KB" @@ -1275,9 +1248,6 @@ msgstr "Očisti povijest slika" msgid "Create..." msgstr "Stvori..." -msgid "previous image" -msgstr "prethodna slika" - msgid "Host CD/DVD Drive (%1)" msgstr "CD/DVD pogon nositelja (%1)" @@ -1287,23 +1257,8 @@ msgstr "Nepoznata sabirnica" msgid "Null Driver" msgstr "Nulti upravljački program" -msgid "NIC %02i (%ls) %ls" -msgstr "NIC %02i (%ls) %ls" - -msgid "Error opening \"%1\": %2" -msgstr "Nije moguće otvoriti \"%1\": %2" - -msgid "Error compiling vertex shader in file \"%1\"" -msgstr "Nije moguće sastaviti vertex shader u datoteci \"%1\"" - -msgid "Error compiling fragment shader in file \"%1\"" -msgstr "Nije moguće sastaviti framgent shader u datoteci \"%1\"" - -msgid "Error linking shader program in file \"%1\"" -msgstr "Nije moguće povezati program shader u datoteci \"%1\"" - -msgid "OpenGL 3.0 renderer options" -msgstr "Opcije renderera OpenGL 3.0" +msgid "NIC %1 (%2) %3" +msgstr "NIC %1 (%2) %3" msgid "Render behavior" msgstr "Ponašanje rendera" @@ -1317,9 +1272,6 @@ msgstr " fps" msgid "VSync" msgstr "VSync" -msgid "<html><head/><body><p>Render each frame immediately, in sync with the emulated display.</p><p><span style=" font-style:italic;">This is the recommended option if the shaders in use don't utilize frametime for animated effects.</span></p></body></html>" -msgstr "<html><head/><body><p>Odmah napravi svaki okvir, sinkronizirano s emuliranim zaslonom.</p><p><span style=" font-style:italic;">Ovo je preporučena opcija, ako korišćeni shader ne koristi vreme okvira za animirane efekte.</span></p></body></html>" - msgid "Synchronize with video" msgstr "Sinkroniziraj s videom" @@ -1329,21 +1281,9 @@ msgstr "Shaderi" msgid "Remove" msgstr "Ukloni" -msgid "No shader selected" -msgstr "Bez odabranog shadera" - msgid "Browse..." msgstr "Pregledajte..." -msgid "Shader error" -msgstr "Greška shadera" - -msgid "Could not load shaders." -msgstr "Nije moguće učitati shadere." - -msgid "More information in details." -msgstr "Više informacija u detaljima." - msgid "Couldn't create OpenGL context." msgstr "Nije moguće stvoriti kontekst OpenGL." @@ -1353,20 +1293,14 @@ msgstr "Nije se moguće prebaciti na kontekst OpenGL." msgid "OpenGL version 3.0 or greater is required. Current version is %1.%2" msgstr "Potrebna je OpenGL verzija 3.0 ili više. Trenutna verzija je %1. %2" -msgid "OpenGL initialization failed. Error %1." -msgstr "Nije moguće inicijalizirati OpenGL. Greška %1." - msgid "Error initializing OpenGL" msgstr "Nije moguće inicijalizirati OpenGL" -msgid "Falling back to software rendering.\n" -msgstr "Vraća se na softverski renderer.\n" +msgid "\nFalling back to software rendering." +msgstr "\nVraća se na softverski renderer." -msgid "Allocating memory for unpack buffer failed.\n" -msgstr "Nije moguće idodijeliti memoriju za međuspremnik za raspakiranje.\n" - -msgid "<html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html>" -msgstr "<html><head/><body><p>Prilikom odabira medijskih slika (CD-ROM, diskete itd.), otvoreni dijalog zopočet će u istom direktoriju kao i konfiguracijska datoteka 86Box-a. Razlika će vjerojatno biti primjetna samo na macOS-u.</p></body></html>" +msgid "

When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" +msgstr "

Prilikom odabira medijskih slika (CD-ROM, diskete itd.), otvoreni dijalog zopočet će u istom direktoriju kao i konfiguracijska datoteka 86Box-a. Razlika će vjerojatno biti primjetna samo na macOS-u.

" msgid "This machine might have been moved or copied." msgstr "Ovaj je sistem mogao biti premješten ili kopiran." @@ -1401,17 +1335,17 @@ msgstr "Mrežna kartica 3" msgid "Network Card #4" msgstr "Mrežna kartica 4" -msgid "Mode" -msgstr "Način" +msgid "Mode:" +msgstr "Način:" -msgid "Interface" -msgstr "Sučelje" +msgid "Interface:" +msgstr "Sučelje:" -msgid "Adapter" -msgstr "Adapter" +msgid "Adapter:" +msgstr "Adapter:" -msgid "VDE Socket" -msgstr "VDE utičnica" +msgid "VDE Socket:" +msgstr "VDE utičnica:" msgid "86Box Unit Tester" msgstr "Jedinični ispitivač 86Box-a" @@ -1431,9 +1365,6 @@ msgstr "Prolaz serijskih vrata 3" msgid "Serial port passthrough 4" msgstr "Prolaz serijskih vrata 4" -msgid "Vision Systems LBA Enhancer" -msgstr "Vision Systems LBA Enhancer" - msgid "Renderer options..." msgstr "Opcije rendera..." @@ -1872,6 +1803,9 @@ msgstr "Kotač" msgid "Five + Wheel" msgstr "Pet + kotač" +msgid "Five + 2 Wheels" +msgstr "" + msgid "A3 - SMT2 Serial / SMT3(R)V" msgstr "A3 - SMT2 serijski / SMT3(R)V" @@ -1900,7 +1834,7 @@ msgid "2 MB" msgstr "2 MB" msgid "8 MB" -msgstr " 8 MB" +msgstr "8 MB" msgid "28 MB" msgstr "28 MB" @@ -2059,7 +1993,7 @@ msgid "Generic Text Printer" msgstr "Generični tekstovni pisač" msgid "Generic ESC/P Dot-Matrix Printer" -msgstr "Generični pisač matrični ESC/P" +msgstr "Generični matrični pisač ESC/P" msgid "Generic PostScript Printer" msgstr "Generični pisač PostScript" @@ -2100,8 +2034,8 @@ msgstr "Imenovani vod (server)" msgid "Host Serial Passthrough" msgstr "Prolaz serijskih vrata nositelja" -msgid "Eject %s" -msgstr "Izbaci %s" +msgid "E&ject %1" +msgstr "&Izbaci %1" msgid "&Unmute" msgstr "&Uključi zvuk" @@ -2112,11 +2046,104 @@ msgstr "Softfloat FPU" msgid "High performance impact" msgstr "Visoki učinak na brzinu izvršavanja" -msgid "RAM Disk (max. speed)" -msgstr "Disk RAM (najviša brzina)" +msgid "[Generic] RAM Disk (max. speed)" +msgstr "[Generic] Disk RAM (najviša brzina)" + +msgid "[Generic] 1989 (3500 RPM)" +msgstr "" + +msgid "[Generic] 1992 (3600 RPM)" +msgstr "" + +msgid "[Generic] 1994 (4500 RPM)" +msgstr "" + +msgid "[Generic] 1996 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1997 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1998 (5400 RPM)" +msgstr "" + +msgid "[Generic] 2000 (7200 RPM)" +msgstr "" msgid "IBM 8514/A clone (ISA)" msgstr "Klon IBM 8514/A (ISA)" msgid "Vendor" msgstr "Proizvođać" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Generičko proširenje memorije PC/XT" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Generičko proširenje memorije PC/AT" + +msgid "Unable to find Dot-Matrix fonts" +msgstr "Nije moguće pronaći matrične fontove" + +msgid "TrueType fonts in the \"roms/printer/fonts\" directory are required for the emulation of the Generic ESC/P Dot-Matrix Printer." +msgstr "TrueType fontovi u mapi \"roms/printer/fonts\" potrebni su za emulaciju generičnog matričnog pisača ESC/P." + +msgid "Inhibit multimedia keys" +msgstr "" + +msgid "Ask for confirmation before saving settings" +msgstr "" + +msgid "Ask for confirmation before hard resetting" +msgstr "" + +msgid "Ask for confirmation before quitting" +msgstr "" + +msgid "Options" +msgstr "" + +msgid "Model" +msgstr "" + +msgid "Model:" +msgstr "" + +msgid "Failed to initialize Vulkan renderer." +msgstr "" + +msgid "GLSL Error" +msgstr "" + +msgid "Could not load shader: %1" +msgstr "" + +msgid "OpenGL version 3.0 or greater is required. Current GLSL version is %1.%2" +msgstr "" + +msgid "Could not load texture: %1" +msgstr "" + +msgid "Could not compile shader:\n\n%1" +msgstr "" + +msgid "Program not linked:\n\n%1" +msgstr "" + +msgid "Shader Manager" +msgstr "" + +msgid "Shader Configuration" +msgstr "" + +msgid "Add" +msgstr "" + +msgid "Move up" +msgstr "" + +msgid "Move down" +msgstr "" + +msgid "Could not load file %1" +msgstr "" diff --git a/src/qt/languages/hu-HU.po b/src/qt/languages/hu-HU.po index 732a75df7..981edad71 100644 --- a/src/qt/languages/hu-HU.po +++ b/src/qt/languages/hu-HU.po @@ -18,8 +18,8 @@ msgstr "A &jobb oldali CTRL a bal ALT" msgid "&Hard Reset..." msgstr "Hardveres &újraindítás..." -msgid "&Ctrl+Alt+Del\tCtrl+F12" -msgstr "&Ctrl+Alt+Del\tCtrl+F12" +msgid "&Ctrl+Alt+Del" +msgstr "&Ctrl+Alt+Del" msgid "Ctrl+Alt+&Esc" msgstr "Ctrl+Alt+&Esc" @@ -111,8 +111,8 @@ msgstr "&Lineáris" msgid "Hi&DPI scaling" msgstr "Hi&DPI méretezés" -msgid "&Fullscreen\tCtrl+Alt+PgUp" -msgstr "&Teljes képernyő\tCtrl+Alt+PgUp" +msgid "&Fullscreen" +msgstr "&Teljes képernyő" msgid "Fullscreen &stretch mode" msgstr "Teljes képernyős &méretezés" @@ -186,8 +186,11 @@ msgstr "&Konfigurálás..." msgid "&Update status bar icons" msgstr "Állapotsori ikonok &frissítése" -msgid "Take s&creenshot\tCtrl+F11" -msgstr "&Képernyőkép készítése\tCtrl+F11" +msgid "Take s&creenshot" +msgstr "&Képernyőkép készítése" + +msgid "S&ound" +msgstr "&Hang" msgid "&Preferences..." msgstr "&Beállítások..." @@ -198,11 +201,11 @@ msgstr "&Discord integráció engedélyezése" msgid "Sound &gain..." msgstr "&Hangerőszabályzó..." -msgid "Begin trace\tCtrl+T" -msgstr "Nyomkövetés megkezdése\tCtrl+T" +msgid "Begin trace" +msgstr "Nyomkövetés megkezdése" -msgid "End trace\tCtrl+T" -msgstr "Nyomkövetés befejezése\tCtrl+T" +msgid "End trace" +msgstr "Nyomkövetés befejezése" msgid "&Help" msgstr "&Súgó" @@ -249,8 +252,8 @@ msgstr "&Némítás" msgid "E&mpty" msgstr "&Kiadás" -msgid "&Reload previous image" -msgstr "Előző képfájl &újratöltése" +msgid "Reload previous image" +msgstr "Előző képfájl újratöltése" msgid "&Folder..." msgstr "&Mappa..." @@ -306,18 +309,12 @@ msgstr "OK" msgid "Cancel" msgstr "Mégse" -msgid "Save these settings as &global defaults" -msgstr "Beállítások mentése &globális alapértékként" - msgid "&Default" msgstr "&Alapértelmezett" msgid "Language:" msgstr "Nyelv:" -msgid "Icon set:" -msgstr "Ikonkészlet:" - msgid "Gain" msgstr "Hangerő" @@ -453,15 +450,6 @@ msgstr "Nuked (pontosabb)" msgid "YMFM (faster)" msgstr "YMFM (gyorsabb)" -msgid "Network type:" -msgstr "Hálózati típusa:" - -msgid "PCap device:" -msgstr "PCap eszköz:" - -msgid "Network adapter:" -msgstr "Hálózati kártya:" - msgid "COM1 Device:" msgstr "COM1 eszköz:" @@ -642,14 +630,11 @@ msgstr "Végzetes hiba" msgid " - PAUSED" msgstr " - SZÜNETELT" -msgid "Press Ctrl+Alt+PgDn to return to windowed mode." -msgstr "Használja a Ctrl+Alt+PgDn gombokat az ablakhoz való visszatéréshez." - msgid "Speed" msgstr "Sebesség" -msgid "ZIP %03i %i (%s): %ls" -msgstr "ZIP %03i %i (%s): %ls" +msgid "ZIP %1 %2 (%3): %4" +msgstr "ZIP %1 %2 (%3): %4" msgid "ZIP images" msgstr "ZIP-lemezképek" @@ -687,8 +672,11 @@ msgstr "A számítógép \"%hs\" nem elérhető a \"roms/machines\" mappából h msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "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." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "A videokártya 2 \"%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." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "A videokártya 2 \"%hs\" nem elérhető a \"roms/video\" mappából hiányzó ROM-képek miatt. A második videokártya kerül letiltásra." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Az eszköz \"%hs\" nem elérhető a hiányzó ROM-képek miatt. Az eszköz figyelmen kívül marad." msgid "Machine" msgstr "Számítógép" @@ -750,14 +738,11 @@ msgstr "S" msgid "KB" msgstr "KB" -msgid "Could not initialize the video renderer." -msgstr "Nem sikerült inicializálni a videó megjelenítőt." - msgid "Default" msgstr "Alapértelmezett" -msgid "%i Wait state(s)" -msgstr "%i várakozási ciklus(ok)" +msgid "%1 Wait state(s)" +msgstr "%1 várakozási ciklus(ok)" msgid "Type" msgstr "Típus" @@ -801,11 +786,11 @@ msgstr "Thrustmaster Flight Control System" msgid "None" msgstr "Nincs" -msgid "%u MB (CHS: %i, %i, %i)" -msgstr "%u MB (CHS: %i, %i, %i)" +msgid "%1 MB (CHS: %2, %3, %4)" +msgstr "%1 MB (CHS: %2, %3, %4)" -msgid "Floppy %i (%s): %ls" -msgstr "Floppy %i (%s): %ls" +msgid "Floppy %1 (%2): %3" +msgstr "Floppy %1 (%2): %3" msgid "Advanced sector images" msgstr "Továbbfejlesztett szektor képek" @@ -825,8 +810,8 @@ msgstr "Nem sikerült inicializálni a Ghostscript-et" msgid "Unable to initialize GhostPCL" msgstr "Nem sikerült inicializálni a GhostPCL-et" -msgid "MO %i (%ls): %ls" -msgstr "MO %i (%ls): %ls" +msgid "MO %1 (%2): %3" +msgstr "MO %1 (%2): %3" msgid "MO images" msgstr "MO-képfájlok" @@ -876,9 +861,6 @@ msgstr "%1 szükséges a PostScript fájlok PDF formátumba való automatikus ko msgid "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PCL printer will be saved as Printer Command Lnaugage (.pcl) files." msgstr "%1 szükséges a PCL fájlok PDF formátumba való automatikus konvertálásához.\n\nAz általános PCL nyomtatóra küldött dokumentumok Printer Command Language (.pcl) fájlként kerülnek mentésre." -msgid "Entering fullscreen mode" -msgstr "Teljes képernyős módra váltás" - msgid "Don't show this message again" msgstr "Ne jelenítse meg újra ezt az üzenetet " @@ -900,11 +882,8 @@ msgstr "%1 eszközkonfiguráció" msgid "Monitor in sleep mode" msgstr "Képernyő alvó módban" -msgid "OpenGL Shaders" -msgstr "OpenGL Shaderek" - -msgid "OpenGL options" -msgstr "OpenGL beállítások" +msgid "GLSL shaders" +msgstr "GLSL shaderek" msgid "You are loading an unsupported configuration" msgstr "Egy nem támogatott konfigurációt tölt be" @@ -915,24 +894,18 @@ msgstr "A kiválasztott gépen alapuló CPU-típusszűrés le van tiltva ezen az msgid "Continue" msgstr "Folytatás" -msgid "Cassette: %s" -msgstr "Magnókazetta: %s" +msgid "Cassette: %1" +msgstr "Magnókazetta: %1" msgid "Cassette images" msgstr "Magnókazetta-képek" -msgid "Cartridge %i: %ls" -msgstr "ROM-kazetta %i: %ls" +msgid "Cartridge %1: %2" +msgstr "ROM-kazetta %1: %2" msgid "Cartridge images" msgstr "ROM-kazetta képek" -msgid "Error initializing renderer" -msgstr "Hiba történt a renderelő inicializálásakor" - -msgid "OpenGL (3.0 Core) renderer could not be initialized. Use another renderer." -msgstr "Az OpenGL (3.0 Core) megjelenítő-motort nem sikerült inicializálni. Kérem használjon másik renderelőt." - msgid "Resume execution" msgstr "Folytassa a végrehajtást" @@ -1095,8 +1068,8 @@ msgstr "IDE" msgid "ATAPI" msgstr "ATAPI" -msgid "CD-ROM %i (%s): %s" -msgstr "CD-ROM %i (%s): %s" +msgid "CD-ROM %1 (%2): %3" +msgstr "CD-ROM %1 (%2): %3" msgid "160 KB" msgstr "160 KB" @@ -1267,7 +1240,7 @@ msgid "Host CD/DVD Drive (%1:)" msgstr "Gazdag CD/DVD-meghajtó (%1:)" msgid "&Connected" -msgstr "&Connected" +msgstr "" msgid "Clear image history" msgstr "Törölje a kép előzményeit" @@ -1275,9 +1248,6 @@ msgstr "Törölje a kép előzményeit" msgid "Create..." msgstr "Hozzon létre..." -msgid "previous image" -msgstr "előző képfájl" - msgid "Host CD/DVD Drive (%1)" msgstr "Gazdag CD/DVD-meghajtó (%1)" @@ -1287,23 +1257,8 @@ msgstr "Ismeretlen busz" msgid "Null Driver" msgstr "Null Driver" -msgid "NIC %02i (%ls) %ls" -msgstr "NIC %02i (%ls) %ls" - -msgid "Error opening \"%1\": %2" -msgstr "Hiba a \"%1\" megnyitásakor: %2" - -msgid "Error compiling vertex shader in file \"%1\"" -msgstr "Hiba a vertex shader fordításában a \"%1\" fájlban" - -msgid "Error compiling fragment shader in file \"%1\"" -msgstr "Hiba a fragment shader fordításában a \"%1\" fájlban" - -msgid "Error linking shader program in file \"%1\"" -msgstr "Hiba a shader program összekapcsolásában a \"%1\" fájlban" - -msgid "OpenGL 3.0 renderer options" -msgstr "OpenGL 3.0 renderelési beállítások" +msgid "NIC %1 (%2) %3" +msgstr "NIC %1 (%2) %3" msgid "Render behavior" msgstr "Renderelési viselkedés" @@ -1317,9 +1272,6 @@ msgstr " fps" msgid "VSync" msgstr "VSync" -msgid "<html><head/><body><p>Render each frame immediately, in sync with the emulated display.</p><p><span style=" font-style:italic;">This is the recommended option if the shaders in use don't utilize frametime for animated effects.</span></p></body></html>" -msgstr "<html><head/><body><p>Az egyes képkockák azonnali, az emulált kijelzővel szinkronizált megjelenítése.</p><p><span style=" font-style:italic;"">Ez az ajánlott opció, ha a használt shaderek nem használják a frametime-ot az animált effektusokhoz.</span></p></body></html>" - msgid "Synchronize with video" msgstr "Szinkronizálás a videóval" @@ -1329,21 +1281,9 @@ msgstr "Shaderek" msgid "Remove" msgstr "Távolítsa el a" -msgid "No shader selected" -msgstr "Nincs shader kiválasztva" - msgid "Browse..." msgstr "Böngésszen..." -msgid "Shader error" -msgstr "Shader hiba" - -msgid "Could not load shaders." -msgstr "Nem sikerült betölteni a shadereket." - -msgid "More information in details." -msgstr "További információ a részletekről." - msgid "Couldn't create OpenGL context." msgstr "Nem sikerült OpenGL-kontextust létrehozni." @@ -1353,20 +1293,14 @@ msgstr "Nem tudott OpenGL-kontextusra váltani." msgid "OpenGL version 3.0 or greater is required. Current version is %1.%2" msgstr "Az OpenGL 3.0 vagy magasabb verziója szükséges. Az aktuális verzió %1.%2" -msgid "OpenGL initialization failed. Error %1." -msgstr "Az OpenGL inicializálása sikertelen. Hiba %1." - msgid "Error initializing OpenGL" msgstr "Hiba az OpenGL inicializálásában" -msgid "Falling back to software rendering.\n" -msgstr "Visszatérés a szoftveres rendereléshez.\n" +msgid "\nFalling back to software rendering." +msgstr "\nVisszatérés a szoftveres rendereléshez." -msgid "Allocating memory for unpack buffer failed.\n" -msgstr "A memória kiosztása a kicsomagolási pufferhez sikertelen.\n" - -msgid "<html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html>" -msgstr "<html><head/><body><p>A médiaképek (CD-ROM, floppy stb.) kiválasztásakor a megnyitási párbeszédpanel ugyanabban a könyvtárban indul, mint a 86Box konfigurációs fájl. Ez a beállítás valószínűleg csak a macOS rendszerben jelent különbséget.</p></body></html>" +msgid "

When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" +msgstr "

A médiaképek (CD-ROM, floppy stb.) kiválasztásakor a megnyitási párbeszédpanel ugyanabban a könyvtárban indul, mint a 86Box konfigurációs fájl. Ez a beállítás valószínűleg csak a macOS rendszerben jelent különbséget.

" msgid "This machine might have been moved or copied." msgstr "Lehet, hogy ezt a gépet áthelyezték vagy lemásolták." @@ -1401,17 +1335,17 @@ msgstr "Hálózati kártya 3" msgid "Network Card #4" msgstr "Hálózati kártya 4" -msgid "Mode" -msgstr "Mód" +msgid "Mode:" +msgstr "Mód:" -msgid "Interface" -msgstr "Interfész" +msgid "Interface:" +msgstr "Interfész:" -msgid "Adapter" -msgstr "Adapter" +msgid "Adapter:" +msgstr "Adapter:" -msgid "VDE Socket" -msgstr "VDE aljzat" +msgid "VDE Socket:" +msgstr "VDE aljzat:" msgid "86Box Unit Tester" msgstr "86Box Unit Tester" @@ -1431,9 +1365,6 @@ msgstr "Soros port áthaladás 3" msgid "Serial port passthrough 4" msgstr "Soros port áthaladás 4" -msgid "Vision Systems LBA Enhancer" -msgstr "Vision Systems LBA Enhancer" - msgid "Renderer options..." msgstr "Renderer opciók..." @@ -1872,6 +1803,9 @@ msgstr "Kerék" msgid "Five + Wheel" msgstr "Öt + kerék" +msgid "Five + 2 Wheels" +msgstr "" + msgid "A3 - SMT2 Serial / SMT3(R)V" msgstr "A3 - SMT2 soros / SMT3(R)V" @@ -2100,8 +2034,8 @@ msgstr "Megnevezett cső (kiszolgáló)" msgid "Host Serial Passthrough" msgstr "Az állomás soros portjának áthaladása" -msgid "Eject %s" -msgstr "%s kiadás" +msgid "E&ject %1" +msgstr "%1 &kiadás" msgid "&Unmute" msgstr "&Hang újra bekapcsolása" @@ -2112,11 +2046,104 @@ msgstr "Softfloat FPU" msgid "High performance impact" msgstr "Nagy hatással van a teljesítményre" -msgid "RAM Disk (max. speed)" -msgstr "RAM lemez (max. sebesség)" +msgid "[Generic] RAM Disk (max. speed)" +msgstr "[Generic] RAM lemez (max. sebesség)" + +msgid "[Generic] 1989 (3500 RPM)" +msgstr "" + +msgid "[Generic] 1992 (3600 RPM)" +msgstr "" + +msgid "[Generic] 1994 (4500 RPM)" +msgstr "" + +msgid "[Generic] 1996 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1997 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1998 (5400 RPM)" +msgstr "" + +msgid "[Generic] 2000 (7200 RPM)" +msgstr "" msgid "IBM 8514/A clone (ISA)" msgstr "IBM 8514/A klón (ISA)" msgid "Vendor" msgstr "Gyártó" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Általános PC/XT memóriabővítők" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Általános PC/AT memóriabővítők" + +msgid "Unable to find Dot-Matrix fonts" +msgstr "Nem találja a Dot-Matrix betűtípusokat" + +msgid "TrueType fonts in the \"roms/printer/fonts\" directory are required for the emulation of the Generic ESC/P Dot-Matrix Printer." +msgstr "Az általános ESC/P pontmátrixnyomtató emulációjához a \"roms/printer/fonts\" könyvtárban található TrueType betűtípusok szükségesek." + +msgid "Inhibit multimedia keys" +msgstr "" + +msgid "Ask for confirmation before saving settings" +msgstr "" + +msgid "Ask for confirmation before hard resetting" +msgstr "" + +msgid "Ask for confirmation before quitting" +msgstr "" + +msgid "Options" +msgstr "" + +msgid "Model" +msgstr "" + +msgid "Model:" +msgstr "" + +msgid "Failed to initialize Vulkan renderer." +msgstr "" + +msgid "GLSL Error" +msgstr "" + +msgid "Could not load shader: %1" +msgstr "" + +msgid "OpenGL version 3.0 or greater is required. Current GLSL version is %1.%2" +msgstr "" + +msgid "Could not load texture: %1" +msgstr "" + +msgid "Could not compile shader:\n\n%1" +msgstr "" + +msgid "Program not linked:\n\n%1" +msgstr "" + +msgid "Shader Manager" +msgstr "" + +msgid "Shader Configuration" +msgstr "" + +msgid "Add" +msgstr "" + +msgid "Move up" +msgstr "" + +msgid "Move down" +msgstr "" + +msgid "Could not load file %1" +msgstr "" diff --git a/src/qt/languages/it-IT.po b/src/qt/languages/it-IT.po index 088b625af..877032c85 100644 --- a/src/qt/languages/it-IT.po +++ b/src/qt/languages/it-IT.po @@ -18,8 +18,8 @@ msgstr "&CTRL destro è ALT sinistro" msgid "&Hard Reset..." msgstr "&Riavvia..." -msgid "&Ctrl+Alt+Del\tCtrl+F12" -msgstr "&Ctrl+Alt+Del\tCtrl+F12" +msgid "&Ctrl+Alt+Del" +msgstr "&Ctrl+Alt+Del" msgid "Ctrl+Alt+&Esc" msgstr "Ctrl+Alt+&Esc" @@ -111,8 +111,8 @@ msgstr "&Lineare" msgid "Hi&DPI scaling" msgstr "Scala Hi&DPI" -msgid "&Fullscreen\tCtrl+Alt+PgUp" -msgstr "&Schermo intero\tCtrl+Alt+PgUp" +msgid "&Fullscreen" +msgstr "&Schermo intero" msgid "Fullscreen &stretch mode" msgstr "Modalità adattamento &schermo intero" @@ -186,8 +186,11 @@ msgstr "&Impostazioni..." msgid "&Update status bar icons" msgstr "&Aggiorna icone della barra di stato" -msgid "Take s&creenshot\tCtrl+F11" -msgstr "Cattura schermata\tCtrl+F11" +msgid "Take s&creenshot" +msgstr "Cattura schermata" + +msgid "S&ound" +msgstr "A&udio" msgid "&Preferences..." msgstr "&Preferenze..." @@ -198,11 +201,11 @@ msgstr "Abilita &integrazione Discord" msgid "Sound &gain..." msgstr "Guadagno &suono..." -msgid "Begin trace\tCtrl+T" -msgstr "Inizia traccia\tCtrl+T" +msgid "Begin trace" +msgstr "Inizia traccia" -msgid "End trace\tCtrl+T" -msgstr "Ferma traccia\tCtrl+T" +msgid "End trace" +msgstr "Ferma traccia" msgid "&Help" msgstr "&?" @@ -249,8 +252,8 @@ msgstr "&Muto" msgid "E&mpty" msgstr "&Espelli" -msgid "&Reload previous image" -msgstr "&Ricarica l'immagine precedente" +msgid "Reload previous image" +msgstr "Ricarica l'immagine precedente" msgid "&Folder..." msgstr "&Cartella..." @@ -306,18 +309,12 @@ msgstr "OK" msgid "Cancel" msgstr "Annulla" -msgid "Save these settings as &global defaults" -msgstr "Salva queste impostazioni come &predefinite globali" - msgid "&Default" msgstr "&Predefinito" msgid "Language:" msgstr "Lingua:" -msgid "Icon set:" -msgstr "Pacchetto di icone:" - msgid "Gain" msgstr "Guadagno" @@ -453,15 +450,6 @@ msgstr "Nuked (più accurato)" msgid "YMFM (faster)" msgstr "YMFM (più veloce)" -msgid "Network type:" -msgstr "Tipo di rete:" - -msgid "PCap device:" -msgstr "Dispositivo PCap:" - -msgid "Network adapter:" -msgstr "Scheda di rete:" - msgid "COM1 Device:" msgstr "Dispositivo COM1:" @@ -642,20 +630,17 @@ msgstr "Errore fatale" msgid " - PAUSED" msgstr " - IN PAUSA" -msgid "Press Ctrl+Alt+PgDn to return to windowed mode." -msgstr "Usa Ctrl+Alt+PgDn per tornare alla modalità finestra." - msgid "Speed" msgstr "Velocità" -msgid "ZIP %03i %i (%s): %ls" -msgstr "ZIP %03i %i (%s): %ls" +msgid "ZIP %1 %2 (%3): %4" +msgstr "ZIP %1 %2 (%3): %4" msgid "ZIP images" msgstr "Immagini 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 non può trovare immagini ROM utilizzabili.\n\nPlease download a ROM set and extract it into the \"roms\" directory." +msgstr "86Box non può trovare immagini ROM utilizzabili.\n\nSi prega di scaricare un set di ROM ed estrarlo nella directory \"roms\"." msgid "(empty)" msgstr "(empty)" @@ -687,6 +672,12 @@ msgstr "La macchina \"%hs\" non è disponibile a causa di immagini ROM mancanti msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "La scheda video \"%hs\" non è disponibile a causa di immagini ROM mancanti nella directory roms/video. Cambiando ad una scheda video disponibile." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "La scheda video 2 \"%hs\" non è disponibile a causa di immagini ROM mancanti nella directory roms/video. Disabilitando la seconda scheda video." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Il dispositivo \"%hs\" non è disponibile a causa di immagini ROM mancanti. Ignorando il dispositivo." + msgid "Machine" msgstr "Piastra madre" @@ -747,14 +738,11 @@ msgstr "S" msgid "KB" msgstr "KB" -msgid "Could not initialize the video renderer." -msgstr "Impossibile inizializzare il renderer video." - msgid "Default" msgstr "Predefinito" -msgid "%i Wait state(s)" -msgstr "%i stati d'attesa" +msgid "%1 Wait state(s)" +msgstr "%1 stati d'attesa" msgid "Type" msgstr "Tipo" @@ -798,11 +786,11 @@ msgstr "Thrustmaster Flight Control System" msgid "None" msgstr "Nessuno" -msgid "%u MB (CHS: %i, %i, %i)" -msgstr "%u MB (CHS: %i, %i, %i)" +msgid "%1 MB (CHS: %2, %3, %4)" +msgstr "%1 MB (CHS: %2, %3, %4)" -msgid "Floppy %i (%s): %ls" -msgstr "Floppy %i (%s): %ls" +msgid "Floppy %1 (%2): %3" +msgstr "Floppy %1 (%2): %3" msgid "Advanced sector images" msgstr "Immagini da settori avanzati" @@ -822,8 +810,8 @@ msgstr "Impossibile inizializzare Ghostscript" msgid "Unable to initialize GhostPCL" msgstr "Impossibile inizializzare GhostPCL" -msgid "MO %i (%ls): %ls" -msgstr "MO %i (%ls): %ls" +msgid "MO %1 (%2): %3" +msgstr "MO %1 (%2): %3" msgid "MO images" msgstr "Immagini MO" @@ -873,9 +861,6 @@ msgstr "%1 è richiesto per la conversione automatica di file PostScript a file msgid "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as Printer Command Language (.pcl) files." msgstr "%1 è richiesto per la conversione automatica di file PCL a file PDF.\n\nQualsiasi documento mandato alla stampante generica PCL sarà salvato come file Printer Command Language (.cl)." -msgid "Entering fullscreen mode" -msgstr "Entrando nella modalità schermo intero" - msgid "Don't show this message again" msgstr "Non mostrare più questo messaggio" @@ -897,11 +882,8 @@ msgstr "Configurazione del dispositivo %1" msgid "Monitor in sleep mode" msgstr "Monitor in modalità riposo" -msgid "OpenGL Shaders" -msgstr "Shader OpenGL" - -msgid "OpenGL options" -msgstr "Impostazioni OpenGL" +msgid "GLSL shaders" +msgstr "Shader GLSL" msgid "You are loading an unsupported configuration" msgstr "Stai caricando una configurazione non supportata" @@ -912,24 +894,18 @@ msgstr "Il filtraggio della tipologia di CPU è disabilitato per la macchina sel msgid "Continue" msgstr "Continua" -msgid "Cassette: %s" -msgstr "Cassetta: %s" +msgid "Cassette: %1" +msgstr "Cassetta: %1" msgid "Cassette images" msgstr "Immagini cassetta" -msgid "Cartridge %i: %ls" -msgstr "Cartuccia %i: %ls" +msgid "Cartridge %1: %2" +msgstr "Cartuccia %1: %2" msgid "Cartridge images" msgstr "Immagini cartuccia" -msgid "Error initializing renderer" -msgstr "Errore nell'inizializzazione del renderer" - -msgid "OpenGL (3.0 Core) renderer could not be initialized. Use another renderer." -msgstr "Non è stato possibile inizializzare il renderer OpenGL (3.0 Core). Utilizzare un altro renderer." - msgid "Resume execution" msgstr "Riprendere l'esecuzione" @@ -1092,8 +1068,8 @@ msgstr "IDE" msgid "ATAPI" msgstr "ATAPI" -msgid "CD-ROM %i (%s): %s" -msgstr "CD-ROM %i (%s): %s" +msgid "CD-ROM %1 (%2): %3" +msgstr "CD-ROM %1 (%2): %3" msgid "160 KB" msgstr "160 KB" @@ -1272,35 +1248,17 @@ msgstr "Cancella la cronologia delle immagini" msgid "Create..." msgstr "Creare..." -msgid "previous image" -msgstr "immagine precedente" - msgid "Host CD/DVD Drive (%1)" msgstr "Unità CD/DVD host (%1)" msgid "Unknown Bus" -msgstr "Autobus sconosciuto" +msgstr "Bus sconosciuto" msgid "Null Driver" msgstr "Driver nullo" -msgid "NIC %02i (%ls) %ls" -msgstr "NIC %02i (%ls) %ls" - -msgid "Error opening \"%1\": %2" -msgstr "Errore nell'apertura di \"%1\": %2" - -msgid "Error compiling vertex shader in file \"%1\"" -msgstr "Errore nella compilazione di vertex shader nel file \"%1\"" - -msgid "Error compiling fragment shader in file \"%1\"" -msgstr "Errore nella compilazione dello shader dei frammenti nel file \"%1\"" - -msgid "Error linking shader program in file \"%1\"" -msgstr "Errore nel collegamento del programma shader nel file \"%1\"" - -msgid "OpenGL 3.0 renderer options" -msgstr "Opzioni del renderer OpenGL 3.0" +msgid "NIC %1 (%2) %3" +msgstr "NIC %1 (%2) %3" msgid "Render behavior" msgstr "Comportamento di rendering" @@ -1314,9 +1272,6 @@ msgstr " fps" msgid "VSync" msgstr "VSync" -msgid "<html><head/><body><p>Render each frame immediately, in sync with the emulated display.</p><p><span style=" font-style:italic;">This is the recommended option if the shaders in use don't utilize frametime for animated effects.</span></p></body></html>" -msgstr "<html><head/><body><p>Renderizza ogni fotogramma immediatamente, in sincronia con la visualizzazione emulata.</p><p><span style=" font-style:italic;">Questa è l'opzione consigliata se gli shader in uso non utilizzano il frametime per gli effetti animati.</span></p></body></html>" - msgid "Synchronize with video" msgstr "Sincronizza col video" @@ -1326,21 +1281,9 @@ msgstr "Shader" msgid "Remove" msgstr "Rimuovere" -msgid "No shader selected" -msgstr "Nessuno shader selezionato" - msgid "Browse..." msgstr "Sfoglia..." -msgid "Shader error" -msgstr "Errore dello shader" - -msgid "Could not load shaders." -msgstr "Impossibile caricare gli shader." - -msgid "More information in details." -msgstr "Maggiori informazioni in dettaglio." - msgid "Couldn't create OpenGL context." msgstr "Impossibile creare un contesto OpenGL." @@ -1350,20 +1293,14 @@ msgstr "Impossibile passare al contesto OpenGL." msgid "OpenGL version 3.0 or greater is required. Current version is %1.%2" msgstr "È richiesta la versione OpenGL 3.0 o superiore. La versione attuale è %1.%2" -msgid "OpenGL initialization failed. Error %1." -msgstr "Inizializzazione OpenGL non riuscita. Errore %1." - msgid "Error initializing OpenGL" msgstr "Errore nell'inizializzazione di OpenGL" -msgid "Falling back to software rendering.\n" -msgstr "Ricaduta sul rendering software." +msgid "\nFalling back to software rendering." +msgstr "\nRicaduta sul rendering software." -msgid "Allocating memory for unpack buffer failed.\n" -msgstr "L'allocazione della memoria per il buffer di disimballaggio non è riuscita." - -msgid "<html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html>" -msgstr "<html><head/><body><p>Quando si selezionano immagini multimediali (CD-ROM, floppy, ecc.) la finestra di dialogo di apertura si avvia nella stessa directory del file di configurazione di 86Box. Questa impostazione probabilmente farà la differenza solo su macOS.</p></body></html>" +msgid "

When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" +msgstr "

Quando si selezionano immagini multimediali (CD-ROM, floppy, ecc.) la finestra di dialogo di apertura si avvia nella stessa directory del file di configurazione di 86Box. Questa impostazione probabilmente farà la differenza solo su macOS.

" msgid "This machine might have been moved or copied." msgstr "Questa macchina potrebbe essere stata spostata o copiata." @@ -1398,17 +1335,17 @@ msgstr "Scheda di rete n. 3" msgid "Network Card #4" msgstr "Scheda di rete n. 4" -msgid "Mode" -msgstr "Modalità" +msgid "Mode:" +msgstr "Modalità:" -msgid "Interface" -msgstr "Interfaccia" +msgid "Interface:" +msgstr "Interfaccia:" -msgid "Adapter" -msgstr "Adattatore" +msgid "Adapter:" +msgstr "Adattatore:" -msgid "VDE Socket" -msgstr "Presa VDE" +msgid "VDE Socket:" +msgstr "Presa VDE:" msgid "86Box Unit Tester" msgstr "Tester di unità 86Box" @@ -1428,9 +1365,6 @@ msgstr "Passaggio della porta seriale 3" msgid "Serial port passthrough 4" msgstr "Passaggio della porta seriale 4" -msgid "Vision Systems LBA Enhancer" -msgstr "Vision Systems LBA Enhancer" - msgid "Renderer options..." msgstr "Opzioni del renderer..." @@ -1869,6 +1803,9 @@ msgstr "Ruota" msgid "Five + Wheel" msgstr "Cinque + ruota" +msgid "Five + 2 Wheels" +msgstr "" + msgid "A3 - SMT2 Serial / SMT3(R)V" msgstr "A3 - SMT2 seriale / SMT3(R)V" @@ -2097,8 +2034,8 @@ msgstr "Tubo denominato (Server)" msgid "Host Serial Passthrough" msgstr "Passaggio della porta seriale host" -msgid "Eject %s" -msgstr "Espelli %s" +msgid "E&ject %1" +msgstr "&Espelli %1" msgid "&Unmute" msgstr "&Riattiva l'audio" @@ -2109,11 +2046,104 @@ msgstr "FPU Softfloat" msgid "High performance impact" msgstr "Impatto elevato sulla prestazione" -msgid "RAM Disk (max. speed)" -msgstr "Disco RAM (velocità massima)" +msgid "[Generic] RAM Disk (max. speed)" +msgstr "[Generic] Disco RAM (velocità massima)" + +msgid "[Generic] 1989 (3500 RPM)" +msgstr "" + +msgid "[Generic] 1992 (3600 RPM)" +msgstr "" + +msgid "[Generic] 1994 (4500 RPM)" +msgstr "" + +msgid "[Generic] 1996 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1997 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1998 (5400 RPM)" +msgstr "" + +msgid "[Generic] 2000 (7200 RPM)" +msgstr "" msgid "IBM 8514/A clone (ISA)" -msgstr "Clone IBM 8514/A(ISA)" +msgstr "Clone IBM 8514/A (ISA)" msgid "Vendor" msgstr "Fabricante" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Espansione di memoria generica PC/XT" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Espansione di memoria generica PC/AT" + +msgid "Unable to find Dot-Matrix fonts" +msgstr "Impossibile trovare i font a matrice di punti" + +msgid "TrueType fonts in the \"roms/printer/fonts\" directory are required for the emulation of the Generic ESC/P Dot-Matrix Printer." +msgstr "I font TrueType presenti nella directory \"roms/printer/fonts\" sono necessari per l'emulazione della stampante a matrice di punti ESC/P generica." + +msgid "Inhibit multimedia keys" +msgstr "" + +msgid "Ask for confirmation before saving settings" +msgstr "" + +msgid "Ask for confirmation before hard resetting" +msgstr "" + +msgid "Ask for confirmation before quitting" +msgstr "" + +msgid "Options" +msgstr "" + +msgid "Model" +msgstr "" + +msgid "Model:" +msgstr "" + +msgid "Failed to initialize Vulkan renderer." +msgstr "" + +msgid "GLSL Error" +msgstr "" + +msgid "Could not load shader: %1" +msgstr "" + +msgid "OpenGL version 3.0 or greater is required. Current GLSL version is %1.%2" +msgstr "" + +msgid "Could not load texture: %1" +msgstr "" + +msgid "Could not compile shader:\n\n%1" +msgstr "" + +msgid "Program not linked:\n\n%1" +msgstr "" + +msgid "Shader Manager" +msgstr "" + +msgid "Shader Configuration" +msgstr "" + +msgid "Add" +msgstr "" + +msgid "Move up" +msgstr "" + +msgid "Move down" +msgstr "" + +msgid "Could not load file %1" +msgstr "" diff --git a/src/qt/languages/ja-JP.po b/src/qt/languages/ja-JP.po index 8ad510745..5efd599ed 100644 --- a/src/qt/languages/ja-JP.po +++ b/src/qt/languages/ja-JP.po @@ -18,8 +18,8 @@ msgstr "右CTRLを左ALTへ変換(&R)" msgid "&Hard Reset..." msgstr "ハード リセット(&H)..." -msgid "&Ctrl+Alt+Del\tCtrl+F12" -msgstr "Ctrl+Alt+Del(&C)\tCtrl+F12" +msgid "&Ctrl+Alt+Del" +msgstr "Ctrl+Alt+Del(&C)" msgid "Ctrl+Alt+&Esc" msgstr "Ctrl+Alt+Esc(&E)" @@ -111,8 +111,8 @@ msgstr "線形補間(&L)" msgid "Hi&DPI scaling" msgstr "HiDPIスケーリング(&D)" -msgid "&Fullscreen\tCtrl+Alt+PgUp" -msgstr "全画面表示(&F)\tCtrl+Alt+PgUp" +msgid "&Fullscreen" +msgstr "全画面表示(&F)" msgid "Fullscreen &stretch mode" msgstr "全画面の拡大表示モード(&S)" @@ -186,8 +186,11 @@ msgstr "設定(&S)..." msgid "&Update status bar icons" msgstr "ステータスバーのアイコンを更新(&U)" -msgid "Take s&creenshot\tCtrl+F11" -msgstr "スクリーンショットを撮る(&C)\tCtrl+F11" +msgid "Take s&creenshot" +msgstr "スクリーンショットを撮る(&C)" + +msgid "S&ound" +msgstr "サウンド(&O)" msgid "&Preferences..." msgstr "環境設定(&P)..." @@ -198,11 +201,11 @@ msgstr "Discord連携機能(&D)" msgid "Sound &gain..." msgstr "音量調整(&G)..." -msgid "Begin trace\tCtrl+T" -msgstr "トレース開始\tCtrl+T" +msgid "Begin trace" +msgstr "トレース開始" -msgid "End trace\tCtrl+T" -msgstr "トレース終了\tCtrl+T" +msgid "End trace" +msgstr "トレース終了" msgid "&Help" msgstr "ヘルプ(&H)" @@ -249,8 +252,8 @@ msgstr "ミュート(&M)" msgid "E&mpty" msgstr "なし(&M)" -msgid "&Reload previous image" -msgstr "前のイメージを再読み込み(&R)" +msgid "Reload previous image" +msgstr "前のイメージを再読み込み" msgid "&Folder..." msgstr "フォルダ(&F)..." @@ -306,18 +309,12 @@ msgstr "OK" msgid "Cancel" msgstr "キャンセル" -msgid "Save these settings as &global defaults" -msgstr "これらの設定をグローバル既定値として保存(&G)" - msgid "&Default" msgstr "既定値(&D)" msgid "Language:" msgstr "言語:" -msgid "Icon set:" -msgstr "アイコンセット:" - msgid "Gain" msgstr "音量" @@ -453,15 +450,6 @@ msgstr "Nuked(高精度化)" msgid "YMFM (faster)" msgstr "YMFM(より速く)" -msgid "Network type:" -msgstr "ネットワーク タイプ:" - -msgid "PCap device:" -msgstr "PCapデバイス:" - -msgid "Network adapter:" -msgstr "ネットワークアダプター:" - msgid "COM1 Device:" msgstr "COM1デバイス:" @@ -642,14 +630,11 @@ msgstr "致命的なエラー" msgid " - PAUSED" msgstr " - 一時停止" -msgid "Press Ctrl+Alt+PgDn to return to windowed mode." -msgstr "Ctrl+Alt+PgDnでウィンドウ モードに戻ります。" - msgid "Speed" msgstr "速度" -msgid "ZIP %03i %i (%s): %ls" -msgstr "ZIP %03i %i (%s): %ls" +msgid "ZIP %1 %2 (%3): %4" +msgstr "ZIP %1 %2 (%3): %4" msgid "ZIP images" msgstr "ZIPイメージ" @@ -687,8 +672,11 @@ msgstr "roms/machines ディレクトリにROMがないため、マシン「%hs msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "roms/video ディレクトリにROMがないため、ビデオ カード「%hs」は使用できません。使用可能なビデオカードに切り替えます。" -msgid "Video card 2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "roms/video ディレクトリにROMがないため、ビデオ カード2「%hs」は使用できません。使用可能なビデオカードに切り替えます。" +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "roms/video ディレクトリにROMがないため、ビデオ カード2「%hs」は使用できません。2枚目のビデオカードを無効にします。" + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "ROMがないため、デバイス「%hs」は使用できません。装置を無視する。" msgid "Machine" msgstr "マシン" @@ -750,14 +738,11 @@ msgstr "S" msgid "KB" msgstr "KB" -msgid "Could not initialize the video renderer." -msgstr "ビデオレンダラーが初期化できません。" - msgid "Default" msgstr "既定値" -msgid "%i Wait state(s)" -msgstr "%iつのウェイト ステート" +msgid "%1 Wait state(s)" +msgstr "%1つのウェイト ステート" msgid "Type" msgstr "タイプ" @@ -801,11 +786,11 @@ msgstr "Thrustmaster飛行制御システム" msgid "None" msgstr "なし" -msgid "%u MB (CHS: %i, %i, %i)" +msgid "%1 MB (CHS: %2, %3, %4)" msgstr "%u MB (CHS値: %i、%i、%i)" -msgid "Floppy %i (%s): %ls" -msgstr "フロッピー %i (%s): %ls" +msgid "Floppy %1 (%2): %3" +msgstr "フロッピー %1 (%2): %3" msgid "Advanced sector images" msgstr "アドバンスドセクターイメージ" @@ -825,8 +810,8 @@ msgstr "Ghostscriptが初期化できません" msgid "Unable to initialize GhostPCL" msgstr "GhostPCLが初期化できません" -msgid "MO %i (%ls): %ls" -msgstr "光磁気 %i (%ls): %ls" +msgid "MO %1 (%2): %3" +msgstr "光磁気 %1 (%2): %3" msgid "MO images" msgstr "光磁気イメージ" @@ -865,7 +850,7 @@ msgid "Hardware not available" msgstr "ハードウェアが利用できません" msgid "Make sure %1 is installed and that you are on a %1-compatible network connection." -msgstr "がインストールされてるか、%1に対応したネットワークに接続されてるか確認してください。" +msgstr "%1がインストールされていてかつ、%1に対応したネットワークに接続されてるか確認してください。" msgid "Invalid configuration" msgstr "不正な設定です" @@ -876,9 +861,6 @@ msgstr "PostScriptファイルをPDFに自動変換するには%1が必要です msgid "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PCL printer will be saved as Printer Command Language (.pcl) files." msgstr "PCLファイルをPDFに自動変換するには%1が必要です。\n\n汎用PCLプリンターに送信された文書は、Printer Command Language (.pcl) ファイルとして保存されます。" -msgid "Entering fullscreen mode" -msgstr "全画面モードを入力" - msgid "Don't show this message again" msgstr "今後、このメッセージを表示しない" @@ -900,39 +882,30 @@ msgstr "%1 のデバイス設定" msgid "Monitor in sleep mode" msgstr "モニターのスリープモード" -msgid "OpenGL Shaders" -msgstr "OpenGLシェーダー" - -msgid "OpenGL options" -msgstr "OpenGL設定" +msgid "GLSL shaders" +msgstr "GLSLシェーダー" 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この設定を有効にすることは公式にはサポートされておらず、バグレポートは無効として中止される可能性があります。" +msgstr "選択したマシンに基づくCPUタイプのフィルター機能は、使用中のマシンでは無効になっています。\n\nこれにより、選択したマシンと互換性のないCPUが選択できます。しかし、マシンのBIOSや他のソフトウェアと互換性がない場合があります。\n\nこの設定を有効にすることは公式にはサポートされておらず、バグレポートは無効としてクローズされる可能性があります。" msgid "Continue" msgstr "続行" -msgid "Cassette: %s" -msgstr "カセット: %s" +msgid "Cassette: %1" +msgstr "カセット: %1" msgid "Cassette images" msgstr "カセットイメージ" -msgid "Cartridge %i: %ls" -msgstr "カートリッジ %i: %ls" +msgid "Cartridge %1: %2" +msgstr "カートリッジ %1: %2" msgid "Cartridge images" msgstr "カートリッジイメージ" -msgid "Error initializing renderer" -msgstr "レンダラーの初期化エラー" - -msgid "OpenGL (3.0 Core) renderer could not be initialized. Use another renderer." -msgstr "OpenGL (3.0 Core) レンダラーが初期化できません。別のレンダラーを使用してください。" - msgid "Resume execution" msgstr "実行を再開" @@ -1012,7 +985,7 @@ 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 "上書き" @@ -1095,8 +1068,8 @@ msgstr "IDE" msgid "ATAPI" msgstr "ATAPI" -msgid "CD-ROM %i (%s): %s" -msgstr "CD-ROM %i (%s): %s" +msgid "CD-ROM %1 (%2): %3" +msgstr "CD-ROM %1 (%2): %3" msgid "160 KB" msgstr "160 KB" @@ -1275,35 +1248,17 @@ msgstr "クリア画像履歴" msgid "Create..." msgstr "作成..." -msgid "previous image" -msgstr "前の画像" - msgid "Host CD/DVD Drive (%1)" msgstr "ホスト CD/DVD ドライブ (%1)" msgid "Unknown Bus" -msgstr "不明バス" +msgstr "不明なバス" msgid "Null Driver" msgstr "ヌル・ドライバー" -msgid "NIC %02i (%ls) %ls" -msgstr "NIC %02i (%ls) %ls" - -msgid "Error opening \"%1\": %2" -msgstr "エラー・オープニング\"%1\": %2" - -msgid "Error compiling vertex shader in file \"%1\"" -msgstr "ファイル\"%1\"の頂点シェーダのコンパイルエラー。" - -msgid "Error compiling fragment shader in file \"%1\"" -msgstr "ファイル\"%1\"のフラグメント・シェーダのコンパイル・エラー。" - -msgid "Error linking shader program in file \"%1\"" -msgstr "ファイル\"%1\"のシェーダープログラムのリンクエラー。" - -msgid "OpenGL 3.0 renderer options" -msgstr "OpenGL 3.0レンダラー設定" +msgid "NIC %1 (%2) %3" +msgstr "NIC %1 (%2) %3" msgid "Render behavior" msgstr "レンダリング動作" @@ -1317,9 +1272,6 @@ msgstr " fps" msgid "VSync" msgstr "VSシンク" -msgid "<html><head/><body><p>Render each frame immediately, in sync with the emulated display.</p><p><span style=" font-style:italic;">This is the recommended option if the shaders in use don't utilize frametime for animated effects.</span></p></body></html>" -msgstr "<html><head/><body><p>エミュレートされたディスプレイと同期して、各フレームを即座にレンダリングします。</p><p><span style=" font-style:italic;">これは、使用中のシェーダがアニメーション効果のためにフレームタイムを利用しない場合に推奨されるオプションです。</span></p></body></html>" - msgid "Synchronize with video" msgstr "ビデオと同期" @@ -1329,21 +1281,9 @@ msgstr "シェーダー" msgid "Remove" msgstr "削除" -msgid "No shader selected" -msgstr "シェーダーが選択されていない" - msgid "Browse..." msgstr "ブラウズ..." -msgid "Shader error" -msgstr "シェーダーエラー" - -msgid "Could not load shaders." -msgstr "シェーダーをロードできませんでした。" - -msgid "More information in details." -msgstr "詳細はこちら。" - msgid "Couldn't create OpenGL context." msgstr "OpenGLコンテキストを作成できませんでした。" @@ -1353,20 +1293,14 @@ msgstr "OpenGLコンテキストに切り替えられなかった。" msgid "OpenGL version 3.0 or greater is required. Current version is %1.%2" msgstr "OpenGLのバージョン3.0以上が必要です。現在のバージョンは %1.%2 です。" -msgid "OpenGL initialization failed. Error %1." -msgstr "OpenGL の初期化に失敗しました。エラー %1。" - msgid "Error initializing OpenGL" msgstr "OpenGLの初期化エラー" -msgid "Falling back to software rendering.\n" -msgstr "ソフトウェアレンダリングに逆戻り。" +msgid "\nFalling back to software rendering." +msgstr "\nソフトウェアレンダリングに逆戻り。" -msgid "Allocating memory for unpack buffer failed.\n" -msgstr "アンパックバッファのメモリ確保に失敗しました。" - -msgid "<html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html>" -msgstr "<html><head/><body><p>メディアイメージ(CD-ROM、フロッピーなど)を選択するとき、オープンダイアログは86Box設定ファイルと同じディレクトリで開始します。この設定は、おそらく macOS でのみ違いがあります。</p></body></html>" +msgid "

When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" +msgstr "

メディアイメージ(CD-ROM、フロッピーなど)を選択するとき、オープンダイアログは86Box設定ファイルと同じディレクトリで開始します。この設定は、おそらく macOS でのみ違いがあります。

" msgid "This machine might have been moved or copied." msgstr "このマシンは移動されたかコピーされた可能性がある。" @@ -1401,17 +1335,17 @@ msgstr "ネットワークカード 3" msgid "Network Card #4" msgstr "ネットワークカード 4" -msgid "Mode" -msgstr "モード" +msgid "Mode:" +msgstr "モード:" -msgid "Interface" -msgstr "インターフェース" +msgid "Interface:" +msgstr "インターフェース:" -msgid "Adapter" -msgstr "アダプター" +msgid "Adapter:" +msgstr "アダプター:" -msgid "VDE Socket" -msgstr "VDEソケット" +msgid "VDE Socket:" +msgstr "VDEソケット:" msgid "86Box Unit Tester" msgstr "86Boxユニットテスター" @@ -1431,9 +1365,6 @@ msgstr "シリアル・ポート・パススルー 3" msgid "Serial port passthrough 4" msgstr "シリアル・ポート・パススルー 4" -msgid "Vision Systems LBA Enhancer" -msgstr "ビジョン・システムズ LBAエンハンサー" - msgid "Renderer options..." msgstr "レンダラー設定..." @@ -1872,6 +1803,9 @@ msgstr "ホイール" msgid "Five + Wheel" msgstr "五つ+ホイール" +msgid "Five + 2 Wheels" +msgstr "" + msgid "A3 - SMT2 Serial / SMT3(R)V" msgstr "A3 - SMT2 シリアル / SMT3(R)V" @@ -2100,8 +2034,8 @@ msgstr "名前付きパイプ(サーバー)" msgid "Host Serial Passthrough" msgstr "ホストシリアルポートのパススルー" -msgid "Eject %s" -msgstr "%sを取り出す" +msgid "E&ject %1" +msgstr "%1を取り出す(&J)" msgid "&Unmute" msgstr "ミュート解除(&U)" @@ -2112,11 +2046,104 @@ msgstr "Softfloat FPU" msgid "High performance impact" msgstr "パフォーマンスへの影響が大きい" -msgid "RAM Disk (max. speed)" -msgstr "RAMディスク(最高速度)" +msgid "[Generic] RAM Disk (max. speed)" +msgstr "[Generic] RAMディスク(最高速度)" + +msgid "[Generic] 1989 (3500 RPM)" +msgstr "" + +msgid "[Generic] 1992 (3600 RPM)" +msgstr "" + +msgid "[Generic] 1994 (4500 RPM)" +msgstr "" + +msgid "[Generic] 1996 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1997 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1998 (5400 RPM)" +msgstr "" + +msgid "[Generic] 2000 (7200 RPM)" +msgstr "" msgid "IBM 8514/A clone (ISA)" msgstr "IBM 8514/A クローン(ISA)" msgid "Vendor" msgstr "業者" + +msgid "Generic PC/XT Memory Expansion" +msgstr "汎用PC/XTメモリ拡張カード" + +msgid "Generic PC/AT Memory Expansion" +msgstr "汎用PC/ATメモリ拡張カード" + +msgid "Unable to find Dot-Matrix fonts" +msgstr "ドットマトリクスフォントが見つかりません" + +msgid "TrueType fonts in the \"roms/printer/fonts\" directory are required for the emulation of the Generic ESC/P Dot-Matrix Printer." +msgstr "汎用ESC/Pドットマトリクスプリンタのエミュレーションには、roms/printer/fontsディレクトリ内のTrueTypeフォントが必要です。" + +msgid "Inhibit multimedia keys" +msgstr "" + +msgid "Ask for confirmation before saving settings" +msgstr "" + +msgid "Ask for confirmation before hard resetting" +msgstr "" + +msgid "Ask for confirmation before quitting" +msgstr "" + +msgid "Options" +msgstr "" + +msgid "Model" +msgstr "" + +msgid "Model:" +msgstr "" + +msgid "Failed to initialize Vulkan renderer." +msgstr "" + +msgid "GLSL Error" +msgstr "" + +msgid "Could not load shader: %1" +msgstr "" + +msgid "OpenGL version 3.0 or greater is required. Current GLSL version is %1.%2" +msgstr "" + +msgid "Could not load texture: %1" +msgstr "" + +msgid "Could not compile shader:\n\n%1" +msgstr "" + +msgid "Program not linked:\n\n%1" +msgstr "" + +msgid "Shader Manager" +msgstr "" + +msgid "Shader Configuration" +msgstr "" + +msgid "Add" +msgstr "" + +msgid "Move up" +msgstr "" + +msgid "Move down" +msgstr "" + +msgid "Could not load file %1" +msgstr "" diff --git a/src/qt/languages/ko-KR.po b/src/qt/languages/ko-KR.po index 485789f56..89dbf5809 100644 --- a/src/qt/languages/ko-KR.po +++ b/src/qt/languages/ko-KR.po @@ -18,8 +18,8 @@ msgstr "우측CTRL로 좌측ALT 입력(&R)" msgid "&Hard Reset..." msgstr "재시작(&H)..." -msgid "&Ctrl+Alt+Del\tCtrl+F12" -msgstr "Ctrl+Alt+Del(&C)\tCtrl+F12" +msgid "&Ctrl+Alt+Del" +msgstr "Ctrl+Alt+Del(&C)" msgid "Ctrl+Alt+&Esc" msgstr "Ctrl+Alt+Esc(&E)" @@ -111,8 +111,8 @@ msgstr "선형 보간법(&L)" msgid "Hi&DPI scaling" msgstr "HiDPI 스케일링(&D)" -msgid "&Fullscreen\tCtrl+Alt+PgUp" -msgstr "전체 화면(&F)\tCtrl+Alt+PgUp" +msgid "&Fullscreen" +msgstr "전체 화면(&F)" msgid "Fullscreen &stretch mode" msgstr "전체 화면 비율(&S)" @@ -186,8 +186,11 @@ msgstr "설정(&S)..." msgid "&Update status bar icons" msgstr "상태 바 아이콘 갱신하기(&U)" -msgid "Take s&creenshot\tCtrl+F11" -msgstr "스크린샷 찍기(&C)\tCtrl+F11" +msgid "Take s&creenshot" +msgstr "스크린샷 찍기(&C)" + +msgid "S&ound" +msgstr "사운드(&O)" msgid "&Preferences..." msgstr "환경설정(&P)..." @@ -198,11 +201,11 @@ msgstr "디스코드 연동 활성화하기(&D)" msgid "Sound &gain..." msgstr "음량 증폭(&G)..." -msgid "Begin trace\tCtrl+T" -msgstr "추적 시작하기\tCtrl+T" +msgid "Begin trace" +msgstr "추적 시작하기" -msgid "End trace\tCtrl+T" -msgstr "추적 끝내기\tCtrl+T" +msgid "End trace" +msgstr "추적 끝내기" msgid "&Help" msgstr "도움말(&H)" @@ -249,8 +252,8 @@ msgstr "음소거(&M)" msgid "E&mpty" msgstr "비었음(&M)" -msgid "&Reload previous image" -msgstr "이전 이미지 다시 불러오기(&R)" +msgid "Reload previous image" +msgstr "이전 이미지 다시 불러오기" msgid "&Folder..." msgstr "폴더(&F)..." @@ -306,18 +309,12 @@ msgstr "확인" msgid "Cancel" msgstr "취소" -msgid "Save these settings as &global defaults" -msgstr "이 설정들을 전역 기본값으로 저장하기(&G)" - msgid "&Default" msgstr "기본값(&D)" msgid "Language:" msgstr "언어:" -msgid "Icon set:" -msgstr "아이콘셋:" - msgid "Gain" msgstr "증가값" @@ -453,15 +450,6 @@ msgstr "Nuked (더 정확한)" msgid "YMFM (faster)" msgstr "YMFM (더 빠르게)" -msgid "Network type:" -msgstr "네트워크 종류:" - -msgid "PCap device:" -msgstr "PCap 장치:" - -msgid "Network adapter:" -msgstr "네트워크 어댑터:" - msgid "COM1 Device:" msgstr "COM1 장치:" @@ -642,14 +630,11 @@ msgstr "치명적인 오류" msgid " - PAUSED" msgstr " - 일시 중지됨" -msgid "Press Ctrl+Alt+PgDn to return to windowed mode." -msgstr "Ctrl+Alt+PgDn 키를 누르면 창 모드로 전환합니다." - msgid "Speed" msgstr "속도" -msgid "ZIP %03i %i (%s): %ls" -msgstr "ZIP %03i %i (%s): %ls" +msgid "ZIP %1 %2 (%3): %4" +msgstr "ZIP %1 %2 (%3): %4" msgid "ZIP images" msgstr "ZIP 이미지" @@ -687,8 +672,11 @@ msgstr "roms/machines 디렉토리에 필요한 롬파일이 없어 기종 \"%hs msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "roms/video 디렉토리에 필요한 롬파일이 없어 비디오 카드 \"%hs\"을(를) 사용할 수 없습니다. 사용 가능한 기종으로 변경합니다." -msgid "Video card 2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "roms/video 디렉토리에 필요한 롬파일이 없어 비디오 카드 2 \"%hs\"을(를) 사용할 수 없습니다. 사용 가능한 기종으로 변경합니다." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "roms/video 디렉토리에 필요한 롬파일이 없어 비디오 카드 2 \"%hs\"을(를) 사용할 수 없습니다. 두 번째 비디오 카드를 비활성화합니다." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "필요한 롬파일이 없어 장치 \"%hs\"을(를) 사용할 수 없습니다. 장치를 무시합니다." msgid "Machine" msgstr "기종" @@ -750,14 +738,11 @@ msgstr "S" msgid "KB" msgstr "KB" -msgid "Could not initialize the video renderer." -msgstr "비디오 렌더러를 초기화할 수 없습니다." - msgid "Default" msgstr "기본값" -msgid "%i Wait state(s)" -msgstr "%i 대기 상태" +msgid "%1 Wait state(s)" +msgstr "%1 대기 상태" msgid "Type" msgstr "형식" @@ -801,11 +786,11 @@ msgstr "Thrustmaster Flight Control System" msgid "None" msgstr "없음" -msgid "%u MB (CHS: %i, %i, %i)" -msgstr "%u MB (CHS: %i, %i, %i)" +msgid "%1 MB (CHS: %2, %3, %4)" +msgstr "%1 MB (CHS: %2, %3, %4)" -msgid "Floppy %i (%s): %ls" -msgstr "플로피 %i (%s): %ls" +msgid "Floppy %1 (%2): %3" +msgstr "플로피 %1 (%2): %3" msgid "Advanced sector images" msgstr "어드밴스드 섹터 이미지" @@ -825,8 +810,8 @@ msgstr "Ghostscript를 초기화할 수 없습니다" msgid "Unable to initialize GhostPCL" msgstr "GhostPCL를 초기화할 수 없습니다" -msgid "MO %i (%ls): %ls" -msgstr "광자기 %i (%ls): %ls" +msgid "MO %1 (%2): %3" +msgstr "광자기 %1 (%2): %3" msgid "MO images" msgstr "광자기 이미지" @@ -876,9 +861,6 @@ msgstr "%1은(는) PostScript 파일을 PDF로 자동변환하는 데에 필요 msgid "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PCL printer will be saved as Printer Command Language (.pcl) files." msgstr "%1은(는) PCL 파일을 PDF로 자동변환하는 데에 필요합니다.\n\n표준 PCL 프린터로 보내신 임의의 문서는 Printer Command Language (.pcl) 파일로 저장됩니다." -msgid "Entering fullscreen mode" -msgstr "전체 화면으로 전환" - msgid "Don't show this message again" msgstr "이 메시지 그만 보기" @@ -900,11 +882,8 @@ msgstr "%1 장치 설정" msgid "Monitor in sleep mode" msgstr "모니터 절전 모드" -msgid "OpenGL Shaders" -msgstr "OpenGL 쉐이더" - -msgid "OpenGL options" -msgstr "OpenGL 설정" +msgid "GLSL shaders" +msgstr "GLSL 쉐이더" msgid "You are loading an unsupported configuration" msgstr "지원하지 않는 설정입니다" @@ -915,24 +894,18 @@ msgstr "이 에뮬레이트된 기종에 대해 선택한 기종을 기반으로 msgid "Continue" msgstr "계속" -msgid "Cassette: %s" -msgstr "카세트: %s" +msgid "Cassette: %1" +msgstr "카세트: %1" msgid "Cassette images" msgstr "카세트 이미지" -msgid "Cartridge %i: %ls" -msgstr "카트리지 %i: %ls" +msgid "Cartridge %1: %2" +msgstr "카트리지 %1: %2" msgid "Cartridge images" msgstr "카트리지 이미지" -msgid "Error initializing renderer" -msgstr "렌더러 초기화 오류" - -msgid "OpenGL (3.0 Core) renderer could not be initialized. Use another renderer." -msgstr "OpenGL (3.0 Core) 렌더러를 초기화할 수 없습니다. 다른 렌더러를 사용하십시오." - msgid "Resume execution" msgstr "실행 재개" @@ -1095,8 +1068,8 @@ msgstr "IDE" msgid "ATAPI" msgstr "ATAPI" -msgid "CD-ROM %i (%s): %s" -msgstr "CD-ROM %i (%s): %s" +msgid "CD-ROM %1 (%2): %3" +msgstr "CD-ROM %1 (%2): %3" msgid "160 KB" msgstr "160 KB" @@ -1275,9 +1248,6 @@ msgstr "이미지 기록 지우기" msgid "Create..." msgstr "만들기..." -msgid "previous image" -msgstr "이전 이미지" - msgid "Host CD/DVD Drive (%1)" msgstr "호스트 CD/DVD 드라이브 (%1)" @@ -1287,23 +1257,8 @@ msgstr "알 수 없는 버스" msgid "Null Driver" msgstr "Null 드라이버" -msgid "NIC %02i (%ls) %ls" -msgstr "NIC %02i (%ls) %ls" - -msgid "Error opening \"%1\": %2" -msgstr "열기 오류 \"%1\": %2" - -msgid "Error compiling vertex shader in file \"%1\"" -msgstr "파일 \"%1\"에서 버텍스 셰이더를 컴파일하는 동안 오류가 발생했습니다." - -msgid "Error compiling fragment shader in file \"%1\"" -msgstr "파일에서 조각 셰이더 컴파일 중 오류 발생 \"%1\"" - -msgid "Error linking shader program in file \"%1\"" -msgstr "파일에서 셰이더 프로그램 연결 중 오류 \"%1\"\"" - -msgid "OpenGL 3.0 renderer options" -msgstr "OpenGL 3.0 렌더러 옵션" +msgid "NIC %1 (%2) %3" +msgstr "NIC %1 (%2) %3" msgid "Render behavior" msgstr "렌더링 동작" @@ -1317,9 +1272,6 @@ msgstr " fps" msgid "VSync" msgstr "VSync" -msgid "<html><head/><body><p>Render each frame immediately, in sync with the emulated display.</p><p><span style=" font-style:italic;">This is the recommended option if the shaders in use don't utilize frametime for animated effects.</span></p></body></html>" -msgstr "<html><head/><body><p>;에뮬레이트된 디스플레이와 동기화하여 각 프레임을 즉시 렌더링합니다.</p><p><span style=" font-style:italic;">사용 중인 셰이더가 애니메이션 효과에 프레임 시간을 활용하지 않는 경우 권장되는 옵션입니다.</span></p></body></html>" - msgid "Synchronize with video" msgstr "비디오와 동기" @@ -1329,21 +1281,9 @@ msgstr "셰이더" msgid "Remove" msgstr "제거" -msgid "No shader selected" -msgstr "셰이더를 선택하지 않음" - msgid "Browse..." msgstr "찾아보기..." -msgid "Shader error" -msgstr "셰이더 오류" - -msgid "Could not load shaders." -msgstr "셰이더를 로드할 수 없습니다." - -msgid "More information in details." -msgstr "자세한 내용은 자세히 알아보세요." - msgid "Couldn't create OpenGL context." msgstr "OpenGL 컨텍스트를 만들 수 없습니다." @@ -1353,20 +1293,14 @@ msgstr "OpenGL 컨텍스트로 전환할 수 없습니다." msgid "OpenGL version 3.0 or greater is required. Current version is %1.%2" msgstr "OpenGL 버전 3.0 이상이 필요합니다. 현재 버전은 %1.%2입니다." -msgid "OpenGL initialization failed. Error %1." -msgstr "OpenGL 초기화에 실패했습니다. 오류 %1입니다." - msgid "Error initializing OpenGL" msgstr "OpenGL 초기화 중 오류 발생" -msgid "Falling back to software rendering.\n" -msgstr "소프트웨어 렌더링으로 돌아가기.\n" +msgid "\nFalling back to software rendering." +msgstr "\n소프트웨어 렌더링으로 돌아가기." -msgid "Allocating memory for unpack buffer failed.\n" -msgstr "압축 해제 버퍼에 메모리를 할당하지 못했습니다.\n" - -msgid "<html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html>" -msgstr "<html><head/><body><p>미디어 이미지(CD-ROM, 플로피 등)를 선택하면 86Box 구성 파일과 동일한 디렉터리에서 열기 대화 상자가 시작됩니다. 이 설정은 macOS에서만 차이가 있을 수 있습니다.</p></body></html>" +msgid "

When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" +msgstr "

미디어 이미지(CD-ROM, 플로피 등)를 선택하면 86Box 구성 파일과 동일한 디렉터리에서 열기 대화 상자가 시작됩니다. 이 설정은 macOS에서만 차이가 있을 수 있습니다.

" msgid "This machine might have been moved or copied." msgstr "이 컴퓨터가 이동되었거나 복사되었을 수 있습니다." @@ -1401,17 +1335,17 @@ msgstr "네트워크 카드 3" msgid "Network Card #4" msgstr "네트워크 카드 4" -msgid "Mode" -msgstr "모드" +msgid "Mode:" +msgstr "모드:" -msgid "Interface" -msgstr "인터페이스" +msgid "Interface:" +msgstr "인터페이스:" -msgid "Adapter" -msgstr "어댑터" +msgid "Adapter:" +msgstr "어댑터:" -msgid "VDE Socket" -msgstr "VDE 소켓" +msgid "VDE Socket:" +msgstr "VDE 소켓:" msgid "86Box Unit Tester" msgstr "86Box 유닛 테스터" @@ -1431,9 +1365,6 @@ msgstr "직렬 포트 패스스루 3" msgid "Serial port passthrough 4" msgstr "직렬 포트 패스스루 4" -msgid "Vision Systems LBA Enhancer" -msgstr "비전 시스템 LBA 인핸서" - msgid "Renderer options..." msgstr "렌더러 옵션..." @@ -1872,6 +1803,9 @@ msgstr "휠" msgid "Five + Wheel" msgstr "5개 + 휠" +msgid "Five + 2 Wheels" +msgstr "" + msgid "A3 - SMT2 Serial / SMT3(R)V" msgstr "A3 - SMT2 직렬/SMT3(R)V" @@ -2100,8 +2034,8 @@ msgstr "네임드 파이프(서버)" msgid "Host Serial Passthrough" msgstr "호스트 직렬 포트 패스스루" -msgid "Eject %s" -msgstr "%s 꺼내기" +msgid "E&ject %1" +msgstr "%1 꺼내기(&J)" msgid "&Unmute" msgstr "음소거 해제(&U)" @@ -2112,11 +2046,104 @@ msgstr "소프트플로트 FPU" msgid "High performance impact" msgstr "성능에 미치는 영향" -msgid "RAM Disk (max. speed)" -msgstr "RAM 디스크(최대 속도)" +msgid "[Generic] RAM Disk (max. speed)" +msgstr "[Generic] RAM 디스크(최대 속도)" + +msgid "[Generic] 1989 (3500 RPM)" +msgstr "" + +msgid "[Generic] 1992 (3600 RPM)" +msgstr "" + +msgid "[Generic] 1994 (4500 RPM)" +msgstr "" + +msgid "[Generic] 1996 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1997 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1998 (5400 RPM)" +msgstr "" + +msgid "[Generic] 2000 (7200 RPM)" +msgstr "" msgid "IBM 8514/A clone (ISA)" msgstr "IBM 8514/A 클론(ISA)" msgid "Vendor" msgstr "제조사" + +msgid "Generic PC/XT Memory Expansion" +msgstr "일반 PC/XT 메모리 확장 카드" + +msgid "Generic PC/AT Memory Expansion" +msgstr "일반 PC/AT 메모리 확장 카드" + +msgid "Unable to find Dot-Matrix fonts" +msgstr "도트 매트릭스 글꼴을 찾을 수 없습니다" + +msgid "TrueType fonts in the \"roms/printer/fonts\" directory are required for the emulation of the Generic ESC/P Dot-Matrix Printer." +msgstr "일반 ESC/P 도트 매트릭스 프린터의 에뮬레이션을 사용하려면 \"roms/printer/fonts\" 디렉터리에 있는 트루타입 글꼴이 필요합니다." + +msgid "Inhibit multimedia keys" +msgstr "" + +msgid "Ask for confirmation before saving settings" +msgstr "" + +msgid "Ask for confirmation before hard resetting" +msgstr "" + +msgid "Ask for confirmation before quitting" +msgstr "" + +msgid "Options" +msgstr "" + +msgid "Model" +msgstr "" + +msgid "Model:" +msgstr "" + +msgid "Failed to initialize Vulkan renderer." +msgstr "" + +msgid "GLSL Error" +msgstr "" + +msgid "Could not load shader: %1" +msgstr "" + +msgid "OpenGL version 3.0 or greater is required. Current GLSL version is %1.%2" +msgstr "" + +msgid "Could not load texture: %1" +msgstr "" + +msgid "Could not compile shader:\n\n%1" +msgstr "" + +msgid "Program not linked:\n\n%1" +msgstr "" + +msgid "Shader Manager" +msgstr "" + +msgid "Shader Configuration" +msgstr "" + +msgid "Add" +msgstr "" + +msgid "Move up" +msgstr "" + +msgid "Move down" +msgstr "" + +msgid "Could not load file %1" +msgstr "" diff --git a/src/qt/languages/nl-NL.po b/src/qt/languages/nl-NL.po index b54bc1cb0..aa87cd37d 100644 --- a/src/qt/languages/nl-NL.po +++ b/src/qt/languages/nl-NL.po @@ -6,2129 +6,2144 @@ msgstr "" "X-Language: nl_NL\n" "X-Source-Language: en_US\n" -msgid "&Action" +msgid "&Action" msgstr "&Actie" -msgid "&Keyboard requires capture" +msgid "&Keyboard requires capture" msgstr "&Keyboard vereist vastleggen" -msgid "&Right CTRL is left ALT" +msgid "&Right CTRL is left ALT" msgstr "&Rechtse CTRL is linkse ALT" -msgid "&Hard Reset..." +msgid "&Hard Reset..." msgstr "&Harde Reset..." -msgid "&Ctrl+Alt+Del\tCtrl+F12" -msgstr "&Ctrl+Alt+Del\tCtrl+F12" +msgid "&Ctrl+Alt+Del" +msgstr "&Ctrl+Alt+Del" -msgid "Ctrl+Alt+&Esc" +msgid "Ctrl+Alt+&Esc" msgstr "Ctrl+Alt+&Esc" -msgid "&Pause" +msgid "&Pause" msgstr "&Pauze" -msgid "E&xit..." +msgid "E&xit..." msgstr "&Afsluiten..." -msgid "&View" +msgid "&View" msgstr "&Beeld" -msgid "&Hide status bar" +msgid "&Hide status bar" msgstr "&Statusbalk verbergen" -msgid "Hide &toolbar" +msgid "Hide &toolbar" msgstr "Verberg &toolbar" -msgid "&Resizeable window" +msgid "&Resizeable window" msgstr "&Venster met aanpasbare grootte" -msgid "R&emember size && position" +msgid "R&emember size && position" msgstr "&Onthoud grootte && positie" -msgid "Re&nderer" +msgid "Re&nderer" msgstr "Re&nderer" -msgid "&Qt (Software)" +msgid "&Qt (Software)" msgstr "&Qt (software)" -msgid "Qt (&OpenGL)" +msgid "Qt (&OpenGL)" msgstr "Qt (&OpenGL)" -msgid "Open&GL (3.0 Core)" +msgid "Open&GL (3.0 Core)" msgstr "Open&GL (3.0 Core)" -msgid "&VNC" +msgid "&VNC" msgstr "&VNC" -msgid "Specify dimensions..." +msgid "Specify dimensions..." msgstr "Afmetingen opgeven..." -msgid "F&orce 4:3 display ratio" +msgid "F&orce 4:3 display ratio" msgstr "F&orceer 4:3 beeldverhouding" -msgid "&Window scale factor" +msgid "&Window scale factor" msgstr "&Venster schaalfactor" -msgid "&0.5x" +msgid "&0.5x" msgstr "&0,5x" -msgid "&1x" +msgid "&1x" msgstr "&1x" -msgid "1.&5x" +msgid "1.&5x" msgstr "1,&5x" -msgid "&2x" +msgid "&2x" msgstr "&2x" -msgid "&3x" +msgid "&3x" msgstr "&3x" -msgid "&4x" +msgid "&4x" msgstr "&4x" -msgid "&5x" +msgid "&5x" msgstr "&5x" -msgid "&6x" +msgid "&6x" msgstr "&6x" -msgid "&7x" +msgid "&7x" msgstr "&7x" -msgid "&8x" +msgid "&8x" msgstr "&8x" -msgid "Filter method" +msgid "Filter method" msgstr "Filtermethode" -msgid "&Nearest" +msgid "&Nearest" msgstr "&Dichtsbijzijnde" -msgid "&Linear" +msgid "&Linear" msgstr "&Lineair" -msgid "Hi&DPI scaling" +msgid "Hi&DPI scaling" msgstr "Hi&DPI-schaling" -msgid "&Fullscreen\tCtrl+Alt+PgUp" -msgstr "&Fullscreen\tCtrl+Alt+PgUp" +msgid "&Fullscreen" +msgstr "&Volledig scherm" -msgid "Fullscreen &stretch mode" +msgid "Fullscreen &stretch mode" msgstr "Volledig scherm &uitrekmodus" -msgid "&Full screen stretch" +msgid "&Full screen stretch" msgstr "&Volledig scherm uitrekken" -msgid "&4:3" +msgid "&4:3" msgstr "&4:3" -msgid "&Square pixels (Keep ratio)" +msgid "&Square pixels (Keep ratio)" msgstr "&Vierkante pixels (behoud verhouding)" -msgid "&Integer scale" +msgid "&Integer scale" msgstr "&Integerschaal" -msgid "4:&3 Integer scale" +msgid "4:&3 Integer scale" msgstr "4:&3 integerschaal" -msgid "E&GA/(S)VGA settings" +msgid "E&GA/(S)VGA settings" msgstr "E&GA/(S)VGA-instellingen" -msgid "&Inverted VGA monitor" +msgid "&Inverted VGA monitor" msgstr "Ge&ïnverteerde VGA-monitor" -msgid "VGA screen &type" +msgid "VGA screen &type" msgstr "VGA-scherm &type" -msgid "RGB &Color" +msgid "RGB &Color" msgstr "RGB &Kleur" -msgid "&RGB Grayscale" +msgid "&RGB Grayscale" msgstr "&RGB grijstinten" -msgid "&Amber monitor" +msgid "&Amber monitor" msgstr "&Amber monitor" -msgid "&Green monitor" +msgid "&Green monitor" msgstr "&Groene monitor" -msgid "&White monitor" +msgid "&White monitor" msgstr "&Witte monitor" -msgid "Grayscale &conversion type" +msgid "Grayscale &conversion type" msgstr "Grijstinten &conversietype" -msgid "BT&601 (NTSC/PAL)" +msgid "BT&601 (NTSC/PAL)" msgstr "BT&601 (NTSC/PAL)" -msgid "BT&709 (HDTV)" +msgid "BT&709 (HDTV)" msgstr "BT&709 (HDTV)" -msgid "&Average" +msgid "&Average" msgstr "&Gemiddelde" -msgid "CGA/PCjr/Tandy/E&GA/(S)VGA overscan" +msgid "CGA/PCjr/Tandy/E&GA/(S)VGA overscan" msgstr "CGA/PCjr/Tandy/E&GA/(S)VGA overscan" -msgid "Change contrast for &monochrome display" +msgid "Change contrast for &monochrome display" msgstr "Contrast wijzigen voor &monochroom beeldscherm" -msgid "&Media" +msgid "&Media" msgstr "&Media" -msgid "&Tools" +msgid "&Tools" msgstr "&Tools" -msgid "&Settings..." +msgid "&Settings..." msgstr "&Instellingen..." -msgid "&Update status bar icons" +msgid "&Update status bar icons" msgstr "&Statusbalkpictogrammen bijwerken" -msgid "Take s&creenshot\tCtrl+F11" -msgstr "Maak een schermafbeelding\tCtrl+F11" +msgid "Take s&creenshot" +msgstr "Maak een schermafbeelding" -msgid "&Preferences..." +msgid "S&ound" +msgstr "&Geluid" + +msgid "&Preferences..." msgstr "&Voorkeuren..." -msgid "Enable &Discord integration" +msgid "Enable &Discord integration" msgstr "&Discord integratie inschakelen" -msgid "Sound &gain..." +msgid "Sound &gain..." msgstr "&Geluidsversterking..." -msgid "Begin trace\tCtrl+T" -msgstr "Begin traceren\tCtrl+T" +msgid "Begin trace" +msgstr "Begin traceren" -msgid "End trace\tCtrl+T" -msgstr "Traceren beëindigen\tCtrl+T" +msgid "End trace" +msgstr "Traceren beëindigen" -msgid "&Help" +msgid "&Help" msgstr "&Help" -msgid "&Documentation..." +msgid "&Documentation..." msgstr "&Documentatie..." -msgid "&About 86Box..." +msgid "&About 86Box..." msgstr "&Over 86Box..." -msgid "&New image..." +msgid "&New image..." msgstr "&Nieuw image..." -msgid "&Existing image..." +msgid "&Existing image..." msgstr "&Bestaande image..." -msgid "Existing image (&Write-protected)..." +msgid "Existing image (&Write-protected)..." msgstr "Bestaande image (&Schrijfbeveiligd)..." -msgid "&Record" +msgid "&Record" msgstr "&Opnemen" -msgid "&Play" +msgid "&Play" msgstr "&Play" -msgid "&Rewind to the beginning" +msgid "&Rewind to the beginning" msgstr "&Terugspoelen naar het begin" -msgid "&Fast forward to the end" +msgid "&Fast forward to the end" msgstr "&Snel vooruit naar het einde" -msgid "E&ject" -msgstr "E&ject" +msgid "E&ject" +msgstr "&Uitwerpen" -msgid "&Image..." +msgid "&Image..." msgstr "&Image..." -msgid "E&xport to 86F..." +msgid "E&xport to 86F..." msgstr "E&xporteer naar 86F..." -msgid "&Mute" +msgid "&Mute" msgstr "&Mute" -msgid "E&mpty" +msgid "E&mpty" msgstr "E&mpty" -msgid "&Reload previous image" -msgstr "&Herlaad vorige image" +msgid "Reload previous image" +msgstr "Herlaad vorige image" -msgid "&Folder..." +msgid "&Folder..." msgstr "&Map..." -msgid "Target &framerate" +msgid "Target &framerate" msgstr "Doel &framerate" -msgid "&Sync with video" +msgid "&Sync with video" msgstr "&Synchroniseer met video" -msgid "&25 fps" +msgid "&25 fps" msgstr "&25 fps" -msgid "&30 fps" +msgid "&30 fps" msgstr "&30 fps" -msgid "&50 fps" +msgid "&50 fps" msgstr "&50 fps" -msgid "&60 fps" +msgid "&60 fps" msgstr "&60 fps" -msgid "&75 fps" +msgid "&75 fps" msgstr "&75 fps" -msgid "&VSync" +msgid "&VSync" msgstr "&VSync" -msgid "&Select shader..." +msgid "&Select shader..." msgstr "&Selecteer shader..." -msgid "&Remove shader" +msgid "&Remove shader" msgstr "&Remove shader" -msgid "Preferences" +msgid "Preferences" msgstr "Voorkeuren" -msgid "Sound Gain" +msgid "Sound Gain" msgstr "Geluidsversterking" -msgid "New Image" +msgid "New Image" msgstr "Nieuw image" -msgid "Settings" +msgid "Settings" msgstr "Instellingen" -msgid "Specify Main Window Dimensions" +msgid "Specify Main Window Dimensions" msgstr "Afmetingen hoofdvenster opgeven" -msgid "OK" +msgid "OK" msgstr "OK" -msgid "Cancel" +msgid "Cancel" msgstr "Annuleren" -msgid "Save these settings as &global defaults" -msgstr "Sla deze instellingen op als &globale standaardinstellingen" - -msgid "&Default" +msgid "&Default" msgstr "&Standaard" -msgid "Language:" +msgid "Language:" msgstr "Taal:" -msgid "Icon set:" -msgstr "Pictogrammenset:" - -msgid "Gain" +msgid "Gain" msgstr "Versterking" -msgid "File name:" +msgid "File name:" msgstr "Bestandsnaam:" -msgid "Disk size:" +msgid "Disk size:" msgstr "Schijfgrootte:" -msgid "RPM mode:" +msgid "RPM mode:" msgstr "RPM-modus:" -msgid "Progress:" +msgid "Progress:" msgstr "Vooruitgang:" -msgid "Width:" +msgid "Width:" msgstr "Breedte:" -msgid "Height:" +msgid "Height:" msgstr "Hoogte:" -msgid "Lock to this size" +msgid "Lock to this size" msgstr "Leg vast op deze grootte" -msgid "Machine type:" +msgid "Machine type:" msgstr "Machinetype:" -msgid "Machine:" +msgid "Machine:" msgstr "Machine:" -msgid "Configure" +msgid "Configure" msgstr "Configureren" -msgid "CPU type:" +msgid "CPU type:" msgstr "CPU type:" -msgid "Speed:" +msgid "Speed:" msgstr "Snelheid:" -msgid "Frequency:" +msgid "Frequency:" msgstr "Frequentie:" -msgid "FPU:" +msgid "FPU:" msgstr "FPU:" -msgid "Wait states:" +msgid "Wait states:" msgstr "Wachttoestanden:" -msgid "MB" +msgid "MB" msgstr "MB" -msgid "Memory:" +msgid "Memory:" msgstr "Geheugen:" -msgid "Time synchronization" +msgid "Time synchronization" msgstr "Tijdsynchronisatie" -msgid "Disabled" +msgid "Disabled" msgstr "Uitgeschakeld" -msgid "Enabled (local time)" +msgid "Enabled (local time)" msgstr "Ingeschakeld (lokale tijd)" -msgid "Enabled (UTC)" +msgid "Enabled (UTC)" msgstr "Ingeschakeld (UTC)" -msgid "Dynamic Recompiler" +msgid "Dynamic Recompiler" msgstr "Dynamische Recompiler" -msgid "Video:" +msgid "Video:" msgstr "Video:" -msgid "Video #2:" +msgid "Video #2:" msgstr "Video #2:" -msgid "Voodoo 1 or 2 Graphics" +msgid "Voodoo 1 or 2 Graphics" msgstr "Voodoo 1 of 2 graphics" -msgid "IBM 8514/A Graphics" +msgid "IBM 8514/A Graphics" msgstr "IBM 8514/A-graphics" -msgid "XGA Graphics" +msgid "XGA Graphics" msgstr "XGA Graphics" -msgid "Mouse:" +msgid "Mouse:" msgstr "Muis:" -msgid "Joystick:" +msgid "Joystick:" msgstr "Joystick:" -msgid "Joystick 1..." +msgid "Joystick 1..." msgstr "Joystick 1..." -msgid "Joystick 2..." +msgid "Joystick 2..." msgstr "Joystick 2..." -msgid "Joystick 3..." +msgid "Joystick 3..." msgstr "Joystick 3..." -msgid "Joystick 4..." +msgid "Joystick 4..." msgstr "Joystick 4..." -msgid "Sound card #1:" +msgid "Sound card #1:" msgstr "Geluidskaart #1:" -msgid "Sound card #2:" +msgid "Sound card #2:" msgstr "Geluidskaart #2:" -msgid "Sound card #3:" +msgid "Sound card #3:" msgstr "Geluidskaart #3:" -msgid "Sound card #4:" +msgid "Sound card #4:" msgstr "Geluidskaart #4:" -msgid "MIDI Out Device:" +msgid "MIDI Out Device:" msgstr "MIDI Out-apparaat:" -msgid "MIDI In Device:" +msgid "MIDI In Device:" msgstr "MIDI In-apparaat:" -msgid "Standalone MPU-401" +msgid "Standalone MPU-401" msgstr "Standalone MPU-401" -msgid "Use FLOAT32 sound" +msgid "Use FLOAT32 sound" msgstr "Gebruik FLOAT32-geluid" -msgid "FM synth driver" +msgid "FM synth driver" msgstr "FM-synthesizer" -msgid "Nuked (more accurate)" +msgid "Nuked (more accurate)" msgstr "Nuked (nauwkeuriger)" -msgid "YMFM (faster)" +msgid "YMFM (faster)" msgstr "YMFM (sneller)" -msgid "Network type:" -msgstr "Type netwerk:" - -msgid "PCap device:" -msgstr "PCap-apparaat:" - -msgid "Network adapter:" -msgstr "Netwerkadapter:" - -msgid "COM1 Device:" +msgid "COM1 Device:" msgstr "COM1-apparaat:" -msgid "COM2 Device:" +msgid "COM2 Device:" msgstr "COM2-apparaat:" -msgid "COM3 Device:" +msgid "COM3 Device:" msgstr "COM3-apparaat:" -msgid "COM4 Device:" +msgid "COM4 Device:" msgstr "COM4-apparaat:" -msgid "LPT1 Device:" +msgid "LPT1 Device:" msgstr "LPT1-apparaat:" -msgid "LPT2 Device:" +msgid "LPT2 Device:" msgstr "LPT2-apparaat:" -msgid "LPT3 Device:" +msgid "LPT3 Device:" msgstr "LPT3-apparaat:" -msgid "LPT4 Device:" +msgid "LPT4 Device:" msgstr "LPT4-apparaat:" -msgid "Serial port 1" +msgid "Serial port 1" msgstr "Seriële poort 1" -msgid "Serial port 2" +msgid "Serial port 2" msgstr "Seriële poort 2" -msgid "Serial port 3" +msgid "Serial port 3" msgstr "Seriële poort 3" -msgid "Serial port 4" +msgid "Serial port 4" msgstr "Seriële poort 4" -msgid "Parallel port 1" +msgid "Parallel port 1" msgstr "Parallelle poort 1" -msgid "Parallel port 2" +msgid "Parallel port 2" msgstr "Parallelle poort 2" -msgid "Parallel port 3" +msgid "Parallel port 3" msgstr "Parallelle poort 3" -msgid "Parallel port 4" +msgid "Parallel port 4" msgstr "Parallelle poort 4" -msgid "HD Controller:" +msgid "HD Controller:" msgstr "HD-controller:" -msgid "FD Controller:" +msgid "FD Controller:" msgstr "FD-Controller:" -msgid "Tertiary IDE Controller" +msgid "Tertiary IDE Controller" msgstr "Tertiaire IDE-controller" -msgid "Quaternary IDE Controller" +msgid "Quaternary IDE Controller" msgstr "Quaternaire IDE-controller" -msgid "SCSI" +msgid "SCSI" msgstr "SCSI" -msgid "Controller 1:" +msgid "Controller 1:" msgstr "Controller 1:" -msgid "Controller 2:" +msgid "Controller 2:" msgstr "Controller 2:" -msgid "Controller 3:" +msgid "Controller 3:" msgstr "Controller 3:" -msgid "Controller 4:" +msgid "Controller 4:" msgstr "Controller 4:" -msgid "Cassette" +msgid "Cassette" msgstr "Cassette" -msgid "Hard disks:" +msgid "Hard disks:" msgstr "Harde schijven:" -msgid "&New..." +msgid "&New..." msgstr "&Nieuw..." -msgid "&Existing..." +msgid "&Existing..." msgstr "&Bestaande..." -msgid "&Remove" +msgid "&Remove" msgstr "&Verwijderen" -msgid "Bus:" +msgid "Bus:" msgstr "Bus:" -msgid "Channel:" +msgid "Channel:" msgstr "Kanaal:" -msgid "ID:" +msgid "ID:" msgstr "ID:" -msgid "&Specify..." +msgid "&Specify..." msgstr "&Specificeer..." -msgid "Sectors:" +msgid "Sectors:" msgstr "Sectoren:" -msgid "Heads:" +msgid "Heads:" msgstr "Heads:" -msgid "Cylinders:" +msgid "Cylinders:" msgstr "Cilinders:" -msgid "Size (MB):" +msgid "Size (MB):" msgstr "Grootte (MB):" -msgid "Type:" +msgid "Type:" msgstr "Type:" -msgid "Image Format:" +msgid "Image Format:" msgstr "Imageformaat:" -msgid "Block Size:" +msgid "Block Size:" msgstr "Blokgrootte:" -msgid "Floppy drives:" +msgid "Floppy drives:" msgstr "Floppy-schijfstations:" -msgid "Turbo timings" +msgid "Turbo timings" msgstr "Turbo timings" -msgid "Check BPB" +msgid "Check BPB" msgstr "Controleer BPB" -msgid "CD-ROM drives:" +msgid "CD-ROM drives:" msgstr "CD-ROM-stations:" -msgid "MO drives:" +msgid "MO drives:" msgstr "MO-schijven:" -msgid "ZIP drives:" +msgid "ZIP drives:" msgstr "ZIP-schijven:" -msgid "ZIP 250" +msgid "ZIP 250" msgstr "ZIP 250" -msgid "ISA RTC:" +msgid "ISA RTC:" msgstr "ISA RTC:" -msgid "ISA Memory Expansion" +msgid "ISA Memory Expansion" msgstr "ISA-geheugenuitbreiding" -msgid "Card 1:" +msgid "Card 1:" msgstr "Kaart 1:" -msgid "Card 2:" +msgid "Card 2:" msgstr "Kaart 2:" -msgid "Card 3:" +msgid "Card 3:" msgstr "Kaart 3:" -msgid "Card 4:" +msgid "Card 4:" msgstr "Kaart 4:" -msgid "ISABugger device" +msgid "ISABugger device" msgstr "ISABugger-apparaat" -msgid "POST card" +msgid "POST card" msgstr "POST-kaart" -msgid "86Box" +msgid "86Box" msgstr "86Box" -msgid "Error" +msgid "Error" msgstr "Fout" -msgid "Fatal error" +msgid "Fatal error" msgstr "Fatale fout" -msgid " - PAUSED" +msgid " - PAUSED" msgstr " - GEPAUZEERD" -msgid "Press Ctrl+Alt+PgDn to return to windowed mode." -msgstr "Druk op Ctrl+Alt+PgDn om terug te gaan naar de venstermodus." - -msgid "Speed" +msgid "Speed" msgstr "Snelheid" -msgid "ZIP %03i %i (%s): %ls" -msgstr "ZIP %03i %i (%s): %ls" +msgid "ZIP %1 %2 (%3): %4" +msgstr "ZIP %1 %2 (%3): %4" -msgid "ZIP images" +msgid "ZIP images" msgstr "ZIP-images" -msgid "86Box could not find any usable ROM images.\n\nPlease download a ROM set and extract it into the \"roms\" directory." +msgid "86Box could not find any usable ROM images.\n\nPlease download a ROM set and extract it into the \"roms\" directory." msgstr "86Box kon geen bruikbare ROM images vinden.\n\nDownload een ROM set en pak deze uit in de map \"roms\"." -msgid "(empty)" +msgid "(empty)" msgstr "(leeg)" -msgid "All files" +msgid "All files" msgstr "Alle bestanden" -msgid "Turbo" +msgid "Turbo" msgstr "Turbo" -msgid "On" +msgid "On" msgstr "Aan" -msgid "Off" +msgid "Off" msgstr "Uit" -msgid "All images" +msgid "All images" msgstr "Alle schijfimages" -msgid "Basic sector images" +msgid "Basic sector images" msgstr "Basissectorimages" -msgid "Surface images" +msgid "Surface images" msgstr "Oppervlakte-images" -msgid "Machine \"%hs\" is not available due to missing ROMs in the roms/machines directory. Switching to an available machine." -msgstr "Machine \"%hs\" is niet beschikbaar door ontbrekende ROMs in de map roms/machines. Overschakelen naar een beschikbare machine." +msgid "Machine \"%hs\" is not available due to missing ROMs in the roms/machines directory. Switching to an available machine." +msgstr "Machine \"%hs\" is niet beschikbaar door ontbrekende ROMs in de map roms/machines. Er wordt overgeschakeld naar een beschikbare machine." -msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Videokaart \"%hs\" is niet beschikbaar door ontbrekende ROMs in de map roms/video. Overschakel over naar een beschikbare videokaart." +msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." +msgstr "Videokaart \"%hs\" is niet beschikbaar door ontbrekende ROMs in de map roms/video. Er wordt overgeschakeld naar een beschikbare videokaart." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Videokaart #2 \"%hs\" is niet beschikbaar door ontbrekende ROMs in de map roms/video. Overschakel over naar een beschikbare videokaart." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "Videokaart #2 \"%hs\" is niet beschikbaar door ontbrekende ROMs in de map roms/video. De tweede videokaart wordt uitgeschakeld." -msgid "Machine" +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Het apparaat \"%hs\" is niet beschikbaar door ontbrekende ROMs. Het apparaat wordt genegeerd." + +msgid "Machine" msgstr "Machine" -msgid "Display" +msgid "Display" msgstr "Scherm" -msgid "Input devices" +msgid "Input devices" msgstr "Invoerapparaten" -msgid "Sound" +msgid "Sound" msgstr "Geluid" -msgid "Network" +msgid "Network" msgstr "Netwerk" -msgid "Ports (COM & LPT)" +msgid "Ports (COM & LPT)" msgstr "Poorten (COM & LPT)" -msgid "Storage controllers" +msgid "Storage controllers" msgstr "Opslagcontrollers" -msgid "Hard disks" +msgid "Hard disks" msgstr "Harde schijven" -msgid "Floppy & CD-ROM drives" +msgid "Floppy & CD-ROM drives" msgstr "Floppy- en CD-ROM-stations" -msgid "Other removable devices" +msgid "Other removable devices" msgstr "Andere verwijderbare apparaten" -msgid "Other peripherals" +msgid "Other peripherals" msgstr "Andere randapparatuur" -msgid "Click to capture mouse" +msgid "Click to capture mouse" msgstr "Klik om muis vast te leggen" -msgid "Press %1 to release mouse" +msgid "Press %1 to release mouse" msgstr "Druk op %1 om de muis los te laten" -msgid "Press %1 or middle button to release mouse" +msgid "Press %1 or middle button to release mouse" msgstr "Druk op %1 of middelste knop om de muis los te laten" -msgid "Bus" +msgid "Bus" msgstr "Bus" -msgid "File" +msgid "File" msgstr "Bestand" -msgid "C" +msgid "C" msgstr "C" -msgid "H" +msgid "H" msgstr "H" -msgid "S" +msgid "S" msgstr "S" -msgid "KB" +msgid "KB" msgstr "KB" -msgid "Could not initialize the video renderer." -msgstr "Kan de videorenderer niet initialiseren." - -msgid "Default" +msgid "Default" msgstr "Standaard" -msgid "%i estat(s) d'espera" -msgstr "%i estat(s) d'espera" +msgid "%1 Wait state(s)" +msgstr "%1 Wachttoestand(en)" -msgid "Type" +msgid "Type" msgstr "Type" -msgid "No PCap devices found" +msgid "No PCap devices found" msgstr "Geen PCap-apparaten gevonden" -msgid "Invalid PCap device" +msgid "Invalid PCap device" msgstr "Ongeldig PCap-apparaat" -msgid "2-axis, 2-button joystick(s)" +msgid "2-axis, 2-button joystick(s)" msgstr "Joystick(s) met 2 assen en 2 knoppen" -msgid "2-axis, 4-button joystick" +msgid "2-axis, 4-button joystick" msgstr "Joystick met 2 assen en 4 knoppen" -msgid "2-axis, 6-button joystick" +msgid "2-axis, 6-button joystick" msgstr "Joystick met 2 assen en 6 knoppen" -msgid "2-axis, 8-button joystick" +msgid "2-axis, 8-button joystick" msgstr "Joystick met 2 assen en 8 knoppen" -msgid "3-axis, 2-button joystick" +msgid "3-axis, 2-button joystick" msgstr "Joystick met 3 assen en 2 knoppen" -msgid "3-axis, 4-button joystick" +msgid "3-axis, 4-button joystick" msgstr "Joystick met 3 assen en 4 knoppen" -msgid "4-axis, 4-button joystick" +msgid "4-axis, 4-button joystick" msgstr "Joystick met 4 assen en 4 knoppen" -msgid "CH Flightstick Pro" +msgid "CH Flightstick Pro" msgstr "CH Flightstick Pro" -msgid "Microsoft SideWinder Pad" +msgid "Microsoft SideWinder Pad" msgstr "Microsoft SideWinder Pad" -msgid "Thrustmaster Flight Control System" +msgid "Thrustmaster Flight Control System" msgstr "Thrustmaster Flight Control systeem" -msgid "None" +msgid "None" msgstr "Geen" -msgid "%u MB (CHS: %i, %i, %i)" -msgstr "%u MB (CHS: %i, %i, %i)" +msgid "%1 MB (CHS: %2, %3, %4)" +msgstr "%1 MB (CHS: %2, %3, %4)" -msgid "Floppy %i (%s): %ls" -msgstr "Floppy %i (%s): %ls" +msgid "Floppy %1 (%2): %3" +msgstr "Floppy %1 (%2): %3" -msgid "Advanced sector images" +msgid "Advanced sector images" msgstr "Geavanceerde sector-images" -msgid "Flux images" +msgid "Flux images" msgstr "Flux images" -msgid "Are you sure you want to hard reset the emulated machine?" +msgid "Are you sure you want to hard reset the emulated machine?" msgstr "Weet je zeker dat je de geëmuleerde machine wilt resetten?" -msgid "Are you sure you want to exit 86Box?" +msgid "Are you sure you want to exit 86Box?" msgstr "Weet je zeker dat je 86Box wilt verlaten?" -msgid "Unable to initialize Ghostscript" +msgid "Unable to initialize Ghostscript" msgstr "Kan Ghostscript niet initialiseren" -msgid "Unable to initialize GhostPCL" +msgid "Unable to initialize GhostPCL" msgstr "Kan GhostPCL niet initialiseren" -msgid "MO %i (%ls): %ls" -msgstr "MO %i (%ls): %ls" +msgid "MO %1 (%2): %3" +msgstr "MO %1 (%2): %3" -msgid "MO images" +msgid "MO images" msgstr "MO-images" -msgid "Welcome to 86Box!" +msgid "Welcome to 86Box!" msgstr "Welkom bij 86Box!" -msgid "Internal device" +msgid "Internal device" msgstr "Intern apparaat" -msgid "Exit" +msgid "Exit" msgstr "&Afsluiten" -msgid "No ROMs found" +msgid "No ROMs found" msgstr "Geen ROMs gevonden" -msgid "Do you want to save the settings?" +msgid "Do you want to save the settings?" msgstr "Wil je de instellingen opslaan?" -msgid "This will hard reset the emulated machine." +msgid "This will hard reset the emulated machine." msgstr "Dit zal de geëmuleerde machine een hard reset geven." -msgid "Save" +msgid "Save" msgstr "Opslaan" -msgid "About 86Box" +msgid "About 86Box" msgstr "Over 86Box" -msgid "86Box v" +msgid "86Box v" msgstr "86Box v" -msgid "An emulator of old computers\n\nAuthors: Miran Grča (OBattler), RichardG867, Jasmine Iwanek, TC1995, coldbrewed, Teemu Korhonen (Manaatti), Joakim L. Gilje, Adrien Moulin (elyosh), Daniel Balsom (gloriouscow), Cacodemon345, Fred N. van Kempen (waltje), Tiseno100, reenigne, and others.\n\nWith previous core contributions from Sarah Walker, leilei, JohnElliott, greatpsycho, and others.\n\nReleased under the GNU General Public License version 2 or later. See LICENSE for more information." +msgid "An emulator of old computers\n\nAuthors: Miran Grča (OBattler), RichardG867, Jasmine Iwanek, TC1995, coldbrewed, Teemu Korhonen (Manaatti), Joakim L. Gilje, Adrien Moulin (elyosh), Daniel Balsom (gloriouscow), Cacodemon345, Fred N. van Kempen (waltje), Tiseno100, reenigne, and others.\n\nWith previous core contributions from Sarah Walker, leilei, JohnElliott, greatpsycho, and others.\n\nReleased under the GNU General Public License version 2 or later. See LICENSE for more information." msgstr "Een emulator van oude computers\n\nAuteurs: Miran Grča (OBattler), RichardG867, Jasmine Iwanek, TC1995, coldbrewed, Teemu Korhonen (Manaatti), Joakim L. Gilje, Adrien Moulin (elyosh), Daniel Balsom (gloriouscow), Cacodemon345, Fred N. van Kempen (waltje), Tiseno100, reenigne, and others.\n\nMet eerdere bijdragen van Sarah Walker, leilei, JohnElliott, greatpsycho en anderen.\n\nUitgebracht onder de GNU General Public License versie 2 of later. Zie LICENSE voor meer informatie." -msgid "Hardware not available" +msgid "Hardware not available" msgstr "Hardware niet beschikbaar" -msgid "Make sure %1 is installed and that you are on a %1-compatible network connection." +msgid "Make sure %1 is installed and that you are on a %1-compatible network connection." msgstr "Zorg ervoor dat %1 is geïnstalleerd en dat je een %1-compatibele netwerkverbinding hebt." -msgid "Invalid configuration" +msgid "Invalid configuration" msgstr "Ongeldige configuratie" -msgid "%1 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 "%1 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 "%1 is vereist voor automatische conversie van PostScript-bestanden naar PDF.\n\nAlle documenten die naar de generieke PostScript-printer worden gestuurd, worden opgeslagen als PostScript-bestanden (.ps)." -msgid "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PCL printer will be saved as Printer Command Language (.pcl) files." +msgid "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PCL printer will be saved as Printer Command Language (.pcl) files." msgstr "%1 is vereist voor automatische conversie van PCL-bestanden naar PDF.\n\nAlle documenten die naar de generieke PCL-printer worden gestuurd, worden opgeslagen als Printer Command Language (.pcl) bestanden." -msgid "Entering fullscreen mode" -msgstr "Volledig scherm modus openen" - -msgid "Don't show this message again" +msgid "Don't show this message again" msgstr "Dit bericht niet meer tonen" -msgid "Don't exit" +msgid "Don't exit" msgstr "Niet afsluiten" -msgid "Reset" +msgid "Reset" msgstr "Reset" -msgid "Don't reset" +msgid "Don't reset" msgstr "Niet resetten" -msgid "CD-ROM images" +msgid "CD-ROM images" msgstr "CD-ROM-images" -msgid "%1 Device Configuration" +msgid "%1 Device Configuration" msgstr "%1 Apparaatconfiguratie" -msgid "Monitor in sleep mode" +msgid "Monitor in sleep mode" msgstr "Monitor in slaapstand" -msgid "OpenGL Shaders" -msgstr "OpenGL Shaders" +msgid "GLSL shaders" +msgstr "GLSL Shaders" -msgid "OpenGL options" -msgstr "OpenGL-opties" - -msgid "You are loading an unsupported configuration" +msgid "You are loading an unsupported configuration" msgstr "U laadt een configuratie die niet wordt ondersteund" -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." +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 "Filteren op CPU type voor de geselecteerde machine is niet mogelijk met de geselecteerde machine.\n\nDit maakt het mogelijk een CPU te kunnen kiezen die anders niet compatible zou zijn met de geselecteerde machine. Je kunt hiermee echter compatibiliteitsproblemen krijgen met de BIOS van de machine of met andere software.\n\nHet inschakelen van deze instelling wordt niet officieel ondersteund en bugrapporten die worden ingediend kunnen als ongeldig worden gesloten." -msgid "Continue" +msgid "Continue" msgstr "Doorgaan" -msgid "Cassette: %s" -msgstr "Cassette: %s" +msgid "Cassette: %1" +msgstr "Cassette: %1" -msgid "Cassette images" +msgid "Cassette images" msgstr "Cassette-images" -msgid "Cartridge %i: %ls" -msgstr "Cartridge %i: %ls" +msgid "Cartridge %1: %2" +msgstr "Cartridge %1: %2" -msgid "Cartridge images" +msgid "Cartridge images" msgstr "Cartridge-images" -msgid "Error initializing renderer" -msgstr "Fout bij het initialiseren van renderer" - -msgid "OpenGL (3.0 Core) renderer could not be initialized. Use another renderer." -msgstr "OpenGL (3.0 Core) renderer kon niet worden geïnitialiseerd. Gebruik een andere renderer." - -msgid "Resume execution" +msgid "Resume execution" msgstr "Hervat executie" -msgid "Pause execution" +msgid "Pause execution" msgstr "Pauze executie" -msgid "Press Ctrl+Alt+Del" +msgid "Press Ctrl+Alt+Del" msgstr "Druk op Ctrl+Alt+Del" -msgid "Press Ctrl+Alt+Esc" +msgid "Press Ctrl+Alt+Esc" msgstr "Druk op Ctrl+Alt+Esc" -msgid "Hard reset" +msgid "Hard reset" msgstr "Harde reset" -msgid "ACPI shutdown" +msgid "ACPI shutdown" msgstr "ACPI uitschakeling" -msgid "Hard disk (%1)" +msgid "Hard disk (%1)" msgstr "Harde schijf (%1)" -msgid "MFM/RLL or ESDI CD-ROM drives never existed" +msgid "MFM/RLL or ESDI CD-ROM drives never existed" msgstr "MFM/RLL of ESDI CD-ROM-stations hebben nooit bestaan" -msgid "Custom..." +msgid "Custom..." msgstr "Aangepast..." -msgid "Custom (large)..." +msgid "Custom (large)..." msgstr "Aangepast (groot)..." -msgid "Add New Hard Disk" +msgid "Add New Hard Disk" msgstr "Nieuwe harde schijf toevoegen" -msgid "Add Existing Hard Disk" +msgid "Add Existing Hard Disk" msgstr "Bestaande harde schijf toevoegen" -msgid "HDI disk images cannot be larger than 4 GB." +msgid "HDI disk images cannot be larger than 4 GB." msgstr "HDI-schijfimages kunnen niet groter zijn dan 4 GB." -msgid "Disk images cannot be larger than 127 GB." +msgid "Disk images cannot be larger than 127 GB." msgstr "Schijfimages kunnen niet groter zijn dan 127 GB." -msgid "Hard disk images" +msgid "Hard disk images" msgstr "Harde schijf-image" -msgid "Unable to read file" +msgid "Unable to read file" msgstr "Kan bestand niet lezen" -msgid "Unable to write file" +msgid "Unable to write file" msgstr "Kan bestand niet schrijven" -msgid "HDI or HDX images with a sector size other than 512 are not supported." +msgid "HDI or HDX images with a sector size other than 512 are not supported." msgstr "HDI- of HDX-image met een andere sectorgrootte dan 512 worden niet ondersteund." -msgid "Disk image file already exists" +msgid "Disk image file already exists" msgstr "Schijfimagebestand bestaat al" -msgid "Please specify a valid file name." +msgid "Please specify a valid file name." msgstr "Geef een geldige bestandsnaam op." -msgid "Disk image created" +msgid "Disk image created" msgstr "Schijfimage gemaakt" -msgid "Make sure the file exists and is readable." +msgid "Make sure the file exists and is readable." msgstr "Controleer of het bestand bestaat en leesbaar is." -msgid "Make sure the file is being saved to a writable directory." +msgid "Make sure the file is being saved to a writable directory." msgstr "Zorg ervoor dat het bestand wordt opgeslagen in een schrijfbare map." -msgid "Disk image too large" +msgid "Disk image too large" msgstr "Schijfimage te groot" -msgid "Remember to partition and format the newly-created drive." +msgid "Remember to partition and format the newly-created drive." msgstr "Vergeet niet om de nieuw aangemaakte schijf te partitioneren en te formatteren." -msgid "The selected file will be overwritten. Are you sure you want to use it?" +msgid "The selected file will be overwritten. Are you sure you want to use it?" msgstr "Het geselecteerde bestand wordt overschreven. Weet u zeker dat u het wilt gebruiken?" -msgid "Unsupported disk image" +msgid "Unsupported disk image" msgstr "Niet-ondersteunde schijfimage" -msgid "Overwrite" +msgid "Overwrite" msgstr "Overschrijven" -msgid "Don't overwrite" +msgid "Don't overwrite" msgstr "Niet overschrijven" -msgid "Raw image" +msgid "Raw image" msgstr "Ruw image" -msgid "HDI image" +msgid "HDI image" msgstr "HDI-image" -msgid "HDX image" +msgid "HDX image" msgstr "HDX-image" -msgid "Fixed-size VHD" +msgid "Fixed-size VHD" msgstr "VHD met vaste grootte" -msgid "Dynamic-size VHD" +msgid "Dynamic-size VHD" msgstr "VHD met dynamisch grootte" -msgid "Differencing VHD" +msgid "Differencing VHD" msgstr "Verschil-VHD" -msgid "(N/A)" -msgstr "(N/A)" +msgid "(N/A)" +msgstr "(N/B)" -msgid "Raw image (.img)" +msgid "Raw image (.img)" msgstr "Ruw image (.img)" -msgid "HDI image (.hdi)" +msgid "HDI image (.hdi)" msgstr "HDI-image (.hdi)" -msgid "HDX image (.hdx)" +msgid "HDX image (.hdx)" msgstr "HDX-image (.hdx)" -msgid "Fixed-size VHD (.vhd)" +msgid "Fixed-size VHD (.vhd)" msgstr "VHD met vaste grootte (.vhd)" -msgid "Dynamic-size VHD (.vhd)" +msgid "Dynamic-size VHD (.vhd)" msgstr "VHD met dynamisch grootte (.vhd)" -msgid "Differencing VHD (.vhd)" +msgid "Differencing VHD (.vhd)" msgstr "Verschil-VHD (.vhd)" -msgid "Large blocks (2 MB)" +msgid "Large blocks (2 MB)" msgstr "Grote blokken (2 MB)" -msgid "Small blocks (512 KB)" +msgid "Small blocks (512 KB)" msgstr "Kleine blokken (512 KB)" -msgid "VHD files" +msgid "VHD files" msgstr "VHD-bestanden" -msgid "Select the parent VHD" +msgid "Select the parent VHD" msgstr "Selecteer de bovenliggende 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?" +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 "Dit kan betekenen dat de bovenliggende image is gewijzigd nadat de verschil-image is gemaakt.\n\nDit kan ook gebeuren als de imagebestanden zijn verplaatst of gekopieerd, of door een fout in het programma waarmee deze schijf is gemaakt.\n\nWil je de tijdstempels herstellen?" -msgid "Parent and child disk timestamps do not match" -msgstr "Bovenliggende en onderliggende schijf tijdstempels komen niet overeen" +msgid "Parent and child disk timestamps do not match" +msgstr "Bovenliggende en onderliggende schijftijdstempels komen niet overeen" -msgid "Could not fix VHD timestamp." +msgid "Could not fix VHD timestamp." msgstr "Kan VHD tijdstempel niet herstellen." -msgid "MFM/RLL" +msgid "MFM/RLL" msgstr "MFM/RLL" -msgid "XTA" +msgid "XTA" msgstr "XTA" -msgid "ESDI" +msgid "ESDI" msgstr "ESDI" -msgid "IDE" +msgid "IDE" msgstr "IDE" -msgid "ATAPI" +msgid "ATAPI" msgstr "ATAPI" -msgid "CD-ROM %i (%s): %s" -msgstr "CD-ROM %i (%s): %s" +msgid "CD-ROM %1 (%2): %3" +msgstr "CD-ROM %1 (%2): %3" -msgid "160 KB" +msgid "160 KB" msgstr "160 KB" -msgid "180 KB" +msgid "180 KB" msgstr "180 KB" -msgid "320 KB" +msgid "320 KB" msgstr "320 KB" -msgid "360 KB" +msgid "360 KB" msgstr "360 KB" -msgid "640 KB" +msgid "640 KB" msgstr "640 KB" -msgid "720 KB" +msgid "720 KB" msgstr "720 KB" -msgid "1.2 MB" +msgid "1.2 MB" msgstr "1,2 MB" -msgid "1.25 MB" +msgid "1.25 MB" msgstr "1,25 MB" -msgid "1.44 MB" +msgid "1.44 MB" msgstr "1,44 MB" -msgid "DMF (cluster 1024)" +msgid "DMF (cluster 1024)" msgstr "DMF (cluster 1024)" -msgid "DMF (cluster 2048)" +msgid "DMF (cluster 2048)" msgstr "DMF (cluster 2048)" -msgid "2.88 MB" +msgid "2.88 MB" msgstr "2,88 MB" -msgid "ZIP 100" +msgid "ZIP 100" msgstr "ZIP 100" -msgid "3.5\" 128 MB (ISO 10090)" +msgid "3.5\" 128 MB (ISO 10090)" msgstr "3,5\" 128 MB (ISO 10090)" -msgid "3.5\" 230 MB (ISO 13963)" +msgid "3.5\" 230 MB (ISO 13963)" msgstr "3,5\" 230 MB (ISO 13963)" -msgid "3.5\" 540 MB (ISO 15498)" +msgid "3.5\" 540 MB (ISO 15498)" msgstr "3,5\" 540 MB (ISO 15498)" -msgid "3.5\" 640 MB (ISO 15498)" +msgid "3.5\" 640 MB (ISO 15498)" msgstr "3,5\" 640 MB (ISO 15498)" -msgid "3.5\" 1.3 GB (GigaMO)" +msgid "3.5\" 1.3 GB (GigaMO)" msgstr "3,5\" 1,3 GB (GigaMO)" -msgid "3.5\" 2.3 GB (GigaMO 2)" +msgid "3.5\" 2.3 GB (GigaMO 2)" msgstr "3,5\" 2,3 GB (GigaMO 2)" -msgid "5.25\" 600 MB" +msgid "5.25\" 600 MB" msgstr "5,25\" 600 MB" -msgid "5.25\" 650 MB" +msgid "5.25\" 650 MB" msgstr "5,25\" 650 MB" -msgid "5.25\" 1 GB" +msgid "5.25\" 1 GB" msgstr "5,25\" 1 GB" -msgid "5.25\" 1.3 GB" +msgid "5.25\" 1.3 GB" msgstr "5,25\" 1,3 GB" -msgid "Perfect RPM" +msgid "Perfect RPM" msgstr "Perfecte RPM" -msgid "1% below perfect RPM" +msgid "1% below perfect RPM" msgstr "1% onder perfecte RPM" -msgid "1.5% below perfect RPM" +msgid "1.5% below perfect RPM" msgstr "1,5% onder perfecte RPM" -msgid "2% below perfect RPM" +msgid "2% below perfect RPM" msgstr "2% onder perfecte RPM" -msgid "(System Default)" +msgid "(System Default)" msgstr "(Systeemstandaard)" -msgid "Failed to initialize network driver" +msgid "Failed to initialize network driver" msgstr "Netwerkstuurprogramma niet geïnitialiseerd" -msgid "The network configuration will be switched to the null driver" +msgid "The network configuration will be switched to the null driver" msgstr "De netwerkconfiguratie wordt overgeschakeld naar de nul-driver" -msgid "Mouse sensitivity:" +msgid "Mouse sensitivity:" msgstr "Muisgevoeligheid:" -msgid "Select media images from program working directory" +msgid "Select media images from program working directory" msgstr "Selecteer media-images uit de werkmap van het programma" -msgid "PIT mode:" +msgid "PIT mode:" msgstr "PIT-modus:" -msgid "Auto" +msgid "Auto" msgstr "Auto" -msgid "Slow" +msgid "Slow" msgstr "Langzaam" -msgid "Fast" +msgid "Fast" msgstr "Snel" -msgid "&Auto-pause on focus loss" +msgid "&Auto-pause on focus loss" msgstr "&Autopauze bij focusverlies" -msgid "WinBox is no longer supported" +msgid "WinBox is no longer supported" msgstr "WinBox wordt niet langer ondersteund" -msgid "Development of the WinBox manager stopped in 2022 due to a lack of maintainers. As we direct our efforts towards making 86Box even better, we have made the decision to no longer support WinBox as a manager.\n\nNo further updates will be provided through WinBox, and you may encounter incorrect behavior should you continue using it with newer versions of 86Box. Any bug reports related to WinBox behavior will be closed as invalid.\n\nGo to 86box.net for a list of other managers you can use." +msgid "Development of the WinBox manager stopped in 2022 due to a lack of maintainers. As we direct our efforts towards making 86Box even better, we have made the decision to no longer support WinBox as a manager.\n\nNo further updates will be provided through WinBox, and you may encounter incorrect behavior should you continue using it with newer versions of 86Box. Any bug reports related to WinBox behavior will be closed as invalid.\n\nGo to 86box.net for a list of other managers you can use." msgstr "De ontwikkeling van de WinBox manager is gestopt in 2022 door een gebrek aan beheerders. Omdat we onze inspanningen richten op het nog beter maken van 86Box, hebben we de beslissing genomen om WinBox niet langer te ondersteunen als een manager.\n\nEr zullen geen verdere updates worden geleverd door WinBox. Je kunt onjuist gedrag tegenkomen als je het blijft gebruiken met nieuwere versies van 86Box. Alle bugrapporten gerelateerd aan het gedrag van WinBox zullen worden gesloten als ongeldig.\n\nGa naar 86box.net voor een lijst van andere managers die je kunt gebruiken." -msgid "Generate" +msgid "Generate" msgstr "Genereren" -msgid "Joystick configuration" +msgid "Joystick configuration" msgstr "Joystick configuratie " -msgid "Device" +msgid "Device" msgstr "Apparaat" -msgid "%1 (X axis)" +msgid "%1 (X axis)" msgstr "%1 (X-as)" -msgid "%1 (Y axis)" +msgid "%1 (Y axis)" msgstr "%1 (Y-as)" -msgid "MCA devices" +msgid "MCA devices" msgstr "MCA-apparaten" -msgid "List of MCA devices:" +msgid "List of MCA devices:" msgstr "Lijst van MCA-apparaten:" -msgid "Tablet tool" +msgid "Tablet tool" msgstr "Tablet-hulpmiddel" -msgid "Qt (OpenGL &ES)" +msgid "Qt (OpenGL &ES)" msgstr "Qt (OpenGL &ES)" -msgid "About Qt" +msgid "About Qt" msgstr "Over Qt" -msgid "MCA devices..." +msgid "MCA devices..." msgstr "MCA-apparaten..." -msgid "Show non-primary monitors" +msgid "Show non-primary monitors" msgstr "Toon niet-primaire monitors" -msgid "Open screenshots folder..." +msgid "Open screenshots folder..." msgstr "Map met schermafbeeldingen openen..." -msgid "Apply fullscreen stretch mode when maximized" -msgstr "Pas fullscreen stretchmodus toe wanneer gemaximaliseerd" +msgid "Apply fullscreen stretch mode when maximized" +msgstr "Schakel de volledig scherm-uitrekmodus in bij maximaliseren" -msgid "Cursor/Puck" +msgid "Cursor/Puck" msgstr "Cursor/Puck" -msgid "Pen" +msgid "Pen" msgstr "Pen" -msgid "Host CD/DVD Drive (%1:)" +msgid "Host CD/DVD Drive (%1:)" msgstr "Host cd/dvd-station (%1:)" -msgid "&Connected" +msgid "&Connected" msgstr "&Verbonden" -msgid "Clear image history" +msgid "Clear image history" msgstr "Imagegeschiedenis verwijderen" -msgid "Create..." +msgid "Create..." msgstr "Creëer..." -msgid "previous image" -msgstr "vorige image" - -msgid "Host CD/DVD Drive (%1)" +msgid "Host CD/DVD Drive (%1)" msgstr "Host CD/DVD-station (%1)" -msgid "Unknown Bus" +msgid "Unknown Bus" msgstr "Onbekende bus" -msgid "Null Driver" +msgid "Null Driver" msgstr "Null Driver" -msgid "NIC %02i (%ls) %ls" -msgstr "NIC %02i (%ls) %ls" +msgid "NIC %1 (%2) %3" +msgstr "NIC %1 (%2) %3" -msgid "Error opening \"%1\": %2" -msgstr "Fout bij het openen van \"%1\": %2" - -msgid "Error compiling vertex shader in file \"%1\"" -msgstr "Fout bij het compileren van vertex shader in bestand \"%1\"" - -msgid "Error compiling fragment shader in file \"%1\"" -msgstr "Fout bij het compileren van fragment shader in bestand \"%1\"" - -msgid "Error linking shader program in file \"%1\"" -msgstr "Fout bij koppelen shaderprogramma in bestand \"%1\"" - -msgid "OpenGL 3.0 renderer options" -msgstr "OpenGL 3.0 renderer opties" - -msgid "Render behavior" +msgid "Render behavior" msgstr "Rendergedrag" -msgid "Use target framerate:" +msgid "Use target framerate:" msgstr "Gebruik doelframerate:" -msgid " fps" +msgid " fps" msgstr " fps" -msgid "VSync" +msgid "VSync" msgstr "VSync" -msgid "<html><head/><body><p>Render each frame immediately, in sync with the emulated display.</p><p><span style=" font-style:italic;">This is the recommended option if the shaders in use don't utilize frametime for animated effects.</span></p></body></html>" -msgstr "<html><head/><body><p>Onmiddellijk elk frame synchroon met het geëmuleerde beeldscherm renderen.</p><p><span style=" font-style:italic;">Dit is de aanbevolen optie als de gebruikte shaders geen frametime gebruiken voor geanimeerde effecten.</span></p></body></html>" - -msgid "Synchronize with video" +msgid "Synchronize with video" msgstr "Synchroniseren met video" -msgid "Shaders" +msgid "Shaders" msgstr "Shaders" -msgid "Remove" +msgid "Remove" msgstr "Verwijderen" -msgid "No shader selected" -msgstr "Geen shader geselecteerd" - -msgid "Browse..." +msgid "Browse..." msgstr "Bladeren..." -msgid "Shader error" -msgstr "Shader-fout" +msgid "Couldn't create OpenGL context." +msgstr "Kan OpenGL context niet aanmaken." -msgid "Could not load shaders." -msgstr "Kan shaders niet laden." - -msgid "More information in details." -msgstr "Meer informatie in details." - -msgid "Couldn't create OpenGL context." -msgstr "Kan OpenGL context niet maken." - -msgid "Couldn't switch to OpenGL context." +msgid "Couldn't switch to OpenGL context." msgstr "Kan niet overschakelen naar OpenGL context." -msgid "OpenGL version 3.0 or greater is required. Current version is %1.%2" +msgid "OpenGL version 3.0 or greater is required. Current version is %1.%2" msgstr "OpenGL versie 3.0 of hoger is vereist. De huidige versie is %1.%2" -msgid "OpenGL initialization failed. Error %1." -msgstr "OpenGL initialisatie mislukt. Fout %1." - -msgid "Error initializing OpenGL" +msgid "Error initializing OpenGL" msgstr "Fout bij het initialiseren van OpenGL" -msgid "Falling back to software rendering.\n" -msgstr "Terugvallen op software rendering.\n" +msgid "\nFalling back to software rendering." +msgstr "\nTerugvallen op software rendering." -msgid "Allocating memory for unpack buffer failed.\n" -msgstr "Toewijzen van geheugen voor uitpakbuffer mislukt.\n" +msgid "

When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" +msgstr "

Bij het selecteren van media-images (CD-ROM, floppy, etc.) zal de \"open dialoog\" starten in dezelfde map als het 86Box configuratiebestand. Deze instelling is doet er waarschijnlijk alleen toe op macOS.

" -msgid "<html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html>" -msgstr "<html><head/><body><p>Bij het selecteren van media-images (CD-ROM, floppy, etc.) zal de \"open dialoog\" starten in dezelfde map als het 86Box configuratiebestand. Deze instelling is doet er waarschijnlijk alleen toe op macOS.</p></body></html>" - -msgid "This machine might have been moved or copied." +msgid "This machine might have been moved or copied." msgstr "Deze machine is misschien verplaatst of gekopieerd." -msgid "In order to ensure proper networking functionality, 86Box needs to know if this machine was moved or copied.\n\nSelect \"I Copied It\" if you are not sure." +msgid "In order to ensure proper networking functionality, 86Box needs to know if this machine was moved or copied.\n\nSelect \"I Copied It\" if you are not sure." msgstr "Om een goede netwerkfunctionaliteit te garanderen, moet 86Box weten of deze machine verplaatst of gekopieerd is.\n\nSelecteer \"Ik heb het gekopieerd\" als u het niet zeker weet." -msgid "I Moved It" +msgid "I Moved It" msgstr "Ik heb het verplaatst" -msgid "I Copied It" +msgid "I Copied It" msgstr "Ik heb het gekopieerd" -msgid "86Box Monitor #" +msgid "86Box Monitor #" msgstr "86Box Monitor #" -msgid "No MCA devices." +msgid "No MCA devices." msgstr "Geen MCA-apparaten." -msgid "MiB" +msgid "MiB" msgstr "MiB" -msgid "Network Card #1" +msgid "Network Card #1" msgstr "Netwerkkaart #1" -msgid "Network Card #2" +msgid "Network Card #2" msgstr "Netwerkkaart #2" -msgid "Network Card #3" +msgid "Network Card #3" msgstr "Netwerkkaart #3" -msgid "Network Card #4" +msgid "Network Card #4" msgstr "Netwerkkaart #4" -msgid "Mode" -msgstr "Modus" +msgid "Mode:" +msgstr "Modus:" -msgid "Interface" -msgstr "Interface" +msgid "Interface:" +msgstr "Interface:" -msgid "Adapter" -msgstr "Adapter" +msgid "Adapter:" +msgstr "Adapter:" -msgid "VDE Socket" -msgstr "VDE-socket" +msgid "VDE Socket:" +msgstr "VDE-socket:" -msgid "86Box Unit Tester" +msgid "86Box Unit Tester" msgstr "86Box apparaattester" -msgid "Novell NetWare 2.x Key Card" +msgid "Novell NetWare 2.x Key Card" msgstr "Novell NetWare 2.x Key Card" -msgid "Serial port passthrough 1" +msgid "Serial port passthrough 1" msgstr "Seriële poort doorvoer 1" -msgid "Serial port passthrough 2" +msgid "Serial port passthrough 2" msgstr "Seriële poort doorvoer 2" -msgid "Serial port passthrough 3" +msgid "Serial port passthrough 3" msgstr "Seriële poort doorvoer 3" -msgid "Serial port passthrough 4" +msgid "Serial port passthrough 4" msgstr "Seriële poort doorvoer 4" -msgid "Vision Systems LBA Enhancer" -msgstr "Vision Systems LBA Enhancer" - -msgid "Renderer options..." +msgid "Renderer options..." msgstr "Renderer-opties..." -msgid "Logitech/Microsoft Bus Mouse" +msgid "Logitech/Microsoft Bus Mouse" msgstr "Logitech/Microsoft busmuis" -msgid "Microsoft Bus Mouse (InPort)" +msgid "Microsoft Bus Mouse (InPort)" msgstr "Microsoft busmuis (InPort)" -msgid "Mouse Systems Serial Mouse" +msgid "Mouse Systems Serial Mouse" msgstr "Mouse Systems seriële muis" -msgid "Microsoft Serial Mouse" +msgid "Microsoft Serial Mouse" msgstr "Microsoft seriële muis" -msgid "Logitech Serial Mouse" +msgid "Logitech Serial Mouse" msgstr "Logitech seriële muis" -msgid "PS/2 Mouse" +msgid "PS/2 Mouse" msgstr "PS/2-muis" -msgid "3M MicroTouch (Serial)" +msgid "3M MicroTouch (Serial)" msgstr "3M MicroTouch (serieel)" -msgid "[COM] Standard Hayes-compliant Modem" +msgid "[COM] Standard Hayes-compliant Modem" msgstr "COM] Standaard Hayes-compatibele modem " -msgid "Roland MT-32 Emulation" +msgid "Roland MT-32 Emulation" msgstr "Roland MT-32-emulatie" -msgid "Roland MT-32 (New) Emulation" +msgid "Roland MT-32 (New) Emulation" msgstr "Roland MT-32 (nieuwe) emulatie" -msgid "Roland CM-32L Emulation" +msgid "Roland CM-32L Emulation" msgstr "Roland CM-32L-emulatie" -msgid "Roland CM-32LN Emulation" +msgid "Roland CM-32LN Emulation" msgstr "Roland CM-32LN-emulatie" -msgid "OPL4-ML Daughterboard" +msgid "OPL4-ML Daughterboard" msgstr "OPL4-ML-dochterbord" -msgid "System MIDI" +msgid "System MIDI" msgstr "Systeem MIDI" -msgid "MIDI Input Device" +msgid "MIDI Input Device" msgstr "MIDI-ingangsapparaat" -msgid "BIOS Address" +msgid "BIOS Address" msgstr "BIOS-adres" -msgid "Enable BIOS extension ROM Writes" +msgid "Enable BIOS extension ROM Writes" msgstr "BIOS-extensie ROM Writes inschakelen" -msgid "Address" +msgid "Address" msgstr "Adres" -msgid "IRQ" +msgid "IRQ" msgstr "IRQ" -msgid "BIOS Revision" +msgid "BIOS Revision" msgstr "BIOS Revisie" -msgid "Translate 26 -> 17" +msgid "Translate 26 -> 17" msgstr "Vertaal 26 -> 17" -msgid "Language" +msgid "Language" msgstr "Taal" -msgid "Enable backlight" +msgid "Enable backlight" msgstr "Backlight inschakelen" -msgid "Invert colors" -msgstr "Kleuren omkeren" +msgid "Invert colors" +msgstr "Kleuren inverteren" -msgid "BIOS size" +msgid "BIOS size" msgstr "BIOS-grootte" -msgid "Map C0000-C7FFF as UMB" +msgid "Map C0000-C7FFF as UMB" msgstr "Geheugenadres C0000-C7FFF toewijzen aan UMB" -msgid "Map C8000-CFFFF as UMB" +msgid "Map C8000-CFFFF as UMB" msgstr "Geheugenadres C8000-CFFFF toewijzen aan UMB" -msgid "Map D0000-D7FFF as UMB" +msgid "Map D0000-D7FFF as UMB" msgstr "Geheugenadres D0000-D7FFF toewijzen aan UMB" -msgid "Map D8000-DFFFF as UMB" +msgid "Map D8000-DFFFF as UMB" msgstr "Geheugenadres D8000-DFFFF toewijzen aan UMB" -msgid "Map E0000-E7FFF as UMB" +msgid "Map E0000-E7FFF as UMB" msgstr "Geheugenadres E0000-E7FFF toewijzen aan UMB" -msgid "Map E8000-EFFFF as UMB" +msgid "Map E8000-EFFFF as UMB" msgstr "Geheugenadres E8000-EFFFF toewijzen aan UMB" -msgid "JS9 Jumper (JIM)" +msgid "JS9 Jumper (JIM)" msgstr "JS9 Jumper (JIM)" -msgid "MIDI Output Device" +msgid "MIDI Output Device" msgstr "MIDI-uitgangsapparaat" -msgid "MIDI Real time" +msgid "MIDI Real time" msgstr "MIDI real-time" -msgid "MIDI Thru" +msgid "MIDI Thru" msgstr "MIDI doorvoer" -msgid "MIDI Clockout" +msgid "MIDI Clockout" msgstr "MIDI Clockout" -msgid "SoundFont" +msgid "SoundFont" msgstr "SoundFont" -msgid "Output Gain" +msgid "Output Gain" msgstr "Output Gain" -msgid "Chorus" +msgid "Chorus" msgstr "Chorus" -msgid "Chorus Voices" +msgid "Chorus Voices" msgstr "Chorus-stemmen" -msgid "Chorus Level" +msgid "Chorus Level" msgstr "Chorus-niveau" -msgid "Chorus Speed" +msgid "Chorus Speed" msgstr "Chorus-snelheid" -msgid "Chorus Depth" +msgid "Chorus Depth" msgstr "Chorus-diepte" -msgid "Chorus Waveform" +msgid "Chorus Waveform" msgstr "Chorus-golfvorm" -msgid "Reverb" +msgid "Reverb" msgstr "Reverb" -msgid "Reverb Room Size" +msgid "Reverb Room Size" msgstr "Reverbkamer afmetingen" -msgid "Reverb Damping" +msgid "Reverb Damping" msgstr "Reverbdemping" -msgid "Reverb Width" +msgid "Reverb Width" msgstr "Reverbbreedte" -msgid "Reverb Level" +msgid "Reverb Level" msgstr "Reverbniveau" -msgid "Interpolation Method" +msgid "Interpolation Method" msgstr "Interpolatiemethode" -msgid "Reverb Output Gain" +msgid "Reverb Output Gain" msgstr "Reverbuitgang Versterking" -msgid "Reversed stereo" +msgid "Reversed stereo" msgstr "Omgekeerde stereo" -msgid "Nice ramp" +msgid "Nice ramp" msgstr "Mooie helling" -msgid "Hz" +msgid "Hz" msgstr "Hz" -msgid "Buttons" +msgid "Buttons" msgstr "Knoppen" -msgid "Serial Port" +msgid "Serial Port" msgstr "Seriële poort" -msgid "RTS toggle" +msgid "RTS toggle" msgstr "RTS toggle" -msgid "Revision" +msgid "Revision" msgstr "Revisie" -msgid "Controller" +msgid "Controller" msgstr "Controller" -msgid "Show Crosshair" +msgid "Show Crosshair" msgstr "Toon dradenkruis" -msgid "DMA" +msgid "DMA" msgstr "DMA" -msgid "MAC Address" +msgid "MAC Address" msgstr "MAC-adres" -msgid "MAC Address OUI" +msgid "MAC Address OUI" msgstr "MAC-adres OUI" -msgid "Enable BIOS" +msgid "Enable BIOS" msgstr "BIOS inschakelen" -msgid "Baud Rate" +msgid "Baud Rate" msgstr "Baud-snelheid" -msgid "TCP/IP listening port" +msgid "TCP/IP listening port" msgstr "TCP/IP-luisterpoort" -msgid "Phonebook File" +msgid "Phonebook File" msgstr "Telefoonboekbestand" -msgid "Telnet emulation" +msgid "Telnet emulation" msgstr "Telnet-emulatie" -msgid "RAM Address" +msgid "RAM Address" msgstr "RAM-adres" -msgid "RAM size" +msgid "RAM size" msgstr "RAM-grootte" -msgid "Initial RAM size" +msgid "Initial RAM size" msgstr "Oorspronkelijke RAM-grootte" -msgid "Serial Number" +msgid "Serial Number" msgstr "Serienummer" -msgid "Host ID" +msgid "Host ID" msgstr "Host-ID" -msgid "FDC Address" +msgid "FDC Address" msgstr "FDC Adres" -msgid "MPU-401 Address" +msgid "MPU-401 Address" msgstr "MPU-401 Adres" -msgid "MPU-401 IRQ" +msgid "MPU-401 IRQ" msgstr "MPU-401 IRQ" -msgid "Receive MIDI input" +msgid "Receive MIDI input" msgstr "MIDI-ingang ontvangen" -msgid "Low DMA" +msgid "Low DMA" msgstr "Lage DMA" -msgid "Enable Game port" +msgid "Enable Game port" msgstr "Game-poort inschakelen" -msgid "Surround module" +msgid "Surround module" msgstr "Surroundmodule" -msgid "CODEC" +msgid "CODEC" msgstr "Codec" -msgid "Raise CODEC interrupt on CODEC setup (needed by some drivers)" +msgid "Raise CODEC interrupt on CODEC setup (needed by some drivers)" msgstr "Verhoog CODEC interrupt bij CODEC setup (nodig voor sommige stuurprogramma's)" -msgid "SB Address" +msgid "SB Address" msgstr "SB-adres" -msgid "WSS IRQ" +msgid "WSS IRQ" msgstr "WSS IRQ" -msgid "WSS DMA" +msgid "WSS DMA" msgstr "WSS DMA" -msgid "Enable OPL" +msgid "Enable OPL" msgstr "OPL inschakelen" -msgid "Receive MIDI input (MPU-401)" +msgid "Receive MIDI input (MPU-401)" msgstr "MIDI-ingang ontvangen (MPU-401)" -msgid "SB low DMA" +msgid "SB low DMA" msgstr "SB lage DMA" -msgid "6CH variant (6-channel)" +msgid "6CH variant (6-channel)" msgstr "6CH-variant (6-kanaals)" -msgid "Enable CMS" +msgid "Enable CMS" msgstr "CMS inschakelen" -msgid "Mixer" +msgid "Mixer" msgstr "Mixer" -msgid "High DMA" +msgid "High DMA" msgstr "Hoge DMA" -msgid "Control PC speaker" +msgid "Control PC speaker" msgstr "Bestuur pc-luidspreker" -msgid "Memory size" +msgid "Memory size" msgstr "Geheugengrootte" -msgid "EMU8000 Address" +msgid "EMU8000 Address" msgstr "EMU8000 Adres" -msgid "IDE Controller" +msgid "IDE Controller" msgstr "IDE-controller" -msgid "Codec" +msgid "Codec" msgstr "Codec" -msgid "GUS type" +msgid "GUS type" msgstr "GUS-type" -msgid "Enable 0x04 \"Exit 86Box\" command" +msgid "Enable 0x04 \"Exit 86Box\" command" msgstr "Schakel het commando 0x04 \"Exit 86Box\" in" -msgid "Display type" +msgid "Display type" msgstr "Scherm type" -msgid "Composite type" +msgid "Composite type" msgstr "Composite type" -msgid "RGB type" +msgid "RGB type" msgstr "RGB-type" -msgid "Line doubling type" +msgid "Line doubling type" msgstr "Type lijnverdubbeling" -msgid "Snow emulation" +msgid "Snow emulation" msgstr "Sneeuwemulatie" -msgid "Monitor type" +msgid "Monitor type" msgstr "Type monitor" -msgid "Character set" +msgid "Character set" msgstr "Tekenset" -msgid "XGA type" +msgid "XGA type" msgstr "XGA-type" -msgid "Instance" +msgid "Instance" msgstr "Instantie" -msgid "MMIO Address" +msgid "MMIO Address" msgstr "MMIO-adres" -msgid "RAMDAC type" +msgid "RAMDAC type" msgstr "RAMDAC type" -msgid "Blend" +msgid "Blend" msgstr "Mengen" -msgid "Bilinear filtering" +msgid "Bilinear filtering" msgstr "Bilineaire filtering" -msgid "Dithering" +msgid "Dithering" msgstr "Dithering" -msgid "Enable NMI for CGA emulation" +msgid "Enable NMI for CGA emulation" msgstr "NMI inschakelen voor CGA-emulatie" -msgid "Voodoo type" +msgid "Voodoo type" msgstr "Voodoo-type" -msgid "Framebuffer memory size" +msgid "Framebuffer memory size" msgstr "Framebuffer geheugengrootte" -msgid "Texture memory size" +msgid "Texture memory size" msgstr "Grootte textuurgeheugen" -msgid "Dither subtraction" +msgid "Dither subtraction" msgstr "Dither aftrekken" -msgid "Screen Filter" +msgid "Screen Filter" msgstr "Schermfilter" -msgid "Render threads" +msgid "Render threads" msgstr "Render threads" -msgid "SLI" +msgid "SLI" msgstr "SLI" -msgid "Start Address" +msgid "Start Address" msgstr "Startadres" -msgid "Contiguous Size" +msgid "Contiguous Size" msgstr "Aaneengesloten grootte" -msgid "I/O Width" +msgid "I/O Width" msgstr "I/O-breedte" -msgid "Transfer Speed" +msgid "Transfer Speed" msgstr "Overdrachtssnelheid" -msgid "EMS mode" +msgid "EMS mode" msgstr "EMS-modus" -msgid "Address for > 2 MB" +msgid "Address for > 2 MB" msgstr "Adres voor > 2 MB" -msgid "Frame Address" +msgid "Frame Address" msgstr "Frameadres" -msgid "USA" +msgid "USA" msgstr "USA" -msgid "Danish" +msgid "Danish" msgstr "Deens" -msgid "Always at selected speed" +msgid "Always at selected speed" msgstr "Altijd op geselecteerde snelheid" -msgid "BIOS setting + Hotkeys (off during POST)" +msgid "BIOS setting + Hotkeys (off during POST)" msgstr "BIOS-instelling + Sneltoetsen (niet actief tijdens POST)" -msgid "64 kB starting from F0000" +msgid "64 kB starting from F0000" msgstr "64 kB vanaf F0000" -msgid "128 kB starting from E0000 (address MSB inverted, last 64KB first)" +msgid "128 kB starting from E0000 (address MSB inverted, last 64KB first)" msgstr "128 kB vanaf E0000 (geïnverteerd MSB adres, laatste 64KB eerst)" -msgid "Sine" +msgid "Sine" msgstr "Sinus" -msgid "Triangle" +msgid "Triangle" msgstr "Driehoek" -msgid "Linear" +msgid "Linear" msgstr "Lineair" -msgid "4th Order" +msgid "4th Order" msgstr "4e Orde" -msgid "7th Order" +msgid "7th Order" msgstr "7e Orde" -msgid "Non-timed (original)" +msgid "Non-timed (original)" msgstr "Niet-getimed (origineel)" -msgid "45 Hz (JMP2 not populated)" +msgid "45 Hz (JMP2 not populated)" msgstr "45 Hz (JMP2 niet gezet)" -msgid "Two" +msgid "Two" msgstr "Twee" -msgid "Three" +msgid "Three" msgstr "Drie" -msgid "Wheel" +msgid "Wheel" msgstr "Wiel" -msgid "Five + Wheel" +msgid "Five + Wheel" msgstr "Vijf + Wiel" -msgid "A3 - SMT2 Serial / SMT3(R)V" +msgid "Five + 2 Wheels" +msgstr "Vijf + 2 Wielen" + +msgid "A3 - SMT2 Serial / SMT3(R)V" msgstr "A3 - SMT2 Serieel / SMT3(R)V" -msgid "Q1 - SMT3(R) Serial" +msgid "Q1 - SMT3(R) Serial" msgstr "Q1 - SMT3(R) Serieel" -msgid "8 KB" +msgid "8 KB" msgstr "8 KB" -msgid "32 KB" +msgid "32 KB" msgstr "32 KB" -msgid "16 KB" +msgid "16 KB" msgstr "16 KB" -msgid "64 KB" +msgid "64 KB" msgstr "64 KB" -msgid "Disable BIOS" +msgid "Disable BIOS" msgstr "BIOS uitschakelen" -msgid "512 KB" +msgid "512 KB" msgstr "512 KB" -msgid "2 MB" +msgid "2 MB" msgstr "2 MB" -msgid "8 MB" +msgid "8 MB" msgstr "8 MB" -msgid "28 MB" +msgid "28 MB" msgstr "28 MB" -msgid "1 MB" +msgid "1 MB" msgstr "1 MB" -msgid "4 MB" +msgid "4 MB" msgstr "4 MB" -msgid "12 MB" +msgid "12 MB" msgstr "12 MB" -msgid "16 MB" +msgid "16 MB" msgstr "16 MB" -msgid "20 MB" +msgid "20 MB" msgstr "20 MB" -msgid "24 MB" +msgid "24 MB" msgstr "24 MB" -msgid "SigmaTel STAC9721T (stereo)" +msgid "SigmaTel STAC9721T (stereo)" msgstr "SigmaTel STAC9721T (stereo)" -msgid "Classic" +msgid "Classic" msgstr "Klassiek" -msgid "256 KB" +msgid "256 KB" msgstr "256 KB" -msgid "Composite" +msgid "Composite" msgstr "Composite" -msgid "Old" +msgid "Old" msgstr "Oud" -msgid "New" +msgid "New" msgstr "Nieuw" -msgid "Color (generic)" +msgid "Color (generic)" msgstr "Kleur (algemeen)" -msgid "Green Monochrome" +msgid "Green Monochrome" msgstr "Groen monochroom" -msgid "Amber Monochrome" +msgid "Amber Monochrome" msgstr "Amber Monochroom" -msgid "Gray Monochrome" +msgid "Gray Monochrome" msgstr "Grijs monochroom" -msgid "Color (no brown)" +msgid "Color (no brown)" msgstr "Kleur (geen bruin)" -msgid "Color (IBM 5153)" +msgid "Color (IBM 5153)" msgstr "Kleur (IBM 5153)" -msgid "Simple doubling" +msgid "Simple doubling" msgstr "Eenvoudige verdubbeling" -msgid "sRGB interpolation" +msgid "sRGB interpolation" msgstr "sRGB-interpolatie" -msgid "Linear interpolation" +msgid "Linear interpolation" msgstr "Lineaire interpolatie" -msgid "128 KB" +msgid "128 KB" msgstr "128 KB" -msgid "Monochrome (5151/MDA) (white)" +msgid "Monochrome (5151/MDA) (white)" msgstr "Monochroom (5151/MDA) (wit)" -msgid "Monochrome (5151/MDA) (green)" +msgid "Monochrome (5151/MDA) (green)" msgstr "Monochroom (5151/MDA) (groen)" -msgid "Monochrome (5151/MDA) (amber)" +msgid "Monochrome (5151/MDA) (amber)" msgstr "Monochroom (5151/MDA) (amber)" -msgid "Color 40x25 (5153/CGA)" +msgid "Color 40x25 (5153/CGA)" msgstr "Kleur 40x25 (5153/CGA)" -msgid "Color 80x25 (5153/CGA)" +msgid "Color 80x25 (5153/CGA)" msgstr "Kleur 80x25 (5153/CGA)" -msgid "Enhanced Color - Normal Mode (5154/ECD)" +msgid "Enhanced Color - Normal Mode (5154/ECD)" msgstr "Verbeterde kleur - normale modus (5154/ECD)" -msgid "Enhanced Color - Enhanced Mode (5154/ECD)" +msgid "Enhanced Color - Enhanced Mode (5154/ECD)" msgstr "Verbeterde kleur - Verbeterde modus (5154/ECD)" -msgid "Green" +msgid "Green" msgstr "Groen" -msgid "Amber" +msgid "Amber" msgstr "Amber" -msgid "Gray" +msgid "Gray" msgstr "Grijs" -msgid "Color" +msgid "Color" msgstr "Kleur" -msgid "U.S. English" +msgid "U.S. English" msgstr "Amerikaans Engels" -msgid "Scandinavian" +msgid "Scandinavian" msgstr "Scandinavisch" -msgid "Other languages" +msgid "Other languages" msgstr "Andere talen" -msgid "Bochs latest" +msgid "Bochs latest" msgstr "Bochs nieuwste" -msgid "Mono Non-Interlaced" -msgstr "Mono Non-Interlaced" +msgid "Mono Non-Interlaced" +msgstr "Mono niet geïnterlaced" -msgid "Color Interlaced" +msgid "Color Interlaced" msgstr "Kleur interlaced" -msgid "Color Non-Interlaced" -msgstr "Kleur non-interlaced" +msgid "Color Non-Interlaced" +msgstr "Kleur niet geïnterlaced" -msgid "3Dfx Voodoo Graphics" +msgid "3Dfx Voodoo Graphics" msgstr "3Dfx Voodoo Graphics" -msgid "Obsidian SB50 + Amethyst (2 TMUs)" +msgid "Obsidian SB50 + Amethyst (2 TMUs)" msgstr "Obsidian SB50 + Amethyst (2 TMU's)" -msgid "8-bit" +msgid "8-bit" msgstr "8-bit" -msgid "16-bit" +msgid "16-bit" msgstr "16-bit" -msgid "Standard (150ns)" +msgid "Standard (150ns)" msgstr "Standaard (150ns)" -msgid "High-Speed (120ns)" +msgid "High-Speed (120ns)" msgstr "Hoge snelheid (120ns)" -msgid "Enabled" +msgid "Enabled" msgstr "Ingeschakeld" -msgid "Standard" +msgid "Standard" msgstr "Standaard" -msgid "High-Speed" +msgid "High-Speed" msgstr "Hoge snelheid" -msgid "Stereo LPT DAC" +msgid "Stereo LPT DAC" msgstr "Stereo LPT DAC" -msgid "Generic Text Printer" +msgid "Generic Text Printer" msgstr "Generieke tekstprinter" -msgid "Generic ESC/P Dot-Matrix Printer" +msgid "Generic ESC/P Dot-Matrix Printer" msgstr "Generieke ESC/P dot-matrix-printer" -msgid "Generic PostScript Printer" +msgid "Generic PostScript Printer" msgstr "Generieke PostScript-printer" -msgid "Generic PCL5e Printer" +msgid "Generic PCL5e Printer" msgstr "Generieke PCL5e-printer" -msgid "Parallel Line Internet Protocol" +msgid "Parallel Line Internet Protocol" msgstr "Internetprotocol voor parallelle lijnen" -msgid "Protection Dongle for Savage Quest" +msgid "Protection Dongle for Savage Quest" msgstr "Beschermingsdongle voor Savage Quest" -msgid "Serial Passthrough Device" +msgid "Serial Passthrough Device" msgstr "Serieel doorvoerapparaat" -msgid "Passthrough Mode" +msgid "Passthrough Mode" msgstr "Doorgeefmodus" -msgid "Host Serial Device" +msgid "Host Serial Device" msgstr "Host Serieel Apparaat" -msgid "Name of pipe" +msgid "Name of pipe" msgstr "Naam van de pipe" -msgid "Data bits" +msgid "Data bits" msgstr "Databits" -msgid "Stop bits" +msgid "Stop bits" msgstr "Stopbits" -msgid "Baud Rate of Passthrough" +msgid "Baud Rate of Passthrough" msgstr "Baud-snelheid van doorvoer" -msgid "Named Pipe (Server)" +msgid "Named Pipe (Server)" msgstr "Named Pipe (Server)" -msgid "Host Serial Passthrough" +msgid "Host Serial Passthrough" msgstr "Host seriële doorgave" -msgid "Eject %s" -msgstr "Uitwerpen %s" +msgid "E&ject %1" +msgstr "&Uitwerpen %1" -msgid "&Unmute" +msgid "&Unmute" msgstr "&Geluid aanzetten" -msgid "Softfloat FPU" +msgid "Softfloat FPU" msgstr "Softfloat FPU" -msgid "High performance impact" +msgid "High performance impact" msgstr "Hoge prestatie-impact" -msgid "RAM Disk (max. speed)" -msgstr "RAM-schijf (max. snelheid)" +msgid "[Generic] RAM Disk (max. speed)" +msgstr "[Generiek] RAM-schijf (max. snelheid)" -msgid "IBM 8514/A clone (ISA)" +msgid "[Generic] 1989 (3500 RPM)" +msgstr "[Generiek] 1989 (3500 RPM)" + +msgid "[Generic] 1992 (3600 RPM)" +msgstr "[Generiek] 1992 (3600 RPM)" + +msgid "[Generic] 1994 (4500 RPM)" +msgstr "[Generiek] 1994 (4500 RPM)" + +msgid "[Generic] 1996 (5400 RPM)" +msgstr "[Generiek] 1996 (5400 RPM)" + +msgid "[Generic] 1997 (5400 RPM)" +msgstr "[Generiek] 1997 (5400 RPM)" + +msgid "[Generic] 1998 (5400 RPM)" +msgstr "[Generiek] 1998 (5400 RPM)" + +msgid "[Generic] 2000 (7200 RPM)" +msgstr "[Generiek] 2000 (7200 RPM)" + +msgid "IBM 8514/A clone (ISA)" msgstr "IBM 8514/A-kloon (ISA)" -msgid "Vendor" -msgstr "Verkoper" +msgid "Vendor" +msgstr "Leverancier" -msgid "30 Hz (JMP2 = 1)" -msgstr "30 Hz (JMP2 = 1)" - -msgid "60 Hz (JMP2 = 2)" -msgstr "60 Hz (JMP2 = 2)" - -msgid "Generic PC/XT Memory Expansion" +msgid "Generic PC/XT Memory Expansion" msgstr "Generieke PC/XT geheugenuitbreiding" -msgid "Generic PC/AT Memory Expansion" +msgid "Generic PC/AT Memory Expansion" msgstr "Generieke PC/AT geheugenuitbreiding" + +msgid "Unable to find Dot-Matrix fonts" +msgstr "Dot-matrix-lettertypen niet gevonden" + +msgid "TrueType fonts in the \"roms/printer/fonts\" directory are required for the emulation of the Generic ESC/P Dot-Matrix Printer." +msgstr "TrueType lettertypen in de map \"roms/printer/fonts\" zijn nodig voor de emulatie van de generieke ESC/P dot-matrix-printer." + +msgid "Inhibit multimedia keys" +msgstr "Multimedia-toetsen blokkeren" + +msgid "Ask for confirmation before saving settings" +msgstr "Vraag om bevestiging voor het opslaan van instellingen" + +msgid "Ask for confirmation before hard resetting" +msgstr "Vraag om bevestiging voor een harde reset" + +msgid "Ask for confirmation before quitting" +msgstr "Vraag om bevestiging voor afsluiten" + +msgid "Options" +msgstr "Opties" + +msgid "Model" +msgstr "Model" + +msgid "Model:" +msgstr "Model:" + +msgid "Failed to initialize Vulkan renderer." +msgstr "Initialisatie van de Vulkan-renderer is mislukt." + +msgid "GLSL Error" +msgstr "GLSL-fout" + +msgid "Could not load shader: %1" +msgstr "Kon de shader niet laden: %1" + +msgid "OpenGL version 3.0 or greater is required. Current GLSL version is %1.%2" +msgstr "OpenGL versie 3.0 of hoger is vereist. Huidige GLSL-versie is %1.%2" + +msgid "Could not load texture: %1" +msgstr "Kon de textuur niet laden: %1" + +msgid "Could not compile shader:\n\n%1" +msgstr "Kon de shader niet compileren:\n\n%1" + +msgid "Program not linked:\n\n%1" +msgstr "Programma niet gelinkt:\n\n%1" + +msgid "Shader Manager" +msgstr "Shaderbeheer" + +msgid "Shader Configuration" +msgstr "Shaderconfiguratie" + +msgid "Add" +msgstr "Toevoegen" + +msgid "Move up" +msgstr "Omhoog verplaatsen" + +msgid "Move down" +msgstr "Omlaag verplaatsen" + +msgid "Could not load file %1" +msgstr "Kon bestand %1 niet laden" diff --git a/src/qt/languages/pl-PL.po b/src/qt/languages/pl-PL.po index 9fa67bf9e..b161370ed 100644 --- a/src/qt/languages/pl-PL.po +++ b/src/qt/languages/pl-PL.po @@ -13,13 +13,13 @@ msgid "&Keyboard requires capture" msgstr "&Klawaitura wymaga przechwytu myszy" msgid "&Right CTRL is left ALT" -msgstr "&Prawy CTRL to lewy Alt" +msgstr "&Prawy CTRL to lewy ALT" msgid "&Hard Reset..." msgstr "&Twardy reset..." -msgid "&Ctrl+Alt+Del\tCtrl+F12" -msgstr "&Ctrl+Alt+Del\tCtrl+F12" +msgid "&Ctrl+Alt+Del" +msgstr "&Ctrl+Alt+Del" msgid "Ctrl+Alt+&Esc" msgstr "Ctrl+Alt+&Esc" @@ -49,7 +49,7 @@ msgid "Re&nderer" msgstr "Re&nderer" msgid "&Qt (Software)" -msgstr "&Qt (Software)" +msgstr "&Qt (programowy)" msgid "Qt (&OpenGL)" msgstr "Qt (&OpenGL)" @@ -61,13 +61,13 @@ msgid "&VNC" msgstr "&VNC" msgid "Specify dimensions..." -msgstr "Określ rozmiary..." +msgstr "Określ wymiary..." msgid "F&orce 4:3 display ratio" msgstr "&Wymuś proporcje wyświetlania 4:3" msgid "&Window scale factor" -msgstr "&Czynnik skalowania okna" +msgstr "Współ&czynnik skalowania okna" msgid "&0.5x" msgstr "&0.5x" @@ -103,16 +103,16 @@ msgid "Filter method" msgstr "Metoda filtrowania" msgid "&Nearest" -msgstr "&Nearest" +msgstr "&Najbliższa" msgid "&Linear" -msgstr "&Linear" +msgstr "&Liniowa" msgid "Hi&DPI scaling" msgstr "Skalowanie Hi&DPI" -msgid "&Fullscreen\tCtrl+Alt+PgUp" -msgstr "&Pełny ekran\tCtrl+Alt+PgUp" +msgid "&Fullscreen" +msgstr "&Pełny ekran" msgid "Fullscreen &stretch mode" msgstr "Tryb rozciągania na pełnym ekranie" @@ -145,7 +145,7 @@ msgid "RGB &Color" msgstr "RGB - &Kolorowy" msgid "&RGB Grayscale" -msgstr "&RGB - Skala szarości" +msgstr "&RGB - Skala odcieni szarości" msgid "&Amber monitor" msgstr "&Bursztynowy monitor" @@ -157,7 +157,7 @@ msgid "&White monitor" msgstr "&Biały monitor" msgid "Grayscale &conversion type" -msgstr "Typ konwersji &w skali szarości" +msgstr "Typ konwersji &w skali odcieni szarości" msgid "BT&601 (NTSC/PAL)" msgstr "BT&601 (NTSC/PAL)" @@ -166,13 +166,13 @@ msgid "BT&709 (HDTV)" msgstr "BT&709 (HDTV)" msgid "&Average" -msgstr "&Średni" +msgstr "&Średnia" msgid "CGA/PCjr/Tandy/E&GA/(S)VGA overscan" msgstr "Overscan dla CGA/PCjr/Tandy/E&GA/(S)VGA" msgid "Change contrast for &monochrome display" -msgstr "Zmień kontrast dla &monochromatycznego ekranu" +msgstr "Zmień kontrast dla ekranu &monochromatycznego" msgid "&Media" msgstr "&Nośnik" @@ -186,23 +186,26 @@ msgstr "&Ustawienia..." msgid "&Update status bar icons" msgstr "&Aktualizuj ikony na pasku statusu" -msgid "Take s&creenshot\tCtrl+F11" -msgstr "Zrób &zrzut ekranu\tCtrl+F11" +msgid "Take s&creenshot" +msgstr "Zrób &zrzut ekranu" + +msgid "S&ound" +msgstr "Dź&więk" msgid "&Preferences..." msgstr "&Preferencje..." msgid "Enable &Discord integration" -msgstr "Włącz integrację z &Discord" +msgstr "Włącz integrację z &Discordem" msgid "Sound &gain..." msgstr "Wzmocnienie &dźwięku..." -msgid "Begin trace\tCtrl+T" -msgstr "Rozpocznij śledzenie\tCtrl+T" +msgid "Begin trace" +msgstr "Rozpocznij śledzenie" -msgid "End trace\tCtrl+T" -msgstr "Zakończ śledzenie\tCtrl+T" +msgid "End trace" +msgstr "Zakończ śledzenie" msgid "&Help" msgstr "&Pomoc" @@ -211,7 +214,7 @@ msgid "&Documentation..." msgstr "&Dokumentacja..." msgid "&About 86Box..." -msgstr "&O 86Box..." +msgstr "&O 86Boxie..." msgid "&New image..." msgstr "&Nowy obraz..." @@ -244,22 +247,22 @@ msgid "E&xport to 86F..." msgstr "E&ksportuj do 86F..." msgid "&Mute" -msgstr "&Ścisz" +msgstr "&Wycisz" msgid "E&mpty" msgstr "P&usty" -msgid "&Reload previous image" -msgstr "&Przeładuj poprzedni obraz" +msgid "Reload previous image" +msgstr "Przeładuj poprzedni obraz" msgid "&Folder..." -msgstr "&Teczka..." +msgstr "&Folder..." msgid "Target &framerate" msgstr "Docelowa &liczba klatek na sekundę" msgid "&Sync with video" -msgstr "&Zsynchronizuj z wideo" +msgstr "&Zsynchronizuj z obrazem" msgid "&25 fps" msgstr "&25 fps" @@ -306,18 +309,12 @@ msgstr "OK" msgid "Cancel" msgstr "Anuluj" -msgid "Save these settings as &global defaults" -msgstr "Zapisz ustawienia jako &globalne ustawienia domyślne" - msgid "&Default" msgstr "&Domyślny" msgid "Language:" msgstr "Język:" -msgid "Icon set:" -msgstr "Zestaw ikon:" - msgid "Gain" msgstr "Wzmacniacz" @@ -358,7 +355,7 @@ msgid "Speed:" msgstr "Szybkość:" msgid "Frequency:" -msgstr "Częstotliwość:" +msgstr "Taktowanie:" msgid "FPU:" msgstr "Jednostka FPU:" @@ -394,7 +391,7 @@ msgid "Video #2:" msgstr "Wideo 2:" msgid "Voodoo 1 or 2 Graphics" -msgstr "Grafika Voodoo 1 czy 2" +msgstr "Grafika Voodoo 1 lub 2" msgid "IBM 8514/A Graphics" msgstr "Grafika IBM 8514/A" @@ -453,15 +450,6 @@ msgstr "Nuked (dokładniejszy)" msgid "YMFM (faster)" msgstr "YMFM (szybszy)" -msgid "Network type:" -msgstr "Rodzaj sieci:" - -msgid "PCap device:" -msgstr "Urządzenie PCap:" - -msgid "Network adapter:" -msgstr "Karta sieciowa:" - msgid "COM1 Device:" msgstr "Urządzenie COM1:" @@ -517,10 +505,10 @@ msgid "FD Controller:" msgstr "Kontroler dyskietek:" msgid "Tertiary IDE Controller" -msgstr "Trzeciorzędowy kontroler IDE" +msgstr "Trzeciorzędny kontroler IDE" msgid "Quaternary IDE Controller" -msgstr "Czwartorzędowy kontroler IDE" +msgstr "Czwartorzędny kontroler IDE" msgid "SCSI" msgstr "SCSI" @@ -589,7 +577,7 @@ msgid "Floppy drives:" msgstr "Napędy dyskietek:" msgid "Turbo timings" -msgstr "Rozrządy Turbo" +msgstr "Timing Turbo" msgid "Check BPB" msgstr "Sprawdzaj BPB" @@ -640,16 +628,13 @@ msgid "Fatal error" msgstr "Fatalny błąd" msgid " - PAUSED" -msgstr " - PAUSED" - -msgid "Press Ctrl+Alt+PgDn to return to windowed mode." -msgstr "Naciśnij klawisze Ctrl+Alt+PgDn aby wrócić to trybu okna." +msgstr " - PAUZA" msgid "Speed" msgstr "Szybkość" -msgid "ZIP %03i %i (%s): %ls" -msgstr "ZIP %03i %i (%s): %ls" +msgid "ZIP %1 %2 (%3): %4" +msgstr "ZIP %1 %2 (%3): %4" msgid "ZIP images" msgstr "Obrazy ZIP" @@ -679,16 +664,19 @@ msgid "Basic sector images" msgstr "Podstawowe obrazy sektorów" msgid "Surface images" -msgstr "Obrazy powierzchniowe" +msgstr "Obrazy powierzchni" msgid "Machine \"%hs\" is not available due to missing ROMs in the roms/machines directory. Switching to an available machine." -msgstr "Maszyna \"%hs\" nie jest dostępna, ponieważ brakuje obrazów ROM w katalogu roms/machines. Przełączanie na dostępną maszynę." +msgstr "Maszyna \"%hs\" nie jest dostępna, ponieważ brakuje ROM-ów w katalogu roms/machines. Przełączanie na dostępną maszynę." msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Karta wideo \"%hs\" nie jest dostępna, ponieważ brakuje obrazów ROM w katalogu roms/video. Przełączanie na dostępną kartę wideo." +msgstr "Karta wideo \"%hs\" nie jest dostępna, ponieważ brakuje ROM-ów w katalogu roms/video. Przełączanie na dostępną kartę graficzną." -msgid "Video card 2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Karta wideo 2 \"%hs\" nie jest dostępna, ponieważ brakuje obrazów ROM w katalogu roms/video. Przełączanie na dostępną kartę wideo." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "Karta wideo 2 \"%hs\" nie jest dostępna, ponieważ brakuje ROM-ów w katalogu roms/video. Wyłączenie drugiej karty graficznej." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Urządzenie \"%hs\" nie jest dostępne, ponieważ brakuje ROM-ów. Ignorowanie urządzenia." msgid "Machine" msgstr "Maszyna" @@ -709,7 +697,7 @@ msgid "Ports (COM & LPT)" msgstr "Porty (COM & LPT)" msgid "Storage controllers" -msgstr "Kontrolery pamięci" +msgstr "Kontrolery pamięci masowej" msgid "Hard disks" msgstr "Dyski twarde" @@ -724,13 +712,13 @@ msgid "Other peripherals" msgstr "Inne urządzenia peryferyjne" msgid "Click to capture mouse" -msgstr "Kliknij w celu przechwycenia myszy" +msgstr "Kliknij, by przechwycić mysz" msgid "Press %1 to release mouse" -msgstr "Naciśnij klawisze %1 w celu uwolnienia myszy" +msgstr "Naciśnij %1 w celu uwolnienia myszy" msgid "Press %1 or middle button to release mouse" -msgstr "Naciśnij klawisze %1 lub środkowy przycisk w celu uwolnienia myszy" +msgstr "Naciśnij %1 lub środkowy przycisk w celu uwolnienia myszy" msgid "Bus" msgstr "Magistrala" @@ -750,14 +738,11 @@ msgstr "S" msgid "KB" msgstr "KB" -msgid "Could not initialize the video renderer." -msgstr "Nie można zainicjować renderera wideo." - msgid "Default" msgstr "Domyślny" -msgid "%i Wait state(s)" -msgstr "%i Stany oczekiwania" +msgid "%1 Wait state(s)" +msgstr "%1 stan(y/ów) oczekiwania" msgid "Type" msgstr "Rodzaj" @@ -801,38 +786,38 @@ msgstr "Thrustmaster Flight Control System" msgid "None" msgstr "Żaden" -msgid "%u MB (CHS: %i, %i, %i)" -msgstr "%u MB (CHS: %i, %i, %i)" +msgid "%1 MB (CHS: %2, %3, %4)" +msgstr "%1 MB (CHS: %2, %3, %4)" -msgid "Floppy %i (%s): %ls" -msgstr "Dyskietka %i (%s): %ls" +msgid "Floppy %1 (%2): %3" +msgstr "Dyskietka %1 (%2): %3" msgid "Advanced sector images" msgstr "Zaawansowane obrazy sektorów" msgid "Flux images" -msgstr "Flux images" +msgstr "Obrazy flux" msgid "Are you sure you want to hard reset the emulated machine?" -msgstr "Jesteś pewien że chcesz wykonać twardy reset emulowanej maszyny?" +msgstr "Czy na pewno chcesz wykonać twardy reset emulowanej maszyny?" msgid "Are you sure you want to exit 86Box?" -msgstr "Jesteś pewien że chcesz zakończyć 86Box?" +msgstr "Czy na pewno chcesz zakończyć 86Box?" msgid "Unable to initialize Ghostscript" -msgstr "Nie można zainicjować Ghostscript" +msgstr "Nie można zainicjować Ghostscriptu" msgid "Unable to initialize GhostPCL" msgstr "Nie można zainicjować GhostPCL" -msgid "MO %i (%ls): %ls" -msgstr "MO %i (%ls): %ls" +msgid "MO %1 (%2): %3" +msgstr "MO %1 (%2): %3" msgid "MO images" msgstr "Obrazy MO" msgid "Welcome to 86Box!" -msgstr "Witamy w 86Box!" +msgstr "Witamy w 86Boxie!" msgid "Internal device" msgstr "Urządzenie wewnętrzne" @@ -841,7 +826,7 @@ msgid "Exit" msgstr "Zakończ" msgid "No ROMs found" -msgstr "Nie znaleziono obrazów ROM" +msgstr "Nie znaleziono ROM-ów" msgid "Do you want to save the settings?" msgstr "Czy chcesz zapisać ustawienia?" @@ -859,7 +844,7 @@ msgid "86Box v" msgstr "86Box v" msgid "An emulator of old computers\n\nAuthors: Miran Grča (OBattler), RichardG867, Jasmine Iwanek, TC1995, coldbrewed, Teemu Korhonen (Manaatti), Joakim L. Gilje, Adrien Moulin (elyosh), Daniel Balsom (gloriouscow), Cacodemon345, Fred N. van Kempen (waltje), Tiseno100, reenigne, and others.\n\nWith previous core contributions from Sarah Walker, leilei, JohnElliott, greatpsycho, and others.\n\nReleased under the GNU General Public License version 2 or later. See LICENSE for more information." -msgstr "Emulator starych komputerów\n\nAutorzy: Miran Grča (OBattler), RichardG867, Jasmine Iwanek, TC1995, coldbrewed, Teemu Korhonen (Manaatti), Joakim L. Gilje, Adrien Moulin (elyosh), Daniel Balsom (gloriouscow), Cacodemon345, Fred N. van Kempen (waltje), Tiseno100, reenigne, i inni.\n\nZ wcześniejszym wkładem od Sarah Walker, leilei, JohnElliott, greatpsycho i innych.\n\nPrzetłumaczony przez: Fanta-Shokata\n\nWydany na licencji GNU General Public License w wersji 2 lub nowszej. Zobacz LICENSE aby uzyskać więcej informacji." +msgstr "Emulator starych komputerów\n\nAutorzy: Miran Grča (OBattler), RichardG867, Jasmine Iwanek, TC1995, coldbrewed, Teemu Korhonen (Manaatti), Joakim L. Gilje, Adrien Moulin (elyosh), Daniel Balsom (gloriouscow), Cacodemon345, Fred N. van Kempen (waltje), Tiseno100, reenigne, i inni.\n\nZ wcześniejszym wkładem od Sarah Walker, leilei, JohnElliott, greatpsycho i innych.\n\nPrzetłumaczony przez: Fanta-Shokata, Lili1228\n\nWydany na licencji GNU General Public License w wersji 2 lub nowszej. Zobacz LICENSE aby uzyskać więcej informacji." msgid "Hardware not available" msgstr "Sprzęt niedostępny" @@ -871,13 +856,10 @@ msgid "Invalid configuration" msgstr "Nieprawidłowa konfiguracja" msgid "%1 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 "%1 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)." +msgstr "%1 jest wymagany do automatycznej konwersji plików PostScript do PDF.\n\nDokumenty wysłane do generycznej drukarki PostScript zostaną zapisane jako pliki PostScript (.ps)." msgid "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PCL printer will be saved as Printer Command Language (.pcl) files." -msgstr "%1 jest wymagany do automatycznej konwersji plików PCL do PDF.\n\nDokumenty wysłane do ogólnej drukarki PCL zostaną zapisane jako pliki Printer Command Language (.pcl)." - -msgid "Entering fullscreen mode" -msgstr "Przechodzenie do trybu pełnoekranowego" +msgstr "%1 jest wymagany do automatycznej konwersji plików PCL do PDF.\n\nDokumenty wysłane do generycznej drukarki PCL zostaną zapisane jako pliki Printer Command Language (.pcl)." msgid "Don't show this message again" msgstr "Nie pokazuj więcej tego komunikatu" @@ -900,38 +882,29 @@ msgstr "Konfiguracja urządzenia %1" msgid "Monitor in sleep mode" msgstr "Monitor w trybie czuwania" -msgid "OpenGL Shaders" -msgstr "Shadery OpenGL" - -msgid "OpenGL options" -msgstr "Opcje OpenGL" +msgid "GLSL shaders" +msgstr "Shadery GLSL" msgid "You are loading an unsupported configuration" -msgstr "Ładujesz nieobsługiwaną konfigurację" +msgstr "Wczytujesz nieobsługiwaną konfigurację" 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 "Wybór rodzaju procesora oparty na wybranej maszynie jest wyłączony dla tej emulowanej maszyny.\n\nPozwala to na wybór procesora który jest niekompatybilny z wybraną maszyną. Jednak możesz napotkać niezgodności z BIOS-em maszyny lub innym oprogramowaniem.\n\nAktywacja tego ustawienia nie jest wspierana i każde zgłoszenie błędu może zostać zamknięte jako nieważne." +msgstr "Filtrowanie rodzaju procesora na podstawie wybranej maszyny jest wyłączone dla tej emulowanej maszyny.\n\nPozwala to na wybór procesora, który jest niekompatybilny z wybraną maszyną, jednak możesz napotkać niezgodności z BIOS-em maszyny lub innym oprogramowaniem.\n\nAktywacja tego ustawienia nie jest wspierana i każde zgłoszenie błędu może zostać zamknięte jako nieprawidłowe." msgid "Continue" msgstr "Kontynuuj" -msgid "Cassette: %s" -msgstr "Kaseta: %s" +msgid "Cassette: %1" +msgstr "Kaseta: %1" msgid "Cassette images" msgstr "Obrazy kaset" -msgid "Cartridge %i: %ls" -msgstr "Kartrydż %i: %ls" +msgid "Cartridge %1: %2" +msgstr "Kartridż %1: %2" msgid "Cartridge images" -msgstr "Obrazy kartrydżu" - -msgid "Error initializing renderer" -msgstr "Błąd inicjalizacji renderera" - -msgid "OpenGL (3.0 Core) renderer could not be initialized. Use another renderer." -msgstr "Nie można zainicjować renderera OpenGL (3.0 Core). Użyj innego." +msgstr "Obrazy kartridżów" msgid "Resume execution" msgstr "Wznów wykonywanie" @@ -1021,7 +994,7 @@ msgid "Don't overwrite" msgstr "Nie nadpisuj" msgid "Raw image" -msgstr "Obraz surowy" +msgstr "Surowy obraz" msgid "HDI image" msgstr "Obraz HDI" @@ -1039,10 +1012,10 @@ msgid "Differencing VHD" msgstr "VHD różnicujący" msgid "(N/A)" -msgstr "(Bez)" +msgstr "(nd.)" msgid "Raw image (.img)" -msgstr "Obraz surowy (.img)" +msgstr "Surowy obraz (.img)" msgid "HDI image (.hdi)" msgstr "Obraz HDI (.hdi)" @@ -1057,7 +1030,7 @@ msgid "Dynamic-size VHD (.vhd)" msgstr "VHD o dynamicznym rozmiarze (.vhd)" msgid "Differencing VHD (.vhd)" -msgstr "VHD różnicujący (.vhd)" +msgstr "VHD różnicowy (.vhd)" msgid "Large blocks (2 MB)" msgstr "Duże bloki (2 MB)" @@ -1072,7 +1045,7 @@ msgid "Select the parent VHD" msgstr "Wybierz nadrzędny plik 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 "Może to oznaczać, że obraz nadrzędny został zmodyfikowany po utworzeniu obrazu różnicującego.\n\nMoże się to również zdarzyć, jeśli pliki obrazów zostały przeniesione lub skopiowane, lub wystąpił błąd w programie, który utworzył ten dysk\n\nCzy chcesz naprawić sygnatury czasowe?" +msgstr "Może to oznaczać, że obraz nadrzędny został zmodyfikowany po utworzeniu obrazu różnicowego.\n\nMoże się to również zdarzyć, jeśli pliki obrazów zostały przeniesione lub skopiowane, lub wystąpił błąd w programie, który utworzył ten dysk.\n\nCzy chcesz naprawić sygnatury czasowe?" msgid "Parent and child disk timestamps do not match" msgstr "Sygnatury czasowe dysku nadrzędnego i podrzędnego nie zgadzają się" @@ -1095,8 +1068,8 @@ msgstr "IDE" msgid "ATAPI" msgstr "ATAPI" -msgid "CD-ROM %i (%s): %s" -msgstr "CD-ROM %i (%s): %s" +msgid "CD-ROM %1 (%2): %3" +msgstr "CD-ROM %1 (%2): %3" msgid "160 KB" msgstr "160 KB" @@ -1189,10 +1162,10 @@ msgid "The network configuration will be switched to the null driver" msgstr "Konfiguracja sieci zostanie przełączona na sterownik null" msgid "Mouse sensitivity:" -msgstr "Wrażliwość myszy:" +msgstr "Czułość myszy:" msgid "Select media images from program working directory" -msgstr "Wybór obrazów multimedialnych z katalogu roboczego programu" +msgstr "Wybór obrazów nośników z katalogu roboczego programu" msgid "PIT mode:" msgstr "Tryb PIT:" @@ -1213,7 +1186,7 @@ msgid "WinBox is no longer supported" msgstr "WinBox nie jest już wspierany" msgid "Development of the WinBox manager stopped in 2022 due to a lack of maintainers. As we direct our efforts towards making 86Box even better, we have made the decision to no longer support WinBox as a manager.\n\nNo further updates will be provided through WinBox, and you may encounter incorrect behavior should you continue using it with newer versions of 86Box. Any bug reports related to WinBox behavior will be closed as invalid.\n\nGo to 86box.net for a list of other managers you can use." -msgstr "Rozwój menedżera WinBox został zatrzymany w 2022 roku z powodu braku opiekunów. Ponieważ kierujemy nasze wysiłki na uczynienie 86Box jeszcze lepszym, podjęliśmy decyzję o zaprzestaniu wspierania WinBox jako menedżera.\n\nŻadne dalsze aktualizacje nie będą dostarczane za pośrednictwem WinBox i możesz napotkać nieprawidłowe zachowanie, jeśli będziesz go nadal używać z nowszymi wersjami 86Box. Wszelkie zgłoszenia błędów związane z działaniem WinBox zostaną zamknięte jako nieważne.\n\nLista innych menedżerów, z których można korzystać, znajduje się na stronie 86box.net." +msgstr "Menedżer WinBox przestał być rozwijany w 2022 roku z powodu braku opiekunów. Ponieważ kierujemy nasze wysiłki na uczynienie 86Box jeszcze lepszym, podjęliśmy decyzję o zaprzestaniu wspierania WinBox jako menedżera.\n\nŻadne dalsze aktualizacje nie będą dostarczane za pośrednictwem WinBoxa i możesz napotkać nieprawidłowe zachowanie, jeśli będziesz go nadal używać z nowszymi wersjami 86Box. Wszelkie zgłoszenia błędów związane z działaniem WinBox zostaną zamknięte jako nieważne.\n\nLista innych menedżerów, z których można korzystać, znajduje się na stronie 86box.net." msgid "Generate" msgstr "Generuj" @@ -1267,7 +1240,7 @@ msgid "Host CD/DVD Drive (%1:)" msgstr "Napęd CD/DVD hosta (%1:)" msgid "&Connected" -msgstr "&Connected" +msgstr "" msgid "Clear image history" msgstr "Wyczyść historię obrazów" @@ -1275,9 +1248,6 @@ msgstr "Wyczyść historię obrazów" msgid "Create..." msgstr "Stwórz..." -msgid "previous image" -msgstr "poprzedni obraz" - msgid "Host CD/DVD Drive (%1)" msgstr "Napęd CD/DVD hosta (%1)" @@ -1287,23 +1257,8 @@ msgstr "Nieznana magistrala" msgid "Null Driver" msgstr "Null Driver" -msgid "NIC %02i (%ls) %ls" -msgstr "NIC %02i (%ls) %ls" - -msgid "Error opening \"%1\": %2" -msgstr "Błąd otwarcia \"%1\": %2" - -msgid "Error compiling vertex shader in file \"%1\"" -msgstr "Błąd kompilacji shadera wierzchołków w pliku \"%1\"" - -msgid "Error compiling fragment shader in file \"%1\"" -msgstr "Błąd kompilacji shadera fragmentów w pliku \"%1\"" - -msgid "Error linking shader program in file \"%1\"" -msgstr "Błąd łączenia programu shader w pliku \"%1\"" - -msgid "OpenGL 3.0 renderer options" -msgstr "Opcje renderowania OpenGL 3.0" +msgid "NIC %1 (%2) %3" +msgstr "NIC %1 (%2) %3" msgid "Render behavior" msgstr "Zachowanie renderowania" @@ -1317,11 +1272,8 @@ msgstr " fps" msgid "VSync" msgstr "VSync" -msgid "<html><head/><body><p>Render each frame immediately, in sync with the emulated display.</p><p><span style=" font-style:italic;">This is the recommended option if the shaders in use don't utilize frametime for animated effects.</span></p></body></html>" -msgstr "<html><head/><body><p>Renderuj każdą klatkę natychmiast, w synchronizacji z emulowanym wyświetlaczem.</p><p><span style=" font-style:italic;">Jest to zalecana opcja, jeśli używane shadery nie wykorzystują frametime do animowanych efektów.</span></p></body></html>" - msgid "Synchronize with video" -msgstr "Zsynchronizuj z wideo" +msgstr "Synchronizuj z obrazem" msgid "Shaders" msgstr "Shadery" @@ -1329,21 +1281,9 @@ msgstr "Shadery" msgid "Remove" msgstr "Usuń" -msgid "No shader selected" -msgstr "Nie wybrano shadera" - msgid "Browse..." msgstr "Przeglądaj..." -msgid "Shader error" -msgstr "Błąd shadera" - -msgid "Could not load shaders." -msgstr "Nie można załadować shaderów." - -msgid "More information in details." -msgstr "Więcej informacji w szczegółach." - msgid "Couldn't create OpenGL context." msgstr "Nie można utworzyć kontekstu OpenGL." @@ -1353,20 +1293,14 @@ msgstr "Nie można przełączyć na kontekst OpenGL." msgid "OpenGL version 3.0 or greater is required. Current version is %1.%2" msgstr "Wymagana jest wersja OpenGL 3.0 lub wyższa. Aktualna wersja to %1.%2" -msgid "OpenGL initialization failed. Error %1." -msgstr "Inicjalizacja OpenGL nie powiodła się. Błąd %1." - msgid "Error initializing OpenGL" msgstr "Błąd inicjalizacji OpenGL" -msgid "Falling back to software rendering.\n" -msgstr "Powrót do renderowania oprogramowania.\n" +msgid "\nFalling back to software rendering." +msgstr "\nPowrót do renderowania programowego." -msgid "Allocating memory for unpack buffer failed.\n" -msgstr "Przydzielenie pamięci dla bufora rozpakowywania nie powiodło się.\n" - -msgid "<html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html>" -msgstr "<html><head/><body><p>Podczas wybierania obrazów nośników (CD-ROM, dyskietka itp.) otwarte okno dialogowe rozpocznie się w tym samym katalogu, co plik konfiguracyjny 86Box. To ustawienie prawdopodobnie będzie miało znaczenie tylko na macOS.</p></body></html>" +msgid "

When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" +msgstr "

Podczas wybierania obrazów nośników (CD-ROM, dyskietka itd.), otwarte okno dialogowe rozpocznie się w tym samym katalogu, co plik konfiguracyjny 86Box. To ustawienie prawdopodobnie będzie miało znaczenie tylko na macOS.

" msgid "This machine might have been moved or copied." msgstr "To urządzenie mogło zostać przeniesione lub skopiowane." @@ -1401,17 +1335,17 @@ msgstr "Karta sieciowa 3" msgid "Network Card #4" msgstr "Karta sieciowa 4" -msgid "Mode" -msgstr "Tryb" +msgid "Mode:" +msgstr "Tryb:" -msgid "Interface" -msgstr "Interfejs" +msgid "Interface:" +msgstr "Interfejs:" -msgid "Adapter" -msgstr "Adapter" +msgid "Adapter:" +msgstr "Adapter:" -msgid "VDE Socket" -msgstr "Gniazdo VDE" +msgid "VDE Socket:" +msgstr "Gniazdo VDE:" msgid "86Box Unit Tester" msgstr "Tester urządzeń 86Box" @@ -1420,28 +1354,25 @@ msgid "Novell NetWare 2.x Key Card" msgstr "Karta klucza Novell NetWare 2.x" msgid "Serial port passthrough 1" -msgstr "Przełączanie portu szeregowego 1" +msgstr "Przelotka portu szeregowego 1" msgid "Serial port passthrough 2" -msgstr "Przełączanie portu szeregowego 2" +msgstr "Przelotka portu szeregowego 2" msgid "Serial port passthrough 3" -msgstr "Przełączanie portu szeregowego 3" +msgstr "Przelotka portu szeregowego 3" msgid "Serial port passthrough 4" -msgstr "Przełączanie portu szeregowego 4" - -msgid "Vision Systems LBA Enhancer" -msgstr "Vision Systems LBA Enhancer" +msgstr "Przelotka portu szeregowego 4" msgid "Renderer options..." msgstr "Opcje renderowania..." msgid "Logitech/Microsoft Bus Mouse" -msgstr "Mysz magistralna Logitech/Microsoft" +msgstr "Mysz magistralowa Logitech/Microsoft" msgid "Microsoft Bus Mouse (InPort)" -msgstr "Mysz magistralna Microsoft (InPort)" +msgstr "Mysz magistralowa Microsoft (InPort)" msgid "Mouse Systems Serial Mouse" msgstr "Mysz szeregowa Mouse Systems" @@ -1456,7 +1387,7 @@ msgid "PS/2 Mouse" msgstr "Mysz PS/2" msgid "3M MicroTouch (Serial)" -msgstr "3M MicroTouch (szeregowa)" +msgstr "3M MicroTouch (szeregowy)" msgid "[COM] Standard Hayes-compliant Modem" msgstr "[COM] Standardowy modem zgodny z Hayes" @@ -1465,7 +1396,7 @@ msgid "Roland MT-32 Emulation" msgstr "Emulacja Roland MT-32" msgid "Roland MT-32 (New) Emulation" -msgstr "Emulacja Roland MT-32 (nowego)" +msgstr "(Nowa) emulacja Roland MT-32" msgid "Roland CM-32L Emulation" msgstr "Emulacja Roland CM-32L" @@ -1474,7 +1405,7 @@ msgid "Roland CM-32LN Emulation" msgstr "Emulacja Roland CM-32LN" msgid "OPL4-ML Daughterboard" -msgstr "Płyta córka OPL4-ML" +msgstr "Płyta-córka OPL4-ML" msgid "System MIDI" msgstr "System MIDI" @@ -1681,7 +1612,7 @@ msgid "CODEC" msgstr "CODEC" msgid "Raise CODEC interrupt on CODEC setup (needed by some drivers)" -msgstr "Podniesienie przerwania CODEC przy konfiguracji CODEC (wymagane przez niektóre sterowniki)" +msgstr "Podnieś przerwanie CODEC podczas konfiguracji CODEC-a (wymagane przez niektóre sterowniki)" msgid "SB Address" msgstr "Adres SB" @@ -1699,7 +1630,7 @@ msgid "Receive MIDI input (MPU-401)" msgstr "Odbiór wejścia MIDI (MPU-401)" msgid "SB low DMA" -msgstr "SB low DMA" +msgstr "Low DMA SB" msgid "6CH variant (6-channel)" msgstr "Wariant 6CH (6-kanałowy)" @@ -1714,7 +1645,7 @@ msgid "High DMA" msgstr "Wysokie DMA" msgid "Control PC speaker" -msgstr "Głośnik komputera sterującego" +msgstr "Kontroluj PC speaker" msgid "Memory size" msgstr "Rozmiar pamięci" @@ -1732,10 +1663,10 @@ msgid "GUS type" msgstr "Typ GUS" msgid "Enable 0x04 \"Exit 86Box\" command" -msgstr "Włącz polecenie 0x04 \"Wyjdź z 86Box\"" +msgstr "Włącz polecenie 0x04 \"Wyjdź z 86Boxa\"" msgid "Display type" -msgstr "Typ wyświetlacza" +msgstr "Typ ekranu" msgid "Composite type" msgstr "Typ kompozytowy" @@ -1846,7 +1777,7 @@ msgid "Triangle" msgstr "Trójkątny" msgid "Linear" -msgstr "Liniowa" +msgstr "Liniowy" msgid "4th Order" msgstr "4. rzędu" @@ -1867,10 +1798,13 @@ msgid "Three" msgstr "Trzy" msgid "Wheel" -msgstr "Koło" +msgstr "Rolka" msgid "Five + Wheel" -msgstr "Five + Wheel" +msgstr "Pięć + rolka" + +msgid "Five + 2 Wheels" +msgstr "Pięć + dwie rolki" msgid "A3 - SMT2 Serial / SMT3(R)V" msgstr "A3 - SMT2 szeregowa / SMT3(R)V" @@ -1942,7 +1876,7 @@ msgid "New" msgstr "Nowość" msgid "Color (generic)" -msgstr "Kolor (ogólny)" +msgstr "Kolorowy (generyczny)" msgid "Green Monochrome" msgstr "Zielony monochromatyczny" @@ -1954,10 +1888,10 @@ msgid "Gray Monochrome" msgstr "Szary monochromatyczny" msgid "Color (no brown)" -msgstr "Kolor (bez brązowego)" +msgstr "Kolorowy (bez brązowego)" msgid "Color (IBM 5153)" -msgstr "Kolor (IBM 5153)" +msgstr "Kolorowy (IBM 5153)" msgid "Simple doubling" msgstr "Proste podwojenie" @@ -1987,7 +1921,7 @@ msgid "Color 80x25 (5153/CGA)" msgstr "Kolor 80x25 (5153/CGA)" msgid "Enhanced Color - Normal Mode (5154/ECD)" -msgstr "Rozszerzone kolory - tryb normalny (5154/ECD)" +msgstr "Rozszerzony kolor - tryb zwykły (5154/ECD)" msgid "Enhanced Color - Enhanced Mode (5154/ECD)" msgstr "Rozszerzony kolor - tryb rozszerzony (5154/ECD)" @@ -2002,10 +1936,10 @@ msgid "Gray" msgstr "Szary" msgid "Color" -msgstr "Kolor" +msgstr "Kolorowy" msgid "U.S. English" -msgstr "Amerykański angielski" +msgstr "Angielski (USA)" msgid "Scandinavian" msgstr "Skandynawski" @@ -2014,13 +1948,13 @@ msgid "Other languages" msgstr "Inne języki" msgid "Bochs latest" -msgstr "Bochs najnowsze" +msgstr "Najnowszy Bochs" msgid "Mono Non-Interlaced" -msgstr "Mono bez przeplotu" +msgstr "Monochromatyczny bez przeplotu" msgid "Color Interlaced" -msgstr "Kolor z przeplotem" +msgstr "Kolorowy z przeplotem" msgid "Color Non-Interlaced" msgstr "Kolor bez przeplotu" @@ -2029,7 +1963,7 @@ msgid "3Dfx Voodoo Graphics" msgstr "Grafika 3Dfx Voodoo" msgid "Obsidian SB50 + Amethyst (2 TMUs)" -msgstr "Obsydian SB50 + Ametyst (2 jednostki TMU)" +msgstr "Obsydian SB50 + Amethyst (2 jednostki TMU)" msgid "8-bit" msgstr "8-bitowy" @@ -2053,22 +1987,22 @@ msgid "High-Speed" msgstr "Wysoka prędkość" msgid "Stereo LPT DAC" -msgstr "Stereofoniczny przetwornik cyfrowo-analogowy LPT" +msgstr "Stereo LPT DAC" msgid "Generic Text Printer" -msgstr "Ogólna drukarka tekstowa" +msgstr "Generyczna drukarka tekstowa" msgid "Generic ESC/P Dot-Matrix Printer" msgstr "Generyczna drukarka igłowa ESC/P" msgid "Generic PostScript Printer" -msgstr "Ogólna drukarka PostScript" +msgstr "Generyczna drukarka PostScript" msgid "Generic PCL5e Printer" -msgstr "Drukarka PCL5e" +msgstr "Generyczna drukarka PCL5e" msgid "Parallel Line Internet Protocol" -msgstr "Protokół internetowy linii równoległej" +msgstr "Parallel Line Internet Protocol" msgid "Protection Dongle for Savage Quest" msgstr "Klucz ochronny dla Savage Quest" @@ -2083,7 +2017,7 @@ msgid "Host Serial Device" msgstr "Urządzenie szeregowe hosta" msgid "Name of pipe" -msgstr "Nazwa rury" +msgstr "Nazwa potoku" msgid "Data bits" msgstr "Bity danych" @@ -2092,19 +2026,19 @@ msgid "Stop bits" msgstr "Bity stopu" msgid "Baud Rate of Passthrough" -msgstr "Szybkość transmisji Passthrough" +msgstr "Szybkość transmisji przelotowej" msgid "Named Pipe (Server)" -msgstr "Nazwana rura (serwer)" +msgstr "Nazwany potok (serwer)" msgid "Host Serial Passthrough" -msgstr "Przejście przez port szeregowy hosta" +msgstr "Przelot przez port szeregowy hosta" -msgid "Eject %s" -msgstr "Wyjmij %s" +msgid "E&ject %1" +msgstr "W&yjmij %1" msgid "&Unmute" -msgstr "&Wycisz" +msgstr "O&dcisz" msgid "Softfloat FPU" msgstr "FPU Softfloat" @@ -2112,11 +2046,104 @@ msgstr "FPU Softfloat" msgid "High performance impact" msgstr "Wysoki wpływ na wydajność" -msgid "RAM Disk (max. speed)" -msgstr "Dysk RAM (maks. prędkość)" +msgid "[Generic] RAM Disk (max. speed)" +msgstr "[generyczny] Dysk RAM (maks. prędkość)" + +msgid "[Generic] 1989 (3500 RPM)" +msgstr "[generyczny] 1989 (3500 RPM)" + +msgid "[Generic] 1992 (3600 RPM)" +msgstr "[generyczny] 1992 (3600 RPM)" + +msgid "[Generic] 1994 (4500 RPM)" +msgstr "[generyczny] 1994 (4500 RPM)" + +msgid "[Generic] 1996 (5400 RPM)" +msgstr "[generyczny] 1996 (5400 RPM)" + +msgid "[Generic] 1997 (5400 RPM)" +msgstr "[generyczny] 1997 (5400 RPM)" + +msgid "[Generic] 1998 (5400 RPM)" +msgstr "[generyczny] 1998 (5400 RPM)" + +msgid "[Generic] 2000 (7200 RPM)" +msgstr "[generyczny] 2000 (7200 RPM)" msgid "IBM 8514/A clone (ISA)" msgstr "Klon IBM 8514/A (ISA)" msgid "Vendor" msgstr "Producent" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Generyczne rozszerzenie pamięci PC/XT" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Generyczne rozszerzenie pamięci PC/AT" + +msgid "Unable to find Dot-Matrix fonts" +msgstr "Nie można znaleźć fontów igłowych" + +msgid "TrueType fonts in the \"roms/printer/fonts\" directory are required for the emulation of the Generic ESC/P Dot-Matrix Printer." +msgstr "Fonty TrueType w katalogu \"roms/printer/fonts\" są wymagane do emulacji generycznej drukarki igłowej ESC/P." + +msgid "Inhibit multimedia keys" +msgstr "Przejmij klawisze multimedialne" + +msgid "Ask for confirmation before saving settings" +msgstr "Pytaj o potwierdzenie przed zapisaniem ustawień" + +msgid "Ask for confirmation before hard resetting" +msgstr "Pytaj o potwierdzenie przed twardym resetem" + +msgid "Ask for confirmation before quitting" +msgstr "Pytaj o potwierdzenie przed wyjściem" + +msgid "Options" +msgstr "Opcje" + +msgid "Model" +msgstr "Model" + +msgid "Model:" +msgstr "Model:" + +msgid "Failed to initialize Vulkan renderer." +msgstr "Nie udało się zainicjować renderera Vulkan." + +msgid "GLSL Error" +msgstr "Błąd GLSL" + +msgid "Could not load shader: %1" +msgstr "Nie udało się wczytać shadera: %1" + +msgid "OpenGL version 3.0 or greater is required. Current GLSL version is %1.%2" +msgstr "Wymagana jest wersja OpenGL 3.0 lub wyższa. Aktualna wersja GLSL to %1.%2" + +msgid "Could not load texture: %1" +msgstr "Nie udało się wczytać tekstury: %1" + +msgid "Could not compile shader:\n\n%1" +msgstr "Nie udało się skompilować shadera:\n\n%1" + +msgid "Program not linked:\n\n%1" +msgstr "Program niezalinkowany:\n\n%1" + +msgid "Shader Manager" +msgstr "Menedżer shaderów" + +msgid "Shader Configuration" +msgstr "Konfiguracja shadera" + +msgid "Add" +msgstr "Dodaj" + +msgid "Move up" +msgstr "Przesuń w górę" + +msgid "Move down" +msgstr "Przesuń w dół" + +msgid "Could not load file %1" +msgstr "Nie można wczytać pliku %1" diff --git a/src/qt/languages/pt-BR.po b/src/qt/languages/pt-BR.po index c9ff9615b..70e6d7b29 100644 --- a/src/qt/languages/pt-BR.po +++ b/src/qt/languages/pt-BR.po @@ -18,8 +18,8 @@ msgstr "&CTRL direito é o ALT esquerdo" msgid "&Hard Reset..." msgstr "&Reinicialização completa..." -msgid "&Ctrl+Alt+Del\tCtrl+F12" -msgstr "&Ctrl+Alt+Del\tCtrl+F12" +msgid "&Ctrl+Alt+Del" +msgstr "&Ctrl+Alt+Del" msgid "Ctrl+Alt+&Esc" msgstr "Ctrl+Alt+&Esc" @@ -111,8 +111,8 @@ msgstr "&Linear" msgid "Hi&DPI scaling" msgstr "Escala Hi&DPI" -msgid "&Fullscreen\tCtrl+Alt+PgUp" -msgstr "&Tela cheia\tCtrl+Alt+PgUp" +msgid "&Fullscreen" +msgstr "&Tela cheia" msgid "Fullscreen &stretch mode" msgstr "Modo de &redimensionamento da tela cheia" @@ -186,8 +186,11 @@ msgstr "&Configurações..." msgid "&Update status bar icons" msgstr "&Atualizar ícones da barra de status" -msgid "Take s&creenshot\tCtrl+F11" -msgstr "Capturar &tela\tCtrl+F11" +msgid "Take s&creenshot" +msgstr "Capturar &tela" + +msgid "S&ound" +msgstr "&Som" msgid "&Preferences..." msgstr "&Preferências..." @@ -198,11 +201,11 @@ msgstr "Ativar integração com o &Discord" msgid "Sound &gain..." msgstr "&Ganho de som..." -msgid "Begin trace\tCtrl+T" -msgstr "Inicio do rastreamento\tCtrl+T" +msgid "Begin trace" +msgstr "Inicio do rastreamento" -msgid "End trace\tCtrl+T" -msgstr "Finalizar rastreamento\tCtrl+T" +msgid "End trace" +msgstr "Finalizar rastreamento" msgid "&Help" msgstr "&Ajuda" @@ -249,8 +252,8 @@ msgstr "&Silenciar" msgid "E&mpty" msgstr "&Vazio" -msgid "&Reload previous image" -msgstr "&Recarregar imagem anterior" +msgid "Reload previous image" +msgstr "Recarregar imagem anterior" msgid "&Folder..." msgstr "&Pasta..." @@ -306,18 +309,12 @@ msgstr "OK" msgid "Cancel" msgstr "Cancelar" -msgid "Save these settings as &global defaults" -msgstr "Salvar estas configurações como &padrões globais" - msgid "&Default" msgstr "&Padrão" msgid "Language:" msgstr "Idioma:" -msgid "Icon set:" -msgstr "Conjunto de ícones:" - msgid "Gain" msgstr "Ganho" @@ -453,15 +450,6 @@ msgstr "Nuked (mais preciso)" msgid "YMFM (faster)" msgstr "YMFM (mais rápido)" -msgid "Network type:" -msgstr "Tipo de rede:" - -msgid "PCap device:" -msgstr "Dispositivo PCap:" - -msgid "Network adapter:" -msgstr "Adaptador de rede:" - msgid "COM1 Device:" msgstr "Dispositivo COM1:" @@ -642,14 +630,11 @@ msgstr "Erro fatal" msgid " - PAUSED" msgstr " - PAUSADO" -msgid "Press Ctrl+Alt+PgDn to return to windowed mode." -msgstr "Use Ctrl+Alt+PgDn para retornar ao modo janela" - msgid "Speed" msgstr "Velocidade" -msgid "ZIP %03i %i (%s): %ls" -msgstr "ZIP %03i %i (%s): %ls" +msgid "ZIP %1 %2 (%3): %4" +msgstr "ZIP %1 %2 (%3): %4" msgid "ZIP images" msgstr "Imagens ZIP" @@ -687,8 +672,11 @@ msgstr "A máquina \"%hs\" não está disponível devido à falta de ROMs no dir msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "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." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "A placa de vídeo 2 \"%hs\" não está disponível devido à falta de ROMs no diretório roms/video. Mudando para uma placa de vídeo disponível." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "A placa de vídeo 2 \"%hs\" não está disponível devido à falta de ROMs no diretório roms/video. Desativando a segunda placa vídeo." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "O dispositivo \"%hs\" não está disponível devido à falta de ROMs. Ignorando o dispositivo." msgid "Machine" msgstr "Máquina" @@ -750,14 +738,11 @@ msgstr "SE" msgid "KB" msgstr "KB" -msgid "Could not initialize the video renderer." -msgstr "Não foi possível inicializar o renderizador de vídeo." - msgid "Default" msgstr "Padrão" -msgid "%i Wait state(s)" -msgstr "%i estado(s) de espera" +msgid "%1 Wait state(s)" +msgstr "%1 estado(s) de espera" msgid "Type" msgstr "Tipo" @@ -801,11 +786,11 @@ msgstr "Sistema de Controle de Voo Thrustmaster" msgid "None" msgstr "Nenhum" -msgid "%u MB (CHS: %i, %i, %i)" -msgstr "%u MB (CCS: %i, %i, %i)" +msgid "%1 MB (CHS: %2, %3, %4)" +msgstr "%1 MB (CCS: %2, %3, %4)" -msgid "Floppy %i (%s): %ls" -msgstr "Disquete %i (%s): %ls" +msgid "Floppy %1 (%2): %3" +msgstr "Disquete %1 (%2): %3" msgid "Advanced sector images" msgstr "Imagens de setor avançado" @@ -825,8 +810,8 @@ msgstr "Não foi possível inicializar o Ghostscript" msgid "Unable to initialize GhostPCL" msgstr "Não foi possível inicializar o GhostPCL" -msgid "MO %i (%ls): %ls" -msgstr "Magneto-óptico %i (%ls): %ls" +msgid "MO %1 (%2): %3" +msgstr "Magneto-óptico %1 (%2): %3" msgid "MO images" msgstr "Imagens magneto-ópticas" @@ -859,7 +844,7 @@ msgid "86Box v" msgstr "86Box versão" msgid "An emulator of old computers\n\nAuthors: Miran Grča (OBattler), RichardG867, Jasmine Iwanek, TC1995, coldbrewed, Teemu Korhonen (Manaatti), Joakim L. Gilje, Adrien Moulin (elyosh), Daniel Balsom (gloriouscow), Cacodemon345, Fred N. van Kempen (waltje), Tiseno100, reenigne, and others.\n\nWith previous core contributions from Sarah Walker, leilei, JohnElliott, greatpsycho, and others.\n\nReleased under the GNU General Public License version 2 or later. See LICENSE for more information." -msgstr "Um emulador de computadores antigos\n\nAutores: Miran Grča (OBattler), RichardG867, Jasmine Iwanek, TC1995, coldbrewed, Teemu Korhonen (Manaatti), Joakim L. Gilje, Adrien Moulin (elyosh), Daniel Balsom (gloriouscow), Cacodemon345, Fred N. van Kempen (waltje), Tiseno100, reenigne, e outros.\n\nCom contribuições anteriores de Sarah Walker, leilei, JohnElliott, greatpsycho, e outros.\n\nTraduzido por: Altieres Lima da Silva\n\nLançado sob a Licença Pública Geral GNU, versão 2 ou posterior. Veja o arquivo LICENSE para mais informações." +msgstr "Um emulador de computadores antigos\n\nAutores: Miran Grča (OBattler), RichardG867, Jasmine Iwanek, TC1995, coldbrewed, Teemu Korhonen (Manaatti), Joakim L. Gilje, Adrien Moulin (elyosh), Daniel Balsom (gloriouscow), Cacodemon345, Fred N. van Kempen (waltje), Tiseno100, reenigne, e outros.\n\nCom contribuições anteriores de Sarah Walker, leilei, JohnElliott, greatpsycho, e outros.\n\nTraduzido por: Altieres Lima da Silva, Nelson K. Hennemann Filho\n\nLançado sob a Licença Pública Geral GNU, versão 2 ou posterior. Veja o arquivo LICENSE para mais informações." msgid "Hardware not available" msgstr "Hardware não disponível" @@ -876,9 +861,6 @@ msgstr "%1 é necessário para a conversão automática de arquivos PostScript p msgid "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PCL printer will be saved as Printer Command Language (.pcl) files." msgstr "%1 é necessário para a conversão automática de arquivos PCL para PDF.\n\nQualquer documento enviado para a impressora genérica PCL será salvo como arquivos Printer Command Language (.pcl)." -msgid "Entering fullscreen mode" -msgstr "Entrando no modo de tela cheia" - msgid "Don't show this message again" msgstr "Não exibir esta mensagem novamente" @@ -900,11 +882,8 @@ msgstr "Configuração do dispositivo %1" msgid "Monitor in sleep mode" msgstr "Monitor em modo de suspensão" -msgid "OpenGL Shaders" -msgstr "Shaders OpenGL" - -msgid "OpenGL options" -msgstr "Opções do OpenGL" +msgid "GLSL shaders" +msgstr "Shaders GLSL" msgid "You are loading an unsupported configuration" msgstr "Você está carregando uma configuração não suportada" @@ -915,24 +894,18 @@ msgstr "A filtragem do tipo de CPU baseada na máquina selecionada está desativ msgid "Continue" msgstr "Continuar" -msgid "Cassette: %s" -msgstr "Cassete: %s" +msgid "Cassette: %1" +msgstr "Cassete: %1" msgid "Cassette images" msgstr "Imagens de cassete" -msgid "Cartridge %i: %ls" -msgstr "Cartucho %i: %ls" +msgid "Cartridge %1: %2" +msgstr "Cartucho %1: %2" msgid "Cartridge images" msgstr "Imagens de cartucho" -msgid "Error initializing renderer" -msgstr "Erro ao inicializar o renderizador" - -msgid "OpenGL (3.0 Core) renderer could not be initialized. Use another renderer." -msgstr "O renderizador OpenGL (Núcleo 3.0) não pôde ser inicializado. Use outro renderizador." - msgid "Resume execution" msgstr "Continuar a execução" @@ -988,13 +961,13 @@ msgid "HDI or HDX images with a sector size other than 512 are not supported." msgstr "Imagens HDI ou HDX com um tamanho de setor que não seja 512 não são suportadas." msgid "Disk image file already exists" -msgstr "Esta imagem existe" +msgstr "A imagem de disco já existe" msgid "Please specify a valid file name." msgstr "Digite um nome de arquivo válido." msgid "Disk image created" -msgstr "A imagem foi criada com sucesso" +msgstr "A imagem de disco foi criada" msgid "Make sure the file exists and is readable." msgstr "Certifique-se de que o arquivo existe e é legível." @@ -1003,7 +976,7 @@ msgid "Make sure the file is being saved to a writable directory." msgstr "Certifique-se de que o arquivo está sendo salvo em um diretório gravável." msgid "Disk image too large" -msgstr "A imagem do disco é muito grande" +msgstr "A imagem de disco é muito grande" msgid "Remember to partition and format the newly-created drive." msgstr "Lembre-se de particionar e formatar a unidade recém-criada." @@ -1095,8 +1068,8 @@ msgstr "IDE" msgid "ATAPI" msgstr "ATAPI" -msgid "CD-ROM %i (%s): %s" -msgstr "CD-ROM %i (%s): %s" +msgid "CD-ROM %1 (%2): %3" +msgstr "CD-ROM %1 (%2): %3" msgid "160 KB" msgstr "160 KB" @@ -1275,9 +1248,6 @@ msgstr "Limpar histórico de imagens" msgid "Create..." msgstr "Criar..." -msgid "previous image" -msgstr "imagem anterior" - msgid "Host CD/DVD Drive (%1)" msgstr "Unidade de CD/DVD do anfitrião (%1)" @@ -1287,23 +1257,8 @@ msgstr "Barramento desconhecido" msgid "Null Driver" msgstr "Driver nulo" -msgid "NIC %02i (%ls) %ls" -msgstr "NIC %02i (%ls) %ls" - -msgid "Error opening \"%1\": %2" -msgstr "Erro ao abrir \"%1\": %2" - -msgid "Error compiling vertex shader in file \"%1\"" -msgstr "Erro ao compilar o sombreador de vértice no arquivo \"%1\"" - -msgid "Error compiling fragment shader in file \"%1\"" -msgstr "Erro ao compilar o fragment shader no arquivo \"%1\"" - -msgid "Error linking shader program in file \"%1\"" -msgstr "Erro ao vincular o programa de shader no arquivo \"%1\"" - -msgid "OpenGL 3.0 renderer options" -msgstr "Opções do renderizador OpenGL 3.0" +msgid "NIC %1 (%2) %3" +msgstr "NIC %1 (%2) %3" msgid "Render behavior" msgstr "Comportamento de renderização" @@ -1317,9 +1272,6 @@ msgstr " fps" msgid "VSync" msgstr "VSync" -msgid "<html><head/><body><p>Render each frame immediately, in sync with the emulated display.</p><p><span style=" font-style:italic;">This is the recommended option if the shaders in use don't utilize frametime for animated effects.</span></p></body></html>" -msgstr "<html><head/><body><p>Renderize cada quadro imediatamente, em sincronia com a tela emulada.</p><p><span style=" font-style:italic;">Essa é a opção recomendada se os shaders em uso não utilizarem o frametime para efeitos animados.</span></p></body></html>" - msgid "Synchronize with video" msgstr "Sincronizar com o vídeo" @@ -1329,21 +1281,9 @@ msgstr "Shaders" msgid "Remove" msgstr "Remover" -msgid "No shader selected" -msgstr "Nenhum shader selecionado" - msgid "Browse..." msgstr "Procurar..." -msgid "Shader error" -msgstr "Erro do sombreador" - -msgid "Could not load shaders." -msgstr "Não foi possível carregar os shaders." - -msgid "More information in details." -msgstr "Mais informações em detalhes." - msgid "Couldn't create OpenGL context." msgstr "Não foi possível criar o contexto OpenGL." @@ -1353,35 +1293,29 @@ msgstr "Não foi possível alternar para o contexto OpenGL." msgid "OpenGL version 3.0 or greater is required. Current version is %1.%2" msgstr "É necessária a versão 3.0 ou superior do OpenGL. A versão atual é %1.%2" -msgid "OpenGL initialization failed. Error %1." -msgstr "Falha na inicialização do OpenGL. Erro %1." - msgid "Error initializing OpenGL" msgstr "Erro ao inicializar o OpenGL" -msgid "Falling back to software rendering.\n" -msgstr "Voltando à renderização de software.\n" +msgid "\nFalling back to software rendering." +msgstr "\nVoltando à renderização de software." -msgid "Allocating memory for unpack buffer failed.\n" -msgstr "Falha na alocação de memória para o buffer de descompactação.\n" - -msgid "<html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html>" -msgstr "<html><head/><body><p>Ao selecionar imagens de mídia (CD-ROM, disquete, etc.), a caixa de diálogo de abertura será iniciada no mesmo diretório do arquivo de configuração do 86Box. Essa configuração provavelmente só fará diferença no macOS.</p></body></html>" +msgid "

When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" +msgstr "

Ao selecionar imagens de mídia (CD-ROM, disquete, etc.), a caixa de diálogo de abertura será iniciada no mesmo diretório do arquivo de configuração do 86Box. Essa configuração provavelmente só fará diferença no macOS.

" msgid "This machine might have been moved or copied." msgstr "Essa máquina pode ter sido movida ou copiada." msgid "In order to ensure proper networking functionality, 86Box needs to know if this machine was moved or copied.\n\nSelect \"I Copied It\" if you are not sure." -msgstr "Para garantir a funcionalidade adequada da rede, o 86Box precisa saber se essa máquina foi movida ou copiada.\n\nSelecione \"A copiei\" se não tiver certeza." +msgstr "Para garantir a funcionalidade adequada da rede, o 86Box precisa saber se essa máquina foi movida ou copiada.\n\nSelecione \"Copiei\" se não tiver certeza." msgid "I Moved It" -msgstr "O movi" +msgstr "Movi" msgid "I Copied It" -msgstr "A copiei" +msgstr "Copiei" msgid "86Box Monitor #" -msgstr "Monitor 86Box " +msgstr "Monitor 86Box #" msgid "No MCA devices." msgstr "Nenhum dispositivo MCA." @@ -1401,17 +1335,17 @@ msgstr "Placa de rede 3" msgid "Network Card #4" msgstr "Placa de rede 4" -msgid "Mode" -msgstr "Modo" +msgid "Mode:" +msgstr "Modo:" -msgid "Interface" -msgstr "Interface" +msgid "Interface:" +msgstr "Interface:" -msgid "Adapter" -msgstr "Adaptador" +msgid "Adapter:" +msgstr "Adaptador:" -msgid "VDE Socket" -msgstr "Soquete VDE" +msgid "VDE Socket:" +msgstr "Soquete VDE:" msgid "86Box Unit Tester" msgstr "Testador de unidade 86Box" @@ -1431,9 +1365,6 @@ msgstr "Passagem de porta serial 3" msgid "Serial port passthrough 4" msgstr "Passagem de porta serial 4" -msgid "Vision Systems LBA Enhancer" -msgstr "Vision Systems LBA Enhancer" - msgid "Renderer options..." msgstr "Opções do renderizador..." @@ -1546,7 +1477,7 @@ msgid "MIDI Clockout" msgstr "Saída do relógio MIDI" msgid "SoundFont" -msgstr "Fonte de som" +msgstr "SoundFont" msgid "Output Gain" msgstr "Ganho de saída" @@ -1852,7 +1783,7 @@ msgid "4th Order" msgstr "De 4ª ordem" msgid "7th Order" -msgstr "De 7º order" +msgstr "De 7ª ordem" msgid "Non-timed (original)" msgstr "Sem cronômetro (original)" @@ -1870,7 +1801,10 @@ msgid "Wheel" msgstr "Roda" msgid "Five + Wheel" -msgstr "Cinco + roda" +msgstr "Cinco + Roda" + +msgid "Five + 2 Wheels" +msgstr "Cinco + 2 Rodas" msgid "A3 - SMT2 Serial / SMT3(R)V" msgstr "A3 - SMT2 Serial / SMT3(R)V" @@ -2095,13 +2029,13 @@ msgid "Baud Rate of Passthrough" msgstr "Taxa de transmissão de passagem" msgid "Named Pipe (Server)" -msgstr "Tubo nomeado (servidor)" +msgstr "Pipe nomeado (servidor)" msgid "Host Serial Passthrough" msgstr "Passagem da porta serial do host" -msgid "Eject %s" -msgstr "Ejetar %s" +msgid "E&ject %1" +msgstr "E&jetar %1" msgid "&Unmute" msgstr "&Reativar som" @@ -2112,8 +2046,29 @@ msgstr "FPU Softfloat" msgid "High performance impact" msgstr "Alto impacto no desempenho" -msgid "RAM Disk (max. speed)" -msgstr "Disco RAM (velocidade máxima)" +msgid "[Generic] RAM Disk (max. speed)" +msgstr "[Genérico] Disco RAM (velocidade máxima)" + +msgid "[Generic] 1989 (3500 RPM)" +msgstr "[Genérico] 1989 (3500 RPM)" + +msgid "[Generic] 1992 (3600 RPM)" +msgstr "[Genérico] 1992 (3600 RPM)" + +msgid "[Generic] 1994 (4500 RPM)" +msgstr "[Genérico] 1994 (4500 RPM)" + +msgid "[Generic] 1996 (5400 RPM)" +msgstr "[Genérico] 1996 (5400 RPM)" + +msgid "[Generic] 1997 (5400 RPM)" +msgstr "[Genérico] 1997 (5400 RPM)" + +msgid "[Generic] 1998 (5400 RPM)" +msgstr "[Genérico] 1998 (5400 RPM)" + +msgid "[Generic] 2000 (7200 RPM)" +msgstr "[Genérico] 2000 (7200 RPM)" msgid "IBM 8514/A clone (ISA)" msgstr "Clone IBM 8514/A (ISA)" @@ -2121,14 +2076,116 @@ msgstr "Clone IBM 8514/A (ISA)" msgid "Vendor" msgstr "Fabricante" -msgid "30 Hz (JMP2 = 1)" -msgstr "30 Hz (JMP2 = 1)" - -msgid "60 Hz (JMP2 = 2)" -msgstr "60 Hz (JMP2 = 2)" - msgid "Generic PC/XT Memory Expansion" msgstr "Expansão de memória genérica PC/XT" msgid "Generic PC/AT Memory Expansion" msgstr "Expansão de memória genérica PC/AT" + +msgid "Unable to find Dot-Matrix fonts" +msgstr "Não foi possível localizar os fontes matriciais de pontos" + +msgid "TrueType fonts in the \"roms/printer/fonts\" directory are required for the emulation of the Generic ESC/P Dot-Matrix Printer." +msgstr "As fontes TrueType no diretório \"roms/printer/fonts\" são necessárias para a emulação da impressora matricial de pontos ESC/P genérica." + +msgid "Inhibit multimedia keys" +msgstr "Inibir teclas multimídia" + +msgid "Ask for confirmation before saving settings" +msgstr "Perguntar antes de salvar configurações" + +msgid "Ask for confirmation before hard resetting" +msgstr "Perguntar antes de reinicialização completa" + +msgid "Ask for confirmation before quitting" +msgstr "Perguntar antes de sair" + +msgid "Options" +msgstr "Opções" + +msgid "Model" +msgstr "Modelo" + +msgid "Model:" +msgstr "Modelo:" + +msgid "Failed to initialize Vulkan renderer." +msgstr "Falha ao inicializar o renderizador Vulkan." + +msgid "GLSL Error" +msgstr "Erro GLSL" + +msgid "Could not load shader: %1" +msgstr "Impossível carregar o shader: %1" + +msgid "OpenGL version 3.0 or greater is required. Current GLSL version is %1.%2" +msgstr "OpenGL versão 3.0 ou superior é exigido. Versão atual GLSL é %1.%2" + +msgid "Could not load texture: %1" +msgstr "Impossível carregar a textura: %1" + +msgid "Could not compile shader:\n\n%1" +msgstr "Impossível compilar o shader:\n\n%1" + +msgid "Program not linked:\n\n%1" +msgstr "Programa não linkado:\n\n%1" + +msgid "Shader Manager" +msgstr "Gerenciador de Shader" + +msgid "Shader Configuration" +msgstr "Configuração de Shader" + +msgid "Add" +msgstr "Adicionar" + +msgid "Move up" +msgstr "Mover para cima" + +msgid "Move down" +msgstr "Mover para baixo" + +msgid "Could not load file %1" +msgstr "Impossível carregar arquivo %1" + +msgid "Key Bindings:" +msgstr "Atalhos:" + +msgid "Action" +msgstr "Ação" + +msgid "Keybind" +msgstr "Atalho" + +msgid "Clear binding" +msgstr "Limpar atalho" + +msgid "Bind" +msgstr "Vincular" + +msgid "Bind Key" +msgstr "Vincular tecla" + +msgid "Enter key combo:" +msgstr "Pressione combinação de teclas:" + +msgid "Send Control+Alt+Del" +msgstr "Enviar Control+Alt+Del" + +msgid "Send Control+Alt+Escape" +msgstr "Enviar Control+Alt+Escape" + +msgid "Toggle fullscreen" +msgstr "Alternar tela cheia" + +msgid "Screenshot" +msgstr "Captura de tela" + +msgid "Release mouse pointer" +msgstr "Liberar ponteiro do mouse" + +msgid "Toggle pause" +msgstr "Alternar pausa" + +msgid "Toggle mute" +msgstr "Alternar mudo" diff --git a/src/qt/languages/pt-PT.po b/src/qt/languages/pt-PT.po index 1494ce1dc..795d44e2b 100644 --- a/src/qt/languages/pt-PT.po +++ b/src/qt/languages/pt-PT.po @@ -18,8 +18,8 @@ msgstr "&CTRL direito é ALT esquerdo" msgid "&Hard Reset..." msgstr "&Reinicialização completa..." -msgid "&Ctrl+Alt+Del\tCtrl+F12" -msgstr "&Ctrl+Alt+Del\tCtrl+F12" +msgid "&Ctrl+Alt+Del" +msgstr "&Ctrl+Alt+Del" msgid "Ctrl+Alt+&Esc" msgstr "Ctrl+Alt+&Esc" @@ -111,8 +111,8 @@ msgstr "&Linear" msgid "Hi&DPI scaling" msgstr "Escala Hi&DPI" -msgid "&Fullscreen\tCtrl+Alt+PgUp" -msgstr "E&crã cheio\tCtrl+Alt+PgUp" +msgid "&Fullscreen" +msgstr "E&crã cheio" msgid "Fullscreen &stretch mode" msgstr "Modo &de estiramento na tela cheia" @@ -186,8 +186,11 @@ msgstr "&Definições..." msgid "&Update status bar icons" msgstr "&Atualizar ícones da barra de estado" -msgid "Take s&creenshot\tCtrl+F11" -msgstr "Gravar imagem de ecrã\tCtrl+F11" +msgid "Take s&creenshot" +msgstr "Gravar imagem de ecrã" + +msgid "S&ound" +msgstr "&Som" msgid "&Preferences..." msgstr "&Preferências..." @@ -198,11 +201,11 @@ msgstr "Ativar integração com &Discord" msgid "Sound &gain..." msgstr "&Ganho de som..." -msgid "Begin trace\tCtrl+T" -msgstr "Iniciar o rastreio\tCtrl+T" +msgid "Begin trace" +msgstr "Iniciar o rastreio" -msgid "End trace\tCtrl+T" -msgstr "Terminar o rastreio\tCtrl+T" +msgid "End trace" +msgstr "Terminar o rastreio" msgid "&Help" msgstr "&Ajuda" @@ -249,8 +252,8 @@ msgstr "&Desativar som" msgid "E&mpty" msgstr "&CDROM vazio" -msgid "&Reload previous image" -msgstr "&Recarregar imagem anterior" +msgid "Reload previous image" +msgstr "Recarregar imagem anterior" msgid "&Folder..." msgstr "&Pasta..." @@ -306,18 +309,12 @@ msgstr "OK" msgid "Cancel" msgstr "Cancelar" -msgid "Save these settings as &global defaults" -msgstr "Guardar estas definições como padrões &globais" - msgid "&Default" msgstr "&Padrão" msgid "Language:" msgstr "Idioma:" -msgid "Icon set:" -msgstr "Pacote de ícones:" - msgid "Gain" msgstr "Ganho" @@ -453,15 +450,6 @@ msgstr "Nuked (mais exacto)" msgid "YMFM (faster)" msgstr "YMFM (mais rápido)" -msgid "Network type:" -msgstr "Tipo de rede:" - -msgid "PCap device:" -msgstr "Dispositivo PCap:" - -msgid "Network adapter:" -msgstr "Placa de rede:" - msgid "COM1 Device:" msgstr "Dispositivo COM1:" @@ -642,14 +630,11 @@ msgstr "Erro fatal" msgid " - PAUSED" msgstr " - EM PAUSA" -msgid "Press Ctrl+Alt+PgDn to return to windowed mode." -msgstr "Pressione Ctrl+Alt+PgDn para voltar ao modo de janela." - msgid "Speed" msgstr "Velocidade" -msgid "ZIP %03i %i (%s): %ls" -msgstr "ZIP %03i %i (%s): %ls" +msgid "ZIP %1 %2 (%3): %4" +msgstr "ZIP %1 %2 (%3): %4" msgid "ZIP images" msgstr "Imagens ZIP" @@ -687,8 +672,11 @@ msgstr "A máquina \"%hs\" não está disponível devido à falta de ROMs na pas msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "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." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "A placa vídeo 2 \"%hs\" não está disponível devido à falta de ROMs na pasta roms/video. A mudar para uma placa vídeo disponível." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "A placa vídeo 2 \"%hs\" não está disponível devido à falta de ROMs na pasta roms/video. A desativar a segunda placa vídeo." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "O dispositivo \"%hs\" não está disponível devido à falta de ROMs A ignorar o dispositivo." msgid "Machine" msgstr "Máquina" @@ -750,14 +738,11 @@ msgstr "S" msgid "KB" msgstr "KB" -msgid "Could not initialize the video renderer." -msgstr "Não foi possível inicializar o renderizador vídeo." - msgid "Default" msgstr "Padrão" -msgid "%i Wait state(s)" -msgstr "%i estado(s) de espera" +msgid "%1 Wait state(s)" +msgstr "%1 estado(s) de espera" msgid "Type" msgstr "Tipo" @@ -801,11 +786,11 @@ msgstr "Thrustmaster Flight Control System" msgid "None" msgstr "Nenhum" -msgid "%u MB (CHS: %i, %i, %i)" -msgstr "%u MB (CCS: %i, %i, %i)" +msgid "%1 MB (CHS: %2, %3, %4)" +msgstr "%1 MB (CCS: %2, %3, %4)" -msgid "Floppy %i (%s): %ls" -msgstr "Disquete %i (%s): %ls" +msgid "Floppy %1 (%2): %3" +msgstr "Disquete %1 (%2): %3" msgid "Advanced sector images" msgstr "Imagens avançadas de sector" @@ -825,8 +810,8 @@ msgstr "Não foi possível inicializar o Ghostscript" msgid "Unable to initialize GhostPCL" msgstr "Não foi possível inicializar o GhostPCL" -msgid "MO %i (%ls): %ls" -msgstr "Magneto-óptico %i (%ls): %ls" +msgid "MO %1 (%2): %3" +msgstr "Magneto-óptico %1 (%2): %3" msgid "MO images" msgstr "Imagens magneto-ópticas" @@ -876,9 +861,6 @@ msgstr "%1 é requerido para a conversão automática de ficheiros PostScript pa msgid "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PCL printer will be saved as Printer Command Language (.pcl) files." msgstr "%1 é requerido para a conversão automática de ficheiros PCL para ficheiros PDF.\n\nQualquer documento enviado para a impressora PCL genérica será gravado como um ficheiro Printer Command Language (.pcl)." -msgid "Entering fullscreen mode" -msgstr "A entrar no modo de tela cheia" - msgid "Don't show this message again" msgstr "Não mostrar mais esta mensagem" @@ -900,11 +882,8 @@ msgstr "Configuração de dispositivo %1" msgid "Monitor in sleep mode" msgstr "Ecrã em modo de sono" -msgid "OpenGL Shaders" -msgstr "Shaders OpenGL" - -msgid "OpenGL options" -msgstr "Opções de OpenGL" +msgid "GLSL shaders" +msgstr "Shaders GLSL" msgid "You are loading an unsupported configuration" msgstr "Está a carregar uma configuração sem suporte!" @@ -915,24 +894,18 @@ msgstr "A filtragem do tipo de CPU baseada na máquina escolhida está desativad msgid "Continue" msgstr "Continuar" -msgid "Cassette: %s" -msgstr "Cassete: %s" +msgid "Cassette: %1" +msgstr "Cassete: %1" msgid "Cassette images" msgstr "Imagens de cassete" -msgid "Cartridge %i: %ls" -msgstr "Cartucho %i: %ls" +msgid "Cartridge %1: %2" +msgstr "Cartucho %1: %2" msgid "Cartridge images" msgstr "Imagens de cartucho" -msgid "Error initializing renderer" -msgstr "Erro na inicialização do renderizador" - -msgid "OpenGL (3.0 Core) renderer could not be initialized. Use another renderer." -msgstr "Não foi possível inicializar o renderizador OpenGL (3.0 Core). Utilize outro renderizador." - msgid "Resume execution" msgstr "Retomar execução" @@ -1095,8 +1068,8 @@ msgstr "IDE" msgid "ATAPI" msgstr "ATAPI" -msgid "CD-ROM %i (%s): %s" -msgstr "CD-ROM %i (%s): %s" +msgid "CD-ROM %1 (%2): %3" +msgstr "CD-ROM %1 (%2): %3" msgid "160 KB" msgstr "160 KB" @@ -1275,9 +1248,6 @@ msgstr "Limpar o histórico de imagens" msgid "Create..." msgstr "Criar..." -msgid "previous image" -msgstr "imagem anterior" - msgid "Host CD/DVD Drive (%1)" msgstr "Unidade de CD/DVD do anfitrião (%1)" @@ -1287,23 +1257,8 @@ msgstr "Autocarro desconhecido" msgid "Null Driver" msgstr "Condutor nulo" -msgid "NIC %02i (%ls) %ls" -msgstr "NIC %02i (%ls) %ls" - -msgid "Error opening \"%1\": %2" -msgstr "Erro ao abrir \"%1\": %2" - -msgid "Error compiling vertex shader in file \"%1\"" -msgstr "Erro ao compilar o sombreador de vértice no ficheiro \"%1\"" - -msgid "Error compiling fragment shader in file \"%1\"" -msgstr "Erro ao compilar o shader de fragmento no ficheiro \"%1\"" - -msgid "Error linking shader program in file \"%1\"" -msgstr "Erro ao ligar o programa de shader no ficheiro \"%1\"" - -msgid "OpenGL 3.0 renderer options" -msgstr "Opções do renderizador OpenGL 3.0" +msgid "NIC %1 (%2) %3" +msgstr "NIC %1 (%2) %3" msgid "Render behavior" msgstr "Comportamento de renderização" @@ -1317,9 +1272,6 @@ msgstr " fps" msgid "VSync" msgstr "VSync" -msgid "<html><head/><body><p>Render each frame immediately, in sync with the emulated display.</p><p><span style=" font-style:italic;">This is the recommended option if the shaders in use don't utilize frametime for animated effects.</span></p></body></html>" -msgstr "<html><head/><body><p>Renderiza cada frame imediatamente, em sincronia com o ecrã emulado.</p><p><span style=" font-style:italic;">Esta é a opção recomendada se os shaders em uso não utilizam frametime para efeitos animados.</span></p></body></html>" - msgid "Synchronize with video" msgstr "Sincronizar com vídeo" @@ -1329,21 +1281,9 @@ msgstr "Shaders" msgid "Remove" msgstr "Remover" -msgid "No shader selected" -msgstr "Nenhum sombreador selecionado" - msgid "Browse..." msgstr "Navegar..." -msgid "Shader error" -msgstr "Erro de shader" - -msgid "Could not load shaders." -msgstr "Não foi possível carregar os shaders." - -msgid "More information in details." -msgstr "Mais informações em pormenor." - msgid "Couldn't create OpenGL context." msgstr "Não foi possível criar o contexto OpenGL." @@ -1353,20 +1293,14 @@ msgstr "Não foi possível mudar para o contexto OpenGL." msgid "OpenGL version 3.0 or greater is required. Current version is %1.%2" msgstr "É necessária a versão 3.0 ou superior do OpenGL. A versão atual é %1.%2" -msgid "OpenGL initialization failed. Error %1." -msgstr "Falha na inicialização do OpenGL. Erro %1." - msgid "Error initializing OpenGL" msgstr "Erro ao inicializar o OpenGL" -msgid "Falling back to software rendering.\n" -msgstr "Recuando para a renderização de software." +msgid "\nFalling back to software rendering." +msgstr "\nRecuando para a renderização de software." -msgid "Allocating memory for unpack buffer failed.\n" -msgstr "Falha na atribuição de memória para a memória intermédia de descompactação.\n" - -msgid "<html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html>" -msgstr "<html><head/><body><p>Ao selecionar imagens multimédia (CD-ROM, disquete, etc.) a caixa de diálogo de abertura irá começar no mesmo diretório que o ficheiro de configuração da 86Box. Esta configuração provavelmente só fará diferença no macOS.</p></body></html>" +msgid "

When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" +msgstr "

Ao selecionar imagens multimédia (CD-ROM, disquete, etc.) a caixa de diálogo de abertura irá começar no mesmo diretório que o ficheiro de configuração da 86Box. Esta configuração provavelmente só fará diferença no macOS.

" msgid "This machine might have been moved or copied." msgstr "Esta máquina pode ter sido deslocada ou copiada." @@ -1401,17 +1335,17 @@ msgstr "Placa de rede 3" msgid "Network Card #4" msgstr "Placa de rede 4" -msgid "Mode" -msgstr "Modo" +msgid "Mode:" +msgstr "Modo:" -msgid "Interface" -msgstr "Interface" +msgid "Interface:" +msgstr "Interface:" -msgid "Adapter" -msgstr "Adaptador" +msgid "Adapter:" +msgstr "Adaptador:" -msgid "VDE Socket" -msgstr "Tomada VDE" +msgid "VDE Socket:" +msgstr "Tomada VDE:" msgid "86Box Unit Tester" msgstr "Testador de unidades 86Box" @@ -1431,9 +1365,6 @@ msgstr "Passagem da porta de série 3" msgid "Serial port passthrough 4" msgstr "Passagem da porta de série 4" -msgid "Vision Systems LBA Enhancer" -msgstr "Sistemas de visão Melhorador LBA" - msgid "Renderer options..." msgstr "Opções do renderizador..." @@ -1872,6 +1803,9 @@ msgstr "Roda" msgid "Five + Wheel" msgstr "Cinco + Roda" +msgid "Five + 2 Wheels" +msgstr "" + msgid "A3 - SMT2 Serial / SMT3(R)V" msgstr "A3 - SMT2 série / SMT3(R)V" @@ -2100,8 +2034,8 @@ msgstr "Tubo nomeado (servidor)" msgid "Host Serial Passthrough" msgstr "Passagem da porta de série do anfitrião" -msgid "Eject %s" -msgstr "Ejetar %s" +msgid "E&ject %1" +msgstr "E&jetar %1" msgid "&Unmute" msgstr "&Reativar som" @@ -2112,11 +2046,104 @@ msgstr "FPU Softfloat" msgid "High performance impact" msgstr "Elevado impacto no desempenho" -msgid "RAM Disk (max. speed)" -msgstr "Disco RAM (velocidade máxima)" +msgid "[Generic] RAM Disk (max. speed)" +msgstr "[Generic] Disco RAM (velocidade máxima)" + +msgid "[Generic] 1989 (3500 RPM)" +msgstr "" + +msgid "[Generic] 1992 (3600 RPM)" +msgstr "" + +msgid "[Generic] 1994 (4500 RPM)" +msgstr "" + +msgid "[Generic] 1996 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1997 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1998 (5400 RPM)" +msgstr "" + +msgid "[Generic] 2000 (7200 RPM)" +msgstr "" msgid "IBM 8514/A clone (ISA)" msgstr "Clone IBM 8514/A (ISA)" msgid "Vendor" msgstr "Fabricante" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Expansão de memória genérica PC/XT" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Expansão de memória genérica PC/AT" + +msgid "Unable to find Dot-Matrix fonts" +msgstr "Não foi possível encontrar os fontes matriciais de pontos" + +msgid "TrueType fonts in the \"roms/printer/fonts\" directory are required for the emulation of the Generic ESC/P Dot-Matrix Printer." +msgstr "As fontes TrueType no diretório \"roms/printer/fonts\" são necessárias para a emulação da impressora matricial de pontos ESC/P genérica" + +msgid "Inhibit multimedia keys" +msgstr "" + +msgid "Ask for confirmation before saving settings" +msgstr "" + +msgid "Ask for confirmation before hard resetting" +msgstr "" + +msgid "Ask for confirmation before quitting" +msgstr "" + +msgid "Options" +msgstr "" + +msgid "Model" +msgstr "" + +msgid "Model:" +msgstr "" + +msgid "Failed to initialize Vulkan renderer." +msgstr "" + +msgid "GLSL Error" +msgstr "" + +msgid "Could not load shader: %1" +msgstr "" + +msgid "OpenGL version 3.0 or greater is required. Current GLSL version is %1.%2" +msgstr "" + +msgid "Could not load texture: %1" +msgstr "" + +msgid "Could not compile shader:\n\n%1" +msgstr "" + +msgid "Program not linked:\n\n%1" +msgstr "" + +msgid "Shader Manager" +msgstr "" + +msgid "Shader Configuration" +msgstr "" + +msgid "Add" +msgstr "" + +msgid "Move up" +msgstr "" + +msgid "Move down" +msgstr "" + +msgid "Could not load file %1" +msgstr "" diff --git a/src/qt/languages/ru-RU.po b/src/qt/languages/ru-RU.po index 8476090d1..b721d6f29 100644 --- a/src/qt/languages/ru-RU.po +++ b/src/qt/languages/ru-RU.po @@ -18,8 +18,8 @@ msgstr "&Правый CTRL - это левый ALT" msgid "&Hard Reset..." msgstr "&Холодная перезагрузка..." -msgid "&Ctrl+Alt+Del\tCtrl+F12" -msgstr "&Ctrl+Alt+Del\tCtrl+F12" +msgid "&Ctrl+Alt+Del" +msgstr "&Ctrl+Alt+Del" msgid "Ctrl+Alt+&Esc" msgstr "Ctrl+Alt+&Esc" @@ -55,7 +55,7 @@ msgid "Qt (&OpenGL)" msgstr "Qt (&OpenGL)" msgid "Open&GL (3.0 Core)" -msgstr "Open&GL (3.0)" +msgstr "Open&GL (3.0 Core)" msgid "&VNC" msgstr "&VNC" @@ -111,8 +111,8 @@ msgstr "&Линейный" msgid "Hi&DPI scaling" msgstr "Масштабирование Hi&DPI" -msgid "&Fullscreen\tCtrl+Alt+PgUp" -msgstr "&Полноэкранный режим\tCtrl+Alt+PgUp" +msgid "&Fullscreen" +msgstr "&Полноэкранный режим" msgid "Fullscreen &stretch mode" msgstr "&Растягивание в полноэкранном режиме" @@ -147,6 +147,12 @@ msgstr "RGB &цветной" msgid "&RGB Grayscale" msgstr "&RGB монохромный" +msgid "RGB (no brown)" +msgstr "RGB (без коричневого)" + +msgid "Generic RGBI color monitor" +msgstr "Стандартный цветной монитор RGBI" + msgid "&Amber monitor" msgstr "&Янтарный оттенок" @@ -186,8 +192,11 @@ msgstr "&Настройки машины..." msgid "&Update status bar icons" msgstr "&Обновление значков строки состояния" -msgid "Take s&creenshot\tCtrl+F11" -msgstr "Сделать с&криншот\tCtrl+F11" +msgid "Take s&creenshot" +msgstr "Сделать с&криншот" + +msgid "S&ound" +msgstr "&Звук" msgid "&Preferences..." msgstr "&Параметры..." @@ -198,11 +207,11 @@ msgstr "Включить интеграцию &Discord" msgid "Sound &gain..." msgstr "&Усиление звука..." -msgid "Begin trace\tCtrl+T" -msgstr "Начать трассировку\tCtrl+T" +msgid "Begin trace" +msgstr "Начать трассировку" -msgid "End trace\tCtrl+T" -msgstr "Завершить трассировку\tCtrl+T" +msgid "End trace" +msgstr "Завершить трассировку" msgid "&Help" msgstr "&Помощь" @@ -211,7 +220,7 @@ msgid "&Documentation..." msgstr "&Документация..." msgid "&About 86Box..." -msgstr "&О программе 86Box..." +msgstr "&О 86Box..." msgid "&New image..." msgstr "&Новый образ..." @@ -249,8 +258,8 @@ msgstr "О&тключить звук" msgid "E&mpty" msgstr "П&устой" -msgid "&Reload previous image" -msgstr "&Снова загрузить предыдущий образ" +msgid "Reload previous image" +msgstr "Перезагрузить предыдущий образ" msgid "&Folder..." msgstr "&Папка..." @@ -306,18 +315,12 @@ msgstr "OK" msgid "Cancel" msgstr "Отмена" -msgid "Save these settings as &global defaults" -msgstr "Сохранить эти параметры как &глобальные по умолчанию" - msgid "&Default" msgstr "&По умолчанию" msgid "Language:" msgstr "Язык:" -msgid "Icon set:" -msgstr "Набор иконок:" - msgid "Gain" msgstr "Усиление" @@ -433,10 +436,10 @@ msgid "Sound card #4:" msgstr "Звуковая карта 4:" msgid "MIDI Out Device:" -msgstr "MIDI Out устройство:" +msgstr "Устройство вывода MIDI:" msgid "MIDI In Device:" -msgstr "MIDI In устройство:" +msgstr "Устройство ввода MIDI:" msgid "Standalone MPU-401" msgstr "Отдельный MPU-401" @@ -453,15 +456,6 @@ msgstr "Nuked (более точный)" msgid "YMFM (faster)" msgstr "YMFM (быстрее)" -msgid "Network type:" -msgstr "Тип сети:" - -msgid "PCap device:" -msgstr "Устройство PCap:" - -msgid "Network adapter:" -msgstr "Сетевая карта:" - msgid "COM1 Device:" msgstr "Устройство COM1:" @@ -610,7 +604,10 @@ msgid "ISA RTC:" msgstr "ISA RTC:" msgid "ISA Memory Expansion" -msgstr "Карта расширения памяти ISA" +msgstr "Карты расширения памяти ISA" + +msgid "ISA ROM Cards" +msgstr "Карты ПЗУ ISA" msgid "Card 1:" msgstr "Карта 1:" @@ -642,14 +639,11 @@ msgstr "Неустранимая ошибка" msgid " - PAUSED" msgstr " - ПАУЗА" -msgid "Press Ctrl+Alt+PgDn to return to windowed mode." -msgstr "Нажмите Ctrl+Alt+PgDn для возврата в оконный режим." - msgid "Speed" msgstr "Скорость" -msgid "ZIP %03i %i (%s): %ls" -msgstr "ZIP %03i %i (%s): %ls" +msgid "ZIP %1 %2 (%3): %4" +msgstr "ZIP %1 %2 (%3): %4" msgid "ZIP images" msgstr "Образы ZIP" @@ -687,8 +681,11 @@ msgstr "Системная плата \"%hs\" недоступна из-за о msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "Видеокарта \"%hs\" недоступна из-за отсутствия файла её ПЗУ в каталоге roms/video. Переключение на доступную видеокарту." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Видеокарта 2 \"%hs\" недоступна из-за отсутствия файла её ПЗУ в каталоге roms/video. Переключение на доступную видеокарту." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "Видеокарта 2 \"%hs\" недоступна из-за отсутствия файла её ПЗУ в каталоге roms/video. Вторая видеокарта отключена." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Устройство \"%hs\" недоступно из-за отсутствия файла его ПЗУ. Устройство проигнорировано." msgid "Machine" msgstr "Компьютер" @@ -750,14 +747,11 @@ msgstr "S" msgid "KB" msgstr "КБ" -msgid "Could not initialize the video renderer." -msgstr "Не удалось инициализировать рендерер видео." - msgid "Default" msgstr "По умолчанию" -msgid "%i Wait state(s)" -msgstr "%i WS" +msgid "%1 Wait state(s)" +msgstr "%1 WS" msgid "Type" msgstr "Тип" @@ -801,11 +795,11 @@ msgstr "Система управления полётом Thrustmaster" msgid "None" msgstr "Нет" -msgid "%u MB (CHS: %i, %i, %i)" -msgstr "%u МБ (CHS: %i, %i, %i)" +msgid "%1 MB (CHS: %2, %3, %4)" +msgstr "%1 МБ (CHS: %2, %3, %4)" -msgid "Floppy %i (%s): %ls" -msgstr "Дисковод %i (%s): %ls" +msgid "Floppy %1 (%2): %3" +msgstr "Дисковод %1 (%2): %3" msgid "Advanced sector images" msgstr "Расширенные образы секторов" @@ -825,8 +819,8 @@ msgstr "Невозможно инициализировать Ghostscript" msgid "Unable to initialize GhostPCL" msgstr "Невозможно инициализировать GhostPCL" -msgid "MO %i (%ls): %ls" -msgstr "Магнитооптический %i (%ls): %ls" +msgid "MO %1 (%2): %3" +msgstr "Магнитооптический %1 (%2): %3" msgid "MO images" msgstr "Образы магнитооптических дисков" @@ -876,9 +870,6 @@ msgstr "Для автоматического преобразования фа msgid "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PCL printer will be saved as Printer Command Language (.pcl) files." msgstr "Для автоматического преобразования файлов PCL в PDF требуется %1.\n\nВсе документы, отправленные на стандартный принтер PCL, будут сохранены в виде файлов Printer Command Language (.pcl)." -msgid "Entering fullscreen mode" -msgstr "Вход в полноэкранный режим" - msgid "Don't show this message again" msgstr "Больше не показывать это сообщение" @@ -900,11 +891,8 @@ msgstr "Конфигурация устройства %1" msgid "Monitor in sleep mode" msgstr "Монитор в спящем режиме" -msgid "OpenGL Shaders" -msgstr "Шейдеры OpenGL" - -msgid "OpenGL options" -msgstr "Параметры OpenGL" +msgid "GLSL shaders" +msgstr "Шейдеры GLSL" msgid "You are loading an unsupported configuration" msgstr "Вы загружаете неподдерживаемую конфигурацию" @@ -915,24 +903,18 @@ msgstr "Выбор типов ЦП для этой системной платы msgid "Continue" msgstr "Продолжить" -msgid "Cassette: %s" -msgstr "Кассета: %s" +msgid "Cassette: %1" +msgstr "Кассета: %1" msgid "Cassette images" msgstr "Образы кассет" -msgid "Cartridge %i: %ls" -msgstr "Картридж %i: %ls" +msgid "Cartridge %1: %2" +msgstr "Картридж %1: %2" msgid "Cartridge images" msgstr "Образы картриджей" -msgid "Error initializing renderer" -msgstr "Ошибка инициализации рендерера" - -msgid "OpenGL (3.0 Core) renderer could not be initialized. Use another renderer." -msgstr "Невозможно инициализировать рендерер OpenGL (3.0). Пожалуйста, используйте другой рендерер." - msgid "Resume execution" msgstr "Возобновить выполнение" @@ -1095,8 +1077,8 @@ msgstr "IDE" msgid "ATAPI" msgstr "ATAPI" -msgid "CD-ROM %i (%s): %s" -msgstr "CD-ROM %i (%s): %s" +msgid "CD-ROM %1 (%2): %3" +msgstr "CD-ROM %1 (%2): %3" msgid "160 KB" msgstr "160 КБ" @@ -1264,22 +1246,19 @@ msgid "Pen" msgstr "Ручка" msgid "Host CD/DVD Drive (%1:)" -msgstr "Главный CD/DVD-привод (%1:)" +msgstr "CD/DVD Привод хоста (%1:)" msgid "&Connected" -msgstr "&Connected" +msgstr "&Кабель подключен" msgid "Clear image history" msgstr "Очистить историю образов" msgid "Create..." -msgstr "Создайте..." - -msgid "previous image" -msgstr "предыдущее изображение" +msgstr "Создать..." msgid "Host CD/DVD Drive (%1)" -msgstr "Главный CD/DVD-привод (%1)" +msgstr "CD/DVD Привод хоста (%1)" msgid "Unknown Bus" msgstr "Неизвестная шина" @@ -1287,23 +1266,8 @@ msgstr "Неизвестная шина" msgid "Null Driver" msgstr "Нулевой драйвер" -msgid "NIC %02i (%ls) %ls" -msgstr "NIC %02i (%ls) %ls" - -msgid "Error opening \"%1\": %2" -msgstr "Ошибка при открытии \"%1\": %2" - -msgid "Error compiling vertex shader in file \"%1\"" -msgstr "Ошибка компиляции вершинного шейдера в файле \"%1\"" - -msgid "Error compiling fragment shader in file \"%1\"" -msgstr "Ошибка компиляции фрагментного шейдера в файле \"%1\"" - -msgid "Error linking shader program in file \"%1\"" -msgstr "Ошибка компоновки программы шейдера в файле \"%1\"" - -msgid "OpenGL 3.0 renderer options" -msgstr "Параметры рендеринга OpenGL 3.0" +msgid "NIC %1 (%2) %3" +msgstr "NIC %1 (%2) %3" msgid "Render behavior" msgstr "Режим рендеринга" @@ -1317,11 +1281,8 @@ msgstr " fps" msgid "VSync" msgstr "Вертикальная синхронизация" -msgid "<html><head/><body><p>Render each frame immediately, in sync with the emulated display.</p><p><span style=" font-style:italic;">This is the recommended option if the shaders in use don't utilize frametime for animated effects.</span></p></body></html>" -msgstr "<html><head/><body><p>Рендерить каждый кадр немедленно, синхронно с эмулируемым дисплеем.</p><p><span style="font-style:italic;">Это рекомендуемый вариант, если используемые шейдеры не используют время кадров для анимированных эффектов.</span></p></body></html>" - msgid "Synchronize with video" -msgstr "Синхронизация с видео" +msgstr "Синхронизировать с видео" msgid "Shaders" msgstr "Шейдеры" @@ -1329,21 +1290,9 @@ msgstr "Шейдеры" msgid "Remove" msgstr "Удалить" -msgid "No shader selected" -msgstr "Шейдер не выбран" - msgid "Browse..." msgstr "Обзор..." -msgid "Shader error" -msgstr "Ошибка шейдера" - -msgid "Could not load shaders." -msgstr "Не удалось загрузить шейдеры." - -msgid "More information in details." -msgstr "Более подробная информация в деталях." - msgid "Couldn't create OpenGL context." msgstr "Не удалось создать контекст OpenGL." @@ -1353,20 +1302,14 @@ msgstr "Не удалось переключиться на контекст Ope msgid "OpenGL version 3.0 or greater is required. Current version is %1.%2" msgstr "Требуется OpenGL версии 3.0 или выше. Текущая версия %1.%2" -msgid "OpenGL initialization failed. Error %1." -msgstr "Не удалось выполнить инициализацию OpenGL. Ошибка %1." - msgid "Error initializing OpenGL" msgstr "Ошибка инициализации OpenGL" -msgid "Falling back to software rendering.\n" -msgstr "Переключение на программный рендеринг.\n" +msgid "\nFalling back to software rendering." +msgstr "\nПереключение на программный рендеринг." -msgid "Allocating memory for unpack buffer failed.\n" -msgstr "Выделение памяти для буфера распаковки не удалось.\n" - -msgid "<html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html>" -msgstr "<html><head/><body><p>При выборе образов носителей (CD-ROM, дискет и т. д.) диалог открытия будет запускаться в том же каталоге, что и файл конфигурации 86Box. Эта настройка, скорее всего, будет иметь значение только на macOS.</p></body></html>" +msgid "

When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" +msgstr "

При выборе образов носителей (CD-ROM, дискет и т. д.) диалог открытия будет запускаться в том же каталоге, что и файл конфигурации 86Box. Эта настройка, скорее всего, будет иметь значение только на macOS.

" msgid "This machine might have been moved or copied." msgstr "Возможно, эта машина была перемещена или скопирована." @@ -1401,17 +1344,17 @@ msgstr "Сетевая карта 3" msgid "Network Card #4" msgstr "Сетевая карта 4" -msgid "Mode" -msgstr "Режим" +msgid "Mode:" +msgstr "Режим:" -msgid "Interface" -msgstr "Интерфейс" +msgid "Interface:" +msgstr "Интерфейс:" -msgid "Adapter" -msgstr "Адаптер" +msgid "Adapter:" +msgstr "Адаптер:" -msgid "VDE Socket" -msgstr "VDE сокет" +msgid "VDE Socket:" +msgstr "VDE сокет:" msgid "86Box Unit Tester" msgstr "Модульный Тестер 86Box" @@ -1431,32 +1374,29 @@ msgstr "Сквозной последовательный порт COM3" msgid "Serial port passthrough 4" msgstr "Сквозной последовательный порт COM4" -msgid "Vision Systems LBA Enhancer" -msgstr "Vision Systems LBA Enhancer" - msgid "Renderer options..." msgstr "Параметры рендеринга..." msgid "Logitech/Microsoft Bus Mouse" -msgstr "Шинная мышь Logitech/Microsoft" +msgstr "Bus-мышь Logitech/Microsoft" msgid "Microsoft Bus Mouse (InPort)" -msgstr "Шинная мышь Microsoft (InPort)" +msgstr "Bus-мышь Microsoft (InPort)" msgid "Mouse Systems Serial Mouse" -msgstr "Последовательная мышь Mouse Systems" +msgstr "COM-мышь Mouse Systems" msgid "Microsoft Serial Mouse" -msgstr "Последовательная мышь Microsoft" +msgstr "COM-мышь Microsoft" msgid "Logitech Serial Mouse" -msgstr "Последовательная мышь Logitech" +msgstr "COM-мышь Logitech" msgid "PS/2 Mouse" msgstr "Мышь PS/2" msgid "3M MicroTouch (Serial)" -msgstr "3M MicroTouch (последовательная)" +msgstr "3M MicroTouch (последовательный)" msgid "[COM] Standard Hayes-compliant Modem" msgstr "[COM] Стандартный Hayes-совместимый модем" @@ -1482,12 +1422,54 @@ msgstr "Системный MIDI" msgid "MIDI Input Device" msgstr "Устройство ввода MIDI" +msgid "BIOS file" +msgstr "Файл BIOS" + +msgid "BIOS file (ROM #1)" +msgstr "Файл BIOS (ПЗУ #1)" + +msgid "BIOS file (ROM #2)" +msgstr "Файл BIOS (ПЗУ #2)" + +msgid "BIOS file (ROM #3)" +msgstr "Файл BIOS (ПЗУ #3)" + +msgid "BIOS file (ROM #4)" +msgstr "Файл BIOS (ПЗУ #4)" + msgid "BIOS Address" msgstr "Адрес BIOS" +msgid "BIOS address (ROM #1)" +msgstr "Адрес BIOS (ПЗУ #1)" + +msgid "BIOS address (ROM #2)" +msgstr "Адрес BIOS (ПЗУ #2)" + +msgid "BIOS address (ROM #3)" +msgstr "Адрес BIOS (ПЗУ #3)" + +msgid "BIOS address (ROM #4)" +msgstr "Адрес BIOS (ПЗУ #4)" + msgid "Enable BIOS extension ROM Writes" msgstr "Разрешить запись в ПЗУ расширения BIOS" +msgid "Enable BIOS extension ROM Writes (ROM #1)" +msgstr "Разрешить запись в ПЗУ расширения BIOS (ПЗУ #1)" + +msgid "Enable BIOS extension ROM Writes (ROM #2)" +msgstr "Разрешить запись в ПЗУ расширения BIOS (ПЗУ #2)" + +msgid "Enable BIOS extension ROM Writes (ROM #3)" +msgstr "Разрешить запись в ПЗУ расширения BIOS (ПЗУ #3)" + +msgid "Enable BIOS extension ROM Writes (ROM #4)" +msgstr "Разрешить запись в ПЗУ расширения BIOS (ПЗУ #4)" + +msgid "Linear framebuffer base" +msgstr "Линейная база кадрового буфера" + msgid "Address" msgstr "Адрес" @@ -1497,8 +1479,23 @@ msgstr "IRQ" msgid "BIOS Revision" msgstr "Версия BIOS" +msgid "BIOS Version" +msgstr "Версия BIOS" + +msgid "BIOS Versions" +msgstr "Версии BIOS" + +msgid "BIOS Language" +msgstr "Язык BIOS" + +msgid "IBM 5161 Expansion Unit" +msgstr "Блок расширения IBM 5161" + +msgid "IBM Cassette Basic" +msgstr "Кассетный бейсик IBM" + msgid "Translate 26 -> 17" -msgstr "Перевести 26 -> 17" +msgstr "Переводить 26 -> 17" msgid "Language" msgstr "Язык" @@ -1512,6 +1509,18 @@ msgstr "Инвертировать цвета" msgid "BIOS size" msgstr "Размер BIOS" +msgid "BIOS size (ROM #1)" +msgstr "Размер BIOS (ПЗУ #1)" + +msgid "BIOS size (ROM #2)" +msgstr "Размер BIOS (ПЗУ #2)" + +msgid "BIOS size (ROM #3)" +msgstr "Размер BIOS (ПЗУ #3)" + +msgid "BIOS size (ROM #4)" +msgstr "Размер BIOS (ПЗУ #4)" + msgid "Map C0000-C7FFF as UMB" msgstr "Отображение C0000-C7FFF в качестве UMB" @@ -1587,6 +1596,9 @@ msgstr "Уровень реверберации" msgid "Interpolation Method" msgstr "Метод интерполяции" +msgid "Dynamic Sample Loading" +msgstr "Динамическая загрузка сэмплов" + msgid "Reverb Output Gain" msgstr "Усиление выходного сигнала ревербератора" @@ -1594,7 +1606,7 @@ msgid "Reversed stereo" msgstr "Реверс стерео" msgid "Nice ramp" -msgstr "Nice ramp" +msgstr "Улучшение рампы" msgid "Hz" msgstr "Гц" @@ -1645,7 +1657,7 @@ msgid "RAM Address" msgstr "Адрес оперативной памяти" msgid "RAM size" -msgstr "Объем оперативной памяти" +msgstr "Размер оперативной памяти" msgid "Initial RAM size" msgstr "Начальный размер оперативной памяти" @@ -1675,17 +1687,20 @@ msgid "Enable Game port" msgstr "Включить игровой порт" msgid "Surround module" -msgstr "Модуль объемного звучания" +msgstr "Модуль объёмного звучания" msgid "CODEC" -msgstr "КОДЕК" +msgstr "Кодек" msgid "Raise CODEC interrupt on CODEC setup (needed by some drivers)" -msgstr "Поднимать прерывание CODEC при настройке CODEC (необходимо некоторым драйверам)." +msgstr "Поднимать прерывание кодека при настройке кодека (необходимо некоторым драйверам)" msgid "SB Address" msgstr "Адрес SB" +msgid "Use EEPROM setting" +msgstr "Использовать настройку EEPROM" + msgid "WSS IRQ" msgstr "IRQ WSS" @@ -1708,7 +1723,7 @@ msgid "Enable CMS" msgstr "Включить CMS" msgid "Mixer" -msgstr "Смеситель" +msgstr "Микшер" msgid "High DMA" msgstr "Высокий DMA" @@ -1717,7 +1732,7 @@ msgid "Control PC speaker" msgstr "Управление динамиком ПК" msgid "Memory size" -msgstr "Объем памяти" +msgstr "Размер памяти" msgid "EMU8000 Address" msgstr "Адрес EMU8000" @@ -1732,7 +1747,7 @@ msgid "GUS type" msgstr "Тип GUS" msgid "Enable 0x04 \"Exit 86Box\" command" -msgstr "Включить команду 0x04 \"Выход 86Box\"." +msgstr "Включить команду 0x04 \"Выход из 86Box\"" msgid "Display type" msgstr "Тип дисплея" @@ -1770,17 +1785,20 @@ msgstr "Тип RAMDAC" msgid "Blend" msgstr "Смесь" +msgid "Font" +msgstr "Шрифт" + msgid "Bilinear filtering" msgstr "Билинейная фильтрация" msgid "Dithering" -msgstr "Dithering" +msgstr "Дизеринг" msgid "Enable NMI for CGA emulation" -msgstr "Включение NMI для эмуляции CGA" +msgstr "Включить NMI для эмуляции CGA" msgid "Voodoo type" -msgstr "Тип Вуду" +msgstr "Тип Voodoo" msgid "Framebuffer memory size" msgstr "Размер памяти фреймбуфера" @@ -1789,10 +1807,10 @@ msgid "Texture memory size" msgstr "Размер памяти текстур" msgid "Dither subtraction" -msgstr "Вычитание с вычитанием" +msgstr "Вычитание дизеринга" msgid "Screen Filter" -msgstr "Фильтр экрана" +msgstr "Экранный фильтр" msgid "Render threads" msgstr "Потоки рендеринга" @@ -1815,6 +1833,33 @@ msgstr "Скорость передачи данных" msgid "EMS mode" msgstr "Режим EMS" +msgid "EMS Address" +msgstr "Адрес EMS" + +msgid "EMS 1 Address" +msgstr "Адрес EMS 1" + +msgid "EMS 2 Address" +msgstr "Адрес EMS 2" + +msgid "EMS Memory Size" +msgstr "Размер памяти EMS" + +msgid "EMS 1 Memory Size" +msgstr "Размер памяти EMS 1" + +msgid "EMS 2 Memory Size" +msgstr "Размер памяти EMS 2" + +msgid "Enable EMS" +msgstr "Включить EMS" + +msgid "Enable EMS 1" +msgstr "Включить EMS 1" + +msgid "Enable EMS 2" +msgstr "Включить EMS 2" + msgid "Address for > 2 MB" msgstr "Адрес для > 2 МБ" @@ -1834,10 +1879,10 @@ msgid "BIOS setting + Hotkeys (off during POST)" msgstr "Настройка BIOS + горячие клавиши (отключается во время POST)" msgid "64 kB starting from F0000" -msgstr "64 кБ, начиная с F0000" +msgstr "64 КБ, начиная с F0000" msgid "128 kB starting from E0000 (address MSB inverted, last 64KB first)" -msgstr "128 кБ, начиная с E0000 (адрес MSB инвертирован, сначала последние 64 КБ)" +msgstr "128 КБ, начиная с E0000 (адрес MSB инвертирован, сначала последние 64 КБ)" msgid "Sine" msgstr "Синусоидальная" @@ -1861,7 +1906,7 @@ msgid "45 Hz (JMP2 not populated)" msgstr "45 Гц (без джампера на JMP2)" msgid "Two" -msgstr "Два" +msgstr "Две" msgid "Three" msgstr "Три" @@ -1872,6 +1917,9 @@ msgstr "Колесо" msgid "Five + Wheel" msgstr "Пять + колесо" +msgid "Five + 2 Wheels" +msgstr "Пять + 2 колеса" + msgid "A3 - SMT2 Serial / SMT3(R)V" msgstr "A3 - SMT2 последовательная / SMT3(R)V" @@ -1945,7 +1993,7 @@ msgid "Color (generic)" msgstr "Цветной (стандартный)" msgid "Green Monochrome" -msgstr "Зеленый монохромный" +msgstr "Зелёный монохромный" msgid "Amber Monochrome" msgstr "Янтарный монохромный" @@ -1975,7 +2023,7 @@ msgid "Monochrome (5151/MDA) (white)" msgstr "Монохромный (5151/MDA) (белый)" msgid "Monochrome (5151/MDA) (green)" -msgstr "Монохромный (5151/MDA) (зеленый)" +msgstr "Монохромный (5151/MDA) (зелёный)" msgid "Monochrome (5151/MDA) (amber)" msgstr "Монохромный (5151/MDA) (янтарный)" @@ -1993,7 +2041,7 @@ msgid "Enhanced Color - Enhanced Mode (5154/ECD)" msgstr "Улучшенный цветной - улучшенный режим (5154/ECD)" msgid "Green" -msgstr "Зеленый" +msgstr "Зелёный" msgid "Amber" msgstr "Янтарный" @@ -2001,6 +2049,9 @@ msgstr "Янтарный" msgid "Gray" msgstr "Серый" +msgid "Grayscale" +msgstr "Монохромный" + msgid "Color" msgstr "Цветной" @@ -2016,14 +2067,20 @@ msgstr "Другие языки" msgid "Bochs latest" msgstr "Bochs последний" +msgid "Apply overscan deltas" +msgstr "Применить дельты вылетов развёртки" + +msgid "Mono Interlaced" +msgstr "Монохромный с чересстрочной развёрткой" + msgid "Mono Non-Interlaced" -msgstr "Монохромный без чересстрочной развертки" +msgstr "Монохромный без чересстрочной развёртки" msgid "Color Interlaced" -msgstr "Цветной с чересстрочной разверткой" +msgstr "Цветной с чересстрочной развёрткой" msgid "Color Non-Interlaced" -msgstr "Цветной без чересстрочной развертки" +msgstr "Цветной без чересстрочной развёртки" msgid "3Dfx Voodoo Graphics" msgstr "Ускоритель 3Dfx Voodoo" @@ -2074,10 +2131,10 @@ msgid "Protection Dongle for Savage Quest" msgstr "Защитный донгл для Savage Quest" msgid "Serial Passthrough Device" -msgstr "Устройство прохода через последовательный порт" +msgstr "Устройство проброса через последовательный порт" msgid "Passthrough Mode" -msgstr "Проходной режим" +msgstr "Режим проброса" msgid "Host Serial Device" msgstr "Последовательное устройство хоста" @@ -2100,8 +2157,8 @@ msgstr "Именованный пайп (Сервер)" msgid "Host Serial Passthrough" msgstr "Последовательный порт хоста" -msgid "Eject %s" -msgstr "Извлечь %s" +msgid "E&ject %1" +msgstr "И&звлечь %1" msgid "&Unmute" msgstr "В&ключить звук" @@ -2112,8 +2169,29 @@ msgstr "Softfloat FPU" msgid "High performance impact" msgstr "Сильное влияние на производительность" -msgid "RAM Disk (max. speed)" -msgstr "RAM-диск (макс. скорость)" +msgid "[Generic] RAM Disk (max. speed)" +msgstr "[Стандартный] RAM-диск (макс. скорость)" + +msgid "[Generic] 1989 (3500 RPM)" +msgstr "[Стандартный] 1989 (3500 RPM)" + +msgid "[Generic] 1992 (3600 RPM)" +msgstr "[Стандартный] 1992 (3600 RPM)" + +msgid "[Generic] 1994 (4500 RPM)" +msgstr "[Стандартный] 1994 (4500 RPM)" + +msgid "[Generic] 1996 (5400 RPM)" +msgstr "[Стандартный] 1996 (5400 RPM)" + +msgid "[Generic] 1997 (5400 RPM)" +msgstr "[Стандартный] 1997 (5400 RPM)" + +msgid "[Generic] 1998 (5400 RPM)" +msgstr "[Стандартный] 1998 (5400 RPM)" + +msgid "[Generic] 2000 (7200 RPM)" +msgstr "[Стандартный] 2000 (7200 RPM)" msgid "IBM 8514/A clone (ISA)" msgstr "Клон IBM 8514/A (ISA)" @@ -2132,3 +2210,120 @@ msgstr "Стандартное расширение памяти PC/XT" msgid "Generic PC/AT Memory Expansion" msgstr "Стандартное расширение памяти PC/AT" + +msgid "Unable to find Dot-Matrix fonts" +msgstr "Невозможно найти матричные шрифты" + +msgid "TrueType fonts in the \"roms/printer/fonts\" directory are required for the emulation of the Generic ESC/P Dot-Matrix Printer." +msgstr "Шрифты TrueType в каталоге \"roms/printer/fonts\" необходимы для эмуляции стандартного матричного принтера ESC/P." + +msgid "Inhibit multimedia keys" +msgstr "Перехватывать мультимедийные клавиши" + +msgid "Ask for confirmation before saving settings" +msgstr "Запрашивать подтверждение перед сохранением настроек" + +msgid "Ask for confirmation before hard resetting" +msgstr "Запрашивать подтверждение перед холодной перезагрузкой" + +msgid "Ask for confirmation before quitting" +msgstr "Запрашивать подтверждение перед выходом" + +msgid "Options" +msgstr "Параметры" + +msgid "Model" +msgstr "Модель" + +msgid "Model:" +msgstr "Модель:" + +msgid "Failed to initialize Vulkan renderer." +msgstr "Не удалось инициализировать рендерер Vulkan." + +msgid "GLSL Error" +msgstr "Ошибка GLSL" + +msgid "Could not load shader: %1" +msgstr "Не удалось загрузить шейдер: %1" + +msgid "OpenGL version 3.0 or greater is required. Current GLSL version is %1.%2" +msgstr "Требуется OpenGL версии 3.0 или выше. Текущая версия GLSL %1.%2" + +msgid "Could not load texture: %1" +msgstr "Не удалось загрузить текстуру: %1" + +msgid "Could not compile shader:\n\n%1" +msgstr "Не удалось скомпилировать шейдер:\n\n%1" + +msgid "Program not linked:\n\n%1" +msgstr "Не удалось скомпоновать шейдер:\n\n%1" + +msgid "Shader Manager" +msgstr "Управление шейдерами" + +msgid "Shader Configuration" +msgstr "Конфигурация шейдера" + +msgid "Add" +msgstr "Добавить" + +msgid "Move up" +msgstr "Вверх" + +msgid "Move down" +msgstr "Вниз" + +msgid "Could not load file %1" +msgstr "Не удалось загрузить файл %1" + +msgid "Key Bindings:" +msgstr "Привязки клавиш:" + +msgid "Action" +msgstr "Действие" + +msgid "Keybind" +msgstr "Привязка клавиш" + +msgid "Clear binding" +msgstr "Очистить привязку" + +msgid "Bind" +msgstr "Привязка" + +msgid "Bind Key" +msgstr "Привязать клавишу" + +msgid "Enter key combo:" +msgstr "Введите комбинацию клавиш:" + +msgid "Send Control+Alt+Del" +msgstr "Отправить Control+Alt+Del" + +msgid "Send Control+Alt+Escape" +msgstr "Отправить Control+Alt+Escape" + +msgid "Toggle fullscreen" +msgstr "Переключить полноэкранный режим" + +msgid "Screenshot" +msgstr "Скриншот" + +msgid "Release mouse pointer" +msgstr "Отпустить указатель мыши" + +msgid "Toggle pause" +msgstr "Переключить паузу" + +msgid "Toggle mute" +msgstr "Переключить беззвучный режим" + +msgid "Text files" +msgstr "Текстовые файлы" + +msgid "ROM files" +msgstr "Файлы ПЗУ" + +msgid "SoundFont files" +msgstr "Файлы SoundFont" diff --git a/src/qt/languages/sk-SK.po b/src/qt/languages/sk-SK.po index 708c24dd8..ef89f831a 100644 --- a/src/qt/languages/sk-SK.po +++ b/src/qt/languages/sk-SK.po @@ -18,8 +18,8 @@ msgstr "&Pravý Ctrl je ľavý Alt" msgid "&Hard Reset..." msgstr "&Resetovať" -msgid "&Ctrl+Alt+Del\tCtrl+F12" -msgstr "&Ctrl+Alt+Del\tCtrl+F12" +msgid "&Ctrl+Alt+Del" +msgstr "&Ctrl+Alt+Del" msgid "Ctrl+Alt+&Esc" msgstr "Ctrl+Alt+&Esc" @@ -111,8 +111,8 @@ msgstr "&Lineárny" msgid "Hi&DPI scaling" msgstr "Š&kálovanie HiDPI" -msgid "&Fullscreen\tCtrl+Alt+PgUp" -msgstr "&Celá obrazovka\tCtrl+Alt+PgUp" +msgid "&Fullscreen" +msgstr "&Celá obrazovka" msgid "Fullscreen &stretch mode" msgstr "Režim roztia&hnutia na celú obrazovku" @@ -186,8 +186,11 @@ msgstr "&Nastavenia..." msgid "&Update status bar icons" msgstr "&Aktualizovať ikony na stavovom riadku" -msgid "Take s&creenshot\tCtrl+F11" -msgstr "Urobiť snímku &obrazovky\tCtrl+F11" +msgid "Take s&creenshot" +msgstr "Urobiť snímku &obrazovky" + +msgid "S&ound" +msgstr "&Zvuk" msgid "&Preferences..." msgstr "&Predvoľby..." @@ -198,11 +201,11 @@ msgstr "Povolenie integrácie s &Discordem" msgid "Sound &gain..." msgstr "&Zosilnenie zvuku" -msgid "Begin trace\tCtrl+T" -msgstr "Začať trace\tCtrl+T" +msgid "Begin trace" +msgstr "Začať trace" -msgid "End trace\tCtrl+T" -msgstr "Zastaviť trace\tCtrl+T" +msgid "End trace" +msgstr "Zastaviť trace" msgid "&Help" msgstr "&Pomoc" @@ -249,8 +252,8 @@ msgstr "&Stíšiť" msgid "E&mpty" msgstr "&Vystrihnúť" -msgid "&Reload previous image" -msgstr "&Načítať znova predchádzajúci obraz" +msgid "Reload previous image" +msgstr "Načítať znova predchádzajúci obraz" msgid "&Folder..." msgstr "&Zložka..." @@ -306,18 +309,12 @@ msgstr "OK" msgid "Cancel" msgstr "Storno" -msgid "Save these settings as &global defaults" -msgstr "Uložiť toto nastavenie ako &globálny východiskový stav" - msgid "&Default" msgstr "&Východiskové" msgid "Language:" msgstr "Jazyk:" -msgid "Icon set:" -msgstr "Súprava ikon:" - msgid "Gain" msgstr "Zosilnenie" @@ -453,15 +450,6 @@ msgstr "Nuked (presnejší)" msgid "YMFM (faster)" msgstr "YMFM (rýchlejší)" -msgid "Network type:" -msgstr "Druh siete:" - -msgid "PCap device:" -msgstr "PCap zariadenia:" - -msgid "Network adapter:" -msgstr "Sieťový adaptér:" - msgid "COM1 Device:" msgstr "Zariadenie na COM1:" @@ -642,14 +630,11 @@ msgstr "Kritická chyba" msgid " - PAUSED" msgstr " - POZASTAVENÝ" -msgid "Press Ctrl+Alt+PgDn to return to windowed mode." -msgstr "Stlačte Ctrl+Alt+PgDn pre návrat z režimu celej obrazovky." - msgid "Speed" msgstr "Rýchlosť" -msgid "ZIP %03i %i (%s): %ls" -msgstr "ZIP %03i %i (%s): %ls" +msgid "ZIP %1 %2 (%3): %4" +msgstr "ZIP %1 %2 (%3): %4" msgid "ZIP images" msgstr "Obrazy ZIP diskov" @@ -687,8 +672,11 @@ msgstr "Počítač \"%hs\" ie je dostupný, pretože chýba obraz jeho pamäte R msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "Video adaptér \"%hs\" nie je dostupný, pretože chýba obraz jeho pamäte ROM v zložke \"roms/video\". Konfigurácia sa prepne na iný dostupný adaptér." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Video adaptér 2 \"%hs\" nie je dostupný, pretože chýba obraz jeho pamäte ROM v zložke \"roms/video\". Konfigurácia sa prepne na iný dostupný adaptér." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "Video adaptér 2 \"%hs\" nie je dostupný, pretože chýba obraz jeho pamäte ROM v zložke \"roms/video\". Druhá grafická karta sa zakáže." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Zariadenie \"%hs\" nie je dostupné, pretože chýba obraz jeho pamäte ROM. Zariadenie sa ignoruje." msgid "Machine" msgstr "Počítač" @@ -750,14 +738,11 @@ msgstr "S" msgid "KB" msgstr "KB" -msgid "Could not initialize the video renderer." -msgstr "Nastala chyba pri inicializácii video renderera." - msgid "Default" msgstr "Východiskové" -msgid "%i Wait state(s)" -msgstr "%i čakací stav(y)" +msgid "%1 Wait state(s)" +msgstr "%1 čakací stav(y)" msgid "Type" msgstr "Typ" @@ -801,11 +786,11 @@ msgstr "Thrustmaster Flight Control System" msgid "None" msgstr "Žiadne" -msgid "%u MB (CHS: %i, %i, %i)" -msgstr "%u MB (CHS: %i, %i, %i)" +msgid "%1 MB (CHS: %2, %3, %4)" +msgstr "%1 MB (CHS: %2, %3, %4)" -msgid "Floppy %i (%s): %ls" -msgstr "Disketová mechanika %i (%s): %ls" +msgid "Floppy %1 (%2): %3" +msgstr "Disketová mechanika %1 (%2): %3" msgid "Advanced sector images" msgstr "Rozšírené sektorové obrazy" @@ -825,8 +810,8 @@ msgstr "Nastala chyba pri inicializácii knižnice Ghostscript" msgid "Unable to initialize GhostPCL" msgstr "Nastala chyba pri inicializácii knižnice GhostPCL" -msgid "MO %i (%ls): %ls" -msgstr "MO %i (%ls): %ls" +msgid "MO %1 (%2): %3" +msgstr "MO %1 (%2): %3" msgid "MO images" msgstr "Obrazy MO" @@ -876,9 +861,6 @@ msgstr "%1 je potrebná pre automatický prevod PostScript dokumentov do PDF.\n\ msgid "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PCL printer will be saved as Printer Command Lnaugage (.pcl) files." msgstr "%1 je potrebná pre automatický prevod PCL dokumentov do PDF.\n\nAkékoľvek dokumenty vytlačené cez všeobecnú PCLovú tlačiareň budú uložené ako Printer Command Language (.pcl) súbory." -msgid "Entering fullscreen mode" -msgstr "Vstup do režimu celej obrazovky" - msgid "Don't show this message again" msgstr "Nezobrazovať ďalej túto správu" @@ -900,11 +882,8 @@ msgstr "Konfigurácia zariadenia %1" msgid "Monitor in sleep mode" msgstr "Monitor je v režime spánku" -msgid "OpenGL Shaders" -msgstr "Shadery OpenGL" - -msgid "OpenGL options" -msgstr "Možnosti OpenGL" +msgid "GLSL shaders" +msgstr "Shadery GLSL" msgid "You are loading an unsupported configuration" msgstr "Pokúšate sa spustiť nepodporovanú konfiguráciu" @@ -915,24 +894,18 @@ msgstr "Pre túto konfiguráciu bolo vypnuté filtrovanie procesorov podľa zvol msgid "Continue" msgstr "Pokračovať" -msgid "Cassette: %s" -msgstr "Kazeta: %s" +msgid "Cassette: %1" +msgstr "Kazeta: %1" msgid "Cassette images" msgstr "Kazetové nahrávky" -msgid "Cartridge %i: %ls" -msgstr "Cartridge %i: %ls" +msgid "Cartridge %1: %2" +msgstr "Cartridge %1: %2" msgid "Cartridge images" msgstr "Obrazy cartridge" -msgid "Error initializing renderer" -msgstr "Chyba pri inicializácii vykresľovača" - -msgid "OpenGL (3.0 Core) renderer could not be initialized. Use another renderer." -msgstr "Vykresľovač OpenGL (3.0 Core) sa nepodarilo inicializovať. Použite iný renderer." - msgid "Resume execution" msgstr "Obnoviť" @@ -1095,8 +1068,8 @@ msgstr "IDE" msgid "ATAPI" msgstr "ATAPI" -msgid "CD-ROM %i (%s): %s" -msgstr "CD-ROM %i (%s): %s" +msgid "CD-ROM %1 (%2): %3" +msgstr "CD-ROM %1 (%2): %3" msgid "160 KB" msgstr "160 KB" @@ -1267,7 +1240,7 @@ msgid "Host CD/DVD Drive (%1:)" msgstr "Hostiteľská jednotka CD/DVD (%1:)" msgid "&Connected" -msgstr "&Connected" +msgstr "" msgid "Clear image history" msgstr "Vymazanie histórie obrázkov" @@ -1275,9 +1248,6 @@ msgstr "Vymazanie histórie obrázkov" msgid "Create..." msgstr "Vytvorte..." -msgid "previous image" -msgstr "predchádzajúca snímka" - msgid "Host CD/DVD Drive (%1)" msgstr "Hostiteľská jednotka CD/DVD (%1)" @@ -1287,23 +1257,9 @@ msgstr "Neznáma zbernica" msgid "Null Driver" msgstr "Nulový ovládač" -msgid "NIC %02i (%ls) %ls" -msgstr "NIC %02i (%ls) %ls" +msgid "NIC %1 (%2) %3" +msgstr "NIC %1 (%2) %3" -msgid "Error opening \"%1\": %2" -msgstr "Chyba pri otváraní \"%1\": %2" - -msgid "Error compiling vertex shader in file \"%1\"" -msgstr "Chyba kompilácie vertex shadera v súbore \"%1\"" - -msgid "Error compiling fragment shader in file \"%1\"" -msgstr "Chyba kompilácie fragment shadera v súbore \"%1\"" - -msgid "Error linking shader program in file \"%1\"" -msgstr "Chyba pri prepojení shader programu v súbore \"%1\"" - -msgid "OpenGL 3.0 renderer options" -msgstr "Možnosti vykresľovania OpenGL 3.0" msgid "Render behavior" msgstr "Správanie pri vykresľovaní" @@ -1317,9 +1273,6 @@ msgstr " fps" msgid "VSync" msgstr "VSync" -msgid "<html><head/><body><p>Render each frame immediately, in sync with the emulated display.</p><p><span style=" font-style:italic;">This is the recommended option if the shaders in use don't utilize frametime for animated effects.</span></p></body></html>" -msgstr "<html><head/><body><p>Okamžite vykresliť každú snímku v synchronizácii s emulovaným displejom.</p><p><span style=" font-style:italic;">Toto je odporúčaná možnosť, ak používané shadery nevyužívajú frametime pre animované efekty.</span></p></body></html>" - msgid "Synchronize with video" msgstr "Synchronizovať s obrazom" @@ -1329,21 +1282,9 @@ msgstr "Shadery" msgid "Remove" msgstr "Odstránenie stránky" -msgid "No shader selected" -msgstr "Nie je vybraný žiadny tieňovač" - msgid "Browse..." msgstr "Prehľadávať..." -msgid "Shader error" -msgstr "Chyba shadera" - -msgid "Could not load shaders." -msgstr "Nepodarilo sa načítať shadery." - -msgid "More information in details." -msgstr "Viac informácií v detailoch." - msgid "Couldn't create OpenGL context." msgstr "Nepodarilo sa vytvoriť kontext OpenGL." @@ -1353,20 +1294,14 @@ msgstr "Nepodarilo sa prepnúť na kontext OpenGL." msgid "OpenGL version 3.0 or greater is required. Current version is %1.%2" msgstr "Vyžaduje sa verzia OpenGL 3.0 alebo vyššia. Aktuálna verzia je %1.%2" -msgid "OpenGL initialization failed. Error %1." -msgstr "Inicializácia OpenGL zlyhala. Chyba %1." - msgid "Error initializing OpenGL" msgstr "Chyba pri inicializácii OpenGL" -msgid "Falling back to software rendering.\n" -msgstr "Návrat k softvérovému vykresľovaniu.\n" +msgid "\nFalling back to software rendering." +msgstr "\nNávrat k softvérovému vykresľovaniu." -msgid "Allocating memory for unpack buffer failed.\n" -msgstr "Alokácia pamäte pre rozbaľovaciu vyrovnávaciu pamäť zlyhala.\n" - -msgid "<html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html>" -msgstr "<html><head/><body><p>Pri výbere multimediálnych obrazov (CD-ROM, disketa atď.) sa dialógové okno otvorenia spustí v rovnakom adresári ako konfiguračný súbor 86Box. Toto nastavenie bude mať pravdepodobne význam len v systéme MacOS.</p></body></html>" +msgid "

When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" +msgstr "

Pri výbere multimediálnych obrazov (CD-ROM, disketa atď.) sa dialógové okno otvorenia spustí v rovnakom adresári ako konfiguračný súbor 86Box. Toto nastavenie bude mať pravdepodobne význam len v systéme MacOS.

" msgid "This machine might have been moved or copied." msgstr "Tento stroj mohol byť premiestnený alebo skopírovaný." @@ -1401,17 +1336,17 @@ msgstr "Sieťová karta 3" msgid "Network Card #4" msgstr "Sieťová karta 4" -msgid "Mode" -msgstr "Režim" +msgid "Mode:" +msgstr "Režim:" -msgid "Interface" -msgstr "Rozhranie" +msgid "Interface:" +msgstr "Rozhranie:" -msgid "Adapter" -msgstr "Adaptér" +msgid "Adapter:" +msgstr "Adaptér:" -msgid "VDE Socket" -msgstr "Zásuvka VDE" +msgid "VDE Socket:" +msgstr "Zásuvka VDE:" msgid "86Box Unit Tester" msgstr "86Box Unit Tester" @@ -1431,9 +1366,6 @@ msgstr "Priechod sériového portu 3" msgid "Serial port passthrough 4" msgstr "Priechod cez sériový port 4" -msgid "Vision Systems LBA Enhancer" -msgstr "Vision Systems LBA Enhancer" - msgid "Renderer options..." msgstr "Možnosti vykresľovača..." @@ -1872,6 +1804,9 @@ msgstr "Koleso" msgid "Five + Wheel" msgstr "Päť + koleso" +msgid "Five + 2 Wheels" +msgstr "" + msgid "A3 - SMT2 Serial / SMT3(R)V" msgstr "A3 - SMT2 sériová / SMT3(R)V" @@ -2100,8 +2035,8 @@ msgstr "Pomenované potrubie (server)" msgid "Host Serial Passthrough" msgstr "Priechod sériového portu hostiteľa" -msgid "Eject %s" -msgstr "Vystrihnúť %s" +msgid "E&ject %1" +msgstr "&Vystrihnúť %1" msgid "&Unmute" msgstr "&Roztíšiť" @@ -2112,11 +2047,104 @@ msgstr "Softfloat FPU" msgid "High performance impact" msgstr "Vysoký vplyv na výkon" -msgid "RAM Disk (max. speed)" -msgstr "Disk RAM (max. rýchlosť)" +msgid "[Generic] RAM Disk (max. speed)" +msgstr "[Generic] Disk RAM (max. rýchlosť)" + +msgid "[Generic] 1989 (3500 RPM)" +msgstr "" + +msgid "[Generic] 1992 (3600 RPM)" +msgstr "" + +msgid "[Generic] 1994 (4500 RPM)" +msgstr "" + +msgid "[Generic] 1996 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1997 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1998 (5400 RPM)" +msgstr "" + +msgid "[Generic] 2000 (7200 RPM)" +msgstr "" msgid "IBM 8514/A clone (ISA)" msgstr "Klon IBM 8514/A (ISA)" msgid "Vendor" msgstr "Výrobca" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Všeobecné rozšírenie pamäte PC/XT" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Všeobecné rozšírenie pamäte PC/AT" + +msgid "Unable to find Dot-Matrix fonts" +msgstr "Nastala chyba pri hľadaní ihličkových písem" + +msgid "TrueType fonts in the \"roms/printer/fonts\" directory are required for the emulation of the Generic ESC/P Dot-Matrix Printer." +msgstr "Písma TrueType v adresári \"roms/printer/fonts\" sú potrebné na emuláciu generickej ihličkovej tlačiarne ESC/P." + +msgid "Inhibit multimedia keys" +msgstr "" + +msgid "Ask for confirmation before saving settings" +msgstr "" + +msgid "Ask for confirmation before hard resetting" +msgstr "" + +msgid "Ask for confirmation before quitting" +msgstr "" + +msgid "Options" +msgstr "" + +msgid "Model" +msgstr "" + +msgid "Model:" +msgstr "" + +msgid "Failed to initialize Vulkan renderer." +msgstr "" + +msgid "GLSL Error" +msgstr "" + +msgid "Could not load shader: %1" +msgstr "" + +msgid "OpenGL version 3.0 or greater is required. Current GLSL version is %1.%2" +msgstr "" + +msgid "Could not load texture: %1" +msgstr "" + +msgid "Could not compile shader:\n\n%1" +msgstr "" + +msgid "Program not linked:\n\n%1" +msgstr "" + +msgid "Shader Manager" +msgstr "" + +msgid "Shader Configuration" +msgstr "" + +msgid "Add" +msgstr "" + +msgid "Move up" +msgstr "" + +msgid "Move down" +msgstr "" + +msgid "Could not load file %1" +msgstr "" diff --git a/src/qt/languages/sl-SI.po b/src/qt/languages/sl-SI.po index c9c99d6b2..d4fd10e43 100644 --- a/src/qt/languages/sl-SI.po +++ b/src/qt/languages/sl-SI.po @@ -18,8 +18,8 @@ msgstr "&Desni CTRL je levi ALT" msgid "&Hard Reset..." msgstr "&Ponovni zagon..." -msgid "&Ctrl+Alt+Del\tCtrl+F12" -msgstr "&Ctrl+Alt+Del\tCtrl+F12" +msgid "&Ctrl+Alt+Del" +msgstr "&Ctrl+Alt+Del" msgid "Ctrl+Alt+&Esc" msgstr "Ctrl+Alt+&Esc" @@ -37,7 +37,7 @@ msgid "&Hide status bar" msgstr "&Skrij statusno vrstico" msgid "Hide &toolbar" -msgstr "Hide &toolbar" +msgstr "Skrij &orodno vrstico" msgid "&Resizeable window" msgstr "S&premenljiva velikost okna" @@ -55,7 +55,7 @@ msgid "Qt (&OpenGL)" msgstr "Qt (&OpenGL)" msgid "Open&GL (3.0 Core)" -msgstr "Open&GL (Jedro 3.0)" +msgstr "Open&GL (jedro 3.0)" msgid "&VNC" msgstr "&VNC" @@ -64,10 +64,10 @@ msgid "Specify dimensions..." msgstr "&Določi velikost..." msgid "F&orce 4:3 display ratio" -msgstr "&Vsili 4:3 razmerje zaslona" +msgstr "&Vsili razmerje zaslona 4:3" msgid "&Window scale factor" -msgstr "&Faktor velikosti okna" +msgstr "&Faktor povečave okna" msgid "&0.5x" msgstr "&0.5x" @@ -100,7 +100,7 @@ msgid "&8x" msgstr "&8x" msgid "Filter method" -msgstr "&Metoda filtriranja" +msgstr "&Vrsta filtriranja" msgid "&Nearest" msgstr "&Najbližja" @@ -111,8 +111,8 @@ msgstr "&Linearna" msgid "Hi&DPI scaling" msgstr "&Raztezanje za visok DPI" -msgid "&Fullscreen\tCtrl+Alt+PgUp" -msgstr "&Celozaslonski način\tCtrl+Alt+PgUp" +msgid "&Fullscreen" +msgstr "&Celozaslonski način" msgid "Fullscreen &stretch mode" msgstr "&Način celozaslonskega raztezanja" @@ -186,8 +186,11 @@ msgstr "&Nastavitve..." msgid "&Update status bar icons" msgstr "&Posodabljaj ikone statusne vrstice" -msgid "Take s&creenshot\tCtrl+F11" -msgstr "&Zajemi posnetek zaslona\tCtrl+F11" +msgid "Take s&creenshot" +msgstr "&Zajemi posnetek zaslona" + +msgid "S&ound" +msgstr "Z&vok" msgid "&Preferences..." msgstr "&Možnosti..." @@ -198,11 +201,11 @@ msgstr "Omogoči integracijo s programom &Discord" msgid "Sound &gain..." msgstr "&Ojačanje zvoka..." -msgid "Begin trace\tCtrl+T" -msgstr "Z&ačni sledenje\tCtrl+T" +msgid "Begin trace" +msgstr "Z&ačni sledenje" -msgid "End trace\tCtrl+T" -msgstr "&Končaj sledenje\tCtrl+T" +msgid "End trace" +msgstr "&Končaj sledenje" msgid "&Help" msgstr "&Pomoč" @@ -238,7 +241,7 @@ msgid "E&ject" msgstr "I&zvrzi" msgid "&Image..." -msgstr "Slika..." +msgstr "S&lika..." msgid "E&xport to 86F..." msgstr "&Izvozi v 86F..." @@ -249,8 +252,8 @@ msgstr "&Utišaj" msgid "E&mpty" msgstr "&Prazen" -msgid "&Reload previous image" -msgstr "&Naloži zadnjo sliko" +msgid "Reload previous image" +msgstr "Naloži zadnjo sliko" msgid "&Folder..." msgstr "&Mapa..." @@ -306,18 +309,12 @@ msgstr "V redu" msgid "Cancel" msgstr "Prekliči" -msgid "Save these settings as &global defaults" -msgstr "Shrani te nastavitve kot globalne privzete" - msgid "&Default" msgstr "Privzeto" msgid "Language:" msgstr "Jezik:" -msgid "Icon set:" -msgstr "Komplet ikon:" - msgid "Gain" msgstr "Ojačanje" @@ -358,7 +355,7 @@ msgid "Speed:" msgstr "Hitrost:" msgid "Frequency:" -msgstr "Pogostost:" +msgstr "Takt:" msgid "FPU:" msgstr "Procesor plavajoče vejice:" @@ -370,7 +367,7 @@ msgid "MB" msgstr "MB" msgid "Memory:" -msgstr "Spomin:" +msgstr "Pomnilnik:" msgid "Time synchronization" msgstr "Sinhronizacija časa" @@ -448,20 +445,11 @@ msgid "FM synth driver" msgstr "Gonilnik sintetizacije FM" msgid "Nuked (more accurate)" -msgstr "Nuked (točnejši)" +msgstr "Nuked (natančnejši)" msgid "YMFM (faster)" msgstr "YMFM (hitrejši)" -msgid "Network type:" -msgstr "Vrsta omrežja:" - -msgid "PCap device:" -msgstr "Naprava PCap:" - -msgid "Network adapter:" -msgstr "Omrežna kartica:" - msgid "COM1 Device:" msgstr "Naprava COM1:" @@ -499,22 +487,22 @@ msgid "Serial port 4" msgstr "Serijska vrata 4" msgid "Parallel port 1" -msgstr "Paralelna vrata 1" +msgstr "Vzporedna vrata 1" msgid "Parallel port 2" -msgstr "Paralelna vrata 2" +msgstr "Vzporedna vrata 2" msgid "Parallel port 3" -msgstr "Paralelna vrata 3" +msgstr "Vzporedna vrata 3" msgid "Parallel port 4" -msgstr "Paralelna vrata 4" +msgstr "Vzporedna vrata 4" msgid "HD Controller:" msgstr "Krmilnik trdega diska:" msgid "FD Controller:" -msgstr "Krmilnik disketnika:" +msgstr "Disketni krmilnik:" msgid "Tertiary IDE Controller" msgstr "Terciarni krmilnik IDE" @@ -562,7 +550,7 @@ msgid "ID:" msgstr "ID:" msgid "&Specify..." -msgstr "Določi..." +msgstr "&Določi..." msgid "Sectors:" msgstr "Sektorji:" @@ -607,7 +595,7 @@ msgid "ZIP 250" msgstr "ZIP 250" msgid "ISA RTC:" -msgstr "Ura v realnem času ISA:" +msgstr "Ura realnega časa ISA:" msgid "ISA Memory Expansion" msgstr "Razširitev pomnilnika ISA" @@ -642,20 +630,17 @@ msgstr "Kritična napaka" msgid " - PAUSED" msgstr " - ZAUSTAVLJEN" -msgid "Press Ctrl+Alt+PgDn to return to windowed mode." -msgstr "Pritisnite Ctrl+Alt+PgDn za povratek iz celozaslonskega načina." - msgid "Speed" msgstr "Hitrost" -msgid "ZIP %03i %i (%s): %ls" -msgstr "ZIP %03i %i (%s): %ls" +msgid "ZIP %1 %2 (%3): %4" +msgstr "ZIP %1 %2 (%3): %4" msgid "ZIP images" msgstr "ZIP slike" msgid "86Box could not find any usable ROM images.\n\nPlease download a ROM set and extract it into the \"roms\" directory." -msgstr "86Box ni našel nobenih uporabnih ROM slik.\n\nProsim prenesite set ROM-ov in ga razširite v mapo \"roms\"." +msgstr "86Box ni našel nobenih uporabnih ROM slik.\n\nProsim prenesite komplet ROM-ov in ga razširite v mapo \"roms\"." msgid "(empty)" msgstr "(prazno)" @@ -685,10 +670,13 @@ msgid "Machine \"%hs\" is not available due to missing ROMs in the roms/machines msgstr "Sistem \"%hs\" ni na voljo zaradi manjkajočih ROM-ov v mapi roms/machines. Preklapljam na drug sistem, ki je na voljo." msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "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.." +msgstr "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." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Grafična kartica 2 \"%hs\" ni na voljo zaradi manjkajočih ROM-ov v mapi roms/video. Preklapljam na drugo grafično kartico, ki je na voljo.." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "Grafična kartica 2 \"%hs\" ni na voljo zaradi manjkajočih ROM-ov v mapi roms/video. Onemogočam drugo grafično kartico." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Naprava \"%hs\" ni na voljo zaradi manjkajočih ROM-ov. Preziram napravo." msgid "Machine" msgstr "Sistem" @@ -750,20 +738,17 @@ msgstr "S" msgid "KB" msgstr "KB" -msgid "Could not initialize the video renderer." -msgstr "Ne morem inicializirati sistema za upodabljanje." - msgid "Default" msgstr "Privzeto" -msgid "%i Wait state(s)" -msgstr "%i stanj čakanja" +msgid "%1 Wait state(s)" +msgstr "%1 stanj čakanja" msgid "Type" msgstr "Vrsta" msgid "No PCap devices found" -msgstr "Nobena naprava PCap ni bila najdena" +msgstr "Najdena ni bila nobena naprava PCap" msgid "Invalid PCap device" msgstr "Neveljavna naprava PCap" @@ -801,11 +786,11 @@ msgstr "Thrustmaster Flight Control System" msgid "None" msgstr "Brez" -msgid "%u MB (CHS: %i, %i, %i)" -msgstr "%u MB (CHS: %i, %i, %i)" +msgid "%1 MB (CHS: %2, %3, %4)" +msgstr "%1 MB (CHS: %2, %3, %4)" -msgid "Floppy %i (%s): %ls" -msgstr "Disketa %i (%s): %ls" +msgid "Floppy %1 (%2): %3" +msgstr "Disketa %1 (%2): %3" msgid "Advanced sector images" msgstr "Napredne sektorske slike" @@ -820,13 +805,13 @@ msgid "Are you sure you want to exit 86Box?" msgstr "Ste prepričani, da želite zapreti 86Box?" msgid "Unable to initialize Ghostscript" -msgstr "Ne morem inicializirati Ghostscript" +msgstr "Ghostscript-a ni bilo mogoče inicializirati" msgid "Unable to initialize GhostPCL" -msgstr "Ne morem inicializirati GhostPCL" +msgstr "GhostPCL-ja ni bilo mogoče inicializirati" -msgid "MO %i (%ls): %ls" -msgstr "MO %i (%ls): %ls" +msgid "MO %1 (%2): %3" +msgstr "MO %1 (%2): %3" msgid "MO images" msgstr "Slike MO" @@ -876,9 +861,6 @@ msgstr "%1 je potreben za samodejno pretvorbo datotek PostScript v PDF.\n\nVsi d msgid "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PCL printer will be saved as Printer Command Lnaugage (.pcl) files." msgstr "%1 je potreben za samodejno pretvorbo datotek PCL v PDF.\n\nVsi dokumenti, poslani generičnemu tiskalniku PCL bodo shranjeni kot datoteke Printer Command Language (.pcl)." -msgid "Entering fullscreen mode" -msgstr "Preklapljam v celozaslonski način" - msgid "Don't show this message again" msgstr "Ne pokaži več tega sporočila" @@ -886,25 +868,22 @@ msgid "Don't exit" msgstr "Prekliči izhod" msgid "Reset" -msgstr "Resetiraj" +msgstr "Znova zaženi" msgid "Don't reset" -msgstr "Ne resetiraj" +msgstr "Ne zaženi znova" msgid "CD-ROM images" msgstr "Slike CD-ROM" msgid "%1 Device Configuration" -msgstr "Konfiguracija naprave %1" +msgstr "Nastavitev naprave %1" msgid "Monitor in sleep mode" msgstr "Zaslon v načinu spanja" -msgid "OpenGL Shaders" -msgstr "Senčilniki OpenGL" - -msgid "OpenGL options" -msgstr "Možnosti OpenGL" +msgid "GLSL shaders" +msgstr "Senčilniki GLSL" msgid "You are loading an unsupported configuration" msgstr "Nalagate nepodprto konfiguracijo" @@ -915,24 +894,18 @@ msgstr "Filtriranje vrste procesorja glede na izbran sistem je onemogočeno za t msgid "Continue" msgstr "Nadaljuj" -msgid "Cassette: %s" -msgstr "Kaseta: %s" +msgid "Cassette: %1" +msgstr "Kaseta: %1" msgid "Cassette images" msgstr "Slike kaset" -msgid "Cartridge %i: %ls" -msgstr "Spominski vložek %i: %ls" +msgid "Cartridge %1: %2" +msgstr "Spominski vložek %1: %2" msgid "Cartridge images" msgstr "Slike spominskega vložka" -msgid "Error initializing renderer" -msgstr "Napaka pri zagonu sistema za upodabljanje" - -msgid "OpenGL (3.0 Core) renderer could not be initialized. Use another renderer." -msgstr "Sistema za upodabljanje OpenGL (3.0 Core) ni bilo mogoče zagnati. Uporabite drug sistem za upodabljanje." - msgid "Resume execution" msgstr "Nadaljuj izvajanje" @@ -967,7 +940,7 @@ msgid "Add New Hard Disk" msgstr "Dodaj nov trdi disk" msgid "Add Existing Hard Disk" -msgstr "Dodaj obstoječ trdi disk" +msgstr "Dodaj obstoječi trdi disk" msgid "HDI disk images cannot be larger than 4 GB." msgstr "Slike diska HDI ne morejo biti večje od 4 GB." @@ -1069,13 +1042,13 @@ msgid "VHD files" msgstr "Datoteke VHD" msgid "Select the parent VHD" -msgstr "Izberite starševsko sliko VHD" +msgstr "Izberite nadrejeno sliko 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 "To lahko pomeni, da je bila starševska slika spremenjena potem, ko je že bila ustvarjena diferencialna slika.\n\nDo tega lahko pride tudi kadar so datoteke slik diska premaknjene ali kopirane, ali pa gre za hrošča v programu, ki je ustvaril ta disk.\n\nŽelite popraviti časovni žig?" +msgstr "To lahko pomeni, da je bila nadrejena slika spremenjena po ustvaritvi diferencialne slike.\n\nDo tega lahko pride tudi kadar so datoteke slik diska premaknjene ali kopirane, ali pa gre za hrošča v programu, ki je ustvaril ta disk.\n\nŽelite popraviti časovni žig?" msgid "Parent and child disk timestamps do not match" -msgstr "Časovna žiga starševske slike diska in slike diska otroka se ne ujemata" +msgstr "Časovna žiga nadrejene in podrejene slike diska se ne ujemata" msgid "Could not fix VHD timestamp." msgstr "Ne morem popraviti časovnega žiga slike VHD." @@ -1095,8 +1068,8 @@ msgstr "IDE" msgid "ATAPI" msgstr "ATAPI" -msgid "CD-ROM %i (%s): %s" -msgstr "CD-ROM %i (%s): %s" +msgid "CD-ROM %1 (%2): %3" +msgstr "CD-ROM %1 (%2): %3" msgid "160 KB" msgstr "160 KB" @@ -1126,10 +1099,10 @@ msgid "1.44 MB" msgstr "1.44 MB" msgid "DMF (cluster 1024)" -msgstr "DMF (grozd 1024)" +msgstr "DMF (gruča 1024)" msgid "DMF (cluster 2048)" -msgstr "DMF (grozd 2048)" +msgstr "DMF (gruča 2048)" msgid "2.88 MB" msgstr "2.88 MB" @@ -1183,7 +1156,7 @@ msgid "(System Default)" msgstr "(Sistemsko privzeto)" msgid "Failed to initialize network driver" -msgstr "Ni uspelo inicializirati omrežnega gonilnika" +msgstr "Inicializacija omrežnega gonilnika ni uspela" msgid "The network configuration will be switched to the null driver" msgstr "Omrežne nastavitve bodo preklopljene na ničelni gonilnik" @@ -1255,7 +1228,7 @@ msgid "Open screenshots folder..." msgstr "Odprite mapo s posnetki zaslona..." msgid "Apply fullscreen stretch mode when maximized" -msgstr "Uporabi način celozaslonskega raztezanja v povečanem stanju" +msgstr "Uporabi način celozaslonskega raztezanja v maksimiranem stanju" msgid "Cursor/Puck" msgstr "Kazalec/ključ" @@ -1264,22 +1237,19 @@ msgid "Pen" msgstr "Pisalo" msgid "Host CD/DVD Drive (%1:)" -msgstr "Pogon CD/DVD gostitelja (%1:)" +msgstr "Gostiteljski pogon CD/DVD (%1:)" msgid "&Connected" msgstr "&Povezan" msgid "Clear image history" -msgstr "Jasna zgodovina slik" +msgstr "Počisti zgodovino slik" msgid "Create..." msgstr "Ustvari..." -msgid "previous image" -msgstr "zadnja slika" - msgid "Host CD/DVD Drive (%1)" -msgstr "Pogon CD/DVD gostitelja (%1)" +msgstr "Gostiteljski pogon CD/DVD (%1)" msgid "Unknown Bus" msgstr "Neznano vodilo" @@ -1287,23 +1257,8 @@ msgstr "Neznano vodilo" msgid "Null Driver" msgstr "Ničelni gonilnik" -msgid "NIC %02i (%ls) %ls" -msgstr "NIC %02i (%ls) %ls" - -msgid "Error opening \"%1\": %2" -msgstr "Napaka pri odpiranju \"%1\": %2" - -msgid "Error compiling vertex shader in file \"%1\"" -msgstr "Napaka pri sestavljanju senčilnika vrhov v datoteki \"%1\"" - -msgid "Error compiling fragment shader in file \"%1\"" -msgstr "Napaka pri sestavljanju shaderja fragmentov v datoteki \"%1\"" - -msgid "Error linking shader program in file \"%1\"" -msgstr "Napaka pri povezovanju programa shader v datoteki \"%1\"" - -msgid "OpenGL 3.0 renderer options" -msgstr "Možnosti sistema za upodabljanje OpenGL 3.0" +msgid "NIC %1 (%2) %3" +msgstr "NIC %1 (%2) %3" msgid "Render behavior" msgstr "Obnašanje pri upodabljanju" @@ -1317,9 +1272,6 @@ msgstr " fps" msgid "VSync" msgstr "VSync" -msgid "<html><head/><body><p>Render each frame immediately, in sync with the emulated display.</p><p><span style=" font-style:italic;">This is the recommended option if the shaders in use don't utilize frametime for animated effects.</span></p></body></html>" -msgstr "<html><head/><body><p>Vsako sličico prikažite takoj, sinhronizirano z emuliranim zaslonom.</p><p><span style=" font-style:italic;">To je priporočljiva možnost, če uporabljeni senčilniki ne uporabljajo časa okvirja za animirane učinke.</span></p></body></html>" - msgid "Synchronize with video" msgstr "Sinhroniziraj z videom" @@ -1329,20 +1281,8 @@ msgstr "Senčilniki" msgid "Remove" msgstr "Odstrani" -msgid "No shader selected" -msgstr "Ni izbran noben senčnik" - msgid "Browse..." -msgstr "Brskaj..." - -msgid "Shader error" -msgstr "Napaka senčilnika" - -msgid "Could not load shaders." -msgstr "Ni bilo mogoče naložiti senčilnikov." - -msgid "More information in details." -msgstr "Več informacij v podrobnostih." +msgstr "Prerskaj..." msgid "Couldn't create OpenGL context." msgstr "Ni bilo mogoče ustvariti konteksta OpenGL." @@ -1351,28 +1291,22 @@ msgid "Couldn't switch to OpenGL context." msgstr "Ni bilo mogoče preklopiti na kontekst OpenGL." msgid "OpenGL version 3.0 or greater is required. Current version is %1.%2" -msgstr "Zahteva se različica OpenGL 3.0 ali novejša. Trenutna različica je %1.%2" - -msgid "OpenGL initialization failed. Error %1." -msgstr "Inicializacija OpenGL ni uspela. Napaka %1." +msgstr "Potrebna je OpenGL različica 3.0 ali novejša. Trenutna različica je %1.%2" msgid "Error initializing OpenGL" msgstr "Napaka pri inicializaciji OpenGL" -msgid "Falling back to software rendering.\n" -msgstr "Vrnitev k programskemu upodabljanju.\n" +msgid "\nFalling back to software rendering." +msgstr "\nVrnitev na programsko upodabljanje." -msgid "Allocating memory for unpack buffer failed.\n" -msgstr "Dodelitev pomnilnika za razpakirni predpomnilnik ni uspela.\n" - -msgid "<html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html>" -msgstr "<html><head/><body><p>Pri izbiri medijskih slik (CD-ROM, disketa itd.) se bo odprto pogovorno okno začelo v istem imeniku kot konfiguracijska datoteka 86Box. Ta nastavitev bo verjetno imela pomen le v operacijskem sistemu MacOS.</p></body></html>" +msgid "

When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" +msgstr "

Pri izbiri medijskih slik (CD-ROM, disketa itd.) se bo odprto pogovorno okno začelo v istem imeniku kot konfiguracijska datoteka 86Box. Ta nastavitev bo verjetno imela pomen le v operacijskem sistemu MacOS.

" msgid "This machine might have been moved or copied." msgstr "Ta naprava je bila morda premeščena ali kopirana." msgid "In order to ensure proper networking functionality, 86Box needs to know if this machine was moved or copied.\n\nSelect \"I Copied It\" if you are not sure." -msgstr "Da bi zagotovili pravilno delovanje omrežja, mora 86Box vedeti, ali je bil ta stroj prestavljen ali kopiran.\n\nČe niste prepričani, izberite \"Kopiral sem jo\"." +msgstr "Da bi zagotovili pravilno delovanje omrežja, mora 86Box vedeti, ali je bil ta virtualna naprava prestavljena ali kopirana.\n\nČe niste prepričani, izberite \"Kopiral sem jo\"." msgid "I Moved It" msgstr "Premaknil sem jo" @@ -1401,17 +1335,17 @@ msgstr "Omrežna kartica 3" msgid "Network Card #4" msgstr "Omrežna kartica 4" -msgid "Mode" -msgstr "Način" +msgid "Mode:" +msgstr "Način:" -msgid "Interface" -msgstr "Vmesnik" +msgid "Interface:" +msgstr "Vmesnik:" -msgid "Adapter" -msgstr "Adapter" +msgid "Adapter:" +msgstr "Mrežna kartica:" -msgid "VDE Socket" -msgstr "Vtičnica VDE" +msgid "VDE Socket:" +msgstr "Vtičnica VDE:" msgid "86Box Unit Tester" msgstr "Tester enote 86Box" @@ -1431,9 +1365,6 @@ msgstr "Prepust za serijska vrata 3" msgid "Serial port passthrough 4" msgstr "Prepust za serijska vrata 4" -msgid "Vision Systems LBA Enhancer" -msgstr "Vision Systems LBA Enhancer" - msgid "Renderer options..." msgstr "Možnosti sistema za upodabljanje..." @@ -1459,7 +1390,7 @@ msgid "3M MicroTouch (Serial)" msgstr "3M MicroTouch (serijska)" msgid "[COM] Standard Hayes-compliant Modem" -msgstr "[COM] Standardni modem v skladu s standardom Hayes" +msgstr "[COM] Standardni modem v skladen s Hayes" msgid "Roland MT-32 Emulation" msgstr "Emulacija Roland MT-32" @@ -1474,10 +1405,10 @@ msgid "Roland CM-32LN Emulation" msgstr "Emulacija Roland CM-32LN" msgid "OPL4-ML Daughterboard" -msgstr "Hčerinska plošča OPL4-ML" +msgstr "Dodatna kartica OPL4-ML" msgid "System MIDI" -msgstr "Sistem MIDI" +msgstr "Sistemski MIDI" msgid "MIDI Input Device" msgstr "Vhodna naprava MIDI" @@ -1486,7 +1417,7 @@ msgid "BIOS Address" msgstr "Naslov BIOS-a" msgid "Enable BIOS extension ROM Writes" -msgstr "Omogočanje razširitve BIOS-a ROM piše" +msgstr "Omogoči zapisovanje razširitev BIOS ROM-a" msgid "Address" msgstr "Naslov" @@ -1498,7 +1429,7 @@ msgid "BIOS Revision" msgstr "Revizija BIOS-a" msgid "Translate 26 -> 17" -msgstr "Prevesti 26 -> 17" +msgstr "Prevedi 26 -> 17" msgid "Language" msgstr "Jezik" @@ -1513,25 +1444,25 @@ msgid "BIOS size" msgstr "Velikost BIOS-a" msgid "Map C0000-C7FFF as UMB" -msgstr "Zemljevid C0000-C7FFF kot UMB" +msgstr "Preslikaj C0000-C7FFF kot UMB" msgid "Map C8000-CFFFF as UMB" -msgstr "Zemljevid C8000-CFFFF kot UMB" +msgstr "Preslikaj C8000-CFFFF kot UMB" msgid "Map D0000-D7FFF as UMB" -msgstr "Zemljevid D0000-D7FFF kot UMB" +msgstr "Preslikaj D0000-D7FFF kot UMB" msgid "Map D8000-DFFFF as UMB" -msgstr "Zemljevid D8000-DFFFF kot UMB" +msgstr "Preslikaj D8000-DFFFF kot UMB" msgid "Map E0000-E7FFF as UMB" -msgstr "Zemljevid E0000-E7FFF kot UMB" +msgstr "Preslikaj E0000-E7FFF kot UMB" msgid "Map E8000-EFFFF as UMB" -msgstr "Zemljevid E8000-EFFFF kot UMB" +msgstr "Preslikaj E8000-EFFFF kot UMB" msgid "JS9 Jumper (JIM)" -msgstr "JS9 Jumper (JIM)" +msgstr "JS9 mostiček (JIM)" msgid "MIDI Output Device" msgstr "Izhodna naprava MIDI" @@ -1645,10 +1576,10 @@ msgid "RAM Address" msgstr "Naslov RAM" msgid "RAM size" -msgstr "Velikost pomnilnika RAM" +msgstr "Velikost pomnilnika" msgid "Initial RAM size" -msgstr "Začetna velikost pomnilnika RAM" +msgstr "Začetna velikost pomnilnika" msgid "Serial Number" msgstr "Serijska številka" @@ -1660,7 +1591,7 @@ msgid "FDC Address" msgstr "Naslov FDC" msgid "MPU-401 Address" -msgstr "MPU-401 Naslov" +msgstr "Naslov MPU-401" msgid "MPU-401 IRQ" msgstr "MPU-401 IRQ" @@ -1696,7 +1627,7 @@ msgid "Enable OPL" msgstr "Omogoči OPL" msgid "Receive MIDI input (MPU-401)" -msgstr "Sprejemaj vhod MIDI (MPU-401)" +msgstr "Vhod MIDI za sprejem (MPU-401)" msgid "SB low DMA" msgstr "Nizki DMA SB" @@ -1729,7 +1660,7 @@ msgid "Codec" msgstr "Kodek" msgid "GUS type" -msgstr "Tip GUS" +msgstr "Vrsta GUS" msgid "Enable 0x04 \"Exit 86Box\" command" msgstr "Omogoči ukaz 0x04 \"Zapusti 86Box\"" @@ -1744,7 +1675,7 @@ msgid "RGB type" msgstr "Vrsta RGB zaslona" msgid "Line doubling type" -msgstr "Vrsta podvojitve črt" +msgstr "Vrsta podvojevanja črt" msgid "Snow emulation" msgstr "Emulacija snega" @@ -1756,16 +1687,16 @@ msgid "Character set" msgstr "Nabor znakov" msgid "XGA type" -msgstr "Tip kartice XGA" +msgstr "Vrsta kartice XGA" msgid "Instance" -msgstr "Primer" +msgstr "Primerek" msgid "MMIO Address" msgstr "Naslov MMIO" msgid "RAMDAC type" -msgstr "Vrsta čipa RAMDAC" +msgstr "Vrsta RAMDAC" msgid "Blend" msgstr "Mešanica" @@ -1777,13 +1708,13 @@ msgid "Dithering" msgstr "Barvno stresanje" msgid "Enable NMI for CGA emulation" -msgstr "Omogočite NMI za emulacijo CGA" +msgstr "Omogoči NMI za emulacijo CGA" msgid "Voodoo type" -msgstr "Tip kartice Voodoo" +msgstr "Vrsta kartice Voodoo" msgid "Framebuffer memory size" -msgstr "Velikost pomnilnika predpomnilnika okvirja" +msgstr "Velikost videopomnilnika" msgid "Texture memory size" msgstr "Velikost pomnilnika tekstur" @@ -1795,7 +1726,7 @@ msgid "Screen Filter" msgstr "Filter zaslona" msgid "Render threads" -msgstr "Nitke za upodabljanje" +msgstr "Niti za upodabljanje" msgid "SLI" msgstr "SLI" @@ -1858,7 +1789,7 @@ msgid "Non-timed (original)" msgstr "Brez časovnika (izvirnik)" msgid "45 Hz (JMP2 not populated)" -msgstr "45 Hz (brez mostička na JMP2)" +msgstr "45 Hz (brez mostička JMP2)" msgid "Two" msgstr "Dva" @@ -1867,10 +1798,13 @@ msgid "Three" msgstr "Tri" msgid "Wheel" -msgstr "Kolesa" +msgstr "Kolesce" msgid "Five + Wheel" -msgstr "Pet + kolo" +msgstr "Pet + kolesce" + +msgid "Five + 2 Wheels" +msgstr "Pet + 2 kolesci" msgid "A3 - SMT2 Serial / SMT3(R)V" msgstr "A3 - SMT2 serijska / SMT3(R)V" @@ -1945,13 +1879,13 @@ msgid "Color (generic)" msgstr "Barvni (generični)" msgid "Green Monochrome" -msgstr "Zeleni enobvarni" +msgstr "Zeleni monokromatski" msgid "Amber Monochrome" -msgstr "Jantarni enobarvni" +msgstr "Jantarni monokromatski" msgid "Gray Monochrome" -msgstr "Sivi enobarvni" +msgstr "Sivi monokromatski" msgid "Color (no brown)" msgstr "Barvni (brez rjave)" @@ -1972,13 +1906,13 @@ msgid "128 KB" msgstr "128 KB" msgid "Monochrome (5151/MDA) (white)" -msgstr "Enobarvni (5151/MDA) (beli)" +msgstr "Monokromatski (5151/MDA) (beli)" msgid "Monochrome (5151/MDA) (green)" -msgstr "Enobarvni (5151/MDA) (zeleni)" +msgstr "Monokromatski (5151/MDA) (zeleni)" msgid "Monochrome (5151/MDA) (amber)" -msgstr "Enobarvni (5151/MDA) (jantarni)" +msgstr "Monokromatski (5151/MDA) (jantarni)" msgid "Color 40x25 (5153/CGA)" msgstr "Barvni 40x25 (5153/CGA)" @@ -1990,7 +1924,7 @@ msgid "Enhanced Color - Normal Mode (5154/ECD)" msgstr "Izboljšani barvni - običajni način (5154/ECD)" msgid "Enhanced Color - Enhanced Mode (5154/ECD)" -msgstr "Izboljšani barvni - Izboljšani način (5154/ECD)" +msgstr "Izboljšani barvni - izboljšani način (5154/ECD)" msgid "Green" msgstr "Zeleni" @@ -2068,7 +2002,7 @@ msgid "Generic PCL5e Printer" msgstr "Generični tiskalnik PCL5e" msgid "Parallel Line Internet Protocol" -msgstr "Internetni protokol za paralelno linijo" +msgstr "Internetni protokol za vzporedno linijo" msgid "Protection Dongle for Savage Quest" msgstr "Zaščitni ključek za Savage Quest" @@ -2089,7 +2023,7 @@ msgid "Data bits" msgstr "Podatkovni biti" msgid "Stop bits" -msgstr "Stop biti" +msgstr "Zaključni biti" msgid "Baud Rate of Passthrough" msgstr "Baudna hitrost prepusta" @@ -2098,10 +2032,10 @@ msgid "Named Pipe (Server)" msgstr "Poimenovana cev (Strežnik)" msgid "Host Serial Passthrough" -msgstr "Prepustno serijskih vrat gostitelja" +msgstr "Prepust serijskih vrat gostitelja" -msgid "Eject %s" -msgstr "Izvrzi %s" +msgid "E&ject %1" +msgstr "I&zvrzi %1" msgid "&Unmute" msgstr "&Vklopi zvok" @@ -2112,11 +2046,104 @@ msgstr "Softfloat FPU" msgid "High performance impact" msgstr "Visok učinek na hitrost delovanja" -msgid "RAM Disk (max. speed)" -msgstr "Pogon RAM (največja hitrost)" +msgid "[Generic] RAM Disk (max. speed)" +msgstr "[Generic] Pomnilniški disk (največja hitrost)" + +msgid "[Generic] 1989 (3500 RPM)" +msgstr "" + +msgid "[Generic] 1992 (3600 RPM)" +msgstr "" + +msgid "[Generic] 1994 (4500 RPM)" +msgstr "" + +msgid "[Generic] 1996 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1997 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1998 (5400 RPM)" +msgstr "" + +msgid "[Generic] 2000 (7200 RPM)" +msgstr "" msgid "IBM 8514/A clone (ISA)" msgstr "Klon IBM 8514/A (ISA)" msgid "Vendor" msgstr "Proizvajalec" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Generična razširitev pomnilnika PC/XT" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Generična razširitev pomnilnika PC/AT" + +msgid "Unable to find Dot-Matrix fonts" +msgstr "Ni bilo mogoče najti matričnih pisav" + +msgid "TrueType fonts in the \"roms/printer/fonts\" directory are required for the emulation of the Generic ESC/P Dot-Matrix Printer." +msgstr "Za emulacijo generičnega ESC/P matričnega tiskalnika so potrebne TrueType pisave v imeniku \"roms/printer/fonts\"." + +msgid "Inhibit multimedia keys" +msgstr "Blokiraj multimedijske tipke" + +msgid "Ask for confirmation before saving settings" +msgstr "Vprašaj za potrditev pred shranjevanjem nastavitev" + +msgid "Ask for confirmation before hard resetting" +msgstr "Vprašaj za potrditev pred ponovnim zagonom" + +msgid "Ask for confirmation before quitting" +msgstr "Vprašaj za potrditev pred izhodom" + +msgid "Options" +msgstr "Možnosti" + +msgid "Model" +msgstr "" + +msgid "Model:" +msgstr "" + +msgid "Failed to initialize Vulkan renderer." +msgstr "Inicializacija upodobljevalnika Vulkan ni uspela." + +msgid "GLSL Error" +msgstr "Napaka GLSL" + +msgid "Could not load shader: %1" +msgstr "Ni bilo mogoče naložiti senčilnika: %1" + +msgid "OpenGL version 3.0 or greater is required. Current GLSL version is %1.%2" +msgstr "Potrebna je OpenGL različica 3.0 ali novejša. Trenutna različica GLSL je %1.%2" + +msgid "Could not load texture: %1" +msgstr "Ni bilo mogoče naložiti teksture: %1" + +msgid "Could not compile shader:\n\n%1" +msgstr "Ni bilo mogoče prevesti senčilnika:\n\n%1" + +msgid "Program not linked:\n\n%1" +msgstr "Program ni povezan:\n\n%1" + +msgid "Shader Manager" +msgstr "Upravljalnik senčilnikov" + +msgid "Shader Configuration" +msgstr "Nastavitve senčilnikov" + +msgid "Add" +msgstr "Dodaj" + +msgid "Move up" +msgstr "Premakni gor" + +msgid "Move down" +msgstr "Premakni dol" + +msgid "Could not load file %1" +msgstr "Ni bilo mogoče naložiti datoteke %1" diff --git a/src/qt/languages/sv-SE.po b/src/qt/languages/sv-SE.po new file mode 100644 index 000000000..efbfab7eb --- /dev/null +++ b/src/qt/languages/sv-SE.po @@ -0,0 +1,2155 @@ +msgid "" +msgstr "" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Language: sv_SE\n" +"X-Source-Language: en_US\n" + +msgid "&Action" +msgstr "" + +msgid "&Keyboard requires capture" +msgstr "Tangentbord behöver uppfångas" + +msgid "&Right CTRL is left ALT" +msgstr "&Höger CTRL är vänster ALT" + +msgid "&Hard Reset..." +msgstr "&Hård omstart..." + +msgid "&Ctrl+Alt+Del" +msgstr "&Ctrl+Alt+Del" + +msgid "Ctrl+Alt+&Esc" +msgstr "Ctrl+Alt+&Esc" + +msgid "&Pause" +msgstr "&Pausa" + +msgid "E&xit..." +msgstr "A&vsluta..." + +msgid "&View" +msgstr "&Visa" + +msgid "&Hide status bar" +msgstr "&Dölj statusfältet" + +msgid "Hide &toolbar" +msgstr "Dölj &verktygsfältet" + +msgid "&Resizeable window" +msgstr "&Ändringsbar fönsterstorlek" + +msgid "R&emember size && position" +msgstr "K&om ihåg storlek && position" + +msgid "Re&nderer" +msgstr "Re&nderare" + +msgid "&Qt (Software)" +msgstr "&Qt (Mjukvara)" + +msgid "Qt (&OpenGL)" +msgstr "Qt (&OpenGL)" + +msgid "Open&GL (3.0 Core)" +msgstr "Open&GL (3.0 Core)" + +msgid "&VNC" +msgstr "&VNC" + +msgid "Specify dimensions..." +msgstr "Ange mått..." + +msgid "F&orce 4:3 display ratio" +msgstr "T&vinga 4:3 bildförhållande" + +msgid "&Window scale factor" +msgstr "&Skalningsfaktor för fönster" + +msgid "&0.5x" +msgstr "&0.5x" + +msgid "&1x" +msgstr "&1x" + +msgid "1.&5x" +msgstr "1.&5x" + +msgid "&2x" +msgstr "&2x" + +msgid "&3x" +msgstr "&3x" + +msgid "&4x" +msgstr "&4x" + +msgid "&5x" +msgstr "&5x" + +msgid "&6x" +msgstr "&6x" + +msgid "&7x" +msgstr "&7x" + +msgid "&8x" +msgstr "&8x" + +msgid "Filter method" +msgstr "Filtermetod" + +msgid "&Nearest" +msgstr "&Närmsta" + +msgid "&Linear" +msgstr "&Linjär" + +msgid "Hi&DPI scaling" +msgstr "Hög&DPI-skalning" + +msgid "&Fullscreen" +msgstr "&Helskärm" + +msgid "Fullscreen &stretch mode" +msgstr "Sträckningsläge för &helskärm" + +msgid "&Full screen stretch" +msgstr "&Sträck till helskärm" + +msgid "&4:3" +msgstr "&4:3" + +msgid "&Square pixels (Keep ratio)" +msgstr "&Fyrkantiga pixlar (Behåll bildförhållande)" + +msgid "&Integer scale" +msgstr "&Skala till heltal" + +msgid "4:&3 Integer scale" +msgstr "Skala till heltal i 4:&3" + +msgid "E&GA/(S)VGA settings" +msgstr "E&GA/(S)VGA-inställningar" + +msgid "&Inverted VGA monitor" +msgstr "&Inverterad VGA-skärm" + +msgid "VGA screen &type" +msgstr "Skärmtyp för &VGA" + +msgid "RGB &Color" +msgstr "RGB &färg" + +msgid "&RGB Grayscale" +msgstr "&RGB gråskala" + +msgid "&Amber monitor" +msgstr "&Bärnstensfärgad skärm" + +msgid "&Green monitor" +msgstr "&Grön skärm" + +msgid "&White monitor" +msgstr "&Vit skärm" + +msgid "Grayscale &conversion type" +msgstr "Konverteringstyp till &gråskala" + +msgid "BT&601 (NTSC/PAL)" +msgstr "BT&601 (NTSC/PAL)" + +msgid "BT&709 (HDTV)" +msgstr "BT&709 (HDTV)" + +msgid "&Average" +msgstr "&Genomsnittlig" + +msgid "CGA/PCjr/Tandy/E&GA/(S)VGA overscan" +msgstr "CGA/PCjr/Tandy/E&GA/(S)VGA överskanning" + +msgid "Change contrast for &monochrome display" +msgstr "Ändra kontrast för &svartvita skärmar" + +msgid "&Media" +msgstr "&Media" + +msgid "&Tools" +msgstr "&Verktyg" + +msgid "&Settings..." +msgstr "&Inställningar..." + +msgid "&Update status bar icons" +msgstr "&Uppdatera statusfältets ikoner" + +msgid "Take s&creenshot" +msgstr "Tag s&kärmbild" + +msgid "S&ound" +msgstr "L&jud" + +msgid "&Preferences..." +msgstr "&Preferenser..." + +msgid "Enable &Discord integration" +msgstr "Aktivera &integration med Discord" + +msgid "Sound &gain..." +msgstr "Ljud&förstärkning..." + +msgid "Begin trace" +msgstr "Börja spårning" + +msgid "End trace" +msgstr "Avsluta spårning" + +msgid "&Help" +msgstr "&Hjälp" + +msgid "&Documentation..." +msgstr "&Dokumentation..." + +msgid "&About 86Box..." +msgstr "&Om 86Box..." + +msgid "&New image..." +msgstr "&Ny avbildning..." + +msgid "&Existing image..." +msgstr "&Befintlig avbildning..." + +msgid "Existing image (&Write-protected)..." +msgstr "Befintlig avbildning (&skrivskyddad)..." + +msgid "&Record" +msgstr "&Spela in" + +msgid "&Play" +msgstr "&Spela upp" + +msgid "&Rewind to the beginning" +msgstr "&Spola tillbaka till början" + +msgid "&Fast forward to the end" +msgstr "&Spola fram till slutet" + +msgid "E&ject" +msgstr "M&ata ut" + +msgid "&Image..." +msgstr "&Avbildning..." + +msgid "E&xport to 86F..." +msgstr "E&xportera till 86F..." + +msgid "&Mute" +msgstr "&Tysta" + +msgid "E&mpty" +msgstr "T&om" + +msgid "Reload previous image" +msgstr "Ladda om föregående avbildning" + +msgid "&Folder..." +msgstr "&Mapp..." + +msgid "Target &framerate" +msgstr "Mål för &bildhastighet" + +msgid "&Sync with video" +msgstr "&Synkronisera med bild" + +msgid "&25 fps" +msgstr "&25 fps" + +msgid "&30 fps" +msgstr "&30 fps" + +msgid "&50 fps" +msgstr "&50 fps" + +msgid "&60 fps" +msgstr "&60 fps" + +msgid "&75 fps" +msgstr "&75 fps" + +msgid "&VSync" +msgstr "&VSync" + +msgid "&Select shader..." +msgstr "&Välj shader..." + +msgid "&Remove shader" +msgstr "&Ta bort shader" + +msgid "Preferences" +msgstr "Preferenser" + +msgid "Sound Gain" +msgstr "Ljudförstärkning" + +msgid "New Image" +msgstr "Ny avbildning" + +msgid "Settings" +msgstr "Inställningar" + +msgid "Specify Main Window Dimensions" +msgstr "Ange mått för huvudfönster" + +msgid "OK" +msgstr "Okej" + +msgid "Cancel" +msgstr "Avbryt" + +msgid "&Default" +msgstr "&Standard" + +msgid "Language:" +msgstr "Språk:" + +msgid "Gain" +msgstr "Förstärkning" + +msgid "File name:" +msgstr "Filnamn:" + +msgid "Disk size:" +msgstr "Storlek på disk:" + +msgid "RPM mode:" +msgstr "Varvtalsläge:" + +msgid "Progress:" +msgstr "Framsteg:" + +msgid "Width:" +msgstr "Bredd:" + +msgid "Height:" +msgstr "Höjd:" + +msgid "Lock to this size" +msgstr "Lås till denna storlek" + +msgid "Machine type:" +msgstr "Maskintyp:" + +msgid "Machine:" +msgstr "Maskin:" + +msgid "Configure" +msgstr "Konfigurera" + +msgid "CPU type:" +msgstr "Processortyp:" + +msgid "Speed:" +msgstr "Hastighet:" + +msgid "Frequency:" +msgstr "Frekvens:" + +msgid "FPU:" +msgstr "Flyttalsprocessor:" + +msgid "Wait states:" +msgstr "Väntcykler:" + +msgid "MB" +msgstr "MB" + +msgid "Memory:" +msgstr "Minne:" + +msgid "Time synchronization" +msgstr "Synkronisera tid" + +msgid "Disabled" +msgstr "Inaktiverad" + +msgid "Enabled (local time)" +msgstr "Aktiverad (lokal tid)" + +msgid "Enabled (UTC)" +msgstr "Aktiverad (UTC)" + +msgid "Dynamic Recompiler" +msgstr "Dynamisk omkompilering" + +msgid "Video:" +msgstr "Bildskärmskort:" + +msgid "Video #2:" +msgstr "Bildskärmskort #2:" + +msgid "Voodoo 1 or 2 Graphics" +msgstr "Voodoo 1 eller 2-grafik" + +msgid "IBM 8514/A Graphics" +msgstr "IBM 8514/A-grafik" + +msgid "XGA Graphics" +msgstr "XGA-grafik" + +msgid "Mouse:" +msgstr "Mus:" + +msgid "Joystick:" +msgstr "Styrspak:" + +msgid "Joystick 1..." +msgstr "Styrspak 1..." + +msgid "Joystick 2..." +msgstr "Styrspak 2..." + +msgid "Joystick 3..." +msgstr "Styrspak 3..." + +msgid "Joystick 4..." +msgstr "Styrspak 4..." + +msgid "Sound card #1:" +msgstr "Ljudkort #1:" + +msgid "Sound card #2:" +msgstr "Ljudkort #2:" + +msgid "Sound card #3:" +msgstr "Ljudkort #3:" + +msgid "Sound card #4:" +msgstr "Ljudkort #4:" + +msgid "MIDI Out Device:" +msgstr "Enhet för MIDI-utdata:" + +msgid "MIDI In Device:" +msgstr "Enhet för MIDI-indata:" + +msgid "Standalone MPU-401" +msgstr "Fristående MPU-401" + +msgid "Use FLOAT32 sound" +msgstr "Använd FLOAT32-ljud" + +msgid "FM synth driver" +msgstr "Drivrutin för FM-synt" + +msgid "Nuked (more accurate)" +msgstr "Nuked (mer exakt)" + +msgid "YMFM (faster)" +msgstr "YMFM (snabbare)" + +msgid "COM1 Device:" +msgstr "COM1-enhet:" + +msgid "COM2 Device:" +msgstr "COM2-enhet:" + +msgid "COM3 Device:" +msgstr "COM3-enhet:" + +msgid "COM4 Device:" +msgstr "COM4-enhet:" + +msgid "LPT1 Device:" +msgstr "LPT1-enhet:" + +msgid "LPT2 Device:" +msgstr "LPT2-enhet:" + +msgid "LPT3 Device:" +msgstr "LPT3-enhet:" + +msgid "LPT4 Device:" +msgstr "LPT4-enhet:" + +msgid "Serial port 1" +msgstr "Serieport 1" + +msgid "Serial port 2" +msgstr "Serieport 2" + +msgid "Serial port 3" +msgstr "Serieport 3" + +msgid "Serial port 4" +msgstr "Serieport 4" + +msgid "Parallel port 1" +msgstr "Parallellport 1" + +msgid "Parallel port 2" +msgstr "Parallellport 2" + +msgid "Parallel port 3" +msgstr "Parallellport 3" + +msgid "Parallel port 4" +msgstr "Parallellport 4" + +msgid "HD Controller:" +msgstr "Styrenhet för hårddisk:" + +msgid "FD Controller:" +msgstr "Styrenhet för diskett:" + +msgid "Tertiary IDE Controller" +msgstr "Tertiär IDE-kontroller" + +msgid "Quaternary IDE Controller" +msgstr "Kvartär IDE-kontroller" + +msgid "SCSI" +msgstr "SCSI" + +msgid "Controller 1:" +msgstr "Styrenhet 1:" + +msgid "Controller 2:" +msgstr "Styrenhet 2:" + +msgid "Controller 3:" +msgstr "Styrenhet 3:" + +msgid "Controller 4:" +msgstr "Styrenhet 4:" + +msgid "Cassette" +msgstr "Kassettband" + +msgid "Hard disks:" +msgstr "Hårddiskar:" + +msgid "&New..." +msgstr "&Ny..." + +msgid "&Existing..." +msgstr "&Befintlig..." + +msgid "&Remove" +msgstr "&Ta bort" + +msgid "Bus:" +msgstr "Buss:" + +msgid "Channel:" +msgstr "Kanal:" + +msgid "ID:" +msgstr "ID:" + +msgid "&Specify..." +msgstr "&Specificera..." + +msgid "Sectors:" +msgstr "Sektorer:" + +msgid "Heads:" +msgstr "Läshuvuden:" + +msgid "Cylinders:" +msgstr "Cylindrar:" + +msgid "Size (MB):" +msgstr "Storlek (MB):" + +msgid "Type:" +msgstr "Typ:" + +msgid "Image Format:" +msgstr "Avbildningsformat:" + +msgid "Block Size:" +msgstr "Blockstorlek:" + +msgid "Floppy drives:" +msgstr "Diskettenhet:" + +msgid "Turbo timings" +msgstr "Turbo timings" + +msgid "Check BPB" +msgstr "Kontrollera BPB" + +msgid "CD-ROM drives:" +msgstr "CD-ROM-enheter:" + +msgid "MO drives:" +msgstr "MO-enheter:" + +msgid "ZIP drives:" +msgstr "Zip-enheter:" + +msgid "ZIP 250" +msgstr "ZIP 250" + +msgid "ISA RTC:" +msgstr "ISA realtidsklocka:" + +msgid "ISA Memory Expansion" +msgstr "ISA minnesexpansion" + +msgid "Card 1:" +msgstr "Kort 1:" + +msgid "Card 2:" +msgstr "Kort 2:" + +msgid "Card 3:" +msgstr "Kort 3:" + +msgid "Card 4:" +msgstr "Kort 4:" + +msgid "ISABugger device" +msgstr "ISABugger-enhet" + +msgid "POST card" +msgstr "POST-kort" + +msgid "86Box" +msgstr "86Box" + +msgid "Error" +msgstr "Fel" + +msgid "Fatal error" +msgstr "Allvarligt fel" + +msgid " - PAUSED" +msgstr " - PAUSAD" + +msgid "Speed" +msgstr "Hastighet" + +msgid "ZIP %1 %2 (%3): %4" +msgstr "ZIP %1 %2 (%3): %4" + +msgid "ZIP images" +msgstr "Zip-avbildningar" + +msgid "86Box could not find any usable ROM images.\n\nPlease download a ROM set and extract it into the \"roms\" directory." +msgstr "86Box kunde inte hitta några användbara ROM-avbildningar.\n\nVänligen ladda ner en ROM-uppsättning och extrahera den till mappen \"roms\"." + +msgid "(empty)" +msgstr "(tom)" + +msgid "All files" +msgstr "Alla filer" + +msgid "Turbo" +msgstr "Turbo" + +msgid "On" +msgstr "På" + +msgid "Off" +msgstr "Av" + +msgid "All images" +msgstr "Alla avbildningar" + +msgid "Basic sector images" +msgstr "Grundläggande sektoravbildningar" + +msgid "Surface images" +msgstr "Ytavbildningar" + +msgid "Machine \"%hs\" is not available due to missing ROMs in the roms/machines directory. Switching to an available machine." +msgstr "Maskinen \"%hs\" är inte tillgänglig på grund av saknade ROM-avbildningar i mappen roms/machines. Byter till en tillgänglig maskin." + +msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." +msgstr "Bildskärmskortet \"%hs\" är inte tillgängligt på grund av saknade ROM-avbildningar i mappen roms/video. Byter till ett tillgängligt bildskärmskort." + +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "Bildskärmskort #2 \"%hs\" är inte tillgängligt på grund av saknade ROM-avbildningar i mappen roms/video. Avaktiverar det andra bildskärmskortet." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Enheten \"%hs\" är inte tillgänglig på grund av saknade ROM-avbildningar. Ignorerar enheten." + +msgid "Machine" +msgstr "Maskin" + +msgid "Display" +msgstr "Bildskärm" + +msgid "Input devices" +msgstr "Inmatningsenheter" + +msgid "Sound" +msgstr "Ljud" + +msgid "Network" +msgstr "Nätverk" + +msgid "Ports (COM & LPT)" +msgstr "Portar (COM & LPT)" + +msgid "Storage controllers" +msgstr "Styrenheter för lagring" + +msgid "Hard disks" +msgstr "Hårddiskar" + +msgid "Floppy & CD-ROM drives" +msgstr "Diskett- och CD-ROM-enheter" + +msgid "Other removable devices" +msgstr "Andra flyttbara enheter" + +msgid "Other peripherals" +msgstr "Andra tillbehör" + +msgid "Click to capture mouse" +msgstr "Klicka för att fånga upp musen" + +msgid "Press %1 to release mouse" +msgstr "Tryck på %1 för att släppa musen" + +msgid "Press %1 or middle button to release mouse" +msgstr "Tryck på %1 eller mellersta musknappen för att släppa musen" + +msgid "Bus" +msgstr "Buss" + +msgid "File" +msgstr "Fil" + +msgid "C" +msgstr "C" + +msgid "H" +msgstr "H" + +msgid "S" +msgstr "S" + +msgid "KB" +msgstr "KB" + +msgid "Default" +msgstr "Standard" + +msgid "%1 Wait state(s)" +msgstr "" + +msgid "Type" +msgstr "Typ" + +msgid "No PCap devices found" +msgstr "Inga PCap-enheter hittade" + +msgid "Invalid PCap device" +msgstr "Ogiltig PCap-enhet" + +msgid "2-axis, 2-button joystick(s)" +msgstr "Styrspak med 2 axlar och 2 knappar" + +msgid "2-axis, 4-button joystick" +msgstr "Styrspak med 2 axlar och 4 knappar" + +msgid "2-axis, 6-button joystick" +msgstr "Styrspak med 2 axlar och 6 knappar" + +msgid "2-axis, 8-button joystick" +msgstr "Styrspak med 2 axlar och 8 knappar" + +msgid "3-axis, 2-button joystick" +msgstr "Styrspak med 3 axlar och 2 knappar" + +msgid "3-axis, 4-button joystick" +msgstr "Styrspak med 3 axlar och 4 knappar" + +msgid "4-axis, 4-button joystick" +msgstr "Styrspak med 4 axlar och 4 knappar" + +msgid "CH Flightstick Pro" +msgstr "CH Flightstick Pro" + +msgid "Microsoft SideWinder Pad" +msgstr "Microsoft SideWinder Pad" + +msgid "Thrustmaster Flight Control System" +msgstr "Thrustmaster Flight Control System" + +msgid "None" +msgstr "Ingen" + +msgid "%1 MB (CHS: %2, %3, %4)" +msgstr "%1 MB (CHS: %2, %3, %4)" + +msgid "Floppy %1 (%2): %3" +msgstr "Diskett %1 (%2): %3" + +msgid "Advanced sector images" +msgstr "Avancerade sektoravbildningar" + +msgid "Flux images" +msgstr "Flux-avbildningar" + +msgid "Are you sure you want to hard reset the emulated machine?" +msgstr "Är du säker på att du vill göra en hård omstart av den emulerade maskinen?" + +msgid "Are you sure you want to exit 86Box?" +msgstr "Är du säker på att du vill avsluta 86Box?" + +msgid "Unable to initialize Ghostscript" +msgstr "Ej möjligt att initialisera Ghostscript" + +msgid "Unable to initialize GhostPCL" +msgstr "Ej möjligt att initialisera GhostPCL" + +msgid "MO %1 (%2): %3" +msgstr "MO %1 (%2): %3" + +msgid "MO images" +msgstr "MO-avbildningar" + +msgid "Welcome to 86Box!" +msgstr "Välkommen till 86Box!" + +msgid "Internal device" +msgstr "Intern enhet" + +msgid "Exit" +msgstr "Avsluta" + +msgid "No ROMs found" +msgstr "Inga ROM-avbildningar hittades" + +msgid "Do you want to save the settings?" +msgstr "Vill du spara inställningarna?" + +msgid "This will hard reset the emulated machine." +msgstr "Detta kommer att göra en hård omstart av den emulerade maskinen." + +msgid "Save" +msgstr "Spara" + +msgid "About 86Box" +msgstr "Om 86Box" + +msgid "86Box v" +msgstr "86Box v" + +msgid "An emulator of old computers\n\nAuthors: Miran Grča (OBattler), RichardG867, Jasmine Iwanek, TC1995, coldbrewed, Teemu Korhonen (Manaatti), Joakim L. Gilje, Adrien Moulin (elyosh), Daniel Balsom (gloriouscow), Cacodemon345, Fred N. van Kempen (waltje), Tiseno100, reenigne, and others.\n\nWith previous core contributions from Sarah Walker, leilei, JohnElliott, greatpsycho, and others.\n\nReleased under the GNU General Public License version 2 or later. See LICENSE for more information." +msgstr "En emulator av gamla datorer\n\nUpphovsmän: Miran Grča (OBattler), RichardG867, Jasmine Iwanek, TC1995, coldbrewed, Teemu Korhonen (Manaatti), Joakim L. Gilje, Adrien Moulin (elyosh), Daniel Balsom (gloriouscow), Cacodemon345, Fred N. van Kempen (waltje), Tiseno100, reenigne, med flera.\n\nMed tidigare grundbidrag från Sarah Walker, leilei, JohnElliott, greatpsycho, med flera.\n\nSläppt under GNU General Public License upplaga 2 eller senare. Se LICENSE för mer information." + +msgid "Hardware not available" +msgstr "Hårdvara ej tillgänglig" + +msgid "Make sure %1 is installed and that you are on a %1-compatible network connection." +msgstr "Säkerställ att %1 är installerad och att du använder en %1-kompatibel nätverksanslutning." + +msgid "Invalid configuration" +msgstr "Ogiltig konfiguration" + +msgid "%1 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 "%1 krävs för automatisk omvandling av PostScript-filer till PDF.\n\nAlla dokument som skickats till den allmänna PostScript-skrivaren kommer att sparas som PostScript-filer (.ps)." + +msgid "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PCL printer will be saved as Printer Command Language (.pcl) files." +msgstr "%1 krävs för automatisk omvandling av PCL-filer till PDF.\n\nAlla dokument som skickas till den allmänna PCL-skrivaren kommer att sparas som Printer Command Language-filer (.pcl)." + +msgid "Don't show this message again" +msgstr "Visa inte detta meddelande igen" + +msgid "Don't exit" +msgstr "Avsluta inte" + +msgid "Reset" +msgstr "Starta om" + +msgid "Don't reset" +msgstr "Starta inte om" + +msgid "CD-ROM images" +msgstr "CD-ROM-avbildningar" + +msgid "%1 Device Configuration" +msgstr "%1 Enhetskonfiguration" + +msgid "Monitor in sleep mode" +msgstr "Skärm i viloläge" + +msgid "GLSL shaders" +msgstr "GLSL shaders" + +msgid "You are loading an unsupported configuration" +msgstr "Du laddar en konfiguration som inte stöds" + +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 "Filtrering av processortyp grundat på den valda maskinen är avaktiverat för denna emulerade maskin.\n\nDetta gör det möjligt att välja en processor som annars är oförenlig med den valda maskinen. Detta kan dock leda till oförenligheter med maskinens BIOS eller annan mjukvara\n\nAtt aktivera denna inställning stöds inte officiellt, och alla felrapporter som lämnas in kan komma att stängas som ogiltiga." + +msgid "Continue" +msgstr "Fortsätt" + +msgid "Cassette: %1" +msgstr "Kassettband: %1" + +msgid "Cassette images" +msgstr "Kassettbandsavbildningar" + +msgid "Cartridge %1: %2" +msgstr "Kassett %1: %2" + +msgid "Cartridge images" +msgstr "Kassettavbildningar" + +msgid "Resume execution" +msgstr "Fortsätt exekvering" + +msgid "Pause execution" +msgstr "Pausa exekvering" + +msgid "Press Ctrl+Alt+Del" +msgstr "Tryck på Ctrl+Alt+Del" + +msgid "Press Ctrl+Alt+Esc" +msgstr "Tryck på Ctrl+Alt+Esc" + +msgid "Hard reset" +msgstr "Hård omstart" + +msgid "ACPI shutdown" +msgstr "ACPI-avstängning" + +msgid "Hard disk (%1)" +msgstr "Hårddisk (%1)" + +msgid "MFM/RLL or ESDI CD-ROM drives never existed" +msgstr "MFM/RLL eller ESDI CD-ROM-enheter fanns aldrig" + +msgid "Custom..." +msgstr "Egen..." + +msgid "Custom (large)..." +msgstr "Egen (stor)..." + +msgid "Add New Hard Disk" +msgstr "Lägg till ny hårddisk" + +msgid "Add Existing Hard Disk" +msgstr "Lägg till befintlig hårddisk" + +msgid "HDI disk images cannot be larger than 4 GB." +msgstr "Avbildningar i HDI-format kan inte vara större än 4 GB." + +msgid "Disk images cannot be larger than 127 GB." +msgstr "Avbildningar kan inte vara större än 127 GB." + +msgid "Hard disk images" +msgstr "Hårddiskavbilningar" + +msgid "Unable to read file" +msgstr "Kan inte läsa fil" + +msgid "Unable to write file" +msgstr "Kan inte skriva till fil" + +msgid "HDI or HDX images with a sector size other than 512 are not supported." +msgstr "HDI- eller HDX-avbildningar med en sektorstorlek annat än 512 stöds inte." + +msgid "Disk image file already exists" +msgstr "Avbildningsfil finns redan" + +msgid "Please specify a valid file name." +msgstr "Vänligen ange ett giltigt filnamn." + +msgid "Disk image created" +msgstr "Avbildning skapad" + +msgid "Make sure the file exists and is readable." +msgstr "Säkerställ att filen finns och är läsbar." + +msgid "Make sure the file is being saved to a writable directory." +msgstr "Säkerställ att filen sparas till en skrivbar mapp." + +msgid "Disk image too large" +msgstr "Avbildning för stor" + +msgid "Remember to partition and format the newly-created drive." +msgstr "Kom ihåg att partitionera och formatera den skapade enheten." + +msgid "The selected file will be overwritten. Are you sure you want to use it?" +msgstr "Den valda filen kommer att skrivas över. Är du säker på att du vill använda den?" + +msgid "Unsupported disk image" +msgstr "Avbildning stöds inte" + +msgid "Overwrite" +msgstr "Skriv över" + +msgid "Don't overwrite" +msgstr "Skriv inte över" + +msgid "Raw image" +msgstr "Rå avbildning" + +msgid "HDI image" +msgstr "HDI-avbildning" + +msgid "HDX image" +msgstr "HDX-avbildning" + +msgid "Fixed-size VHD" +msgstr "VHD med fastställd storlek" + +msgid "Dynamic-size VHD" +msgstr "VHD med dynamisk storlek" + +msgid "Differencing VHD" +msgstr "Differencing-avbildning av VHD" + +msgid "(N/A)" +msgstr "(ej)" + +msgid "Raw image (.img)" +msgstr "Rå avbildning (.img)" + +msgid "HDI image (.hdi)" +msgstr "HDI-avbildning (.hdi)" + +msgid "HDX image (.hdx)" +msgstr "HDX-avbildning (.hdx)" + +msgid "Fixed-size VHD (.vhd)" +msgstr "VHD med fastställd storlek (.vhd)" + +msgid "Dynamic-size VHD (.vhd)" +msgstr "VHD med dynamisk storlek (.vhd)" + +msgid "Differencing VHD (.vhd)" +msgstr "Differencing-avbildning av VHD (.vhd)" + +msgid "Large blocks (2 MB)" +msgstr "Stora block (2 MB)" + +msgid "Small blocks (512 KB)" +msgstr "Små block (512 KB)" + +msgid "VHD files" +msgstr "VHD-filer" + +msgid "Select the parent VHD" +msgstr "Välj moders-VHDn" + +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 "Detta kan betyda att modersavbildningen har ändrats efter att skillnadsavbildningen skapades.\n\nDet kan också hända om avbildningarna har flyttats eller kopierats, eller av en bugg i programmet som skapade denna disk.\n\nVill du laga tidsstämplarna?" + +msgid "Parent and child disk timestamps do not match" +msgstr "Tidsstämpeln på moders- och dotterdisken stämmer inte överens" + +msgid "Could not fix VHD timestamp." +msgstr "Kunde inte laga tidsstämpeln på VHDn." + +msgid "MFM/RLL" +msgstr "MFM/RLL" + +msgid "XTA" +msgstr "XTA" + +msgid "ESDI" +msgstr "ESDI" + +msgid "IDE" +msgstr "IDE" + +msgid "ATAPI" +msgstr "ATAPI" + +msgid "CD-ROM %1 (%2): %3" +msgstr "CD-ROM %1 (%2): %3" + +msgid "160 KB" +msgstr "160 KB" + +msgid "180 KB" +msgstr "180 KB" + +msgid "320 KB" +msgstr "320 KB" + +msgid "360 KB" +msgstr "360 KB" + +msgid "640 KB" +msgstr "640 KB" + +msgid "720 KB" +msgstr "720 KB" + +msgid "1.2 MB" +msgstr "1.2 MB" + +msgid "1.25 MB" +msgstr "1.25 MB" + +msgid "1.44 MB" +msgstr "1.44 MB" + +msgid "DMF (cluster 1024)" +msgstr "DMF (kluster 1024)" + +msgid "DMF (cluster 2048)" +msgstr "DMF (kluster 2048)" + +msgid "2.88 MB" +msgstr "2.88 MB" + +msgid "ZIP 100" +msgstr "ZIP 100" + +msgid "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)" + +msgid "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)" + +msgid "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)" + +msgid "5.25\" 600 MB" +msgstr "5.25\" 600 MB" + +msgid "5.25\" 650 MB" +msgstr "5.25\" 650 MB" + +msgid "5.25\" 1 GB" +msgstr "5.25\" 1 GB" + +msgid "5.25\" 1.3 GB" +msgstr "5.25\" 1.3 GB" + +msgid "Perfect RPM" +msgstr "Perfekt varv/min" + +msgid "1% below perfect RPM" +msgstr "1% under perfekt varv/min" + +msgid "1.5% below perfect RPM" +msgstr "1.5% under perfekt varv/min" + +msgid "2% below perfect RPM" +msgstr "2& under perfekt varm/min" + +msgid "(System Default)" +msgstr "(Systemstandard)" + +msgid "Failed to initialize network driver" +msgstr "Kunde inte initialisera drivrutiner för nätverk" + +msgid "The network configuration will be switched to the null driver" +msgstr "Nätverkskonfigurationen kommer att bytas till den tomma drivrutinen" + +msgid "Mouse sensitivity:" +msgstr "Muskänslighet:" + +msgid "Select media images from program working directory" +msgstr "Välj medieavbildningar från programmets arbetsmapp" + +msgid "PIT mode:" +msgstr "PIT-läge:" + +msgid "Auto" +msgstr "Automatisk" + +msgid "Slow" +msgstr "Långsam" + +msgid "Fast" +msgstr "Snabb" + +msgid "&Auto-pause on focus loss" +msgstr "&Pausa automatiskt när fokus tappas" + +msgid "WinBox is no longer supported" +msgstr "WinBox stöds inte längre" + +msgid "Development of the WinBox manager stopped in 2022 due to a lack of maintainers. As we direct our efforts towards making 86Box even better, we have made the decision to no longer support WinBox as a manager.\n\nNo further updates will be provided through WinBox, and you may encounter incorrect behavior should you continue using it with newer versions of 86Box. Any bug reports related to WinBox behavior will be closed as invalid.\n\nGo to 86box.net for a list of other managers you can use." +msgstr "Utvecklingen av hanteraren WinBox stoppades under 2022 på grund av avsaknad av underhållare. När vi nu riktar våra ansträngningar till att göra 86Box ännu bättre så har vi fattat beslutet att inte längre stödja WinBox som en hanterare.\n\nInga framtida uppdateringar kommer att tillhandahållas genom WinBox, och du kan stöta på felaktiga beteenden om du skulle fortsätta att använda det med nyare versioner av 86Box. Alla felrapporter som har att göra med WinBox kommer att stängas som ogiltiga.\n\nGå till 86Box.net för en lista med andra hanterare som du kan använda." + +msgid "Generate" +msgstr "Generera" + +msgid "Joystick configuration" +msgstr "Konfiguration av styrspak" + +msgid "Device" +msgstr "Enhet" + +msgid "%1 (X axis)" +msgstr "%1 (X-axeln)" + +msgid "%1 (Y axis)" +msgstr "%1 (Y-axeln)" + +msgid "MCA devices" +msgstr "MCA-enheter" + +msgid "List of MCA devices:" +msgstr "Lista på MCA-enheter:" + +msgid "Tablet tool" +msgstr "Plattverktyg" + +msgid "Qt (OpenGL &ES)" +msgstr "Qt (OpenGL &ES)" + +msgid "About Qt" +msgstr "Om Qt" + +msgid "MCA devices..." +msgstr "MCA-enheter..." + +msgid "Show non-primary monitors" +msgstr "Visa icke-primära skärmar" + +msgid "Open screenshots folder..." +msgstr "Öppna skärmbildsmappen..." + +msgid "Apply fullscreen stretch mode when maximized" +msgstr "Tillämpa sträckläge för helskärm när den är maximerad" + +msgid "Cursor/Puck" +msgstr "Pekare/puck" + +msgid "Pen" +msgstr "Penna" + +msgid "Host CD/DVD Drive (%1:)" +msgstr "Värdenhet för CD/DVD (%1:)" + +msgid "&Connected" +msgstr "&Ansluten" + +msgid "Clear image history" +msgstr "Rensa historik för avbildningar" + +msgid "Create..." +msgstr "Skapa..." + +msgid "Host CD/DVD Drive (%1)" +msgstr "Värdenhet för CD/DVD (%1)" + +msgid "Unknown Bus" +msgstr "Okänd buss" + +msgid "Null Driver" +msgstr "Tom drivrutin" + +msgid "NIC %1 (%2) %3" +msgstr "NIC %1 (%2) %3" + +msgid "Render behavior" +msgstr "Renderingsbeteende" + +msgid "Use target framerate:" +msgstr "Använd målbildhatighet:" + +msgid " fps" +msgstr " Bildhastighet" + +msgid "VSync" +msgstr "VSync" + +msgid "Synchronize with video" +msgstr "Synkronisera med bild" + +msgid "Shaders" +msgstr "" + +msgid "Remove" +msgstr "Ta bort" + +msgid "Browse..." +msgstr "Bläddra..." + +msgid "Couldn't create OpenGL context." +msgstr "Kunde inte skapa OpenGL-sammanhang." + +msgid "Couldn't switch to OpenGL context." +msgstr "Kunde inte växla till OpenGL-sammanhang." + +msgid "OpenGL version 3.0 or greater is required. Current version is %1.%2" +msgstr "OpenGL version 3.0 eller högre krävs. Nuvarande version är %1.%2" + +msgid "Error initializing OpenGL" +msgstr "Fel vid initialisering av OpenGL" + +msgid "\nFalling back to software rendering." +msgstr "\nFaller tillbaka på mjukvarurendering." + +msgid "

When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" +msgstr "

Vid val av medieavbildningar (CD-ROM, diskett, osv.) så kommer fönstret att börja i samma mapp som 86Box konfigurationsfil. Denna inställning kommer troligtvis endast göra en skillnad på macOS.

" + +msgid "This machine might have been moved or copied." +msgstr "Denna maskin kan ha flyttats eller kopierats." + +msgid "In order to ensure proper networking functionality, 86Box needs to know if this machine was moved or copied.\n\nSelect \"I Copied It\" if you are not sure." +msgstr "För att säkerställa korrekt funktionalitet av nätverk så behöver 86Box veta om denna maskin har flyttats eller kopierats.\n\nVälj \"Jag kopierade den\" om du är osäker." + +msgid "I Moved It" +msgstr "Jag flyttade den" + +msgid "I Copied It" +msgstr "Jag kopierade den" + +msgid "86Box Monitor #" +msgstr "86Box skärm #" + +msgid "No MCA devices." +msgstr "Inga MCA-enheter." + +msgid "MiB" +msgstr "MiB" + +msgid "Network Card #1" +msgstr "Nätverkskort #1" + +msgid "Network Card #2" +msgstr "Nätverkskort #2" + +msgid "Network Card #3" +msgstr "Nätverkskort #3" + +msgid "Network Card #4" +msgstr "Nätverkskort #4" + +msgid "Mode:" +msgstr "Läge:" + +msgid "Interface:" +msgstr "Gränssnitt:" + +msgid "Adapter:" +msgstr "Adapter:" + +msgid "VDE Socket:" +msgstr "VDE-sockel:" + +msgid "86Box Unit Tester" +msgstr "86Box enhetsprövare" + +msgid "Novell NetWare 2.x Key Card" +msgstr "Novell NetWare 2.x nyckelkort" + +msgid "Serial port passthrough 1" +msgstr "Serieport passthrough 1" + +msgid "Serial port passthrough 2" +msgstr "Serieport passthrough 2" + +msgid "Serial port passthrough 3" +msgstr "Serieport passthrough 3" + +msgid "Serial port passthrough 4" +msgstr "Serieport passthrough 4" + +msgid "Renderer options..." +msgstr "Renderingsalternativ..." + +msgid "Logitech/Microsoft Bus Mouse" +msgstr "Logitech/Microsoft-buss-mus" + +msgid "Microsoft Bus Mouse (InPort)" +msgstr "Microsoft-buss-mus (InPort)" + +msgid "Mouse Systems Serial Mouse" +msgstr "Mouse Systems seriemus" + +msgid "Microsoft Serial Mouse" +msgstr "Microsoft seriemus" + +msgid "Logitech Serial Mouse" +msgstr "Logitech seriemus" + +msgid "PS/2 Mouse" +msgstr "PS/2-mus" + +msgid "3M MicroTouch (Serial)" +msgstr "3M MicroTouch (serie)" + +msgid "[COM] Standard Hayes-compliant Modem" +msgstr "[COM] Standard Hayes-kompatibelt modem" + +msgid "Roland MT-32 Emulation" +msgstr "Roland MT-32 emulering" + +msgid "Roland MT-32 (New) Emulation" +msgstr "Roland MT-32 (ny) emulering" + +msgid "Roland CM-32L Emulation" +msgstr "Roland CM-32L emulering" + +msgid "Roland CM-32LN Emulation" +msgstr "Roland CM-32LN emulering" + +msgid "OPL4-ML Daughterboard" +msgstr "OPL4-ML dotterkort" + +msgid "System MIDI" +msgstr "System-MIDI" + +msgid "MIDI Input Device" +msgstr "Indataenhet för MIDI" + +msgid "BIOS Address" +msgstr "BIOS-adress" + +msgid "Enable BIOS extension ROM Writes" +msgstr "Aktivera ROM-skrivningar för utökat BIOS" + +msgid "Address" +msgstr "Adress" + +msgid "IRQ" +msgstr "IRQ" + +msgid "BIOS Revision" +msgstr "BIOS revision" + +msgid "Translate 26 -> 17" +msgstr "Översätt 26 -> 17" + +msgid "Language" +msgstr "Språk" + +msgid "Enable backlight" +msgstr "Aktivera bakgrundsbelysning" + +msgid "Invert colors" +msgstr "Invertera färger" + +msgid "BIOS size" +msgstr "Storlek på BIOS" + +msgid "Map C0000-C7FFF as UMB" +msgstr "Kartlägg C0000-C7FFF som UMB" + +msgid "Map C8000-CFFFF as UMB" +msgstr "Kartlägg C8000-CFFFF som UMB" + +msgid "Map D0000-D7FFF as UMB" +msgstr "Kartlägg D0000-D7FFF som UMB" + +msgid "Map D8000-DFFFF as UMB" +msgstr "Kartlägg D8000-DFFFF som UMB" + +msgid "Map E0000-E7FFF as UMB" +msgstr "Kartlägg E0000-E7FFF som UMB" + +msgid "Map E8000-EFFFF as UMB" +msgstr "Kartlägg E8000-EFFFF som UMB" + +msgid "JS9 Jumper (JIM)" +msgstr "JS9-bygel (JIM)" + +msgid "MIDI Output Device" +msgstr "Utdataenhet för MIDI" + +msgid "MIDI Real time" +msgstr "Realtid för MIDI" + +msgid "MIDI Thru" +msgstr "MIDI genom" + +msgid "MIDI Clockout" +msgstr "MIDI utklockning" + +msgid "SoundFont" +msgstr "Ljudsnitt" + +msgid "Output Gain" +msgstr "Förstärkning av utmatning" + +msgid "Chorus" +msgstr "Chorus" + +msgid "Chorus Voices" +msgstr "Chorus voices" + +msgid "Chorus Level" +msgstr "Chorus nivå" + +msgid "Chorus Speed" +msgstr "Chorus hastighet" + +msgid "Chorus Depth" +msgstr "Chorus djup" + +msgid "Chorus Waveform" +msgstr "Chorus vågform" + +msgid "Reverb" +msgstr "Reverb" + +msgid "Reverb Room Size" +msgstr "Reverb rumsstorlek" + +msgid "Reverb Damping" +msgstr "Reverb dämpning" + +msgid "Reverb Width" +msgstr "Reverb bredd" + +msgid "Reverb Level" +msgstr "Reverb nivå" + +msgid "Interpolation Method" +msgstr "Interpoleringsmetod" + +msgid "Reverb Output Gain" +msgstr "Reverb utmatningsförstärkning" + +msgid "Reversed stereo" +msgstr "Omvänd stereo" + +msgid "Nice ramp" +msgstr "Nice ramp" + +msgid "Hz" +msgstr "Hz" + +msgid "Buttons" +msgstr "Knappar" + +msgid "Serial Port" +msgstr "Serieport" + +msgid "RTS toggle" +msgstr "RTS-brytare" + +msgid "Revision" +msgstr "Revision" + +msgid "Controller" +msgstr "Styrenhet" + +msgid "Show Crosshair" +msgstr "Visa hårkors" + +msgid "DMA" +msgstr "DMA" + +msgid "MAC Address" +msgstr "MAC-adress" + +msgid "MAC Address OUI" +msgstr "MAC-adress OUI" + +msgid "Enable BIOS" +msgstr "Aktivera BIOS" + +msgid "Baud Rate" +msgstr "Baudhastighet" + +msgid "TCP/IP listening port" +msgstr "TCP/IP lyssningsport" + +msgid "Phonebook File" +msgstr "Telefonsboksfil" + +msgid "Telnet emulation" +msgstr "Telnet-emulering" + +msgid "RAM Address" +msgstr "RAM-adress" + +msgid "RAM size" +msgstr "RAM-storlek" + +msgid "Initial RAM size" +msgstr "Ursprunglig RAM-storlek" + +msgid "Serial Number" +msgstr "Serienummer" + +msgid "Host ID" +msgstr "Värd-ID" + +msgid "FDC Address" +msgstr "Adress till diskettstyrenhet" + +msgid "MPU-401 Address" +msgstr "Adress till MPU-401" + +msgid "MPU-401 IRQ" +msgstr "MPU-401 IRQ" + +msgid "Receive MIDI input" +msgstr "Ta emot MIDI-indata" + +msgid "Low DMA" +msgstr "Låg DMA" + +msgid "Enable Game port" +msgstr "Aktivera spelport" + +msgid "Surround module" +msgstr "Sorround-modul" + +msgid "CODEC" +msgstr "CODEC" + +msgid "Raise CODEC interrupt on CODEC setup (needed by some drivers)" +msgstr "Öka avbrottsnummer för CODEC vid CODEC-installation (krävs av vissa drivrutiner)" + +msgid "SB Address" +msgstr "Adress för SB" + +msgid "WSS IRQ" +msgstr "WSS IRQ" + +msgid "WSS DMA" +msgstr "WSS DMA" + +msgid "Enable OPL" +msgstr "Aktivera OPL" + +msgid "Receive MIDI input (MPU-401)" +msgstr "Ta emot MIDI-indata (MPU-401)" + +msgid "SB low DMA" +msgstr "Låg DMA för SB" + +msgid "6CH variant (6-channel)" +msgstr "6CH-variant (6-kanals)" + +msgid "Enable CMS" +msgstr "Aktivera CMS" + +msgid "Mixer" +msgstr "Mixer" + +msgid "High DMA" +msgstr "Hög DMA" + +msgid "Control PC speaker" +msgstr "Styr PC-speaker" + +msgid "Memory size" +msgstr "Minnesstorlek" + +msgid "EMU8000 Address" +msgstr "Adress till EMU8000" + +msgid "IDE Controller" +msgstr "IDE-styrenhet" + +msgid "Codec" +msgstr "Kodek" + +msgid "GUS type" +msgstr "GUS-typ" + +msgid "Enable 0x04 \"Exit 86Box\" command" +msgstr "Aktivera kommandot 0x04 \"Avsluta 86Box\"" + +msgid "Display type" +msgstr "Skärmtyp" + +msgid "Composite type" +msgstr "Komposittyp" + +msgid "RGB type" +msgstr "RGB-typ" + +msgid "Line doubling type" +msgstr "Linjefördubblingstyp" + +msgid "Snow emulation" +msgstr "Snöemulering" + +msgid "Monitor type" +msgstr "Bildskärmstyp" + +msgid "Character set" +msgstr "Teckenuppsättning" + +msgid "XGA type" +msgstr "XGA-typ" + +msgid "Instance" +msgstr "Instans" + +msgid "MMIO Address" +msgstr "Adress för MMIO" + +msgid "RAMDAC type" +msgstr "RAMDAC-typ" + +msgid "Blend" +msgstr "Blanda" + +msgid "Bilinear filtering" +msgstr "Bilinjär filtrering" + +msgid "Dithering" +msgstr "Dithering" + +msgid "Enable NMI for CGA emulation" +msgstr "Aktivera NMI till CGA-emulering" + +msgid "Voodoo type" +msgstr "Voodoo-typ" + +msgid "Framebuffer memory size" +msgstr "Minnesstorlek för videobuffert" + +msgid "Texture memory size" +msgstr "Minnesstorlek för texturer" + +msgid "Dither subtraction" +msgstr "Dither subtraktion" + +msgid "Screen Filter" +msgstr "Skärmfilter" + +msgid "Render threads" +msgstr "Renderingstrådar" + +msgid "SLI" +msgstr "SLI" + +msgid "Start Address" +msgstr "Startadress" + +msgid "Contiguous Size" +msgstr "Angränsande storlek" + +msgid "I/O Width" +msgstr "I/O-bredd" + +msgid "Transfer Speed" +msgstr "Överföringshastighet" + +msgid "EMS mode" +msgstr "EMS-läge" + +msgid "Address for > 2 MB" +msgstr "Adress till > 2 MB" + +msgid "Frame Address" +msgstr "Bildadress" + +msgid "USA" +msgstr "Förenta staterna" + +msgid "Danish" +msgstr "Danska" + +msgid "Always at selected speed" +msgstr "Alltid vid den valda hastigheten" + +msgid "BIOS setting + Hotkeys (off during POST)" +msgstr "BIOS-inställningar + Snabbtangenter (av under POST)" + +msgid "64 kB starting from F0000" +msgstr "64 kB som börjar från F0000" + +msgid "128 kB starting from E0000 (address MSB inverted, last 64KB first)" +msgstr "128 kB som börjar från E0000 (adress MSB inverterad, de sista 64KB först)" + +msgid "Sine" +msgstr "Sinus" + +msgid "Triangle" +msgstr "Triangel" + +msgid "Linear" +msgstr "Linjär" + +msgid "4th Order" +msgstr "Fjärde ordningen" + +msgid "7th Order" +msgstr "Sjunde ordningen" + +msgid "Non-timed (original)" +msgstr "Ej tajmad (ursprunglig)" + +msgid "45 Hz (JMP2 not populated)" +msgstr "45 Hz (JMP2 ej byglad)" + +msgid "Two" +msgstr "Två" + +msgid "Three" +msgstr "Tre" + +msgid "Wheel" +msgstr "Hjul" + +msgid "Five + Wheel" +msgstr "Fem med hjul" + +msgid "Five + 2 Wheels" +msgstr "" + +msgid "A3 - SMT2 Serial / SMT3(R)V" +msgstr "A3 - SMT2 serie / SMT3(R)V" + +msgid "Q1 - SMT3(R) Serial" +msgstr "Q1 - SMT3(R) serie" + +msgid "8 KB" +msgstr "8 KB" + +msgid "32 KB" +msgstr "32 KB" + +msgid "16 KB" +msgstr "16 KB" + +msgid "64 KB" +msgstr "64 KB" + +msgid "Disable BIOS" +msgstr "Avaktivera BIOS" + +msgid "512 KB" +msgstr "512 KB" + +msgid "2 MB" +msgstr "2 MB" + +msgid "8 MB" +msgstr "8 MB" + +msgid "28 MB" +msgstr "28 MB" + +msgid "1 MB" +msgstr "1 MB" + +msgid "4 MB" +msgstr "4 MB" + +msgid "12 MB" +msgstr "12 MB" + +msgid "16 MB" +msgstr "16 MB" + +msgid "20 MB" +msgstr "20 MB" + +msgid "24 MB" +msgstr "24 MB" + +msgid "SigmaTel STAC9721T (stereo)" +msgstr "SigmaTel STAC9721T (stereo)" + +msgid "Classic" +msgstr "Klassisk" + +msgid "256 KB" +msgstr "256 KB" + +msgid "Composite" +msgstr "Komposit" + +msgid "Old" +msgstr "Gammal" + +msgid "New" +msgstr "Ny" + +msgid "Color (generic)" +msgstr "Färg (allmän)" + +msgid "Green Monochrome" +msgstr "Grön monokrom" + +msgid "Amber Monochrome" +msgstr "Bärnstensfärgad monokrom" + +msgid "Gray Monochrome" +msgstr "Grå monokrom" + +msgid "Color (no brown)" +msgstr "Färg (utan brun)" + +msgid "Color (IBM 5153)" +msgstr "Färg (IBM 5153)" + +msgid "Simple doubling" +msgstr "Enkel fördubbling" + +msgid "sRGB interpolation" +msgstr "sRGB-interpolering" + +msgid "Linear interpolation" +msgstr "Linjär interpolering" + +msgid "128 KB" +msgstr "128 KB" + +msgid "Monochrome (5151/MDA) (white)" +msgstr "Monokrom (5151/MDA) (vit)" + +msgid "Monochrome (5151/MDA) (green)" +msgstr "Monokrom (5151/MDA) (grön)" + +msgid "Monochrome (5151/MDA) (amber)" +msgstr "Monokrom (5151/MDA) (bärnstensfärgad)" + +msgid "Color 40x25 (5153/CGA)" +msgstr "Färg 40x25 (5153/CGA)" + +msgid "Color 80x25 (5153/CGA)" +msgstr "Färg 80x25 (5153/CGA)" + +msgid "Enhanced Color - Normal Mode (5154/ECD)" +msgstr "Utökad färg - normalt läge (5154/ECD)" + +msgid "Enhanced Color - Enhanced Mode (5154/ECD)" +msgstr "Utökad färg - utökat läge (5154/ECD)" + +msgid "Green" +msgstr "Grön" + +msgid "Amber" +msgstr "Bärnstensfärgad" + +msgid "Gray" +msgstr "Grå" + +msgid "Color" +msgstr "Färg" + +msgid "U.S. English" +msgstr "Amerikansk engelska" + +msgid "Scandinavian" +msgstr "Skandinaviska" + +msgid "Other languages" +msgstr "Andra språk" + +msgid "Bochs latest" +msgstr "Bochs senaste" + +msgid "Mono Non-Interlaced" +msgstr "Ej sammanflätad monokrom" + +msgid "Color Interlaced" +msgstr "Sammanflätad färg" + +msgid "Color Non-Interlaced" +msgstr "Ej sammanflätad färg" + +msgid "3Dfx Voodoo Graphics" +msgstr "3Dfx Voodoo-grafik" + +msgid "Obsidian SB50 + Amethyst (2 TMUs)" +msgstr "Obsidian SB50 + Amethyst (2 TMUs)" + +msgid "8-bit" +msgstr "8-bitar" + +msgid "16-bit" +msgstr "16-bitar" + +msgid "Standard (150ns)" +msgstr "Standard (150ns)" + +msgid "High-Speed (120ns)" +msgstr "Höghastighet (120ns)" + +msgid "Enabled" +msgstr "Aktiverad" + +msgid "Standard" +msgstr "Standard" + +msgid "High-Speed" +msgstr "Höghastighet" + +msgid "Stereo LPT DAC" +msgstr "Stereo LPT DAC" + +msgid "Generic Text Printer" +msgstr "Allmän textskrivare" + +msgid "Generic ESC/P Dot-Matrix Printer" +msgstr "Allmän ESC/P punktmatrisskrivare" + +msgid "Generic PostScript Printer" +msgstr "Allmän PostScript-skrivare" + +msgid "Generic PCL5e Printer" +msgstr "Allmän PCL5e-skrivare" + +msgid "Parallel Line Internet Protocol" +msgstr "Parallel Line Internet Protocol" + +msgid "Protection Dongle for Savage Quest" +msgstr "Skyddsdongel till Savage Quest" + +msgid "Serial Passthrough Device" +msgstr "Seriepassthrough-enhet" + +msgid "Passthrough Mode" +msgstr "Passthrough-läge" + +msgid "Host Serial Device" +msgstr "Värd-serieenhet" + +msgid "Name of pipe" +msgstr "Namn på pipe" + +msgid "Data bits" +msgstr "Databitar" + +msgid "Stop bits" +msgstr "Stopbitar" + +msgid "Baud Rate of Passthrough" +msgstr "Passthroughns Baudhastighet" + +msgid "Named Pipe (Server)" +msgstr "Namngiven pipe (server)" + +msgid "Host Serial Passthrough" +msgstr "Värd-seriepassthrough" + +msgid "E&ject %1" +msgstr "M&ata ut %1" + +msgid "&Unmute" +msgstr "&Avtysta" + +msgid "Softfloat FPU" +msgstr "Softfloat flyttalsprocessor" + +msgid "High performance impact" +msgstr "Hög påverkan på prestanda" + +msgid "[Generic] RAM Disk (max. speed)" +msgstr "[Allmän] RAM-disk (max hastighet)" + +msgid "[Generic] 1989 (3500 RPM)" +msgstr "[Allmän] 1989 (3500 varv/min)" + +msgid "[Generic] 1992 (3600 RPM)" +msgstr "[Allmän] 1992 (3600 varv/min)" + +msgid "[Generic] 1994 (4500 RPM)" +msgstr "[Allmän] 1994 (4500 varv/min)" + +msgid "[Generic] 1996 (5400 RPM)" +msgstr "[Allmän] 1996 (5400 varv/min)" + +msgid "[Generic] 1997 (5400 RPM)" +msgstr "[Allmän] 1997 (5400 varv/min)" + +msgid "[Generic] 1998 (5400 RPM)" +msgstr "[Allmän] 1998 (5400 varv/min)" + +msgid "[Generic] 2000 (7200 RPM)" +msgstr "[Allmän] 2000 (7200 varv/min)" + +msgid "IBM 8514/A clone (ISA)" +msgstr "IBM 8514/A-klon (ISA)" + +msgid "Vendor" +msgstr "Leverantör" + +msgid "30 Hz (JMP2 = 1)" +msgstr "30 Hz (JMP2 = 1)" + +msgid "60 Hz (JMP2 = 2)" +msgstr "60 Hz (JMP2 = 2)" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Allmän minnesexpansion för PC/XT" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Allmän minnesexpansion PC/AT" + +msgid "Unable to find Dot-Matrix fonts" +msgstr "Kunde inte hitta typsnitt för punktmatris" + +msgid "TrueType fonts in the \"roms/printer/fonts\" directory are required for the emulation of the Generic ESC/P Dot-Matrix Printer." +msgstr "TrueType-typsnitt i mappen \"roms/printer/fonts\" krävs för emulering av den allmänna ESC/P punktmatrisskrivaren." + +msgid "Inhibit multimedia keys" +msgstr "Hindra multimediatangenter" + +msgid "Ask for confirmation before saving settings" +msgstr "Bekräfta innan inställningarna sparas" + +msgid "Ask for confirmation before hard resetting" +msgstr "Bekräfta innan hård omstart" + +msgid "Ask for confirmation before quitting" +msgstr "Bekräfta innan avslut" + +msgid "Options" +msgstr "Alternativ" + +msgid "Model" +msgstr "Modell" + +msgid "Model:" +msgstr "Modell:" + +msgid "Failed to initialize Vulkan renderer." +msgstr "Kunde inte initialisera Vulkan-renderaren" + +msgid "GLSL Error" +msgstr "GLSL-fel" + +msgid "Could not load shader: %1" +msgstr "Kunde inte ladda shader: %1" + +msgid "OpenGL version 3.0 or greater is required. Current GLSL version is %1.%2" +msgstr "OpenGL version 3.0 eller högre krävs. Nuvarande GLSL-version är %1.%2" + +msgid "Could not load texture: %1" +msgstr "Kunde inte ladda textur: %1" + +msgid "Could not compile shader:\n\n%1" +msgstr "Kunde inte kompilera shader:\n\n%1" + +msgid "Program not linked:\n\n%1" +msgstr "Program inte länkat:\n\n%1" + +msgid "Shader Manager" +msgstr "Shader-hanterare" + +msgid "Shader Configuration" +msgstr "Shader-inställningar" + +msgid "Add" +msgstr "Lägg till" + +msgid "Move up" +msgstr "Flytta upp" + +msgid "Move down" +msgstr "Flytta ner" + +msgid "Could not load file %1" +msgstr "Kunde inte ladda fil %1" diff --git a/src/qt/languages/tr-TR.po b/src/qt/languages/tr-TR.po index 3a0cc2b96..73d46a007 100644 --- a/src/qt/languages/tr-TR.po +++ b/src/qt/languages/tr-TR.po @@ -18,8 +18,8 @@ msgstr "&Sağ CTRL tuşunu sol ALT tuşu olarak ayarla" msgid "&Hard Reset..." msgstr "Yeniden başlamaya &zorla" -msgid "&Ctrl+Alt+Del\tCtrl+F12" -msgstr "&Ctrl+Alt+Del\tCtrl+F12" +msgid "&Ctrl+Alt+Del" +msgstr "&Ctrl+Alt+Del" msgid "Ctrl+Alt+&Esc" msgstr "Ctrl+&Alt+Esc" @@ -111,8 +111,8 @@ msgstr "Doğ&rusal" msgid "Hi&DPI scaling" msgstr "HiDPI ölçekle&mesi" -msgid "&Fullscreen\tCtrl+Alt+PgUp" -msgstr "Tam ekran\tCtrl+Alt+Pg&Up" +msgid "&Fullscreen" +msgstr "Tam ekran" msgid "Fullscreen &stretch mode" msgstr "Tam e&kran germe modu" @@ -186,8 +186,8 @@ msgstr "&Ayarlar..." msgid "&Update status bar icons" msgstr "Durum &çubuğu simgelerini güncelle" -msgid "Take s&creenshot\tCtrl+F11" -msgstr "&Ekran görüntüsü al\tCtrl+F11" +msgid "Take s&creenshot" +msgstr "&Ekran görüntüsü al" msgid "&Preferences..." msgstr "&Tercihler..." @@ -195,14 +195,17 @@ msgstr "&Tercihler..." msgid "Enable &Discord integration" msgstr "&Discord entegrasyonunu etkinleştir" +msgid "S&ound" +msgstr "&Ses" + msgid "Sound &gain..." msgstr "&Ses düzeyi artışı..." -msgid "Begin trace\tCtrl+T" -msgstr "İzlemeyi başlat\tCtrl+T" +msgid "Begin trace" +msgstr "İzlemeyi başlat" -msgid "End trace\tCtrl+T" -msgstr "İzlemeyi bitir\tCtrl+T" +msgid "End trace" +msgstr "İzlemeyi bitir" msgid "&Help" msgstr "&Yardım" @@ -249,8 +252,8 @@ msgstr "&Sesi kapat" msgid "E&mpty" msgstr "İmajı &çıkar" -msgid "&Reload previous image" -msgstr "&Önceki imajı yeniden seç" +msgid "Reload previous image" +msgstr "Önceki imajı yeniden seç" msgid "&Folder..." msgstr "&Klasör..." @@ -306,18 +309,12 @@ msgstr "Tamam" msgid "Cancel" msgstr "İptal" -msgid "Save these settings as &global defaults" -msgstr "Ayarları &varsayılan olarak kaydet" - msgid "&Default" msgstr "&Varsayılan" msgid "Language:" msgstr "Dil:" -msgid "Icon set:" -msgstr "Simge seti:" - msgid "Gain" msgstr "Artış" @@ -453,15 +450,6 @@ msgstr "Nuked (daha doğru)" msgid "YMFM (faster)" msgstr "YMFM (daha hızlı)" -msgid "Network type:" -msgstr "Ağ türü:" - -msgid "PCap device:" -msgstr "PCap cihazı:" - -msgid "Network adapter:" -msgstr "Ağ cihazı:" - msgid "COM1 Device:" msgstr "COM1 cihazı:" @@ -642,14 +630,11 @@ msgstr "Kritik hata" msgid " - PAUSED" msgstr " - DURAKLATILDI" -msgid "Press Ctrl+Alt+PgDn to return to windowed mode." -msgstr "Pencere moduna geri dönmek için Ctrl+Alt+PgDn tuşlarına basın." - msgid "Speed" msgstr "Hız" -msgid "ZIP %03i %i (%s): %ls" -msgstr "ZIP %03i %i (%s): %ls" +msgid "ZIP %1 %2 (%3): %4" +msgstr "ZIP %1 %2 (%3): %4" msgid "ZIP images" msgstr "ZIP imajları" @@ -687,8 +672,11 @@ msgstr "\"%hs\" makinesi roms/machines klasöründe gerekli ROM imajlarının me msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "\"%hs\" ekran kartı roms/video klasöründe gerekli ROM imajlarının mevcut olmaması nedeniyle kullanılamıyor. Bundan dolayı kullanılabilen bir ekran kartına geçiş yapılacaktır." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "\"%hs\" ikinci ekran kartı roms/video klasöründe gerekli ROM imajlarının mevcut olmaması nedeniyle kullanılamıyor. Bundan dolayı kullanılabilen bir ekran kartına geçiş yapılacaktır." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "\"%hs\" ikinci ekran kartı roms/video klasöründe gerekli ROM imajlarının mevcut olmaması nedeniyle kullanılamıyor. İkinci ekran kartı devre dışı bırakılır." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "\"%hs\" cihazı gerekli ROM imajlarının mevcut olmaması nedeniyle kullanılamıyor. Cihaz yok sayılıyor." msgid "Machine" msgstr "Makine" @@ -750,14 +738,11 @@ msgstr "S" msgid "KB" msgstr "KB" -msgid "Could not initialize the video renderer." -msgstr "Video işleyici başlatılamadı." - msgid "Default" msgstr "Varsayılan" -msgid "%i Wait state(s)" -msgstr "%i Bekleme durumları" +msgid "%1 Wait state(s)" +msgstr "%1 Bekleme durumları" msgid "Type" msgstr "Tür" @@ -801,11 +786,11 @@ msgstr "Thrustmaster Flight Control System" msgid "None" msgstr "Hiçbiri" -msgid "%u MB (CHS: %i, %i, %i)" -msgstr "%u MB (CHS: %i, %i, %i)" +msgid "%1 MB (CHS: %2, %3, %4)" +msgstr "%1 MB (CHS: %2, %3, %4)" -msgid "Floppy %i (%s): %ls" -msgstr "Disket %i (%s): %ls" +msgid "Floppy %1 (%2): %3" +msgstr "Disket %1 (%2): %3" msgid "Advanced sector images" msgstr "Gelişmiş sektör imajları" @@ -825,8 +810,8 @@ msgstr "Ghostscript başlatılamadı" msgid "Unable to initialize GhostPCL" msgstr "GhostPCL başlatılamadı" -msgid "MO %i (%ls): %ls" -msgstr "MO %i (%ls): %ls" +msgid "MO %1 (%2): %3" +msgstr "MO %1 (%2): %3" msgid "MO images" msgstr "MO imajları" @@ -876,9 +861,6 @@ msgstr "%1 PostScript dosyalarının otomatik olarak PDF dosyalarına çevirilme msgid "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as Printer Command Language (.pcl) files." msgstr "%1 PCL dosyalarının otomatik olarak PDF dosyalarına çevirilmesi için gereklidir.\n\nBu bulunmadığından dolayı genel PostScript yazıcısına gönderilen tüm dökümanlar Printer Command Language (.pcl) dosyası olarak kaydedilecektir." -msgid "Entering fullscreen mode" -msgstr "Tam ekran moduna geçiş yapılıyor" - msgid "Don't show this message again" msgstr "Bu mesajı bir daha gösterme" @@ -900,11 +882,8 @@ msgstr "%1 cihaz konfigürasyonu" msgid "Monitor in sleep mode" msgstr "Monitör uyku modunda" -msgid "OpenGL Shaders" -msgstr "OpenGL gölgelendiricileri" - -msgid "OpenGL options" -msgstr "OpenGL ayarları" +msgid "GLSL shaders" +msgstr "GLSL gölgelendiricileri" msgid "You are loading an unsupported configuration" msgstr "Desteklenmeyen bir konfigürasyon kullanıyorsunuz" @@ -915,24 +894,18 @@ msgstr "Seçtiğiniz makineye uygun işlemci türü filtrelemesi bu emüle edile msgid "Continue" msgstr "Devam et" -msgid "Cassette: %s" -msgstr "Kaset: %s" +msgid "Cassette: %1" +msgstr "Kaset: %1" msgid "Cassette images" msgstr "Kaset imajları" -msgid "Cartridge %i: %ls" -msgstr "Kartuş %i: %ls" +msgid "Cartridge %1: %2" +msgstr "Kartuş %1: %2" msgid "Cartridge images" msgstr "Kartuş imajları" -msgid "Error initializing renderer" -msgstr "İşleyici başlatılırken hata oluştu" - -msgid "OpenGL (3.0 Core) renderer could not be initialized. Use another renderer." -msgstr "OpenGL (3.0 Core) işleyici başlatılamadı. Başka bir görüntüleyici kullanın." - msgid "Resume execution" msgstr "Çalıştırmaya devam et" @@ -1095,8 +1068,8 @@ msgstr "IDE" msgid "ATAPI" msgstr "ATAPI" -msgid "CD-ROM %i (%s): %s" -msgstr "CD-ROM %i (%s): %s" +msgid "CD-ROM %1 (%2): %3" +msgstr "CD-ROM %1 (%2): %3" msgid "160 KB" msgstr "160 KB" @@ -1275,9 +1248,6 @@ msgstr "İmaj geçmişini temizleyin" msgid "Create..." msgstr "Oluştur..." -msgid "previous image" -msgstr "önceki imaj" - msgid "Host CD/DVD Drive (%1)" msgstr "Ana bilgisayar CD/DVD sürücüsü (%1)" @@ -1287,23 +1257,8 @@ msgstr "Bilinmeyen veri yolu" msgid "Null Driver" msgstr "Null sürücü" -msgid "NIC %02i (%ls) %ls" -msgstr "NIC %02i (%ls) %ls" - -msgid "Error opening \"%1\": %2" -msgstr "\"%1\": %2 açılırken hata oluştu" - -msgid "Error compiling vertex shader in file \"%1\"" -msgstr "\"%1\" dosyasında tepe gölgelendirici derlenirken hata oluştu" - -msgid "Error compiling fragment shader in file \"%1\"" -msgstr "\"%1\" dosyasında parça gölgelendirici derlenirken hata oluştu" - -msgid "Error linking shader program in file \"%1\"" -msgstr "\"%1\" dosyasında gölgelendirici programı bağlanırken hata oluştu" - -msgid "OpenGL 3.0 renderer options" -msgstr "OpenGL 3.0 işleyici seçenekleri" +msgid "NIC %1 (%2) %3" +msgstr "NIC %1 (%2) %3" msgid "Render behavior" msgstr "İşleyiş davranışı" @@ -1317,9 +1272,6 @@ msgstr " fps" msgid "VSync" msgstr "VSync" -msgid "<html><head/><body><p>Render each frame immediately, in sync with the emulated display.</p><p><span style=" font-style:italic;">This is the recommended option if the shaders in use don't utilize frametime for animated effects.</span></p></body></html>" -msgstr "<html><head/><body><p>Emüle edilen ekranla senkronize olarak her kareyi hemen işleyin.</p><p><span style=" font-style:italic;">Kullanılan gölgelendiriciler animasyonlu efektler için kare zamanını kullanmıyorsa bu önerilen seçenektir.</span></p></body></html>" - msgid "Synchronize with video" msgstr "Video ile senkronize et" @@ -1329,21 +1281,9 @@ msgstr "Gölgelendiriciler" msgid "Remove" msgstr "Kaldır" -msgid "No shader selected" -msgstr "Gölgelendirici seçili değil" - msgid "Browse..." msgstr "Göz at..." -msgid "Shader error" -msgstr "Gölgelendirici hatası" - -msgid "Could not load shaders." -msgstr "Gölgelendiriciler yüklenemedi." - -msgid "More information in details." -msgstr "Daha fazla bilgi detaylardadır." - msgid "Couldn't create OpenGL context." msgstr "OpenGL bağlamı oluşturulamadı." @@ -1353,20 +1293,14 @@ msgstr "OpenGL bağlamına geçilemedi." msgid "OpenGL version 3.0 or greater is required. Current version is %1.%2" msgstr "OpenGL sürüm 3.0 veya üstü gereklidir. Geçerli sürüm %1.%2" -msgid "OpenGL initialization failed. Error %1." -msgstr "OpenGL başlatılamadı. Hata %1." - msgid "Error initializing OpenGL" msgstr "OpenGL başlatılırken hata oluştu" -msgid "Falling back to software rendering.\n" -msgstr "Yazılım işleyicisine geri dönülüyor.\n" +msgid "\nFalling back to software rendering." +msgstr "\nYazılım işleyicisine geri dönülüyor." -msgid "Allocating memory for unpack buffer failed.\n" -msgstr "Paket açma arabelleği için bellek ayırma başarısız oldu.\n" - -msgid "<html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html>" -msgstr "<html><head/><body><p>Medya görüntüsü (CD-ROM, disket, vb.) seçme diyaloğu 86Box yapılandırma dosyasıyla aynı dizinde başlayacaktır. Bu ayar muhtemelen sadece macOS üzerinde bir fark meydana getirecektir.</p></body></html>" +msgid "

When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" +msgstr "

Medya görüntüsü (CD-ROM, disket, vb.) seçme diyaloğu 86Box yapılandırma dosyasıyla aynı dizinde başlayacaktır. Bu ayar muhtemelen sadece macOS üzerinde bir fark meydana getirecektir.

" msgid "This machine might have been moved or copied." msgstr "Bu makine taşınmış veya kopyalanmış olabilir." @@ -1401,17 +1335,17 @@ msgstr "Ağ kartı 3" msgid "Network Card #4" msgstr "Ağ kartı 4" -msgid "Mode" -msgstr "Mod" +msgid "Mode:" +msgstr "Mod:" -msgid "Interface" -msgstr "Arayüz" +msgid "Interface:" +msgstr "Arayüz:" -msgid "Adapter" -msgstr "Adaptör" +msgid "Adapter:" +msgstr "Adaptör:" -msgid "VDE Socket" -msgstr "VDE soketi" +msgid "VDE Socket:" +msgstr "VDE soketi:" msgid "86Box Unit Tester" msgstr "86Box birim test cihazı" @@ -1431,9 +1365,6 @@ msgstr "Seri port geçişi 3" msgid "Serial port passthrough 4" msgstr "Seri port geçişi 4" -msgid "Vision Systems LBA Enhancer" -msgstr "Vision Systems LBA Enhancer" - msgid "Renderer options..." msgstr "İşleyici seçenekleri..." @@ -1872,6 +1803,9 @@ msgstr "Tekerlek" msgid "Five + Wheel" msgstr "Beş + tekerlek" +msgid "Five + 2 Wheels" +msgstr "" + msgid "A3 - SMT2 Serial / SMT3(R)V" msgstr "A3 - SMT2 seri / SMT3(R)V" @@ -2100,8 +2034,8 @@ msgstr "Adlandırılmış boru (Sunucu)" msgid "Host Serial Passthrough" msgstr "Ana bilgisayar seri port geçişi" -msgid "Eject %s" -msgstr "%s diskini çıkar" +msgid "E&ject %1" +msgstr "%1 diskini &çıkar" msgid "&Unmute" msgstr "&Sesi aç" @@ -2112,11 +2046,104 @@ msgstr "Softfloat FPU" msgid "High performance impact" msgstr "Ciddi performans düşüklüğüne neden olabilir" -msgid "RAM Disk (max. speed)" -msgstr "RAM Disk (maks. hız)" +msgid "[Generic] RAM Disk (max. speed)" +msgstr "[Generic] RAM Disk (maks. hız)" + +msgid "[Generic] 1989 (3500 RPM)" +msgstr "" + +msgid "[Generic] 1992 (3600 RPM)" +msgstr "" + +msgid "[Generic] 1994 (4500 RPM)" +msgstr "" + +msgid "[Generic] 1996 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1997 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1998 (5400 RPM)" +msgstr "" + +msgid "[Generic] 2000 (7200 RPM)" +msgstr "" msgid "IBM 8514/A clone (ISA)" msgstr "IBM 8514/A klonu (ISA)" msgid "Vendor" msgstr "Üretici" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Sıradan PC/XT bellek artırma" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Sıradan PC/AT bellek artırma" + +msgid "Unable to find Dot-Matrix fonts" +msgstr "Dot Matrix yazı tipleri bulunamıyor" + +msgid "TrueType fonts in the \"roms/printer/fonts\" directory are required for the emulation of the Generic ESC/P Dot-Matrix Printer." +msgstr "Sıradan ESC/P Dot Matrix Yazıcının emülasyonu için \"roms/printer/fonts\" dizinindeki TrueType yazı tipleri gereklidir." + +msgid "Inhibit multimedia keys" +msgstr "" + +msgid "Ask for confirmation before saving settings" +msgstr "" + +msgid "Ask for confirmation before hard resetting" +msgstr "" + +msgid "Ask for confirmation before quitting" +msgstr "" + +msgid "Options" +msgstr "" + +msgid "Model" +msgstr "" + +msgid "Model:" +msgstr "" + +msgid "Failed to initialize Vulkan renderer." +msgstr "" + +msgid "GLSL Error" +msgstr "" + +msgid "Could not load shader: %1" +msgstr "" + +msgid "OpenGL version 3.0 or greater is required. Current GLSL version is %1.%2" +msgstr "" + +msgid "Could not load texture: %1" +msgstr "" + +msgid "Could not compile shader:\n\n%1" +msgstr "" + +msgid "Program not linked:\n\n%1" +msgstr "" + +msgid "Shader Manager" +msgstr "" + +msgid "Shader Configuration" +msgstr "" + +msgid "Add" +msgstr "" + +msgid "Move up" +msgstr "" + +msgid "Move down" +msgstr "" + +msgid "Could not load file %1" +msgstr "" diff --git a/src/qt/languages/uk-UA.po b/src/qt/languages/uk-UA.po index 6cef7c294..49a8acf00 100644 --- a/src/qt/languages/uk-UA.po +++ b/src/qt/languages/uk-UA.po @@ -18,8 +18,8 @@ msgstr "&Правий CTRL - це лівий ALT" msgid "&Hard Reset..." msgstr "&Холодне перезавантаження..." -msgid "&Ctrl+Alt+Del\tCtrl+F12" -msgstr "&Ctrl+Alt+Del\tCtrl+F12" +msgid "&Ctrl+Alt+Del" +msgstr "&Ctrl+Alt+Del" msgid "Ctrl+Alt+&Esc" msgstr "Ctrl+Alt+&Esc" @@ -111,8 +111,8 @@ msgstr "&Лінійний" msgid "Hi&DPI scaling" msgstr "Масштабування Hi&DPI" -msgid "&Fullscreen\tCtrl+Alt+PgUp" -msgstr "&Повноекранний режим\tCtrl+Alt+PgUp" +msgid "&Fullscreen" +msgstr "&Повноекранний режим" msgid "Fullscreen &stretch mode" msgstr "&Розстягування у повноекранному режимі" @@ -186,8 +186,11 @@ msgstr "&Налаштування машини..." msgid "&Update status bar icons" msgstr "&Обновлення значків рядка стану" -msgid "Take s&creenshot\tCtrl+F11" -msgstr "Зробити &знімок\tCtrl+F11" +msgid "Take s&creenshot" +msgstr "Зробити &знімок" + +msgid "S&ound" +msgstr "&Звук" msgid "&Preferences..." msgstr "&Параметри..." @@ -198,11 +201,11 @@ msgstr "Увімкнути інтеграцію &Discord" msgid "Sound &gain..." msgstr "&Посилення звуку..." -msgid "Begin trace\tCtrl+T" -msgstr "Почати трасування\tCtrl+T" +msgid "Begin trace" +msgstr "Почати трасування" -msgid "End trace\tCtrl+T" -msgstr "Завершити трасування\tCtrl+T" +msgid "End trace" +msgstr "Завершити трасування" msgid "&Help" msgstr "&Допомога" @@ -249,8 +252,8 @@ msgstr "&Відключити звук" msgid "E&mpty" msgstr "&Пустий" -msgid "&Reload previous image" -msgstr "&Знову завантажити попередній образ" +msgid "Reload previous image" +msgstr "Знову завантажити попередній образ" msgid "&Folder..." msgstr "&Тека..." @@ -306,18 +309,12 @@ msgstr "OK" msgid "Cancel" msgstr "Відміна" -msgid "Save these settings as &global defaults" -msgstr "Зберегти ці параметри як &глобальні за замовчуванням" - msgid "&Default" msgstr "&За замовчуванням" msgid "Language:" msgstr "Мова:" -msgid "Icon set:" -msgstr "Набір іконок:" - msgid "Gain" msgstr "Посилення" @@ -453,15 +450,6 @@ msgstr "Nuked (більш точний)" msgid "YMFM (faster)" msgstr "YMFM (швидший)" -msgid "Network type:" -msgstr "Тип мережі:" - -msgid "PCap device:" -msgstr "Пристрій PCap:" - -msgid "Network adapter:" -msgstr "Мережевий адаптер:" - msgid "COM1 Device:" msgstr "Пристрій COM1:" @@ -642,14 +630,11 @@ msgstr "Непереробна помилка" msgid " - PAUSED" msgstr " - ПРИЗУПИНЕННЯ" -msgid "Press Ctrl+Alt+PgDn to return to windowed mode." -msgstr "Натисніть Ctrl+Alt+PgDn для повернення у віконний режим." - msgid "Speed" msgstr "Швидкість" -msgid "ZIP %03i %i (%s): %ls" -msgstr "ZIP %03i %i (%s): %ls" +msgid "ZIP %1 %2 (%3): %4" +msgstr "ZIP %1 %2 (%3): %4" msgid "ZIP images" msgstr "Образи ZIP" @@ -687,8 +672,11 @@ msgstr "Системна плата \"%hs\" недоступна через ві msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "Відеокарта \"%hs\" недоступна через відсутність файлу її ПЗУ в каталозі roms/video. Переключення на доступну відеокарту." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Відеокарта 2 \"%hs\" недоступна через відсутність файлу її ПЗУ в каталозі roms/video. Переключення на доступну відеокарту." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "Відеокарта 2 \"%hs\" недоступна через відсутність файлу її ПЗУ в каталозі roms/video. Відключення другої відеокарти." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Пристрій \"%hs\" недоступний через відсутність файлу його ПЗУ. Ігнорування пристрою." msgid "Machine" msgstr "Комп'ютер" @@ -750,14 +738,11 @@ msgstr "S" msgid "KB" msgstr "КБ" -msgid "Could not initialize the video renderer." -msgstr "Не вдалося ініціалізувати рендер відео." - msgid "Default" msgstr "За замовчуванням" -msgid "%i Wait state(s)" -msgstr "%i WS" +msgid "%1 Wait state(s)" +msgstr "%1 WS" msgid "Type" msgstr "Тип" @@ -801,11 +786,11 @@ msgstr "Система управління польотом Thrustmaster" msgid "None" msgstr "Ні" -msgid "%u MB (CHS: %i, %i, %i)" -msgstr "%u МБ (CHS: %i, %i, %i)" +msgid "%1 MB (CHS: %2, %3, %4)" +msgstr "%1 МБ (CHS: %2, %3, %4)" -msgid "Floppy %i (%s): %ls" -msgstr "Дисковод %i (%s): %ls" +msgid "Floppy %1 (%2): %3" +msgstr "Дисковод %1 (%2): %3" msgid "Advanced sector images" msgstr "Розширені образи секторів" @@ -825,8 +810,8 @@ msgstr "Неможливо ініціалізувати Ghostscript" msgid "Unable to initialize GhostPCL" msgstr "Неможливо ініціалізувати GhostPCL" -msgid "MO %i (%ls): %ls" -msgstr "Магнітооптичний %i (%ls): %ls" +msgid "MO %1 (%2): %3" +msgstr "Магнітооптичний %1 (%2): %3" msgid "MO images" msgstr "Образи магнітооптичних дисків" @@ -876,9 +861,6 @@ msgstr "%1 потрібно для автоматичного перетворе msgid "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PCL printer will be saved as Printer Command Language (.pcl) files." msgstr "%1 потрібно для автоматичного перетворення файлів PCL в PDF.\n\nВсі документи, відправлені на загальний принтер PCL, будуть збережені у вигляді файлів Printer Command Language (.ps)." -msgid "Entering fullscreen mode" -msgstr "Вхід у повноекранний режим" - msgid "Don't show this message again" msgstr "Більше не показувати це повідомлення" @@ -900,11 +882,8 @@ msgstr "Конфігурація пристрою %1" msgid "Monitor in sleep mode" msgstr "Монітор у сплячому режимі" -msgid "OpenGL Shaders" -msgstr "Шейдери OpenGL" - -msgid "OpenGL options" -msgstr "Параметри OpenGL" +msgid "GLSL shaders" +msgstr "Шейдери GLSL" msgid "You are loading an unsupported configuration" msgstr "Ви завантажуєте непідтримувану конфігурацію" @@ -915,24 +894,18 @@ msgstr "Вибір типів ЦП для цієї системної плати msgid "Continue" msgstr "Продовжити" -msgid "Cassette: %s" -msgstr "Касета: %s" +msgid "Cassette: %1" +msgstr "Касета: %1" msgid "Cassette images" msgstr "Образи касет" -msgid "Cartridge %i: %ls" -msgstr "Картридж %i: %ls" +msgid "Cartridge %1: %2" +msgstr "Картридж %1: %2" msgid "Cartridge images" msgstr "Образи картриджів" -msgid "Error initializing renderer" -msgstr "Помилка ініціалізації рендерера" - -msgid "OpenGL (3.0 Core) renderer could not be initialized. Use another renderer." -msgstr "Неможливо ініціалізувати рендерер OpenGL (3.0). Будь ласка, використовуйте інший рендерер." - msgid "Resume execution" msgstr "Відновити виконання" @@ -1095,8 +1068,8 @@ msgstr "IDE" msgid "ATAPI" msgstr "ATAPI" -msgid "CD-ROM %i (%s): %s" -msgstr "CD-ROM %i (%s): %s" +msgid "CD-ROM %1 (%2): %3" +msgstr "CD-ROM %1 (%2): %3" msgid "160 KB" msgstr "160 КБ" @@ -1275,9 +1248,6 @@ msgstr "Очистити історію образів" msgid "Create..." msgstr "Створити..." -msgid "previous image" -msgstr "попередній образ" - msgid "Host CD/DVD Drive (%1)" msgstr "CD/DVD привід хоста (%1)" @@ -1287,23 +1257,8 @@ msgstr "Невідома шина" msgid "Null Driver" msgstr "Нульовий драйвер" -msgid "NIC %02i (%ls) %ls" -msgstr "NIC %02i (%ls) %ls" - -msgid "Error opening \"%1\": %2" -msgstr "Помилка відкриття \"%1\": %2" - -msgid "Error compiling vertex shader in file \"%1\"" -msgstr "Помилка компіляції вершинного шейдера у файлі \"%1\"." - -msgid "Error compiling fragment shader in file \"%1\"" -msgstr "Помилка компіляції фрагментного шейдера у файлі \"%1\"." - -msgid "Error linking shader program in file \"%1\"" -msgstr "Помилка зв'язування шейдерної програми у файлі \"%1\"." - -msgid "OpenGL 3.0 renderer options" -msgstr "Параметри рендерингу OpenGL 3.0" +msgid "NIC %1 (%2) %3" +msgstr "NIC %1 (%2) %3" msgid "Render behavior" msgstr "Поведінка рендерингу" @@ -1317,9 +1272,6 @@ msgstr " fps" msgid "VSync" msgstr "VSync" -msgid "<html><head/><body><p>Render each frame immediately, in sync with the emulated display.</p><p><span style=" font-style:italic;">This is the recommended option if the shaders in use don't utilize frametime for animated effects.</span></p></body></html>" -msgstr "<html><head/><body><p>Відображати кожен кадр миттєво, синхронно з емульованим дисплеєм.</p><p><span style=" font-style:italic;">Це рекомендований варіант, якщо використовувані шейдери не використовують час кадру для анімованих ефектів.</span></p></body></html>" - msgid "Synchronize with video" msgstr "Синхронізація з відео" @@ -1329,21 +1281,9 @@ msgstr "Шейдери" msgid "Remove" msgstr "Видалити" -msgid "No shader selected" -msgstr "Не вибрано шейдер" - msgid "Browse..." msgstr "Переглянути..." -msgid "Shader error" -msgstr "Помилка шейдеру" - -msgid "Could not load shaders." -msgstr "Не вдалося завантажити шейдери." - -msgid "More information in details." -msgstr "Більше інформації в деталях." - msgid "Couldn't create OpenGL context." msgstr "Не вдалося створити контекст OpenGL." @@ -1353,20 +1293,14 @@ msgstr "Не вдалося переключитися на контекст Ope msgid "OpenGL version 3.0 or greater is required. Current version is %1.%2" msgstr "Потрібна версія OpenGL 3.0 або новіша. Поточна версія %1.%2" -msgid "OpenGL initialization failed. Error %1." -msgstr "Не вдалося ініціалізувати OpenGL. Помилка %1." - msgid "Error initializing OpenGL" msgstr "Помилка ініціалізації OpenGL" -msgid "Falling back to software rendering.\n" -msgstr "Повернення до програмного рендерингу.\n" +msgid "\nFalling back to software rendering." +msgstr "\nПовернення до програмного рендерингу." -msgid "Allocating memory for unpack buffer failed.\n" -msgstr "Не вдалося виділити пам'ять для буфера розпакування.\n" - -msgid "<html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html>" -msgstr "<html><head/><body><p>При виборі медіа-образів (CD-ROM, дискета і т.д.) діалогове вікно буде відкриватися в тому ж каталозі, що і файл конфігурації 86Box. Цей параметр, швидше за все, матиме значення лише на macOS.</p></body></html>" +msgid "

When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" +msgstr "

При виборі медіа-образів (CD-ROM, дискета і т.д.) діалогове вікно буде відкриватися в тому ж каталозі, що і файл конфігурації 86Box. Цей параметр, швидше за все, матиме значення лише на macOS.

" msgid "This machine might have been moved or copied." msgstr "Цю машину могли перемістити або скопіювати." @@ -1401,17 +1335,17 @@ msgstr "Мережева карта 3" msgid "Network Card #4" msgstr "Мережева карта 4" -msgid "Mode" -msgstr "Режим" +msgid "Mode:" +msgstr "Режим:" -msgid "Interface" -msgstr "Інтерфейс" +msgid "Interface:" +msgstr "Інтерфейс:" -msgid "Adapter" -msgstr "Адаптер" +msgid "Adapter:" +msgstr "Адаптер:" -msgid "VDE Socket" -msgstr "VDE сокет" +msgid "VDE Socket:" +msgstr "VDE сокет:" msgid "86Box Unit Tester" msgstr "Тестер блоків 86Box" @@ -1431,9 +1365,6 @@ msgstr "Пропуск послідовного порту 3" msgid "Serial port passthrough 4" msgstr "Пропуск послідовного порту 4" -msgid "Vision Systems LBA Enhancer" -msgstr "Vision Systems LBA Enhancer" - msgid "Renderer options..." msgstr "Параметри рендерингу..." @@ -1872,6 +1803,9 @@ msgstr "Колесо" msgid "Five + Wheel" msgstr "П'ять + колесо" +msgid "Five + 2 Wheels" +msgstr "" + msgid "A3 - SMT2 Serial / SMT3(R)V" msgstr "A3 - SMT2 послідовна / SMT3(R)V" @@ -2100,8 +2034,8 @@ msgstr "Іменований пайп (сервер)" msgid "Host Serial Passthrough" msgstr "Пропуск послідовного порту хоста" -msgid "Eject %s" -msgstr "Вилучити %s" +msgid "E&ject %1" +msgstr "&Вилучити %1" msgid "&Unmute" msgstr "&Увімкнути звук" @@ -2112,8 +2046,29 @@ msgstr "FPU Softfloat" msgid "High performance impact" msgstr "Високий вплив на продуктивність" -msgid "RAM Disk (max. speed)" -msgstr "Диск оперативної пам'яті (макс. швидкість)" +msgid "[Generic] RAM Disk (max. speed)" +msgstr "[Generic] Диск оперативної пам'яті (макс. швидкість)" + +msgid "[Generic] 1989 (3500 RPM)" +msgstr "" + +msgid "[Generic] 1992 (3600 RPM)" +msgstr "" + +msgid "[Generic] 1994 (4500 RPM)" +msgstr "" + +msgid "[Generic] 1996 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1997 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1998 (5400 RPM)" +msgstr "" + +msgid "[Generic] 2000 (7200 RPM)" +msgstr "" msgid "IBM 8514/A clone (ISA)" msgstr "Клон IBM 8514/A (ISA)" @@ -2126,3 +2081,75 @@ msgstr "30 Гц (JMP2 = 1)" msgid "60 Hz (JMP2 = 2)" msgstr "60 Гц (JMP2 = 2)" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Загальне розширення пам'яті PC/XT" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Загальне розширення пам'яті PC/AT" + +msgid "Unable to find Dot-Matrix fonts" +msgstr "Неможливо знайти матричні шрифти" + +msgid "TrueType fonts in the \"roms/printer/fonts\" directory are required for the emulation of the Generic ESC/P Dot-Matrix Printer." +msgstr "Шрифти TrueType у каталозі \"roms/printer/fonts\" потрібні для емуляції загального матричного принтера Generic ESC/P." + +msgid "Inhibit multimedia keys" +msgstr "" + +msgid "Ask for confirmation before saving settings" +msgstr "" + +msgid "Ask for confirmation before hard resetting" +msgstr "" + +msgid "Ask for confirmation before quitting" +msgstr "" + +msgid "Options" +msgstr "" + +msgid "Model" +msgstr "" + +msgid "Model:" +msgstr "" + +msgid "Failed to initialize Vulkan renderer." +msgstr "" + +msgid "GLSL Error" +msgstr "" + +msgid "Could not load shader: %1" +msgstr "" + +msgid "OpenGL version 3.0 or greater is required. Current GLSL version is %1.%2" +msgstr "" + +msgid "Could not load texture: %1" +msgstr "" + +msgid "Could not compile shader:\n\n%1" +msgstr "" + +msgid "Program not linked:\n\n%1" +msgstr "" + +msgid "Shader Manager" +msgstr "" + +msgid "Shader Configuration" +msgstr "" + +msgid "Add" +msgstr "" + +msgid "Move up" +msgstr "" + +msgid "Move down" +msgstr "" + +msgid "Could not load file %1" +msgstr "" diff --git a/src/qt/languages/vi-VN.po b/src/qt/languages/vi-VN.po index 15802fc2d..9fed36393 100644 --- a/src/qt/languages/vi-VN.po +++ b/src/qt/languages/vi-VN.po @@ -18,8 +18,8 @@ msgstr "Gắn ALT trái vào CTRL ph&ải" msgid "&Hard Reset..." msgstr "Buộc khởi độn&g lại" -msgid "&Ctrl+Alt+Del\tCtrl+F12" -msgstr "&Ctrl+Alt+Del\tCtrl+F12" +msgid "&Ctrl+Alt+Del" +msgstr "&Ctrl+Alt+Del" msgid "Ctrl+Alt+&Esc" msgstr "Ctrl+Alt+&Esc" @@ -111,8 +111,8 @@ msgstr "Tu&yến tính" msgid "Hi&DPI scaling" msgstr "Tỷ lệ hinh ảnh phân giải cao" -msgid "&Fullscreen\tCtrl+Alt+PgUp" -msgstr "Toàn màn &hình\tCtrl+Alt+PgUp" +msgid "&Fullscreen" +msgstr "Toàn màn &hình" msgid "Fullscreen &stretch mode" msgstr "&Chế độ kéo giãn hình" @@ -186,8 +186,11 @@ msgstr "&Cài đặt..." msgid "&Update status bar icons" msgstr "Cậ&p nhật biểu tượng thanh trạng thái" -msgid "Take s&creenshot\tCtrl+F11" -msgstr "Chụp &màn hình\tCtrl+F11" +msgid "Take s&creenshot" +msgstr "Chụp &màn hình" + +msgid "S&ound" +msgstr "&Thanh âm" msgid "&Preferences..." msgstr "&Tùy biến..." @@ -198,11 +201,11 @@ msgstr "Bật trình trạng thái cho Discord" msgid "Sound &gain..." msgstr "Bộ &tăng âm..." -msgid "Begin trace\tCtrl+T" -msgstr "Bắt đầu dò\tCtrl+T" +msgid "Begin trace" +msgstr "Bắt đầu dò" -msgid "End trace\tCtrl+T" -msgstr "Ngưng dò\tCtrl+T" +msgid "End trace" +msgstr "Ngưng dò" msgid "&Help" msgstr "&Trợ giúp" @@ -249,8 +252,8 @@ msgstr "Tắt tiến&g" msgid "E&mpty" msgstr "Làm trố&ng đĩa" -msgid "&Reload previous image" -msgstr "Load đĩ&a trước đó" +msgid "Reload previous image" +msgstr "Load đĩa trước đó" msgid "&Folder..." msgstr "Thư mụ&c" @@ -306,18 +309,12 @@ msgstr "Đồng ý" msgid "Cancel" msgstr "Thôi" -msgid "Save these settings as &global defaults" -msgstr "Lưu cài đặt làm mặc định chung" - msgid "&Default" msgstr "&Mặc định" msgid "Language:" msgstr "Ngôn ngữ:" -msgid "Icon set:" -msgstr "Bộ biểu tượng:" - msgid "Gain" msgstr "Tăng" @@ -453,15 +450,6 @@ msgstr "Nuked (chính xác hơn)" msgid "YMFM (faster)" msgstr "YMFM (nhanh hơn)" -msgid "Network type:" -msgstr "Kiểu loại mạng:" - -msgid "PCap device:" -msgstr "Thiết bị PCap:" - -msgid "Network adapter:" -msgstr "Bộ thích ứng (adapter) mạng:" - msgid "COM1 Device:" msgstr "Thiết bị COM1:" @@ -642,14 +630,11 @@ msgstr "Lỗi nghiêm trọng" msgid " - PAUSED" msgstr " - TẠM DỪNG" -msgid "Press Ctrl+Alt+PgDn to return to windowed mode." -msgstr "Bấm Ctrl+Alt+PgDn để quay lại chế độ cửa sổ." - msgid "Speed" msgstr "Vận tốc" -msgid "ZIP %03i %i (%s): %ls" -msgstr "ZIP %03i %i (%s): %ls" +msgid "ZIP %1 %2 (%3): %4" +msgstr "ZIP %1 %2 (%3): %4" msgid "ZIP images" msgstr "Ảnh đĩa ZIP" @@ -682,13 +667,16 @@ msgid "Surface images" msgstr "Ảnh bề mặt" msgid "Machine \"%hs\" is not available due to missing ROMs in the roms/machines directory. Switching to an available machine." -msgstr "Mẫu máy \"%hs\" không giả lập được do thiếu file ROM tương ứng trong mục roms/machines. Hãy chọn mẫu máy khác." +msgstr "Mẫu máy \"%hs\" không giả lập được do thiếu file ROM tương ứng trong thư mục roms/machines. Hãy chọn mẫu máy khác." msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Card đồ họa \"%hs\" không giả lập được do thiếu file ROM tương ứng trong mục roms/video. Hãy chọn card đồ họa khác." +msgstr "Card đồ họa \"%hs\" không giả lập được do thiếu file ROM tương ứng trong thư mục roms/video. Hãy chọn card đồ họa khác." -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Card đồ họa 2 \"%hs\" không giả lập được do thiếu file ROM tương ứng trong mục roms/video. Hãy chọn card đồ họa khác." +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "Card đồ họa 2 \"%hs\" không giả lập được do thiếu file ROM tương ứng trong mục roms/video. Vô hiệu hóa card đồ họa thứ hai." + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "Thiết bị \"%hs\" không giả lập được do thiếu file ROM. Bỏ qua thiết bị." msgid "Machine" msgstr "Mẫu máy" @@ -750,14 +738,11 @@ msgstr "S" msgid "KB" msgstr "KB" -msgid "Could not initialize the video renderer." -msgstr "Không thể khởi tạo trình kết xuất (renderer) video ." - msgid "Default" msgstr "Mặc định" -msgid "%i Wait state(s)" -msgstr "%i trạng thái chờ" +msgid "%1 Wait state(s)" +msgstr "%1 trạng thái chờ" msgid "Type" msgstr "Loại" @@ -801,11 +786,11 @@ msgstr "Thrustmaster Flight Control System" msgid "None" msgstr "Không có" -msgid "%u MB (CHS: %i, %i, %i)" -msgstr "%u MB (CHS: %i, %i, %i)" +msgid "%1 MB (CHS: %2, %3, %4)" +msgstr "%1 MB (CHS: %2, %3, %4)" -msgid "Floppy %i (%s): %ls" -msgstr "Đĩa mềm %i (%s): %ls" +msgid "Floppy %1 (%2): %3" +msgstr "Đĩa mềm %1 (%2): %3" msgid "Advanced sector images" msgstr "Ảnh (đĩa) sector nâng cao" @@ -825,8 +810,8 @@ msgstr "Không thể khởi tạo Ghostscript" msgid "Unable to initialize GhostPCL" msgstr "Không thể khởi tạo GhostPCL" -msgid "MO %i (%ls): %ls" -msgstr "MO %i (%ls): %ls" +msgid "MO %1 (%2): %3" +msgstr "MO %1 (%2): %3" msgid "MO images" msgstr "Ảnh đĩa MO" @@ -876,9 +861,6 @@ msgstr "Cần có %1 để tự động chuyển đổi file PostScript qua PDF. msgid "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PCL printer will be saved as Printer Command Language (.pcl) files." msgstr "Cần có %1 để tự động chuyển đổi file PCL qua PDF.\n\nMọi tài liệu được đưa qua máy in generic PCL sẽ lưu ở dạng Printer Command Language (.pcl)." -msgid "Entering fullscreen mode" -msgstr "Đang tiến vào chế độ toàn màn hình" - msgid "Don't show this message again" msgstr "Không hiện thông báo này nữa" @@ -900,11 +882,8 @@ msgstr "Tinh chỉnh thiết bị %1" msgid "Monitor in sleep mode" msgstr "Màn hình chế độ chờ/ngủ" -msgid "OpenGL Shaders" -msgstr "Shader OpenGL" - -msgid "OpenGL options" -msgstr "Tùy chọn OpenGL" +msgid "GLSL shaders" +msgstr "Shader GLSL" msgid "You are loading an unsupported configuration" msgstr "Bạn đang load tinh chỉnh không được hỗ trợ." @@ -915,24 +894,18 @@ msgstr "Phần chọn loại CPU dựa trên mẫu máy đã chọn bị vô hi msgid "Continue" msgstr "Tiếp tục" -msgid "Cassette: %s" -msgstr "Cassette: %s" +msgid "Cassette: %1" +msgstr "Cassette: %1" msgid "Cassette images" msgstr "Ảnh đĩa Cassette" -msgid "Cartridge %i: %ls" -msgstr "Băng cartridge %i: %ls" +msgid "Cartridge %1: %2" +msgstr "Băng cartridge %1: %2" msgid "Cartridge images" msgstr "Ảnh đĩa băng cartridge" -msgid "Error initializing renderer" -msgstr "Lỗi khởi tạo renderer (trình kết xuất)" - -msgid "OpenGL (3.0 Core) renderer could not be initialized. Use another renderer." -msgstr "Không khởi tạo được renderer OpenGL (3.0 Core). Hãy dùng renderer khác." - msgid "Resume execution" msgstr "Tiếp tục chạy thực thi" @@ -1095,8 +1068,8 @@ msgstr "IDE" msgid "ATAPI" msgstr "ATAPI" -msgid "CD-ROM %i (%s): %s" -msgstr "CD-ROM %i (%s): %s" +msgid "CD-ROM %1 (%2): %3" +msgstr "CD-ROM %1 (%2): %3" msgid "160 KB" msgstr "160 KB" @@ -1216,7 +1189,7 @@ msgid "Development of the WinBox manager stopped in 2022 due to a lack of mainta msgstr "Trình quản lý phiên WinBox đã bị dừng phát triển năm 2022 do thiếu nhân sự duy trì. Vì những quyết định để cho 86Box trở nên tốt hơn, chúng tôi đã không còn hỗ trợ trình quản lý WinBox.\n\n Sẽ không có bản cập nhật mới cho WinBox nữa, và nếu bạn tiếp tục sử dụng với các bản 86Box mới hơn có thể gặp lỗi. Bất kì các bản bug report liên quan đến lỗi của WinBox sẽ bị coi là không hợp lệ và bị đóng.\n\nTruy cập 86Box.net để tìm qua các trình quản lý phiên/manager khác cho phù hợp." msgid "Generate" -msgstr "Phát ra" +msgstr "Tạo" msgid "Joystick configuration" msgstr "Cấu hình cần điều khiển" @@ -1237,7 +1210,7 @@ msgid "List of MCA devices:" msgstr "Danh sách các thiết bị MCA:" msgid "Tablet tool" -msgstr "Công cụ máy tính bảng" +msgstr "Công cụ bảng nhập liệu" msgid "Qt (OpenGL &ES)" msgstr "QT (OpenGL &ES)" @@ -1261,22 +1234,19 @@ msgid "Cursor/Puck" msgstr "Con trỏ/puck" msgid "Pen" -msgstr "Cái bút" +msgstr "Bút" msgid "Host CD/DVD Drive (%1:)" msgstr "Máy chủ CD/DVD ổ đĩa (%1 :)" msgid "&Connected" -msgstr "& Kết nối" +msgstr "&Đã kết nối" msgid "Clear image history" msgstr "Xóa lịch sử ảnh đĩa" msgid "Create..." -msgstr "Tạo nên..." - -msgid "previous image" -msgstr "đĩa trước đó" +msgstr "Tạo..." msgid "Host CD/DVD Drive (%1)" msgstr "Máy chủ CD/DVD Drive (%1)" @@ -1287,26 +1257,11 @@ msgstr "Bus không xác định" msgid "Null Driver" msgstr "Trình điều khiển NULL" -msgid "NIC %02i (%ls) %ls" -msgstr "NIC %02i ( %ls) %ls" - -msgid "Error opening \"%1\": %2" -msgstr "Mở lỗi \"%1\": %2" - -msgid "Error compiling vertex shader in file \"%1\"" -msgstr "Lỗi biên dịch shader đỉnh trong tệp \"%1\"" - -msgid "Error compiling fragment shader in file \"%1\"" -msgstr "Lỗi biên dịch shader fragment trong tệp \"%1\"" - -msgid "Error linking shader program in file \"%1\"" -msgstr "Lỗi liên kết chương trình shader trong tệp \"%1\"" - -msgid "OpenGL 3.0 renderer options" -msgstr "Tùy chọn kết xuất OpenGL 3.0" +msgid "NIC %1 (%2) %3" +msgstr "NIC %1 (%2) %3" msgid "Render behavior" -msgstr "Hiện ra hành vi" +msgstr "Hành vi kết xuất" msgid "Use target framerate:" msgstr "Dùng số khung hình mục tiêu:" @@ -1317,33 +1272,18 @@ msgstr " khung hình / giây" msgid "VSync" msgstr "Vsync" -msgid "<html><head/><body><p>Render each frame immediately, in sync with the emulated display.</p><p><span style=" font-style:italic;">This is the recommended option if the shaders in use don't utilize frametime for animated effects.</span></p></body></html>" -msgstr "<html><head/><body><p>Kết xuất mỗi khung ngay lập tức, đồng bộ với màn hình mô phỏng.</p><p><span style=" font-style:italic;">Đây là tùy chọn được đề xuất nếu các shader đang sử dụng không sử dụng hình chữ nhật cho các hiệu ứng hoạt hình.</span></p></body></html>" - msgid "Synchronize with video" -msgstr "Đồng bộ hóa với video" +msgstr "Đồng bộ với video" msgid "Shaders" msgstr "Shaders" msgid "Remove" -msgstr "Di dời" - -msgid "No shader selected" -msgstr "Không có shader được chọn" +msgstr "Loại bỏ" msgid "Browse..." msgstr "Duyệt..." -msgid "Shader error" -msgstr "Lỗi shader" - -msgid "Could not load shaders." -msgstr "Không thể tải shader." - -msgid "More information in details." -msgstr "Thêm thông tin chi tiết." - msgid "Couldn't create OpenGL context." msgstr "Không thể tạo bối cảnh OpenGL." @@ -1353,26 +1293,20 @@ msgstr "Không thể chuyển sang bối cảnh OpenGL." msgid "OpenGL version 3.0 or greater is required. Current version is %1.%2" msgstr "OpenGL phiên bản 3.0 trở lên là bắt buộc. Phiên bản hiện tại là %1. %2" -msgid "OpenGL initialization failed. Error %1." -msgstr "Khởi tạo OpenGL không thành công. Lỗi %1." - msgid "Error initializing OpenGL" msgstr "Lỗi khởi tạo OpenGL" -msgid "Falling back to software rendering.\n" -msgstr "Rơi trở lại kết xuất phần mềm.\n" +msgid "\nFalling back to software rendering." +msgstr "\nQuay trở lại kết xuất phần mềm." -msgid "Allocating memory for unpack buffer failed.\n" -msgstr "Phân bổ bộ nhớ cho bộ đệm giải nén không thành công.\n" - -msgid "<html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html>" -msgstr "<html><head/><body><p>Khi chọn hình ảnh phương tiện (CD-ROM, FLOPPY, v.v.), hộp thoại mở sẽ bắt đầu trong cùng thư mục với tệp cấu hình 86box. Cài đặt này có thể sẽ chỉ tạo ra sự khác biệt trên macOS.</p></body></html>" +msgid "

When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" +msgstr "

Khi chọn hình ảnh phương tiện (CD-ROM, ổ mềm, v.v.), hộp thoại mở sẽ bắt đầu trong cùng thư mục với tệp cấu hình 86box. Cài đặt này có thể sẽ chỉ tạo ra sự khác biệt trên macOS.

" msgid "This machine might have been moved or copied." -msgstr "Máy này có thể đã được di chuyển hoặc sao chép." +msgstr "Cấu hình máy này có thể đã được di chuyển hoặc sao chép." msgid "In order to ensure proper networking functionality, 86Box needs to know if this machine was moved or copied.\n\nSelect \"I Copied It\" if you are not sure." -msgstr "Để đảm bảo chức năng kết nối mạng thích hợp, 86box cần biết liệu máy này có được di chuyển hay sao chép không.\n\nNếu bạn không chắc chắn, chọn \"Tôi đã sao chép nó\"." +msgstr "Để đảm bảo chức năng kết nối mạng thích hợp, 86Box cần biết liệu máy này có được di chuyển hay sao chép không.\n\nNếu bạn không chắc chắn, chọn \"Tôi đã sao chép nó\"." msgid "I Moved It" msgstr "Tôi đã di chuyển nó" @@ -1387,7 +1321,7 @@ msgid "No MCA devices." msgstr "Không có thiết bị MCA." msgid "MiB" -msgstr "Mib" +msgstr "MiB" msgid "Network Card #1" msgstr "Thẻ mạng 1" @@ -1401,20 +1335,20 @@ msgstr "Thẻ mạng 3" msgid "Network Card #4" msgstr "Thẻ mạng 4" -msgid "Mode" -msgstr "Cách thức" +msgid "Mode:" +msgstr "Chế độ:" -msgid "Interface" -msgstr "Giao diện" +msgid "Interface:" +msgstr "Giao diện:" -msgid "Adapter" -msgstr "Bộ chuyển đổi" +msgid "Adapter:" +msgstr "Bộ chuyển đổi:" -msgid "VDE Socket" -msgstr "Ổ cắm VDE" +msgid "VDE Socket:" +msgstr "Ổ cắm VDE:" msgid "86Box Unit Tester" -msgstr "Người kiểm tra đơn vị 86box" +msgstr "Trình kiểm tra đơn vị 86box" msgid "Novell NetWare 2.x Key Card" msgstr "Thẻ khóa Novell Netware 2.x" @@ -1431,9 +1365,6 @@ msgstr "Thông qua cổng serial 3" msgid "Serial port passthrough 4" msgstr "Thông qua cổng serial 4" -msgid "Vision Systems LBA Enhancer" -msgstr "Hệ thống tầm nhìn LBA Enhancer" - msgid "Renderer options..." msgstr "Tùy chọn kết xuất ..." @@ -1474,7 +1405,7 @@ msgid "Roland CM-32LN Emulation" msgstr "Mô phỏng Roland CM-32LN" msgid "OPL4-ML Daughterboard" -msgstr "Con gái OPL4-ML" +msgstr "Bo mạch con OPL4-ML" msgid "System MIDI" msgstr "MIDI của hệ thống" @@ -1486,7 +1417,7 @@ msgid "BIOS Address" msgstr "Địa chỉ BIOS" msgid "Enable BIOS extension ROM Writes" -msgstr "Bật ROM mở rộng BIOS" +msgstr "Kích hoạt ghi ROM mở rộng BIOS" msgid "Address" msgstr "Địa chỉ" @@ -1513,22 +1444,22 @@ msgid "BIOS size" msgstr "Kích thước BIOS" msgid "Map C0000-C7FFF as UMB" -msgstr "Bản đồ C0000-C7FFF dưới dạng UMB" +msgstr "Map C0000-C7FFF dưới dạng UMB" msgid "Map C8000-CFFFF as UMB" -msgstr "Bản đồ C8000-CFFFF dưới dạng UMB" +msgstr "Map C8000-CFFFF dưới dạng UMB" msgid "Map D0000-D7FFF as UMB" -msgstr "Bản đồ D0000-D7FFF dưới dạng UMB" +msgstr "Map D0000-D7FFF dưới dạng UMB" msgid "Map D8000-DFFFF as UMB" -msgstr "Bản đồ D8000-Dffff dưới dạng UMB" +msgstr "Map D8000-Dffff dưới dạng UMB" msgid "Map E0000-E7FFF as UMB" -msgstr "Bản đồ E0000-E7FFF dưới dạng UMB" +msgstr "Map E0000-E7FFF dưới dạng UMB" msgid "Map E8000-EFFFF as UMB" -msgstr "Bản đồ e8000-effff dưới dạng umb" +msgstr "Map e8000-effff dưới dạng umb" msgid "JS9 Jumper (JIM)" msgstr "JS9 Jumper (Jim)" @@ -1543,13 +1474,13 @@ msgid "MIDI Thru" msgstr "Thông qua đầu vào MIDI" msgid "MIDI Clockout" -msgstr "MIDI đồng hồ" +msgstr "MIDI Clockout" msgid "SoundFont" -msgstr "Soundfont" +msgstr "Font âm thanh" msgid "Output Gain" -msgstr "Đầu ra tăng" +msgstr "Tăng đầu ra" msgid "Chorus" msgstr "Điệp khúc" @@ -1588,7 +1519,7 @@ msgid "Interpolation Method" msgstr "Phương pháp nội suy" msgid "Reverb Output Gain" -msgstr "Gợi ý đầu ra hồi âm" +msgstr "Tăng đầu ra hồi âm" msgid "Reversed stereo" msgstr "Đảo ngược âm thanh nổi" @@ -1609,10 +1540,10 @@ msgid "RTS toggle" msgstr "RT chuyển đổi" msgid "Revision" -msgstr "Ôn tập" +msgstr "Bản sửa đổi" msgid "Controller" -msgstr "Người điều khiển" +msgstr "Bộ điều khiển" msgid "Show Crosshair" msgstr "Hiển thị hình chữ thập" @@ -1624,7 +1555,7 @@ msgid "MAC Address" msgstr "Địa chỉ MAC" msgid "MAC Address OUI" -msgstr " OUI địa chỉ MAC" +msgstr "OUI địa chỉ MAC" msgid "Enable BIOS" msgstr "Bật BIOS" @@ -1696,7 +1627,7 @@ msgid "Enable OPL" msgstr "Bật OPL" msgid "Receive MIDI input (MPU-401)" -msgstr "Nhận nhập MIDI (MPU-401)" +msgstr "Nhận đầu vào MIDI (MPU-401)" msgid "SB low DMA" msgstr "SB DMA thấp" @@ -1708,7 +1639,7 @@ msgid "Enable CMS" msgstr "Bật CMS" msgid "Mixer" -msgstr "Máy trộn" +msgstr "Bộ trộn" msgid "High DMA" msgstr "DMA cao" @@ -1744,13 +1675,13 @@ msgid "RGB type" msgstr "Loại RGB" msgid "Line doubling type" -msgstr "Dòng nhân đôi" +msgstr "Loại dòng kép" msgid "Snow emulation" -msgstr "Đun tuyết" +msgstr "Giả lập hiệu ứng tuyết" msgid "Monitor type" -msgstr "Loại giám sát" +msgstr "Loại màn hình" msgid "Character set" msgstr "Bộ ký tự" @@ -1759,13 +1690,13 @@ msgid "XGA type" msgstr "Loại XGA" msgid "Instance" -msgstr "Ví dụ" +msgstr "Bản chạy" msgid "MMIO Address" msgstr "Địa chỉ MMIO" msgid "RAMDAC type" -msgstr "Loại Ramdac" +msgstr "Loại RAMDAC" msgid "Blend" msgstr "Trộn" @@ -1789,13 +1720,13 @@ msgid "Texture memory size" msgstr "Kích thước bộ nhớ kết cấu" msgid "Dither subtraction" -msgstr "Phân biệt trừ" +msgstr "Giảm ngân tán" msgid "Screen Filter" msgstr "Bộ lọc màn hình" msgid "Render threads" -msgstr "Kết xuất chủ đề" +msgstr "Luồng kết xuất" msgid "SLI" msgstr "SLI" @@ -1810,13 +1741,13 @@ msgid "I/O Width" msgstr "Chiều rộng I/O" msgid "Transfer Speed" -msgstr "Tốc độ chuyển" +msgstr "Tốc độ truyền tải" msgid "EMS mode" msgstr "Chế độ EMS" msgid "Address for > 2 MB" -msgstr "Địa chỉ cho> 2 MB" +msgstr "Địa chỉ cho > 2 MB" msgid "Frame Address" msgstr "Địa chỉ khung" @@ -1831,7 +1762,7 @@ msgid "Always at selected speed" msgstr "Luôn ở tốc độ đã chọn" msgid "BIOS setting + Hotkeys (off during POST)" -msgstr "Cài đặt BIOS + phím nóng (TẮT trong bài đăng)" +msgstr "Cài đặt BIOS + phím nóng (TẮT trong POST)" msgid "64 kB starting from F0000" msgstr "64 kb bắt đầu từ f0000" @@ -1858,7 +1789,7 @@ msgid "Non-timed (original)" msgstr "Không đúng lúc (bản gốc)" msgid "45 Hz (JMP2 not populated)" -msgstr "45 Hz (JMP2 không dân cư)" +msgstr "45 Hz (JMP2 không phổ cập)" msgid "Two" msgstr "Hai" @@ -1867,10 +1798,13 @@ msgid "Three" msgstr "Ba" msgid "Wheel" -msgstr "Bánh xe" +msgstr "Con lăn" msgid "Five + Wheel" -msgstr "Năm + bánh xe" +msgstr "Năm + con lăn" + +msgid "Five + 2 Wheels" +msgstr "" msgid "A3 - SMT2 Serial / SMT3(R)V" msgstr "A3 - SMT2 Serial / SMT3(R)V" @@ -2005,7 +1939,7 @@ msgid "Color" msgstr "Màu sắc" msgid "U.S. English" -msgstr "Tiếng Anh Hoa Kỳ" +msgstr "Tiếng Anh Mỹ" msgid "Scandinavian" msgstr "Scandinavia" @@ -2017,13 +1951,13 @@ msgid "Bochs latest" msgstr "Bochs mới nhất" msgid "Mono Non-Interlaced" -msgstr "Đơn sắc không được xen kẽ" +msgstr "Đơn sắc không xen kẽ" msgid "Color Interlaced" msgstr "Màu sắc xen kẽ" msgid "Color Non-Interlaced" -msgstr "Màu sắc không được xen kẽ" +msgstr "Màu sắc không xen kẽ" msgid "3Dfx Voodoo Graphics" msgstr "Đồ họa 3Dfx Voodoo" @@ -2071,7 +2005,7 @@ msgid "Parallel Line Internet Protocol" msgstr "Parallel Line Internet Protocol" msgid "Protection Dongle for Savage Quest" -msgstr "Bảo vệ dongle cho Savage Quest" +msgstr "Dongle bảo vệ cho Savage Quest" msgid "Serial Passthrough Device" msgstr "Thiết bị thông qua cổng serial" @@ -2083,7 +2017,7 @@ msgid "Host Serial Device" msgstr "Thiết bị serial máy chủ" msgid "Name of pipe" -msgstr "Tên của đường ống" +msgstr "Tên đường ống" msgid "Data bits" msgstr "Bit dữ liệu" @@ -2092,31 +2026,124 @@ msgid "Stop bits" msgstr "Dừng bit" msgid "Baud Rate of Passthrough" -msgstr "Tốc độ baud của qua đường" +msgstr "Tốc độ baud của đường thông" msgid "Named Pipe (Server)" -msgstr "Đường ống được đặt tên (máy chủ)" +msgstr "Đường ống có tên (máy chủ)" msgid "Host Serial Passthrough" msgstr "Thông qua cổng serial của máy chủ" -msgid "Eject %s" -msgstr "Đẩy đĩa ra %s" +msgid "E&ject %1" +msgstr "Đẩy đĩ&a ra %1" msgid "&Unmute" -msgstr "&Không quay được" +msgstr "&Mở tiếng" msgid "Softfloat FPU" msgstr "Softfloat FPU" msgid "High performance impact" -msgstr "Tác động cao đến hiệu suất" +msgstr "Ảnh hưởng lớn đến hiệu suất" -msgid "RAM Disk (max. speed)" -msgstr "Đĩa RAM (Tối đa. Tốc độ)" +msgid "[Generic] RAM Disk (max. speed)" +msgstr "[Generic] Đĩa RAM (tốc độ tối đa)" + +msgid "[Generic] 1989 (3500 RPM)" +msgstr "" + +msgid "[Generic] 1992 (3600 RPM)" +msgstr "" + +msgid "[Generic] 1994 (4500 RPM)" +msgstr "" + +msgid "[Generic] 1996 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1997 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1998 (5400 RPM)" +msgstr "" + +msgid "[Generic] 2000 (7200 RPM)" +msgstr "" msgid "IBM 8514/A clone (ISA)" -msgstr "IBM 8514/A dòng vô tính (ISA)" +msgstr "IBM 8514/A bản nhái (ISA)" msgid "Vendor" msgstr "Nhà sản xuất" + +msgid "Generic PC/XT Memory Expansion" +msgstr "Chung mở rộng bộ nhớ qua PC/XT" + +msgid "Generic PC/AT Memory Expansion" +msgstr "Chung mở rộng bộ nhớ qua PC/AT" + +msgid "Unable to find Dot-Matrix fonts" +msgstr "Không tìm thấy phông chữ ma trận chấm" + +msgid "TrueType fonts in the \"roms/printer/fonts\" directory are required for the emulation of the Generic ESC/P Dot-Matrix Printer." +msgstr "Cần có phông chữ TrueType trong thư mục \"roms/printer/fonts\" để mô phỏng máy in generic ESC/P ma trận chấm." + +msgid "Inhibit multimedia keys" +msgstr "" + +msgid "Ask for confirmation before saving settings" +msgstr "" + +msgid "Ask for confirmation before hard resetting" +msgstr "" + +msgid "Ask for confirmation before quitting" +msgstr "" + +msgid "Options" +msgstr "" + +msgid "Model" +msgstr "" + +msgid "Model:" +msgstr "" + +msgid "Failed to initialize Vulkan renderer." +msgstr "" + +msgid "GLSL Error" +msgstr "" + +msgid "Could not load shader: %1" +msgstr "" + +msgid "OpenGL version 3.0 or greater is required. Current GLSL version is %1.%2" +msgstr "" + +msgid "Could not load texture: %1" +msgstr "" + +msgid "Could not compile shader:\n\n%1" +msgstr "" + +msgid "Program not linked:\n\n%1" +msgstr "" + +msgid "Shader Manager" +msgstr "" + +msgid "Shader Configuration" +msgstr "" + +msgid "Add" +msgstr "" + +msgid "Move up" +msgstr "" + +msgid "Move down" +msgstr "" + +msgid "Could not load file %1" +msgstr "" diff --git a/src/qt/languages/zh-CN.po b/src/qt/languages/zh-CN.po index 6b659b504..2af5abef9 100644 --- a/src/qt/languages/zh-CN.po +++ b/src/qt/languages/zh-CN.po @@ -18,8 +18,8 @@ msgstr "将右 CTRL 键映射为左 ALT 键(&R)" msgid "&Hard Reset..." msgstr "硬重置(&H)..." -msgid "&Ctrl+Alt+Del\tCtrl+F12" -msgstr "Ctrl+Alt+Del(&C)\tCtrl+F12" +msgid "&Ctrl+Alt+Del" +msgstr "Ctrl+Alt+Del(&C)" msgid "Ctrl+Alt+&Esc" msgstr "Ctrl+Alt+Esc(&E)" @@ -111,8 +111,8 @@ msgstr "线性(&L)" msgid "Hi&DPI scaling" msgstr "HiDPI 缩放(&D)" -msgid "&Fullscreen\tCtrl+Alt+PgUp" -msgstr "全屏(&F)\tCtrl+Alt+PgUp" +msgid "&Fullscreen" +msgstr "全屏(&F)" msgid "Fullscreen &stretch mode" msgstr "全屏拉伸模式(&S)" @@ -186,8 +186,11 @@ msgstr "设置(&S)..." msgid "&Update status bar icons" msgstr "更新状态栏图标(&U)" -msgid "Take s&creenshot\tCtrl+F11" -msgstr "截图(&C)\tCtrl+F11" +msgid "Take s&creenshot" +msgstr "截图(&C)" + +msgid "S&ound" +msgstr "声音(&O)" msgid "&Preferences..." msgstr "首选项(&P)..." @@ -198,11 +201,11 @@ msgstr "启用 Discord 集成(&D)" msgid "Sound &gain..." msgstr "音量增益(&G)..." -msgid "Begin trace\tCtrl+T" -msgstr "开始追踪\tCtrl+T" +msgid "Begin trace" +msgstr "开始追踪" -msgid "End trace\tCtrl+T" -msgstr "结束追踪\tCtrl+T" +msgid "End trace" +msgstr "结束追踪" msgid "&Help" msgstr "帮助(&H)" @@ -249,8 +252,8 @@ msgstr "静音(&M)" msgid "E&mpty" msgstr "空置驱动器(&M)" -msgid "&Reload previous image" -msgstr "载入上一个映像(&R)" +msgid "Reload previous image" +msgstr "载入上一个映像" msgid "&Folder..." msgstr "文件夹(&F)..." @@ -306,18 +309,12 @@ msgstr "确定" msgid "Cancel" msgstr "取消" -msgid "Save these settings as &global defaults" -msgstr "将以上设置存储为全局默认值(&G)" - msgid "&Default" msgstr "默认(&D)" msgid "Language:" msgstr "语言:" -msgid "Icon set:" -msgstr "图标集:" - msgid "Gain" msgstr "增益" @@ -453,15 +450,6 @@ msgstr "Nuked (更准确)" msgid "YMFM (faster)" msgstr "YMFM (更快)" -msgid "Network type:" -msgstr "网络类型:" - -msgid "PCap device:" -msgstr "PCap 设备:" - -msgid "Network adapter:" -msgstr "网络适配器:" - msgid "COM1 Device:" msgstr "COM1 设备:" @@ -642,14 +630,11 @@ msgstr "致命错误" msgid " - PAUSED" msgstr " - 已暂停" -msgid "Press Ctrl+Alt+PgDn to return to windowed mode." -msgstr "按下 Ctrl+Alt+PgDn 返回到窗口模式。" - msgid "Speed" msgstr "速度" -msgid "ZIP %03i %i (%s): %ls" -msgstr "ZIP %03i %i (%s): %ls" +msgid "ZIP %1 %2 (%3): %4" +msgstr "ZIP %1 %2 (%3): %4" msgid "ZIP images" msgstr "ZIP 映像" @@ -687,8 +672,11 @@ msgstr "由于 roms/machines 文件夹中缺少合适的 ROM,机型 \"%hs\" msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "由于 roms/video 文件夹中缺少合适的 ROM,显卡 \"%hs\" 不可用。将切换到其他可用显卡。" -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "由于 roms/video 文件夹中缺少合适的 ROM,显卡 2 \"%hs\" 不可用。将切换到其他可用显卡。" +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "由于 roms/video 文件夹中缺少合适的 ROM,显卡 2 \"%hs\" 不可用。禁用第二块显卡。" + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "由于缺少合适的 ROM,设备 \"%hs\" 不可用。忽略设备。" msgid "Machine" msgstr "机型" @@ -750,14 +738,11 @@ msgstr "S" msgid "KB" msgstr "KB" -msgid "Could not initialize the video renderer." -msgstr "无法初始化视频渲染器。" - msgid "Default" msgstr "默认" -msgid "%i Wait state(s)" -msgstr "%i 等待状态 (WS)" +msgid "%1 Wait state(s)" +msgstr "%1 等待状态 (WS)" msgid "Type" msgstr "类型" @@ -801,11 +786,11 @@ msgstr "Thrustmaster Flight Control System" msgid "None" msgstr "无" -msgid "%u MB (CHS: %i, %i, %i)" -msgstr "%u MB (CHS: %i, %i, %i)" +msgid "%1 MB (CHS: %2, %3, %4)" +msgstr "%1 MB (CHS: %2, %3, %4)" -msgid "Floppy %i (%s): %ls" -msgstr "软盘 %i (%s): %ls" +msgid "Floppy %1 (%2): %3" +msgstr "软盘 %1 (%2): %3" msgid "Advanced sector images" msgstr "高级扇区映像" @@ -825,8 +810,8 @@ msgstr "无法初始化 Ghostscript" msgid "Unable to initialize GhostPCL" msgstr "无法初始化 GhostPCL" -msgid "MO %i (%ls): %ls" -msgstr "磁光盘 %i (%ls): %ls" +msgid "MO %1 (%2): %3" +msgstr "磁光盘 %1 (%2): %3" msgid "MO images" msgstr "磁光盘映像" @@ -864,8 +849,8 @@ msgstr "一个旧式计算机模拟器\n\n作者: Miran Grča (OBattler)、Richa msgid "Hardware not available" msgstr "硬件不可用" -msgid "Make sure %1 is installed and that you are on a libpcap-compatible network connection." -msgstr "请确认 %1 已安装且使用兼容 libpcap 的网络连接。" +msgid "Make sure %1 is installed and that you are on a %1-compatible network connection." +msgstr "请确认 %1 已安装且使用兼容 %1 的网络连接。" msgid "Invalid configuration" msgstr "无效配置" @@ -876,9 +861,6 @@ msgstr "%1 是将 PostScript 文件转换为 PDF 所需要的库。\n\n使用通 msgid "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PCL printer will be saved as Printer Command Language (.pcl) files." msgstr "%1 是将 PCL 文件转换为 PDF 所需要的库。\n\n使用通用 PCL 打印机打印的文档将被保存为 Printer Command Language (.pcl) 文件。" -msgid "Entering fullscreen mode" -msgstr "正在进入全屏模式" - msgid "Don't show this message again" msgstr "不要再显示此消息" @@ -900,11 +882,8 @@ msgstr "%1 设备配置" msgid "Monitor in sleep mode" msgstr "显示器处在睡眠状态" -msgid "OpenGL Shaders" -msgstr "OpenGL 着色器" - -msgid "OpenGL options" -msgstr "OpenGL 选项" +msgid "GLSL shaders" +msgstr "GLSL 着色器" msgid "You are loading an unsupported configuration" msgstr "正在载入一个不受支持的配置" @@ -915,24 +894,18 @@ msgstr "此模拟计算机禁用了基于选定计算机的 CPU 类型过滤。\ msgid "Continue" msgstr "继续" -msgid "Cassette: %s" -msgstr "磁带: %s" +msgid "Cassette: %1" +msgstr "磁带: %1" msgid "Cassette images" msgstr "磁带映像" -msgid "Cartridge %i: %ls" -msgstr "卡带 %i: %ls" +msgid "Cartridge %1: %2" +msgstr "卡带 %1: %2" msgid "Cartridge images" msgstr "卡带映像" -msgid "Error initializing renderer" -msgstr "初始化渲染器时出错" - -msgid "OpenGL (3.0 Core) renderer could not be initialized. Use another renderer." -msgstr "无法初始化 OpenGL (3.0 Core) 渲染器。请使用其他渲染器。" - msgid "Resume execution" msgstr "恢复执行" @@ -1095,8 +1068,8 @@ msgstr "IDE" msgid "ATAPI" msgstr "ATAPI" -msgid "CD-ROM %i (%s): %s" -msgstr "光盘 %i (%s): %s" +msgid "CD-ROM %1 (%2): %3" +msgstr "光盘 %1 (%2): %3" msgid "160 KB" msgstr "160 KB" @@ -1267,7 +1240,7 @@ msgid "Host CD/DVD Drive (%1:)" msgstr "主机 CD/DVD 驱动器 (%1:)" msgid "&Connected" -msgstr "&Connected" +msgstr "已连接(&C)" msgid "Clear image history" msgstr "清除映像历史记录" @@ -1275,9 +1248,6 @@ msgstr "清除映像历史记录" msgid "Create..." msgstr "创建..." -msgid "previous image" -msgstr "上一张" - msgid "Host CD/DVD Drive (%1)" msgstr "主机 CD/DVD 驱动器 (%1)" @@ -1287,23 +1257,8 @@ msgstr "未知总线" msgid "Null Driver" msgstr "空驱动程序" -msgid "NIC %02i (%ls) %ls" -msgstr "NIC %02i (%ls) %ls" - -msgid "Error opening \"%1\": %2" -msgstr "打开 \"%1\": %2 时出错" - -msgid "Error compiling vertex shader in file \"%1\"" -msgstr "文件 \"%1\" 中的顶点着色器编译出错" - -msgid "Error compiling fragment shader in file \"%1\"" -msgstr "文件 \"%1\" 中的片段着色器编译出错" - -msgid "Error linking shader program in file \"%1\"" -msgstr "文件 \"%1\" 中的着色器程序链接出错" - -msgid "OpenGL 3.0 renderer options" -msgstr "OpenGL 3.0 渲染器选项" +msgid "NIC %1 (%2) %3" +msgstr "NIC %1 (%2) %3" msgid "Render behavior" msgstr "渲染行为" @@ -1317,9 +1272,6 @@ msgstr " fps" msgid "VSync" msgstr "VSync" -msgid "<html><head/><body><p>Render each frame immediately, in sync with the emulated display.</p><p><span style=" font-style:italic;">This is the recommended option if the shaders in use don't utilize frametime for animated effects.</span></p></body></html>" -msgstr "<html><head/><body><p>与模拟显示同步,即时渲染每一帧。</p><p><span style=" font-style:italic;">如果使用的着色器不使用帧时间来产生动画效果,则建议使用此选项。</span></p></body></html>" - msgid "Synchronize with video" msgstr "与视频同步" @@ -1329,21 +1281,9 @@ msgstr "着色器" msgid "Remove" msgstr "移除" -msgid "No shader selected" -msgstr "未选择着色器" - msgid "Browse..." msgstr "浏览..." -msgid "Shader error" -msgstr "着色器错误" - -msgid "Could not load shaders." -msgstr "无法加载着色器。" - -msgid "More information in details." -msgstr "更多详细信息。" - msgid "Couldn't create OpenGL context." msgstr "无法创建 OpenGL 上下文。" @@ -1353,20 +1293,14 @@ msgstr "无法切换到 OpenGL 上下文。" msgid "OpenGL version 3.0 or greater is required. Current version is %1.%2" msgstr "需要 OpenGL 3.0 或更高版本。当前版本为 %1.%2" -msgid "OpenGL initialization failed. Error %1." -msgstr "OpenGL 初始化失败。错误 %1." - msgid "Error initializing OpenGL" msgstr "初始化 OpenGL 时出错" -msgid "Falling back to software rendering.\n" -msgstr "回到软件渲染。" +msgid "\nFalling back to software rendering." +msgstr "\n回到软件渲染。" -msgid "Allocating memory for unpack buffer failed.\n" -msgstr "为解包缓冲区分配内存失败.\n" - -msgid "<html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html>" -msgstr "<html><head/><body><p>选择媒体图像(光盘、软盘等)时,打开对话框将从与 86Box 配置文件相同的目录开始。这一设置可能只会在 macOS 上产生影响。</p></body></html>;" +msgid "

When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" +msgstr "

选择媒体图像(光盘、软盘等)时,打开对话框将从与 86Box 配置文件相同的目录开始。这一设置可能只会在 macOS 上产生影响。

" msgid "This machine might have been moved or copied." msgstr "这台机器可能被移动或复制过。" @@ -1381,7 +1315,7 @@ msgid "I Copied It" msgstr "我已复制这台机器" msgid "86Box Monitor #" -msgstr "86Box 监测器 " +msgstr "86Box 监测器 #" msgid "No MCA devices." msgstr "无 MCA 设备。" @@ -1401,17 +1335,17 @@ msgstr "网卡 3" msgid "Network Card #4" msgstr "网卡 4" -msgid "Mode" -msgstr "模式" +msgid "Mode:" +msgstr "模式:" -msgid "Interface" -msgstr "界面" +msgid "Interface:" +msgstr "界面:" -msgid "Adapter" -msgstr "适配器" +msgid "Adapter:" +msgstr "适配器:" -msgid "VDE Socket" -msgstr "VDE 套接字" +msgid "VDE Socket:" +msgstr "VDE 套接字:" msgid "86Box Unit Tester" msgstr "86Box 装置测试仪" @@ -1431,9 +1365,6 @@ msgstr "串行端口直通 3" msgid "Serial port passthrough 4" msgstr "串行端口直通 4" -msgid "Vision Systems LBA Enhancer" -msgstr "Vision Systems LBA 增强器" - msgid "Renderer options..." msgstr "渲染器选项..." @@ -1872,6 +1803,9 @@ msgstr "滚轮" msgid "Five + Wheel" msgstr "五键+滚轮" +msgid "Five + 2 Wheels" +msgstr "五键+双滚轮" + msgid "A3 - SMT2 Serial / SMT3(R)V" msgstr "A3 - SMT2 串行 / SMT3(R)V" @@ -2100,8 +2034,8 @@ msgstr "命名管道(服务器)" msgid "Host Serial Passthrough" msgstr "主机串行端口直通" -msgid "Eject %s" -msgstr "弹出 %s" +msgid "E&ject %1" +msgstr "弹出 %1(&J)" msgid "&Unmute" msgstr "解除静音(&U)" @@ -2112,11 +2046,110 @@ msgstr "Softfloat FPU" msgid "High performance impact" msgstr "重大性能影响" -msgid "RAM Disk (max. speed)" -msgstr "RAM 磁盘 (最大速度)" +msgid "[Generic] RAM Disk (max. speed)" +msgstr "[Generic] RAM 磁盘 (最大速度)" + +msgid "[Generic] 1989 (3500 RPM)" +msgstr "[Generic] 1989 (3500 RPM)" + +msgid "[Generic] 1992 (3600 RPM)" +msgstr "[Generic] 1992 (3600 RPM)" + +msgid "[Generic] 1994 (4500 RPM)" +msgstr "[Generic] 1994 (4500 RPM)" + +msgid "[Generic] 1996 (5400 RPM)" +msgstr "[Generic] 1996 (5400 RPM)" + +msgid "[Generic] 1997 (5400 RPM)" +msgstr "[Generic] 1997 (5400 RPM)" + +msgid "[Generic] 1998 (5400 RPM)" +msgstr "[Generic] 1998 (5400 RPM)" + +msgid "[Generic] 2000 (7200 RPM)" +msgstr "[Generic] 2000 (7200 RPM)" msgid "IBM 8514/A clone (ISA)" msgstr "IBM 8514/A 克隆 (ISA)" msgid "Vendor" msgstr "制造商" + +msgid "30 Hz (JMP2 = 1)" +msgstr "30 Hz (JMP2 = 1)" + +msgid "60 Hz (JMP2 = 2)" +msgstr "60 Hz (JMP2 = 2)" + +msgid "Generic PC/XT Memory Expansion" +msgstr "通用 PC/XT 内存扩展" + +msgid "Generic PC/AT Memory Expansion" +msgstr "通用 PC/AT 内存扩展" + +msgid "Unable to find Dot-Matrix fonts" +msgstr "无法找到点阵字体" + +msgid "TrueType fonts in the \"roms/printer/fonts\" directory are required for the emulation of the Generic ESC/P Dot-Matrix Printer." +msgstr "仿真通用 ESC/P 点阵打印机需要使用 \"roms/printer/fonts\" 目录中的 TrueType 字体。" + +msgid "Inhibit multimedia keys" +msgstr "禁止多媒体按键" + +msgid "Ask for confirmation before saving settings" +msgstr "保存设置前要求用户确认" + +msgid "Ask for confirmation before hard resetting" +msgstr "硬重置前要求用户确认" + +msgid "Ask for confirmation before quitting" +msgstr "退出前要求用户确认" + +msgid "Options" +msgstr "选项" + +msgid "Model" +msgstr "模型" + +msgid "Model:" +msgstr "模型:" + +msgid "Failed to initialize Vulkan renderer." +msgstr "Vulkan 渲染器初始化失败。" + +msgid "GLSL Error" +msgstr "GLSL 错误" + +msgid "Could not load shader: %1" +msgstr "无法加载着色器:%1" + +msgid "OpenGL version 3.0 or greater is required. Current GLSL version is %1.%2" +msgstr "OpenGL 版本需要达到 3.0 或更高。当前 GLSL 版本为 %1.%2" + +msgid "Could not load texture: %1" +msgstr "无法加载材质:%1" + +msgid "Could not compile shader:\n\n%1" +msgstr "无法编译着色器:\n\n%1" + +msgid "Program not linked:\n\n%1" +msgstr "程序未链接:\n\n%1" + +msgid "Shader Manager" +msgstr "着色器管理器" + +msgid "Shader Configuration" +msgstr "着色器配置" + +msgid "Add" +msgstr "添加" + +msgid "Move up" +msgstr "上移" + +msgid "Move down" +msgstr "下移" + +msgid "Could not load file %1" +msgstr "无法加载文件 %1" diff --git a/src/qt/languages/zh-TW.po b/src/qt/languages/zh-TW.po index f9e917d98..9d082a9af 100644 --- a/src/qt/languages/zh-TW.po +++ b/src/qt/languages/zh-TW.po @@ -18,8 +18,8 @@ msgstr "將右 CTRL 鍵映射為左 ALT 鍵(&R)" msgid "&Hard Reset..." msgstr "硬重設(&H)..." -msgid "&Ctrl+Alt+Del\tCtrl+F12" -msgstr "Ctrl+Alt+Del(&C)\tCtrl+F12" +msgid "&Ctrl+Alt+Del" +msgstr "Ctrl+Alt+Del(&C)" msgid "Ctrl+Alt+&Esc" msgstr "Ctrl+Alt+Esc(&E)" @@ -111,8 +111,8 @@ msgstr "線性(&L)" msgid "Hi&DPI scaling" msgstr "HiDPI 縮放(&D)" -msgid "&Fullscreen\tCtrl+Alt+PgUp" -msgstr "全螢幕(&F)\tCtrl+Alt+PgUp" +msgid "&Fullscreen" +msgstr "全螢幕(&F)" msgid "Fullscreen &stretch mode" msgstr "全螢幕拉伸模式(&S)" @@ -186,8 +186,11 @@ msgstr "設定(&S)..." msgid "&Update status bar icons" msgstr "更新狀態列圖示(&U)" -msgid "Take s&creenshot\tCtrl+F11" -msgstr "擷圖(&C)\tCtrl+F11" +msgid "Take s&creenshot" +msgstr "擷圖(&C)" + +msgid "S&ound" +msgstr "聲音(&O)" msgid "&Preferences..." msgstr "偏好設定(&P)..." @@ -198,11 +201,11 @@ msgstr "啟用 Discord 整合(&D)" msgid "Sound &gain..." msgstr "音量增益(&G)..." -msgid "Begin trace\tCtrl+T" -msgstr "開始追踪\tCtrl+T" +msgid "Begin trace" +msgstr "開始追踪" -msgid "End trace\tCtrl+T" -msgstr "結束追踪\tCtrl+T" +msgid "End trace" +msgstr "結束追踪" msgid "&Help" msgstr "說明(&H)" @@ -249,8 +252,8 @@ msgstr "靜音(&M)" msgid "E&mpty" msgstr "空置光碟機(&M)" -msgid "&Reload previous image" -msgstr "載入上一個映像(&R)" +msgid "Reload previous image" +msgstr "載入上一個映像" msgid "&Folder..." msgstr "資料夾(&F)..." @@ -306,18 +309,12 @@ msgstr "確定" msgid "Cancel" msgstr "取消" -msgid "Save these settings as &global defaults" -msgstr "將以上設定存儲為全局預設值(&G)" - msgid "&Default" msgstr "預設(&D)" msgid "Language:" msgstr "語言:" -msgid "Icon set:" -msgstr "圖示集:" - msgid "Gain" msgstr "增益" @@ -453,15 +450,6 @@ msgstr "Nuked (更準確)" msgid "YMFM (faster)" msgstr "YMFM (更快)" -msgid "Network type:" -msgstr "網路類型:" - -msgid "PCap device:" -msgstr "PCap 裝置:" - -msgid "Network adapter:" -msgstr "網路配接器:" - msgid "COM1 Device:" msgstr "COM1 裝置:" @@ -642,14 +630,11 @@ msgstr "致命錯誤" msgid " - PAUSED" msgstr " - 已暫停" -msgid "Press Ctrl+Alt+PgDn to return to windowed mode." -msgstr "按下 Ctrl+Alt+PgDn 返回到視窗模式。" - msgid "Speed" msgstr "速度" -msgid "ZIP %03i %i (%s): %ls" -msgstr "ZIP %03i %i (%s): %ls" +msgid "ZIP %1 %2 (%3): %4" +msgstr "ZIP %1 %2 (%3): %4" msgid "ZIP images" msgstr "ZIP 映像" @@ -687,8 +672,11 @@ msgstr "由於 roms/machines 資料夾中缺少合適的 ROM,機型 \"%hs\" msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." msgstr "由於 roms/video 資料夾中缺少合適的 ROM,顯示卡 \"%hs\" 不可用。將切換到其他可用顯示卡。" -msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "由於 roms/video 資料夾中缺少合適的 ROM,顯示卡 2 \"%hs\" 不可用。將切換到其他可用顯示卡。" +msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." +msgstr "由於 roms/video 資料夾中缺少合適的 ROM,顯示卡 2 \"%hs\" 不可用。禁用第二块显卡。" + +msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." +msgstr "由於缺少合適的 ROM,裝置 \"%hs\" 不可用。忽略设备。" msgid "Machine" msgstr "機型" @@ -750,14 +738,11 @@ msgstr "S" msgid "KB" msgstr "KB" -msgid "Could not initialize the video renderer." -msgstr "無法初始化視訊渲染器。" - msgid "Default" msgstr "預設" -msgid "%i Wait state(s)" -msgstr "%i 等待狀態 (WS)" +msgid "%1 Wait state(s)" +msgstr "%1 等待狀態 (WS)" msgid "Type" msgstr "類型" @@ -801,11 +786,11 @@ msgstr "Thrustmaster Flight Control System" msgid "None" msgstr "無" -msgid "%u MB (CHS: %i, %i, %i)" -msgstr "%u MB (CHS: %i, %i, %i)" +msgid "%1 MB (CHS: %2, %3, %4)" +msgstr "%1 MB (CHS: %2, %3, %4)" -msgid "Floppy %i (%s): %ls" -msgstr "軟碟 %i (%s): %ls" +msgid "Floppy %1 (%2): %3" +msgstr "軟碟 %1 (%2): %3" msgid "Advanced sector images" msgstr "進階磁區映像" @@ -825,8 +810,8 @@ msgstr "無法初始化 Ghostscript" msgid "Unable to initialize GhostPCL" msgstr "無法初始化 GhostPCL" -msgid "MO %i (%ls): %ls" -msgstr "磁光碟 %i (%ls): %ls" +msgid "MO %1 (%2): %3" +msgstr "磁光碟 %1 (%2): %3" msgid "MO images" msgstr "磁光碟映像" @@ -876,9 +861,6 @@ msgstr "%1 是將 PostScript 檔案轉換為 PDF 所需要的庫。\n\n使用通 msgid "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PCL printer will be saved as Printer Command Language (.pcl) files." msgstr "%1 是將 PCL 檔案轉換為 PDF 所需要的庫。\n\n使用通用 PCL 印表機列印的文件將被儲存為 Printer Command Language (.pcl) 檔案。" -msgid "Entering fullscreen mode" -msgstr "正在進入全螢幕模式" - msgid "Don't show this message again" msgstr "不要再顯示此消息" @@ -900,11 +882,8 @@ msgstr "%1 裝置設定" msgid "Monitor in sleep mode" msgstr "顯示器處在睡眠狀態" -msgid "OpenGL Shaders" -msgstr "OpenGL 著色器" - -msgid "OpenGL options" -msgstr "OpenGL 選項" +msgid "GLSL shaders" +msgstr "GLSL 著色器" msgid "You are loading an unsupported configuration" msgstr "正在載入一個不受支援的設定" @@ -915,24 +894,18 @@ msgstr "此模擬電腦停用了基於選定電腦的 CPU 類型過濾。\n\n能 msgid "Continue" msgstr "繼續" -msgid "Cassette: %s" -msgstr "磁帶: %s" +msgid "Cassette: %1" +msgstr "磁帶: %1" msgid "Cassette images" msgstr "磁帶映像" -msgid "Cartridge %i: %ls" -msgstr "卡帶 %i: %ls" +msgid "Cartridge %1: %2" +msgstr "卡帶 %1: %2" msgid "Cartridge images" msgstr "卡帶映像" -msgid "Error initializing renderer" -msgstr "初始化渲染器時出錯" - -msgid "OpenGL (3.0 Core) renderer could not be initialized. Use another renderer." -msgstr "無法初始化 OpenGL (3.0 Core) 渲染器。請使用其他渲染器。" - msgid "Resume execution" msgstr "恢復執行" @@ -1095,8 +1068,8 @@ msgstr "IDE" msgid "ATAPI" msgstr "ATAPI" -msgid "CD-ROM %i (%s): %s" -msgstr "光碟 %i (%s): %s" +msgid "CD-ROM %1 (%2): %3" +msgstr "光碟 %1 (%2): %3" msgid "160 KB" msgstr "160 KB" @@ -1275,9 +1248,6 @@ msgstr "清除映像歷史記錄" msgid "Create..." msgstr "建立..." -msgid "previous image" -msgstr "上一個映像" - msgid "Host CD/DVD Drive (%1)" msgstr "主機 CD/DVD 光碟機 (%1)" @@ -1287,23 +1257,8 @@ msgstr "未知匯流排" msgid "Null Driver" msgstr "空驅動程式" -msgid "NIC %02i (%ls) %ls" -msgstr "網路卡 %02i (%ls) %ls" - -msgid "Error opening \"%1\": %2" -msgstr "錯誤開啟 \"%1\": %2" - -msgid "Error compiling vertex shader in file \"%1\"" -msgstr "編譯檔案 \"%1\" 中的頂點著色器時發生錯誤" - -msgid "Error compiling fragment shader in file \"%1\"" -msgstr "編譯檔案 \"%1\" 中的片段著色器出錯" - -msgid "Error linking shader program in file \"%1\"" -msgstr "在檔案中連結shader程式出錯 \"%1\"" - -msgid "OpenGL 3.0 renderer options" -msgstr "OpenGL 3.0 渲染器選項" +msgid "NIC %1 (%2) %3" +msgstr "網路卡 %1 (%2) %3" msgid "Render behavior" msgstr "渲染行為" @@ -1317,9 +1272,6 @@ msgstr "fps" msgid "VSync" msgstr "VSync" -msgid "<html><head/><body><p>Render each frame immediately, in sync with the emulated display.</p><p><span style=" font-style:italic;">This is the recommended option if the shaders in use don't utilize frametime for animated effects.</span></p></body></html>" -msgstr "<html><head/><body><p>立即渲染每個畫面,與模擬顯示同步。</p><p><span style=" font-style:italic;">如果使用中的著色器不利用影格時間製作動畫效果,建議使用此選項。</span></p></body></html>" - msgid "Synchronize with video" msgstr "與視訊同步" @@ -1329,21 +1281,9 @@ msgstr "著色器" msgid "Remove" msgstr "移除" -msgid "No shader selected" -msgstr "未選擇著色器" - msgid "Browse..." msgstr "瀏覽..." -msgid "Shader error" -msgstr "著色器錯誤" - -msgid "Could not load shaders." -msgstr "無法載入著色器。" - -msgid "More information in details." -msgstr "更多詳細資訊。" - msgid "Couldn't create OpenGL context." msgstr "無法建立 OpenGL 上下文。" @@ -1353,20 +1293,14 @@ msgstr "無法切換至 OpenGL 上下文。" msgid "OpenGL version 3.0 or greater is required. Current version is %1.%2" msgstr "需要 OpenGL 版本 3.0 或更高。目前版本為 %1.%2" -msgid "OpenGL initialization failed. Error %1." -msgstr "OpenGL 初始化失敗。錯誤 %1." - msgid "Error initializing OpenGL" msgstr "初始化 OpenGL 出錯" -msgid "Falling back to software rendering.\n" -msgstr "回退到軟體渲染。" +msgid "\nFalling back to software rendering." +msgstr "\n回退到軟體渲染。" -msgid "Allocating memory for unpack buffer failed.\n" -msgstr "為解除封包緩衝區分配記憶體失敗。\n" - -msgid "<html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html>" -msgstr "<html><head/><body><p>當選擇媒體映像 (CD-ROM、軟碟等) 時,開啟對話方塊會在與 86Box 設定檔相同的目錄中開始。此設定可能只會在 macOS 上有所影響。</p></body></html>" +msgid "

When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" +msgstr "

當選擇媒體映像 (CD-ROM、軟碟等) 時,開啟對話方塊會在與 86Box 設定檔相同的目錄中開始。此設定可能只會在 macOS 上有所影響。

" msgid "This machine might have been moved or copied." msgstr "這台機器可能已被移動或複製。" @@ -1401,17 +1335,17 @@ msgstr "網路卡 3" msgid "Network Card #4" msgstr "網路卡 4" -msgid "Mode" -msgstr "模式" +msgid "Mode:" +msgstr "模式:" -msgid "Interface" -msgstr "介面" +msgid "Interface:" +msgstr "介面:" -msgid "Adapter" -msgstr "配接器" +msgid "Adapter:" +msgstr "配接器:" -msgid "VDE Socket" -msgstr "VDE 插座" +msgid "VDE Socket:" +msgstr "VDE 插座:" msgid "86Box Unit Tester" msgstr "86Box 單元測試器" @@ -1431,9 +1365,6 @@ msgstr "序列埠的直通 3" msgid "Serial port passthrough 4" msgstr "序列埠的直通 4" -msgid "Vision Systems LBA Enhancer" -msgstr "Vision Systems LBA Enhancer" - msgid "Renderer options..." msgstr "渲染器選項..." @@ -1872,6 +1803,9 @@ msgstr "滾輪" msgid "Five + Wheel" msgstr "五鍵 + 滾輪" +msgid "Five + 2 Wheels" +msgstr "" + msgid "A3 - SMT2 Serial / SMT3(R)V" msgstr "A3 - SMT2 序列 / SMT3(R)V" @@ -2059,7 +1993,7 @@ msgid "Generic Text Printer" msgstr "通用文字印表機" msgid "Generic ESC/P Dot-Matrix Printer" -msgstr "通用 ESC/P 點矩陣" +msgstr "通用 ESC/P 點矩陣印表機" msgid "Generic PostScript Printer" msgstr "通用 PostScript 印表機" @@ -2100,11 +2034,11 @@ msgstr "已命名管道 (伺服器)" msgid "Host Serial Passthrough" msgstr "主機序列埠的直通" -msgid "Eject %s" -msgstr "退出 %s" +msgid "E&ject %1" +msgstr "退出 %1(&J)" msgid "&Unmute" -msgstr "解除靜音 (&U)" +msgstr "解除靜音(&U)" msgid "Softfloat FPU" msgstr "Softfloat FPU" @@ -2112,11 +2046,104 @@ msgstr "Softfloat FPU" msgid "High performance impact" msgstr "對效能影響大" -msgid "RAM Disk (max. speed)" -msgstr "RAM 磁碟 (最大速度)" +msgid "[Generic] RAM Disk (max. speed)" +msgstr "[Generic] RAM 磁碟 (最大速度)" + +msgid "[Generic] 1989 (3500 RPM)" +msgstr "" + +msgid "[Generic] 1992 (3600 RPM)" +msgstr "" + +msgid "[Generic] 1994 (4500 RPM)" +msgstr "" + +msgid "[Generic] 1996 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1997 (5400 RPM)" +msgstr "" + +msgid "[Generic] 1998 (5400 RPM)" +msgstr "" + +msgid "[Generic] 2000 (7200 RPM)" +msgstr "" msgid "IBM 8514/A clone (ISA)" msgstr "IBM 8514/A 克隆 (ISA)" msgid "Vendor" msgstr "製造商" + +msgid "Generic PC/XT Memory Expansion" +msgstr "通用 PC/XT 記憶體擴充" + +msgid "Generic PC/AT Memory Expansion" +msgstr "通用 PC/AT 記憶體擴充" + +msgid "Unable to find Dot-Matrix fonts" +msgstr "無法找到點矩陣字型" + +msgid "TrueType fonts in the \"roms/printer/fonts\" directory are required for the emulation of the Generic ESC/P Dot-Matrix Printer." +msgstr "通用 ESC/P 點矩陣印表機的模擬需要 \"roms/printer/fonts\" 目錄中的 TrueType 字體。" + +msgid "Inhibit multimedia keys" +msgstr "" + +msgid "Ask for confirmation before saving settings" +msgstr "" + +msgid "Ask for confirmation before hard resetting" +msgstr "" + +msgid "Ask for confirmation before quitting" +msgstr "" + +msgid "Options" +msgstr "" + +msgid "Model" +msgstr "" + +msgid "Model:" +msgstr "" + +msgid "Failed to initialize Vulkan renderer." +msgstr "" + +msgid "GLSL Error" +msgstr "" + +msgid "Could not load shader: %1" +msgstr "" + +msgid "OpenGL version 3.0 or greater is required. Current GLSL version is %1.%2" +msgstr "" + +msgid "Could not load texture: %1" +msgstr "" + +msgid "Could not compile shader:\n\n%1" +msgstr "" + +msgid "Program not linked:\n\n%1" +msgstr "" + +msgid "Shader Manager" +msgstr "" + +msgid "Shader Configuration" +msgstr "" + +msgid "Add" +msgstr "" + +msgid "Move up" +msgstr "" + +msgid "Move down" +msgstr "" + +msgid "Could not load file %1" +msgstr "" diff --git a/src/qt/macos_event_filter.mm b/src/qt/macos_event_filter.mm index ff4e7c4d2..45c8ecbe3 100644 --- a/src/qt/macos_event_filter.mm +++ b/src/qt/macos_event_filter.mm @@ -37,6 +37,7 @@ CocoaEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, return true; } if ([event type] == NSEventTypeScrollWheel) { + mouse_set_w(-[event deltaX]); mouse_set_z([event deltaY]); return true; } diff --git a/src/qt/qdarkstyle/dark/darkstyle.qrc b/src/qt/qdarkstyle/dark/darkstyle.qrc new file mode 100644 index 000000000..ce0d85be6 --- /dev/null +++ b/src/qt/qdarkstyle/dark/darkstyle.qrc @@ -0,0 +1,216 @@ + + + + rc/arrow_down.png + rc/arrow_down@2x.png + rc/arrow_down_disabled.png + rc/arrow_down_disabled@2x.png + rc/arrow_down_focus.png + rc/arrow_down_focus@2x.png + rc/arrow_down_pressed.png + rc/arrow_down_pressed@2x.png + rc/arrow_left.png + rc/arrow_left@2x.png + rc/arrow_left_disabled.png + rc/arrow_left_disabled@2x.png + rc/arrow_left_focus.png + rc/arrow_left_focus@2x.png + rc/arrow_left_pressed.png + rc/arrow_left_pressed@2x.png + rc/arrow_right.png + rc/arrow_right@2x.png + rc/arrow_right_disabled.png + rc/arrow_right_disabled@2x.png + rc/arrow_right_focus.png + rc/arrow_right_focus@2x.png + rc/arrow_right_pressed.png + rc/arrow_right_pressed@2x.png + rc/arrow_up.png + rc/arrow_up@2x.png + rc/arrow_up_disabled.png + rc/arrow_up_disabled@2x.png + rc/arrow_up_focus.png + rc/arrow_up_focus@2x.png + rc/arrow_up_pressed.png + rc/arrow_up_pressed@2x.png + rc/base_icon.png + rc/base_icon@2x.png + rc/base_icon_disabled.png + rc/base_icon_disabled@2x.png + rc/base_icon_focus.png + rc/base_icon_focus@2x.png + rc/base_icon_pressed.png + rc/base_icon_pressed@2x.png + rc/branch_closed.png + rc/branch_closed@2x.png + rc/branch_closed_disabled.png + rc/branch_closed_disabled@2x.png + rc/branch_closed_focus.png + rc/branch_closed_focus@2x.png + rc/branch_closed_pressed.png + rc/branch_closed_pressed@2x.png + rc/branch_end.png + rc/branch_end@2x.png + rc/branch_end_disabled.png + rc/branch_end_disabled@2x.png + rc/branch_end_focus.png + rc/branch_end_focus@2x.png + rc/branch_end_pressed.png + rc/branch_end_pressed@2x.png + rc/branch_line.png + rc/branch_line@2x.png + rc/branch_line_disabled.png + rc/branch_line_disabled@2x.png + rc/branch_line_focus.png + rc/branch_line_focus@2x.png + rc/branch_line_pressed.png + rc/branch_line_pressed@2x.png + rc/branch_more.png + rc/branch_more@2x.png + rc/branch_more_disabled.png + rc/branch_more_disabled@2x.png + rc/branch_more_focus.png + rc/branch_more_focus@2x.png + rc/branch_more_pressed.png + rc/branch_more_pressed@2x.png + rc/branch_open.png + rc/branch_open@2x.png + rc/branch_open_disabled.png + rc/branch_open_disabled@2x.png + rc/branch_open_focus.png + rc/branch_open_focus@2x.png + rc/branch_open_pressed.png + rc/branch_open_pressed@2x.png + rc/checkbox_checked.png + rc/checkbox_checked@2x.png + rc/checkbox_checked_disabled.png + rc/checkbox_checked_disabled@2x.png + rc/checkbox_checked_focus.png + rc/checkbox_checked_focus@2x.png + rc/checkbox_checked_pressed.png + rc/checkbox_checked_pressed@2x.png + rc/checkbox_indeterminate.png + rc/checkbox_indeterminate@2x.png + rc/checkbox_indeterminate_disabled.png + rc/checkbox_indeterminate_disabled@2x.png + rc/checkbox_indeterminate_focus.png + rc/checkbox_indeterminate_focus@2x.png + rc/checkbox_indeterminate_pressed.png + rc/checkbox_indeterminate_pressed@2x.png + rc/checkbox_unchecked.png + rc/checkbox_unchecked@2x.png + rc/checkbox_unchecked_disabled.png + rc/checkbox_unchecked_disabled@2x.png + rc/checkbox_unchecked_focus.png + rc/checkbox_unchecked_focus@2x.png + rc/checkbox_unchecked_pressed.png + rc/checkbox_unchecked_pressed@2x.png + rc/line_horizontal.png + rc/line_horizontal@2x.png + rc/line_horizontal_disabled.png + rc/line_horizontal_disabled@2x.png + rc/line_horizontal_focus.png + rc/line_horizontal_focus@2x.png + rc/line_horizontal_pressed.png + rc/line_horizontal_pressed@2x.png + rc/line_vertical.png + rc/line_vertical@2x.png + rc/line_vertical_disabled.png + rc/line_vertical_disabled@2x.png + rc/line_vertical_focus.png + rc/line_vertical_focus@2x.png + rc/line_vertical_pressed.png + rc/line_vertical_pressed@2x.png + rc/radio_checked.png + rc/radio_checked@2x.png + rc/radio_checked_disabled.png + rc/radio_checked_disabled@2x.png + rc/radio_checked_focus.png + rc/radio_checked_focus@2x.png + rc/radio_checked_pressed.png + rc/radio_checked_pressed@2x.png + rc/radio_unchecked.png + rc/radio_unchecked@2x.png + rc/radio_unchecked_disabled.png + rc/radio_unchecked_disabled@2x.png + rc/radio_unchecked_focus.png + rc/radio_unchecked_focus@2x.png + rc/radio_unchecked_pressed.png + rc/radio_unchecked_pressed@2x.png + rc/toolbar_move_horizontal.png + rc/toolbar_move_horizontal@2x.png + rc/toolbar_move_horizontal_disabled.png + rc/toolbar_move_horizontal_disabled@2x.png + rc/toolbar_move_horizontal_focus.png + rc/toolbar_move_horizontal_focus@2x.png + rc/toolbar_move_horizontal_pressed.png + rc/toolbar_move_horizontal_pressed@2x.png + rc/toolbar_move_vertical.png + rc/toolbar_move_vertical@2x.png + rc/toolbar_move_vertical_disabled.png + rc/toolbar_move_vertical_disabled@2x.png + rc/toolbar_move_vertical_focus.png + rc/toolbar_move_vertical_focus@2x.png + rc/toolbar_move_vertical_pressed.png + rc/toolbar_move_vertical_pressed@2x.png + rc/toolbar_separator_horizontal.png + rc/toolbar_separator_horizontal@2x.png + rc/toolbar_separator_horizontal_disabled.png + rc/toolbar_separator_horizontal_disabled@2x.png + rc/toolbar_separator_horizontal_focus.png + rc/toolbar_separator_horizontal_focus@2x.png + rc/toolbar_separator_horizontal_pressed.png + rc/toolbar_separator_horizontal_pressed@2x.png + rc/toolbar_separator_vertical.png + rc/toolbar_separator_vertical@2x.png + rc/toolbar_separator_vertical_disabled.png + rc/toolbar_separator_vertical_disabled@2x.png + rc/toolbar_separator_vertical_focus.png + rc/toolbar_separator_vertical_focus@2x.png + rc/toolbar_separator_vertical_pressed.png + rc/toolbar_separator_vertical_pressed@2x.png + rc/transparent.png + rc/transparent@2x.png + rc/transparent_disabled.png + rc/transparent_disabled@2x.png + rc/transparent_focus.png + rc/transparent_focus@2x.png + rc/transparent_pressed.png + rc/transparent_pressed@2x.png + rc/window_close.png + rc/window_close@2x.png + rc/window_close_disabled.png + rc/window_close_disabled@2x.png + rc/window_close_focus.png + rc/window_close_focus@2x.png + rc/window_close_pressed.png + rc/window_close_pressed@2x.png + rc/window_grip.png + rc/window_grip@2x.png + rc/window_grip_disabled.png + rc/window_grip_disabled@2x.png + rc/window_grip_focus.png + rc/window_grip_focus@2x.png + rc/window_grip_pressed.png + rc/window_grip_pressed@2x.png + rc/window_minimize.png + rc/window_minimize@2x.png + rc/window_minimize_disabled.png + rc/window_minimize_disabled@2x.png + rc/window_minimize_focus.png + rc/window_minimize_focus@2x.png + rc/window_minimize_pressed.png + rc/window_minimize_pressed@2x.png + rc/window_undock.png + rc/window_undock@2x.png + rc/window_undock_disabled.png + rc/window_undock_disabled@2x.png + rc/window_undock_focus.png + rc/window_undock_focus@2x.png + rc/window_undock_pressed.png + rc/window_undock_pressed@2x.png + + + darkstyle.qss + + diff --git a/src/qt/qdarkstyle/dark/darkstyle.qss b/src/qt/qdarkstyle/dark/darkstyle.qss new file mode 100644 index 000000000..134d6708e --- /dev/null +++ b/src/qt/qdarkstyle/dark/darkstyle.qss @@ -0,0 +1,2204 @@ +/* --------------------------------------------------------------------------- + + WARNING! File created programmatically. All changes made in this file will be lost! + + Created by the qtsass compiler v0.4.0 + + The definitions are in the "qdarkstyle.qss._styles.scss" module + +--------------------------------------------------------------------------- */ +/* Light Style - QDarkStyleSheet ------------------------------------------ */ +/* + +See Qt documentation: + + - https://doc.qt.io/qt-5/stylesheet.html + - https://doc.qt.io/qt-5/stylesheet-reference.html + - https://doc.qt.io/qt-5/stylesheet-examples.html + +--------------------------------------------------------------------------- */ +/* Reset elements ------------------------------------------------------------ + +Resetting everything helps to unify styles across different operating systems + +--------------------------------------------------------------------------- */ + +/* Changed to be fully grayscale. */ + +* { + padding: 0px; + margin: 0px; + border: 0px; + border-style: none; + border-image: none; + outline: 0; +} + +/* specific reset for elements inside QToolBar */ +QToolBar * { + margin: 0px; + padding: 0px; +} + +/* QWidget ---------------------------------------------------------------- + +--------------------------------------------------------------------------- */ +QWidget { + background-color: #272727; + border: 0px solid #525252; + padding: 0px; + color: #E3E3E3; + selection-background-color: #616161; + selection-color: #E3E3E3; +} + +QWidget:disabled { + background-color: #272727; + color: #8B8B8B; + selection-background-color: #444444; + selection-color: #8B8B8B; +} + +QWidget::item:selected { + background-color: #616161; +} + +QWidget::item:hover:!selected { + background-color: #666666; +} + +/* QMainWindow ------------------------------------------------------------ + +This adjusts the splitter in the dock widget, not qsplitter +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qmainwindow + +--------------------------------------------------------------------------- */ +QMainWindow::separator { + background-color: #525252; + border: 0px solid #272727; + spacing: 0px; + padding: 2px; +} + +QMainWindow::separator:hover { + background-color: #767676; + border: 0px solid #666666; +} + +QMainWindow::separator:horizontal { + width: 5px; + margin-top: 2px; + margin-bottom: 2px; + image: url(":/qss_icons/dark/rc/toolbar_separator_vertical.png"); +} + +QMainWindow::separator:vertical { + height: 5px; + margin-left: 2px; + margin-right: 2px; + image: url(":/qss_icons/dark/rc/toolbar_separator_horizontal.png"); +} + +/* QToolTip --------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qtooltip + +--------------------------------------------------------------------------- */ +QToolTip { + background-color: #616161; + color: #E3E3E3; + /* If you remove the border property, background stops working on Windows */ + border: none; + /* Remove padding, for fix combo box tooltip */ + padding: 0px; + /* Remove opacity, fix #174 - may need to use RGBA */ +} + +/* QStatusBar ------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qstatusbar + +--------------------------------------------------------------------------- */ +QStatusBar { + border: 1px solid #272727; + /* Fixes Spyder #9120, #9121 */ + background: #272727; + /* Fixes #205, white vertical borders separating items */ +} + +QStatusBar::item { + border: none; +} + +QStatusBar QLabel { + /* Fixes Spyder #9120, #9121 */ + background: transparent; + padding: 0px; +} + +/* QCheckBox -------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qcheckbox + +--------------------------------------------------------------------------- */ +QCheckBox { + background-color: #272727; + color: #E3E3E3; + spacing: 4px; + outline: none; + padding-top: 4px; + padding-bottom: 4px; +} + +QCheckBox:focus { + border: none; +} + +QCheckBox QWidget:disabled { + background-color: #272727; + color: #8B8B8B; +} + +QCheckBox::indicator { + margin-left: 2px; + height: 14px; + width: 14px; +} + +QCheckBox::indicator:unchecked { + image: url(":/qss_icons/dark/rc/checkbox_unchecked.png"); +} + +QCheckBox::indicator:unchecked:hover, QCheckBox::indicator:unchecked:focus, QCheckBox::indicator:unchecked:pressed { + border: none; + image: url(":/qss_icons/dark/rc/checkbox_unchecked_focus.png"); +} + +QCheckBox::indicator:unchecked:disabled { + image: url(":/qss_icons/dark/rc/checkbox_unchecked_disabled.png"); +} + +QCheckBox::indicator:checked { + image: url(":/qss_icons/dark/rc/checkbox_checked.png"); +} + +QCheckBox::indicator:checked:hover, QCheckBox::indicator:checked:focus, QCheckBox::indicator:checked:pressed { + border: none; + image: url(":/qss_icons/dark/rc/checkbox_checked_focus.png"); +} + +QCheckBox::indicator:checked:disabled { + image: url(":/qss_icons/dark/rc/checkbox_checked_disabled.png"); +} + +QCheckBox::indicator:indeterminate { + image: url(":/qss_icons/dark/rc/checkbox_indeterminate.png"); +} + +QCheckBox::indicator:indeterminate:disabled { + image: url(":/qss_icons/dark/rc/checkbox_indeterminate_disabled.png"); +} + +QCheckBox::indicator:indeterminate:focus, QCheckBox::indicator:indeterminate:hover, QCheckBox::indicator:indeterminate:pressed { + image: url(":/qss_icons/dark/rc/checkbox_indeterminate_focus.png"); +} + +/* QGroupBox -------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qgroupbox + +--------------------------------------------------------------------------- */ +QGroupBox { + font-weight: bold; + border: 1px solid #525252; + border-radius: 4px; + padding: 2px; + margin-top: 6px; + margin-bottom: 4px; +} + +QGroupBox::title { + subcontrol-origin: margin; + subcontrol-position: top left; + left: 4px; + padding-left: 2px; + padding-right: 4px; + padding-top: -4px; +} + +QGroupBox::indicator { + margin-left: 2px; + margin-top: 2px; + padding: 0; + height: 14px; + width: 14px; +} + +QGroupBox::indicator:unchecked { + border: none; + image: url(":/qss_icons/dark/rc/checkbox_unchecked.png"); +} + +QGroupBox::indicator:unchecked:hover, QGroupBox::indicator:unchecked:focus, QGroupBox::indicator:unchecked:pressed { + border: none; + image: url(":/qss_icons/dark/rc/checkbox_unchecked_focus.png"); +} + +QGroupBox::indicator:unchecked:disabled { + image: url(":/qss_icons/dark/rc/checkbox_unchecked_disabled.png"); +} + +QGroupBox::indicator:checked { + border: none; + image: url(":/qss_icons/dark/rc/checkbox_checked.png"); +} + +QGroupBox::indicator:checked:hover, QGroupBox::indicator:checked:focus, QGroupBox::indicator:checked:pressed { + border: none; + image: url(":/qss_icons/dark/rc/checkbox_checked_focus.png"); +} + +QGroupBox::indicator:checked:disabled { + image: url(":/qss_icons/dark/rc/checkbox_checked_disabled.png"); +} + +/* QRadioButton ----------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qradiobutton + +--------------------------------------------------------------------------- */ +QRadioButton { + background-color: #272727; + color: #E3E3E3; + spacing: 4px; + padding-top: 4px; + padding-bottom: 4px; + border: none; + outline: none; +} + +QRadioButton:focus { + border: none; +} + +QRadioButton:disabled { + background-color: #272727; + color: #8B8B8B; + border: none; + outline: none; +} + +QRadioButton QWidget { + background-color: #272727; + color: #E3E3E3; + spacing: 0px; + padding: 0px; + outline: none; + border: none; +} + +QRadioButton::indicator { + border: none; + outline: none; + margin-left: 2px; + height: 14px; + width: 14px; +} + +QRadioButton::indicator:unchecked { + image: url(":/qss_icons/dark/rc/radio_unchecked.png"); +} + +QRadioButton::indicator:unchecked:hover, QRadioButton::indicator:unchecked:focus, QRadioButton::indicator:unchecked:pressed { + border: none; + outline: none; + image: url(":/qss_icons/dark/rc/radio_unchecked_focus.png"); +} + +QRadioButton::indicator:unchecked:disabled { + image: url(":/qss_icons/dark/rc/radio_unchecked_disabled.png"); +} + +QRadioButton::indicator:checked { + border: none; + outline: none; + image: url(":/qss_icons/dark/rc/radio_checked.png"); +} + +QRadioButton::indicator:checked:hover, QRadioButton::indicator:checked:focus, QRadioButton::indicator:checked:pressed { + border: none; + outline: none; + image: url(":/qss_icons/dark/rc/radio_checked_focus.png"); +} + +QRadioButton::indicator:checked:disabled { + outline: none; + image: url(":/qss_icons/dark/rc/radio_checked_disabled.png"); +} + +/* QMenuBar --------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qmenubar + +--------------------------------------------------------------------------- */ +QMenuBar { + background-color: #272727; + padding: 2px; + border: 1px solid #525252; + color: #E3E3E3; + selection-background-color: #666666; +} + +QMenuBar:focus { + border: 1px solid #616161; +} + +QMenuBar::item { + background: transparent; + padding-left: 7px; + padding-right: 7px; +} + +QMenuBar::item:selected { + padding: 4px; + background: transparent; + border: 0px solid #525252; + background-color: #383838; +} + +QMenuBar::item:pressed { + padding: 4px; + border: 0px solid #525252; + background-color: #383838; + color: #E3E3E3; +} + +/* QMenu ------------------------------------------------------------------ + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qmenu + +--------------------------------------------------------------------------- */ +QMenu { + border: 0px solid #525252; + color: #E3E3E3; + margin: 0px; + background-color: #2C2C2C; + selection-background-color: #666666; +} + +QMenu::separator { + height: 1px; + background-color: #767676; + color: #E3E3E3; +} + +QMenu::item { + background-color: #2C2C2C; + padding: 4px 24px 4px 28px; + /* Reserve space for selection border */ + border: 1px transparent #525252; +} + +QMenu::item:selected { + color: #E3E3E3; + background-color: #353535; +} + +QMenu::item:pressed { + background-color: #353535; +} + +QMenu::icon { + padding-left: 10px; + width: 14px; + height: 14px; +} + +QMenu::indicator { + padding-left: 8px; + width: 12px; + height: 12px; + /* non-exclusive indicator = check box style indicator (see QActionGroup::setExclusive) */ + /* exclusive indicator = radio button style indicator (see QActionGroup::setExclusive) */ +} + +QMenu::indicator:non-exclusive:unchecked { + image: url(":/qss_icons/dark/rc/checkbox_unchecked.png"); +} + +QMenu::indicator:non-exclusive:unchecked:hover, QMenu::indicator:non-exclusive:unchecked:focus, QMenu::indicator:non-exclusive:unchecked:pressed { + border: none; + image: url(":/qss_icons/dark/rc/checkbox_unchecked_focus.png"); +} + +QMenu::indicator:non-exclusive:unchecked:disabled { + image: url(":/qss_icons/dark/rc/checkbox_unchecked_disabled.png"); +} + +QMenu::indicator:non-exclusive:checked { + image: url(":/qss_icons/dark/rc/checkbox_checked.png"); +} + +QMenu::indicator:non-exclusive:checked:hover, QMenu::indicator:non-exclusive:checked:focus, QMenu::indicator:non-exclusive:checked:pressed { + border: none; + image: url(":/qss_icons/dark/rc/checkbox_checked_focus.png"); +} + +QMenu::indicator:non-exclusive:checked:disabled { + image: url(":/qss_icons/dark/rc/checkbox_checked_disabled.png"); +} + +QMenu::indicator:non-exclusive:indeterminate { + image: url(":/qss_icons/dark/rc/checkbox_indeterminate.png"); +} + +QMenu::indicator:non-exclusive:indeterminate:disabled { + image: url(":/qss_icons/dark/rc/checkbox_indeterminate_disabled.png"); +} + +QMenu::indicator:non-exclusive:indeterminate:focus, QMenu::indicator:non-exclusive:indeterminate:hover, QMenu::indicator:non-exclusive:indeterminate:pressed { + image: url(":/qss_icons/dark/rc/checkbox_indeterminate_focus.png"); +} + +QMenu::indicator:exclusive:unchecked { + image: url(":/qss_icons/dark/rc/radio_unchecked.png"); +} + +QMenu::indicator:exclusive:unchecked:hover, QMenu::indicator:exclusive:unchecked:focus, QMenu::indicator:exclusive:unchecked:pressed { + border: none; + outline: none; + image: url(":/qss_icons/dark/rc/radio_unchecked_focus.png"); +} + +QMenu::indicator:exclusive:unchecked:disabled { + image: url(":/qss_icons/dark/rc/radio_unchecked_disabled.png"); +} + +QMenu::indicator:exclusive:checked { + border: none; + outline: none; + image: url(":/qss_icons/dark/rc/radio_checked.png"); +} + +QMenu::indicator:exclusive:checked:hover, QMenu::indicator:exclusive:checked:focus, QMenu::indicator:exclusive:checked:pressed { + border: none; + outline: none; + image: url(":/qss_icons/dark/rc/radio_checked_focus.png"); +} + +QMenu::indicator:exclusive:checked:disabled { + outline: none; + image: url(":/qss_icons/dark/rc/radio_checked_disabled.png"); +} + +QMenu::right-arrow { + margin: 5px; + padding-left: 12px; + image: url(":/qss_icons/dark/rc/arrow_right.png"); + height: 12px; + width: 12px; +} + +/* QAbstractItemView ------------------------------------------------------ + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qcombobox + +--------------------------------------------------------------------------- */ +QAbstractItemView { + alternate-background-color: #272727; + color: #E3E3E3; + border: 1px solid #525252; + border-radius: 4px; +} + +QAbstractItemView QLineEdit { + padding: 2px; +} + +/* QAbstractScrollArea ---------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qabstractscrollarea + +--------------------------------------------------------------------------- */ +QAbstractScrollArea { + background-color: #272727; + border: 1px solid #525252; + border-radius: 4px; + /* fix #159 */ + padding: 2px; + /* remove min-height to fix #244 */ + color: #E3E3E3; +} + +QAbstractScrollArea:disabled { + color: #8B8B8B; +} + +/* QScrollArea ------------------------------------------------------------ + +--------------------------------------------------------------------------- */ +QScrollArea QWidget QWidget:disabled { + background-color: #272727; +} + +/* QScrollBar ------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qscrollbar + +--------------------------------------------------------------------------- */ +QScrollBar:horizontal { + height: 16px; + margin: 2px 16px 2px 16px; + border: 1px solid #525252; + border-radius: 4px; + background-color: #272727; +} + +QScrollBar:vertical { + background-color: #272727; + width: 16px; + margin: 16px 2px 16px 2px; + border: 1px solid #525252; + border-radius: 4px; +} + +QScrollBar::handle:horizontal { + background-color: #767676; + border: 1px solid #525252; + border-radius: 4px; + min-width: 8px; +} + +QScrollBar::handle:horizontal:hover { + background-color: #616161; + border: #616161; + border-radius: 4px; + min-width: 8px; +} + +QScrollBar::handle:horizontal:focus { + border: 1px solid #666666; +} + +QScrollBar::handle:vertical { + background-color: #767676; + border: 1px solid #525252; + min-height: 8px; + border-radius: 4px; +} + +QScrollBar::handle:vertical:hover { + background-color: #616161; + border: #616161; + border-radius: 4px; + min-height: 8px; +} + +QScrollBar::handle:vertical:focus { + border: 1px solid #666666; +} + +QScrollBar::add-line:horizontal { + margin: 0px 0px 0px 0px; + border-image: url(":/qss_icons/dark/rc/arrow_right_disabled.png"); + height: 12px; + width: 12px; + subcontrol-position: right; + subcontrol-origin: margin; +} + +QScrollBar::add-line:horizontal:hover, QScrollBar::add-line:horizontal:on { + border-image: url(":/qss_icons/dark/rc/arrow_right.png"); + height: 12px; + width: 12px; + subcontrol-position: right; + subcontrol-origin: margin; +} + +QScrollBar::add-line:vertical { + margin: 3px 0px 3px 0px; + border-image: url(":/qss_icons/dark/rc/arrow_down_disabled.png"); + height: 12px; + width: 12px; + subcontrol-position: bottom; + subcontrol-origin: margin; +} + +QScrollBar::add-line:vertical:hover, QScrollBar::add-line:vertical:on { + border-image: url(":/qss_icons/dark/rc/arrow_down.png"); + height: 12px; + width: 12px; + subcontrol-position: bottom; + subcontrol-origin: margin; +} + +QScrollBar::sub-line:horizontal { + margin: 0px 3px 0px 3px; + border-image: url(":/qss_icons/dark/rc/arrow_left_disabled.png"); + height: 12px; + width: 12px; + subcontrol-position: left; + subcontrol-origin: margin; +} + +QScrollBar::sub-line:horizontal:hover, QScrollBar::sub-line:horizontal:on { + border-image: url(":/qss_icons/dark/rc/arrow_left.png"); + height: 12px; + width: 12px; + subcontrol-position: left; + subcontrol-origin: margin; +} + +QScrollBar::sub-line:vertical { + margin: 3px 0px 3px 0px; + border-image: url(":/qss_icons/dark/rc/arrow_up_disabled.png"); + height: 12px; + width: 12px; + subcontrol-position: top; + subcontrol-origin: margin; +} + +QScrollBar::sub-line:vertical:hover, QScrollBar::sub-line:vertical:on { + border-image: url(":/qss_icons/dark/rc/arrow_up.png"); + height: 12px; + width: 12px; + subcontrol-position: top; + subcontrol-origin: margin; +} + +QScrollBar::up-arrow:horizontal, QScrollBar::down-arrow:horizontal { + background: none; +} + +QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical { + background: none; +} + +QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal { + background: none; +} + +QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical { + background: none; +} + +/* QTextEdit -------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-specific-widgets + +--------------------------------------------------------------------------- */ +QTextEdit { + background-color: #272727; + color: #E3E3E3; + border-radius: 4px; + border: 1px solid #525252; +} + +QTextEdit:focus { + border: 1px solid #666666; +} + +QTextEdit:selected { + background: #616161; + color: #525252; +} + +/* QPlainTextEdit --------------------------------------------------------- + +--------------------------------------------------------------------------- */ +QPlainTextEdit { + background-color: #272727; + color: #E3E3E3; + border-radius: 4px; + border: 1px solid #525252; +} + +QPlainTextEdit:focus { + border: 1px solid #666666; +} + +QPlainTextEdit:selected { + background: #616161; + color: #525252; +} + +/* QSizeGrip -------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qsizegrip + +--------------------------------------------------------------------------- */ +QSizeGrip { + background: transparent; + width: 12px; + height: 12px; + image: url(":/qss_icons/dark/rc/window_grip.png"); +} + +/* QToolBar --------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qtoolbar + +--------------------------------------------------------------------------- */ +QToolBar { + background-color: #272727; + border-bottom: 1px solid #272727; + padding: 1px; + font-weight: bold; +} + +QToolBar:disabled { + /* Fixes #272 */ + background-color: #272727; +} + +QToolBar::handle:horizontal { + width: 16px; + image: url(":/qss_icons/dark/rc/toolbar_move_horizontal.png"); +} + +QToolBar::handle:vertical { + height: 16px; + image: url(":/qss_icons/dark/rc/toolbar_move_vertical.png"); +} + +QToolBar::separator:horizontal { + width: 16px; + image: url(":/qss_icons/dark/rc/toolbar_separator_horizontal.png"); +} + +QToolBar::separator:vertical { + height: 16px; + image: url(":/qss_icons/dark/rc/toolbar_separator_vertical.png"); +} + +QToolButton#qt_toolbar_ext_button { + background: #272727; + border: 0px; + color: #E3E3E3; + image: url(":/qss_icons/dark/rc/arrow_right.png"); +} + +/* QAbstractSpinBox ------------------------------------------------------- + +--------------------------------------------------------------------------- */ +QAbstractSpinBox { + background-color: #272727; + border: 1px solid #525252; + color: #E3E3E3; + /* This fixes 103, 111 */ + padding-top: 2px; + /* This fixes 103, 111 */ + padding-bottom: 2px; + padding-left: 4px; + padding-right: 4px; + border-radius: 4px; + /* min-width: 5px; removed to fix 109 */ +} + +QAbstractSpinBox:up-button { + background-color: transparent #272727; + subcontrol-origin: border; + subcontrol-position: top right; + border-left: 1px solid #525252; + border-bottom: 1px solid #525252; + border-top-left-radius: 0; + border-bottom-left-radius: 0; + margin: 1px; + width: 12px; + margin-bottom: -1px; +} + +QAbstractSpinBox::up-arrow, QAbstractSpinBox::up-arrow:disabled, QAbstractSpinBox::up-arrow:off { + image: url(":/qss_icons/dark/rc/arrow_up_disabled.png"); + height: 8px; + width: 8px; +} + +QAbstractSpinBox::up-arrow:hover { + image: url(":/qss_icons/dark/rc/arrow_up.png"); +} + +QAbstractSpinBox:down-button { + background-color: transparent #272727; + subcontrol-origin: border; + subcontrol-position: bottom right; + border-left: 1px solid #525252; + border-top: 1px solid #525252; + border-top-left-radius: 0; + border-bottom-left-radius: 0; + margin: 1px; + width: 12px; + margin-top: -1px; +} + +QAbstractSpinBox::down-arrow, QAbstractSpinBox::down-arrow:disabled, QAbstractSpinBox::down-arrow:off { + image: url(":/qss_icons/dark/rc/arrow_down_disabled.png"); + height: 8px; + width: 8px; +} + +QAbstractSpinBox::down-arrow:hover { + image: url(":/qss_icons/dark/rc/arrow_down.png"); +} + +QAbstractSpinBox:hover { + border: 1px solid #616161; + color: #E3E3E3; +} + +QAbstractSpinBox:focus { + border: 1px solid #666666; +} + +QAbstractSpinBox:selected { + background: #616161; + color: #525252; +} + +/* ------------------------------------------------------------------------ */ +/* DISPLAYS --------------------------------------------------------------- */ +/* ------------------------------------------------------------------------ */ +/* QLabel ----------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qframe + +--------------------------------------------------------------------------- */ +QLabel { + background-color: #272727; + border: 0px solid #525252; + padding: 2px; + margin: 0px; + color: #E3E3E3; +} + +QLabel:disabled { + background-color: #272727; + border: 0px solid #525252; + color: #8B8B8B; +} + +/* QTextBrowser ----------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qabstractscrollarea + +--------------------------------------------------------------------------- */ +QTextBrowser { + background-color: #272727; + border: 1px solid #525252; + color: #E3E3E3; + border-radius: 4px; +} + +QTextBrowser:disabled { + background-color: #272727; + border: 1px solid #525252; + color: #8B8B8B; + border-radius: 4px; +} + +QTextBrowser:hover, QTextBrowser:!hover, QTextBrowser:selected, QTextBrowser:pressed { + border: 1px solid #525252; +} + +/* QGraphicsView ---------------------------------------------------------- + +--------------------------------------------------------------------------- */ +QGraphicsView { + background-color: #272727; + border: 1px solid #525252; + color: #E3E3E3; + border-radius: 4px; +} + +QGraphicsView:disabled { + background-color: #272727; + border: 1px solid #525252; + color: #8B8B8B; + border-radius: 4px; +} + +QGraphicsView:hover, QGraphicsView:!hover, QGraphicsView:selected, QGraphicsView:pressed { + border: 1px solid #525252; +} + +/* QCalendarWidget -------------------------------------------------------- + +--------------------------------------------------------------------------- */ +QCalendarWidget { + border: 1px solid #525252; + border-radius: 4px; +} + +QCalendarWidget:disabled { + background-color: #272727; + color: #8B8B8B; +} + +/* QLCDNumber ------------------------------------------------------------- + +--------------------------------------------------------------------------- */ +QLCDNumber { + background-color: #272727; + color: #E3E3E3; +} + +QLCDNumber:disabled { + background-color: #272727; + color: #8B8B8B; +} + +/* QProgressBar ----------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qprogressbar + +--------------------------------------------------------------------------- */ +QProgressBar { + background-color: #272727; + border: 1px solid #525252; + color: #E3E3E3; + border-radius: 4px; + text-align: center; +} + +QProgressBar:disabled { + background-color: #272727; + border: 1px solid #525252; + color: #8B8B8B; + border-radius: 4px; + text-align: center; +} + +QProgressBar::chunk { + background-color: #616161; + color: #272727; + border-radius: 4px; +} + +QProgressBar::chunk:disabled { + background-color: #444444; + color: #8B8B8B; + border-radius: 4px; +} + +/* ------------------------------------------------------------------------ */ +/* BUTTONS ---------------------------------------------------------------- */ +/* ------------------------------------------------------------------------ */ +/* QPushButton ------------------------------------------------------------ + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qpushbutton + +--------------------------------------------------------------------------- */ +QPushButton { + background-color: #333333; + color: #E3E3E3; + border-radius: 4px; + padding: 4px; + outline: none; + border: 1px solid white; +} + +QPushButton:disabled { + background-color: #333333; + color: #8B8B8B; + border-radius: 4px; + padding: 4px; + border: 1px solid #9B9B9B; +} + +QPushButton:checked { + background-color: #666666; + border-radius: 4px; + padding: 4px; + outline: none; +} + +QPushButton:checked:disabled { + background-color: #525252; + color: #8B8B8B; + border-radius: 4px; + padding: 4px; + outline: none; +} + +QPushButton:checked:selected { + background: #454545; +} + +QPushButton:hover { + background-color: #454545; + color: #E3E3E3; + border: 1px solid #9B9B9B; +} + +QPushButton:pressed { + background-color: #666666; + border: 1px solid #9B9B9B; +} + +QPushButton:selected { + background: #333333; + color: #E3E3E3; +} + +QPushButton::menu-indicator { + subcontrol-origin: padding; + subcontrol-position: bottom right; + bottom: 4px; +} + +QDialogButtonBox QPushButton { + /* Issue #194 #248 - Special case of QPushButton inside dialogs, for better UI */ + min-width: 80px; +} + +/* QToolButton ------------------------------------------------------------ + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qtoolbutton + +--------------------------------------------------------------------------- */ +QToolButton { + background-color: #272727; + color: #E3E3E3; + border-radius: 4px; + padding: 2px; + outline: none; + border: none; + /* The subcontrols below are used only in the DelayedPopup mode */ + /* The subcontrols below are used only in the MenuButtonPopup mode */ + /* The subcontrol below is used only in the InstantPopup or DelayedPopup mode */ +} + +QToolButton:disabled { + background-color: #272727; + color: #8B8B8B; + border-radius: 4px; + padding: 2px; +} + +QToolButton:checked { + background-color: #767676; + border-radius: 4px; + padding: 2px; + outline: none; +} + +QToolButton:checked:disabled { + background-color: #767676; + color: #8B8B8B; + border-radius: 4px; + padding: 2px; + outline: none; +} + +QToolButton:checked:hover { + background-color: #666666; + color: #E3E3E3; +} + +QToolButton:checked:pressed { + background-color: #767676; +} + +QToolButton:checked:selected { + background: #767676; + color: #E3E3E3; +} + +QToolButton:hover { + background-color: #666666; + color: #E3E3E3; +} + +QToolButton:pressed { + background-color: #767676; +} + +QToolButton:selected { + background: #767676; + color: #E3E3E3; +} + +QToolButton[popupMode="0"] { + /* Only for DelayedPopup */ + padding-right: 2px; +} + +QToolButton[popupMode="1"] { + /* Only for MenuButtonPopup */ + padding-right: 20px; +} + +QToolButton[popupMode="1"]::menu-button { + border: none; +} + +QToolButton[popupMode="1"]::menu-button:hover { + border: none; + border-left: 1px solid #525252; + border-radius: 0; +} + +QToolButton[popupMode="2"] { + /* Only for InstantPopup */ + padding-right: 2px; +} + +QToolButton::menu-button { + padding: 2px; + border-radius: 4px; + width: 12px; + border: none; + outline: none; +} + +QToolButton::menu-button:hover { + border: 1px solid #616161; +} + +QToolButton::menu-button:checked:hover { + border: 1px solid #616161; +} + +QToolButton::menu-indicator { + image: url(":/qss_icons/dark/rc/arrow_down.png"); + height: 8px; + width: 8px; + top: 0; + /* Exclude a shift for better image */ + left: -2px; + /* Shift it a bit */ +} + +QToolButton::menu-arrow { + image: url(":/qss_icons/dark/rc/arrow_down.png"); + height: 8px; + width: 8px; +} + +QToolButton::menu-arrow:hover { + image: url(":/qss_icons/dark/rc/arrow_down_focus.png"); +} + +/* QCommandLinkButton ----------------------------------------------------- + +--------------------------------------------------------------------------- */ +QCommandLinkButton { + background-color: transparent; + border: 1px solid #525252; + color: #E3E3E3; + border-radius: 4px; + padding: 0px; + margin: 0px; +} + +QCommandLinkButton:disabled { + background-color: transparent; + color: #8B8B8B; +} + +/* ------------------------------------------------------------------------ */ +/* INPUTS - NO FIELDS ----------------------------------------------------- */ +/* ------------------------------------------------------------------------ */ +/* QComboBox -------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qcombobox + +--------------------------------------------------------------------------- */ +QComboBox { + border: 1px solid #525252; + border-radius: 4px; + selection-background-color: #616161; + padding-left: 4px; + padding-right: 4px; + /* padding-right = 36; 4 + 16*2 See scrollbar size */ + /* changed to 4px to fix #239 */ + /* Fixes #103, #111 */ + min-height: 1.5em; + /* padding-top: 2px; removed to fix #132 */ + /* padding-bottom: 2px; removed to fix #132 */ + /* min-width: 75px; removed to fix #109 */ + /* Needed to remove indicator - fix #132 */ +} + +QComboBox QAbstractItemView { + border: 1px solid #525252; + border-radius: 0; + background-color: #272727; + selection-background-color: #616161; +} + +QComboBox QAbstractItemView:hover { + background-color: #272727; + color: #E3E3E3; +} + +QComboBox QAbstractItemView:selected { + background: #616161; + color: #525252; +} + +QComboBox QAbstractItemView:alternate { + background: #272727; +} + +QComboBox:disabled { + background-color: #272727; + color: #8B8B8B; +} + +QComboBox:hover { + border: 1px solid #616161; + background-color: #454545; +} + +QComboBox:focus { + border: 1px solid #666666; +} + +QComboBox:on { + selection-background-color: #616161; + background-color: #666666; +} + +QComboBox::indicator { + border: none; + border-radius: 0; + background-color: transparent; + selection-background-color: transparent; + color: transparent; + selection-color: transparent; + /* Needed to remove indicator - fix #132 */ +} + +QComboBox::indicator:alternate { + background: #272727; +} + +QComboBox::item { + /* Remove to fix #282, #285 and MR #288*/ + /*&:checked { + font-weight: bold; + } + + &:selected { + border: 0px solid transparent; + } + */ +} + +QComboBox::item:alternate { + background: #272727; +} + +QComboBox::drop-down { + subcontrol-origin: padding; + subcontrol-position: top right; + width: 12px; + border-left: 1px solid #525252; +} + +QComboBox::down-arrow { + image: url(":/qss_icons/dark/rc/arrow_down_disabled.png"); + height: 8px; + width: 8px; +} + +QComboBox::down-arrow:on, QComboBox::down-arrow:hover, QComboBox::down-arrow:focus { + image: url(":/qss_icons/dark/rc/arrow_down.png"); +} + +/* QSlider ---------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qslider + +--------------------------------------------------------------------------- */ +QSlider:disabled { + background: #272727; +} + +QSlider:focus { + border: none; +} + +QSlider::groove:horizontal { + background: #525252; + border: 1px solid #525252; + height: 4px; + margin: 0px; + border-radius: 4px; +} + +QSlider::groove:vertical { + background: #525252; + border: 1px solid #525252; + width: 4px; + margin: 0px; + border-radius: 4px; +} + +QSlider::add-page:vertical { + background: #616161; + border: 1px solid #525252; + width: 4px; + margin: 0px; + border-radius: 4px; +} + +QSlider::add-page:vertical :disabled { + background: #444444; +} + +QSlider::sub-page:horizontal { + background: #616161; + border: 1px solid #525252; + height: 4px; + margin: 0px; + border-radius: 4px; +} + +QSlider::sub-page:horizontal:disabled { + background: #444444; +} + +QSlider::handle:horizontal { + background: #A9A9A9; + border: 1px solid #525252; + width: 8px; + height: 8px; + margin: -8px 0px; + border-radius: 4px; +} + +QSlider::handle:horizontal:hover { + background: #616161; + border: 1px solid #616161; +} + +QSlider::handle:horizontal:focus { + border: 1px solid #666666; +} + +QSlider::handle:vertical { + background: #A9A9A9; + border: 1px solid #525252; + width: 8px; + height: 8px; + margin: 0 -8px; + border-radius: 4px; +} + +QSlider::handle:vertical:hover { + background: #616161; + border: 1px solid #616161; +} + +QSlider::handle:vertical:focus { + border: 1px solid #666666; +} + +/* QLineEdit -------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qlineedit + +--------------------------------------------------------------------------- */ +QLineEdit { + background-color: #272727; + padding-top: 2px; + /* This QLineEdit fix 103, 111 */ + padding-bottom: 2px; + /* This QLineEdit fix 103, 111 */ + padding-left: 4px; + padding-right: 4px; + border-style: solid; + border: 1px solid #525252; + border-radius: 4px; + color: #E3E3E3; +} + +QLineEdit:disabled { + background-color: #272727; + color: #8B8B8B; +} + +QLineEdit:hover { + border: 1px solid #616161; + color: #E3E3E3; +} + +QLineEdit:focus { + border: 1px solid #666666; +} + +QLineEdit:selected { + background-color: #616161; + color: #525252; +} + +/* QTabWiget -------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qtabwidget-and-qtabbar + +--------------------------------------------------------------------------- */ +QTabWidget { + padding: 2px; + selection-background-color: #525252; +} + +QTabWidget QWidget { + /* Fixes #189 */ + border-radius: 4px; +} + +QTabWidget::pane { + border: 1px solid #525252; + border-radius: 4px; + margin: 0px; + /* Fixes double border inside pane with pyqt5 */ + padding: 0px; +} + +QTabWidget::pane:selected { + background-color: #525252; + border: 1px solid #616161; +} + +/* QTabBar ---------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qtabwidget-and-qtabbar + +--------------------------------------------------------------------------- */ +QTabBar, QDockWidget QTabBar { + qproperty-drawBase: 0; + border-radius: 4px; + margin: 0px; + padding: 2px; + border: 0; + /* left: 5px; move to the right by 5px - removed for fix */ +} + +QTabBar::close-button, QDockWidget QTabBar::close-button { + border: 0; + margin: 0; + padding: 4px; + image: url(":/qss_icons/dark/rc/window_close.png"); +} + +QTabBar::close-button:hover, QDockWidget QTabBar::close-button:hover { + image: url(":/qss_icons/dark/rc/window_close_focus.png"); +} + +QTabBar::close-button:pressed, QDockWidget QTabBar::close-button:pressed { + image: url(":/qss_icons/dark/rc/window_close_pressed.png"); +} + +QTabBar::tab, QDockWidget QTabBar::tab { + /* !selected and disabled ----------------------------------------- */ + /* selected ------------------------------------------------------- */ +} + +QTabBar::tab:top:selected:disabled, QDockWidget QTabBar::tab:top:selected:disabled { + border-bottom: 3px solid #444444; + color: #8B8B8B; + background-color: #525252; +} + +QTabBar::tab:bottom:selected:disabled, QDockWidget QTabBar::tab:bottom:selected:disabled { + border-top: 3px solid #444444; + color: #8B8B8B; + background-color: #525252; +} + +QTabBar::tab:left:selected:disabled, QDockWidget QTabBar::tab:left:selected:disabled { + border-right: 3px solid #444444; + color: #8B8B8B; + background-color: #525252; +} + +QTabBar::tab:right:selected:disabled, QDockWidget QTabBar::tab:right:selected:disabled { + border-left: 3px solid #444444; + color: #8B8B8B; + background-color: #525252; +} + +QTabBar::tab:top:!selected:disabled, QDockWidget QTabBar::tab:top:!selected:disabled { + border-bottom: 3px solid #272727; + color: #8B8B8B; + background-color: #272727; +} + +QTabBar::tab:bottom:!selected:disabled, QDockWidget QTabBar::tab:bottom:!selected:disabled { + border-top: 3px solid #272727; + color: #8B8B8B; + background-color: #272727; +} + +QTabBar::tab:left:!selected:disabled, QDockWidget QTabBar::tab:left:!selected:disabled { + border-right: 3px solid #272727; + color: #8B8B8B; + background-color: #272727; +} + +QTabBar::tab:right:!selected:disabled, QDockWidget QTabBar::tab:right:!selected:disabled { + border-left: 3px solid #272727; + color: #8B8B8B; + background-color: #272727; +} + +QTabBar::tab:top:!selected, QDockWidget QTabBar::tab:top:!selected { + border-bottom: 2px solid #272727; + margin-top: 2px; +} + +QTabBar::tab:bottom:!selected, QDockWidget QTabBar::tab:bottom:!selected { + border-top: 2px solid #272727; + margin-bottom: 2px; +} + +QTabBar::tab:left:!selected, QDockWidget QTabBar::tab:left:!selected { + border-left: 2px solid #272727; + margin-right: 2px; +} + +QTabBar::tab:right:!selected, QDockWidget QTabBar::tab:right:!selected { + border-right: 2px solid #272727; + margin-left: 2px; +} + +QTabBar::tab:top, QDockWidget QTabBar::tab:top { + background-color: #525252; + margin-left: 2px; + padding-left: 4px; + padding-right: 4px; + padding-top: 2px; + padding-bottom: 2px; + min-width: 5px; + border-bottom: 3px solid #525252; + border-top-left-radius: 4px; + border-top-right-radius: 4px; +} + +QTabBar::tab:top:selected, QDockWidget QTabBar::tab:top:selected { + background-color: #666666; + border-bottom: 3px solid #898989; + border-top-left-radius: 4px; + border-top-right-radius: 4px; +} + +QTabBar::tab:top:!selected:hover, QDockWidget QTabBar::tab:top:!selected:hover { + border: 1px solid #666666; + border-bottom: 3px solid #666666; + /* Fixes spyder-ide/spyder#9766 and #243 */ + padding-left: 3px; + padding-right: 3px; +} + +QTabBar::tab:bottom, QDockWidget QTabBar::tab:bottom { + border-top: 3px solid #525252; + background-color: #525252; + margin-left: 2px; + padding-left: 4px; + padding-right: 4px; + padding-top: 2px; + padding-bottom: 2px; + border-bottom-left-radius: 4px; + border-bottom-right-radius: 4px; + min-width: 5px; +} + +QTabBar::tab:bottom:selected, QDockWidget QTabBar::tab:bottom:selected { + background-color: #666666; + border-top: 3px solid #898989; + border-bottom-left-radius: 4px; + border-bottom-right-radius: 4px; +} + +QTabBar::tab:bottom:!selected:hover, QDockWidget QTabBar::tab:bottom:!selected:hover { + border: 1px solid #666666; + border-top: 3px solid #666666; + /* Fixes spyder-ide/spyder#9766 and #243 */ + padding-left: 3px; + padding-right: 3px; +} + +QTabBar::tab:left, QDockWidget QTabBar::tab:left { + background-color: #525252; + margin-top: 2px; + padding-left: 2px; + padding-right: 2px; + padding-top: 4px; + padding-bottom: 4px; + border-top-left-radius: 4px; + border-bottom-left-radius: 4px; + min-height: 5px; +} + +QTabBar::tab:left:selected, QDockWidget QTabBar::tab:left:selected { + background-color: #666666; + border-right: 3px solid #898989; +} + +QTabBar::tab:left:!selected:hover, QDockWidget QTabBar::tab:left:!selected:hover { + border: 1px solid #666666; + border-right: 3px solid #666666; + /* Fixes different behavior #271 */ + margin-right: 0px; + padding-right: -1px; +} + +QTabBar::tab:right, QDockWidget QTabBar::tab:right { + background-color: #525252; + margin-top: 2px; + padding-left: 2px; + padding-right: 2px; + padding-top: 4px; + padding-bottom: 4px; + border-top-right-radius: 4px; + border-bottom-right-radius: 4px; + min-height: 5px; +} + +QTabBar::tab:right:selected, QDockWidget QTabBar::tab:right:selected { + background-color: #666666; + border-left: 3px solid #898989; +} + +QTabBar::tab:right:!selected:hover, QDockWidget QTabBar::tab:right:!selected:hover { + border: 1px solid #666666; + border-left: 3px solid #666666; + /* Fixes different behavior #271 */ + margin-left: 0px; + padding-left: 0px; +} + +QTabBar QToolButton, QDockWidget QTabBar QToolButton { + /* Fixes #136 */ + background-color: #525252; + height: 12px; + width: 12px; +} + +QTabBar QToolButton:pressed, QDockWidget QTabBar QToolButton:pressed { + background-color: #525252; +} + +QTabBar QToolButton:pressed:hover, QDockWidget QTabBar QToolButton:pressed:hover { + border: 1px solid #616161; +} + +QTabBar QToolButton::left-arrow:enabled, QDockWidget QTabBar QToolButton::left-arrow:enabled { + image: url(":/qss_icons/dark/rc/arrow_left.png"); +} + +QTabBar QToolButton::left-arrow:disabled, QDockWidget QTabBar QToolButton::left-arrow:disabled { + image: url(":/qss_icons/dark/rc/arrow_left_disabled.png"); +} + +QTabBar QToolButton::right-arrow:enabled, QDockWidget QTabBar QToolButton::right-arrow:enabled { + image: url(":/qss_icons/dark/rc/arrow_right.png"); +} + +QTabBar QToolButton::right-arrow:disabled, QDockWidget QTabBar QToolButton::right-arrow:disabled { + image: url(":/qss_icons/dark/rc/arrow_right_disabled.png"); +} + +/* QDockWiget ------------------------------------------------------------- + +--------------------------------------------------------------------------- */ +QDockWidget { + outline: 1px solid #525252; + background-color: #272727; + border: 1px solid #525252; + border-radius: 4px; + titlebar-close-icon: url(":/qss_icons/dark/rc/transparent.png"); + titlebar-normal-icon: url(":/qss_icons/dark/rc/transparent.png"); +} + +QDockWidget::title { + /* Better size for title bar */ + padding: 3px; + spacing: 4px; + border: none; + background-color: #525252; +} + +QDockWidget::close-button { + icon-size: 12px; + border: none; + background: transparent; + background-image: transparent; + border: 0; + margin: 0; + padding: 0; + image: url(":/qss_icons/dark/rc/window_close.png"); +} + +QDockWidget::close-button:hover { + image: url(":/qss_icons/dark/rc/window_close_focus.png"); +} + +QDockWidget::close-button:pressed { + image: url(":/qss_icons/dark/rc/window_close_pressed.png"); +} + +QDockWidget::float-button { + icon-size: 12px; + border: none; + background: transparent; + background-image: transparent; + border: 0; + margin: 0; + padding: 0; + image: url(":/qss_icons/dark/rc/window_undock.png"); +} + +QDockWidget::float-button:hover { + image: url(":/qss_icons/dark/rc/window_undock_focus.png"); +} + +QDockWidget::float-button:pressed { + image: url(":/qss_icons/dark/rc/window_undock_pressed.png"); +} + +/* QTreeView QListView QTableView ----------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qtreeview +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qlistview +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qtableview + +--------------------------------------------------------------------------- */ +QTreeView:branch:selected, QTreeView:branch:hover { + background: url(":/qss_icons/dark/rc/transparent.png"); +} + +QTreeView:branch:has-siblings:!adjoins-item { + border-image: url(":/qss_icons/dark/rc/branch_line.png") 0; +} + +QTreeView:branch:has-siblings:adjoins-item { + border-image: url(":/qss_icons/dark/rc/branch_more.png") 0; +} + +QTreeView:branch:!has-children:!has-siblings:adjoins-item { + border-image: url(":/qss_icons/dark/rc/branch_end.png") 0; +} + +QTreeView:branch:has-children:!has-siblings:closed, QTreeView:branch:closed:has-children:has-siblings { + border-image: none; + image: url(":/qss_icons/dark/rc/branch_closed.png"); +} + +QTreeView:branch:open:has-children:!has-siblings, QTreeView:branch:open:has-children:has-siblings { + border-image: none; + image: url(":/qss_icons/dark/rc/branch_open.png"); +} + +QTreeView:branch:has-children:!has-siblings:closed:hover, QTreeView:branch:closed:has-children:has-siblings:hover { + image: url(":/qss_icons/dark/rc/branch_closed_focus.png"); +} + +QTreeView:branch:open:has-children:!has-siblings:hover, QTreeView:branch:open:has-children:has-siblings:hover { + image: url(":/qss_icons/dark/rc/branch_open_focus.png"); +} + +QTreeView::indicator:checked, +QListView::indicator:checked, +QTableView::indicator:checked, +QColumnView::indicator:checked { + image: url(":/qss_icons/dark/rc/checkbox_checked.png"); +} + +QTreeView::indicator:checked:hover, QTreeView::indicator:checked:focus, QTreeView::indicator:checked:pressed, +QListView::indicator:checked:hover, +QListView::indicator:checked:focus, +QListView::indicator:checked:pressed, +QTableView::indicator:checked:hover, +QTableView::indicator:checked:focus, +QTableView::indicator:checked:pressed, +QColumnView::indicator:checked:hover, +QColumnView::indicator:checked:focus, +QColumnView::indicator:checked:pressed { + image: url(":/qss_icons/dark/rc/checkbox_checked_focus.png"); +} + +QTreeView::indicator:unchecked, +QListView::indicator:unchecked, +QTableView::indicator:unchecked, +QColumnView::indicator:unchecked { + image: url(":/qss_icons/dark/rc/checkbox_unchecked.png"); +} + +QTreeView::indicator:unchecked:hover, QTreeView::indicator:unchecked:focus, QTreeView::indicator:unchecked:pressed, +QListView::indicator:unchecked:hover, +QListView::indicator:unchecked:focus, +QListView::indicator:unchecked:pressed, +QTableView::indicator:unchecked:hover, +QTableView::indicator:unchecked:focus, +QTableView::indicator:unchecked:pressed, +QColumnView::indicator:unchecked:hover, +QColumnView::indicator:unchecked:focus, +QColumnView::indicator:unchecked:pressed { + image: url(":/qss_icons/dark/rc/checkbox_unchecked_focus.png"); +} + +QTreeView::indicator:indeterminate, +QListView::indicator:indeterminate, +QTableView::indicator:indeterminate, +QColumnView::indicator:indeterminate { + image: url(":/qss_icons/dark/rc/checkbox_indeterminate.png"); +} + +QTreeView::indicator:indeterminate:hover, QTreeView::indicator:indeterminate:focus, QTreeView::indicator:indeterminate:pressed, +QListView::indicator:indeterminate:hover, +QListView::indicator:indeterminate:focus, +QListView::indicator:indeterminate:pressed, +QTableView::indicator:indeterminate:hover, +QTableView::indicator:indeterminate:focus, +QTableView::indicator:indeterminate:pressed, +QColumnView::indicator:indeterminate:hover, +QColumnView::indicator:indeterminate:focus, +QColumnView::indicator:indeterminate:pressed { + image: url(":/qss_icons/dark/rc/checkbox_indeterminate_focus.png"); +} + +QTreeView, +QListView, +QTableView, +QColumnView { + background-color: #272727; + border: 1px solid #525252; + color: #E3E3E3; + gridline-color: #525252; + border-radius: 4px; +} + +QTreeView:disabled, +QListView:disabled, +QTableView:disabled, +QColumnView:disabled { + background-color: #272727; + color: #8B8B8B; +} + +QTreeView:selected, +QListView:selected, +QTableView:selected, +QColumnView:selected { + background-color: #616161; + color: #525252; +} + +QTreeView:focus, +QListView:focus, +QTableView:focus, +QColumnView:focus { + border: 1px solid #666666; +} + +QTreeView::item:pressed, +QListView::item:pressed, +QTableView::item:pressed, +QColumnView::item:pressed { + background-color: #616161; +} + +QTreeView::item:selected:active, +QListView::item:selected:active, +QTableView::item:selected:active, +QColumnView::item:selected:active { + background-color: #616161; +} + +QTreeView::item:selected:!active, +QListView::item:selected:!active, +QTableView::item:selected:!active, +QColumnView::item:selected:!active { + color: #E3E3E3; + background-color: #414141; +} + +QTreeView::item:!selected:hover, +QListView::item:!selected:hover, +QTableView::item:!selected:hover, +QColumnView::item:!selected:hover { + outline: 0; + color: #E3E3E3; + background-color: #414141; +} + +QTableCornerButton::section { + background-color: #272727; + border: 1px transparent #525252; + border-radius: 0px; +} + +/* QHeaderView ------------------------------------------------------------ + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qheaderview + +--------------------------------------------------------------------------- */ +QHeaderView { + background-color: #525252; + border: 0px transparent #525252; + padding: 0; + margin: 0; + border-radius: 0; +} + +QHeaderView:disabled { + background-color: #525252; + border: 1px transparent #525252; +} + +QHeaderView::section { + background-color: #525252; + color: #E3E3E3; + border-radius: 0; + text-align: left; + font-size: 13px; +} + +QHeaderView::section::horizontal { + padding-top: 0; + padding-bottom: 0; + padding-left: 4px; + padding-right: 4px; + border-left: 1px solid #272727; +} + +QHeaderView::section::horizontal::first, QHeaderView::section::horizontal::only-one { + border-left: 1px solid #525252; +} + +QHeaderView::section::horizontal:disabled { + color: #8B8B8B; +} + +QHeaderView::section::vertical { + padding-top: 0; + padding-bottom: 0; + padding-left: 4px; + padding-right: 4px; + border-top: 1px solid #272727; +} + +QHeaderView::section::vertical::first, QHeaderView::section::vertical::only-one { + border-top: 1px solid #525252; +} + +QHeaderView::section::vertical:disabled { + color: #8B8B8B; +} + +QHeaderView::down-arrow { + /* Those settings (border/width/height/background-color) solve bug */ + /* transparent arrow background and size */ + background-color: #525252; + border: none; + height: 12px; + width: 12px; + padding-left: 2px; + padding-right: 2px; + image: url(":/qss_icons/dark/rc/arrow_down.png"); +} + +QHeaderView::up-arrow { + background-color: #525252; + border: none; + height: 12px; + width: 12px; + padding-left: 2px; + padding-right: 2px; + image: url(":/qss_icons/dark/rc/arrow_up.png"); +} + +/* QToolBox -------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qtoolbox + +--------------------------------------------------------------------------- */ +QToolBox { + padding: 0px; + border: 0px; + border: 1px solid #525252; +} + +QToolBox:selected { + padding: 0px; + border: 2px solid #616161; +} + +QToolBox::tab { + background-color: #272727; + border: 1px solid #525252; + color: #E3E3E3; + border-top-left-radius: 4px; + border-top-right-radius: 4px; +} + +QToolBox::tab:disabled { + color: #8B8B8B; +} + +QToolBox::tab:selected { + background-color: #767676; + border-bottom: 2px solid #616161; +} + +QToolBox::tab:selected:disabled { + background-color: #525252; + border-bottom: 2px solid #444444; +} + +QToolBox::tab:!selected { + background-color: #525252; + border-bottom: 2px solid #525252; +} + +QToolBox::tab:!selected:disabled { + background-color: #272727; +} + +QToolBox::tab:hover { + border-color: #666666; + border-bottom: 2px solid #666666; +} + +QToolBox QScrollArea { + padding: 0px; + border: 0px; + background-color: #272727; +} + +/* QFrame ----------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qframe +https://doc.qt.io/qt-5/qframe.html#-prop +https://doc.qt.io/qt-5/qframe.html#details +https://stackoverflow.com/questions/14581498/qt-stylesheet-for-hline-vline-color + +--------------------------------------------------------------------------- */ +/* (dot) .QFrame fix #141, #126, #123 */ +.QFrame { + border-radius: 4px; + border: 1px solid #525252; + /* No frame */ + /* HLine */ + /* HLine */ +} + +.QFrame[frameShape="0"] { + border-radius: 4px; + border: 1px transparent #525252; +} + +.QFrame[frameShape="4"] { + max-height: 2px; + border: none; + background-color: #525252; +} + +.QFrame[frameShape="5"] { + max-width: 2px; + border: none; + background-color: #525252; +} + +/* QSplitter -------------------------------------------------------------- + +https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qsplitter + +--------------------------------------------------------------------------- */ +QSplitter { + background-color: #525252; + spacing: 0px; + padding: 0px; + margin: 0px; +} + +QSplitter::handle { + background-color: #525252; + border: 0px solid #272727; + spacing: 0px; + padding: 1px; + margin: 0px; +} + +QSplitter::handle:hover { + background-color: #A9A9A9; +} + +QSplitter::handle:horizontal { + width: 5px; + image: url(":/qss_icons/dark/rc/line_vertical.png"); +} + +QSplitter::handle:vertical { + height: 5px; + image: url(":/qss_icons/dark/rc/line_horizontal.png"); +} + +/* QDateEdit, QDateTimeEdit ----------------------------------------------- + +--------------------------------------------------------------------------- */ +QDateEdit, QDateTimeEdit { + selection-background-color: #616161; + border-style: solid; + border: 1px solid #525252; + border-radius: 4px; + /* This fixes 103, 111 */ + padding-top: 2px; + /* This fixes 103, 111 */ + padding-bottom: 2px; + padding-left: 4px; + padding-right: 4px; + min-width: 10px; +} + +QDateEdit:on, QDateTimeEdit:on { + selection-background-color: #616161; +} + +QDateEdit::drop-down, QDateTimeEdit::drop-down { + subcontrol-origin: padding; + subcontrol-position: top right; + width: 12px; + border-left: 1px solid #525252; +} + +QDateEdit::down-arrow, QDateTimeEdit::down-arrow { + image: url(":/qss_icons/dark/rc/arrow_down_disabled.png"); + height: 8px; + width: 8px; +} + +QDateEdit::down-arrow:on, QDateEdit::down-arrow:hover, QDateEdit::down-arrow:focus, QDateTimeEdit::down-arrow:on, QDateTimeEdit::down-arrow:hover, QDateTimeEdit::down-arrow:focus { + image: url(":/qss_icons/dark/rc/arrow_down.png"); +} + +QDateEdit QAbstractItemView, QDateTimeEdit QAbstractItemView { + background-color: #272727; + border-radius: 4px; + border: 1px solid #525252; + selection-background-color: #616161; +} + +/* QAbstractView ---------------------------------------------------------- + +--------------------------------------------------------------------------- */ +QAbstractView:hover { + border: 1px solid #616161; + color: #E3E3E3; +} + +QAbstractView:selected { + background: #616161; + color: #525252; +} + +/* PlotWidget ------------------------------------------------------------- + +--------------------------------------------------------------------------- */ +PlotWidget { + /* Fix cut labels in plots #134 */ + padding: 0px; +} diff --git a/src/qt/qdarkstyle/dark/rc/.keep b/src/qt/qdarkstyle/dark/rc/.keep new file mode 100644 index 000000000..8d1c8b69c --- /dev/null +++ b/src/qt/qdarkstyle/dark/rc/.keep @@ -0,0 +1 @@ + diff --git a/src/qt/qdarkstyle/dark/rc/arrow_down.png b/src/qt/qdarkstyle/dark/rc/arrow_down.png new file mode 100644 index 000000000..412b76e6f Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_down.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_down@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_down@2x.png new file mode 100644 index 000000000..74d0099ec Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_down@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_down_disabled.png b/src/qt/qdarkstyle/dark/rc/arrow_down_disabled.png new file mode 100644 index 000000000..972df9cd1 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_down_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_down_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_down_disabled@2x.png new file mode 100644 index 000000000..b0fb4ad11 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_down_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_down_focus.png b/src/qt/qdarkstyle/dark/rc/arrow_down_focus.png new file mode 100644 index 000000000..22df2c525 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_down_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_down_focus@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_down_focus@2x.png new file mode 100644 index 000000000..06b80be4b Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_down_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_down_pressed.png b/src/qt/qdarkstyle/dark/rc/arrow_down_pressed.png new file mode 100644 index 000000000..50f41cc6f Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_down_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_down_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_down_pressed@2x.png new file mode 100644 index 000000000..ef20f2cb0 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_down_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_left.png b/src/qt/qdarkstyle/dark/rc/arrow_left.png new file mode 100644 index 000000000..b7aeac5f8 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_left.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_left@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_left@2x.png new file mode 100644 index 000000000..fef91a8c8 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_left@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_left_disabled.png b/src/qt/qdarkstyle/dark/rc/arrow_left_disabled.png new file mode 100644 index 000000000..79b1f0565 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_left_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_left_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_left_disabled@2x.png new file mode 100644 index 000000000..144fdb5f8 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_left_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_left_focus.png b/src/qt/qdarkstyle/dark/rc/arrow_left_focus.png new file mode 100644 index 000000000..ef0284994 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_left_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_left_focus@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_left_focus@2x.png new file mode 100644 index 000000000..ca821dcac Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_left_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_left_pressed.png b/src/qt/qdarkstyle/dark/rc/arrow_left_pressed.png new file mode 100644 index 000000000..c723d3bff Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_left_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_left_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_left_pressed@2x.png new file mode 100644 index 000000000..f0bcb5229 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_left_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_right.png b/src/qt/qdarkstyle/dark/rc/arrow_right.png new file mode 100644 index 000000000..78d67f2db Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_right.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_right@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_right@2x.png new file mode 100644 index 000000000..ce0a8faeb Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_right@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_right_disabled.png b/src/qt/qdarkstyle/dark/rc/arrow_right_disabled.png new file mode 100644 index 000000000..88da1f980 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_right_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_right_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_right_disabled@2x.png new file mode 100644 index 000000000..5351587e3 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_right_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_right_focus.png b/src/qt/qdarkstyle/dark/rc/arrow_right_focus.png new file mode 100644 index 000000000..92271a8ed Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_right_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_right_focus@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_right_focus@2x.png new file mode 100644 index 000000000..d6c31bdda Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_right_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_right_pressed.png b/src/qt/qdarkstyle/dark/rc/arrow_right_pressed.png new file mode 100644 index 000000000..22902cf4f Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_right_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_right_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_right_pressed@2x.png new file mode 100644 index 000000000..f6181eb64 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_right_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_up.png b/src/qt/qdarkstyle/dark/rc/arrow_up.png new file mode 100644 index 000000000..50321f29b Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_up.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_up@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_up@2x.png new file mode 100644 index 000000000..8c73c3be3 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_up@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_up_disabled.png b/src/qt/qdarkstyle/dark/rc/arrow_up_disabled.png new file mode 100644 index 000000000..48054a8ae Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_up_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_up_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_up_disabled@2x.png new file mode 100644 index 000000000..e99960594 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_up_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_up_focus.png b/src/qt/qdarkstyle/dark/rc/arrow_up_focus.png new file mode 100644 index 000000000..567ec8bdf Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_up_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_up_focus@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_up_focus@2x.png new file mode 100644 index 000000000..f6998104b Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_up_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_up_pressed.png b/src/qt/qdarkstyle/dark/rc/arrow_up_pressed.png new file mode 100644 index 000000000..223320106 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_up_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/arrow_up_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/arrow_up_pressed@2x.png new file mode 100644 index 000000000..9954cf519 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/arrow_up_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/base_icon.png b/src/qt/qdarkstyle/dark/rc/base_icon.png new file mode 100644 index 000000000..bb00857a4 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/base_icon.png differ diff --git a/src/qt/qdarkstyle/dark/rc/base_icon@2x.png b/src/qt/qdarkstyle/dark/rc/base_icon@2x.png new file mode 100644 index 000000000..bc4ab78a2 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/base_icon@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/base_icon_disabled.png b/src/qt/qdarkstyle/dark/rc/base_icon_disabled.png new file mode 100644 index 000000000..bb00857a4 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/base_icon_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/base_icon_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/base_icon_disabled@2x.png new file mode 100644 index 000000000..bc4ab78a2 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/base_icon_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/base_icon_focus.png b/src/qt/qdarkstyle/dark/rc/base_icon_focus.png new file mode 100644 index 000000000..bb00857a4 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/base_icon_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/base_icon_focus@2x.png b/src/qt/qdarkstyle/dark/rc/base_icon_focus@2x.png new file mode 100644 index 000000000..bc4ab78a2 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/base_icon_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/base_icon_pressed.png b/src/qt/qdarkstyle/dark/rc/base_icon_pressed.png new file mode 100644 index 000000000..bb00857a4 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/base_icon_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/base_icon_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/base_icon_pressed@2x.png new file mode 100644 index 000000000..bc4ab78a2 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/base_icon_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_closed.png b/src/qt/qdarkstyle/dark/rc/branch_closed.png new file mode 100644 index 000000000..4c152b795 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_closed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_closed@2x.png b/src/qt/qdarkstyle/dark/rc/branch_closed@2x.png new file mode 100644 index 000000000..a641a550b Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_closed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_closed_disabled.png b/src/qt/qdarkstyle/dark/rc/branch_closed_disabled.png new file mode 100644 index 000000000..165fae29b Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_closed_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_closed_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/branch_closed_disabled@2x.png new file mode 100644 index 000000000..421e8e094 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_closed_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_closed_focus.png b/src/qt/qdarkstyle/dark/rc/branch_closed_focus.png new file mode 100644 index 000000000..ccc249a59 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_closed_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_closed_focus@2x.png b/src/qt/qdarkstyle/dark/rc/branch_closed_focus@2x.png new file mode 100644 index 000000000..88dd0a62b Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_closed_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_closed_pressed.png b/src/qt/qdarkstyle/dark/rc/branch_closed_pressed.png new file mode 100644 index 000000000..2aae68a0a Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_closed_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_closed_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/branch_closed_pressed@2x.png new file mode 100644 index 000000000..3849a7ff0 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_closed_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_end.png b/src/qt/qdarkstyle/dark/rc/branch_end.png new file mode 100644 index 000000000..f92994650 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_end.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_end@2x.png b/src/qt/qdarkstyle/dark/rc/branch_end@2x.png new file mode 100644 index 000000000..582832220 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_end@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_end_disabled.png b/src/qt/qdarkstyle/dark/rc/branch_end_disabled.png new file mode 100644 index 000000000..bb4344c78 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_end_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_end_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/branch_end_disabled@2x.png new file mode 100644 index 000000000..8feb46d46 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_end_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_end_focus.png b/src/qt/qdarkstyle/dark/rc/branch_end_focus.png new file mode 100644 index 000000000..ff713cf5f Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_end_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_end_focus@2x.png b/src/qt/qdarkstyle/dark/rc/branch_end_focus@2x.png new file mode 100644 index 000000000..0bd0e4ba3 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_end_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_end_pressed.png b/src/qt/qdarkstyle/dark/rc/branch_end_pressed.png new file mode 100644 index 000000000..2020162f2 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_end_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_end_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/branch_end_pressed@2x.png new file mode 100644 index 000000000..2a5c4fabf Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_end_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_line.png b/src/qt/qdarkstyle/dark/rc/branch_line.png new file mode 100644 index 000000000..2e8c72ab6 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_line.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_line@2x.png b/src/qt/qdarkstyle/dark/rc/branch_line@2x.png new file mode 100644 index 000000000..c8f07af31 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_line@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_line_disabled.png b/src/qt/qdarkstyle/dark/rc/branch_line_disabled.png new file mode 100644 index 000000000..9c8c47b3d Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_line_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_line_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/branch_line_disabled@2x.png new file mode 100644 index 000000000..9b868f2a5 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_line_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_line_focus.png b/src/qt/qdarkstyle/dark/rc/branch_line_focus.png new file mode 100644 index 000000000..c2ab3e19e Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_line_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_line_focus@2x.png b/src/qt/qdarkstyle/dark/rc/branch_line_focus@2x.png new file mode 100644 index 000000000..512ee13a2 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_line_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_line_pressed.png b/src/qt/qdarkstyle/dark/rc/branch_line_pressed.png new file mode 100644 index 000000000..3ca15c5d0 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_line_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_line_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/branch_line_pressed@2x.png new file mode 100644 index 000000000..368553102 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_line_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_more.png b/src/qt/qdarkstyle/dark/rc/branch_more.png new file mode 100644 index 000000000..976354bc4 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_more.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_more@2x.png b/src/qt/qdarkstyle/dark/rc/branch_more@2x.png new file mode 100644 index 000000000..9c1ab07d0 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_more@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_more_disabled.png b/src/qt/qdarkstyle/dark/rc/branch_more_disabled.png new file mode 100644 index 000000000..29d99a63e Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_more_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_more_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/branch_more_disabled@2x.png new file mode 100644 index 000000000..aba830362 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_more_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_more_focus.png b/src/qt/qdarkstyle/dark/rc/branch_more_focus.png new file mode 100644 index 000000000..20a6f27b8 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_more_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_more_focus@2x.png b/src/qt/qdarkstyle/dark/rc/branch_more_focus@2x.png new file mode 100644 index 000000000..6f42eea84 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_more_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_more_pressed.png b/src/qt/qdarkstyle/dark/rc/branch_more_pressed.png new file mode 100644 index 000000000..4f4d9fb91 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_more_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_more_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/branch_more_pressed@2x.png new file mode 100644 index 000000000..5f18f8341 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_more_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_open.png b/src/qt/qdarkstyle/dark/rc/branch_open.png new file mode 100644 index 000000000..fdf0f8b43 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_open.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_open@2x.png b/src/qt/qdarkstyle/dark/rc/branch_open@2x.png new file mode 100644 index 000000000..703cd6af3 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_open@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_open_disabled.png b/src/qt/qdarkstyle/dark/rc/branch_open_disabled.png new file mode 100644 index 000000000..8328e84d7 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_open_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_open_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/branch_open_disabled@2x.png new file mode 100644 index 000000000..d8d0faecb Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_open_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_open_focus.png b/src/qt/qdarkstyle/dark/rc/branch_open_focus.png new file mode 100644 index 000000000..711ce0979 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_open_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_open_focus@2x.png b/src/qt/qdarkstyle/dark/rc/branch_open_focus@2x.png new file mode 100644 index 000000000..b38e17a33 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_open_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_open_pressed.png b/src/qt/qdarkstyle/dark/rc/branch_open_pressed.png new file mode 100644 index 000000000..441c27344 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_open_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/branch_open_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/branch_open_pressed@2x.png new file mode 100644 index 000000000..0e43e8b73 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/branch_open_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_checked.png b/src/qt/qdarkstyle/dark/rc/checkbox_checked.png new file mode 100644 index 000000000..3687e56c0 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_checked.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_checked@2x.png b/src/qt/qdarkstyle/dark/rc/checkbox_checked@2x.png new file mode 100644 index 000000000..e7a6b1afe Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_checked@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_checked_disabled.png b/src/qt/qdarkstyle/dark/rc/checkbox_checked_disabled.png new file mode 100644 index 000000000..e3cb2f127 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_checked_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_checked_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/checkbox_checked_disabled@2x.png new file mode 100644 index 000000000..0c8c28a24 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_checked_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_checked_focus.png b/src/qt/qdarkstyle/dark/rc/checkbox_checked_focus.png new file mode 100644 index 000000000..58982ce87 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_checked_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_checked_focus@2x.png b/src/qt/qdarkstyle/dark/rc/checkbox_checked_focus@2x.png new file mode 100644 index 000000000..ba33ba4fb Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_checked_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_checked_pressed.png b/src/qt/qdarkstyle/dark/rc/checkbox_checked_pressed.png new file mode 100644 index 000000000..f104bb240 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_checked_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_checked_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/checkbox_checked_pressed@2x.png new file mode 100644 index 000000000..bb972d68f Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_checked_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate.png b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate.png new file mode 100644 index 000000000..8159551de Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate@2x.png b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate@2x.png new file mode 100644 index 000000000..75864b46d Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_disabled.png b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_disabled.png new file mode 100644 index 000000000..181625a00 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_disabled@2x.png new file mode 100644 index 000000000..0d32c78f3 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_focus.png b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_focus.png new file mode 100644 index 000000000..d7b19f61a Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_focus@2x.png b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_focus@2x.png new file mode 100644 index 000000000..d6403ca42 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_pressed.png b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_pressed.png new file mode 100644 index 000000000..37f46ca3d Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_pressed@2x.png new file mode 100644 index 000000000..aa7493edc Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_indeterminate_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_unchecked.png b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked.png new file mode 100644 index 000000000..e363ed620 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_unchecked@2x.png b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked@2x.png new file mode 100644 index 000000000..520f5e2a2 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_disabled.png b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_disabled.png new file mode 100644 index 000000000..066185ee7 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_disabled@2x.png new file mode 100644 index 000000000..9c80ad75a Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_focus.png b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_focus.png new file mode 100644 index 000000000..366b868de Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_focus@2x.png b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_focus@2x.png new file mode 100644 index 000000000..4ab217356 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_pressed.png b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_pressed.png new file mode 100644 index 000000000..d9a0bf71c Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_pressed@2x.png new file mode 100644 index 000000000..9e2b0515e Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/checkbox_unchecked_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_horizontal.png b/src/qt/qdarkstyle/dark/rc/line_horizontal.png new file mode 100644 index 000000000..4f88ddf7b Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_horizontal.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_horizontal@2x.png b/src/qt/qdarkstyle/dark/rc/line_horizontal@2x.png new file mode 100644 index 000000000..63be00c16 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_horizontal@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_horizontal_disabled.png b/src/qt/qdarkstyle/dark/rc/line_horizontal_disabled.png new file mode 100644 index 000000000..941f14a38 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_horizontal_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_horizontal_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/line_horizontal_disabled@2x.png new file mode 100644 index 000000000..972fa0800 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_horizontal_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_horizontal_focus.png b/src/qt/qdarkstyle/dark/rc/line_horizontal_focus.png new file mode 100644 index 000000000..221fd4607 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_horizontal_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_horizontal_focus@2x.png b/src/qt/qdarkstyle/dark/rc/line_horizontal_focus@2x.png new file mode 100644 index 000000000..7e6505cae Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_horizontal_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_horizontal_pressed.png b/src/qt/qdarkstyle/dark/rc/line_horizontal_pressed.png new file mode 100644 index 000000000..9f9113323 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_horizontal_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_horizontal_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/line_horizontal_pressed@2x.png new file mode 100644 index 000000000..465680c3b Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_horizontal_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_vertical.png b/src/qt/qdarkstyle/dark/rc/line_vertical.png new file mode 100644 index 000000000..6ee62c156 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_vertical.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_vertical@2x.png b/src/qt/qdarkstyle/dark/rc/line_vertical@2x.png new file mode 100644 index 000000000..d65e74c62 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_vertical@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_vertical_disabled.png b/src/qt/qdarkstyle/dark/rc/line_vertical_disabled.png new file mode 100644 index 000000000..c7c4c8959 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_vertical_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_vertical_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/line_vertical_disabled@2x.png new file mode 100644 index 000000000..b052de522 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_vertical_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_vertical_focus.png b/src/qt/qdarkstyle/dark/rc/line_vertical_focus.png new file mode 100644 index 000000000..36baa0936 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_vertical_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_vertical_focus@2x.png b/src/qt/qdarkstyle/dark/rc/line_vertical_focus@2x.png new file mode 100644 index 000000000..24a2b771c Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_vertical_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_vertical_pressed.png b/src/qt/qdarkstyle/dark/rc/line_vertical_pressed.png new file mode 100644 index 000000000..60e357446 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_vertical_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/line_vertical_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/line_vertical_pressed@2x.png new file mode 100644 index 000000000..c9494051c Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/line_vertical_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_checked.png b/src/qt/qdarkstyle/dark/rc/radio_checked.png new file mode 100644 index 000000000..acb890155 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_checked.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_checked@2x.png b/src/qt/qdarkstyle/dark/rc/radio_checked@2x.png new file mode 100644 index 000000000..e19047621 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_checked@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_checked_disabled.png b/src/qt/qdarkstyle/dark/rc/radio_checked_disabled.png new file mode 100644 index 000000000..49df43922 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_checked_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_checked_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/radio_checked_disabled@2x.png new file mode 100644 index 000000000..a9ffd40ce Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_checked_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_checked_focus.png b/src/qt/qdarkstyle/dark/rc/radio_checked_focus.png new file mode 100644 index 000000000..4bd472e16 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_checked_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_checked_focus@2x.png b/src/qt/qdarkstyle/dark/rc/radio_checked_focus@2x.png new file mode 100644 index 000000000..aed5e0c94 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_checked_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_checked_pressed.png b/src/qt/qdarkstyle/dark/rc/radio_checked_pressed.png new file mode 100644 index 000000000..ebb323b8c Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_checked_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_checked_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/radio_checked_pressed@2x.png new file mode 100644 index 000000000..ffe0fd851 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_checked_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_unchecked.png b/src/qt/qdarkstyle/dark/rc/radio_unchecked.png new file mode 100644 index 000000000..9ffddc4a0 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_unchecked.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_unchecked@2x.png b/src/qt/qdarkstyle/dark/rc/radio_unchecked@2x.png new file mode 100644 index 000000000..2160a32ed Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_unchecked@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_unchecked_disabled.png b/src/qt/qdarkstyle/dark/rc/radio_unchecked_disabled.png new file mode 100644 index 000000000..7ddff642d Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_unchecked_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_unchecked_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/radio_unchecked_disabled@2x.png new file mode 100644 index 000000000..4de5d0d2d Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_unchecked_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_unchecked_focus.png b/src/qt/qdarkstyle/dark/rc/radio_unchecked_focus.png new file mode 100644 index 000000000..e62b996b1 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_unchecked_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_unchecked_focus@2x.png b/src/qt/qdarkstyle/dark/rc/radio_unchecked_focus@2x.png new file mode 100644 index 000000000..eaf7bc26b Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_unchecked_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_unchecked_pressed.png b/src/qt/qdarkstyle/dark/rc/radio_unchecked_pressed.png new file mode 100644 index 000000000..8aaa343e8 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_unchecked_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/radio_unchecked_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/radio_unchecked_pressed@2x.png new file mode 100644 index 000000000..ba4f83b91 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/radio_unchecked_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal.png new file mode 100644 index 000000000..fa449d6ee Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal@2x.png new file mode 100644 index 000000000..682575ee2 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_disabled.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_disabled.png new file mode 100644 index 000000000..568b0fbe1 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_disabled@2x.png new file mode 100644 index 000000000..4d15f1478 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_focus.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_focus.png new file mode 100644 index 000000000..cdb96bfb9 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_focus@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_focus@2x.png new file mode 100644 index 000000000..23e06a015 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_pressed.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_pressed.png new file mode 100644 index 000000000..9ce6f8d89 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_pressed@2x.png new file mode 100644 index 000000000..4d8e53e8e Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_horizontal_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical.png new file mode 100644 index 000000000..bbc8abb1f Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical@2x.png new file mode 100644 index 000000000..136ebae2c Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_disabled.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_disabled.png new file mode 100644 index 000000000..37453ac25 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_disabled@2x.png new file mode 100644 index 000000000..cca8f6d96 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_focus.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_focus.png new file mode 100644 index 000000000..b54877181 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_focus@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_focus@2x.png new file mode 100644 index 000000000..d4dd49dec Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_pressed.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_pressed.png new file mode 100644 index 000000000..768ebaf4c Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_pressed@2x.png new file mode 100644 index 000000000..2f170ffd8 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_move_vertical_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal.png new file mode 100644 index 000000000..01e350132 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal@2x.png new file mode 100644 index 000000000..68d768e5e Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_disabled.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_disabled.png new file mode 100644 index 000000000..f8796f9e6 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_disabled@2x.png new file mode 100644 index 000000000..1d9f20421 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_focus.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_focus.png new file mode 100644 index 000000000..b592e61c1 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_focus@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_focus@2x.png new file mode 100644 index 000000000..a593a7e76 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_pressed.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_pressed.png new file mode 100644 index 000000000..a806257e0 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_pressed@2x.png new file mode 100644 index 000000000..e1e8e3c14 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_horizontal_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical.png new file mode 100644 index 000000000..2a14f5cbd Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical@2x.png new file mode 100644 index 000000000..35371feea Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_disabled.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_disabled.png new file mode 100644 index 000000000..48b2657f5 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_disabled@2x.png new file mode 100644 index 000000000..a2173c5ee Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_focus.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_focus.png new file mode 100644 index 000000000..e31c694b0 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_focus@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_focus@2x.png new file mode 100644 index 000000000..ce743cc86 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_pressed.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_pressed.png new file mode 100644 index 000000000..4ee7aaaab Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_pressed@2x.png new file mode 100644 index 000000000..d8bf93bf6 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/toolbar_separator_vertical_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/transparent.png b/src/qt/qdarkstyle/dark/rc/transparent.png new file mode 100644 index 000000000..67753617f Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/transparent.png differ diff --git a/src/qt/qdarkstyle/dark/rc/transparent@2x.png b/src/qt/qdarkstyle/dark/rc/transparent@2x.png new file mode 100644 index 000000000..4012944b5 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/transparent@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/transparent_disabled.png b/src/qt/qdarkstyle/dark/rc/transparent_disabled.png new file mode 100644 index 000000000..67753617f Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/transparent_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/transparent_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/transparent_disabled@2x.png new file mode 100644 index 000000000..4012944b5 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/transparent_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/transparent_focus.png b/src/qt/qdarkstyle/dark/rc/transparent_focus.png new file mode 100644 index 000000000..67753617f Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/transparent_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/transparent_focus@2x.png b/src/qt/qdarkstyle/dark/rc/transparent_focus@2x.png new file mode 100644 index 000000000..4012944b5 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/transparent_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/transparent_pressed.png b/src/qt/qdarkstyle/dark/rc/transparent_pressed.png new file mode 100644 index 000000000..67753617f Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/transparent_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/transparent_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/transparent_pressed@2x.png new file mode 100644 index 000000000..4012944b5 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/transparent_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_close.png b/src/qt/qdarkstyle/dark/rc/window_close.png new file mode 100644 index 000000000..0b67d3bcc Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_close.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_close@2x.png b/src/qt/qdarkstyle/dark/rc/window_close@2x.png new file mode 100644 index 000000000..bb8ac7da5 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_close@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_close_disabled.png b/src/qt/qdarkstyle/dark/rc/window_close_disabled.png new file mode 100644 index 000000000..46de804b8 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_close_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_close_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/window_close_disabled@2x.png new file mode 100644 index 000000000..8e4cd15d8 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_close_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_close_focus.png b/src/qt/qdarkstyle/dark/rc/window_close_focus.png new file mode 100644 index 000000000..bb7d8c511 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_close_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_close_focus@2x.png b/src/qt/qdarkstyle/dark/rc/window_close_focus@2x.png new file mode 100644 index 000000000..692ce24f2 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_close_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_close_pressed.png b/src/qt/qdarkstyle/dark/rc/window_close_pressed.png new file mode 100644 index 000000000..53ae7f38e Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_close_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_close_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/window_close_pressed@2x.png new file mode 100644 index 000000000..e02b12292 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_close_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_grip.png b/src/qt/qdarkstyle/dark/rc/window_grip.png new file mode 100644 index 000000000..db9ccb877 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_grip.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_grip@2x.png b/src/qt/qdarkstyle/dark/rc/window_grip@2x.png new file mode 100644 index 000000000..30b0639f4 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_grip@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_grip_disabled.png b/src/qt/qdarkstyle/dark/rc/window_grip_disabled.png new file mode 100644 index 000000000..97c0e0f90 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_grip_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_grip_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/window_grip_disabled@2x.png new file mode 100644 index 000000000..7a3d8de6d Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_grip_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_grip_focus.png b/src/qt/qdarkstyle/dark/rc/window_grip_focus.png new file mode 100644 index 000000000..99b27c9ce Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_grip_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_grip_focus@2x.png b/src/qt/qdarkstyle/dark/rc/window_grip_focus@2x.png new file mode 100644 index 000000000..833cb90a9 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_grip_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_grip_pressed.png b/src/qt/qdarkstyle/dark/rc/window_grip_pressed.png new file mode 100644 index 000000000..afea9749e Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_grip_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_grip_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/window_grip_pressed@2x.png new file mode 100644 index 000000000..c1c1a0e4b Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_grip_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_minimize.png b/src/qt/qdarkstyle/dark/rc/window_minimize.png new file mode 100644 index 000000000..d8c54ebf2 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_minimize.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_minimize@2x.png b/src/qt/qdarkstyle/dark/rc/window_minimize@2x.png new file mode 100644 index 000000000..5421a3690 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_minimize@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_minimize_disabled.png b/src/qt/qdarkstyle/dark/rc/window_minimize_disabled.png new file mode 100644 index 000000000..cc51ed0ee Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_minimize_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_minimize_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/window_minimize_disabled@2x.png new file mode 100644 index 000000000..c1676469f Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_minimize_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_minimize_focus.png b/src/qt/qdarkstyle/dark/rc/window_minimize_focus.png new file mode 100644 index 000000000..1dcd083c0 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_minimize_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_minimize_focus@2x.png b/src/qt/qdarkstyle/dark/rc/window_minimize_focus@2x.png new file mode 100644 index 000000000..2a4c868e0 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_minimize_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_minimize_pressed.png b/src/qt/qdarkstyle/dark/rc/window_minimize_pressed.png new file mode 100644 index 000000000..0bb532126 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_minimize_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_minimize_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/window_minimize_pressed@2x.png new file mode 100644 index 000000000..5a515c806 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_minimize_pressed@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_undock.png b/src/qt/qdarkstyle/dark/rc/window_undock.png new file mode 100644 index 000000000..d1f454259 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_undock.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_undock@2x.png b/src/qt/qdarkstyle/dark/rc/window_undock@2x.png new file mode 100644 index 000000000..f0efa3429 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_undock@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_undock_disabled.png b/src/qt/qdarkstyle/dark/rc/window_undock_disabled.png new file mode 100644 index 000000000..6a609492b Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_undock_disabled.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_undock_disabled@2x.png b/src/qt/qdarkstyle/dark/rc/window_undock_disabled@2x.png new file mode 100644 index 000000000..c2e1b8fa7 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_undock_disabled@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_undock_focus.png b/src/qt/qdarkstyle/dark/rc/window_undock_focus.png new file mode 100644 index 000000000..d6eebbdc2 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_undock_focus.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_undock_focus@2x.png b/src/qt/qdarkstyle/dark/rc/window_undock_focus@2x.png new file mode 100644 index 000000000..1aef06053 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_undock_focus@2x.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_undock_pressed.png b/src/qt/qdarkstyle/dark/rc/window_undock_pressed.png new file mode 100644 index 000000000..8b6beb19e Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_undock_pressed.png differ diff --git a/src/qt/qdarkstyle/dark/rc/window_undock_pressed@2x.png b/src/qt/qdarkstyle/dark/rc/window_undock_pressed@2x.png new file mode 100644 index 000000000..677ded425 Binary files /dev/null and b/src/qt/qdarkstyle/dark/rc/window_undock_pressed@2x.png differ diff --git a/src/qt/qt.c b/src/qt/qt.c index a9a6460eb..9ec907f33 100644 --- a/src/qt/qt.c +++ b/src/qt/qt.c @@ -35,8 +35,6 @@ qt_nvr_save(void) return nvr_save(); } -char icon_set[256] = ""; /* name of the iconset to be used */ - int plat_vidapi(const char *api) { @@ -89,4 +87,4 @@ plat_vidapi_name(int api) } return name; -} +} \ No newline at end of file diff --git a/src/qt/qt_deviceconfig.cpp b/src/qt/qt_deviceconfig.cpp index e2d6759ad..255b3c39f 100644 --- a/src/qt/qt_deviceconfig.cpp +++ b/src/qt/qt_deviceconfig.cpp @@ -31,6 +31,7 @@ #include #include #include +#include extern "C" { #include <86box/86box.h> @@ -45,6 +46,7 @@ extern "C" { #include "qt_filefield.hpp" #include "qt_models_common.hpp" +#include "qt_util.hpp" #ifdef Q_OS_LINUX # include # include @@ -123,7 +125,7 @@ DeviceConfig::ProcessConfig(void *dc, const void *c, const bool is_dep) if (config == NULL) return; - while (config->type != -1) { + while (config->type != CONFIG_END) { const int config_type = config->type & CONFIG_TYPE_MASK; /* Ignore options of the wrong class. */ @@ -242,8 +244,12 @@ DeviceConfig::ProcessConfig(void *dc, const void *c, const bool is_dep) int currentIndex = -1; q = 0; - for (auto *bios = config->bios; (bios != nullptr) && (bios->name != nullptr) && - (strlen(bios->name) > 0); ++bios) { + for (auto *bios = config->bios; (bios != nullptr) && + (bios->name != nullptr) && + (bios->internal_name != nullptr) && + (strlen(bios->name) > 0) && + (strlen(bios->internal_name) > 0) && + (bios->files_no > 0); ++bios) { p = 0; for (int d = 0; d < bios->files_no; d++) p += !!rom_present(const_cast(bios->files[d])); @@ -272,11 +278,25 @@ DeviceConfig::ProcessConfig(void *dc, const void *c, const bool is_dep) } case CONFIG_FNAME: { - auto *fileField = new FileField(); + auto *fileField = new FileField(this); fileField->setObjectName(config->name); fileField->setFileName(selected); - fileField->setFilter(QString(config->file_filter).left(static_cast(strcspn(config->file_filter, - "|")))); + /* Get the actually used part of the filter */ + QString filter = QString(config->file_filter).left(static_cast(strcspn(config->file_filter, "|"))); + /* Extract the description and the extension list */ + QRegularExpressionMatch match = QRegularExpression("(.+) \\((.+)\\)$").match(filter); + QString description = match.captured(1); + QString extensions = match.captured(2); + QStringList extensionList; + /* Split the extension list up and strip the filename globs */ + QRegularExpression re("\\*\\.(.*)"); + int i = 0; + while (extensions.section(' ', i, i) != "") { + QString extension = re.match(extensions.section(' ', i, i)).captured(1); + extensionList.append(extension); + i++; + } + fileField->setFilter(tr(description.toUtf8().constData()) % util::DlgFilter(extensionList) % tr("All files") % util::DlgFilter({ "*" }, true)); this->ui->formLayout->addRow(tr(config->description), fileField); break; } @@ -372,7 +392,7 @@ DeviceConfig::ConfigureDevice(const _device_ *device, int instance, Settings *se return; config = device->config; - while (config->type != -1) { + while (config->type != CONFIG_END) { switch (config->type) { default: break; @@ -384,6 +404,7 @@ DeviceConfig::ConfigureDevice(const _device_ *device, int instance, Settings *se } case CONFIG_MIDI_OUT: case CONFIG_MIDI_IN: + case CONFIG_INT: case CONFIG_SELECTION: { auto *cbox = dc.findChild(config->name); diff --git a/src/qt/qt_deviceconfig.hpp b/src/qt/qt_deviceconfig.hpp index a16c152a6..a5214111f 100644 --- a/src/qt/qt_deviceconfig.hpp +++ b/src/qt/qt_deviceconfig.hpp @@ -23,7 +23,7 @@ public: ~DeviceConfig() override; static void ConfigureDevice(const _device_ *device, int instance = 0, - Settings *settings = nullptr); + Settings *settings = qobject_cast(Settings::settings)); static QString DeviceName(const _device_ *device, const char *internalName, int bus); private: diff --git a/src/qt/qt_downloader.cpp b/src/qt/qt_downloader.cpp new file mode 100644 index 000000000..329aeeafb --- /dev/null +++ b/src/qt/qt_downloader.cpp @@ -0,0 +1,95 @@ +/* + * 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. + * + * Downloader module + * + * + * + * Authors: cold-brewed + * + * Copyright 2024 cold-brewed + */ + +#include +#include +#include +#include + +#include "qt_downloader.hpp" + +extern "C" { +#include <86box/plat.h> +} + +Downloader:: +Downloader(const DownloadLocation downloadLocation, QObject *parent) + : QObject(parent) + , file(nullptr) + , reply(nullptr) + , variantData(QVariant::Invalid) +{ + char PATHBUF[256]; + switch (downloadLocation) { + case DownloadLocation::Data: + plat_get_global_data_dir(PATHBUF, 255); + break; + case DownloadLocation::Config: + plat_get_global_config_dir(PATHBUF, 255); + break; + case DownloadLocation::Temp: + plat_get_temp_dir(PATHBUF, 255); + break; + } + downloadDirectory = QDir(PATHBUF); +} + +Downloader::~Downloader() { delete file; } + +void Downloader::download(const QUrl &url, const QString &filepath, const QVariant &varData) { + + variantData = varData; + // temporary until I get the plat stuff fixed + // const auto global_dir = temporaryGetGlobalDataDir(); + // qDebug() << "I was passed filepath " << filepath; + // Join with filename to create final file + // const auto final_path = QDir(global_dir).filePath(filepath); + const auto final_path = downloadDirectory.filePath(filepath); + + file = new QFile(final_path); + if(!file->open(QIODevice::WriteOnly)) { + qWarning() << "Unable to open file " << final_path; + return; + } + + const auto nam = new QNetworkAccessManager(this); + // Create the network request and execute + const auto request = QNetworkRequest(url); + reply = nam->get(request); + // Connect to the finished signal + connect(reply, &QNetworkReply::finished, this, &Downloader::onResult); +} + +void +Downloader::onResult() +{ + if (reply->error()) { + qWarning() << "Error returned from QNetworkRequest: " << reply->errorString(); + emit errorOccurred(reply->errorString()); + reply->deleteLater(); + return; + } + + file->write(reply->readAll()); + file->flush(); + file->close(); + + reply->deleteLater(); + qDebug() << Q_FUNC_INFO << "Downloaded complete: file written to " << file->fileName(); + emit downloadCompleted(file->fileName(), variantData); +} + diff --git a/src/qt/qt_downloader.hpp b/src/qt/qt_downloader.hpp new file mode 100644 index 000000000..0bd3f1fee --- /dev/null +++ b/src/qt/qt_downloader.hpp @@ -0,0 +1,57 @@ +/* + * 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. + * + * Header for the downloader module + * + * + * + * Authors: cold-brewed + * + * Copyright 2024 cold-brewed + */ + +#ifndef QT_DOWNLOADER_HPP +#define QT_DOWNLOADER_HPP + +#include +#include +#include +#include + + +class Downloader : public QObject { + Q_OBJECT +public: + enum class DownloadLocation { + Data, // AppDataLocation via plat_get_global_data_dir() + Config, // AppConfigLocation via plat_get_global_config_dir() + Temp // TempLocation via plat_get_temp_dir() + }; + explicit Downloader(DownloadLocation downloadLocation = DownloadLocation::Data, QObject *parent = nullptr); + ~Downloader() final; + + void download(const QUrl &url, const QString &filepath, const QVariant &varData = QVariant::Invalid); + +signals: + // Signal emitted when the download is successful + void downloadCompleted(QString filename, QVariant varData); + // Signal emitted when an error occurs + void errorOccurred(const QString&); + +private slots: + void onResult(); + +private: + QFile *file; + QNetworkAccessManager nam; + QNetworkReply *reply; + QVariant variantData; + QDir downloadDirectory; +}; + +#endif diff --git a/src/qt/qt_glsl_parser.cpp b/src/qt/qt_glsl_parser.cpp new file mode 100644 index 000000000..9efeb430b --- /dev/null +++ b/src/qt/qt_glsl_parser.cpp @@ -0,0 +1,417 @@ +#include "qt_mainwindow.hpp" +#include +#include +#include + +extern MainWindow* main_window; + +#include +#include +#include +#include +#include +extern "C" +{ +#include <86box/86box.h> +#include <86box/ini.h> +#include <86box/config.h> +#include <86box/qt-glslp-parser.h> +#include <86box/path.h> +#include <86box/plat.h> + +extern void startblit(); +extern void endblit(); +extern ssize_t local_getline(char **buf, size_t *bufsiz, FILE *fp); +extern char* trim(char* str); +} + +#define safe_strncpy(a, b, n) \ + do { \ + strncpy((a), (b), (n)-1); \ + (a)[(n)-1] = 0; \ + } while (0) + + + +static inline void *wx_config_load(const char *path) { ini_t ini = ini_read(path); if (ini) ini_strip_quotes(ini); return (void*)ini; } + +static inline int wx_config_get_string(void *config, const char *name, char *dst, int size, const char *defVal) { + int res = ini_has_entry(ini_find_or_create_section((ini_t)config, ""), name); + char* str = ini_get_string((ini_t)config, "", name, (char*)defVal); + if (size == 0) + return res; + if (str != NULL) + strncpy(dst, str, size - 1); + else + dst[0] = 0; + return res; +} + +static inline int wx_config_get_int(void *config, const char *name, int *dst, int defVal) { + int res = ini_has_entry(ini_find_or_create_section((ini_t)config, ""), name); + *dst = ini_get_int((ini_t)config, "", name, defVal); + return res; +} + +static inline int wx_config_get_float(void *config, const char *name, float *dst, float defVal) { + int res = ini_has_entry(ini_find_or_create_section((ini_t)config, ""), name); + *dst = (float)ini_get_double((ini_t)config, "", name, defVal); + return res; +} + +static inline int wx_config_get_bool(void *config, const char *name, int *dst, int defVal) { + int res = ini_has_entry(ini_find_or_create_section((ini_t)config, ""), name); + *dst = !!ini_get_int((ini_t)config, "", name, defVal); + return res; +} + +static inline int wx_config_has_entry(void *config, const char *name) { return ini_has_entry(ini_find_or_create_section((ini_t)config, ""), name); } +static inline void wx_config_free(void *config) { ini_close(config); }; + +static int endswith(const char *str, const char *ext) { + int i; + const char *p; + int elen = strlen(ext); + int slen = strlen(str); + if (slen >= elen) { + p = &str[slen - elen]; + for (i = 0; i < elen; ++i) { + if (tolower(p[i]) != tolower(ext[i])) + return 0; + } + return 1; + } + return 0; +} + +static int +glsl_detect_bom(const char *fn) +{ + FILE *fp; + unsigned char bom[4] = { 0, 0, 0, 0 }; + + fp = plat_fopen(fn, "rb"); + if (fp == NULL) + return 0; + (void) !fread(bom, 1, 3, fp); + if (bom[0] == 0xEF && bom[1] == 0xBB && bom[2] == 0xBF) { + fclose(fp); + return 1; + } + fclose(fp); + return 0; +} + +static char *load_file(const char *fn) { + int bom = glsl_detect_bom(fn); + FILE *fp = plat_fopen(fn, "rb"); + if (!fp) + return 0; + fseek(fp, 0, SEEK_END); + long fsize = ftell(fp); + fseek(fp, 0, SEEK_SET); + + if (bom) { + fsize -= 3; + fseek(fp, 3, SEEK_SET); + } + + char *data = (char*)malloc(fsize + 1); + + (void) fread(data, fsize, 1, fp); + fclose(fp); + + data[fsize] = 0; + + return data; +} + +static void strip_lines(const char *program, const char *starts_with) { + /* strip parameters */ + char *ptr = (char *) strstr(program, starts_with); + while (ptr != nullptr) { + while (*ptr != '\n' && *ptr != '\0') + *ptr++ = ' '; + ptr = (char *) strstr(program, starts_with); + } +} + +static void strip_parameters(const char *program) { + /* strip parameters */ + strip_lines(program, "#pragma parameter"); +} + +static void strip_defines(const char *program) { + /* strip texture define */ + strip_lines(program, "#define texture"); +} + +static int has_parameter(glslp_t *glsl, char *id) { + int i; + for (i = 0; i < glsl->num_parameters; ++i) + if (!strcmp(glsl->parameters[i].id, id)) + return 1; + return 0; +} + +static int get_parameters(glslp_t *glsl) { + int i; + struct parameter p; + for (i = 0; i < glsl->num_shaders; ++i) { + size_t size = 0; + char* line = NULL; + struct shader *shader = &glsl->shaders[i]; + int bom = glsl_detect_bom(shader->shader_fn); + FILE *f = plat_fopen(shader->shader_fn, "rb"); + if (!f) + return 0; + if (bom) { + fseek(f, 3, SEEK_SET); + } + while (local_getline(&line, &size, f) != -1 && glsl->num_parameters < MAX_PARAMETERS) { + line[strcspn(line, "\r\n")] = '\0'; + trim(line); + int num = sscanf(line, "#pragma parameter %63s \"%63[^\"]\" %f %f %f %f", p.id, p.description, + &p.default_value, &p.min, &p.max, &p.step); + if (num < 5) + continue; + p.id[63] = 0; + p.description[63] = 0; + + if (num == 5) + p.step = 0.1f * (p.max - p.min); + + p.value = p.default_value; + + if (!has_parameter(glsl, p.id)) { + memcpy(&glsl->parameters[glsl->num_parameters++], &p, sizeof(struct parameter)); + pclog("Read parameter: %s (%s) %f, %f -> %f (%f)\n", p.id, p.description, p.default_value, p.min, + p.max, p.step); + } + } + + fclose(f); + } + + return 1; +} + +static struct parameter *get_parameter(glslp_t *glslp, const char *id) { + int i; + for (i = 0; i < glslp->num_parameters; ++i) { + if (!strcmp(glslp->parameters[i].id, id)) { + return &glslp->parameters[i]; + } + } + return 0; +} + +static glslp_t *glsl_parse(const char *f) { + glslp_t *glslp = (glslp_t*)malloc(sizeof(glslp_t)); + memset(glslp, 0, sizeof(glslp_t)); + glslp->num_shaders = 1; + struct shader *shader = &glslp->shaders[0]; + strcpy(shader->shader_fn, f); + shader->shader_program = load_file(f); + if (!shader->shader_program) { + QMessageBox::critical((QWidget *) qApp->findChild(), QObject::tr("GLSL error"), QObject::tr("Could not load shader: %1").arg(shader->shader_fn)); + //wx_simple_messagebox("GLSL error", "Could not load shader %s\n", shader->shader_fn); + glslp_free(glslp); + return 0; + } + strip_parameters(shader->shader_program); + strip_defines(shader->shader_program); + shader->scale_x = shader->scale_y = 1.0f; + strcpy(shader->scale_type_x, "source"); + strcpy(shader->scale_type_y, "source"); + get_parameters(glslp); + return glslp; +} + +extern "C" { + +void get_glslp_name(const char *f, char *s, int size) { safe_strncpy(s, path_get_filename((char *)f), size); } + +glslp_t *glslp_parse(const char *f) { + int i, j, len, sublen; + char s[513], t[513], z[540]; + + memset(s, 0, sizeof(s)); + if (endswith(f, ".glsl")) + return glsl_parse(f); + + void *cfg = wx_config_load(f); + + if (!cfg) { + fprintf(stderr, "GLSLP Error: Could not load GLSLP-file %s\n", f); + return 0; + } + + glslp_t *glslp = (glslp_t*)malloc(sizeof(glslp_t)); + memset(glslp, 0, sizeof(glslp_t)); + + get_glslp_name(f, glslp->name, sizeof(glslp->name)); + + wx_config_get_int(cfg, "shaders", &glslp->num_shaders, 0); + + wx_config_get_bool(cfg, "filter_linear0", &glslp->input_filter_linear, -1); + + for (i = 0; i < glslp->num_shaders; ++i) { + struct shader *shader = &glslp->shaders[i]; + + snprintf(s, sizeof(s) - 1, "shader%d", i); + if (!wx_config_get_string(cfg, s, t, sizeof(t), 0)) { + /* shader doesn't exist, lets break here */ + glslp->num_shaders = i; + break; + } + strcpy(s, f); + *path_get_filename(s) = 0; + snprintf(shader->shader_fn, sizeof(shader->shader_fn) - 1, "%s%s", s, t); + shader->shader_program = load_file(shader->shader_fn); + if (!shader->shader_program) { + fprintf(stderr, "GLSLP Error: Could not load shader %s\n", shader->shader_fn); + glslp_free(glslp); + return 0; + } + strip_parameters(shader->shader_program); + strip_defines(shader->shader_program); + + snprintf(s, sizeof(s) - 1, "alias%d", i); + wx_config_get_string(cfg, s, shader->alias, sizeof(shader->alias), 0); + + snprintf(s, sizeof(s) - 1, "filter_linear%d", i + 1); + wx_config_get_bool(cfg, s, &shader->filter_linear, 0); + + snprintf(s, sizeof(s) - 1, "wrap_mode%d", i); + wx_config_get_string(cfg, s, shader->wrap_mode, sizeof(shader->wrap_mode), 0); + + snprintf(s, sizeof(s) - 1, "float_framebuffer%d", i); + wx_config_get_bool(cfg, s, &shader->float_framebuffer, 0); + snprintf(s, sizeof(s) - 1, "srgb_framebuffer%d", i); + wx_config_get_bool(cfg, s, &shader->srgb_framebuffer, 0); + + snprintf(s, sizeof(s) - 1, "mipmap_input%d", i); + wx_config_get_bool(cfg, s, &shader->mipmap_input, 0); + + strcpy(shader->scale_type_x, "source"); + snprintf(s, sizeof(s) - 1, "scale_type_x%d", i); + wx_config_get_string(cfg, s, shader->scale_type_x, sizeof(shader->scale_type_x), 0); + strcpy(shader->scale_type_y, "source"); + snprintf(s, sizeof(s) - 1, "scale_type_y%d", i); + wx_config_get_string(cfg, s, shader->scale_type_y, sizeof(shader->scale_type_y), 0); + snprintf(s, sizeof(s) - 1, "scale_type%d", i); + if (wx_config_has_entry(cfg, s)) { + wx_config_get_string(cfg, s, shader->scale_type_x, sizeof(shader->scale_type_x), 0); + wx_config_get_string(cfg, s, shader->scale_type_y, sizeof(shader->scale_type_y), 0); + } + + snprintf(s, sizeof(s) - 1, "scale_x%d", i); + wx_config_get_float(cfg, s, &shader->scale_x, 1.0f); + snprintf(s, sizeof(s) - 1, "scale_y%d", i); + wx_config_get_float(cfg, s, &shader->scale_y, 1.0f); + snprintf(s, sizeof(s) - 1, "scale%d", i); + if (wx_config_has_entry(cfg, s)) { + wx_config_get_float(cfg, s, &shader->scale_x, 1.0f); + wx_config_get_float(cfg, s, &shader->scale_y, 1.0f); + } + + snprintf(s, sizeof(s) - 1, "frame_count_mod%d", i); + wx_config_get_int(cfg, s, &shader->frame_count_mod, 0); + } + + /* textures */ + glslp->num_textures = 0; + wx_config_get_string(cfg, "textures", t, sizeof(t), 0); + + len = strlen(t); + j = 0; + sublen = 0; + for (i = 0; i < len; ++i) { + if (t[i] == ';' || i == len - 1) { + sublen = (i - j) + ((i == len - 1) ? 1 : 0) + 1; + safe_strncpy(s, t + j, sublen); + s[511 < sublen ? 511 : sublen] = 0; + + if (s[strlen(s) - 1] == ';') s[strlen(s) - 1] = 0; + + struct texture *tex = &glslp->textures[glslp->num_textures++]; + + strcpy(tex->name, s); + wx_config_get_string(cfg, s, tex->path, sizeof(tex->path), 0); + + snprintf(z, sizeof(z) - 1, "%s_linear", s); + wx_config_get_bool(cfg, z, &tex->linear, 0); + + snprintf(z, sizeof(z) - 1, "%s_mipmap", s); + wx_config_get_bool(cfg, z, &tex->mipmap, 0); + + snprintf(z, sizeof(z) - 1, "%s_wrap_mode", s); + wx_config_get_string(cfg, z, tex->wrap_mode, sizeof(tex->wrap_mode), 0); + + j = i + 1; + } + } + + /* parameters */ + get_parameters(glslp); + + wx_config_get_string(cfg, "parameters", t, sizeof(t), 0); + + len = strlen(t); + j = 0; + sublen = 0; + for (i = 0; i < len; ++i) { + if (t[i] == ';' || i == len - 1) { + sublen = (i - j) + ((i == len - 1) ? 1 : 0) + 1; + safe_strncpy(s, t + j, sublen); + s[511 < sublen ? 511 : sublen] = 0; + + struct parameter *p = get_parameter(glslp, s); + + if (p) + wx_config_get_float(cfg, s, &p->default_value, 0); + + j = i + 1; + } + } + + wx_config_free(cfg); + + return glslp; +} + +void glslp_free(glslp_t *p) { + int i; + for (i = 0; i < p->num_shaders; ++i) + if (p->shaders[i].shader_program) + free(p->shaders[i].shader_program); + free(p); +} + +void glslp_read_shader_config(glslp_t *shader) { + char s[512]; + int i; + char *name = shader->name; + sprintf(s, "GL3 Shaders - %s", name); + for (i = 0; i < shader->num_parameters; ++i) { + struct parameter *param = &shader->parameters[i]; + param->value = config_get_double(s, param->id, param->default_value); + } +} + +void glslp_write_shader_config(glslp_t *shader) { + char s[512]; + int i; + char *name = shader->name; + + startblit(); + sprintf(s, "GL3 Shaders - %s", name); + for (i = 0; i < shader->num_parameters; ++i) { + struct parameter *param = &shader->parameters[i]; + config_set_double(s, param->id, param->value); + } + endblit(); +} + +} diff --git a/src/qt/qt_harddiskdialog.cpp b/src/qt/qt_harddiskdialog.cpp index f2326ef8b..ae1c60971 100644 --- a/src/qt/qt_harddiskdialog.cpp +++ b/src/qt/qt_harddiskdialog.cpp @@ -77,8 +77,7 @@ HarddiskDialog::HarddiskDialog(bool existing, QWidget *parent) for (int i = 0; i < 127; i++) { 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 = tr("%1 MB (CHS: %2, %3, %4)").arg(size_mb).arg(hdd_table[i][0]).arg(hdd_table[i][1]).arg(hdd_table[i][2]); Models::AddEntry(model, text, i); } Models::AddEntry(model, tr("Custom..."), 127); @@ -200,7 +199,7 @@ HarddiskDialog::on_comboBoxFormat_currentIndexChanged(int index) * than a tenth of a percent change in size. */ static void -adjust_86box_geometry_for_vhd(MVHDGeom *_86box_geometry, MVHDGeom *vhd_geometry) +adjust_86box_geometry_for_vhd(_86BoxGeom *_86box_geometry, MVHDGeom *vhd_geometry) { if (_86box_geometry->cyl <= 65535) { vhd_geometry->cyl = _86box_geometry->cyl; @@ -227,10 +226,14 @@ adjust_86box_geometry_for_vhd(MVHDGeom *_86box_geometry, MVHDGeom *vhd_geometry) } static HarddiskDialog *callbackPtr = nullptr; -static MVHDGeom -create_drive_vhd_fixed(const QString &fileName, HarddiskDialog *p, uint16_t cyl, uint8_t heads, uint8_t spt) +static _86BoxGeom +create_drive_vhd_fixed(const QString &fileName, HarddiskDialog *p, uint32_t cyl, uint32_t heads, uint32_t spt) { - MVHDGeom _86box_geometry = { .cyl = cyl, .heads = heads, .spt = spt }; + _86BoxGeom _86box_geometry = { + .cyl = cyl, + .heads = heads, + .spt = spt + }; MVHDGeom vhd_geometry; adjust_86box_geometry_for_vhd(&_86box_geometry, &vhd_geometry); @@ -253,10 +256,14 @@ create_drive_vhd_fixed(const QString &fileName, HarddiskDialog *p, uint16_t cyl, return _86box_geometry; } -static MVHDGeom -create_drive_vhd_dynamic(const QString &fileName, uint16_t cyl, uint8_t heads, uint8_t spt, int blocksize) +static _86BoxGeom +create_drive_vhd_dynamic(const QString &fileName, uint32_t cyl, uint32_t heads, uint32_t spt, int blocksize) { - MVHDGeom _86box_geometry = { .cyl = cyl, .heads = heads, .spt = spt }; + _86BoxGeom _86box_geometry = { + .cyl = cyl, + .heads = heads, + .spt = spt + }; MVHDGeom vhd_geometry; adjust_86box_geometry_for_vhd(&_86box_geometry, &vhd_geometry); int vhd_error = 0; @@ -280,7 +287,7 @@ create_drive_vhd_dynamic(const QString &fileName, uint16_t cyl, uint8_t heads, u return _86box_geometry; } -static MVHDGeom +static _86BoxGeom create_drive_vhd_diff(const QString &fileName, const QString &parentFileName, int blocksize) { int vhd_error = 0; @@ -292,25 +299,31 @@ create_drive_vhd_diff(const QString &fileName, const QString &parentFileName, in options.parent_path = parentFilenameBytes.data(); options.type = MVHD_TYPE_DIFF; - MVHDMeta *vhd = mvhd_create_ex(options, &vhd_error); - MVHDGeom vhd_geometry; + MVHDMeta *vhd = mvhd_create_ex(options, &vhd_error); + MVHDGeom vhd_geometry; + _86BoxGeom _86box_geometry; if (vhd == NULL) { - vhd_geometry.cyl = 0; - vhd_geometry.heads = 0; - vhd_geometry.spt = 0; + _86box_geometry.cyl = 0; + _86box_geometry.heads = 0; + _86box_geometry.spt = 0; } else { vhd_geometry = mvhd_get_geometry(vhd); if (vhd_geometry.spt > 63) { - vhd_geometry.cyl = mvhd_calc_size_sectors(&vhd_geometry) / (16 * 63); - vhd_geometry.heads = 16; - vhd_geometry.spt = 63; + _86box_geometry.cyl = mvhd_calc_size_sectors(&vhd_geometry) / (16 * 63); + _86box_geometry.heads = 16; + _86box_geometry.spt = 63; + } else { + _86box_geometry.cyl = vhd_geometry.cyl; + _86box_geometry.heads = vhd_geometry.heads; + _86box_geometry.spt = vhd_geometry.spt; } + mvhd_close(vhd); } - return vhd_geometry; + return _86box_geometry; } void @@ -402,7 +415,7 @@ HarddiskDialog::onCreateNewFile() } else if (img_format >= IMG_FMT_VHD_FIXED) { /* VHD file */ file.close(); - MVHDGeom _86box_geometry {}; + _86BoxGeom _86box_geometry {}; int block_size = ui->comboBoxBlockSize->currentIndex() == 0 ? MVHD_BLOCK_LARGE : MVHD_BLOCK_SMALL; switch (img_format) { case IMG_FMT_VHD_FIXED: @@ -486,10 +499,14 @@ HarddiskDialog::onCreateNewFile() } static void -adjust_vhd_geometry_for_86box(MVHDGeom *vhd_geometry) +adjust_vhd_geometry_for_86box(MVHDGeom *vhd_geometry, _86BoxGeom *_86box_geometry) { - if (vhd_geometry->spt <= 63) + if (vhd_geometry->spt <= 63) { + _86box_geometry->cyl = vhd_geometry->cyl; + _86box_geometry->heads = vhd_geometry->heads; + _86box_geometry->spt = vhd_geometry->spt; return; + } int desired_sectors = vhd_geometry->cyl * vhd_geometry->heads * vhd_geometry->spt; if (desired_sectors > 267321600) @@ -499,9 +516,9 @@ adjust_vhd_geometry_for_86box(MVHDGeom *vhd_geometry) if (remainder > 0) desired_sectors -= remainder; - vhd_geometry->cyl = desired_sectors / (16 * 63); - vhd_geometry->heads = 16; - vhd_geometry->spt = 63; + _86box_geometry->cyl = desired_sectors / (16 * 63); + _86box_geometry->heads = 16; + _86box_geometry->spt = 63; } void @@ -595,11 +612,12 @@ HarddiskDialog::onExistingFileSelected(const QString &fileName, bool precheck) } } - MVHDGeom vhd_geom = mvhd_get_geometry(vhd); - adjust_vhd_geometry_for_86box(&vhd_geom); - cylinders = vhd_geom.cyl; - heads = vhd_geom.heads; - sectors = vhd_geom.spt; + MVHDGeom vhd_geom = mvhd_get_geometry(vhd); + _86BoxGeom _86box_geom; + adjust_vhd_geometry_for_86box(&vhd_geom, &_86box_geom); + cylinders = _86box_geom.cyl; + heads = _86box_geom.heads; + sectors = _86box_geom.spt; size = static_cast(cylinders * heads * sectors * 512); mvhd_close(vhd); } else { diff --git a/src/qt/qt_harddiskdialog.hpp b/src/qt/qt_harddiskdialog.hpp index 9de61c51b..62ec6e963 100644 --- a/src/qt/qt_harddiskdialog.hpp +++ b/src/qt/qt_harddiskdialog.hpp @@ -64,4 +64,10 @@ private: void recalcSelection(); }; +typedef struct _86BoxGeom { + uint32_t cyl; + uint32_t heads; + uint32_t spt; +} _86BoxGeom; + #endif // QT_HARDDISKDIALOG_HPP diff --git a/src/qt/qt_harddiskdialog.ui b/src/qt/qt_harddiskdialog.ui index 91499d2cb..cba835134 100644 --- a/src/qt/qt_harddiskdialog.ui +++ b/src/qt/qt_harddiskdialog.ui @@ -32,27 +32,16 @@ Dialog - - - - - - - Channel: + + + + false - - - - - - Speed: + + 0 - - - - - - 30 + + true @@ -63,86 +52,34 @@ - - + + - Type: + Image Format: - - - - - 0 - 0 - - - - - 64 - 16777215 - - - - - - - - - 0 - 0 - - - - - 64 - 16777215 - - - - - - - - Size (MB): - - - - - + + 30 - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + Bus: - - - - Qt::Vertical - - - - 20 - 20 - - - + + - - + + - Cylinders: + Type: @@ -165,10 +102,29 @@ - - - - Image Format: + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + 0 + 0 + + + + + 64 + 16777215 + @@ -179,31 +135,47 @@ - - + + + + + 0 + 0 + + + + + 64 + 16777215 + + + + + + 30 - - + + - Bus: + Cylinders: - - - - 30 + + + + File name: - - - - 30 + + + + Size (MB): @@ -226,37 +198,65 @@ - - + + + + Channel: + + + + + 30 - + Block Size: - - + + + + Qt::Vertical + + + + 20 + 20 + + + + + + - File name: + Model: - - - - false + + + + 30 - - 0 + + + + + + 30 - - true + + + + + + 30 diff --git a/src/qt/qt_harddrive_common.cpp b/src/qt/qt_harddrive_common.cpp index e0b0233f1..52ae10a98 100644 --- a/src/qt/qt_harddrive_common.cpp +++ b/src/qt/qt_harddrive_common.cpp @@ -51,7 +51,7 @@ void Harddrives::populateRemovableBuses(QAbstractItemModel *model) { model->removeRows(0, model->rowCount()); -#if 0 +#ifdef USE_CDROM_MITSUMI model->insertRows(0, 4); #else model->insertRows(0, 3); @@ -59,14 +59,14 @@ Harddrives::populateRemovableBuses(QAbstractItemModel *model) model->setData(model->index(0, 0), QObject::tr("Disabled")); model->setData(model->index(1, 0), QObject::tr("ATAPI")); model->setData(model->index(2, 0), QObject::tr("SCSI")); -#if 0 +#ifdef USE_CDROM_MITSUMI model->setData(model->index(3, 0), QObject::tr("Mitsumi")); #endif model->setData(model->index(0, 0), HDD_BUS_DISABLED, Qt::UserRole); model->setData(model->index(1, 0), HDD_BUS_ATAPI, Qt::UserRole); model->setData(model->index(2, 0), HDD_BUS_SCSI, Qt::UserRole); -#if 0 +#ifdef USE_CDROM_MITSUMI model->setData(model->index(3, 0), CDROM_BUS_MITSUMI, Qt::UserRole); #endif } diff --git a/src/qt/qt_hardwarerenderer.cpp b/src/qt/qt_hardwarerenderer.cpp index ee2ec07df..fb84606b0 100644 --- a/src/qt/qt_hardwarerenderer.cpp +++ b/src/qt/qt_hardwarerenderer.cpp @@ -37,7 +37,7 @@ void HardwareRenderer::resizeGL(int w, int h) { m_context->makeCurrent(this); - glViewport(0, 0, qRound(w * devicePixelRatio()), qRound(h * devicePixelRatio())); + glViewport(0, 0, qRound(w * devicePixelRatioF()), qRound(h * devicePixelRatioF())); } #define PROGRAM_VERTEX_ATTRIBUTE 0 @@ -145,7 +145,7 @@ HardwareRenderer::paintGL() QVector texcoords; QMatrix4x4 mat; mat.setToIdentity(); - mat.ortho(QRectF(0, 0, (qreal) width(), (qreal) height())); + mat.ortho(QRectF(0, 0, (qreal) width() * (qreal) devicePixelRatioF(), (qreal) height() * (qreal) devicePixelRatioF())); verts.push_back(QVector2D((float) destination.x(), (float) destination.y())); verts.push_back(QVector2D((float) destination.x(), (float) destination.y() + (float) destination.height())); verts.push_back(QVector2D((float) destination.x() + (float) destination.width(), (float) destination.y() + (float) destination.height())); @@ -220,14 +220,17 @@ HardwareRenderer::onBlit(int buf_idx, int x, int y, int w, int h) #endif buf_usage[buf_idx].clear(); source.setRect(x, y, w, h); - if (origSource != source) + if (origSource != source) { + this->pixelRatio = devicePixelRatioF(); onResize(this->width(), this->height()); + } update(); } void HardwareRenderer::resizeEvent(QResizeEvent *event) { + this->pixelRatio = devicePixelRatioF(); onResize(width(), height()); QOpenGLWindow::resizeEvent(event); diff --git a/src/qt/qt_iconindicators.cpp b/src/qt/qt_iconindicators.cpp new file mode 100644 index 000000000..d5d22c78d --- /dev/null +++ b/src/qt/qt_iconindicators.cpp @@ -0,0 +1,39 @@ +#include +#include +#include "qt_iconindicators.hpp" + +QIcon +getIndicatorIcon(IconIndicator indicator) +{ + switch (indicator) { + case Active: + return QIcon(":/settings/qt/icons/active.ico"); + case WriteActive: + return QIcon(":/settings/qt/icons/write_active.ico"); + case Disabled: + return QIcon(":/settings/qt/icons/disabled.ico"); + default: + return QIcon(); + } +} + +QPixmap +getIconWithIndicator(const QIcon &icon, const QSize &size, QIcon::Mode iconMode, IconIndicator indicator) +{ + auto iconPixmap = icon.pixmap(size, iconMode); + + if (indicator == None) + return iconPixmap; + + auto painter = QPainter(&iconPixmap); + auto indicatorPixmap = getIndicatorIcon(indicator == ReadWriteActive ? Active : indicator).pixmap(size); + + painter.drawPixmap(0, 0, indicatorPixmap); + if (indicator == ReadWriteActive) { + auto writeIndicatorPixmap = getIndicatorIcon(WriteActive).pixmap(size); + painter.drawPixmap(0, 0, writeIndicatorPixmap); + } + painter.end(); + + return iconPixmap; +} \ No newline at end of file diff --git a/src/qt/qt_iconindicators.hpp b/src/qt/qt_iconindicators.hpp new file mode 100644 index 000000000..12f82f259 --- /dev/null +++ b/src/qt/qt_iconindicators.hpp @@ -0,0 +1,17 @@ +#ifndef QT_ICONINDICATORS_HPP +# define QT_ICONINDICATORS_HPP + +#include +#include + +enum IconIndicator { + None, + Active, + WriteActive, + ReadWriteActive, + Disabled, +}; + +QPixmap getIconWithIndicator(const QIcon &icon, const QSize &size, QIcon::Mode iconMode, IconIndicator indicator); + +#endif diff --git a/src/qt/qt_joystickconfiguration.cpp b/src/qt/qt_joystickconfiguration.cpp index 8489dfd22..62a9302d1 100644 --- a/src/qt/qt_joystickconfiguration.cpp +++ b/src/qt/qt_joystickconfiguration.cpp @@ -41,7 +41,7 @@ JoystickConfiguration::JoystickConfiguration(int type, int joystick_nr, QWidget Models::AddEntry(model, plat_joystick_state[c].name, c + 1); } - ui->comboBoxDevice->setCurrentIndex(joystick_state[joystick_nr].plat_joystick_nr); + ui->comboBoxDevice->setCurrentIndex(joystick_state[0][joystick_nr].plat_joystick_nr); layout()->setSizeConstraint(QLayout::SetFixedSize); } @@ -119,7 +119,7 @@ JoystickConfiguration::on_comboBoxDevice_currentIndexChanged(int index) } int nr_axes = plat_joystick_state[joystick].nr_axes; - int mapping = joystick_state[joystick_nr].axis_mapping[c]; + int mapping = joystick_state[0][joystick_nr].axis_mapping[c]; if (mapping & POV_X) cbox->setCurrentIndex(nr_axes + (mapping & 3) * 2); else if (mapping & POV_Y) @@ -147,7 +147,7 @@ JoystickConfiguration::on_comboBoxDevice_currentIndexChanged(int index) Models::AddEntry(model, plat_joystick_state[joystick].button[d].name, 0); } - cbox->setCurrentIndex(joystick_state[joystick_nr].button_mapping[c]); + cbox->setCurrentIndex(joystick_state[0][joystick_nr].button_mapping[c]); ui->ct->addWidget(label, row, 0); ui->ct->addWidget(cbox, row, 1); @@ -179,7 +179,7 @@ JoystickConfiguration::on_comboBoxDevice_currentIndexChanged(int index) Models::AddEntry(model, plat_joystick_state[joystick].axis[d].name, 0); } - int mapping = joystick_state[joystick_nr].pov_mapping[c / 2][c & 1]; + int mapping = joystick_state[0][joystick_nr].pov_mapping[c / 2][c & 1]; int nr_povs = plat_joystick_state[joystick].nr_povs; if (mapping & POV_X) cbox->setCurrentIndex((mapping & 3) * 2); diff --git a/src/qt/qt_keybind.cpp b/src/qt/qt_keybind.cpp new file mode 100644 index 000000000..e6e87a5e2 --- /dev/null +++ b/src/qt/qt_keybind.cpp @@ -0,0 +1,102 @@ +/* + * 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. + * + * Keybind dialog + * + * + * + * Authors: Cathode Ray Dude + * Cacodemon345 + * + * Copyright 2025 Cathode Ray Dude + * Copyright 2025 Cacodemon345 + */ +#include "qt_keybind.hpp" +#include "ui_qt_keybind.h" +#include "qt_settings.hpp" +#include "qt_singlekeyseqedit.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include <86box/86box.h> +#include <86box/ini.h> +#include <86box/config.h> +#include <86box/device.h> +#include <86box/midi_rtmidi.h> +#include <86box/mem.h> +#include <86box/random.h> +#include <86box/rom.h> +} + +#include "qt_filefield.hpp" +#include "qt_models_common.hpp" +#ifdef Q_OS_LINUX +# include +# include +#endif +#ifdef Q_OS_WINDOWS +#include +#endif + +KeyBinder::KeyBinder(QWidget *parent) + : QDialog(parent) + , ui(new Ui::KeyBinder) +{ + ui->setupUi(this); + singleKeySequenceEdit *seq = new singleKeySequenceEdit(); + ui->formLayout->addRow(seq); + seq->setObjectName("keySequence"); + this->setTabOrder(seq, ui->buttonBox); +} + +KeyBinder::~KeyBinder() +{ + delete ui; +} + +void +KeyBinder::showEvent( QShowEvent* event ) { + QWidget::showEvent( event ); + this->findChild()->setFocus(); +} + +bool KeyBinder::eventFilter(QObject *obj, QEvent *event) +{ + return QObject::eventFilter(obj, event); +} + +QKeySequence +KeyBinder::BindKey(QWidget* widget, QString CurValue) +{ + KeyBinder kb(widget); + kb.setWindowTitle(tr("Bind Key")); + kb.setFixedSize(kb.minimumSizeHint()); + kb.findChild()->setKeySequence(QKeySequence::fromString(CurValue, QKeySequence::NativeText)); + kb.setEnabled(true); + + if (kb.exec() == QDialog::Accepted) { + QKeySequenceEdit *seq = kb.findChild(); + return (seq->keySequence()); + } else { + return (false); + } +} \ No newline at end of file diff --git a/src/qt/qt_keybind.hpp b/src/qt/qt_keybind.hpp new file mode 100644 index 000000000..393ee0f5c --- /dev/null +++ b/src/qt/qt_keybind.hpp @@ -0,0 +1,33 @@ +#ifndef QT_KeyBinder_HPP +#define QT_KeyBinder_HPP + +#include + +#include "qt_settings.hpp" + +extern "C" { +struct _device_; +} + +namespace Ui { +class KeyBinder; +} + +class Settings; + +class KeyBinder : public QDialog { + Q_OBJECT + +public: + explicit KeyBinder(QWidget *parent = nullptr); + ~KeyBinder() override; + + static QKeySequence BindKey(QWidget* widget, QString CurValue); + +private: + Ui::KeyBinder *ui; + bool eventFilter(QObject *obj, QEvent *event); + void showEvent( QShowEvent* event ); +}; + +#endif // QT_KeyBinder_HPP diff --git a/src/qt/qt_keybind.ui b/src/qt/qt_keybind.ui new file mode 100644 index 000000000..835e12020 --- /dev/null +++ b/src/qt/qt_keybind.ui @@ -0,0 +1,85 @@ + + + KeyBinder + + + + 0 + 0 + 400 + 103 + + + + Dialog + + + + + + + + Enter key combo: + + + Qt::AlignmentFlag::AlignCenter + + + + + + + + + Qt::Orientation::Horizontal + + + + + + + Qt::Orientation::Horizontal + + + QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok + + + + + + + + + buttonBox + accepted() + KeyBinder + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + KeyBinder + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/qt/qt_machinestatus.cpp b/src/qt/qt_machinestatus.cpp index ebc18e198..db32569f3 100644 --- a/src/qt/qt_machinestatus.cpp +++ b/src/qt/qt_machinestatus.cpp @@ -19,9 +19,6 @@ #include "qt_machinestatus.hpp" extern "C" { -#define EMU_CPU_H // superhack - don't want timer.h to include cpu.h here, and some combo is preventing a compile -extern uint64_t tsc; - #include <86box/hdd.h> #include <86box/timer.h> #include <86box/86box.h> @@ -42,6 +39,9 @@ extern uint64_t tsc; #include <86box/network.h> #include <86box/ui.h> #include <86box/machine_status.h> +#include <86box/config.h> + +extern volatile int fdcinited; }; #include @@ -56,6 +56,7 @@ extern uint64_t tsc; #include "qt_mainwindow.hpp" #include "qt_soundgain.hpp" #include "qt_progsettings.hpp" +#include "qt_iconindicators.hpp" #include @@ -67,19 +68,30 @@ namespace { struct PixmapSetActive { QPixmap normal; QPixmap active; - void load(const QString &basePath); + QPixmap write_active; + QPixmap read_write_active; + void load(const QIcon &icon); +}; +struct PixmapSetDisabled { + QPixmap normal; + QPixmap disabled; + void load(const QIcon &icon); }; struct PixmapSetEmpty { QPixmap normal; QPixmap empty; - void load(const QString &basePath); + void load(const QIcon &icon); }; struct PixmapSetEmptyActive { QPixmap normal; QPixmap active; QPixmap empty; QPixmap empty_active; - void load(QString basePath); + QPixmap write_active; + QPixmap read_write_active; + QPixmap empty_write_active; + QPixmap empty_read_write_active; + void load(const QIcon &icon); }; struct Pixmaps { PixmapSetEmpty cartridge; @@ -92,13 +104,14 @@ struct Pixmaps { PixmapSetEmptyActive mo; PixmapSetActive hd; PixmapSetEmptyActive net; - QPixmap sound; + PixmapSetDisabled sound; }; struct StateActive { std::unique_ptr label; PixmapSetActive *pixmaps = nullptr; bool active = false; + bool write_active = false; void setActive(bool b) { @@ -109,11 +122,23 @@ struct StateActive { refresh(); } + void setWriteActive(bool b) + { + if (!label || b == write_active) + return; + + write_active = b; + refresh(); + } + void refresh() { if (!label) return; - label->setPixmap(active ? pixmaps->active : pixmaps->normal); + if (active && write_active) + label->setPixmap(pixmaps->read_write_active); + else + label->setPixmap(write_active ? pixmaps->write_active : (active ? pixmaps->active : pixmaps->normal)); } }; struct StateEmpty { @@ -139,9 +164,10 @@ struct StateEmpty { }; struct StateEmptyActive { std::unique_ptr label; - PixmapSetEmptyActive *pixmaps = nullptr; - bool empty = false; - bool active = false; + PixmapSetEmptyActive *pixmaps = nullptr; + bool empty = false; + bool active = false; + bool write_active = false; void setActive(bool b) { @@ -151,6 +177,14 @@ struct StateEmptyActive { active = b; refresh(); } + void setWriteActive(bool b) + { + if (!label || b == write_active) + return; + + write_active = b; + refresh(); + } void setEmpty(bool b) { if (!label || b == empty) @@ -164,38 +198,56 @@ struct StateEmptyActive { if (!label) return; if (empty) { - label->setPixmap(active ? pixmaps->empty_active : pixmaps->empty); + if (active && write_active) + label->setPixmap(pixmaps->empty_read_write_active); + else + label->setPixmap(write_active ? pixmaps->empty_write_active : (active ? pixmaps->empty_active : pixmaps->empty)); } else { - label->setPixmap(active ? pixmaps->active : pixmaps->normal); + if (active && write_active) + label->setPixmap(pixmaps->read_write_active); + else + label->setPixmap(write_active ? pixmaps->write_active : (active ? pixmaps->active : pixmaps->normal)); } } }; static QSize pixmap_size(16, 16); -static const QString pixmap_empty = QStringLiteral("_empty"); -static const QString pixmap_active = QStringLiteral("_active"); -static const QString pixmap_empty_active = QStringLiteral("_empty_active"); + void -PixmapSetEmpty::load(const QString &basePath) +PixmapSetEmpty::load(const QIcon &icon) { - normal = ProgSettings::loadIcon(basePath.arg(QStringLiteral(""))).pixmap(pixmap_size); - empty = ProgSettings::loadIcon(basePath.arg(pixmap_empty)).pixmap(pixmap_size); + normal = getIconWithIndicator(icon, pixmap_size, QIcon::Normal, None); + empty = getIconWithIndicator(icon, pixmap_size, QIcon::Disabled, None); } void -PixmapSetActive::load(const QString &basePath) +PixmapSetActive::load(const QIcon &icon) { - normal = ProgSettings::loadIcon(basePath.arg(QStringLiteral(""))).pixmap(pixmap_size); - active = ProgSettings::loadIcon(basePath.arg(pixmap_active)).pixmap(pixmap_size); + normal = getIconWithIndicator(icon, pixmap_size, QIcon::Normal, None); + active = getIconWithIndicator(icon, pixmap_size, QIcon::Normal, Active); + + write_active = getIconWithIndicator(icon, pixmap_size, QIcon::Normal, WriteActive); + read_write_active = getIconWithIndicator(icon, pixmap_size, QIcon::Normal, ReadWriteActive); } void -PixmapSetEmptyActive::load(QString basePath) +PixmapSetDisabled::load(const QIcon &icon) { - normal = ProgSettings::loadIcon(basePath.arg(QStringLiteral(""))).pixmap(pixmap_size); - active = ProgSettings::loadIcon(basePath.arg(pixmap_active)).pixmap(pixmap_size); - empty = ProgSettings::loadIcon(basePath.arg(pixmap_empty)).pixmap(pixmap_size); - empty_active = ProgSettings::loadIcon(basePath.arg(pixmap_empty_active)).pixmap(pixmap_size); + normal = getIconWithIndicator(icon, pixmap_size, QIcon::Normal, None); + disabled = getIconWithIndicator(icon, pixmap_size, QIcon::Disabled, Disabled); +} + +void +PixmapSetEmptyActive::load(const QIcon &icon) +{ + normal = getIconWithIndicator(icon, pixmap_size, QIcon::Normal, None); + active = getIconWithIndicator(icon, pixmap_size, QIcon::Normal, Active); + write_active = getIconWithIndicator(icon, pixmap_size, QIcon::Normal, WriteActive); + read_write_active = getIconWithIndicator(icon, pixmap_size, QIcon::Normal, ReadWriteActive); + empty = getIconWithIndicator(icon, pixmap_size, QIcon::Disabled, None); + empty_active = getIconWithIndicator(icon, pixmap_size, QIcon::Disabled, Active); + empty_write_active = getIconWithIndicator(icon, pixmap_size, QIcon::Disabled, WriteActive); + empty_read_write_active = getIconWithIndicator(icon, pixmap_size, QIcon::Disabled, ReadWriteActive); } } @@ -204,20 +256,23 @@ struct MachineStatus::States { States(QObject *parent) { - pixmaps.cartridge.load("/cartridge%1.ico"); - pixmaps.cassette.load("/cassette%1.ico"); - pixmaps.floppy_disabled.normal = ProgSettings::loadIcon(QStringLiteral("/floppy_disabled.ico")).pixmap(pixmap_size); - pixmaps.floppy_disabled.active = pixmaps.floppy_disabled.normal; - pixmaps.floppy_disabled.empty = pixmaps.floppy_disabled.normal; - pixmaps.floppy_disabled.empty_active = pixmaps.floppy_disabled.normal; - pixmaps.floppy_525.load("/floppy_525%1.ico"); - pixmaps.floppy_35.load("/floppy_35%1.ico"); - pixmaps.cdrom.load("/cdrom%1.ico"); - pixmaps.zip.load("/zip%1.ico"); - pixmaps.mo.load("/mo%1.ico"); - pixmaps.hd.load("/hard_disk%1.ico"); - pixmaps.net.load("/network%1.ico"); - pixmaps.sound = ProgSettings::loadIcon("/sound.ico").pixmap(pixmap_size); + pixmaps.cartridge.load(QIcon(":/settings/qt/icons/cartridge.ico")); + pixmaps.cassette.load(QIcon(":/settings/qt/icons/cassette.ico")); + pixmaps.floppy_disabled.normal = QIcon(":/settings/qt/icons/floppy_disabled.ico").pixmap(pixmap_size); + pixmaps.floppy_disabled.active = pixmaps.floppy_disabled.normal; + pixmaps.floppy_disabled.read_write_active = pixmaps.floppy_disabled.normal; + pixmaps.floppy_disabled.empty = pixmaps.floppy_disabled.normal; + pixmaps.floppy_disabled.empty_active = pixmaps.floppy_disabled.normal; + pixmaps.floppy_disabled.empty_write_active = pixmaps.floppy_disabled.normal; + pixmaps.floppy_disabled.empty_read_write_active = pixmaps.floppy_disabled.normal; + pixmaps.floppy_525.load(QIcon(":/settings/qt/icons/floppy_525.ico")); + pixmaps.floppy_35.load(QIcon(":/settings/qt/icons/floppy_35.ico")); + pixmaps.cdrom.load(QIcon(":/settings/qt/icons/cdrom.ico")); + pixmaps.zip.load(QIcon(":/settings/qt/icons/zip.ico")); + pixmaps.mo.load(QIcon(":/settings/qt/icons/mo.ico")); + pixmaps.hd.load(QIcon(":/settings/qt/icons/hard_disk.ico")); + pixmaps.net.load(QIcon(":/settings/qt/icons/network.ico")); + pixmaps.sound.load(QIcon(":/settings/qt/icons/sound.ico")); cartridge[0].pixmaps = &pixmaps.cartridge; cartridge[1].pixmaps = &pixmaps.cartridge; @@ -259,12 +314,19 @@ MachineStatus::MachineStatus(QObject *parent) , refreshTimer(new QTimer(this)) { d = std::make_unique(this); + soundMenu = nullptr; connect(refreshTimer, &QTimer::timeout, this, &MachineStatus::refreshIcons); refreshTimer->start(75); } MachineStatus::~MachineStatus() = default; +void +MachineStatus::setSoundMenu(QMenu* menu) +{ + soundMenu = menu; +} + bool MachineStatus::hasCassette() { @@ -286,6 +348,9 @@ MachineStatus::hasSCSI() void MachineStatus::iterateFDD(const std::function &cb) { + if (!fdcinited) + return; + for (int i = 0; i < FDD_NUM; ++i) { if (fdd_get_type(i) != 0) { cb(i); @@ -369,12 +434,12 @@ MachineStatus::iterateNIC(const std::function &cb) } static int -hdd_count(int bus) +hdd_count(const int bus_type) { int c = 0; for (uint8_t i = 0; i < HDD_NUM; i++) { - if (hdd[i].bus == bus) { + if (hdd[i].bus_type == bus_type) { c++; } } @@ -414,49 +479,79 @@ MachineStatus::refreshIcons() if (!update_icons) return; - for (size_t i = 0; i < FDD_NUM; ++i) + for (size_t i = 0; i < FDD_NUM; ++i) { d->fdd[i].setActive(machine_status.fdd[i].active); + d->fdd[i].setWriteActive(machine_status.fdd[i].write_active); + } for (size_t i = 0; i < CDROM_NUM; ++i) { d->cdrom[i].setActive(machine_status.cdrom[i].active); - if (machine_status.cdrom[i].active) + d->cdrom[i].setWriteActive(machine_status.cdrom[i].write_active); + if (machine_status.cdrom[i].active) { ui_sb_update_icon(SB_CDROM | i, 0); + } + if (machine_status.cdrom[i].write_active) { + ui_sb_update_icon_write(SB_CDROM | i, 0); + } } for (size_t i = 0; i < ZIP_NUM; i++) { d->zip[i].setActive(machine_status.zip[i].active); + d->zip[i].setWriteActive(machine_status.zip[i].write_active); if (machine_status.zip[i].active) ui_sb_update_icon(SB_ZIP | i, 0); + if (machine_status.zip[i].write_active) + ui_sb_update_icon_write(SB_ZIP | i, 0); } for (size_t i = 0; i < MO_NUM; i++) { d->mo[i].setActive(machine_status.mo[i].active); + d->mo[i].setWriteActive(machine_status.mo[i].write_active); if (machine_status.mo[i].active) ui_sb_update_icon(SB_MO | i, 0); + if (machine_status.mo[i].write_active) + ui_sb_update_icon_write(SB_MO | i, 0); } for (size_t i = 0; i < HDD_BUS_USB; i++) { d->hdds[i].setActive(machine_status.hdd[i].active); + d->hdds[i].setWriteActive(machine_status.hdd[i].write_active); if (machine_status.hdd[i].active) ui_sb_update_icon(SB_HDD | i, 0); + if (machine_status.hdd[i].write_active) + ui_sb_update_icon_write(SB_HDD | i, 0); } - for (size_t i = 0; i < NET_CARD_MAX; i++) + for (size_t i = 0; i < NET_CARD_MAX; i++) { d->net[i].setActive(machine_status.net[i].active); + d->net[i].setWriteActive(machine_status.net[i].write_active); + } } void MachineStatus::clearActivity() { - for (auto &fdd : d->fdd) + for (auto &fdd : d->fdd) { fdd.setActive(false); - for (auto &cdrom : d->cdrom) + fdd.setWriteActive(false); + } + for (auto &cdrom : d->cdrom) { cdrom.setActive(false); - for (auto &zip : d->zip) + cdrom.setWriteActive(false); + } + for (auto &zip : d->zip) { zip.setActive(false); - for (auto &mo : d->mo) + zip.setWriteActive(false); + } + for (auto &mo : d->mo) { mo.setActive(false); - for (auto &hdd : d->hdds) + mo.setWriteActive(false); + } + for (auto &hdd : d->hdds) { hdd.setActive(false); - for (auto &net : d->net) + hdd.setWriteActive(false); + } + for (auto &net : d->net) { net.setActive(false); + net.setWriteActive(false); + } } void @@ -541,6 +636,7 @@ MachineStatus::refresh(QStatusBar *sbar) d->fdd[i].label = std::make_unique(); d->fdd[i].setEmpty(QString(floppyfns[i]).isEmpty()); d->fdd[i].setActive(false); + d->fdd[i].setWriteActive(false); d->fdd[i].refresh(); connect((ClickableLabel *) d->fdd[i].label.get(), &ClickableLabel::clicked, [i](QPoint pos) { MediaMenu::ptr->floppyMenus[i]->popup(pos - QPoint(0, MediaMenu::ptr->floppyMenus[i]->sizeHint().height())); @@ -557,6 +653,7 @@ MachineStatus::refresh(QStatusBar *sbar) d->cdrom[i].label = std::make_unique(); d->cdrom[i].setEmpty(QString(cdrom[i].image_path).isEmpty()); d->cdrom[i].setActive(false); + d->cdrom[i].setWriteActive(false); d->cdrom[i].refresh(); connect((ClickableLabel *) d->cdrom[i].label.get(), &ClickableLabel::clicked, [i](QPoint pos) { MediaMenu::ptr->cdromMenus[i]->popup(pos - QPoint(0, MediaMenu::ptr->cdromMenus[i]->sizeHint().height())); @@ -573,6 +670,7 @@ MachineStatus::refresh(QStatusBar *sbar) d->zip[i].label = std::make_unique(); d->zip[i].setEmpty(QString(zip_drives[i].image_path).isEmpty()); d->zip[i].setActive(false); + d->zip[i].setWriteActive(false); d->zip[i].refresh(); connect((ClickableLabel *) d->zip[i].label.get(), &ClickableLabel::clicked, [i](QPoint pos) { MediaMenu::ptr->zipMenus[i]->popup(pos - QPoint(0, MediaMenu::ptr->zipMenus[i]->sizeHint().height())); @@ -589,6 +687,7 @@ MachineStatus::refresh(QStatusBar *sbar) d->mo[i].label = std::make_unique(); d->mo[i].setEmpty(QString(mo_drives[i].image_path).isEmpty()); d->mo[i].setActive(false); + d->mo[i].setWriteActive(false); d->mo[i].refresh(); connect((ClickableLabel *) d->mo[i].label.get(), &ClickableLabel::clicked, [i](QPoint pos) { MediaMenu::ptr->moMenus[i]->popup(pos - QPoint(0, MediaMenu::ptr->moMenus[i]->sizeHint().height())); @@ -605,6 +704,7 @@ MachineStatus::refresh(QStatusBar *sbar) d->net[i].label = std::make_unique(); d->net[i].setEmpty(!network_is_connected(i)); d->net[i].setActive(false); + d->net[i].setWriteActive(false); d->net[i].refresh(); d->net[i].label->setToolTip(MediaMenu::ptr->netMenus[i]->title()); connect((ClickableLabel *) d->net[i].label.get(), &ClickableLabel::clicked, [i](QPoint pos) { @@ -617,22 +717,49 @@ MachineStatus::refresh(QStatusBar *sbar) if ((has_mfm || (hdc_name.left(5) == QStringLiteral("st506"))) && (c_mfm > 0)) { d->hdds[HDD_BUS_MFM].label = std::make_unique(); d->hdds[HDD_BUS_MFM].setActive(false); + d->hdds[HDD_BUS_MFM].setWriteActive(false); d->hdds[HDD_BUS_MFM].refresh(); d->hdds[HDD_BUS_MFM].label->setToolTip(tr("Hard disk (%1)").arg("MFM/RLL")); + auto tooltip = d->hdds[HDD_BUS_MFM].label->toolTip(); + tooltip.append("\n"); + for (int i = 0; i < HDD_NUM; i++) { + if (hdd[i].bus_type == HDD_BUS_MFM && hdd[i].fn[0] != 0) { + tooltip.append(QString("\n%5:%6: %1 (C:H:S = %2:%3:%4, %7 %8)").arg(QString::fromUtf8(hdd[i].fn), QString::number(hdd[i].tracks), QString::number(hdd[i].hpc), QString::number(hdd[i].spt), QString::number(hdd[i].channel >> 1), QString::number(hdd[i].channel & 1), QString::number((((qulonglong)hdd[i].hpc * (qulonglong)hdd[i].spt * (qulonglong)hdd[i].tracks) * 512ull) / 1048576ull), tr("MB"))); + } + } + d->hdds[HDD_BUS_MFM].label->setToolTip(tooltip); sbar->addWidget(d->hdds[HDD_BUS_MFM].label.get()); } if ((has_esdi || (hdc_name.left(4) == QStringLiteral("esdi"))) && (c_esdi > 0)) { d->hdds[HDD_BUS_ESDI].label = std::make_unique(); d->hdds[HDD_BUS_ESDI].setActive(false); + d->hdds[HDD_BUS_ESDI].setWriteActive(false); d->hdds[HDD_BUS_ESDI].refresh(); d->hdds[HDD_BUS_ESDI].label->setToolTip(tr("Hard disk (%1)").arg("ESDI")); + auto tooltip = d->hdds[HDD_BUS_ESDI].label->toolTip(); + tooltip.append("\n"); + for (int i = 0; i < HDD_NUM; i++) { + if (hdd[i].bus_type == HDD_BUS_ESDI && hdd[i].fn[0] != 0) { + tooltip.append(QString("\n%5:%6: %1 (C:H:S = %2:%3:%4, %7 %8)").arg(QString::fromUtf8(hdd[i].fn), QString::number(hdd[i].tracks), QString::number(hdd[i].hpc), QString::number(hdd[i].spt), QString::number(hdd[i].channel >> 1), QString::number(hdd[i].channel & 1), QString::number((((qulonglong)hdd[i].hpc * (qulonglong)hdd[i].spt * (qulonglong)hdd[i].tracks) * 512ull) / 1048576ull), tr("MB"))); + } + } + d->hdds[HDD_BUS_ESDI].label->setToolTip(tooltip); sbar->addWidget(d->hdds[HDD_BUS_ESDI].label.get()); } if ((has_xta || (hdc_name.left(3) == QStringLiteral("xta"))) && (c_xta > 0)) { d->hdds[HDD_BUS_XTA].label = std::make_unique(); d->hdds[HDD_BUS_XTA].setActive(false); + d->hdds[HDD_BUS_XTA].setWriteActive(false); d->hdds[HDD_BUS_XTA].refresh(); d->hdds[HDD_BUS_XTA].label->setToolTip(tr("Hard disk (%1)").arg("XTA")); + auto tooltip = d->hdds[HDD_BUS_XTA].label->toolTip(); + tooltip.append("\n"); + for (int i = 0; i < HDD_NUM; i++) { + if (hdd[i].bus_type == HDD_BUS_XTA && hdd[i].fn[0] != 0) { + tooltip.append(QString("\n%5:%6: %1 (C:H:S = %2:%3:%4, %7 %8)").arg(QString::fromUtf8(hdd[i].fn), QString::number(hdd[i].tracks), QString::number(hdd[i].hpc), QString::number(hdd[i].spt), QString::number(hdd[i].channel >> 1), QString::number(hdd[i].channel & 1), QString::number((((qulonglong)hdd[i].hpc * (qulonglong)hdd[i].spt * (qulonglong)hdd[i].tracks) * 512ull) / 1048576ull), tr("MB"))); + } + } + d->hdds[HDD_BUS_XTA].label->setToolTip(tooltip); sbar->addWidget(d->hdds[HDD_BUS_XTA].label.get()); } if (hasIDE() || (hdc_name.left(5) == QStringLiteral("xtide")) || @@ -641,15 +768,33 @@ MachineStatus::refresh(QStatusBar *sbar) if (c_ide > 0) { d->hdds[HDD_BUS_IDE].label = std::make_unique(); d->hdds[HDD_BUS_IDE].setActive(false); + d->hdds[HDD_BUS_IDE].setWriteActive(false); d->hdds[HDD_BUS_IDE].refresh(); d->hdds[HDD_BUS_IDE].label->setToolTip(tr("Hard disk (%1)").arg("IDE")); + auto tooltip = d->hdds[HDD_BUS_IDE].label->toolTip(); + tooltip.append("\n"); + for (int i = 0; i < HDD_NUM; i++) { + if (hdd[i].bus_type == HDD_BUS_IDE && hdd[i].fn[0] != 0) { + tooltip.append(QString("\n%5:%6: %1 (C:H:S = %2:%3:%4, %7 %8)").arg(QString::fromUtf8(hdd[i].fn), QString::number(hdd[i].tracks), QString::number(hdd[i].hpc), QString::number(hdd[i].spt), QString::number(hdd[i].channel >> 1), QString::number(hdd[i].channel & 1), QString::number((((qulonglong)hdd[i].hpc * (qulonglong)hdd[i].spt * (qulonglong)hdd[i].tracks) * 512ull) / 1048576ull), tr("MB"))); + } + } + d->hdds[HDD_BUS_IDE].label->setToolTip(tooltip); sbar->addWidget(d->hdds[HDD_BUS_IDE].label.get()); } if (c_atapi > 0) { d->hdds[HDD_BUS_ATAPI].label = std::make_unique(); d->hdds[HDD_BUS_ATAPI].setActive(false); + d->hdds[HDD_BUS_ATAPI].setWriteActive(false); d->hdds[HDD_BUS_ATAPI].refresh(); d->hdds[HDD_BUS_ATAPI].label->setToolTip(tr("Hard disk (%1)").arg("ATAPI")); + auto tooltip = d->hdds[HDD_BUS_ATAPI].label->toolTip(); + tooltip.append("\n"); + for (int i = 0; i < HDD_NUM; i++) { + if (hdd[i].bus_type == HDD_BUS_ATAPI && hdd[i].fn[0] != 0) { + tooltip.append(QString("\n%5:%6: %1 (C:H:S = %2:%3:%4, %7 %8)").arg(QString::fromUtf8(hdd[i].fn), QString::number(hdd[i].tracks), QString::number(hdd[i].hpc), QString::number(hdd[i].spt), QString::number(hdd[i].channel >> 1), QString::number(hdd[i].channel & 1), QString::number((((qulonglong)hdd[i].hpc * (qulonglong)hdd[i].spt * (qulonglong)hdd[i].tracks) * 512ull) / 1048576ull), tr("MB"))); + } + } + d->hdds[HDD_BUS_ATAPI].label->setToolTip(tooltip); sbar->addWidget(d->hdds[HDD_BUS_ATAPI].label.get()); } } @@ -659,18 +804,27 @@ MachineStatus::refresh(QStatusBar *sbar) (c_scsi > 0)) { d->hdds[HDD_BUS_SCSI].label = std::make_unique(); d->hdds[HDD_BUS_SCSI].setActive(false); + d->hdds[HDD_BUS_SCSI].setWriteActive(false); d->hdds[HDD_BUS_SCSI].refresh(); d->hdds[HDD_BUS_SCSI].label->setToolTip(tr("Hard disk (%1)").arg("SCSI")); + auto tooltip = d->hdds[HDD_BUS_SCSI].label->toolTip(); + tooltip.append("\n"); + for (int i = 0; i < HDD_NUM; i++) { + if (hdd[i].bus_type == HDD_BUS_SCSI && hdd[i].fn[0] != 0) { + tooltip.append(QString("\n%5:%6: %1 (C:H:S = %2:%3:%4, %7 %8)").arg(QString::fromUtf8(hdd[i].fn), QString::number(hdd[i].tracks), QString::number(hdd[i].hpc), QString::number(hdd[i].spt), QString::number(hdd[i].channel >> 4), QString::asprintf("%02d", hdd[i].channel & 15), QString::number((((qulonglong)hdd[i].hpc * (qulonglong)hdd[i].spt * (qulonglong)hdd[i].tracks) * 512ull) / 1048576ull), tr("MB"))); + } + } + d->hdds[HDD_BUS_SCSI].label->setToolTip(tooltip); sbar->addWidget(d->hdds[HDD_BUS_SCSI].label.get()); } d->sound = std::make_unique(); - d->sound->setPixmap(d->pixmaps.sound); + d->sound->setPixmap(sound_muted ? d->pixmaps.sound.disabled : d->pixmaps.sound.normal); - connect(d->sound.get(), &ClickableLabel::doubleClicked, d->sound.get(), [](QPoint pos) { - SoundGain gain(main_window); - gain.exec(); + connect(d->sound.get(), &ClickableLabel::clicked, this, [this](QPoint pos) { + this->soundMenu->popup(pos - QPoint(0, this->soundMenu->sizeHint().height())); }); + d->sound->setToolTip(tr("Sound")); sbar->addWidget(d->sound.get()); d->text = std::make_unique(); @@ -681,6 +835,13 @@ MachineStatus::refresh(QStatusBar *sbar) refreshEmptyIcons(); } +void +MachineStatus::updateSoundIcon() +{ + if (d->sound) + d->sound->setPixmap(sound_muted ? d->pixmaps.sound.disabled : d->pixmaps.sound.normal); +} + void MachineStatus::message(const QString &msg) { diff --git a/src/qt/qt_machinestatus.hpp b/src/qt/qt_machinestatus.hpp index fc0e33e91..ad6425b5a 100644 --- a/src/qt/qt_machinestatus.hpp +++ b/src/qt/qt_machinestatus.hpp @@ -1,6 +1,8 @@ #ifndef QT_MACHINESTATUS_HPP #define QT_MACHINESTATUS_HPP +#include +#include #include #include #include @@ -71,17 +73,20 @@ public: QString getMessage(); void clearActivity(); + void setSoundMenu(QMenu* menu); public slots: void refresh(QStatusBar *sbar); void message(const QString &msg); void updateTip(int tag); void refreshEmptyIcons(); void refreshIcons(); + void updateSoundIcon(); private: struct States; std::unique_ptr d; QTimer *refreshTimer; + QMenu *soundMenu; }; #endif // QT_MACHINESTATUS_HPP diff --git a/src/qt/qt_main.cpp b/src/qt/qt_main.cpp index f77370574..cffae1597 100644 --- a/src/qt/qt_main.cpp +++ b/src/qt/qt_main.cpp @@ -31,6 +31,8 @@ #include #include #include +#include +#include #ifdef QT_STATIC /* Static builds need plugin imports */ @@ -42,15 +44,6 @@ Q_IMPORT_PLUGIN(QWindowsVistaStylePlugin) # endif #endif -#ifdef Q_OS_WINDOWS -# include "qt_rendererstack.hpp" -# include "qt_winrawinputfilter.hpp" -# include "qt_winmanagerfilter.hpp" -# include <86box/win.h> -# include -# include -#endif - extern "C" { #include <86box/86box.h> #include <86box/config.h> @@ -64,6 +57,15 @@ extern "C" { #include <86box/version.h> } +#ifdef Q_OS_WINDOWS +# include "qt_rendererstack.hpp" +# include "qt_winrawinputfilter.hpp" +# include "qt_winmanagerfilter.hpp" +# include <86box/win.h> +# include +# include +#endif + #include #include #include @@ -75,6 +77,8 @@ extern "C" { #include "qt_styleoverride.hpp" #include "qt_unixmanagerfilter.hpp" #include "qt_util.hpp" +#include "qt_vmmanager_clientsocket.hpp" +#include "qt_vmmanager_mainwindow.hpp" // Void Cast #define VC(x) const_cast(x) @@ -84,11 +88,16 @@ extern MainWindow *main_window; extern "C" { #include <86box/keyboard.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/nvr.h> extern int qt_nvr_save(void); + +bool cpu_thread_running = false; } +#include + void qt_set_sequence_auto_mnemonic(bool b); #ifdef Q_OS_WINDOWS @@ -187,8 +196,6 @@ win_keyboard_handle(uint32_t scancode, int up, int e0, int e1) it's not an invalid scan code. */ if (scancode != 0xFFFF) keyboard_input(!up, scancode); - - main_window->checkFullscreenHotkey(); } } @@ -209,8 +216,144 @@ emu_LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) (GetForegroundWindow() == ((HWND) secondaryRenderer->winId()))); } - if ((nCode < 0) || (nCode != HC_ACTION) || !is_over_window) + bool skip = ((nCode < 0) || (nCode != HC_ACTION) || !is_over_window || (kbd_req_capture && !mouse_capture)); + + if (skip) return CallNextHookEx(NULL, nCode, wParam, lParam); + + /* USB keyboards send a scancode of 0x00 for multimedia keys. */ + if (lpKdhs->scanCode == 0x00) { + /* Handle USB keyboard multimedia keys where possible. + Only a handful of keys can be handled via Virtual Key + detection; rest can't be reliably detected. */ + DWORD vkCode = lpKdhs->vkCode; + bool up = !!(lpKdhs->flags & LLKHF_UP); + + if (inhibit_multimedia_keys + && (lpKdhs->vkCode == VK_MEDIA_PLAY_PAUSE + || lpKdhs->vkCode == VK_MEDIA_NEXT_TRACK + || lpKdhs->vkCode == VK_MEDIA_PREV_TRACK + || lpKdhs->vkCode == VK_VOLUME_DOWN + || lpKdhs->vkCode == VK_VOLUME_UP + || lpKdhs->vkCode == VK_VOLUME_MUTE + || lpKdhs->vkCode == VK_MEDIA_STOP + || lpKdhs->vkCode == VK_LAUNCH_MEDIA_SELECT + || lpKdhs->vkCode == VK_LAUNCH_MAIL + || lpKdhs->vkCode == VK_LAUNCH_APP1 + || lpKdhs->vkCode == VK_LAUNCH_APP2 + || lpKdhs->vkCode == VK_HELP + || lpKdhs->vkCode == VK_BROWSER_BACK + || lpKdhs->vkCode == VK_BROWSER_FORWARD + || lpKdhs->vkCode == VK_BROWSER_FAVORITES + || lpKdhs->vkCode == VK_BROWSER_HOME + || lpKdhs->vkCode == VK_BROWSER_REFRESH + || lpKdhs->vkCode == VK_BROWSER_SEARCH + || lpKdhs->vkCode == VK_BROWSER_STOP)) + ret = TRUE; + else + ret = CallNextHookEx(NULL, nCode, wParam, lParam); + + switch (vkCode) + { + case VK_MEDIA_PLAY_PAUSE: + { + win_keyboard_handle(0x22, up, 1, 0); + break; + } + case VK_MEDIA_STOP: + { + win_keyboard_handle(0x24, up, 1, 0); + break; + } + case VK_VOLUME_UP: + { + win_keyboard_handle(0x30, up, 1, 0); + break; + } + case VK_VOLUME_DOWN: + { + win_keyboard_handle(0x2E, up, 1, 0); + break; + } + case VK_VOLUME_MUTE: + { + win_keyboard_handle(0x20, up, 1, 0); + break; + } + case VK_MEDIA_NEXT_TRACK: + { + win_keyboard_handle(0x19, up, 1, 0); + break; + } + case VK_MEDIA_PREV_TRACK: + { + win_keyboard_handle(0x10, up, 1, 0); + break; + } + case VK_LAUNCH_MEDIA_SELECT: + { + win_keyboard_handle(0x6D, up, 1, 0); + break; + } + case VK_LAUNCH_MAIL: + { + win_keyboard_handle(0x6C, up, 1, 0); + break; + } + case VK_LAUNCH_APP1: + { + win_keyboard_handle(0x6B, up, 1, 0); + break; + } + case VK_LAUNCH_APP2: + { + win_keyboard_handle(0x21, up, 1, 0); + break; + } + case VK_BROWSER_BACK: + { + win_keyboard_handle(0x6A, up, 1, 0); + break; + } + case VK_BROWSER_FORWARD: + { + win_keyboard_handle(0x69, up, 1, 0); + break; + } + case VK_BROWSER_STOP: + { + win_keyboard_handle(0x68, up, 1, 0); + break; + } + case VK_BROWSER_HOME: + { + win_keyboard_handle(0x32, up, 1, 0); + break; + } + case VK_BROWSER_SEARCH: + { + win_keyboard_handle(0x65, up, 1, 0); + break; + } + case VK_BROWSER_REFRESH: + { + win_keyboard_handle(0x67, up, 1, 0); + break; + } + case VK_BROWSER_FAVORITES: + { + win_keyboard_handle(0x66, up, 1, 0); + break; + } + case VK_HELP: + { + win_keyboard_handle(0x3b, up, 1, 0); + break; + } + } + + return ret; + } else if ((lpKdhs->scanCode == 0x01) && (lpKdhs->flags & LLKHF_ALTDOWN) && !(lpKdhs->flags & (LLKHF_UP | LLKHF_EXTENDED))) ret = TRUE; @@ -227,10 +370,29 @@ emu_LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) else if ((lpKdhs->scanCode == 0x3e) && (lpKdhs->flags & LLKHF_ALTDOWN) && !(lpKdhs->flags & (LLKHF_UP | LLKHF_EXTENDED))) ret = TRUE; - else if ((lpKdhs->scanCode == 0x49) && bCtrlDown && !(lpKdhs->flags & LLKHF_UP)) - ret = TRUE; else if ((lpKdhs->scanCode >= 0x5b) && (lpKdhs->scanCode <= 0x5d) && (lpKdhs->flags & LLKHF_EXTENDED)) ret = TRUE; + else if (inhibit_multimedia_keys + && (lpKdhs->vkCode == VK_MEDIA_PLAY_PAUSE + || lpKdhs->vkCode == VK_MEDIA_NEXT_TRACK + || lpKdhs->vkCode == VK_MEDIA_PREV_TRACK + || lpKdhs->vkCode == VK_VOLUME_DOWN + || lpKdhs->vkCode == VK_VOLUME_UP + || lpKdhs->vkCode == VK_VOLUME_MUTE + || lpKdhs->vkCode == VK_MEDIA_STOP + || lpKdhs->vkCode == VK_LAUNCH_MEDIA_SELECT + || lpKdhs->vkCode == VK_LAUNCH_MAIL + || lpKdhs->vkCode == VK_LAUNCH_APP1 + || lpKdhs->vkCode == VK_LAUNCH_APP2 + || lpKdhs->vkCode == VK_HELP + || lpKdhs->vkCode == VK_BROWSER_BACK + || lpKdhs->vkCode == VK_BROWSER_FORWARD + || lpKdhs->vkCode == VK_BROWSER_FAVORITES + || lpKdhs->vkCode == VK_BROWSER_HOME + || lpKdhs->vkCode == VK_BROWSER_REFRESH + || lpKdhs->vkCode == VK_BROWSER_SEARCH + || lpKdhs->vkCode == VK_BROWSER_STOP)) + ret = TRUE; else ret = CallNextHookEx(NULL, nCode, wParam, lParam); @@ -241,7 +403,7 @@ emu_LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) } else if (!(lpKdhs->flags & LLKHF_EXTENDED) && (lpKdhs->vkCode == 0x00000013)) { /* Pause - send E1 1D. */ win_keyboard_handle(0xe1, 0, 0, 0); - win_keyboard_handle(0x1d, LLKHF_UP, 0, 0); + win_keyboard_handle(0x1d, lpKdhs->flags & LLKHF_UP, 0, 0); } } else if (!last && (lpKdhs->scanCode == 0x00000036)) /* Non-fake right shift. */ @@ -252,7 +414,11 @@ emu_LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) else if (last && (lpKdhs->scanCode == 0x00000036)) last = 0; - win_keyboard_handle(lpKdhs->scanCode, lpKdhs->flags & LLKHF_UP, lpKdhs->flags & LLKHF_EXTENDED, 0); + if ((lpKdhs->scanCode == 0xf1) || (lpKdhs->scanCode == 0xf2)) + /* Hanja and Han/Eng keys, suppress the extended flag. */ + win_keyboard_handle(lpKdhs->scanCode, lpKdhs->flags & LLKHF_UP, 0, 0); + else + win_keyboard_handle(lpKdhs->scanCode, lpKdhs->flags & LLKHF_UP, lpKdhs->flags & LLKHF_EXTENDED, 0); return ret; } @@ -273,6 +439,7 @@ main_thread_fn() // title_update = 1; uint64_t old_time = elapsed_timer.elapsed(); int drawits = frames = 0; + is_cpu_thread = 1; while (!is_quit && cpu_thread_run) { /* See if it is time to run a frame of code. */ const uint64_t new_time = elapsed_timer.elapsed(); @@ -327,6 +494,7 @@ main_thread_fn() } } + cpu_thread_running = false; is_quit = 1; for (uint8_t i = 1; i < GFXCARD_MAX; i ++) { if (gfxcard[i]) { @@ -339,6 +507,10 @@ main_thread_fn() static std::thread *main_thread; +#ifdef Q_OS_WINDOWS +extern bool windows_is_light_theme(); +#endif + int main(int argc, char *argv[]) { @@ -353,6 +525,24 @@ main(int argc, char *argv[]) QApplication app(argc, argv); QLocale::setDefault(QLocale::C); + setlocale(LC_NUMERIC, "C"); + +#ifdef Q_OS_WINDOWS + Q_INIT_RESOURCE(darkstyle); + QApplication::setAttribute(Qt::AA_NativeWindows); + + if (!windows_is_light_theme()) { + QFile f(":qdarkstyle/dark/darkstyle.qss"); + + if (!f.exists()) { + printf("Unable to set stylesheet, file not found\n"); + } else { + f.open(QFile::ReadOnly | QFile::Text); + QTextStream ts(&f); + qApp->setStyleSheet(ts.readAll()); + } + } +#endif qt_set_sequence_auto_mnemonic(false); Q_INIT_RESOURCE(qt_resources); @@ -474,6 +664,19 @@ main(int argc, char *argv[]) return 0; } + if (vmm_enabled) { + // VMManagerMain vmm; + // // Hackish until there is a proper solution + // QApplication::setApplicationName("86Box VM Manager"); + // QApplication::setApplicationDisplayName("86Box VM Manager"); + // vmm.show(); + // vmm.exec(); + const auto vmm_main_window = new VMManagerMainWindow(); + vmm_main_window->show(); + QApplication::exec(); + return 0; + } + #ifdef DISCORD discord_load(); #endif @@ -484,6 +687,16 @@ main(int argc, char *argv[]) } else { main_window->show(); } +#ifdef WAYLAND + if (QApplication::platformName().contains("wayland")) { + /* Force a sync. */ + (void)main_window->winId(); + QApplication::sync(); + extern void wl_keyboard_grab(QWindow *window); + wl_keyboard_grab(main_window->windowHandle()); + } +#endif + app.installEventFilter(main_window); @@ -524,7 +737,7 @@ main(int argc, char *argv[]) /* Force raw input if a debugger is present. */ if (IsDebuggerPresent()) { - pclog("WARNING: Debugged detected, forcing raw input\n"); + pclog("WARNING: Debugger detected, forcing raw input\n"); hook_enabled = 0; } @@ -560,6 +773,36 @@ main(int argc, char *argv[]) socket.connectToServer(qgetenv("86BOX_MANAGER_SOCKET")); } + VMManagerClientSocket manager_socket; + if (qgetenv("VMM_86BOX_SOCKET").size()) { + manager_socket.IPCConnect(qgetenv("VMM_86BOX_SOCKET")); + QObject::connect(&manager_socket, &VMManagerClientSocket::pause, main_window, &MainWindow::togglePause); + QObject::connect(&manager_socket, &VMManagerClientSocket::resetVM, main_window, &MainWindow::hardReset); + QObject::connect(&manager_socket, &VMManagerClientSocket::showsettings, main_window, &MainWindow::showSettings); + QObject::connect(&manager_socket, &VMManagerClientSocket::ctrlaltdel, []() { pc_send_cad(); }); + QObject::connect(&manager_socket, &VMManagerClientSocket::request_shutdown, main_window, &MainWindow::close); + QObject::connect(&manager_socket, &VMManagerClientSocket::force_shutdown, []() { + do_stop(); + emit main_window->close(); + }); + QObject::connect(main_window, &MainWindow::vmmRunningStateChanged, &manager_socket, &VMManagerClientSocket::clientRunningStateChanged); + main_window->installEventFilter(&manager_socket); + } + + /* Warn the user about unsupported configs */ + if (cpu_override) { + QMessageBox warningbox(QMessageBox::Icon::Warning, QObject::tr("You are loading an unsupported configuration"), + QObject::tr("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."), + QMessageBox::NoButton, main_window); + warningbox.addButton(QObject::tr("Continue"), QMessageBox::AcceptRole); + warningbox.addButton(QObject::tr("Exit"), QMessageBox::RejectRole); + warningbox.exec(); + if (warningbox.result() == QDialog::Accepted) { + confirm_exit_cmdl = 0; /* skip the confirmation prompt without touching the config */ + emit main_window->close(); + } + } + // pc_reset_hard_init(); QTimer onesec; @@ -598,6 +841,7 @@ main(int argc, char *argv[]) #endif plat_pause(0); + cpu_thread_running = true; main_thread = new std::thread(main_thread_fn); }); diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index 3ee58f23b..5c9e10a85 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -48,11 +48,10 @@ extern "C" { #include <86box/machine.h> #include <86box/vid_ega.h> #include <86box/version.h> -#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; +#include <86box/timer.h> +#include <86box/apm.h> +#include <86box/nvr.h> +#include <86box/acpi.h> #ifdef USE_VNC # include <86box/vnc.h> @@ -63,6 +62,8 @@ extern int qt_nvr_save(void); #ifdef MTR_ENABLED # include #endif + +extern bool cpu_thread_running; }; #include @@ -138,6 +139,7 @@ namespace IOKit { # include "be_keyboard.hpp" extern MainWindow *main_window; +QShortcut *windowedShortcut; filter_result keyb_filter(BMessage *message, BHandler **target, BMessageFilter *filter) @@ -179,8 +181,65 @@ MainWindow::MainWindow(QWidget *parent) extern MainWindow *main_window; main_window = this; ui->setupUi(this); + status->setSoundMenu(ui->menuSound); + ui->actionMute_Unmute->setText(sound_muted ? tr("&Unmute") : tr("&Mute")); + ui->menuEGA_S_VGA_settings->menuAction()->setMenuRole(QAction::NoRole); ui->stackedWidget->setMouseTracking(true); statusBar()->setVisible(!hide_status_bar); + + num_icon = QIcon(":/settings/qt/icons/num_lock_on.ico"); + num_icon_off = QIcon(":/settings/qt/icons/num_lock_off.ico"); + scroll_icon = QIcon(":/settings/qt/icons/scroll_lock_on.ico"); + scroll_icon_off = QIcon(":/settings/qt/icons/scroll_lock_off.ico"); + caps_icon = QIcon(":/settings/qt/icons/caps_lock_on.ico"); + caps_icon_off = QIcon(":/settings/qt/icons/caps_lock_off.ico"); + kana_icon = QIcon(":/settings/qt/icons/kana_lock_on.ico"); + kana_icon_off = QIcon(":/settings/qt/icons/kana_lock_off.ico"); + + num_label = new QLabel; + num_label->setPixmap(num_icon_off.pixmap(QSize(16, 16))); + num_label->setToolTip(QShortcut::tr("Num Lock")); + statusBar()->addPermanentWidget(num_label); + + caps_label = new QLabel; + caps_label->setPixmap(caps_icon_off.pixmap(QSize(16, 16))); + caps_label->setToolTip(QShortcut::tr("Caps Lock")); + statusBar()->addPermanentWidget(caps_label); + + scroll_label = new QLabel; + scroll_label->setPixmap(scroll_icon_off.pixmap(QSize(16, 16))); + scroll_label->setToolTip(QShortcut::tr("Scroll Lock")); + statusBar()->addPermanentWidget(scroll_label); + + kana_label = new QLabel; + kana_label->setPixmap(kana_icon_off.pixmap(QSize(16, 16))); + kana_label->setToolTip(QShortcut::tr("Kana Lock")); + statusBar()->addPermanentWidget(kana_label); + + QTimer* ledKeyboardTimer = new QTimer(this); + ledKeyboardTimer->setTimerType(Qt::CoarseTimer); + ledKeyboardTimer->setInterval(1); + connect(ledKeyboardTimer, &QTimer::timeout, this, [this] () { + uint8_t caps, num, scroll, kana; + keyboard_get_states(&caps, &num, &scroll, &kana); + + if (num_label->isVisible()) + num_label->setPixmap(num ? this->num_icon.pixmap(QSize(16, 16)) : this->num_icon_off.pixmap(QSize(16, 16))); + if (caps_label->isVisible()) + caps_label->setPixmap(caps ? this->caps_icon.pixmap(QSize(16, 16)) : this->caps_icon_off.pixmap(QSize(16, 16))); + if (scroll_label->isVisible()) + scroll_label->setPixmap(scroll ? this->scroll_icon.pixmap(QSize(16, 16)) : + this->scroll_icon_off.pixmap(QSize(16, 16))); + + if (kana_label->isVisible()) + kana_label->setPixmap(kana ? this->kana_icon.pixmap(QSize(16, 16)) : + this->kana_icon_off.pixmap(QSize(16, 16))); + }); + ledKeyboardTimer->start(); + +#ifdef Q_OS_WINDOWS + util::setWin11RoundedCorners(this->winId(), (hide_status_bar ? false : true)); +#endif statusBar()->setStyleSheet("QStatusBar::item {border: None; } QStatusBar QLabel { margin-right: 2px; margin-bottom: 1px; }"); this->centralWidget()->setStyleSheet("background-color: black;"); ui->toolBar->setVisible(!hide_tool_bar); @@ -205,6 +264,12 @@ MainWindow::MainWindow(QWidget *parent) connect(this, &MainWindow::hardResetCompleted, this, [this]() { ui->actionMCA_devices->setVisible(machine_has_bus(machine, MACHINE_BUS_MCA)); + num_label->setVisible(machine_has_bus(machine, MACHINE_BUS_PS2_PORTS | MACHINE_BUS_AT_KBD)); + scroll_label->setVisible(machine_has_bus(machine, MACHINE_BUS_PS2_PORTS | MACHINE_BUS_AT_KBD)); + caps_label->setVisible(machine_has_bus(machine, MACHINE_BUS_PS2_PORTS | MACHINE_BUS_AT_KBD)); + /* TODO: Base this on keyboard type instead when that's done. */ + kana_label->setVisible(machine_has_bus(machine, MACHINE_BUS_PS2_PORTS | MACHINE_BUS_AT_KBD) && + machine_has_flags(machine, MACHINE_AX)); while (QApplication::overrideCursor()) QApplication::restoreOverrideCursor(); #ifdef USE_WACOM @@ -257,13 +322,16 @@ MainWindow::MainWindow(QWidget *parent) mouse_capture = state ? 1 : 0; qt_mouse_capture(mouse_capture); if (mouse_capture) { - this->grabKeyboard(); + if (hook_enabled) + this->grabKeyboard(); if (ui->stackedWidget->mouse_capture_func) ui->stackedWidget->mouse_capture_func(this->windowHandle()); } else { this->releaseKeyboard(); - if (ui->stackedWidget->mouse_uncapture_func) + if (ui->stackedWidget->mouse_uncapture_func) { ui->stackedWidget->mouse_uncapture_func(); + } + ui->stackedWidget->unsetCursor(); } }); @@ -277,6 +345,8 @@ MainWindow::MainWindow(QWidget *parent) if (mouse_capture) emit setMouseCapture(false); + keyboard_all_up(); + if (do_auto_pause && !dopause) { auto_paused = 1; plat_pause(1); @@ -456,7 +526,7 @@ MainWindow::MainWindow(QWidget *parent) }); connect(ui->stackedWidget, &RendererStack::rendererChanged, [this]() { - ui->actionRenderer_options->setVisible(ui->stackedWidget->hasOptions()); + ui->actionRenderer_options->setEnabled(ui->stackedWidget->hasOptions()); }); /* Trigger initial renderer switch */ @@ -686,6 +756,22 @@ MainWindow::MainWindow(QWidget *parent) }); #endif + QTimer::singleShot(0, this, [this]() { + for (auto curObj : this->menuBar()->children()) { + if (qobject_cast(curObj)) { + auto menu = qobject_cast(curObj); + for (auto curObj2 : menu->children()) { + if (qobject_cast(curObj2)) { + auto action = qobject_cast(curObj2); + if (!action->shortcut().isEmpty()) { + this->insertAction(nullptr, action); + } + } + } + } + } + }); + actGroup = new QActionGroup(this); actGroup->addAction(ui->actionCursor_Puck); actGroup->addAction(ui->actionPen); @@ -723,6 +809,8 @@ MainWindow::MainWindow(QWidget *parent) }); } #endif + + updateShortcuts(); } void @@ -772,6 +860,14 @@ MainWindow::closeEvent(QCloseEvent *event) ui->stackedWidget->mouse_exit_func(); ui->stackedWidget->switchRenderer(RendererStack::Renderer::Software); + for (int i = 1; i < MONITORS_NUM; i++) { + if (renderers[i] && renderers[i]->isHidden()) { + renderers[i]->show(); + QApplication::processEvents(); + renderers[i]->switchRenderer(RendererStack::Renderer::Software); + QApplication::processEvents(); + } + } qt_nvr_save(); config_save(); @@ -780,6 +876,81 @@ MainWindow::closeEvent(QCloseEvent *event) event->accept(); } + +void MainWindow::updateShortcuts() +{ + /* + Update menu shortcuts from accelerator table + + Note that these only work in windowed mode. If you add any new shortcuts, + you have to go duplicate them in MainWindow::eventFilter() + */ + + // First we need to wipe all existing accelerators, otherwise Qt will + // run into conflicts with old ones. + ui->actionTake_screenshot->setShortcut(QKeySequence()); + ui->actionCtrl_Alt_Del->setShortcut(QKeySequence()); + ui->actionCtrl_Alt_Esc->setShortcut(QKeySequence()); + ui->actionHard_Reset->setShortcut(QKeySequence()); + ui->actionPause->setShortcut(QKeySequence()); + ui->actionMute_Unmute->setShortcut(QKeySequence()); + + int accID; + QKeySequence seq; + + accID = FindAccelerator("screenshot"); + seq = QKeySequence::fromString(acc_keys[accID].seq); + ui->actionTake_screenshot->setShortcut(seq); + + accID = FindAccelerator("send_ctrl_alt_del"); + seq = QKeySequence::fromString(acc_keys[accID].seq); + ui->actionCtrl_Alt_Del->setShortcut(seq); + + accID = FindAccelerator("send_ctrl_alt_esc"); + seq = QKeySequence::fromString(acc_keys[accID].seq); + ui->actionCtrl_Alt_Esc->setShortcut(seq); + + accID = FindAccelerator("hard_reset"); + seq = QKeySequence::fromString(acc_keys[accID].seq); + ui->actionHard_Reset->setShortcut(seq); + + accID = FindAccelerator("fullscreen"); + seq = QKeySequence::fromString(acc_keys[accID].seq); + ui->actionFullscreen->setShortcut(seq); + + accID = FindAccelerator("pause"); + seq = QKeySequence::fromString(acc_keys[accID].seq); + ui->actionPause->setShortcut(seq); + + accID = FindAccelerator("mute"); + seq = QKeySequence::fromString(acc_keys[accID].seq); + ui->actionMute_Unmute->setShortcut(seq); +} + +void +MainWindow::resizeEvent(QResizeEvent *event) +{ + //qDebug() << pos().x() + event->size().width(); + //qDebug() << pos().y() + event->size().height(); + if (vid_resize == 1 || video_fullscreen) + return; + + int newX = pos().x(); + int newY = pos().y(); + + if (((frameGeometry().x() + event->size().width() + 1) > util::screenOfWidget(this)->availableGeometry().right())) { + //move(util::screenOfWidget(this)->availableGeometry().right() - size().width() - 1, pos().y()); + newX = util::screenOfWidget(this)->availableGeometry().right() - frameGeometry().width() - 1; + if (newX < 1) newX = 1; + } + + if (((frameGeometry().y() + event->size().height() + 1) > util::screenOfWidget(this)->availableGeometry().bottom())) { + newY = util::screenOfWidget(this)->availableGeometry().bottom() - frameGeometry().height() - 1; + if (newY < 1) newY = 1; + } + move(newX, newY); +} + void MainWindow::initRendererMonitorSlot(int monitor_index) { @@ -791,10 +962,18 @@ MainWindow::initRendererMonitorSlot(int monitor_index) }); secondaryRenderer->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); secondaryRenderer->setWindowTitle(QObject::tr("86Box Monitor #") + QString::number(monitor_index + 1)); + secondaryRenderer->setContextMenuPolicy(Qt::PreventContextMenu); + + for (int i = 0; i < this->actions().size(); i++) { + secondaryRenderer->addAction(this->actions()[i]); + } if (vid_resize == 2) secondaryRenderer->setFixedSize(fixed_size_x, fixed_size_y); secondaryRenderer->setWindowIcon(this->windowIcon()); +#ifdef Q_OS_WINDOWS + util::setWin11RoundedCorners(secondaryRenderer->winId(), false); +#endif if (show_second_monitors) { secondaryRenderer->show(); if (window_remember) { @@ -948,6 +1127,7 @@ MainWindow::on_actionSettings_triggered() case QDialog::Accepted: settings.save(); config_changed = 2; + updateShortcuts(); pc_reset_hard(); break; case QDialog::Rejected: @@ -1169,24 +1349,6 @@ MainWindow::on_actionFullscreen_triggered() emit resizeContents(vid_resize == 2 ? fixed_size_x : monitors[0].mon_scrnsz_x, vid_resize == 2 ? fixed_size_y : monitors[0].mon_scrnsz_y); } } else { - if (video_fullscreen_first) { - bool wasCaptured = mouse_capture == 1; - - QMessageBox questionbox(QMessageBox::Icon::Information, tr("Entering fullscreen mode"), tr("Press Ctrl+Alt+PgDn to return to windowed mode."), QMessageBox::Ok, this); - QCheckBox *chkbox = new QCheckBox(tr("Don't show this message again")); - questionbox.setCheckBox(chkbox); - chkbox->setChecked(!video_fullscreen_first); - - QObject::connect(chkbox, &QCheckBox::stateChanged, [](int state) { - video_fullscreen_first = (state == Qt::CheckState::Unchecked); - }); - questionbox.exec(); - config_save(); - - /* (re-capture mouse after dialog). */ - if (wasCaptured) - emit setMouseCapture(true); - } video_fullscreen = 1; setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); ui->menubar->hide(); @@ -1216,9 +1378,78 @@ MainWindow::getTitle(wchar_t *title) } } + +// Helper to find an accelerator key and return it's sequence +// TODO: Is there a more central place to put this? +QKeySequence +MainWindow::FindAcceleratorSeq(const char *name) +{ + int accID = FindAccelerator(name); + if(accID == -1) + return false; + + return(QKeySequence::fromString(acc_keys[accID].seq)); +} + bool MainWindow::eventFilter(QObject *receiver, QEvent *event) { + // Detect shortcuts when menubar is hidden + // TODO: Could this be simplified by proxying the event and manually + // shoving it into the menubar? + if (event->type() == QEvent::KeyPress) + { + this->keyPressEvent((QKeyEvent *) event); + + // We check for mouse release even if we aren't fullscreen, + // because it's not a menu accelerator. + if (event->type() == QEvent::KeyPress) + { + QKeyEvent *ke = (QKeyEvent *) event; + if ((QKeySequence)(ke->key() | ke->modifiers()) == FindAcceleratorSeq("release_mouse")) + { + plat_mouse_capture(0); + } + } + + if (event->type() == QEvent::KeyPress && video_fullscreen != 0) + { + QKeyEvent *ke = (QKeyEvent *) event; + + if ((QKeySequence)(ke->key() | ke->modifiers()) == FindAcceleratorSeq("screenshot")) + { + ui->actionTake_screenshot->trigger(); + } + if ((QKeySequence)(ke->key() | ke->modifiers()) == FindAcceleratorSeq("fullscreen")) + { + ui->actionFullscreen->trigger(); + } + if ((QKeySequence)(ke->key() | ke->modifiers()) == FindAcceleratorSeq("hard_reset")) + { + ui->actionHard_Reset->trigger(); + } + if ((QKeySequence)(ke->key() | ke->modifiers()) == FindAcceleratorSeq("send_ctrl_alt_del")) + { + ui->actionCtrl_Alt_Del->trigger(); + } + if ((QKeySequence)(ke->key() | ke->modifiers()) == FindAcceleratorSeq("send_ctrl_alt_esc")) + { + ui->actionCtrl_Alt_Esc->trigger(); + } + if ((QKeySequence)(ke->key() | ke->modifiers()) == FindAcceleratorSeq("pause")) + { + ui->actionPause->trigger(); + } + if ((QKeySequence)(ke->key() | ke->modifiers()) == FindAcceleratorSeq("mute")) + { + ui->actionMute_Unmute->trigger(); + } + + return true; + } + } + + if (!dopause) { if (event->type() == QEvent::Shortcut) { auto shortcutEvent = (QShortcutEvent *) event; @@ -1228,8 +1459,8 @@ MainWindow::eventFilter(QObject *receiver, QEvent *event) } } if (event->type() == QEvent::KeyPress) { - event->accept(); - this->keyPressEvent((QKeyEvent *) event); + event->accept(); + return true; } if (event->type() == QEvent::KeyRelease) { @@ -1243,13 +1474,14 @@ MainWindow::eventFilter(QObject *receiver, QEvent *event) static auto curdopause = dopause; if (event->type() == QEvent::WindowBlocked) { curdopause = dopause; - plat_pause(1); + plat_pause(isShowMessage ? 2 : 1); emit setMouseCapture(false); + releaseKeyboard(); } else if (event->type() == QEvent::WindowUnblocked) { plat_pause(curdopause); } } - + return QMainWindow::eventFilter(receiver, event); } @@ -1257,19 +1489,34 @@ void MainWindow::refreshMediaMenu() { mm->refresh(ui->menuMedia); + status->setSoundMenu(ui->menuSound); status->refresh(ui->statusbar); ui->actionMCA_devices->setVisible(machine_has_bus(machine, MACHINE_BUS_MCA)); ui->actionACPI_Shutdown->setEnabled(!!acpi_enabled); + + num_label->setToolTip(QShortcut::tr("Num Lock")); + num_label->setVisible(machine_has_bus(machine, MACHINE_BUS_PS2_PORTS | MACHINE_BUS_AT_KBD)); + scroll_label->setToolTip(QShortcut::tr("Scroll Lock")); + scroll_label->setVisible(machine_has_bus(machine, MACHINE_BUS_PS2_PORTS | MACHINE_BUS_AT_KBD)); + caps_label->setToolTip(QShortcut::tr("Caps Lock")); + caps_label->setVisible(machine_has_bus(machine, MACHINE_BUS_PS2_PORTS | MACHINE_BUS_AT_KBD)); + kana_label->setToolTip(QShortcut::tr("Kana Lock")); + kana_label->setVisible(machine_has_bus(machine, MACHINE_BUS_PS2_PORTS | MACHINE_BUS_AT_KBD) && + machine_has_flags(machine, MACHINE_AX)); } void -MainWindow::showMessage(int flags, const QString &header, const QString &message) +MainWindow::showMessage(int flags, const QString &header, const QString &message, bool richText) { if (QThread::currentThread() == this->thread()) { - showMessage_(flags, header, message); + if (!cpu_thread_running) { + showMessageForNonQtThread(flags, header, message, richText, nullptr); + } + else + showMessage_(flags, header, message, richText); } else { std::atomic_bool done = false; - emit showMessageForNonQtThread(flags, header, message, &done); + emit showMessageForNonQtThread(flags, header, message, richText, &done); while (!done) { QThread::msleep(1); } @@ -1277,22 +1524,25 @@ MainWindow::showMessage(int flags, const QString &header, const QString &message } void -MainWindow::showMessage_(int flags, const QString &header, const QString &message, std::atomic_bool *done) +MainWindow::showMessage_(int flags, const QString &header, const QString &message, bool richText, std::atomic_bool *done) { if (done) { *done = false; } + isShowMessage = true; QMessageBox box(QMessageBox::Warning, header, message, QMessageBox::NoButton, this); if (flags & (MBX_FATAL)) { box.setIcon(QMessageBox::Critical); } else if (!(flags & (MBX_ERROR | MBX_WARNING))) { box.setIcon(QMessageBox::Warning); } - box.setTextFormat(Qt::TextFormat::RichText); + if (richText) + box.setTextFormat(Qt::TextFormat::RichText); box.exec(); if (done) { *done = true; } + isShowMessage = false; if (cpu_thread_run == 0) QApplication::exit(-1); } @@ -1307,19 +1557,7 @@ MainWindow::keyPressEvent(QKeyEvent *event) processKeyboardInput(true, event->nativeScanCode()); #endif } - - checkFullscreenHotkey(); - - if (keyboard_ismsexit()) - plat_mouse_capture(0); - - if ((video_fullscreen > 0) && (keyboard_recv_ui(0x1D) || keyboard_recv_ui(0x11D))) { - if (keyboard_recv_ui(0x57)) - ui->actionTake_screenshot->trigger(); - else if (keyboard_recv_ui(0x58)) - pc_send_cad(); - } - + event->accept(); } @@ -1351,28 +1589,6 @@ MainWindow::keyReleaseEvent(QKeyEvent *event) processKeyboardInput(false, event->nativeScanCode()); #endif } - - checkFullscreenHotkey(); -} - -void -MainWindow::checkFullscreenHotkey() -{ - if (!fs_off_signal && video_fullscreen && keyboard_isfsexit()) { - /* Signal "exit fullscreen mode". */ - fs_off_signal = true; - } else if (fs_off_signal && video_fullscreen && keyboard_isfsexit_up()) { - ui->actionFullscreen->trigger(); - fs_off_signal = false; - } - - if (!fs_on_signal && !video_fullscreen && keyboard_isfsenter()) { - /* Signal "enter fullscreen mode". */ - fs_on_signal = true; - } else if (fs_on_signal && !video_fullscreen && keyboard_isfsenter_up()) { - ui->actionFullscreen->trigger(); - fs_on_signal = false; - } } QSize @@ -1384,13 +1600,13 @@ MainWindow::getRenderWidgetSize() void MainWindow::focusInEvent(QFocusEvent *event) { - this->grabKeyboard(); + //this->grabKeyboard(); } void MainWindow::focusOutEvent(QFocusEvent *event) { - this->releaseKeyboard(); + //this->releaseKeyboard(); } void @@ -1724,7 +1940,7 @@ MainWindow::on_actionAbout_86Box_triggered() versioninfo.append(QString(" [%1, %2]").arg(QSysInfo::buildCpuArchitecture(), tr(DYNAREC_STR))); msgBox.setText(QString("%3%1%2").arg(EMU_VERSION_FULL, versioninfo, tr("86Box v"))); msgBox.setInformativeText(tr("An emulator of old computers\n\nAuthors: Miran Grča (OBattler), RichardG867, Jasmine Iwanek, TC1995, coldbrewed, Teemu Korhonen (Manaatti), Joakim L. Gilje, Adrien Moulin (elyosh), Daniel Balsom (gloriouscow), Cacodemon345, Fred N. van Kempen (waltje), Tiseno100, reenigne, and others.\n\nWith previous core contributions from Sarah Walker, leilei, JohnElliott, greatpsycho, and others.\n\nReleased under the GNU General Public License version 2 or later. See LICENSE for more information.")); - msgBox.setWindowTitle("About 86Box"); + msgBox.setWindowTitle(tr("About 86Box")); const auto closeButton = msgBox.addButton("OK", QMessageBox::ButtonRole::AcceptRole); msgBox.setEscapeButton(closeButton); const auto webSiteButton = msgBox.addButton(EMU_SITE, QMessageBox::ButtonRole::HelpRole); @@ -1829,6 +2045,9 @@ MainWindow::on_actionHide_status_bar_triggered() hide_status_bar ^= 1; ui->actionHide_status_bar->setChecked(hide_status_bar); statusBar()->setVisible(!hide_status_bar); +#ifdef Q_OS_WINDOWS + util::setWin11RoundedCorners(main_window->winId(), (hide_status_bar ? false : true)); +#endif if (vid_resize >= 2) { setFixedSize(fixed_size_x, fixed_size_y + menuBar()->height() + (hide_status_bar ? 0 : statusBar()->height()) + (hide_tool_bar ? 0 : ui->toolBar->height())); } else { @@ -1881,6 +2100,15 @@ MainWindow::on_actionTake_screenshot_triggered() device_force_redraw(); } +void +MainWindow::on_actionMute_Unmute_triggered() +{ + sound_muted ^= 1; + config_save(); + status->updateSoundIcon(); + ui->actionMute_Unmute->setText(sound_muted ? tr("&Unmute") : tr("&Mute")); +} + void MainWindow::on_actionSound_gain_triggered() { @@ -1903,6 +2131,7 @@ MainWindow::updateUiPauseState() QString(tr("Pause execution")); ui->actionPause->setIcon(pause_icon); ui->actionPause->setToolTip(tooltip_text); + emit vmmRunningStateChanged(static_cast(dopause)); } void @@ -1966,15 +2195,40 @@ MainWindow::changeEvent(QEvent *event) } } +void +MainWindow::reloadAllRenderers() +{ + reload_renderers = true; +} + void MainWindow::on_actionRenderer_options_triggered() { if (const auto dlg = ui->stackedWidget->getOptions(this)) { if (dlg->exec() == QDialog::Accepted) { - for (int i = 1; i < MONITORS_NUM; i++) { + if (ui->stackedWidget->reloadRendererOption()) { + ui->stackedWidget->switchRenderer(static_cast(vid_api)); + if (show_second_monitors) { + for (int i = 1; i < MONITORS_NUM; i++) { + if (renderers[i] && renderers[i]->reloadRendererOption() && renderers[i]->hasOptions()) { + ui->stackedWidget->switchRenderer(static_cast(vid_api)); + } + } + } + } else for (int i = 1; i < MONITORS_NUM; i++) { if (renderers[i] && renderers[i]->hasOptions()) renderers[i]->reloadOptions(); } + } else if (reload_renderers && ui->stackedWidget->reloadRendererOption()) { + reload_renderers = false; + ui->stackedWidget->switchRenderer(static_cast(vid_api)); + if (show_second_monitors) { + for (int i = 1; i < MONITORS_NUM; i++) { + if (renderers[i]) { + renderers[i]->switchRenderer(static_cast(vid_api)); + } + } + } } } } diff --git a/src/qt/qt_mainwindow.hpp b/src/qt/qt_mainwindow.hpp index 9db428051..54a04a975 100644 --- a/src/qt/qt_mainwindow.hpp +++ b/src/qt/qt_mainwindow.hpp @@ -5,11 +5,16 @@ #include #include #include +#include +#include +#include #include #include #include +#include "qt_vmmanager_protocol.hpp" + class MediaMenu; class RendererStack; @@ -26,13 +31,16 @@ public: explicit MainWindow(QWidget *parent = nullptr); ~MainWindow(); - void showMessage(int flags, const QString &header, const QString &message); + void showMessage(int flags, const QString &header, const QString &message, bool richText); void getTitle(wchar_t *title); void blitToWidget(int x, int y, int w, int h, int monitor_index); QSize getRenderWidgetSize(); void setSendKeyboardInput(bool enabled); - void checkFullscreenHotkey(); - + void reloadAllRenderers(); + QShortcut *windowedShortcut; + QKeySequence FindAcceleratorSeq(const char *name); + + std::array, 8> renderers; signals: void paint(const QImage &image); @@ -55,8 +63,10 @@ signals: void setFullscreen(bool state); void setMouseCapture(bool state); - void showMessageForNonQtThread(int flags, const QString &header, const QString &message, std::atomic_bool* done); + void showMessageForNonQtThread(int flags, const QString &header, const QString &message, bool richText, std::atomic_bool* done); void getTitleForNonQtThread(wchar_t *title); + + void vmmRunningStateChanged(VMManagerProtocol::RunningState state); public slots: void showSettings(); void hardReset(); @@ -116,13 +126,14 @@ private slots: void on_actionHide_tool_bar_triggered(); void on_actionUpdate_status_bar_icons_triggered(); void on_actionTake_screenshot_triggered(); + void on_actionMute_Unmute_triggered(); void on_actionSound_gain_triggered(); void on_actionPreferences_triggered(); void on_actionEnable_Discord_integration_triggered(bool checked); void on_actionRenderer_options_triggered(); void refreshMediaMenu(); - void showMessage_(int flags, const QString &header, const QString &message, std::atomic_bool* done = nullptr); + void showMessage_(int flags, const QString &header, const QString &message, bool richText, std::atomic_bool* done = nullptr); void getTitle_(wchar_t *title); void on_actionMCA_devices_triggered(); @@ -136,6 +147,7 @@ protected: void showEvent(QShowEvent *event) override; void closeEvent(QCloseEvent *event) override; void changeEvent(QEvent *event) override; + void resizeEvent(QResizeEvent *event) override; private slots: void on_actionPen_triggered(); @@ -157,6 +169,7 @@ private: std::unique_ptr status; std::shared_ptr mm; + void updateShortcuts(); void processKeyboardInput(bool down, uint32_t keycode); #ifdef Q_OS_MACOS uint32_t last_modifiers = 0; @@ -173,10 +186,20 @@ private: bool fs_on_signal = false; bool fs_off_signal = false; + /* Reload the renderers after closing renderer options dialog. */ + bool reload_renderers = false; + friend class SpecifyDimensions; friend class ProgSettings; friend class RendererCommon; friend class RendererStack; // For UI variable access by non-primary renderer windows. + friend class WindowsRawInputFilter; // Needed to reload renderers on style sheet changes. + + QLabel *caps_label, *scroll_label, *num_label, *kana_label; + QIcon caps_icon, scroll_icon, num_icon, kana_icon; + QIcon caps_icon_off, scroll_icon_off, num_icon_off, kana_icon_off; + + bool isShowMessage = false; }; #endif // QT_MAINWINDOW_HPP diff --git a/src/qt/qt_mainwindow.ui b/src/qt/qt_mainwindow.ui index b1dc0ecf1..83a80342b 100644 --- a/src/qt/qt_mainwindow.ui +++ b/src/qt/qt_mainwindow.ui @@ -87,13 +87,21 @@ &Tools + + + S&ound + + + + + - + @@ -353,6 +361,9 @@ Exit + + QAction::QuitRole + @@ -722,6 +733,11 @@ false + + + &Mute + + Sound &gain... @@ -815,6 +831,9 @@ Renderer options... + + QAction::NoRole + diff --git a/src/qt/qt_mediahistorymanager.cpp b/src/qt/qt_mediahistorymanager.cpp index d548c0779..5892c55cd 100644 --- a/src/qt/qt_mediahistorymanager.cpp +++ b/src/qt/qt_mediahistorymanager.cpp @@ -101,15 +101,20 @@ MediaHistoryManager::getImageForSlot(int index, int slot, ui::MediaType type) return image_name; } -// These are hardcoded since we can't include the various -// header files where they are defined (e.g., fdd.h, mo.h). -// However, all in ui::MediaType support 4 except cassette. int MediaHistoryManager::maxDevicesSupported(ui::MediaType type) { switch (type) { default: return 4; + case ui::MediaType::Optical: + return CDROM_NUM; + case ui::MediaType::Floppy: + return FDD_NUM; + case ui::MediaType::Zip: + return ZIP_NUM; + case ui::MediaType::Mo: + return MO_NUM; case ui::MediaType::Cassette: return 1; case ui::MediaType::Cartridge: diff --git a/src/qt/qt_mediamenu.cpp b/src/qt/qt_mediamenu.cpp index 9c4fc51be..11fac2a70 100644 --- a/src/qt/qt_mediamenu.cpp +++ b/src/qt/qt_mediamenu.cpp @@ -93,7 +93,7 @@ MediaMenu::refresh(QMenu *parentMenu) cassetteMenu->addSeparator(); for (int slot = 0; slot < MAX_PREV_IMAGES; slot++) { cassetteImageHistoryPos[slot] = cassetteMenu->children().count(); - cassetteMenu->addAction(QString::asprintf(tr("Image %i").toUtf8().constData(), slot), [this, slot]() { cassetteMenuSelect(slot); })->setCheckable(false); + cassetteMenu->addAction(tr("Image %1").arg(slot), [this, slot]() { cassetteMenuSelect(slot); })->setCheckable(false); } cassetteMenu->addSeparator(); cassetteRecordPos = cassetteMenu->children().count(); @@ -118,7 +118,7 @@ MediaMenu::refresh(QMenu *parentMenu) menu->addSeparator(); for (int slot = 0; slot < MAX_PREV_IMAGES; slot++) { cartridgeImageHistoryPos[slot] = menu->children().count(); - menu->addAction(QString::asprintf(tr("Image %i").toUtf8().constData(), slot), [this, i, slot]() { cartridgeMenuSelect(i, slot); })->setCheckable(false); + menu->addAction(tr("Image %1").arg(slot), [this, i, slot]() { cartridgeMenuSelect(i, slot); })->setCheckable(false); } menu->addSeparator(); cartridgeEjectPos = menu->children().count(); @@ -138,7 +138,7 @@ MediaMenu::refresh(QMenu *parentMenu) menu->addSeparator(); for (int slot = 0; slot < MAX_PREV_IMAGES; slot++) { floppyImageHistoryPos[slot] = menu->children().count(); - menu->addAction(QString::asprintf(tr("Image %i").toUtf8().constData(), slot), [this, i, slot]() { floppyMenuSelect(i, slot); })->setCheckable(false); + menu->addAction(tr("Image %1").arg(slot), [this, i, slot]() { floppyMenuSelect(i, slot); })->setCheckable(false); } menu->addSeparator(); floppyExportPos = menu->children().count(); @@ -154,14 +154,14 @@ MediaMenu::refresh(QMenu *parentMenu) MachineStatus::iterateCDROM([this, parentMenu](int i) { auto *menu = parentMenu->addMenu(""); cdromMutePos = menu->children().count(); - menu->addAction(ProgSettings::loadIcon("/cdrom_mute.ico"), tr("&Mute"), [this, i]() { cdromMute(i); })->setCheckable(true); + menu->addAction(QIcon(":/settings/qt/icons/cdrom_mute.ico"), tr("&Mute"), [this, i]() { cdromMute(i); })->setCheckable(true); menu->addSeparator(); - menu->addAction(ProgSettings::loadIcon("/cdrom_image.ico"), tr("&Image..."), [this, i]() { cdromMount(i, 0, nullptr); })->setCheckable(false); - menu->addAction(ProgSettings::loadIcon("/cdrom_folder.ico"), tr("&Folder..."), [this, i]() { cdromMount(i, 1, nullptr); })->setCheckable(false); + menu->addAction(QIcon(":/settings/qt/icons/cdrom_image.ico"), tr("&Image..."), [this, i]() { cdromMount(i, 0, nullptr); })->setCheckable(false); + menu->addAction(QIcon(":/settings/qt/icons/cdrom_folder.ico"), tr("&Folder..."), [this, i]() { cdromMount(i, 1, nullptr); })->setCheckable(false); menu->addSeparator(); for (int slot = 0; slot < MAX_PREV_IMAGES; slot++) { cdromImageHistoryPos[slot] = menu->children().count(); - menu->addAction(QString::asprintf(tr("Image %i").toUtf8().constData(), slot), [this, i, slot]() { cdromReload(i, slot); })->setCheckable(false); + menu->addAction(tr("Image %1").arg(slot), [this, i, slot]() { cdromReload(i, slot); })->setCheckable(false); } menu->addSeparator(); #ifdef Q_OS_WINDOWS @@ -170,12 +170,11 @@ MediaMenu::refresh(QMenu *parentMenu) for (const auto &letter : driveLetters) { auto drive = QString("%1:\\").arg(letter); if (GetDriveType(drive.toUtf8().constData()) == DRIVE_CDROM) - menu->addAction(ProgSettings::loadIcon("/cdrom_host.ico"), tr("Host CD/DVD Drive (%1:)").arg(letter), [this, i, letter] { cdromMount(i, 2, QString(R"(\\.\%1:)").arg(letter)); })->setCheckable(false); + menu->addAction(QIcon(":/settings/qt/icons/cdrom_host.ico"), tr("Host CD/DVD Drive (%1:)").arg(letter), [this, i, letter] { cdromMount(i, 2, QString(R"(\\.\%1:)").arg(letter)); })->setCheckable(false); } menu->addSeparator(); #endif // Q_OS_WINDOWS - cdromImagePos = menu->children().count(); - cdromDirPos = menu->children().count(); + cdromEjectPos = menu->children().count(); menu->addAction(tr("E&ject"), [this, i]() { cdromEject(i); })->setCheckable(false); cdromMenus[i] = menu; cdromUpdateMenu(i); @@ -191,7 +190,7 @@ MediaMenu::refresh(QMenu *parentMenu) menu->addSeparator(); for (int slot = 0; slot < MAX_PREV_IMAGES; slot++) { zipImageHistoryPos[slot] = menu->children().count(); - menu->addAction(QString::asprintf(tr("Image %i").toUtf8().constData(), slot), [this, i, slot]() { zipReload(i, slot); })->setCheckable(false); + menu->addAction(tr("Image %1").arg(slot), [this, i, slot]() { zipReload(i, slot); })->setCheckable(false); } menu->addSeparator(); zipEjectPos = menu->children().count(); @@ -210,7 +209,7 @@ MediaMenu::refresh(QMenu *parentMenu) menu->addSeparator(); for (int slot = 0; slot < MAX_PREV_IMAGES; slot++) { moImageHistoryPos[slot] = menu->children().count(); - menu->addAction(QString::asprintf(tr("Image %i").toUtf8().constData(), slot), [this, i, slot]() { moReload(i, slot); })->setCheckable(false); + menu->addAction(tr("Image %1").arg(slot), [this, i, slot]() { moReload(i, slot); })->setCheckable(false); } menu->addSeparator(); moEjectPos = menu->children().count(); @@ -263,7 +262,7 @@ void MediaMenu::cassetteMenuSelect(int slot) { QString filename = mhm.getImageForSlot(0, slot, ui::MediaType::Cassette); - cassetteMount(filename.toUtf8().constData(), 0); + cassetteMount(filename, 0); cassetteUpdateMenu(); ui_sb_update_tip(SB_CASSETTE); } @@ -304,7 +303,8 @@ MediaMenu::cassetteEject() void MediaMenu::cassetteUpdateMenu() { - QString name = cassette_fname; + QString name = cassette_fname; + QFileInfo fi(cassette_fname); const QString mode = cassette_mode; auto childs = cassetteMenu->children(); auto *recordMenu = dynamic_cast(childs[cassetteRecordPos]); @@ -318,13 +318,13 @@ MediaMenu::cassetteUpdateMenu() rewindMenu->setEnabled(!name.isEmpty()); fastFwdMenu->setEnabled(!name.isEmpty()); ejectMenu->setEnabled(!name.isEmpty()); + ejectMenu->setText(name.isEmpty() ? tr("E&ject") : tr("E&ject %1").arg(fi.fileName())); const bool isSaving = (mode == QStringLiteral("save")); recordMenu->setChecked(isSaving); playMenu->setChecked(!isSaving); - cassetteMenu->setTitle(QString::asprintf(tr("Cassette: %s").toUtf8().constData(), - (name.isEmpty() ? tr("(empty)") : name).toUtf8().constData())); + cassetteMenu->setTitle(tr("Cassette: %1").arg(name.isEmpty() ? tr("(empty)") : name)); for (int slot = 0; slot < MAX_PREV_IMAGES; slot++) { updateImageHistory(0, slot, ui::MediaType::Cassette); @@ -365,7 +365,7 @@ void MediaMenu::cartridgeMenuSelect(int index, int slot) { QString filename = mhm.getImageForSlot(index, slot, ui::MediaType::Cartridge); - cartridgeMount(index, filename.toUtf8().constData()); + cartridgeMount(index, filename); cartridgeUpdateMenu(index); ui_sb_update_tip(SB_CARTRIDGE | index); } @@ -385,12 +385,13 @@ void MediaMenu::cartridgeUpdateMenu(int i) { const QString name = cart_fns[i]; - auto *menu = cartridgeMenus[i]; + QFileInfo fi(cart_fns[i]); + auto *menu = cartridgeMenus[i]; auto childs = menu->children(); auto *ejectMenu = dynamic_cast(childs[cartridgeEjectPos]); ejectMenu->setEnabled(!name.isEmpty()); - // menu->setTitle(tr("Cartridge %1: %2").arg(QString::number(i+1), name.isEmpty() ? tr("(empty)") : name)); - menu->setTitle(QString::asprintf(tr("Cartridge %i: %ls").toUtf8().constData(), i + 1, name.isEmpty() ? tr("(empty)").toStdU16String().data() : name.toStdU16String().data())); + ejectMenu->setText(name.isEmpty() ? tr("E&ject") : tr("E&ject %1").arg(fi.fileName())); + menu->setTitle(tr("Cartridge %1: %2").arg(QString::number(i + 1), name.isEmpty() ? tr("(empty)") : name)); for (int slot = 0; slot < MAX_PREV_IMAGES; slot++) { updateImageHistory(i, slot, ui::MediaType::Cartridge); @@ -491,7 +492,7 @@ MediaMenu::floppyUpdateMenu(int i) auto *ejectMenu = dynamic_cast(childs[floppyEjectPos]); auto *exportMenu = dynamic_cast(childs[floppyExportPos]); ejectMenu->setEnabled(!name.isEmpty()); - ejectMenu->setText(QString::asprintf(tr("Eject %s").toUtf8().constData(), name.isEmpty() ? QString().toUtf8().constData() : fi.fileName().toUtf8().constData())); + ejectMenu->setText(name.isEmpty() ? tr("E&ject") : tr("E&ject %1").arg(fi.fileName())); exportMenu->setEnabled(!name.isEmpty()); for (int slot = 0; slot < MAX_PREV_IMAGES; slot++) { @@ -499,15 +500,15 @@ MediaMenu::floppyUpdateMenu(int i) } int type = fdd_get_type(i); - // floppyMenus[i]->setTitle(tr("Floppy %1 (%2): %3").arg(QString::number(i+1), fdd_getname(type), name.isEmpty() ? tr("(empty)") : name)); - floppyMenus[i]->setTitle(QString::asprintf(tr("Floppy %i (%s): %ls").toUtf8().constData(), i + 1, fdd_getname(type), name.isEmpty() ? tr("(empty)").toStdU16String().data() : name.toStdU16String().data())); + floppyMenus[i]->setTitle(tr("Floppy %1 (%2): %3").arg(QString::number(i + 1), fdd_getname(type), name.isEmpty() ? tr("(empty)") : name)); + } void MediaMenu::floppyMenuSelect(int index, int slot) { QString filename = mhm.getImageForSlot(index, slot, ui::MediaType::Floppy); - floppyMount(index, filename.toUtf8().constData(), false); + floppyMount(index, filename, false); floppyUpdateMenu(index); ui_sb_update_tip(SB_FLOPPY | index); } @@ -537,10 +538,7 @@ MediaMenu::cdromMount(int i, const QString &filename) if ((fn.data() != NULL) && (strlen(fn.data()) >= 1) && (fn.data()[strlen(fn.data()) - 1] == '\\')) fn.data()[strlen(fn.data()) - 1] = '/'; #endif - if ((fn.data() != nullptr) && fn.contains("ioctl://")) - cdrom_ioctl_open(&(cdrom[i]), fn.data()); - else - cdrom_image_open(&(cdrom[i]), fn.data()); + cdrom_load(&(cdrom[i]), fn.data(), 1); /* Signal media change to the emulated machine. */ if (cdrom[i].insert) { @@ -597,7 +595,7 @@ void MediaMenu::cdromReload(int index, int slot) { const QString filename = mhm.getImageForSlot(index, slot, ui::MediaType::Optical); - cdromMount(index, filename.toUtf8().constData()); + cdromMount(index, filename); cdromUpdateMenu(index); ui_sb_update_tip(SB_CDROM | index); } @@ -633,7 +631,7 @@ MediaMenu::updateImageHistory(int index, int slot, ui::MediaType type) switch (type) { default: - menu_item_name = fi.fileName().isEmpty() ? tr("previous image").toUtf8().constData() : fi.fileName().toUtf8().constData(); + menu_item_name = fi.fileName().isEmpty() ? tr("Reload previous image") : fn; return; case ui::MediaType::Cassette: if (!MachineStatus::hasCassette()) @@ -642,7 +640,7 @@ MediaMenu::updateImageHistory(int index, int slot, ui::MediaType type) children = menu->children(); imageHistoryUpdatePos = dynamic_cast(children[cassetteImageHistoryPos[slot]]); fi.setFile(fn); - menu_item_name = fi.fileName().isEmpty() ? tr("previous image").toUtf8().constData() : fi.fileName().toUtf8().constData(); + menu_item_name = fi.fileName().isEmpty() ? tr("Reload previous image") : fn; break; case ui::MediaType::Cartridge: if (!machine_has_cartridge(machine)) @@ -651,7 +649,7 @@ MediaMenu::updateImageHistory(int index, int slot, ui::MediaType type) children = menu->children(); imageHistoryUpdatePos = dynamic_cast(children[cartridgeImageHistoryPos[slot]]); fi.setFile(fn); - menu_item_name = fi.fileName().isEmpty() ? tr("previous image").toUtf8().constData() : fi.fileName().toUtf8().constData(); + menu_item_name = fi.fileName().isEmpty() ? tr("Reload previous image") : fn; break; case ui::MediaType::Floppy: if (!floppyMenus.contains(index)) @@ -660,7 +658,7 @@ MediaMenu::updateImageHistory(int index, int slot, ui::MediaType type) children = menu->children(); imageHistoryUpdatePos = dynamic_cast(children[floppyImageHistoryPos[slot]]); fi.setFile(fn); - menu_item_name = fi.fileName().isEmpty() ? tr("previous image").toUtf8().constData() : fi.fileName().toUtf8().constData(); + menu_item_name = fi.fileName().isEmpty() ? tr("Reload previous image") : fn; break; case ui::MediaType::Optical: if (!cdromMenus.contains(index)) @@ -669,16 +667,16 @@ MediaMenu::updateImageHistory(int index, int slot, ui::MediaType type) children = menu->children(); imageHistoryUpdatePos = dynamic_cast(children[cdromImageHistoryPos[slot]]); if (fn.left(8) == "ioctl://") { - menu_icon = ProgSettings::loadIcon("/cdrom_host.ico"); + menu_icon = QIcon(":/settings/qt/icons/cdrom_host.ico"); #ifdef Q_OS_WINDOWS - menu_item_name = tr("Host CD/DVD Drive (%1)").arg(fn.right(2)).toUtf8().constData(); + menu_item_name = tr("Host CD/DVD Drive (%1)").arg(fn.right(2)); #else menu_item_name = tr("Host CD/DVD Drive (%1)").arg(fn.right(fn.length() - 8)); #endif } else { fi.setFile(fn); - menu_icon = fi.isDir() ? ProgSettings::loadIcon("/cdrom_folder.ico") : ProgSettings::loadIcon("/cdrom_image.ico"); - menu_item_name = fn.isEmpty() ? tr("previous image").toUtf8().constData() : fn.toUtf8().constData(); + menu_icon = fi.isDir() ? QIcon(":/settings/qt/icons/cdrom_folder.ico") : QIcon(":/settings/qt/icons/cdrom_image.ico"); + menu_item_name = fn.isEmpty() ? tr("Reload previous image") : fn; } imageHistoryUpdatePos->setIcon(menu_icon); break; @@ -689,7 +687,7 @@ MediaMenu::updateImageHistory(int index, int slot, ui::MediaType type) children = menu->children(); imageHistoryUpdatePos = dynamic_cast(children[zipImageHistoryPos[slot]]); fi.setFile(fn); - menu_item_name = fi.fileName().isEmpty() ? tr("previous image").toUtf8().constData() : fi.fileName().toUtf8().constData(); + menu_item_name = fi.fileName().isEmpty() ? tr("Reload previous image") : fn; break; case ui::MediaType::Mo: if (!moMenus.contains(index)) @@ -698,11 +696,11 @@ MediaMenu::updateImageHistory(int index, int slot, ui::MediaType type) children = menu->children(); imageHistoryUpdatePos = dynamic_cast(children[moImageHistoryPos[slot]]); fi.setFile(fn); - menu_item_name = fi.fileName().isEmpty() ? tr("previous image").toUtf8().constData() : fi.fileName().toUtf8().constData(); + menu_item_name = fi.fileName().isEmpty() ? tr("Reload previous image") : fn; break; } - imageHistoryUpdatePos->setText(QString::asprintf(tr("%s").toUtf8().constData(), menu_item_name.toUtf8().constData())); + imageHistoryUpdatePos->setText(menu_item_name); if (fn.left(8) == "ioctl://") imageHistoryUpdatePos->setVisible(true); @@ -730,29 +728,29 @@ MediaMenu::cdromUpdateMenu(int i) auto childs = menu->children(); auto *muteMenu = dynamic_cast(childs[cdromMutePos]); - muteMenu->setIcon(ProgSettings::loadIcon((cdrom[i].sound_on == 0) ? "/cdrom_unmute.ico" : "/cdrom_mute.ico")); + muteMenu->setIcon(QIcon((cdrom[i].sound_on == 0) ? ":/settings/qt/icons/cdrom_unmute.ico" : ":/settings/qt/icons/cdrom_mute.ico")); muteMenu->setText((cdrom[i].sound_on == 0) ? tr("&Unmute") : tr("&Mute")); - auto *imageMenu = dynamic_cast(childs[cdromImagePos]); - imageMenu->setEnabled(!name.isEmpty()); + auto *ejectMenu = dynamic_cast(childs[cdromEjectPos]); + ejectMenu->setEnabled(!name.isEmpty()); QString menu_item_name; if (name.left(8) == "ioctl://") { #ifdef Q_OS_WINDOWS - menu_item_name = tr("Host CD/DVD Drive (%1)").arg(name.right(2)).toUtf8().constData(); + menu_item_name = tr("Host CD/DVD Drive (%1)").arg(name.right(2)); #else menu_item_name = tr("Host CD/DVD Drive (%1)").arg(name.right(name.length() - 8)); #endif name2 = menu_item_name; - menu_icon = ProgSettings::loadIcon("/cdrom_host.ico"); + menu_icon = QIcon(":/settings/qt/icons/cdrom_host.ico"); } else { QFileInfo fi(cdrom[i].image_path); - menu_item_name = name.isEmpty() ? QString().toUtf8().constData() : name.toUtf8().constData(); + menu_item_name = name.isEmpty() ? QString() : fi.fileName(); name2 = name; - menu_icon = fi.isDir() ? ProgSettings::loadIcon("/cdrom_folder.ico") : ProgSettings::loadIcon("/cdrom_image.ico"); + menu_icon = fi.isDir() ? QIcon(":/settings/qt/icons/cdrom_folder.ico") : QIcon(":/settings/qt/icons/cdrom_image.ico"); } - imageMenu->setIcon(menu_icon); - imageMenu->setText(QString::asprintf(tr("Eject %s").toUtf8().constData(), menu_item_name.toUtf8().constData())); + ejectMenu->setIcon(menu_icon); + ejectMenu->setText(name.isEmpty() ? tr("E&ject") : tr("E&ject %1").arg(menu_item_name)); for (int slot = 0; slot < MAX_PREV_IMAGES; slot++) updateImageHistory(i, slot, ui::MediaType::Optical); @@ -772,8 +770,7 @@ MediaMenu::cdromUpdateMenu(int i) break; } - // menu->setTitle(tr("CD-ROM %1 (%2): %3").arg(QString::number(i+1), busName, name.isEmpty() ? tr("(empty)") : name)); - menu->setTitle(QString::asprintf(tr("CD-ROM %i (%s): %s").toUtf8().constData(), i + 1, busName.toUtf8().data(), name.isEmpty() ? tr("(empty)").toUtf8().data() : name2.toUtf8().data())); + menu->setTitle(tr("CD-ROM %1 (%2): %3").arg(QString::number(i+1), busName, name.isEmpty() ? tr("(empty)") : name2)); } void @@ -806,14 +803,21 @@ MediaMenu::zipSelectImage(int i, bool wp) void MediaMenu::zipMount(int i, const QString &filename, bool wp) { - const auto dev = static_cast(zip_drives[i].priv); + const auto dev = static_cast(zip_drives[i].priv); + int was_empty = zip_is_empty(i); zip_disk_close(dev); zip_drives[i].read_only = wp; if (!filename.isEmpty()) { QByteArray filenameBytes = filename.toUtf8(); - zip_load(dev, filenameBytes.data()); + zip_load(dev, filenameBytes.data(), 1); + + /* Signal media change to the emulated machine. */ zip_insert(dev); + + /* The drive was previously empty, transition directly to UNIT ATTENTION. */ + if (was_empty) + zip_insert(dev); } mhm.addImageToHistory(i, ui::MediaType::Zip, zip_drives[i].prev_image_path, zip_drives[i].image_path); @@ -875,6 +879,7 @@ MediaMenu::zipUpdateMenu(int i) { const QString name = zip_drives[i].image_path; const QString prev_name = zip_drives[i].prev_image_path; + QFileInfo fi(zip_drives[i].image_path); if (!zipMenus.contains(i)) return; auto *menu = zipMenus[i]; @@ -882,6 +887,7 @@ MediaMenu::zipUpdateMenu(int i) auto *ejectMenu = dynamic_cast(childs[zipEjectPos]); ejectMenu->setEnabled(!name.isEmpty()); + ejectMenu->setText(name.isEmpty() ? tr("E&ject") : tr("E&ject %1").arg(fi.fileName())); QString busName = tr("Unknown Bus"); switch (zip_drives[i].bus_type) { @@ -895,8 +901,7 @@ MediaMenu::zipUpdateMenu(int i) break; } - // menu->setTitle(tr("ZIP %1 %2 (%3): %4").arg((zip_drives[i].is_250 > 0) ? "250" : "100", QString::number(i+1), busName, name.isEmpty() ? tr("(empty)") : name)); - menu->setTitle(QString::asprintf(tr("ZIP %03i %i (%s): %ls").toUtf8().constData(), (zip_drives[i].is_250 > 0) ? 250 : 100, i + 1, busName.toUtf8().data(), name.isEmpty() ? tr("(empty)").toStdU16String().data() : name.toStdU16String().data())); + menu->setTitle(tr("ZIP %1 %2 (%3): %4").arg((zip_drives[i].is_250 > 0) ? QString("250") : QString("100"), QString::number(i + 1), busName, name.isEmpty() ? tr("(empty)") : name)); for (int slot = 0; slot < MAX_PREV_IMAGES; slot++) updateImageHistory(i, slot, ui::MediaType::Zip); @@ -935,14 +940,21 @@ MediaMenu::moSelectImage(int i, bool wp) void MediaMenu::moMount(int i, const QString &filename, bool wp) { - const auto dev = static_cast(mo_drives[i].priv); + const auto dev = static_cast(mo_drives[i].priv); + int was_empty = mo_is_empty(i); mo_disk_close(dev); mo_drives[i].read_only = wp; if (!filename.isEmpty()) { QByteArray filenameBytes = filename.toUtf8(); - mo_load(dev, filenameBytes.data()); + mo_load(dev, filenameBytes.data(), 1); + + /* Signal media change to the emulated machine. */ mo_insert(dev); + + /* The drive was previously empty, transition directly to UNIT ATTENTION. */ + if (was_empty) + mo_insert(dev); } mhm.addImageToHistory(i, ui::MediaType::Mo, mo_drives[i].prev_image_path, mo_drives[i].image_path); @@ -1002,8 +1014,9 @@ MediaMenu::moReload(int index, int slot) void MediaMenu::moUpdateMenu(int i) { - QString name = mo_drives[i].image_path; - QString prev_name = mo_drives[i].prev_image_path; + QString name = mo_drives[i].image_path; + QString prev_name = mo_drives[i].prev_image_path; + QFileInfo fi(mo_drives[i].image_path); if (!moMenus.contains(i)) return; auto *menu = moMenus[i]; @@ -1011,6 +1024,7 @@ MediaMenu::moUpdateMenu(int i) auto *ejectMenu = dynamic_cast(childs[moEjectPos]); ejectMenu->setEnabled(!name.isEmpty()); + ejectMenu->setText(name.isEmpty() ? tr("E&ject") : tr("E&ject %1").arg(fi.fileName())); QString busName = tr("Unknown Bus"); switch (mo_drives[i].bus_type) { @@ -1024,7 +1038,7 @@ MediaMenu::moUpdateMenu(int i) break; } - menu->setTitle(QString::asprintf(tr("MO %i (%ls): %ls").toUtf8().constData(), i + 1, busName.toStdU16String().data(), name.isEmpty() ? tr("(empty)").toStdU16String().data() : name.toStdU16String().data())); + menu->setTitle(tr("MO %1 (%2): %3").arg(QString::number(i + 1), busName, name.isEmpty() ? tr("(empty)") : name)); for (int slot = 0; slot < MAX_PREV_IMAGES; slot++) updateImageHistory(i, slot, ui::MediaType::Mo); @@ -1079,7 +1093,7 @@ MediaMenu::nicUpdateMenu(int i) auto *connectedAction = dynamic_cast(childs[netDisconnPos]); connectedAction->setChecked(network_is_connected(i)); - menu->setTitle(QString::asprintf(tr("NIC %02i (%ls) %ls").toUtf8().constData(), i + 1, netType.toStdU16String().data(), devName.toStdU16String().data())); + menu->setTitle(tr("NIC %1 (%2) %3").arg(QString::number(i + 1), netType, devName)); } QString diff --git a/src/qt/qt_mediamenu.hpp b/src/qt/qt_mediamenu.hpp index b069c67d9..ed97a0a50 100644 --- a/src/qt/qt_mediamenu.hpp +++ b/src/qt/qt_mediamenu.hpp @@ -108,8 +108,7 @@ private: int floppyImageHistoryPos[MAX_PREV_IMAGES]; int cdromMutePos; - int cdromImagePos; - int cdromDirPos; + int cdromEjectPos; int cdromImageHistoryPos[MAX_PREV_IMAGES]; int zipEjectPos; diff --git a/src/qt/qt_newfloppydialog.cpp b/src/qt/qt_newfloppydialog.cpp index 48be09777..58a7a3df2 100644 --- a/src/qt/qt_newfloppydialog.cpp +++ b/src/qt/qt_newfloppydialog.cpp @@ -367,7 +367,7 @@ NewFloppyDialog::create86f(const QString &filename, const disk_size_t &disk_size bool NewFloppyDialog::createSectorImage(const QString &filename, const disk_size_t &disk_size, FileType type) { - uint32_t total_size = 0; + uint64_t total_size = 0; uint32_t total_sectors = 0; uint32_t sector_bytes = 0; uint32_t root_dir_bytes = 0; @@ -388,7 +388,7 @@ NewFloppyDialog::createSectorImage(const QString &filename, const disk_size_t &d total_sectors = disk_size.sides * disk_size.tracks * disk_size.sectors; if (total_sectors > ZIP_SECTORS) total_sectors = ZIP_250_SECTORS; - total_size = total_sectors * sector_bytes; + total_size = (uint64_t) total_sectors * sector_bytes; root_dir_bytes = (disk_size.root_dir_entries << 5); fat_size = (disk_size.spfat * sector_bytes); fat1_offs = sector_bytes; @@ -465,11 +465,11 @@ NewFloppyDialog::createSectorImage(const QString &filename, const disk_size_t &d bool NewFloppyDialog::createZipSectorImage(const QString &filename, const disk_size_t &disk_size, FileType type, QProgressDialog &pbar) { - uint32_t total_size = 0; + uint64_t total_size = 0; uint32_t total_sectors = 0; uint32_t sector_bytes = 0; uint16_t base = 0x1000; - uint32_t pbar_max = 0; + uint64_t pbar_max = 0; QFile file(filename); if (!file.open(QIODevice::WriteOnly)) { @@ -482,7 +482,7 @@ NewFloppyDialog::createZipSectorImage(const QString &filename, const disk_size_t total_sectors = disk_size.sides * disk_size.tracks * disk_size.sectors; if (total_sectors > ZIP_SECTORS) total_sectors = ZIP_250_SECTORS; - total_size = total_sectors * sector_bytes; + total_size = (uint64_t) total_sectors * sector_bytes; pbar_max = total_size; if (type == FileType::Zdi) { @@ -649,12 +649,12 @@ 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; - uint32_t total_size2; + uint64_t total_size = 0; + uint64_t total_size2; uint32_t total_sectors = 0; uint32_t sector_bytes = 0; uint16_t base = 0x1000; - uint32_t pbar_max = 0; + uint64_t pbar_max = 0; uint32_t blocks_num; QFile file(filename); @@ -666,7 +666,7 @@ NewFloppyDialog::createMoSectorImage(const QString &filename, int8_t disk_size, sector_bytes = dp->bytes_per_sector; total_sectors = dp->sectors; - total_size = total_sectors * sector_bytes; + total_size = (uint64_t) total_sectors * sector_bytes; total_size2 = (total_size >> 20) << 20; total_size2 = total_size - total_size2; diff --git a/src/qt/qt_opengloptions.cpp b/src/qt/qt_opengloptions.cpp deleted file mode 100644 index 58030b467..000000000 --- a/src/qt/qt_opengloptions.cpp +++ /dev/null @@ -1,196 +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. - * - * OpenGL renderer options for Qt - * - * - * - * Authors: Teemu Korhonen - * - * Copyright 2022 Teemu Korhonen - */ - -#include -#include -#include -#include - -#include - -#include "qt_opengloptions.hpp" - -extern "C" { -#include <86box/86box.h> -} - -/* Default vertex shader. */ -static const GLchar *vertex_shader = "\ -in vec2 VertexCoord;\n\ -in vec2 TexCoord;\n\ -out vec2 tex;\n\ -void main(){\n\ - gl_Position = vec4(VertexCoord, 0.0, 1.0);\n\ - tex = TexCoord;\n\ -}\n"; - -/* Default fragment shader. */ -static const GLchar *fragment_shader = "\ -in vec2 tex;\n\ -uniform sampler2D texsampler;\n\ -out vec4 color;\n\ -void main() {\n\ - color = texture(texsampler, tex);\n\ -}\n"; - -OpenGLOptions::OpenGLOptions(QObject *parent, bool loadConfig, const QString &glslVersion) - : QObject(parent) - , m_glslVersion(glslVersion) -{ - m_filter = video_filter_method == 0 - ? FilterType::Nearest - : FilterType::Linear; - - if (!loadConfig) - return; - - /* Initialize with config. */ - m_vsync = video_vsync != 0; - m_framerate = video_framerate; - - m_renderBehavior = video_framerate == -1 - ? RenderBehaviorType::SyncWithVideo - : RenderBehaviorType::TargetFramerate; - - QString shaderPath(video_shader); - - if (shaderPath.isEmpty()) { - addDefaultShader(); - } else { - try { - addShader(shaderPath); - } catch (const std::runtime_error &) { - /* Fallback to default shader */ - addDefaultShader(); - } - } -} - -void -OpenGLOptions::save() const -{ - video_vsync = m_vsync ? 1 : 0; - video_framerate = m_renderBehavior == RenderBehaviorType::SyncWithVideo ? -1 : m_framerate; - video_filter_method = m_filter == FilterType::Nearest ? 0 : 1; - - /* TODO: multiple shaders */ - auto path = m_shaders.first().path().toLocal8Bit(); - - if (!path.isEmpty()) - qstrncpy(video_shader, path.constData(), sizeof(video_shader)); - else - video_shader[0] = '\0'; -} - -OpenGLOptions::FilterType -OpenGLOptions::filter() const -{ - /* Filter method is controlled externally */ - return video_filter_method == 0 - ? FilterType::Nearest - : FilterType::Linear; -} - -void -OpenGLOptions::setRenderBehavior(RenderBehaviorType value) -{ - m_renderBehavior = value; -} - -void -OpenGLOptions::setFrameRate(int value) -{ - m_framerate = value; -} - -void -OpenGLOptions::setVSync(bool value) -{ - m_vsync = value; -} - -void -OpenGLOptions::setFilter(FilterType value) -{ - m_filter = value; -} - -void -OpenGLOptions::addShader(const QString &path) -{ - QFile shader_file(path); - - if (!shader_file.open(QIODevice::ReadOnly | QIODevice::Text)) { - throw std::runtime_error( - QString(tr("Error opening \"%1\": %2")) - .arg(path) - .arg(shader_file.errorString()) - .toStdString()); - } - - auto shader_text = QString(shader_file.readAll()); - - shader_file.close(); - - /* Remove parameter lines */ - shader_text.remove(QRegularExpression("^\\s*#pragma parameter.*?\\n", QRegularExpression::MultilineOption)); - - QRegularExpression version("^\\s*(#version\\s+\\w+)", QRegularExpression::MultilineOption); - - auto match = version.match(shader_text); - - QString version_line(m_glslVersion); - - if (match.hasMatch()) { - /* Extract existing version and remove it. */ - version_line = match.captured(1); - shader_text.remove(version); - } - - auto shader = new QOpenGLShaderProgram(this); - - auto throw_shader_error = [path, shader](const QString &what) { - throw std::runtime_error( - QString(what % ":\n\n %2") - .arg(path) - .arg(shader->log()) - .toStdString()); - }; - - static const char *extension = "\n#extension GL_ARB_shading_language_420pack : enable\n"; - - if (!shader->addShaderFromSourceCode(QOpenGLShader::Vertex, version_line % extension % "\n#define VERTEX\n#line 1\n" % shader_text)) - throw_shader_error(tr("Error compiling vertex shader in file \"%1\"")); - - if (!shader->addShaderFromSourceCode(QOpenGLShader::Fragment, version_line % extension % "\n#define FRAGMENT\n#line 1\n" % shader_text)) - throw_shader_error(tr("Error compiling fragment shader in file \"%1\"")); - - if (!shader->link()) - throw_shader_error(tr("Error linking shader program in file \"%1\"")); - - m_shaders << OpenGLShaderPass(shader, path); -} - -void -OpenGLOptions::addDefaultShader() -{ - auto shader = new QOpenGLShaderProgram(this); - shader->addShaderFromSourceCode(QOpenGLShader::Vertex, m_glslVersion % "\n" % vertex_shader); - shader->addShaderFromSourceCode(QOpenGLShader::Fragment, m_glslVersion % "\n" % fragment_shader); - shader->link(); - m_shaders << OpenGLShaderPass(shader, QString()); -} diff --git a/src/qt/qt_opengloptions.hpp b/src/qt/qt_opengloptions.hpp deleted file mode 100644 index 64f761670..000000000 --- a/src/qt/qt_opengloptions.hpp +++ /dev/null @@ -1,102 +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. - * - * Header for OpenGL renderer options - * - * - * - * Authors: Teemu Korhonen - * - * Copyright 2022 Teemu Korhonen - */ - -#ifndef QT_OPENGLOPTIONS_HPP -#define QT_OPENGLOPTIONS_HPP - -#include -#include -#include -#include - -class OpenGLShaderPass { -public: - OpenGLShaderPass(QOpenGLShaderProgram *shader, const QString &path) - : m_shader(shader) - , m_path(path) - , m_vertex_coord(shader->attributeLocation("VertexCoord")) - , m_tex_coord(shader->attributeLocation("TexCoord")) - , m_color(shader->attributeLocation("Color")) - , m_mvp_matrix(shader->uniformLocation("MVPMatrix")) - , m_input_size(shader->uniformLocation("InputSize")) - , m_output_size(shader->uniformLocation("OutputSize")) - , m_texture_size(shader->uniformLocation("TextureSize")) - , m_frame_count(shader->uniformLocation("FrameCount")) - { - } - - bool bind() const { return m_shader->bind(); } - const QString &path() const { return m_path; } - const GLint &vertex_coord() const { return m_vertex_coord; } - const GLint &tex_coord() const { return m_tex_coord; } - const GLint &color() const { return m_color; } - const GLint &mvp_matrix() const { return m_mvp_matrix; } - const GLint &input_size() const { return m_input_size; } - const GLint &output_size() const { return m_output_size; } - const GLint &texture_size() const { return m_texture_size; } - const GLint &frame_count() const { return m_frame_count; } - -private: - QOpenGLShaderProgram *m_shader; - QString m_path; - GLint m_vertex_coord; - GLint m_tex_coord; - GLint m_color; - GLint m_mvp_matrix; - GLint m_input_size; - GLint m_output_size; - GLint m_texture_size; - GLint m_frame_count; -}; - -class OpenGLOptions : public QObject { - Q_OBJECT - -public: - enum RenderBehaviorType { SyncWithVideo, - TargetFramerate }; - - enum FilterType { Nearest, - Linear }; - - OpenGLOptions(QObject *parent, bool loadConfig, const QString &glslVersion); - - RenderBehaviorType renderBehavior() const { return m_renderBehavior; } - int framerate() const { return m_framerate; } - bool vSync() const { return m_vsync; } - FilterType filter() const; - - const QList &shaders() const { return m_shaders; } - - void setRenderBehavior(RenderBehaviorType value); - void setFrameRate(int value); - void setVSync(bool value); - void setFilter(FilterType value); - void addShader(const QString &path); - void addDefaultShader(); - void save() const; - -private: - RenderBehaviorType m_renderBehavior = SyncWithVideo; - int m_framerate = -1; - bool m_vsync = false; - FilterType m_filter = Nearest; - QList m_shaders; - QString m_glslVersion; -}; - -#endif diff --git a/src/qt/qt_opengloptionsdialog.cpp b/src/qt/qt_opengloptionsdialog.cpp deleted file mode 100644 index acb2ce9f2..000000000 --- a/src/qt/qt_opengloptionsdialog.cpp +++ /dev/null @@ -1,116 +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. - * - * OpenGL renderer options dialog for Qt - * - * - * - * Authors: Teemu Korhonen - * - * Copyright 2022 Teemu Korhonen - */ - -#include -#include -#include - -#include - -#include "qt_opengloptionsdialog.hpp" -#include "qt_util.hpp" -#include "ui_qt_opengloptionsdialog.h" - -OpenGLOptionsDialog::OpenGLOptionsDialog(QWidget *parent, const OpenGLOptions &options, std::function optionsFactory) - : QDialog(parent) - , ui(new Ui::OpenGLOptionsDialog) - , createOptions(optionsFactory) -{ - ui->setupUi(this); - - if (options.renderBehavior() == OpenGLOptions::SyncWithVideo) - ui->syncWithVideo->setChecked(true); - else { - ui->syncToFramerate->setChecked(true); - ui->targetFps->setValue(options.framerate()); - } - - ui->vsync->setChecked(options.vSync()); - - if (!options.shaders().isEmpty()) { - auto path = options.shaders().first().path(); - if (!path.isEmpty()) - ui->shader->setPlainText(path); - } -} - -OpenGLOptionsDialog::~OpenGLOptionsDialog() -{ - delete ui; -} - -void -OpenGLOptionsDialog::accept() -{ - auto options = createOptions(); - - options->setRenderBehavior( - ui->syncWithVideo->isChecked() - ? OpenGLOptions::SyncWithVideo - : OpenGLOptions::TargetFramerate); - - options->setFrameRate(ui->targetFps->value()); - - options->setVSync(ui->vsync->isChecked()); - - auto shader = ui->shader->toPlainText(); - - try { - - if (!shader.isEmpty()) - options->addShader(shader); - else - options->addDefaultShader(); - - } catch (const std::runtime_error &e) { - delete options; - - QMessageBox msgBox(this); - msgBox.setWindowTitle(tr("Shader error")); - msgBox.setText(tr("Could not load shaders.")); - msgBox.setInformativeText(tr("More information in details.")); - msgBox.setDetailedText(e.what()); - msgBox.setIcon(QMessageBox::Critical); - msgBox.setStandardButtons(QMessageBox::Close); - msgBox.setDefaultButton(QMessageBox::Close); - msgBox.setStyleSheet("QTextEdit { min-width: 45em; }"); - msgBox.exec(); - - return; - } - - options->save(); - - emit optionsChanged(options); - - QDialog::accept(); -} - -void -OpenGLOptionsDialog::on_addShader_clicked() -{ - auto shader = QFileDialog::getOpenFileName( - this, - QString(), - QString(), - tr("OpenGL Shaders") % util::DlgFilter({ "glsl" }, true)); - - if (shader.isNull()) - return; - - ui->shader->setPlainText(shader); -} diff --git a/src/qt/qt_opengloptionsdialog.hpp b/src/qt/qt_opengloptionsdialog.hpp deleted file mode 100644 index f34d74d75..000000000 --- a/src/qt/qt_opengloptionsdialog.hpp +++ /dev/null @@ -1,51 +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. - * - * Header for OpenGL renderer options dialog - * - * Authors: Teemu Korhonen - * - * Copyright 2022 Teemu Korhonen - */ - -#ifndef QT_OPENGLOPTIONSDIALOG_H -#define QT_OPENGLOPTIONSDIALOG_H - -#include - -#include - -#include "qt_opengloptions.hpp" - -namespace Ui { -class OpenGLOptionsDialog; -} - -class OpenGLOptionsDialog : public QDialog { - Q_OBJECT - -public: - explicit OpenGLOptionsDialog(QWidget *parent, const OpenGLOptions &options, std::function optionsFactory); - ~OpenGLOptionsDialog(); - -signals: - void optionsChanged(OpenGLOptions *options); - -public slots: - void accept() override; - -private: - Ui::OpenGLOptionsDialog *ui; - - std::function createOptions; - -private slots: - void on_addShader_clicked(); -}; - -#endif // QT_OPENGLOPTIONSDIALOG_H diff --git a/src/qt/qt_opengloptionsdialog.ui b/src/qt/qt_opengloptionsdialog.ui deleted file mode 100644 index a6f86b6c2..000000000 --- a/src/qt/qt_opengloptionsdialog.ui +++ /dev/null @@ -1,280 +0,0 @@ - - - OpenGLOptionsDialog - - - - 0 - 0 - 400 - 320 - - - - OpenGL 3.0 renderer options - - - - - - Render behavior - - - - - - Use target framerate: - - - - - - - false - - - fps - - - 15 - - - 240 - - - 60 - - - - - - - VSync - - - - - - - <html><head/><body><p>Render each frame immediately, in sync with the emulated display.</p><p><span style=" font-style:italic;">This is the recommended option if the shaders in use don't utilize frametime for animated effects.</span></p></body></html> - - - Synchronize with video - - - true - - - - - - - false - - - 15 - - - 240 - - - 60 - - - Qt::Horizontal - - - false - - - QSlider::NoTicks - - - - - - - - - - Shaders - - - - - - Remove - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - true - - - No shader selected - - - - - - - Browse... - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - syncWithVideo - syncToFramerate - fpsSlider - targetFps - vsync - shader - addShader - removeShader - - - - - buttonBox - accepted() - OpenGLOptionsDialog - accept() - - - 257 - 310 - - - 157 - 274 - - - - - buttonBox - rejected() - OpenGLOptionsDialog - reject() - - - 325 - 310 - - - 286 - 274 - - - - - syncToFramerate - toggled(bool) - targetFps - setEnabled(bool) - - - 140 - 71 - - - 380 - 98 - - - - - syncToFramerate - toggled(bool) - fpsSlider - setEnabled(bool) - - - 158 - 66 - - - 168 - 87 - - - - - fpsSlider - valueChanged(int) - targetFps - setValue(int) - - - 252 - 90 - - - 308 - 89 - - - - - targetFps - valueChanged(int) - fpsSlider - setValue(int) - - - 364 - 93 - - - 134 - 93 - - - - - removeShader - clicked() - shader - clear() - - - 333 - 201 - - - 235 - 208 - - - - - diff --git a/src/qt/qt_openglrenderer.cpp b/src/qt/qt_openglrenderer.cpp index 60aa998a9..9ca2d887e 100644 --- a/src/qt/qt_openglrenderer.cpp +++ b/src/qt/qt_openglrenderer.cpp @@ -6,52 +6,829 @@ * * This file is part of the 86Box distribution. * - * OpenGL renderer for Qt + * OpenGL renderer for Qt, mostly ported over from PCem. * * * * Authors: Teemu Korhonen + * Cacodemon345 + * bit + * Sarah Walker * * Copyright 2022 Teemu Korhonen + * Copyright 2025 Cacodemon345 + * Copyright 2017 Bit + * Copyright 2017-2020 Sarah Walker */ +#include "qt_renderercommon.hpp" +#include "qt_mainwindow.hpp" + +extern MainWindow* main_window; + #include #include -#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include #include -#include -#include +#include + +#include #include -#include "qt_opengloptionsdialog.hpp" #include "qt_openglrenderer.hpp" +#include "qt_openglshadermanagerdialog.hpp" -#ifndef GL_MAP_PERSISTENT_BIT -# define GL_MAP_PERSISTENT_BIT 0x0040 +extern "C" { +#include <86box/86box.h> +#include <86box/plat.h> +#include <86box/ui.h> +#include <86box/video.h> +#include <86box/path.h> +#include <86box/ini.h> +#include <86box/config.h> +#include <86box/qt-glslp-parser.h> + +char gl3_shader_file[MAX_USER_SHADERS][512]; +extern bool cpu_thread_running; +} + +#define SCALE_SOURCE 0 +#define SCALE_VIEWPORT 1 +#define SCALE_ABSOLUTE 2 + +static GLfloat matrix[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; + +extern int video_filter_method; +extern int video_vsync; +extern int video_focus_dim; +extern int video_refresh_rate; + +const char* vertex_shader_default_tex_src = +#ifdef __APPLE__ + "#version 150\n" +#else + "#version 130\n" +#endif + "\n" + "in vec4 VertexCoord;\n" + "in vec2 TexCoord;\n" + "\n" + "out vec2 texCoord;\n" + "\n" + "void main()\n" + "{\n" + " gl_Position = VertexCoord;\n" + " texCoord = TexCoord;\n" + "}\n"; + +const char* fragment_shader_default_tex_src = +#ifdef __APPLE__ + "#version 150\n" +#else + "#version 130\n" +#endif + "\n" + "in vec2 texCoord;\n" + "uniform sampler2D Texture;\n" + "\n" + "out vec4 color;" + "\n" + "void main()\n" + "{\n" + " color = texture(Texture, texCoord);\n" + " color.a = 1.0;\n" + "}\n"; + +const char* vertex_shader_default_color_src = +#ifdef __APPLE__ + "#version 150\n" +#else + "#version 130\n" +#endif + "\n" + "in vec4 VertexCoord;\n" + "in vec4 Color;\n" + "\n" + "out vec4 color;\n" + "\n" + "void main()\n" + "{\n" + " gl_Position = VertexCoord;\n" + " color = Color;\n" + "}\n"; + +const char* fragment_shader_default_color_src = +#ifdef __APPLE__ + "#version 150\n" +#else + "#version 130\n" +#endif + "\n" + "in vec4 color;\n" + "\n" + "out vec4 outColor;" + "\n" + "void main()\n" + "{\n" + " outColor = color;\n" + " outColor.a = 1.0;\n" + "}\n"; + +#ifdef ENABLE_OGL3_LOG +int ogl3_do_log = ENABLE_OGL3_LOG; + +static void +ogl3_log(const char *fmt, ...) +{ + va_list ap; + + if (ogl3_do_log) { + va_start(ap, fmt); + ogl3_log_ex(fmt, ap); + va_end(ap); + } +} +#else +# define ogl3_log(fmt, ...) #endif -#ifndef GL_MAP_COHERENT_BIT -# define GL_MAP_COHERENT_BIT 0x0080 +static inline int +next_pow2(unsigned int n) +{ + n--; + n |= n >> 1; // Divide by 2^k for consecutive doublings of k up to 32, + n |= n >> 2; // and then or the results. + n |= n >> 4; + n |= n >> 8; + n |= n >> 16; + n++; + + return n; +} + +int +OpenGLRenderer::create_program(struct shader_program *program) +{ + GLint status; + program->id = glw.glCreateProgram(); + glw.glAttachShader(program->id, program->vertex_shader); + glw.glAttachShader(program->id, program->fragment_shader); + + glw.glLinkProgram(program->id); + + glw.glDeleteShader(program->vertex_shader); + glw.glDeleteShader(program->fragment_shader); + + program->vertex_shader = program->fragment_shader = 0; + + glw.glGetProgramiv(program->id, GL_LINK_STATUS, &status); + + if (!status) { + int maxLength; + int length; + glw.glGetProgramiv(program->id, GL_INFO_LOG_LENGTH, &maxLength); + char *log = (char *) malloc(maxLength); + glw.glGetProgramInfoLog(program->id, maxLength, &length, log); + main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("GLSL Error"), tr("Program not linked:\n\n%1").arg(log), false); + // wx_simple_messagebox("GLSL Error", "Program not linked:\n%s", log); + free(log); + return 0; + } + + return 1; +} + +int +OpenGLRenderer::compile_shader(GLenum shader_type, const char *prepend, const char *program, int *dst) +{ + QRegularExpression versionRegex("^\\s*(#version\\s+\\w+)", QRegularExpression::MultilineOption); + QString progSource = QString(program); + QByteArray finalSource = nullptr; + const char *source[5]; + char version[50]; + char *version_loc = (char *) strstr(program, "#version"); + if (version_loc) { + snprintf(version, 49, "%s\n", versionRegex.match(progSource).captured(1).toLatin1().data()); + progSource.remove(versionRegex); + } else { + snprintf(version, 49, "%s\n", this->glslVersion.toLatin1().data()); + } + + /* Remove parameter lines. */ + progSource.remove(QRegularExpression("^\\s*#pragma parameter.*?\\n", QRegularExpression::MultilineOption)); + + finalSource = progSource.toLatin1(); + + source[0] = version; + source[1] = "\n#extension GL_ARB_shading_language_420pack : enable\n"; + source[2] = prepend ? prepend : ""; + source[3] = "\n#line 1\n"; + source[4] = finalSource.data(); + + GLuint shader = glw.glCreateShader(shader_type); + glw.glShaderSource(shader, 5, source, NULL); + glw.glCompileShader(shader); + + GLint status = 0; + glw.glGetShaderiv(shader, GL_COMPILE_STATUS, &status); + if (!status) { + GLint length; + glw.glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length); + char *log = (char *) malloc(length); + glw.glGetShaderInfoLog(shader, length, &length, log); + main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("GLSL Error"), tr("Could not compile shader:\n\n%1").arg(log), false); + // wx_simple_messagebox("GLSL Error", "Could not compile shader:\n%s", log); + + ogl3_log("Could not compile shader: %s\n", log); + // ogl3_log("Shader: %s\n", program); + + free(log); + return 0; + } + + *dst = shader; + + return 1; +} + +GLuint +OpenGLRenderer::get_uniform(GLuint program, const char *name) +{ + return glw.glGetUniformLocation(program, name); +} + +GLuint +OpenGLRenderer::get_attrib(GLuint program, const char *name) +{ + return glw.glGetAttribLocation(program, name); +} + +void +OpenGLRenderer::find_uniforms(struct glsl_shader *glsl, int num_pass) +{ + int i; + char s[50]; + struct shader_pass *pass = &glsl->passes[num_pass]; + int p = pass->program.id; + glw.glUseProgram(p); + + struct shader_uniforms *u = &pass->uniforms; + + u->mvp_matrix = get_uniform(p, "MVPMatrix"); + u->vertex_coord = get_attrib(p, "VertexCoord"); + u->tex_coord = get_attrib(p, "TexCoord"); + u->color = get_attrib(p, "Color"); + + u->frame_count = get_uniform(p, "FrameCount"); + u->frame_direction = get_uniform(p, "FrameDirection"); + + u->texture = get_uniform(p, "Texture"); + u->input_size = get_uniform(p, "InputSize"); + u->texture_size = get_uniform(p, "TextureSize"); + u->output_size = get_uniform(p, "OutputSize"); + + u->orig.texture = get_uniform(p, "OrigTexture"); + u->orig.input_size = get_uniform(p, "OrigInputSize"); + u->orig.texture_size = get_uniform(p, "OrigTextureSize"); + + for (i = 0; i < glsl->num_passes; ++i) { + sprintf(s, "Pass%dTexture", (i + 1)); + u->pass[i].texture = get_uniform(p, s); + sprintf(s, "Pass%dInputSize", (i + 1)); + u->pass[i].input_size = get_uniform(p, s); + sprintf(s, "Pass%dTextureSize", (i + 1)); + u->pass[i].texture_size = get_uniform(p, s); + + sprintf(s, "PassPrev%dTexture", num_pass - i); + u->prev_pass[i].texture = get_uniform(p, s); + sprintf(s, "PassPrev%dInputSize", num_pass - i); + u->prev_pass[i].input_size = get_uniform(p, s); + sprintf(s, "PassPrev%dTextureSize", num_pass - i); + u->prev_pass[i].texture_size = get_uniform(p, s); + } + + u->prev[0].texture = get_uniform(p, "PrevTexture"); + u->prev[0].tex_coord = get_attrib(p, "PrevTexCoord"); + for (i = 1; i < MAX_PREV; ++i) { + sprintf(s, "Prev%dTexture", i); + u->prev[i].texture = get_uniform(p, s); + sprintf(s, "Prev%dTexCoord", i); + u->prev[i].tex_coord = get_attrib(p, s); + } + for (i = 0; i < MAX_PREV; ++i) + if (u->prev[i].texture >= 0) + glsl->has_prev = 1; + + for (i = 0; i < glsl->num_lut_textures; ++i) + u->lut_textures[i] = get_uniform(p, glsl->lut_textures[i].name); + + for (i = 0; i < glsl->num_parameters; ++i) + u->parameters[i] = get_uniform(p, glsl->parameters[i].id); + + glw.glUseProgram(0); +} + +static void +set_scale_mode(char *scale, int *dst) +{ + if (!strcmp(scale, "viewport")) + *dst = SCALE_VIEWPORT; + else if (!strcmp(scale, "absolute")) + *dst = SCALE_ABSOLUTE; + else + *dst = SCALE_SOURCE; +} + +static void +setup_scale(struct shader *shader, struct shader_pass *pass) +{ + set_scale_mode(shader->scale_type_x, &pass->scale.mode[0]); + set_scale_mode(shader->scale_type_y, &pass->scale.mode[1]); + pass->scale.value[0] = shader->scale_x; + pass->scale.value[1] = shader->scale_y; +} + +void +OpenGLRenderer::create_texture(struct shader_texture *tex) +{ + if (tex->width > max_texture_size) + tex->width = max_texture_size; + if (tex->height > max_texture_size) + tex->height = max_texture_size; + ogl3_log("Create texture with size %dx%d\n", tex->width, tex->height); + glw.glGenTextures(1, (GLuint *) &tex->id); + glw.glBindTexture(GL_TEXTURE_2D, tex->id); + glw.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, tex->wrap_mode); + glw.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, tex->wrap_mode); + glw.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, tex->min_filter); + glw.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, tex->mag_filter); + glw.glTexImage2D(GL_TEXTURE_2D, 0, tex->internal_format, tex->width, tex->height, 0, tex->format, tex->type, tex->data); + if (tex->mipmap) + glw.glGenerateMipmap(GL_TEXTURE_2D); + glw.glBindTexture(GL_TEXTURE_2D, 0); +} + +void +OpenGLRenderer::delete_texture(struct shader_texture *tex) +{ + if (tex->id > 0) + glw.glDeleteTextures(1, (GLuint *) &tex->id); + tex->id = 0; +} + +void +OpenGLRenderer::delete_fbo(struct shader_fbo *fbo) +{ + if (fbo->id >= 0) { + glw.glDeleteFramebuffers(1, (GLuint *) &fbo->id); + delete_texture(&fbo->texture); + } +} + +void +OpenGLRenderer::delete_program(struct shader_program *program) +{ + if (program->vertex_shader) + glw.glDeleteShader(program->vertex_shader); + if (program->fragment_shader) + glw.glDeleteShader(program->fragment_shader); + glw.glDeleteProgram(program->id); +} + +void +OpenGLRenderer::delete_vbo(struct shader_vbo *vbo) +{ + if (vbo->color >= 0) + glw.glDeleteBuffers(1, (GLuint *) &vbo->color); + glw.glDeleteBuffers(1, (GLuint *) &vbo->vertex_coord); + glw.glDeleteBuffers(1, (GLuint *) &vbo->tex_coord); +} + +void +OpenGLRenderer::delete_pass(struct shader_pass *pass) +{ + delete_fbo(&pass->fbo); + delete_vbo(&pass->vbo); + delete_program(&pass->program); + glw.glDeleteVertexArrays(1, (GLuint *) &pass->vertex_array); +} + +void +OpenGLRenderer::delete_prev(struct shader_prev *prev) +{ + delete_fbo(&prev->fbo); + delete_vbo(&prev->vbo); +} + +void +OpenGLRenderer::delete_shader(struct glsl_shader *glsl) +{ + int i; + for (i = 0; i < glsl->num_passes; ++i) + delete_pass(&glsl->passes[i]); + if (glsl->has_prev) { + delete_pass(&glsl->prev_scene); + for (i = 0; i < MAX_PREV; ++i) + delete_prev(&glsl->prev[i]); + } + for (i = 0; i < glsl->num_lut_textures; ++i) + delete_texture(&glsl->lut_textures[i].texture); +} + +void +OpenGLRenderer::delete_glsl(glsl_t *glsl) +{ + int i; + for (i = 0; i < glsl->num_shaders; ++i) + delete_shader(&glsl->shaders[i]); + delete_pass(&glsl->scene); + delete_pass(&glsl->fs_color); + delete_pass(&glsl->final_pass); +#ifdef SDL2_SHADER_DEBUG + delete_pass(&glsl->debug); #endif +} + +void +OpenGLRenderer::create_fbo(struct shader_fbo *fbo) +{ + create_texture(&fbo->texture); + + glw.glGenFramebuffers(1, (GLuint *) &fbo->id); + glw.glBindFramebuffer(GL_FRAMEBUFFER, fbo->id); + glw.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbo->texture.id, 0); + + if (glw.glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) + ogl3_log("Could not create framebuffer!\n"); + + glw.glBindFramebuffer(GL_FRAMEBUFFER, 0); +} + +void +OpenGLRenderer::setup_fbo(struct shader *shader, struct shader_fbo *fbo) +{ + fbo->texture.internal_format = GL_RGBA8; + fbo->texture.format = GL_RGBA; + fbo->texture.min_filter = fbo->texture.mag_filter = shader->filter_linear ? GL_LINEAR : GL_NEAREST; + fbo->texture.width = 2048; + fbo->texture.height = 2048; + fbo->texture.type = GL_UNSIGNED_BYTE; + if (!strcmp(shader->wrap_mode, "repeat")) + fbo->texture.wrap_mode = GL_REPEAT; + else if (!strcmp(shader->wrap_mode, "mirrored_repeat")) + fbo->texture.wrap_mode = GL_MIRRORED_REPEAT; + else if (!strcmp(shader->wrap_mode, "clamp_to_edge")) + fbo->texture.wrap_mode = GL_CLAMP_TO_EDGE; + else + fbo->texture.wrap_mode = GL_CLAMP_TO_BORDER; + fbo->srgb = 0; + if (shader->srgb_framebuffer) { + fbo->texture.internal_format = GL_SRGB8_ALPHA8; + fbo->srgb = 1; + } else if (shader->float_framebuffer) { + fbo->texture.internal_format = GL_RGBA32F; + fbo->texture.type = GL_FLOAT; + } + + if (fbo->texture.mipmap) + fbo->texture.min_filter = shader->filter_linear ? GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST_MIPMAP_NEAREST; + + create_fbo(fbo); +} + +void +OpenGLRenderer::recreate_fbo(struct shader_fbo *fbo, int width, int height) +{ + if (width != fbo->texture.width || height != fbo->texture.height) { + glw.glDeleteFramebuffers(1, (GLuint *) &fbo->id); + glw.glDeleteTextures(1, (GLuint *) &fbo->texture.id); + fbo->texture.width = width; + fbo->texture.height = height; + create_fbo(fbo); + } +} + +int +OpenGLRenderer::create_default_shader_tex(struct shader_pass *pass) +{ + if (!compile_shader(GL_VERTEX_SHADER, 0, vertex_shader_default_tex_src, &pass->program.vertex_shader) || !compile_shader(GL_FRAGMENT_SHADER, 0, fragment_shader_default_tex_src, &pass->program.fragment_shader) || !create_program(&pass->program)) + return 0; + glw.glGenVertexArrays(1, (GLuint *) &pass->vertex_array); + + struct shader_uniforms *u = &pass->uniforms; + int p = pass->program.id; + memset(u, -1, sizeof(struct shader_uniforms)); + u->vertex_coord = get_attrib(p, "VertexCoord"); + u->tex_coord = get_attrib(p, "TexCoord"); + u->texture = get_uniform(p, "Texture"); + pass->scale.mode[0] = pass->scale.mode[1] = SCALE_SOURCE; + pass->scale.value[0] = pass->scale.value[1] = 1.0f; + pass->fbo.id = -1; + pass->active = 1; + return 1; +} + +int +OpenGLRenderer::create_default_shader_color(struct shader_pass *pass) +{ + if (!compile_shader(GL_VERTEX_SHADER, 0, vertex_shader_default_color_src, &pass->program.vertex_shader) || !compile_shader(GL_FRAGMENT_SHADER, 0, fragment_shader_default_color_src, &pass->program.fragment_shader) || !create_program(&pass->program)) + return 0; + glw.glGenVertexArrays(1, (GLuint *) &pass->vertex_array); + + struct shader_uniforms *u = &pass->uniforms; + int p = pass->program.id; + memset(u, -1, sizeof(struct shader_uniforms)); + u->vertex_coord = get_attrib(p, "VertexCoord"); + u->color = get_attrib(p, "Color"); + pass->scale.mode[0] = pass->scale.mode[1] = SCALE_SOURCE; + pass->scale.value[0] = pass->scale.value[1] = 1.0f; + pass->fbo.id = -1; + pass->active = 1; + return 1; +} + +/* create the default scene shader */ +void +OpenGLRenderer::create_scene_shader() +{ + struct shader scene_shader_conf; + memset(&scene_shader_conf, 0, sizeof(struct shader)); + create_default_shader_tex(&active_shader->scene); + scene_shader_conf.filter_linear = video_filter_method; + if (active_shader->num_shaders > 0 && active_shader->shaders[0].input_filter_linear >= 0) + scene_shader_conf.filter_linear = active_shader->shaders[0].input_filter_linear; + setup_fbo(&scene_shader_conf, &active_shader->scene.fbo); + + memset(&scene_shader_conf, 0, sizeof(struct shader)); + create_default_shader_color(&active_shader->fs_color); + setup_fbo(&scene_shader_conf, &active_shader->fs_color.fbo); +} + +static int +load_texture(const char *f, struct shader_texture *tex) +{ + QImage img; + if (!img.load(f)) + return 0; + int width, height; + width = img.size().width(); + height = img.size().height(); + + if (width != next_pow2(width) || height != next_pow2(height)) + img = img.scaled(next_pow2(width), next_pow2(height)); + + width = img.size().width(); + height = img.size().height(); + + img.convertTo(QImage::Format_RGBA8888); + + const GLubyte *rgb = img.constBits(); + + int bpp = 4; + + GLubyte *data = (GLubyte *) malloc(width * height * bpp); + + int x, y, Y; + for (y = 0; y < height; ++y) { + Y = height - y - 1; + for (x = 0; x < width; x++) { + data[(y * width + x) * bpp + 0] = rgb[(Y * width + x) * 3 + 0]; + data[(y * width + x) * bpp + 1] = rgb[(Y * width + x) * 3 + 1]; + data[(y * width + x) * bpp + 2] = rgb[(Y * width + x) * 3 + 2]; + data[(y * width + x) * bpp + 3] = rgb[(Y * width + x) * 3 + 3]; + } + } + + tex->width = width; + tex->height = height; + tex->internal_format = GL_RGBA8; + tex->format = GL_RGBA; + tex->type = GL_UNSIGNED_BYTE; + tex->data = data; + return 1; +} + +glsl_t * +OpenGLRenderer::load_glslp(glsl_t *glsl, int num_shader, const char *f) +{ + int i, j; + glslp_t *p = glslp_parse(f); + + if (p) { + char path[512]; + char file[1024]; + int failed = 0; + strcpy(path, f); + char *filename = path_get_filename(path); + + struct glsl_shader *gshader = &glsl->shaders[num_shader]; + + strcpy(gshader->name, p->name); + *filename = 0; + + gshader->num_lut_textures = p->num_textures; + + for (i = 0; i < p->num_textures; ++i) { + struct texture *texture = &p->textures[i]; + + sprintf(file, "%s%s", path, texture->path); + + struct shader_lut_texture *tex = &gshader->lut_textures[i]; + strcpy(tex->name, texture->name); + + ogl3_log("Load texture %s...\n", file); + + if (!load_texture(file, &tex->texture)) { + //QMessageBox::critical(main_window, tr("GLSL Error"), tr("Could not load texture: %s").arg(file)); + main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("GLSL Error"), tr("Could not load texture: %1").arg(file), false); + ogl3_log("Could not load texture %s!\n", file); + failed = 1; + break; + } + + if (!strcmp(texture->wrap_mode, "repeat")) + tex->texture.wrap_mode = GL_REPEAT; + else if (!strcmp(texture->wrap_mode, "mirrored_repeat")) + tex->texture.wrap_mode = GL_MIRRORED_REPEAT; + else if (!strcmp(texture->wrap_mode, "clamp_to_edge")) + tex->texture.wrap_mode = GL_CLAMP_TO_EDGE; + else + tex->texture.wrap_mode = GL_CLAMP_TO_BORDER; + + tex->texture.mipmap = texture->mipmap; + + tex->texture.min_filter = tex->texture.mag_filter = texture->linear ? GL_LINEAR : GL_NEAREST; + if (tex->texture.mipmap) + tex->texture.min_filter = texture->linear ? GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST_MIPMAP_NEAREST; + + create_texture(&tex->texture); + free(tex->texture.data); + tex->texture.data = 0; + } + + if (!failed) { + gshader->input_filter_linear = p->input_filter_linear; + + gshader->num_parameters = p->num_parameters; + for (j = 0; j < gshader->num_parameters; ++j) + memcpy(&gshader->parameters[j], &p->parameters[j], sizeof(struct shader_parameter)); + + gshader->num_passes = p->num_shaders; + + for (i = 0; i < p->num_shaders; ++i) { + struct shader *shader = &p->shaders[i]; + struct shader_pass *pass = &gshader->passes[i]; + + strcpy(pass->alias, shader->alias); + if (!strlen(pass->alias)) + sprintf(pass->alias, "Pass %u", (i + 1)); + + ogl3_log("Creating pass %u (%s)\n", (i + 1), pass->alias); + ogl3_log("Loading shader %s...\n", shader->shader_fn); + if (!shader->shader_program) { + main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("GLSL Error"), tr("Could not load shader: %1").arg(shader->shader_fn), false); + // wx_simple_messagebox("GLSL Error", "Could not load shader: %s", shader->shader_fn); + ogl3_log("Could not load shader %s\n", shader->shader_fn); + failed = 1; + break; + } else + ogl3_log("Shader %s loaded\n", shader->shader_fn); + failed = !compile_shader(GL_VERTEX_SHADER, "#define VERTEX\n#define PARAMETER_UNIFORM\n", + shader->shader_program, &pass->program.vertex_shader) + || !compile_shader(GL_FRAGMENT_SHADER, "#define FRAGMENT\n#define PARAMETER_UNIFORM\n", + shader->shader_program, &pass->program.fragment_shader); + if (failed) + break; + + if (!create_program(&pass->program)) { + failed = 1; + break; + } + pass->frame_count_mod = shader->frame_count_mod; + pass->fbo.mipmap_input = shader->mipmap_input; + + glw.glGenVertexArrays(1, (GLuint *) &pass->vertex_array); + find_uniforms(gshader, i); + setup_scale(shader, pass); + if (i == p->num_shaders - 1) /* last pass may or may not be an fbo depending on scale */ + { + if (num_shader == glsl->num_shaders - 1) { + pass->fbo.id = -1; + + for (j = 0; j < 2; ++j) { + if (pass->scale.mode[j] != SCALE_SOURCE || pass->scale.value[j] != 1) { + setup_fbo(shader, &pass->fbo); + break; + } + } + } else { + /* check if next shaders' first pass wants the input mipmapped (will this ever + * happen?) */ + pass->fbo.texture.mipmap = glsl->shaders[num_shader + 1].num_passes > 0 && glsl->shaders[num_shader + 1].passes[0].fbo.mipmap_input; + /* check if next shader wants the output of this pass to be filtered */ + if (glsl->shaders[num_shader + 1].num_passes > 0 && glsl->shaders[num_shader + 1].input_filter_linear >= 0) + shader->filter_linear = glsl->shaders[num_shader + 1].input_filter_linear; + setup_fbo(shader, &pass->fbo); + } + } else { + /* check if next pass wants the input mipmapped, if so we need to generate mipmaps of this + * pass */ + pass->fbo.texture.mipmap = (i + 1) < p->num_shaders && p->shaders[i + 1].mipmap_input; + setup_fbo(shader, &pass->fbo); + } + if (pass->fbo.srgb) + glsl->srgb = 1; + pass->active = 1; + } + if (!failed) { + if (gshader->has_prev) { + struct shader scene_shader_conf; + memset(&scene_shader_conf, 0, sizeof(struct shader)); + for (i = 0; i < MAX_PREV; ++i) { + setup_fbo(&scene_shader_conf, &gshader->prev[i].fbo); + } + } + } + } + + glslp_free(p); + + return glsl; + } + return 0; +} + +glsl_t * +OpenGLRenderer::load_shaders(int num, char shaders[MAX_USER_SHADERS][512]) +{ + int i; + glsl_t *glsl; + + glsl = (glsl_t *) malloc(sizeof(glsl_t)); + memset(glsl, 0, sizeof(glsl_t)); + + glsl->num_shaders = num; + int failed = 0; + for (i = num - 1; i >= 0; --i) { + const char *f = shaders[i]; + if (f && strlen(f)) { + if (!load_glslp(glsl, i, f)) { + failed = 1; + break; + } + } + } + if (failed) { + delete_glsl(glsl); + memset(glsl, 0, sizeof(glsl_t)); + } + return glsl; +} + +void +OpenGLRenderer::read_shader_config() +{ + char s[512]; + int i, j; + for (i = 0; i < active_shader->num_shaders; ++i) { + struct glsl_shader *shader = &active_shader->shaders[i]; + char *name = shader->name; + sprintf(s, "GL3 Shaders - %s", name); + // shader->shader_refresh_rate = config_get_float(CFG_MACHINE, s, "shader_refresh_rate", -1); + for (j = 0; j < shader->num_parameters; ++j) { + struct shader_parameter *param = &shader->parameters[j]; + param->value = config_get_double(s, param->id, param->default_value); + } + } +} OpenGLRenderer::OpenGLRenderer(QWidget *parent) : QWindow(parent->windowHandle()) , renderTimer(new QTimer(this)) - , options(nullptr) { - renderTimer->setTimerType(Qt::PreciseTimer); - /* TODO: need's more accuracy, maybe target 1ms earlier and spin yield */ - connect(renderTimer, &QTimer::timeout, this, &OpenGLRenderer::render); + connect(renderTimer, &QTimer::timeout, this, [this]() { this->render(); } ); + imagebufs[0] = std::unique_ptr(new uint8_t[2048 * 2048 * 4]); + imagebufs[1] = std::unique_ptr(new uint8_t[2048 * 2048 * 4]); - buf_usage = std::vector(BUFFERCOUNT); - for (auto &flag : buf_usage) - flag.clear(); - - setSurfaceType(QWindow::OpenGLSurface); + buf_usage = std::vector(2); + buf_usage[0].clear(); + buf_usage[1].clear(); QSurfaceFormat format; + setSurfaceType(QWindow::OpenGLSurface); + #ifdef Q_OS_MACOS format.setVersion(4, 1); #else @@ -62,58 +839,19 @@ OpenGLRenderer::OpenGLRenderer(QWidget *parent) if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES) format.setRenderableType(QSurfaceFormat::OpenGLES); + format.setSwapInterval(video_vsync ? 1 : 0); + setFormat(format); parentWidget = parent; - source.setRect(0, 0, INIT_WIDTH, INIT_HEIGHT); + source.setRect(0, 0, 100, 100); + isInitialized = false; + isFinalized = false; + context = nullptr; } -OpenGLRenderer::~OpenGLRenderer() -{ - finalize(); -} - -void -OpenGLRenderer::exposeEvent(QExposeEvent *event) -{ - Q_UNUSED(event); - - if (!isInitialized) - initialize(); - - onResize(size().width(), size().height()); -} - -void -OpenGLRenderer::resizeEvent(QResizeEvent *event) -{ - Q_UNUSED(event); - - onResize(event->size().width(), event->size().height()); - - if (notReady()) - return; - - context->makeCurrent(this); - - glViewport( - destination.x() * devicePixelRatio(), - destination.y() * devicePixelRatio(), - destination.width() * devicePixelRatio(), - destination.height() * devicePixelRatio()); -} - -bool -OpenGLRenderer::event(QEvent *event) -{ - Q_UNUSED(event); - - bool res = false; - if (!eventDelegate(event, res)) - return QWindow::event(event); - return res; -} +OpenGLRenderer::~OpenGLRenderer() { finalize(); } void OpenGLRenderer::initialize() @@ -134,10 +872,19 @@ OpenGLRenderer::initialize() if (version.first < 3) throw opengl_init_error(tr("OpenGL version 3.0 or greater is required. Current version is %1.%2").arg(version.first).arg(version.second)); - initializeOpenGLFunctions(); + glw.initializeOpenGLFunctions(); - /* Prepare the shader version string */ - glslVersion = reinterpret_cast(glGetString(GL_SHADING_LANGUAGE_VERSION)); + ogl3_log("OpenGL information: [%s] %s (%s)\n", glw.glGetString(GL_VENDOR), glw.glGetString(GL_RENDERER), glw.glGetString(GL_VERSION)); + glsl_version[0] = glsl_version[1] = -1; + glw.glGetIntegerv(GL_MAJOR_VERSION, &glsl_version[0]); + glw.glGetIntegerv(GL_MINOR_VERSION, &glsl_version[1]); + if (glsl_version[0] < 3) { + throw opengl_init_error(tr("OpenGL version 3.0 or greater is required. Current GLSL version is %1.%2").arg(glsl_version[0]).arg(glsl_version[1])); + } + ogl3_log("Using OpenGL %s\n", glw.glGetString(GL_VERSION)); + ogl3_log("Using Shading Language %s\n", glw.glGetString(GL_SHADING_LANGUAGE_VERSION)); + + glslVersion = reinterpret_cast(glw.glGetString(GL_SHADING_LANGUAGE_VERSION)); glslVersion.truncate(4); glslVersion.remove('.'); glslVersion.prepend("#version "); @@ -146,56 +893,221 @@ OpenGLRenderer::initialize() else if (context->format().profile() == QSurfaceFormat::CoreProfile) glslVersion.append(" core"); - initializeExtensions(); + glw.glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); + ogl3_log("Max texture size: %dx%d\n", max_texture_size, max_texture_size); - initializeBuffers(); + glw.glEnable(GL_TEXTURE_2D); - /* Vertex, texture 2d coordinates and color (white) making a quad as triangle strip */ - const GLfloat surface[] = { - -1.f, 1.f, 0.f, 0.f, 1.f, 1.f, 1.f, 1.f, - 1.f, 1.f, 1.f, 0.f, 1.f, 1.f, 1.f, 1.f, - -1.f, -1.f, 0.f, 1.f, 1.f, 1.f, 1.f, 1.f, - 1.f, -1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f - }; + //renderTimer->start(75); + if (video_framerate != -1) { + renderTimer->start(ceilf(1000.f / (float)video_framerate)); + } - glGenVertexArrays(1, &vertexArrayID); + scene_texture.data = NULL; + scene_texture.width = 2048; + scene_texture.height = 2048; + scene_texture.internal_format = GL_RGBA8; + scene_texture.format = GL_BGRA; + scene_texture.type = GL_UNSIGNED_INT_8_8_8_8_REV; + scene_texture.wrap_mode = GL_CLAMP_TO_BORDER; + scene_texture.min_filter = scene_texture.mag_filter = video_filter_method ? GL_LINEAR : GL_NEAREST; + scene_texture.mipmap = 0; - glBindVertexArray(vertexArrayID); + create_texture(&scene_texture); - glGenBuffers(1, &vertexBufferID); - glBindBuffer(GL_ARRAY_BUFFER, vertexBufferID); - glBufferData(GL_ARRAY_BUFFER, sizeof(surface), surface, GL_STATIC_DRAW); + /* load shader */ + // const char* shaders[1]; + // shaders[0] = gl3_shader_file; + // + // active_shader = load_shaders(1, shaders); - glGenTextures(1, &textureID); - glBindTexture(GL_TEXTURE_2D, textureID); + // const char* shaders[3]; + // shaders[0] = "/home/phantasy/git/glsl-shaders/ntsc/ntsc-320px.glslp"; + // shaders[1] = "/home/phantasy/git/glsl-shaders/motionblur/motionblur-simple.glslp"; + // shaders[2] = "/home/phantasy/git/glsl-shaders/crt/crt-lottes-multipass.glslp"; + // + // active_shader = load_shaders(3, shaders); + int num_shaders = 0; + for (int i = 0; i < MAX_USER_SHADERS; ++i) { + if (strlen(gl3_shader_file[i])) + ++num_shaders; + else + break; + } + active_shader = load_shaders(num_shaders, gl3_shader_file); - const GLfloat border_color[] = { 0.f, 0.f, 0.f, 1.f }; + create_scene_shader(); - glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, border_color); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + /* read config */ + read_shader_config(); - glTexImage2D(GL_TEXTURE_2D, 0, QOpenGLTexture::RGBA8_UNorm, INIT_WIDTH, INIT_HEIGHT, 0, QOpenGLTexture::BGRA, QOpenGLTexture::UInt32_RGBA8_Rev, NULL); + /* buffers */ - reloadOptions(); + GLfloat vertex[] = { -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f }; - glClearColor(0.f, 0.f, 0.f, 1.f); + GLfloat inv_vertex[] = { -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, -1.0f }; - glViewport( - destination.x() * devicePixelRatio(), - destination.y() * devicePixelRatio(), - destination.width() * devicePixelRatio(), - destination.height() * devicePixelRatio()); + GLfloat tex_coords[] = { 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f }; - GLenum error = glGetError(); - if (error != GL_NO_ERROR) - throw opengl_init_error(tr("OpenGL initialization failed. Error %1.").arg(error)); + GLfloat colors[] = { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f }; + + /* set the scene shader buffers */ + { + glw.glBindVertexArray(active_shader->scene.vertex_array); + + struct shader_vbo *vbo = &active_shader->scene.vbo; + + glw.glGenBuffers(1, (GLuint *) &vbo->vertex_coord); + glw.glBindBuffer(GL_ARRAY_BUFFER, vbo->vertex_coord); + glw.glBufferData(GL_ARRAY_BUFFER, sizeof(inv_vertex), inv_vertex, GL_STATIC_DRAW); + glw.glVertexAttribPointer(active_shader->scene.uniforms.vertex_coord, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), + (GLvoid *) 0); + + glw.glGenBuffers(1, (GLuint *) &vbo->tex_coord); + glw.glBindBuffer(GL_ARRAY_BUFFER, vbo->tex_coord); + glw.glBufferData(GL_ARRAY_BUFFER, sizeof(tex_coords), tex_coords, GL_DYNAMIC_DRAW); + glw.glVertexAttribPointer(active_shader->scene.uniforms.tex_coord, 2, GL_FLOAT, GL_TRUE, 2 * sizeof(GLfloat), + (GLvoid *) 0); + } + + /* set buffers for all passes */ + for (int j = 0; j < active_shader->num_shaders; ++j) { + struct glsl_shader *shader = &active_shader->shaders[j]; + for (int i = 0; i < shader->num_passes; ++i) { + struct shader_uniforms *u = &shader->passes[i].uniforms; + + glw.glBindVertexArray(shader->passes[i].vertex_array); + + struct shader_vbo *vbo = &shader->passes[i].vbo; + + glw.glGenBuffers(1, (GLuint *) &vbo->vertex_coord); + glw.glBindBuffer(GL_ARRAY_BUFFER, vbo->vertex_coord); + glw.glBufferData(GL_ARRAY_BUFFER, sizeof(vertex), vertex, GL_STATIC_DRAW); + + glw.glVertexAttribPointer(u->vertex_coord, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), (GLvoid *) 0); + + glw.glGenBuffers(1, (GLuint *) &vbo->tex_coord); + glw.glBindBuffer(GL_ARRAY_BUFFER, vbo->tex_coord); + glw.glBufferData(GL_ARRAY_BUFFER, sizeof(tex_coords), tex_coords, GL_DYNAMIC_DRAW); + glw.glVertexAttribPointer(u->tex_coord, 2, GL_FLOAT, GL_TRUE, 2 * sizeof(GLfloat), (GLvoid *) 0); + + if (u->color) { + glw.glGenBuffers(1, (GLuint *) &vbo->color); + glw.glBindBuffer(GL_ARRAY_BUFFER, vbo->color); + glw.glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors, GL_STATIC_DRAW); + glw.glVertexAttribPointer(u->color, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), (GLvoid *) 0); + } + } + } + + for (int i = 0; i < active_shader->num_shaders; ++i) { + struct glsl_shader *shader = &active_shader->shaders[i]; + if (shader->has_prev) { + struct shader_pass *prev_pass = &shader->prev_scene; + create_default_shader_tex(prev_pass); + + struct shader_vbo *vbo = &prev_pass->vbo; + + glw.glBindVertexArray(prev_pass->vertex_array); + + glw.glGenBuffers(1, (GLuint *) &vbo->vertex_coord); + glw.glBindBuffer(GL_ARRAY_BUFFER, vbo->vertex_coord); + glw.glBufferData(GL_ARRAY_BUFFER, sizeof(vertex), vertex, GL_STATIC_DRAW); + glw.glVertexAttribPointer(prev_pass->uniforms.vertex_coord, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), + (GLvoid *) 0); + + glw.glGenBuffers(1, (GLuint *) &vbo->tex_coord); + glw.glBindBuffer(GL_ARRAY_BUFFER, vbo->tex_coord); + glw.glBufferData(GL_ARRAY_BUFFER, sizeof(tex_coords), tex_coords, GL_DYNAMIC_DRAW); + glw.glVertexAttribPointer(prev_pass->uniforms.tex_coord, 2, GL_FLOAT, GL_TRUE, 2 * sizeof(GLfloat), + (GLvoid *) 0); + + for (int j = 0; j < MAX_PREV; ++j) { + struct shader_prev *prev = &shader->prev[j]; + struct shader_vbo *prev_vbo = &prev->vbo; + + glw.glGenBuffers(1, (GLuint *) &prev_vbo->vertex_coord); + glw.glBindBuffer(GL_ARRAY_BUFFER, prev_vbo->vertex_coord); + glw.glBufferData(GL_ARRAY_BUFFER, sizeof(vertex), vertex, GL_STATIC_DRAW); + + glw.glGenBuffers(1, (GLuint *) &prev_vbo->tex_coord); + glw.glBindBuffer(GL_ARRAY_BUFFER, prev_vbo->tex_coord); + glw.glBufferData(GL_ARRAY_BUFFER, sizeof(tex_coords), tex_coords, GL_DYNAMIC_DRAW); + } + } + } + + /* create final pass */ + if (active_shader->num_shaders == 0 || active_shader->shaders[active_shader->num_shaders - 1].passes[active_shader->shaders[active_shader->num_shaders - 1].num_passes - 1].fbo.id >= 0) { + struct shader_pass *final_pass = &active_shader->final_pass; + create_default_shader_tex(final_pass); + + glw.glBindVertexArray(final_pass->vertex_array); + + struct shader_vbo *vbo = &final_pass->vbo; + + glw.glGenBuffers(1, (GLuint *) &vbo->vertex_coord); + glw.glBindBuffer(GL_ARRAY_BUFFER, vbo->vertex_coord); + glw.glBufferData(GL_ARRAY_BUFFER, sizeof(vertex), vertex, GL_STATIC_DRAW); + glw.glVertexAttribPointer(final_pass->uniforms.vertex_coord, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), + (GLvoid *) 0); + + glw.glGenBuffers(1, (GLuint *) &vbo->tex_coord); + glw.glBindBuffer(GL_ARRAY_BUFFER, vbo->tex_coord); + glw.glBufferData(GL_ARRAY_BUFFER, sizeof(tex_coords), tex_coords, GL_DYNAMIC_DRAW); + glw.glVertexAttribPointer(final_pass->uniforms.tex_coord, 2, GL_FLOAT, GL_TRUE, 2 * sizeof(GLfloat), + (GLvoid *) 0); + } + + { + struct shader_pass *color_pass = &active_shader->fs_color; + create_default_shader_color(color_pass); + + glw.glBindVertexArray(color_pass->vertex_array); + + struct shader_vbo *vbo = &color_pass->vbo; + + glw.glGenBuffers(1, (GLuint *) &vbo->vertex_coord); + glw.glBindBuffer(GL_ARRAY_BUFFER, vbo->vertex_coord); + glw.glBufferData(GL_ARRAY_BUFFER, sizeof(vertex), vertex, GL_STATIC_DRAW); + glw.glVertexAttribPointer(color_pass->uniforms.vertex_coord, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), + (GLvoid *) 0); + + glw.glGenBuffers(1, (GLuint *) &vbo->color); + glw.glBindBuffer(GL_ARRAY_BUFFER, vbo->color); + glw.glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors, GL_DYNAMIC_DRAW); + glw.glVertexAttribPointer(color_pass->uniforms.color, 4, GL_FLOAT, GL_TRUE, 4 * sizeof(GLfloat), (GLvoid *) 0); + } +#ifdef SDL2_SHADER_DEBUG + struct shader_pass *debug_pass = &active_shader->debug; + create_default_shader(debug_pass); + + glw.glBindVertexArray(debug_pass->vertex_array); + + struct shader_vbo *vbo = &debug_pass->vbo; + + glw.glGenBuffers(1, &vbo->vertex_coord); + glw.glBindBuffer(GL_ARRAY_BUFFER, vbo->vertex_coord); + glw.glBufferData(GL_ARRAY_BUFFER, sizeof(vertex), vertex, GL_STATIC_DRAW); + glw.glVertexAttribPointer(debug_pass->uniforms.vertex_coord, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), (GLvoid *) 0); + + glw.glGenBuffers(1, &vbo->tex_coord); + glw.glBindBuffer(GL_ARRAY_BUFFER, vbo->tex_coord); + glw.glBufferData(GL_ARRAY_BUFFER, sizeof(tex_coords), tex_coords, GL_DYNAMIC_DRAW); + glw.glVertexAttribPointer(debug_pass->uniforms.tex_coord, 2, GL_FLOAT, GL_TRUE, 2 * sizeof(GLfloat), (GLvoid *) 0); +#endif + + glw.glBindBuffer(GL_ARRAY_BUFFER, 0); + glw.glBindVertexArray(0); isInitialized = true; + isFinalized = false; emit initialized(); - glClear(GL_COLOR_BUFFER_BIT); + glw.glClearColor(0, 0, 0, 1); + + glw.glClear(GL_COLOR_BUFFER_BIT); context->swapBuffers(this); } catch (const opengl_init_error &e) { @@ -203,7 +1115,7 @@ OpenGLRenderer::initialize() for (auto &flag : buf_usage) flag.test_and_set(); - QMessageBox::critical((QWidget *) qApp->findChild(), tr("Error initializing OpenGL"), e.what() % tr("\nFalling back to software rendering.")); + main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("Error initializing OpenGL"), e.what() + tr("\nFalling back to software rendering."), false); context->doneCurrent(); isFinalized = true; @@ -216,216 +1128,26 @@ OpenGLRenderer::initialize() void OpenGLRenderer::finalize() { - if (isFinalized) + if (isFinalized || !context) return; - renderTimer->stop(); - context->makeCurrent(this); - if (hasBufferStorage) - glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); + delete_texture(&scene_texture); - glDeleteBuffers(1, &unpackBufferID); - glDeleteTextures(1, &textureID); - glDeleteBuffers(1, &vertexBufferID); - glDeleteVertexArrays(1, &vertexArrayID); - - if (!hasBufferStorage && unpackBuffer) - free(unpackBuffer); + if (active_shader) { + delete_glsl(active_shader); + free(active_shader); + } + active_shader = NULL; context->doneCurrent(); + context = nullptr; + isFinalized = true; } -QDialog * -OpenGLRenderer::getOptions(QWidget *parent) -{ - auto dialog = new OpenGLOptionsDialog(parent, *options, [this]() { return new OpenGLOptions(this, false, glslVersion); }); - - connect(dialog, &OpenGLOptionsDialog::optionsChanged, this, &OpenGLRenderer::updateOptions); - - return dialog; -} - -void -OpenGLRenderer::initializeExtensions() -{ -#ifndef NO_BUFFER_STORAGE - if (context->hasExtension("GL_ARB_buffer_storage") || context->hasExtension("GL_EXT_buffer_storage")) { - hasBufferStorage = true; - - glBufferStorage = (PFNGLBUFFERSTORAGEEXTPROC_LOCAL) context->getProcAddress(context->hasExtension("GL_EXT_buffer_storage") ? "glBufferStorageEXT" : "glBufferStorage"); - if (!glBufferStorage) - glBufferStorage = (PFNGLBUFFERSTORAGEEXTPROC_LOCAL) context->getProcAddress("glBufferStorage"); - } -#endif -} - -void -OpenGLRenderer::initializeBuffers() -{ - glGenBuffers(1, &unpackBufferID); - - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBufferID); - - if (hasBufferStorage) { -#ifndef NO_BUFFER_STORAGE - /* Create persistent buffer for pixel transfer. */ - glBufferStorage(GL_PIXEL_UNPACK_BUFFER, BUFFERBYTES * BUFFERCOUNT, NULL, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT); - - unpackBuffer = glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, BUFFERBYTES * BUFFERCOUNT, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT); -#endif - } else { - /* Fallback; create our own buffer. */ - unpackBuffer = malloc(BUFFERBYTES * BUFFERCOUNT); - - if (unpackBuffer == nullptr) - throw opengl_init_error(tr("Allocating memory for unpack buffer failed.")); - - glBufferData(GL_PIXEL_UNPACK_BUFFER, BUFFERBYTES * BUFFERCOUNT, NULL, GL_STREAM_DRAW); - } -} - -void -OpenGLRenderer::applyOptions() -{ - /* TODO: change detection in options */ - - if (options->framerate() > 0) { - int interval = (int) ceilf(1000.f / (float) options->framerate()); - renderTimer->setInterval(std::chrono::milliseconds(interval)); - } - - if (options->renderBehavior() == OpenGLOptions::TargetFramerate) - renderTimer->start(); - else - renderTimer->stop(); - - auto format = this->format(); - int interval = options->vSync() ? 1 : 0; - - if (format.swapInterval() != interval) { - format.setSwapInterval(interval); - setFormat(format); - context->setFormat(format); - } - - GLint filter = options->filter() == OpenGLOptions::Linear ? GL_LINEAR : GL_NEAREST; - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); - - currentFilter = options->filter(); -} - -void -OpenGLRenderer::reloadOptions() -{ - if (options) { - delete options; - options = nullptr; - } - options = new OpenGLOptions(this, true, glslVersion); - - applyOptions(); -} - -void -OpenGLRenderer::applyShader(const OpenGLShaderPass &shader) -{ - if (!shader.bind()) - return; - - if (shader.vertex_coord() != -1) { - glEnableVertexAttribArray(shader.vertex_coord()); - glVertexAttribPointer(shader.vertex_coord(), 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), 0); - } - - if (shader.tex_coord() != -1) { - glEnableVertexAttribArray(shader.tex_coord()); - glVertexAttribPointer(shader.tex_coord(), 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (void *) (2 * sizeof(GLfloat))); - } - - if (shader.color() != -1) { - glEnableVertexAttribArray(shader.color()); - glVertexAttribPointer(shader.color(), 4, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (void *) (4 * sizeof(GLfloat))); - } - - if (shader.mvp_matrix() != -1) { - static const GLfloat mvp[] = { - 1.f, 0.f, 0.f, 0.f, - 0.f, 1.f, 0.f, 0.f, - 0.f, 0.f, 1.f, 0.f, - 0.f, 0.f, 0.f, 1.f - }; - glUniformMatrix4fv(shader.mvp_matrix(), 1, GL_FALSE, mvp); - } - - if (shader.output_size() != -1) - glUniform2f(shader.output_size(), destination.width(), destination.height()); - - if (shader.input_size() != -1) - glUniform2f(shader.input_size(), source.width(), source.height()); - - if (shader.texture_size() != -1) - glUniform2f(shader.texture_size(), source.width(), source.height()); - - if (shader.frame_count() != -1) - glUniform1i(shader.frame_count(), frameCounter); -} - -void -OpenGLRenderer::render() -{ - context->makeCurrent(this); - - if (options->filter() != currentFilter) - applyOptions(); - - /* TODO: multiple shader passes */ - applyShader(options->shaders().first()); - - glClear(GL_COLOR_BUFFER_BIT); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - - context->swapBuffers(this); - - frameCounter = (frameCounter + 1) & 1023; -} - -void -OpenGLRenderer::updateOptions(OpenGLOptions *newOptions) -{ - context->makeCurrent(this); - - glUseProgram(0); - - delete options; - - options = newOptions; - - options->setParent(this); - - applyOptions(); -} - -std::vector> -OpenGLRenderer::getBuffers() -{ - std::vector> buffers; - - if (notReady() || !unpackBuffer) - return buffers; - - /* Split the buffer area */ - for (int i = 0; i < BUFFERCOUNT; i++) { - buffers.push_back(std::make_tuple((uint8_t *) unpackBuffer + BUFFERBYTES * i, &buf_usage[i])); - } - - return buffers; -} - void OpenGLRenderer::onBlit(int buf_idx, int x, int y, int w, int h) { @@ -434,35 +1156,574 @@ OpenGLRenderer::onBlit(int buf_idx, int x, int y, int w, int h) context->makeCurrent(this); -#ifdef Q_OS_MACOS - glViewport( - destination.x() * devicePixelRatio(), - destination.y() * devicePixelRatio(), - destination.width() * devicePixelRatio(), - destination.height() * devicePixelRatio()); -#endif - if (source.width() != w || source.height() != h) { - source.setRect(0, 0, w, h); - - /* Resize the texture */ - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); - glTexImage2D(GL_TEXTURE_2D, 0, (GLenum) QOpenGLTexture::RGBA8_UNorm, source.width(), source.height(), 0, (GLenum) QOpenGLTexture::BGRA, (GLenum) QOpenGLTexture::UInt32_RGBA8_Rev, NULL); - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBufferID); + glw.glBindTexture(GL_TEXTURE_2D, scene_texture.id); + glw.glTexImage2D(GL_TEXTURE_2D, 0, (GLenum) QOpenGLTexture::RGBA8_UNorm, w, h, 0, (GLenum) QOpenGLTexture::BGRA, (GLenum) QOpenGLTexture::UInt32_RGBA8_Rev, NULL); + glw.glBindTexture(GL_TEXTURE_2D, 0); } - if (!hasBufferStorage) - glBufferSubData(GL_PIXEL_UNPACK_BUFFER, BUFFERBYTES * buf_idx, h * ROW_LENGTH * sizeof(uint32_t) + (y * ROW_LENGTH * sizeof(uint32_t)), (uint8_t *) unpackBuffer + BUFFERBYTES * buf_idx); + source.setRect(x, y, w, h); - glPixelStorei(GL_UNPACK_SKIP_PIXELS, BUFFERPIXELS * buf_idx + y * ROW_LENGTH + x); - glPixelStorei(GL_UNPACK_ROW_LENGTH, ROW_LENGTH); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, (GLenum) QOpenGLTexture::BGRA, (GLenum) QOpenGLTexture::UInt32_RGBA8_Rev, NULL); - - /* TODO: check if fence sync is implementable here and still has any benefit. */ - glFinish(); + glw.glBindTexture(GL_TEXTURE_2D, scene_texture.id); + glw.glPixelStorei(GL_UNPACK_ROW_LENGTH, 2048); + glw.glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, (GLenum) QOpenGLTexture::BGRA, (GLenum) QOpenGLTexture::UInt32_RGBA8_Rev, (const void *) ((uintptr_t) imagebufs[buf_idx].get() + (uintptr_t) (2048 * 4 * y + x * 4))); + glw.glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glw.glBindTexture(GL_TEXTURE_2D, 0); buf_usage[buf_idx].clear(); + source.setRect(x, y, w, h); + this->pixelRatio = devicePixelRatio(); + onResize(this->width(), this->height()); - if (options->renderBehavior() == OpenGLOptions::SyncWithVideo) +#ifdef Q_OS_MACOS + glw.glViewport( + destination.x(), + destination.y(), + destination.width(), + destination.height()); +#endif + + if (video_framerate == -1) render(); } + +std::vector> +OpenGLRenderer::getBuffers() +{ + std::vector> buffers; + + buffers.push_back(std::make_tuple(imagebufs[0].get(), &buf_usage[0])); + buffers.push_back(std::make_tuple(imagebufs[1].get(), &buf_usage[1])); + + return buffers; +} + +void +OpenGLRenderer::exposeEvent(QExposeEvent *event) +{ + Q_UNUSED(event); + + if (!isInitialized) + initialize(); + + this->pixelRatio = devicePixelRatio(); + onResize(size().width(), size().height()); +} + +void +OpenGLRenderer::resizeEvent(QResizeEvent *event) +{ + Q_UNUSED(event); + + this->pixelRatio = devicePixelRatio(); + onResize(event->size().width(), event->size().height()); + + if (notReady()) + return; + + context->makeCurrent(this); + + glw.glViewport( + destination.x(), + destination.y(), + destination.width(), + destination.height()); +} + +void +OpenGLRenderer::render_pass(struct render_data *data) +{ + int i; + GLuint texture_unit = 0; + + // ogl3_log("pass %d: %gx%g, %gx%g -> %gx%g, %gx%g, %gx%g\n", num_pass, pass->state.input_size[0], + // pass->state.input_size[1], pass->state.input_texture_size[0], pass->state.input_texture_size[1], + // pass->state.output_size[0], pass->state.output_size[1], pass->state.output_texture_size[0], + // pass->state.output_texture_size[1], output_size[0], output_size[1]); + + glw.glBindVertexArray(data->shader_pass->vertex_array); + + GLint p = data->shader_pass->program.id; + struct shader_uniforms *u = &data->shader_pass->uniforms; + + glw.glUseProgram(p); + + if (data->texture) { + glw.glActiveTexture(GL_TEXTURE0 + texture_unit); + glw.glBindTexture(GL_TEXTURE_2D, data->texture); + glw.glUniform1i(u->texture, texture_unit); + texture_unit++; + } + + if (u->color >= 0) + glw.glEnableVertexAttribArray(u->color); + + if (u->mvp_matrix >= 0) + glw.glUniformMatrix4fv(u->mvp_matrix, 1, 0, matrix); + if (u->frame_direction >= 0) + glw.glUniform1i(u->frame_direction, 1); + + int framecnt = data->frame_count; + if (data->shader_pass->frame_count_mod > 0) + framecnt = framecnt % data->shader_pass->frame_count_mod; + if (u->frame_count >= 0) + glw.glUniform1i(u->frame_count, framecnt); + + if (u->input_size >= 0) + glw.glUniform2fv(u->input_size, 1, data->shader_pass->state.input_size); + if (u->texture_size >= 0) + glw.glUniform2fv(u->texture_size, 1, data->shader_pass->state.input_texture_size); + if (u->output_size >= 0) + glw.glUniform2fv(u->output_size, 1, data->output_size); + + if (data->shader) { + /* parameters */ + for (i = 0; i < data->shader->num_parameters; ++i) + if (u->parameters[i] >= 0) + glw.glUniform1f(u->parameters[i], data->shader->parameters[i].value); + + if (data->pass > 0) { + struct shader_pass *passes = data->shader->passes; + struct shader_pass *orig = data->orig_pass; + if (u->orig.texture >= 0) { + glw.glActiveTexture(GL_TEXTURE0 + texture_unit); + glw.glBindTexture(GL_TEXTURE_2D, orig->fbo.texture.id); + glw.glUniform1i(u->orig.texture, texture_unit); + texture_unit++; + } + if (u->orig.input_size >= 0) + glw.glUniform2fv(u->orig.input_size, 1, orig->state.input_size); + if (u->orig.texture_size >= 0) + glw.glUniform2fv(u->orig.texture_size, 1, orig->state.input_texture_size); + + for (i = 0; i < data->pass; ++i) { + if (u->pass[i].texture >= 0) { + glw.glActiveTexture(GL_TEXTURE0 + texture_unit); + glw.glBindTexture(GL_TEXTURE_2D, passes[i].fbo.texture.id); + glw.glUniform1i(u->pass[i].texture, texture_unit); + texture_unit++; + } + if (u->pass[i].texture_size >= 0) + glw.glUniform2fv(u->pass[i].texture_size, 1, passes[i].state.input_texture_size); + if (u->pass[i].input_size >= 0) + glw.glUniform2fv(u->pass[i].input_size, 1, passes[i].state.input_size); + + if (u->prev_pass[i].texture >= 0) { + glw.glActiveTexture(GL_TEXTURE0 + texture_unit); + glw.glBindTexture(GL_TEXTURE_2D, passes[i].fbo.texture.id); + glw.glUniform1i(u->prev_pass[i].texture, texture_unit); + texture_unit++; + } + if (u->prev_pass[i].texture_size >= 0) + glw.glUniform2fv(u->prev_pass[i].texture_size, 1, passes[i].state.input_texture_size); + if (u->prev_pass[i].input_size >= 0) + glw.glUniform2fv(u->prev_pass[i].input_size, 1, passes[i].state.input_size); + } + } + + if (data->shader->has_prev) { + /* loop through each previous frame */ + for (i = 0; i < MAX_PREV; ++i) { + if (u->prev[i].texture >= 0) { + glw.glActiveTexture(GL_TEXTURE0 + texture_unit); + glw.glBindTexture(GL_TEXTURE_2D, data->shader->prev[i].fbo.texture.id); + glw.glUniform1i(u->prev[i].texture, texture_unit); + texture_unit++; + } + if (u->prev[i].tex_coord >= 0) { + glw.glBindBuffer(GL_ARRAY_BUFFER, data->shader->prev[i].vbo.tex_coord); + glw.glVertexAttribPointer(u->prev[i].tex_coord, 2, GL_FLOAT, GL_TRUE, + 2 * sizeof(GLfloat), (GLvoid *) 0); + glw.glEnableVertexAttribArray(u->prev[i].tex_coord); + glw.glBindBuffer(GL_ARRAY_BUFFER, 0); + } + } + } + + for (i = 0; i < data->shader->num_lut_textures; ++i) { + if (u->lut_textures[i] >= 0) { + glw.glActiveTexture(GL_TEXTURE0 + texture_unit); + glw.glBindTexture(GL_TEXTURE_2D, data->shader->lut_textures[i].texture.id); + glw.glUniform1i(u->lut_textures[i], texture_unit); + texture_unit++; + } + } + } + + glw.glEnableVertexAttribArray(u->vertex_coord); + glw.glEnableVertexAttribArray(u->tex_coord); + + glw.glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + + glw.glActiveTexture(GL_TEXTURE0); + glw.glBindTexture(GL_TEXTURE_2D, 0); + + glw.glDisableVertexAttribArray(data->shader_pass->uniforms.vertex_coord); + glw.glDisableVertexAttribArray(data->shader_pass->uniforms.tex_coord); + if (data->shader_pass->uniforms.color >= 0) + glw.glDisableVertexAttribArray(data->shader_pass->uniforms.color); + + if (data->shader && data->shader->has_prev) { + for (i = 0; i < MAX_PREV; ++i) { + if (u->prev[i].tex_coord >= 0) + glw.glDisableVertexAttribArray(u->prev[i].tex_coord); + } + } + + glw.glBindVertexArray(0); + + glw.glUseProgram(0); +} + +bool +OpenGLRenderer::event(QEvent *event) +{ + Q_UNUSED(event); + + bool res = false; + if (!eventDelegate(event, res)) + return QWindow::event(event); + return res; +} + +QDialog* +OpenGLRenderer::getOptions(QWidget *parent) +{ + return new OpenGLShaderManagerDialog(parent); +} + +void +OpenGLRenderer::render() +{ + if (!context) + return; + + if (notReady()) + return; + + int s, i, j; + + struct { + uint32_t x, y, w, h; + } window_rect; + + window_rect.x = destination.x(); + window_rect.y = destination.y(); + window_rect.w = destination.width(); + window_rect.h = destination.height(); + + glw.glBindTexture(GL_TEXTURE_2D, scene_texture.id); + scene_texture.min_filter = scene_texture.mag_filter = video_filter_method ? GL_LINEAR : GL_NEAREST; + active_shader->scene.fbo.texture.min_filter = active_shader->scene.fbo.texture.mag_filter = video_filter_method ? GL_LINEAR : GL_NEAREST; + glw.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, video_filter_method ? GL_LINEAR : GL_NEAREST); + glw.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, video_filter_method ? GL_LINEAR : GL_NEAREST); + glw.glBindTexture(GL_TEXTURE_2D, active_shader->scene.fbo.texture.id); + glw.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, video_filter_method ? GL_LINEAR : GL_NEAREST); + glw.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, video_filter_method ? GL_LINEAR : GL_NEAREST); + glw.glBindTexture(GL_TEXTURE_2D, 0); + + GLfloat orig_output_size[] = { (GLfloat)window_rect.w, (GLfloat)window_rect.h }; + + if (active_shader->srgb) + glw.glEnable(GL_FRAMEBUFFER_SRGB); + + struct render_data data; + + /* render scene to texture */ + { + struct shader_pass *pass = &active_shader->scene; + + struct { + uint32_t x, y, w, h; + } rect; + rect.x = 0; + rect.y = 0; + rect.w = source.width(); + rect.h = source.height(); + + pass->state.input_size[0] = pass->state.output_size[0] = rect.w; + pass->state.input_size[1] = pass->state.output_size[1] = rect.h; + + pass->state.input_texture_size[0] = pass->state.output_texture_size[0] = next_pow2(pass->state.output_size[0]); + pass->state.input_texture_size[1] = pass->state.output_texture_size[1] = next_pow2(pass->state.output_size[1]); + + recreate_fbo(&active_shader->scene.fbo, pass->state.output_texture_size[0], pass->state.output_texture_size[1]); + + glw.glBindFramebuffer(GL_FRAMEBUFFER, active_shader->scene.fbo.id); + glw.glClearColor(0, 0, 0, 1); + glw.glClear(GL_COLOR_BUFFER_BIT); + + glw.glViewport(0, 0, pass->state.output_size[0], pass->state.output_size[1]); + + GLfloat minx = 0; + GLfloat miny = 0; + GLfloat maxx = pass->state.output_size[0] / (GLfloat) pass->state.output_texture_size[0]; + GLfloat maxy = pass->state.output_size[1] / (GLfloat) pass->state.output_texture_size[1]; + + pass->state.tex_coords[0] = minx; + pass->state.tex_coords[1] = miny; + pass->state.tex_coords[2] = minx; + pass->state.tex_coords[3] = maxy; + pass->state.tex_coords[4] = maxx; + pass->state.tex_coords[5] = miny; + pass->state.tex_coords[6] = maxx; + pass->state.tex_coords[7] = maxy; + + // create input tex coords + minx = 0; + miny = 0; + maxx = 1; + maxy = 1; + + GLfloat tex_coords[] = { minx, miny, minx, maxy, maxx, miny, maxx, maxy }; + + glw.glBindVertexArray(pass->vertex_array); + + glw.glBindBuffer(GL_ARRAY_BUFFER, pass->vbo.tex_coord); + glw.glBufferSubData(GL_ARRAY_BUFFER, 0, 8 * sizeof(GLfloat), tex_coords); + glw.glBindBuffer(GL_ARRAY_BUFFER, 0); + + memset(&data, 0, sizeof(struct render_data)); + data.pass = -1; + data.shader_pass = &active_shader->scene; + data.texture = scene_texture.id; + data.output_size = orig_output_size; + render_pass(&data); + + glw.glBindFramebuffer(GL_FRAMEBUFFER, 0); + } + + struct shader_pass *orig = &active_shader->scene; + struct shader_pass *input = &active_shader->scene; + + for (s = 0; s < active_shader->num_shaders; ++s) { + struct glsl_shader *shader = &active_shader->shaders[s]; + + int frame_count = frameCounter; + + /* loop through each pass */ + for (i = 0; i < shader->num_passes; ++i) { + bool resetFiltering = false; + struct shader_pass *pass = &shader->passes[i]; + + memcpy(pass->state.input_size, input->state.output_size, 2 * sizeof(GLfloat)); + memcpy(pass->state.input_texture_size, input->state.output_texture_size, 2 * sizeof(GLfloat)); + + for (j = 0; j < 2; ++j) { + if (pass->scale.mode[j] == SCALE_VIEWPORT) + pass->state.output_size[j] = orig_output_size[j] * pass->scale.value[j]; + else if (pass->scale.mode[j] == SCALE_ABSOLUTE) + pass->state.output_size[j] = pass->scale.value[j]; + else + pass->state.output_size[j] = pass->state.input_size[j] * pass->scale.value[j]; + + pass->state.output_texture_size[j] = next_pow2(pass->state.output_size[j]); + } + + if (pass->fbo.id >= 0) { + recreate_fbo(&pass->fbo, pass->state.output_texture_size[0], pass->state.output_texture_size[1]); + + glw.glBindFramebuffer(GL_FRAMEBUFFER, pass->fbo.id); + glw.glViewport(0, 0, pass->state.output_size[0], pass->state.output_size[1]); + } else { + resetFiltering = true; + glw.glBindTexture(GL_TEXTURE_2D, input->fbo.texture.id); + glw.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, video_filter_method ? GL_LINEAR : GL_NEAREST); + glw.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, video_filter_method ? GL_LINEAR : GL_NEAREST); + glw.glBindTexture(GL_TEXTURE_2D, 0); + glw.glViewport(window_rect.x, window_rect.y, window_rect.w, window_rect.h); + } + + glw.glClearColor(0, 0, 0, 1); + glw.glClear(GL_COLOR_BUFFER_BIT); + + GLfloat minx = 0; + GLfloat miny = 0; + GLfloat maxx = pass->state.output_size[0] / (GLfloat) pass->state.output_texture_size[0]; + GLfloat maxy = pass->state.output_size[1] / (GLfloat) pass->state.output_texture_size[1]; + + pass->state.tex_coords[0] = minx; + pass->state.tex_coords[1] = miny; + pass->state.tex_coords[2] = minx; + pass->state.tex_coords[3] = maxy; + pass->state.tex_coords[4] = maxx; + pass->state.tex_coords[5] = miny; + pass->state.tex_coords[6] = maxx; + pass->state.tex_coords[7] = maxy; + + glw.glBindVertexArray(pass->vertex_array); + + glw.glBindBuffer(GL_ARRAY_BUFFER, pass->vbo.tex_coord); + glw.glBufferSubData(GL_ARRAY_BUFFER, 0, 8 * sizeof(GLfloat), input->state.tex_coords); + glw.glBindBuffer(GL_ARRAY_BUFFER, 0); + + memset(&data, 0, sizeof(struct render_data)); + data.shader = shader; + data.pass = i; + data.shader_pass = pass; + data.texture = input->fbo.texture.id; + data.output_size = orig_output_size; + data.orig_pass = orig; + data.frame_count = frame_count; + + render_pass(&data); + + glw.glBindFramebuffer(GL_FRAMEBUFFER, 0); + + if (pass->fbo.texture.mipmap) { + glw.glActiveTexture(GL_TEXTURE0); + glw.glBindTexture(GL_TEXTURE_2D, pass->fbo.texture.id); + glw.glGenerateMipmap(GL_TEXTURE_2D); + glw.glBindTexture(GL_TEXTURE_2D, 0); + } + + if (resetFiltering) { + glw.glBindTexture(GL_TEXTURE_2D, input->fbo.texture.id); + glw.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, input->fbo.texture.min_filter); + glw.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, input->fbo.texture.mag_filter); + glw.glBindTexture(GL_TEXTURE_2D, 0); + } + + input = pass; + } + + if (shader->has_prev) { + /* shift array */ + memmove(&shader->prev[1], &shader->prev[0], MAX_PREV * sizeof(struct shader_prev)); + memcpy(&shader->prev[0], &shader->prev[MAX_PREV], sizeof(struct shader_prev)); + + struct shader_pass *pass = orig; + struct shader_pass *prev_pass = &shader->prev_scene; + struct shader_prev *prev = &shader->prev[0]; + + memcpy(&prev_pass->state, &pass->state, sizeof(struct shader_state)); + + recreate_fbo(&prev->fbo, prev_pass->state.output_texture_size[0], + prev_pass->state.output_texture_size[1]); + + memcpy(&prev_pass->fbo, &prev->fbo, sizeof(struct shader_fbo)); + + glw.glBindFramebuffer(GL_FRAMEBUFFER, prev->fbo.id); + glw.glClearColor(0, 0, 0, 1); + glw.glClear(GL_COLOR_BUFFER_BIT); + + glw.glViewport(0, 0, pass->state.output_size[0], pass->state.output_size[1]); + + glw.glBindVertexArray(prev_pass->vertex_array); + + glw.glBindBuffer(GL_ARRAY_BUFFER, prev->vbo.tex_coord); + glw.glBufferSubData(GL_ARRAY_BUFFER, 0, 8 * sizeof(GLfloat), pass->state.tex_coords); + glw.glBindBuffer(GL_ARRAY_BUFFER, 0); + + glw.glBindBuffer(GL_ARRAY_BUFFER, prev_pass->vbo.tex_coord); + glw.glBufferSubData(GL_ARRAY_BUFFER, 0, 8 * sizeof(GLfloat), pass->state.tex_coords); + glw.glBindBuffer(GL_ARRAY_BUFFER, 0); + + memset(&data, 0, sizeof(struct render_data)); + data.shader = shader; + data.pass = -10; + data.shader_pass = prev_pass; + data.texture = pass->fbo.texture.id; + data.output_size = orig_output_size; + + render_pass(&data); + + glw.glBindFramebuffer(GL_FRAMEBUFFER, 0); + } + + orig = input; + } + + if (active_shader->final_pass.active) { + struct shader_pass *pass = &active_shader->final_pass; + + memcpy(pass->state.input_size, input->state.output_size, 2 * sizeof(GLfloat)); + memcpy(pass->state.input_texture_size, input->state.output_texture_size, 2 * sizeof(GLfloat)); + + for (j = 0; j < 2; ++j) { + if (pass->scale.mode[j] == SCALE_VIEWPORT) + pass->state.output_size[j] = orig_output_size[j] * pass->scale.value[j]; + else if (pass->scale.mode[j] == SCALE_ABSOLUTE) + pass->state.output_size[j] = pass->scale.value[j]; + else + pass->state.output_size[j] = pass->state.input_size[j] * pass->scale.value[j]; + + pass->state.output_texture_size[j] = next_pow2(pass->state.output_size[j]); + } + + glw.glBindTexture(GL_TEXTURE_2D, input->fbo.texture.id); + glw.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, video_filter_method ? GL_LINEAR : GL_NEAREST); + glw.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, video_filter_method ? GL_LINEAR : GL_NEAREST); + glw.glBindTexture(GL_TEXTURE_2D, 0); + + glw.glViewport(window_rect.x, window_rect.y, window_rect.w, window_rect.h); + + glw.glClearColor(0, 0, 0, 1); + glw.glClear(GL_COLOR_BUFFER_BIT); + + GLfloat minx = 0; + GLfloat miny = 0; + GLfloat maxx = pass->state.output_size[0] / (GLfloat) pass->state.output_texture_size[0]; + GLfloat maxy = pass->state.output_size[1] / (GLfloat) pass->state.output_texture_size[1]; + + pass->state.tex_coords[0] = minx; + pass->state.tex_coords[1] = miny; + pass->state.tex_coords[2] = minx; + pass->state.tex_coords[3] = maxy; + pass->state.tex_coords[4] = maxx; + pass->state.tex_coords[5] = miny; + pass->state.tex_coords[6] = maxx; + pass->state.tex_coords[7] = maxy; + + glw.glBindVertexArray(pass->vertex_array); + + glw.glBindBuffer(GL_ARRAY_BUFFER, pass->vbo.tex_coord); + glw.glBufferSubData(GL_ARRAY_BUFFER, 0, 8 * sizeof(GLfloat), input->state.tex_coords); + glw.glBindBuffer(GL_ARRAY_BUFFER, 0); + + memset(&data, 0, sizeof(struct render_data)); + data.pass = -2; + data.shader_pass = pass; + data.texture = input->fbo.texture.id; + data.output_size = orig_output_size; + data.orig_pass = orig; + + render_pass(&data); + } + + if (monitors[r_monitor_index].mon_screenshots) { + int width = destination.width(), height = destination.height(); + char path[1024]; + char fn[256]; + + memset(fn, 0, sizeof(fn)); + memset(path, 0, sizeof(path)); + + path_append_filename(path, usr_path, SCREENSHOT_PATH); + + if (!plat_dir_check(path)) + plat_dir_create(path); + + path_slash(path); + strcat(path, "Monitor_"); + snprintf(&path[strlen(path)], 42, "%d_", r_monitor_index + 1); + + plat_tempfile(fn, NULL, (char*)".png"); + strcat(path, fn); + + unsigned char *rgba = (unsigned char *)calloc(1, width * height * 4); + + glw.glFinish(); + glw.glReadPixels(window_rect.x, window_rect.y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, rgba); + + QImage image(rgba, width, height, QImage::Format_RGBA8888); + image.mirrored(false, true).save(path, "png"); + monitors[r_monitor_index].mon_screenshots--; + free(rgba); + } + + glw.glDisable(GL_FRAMEBUFFER_SRGB); + + frameCounter++; + context->swapBuffers(this); +} diff --git a/src/qt/qt_openglrenderer.hpp b/src/qt/qt_openglrenderer.hpp index 27822600c..4d1f68acb 100644 --- a/src/qt/qt_openglrenderer.hpp +++ b/src/qt/qt_openglrenderer.hpp @@ -11,12 +11,14 @@ * * * Authors: Teemu Korhonen + * Cacodemon345 * * Copyright 2022 Teemu Korhonen + * Copyright 2025 Cacodemon345 */ -#ifndef QT_OPENGLRENDERER_HPP -#define QT_OPENGLRENDERER_HPP +#ifndef QT_OpenGLRenderer_HPP +#define QT_OpenGLRenderer_HPP #if defined Q_OS_MACOS || __arm__ # define NO_BUFFER_STORAGE @@ -37,12 +39,24 @@ #include #include -#include "qt_opengloptions.hpp" #include "qt_renderercommon.hpp" -typedef void(QOPENGLF_APIENTRYP PFNGLBUFFERSTORAGEEXTPROC_LOCAL)(GLenum target, GLsizeiptr size, const void *data, GLbitfield flags); +extern "C" +{ +#include <86box/qt-glslp-parser.h> +} -class OpenGLRenderer : public QWindow, protected QOpenGLExtraFunctions, public RendererCommon { +struct render_data { + int pass; + struct glsl_shader *shader; + struct shader_pass *shader_pass; + GLfloat *output_size; + struct shader_pass *orig_pass; + GLint texture; + int frame_count; +}; + +class OpenGLRenderer : public QWindow, public RendererCommon { Q_OBJECT public: @@ -56,7 +70,7 @@ public: void finalize() override final; bool hasOptions() const override { return true; } QDialog *getOptions(QWidget *parent) override; - void reloadOptions() override; + bool reloadRendererOption() override { return true; } signals: void initialized(); @@ -71,47 +85,64 @@ protected: bool event(QEvent *event) override; private: - static constexpr int INIT_WIDTH = 640; - static constexpr int INIT_HEIGHT = 400; - static constexpr int ROW_LENGTH = 2048; - static constexpr int BUFFERPIXELS = 4194304; - static constexpr int BUFFERBYTES = 16777216; /* Pixel is 4 bytes. */ - static constexpr int BUFFERCOUNT = 3; /* How many buffers to use for pixel transfer (2-3 is commonly recommended). */ + + std::array, 2> imagebufs; QTimer *renderTimer; - OpenGLOptions *options; - QString glslVersion; + QString glslVersion = ""; bool isInitialized = false; bool isFinalized = false; - GLuint unpackBufferID = 0; - GLuint vertexArrayID = 0; - GLuint vertexBufferID = 0; - GLuint textureID = 0; - int frameCounter = 0; + int max_texture_size = 65536; + int frameCounter = 0; - OpenGLOptions::FilterType currentFilter; + QOpenGLExtraFunctions glw; + struct shader_texture scene_texture; + glsl_t *active_shader; void *unpackBuffer = nullptr; + int glsl_version[2] = { 0, 0 }; + void initialize(); void initializeExtensions(); void initializeBuffers(); void applyOptions(); - void applyShader(const OpenGLShaderPass &shader); - bool notReady() const { return !isInitialized || isFinalized; } + + void create_scene_shader(); + void create_texture(struct shader_texture *tex); + void create_fbo(struct shader_fbo *fbo); + void recreate_fbo(struct shader_fbo *fbo, int width, int height); + void setup_fbo(struct shader *shader, struct shader_fbo *fbo); - /* GL_ARB_buffer_storage */ - bool hasBufferStorage = false; -#ifndef NO_BUFFER_STORAGE - PFNGLBUFFERSTORAGEEXTPROC_LOCAL glBufferStorage = nullptr; -#endif + bool notReady() const { return !isInitialized || isFinalized; } + glsl_t* load_glslp(glsl_t *glsl, int num_shader, const char *f); + glsl_t* load_shaders(int num, char shaders[MAX_USER_SHADERS][512]); + int compile_shader(GLenum shader_type, const char *prepend, const char *program, int *dst); + int create_default_shader_tex(struct shader_pass *pass); + int create_default_shader_color(struct shader_pass *pass); + int create_program(struct shader_program *program); + + GLuint get_uniform(GLuint program, const char *name); + GLuint get_attrib(GLuint program, const char *name); + + void find_uniforms(struct glsl_shader *glsl, int num_pass); + void delete_texture(struct shader_texture *tex); + void delete_fbo(struct shader_fbo *fbo); + void delete_program(struct shader_program *program); + void delete_vbo(struct shader_vbo *vbo); + void delete_pass(struct shader_pass *pass); + void delete_prev(struct shader_prev *prev); + void delete_shader(struct glsl_shader *glsl); + void delete_glsl(glsl_t *glsl); + void read_shader_config(); + + void render_pass(struct render_data *data); private slots: void render(); - void updateOptions(OpenGLOptions *newOptions); }; class opengl_init_error : public std::runtime_error { diff --git a/src/qt/qt_openglshaderconfig.cpp b/src/qt/qt_openglshaderconfig.cpp new file mode 100644 index 000000000..25f9d38a8 --- /dev/null +++ b/src/qt/qt_openglshaderconfig.cpp @@ -0,0 +1,85 @@ +#include "qt_openglshaderconfig.hpp" +#include "ui_qt_openglshaderconfig.h" + +#include "qt_mainwindow.hpp" + +extern MainWindow* main_window; + +extern "C" +{ +#include <86box/86box.h> +#include <86box/plat.h> +#include <86box/config.h> +} + +OpenGLShaderConfig::OpenGLShaderConfig(QWidget *parent, glslp_t* shader) + : QDialog(parent) + , ui(new Ui::OpenGLShaderConfig) +{ + ui->setupUi(this); + + currentShader = shader; + + connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); + + glslp_read_shader_config(currentShader); + + for (int i = 0; i < currentShader->num_parameters; i++) { + auto spinBox = new QDoubleSpinBox; + spinBox->setObjectName(currentShader->parameters[i].id); + spinBox->setRange(currentShader->parameters[i].min, currentShader->parameters[i].max); + spinBox->setValue(currentShader->parameters[i].value); + spinBox->setSingleStep(currentShader->parameters[i].step); + QFormLayout* layout = (QFormLayout*)ui->scrollAreaWidgetContents->layout(); + layout->addRow(currentShader->parameters[i].description, spinBox); + } +} + +OpenGLShaderConfig::~OpenGLShaderConfig() +{ + delete ui; +} + +void OpenGLShaderConfig::on_buttonBox_clicked(QAbstractButton *button) +{ + if (ui->buttonBox->buttonRole(button) == QDialogButtonBox::ResetRole) { + for (int i = 0; i < currentShader->num_parameters; i++) { + QDoubleSpinBox* box = this->findChild(QString(currentShader->parameters[i].id)); + if (box) { + box->setValue(currentShader->parameters[i].default_value); + } + } + } else if (ui->buttonBox->buttonRole(button) == QDialogButtonBox::ApplyRole) { + startblit(); + for (int i = 0; i < currentShader->num_parameters; i++) { + QDoubleSpinBox* box = this->findChild(QString(currentShader->parameters[i].id)); + if (box) { + float val = (float)box->value(); + currentShader->parameters[i].value = val; + } + } + glslp_write_shader_config(currentShader); + config_save(); + endblit(); + main_window->reloadAllRenderers(); + } +} + + +void OpenGLShaderConfig::on_OpenGLShaderConfig_accepted() +{ + startblit(); + for (int i = 0; i < currentShader->num_parameters; i++) { + QDoubleSpinBox* box = (QDoubleSpinBox*)this->findChild(QString(currentShader->parameters[i].id)); + if (box) { + float val = (float)box->value(); + currentShader->parameters[i].value = val; + } + } + glslp_write_shader_config(currentShader); + config_save(); + endblit(); + main_window->reloadAllRenderers(); +} + diff --git a/src/qt/qt_openglshaderconfig.hpp b/src/qt/qt_openglshaderconfig.hpp new file mode 100644 index 000000000..f71299d38 --- /dev/null +++ b/src/qt/qt_openglshaderconfig.hpp @@ -0,0 +1,40 @@ +#ifndef QT_OPENGLSHADERCONFIG_HPP +#define QT_OPENGLSHADERCONFIG_HPP + +#include +#include +#include +#include + +#include +#include + +extern "C" +{ +#include <86box/qt-glslp-parser.h> +} + +namespace Ui { +class OpenGLShaderConfig; +} + +class OpenGLShaderConfig : public QDialog { + Q_OBJECT + +public: + explicit OpenGLShaderConfig(QWidget *parent = nullptr, glslp_t* shader = nullptr); + ~OpenGLShaderConfig(); + +private slots: + void on_buttonBox_clicked(QAbstractButton *button); + + void on_OpenGLShaderConfig_accepted(); + +private: + Ui::OpenGLShaderConfig *ui; + glslp_t* currentShader; + + std::map defaultValues; +}; + +#endif // QT_OPENGLSHADERCONFIG_HPP diff --git a/src/qt/qt_openglshaderconfig.ui b/src/qt/qt_openglshaderconfig.ui new file mode 100644 index 000000000..1aebdb6f6 --- /dev/null +++ b/src/qt/qt_openglshaderconfig.ui @@ -0,0 +1,92 @@ + + + OpenGLShaderConfig + + + + 0 + 0 + 400 + 300 + + + + Shader Configuration + + + + QLayout::SizeConstraint::SetMinAndMaxSize + + + + + true + + + + + 0 + 0 + 380 + 250 + + + + + QLayout::SizeConstraint::SetMaximumSize + + + QFormLayout::FieldGrowthPolicy::AllNonFixedFieldsGrow + + + + + + + + + Qt::Orientation::Horizontal + + + QDialogButtonBox::StandardButton::Apply|QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok|QDialogButtonBox::StandardButton::Reset + + + + + + + + + buttonBox + accepted() + OpenGLShaderConfig + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + OpenGLShaderConfig + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/qt/qt_openglshadermanagerdialog.cpp b/src/qt/qt_openglshadermanagerdialog.cpp new file mode 100644 index 000000000..90f38f40f --- /dev/null +++ b/src/qt/qt_openglshadermanagerdialog.cpp @@ -0,0 +1,266 @@ +#include "qt_openglshadermanagerdialog.hpp" +#include "ui_qt_openglshadermanagerdialog.h" + +#include "qt_mainwindow.hpp" +#include "qt_util.hpp" +extern MainWindow* main_window; + +#include "qt_openglshaderconfig.hpp" + +#include +#include +#include +#include + +extern "C" { +#include <86box/86box.h> +#include <86box/plat.h> +#include <86box/video.h> +#include <86box/path.h> +#include <86box/ini.h> +#include <86box/config.h> +#include <86box/qt-glslp-parser.h> + +extern char gl3_shader_file[MAX_USER_SHADERS][512]; +} + +OpenGLShaderManagerDialog::OpenGLShaderManagerDialog(QWidget *parent) + : QDialog(parent) + , ui(new Ui::OpenGLShaderManagerDialog) +{ + ui->setupUi(this); + + ui->checkBoxVSync->setChecked(!!video_vsync); + ui->radioButtonVideoSync->setChecked(video_framerate == -1); + ui->radioButtonTargetFramerate->setChecked(video_framerate != -1); + if (video_framerate != -1) { + ui->targetFrameRate->setValue(video_framerate); + } else { + ui->targetFrameRate->setDisabled(true); + } + + for (int i = 0; i < MAX_USER_SHADERS; i++) { + if (gl3_shader_file[i][0] != 0) { + char* filename = path_get_filename(gl3_shader_file[i]); + if (filename[0] != 0) { + glslp_t* shaderfile = glslp_parse(gl3_shader_file[i]); + if (shaderfile) { + QListWidgetItem* item = new QListWidgetItem(ui->shaderListWidget); + item->setText(filename); + item->setData(Qt::UserRole + 1, QString(gl3_shader_file[i])); + item->setData(Qt::UserRole + 2, (qulonglong)(uintptr_t)shaderfile); + } + } + } + } + if (ui->shaderListWidget->count()) { + ui->shaderListWidget->setCurrentRow(ui->shaderListWidget->count() - 1); + auto current = ui->shaderListWidget->currentItem(); + if (current) { + glslp_t* shader = (glslp_t*)current->data(Qt::UserRole + 2).toULongLong(); + if (shader->num_parameters > 0) + ui->buttonConfigure->setEnabled(true); + else + ui->buttonConfigure->setEnabled(false); + } else { + ui->buttonConfigure->setEnabled(false); + } + ui->buttonAdd->setDisabled(ui->shaderListWidget->count() >= MAX_USER_SHADERS); + } else { + ui->buttonRemove->setDisabled(true); + ui->buttonMoveUp->setDisabled(true); + ui->buttonMoveDown->setDisabled(true); + ui->buttonConfigure->setDisabled(true); + } +} + +OpenGLShaderManagerDialog::~OpenGLShaderManagerDialog() +{ + for (int i = 0; i < ui->shaderListWidget->count(); i++) { + if (ui->shaderListWidget->item(i) && ui->shaderListWidget->item(i)->data(Qt::UserRole + 2).toULongLong()) { + glslp_free((glslp_t*)ui->shaderListWidget->item(i)->data(Qt::UserRole + 2).toULongLong()); + } + } + delete ui; +} + +void OpenGLShaderManagerDialog::on_buttonBox_clicked(QAbstractButton *button) +{ + if (ui->buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) { + accept(); + } else if (ui->buttonBox->buttonRole(button) == QDialogButtonBox::RejectRole) { + reject(); + } else if (ui->buttonBox->buttonRole(button) == QDialogButtonBox::ApplyRole) { + on_OpenGLShaderManagerDialog_accepted(); + main_window->reloadAllRenderers(); + } +} + + +void OpenGLShaderManagerDialog::on_buttonMoveUp_clicked() +{ + if (ui->shaderListWidget->currentRow() == 0) + return; + + int row = ui->shaderListWidget->currentRow(); + auto item = ui->shaderListWidget->takeItem(row); + ui->shaderListWidget->insertItem(row - 1, item); + ui->shaderListWidget->setCurrentItem(item); +} + + +void OpenGLShaderManagerDialog::on_shaderListWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous) +{ + if (current == nullptr) { + ui->buttonRemove->setDisabled(true); + ui->buttonMoveUp->setDisabled(true); + ui->buttonMoveDown->setDisabled(true); + ui->buttonConfigure->setDisabled(true); + return; + } else { + ui->buttonRemove->setDisabled(false); + ui->buttonConfigure->setDisabled(true); + if (current) { + glslp_t* shader = (glslp_t*)current->data(Qt::UserRole + 2).toULongLong(); + if (shader->num_parameters > 0) + ui->buttonConfigure->setEnabled(true); + } + } + ui->buttonMoveUp->setDisabled(ui->shaderListWidget->currentRow() == 0); + ui->buttonMoveDown->setDisabled(ui->shaderListWidget->currentRow() == (ui->shaderListWidget->count() - 1)); +} + + +void OpenGLShaderManagerDialog::on_shaderListWidget_currentRowChanged(int currentRow) +{ + auto current = ui->shaderListWidget->currentItem(); + if (current == nullptr) { + ui->buttonRemove->setDisabled(true); + ui->buttonMoveUp->setDisabled(true); + ui->buttonMoveDown->setDisabled(true); + ui->buttonConfigure->setDisabled(true); + return; + } else { + ui->buttonRemove->setDisabled(false); + ui->buttonConfigure->setDisabled(true); + if (current) { + glslp_t* shader = (glslp_t*)current->data(Qt::UserRole + 2).toULongLong(); + if (shader->num_parameters > 0) + ui->buttonConfigure->setEnabled(true); + } + } + ui->buttonMoveUp->setDisabled(ui->shaderListWidget->currentRow() == 0); + ui->buttonMoveDown->setDisabled(ui->shaderListWidget->currentRow() == (ui->shaderListWidget->count() - 1)); +} + + +void OpenGLShaderManagerDialog::on_buttonMoveDown_clicked() +{ + if (ui->shaderListWidget->currentRow() == (ui->shaderListWidget->count() - 1)) + return; + + int row = ui->shaderListWidget->currentRow(); + auto item = ui->shaderListWidget->takeItem(row); + ui->shaderListWidget->insertItem(row + 1, item); + ui->shaderListWidget->setCurrentItem(item); +} + + +void OpenGLShaderManagerDialog::on_buttonAdd_clicked() +{ + auto res = QFileDialog::getOpenFileName(this, QString(), QString(), + tr("GLSL shaders") % util::DlgFilter({ "glslp", "glsl" }) % tr("All files") % util::DlgFilter({ "*" }, true)); + if (!res.isEmpty()) { + auto glslp_file = res.toUtf8(); + glslp_t* shaderfile = glslp_parse(glslp_file.data()); + if (shaderfile) { + auto filename = path_get_filename(glslp_file.data()); + QListWidgetItem* item = new QListWidgetItem(ui->shaderListWidget); + item->setText(filename); + item->setData(Qt::UserRole + 1, res); + item->setData(Qt::UserRole + 2, (qulonglong)(uintptr_t)shaderfile); + if (ui->shaderListWidget->count()) { + ui->shaderListWidget->setCurrentRow(ui->shaderListWidget->count() - 1); + ui->buttonAdd->setDisabled(ui->shaderListWidget->count() >= MAX_USER_SHADERS); + } + } else { + QMessageBox::critical(this, tr("GLSL error"), tr("Could not load file %1").arg(res)); + } + } +} + + +void OpenGLShaderManagerDialog::on_buttonRemove_clicked() +{ + if (ui->shaderListWidget->currentItem()) { + auto item = ui->shaderListWidget->takeItem(ui->shaderListWidget->currentRow()); + + if (item->data(Qt::UserRole + 2).toULongLong()) { + glslp_free((glslp_t*)item->data(Qt::UserRole + 2).toULongLong()); + } + delete item; + + on_shaderListWidget_currentRowChanged(ui->shaderListWidget->currentRow()); + } + ui->buttonAdd->setDisabled(ui->shaderListWidget->count() >= MAX_USER_SHADERS); +} + +void OpenGLShaderManagerDialog::on_OpenGLShaderManagerDialog_accepted() +{ + memset(gl3_shader_file, 0, sizeof(gl3_shader_file)); + for (int i = 0; i < ui->shaderListWidget->count(); i++) { + strncpy(gl3_shader_file[i], ui->shaderListWidget->item(i)->data(Qt::UserRole + 1).toString().toUtf8(), 512); + } + startblit(); + video_vsync = ui->checkBoxVSync->isChecked(); + if (ui->radioButtonTargetFramerate->isChecked()) { + video_framerate = ui->horizontalSliderFramerate->value(); + } else { + video_framerate = -1; + } + config_save(); + endblit(); +} + + +void OpenGLShaderManagerDialog::on_buttonConfigure_clicked() +{ + auto item = ui->shaderListWidget->currentItem(); + if (item) { + glslp_t* shader = (glslp_t*)item->data(Qt::UserRole + 2).toULongLong(); + + auto configDialog = new OpenGLShaderConfig(this, shader); + configDialog->exec(); + } +} + + +void OpenGLShaderManagerDialog::on_radioButtonVideoSync_clicked() +{ + ui->targetFrameRate->setDisabled(true); +} + + +void OpenGLShaderManagerDialog::on_radioButtonTargetFramerate_clicked() +{ + ui->targetFrameRate->setDisabled(false); +} + + +void OpenGLShaderManagerDialog::on_horizontalSliderFramerate_sliderMoved(int position) +{ + (void)position; + + if (ui->horizontalSliderFramerate->value() != ui->targetFrameRate->value()) + ui->targetFrameRate->setValue(ui->horizontalSliderFramerate->value()); +} + + +void OpenGLShaderManagerDialog::on_targetFrameRate_valueChanged(int arg1) +{ + (void)arg1; + + if (ui->horizontalSliderFramerate->value() != ui->targetFrameRate->value()) + ui->horizontalSliderFramerate->setValue(ui->targetFrameRate->value()); +} + diff --git a/src/qt/qt_openglshadermanagerdialog.hpp b/src/qt/qt_openglshadermanagerdialog.hpp new file mode 100644 index 000000000..a9f7ad3a9 --- /dev/null +++ b/src/qt/qt_openglshadermanagerdialog.hpp @@ -0,0 +1,50 @@ +#ifndef QT_OPENGLSHADERMANAGERDIALOG_H +#define QT_OPENGLSHADERMANAGERDIALOG_H + +#include +#include +#include + +namespace Ui { +class OpenGLShaderManagerDialog; +} + +class OpenGLShaderManagerDialog : public QDialog { + Q_OBJECT + +public: + explicit OpenGLShaderManagerDialog(QWidget *parent = nullptr); + ~OpenGLShaderManagerDialog(); + +private slots: + void on_buttonBox_clicked(QAbstractButton *button); + + void on_buttonMoveUp_clicked(); + + void on_shaderListWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous); + + void on_shaderListWidget_currentRowChanged(int currentRow); + + void on_buttonMoveDown_clicked(); + + void on_buttonAdd_clicked(); + + void on_buttonRemove_clicked(); + + void on_OpenGLShaderManagerDialog_accepted(); + + void on_buttonConfigure_clicked(); + + void on_radioButtonVideoSync_clicked(); + + void on_radioButtonTargetFramerate_clicked(); + + void on_horizontalSliderFramerate_sliderMoved(int position); + + void on_targetFrameRate_valueChanged(int arg1); + +private: + Ui::OpenGLShaderManagerDialog *ui; +}; + +#endif // QT_OPENGLSHADERMANAGERDIALOG_H diff --git a/src/qt/qt_openglshadermanagerdialog.ui b/src/qt/qt_openglshadermanagerdialog.ui new file mode 100644 index 000000000..2a72c69ed --- /dev/null +++ b/src/qt/qt_openglshadermanagerdialog.ui @@ -0,0 +1,204 @@ + + + OpenGLShaderManagerDialog + + + + 0 + 0 + 400 + 465 + + + + Shader Manager + + + + QLayout::SizeConstraint::SetFixedSize + + + + + Shaders + + + + QLayout::SizeConstraint::SetFixedSize + + + + + QAbstractItemView::DragDropMode::InternalMove + + + QAbstractItemView::SelectionBehavior::SelectItems + + + + + + + QLayout::SizeConstraint::SetFixedSize + + + + + Add + + + + + + + Remove + + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + + + true + + + Configure + + + + + + + Move up + + + + + + + Move down + + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + + + Qt::Orientation::Vertical + + + QDialogButtonBox::StandardButton::Apply|QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok + + + false + + + + + + + + + + + + Render behavior + + + + QLayout::SizeConstraint::SetDefaultConstraint + + + + + Use target framerate: + + + + + + + 15 + + + 240 + + + 60 + + + Qt::Orientation::Horizontal + + + false + + + false + + + + + + + Synchronize with video + + + true + + + + + + + VSync + + + + + + + fps + + + 15 + + + 240 + + + 60 + + + + + + + + + + + diff --git a/src/qt/qt_platform.cpp b/src/qt/qt_platform.cpp index f8b512f78..8c2586482 100644 --- a/src/qt/qt_platform.cpp +++ b/src/qt/qt_platform.cpp @@ -18,6 +18,11 @@ * Copyright 2021-2022 Cacodemon345 * Copyright 2021-2022 Teemu Korhonen */ + +#ifdef __HAIKU__ +#include +#endif + #include #include @@ -38,6 +43,7 @@ #include #include #include +#include #include #include @@ -49,6 +55,10 @@ #include "qt_progsettings.hpp" #include "qt_util.hpp" +#ifndef Q_OS_WINDOWS +# include +#endif + #ifdef Q_OS_UNIX # include # include @@ -78,13 +88,13 @@ public: CharPointer &operator=(const QByteArray &ba) { if (s > 0) { + // If the size is known, copy up to s - 1 bytes + // and null-terminate the string. strncpy(b, ba.data(), s - 1); - b[s] = 0; - } else { - // if we haven't been told the length of b, just assume enough - // because we didn't get it from emulator code + b[s - 1] = 0; + } else if (ba.size() > 0) { + // If the size is unknown, copy the whole QByteArray strcpy(b, ba.data()); - b[ba.size()] = 0; } return *this; } @@ -131,7 +141,6 @@ int update_icons = 1; int kbd_req_capture = 0; int hide_status_bar = 0; int hide_tool_bar = 0; -uint32_t lang_id = 0x0409, lang_sys = 0x0409; // Multilangual UI variables, for now all set to LCID of en-US int stricmp(const char *s1, const char *s2) @@ -156,6 +165,7 @@ strnicmp(const char *s1, const char *s2, size_t n) void do_start(void) { + // } void @@ -367,6 +377,8 @@ plat_mmap(size_t size, uint8_t executable) void *ret = mmap(0, size, PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0), MAP_ANON | MAP_PRIVATE | (executable ? MAP_JIT : 0), -1, 0); # elif defined(PROT_MPROTECT) void *ret = mmap(0, size, PROT_MPROTECT(PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0)), MAP_ANON | MAP_PRIVATE, -1, 0); + if (ret) + mprotect(ret, size, PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0)); # else void *ret = mmap(0, size, PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0), MAP_ANON | MAP_PRIVATE, -1, 0); # endif @@ -384,6 +396,7 @@ plat_munmap(void *ptr, size_t size) #endif } +extern bool cpu_thread_running; void plat_pause(int p) { @@ -391,6 +404,10 @@ plat_pause(int p) wchar_t title[1024]; wchar_t paused_msg[512]; + if (!cpu_thread_running && p == 1) { + p = 2; + } + if ((!!p) == dopause) { #ifdef Q_OS_WINDOWS if (source_hwnd) @@ -444,58 +461,18 @@ plat_power_off(void) QTimer::singleShot(0, (const QWidget *) main_window, &QMainWindow::close); } -extern "C++" { -QMap> ProgSettings::lcid_langcode = { - { 0x0403, { "ca-ES", "Catalan (Spain)" } }, - { 0x0804, { "zh-CN", "Chinese (Simplified)" } }, - { 0x0404, { "zh-TW", "Chinese (Traditional)" } }, - { 0x041A, { "hr-HR", "Croatian (Croatia)" } }, - { 0x0405, { "cs-CZ", "Czech (Czech Republic)" } }, - { 0x0407, { "de-DE", "German (Germany)" } }, - { 0x0809, { "en-GB", "English (United Kingdom)" }}, - { 0x0409, { "en-US", "English (United States)" } }, - { 0x040B, { "fi-FI", "Finnish (Finland)" } }, - { 0x040C, { "fr-FR", "French (France)" } }, - { 0x040E, { "hu-HU", "Hungarian (Hungary)" } }, - { 0x0410, { "it-IT", "Italian (Italy)" } }, - { 0x0411, { "ja-JP", "Japanese (Japan)" } }, - { 0x0412, { "ko-KR", "Korean (Korea)" } }, - { 0x0413, { "nl-NL", "Dutch (Netherlands)" } }, - { 0x0415, { "pl-PL", "Polish (Poland)" } }, - { 0x0416, { "pt-BR", "Portuguese (Brazil)" } }, - { 0x0816, { "pt-PT", "Portuguese (Portugal)" } }, - { 0x0419, { "ru-RU", "Russian (Russia)" } }, - { 0x041B, { "sk-SK", "Slovak (Slovakia)" } }, - { 0x0424, { "sl-SI", "Slovenian (Slovenia)" } }, - { 0x0C0A, { "es-ES", "Spanish (Spain, Modern Sort)" } }, - { 0x041F, { "tr-TR", "Turkish (Turkey)" } }, - { 0x0422, { "uk-UA", "Ukrainian (Ukraine)" } }, - { 0x042A, { "vi-VN", "Vietnamese (Vietnam)" } }, - { 0xFFFF, { "system", "(System Default)" } }, -}; -} - -/* Sets up the program language before initialization. */ -uint32_t +/* Converts the language code string to a numeric language ID */ +int plat_language_code(char *langcode) { - for (auto &curKey : ProgSettings::lcid_langcode.keys()) { - if (ProgSettings::lcid_langcode[curKey].first == langcode) { - return curKey; - } - } - return 0xFFFF; + return ProgSettings::languageCodeToId(QString(langcode)); } -/* Converts back the language code to LCID */ +/* Converts the numeric language ID to a language code string */ void -plat_language_code_r(uint32_t lcid, char *outbuf, int len) +plat_language_code_r(int id, char *outbuf, int len) { - if (!ProgSettings::lcid_langcode.contains(lcid)) { - qstrncpy(outbuf, "system", len); - return; - } - qstrncpy(outbuf, ProgSettings::lcid_langcode[lcid].first.toUtf8().constData(), len); + qstrncpy(outbuf, ProgSettings::languageIdToCode(id).toUtf8().constData(), len); return; } @@ -557,7 +534,7 @@ endblit() std::this_thread::sleep_for(std::chrono::milliseconds(1)); } } -} +} /*extern "C" */ #ifdef Q_OS_WINDOWS size_t @@ -604,12 +581,10 @@ c16stombs(char dst[], const uint16_t src[], int len) # define LIB_NAME_GPCL "gpcl6dll32.dll" # endif # define LIB_NAME_PCAP "Npcap" -# define MOUSE_CAPTURE_KEYSEQ "F8+F12" #else # define LIB_NAME_GS "libgs" # define LIB_NAME_GPCL "libgpcl6" # define LIB_NAME_PCAP "libpcap" -# define MOUSE_CAPTURE_KEYSEQ "Ctrl+End" #endif QMap ProgSettings::translatedstrings; @@ -619,8 +594,8 @@ ProgSettings::reloadStrings() { translatedstrings.clear(); translatedstrings[STRING_MOUSE_CAPTURE] = QCoreApplication::translate("", "Click to capture mouse").toStdWString(); - translatedstrings[STRING_MOUSE_RELEASE] = QCoreApplication::translate("", "Press %1 to release mouse").arg(QCoreApplication::translate("", MOUSE_CAPTURE_KEYSEQ)).toStdWString(); - translatedstrings[STRING_MOUSE_RELEASE_MMB] = QCoreApplication::translate("", "Press %1 or middle button to release mouse").arg(QCoreApplication::translate("", MOUSE_CAPTURE_KEYSEQ)).toStdWString(); + translatedstrings[STRING_MOUSE_RELEASE] = QCoreApplication::translate("", "Press %1 to release mouse").arg(QKeySequence(acc_keys[FindAccelerator("release_mouse")].seq, QKeySequence::PortableText).toString(QKeySequence::NativeText)).toStdWString(); + translatedstrings[STRING_MOUSE_RELEASE_MMB] = QCoreApplication::translate("", "Press %1 or middle button to release mouse").arg(QKeySequence(acc_keys[FindAccelerator("release_mouse")].seq, QKeySequence::PortableText).toString(QKeySequence::NativeText)).toStdWString(); translatedstrings[STRING_INVALID_CONFIG] = QCoreApplication::translate("", "Invalid configuration").toStdWString(); translatedstrings[STRING_NO_ST506_ESDI_CDROM] = QCoreApplication::translate("", "MFM/RLL or ESDI CD-ROM drives never existed").toStdWString(); translatedstrings[STRING_PCAP_ERROR_NO_DEVICES] = QCoreApplication::translate("", "No PCap devices found").toStdWString(); @@ -632,11 +607,14 @@ ProgSettings::reloadStrings() translatedstrings[STRING_GHOSTPCL_ERROR_DESC] = QCoreApplication::translate("", "%1 is required for automatic conversion of PCL files to PDF.\n\nAny documents sent to the generic PCL printer will be saved as Printer Command Language (.pcl) files.").arg(LIB_NAME_GPCL).toStdWString(); translatedstrings[STRING_HW_NOT_AVAILABLE_MACHINE] = QCoreApplication::translate("", "Machine \"%hs\" is not available due to missing ROMs in the roms/machines directory. Switching to an available machine.").toStdWString(); translatedstrings[STRING_HW_NOT_AVAILABLE_VIDEO] = QCoreApplication::translate("", "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card.").toStdWString(); - translatedstrings[STRING_HW_NOT_AVAILABLE_VIDEO2] = QCoreApplication::translate("", "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card.").toStdWString(); + translatedstrings[STRING_HW_NOT_AVAILABLE_VIDEO2] = QCoreApplication::translate("", "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card.").toStdWString(); + translatedstrings[STRING_HW_NOT_AVAILABLE_DEVICE] = QCoreApplication::translate("", "Device \"%hs\" is not available due to missing ROMs. Ignoring the device.").toStdWString(); translatedstrings[STRING_HW_NOT_AVAILABLE_TITLE] = QCoreApplication::translate("", "Hardware not available").toStdWString(); translatedstrings[STRING_MONITOR_SLEEP] = QCoreApplication::translate("", "Monitor in sleep mode").toStdWString(); translatedstrings[STRING_NET_ERROR] = QCoreApplication::translate("", "Failed to initialize network driver").toStdWString(); translatedstrings[STRING_NET_ERROR_DESC] = QCoreApplication::translate("", "The network configuration will be switched to the null driver").toStdWString(); + translatedstrings[STRING_ESCP_ERROR_TITLE] = QCoreApplication::translate("", "Unable to find Dot-Matrix fonts").toStdWString(); + translatedstrings[STRING_ESCP_ERROR_DESC] = QCoreApplication::translate("", "TrueType fonts in the \"roms/printer/fonts\" directory are required for the emulation of the Generic ESC/P Dot-Matrix Printer.").toStdWString(); } wchar_t * @@ -798,8 +776,8 @@ plat_set_thread_name(void *thread, const char *name) if (pSetThreadDescription) { size_t len = strlen(name) + 1; - wchar_t wname[len + 1]; - mbstowcs(wname, name, len); + wchar_t wname[2048]; + mbstowcs(wname, name, (len >= 1024) ? 1024 : len); pSetThreadDescription(thread ? (HANDLE) thread : GetCurrentThread(), wname); } #else @@ -816,7 +794,9 @@ plat_set_thread_name(void *thread, const char *name) # if defined(Q_OS_DARWIN) pthread_setname_np(truncated); # elif defined(Q_OS_NETBSD) - pthread_setname_np(thread ? *((pthread_t *) thread) : pthread_self(), truncated, "%s"); + pthread_setname_np(thread ? *((pthread_t *) thread) : pthread_self(), truncated, (void*)"%s"); +# elif defined(__HAIKU__) + rename_thread(find_thread(NULL), truncated); # elif defined(Q_OS_OPENBSD) pthread_set_name_np(thread ? *((pthread_t *) thread) : pthread_self(), truncated); # else @@ -824,3 +804,13 @@ plat_set_thread_name(void *thread, const char *name) # endif #endif } + +void +plat_break(void) +{ +#ifdef Q_OS_WINDOWS + DebugBreak(); +#else + raise(SIGTRAP); +#endif +} diff --git a/src/qt/qt_progsettings.cpp b/src/qt/qt_progsettings.cpp index 9e1f8c168..825689e78 100644 --- a/src/qt/qt_progsettings.cpp +++ b/src/qt/qt_progsettings.cpp @@ -26,6 +26,10 @@ #include #include #include +#ifdef Q_OS_WINDOWS +# include +# include +#endif extern "C" { #include <86box/86box.h> @@ -36,78 +40,51 @@ extern "C" { #include <86box/rom.h> } -static QMap iconset_to_qt; extern MainWindow *main_window; ProgSettings::CustomTranslator *ProgSettings::translator = nullptr; QTranslator *ProgSettings::qtTranslator = nullptr; -QString -ProgSettings::getIconSetPath() -{ - if (iconset_to_qt.isEmpty()) { - // Always include default bundled icons - iconset_to_qt.insert("", ":/settings/qt/icons"); - // Walk rom_paths to get the candidates - for (rom_path_t *emu_rom_path = &rom_paths; emu_rom_path != nullptr; emu_rom_path = emu_rom_path->next) { - // Check for icons subdir in each candidate - QDir roms_icons_dir(QString(emu_rom_path->path) + "/icons"); - if (roms_icons_dir.isReadable()) { - auto dirList = roms_icons_dir.entryList(QDir::AllDirs | QDir::Executable | QDir::Readable); - for (auto &curIconSet : dirList) { - if (curIconSet == "." || curIconSet == "..") { - continue; - } - iconset_to_qt.insert(curIconSet, (roms_icons_dir.canonicalPath() + '/') + curIconSet); - } - } - } - } - return iconset_to_qt[icon_set]; -} -QIcon -ProgSettings::loadIcon(QString file) -{ - (void) getIconSetPath(); - if (!QFile::exists(iconset_to_qt[icon_set] + file)) - return QIcon(iconset_to_qt[""] + file); - return QIcon(iconset_to_qt[icon_set] + file); -} +QVector> ProgSettings::languages = { + { "system", "(System Default)" }, + { "ca-ES", "Catalan (Spain)" }, + { "zh-CN", "Chinese (Simplified)" }, + { "zh-TW", "Chinese (Traditional)" }, + { "hr-HR", "Croatian (Croatia)" }, + { "cs-CZ", "Czech (Czech Republic)" }, + { "de-DE", "German (Germany)" }, + { "en-GB", "English (United Kingdom)" }, + { "en-US", "English (United States)" }, + { "fi-FI", "Finnish (Finland)" }, + { "fr-FR", "French (France)" }, + { "hu-HU", "Hungarian (Hungary)" }, + { "it-IT", "Italian (Italy)" }, + { "ja-JP", "Japanese (Japan)" }, + { "ko-KR", "Korean (Korea)" }, + { "nl-NL", "Dutch (Netherlands)" }, + { "pl-PL", "Polish (Poland)" }, + { "pt-BR", "Portuguese (Brazil)" }, + { "pt-PT", "Portuguese (Portugal)" }, + { "ru-RU", "Russian (Russia)" }, + { "sk-SK", "Slovak (Slovakia)" }, + { "sl-SI", "Slovenian (Slovenia)" }, + { "sv-SE", "Swedish (Sweden)" }, + { "es-ES", "Spanish (Spain)" }, + { "tr-TR", "Turkish (Turkey)" }, + { "uk-UA", "Ukrainian (Ukraine)" }, + { "vi-VN", "Vietnamese (Vietnam)" }, +}; ProgSettings::ProgSettings(QWidget *parent) : QDialog(parent) , ui(new Ui::ProgSettings) { ui->setupUi(this); - (void) getIconSetPath(); - ui->comboBox->setItemData(0, ""); - ui->comboBox->setCurrentIndex(0); - for (auto i = iconset_to_qt.begin(); i != iconset_to_qt.end(); i++) { - if (i.key() == "") - continue; - QFile iconfile(i.value() + "/iconinfo.txt"); - iconfile.open(QFile::ReadOnly); - QString friendlyName; - QString iconsetinfo(iconfile.readAll()); - iconfile.close(); - if (iconsetinfo.isEmpty()) - friendlyName = i.key(); - else - friendlyName = iconsetinfo.split('\n')[0]; - ui->comboBox->addItem(friendlyName, i.key()); - if (strcmp(icon_set, i.key().toUtf8().data()) == 0) { - ui->comboBox->setCurrentIndex(ui->comboBox->findData(i.key())); - } - } - ui->comboBox->setItemData(0, '(' + tr("Default") + ')', Qt::DisplayRole); - - ui->comboBoxLanguage->setItemData(0, 0xFFFF); - for (auto i = lcid_langcode.begin(); i != lcid_langcode.end(); i++) { - if (i.key() == 0xFFFF) - continue; - ui->comboBoxLanguage->addItem(lcid_langcode[i.key()].second, i.key()); - if (i.key() == lang_id) { - ui->comboBoxLanguage->setCurrentIndex(ui->comboBoxLanguage->findData(i.key())); + ui->comboBoxLanguage->setItemData(0, 0); + for (int i = 1; i < languages.length(); i++) { + ui->comboBoxLanguage->addItem(languages[i].second, i); + if (i == lang_id) { + ui->comboBoxLanguage->setCurrentIndex(ui->comboBoxLanguage->findData(i)); } } ui->comboBoxLanguage->model()->sort(Qt::AscendingOrder); @@ -115,14 +92,25 @@ ProgSettings::ProgSettings(QWidget *parent) mouseSensitivity = mouse_sensitivity; ui->horizontalSlider->setValue(mouseSensitivity * 100.); ui->openDirUsrPath->setChecked(open_dir_usr_path > 0); + ui->checkBoxMultimediaKeys->setChecked(inhibit_multimedia_keys); + ui->checkBoxConfirmExit->setChecked(confirm_exit); + ui->checkBoxConfirmSave->setChecked(confirm_save); + ui->checkBoxConfirmHardReset->setChecked(confirm_reset); + +#ifndef Q_OS_WINDOWS + ui->checkBoxMultimediaKeys->setHidden(true); +#endif } void ProgSettings::accept() { - strcpy(icon_set, ui->comboBox->currentData().toString().toUtf8().data()); - lang_id = ui->comboBoxLanguage->currentData().toUInt(); - open_dir_usr_path = ui->openDirUsrPath->isChecked() ? 1 : 0; + lang_id = ui->comboBoxLanguage->currentData().toInt(); + open_dir_usr_path = ui->openDirUsrPath->isChecked() ? 1 : 0; + confirm_exit = ui->checkBoxConfirmExit->isChecked() ? 1 : 0; + confirm_save = ui->checkBoxConfirmSave->isChecked() ? 1 : 0; + confirm_reset = ui->checkBoxConfirmHardReset->isChecked() ? 1 : 0; + inhibit_multimedia_keys = ui->checkBoxMultimediaKeys->isChecked() ? 1 : 0; loadTranslators(QCoreApplication::instance()); reloadStrings(); @@ -147,33 +135,50 @@ ProgSettings::~ProgSettings() delete ui; } -void -ProgSettings::on_pushButton_released() -{ - ui->comboBox->setCurrentIndex(0); -} - #ifdef Q_OS_WINDOWS /* Return the standard font name on Windows, which is overridden per-language to prevent CJK fonts with embedded bitmaps being chosen as a fallback. */ QString -ProgSettings::getFontName(uint32_t lcid) +ProgSettings::getFontName(int langId) { - switch (lcid) { - case 0x0404: /* zh-TW */ - return "Microsoft JhengHei"; - case 0x0411: /* ja-JP */ + QString langCode = languageIdToCode(lang_id); + if (langCode == "ja-JP") { + /* Check for Windows 10 or later to choose the appropriate system font */ + if (QVersionNumber::fromString(QSysInfo::kernelVersion()).majorVersion() >= 10) + return "Yu Gothic UI"; + else return "Meiryo UI"; - case 0x0412: /* ko-KR */ - return "Malgun Gothic"; - case 0x0804: /* zh-CN */ - return "Microsoft YaHei"; - default: - return "Segoe UI"; - } + } else if (langCode == "ko-KR") + return "Malgun Gothic"; + else if (langCode == "zh-CN") + return "Microsoft YaHei"; + else if (langCode == "zh-TW") + return "Microsoft JhengHei"; + else + return "Segoe UI"; } #endif +int +ProgSettings::languageCodeToId(QString langCode) +{ + for (int i = 0; i < languages.length(); i++) { + if (languages[i].first == langCode) { + return i; + } + } + return 0; +} + +QString +ProgSettings::languageIdToCode(int id) +{ + if ((id == 0) || (id >= languages.length())) { + return "system"; + } + return languages[id].first; +} + void ProgSettings::loadTranslators(QObject *parent) { @@ -188,7 +193,7 @@ ProgSettings::loadTranslators(QObject *parent) qtTranslator = new QTranslator(parent); translator = new CustomTranslator(parent); QString localetofilename = ""; - if (lang_id == 0xFFFF || lcid_langcode.contains(lang_id) == false) { + if (lang_id == 0 || lang_id >= languages.length()) { for (int i = 0; i < QLocale::system().uiLanguages().size(); i++) { localetofilename = QLocale::system().uiLanguages()[i]; if (translator->load(QLatin1String("86box_") + localetofilename, QLatin1String(":/"))) { @@ -206,12 +211,12 @@ ProgSettings::loadTranslators(QObject *parent) } } } else { - translator->load(QLatin1String("86box_") + lcid_langcode[lang_id].first, QLatin1String(":/")); + translator->load(QLatin1String("86box_") + languages[lang_id].first, QLatin1String(":/")); QCoreApplication::installTranslator(translator); - if (!qtTranslator->load(QLatin1String("qtbase_") + QString(lcid_langcode[lang_id].first).replace('-', '_'), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) - if (!qtTranslator->load(QLatin1String("qtbase_") + QString(lcid_langcode[lang_id].first).left(QString(lcid_langcode[lang_id].first).indexOf('-')), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) - if(!qtTranslator->load(QLatin1String("qt_") + QString(lcid_langcode[lang_id].first).replace('-', '_'), QApplication::applicationDirPath() + "/./translations/")) - qtTranslator->load(QLatin1String("qt_") + QString(lcid_langcode[lang_id].first).replace('-', '_'), QLatin1String(":/")); + if (!qtTranslator->load(QLatin1String("qtbase_") + QString(languages[lang_id].first).replace('-', '_'), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) + if (!qtTranslator->load(QLatin1String("qtbase_") + QString(languages[lang_id].first).left(QString(languages[lang_id].first).indexOf('-')), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) + if(!qtTranslator->load(QLatin1String("qt_") + QString(languages[lang_id].first).replace('-', '_'), QApplication::applicationDirPath() + "/./translations/")) + qtTranslator->load(QLatin1String("qt_") + QString(languages[lang_id].first).replace('-', '_'), QLatin1String(":/")); QCoreApplication::installTranslator(qtTranslator); } diff --git a/src/qt/qt_progsettings.hpp b/src/qt/qt_progsettings.hpp index 642b2002d..31600e7f1 100644 --- a/src/qt/qt_progsettings.hpp +++ b/src/qt/qt_progsettings.hpp @@ -14,13 +14,13 @@ class ProgSettings : public QDialog { public: explicit ProgSettings(QWidget *parent = nullptr); ~ProgSettings(); - static QString getIconSetPath(); - static QIcon loadIcon(QString file); #ifdef Q_OS_WINDOWS - static QString getFontName(uint32_t lcid); + static QString getFontName(int langId); #endif - static void loadTranslators(QObject *parent = nullptr); - static void reloadStrings(); + static int languageCodeToId(QString langCode); + static QString languageIdToCode(int id); + static void loadTranslators(QObject *parent = nullptr); + static void reloadStrings(); class CustomTranslator : public QTranslator { public: CustomTranslator(QObject *parent = nullptr) @@ -30,33 +30,17 @@ public: QString translate(const char *context, const char *sourceText, const char *disambiguation = nullptr, int n = -1) const override { - if (strcmp(sourceText, "&Fullscreen") == 0) - sourceText = "&Fullscreen\tCtrl+Alt+PgUp"; - if (strcmp(sourceText, "&Ctrl+Alt+Del") == 0) - sourceText = "&Ctrl+Alt+Del\tCtrl+F12"; - if (strcmp(sourceText, "Take s&creenshot") == 0) - sourceText = "Take s&creenshot\tCtrl+F11"; - if (strcmp(sourceText, "Begin trace") == 0) - sourceText = "Begin trace\tCtrl+T"; - if (strcmp(sourceText, "End trace") == 0) - sourceText = "End trace\tCtrl+T"; - QString finalstr = QTranslator::translate("", sourceText, disambiguation, n); -#ifdef Q_OS_MACOS - if (finalstr.contains('\t')) - finalstr.truncate(finalstr.indexOf('\t')); -#endif - return finalstr; + return QTranslator::translate("", sourceText, disambiguation, n); } }; - static CustomTranslator *translator; - static QTranslator *qtTranslator; - static QMap> lcid_langcode; - static QMap translatedstrings; + static CustomTranslator *translator; + static QTranslator *qtTranslator; + static QVector> languages; + static QMap translatedstrings; protected slots: void accept() override; private slots: - void on_pushButton_released(); void on_pushButtonLanguage_released(); void on_horizontalSlider_valueChanged(int value); diff --git a/src/qt/qt_progsettings.ui b/src/qt/qt_progsettings.ui index ac4327341..6020efd77 100644 --- a/src/qt/qt_progsettings.ui +++ b/src/qt/qt_progsettings.ui @@ -7,7 +7,7 @@ 0 0 458 - 374 + 391 @@ -27,48 +27,19 @@ - QLayout::SetFixedSize + QLayout::SizeConstraint::SetFixedSize - - - - false - - - 30 - - - - (Default) - - - - - - - - Mouse sensitivity: - - - - - - - Icon set: - - - - + Default - + - Qt::Horizontal + Qt::Orientation::Horizontal @@ -78,17 +49,49 @@ - - - - Qt::Horizontal + + + + 30 - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + (System Default) + + + + + + + + <html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html> + + + Select media images from program working directory - + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + Default + + + + 10 @@ -106,76 +109,59 @@ 100 - Qt::Horizontal + Qt::Orientation::Horizontal - - - - 30 - - - - (System Default) - - - - - + Language: - - + + - Default + Ask for confirmation before saving settings - - - - Default + + + + Qt::Orientation::Horizontal + + + QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok - - - - Qt::Horizontal + + + + Inhibit multimedia keys - - - 40 - 20 - - - + - - - - Qt::Horizontal + + + + Mouse sensitivity: - - - 40 - 20 - + + + + + + Ask for confirmation before hard resetting - + - - - <html><head/><body><p>When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.</p></body></html> - + - Select media images from program working directory + Ask for confirmation before quitting diff --git a/src/qt/qt_renderercommon.cpp b/src/qt/qt_renderercommon.cpp index 178134c9d..56217b611 100644 --- a/src/qt/qt_renderercommon.cpp +++ b/src/qt/qt_renderercommon.cpp @@ -59,6 +59,9 @@ RendererCommon::onResize(int width, int height) bool main_max = main_window->isMaximized(); bool main_is_max = (main_is_ancestor && main_max == false); + width = round(pixelRatio * width); + height = round(pixelRatio * height); + if (is_fs && (video_fullscreen_scale_maximized ? (parent_max && main_is_max) : 1)) destination.setRect(0, 0, width, height); else { @@ -129,6 +132,9 @@ RendererCommon::onResize(int width, int height) monitors[r_monitor_index].mon_res_x = (double) destination.width(); monitors[r_monitor_index].mon_res_y = (double) destination.height(); + + destinationF.setRect((double)destination.x() / (double)width, (double)destination.y() / (double)height, + (double)destination.width() / (double)width, (double)destination.height() / (double)height); } bool @@ -144,6 +150,10 @@ RendererCommon::eventDelegate(QEvent *event, bool &result) case QEvent::MouseButtonPress: case QEvent::MouseMove: case QEvent::MouseButtonRelease: + case QEvent::TouchBegin: + case QEvent::TouchEnd: + case QEvent::TouchCancel: + case QEvent::TouchUpdate: case QEvent::Wheel: case QEvent::Enter: case QEvent::Leave: diff --git a/src/qt/qt_renderercommon.hpp b/src/qt/qt_renderercommon.hpp index af72474c7..6bfa51a8d 100644 --- a/src/qt/qt_renderercommon.hpp +++ b/src/qt/qt_renderercommon.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -34,8 +35,13 @@ public: virtual QDialog *getOptions(QWidget *parent) { return nullptr; } /* Reloads options of renderer */ virtual void reloadOptions() { } + /* Make the renderer reload itself */ + virtual bool reloadRendererOption() { return false; } + /* Should the renderer take screenshots itself? */ + virtual bool rendererTakeScreenshot() { return false; } int r_monitor_index = 0; + QRectF destinationF = QRectF(0, 0, 1, 1); /* normalized to 0.0-1.0 range. */ protected: bool eventDelegate(QEvent *event, bool &result); @@ -45,5 +51,7 @@ protected: QRect destination; QWidget *parentWidget { nullptr }; + double pixelRatio = 1.0; + std::vector buf_usage; }; diff --git a/src/qt/qt_rendererstack.cpp b/src/qt/qt_rendererstack.cpp index a8bd47a79..31cc495b0 100644 --- a/src/qt/qt_rendererstack.cpp +++ b/src/qt/qt_rendererstack.cpp @@ -38,6 +38,8 @@ #include #include +#include +#include #ifdef __APPLE__ # include @@ -59,10 +61,17 @@ struct mouseinputdata { static mouseinputdata mousedata; extern MainWindow *main_window; + +#ifdef Q_OS_WINDOWS +HWND rw_hwnd; +#endif + RendererStack::RendererStack(QWidget *parent, int monitor_index) : QStackedWidget(parent) , ui(new Ui::RendererStack) { + setAttribute(Qt::WA_AcceptTouchEvents, true); + rendererTakesScreenshots = false; #ifdef Q_OS_WINDOWS int raw = 1; #else @@ -73,7 +82,7 @@ RendererStack::RendererStack(QWidget *parent, int monitor_index) m_monitor_index = monitor_index; #if defined __unix__ && !defined __HAIKU__ - char auto_mouse_type[16]; + memset(auto_mouse_type, 0, sizeof (auto_mouse_type)); mousedata.mouse_type = getenv("EMU86BOX_MOUSE"); if (!mousedata.mouse_type || (mousedata.mouse_type[0] == '\0') || !stricmp(mousedata.mouse_type, "auto")) { if (QApplication::platformName().contains("wayland")) @@ -155,7 +164,7 @@ RendererStack::mouseReleaseEvent(QMouseEvent *event) } if (mouse_capture && (event->button() == Qt::MiddleButton) && (mouse_get_buttons() < 3)) { plat_mouse_capture(0); - this->setCursor(Qt::ArrowCursor); + this->unsetCursor(); isMouseDown &= ~1; return; } @@ -205,9 +214,13 @@ RendererStack::wheelEvent(QWheelEvent *event) return; } +#if !defined(Q_OS_WINDOWS) && !defined(__APPLE__) double numSteps = (double) event->angleDelta().y() / 120.0; + double numStepsW = (double) event->angleDelta().x() / 120.0; mouse_set_z((int) numSteps); + mouse_set_w((int) numStepsW); +#endif event->accept(); } @@ -243,7 +256,9 @@ RendererStack::mouseMoveEvent(QMouseEvent *event) leaveEvent((QEvent *) event); ignoreNextMouseEvent--; } +#if !defined _WIN32 QCursor::setPos(mapToGlobal(QPoint(width() / 2, height() / 2))); +#endif ignoreNextMouseEvent = 2; oldPos = event->pos(); #endif @@ -269,7 +284,7 @@ RendererStack::leaveEvent(QEvent *event) { mousedata.mouse_tablet_in_proximity = 0; - if (mouse_input_mode == 1 && QApplication::overrideCursor()) { + if (mouse_input_mode >= 1 && QApplication::overrideCursor()) { while (QApplication::overrideCursor()) QApplication::restoreOverrideCursor(); } @@ -287,7 +302,8 @@ RendererStack::leaveEvent(QEvent *event) void RendererStack::switchRenderer(Renderer renderer) { - startblit(); + //startblit(); + switchInProgress = true; if (current) { rendererWindow->finalize(); removeWidget(current.get()); @@ -305,6 +321,7 @@ RendererStack::switchRenderer(Renderer renderer) void RendererStack::createRenderer(Renderer renderer) { + rendererTakesScreenshots = false; switch (renderer) { default: case Renderer::Software: @@ -340,13 +357,14 @@ RendererStack::createRenderer(Renderer renderer) case Renderer::OpenGL3: { this->createWinId(); + this->rendererTakesScreenshots = true; auto hw = new OpenGLRenderer(this); rendererWindow = hw; connect(this, &RendererStack::blitToRenderer, hw, &OpenGLRenderer::onBlit, Qt::QueuedConnection); connect(hw, &OpenGLRenderer::initialized, [=]() { /* Buffers are available only after initialization. */ imagebufs = rendererWindow->getBuffers(); - endblit(); + switchInProgress = false; emit rendererChanged(); }); connect(hw, &OpenGLRenderer::errorInitializing, [=]() { @@ -365,7 +383,7 @@ RendererStack::createRenderer(Renderer renderer) try { hw = new VulkanWindowRenderer(this); } catch (std::runtime_error &e) { - auto msgBox = new QMessageBox(QMessageBox::Critical, "86Box", e.what() + QString("\nFalling back to software rendering."), QMessageBox::Ok); + auto msgBox = new QMessageBox(QMessageBox::Critical, "86Box", e.what() + tr("\nFalling back to software rendering."), QMessageBox::Ok); msgBox->setAttribute(Qt::WA_DeleteOnClose); msgBox->show(); imagebufs = {}; @@ -378,12 +396,12 @@ RendererStack::createRenderer(Renderer renderer) connect(hw, &VulkanWindowRenderer::rendererInitialized, [=]() { /* Buffers are available only after initialization. */ imagebufs = rendererWindow->getBuffers(); - endblit(); + switchInProgress = false; emit rendererChanged(); }); connect(hw, &VulkanWindowRenderer::errorInitializing, [=]() { /* Renderer could not initialize, fallback to software. */ - auto msgBox = new QMessageBox(QMessageBox::Critical, "86Box", QString("Failed to initialize Vulkan renderer.\nFalling back to software rendering."), QMessageBox::Ok); + auto msgBox = new QMessageBox(QMessageBox::Critical, "86Box", tr("Failed to initialize Vulkan renderer.") % tr("\nFalling back to software rendering."), QMessageBox::Ok); msgBox->setAttribute(Qt::WA_DeleteOnClose); msgBox->show(); imagebufs = {}; @@ -394,8 +412,15 @@ RendererStack::createRenderer(Renderer renderer) } #endif } - if (current.get() == nullptr) + if (current.get() == nullptr) { +#ifdef Q_OS_WINDOWS + rw_hwnd = NULL; +#endif return; + } +#ifdef Q_OS_WINDOWS + rw_hwnd = (HWND) this->winId(); +#endif current->setFocusPolicy(Qt::NoFocus); current->setFocusProxy(this); current->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); @@ -404,11 +429,13 @@ RendererStack::createRenderer(Renderer renderer) this->setStyleSheet("background-color: black"); + rendererWindow->r_monitor_index = m_monitor_index; + currentBuf = 0; if (renderer != Renderer::OpenGL3 && renderer != Renderer::Vulkan) { imagebufs = rendererWindow->getBuffers(); - endblit(); + switchInProgress = false; emit rendererChanged(); } } @@ -418,7 +445,7 @@ void RendererStack::blit(int x, int y, int w, int h) { if ((x < 0) || (y < 0) || (w <= 0) || (h <= 0) || - (w > 2048) || (h > 2048) || + (w > 2048) || (h > 2048) || (switchInProgress) || (monitors[m_monitor_index].target_buffer == NULL) || imagebufs.empty() || std::get(imagebufs[currentBuf])->test_and_set()) { video_blit_complete_monitor(m_monitor_index); @@ -434,7 +461,7 @@ RendererStack::blit(int x, int y, int w, int h) video_copy(scanline, &(monitors[m_monitor_index].target_buffer->line[y1][x]), w * 4); } - if (monitors[m_monitor_index].mon_screenshots) { + if (monitors[m_monitor_index].mon_screenshots && !rendererTakesScreenshots) { video_screenshot_monitor((uint32_t *) imagebits, x, y, 2048, m_monitor_index); } video_blit_complete_monitor(m_monitor_index); @@ -471,25 +498,156 @@ RendererStack::event(QEvent* event) if (m_monitor_index >= 1) { if (mouse_input_mode >= 1) { - mouse_x_abs = (mouse_event->localPos().x()) / (long double)width(); - mouse_y_abs = (mouse_event->localPos().y()) / (long double)height(); + mouse_x_abs = (mouse_event->localPos().x()) / (double)width(); + mouse_y_abs = (mouse_event->localPos().y()) / (double)height(); if (!mouse_tablet_in_proximity) mouse_tablet_in_proximity = mousedata.mouse_tablet_in_proximity; + mouse_x_abs -= rendererWindow->destinationF.left(); + mouse_y_abs -= rendererWindow->destinationF.top(); + + if (mouse_x_abs < 0) mouse_x_abs = 0; + if (mouse_y_abs < 0) mouse_y_abs = 0; + + mouse_x_abs /= rendererWindow->destinationF.width(); + mouse_y_abs /= rendererWindow->destinationF.height(); + + if (mouse_x_abs > 1) mouse_x_abs = 1; + if (mouse_y_abs > 1) mouse_y_abs = 1; } return QStackedWidget::event(event); } #ifdef Q_OS_WINDOWS if (mouse_input_mode == 0) { - mouse_x_abs = (mouse_event->localPos().x()) / (long double)width(); - mouse_y_abs = (mouse_event->localPos().y()) / (long double)height(); + mouse_x_abs = (mouse_event->localPos().x()) / (double)width(); + mouse_y_abs = (mouse_event->localPos().y()) / (double)height(); + mouse_x_abs -= rendererWindow->destinationF.left(); + mouse_y_abs -= rendererWindow->destinationF.top(); + + if (mouse_x_abs < 0) mouse_x_abs = 0; + if (mouse_y_abs < 0) mouse_y_abs = 0; + + mouse_x_abs /= rendererWindow->destinationF.width(); + mouse_y_abs /= rendererWindow->destinationF.height(); + + if (mouse_x_abs > 1) mouse_x_abs = 1; + if (mouse_y_abs > 1) mouse_y_abs = 1; return QStackedWidget::event(event); } #endif - mouse_x_abs = (mouse_event->localPos().x()) / (long double)width(); - mouse_y_abs = (mouse_event->localPos().y()) / (long double)height(); + mouse_x_abs = (mouse_event->localPos().x()) / (double)width(); + mouse_y_abs = (mouse_event->localPos().y()) / (double)height(); + mouse_x_abs -= rendererWindow->destinationF.left(); + mouse_y_abs -= rendererWindow->destinationF.top(); + + if (mouse_x_abs < 0) mouse_x_abs = 0; + if (mouse_y_abs < 0) mouse_y_abs = 0; + + mouse_x_abs /= rendererWindow->destinationF.width(); + mouse_y_abs /= rendererWindow->destinationF.height(); + + if (mouse_x_abs > 1) mouse_x_abs = 1; + if (mouse_y_abs > 1) mouse_y_abs = 1; mouse_tablet_in_proximity = mousedata.mouse_tablet_in_proximity; + } else switch (event->type()) { + case QEvent::TouchBegin: + case QEvent::TouchUpdate: + { +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + QTouchEvent* touchevent = (QTouchEvent*)event; + if (mouse_input_mode == 0) break; + if (touchevent->touchPoints().count()) { + mouse_x_abs = (touchevent->touchPoints()[0].pos().x()) / (double)width(); + mouse_y_abs = (touchevent->touchPoints()[0].pos().y()) / (double)height(); + mouse_x_abs -= rendererWindow->destinationF.left(); + mouse_y_abs -= rendererWindow->destinationF.top(); + + if (mouse_x_abs < 0) mouse_x_abs = 0; + if (mouse_y_abs < 0) mouse_y_abs = 0; + + mouse_x_abs /= rendererWindow->destinationF.width(); + mouse_y_abs /= rendererWindow->destinationF.height(); + + if (mouse_x_abs > 1) mouse_x_abs = 1; + if (mouse_y_abs > 1) mouse_y_abs = 1; + } + mouse_set_buttons_ex(mouse_get_buttons_ex() | 1); + touchevent->accept(); + return true; +#else + QTouchEvent* touchevent = (QTouchEvent*)event; + if (mouse_input_mode == 0) break; + if (touchevent->pointCount()) { + mouse_x_abs = (touchevent->point(0).position().x()) / (double)width(); + mouse_y_abs = (touchevent->point(0).position().y()) / (double)height(); + mouse_x_abs -= rendererWindow->destinationF.left(); + mouse_y_abs -= rendererWindow->destinationF.top(); + + if (mouse_x_abs < 0) mouse_x_abs = 0; + if (mouse_y_abs < 0) mouse_y_abs = 0; + + mouse_x_abs /= rendererWindow->destinationF.width(); + mouse_y_abs /= rendererWindow->destinationF.height(); + + if (mouse_x_abs > 1) mouse_x_abs = 1; + if (mouse_y_abs > 1) mouse_y_abs = 1; + } + mouse_set_buttons_ex(mouse_get_buttons_ex() | 1); + touchevent->accept(); + return true; +#endif + } + case QEvent::TouchEnd: + case QEvent::TouchCancel: + { +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + QTouchEvent* touchevent = (QTouchEvent*)event; + if (mouse_input_mode == 0) break; + if (touchevent->touchPoints().count()) { + mouse_x_abs = (touchevent->touchPoints()[0].pos().x()) / (double)width(); + mouse_y_abs = (touchevent->touchPoints()[0].pos().y()) / (double)height(); + mouse_x_abs -= rendererWindow->destinationF.left(); + mouse_y_abs -= rendererWindow->destinationF.top(); + + if (mouse_x_abs < 0) mouse_x_abs = 0; + if (mouse_y_abs < 0) mouse_y_abs = 0; + + mouse_x_abs /= rendererWindow->destinationF.width(); + mouse_y_abs /= rendererWindow->destinationF.height(); + + if (mouse_x_abs > 1) mouse_x_abs = 1; + if (mouse_y_abs > 1) mouse_y_abs = 1; + } + mouse_set_buttons_ex(mouse_get_buttons_ex() & ~1); + touchevent->accept(); + return true; +#else + QTouchEvent* touchevent = (QTouchEvent*)event; + if (mouse_input_mode == 0) break; + if (touchevent->pointCount()) { + mouse_x_abs = (touchevent->point(0).position().x()) / (double)width(); + mouse_y_abs = (touchevent->point(0).position().y()) / (double)height(); + mouse_x_abs -= rendererWindow->destinationF.left(); + mouse_y_abs -= rendererWindow->destinationF.top(); + + if (mouse_x_abs < 0) mouse_x_abs = 0; + if (mouse_y_abs < 0) mouse_y_abs = 0; + + mouse_x_abs /= rendererWindow->destinationF.width(); + mouse_y_abs /= rendererWindow->destinationF.height(); + + if (mouse_x_abs > 1) mouse_x_abs = 1; + if (mouse_y_abs > 1) mouse_y_abs = 1; + } + mouse_set_buttons_ex(mouse_get_buttons_ex() & ~1); + touchevent->accept(); + return true; +#endif + } + + default: + return QStackedWidget::event(event); } return QStackedWidget::event(event); @@ -505,6 +663,14 @@ RendererStack::setFocusRenderer() void RendererStack::onResize(int width, int height) { +#ifdef Q_OS_WINDOWS + if (mouse_capture) { + RECT rect; + if (GetWindowRect((HWND)this->winId(), &rect)) { + ClipCursor(&rect); + } + } +#endif if (rendererWindow) { rendererWindow->r_monitor_index = m_monitor_index; rendererWindow->onResize(width, height); diff --git a/src/qt/qt_rendererstack.hpp b/src/qt/qt_rendererstack.hpp index 5a08b351c..3a76f3ada 100644 --- a/src/qt/qt_rendererstack.hpp +++ b/src/qt/qt_rendererstack.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -14,11 +15,19 @@ #include #include "qt_renderercommon.hpp" +#include "qt_util.hpp" + +#include namespace Ui { class RendererStack; } +extern "C" +{ + extern int vid_resize; +} + class RendererCommon; class RendererStack : public QStackedWidget { Q_OBJECT @@ -41,6 +50,22 @@ public: void changeEvent(QEvent *event) override; void resizeEvent(QResizeEvent *event) override { + if (this->m_monitor_index != 0 && vid_resize != 1) { + int newX = pos().x(); + int newY = pos().y(); + + if (((frameGeometry().x() + event->size().width() + 1) > util::screenOfWidget(this)->availableGeometry().right())) { + //move(util::screenOfWidget(this)->availableGeometry().right() - size().width() - 1, pos().y()); + newX = util::screenOfWidget(this)->availableGeometry().right() - frameGeometry().width() - 1; + if (newX < 1) newX = 1; + } + + if (((frameGeometry().y() + event->size().height() + 1) > util::screenOfWidget(this)->availableGeometry().bottom())) { + newY = util::screenOfWidget(this)->availableGeometry().bottom() - frameGeometry().height() - 1; + if (newY < 1) newY = 1; + } + move(newX, newY); + } onResize(event->size().width(), event->size().height()); } void keyPressEvent(QKeyEvent *event) override @@ -69,6 +94,8 @@ public: void reloadOptions() const { return rendererWindow->reloadOptions(); } /* Returns options dialog for current renderer */ QDialog *getOptions(QWidget *parent) { return rendererWindow ? rendererWindow->getOptions(parent) : nullptr; } + /* Reload the renderer itself */ + bool reloadRendererOption() { return rendererWindow ? rendererWindow->reloadRendererOption() : false; } void setFocusRenderer(); void onResize(int width, int height); @@ -107,6 +134,11 @@ private: RendererCommon *rendererWindow { nullptr }; std::unique_ptr current; + + std::atomic_bool rendererTakesScreenshots; + std::atomic_bool switchInProgress{false}; + + char auto_mouse_type[16]; }; #endif // QT_RENDERERCONTAINER_HPP diff --git a/src/qt/qt_settings.cpp b/src/qt/qt_settings.cpp index 67064b73a..19a537652 100644 --- a/src/qt/qt_settings.cpp +++ b/src/qt/qt_settings.cpp @@ -95,7 +95,7 @@ SettingsModel::data(const QModelIndex &index, int role) const case Qt::DisplayRole: return tr(pages.at(index.row()).toUtf8().data()); case Qt::DecorationRole: - return QIcon(QString("%1/%2.ico").arg(ProgSettings::getIconSetPath(), page_icons[index.row()])); + return QIcon(QString(":/settings/qt/icons/%1.ico").arg(page_icons[index.row()])); case Qt::SizeHintRole: return QSize(-1, fontHeight * 2); default: @@ -153,6 +153,8 @@ Settings::Settings(QWidget *parent) &SettingsSound::onCurrentMachineChanged); connect(machine, &SettingsMachine::currentMachineChanged, network, &SettingsNetwork::onCurrentMachineChanged); + connect(machine, &SettingsMachine::currentMachineChanged, ports, + &SettingsPorts::onCurrentMachineChanged); connect(machine, &SettingsMachine::currentMachineChanged, storageControllers, &SettingsStorageControllers::onCurrentMachineChanged); connect(machine, &SettingsMachine::currentMachineChanged, otherPeripherals, diff --git a/src/qt/qt_settingsdisplay.cpp b/src/qt/qt_settingsdisplay.cpp index 50489ea61..83e19aec7 100644 --- a/src/qt/qt_settingsdisplay.cpp +++ b/src/qt/qt_settingsdisplay.cpp @@ -26,6 +26,7 @@ extern "C" { #include <86box/video.h> #include <86box/vid_8514a_device.h> #include <86box/vid_xga_device.h> +#include <86box/vid_ps55da2.h> } #include "qt_deviceconfig.hpp" @@ -50,21 +51,29 @@ SettingsDisplay::~SettingsDisplay() void SettingsDisplay::save() { - gfxcard[0] = ui->comboBoxVideo->currentData().toInt(); // TODO +#if 0 + for (uint8_t i = 0; i < GFXCARD_MAX; ++i) { + QComboBox *cbox = findChild(QString("comboBoxVideo%1").arg(i + 1)); + gfxcard[i] = cbox->currentData().toInt(); + } +#else + gfxcard[0] = ui->comboBoxVideo->currentData().toInt(); for (uint8_t i = 1; i < GFXCARD_MAX; i ++) - gfxcard[i] = ui->comboBoxVideoSecondary->currentData().toInt(); + gfxcard[i] = ui->comboBoxVideoSecondary->currentData().toInt(); +#endif voodoo_enabled = ui->checkBoxVoodoo->isChecked() ? 1 : 0; ibm8514_standalone_enabled = ui->checkBox8514->isChecked() ? 1 : 0; xga_standalone_enabled = ui->checkBoxXga->isChecked() ? 1 : 0; + da2_standalone_enabled = ui->checkBoxDa2->isChecked() ? 1 : 0; } void SettingsDisplay::onCurrentMachineChanged(int machineId) { // win_settings_video_proc, WM_INITDIALOG - this->machineId = machineId; + this->machineId = machineId; auto curVideoCard = videoCard[0]; auto *model = ui->comboBoxVideo->model(); @@ -96,46 +105,47 @@ SettingsDisplay::onCurrentMachineChanged(int machineId) } model->removeRows(0, removeRows); + // TODO if (machine_has_flags(machineId, MACHINE_VIDEO_ONLY) > 0) { ui->comboBoxVideo->setEnabled(false); ui->comboBoxVideoSecondary->setEnabled(false); - ui->pushButtonConfigureSecondary->setEnabled(false); + ui->pushButtonConfigureVideoSecondary->setEnabled(false); selectedRow = 1; } else { ui->comboBoxVideo->setEnabled(true); ui->comboBoxVideoSecondary->setEnabled(true); - ui->pushButtonConfigureSecondary->setEnabled(true); + ui->pushButtonConfigureVideoSecondary->setEnabled(true); } ui->comboBoxVideo->setCurrentIndex(selectedRow); // TODO for (uint8_t i = 1; i < GFXCARD_MAX; i ++) if (gfxcard[i] == 0) - ui->pushButtonConfigureSecondary->setEnabled(false); + ui->pushButtonConfigureVideoSecondary->setEnabled(false); } void -SettingsDisplay::on_pushButtonConfigure_clicked() +SettingsDisplay::on_pushButtonConfigureVideo_clicked() { int videoCard = ui->comboBoxVideo->currentData().toInt(); auto *device = video_card_getdevice(videoCard); if (videoCard == VID_INTERNAL) device = machine_get_vid_device(machineId); - DeviceConfig::ConfigureDevice(device, 0, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(device); } void SettingsDisplay::on_pushButtonConfigureVoodoo_clicked() { - DeviceConfig::ConfigureDevice(&voodoo_device, 0, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(&voodoo_device); } void SettingsDisplay::on_pushButtonConfigure8514_clicked() { if (machine_has_bus(machineId, MACHINE_BUS_MCA) > 0) { - DeviceConfig::ConfigureDevice(&ibm8514_mca_device, 0, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(&ibm8514_mca_device); } else { - DeviceConfig::ConfigureDevice(&gen8514_isa_device, 0, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(&gen8514_isa_device); } } @@ -143,26 +153,32 @@ void SettingsDisplay::on_pushButtonConfigureXga_clicked() { if (machine_has_bus(machineId, MACHINE_BUS_MCA) > 0) { - DeviceConfig::ConfigureDevice(&xga_device, 0, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(&xga_device); } else { - DeviceConfig::ConfigureDevice(&xga_isa_device, 0, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(&xga_isa_device); } } +void +SettingsDisplay::on_pushButtonConfigureDa2_clicked() +{ + DeviceConfig::ConfigureDevice(&ps55da2_device); +} + void SettingsDisplay::on_comboBoxVideo_currentIndexChanged(int index) { - if (index < 0) { + if (index < 0) return; - } - static QRegularExpression voodooRegex("3dfx|voodoo|banshee", QRegularExpression::CaseInsensitiveOption); + + static QRegularExpression voodooRegex("3dfx|voodoo|banshee|raven", QRegularExpression::CaseInsensitiveOption); auto curVideoCard_2 = videoCard[1]; videoCard[0] = ui->comboBoxVideo->currentData().toInt(); if (videoCard[0] == VID_INTERNAL) - ui->pushButtonConfigure->setEnabled(machine_has_flags(machineId, MACHINE_VIDEO) && - device_has_config(machine_get_vid_device(machineId))); + ui->pushButtonConfigureVideo->setEnabled(machine_has_flags(machineId, MACHINE_VIDEO) && + device_has_config(machine_get_vid_device(machineId))); else - ui->pushButtonConfigure->setEnabled(video_card_has_config(videoCard[0]) > 0); + ui->pushButtonConfigureVideo->setEnabled(video_card_has_config(videoCard[0]) > 0); bool machineHasPci = machine_has_bus(machineId, MACHINE_BUS_PCI) > 0; ui->pushButtonConfigureVoodoo->setEnabled(machineHasPci && ui->checkBoxVoodoo->isChecked()); @@ -174,6 +190,7 @@ SettingsDisplay::on_comboBoxVideo_currentIndexChanged(int index) bool machineSupports8514 = ((machineHasIsa16 || machineHasMca) && !videoCardHas8514); bool machineSupportsXga = (((machineHasIsa16 && device_available(&xga_isa_device)) || (machineHasMca && device_available(&xga_device))) && !videoCardHasXga); + bool machineSupportsDa2 = machineHasMca && device_available(&ps55da2_device); ui->checkBox8514->setEnabled(machineSupports8514); ui->checkBox8514->setChecked(ibm8514_standalone_enabled && machineSupports8514); @@ -183,7 +200,11 @@ SettingsDisplay::on_comboBoxVideo_currentIndexChanged(int index) ui->checkBoxXga->setEnabled(machineSupportsXga); ui->checkBoxXga->setChecked(xga_standalone_enabled && machineSupportsXga); + ui->checkBoxDa2->setEnabled(machineSupportsDa2); + ui->checkBoxDa2->setChecked(da2_standalone_enabled && machineSupportsDa2); + ui->pushButtonConfigureXga->setEnabled(ui->checkBoxXga->isEnabled() && ui->checkBoxXga->isChecked()); + ui->pushButtonConfigureDa2->setEnabled(ui->checkBoxDa2->isEnabled() && ui->checkBoxDa2->isChecked()); int c = 2; @@ -207,9 +228,9 @@ SettingsDisplay::on_comboBoxVideo_currentIndexChanged(int index) int secondaryFlags = video_card_get_flags(c); if (video_card_available(c) && device_is_valid(video_dev, machineId) - && !((secondaryFlags == primaryFlags) && (secondaryFlags != VIDEO_FLAG_TYPE_SPECIAL)) - && !(((primaryFlags == VIDEO_FLAG_TYPE_8514) || (primaryFlags == VIDEO_FLAG_TYPE_XGA)) && (secondaryFlags != VIDEO_FLAG_TYPE_MDA) && (secondaryFlags != VIDEO_FLAG_TYPE_SPECIAL)) - && !((primaryFlags != VIDEO_FLAG_TYPE_MDA) && (primaryFlags != VIDEO_FLAG_TYPE_SPECIAL) && ((secondaryFlags == VIDEO_FLAG_TYPE_8514) || (secondaryFlags == VIDEO_FLAG_TYPE_XGA)))) { + && !((secondaryFlags == primaryFlags) && (secondaryFlags != VIDEO_FLAG_TYPE_SECONDARY)) + && !(((primaryFlags == VIDEO_FLAG_TYPE_8514) || (primaryFlags == VIDEO_FLAG_TYPE_XGA)) && (secondaryFlags != VIDEO_FLAG_TYPE_MDA) && (secondaryFlags != VIDEO_FLAG_TYPE_SECONDARY)) + && !((primaryFlags != VIDEO_FLAG_TYPE_MDA) && (primaryFlags != VIDEO_FLAG_TYPE_SECONDARY) && ((secondaryFlags == VIDEO_FLAG_TYPE_8514) || (secondaryFlags == VIDEO_FLAG_TYPE_XGA)))) { ui->comboBoxVideoSecondary->addItem(name, c); if (c == curVideoCard_2) ui->comboBoxVideoSecondary->setCurrentIndex(ui->comboBoxVideoSecondary->count() - 1); @@ -220,7 +241,7 @@ SettingsDisplay::on_comboBoxVideo_currentIndexChanged(int index) if ((videoCard[1] == 0) || (machine_has_flags(machineId, MACHINE_VIDEO_ONLY) > 0)) { ui->comboBoxVideoSecondary->setCurrentIndex(0); - ui->pushButtonConfigureSecondary->setEnabled(false); + ui->pushButtonConfigureVideoSecondary->setEnabled(false); } // Is the currently selected video card a voodoo? @@ -265,19 +286,25 @@ SettingsDisplay::on_checkBoxXga_stateChanged(int state) } void -SettingsDisplay::on_comboBoxVideoSecondary_currentIndexChanged(int index) +SettingsDisplay::on_checkBoxDa2_stateChanged(int state) { - if (index < 0) { - ui->pushButtonConfigureSecondary->setEnabled(false); - return; - } - videoCard[1] = ui->comboBoxVideoSecondary->currentData().toInt(); - ui->pushButtonConfigureSecondary->setEnabled(index != 0 && video_card_has_config(videoCard[1]) > 0); + ui->pushButtonConfigureDa2->setEnabled(state == Qt::Checked); } void -SettingsDisplay::on_pushButtonConfigureSecondary_clicked() +SettingsDisplay::on_comboBoxVideoSecondary_currentIndexChanged(int index) +{ + if (index < 0) { + ui->pushButtonConfigureVideoSecondary->setEnabled(false); + return; + } + videoCard[1] = ui->comboBoxVideoSecondary->currentData().toInt(); + ui->pushButtonConfigureVideoSecondary->setEnabled(index != 0 && video_card_has_config(videoCard[1]) > 0); +} + +void +SettingsDisplay::on_pushButtonConfigureVideoSecondary_clicked() { auto *device = video_card_getdevice(ui->comboBoxVideoSecondary->currentData().toInt()); - DeviceConfig::ConfigureDevice(device, 0, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(device); } diff --git a/src/qt/qt_settingsdisplay.hpp b/src/qt/qt_settingsdisplay.hpp index 3c28c52e0..7eca7cc60 100644 --- a/src/qt/qt_settingsdisplay.hpp +++ b/src/qt/qt_settingsdisplay.hpp @@ -22,20 +22,23 @@ public slots: void onCurrentMachineChanged(int machineId); private slots: - void on_pushButtonConfigureSecondary_clicked(); - -private slots: - void on_comboBoxVideoSecondary_currentIndexChanged(int index); - -private slots: - void on_checkBoxVoodoo_stateChanged(int state); - void on_checkBox8514_stateChanged(int state); - void on_checkBoxXga_stateChanged(int state); void on_comboBoxVideo_currentIndexChanged(int index); + void on_pushButtonConfigureVideo_clicked(); + + void on_comboBoxVideoSecondary_currentIndexChanged(int index); + void on_pushButtonConfigureVideoSecondary_clicked(); + + void on_checkBoxVoodoo_stateChanged(int state); void on_pushButtonConfigureVoodoo_clicked(); + + void on_checkBox8514_stateChanged(int state); void on_pushButtonConfigure8514_clicked(); + + void on_checkBoxXga_stateChanged(int state); void on_pushButtonConfigureXga_clicked(); - void on_pushButtonConfigure_clicked(); + + void on_checkBoxDa2_stateChanged(int state); + void on_pushButtonConfigureDa2_clicked(); private: Ui::SettingsDisplay *ui; diff --git a/src/qt/qt_settingsdisplay.ui b/src/qt/qt_settingsdisplay.ui index f6bbeeae0..c5eba7adf 100644 --- a/src/qt/qt_settingsdisplay.ui +++ b/src/qt/qt_settingsdisplay.ui @@ -26,28 +26,8 @@ 0 - - - - - 0 - 0 - - - - Configure - - - - - - - XGA Graphics - - - - + 0 @@ -72,15 +52,21 @@ - - + + + + + 0 + 0 + + Configure - + 0 @@ -92,41 +78,6 @@ - - - - IBM 8514/A Graphics - - - - - - - Voodoo 1 or 2 Graphics - - - - - - - Configure - - - - - - - Configure - - - - - - - Configure - - - @@ -140,7 +91,70 @@ - + + + + Configure + + + + + + + Voodoo 1 or 2 Graphics + + + + + + + Configure + + + + + + + IBM 8514/A Graphics + + + + + + + Configure + + + + + + + XGA Graphics + + + + + + + Configure + + + + + + + IBM PS/55 Display Adapter Graphics + + + + + + + Configure + + + + Qt::Vertical diff --git a/src/qt/qt_settingsfloppycdrom.cpp b/src/qt/qt_settingsfloppycdrom.cpp index db54315e4..bf1499076 100644 --- a/src/qt/qt_settingsfloppycdrom.cpp +++ b/src/qt/qt_settingsfloppycdrom.cpp @@ -46,11 +46,11 @@ setFloppyType(QAbstractItemModel *model, const QModelIndex &idx, int type) { QIcon icon; if (type == 0) - icon = ProgSettings::loadIcon("/floppy_disabled.ico"); + icon = QIcon(":/settings/qt/icons/floppy_disabled.ico"); else if (type >= 1 && type <= 6) - icon = ProgSettings::loadIcon("/floppy_525.ico"); + icon = QIcon(":/settings/qt/icons/floppy_525.ico"); else - icon = ProgSettings::loadIcon("/floppy_35.ico"); + icon = QIcon(":/settings/qt/icons/floppy_35.ico"); model->setData(idx, QObject::tr(fdd_getname(type))); model->setData(idx, type, Qt::UserRole); @@ -64,12 +64,12 @@ setCDROMBus(QAbstractItemModel *model, const QModelIndex &idx, uint8_t bus, uint switch (bus) { case CDROM_BUS_DISABLED: - icon = ProgSettings::loadIcon("/cdrom_disabled.ico"); + icon = QIcon(":/settings/qt/icons/cdrom_disabled.ico"); break; case CDROM_BUS_ATAPI: case CDROM_BUS_SCSI: case CDROM_BUS_MITSUMI: - icon = ProgSettings::loadIcon("/cdrom.ico"); + icon = QIcon(":/settings/qt/icons/cdrom.ico"); break; } @@ -90,6 +90,14 @@ setCDROMSpeed(QAbstractItemModel *model, const QModelIndex &idx, uint8_t speed) model->setData(i, speed, Qt::UserRole); } +static QString +CDROMName(int type) +{ + char temp[512]; + cdrom_get_name(type, temp); + return QObject::tr((const char *) temp); +} + static void setCDROMType(QAbstractItemModel *model, const QModelIndex &idx, int type) { @@ -97,7 +105,7 @@ setCDROMType(QAbstractItemModel *model, const QModelIndex &idx, int type) if (idx.siblingAtColumn(0).data(Qt::UserRole).toUInt() == CDROM_BUS_DISABLED) model->setData(i, QCoreApplication::translate("", "None")); else if (idx.siblingAtColumn(0).data(Qt::UserRole).toUInt() != CDROM_BUS_MITSUMI) - model->setData(i, QObject::tr(cdrom_getname(type))); + model->setData(i, CDROMName(type)); model->setData(i, type, Qt::UserRole); } @@ -156,8 +164,12 @@ SettingsFloppyCDROM::SettingsFloppyCDROM(QWidget *parent) auto idx = model->index(i, 0); int type = cdrom_get_type(i); setCDROMBus(model, idx, cdrom[i].bus_type, cdrom[i].res); - setCDROMSpeed(model, idx.siblingAtColumn(1), cdrom[i].speed); setCDROMType(model, idx.siblingAtColumn(2), type); + int speed = cdrom_get_speed(type); + if (speed == -1) + setCDROMSpeed(model, idx.siblingAtColumn(1), cdrom[i].speed); + else + setCDROMSpeed(model, idx.siblingAtColumn(1), speed); if (cdrom[i].bus_type == CDROM_BUS_ATAPI) Harddrives::busTrackClass->device_track(1, DEV_CDROM, cdrom[i].bus_type, cdrom[i].ide_channel); else if (cdrom[i].bus_type == CDROM_BUS_SCSI) @@ -186,9 +198,9 @@ SettingsFloppyCDROM::SettingsFloppyCDROM(QWidget *parent) if (((bus_type == CDROM_BUS_ATAPI) || (bus_type == CDROM_BUS_SCSI)) && ((cdrom_drive_types[j].bus_type == bus_type) || (cdrom_drive_types[j].bus_type == BUS_TYPE_BOTH))) { - QString name = tr(cdrom_getname(j)); + QString name = CDROMName(j); Models::AddEntry(modelType, name, j); - if ((cdrom[cdromIdx].bus_type == bus_type) && (cdrom[cdromIdx].type == j)) + if (cdrom[cdromIdx].type == j) selectedTypeRow = eligibleRows; ++eligibleRows; } @@ -244,10 +256,9 @@ SettingsFloppyCDROM::onFloppyRowChanged(const QModelIndex ¤t) void SettingsFloppyCDROM::onCDROMRowChanged(const QModelIndex ¤t) { - uint8_t bus = current.siblingAtColumn(0).data(Qt::UserRole).toUInt(); - uint8_t channel = current.siblingAtColumn(0).data(Qt::UserRole + 1).toUInt(); - uint8_t speed = current.siblingAtColumn(1).data(Qt::UserRole).toUInt(); - int type = current.siblingAtColumn(2).data(Qt::UserRole).toInt(); + uint8_t bus = current.siblingAtColumn(0).data(Qt::UserRole).toUInt(); + uint8_t channel = current.siblingAtColumn(0).data(Qt::UserRole + 1).toUInt(); + uint32_t type = current.siblingAtColumn(2).data(Qt::UserRole).toUInt(); ui->comboBoxBus->setCurrentIndex(-1); auto* model = ui->comboBoxBus->model(); @@ -260,8 +271,37 @@ SettingsFloppyCDROM::onCDROMRowChanged(const QModelIndex ¤t) if (!match.isEmpty()) ui->comboBoxChannel->setCurrentIndex(match.first().row()); + int speed = cdrom_get_speed(type); + if (speed == -1) { + speed = current.siblingAtColumn(1).data(Qt::UserRole).toUInt(); + ui->comboBoxSpeed->setEnabled(true); + } else + ui->comboBoxSpeed->setEnabled(false); ui->comboBoxSpeed->setCurrentIndex(speed == 0 ? 7 : speed - 1); - ui->comboBoxCDROMType->setCurrentIndex(type); + + auto *modelType = ui->comboBoxCDROMType->model(); + int removeRows = modelType->rowCount(); + + uint32_t j = 0; + int selectedTypeRow = 0; + int eligibleRows = 0; + while (cdrom_drive_types[j].bus_type != BUS_TYPE_NONE) { + if (((bus == CDROM_BUS_ATAPI) || (bus == CDROM_BUS_SCSI)) && + ((cdrom_drive_types[j].bus_type == bus) || + (cdrom_drive_types[j].bus_type == BUS_TYPE_BOTH))) { + QString name = CDROMName(j); + Models::AddEntry(modelType, name, j); + if (type == j) + selectedTypeRow = eligibleRows; + ++eligibleRows; + } + ++j; + } + modelType->removeRows(0, removeRows); + ui->comboBoxCDROMType->setEnabled(eligibleRows > 1); + ui->comboBoxCDROMType->setCurrentIndex(-1); + ui->comboBoxCDROMType->setCurrentIndex(selectedTypeRow); + enableCurrentlySelectedChannel(); } @@ -319,9 +359,9 @@ SettingsFloppyCDROM::on_comboBoxSpeed_activated(int index) void SettingsFloppyCDROM::on_comboBoxBus_activated(int) { - auto i = ui->tableViewCDROM->selectionModel()->currentIndex().siblingAtColumn(0); + auto i = ui->tableViewCDROM->selectionModel()->currentIndex().siblingAtColumn(0); uint8_t bus_type = ui->comboBoxBus->currentData().toUInt(); - int cdromIdx = ui->tableViewCDROM->selectionModel()->currentIndex().data().toInt(); + int cdromIdx = ui->tableViewCDROM->selectionModel()->currentIndex().data().toInt(); Harddrives::busTrackClass->device_track(0, DEV_CDROM, ui->tableViewCDROM->model()->data(i, Qt::UserRole).toInt(), ui->tableViewCDROM->model()->data(i, @@ -344,16 +384,16 @@ SettingsFloppyCDROM::on_comboBoxBus_activated(int) auto *modelType = ui->comboBoxCDROMType->model(); int removeRows = modelType->rowCount(); - uint32_t j = 0; - int selectedTypeRow = 0; - int eligibleRows = 0; + uint32_t j = 0; + int selectedTypeRow = 0; + int eligibleRows = 0; while (cdrom_drive_types[j].bus_type != BUS_TYPE_NONE) { if (((bus_type == CDROM_BUS_ATAPI) || (bus_type == CDROM_BUS_SCSI)) && ((cdrom_drive_types[j].bus_type == bus_type) || (cdrom_drive_types[j].bus_type == BUS_TYPE_BOTH))) { - QString name = tr(cdrom_getname(j)); + QString name = CDROMName(j); Models::AddEntry(modelType, name, j); - if ((cdrom[cdromIdx].bus_type == bus_type) && (cdrom[cdromIdx].type == j)) + if (cdrom[cdromIdx].type == j) selectedTypeRow = eligibleRows; ++eligibleRows; } @@ -374,11 +414,10 @@ void SettingsFloppyCDROM::enableCurrentlySelectedChannel() { const auto *item_model = qobject_cast(ui->comboBoxChannel->model()); - const auto index = ui->comboBoxChannel->currentIndex(); - auto *item = item_model->item(index); - if(item) { + const auto index = ui->comboBoxChannel->currentIndex(); + auto *item = item_model->item(index); + if(item) item->setEnabled(true); - } } void @@ -401,9 +440,22 @@ SettingsFloppyCDROM::on_comboBoxChannel_activated(int) void SettingsFloppyCDROM::on_comboBoxCDROMType_activated(int) { + int type = ui->comboBoxCDROMType->currentData().toUInt(); + setCDROMType(ui->tableViewCDROM->model(), ui->tableViewCDROM->selectionModel()->currentIndex(), - ui->comboBoxCDROMType->currentData().toUInt()); + type); ui->tableViewCDROM->resizeColumnsToContents(); ui->tableViewCDROM->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); + + int speed = cdrom_get_speed(type); + if (speed == -1) { + speed = ui->comboBoxSpeed->currentData().toUInt(); + ui->comboBoxSpeed->setEnabled(true); + } else + ui->comboBoxSpeed->setEnabled(false); + ui->comboBoxSpeed->setCurrentIndex(speed == 0 ? 7 : speed - 1); + + auto idx = ui->tableViewCDROM->selectionModel()->currentIndex(); + setCDROMSpeed(ui->tableViewCDROM->model(), idx.siblingAtColumn(1), speed); } diff --git a/src/qt/qt_settingsfloppycdrom.hpp b/src/qt/qt_settingsfloppycdrom.hpp index 0a3424216..063942201 100644 --- a/src/qt/qt_settingsfloppycdrom.hpp +++ b/src/qt/qt_settingsfloppycdrom.hpp @@ -19,17 +19,20 @@ public: signals: void cdromChannelChanged(); + private slots: - void on_comboBoxCDROMType_activated(int index); - void on_comboBoxChannel_activated(int index); - void on_comboBoxBus_activated(int index); - void on_comboBoxSpeed_activated(int index); - void on_comboBoxBus_currentIndexChanged(int index); - void on_comboBoxFloppyType_activated(int index); - void on_checkBoxCheckBPB_stateChanged(int arg1); - void on_checkBoxTurboTimings_stateChanged(int arg1); void onFloppyRowChanged(const QModelIndex ¤t); + void on_comboBoxFloppyType_activated(int index); + void on_checkBoxTurboTimings_stateChanged(int arg1); + void on_checkBoxCheckBPB_stateChanged(int arg1); + void onCDROMRowChanged(const QModelIndex ¤t); + void on_comboBoxBus_activated(int index); + void on_comboBoxBus_currentIndexChanged(int index); + void on_comboBoxChannel_activated(int index); + void on_comboBoxSpeed_activated(int index); + void on_comboBoxCDROMType_activated(int index); + private: Ui::SettingsFloppyCDROM *ui; diff --git a/src/qt/qt_settingsfloppycdrom.ui b/src/qt/qt_settingsfloppycdrom.ui index b9a937d8d..7dde46631 100644 --- a/src/qt/qt_settingsfloppycdrom.ui +++ b/src/qt/qt_settingsfloppycdrom.ui @@ -27,7 +27,7 @@ 0 - + Floppy drives: @@ -68,7 +68,7 @@ - + Type: @@ -99,7 +99,7 @@ - + CD-ROM drives: @@ -140,33 +140,12 @@ - + Bus: - - - - Channel: - - - - - - - Speed: - - - - - - - Type: - - - @@ -174,6 +153,13 @@ + + + + Channel: + + + @@ -181,6 +167,13 @@ + + + + Speed: + + + @@ -188,6 +181,13 @@ + + + + Type: + + + diff --git a/src/qt/qt_settingsharddisks.cpp b/src/qt/qt_settingsharddisks.cpp index 4f6811ff1..6d82f2b77 100644 --- a/src/qt/qt_settingsharddisks.cpp +++ b/src/qt/qt_settingsharddisks.cpp @@ -49,13 +49,12 @@ static void normalize_hd_list() { hard_disk_t ihdd[HDD_NUM]; - int j; + int j = 0; - j = 0; memset(ihdd, 0x00, HDD_NUM * sizeof(hard_disk_t)); for (uint8_t i = 0; i < HDD_NUM; i++) { - if (temp_hdd[i].bus != HDD_BUS_DISABLED) { + if (temp_hdd[i].bus_type != HDD_BUS_DISABLED) { memcpy(&(ihdd[j]), &(temp_hdd[i]), sizeof(hard_disk_t)); j++; } @@ -75,24 +74,24 @@ static void addRow(QAbstractItemModel *model, hard_disk_t *hd) { const QString userPath = usr_path; - int row = model->rowCount(); + model->insertRow(row); - QString busName = Harddrives::BusChannelName(hd->bus, hd->channel); + QString busName = Harddrives::BusChannelName(hd->bus_type, hd->channel); model->setData(model->index(row, ColumnBus), busName); - model->setData(model->index(row, ColumnBus), ProgSettings::loadIcon("/hard_disk.ico"), Qt::DecorationRole); - model->setData(model->index(row, ColumnBus), hd->bus, DataBus); - model->setData(model->index(row, ColumnBus), hd->bus, DataBusPrevious); + model->setData(model->index(row, ColumnBus), QIcon(":/settings/qt/icons/hard_disk.ico"), Qt::DecorationRole); + model->setData(model->index(row, ColumnBus), hd->bus_type, DataBus); + model->setData(model->index(row, ColumnBus), hd->bus_type, DataBusPrevious); model->setData(model->index(row, ColumnBus), hd->channel, DataBusChannel); model->setData(model->index(row, ColumnBus), hd->channel, DataBusChannelPrevious); - Harddrives::busTrackClass->device_track(1, DEV_HDD, hd->bus, hd->channel); + Harddrives::busTrackClass->device_track(1, DEV_HDD, hd->bus_type, hd->channel); QString fileName = hd->fn; - if (fileName.startsWith(userPath, Qt::CaseInsensitive)) { + if (fileName.startsWith(userPath, Qt::CaseInsensitive)) model->setData(model->index(row, ColumnFilename), fileName.mid(userPath.size())); - } else { + else model->setData(model->index(row, ColumnFilename), fileName); - } + model->setData(model->index(row, ColumnFilename), fileName, Qt::UserRole); model->setData(model->index(row, ColumnCylinders), hd->tracks); @@ -116,13 +115,12 @@ SettingsHarddisks::SettingsHarddisks(QWidget *parent) model->setHeaderData(ColumnHeads, Qt::Horizontal, tr("H")); model->setHeaderData(ColumnSectors, Qt::Horizontal, tr("S")); model->setHeaderData(ColumnSize, Qt::Horizontal, tr("MiB")); - model->setHeaderData(ColumnSpeed, Qt::Horizontal, tr("Speed")); + model->setHeaderData(ColumnSpeed, Qt::Horizontal, tr("Model")); ui->tableView->setModel(model); for (int i = 0; i < HDD_NUM; i++) { - if (hdd[i].bus > 0) { + if (hdd[i].bus_type > 0) addRow(model, &hdd[i]); - } } if (model->rowCount() == HDD_NUM) { ui->pushButtonNew->setEnabled(false); @@ -153,7 +151,7 @@ SettingsHarddisks::save() int rows = model->rowCount(); for (int i = 0; i < rows; ++i) { auto idx = model->index(i, ColumnBus); - hdd[i].bus = idx.data(DataBus).toUInt(); + hdd[i].bus_type = idx.data(DataBus).toUInt(); hdd[i].channel = idx.data(DataBusChannel).toUInt(); hdd[i].tracks = idx.siblingAtColumn(ColumnCylinders).data().toUInt(); hdd[i].hpc = idx.siblingAtColumn(ColumnHeads).data().toUInt(); @@ -176,9 +174,8 @@ void SettingsHarddisks::reloadBusChannels() { void SettingsHarddisks::on_comboBoxBus_currentIndexChanged(int index) { - if (index < 0) { + if (index < 0) return; - } buschangeinprogress = true; auto idx = ui->tableView->selectionModel()->currentIndex(); @@ -226,9 +223,8 @@ SettingsHarddisks::on_comboBoxBus_currentIndexChanged(int index) void SettingsHarddisks::on_comboBoxChannel_currentIndexChanged(int index) { - if (index < 0) { + if (index < 0) return; - } auto idx = ui->tableView->selectionModel()->currentIndex(); if (idx.isValid()) { @@ -250,17 +246,15 @@ SettingsHarddisks::enableCurrentlySelectedChannel() const auto *item_model = qobject_cast(ui->comboBoxChannel->model()); const auto index = ui->comboBoxChannel->currentIndex(); auto *item = item_model->item(index); - if(item) { + if(item) item->setEnabled(true); - } } void SettingsHarddisks::on_comboBoxSpeed_currentIndexChanged(int index) { - if (index < 0) { + if (index < 0) return; - } auto idx = ui->tableView->selectionModel()->currentIndex(); if (idx.isValid()) { @@ -288,20 +282,19 @@ SettingsHarddisks::onTableRowChanged(const QModelIndex ¤t) auto *model = ui->comboBoxBus->model(); auto match = model->match(model->index(0, 0), Qt::UserRole, bus); - if (!match.isEmpty()) { + if (!match.isEmpty()) ui->comboBoxBus->setCurrentIndex(match.first().row()); - } + model = ui->comboBoxChannel->model(); match = model->match(model->index(0, 0), Qt::UserRole, busChannel); - if (!match.isEmpty()) { + if (!match.isEmpty()) ui->comboBoxChannel->setCurrentIndex(match.first().row()); - } model = ui->comboBoxSpeed->model(); match = model->match(model->index(0, 0), Qt::UserRole, speed); - if (!match.isEmpty()) { + if (!match.isEmpty()) ui->comboBoxSpeed->setCurrentIndex(match.first().row()); - } + reloadBusChannels(); } @@ -313,11 +306,11 @@ addDriveFromDialog(Ui::SettingsHarddisks *ui, const HarddiskDialog &dlg) hard_disk_t hd; memset(&hd, 0, sizeof(hd)); - hd.bus = dlg.bus(); - hd.channel = dlg.channel(); - hd.tracks = dlg.cylinders(); - hd.hpc = dlg.heads(); - hd.spt = dlg.sectors(); + hd.bus_type = dlg.bus(); + hd.channel = dlg.channel(); + hd.tracks = dlg.cylinders(); + hd.hpc = dlg.heads(); + hd.spt = dlg.sectors(); strncpy(hd.fn, fn.data(), sizeof(hd.fn) - 1); hd.speed_preset = dlg.speed(); @@ -358,11 +351,10 @@ void SettingsHarddisks::on_pushButtonRemove_clicked() { auto idx = ui->tableView->selectionModel()->currentIndex(); - if (!idx.isValid()) { + if (!idx.isValid()) return; - } - auto *model = ui->tableView->model(); + auto *model = ui->tableView->model(); const auto col = idx.siblingAtColumn(ColumnBus); Harddrives::busTrackClass->device_track(0, DEV_HDD, model->data(col, DataBus).toInt(), model->data(col, DataBusChannel).toInt()); model->removeRow(idx.row()); diff --git a/src/qt/qt_settingsharddisks.hpp b/src/qt/qt_settingsharddisks.hpp index 4bd287d29..f892a79cd 100644 --- a/src/qt/qt_settingsharddisks.hpp +++ b/src/qt/qt_settingsharddisks.hpp @@ -21,14 +21,13 @@ signals: void driveChannelChanged(); private slots: + void on_comboBoxBus_currentIndexChanged(int index); void on_comboBoxChannel_currentIndexChanged(int index); void on_comboBoxSpeed_currentIndexChanged(int index); -private slots: - void on_pushButtonRemove_clicked(); - void on_pushButtonExisting_clicked(); void on_pushButtonNew_clicked(); - void on_comboBoxBus_currentIndexChanged(int index); + void on_pushButtonExisting_clicked(); + void on_pushButtonRemove_clicked(); void onTableRowChanged(const QModelIndex ¤t); diff --git a/src/qt/qt_settingsharddisks.ui b/src/qt/qt_settingsharddisks.ui index 3ae20fee1..f996c76d1 100644 --- a/src/qt/qt_settingsharddisks.ui +++ b/src/qt/qt_settingsharddisks.ui @@ -46,7 +46,7 @@ - + @@ -78,7 +78,7 @@ - Speed: + Model: diff --git a/src/qt/qt_settingsinput.cpp b/src/qt/qt_settingsinput.cpp index 05e44c2c0..6d89c511a 100644 --- a/src/qt/qt_settingsinput.cpp +++ b/src/qt/qt_settingsinput.cpp @@ -16,8 +16,12 @@ */ #include "qt_settingsinput.hpp" #include "ui_qt_settingsinput.h" +#include "qt_mainwindow.hpp" +#include "qt_progsettings.hpp" #include +#include +#include extern "C" { #include <86box/86box.h> @@ -25,11 +29,18 @@ extern "C" { #include <86box/machine.h> #include <86box/mouse.h> #include <86box/gameport.h> +#include <86box/ui.h> } #include "qt_models_common.hpp" #include "qt_deviceconfig.hpp" #include "qt_joystickconfiguration.hpp" +#include "qt_keybind.hpp" + +extern MainWindow *main_window; + +// Temporary working copy of key list +accelKey acc_keys_t[NUM_ACCELS]; SettingsInput::SettingsInput(QWidget *parent) : QWidget(parent) @@ -37,6 +48,37 @@ SettingsInput::SettingsInput(QWidget *parent) { ui->setupUi(this); + QStringList horizontalHeader; + QStringList verticalHeader; + + horizontalHeader.append(tr("Action")); + horizontalHeader.append(tr("Keybind")); + + QTableWidget *keyTable = ui->tableKeys; + keyTable->setRowCount(10); + keyTable->setColumnCount(3); + keyTable->setColumnHidden(2, true); + keyTable->setColumnWidth(0, 200); + keyTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + QStringList headers; + //headers << "Action" << "Bound key"; + keyTable->setHorizontalHeaderLabels(horizontalHeader); + keyTable->verticalHeader()->setVisible(false); + keyTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + keyTable->setSelectionBehavior(QAbstractItemView::SelectRows); + keyTable->setSelectionMode(QAbstractItemView::SingleSelection); + keyTable->setShowGrid(true); + + // Make a working copy of acc_keys so we can check for dupes later without getting + // confused + for(int x = 0; x < NUM_ACCELS; x++) { + strcpy(acc_keys_t[x].name, acc_keys[x].name); + strcpy(acc_keys_t[x].desc, acc_keys[x].desc); + strcpy(acc_keys_t[x].seq, acc_keys[x].seq); + } + + refreshInputList(); + onCurrentMachineChanged(machine); } @@ -50,6 +92,14 @@ SettingsInput::save() { mouse_type = ui->comboBoxMouse->currentData().toInt(); joystick_type = ui->comboBoxJoystick->currentData().toInt(); + + // Copy accelerators from working set to global set + for(int x = 0; x < NUM_ACCELS; x++) { + strcpy(acc_keys[x].name, acc_keys_t[x].name); + strcpy(acc_keys[x].desc, acc_keys_t[x].desc); + strcpy(acc_keys[x].seq, acc_keys_t[x].seq); + } + ProgSettings::reloadStrings(); } void @@ -64,13 +114,11 @@ SettingsInput::onCurrentMachineChanged(int machineId) int selectedRow = 0; for (int i = 0; i < mouse_get_ndev(); ++i) { const auto *dev = mouse_get_device(i); - if ((i == MOUSE_TYPE_INTERNAL) && (machine_has_flags(machineId, MACHINE_MOUSE) == 0)) { + if ((i == MOUSE_TYPE_INTERNAL) && (machine_has_flags(machineId, MACHINE_MOUSE) == 0)) continue; - } - if (device_is_valid(dev, machineId) == 0) { + if (device_is_valid(dev, machineId) == 0) continue; - } QString name = DeviceConfig::DeviceName(dev, mouse_get_internal_name(i), 0); int row = mouseModel->rowCount(); @@ -80,9 +128,8 @@ SettingsInput::onCurrentMachineChanged(int machineId) mouseModel->setData(idx, name, Qt::DisplayRole); mouseModel->setData(idx, i, Qt::UserRole); - if (i == mouse_type) { + if (i == mouse_type) selectedRow = row - removeRows; - } } mouseModel->removeRows(0, removeRows); ui->comboBoxMouse->setCurrentIndex(selectedRow); @@ -90,13 +137,12 @@ SettingsInput::onCurrentMachineChanged(int machineId) int i = 0; const char *joyName = joystick_get_name(i); auto *joystickModel = ui->comboBoxJoystick->model(); - removeRows = joystickModel->rowCount(); - selectedRow = 0; + removeRows = joystickModel->rowCount(); + selectedRow = 0; while (joyName) { int row = Models::AddEntry(joystickModel, tr(joyName).toUtf8().data(), i); - if (i == joystick_type) { + if (i == joystick_type) selectedRow = row - removeRows; - } ++i; joyName = joystick_get_name(i); @@ -105,6 +151,100 @@ SettingsInput::onCurrentMachineChanged(int machineId) ui->comboBoxJoystick->setCurrentIndex(selectedRow); } +void +SettingsInput::refreshInputList() +{ + for (int x = 0; x < NUM_ACCELS; x++) { + ui->tableKeys->setItem(x, 0, new QTableWidgetItem(tr(acc_keys_t[x].desc))); + ui->tableKeys->setItem(x, 1, new QTableWidgetItem(QKeySequence(acc_keys_t[x].seq, QKeySequence::PortableText).toString(QKeySequence::NativeText))); + ui->tableKeys->setItem(x, 2, new QTableWidgetItem(acc_keys_t[x].name)); + } +} + +void +SettingsInput::on_tableKeys_currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn) +{ + // Enable/disable bind/clear buttons if user clicked valid row + QTableWidgetItem *cell = ui->tableKeys->item(currentRow,1); + if (!cell) { + ui->pushButtonBind->setEnabled(false); + ui->pushButtonClearBind->setEnabled(false); + } else { + ui->pushButtonBind->setEnabled(true); + ui->pushButtonClearBind->setEnabled(true); + } +} + +void +SettingsInput::on_tableKeys_cellDoubleClicked(int row, int col) +{ + // Edit bind + QTableWidgetItem *cell = ui->tableKeys->item(row,1); + if (!cell) + return; + + QKeySequence keyseq = KeyBinder::BindKey(this, cell->text()); + if (keyseq != false) { + // If no change was made, don't change anything. + if (keyseq.toString(QKeySequence::NativeText) == cell->text()) + return; + + // Otherwise, check for conflicts. + // Check against the *working* copy - NOT the one in use by the app, + // so we don't test against shortcuts the user already changed. + for(int x = 0; x < NUM_ACCELS; x++) { + if(QString::fromStdString(acc_keys_t[x].seq) == keyseq.toString(QKeySequence::PortableText)) { + // That key is already in use + main_window->showMessage(MBX_ANSI & MBX_INFO, "Bind conflict", "This key combo is already in use", false); + return; + } + } + // If we made it here, there were no conflicts. + // Go ahead and apply the bind. + + // Find the correct accelerator key entry + int accKeyID = FindAccelerator(ui->tableKeys->item(row,2)->text().toUtf8().constData()); + if (accKeyID < 0) + return; // this should never happen + + // Make the change + cell->setText(keyseq.toString(QKeySequence::NativeText)); + strcpy(acc_keys_t[accKeyID].seq, keyseq.toString(QKeySequence::PortableText).toUtf8().constData()); + + refreshInputList(); + } +} + +void +SettingsInput::on_pushButtonBind_clicked() +{ + // Edit bind + QTableWidgetItem *cell = ui->tableKeys->currentItem(); + if (!cell) + return; + + on_tableKeys_cellDoubleClicked(cell->row(), cell->column()); +} + +void +SettingsInput::on_pushButtonClearBind_clicked() +{ + // Wipe bind + QTableWidgetItem *cell = ui->tableKeys->item(ui->tableKeys->currentRow(), 1); + if (!cell) + return; + + cell->setText(""); + // Find the correct accelerator key entry + int accKeyID = FindAccelerator(ui->tableKeys->item(cell->row(),2)->text().toUtf8().constData()); + if (accKeyID < 0) + return; // this should never happen + + // Make the change + cell->setText(""); + strcpy(acc_keys_t[accKeyID].seq, ""); +} + void SettingsInput::on_comboBoxMouse_currentIndexChanged(int index) { @@ -118,9 +258,9 @@ SettingsInput::on_comboBoxJoystick_currentIndexChanged(int index) int joystickId = ui->comboBoxJoystick->currentData().toInt(); for (int i = 0; i < MAX_JOYSTICKS; ++i) { auto *btn = findChild(QString("pushButtonJoystick%1").arg(i + 1)); - if (btn == nullptr) { + if (btn == nullptr) continue; - } + btn->setEnabled(joystick_get_max_joysticks(joystickId) > i); } } @@ -129,18 +269,17 @@ void SettingsInput::on_pushButtonConfigureMouse_clicked() { int mouseId = ui->comboBoxMouse->currentData().toInt(); - DeviceConfig::ConfigureDevice(mouse_get_device(mouseId), 0, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(mouse_get_device(mouseId)); } static int get_axis(JoystickConfiguration &jc, int axis, int joystick_nr) { int axis_sel = jc.selectedAxis(axis); - int nr_axes = plat_joystick_state[joystick_state[joystick_nr].plat_joystick_nr - 1].nr_axes; + int nr_axes = plat_joystick_state[joystick_state[0][joystick_nr].plat_joystick_nr - 1].nr_axes; - if (axis_sel < nr_axes) { + if (axis_sel < nr_axes) return axis_sel; - } axis_sel -= nr_axes; if (axis_sel & 1) @@ -153,7 +292,7 @@ static int get_pov(JoystickConfiguration &jc, int pov, int joystick_nr) { int pov_sel = jc.selectedPov(pov); - int nr_povs = plat_joystick_state[joystick_state[joystick_nr].plat_joystick_nr - 1].nr_povs * 2; + int nr_povs = plat_joystick_state[joystick_state[0][joystick_nr].plat_joystick_nr - 1].nr_povs * 2; if (pov_sel < nr_povs) { if (pov_sel & 1) @@ -176,17 +315,19 @@ updateJoystickConfig(int type, int joystick_nr, QWidget *parent) break; } - joystick_state[joystick_nr].plat_joystick_nr = jc.selectedDevice(); - if (joystick_state[joystick_nr].plat_joystick_nr) { - for (int c = 0; c < joystick_get_axis_count(type); c++) { - joystick_state[joystick_nr].axis_mapping[c] = get_axis(jc, c, joystick_nr); + joystick_state[0][joystick_nr].plat_joystick_nr = jc.selectedDevice(); + if (joystick_state[0][joystick_nr].plat_joystick_nr) { + for (int axis_nr = 0; axis_nr < joystick_get_axis_count(type); axis_nr++) { + joystick_state[0][joystick_nr].axis_mapping[axis_nr] = get_axis(jc, axis_nr, joystick_nr); } - for (int c = 0; c < joystick_get_button_count(type); c++) { - joystick_state[joystick_nr].button_mapping[c] = jc.selectedButton(c); + + for (int button_nr = 0; button_nr < joystick_get_button_count(type); button_nr++) { + joystick_state[0][joystick_nr].button_mapping[button_nr] = jc.selectedButton(button_nr); } - for (int c = 0; c < joystick_get_pov_count(type) * 2; c += 2) { - joystick_state[joystick_nr].pov_mapping[c][0] = get_pov(jc, c, joystick_nr); - joystick_state[joystick_nr].pov_mapping[c][1] = get_pov(jc, c + 1, joystick_nr); + + for (int pov_nr = 0; pov_nr < joystick_get_pov_count(type) * 2; pov_nr += 2) { + joystick_state[0][joystick_nr].pov_mapping[pov_nr][0] = get_pov(jc, pov_nr, joystick_nr); + joystick_state[0][joystick_nr].pov_mapping[pov_nr][1] = get_pov(jc, pov_nr + 1, joystick_nr); } } } diff --git a/src/qt/qt_settingsinput.hpp b/src/qt/qt_settingsinput.hpp index 0b8b665aa..a51ad2564 100644 --- a/src/qt/qt_settingsinput.hpp +++ b/src/qt/qt_settingsinput.hpp @@ -2,6 +2,12 @@ #define QT_SETTINGSINPUT_HPP #include +#include +#include +#include +#include +#include +#include namespace Ui { class SettingsInput; @@ -20,17 +26,25 @@ public slots: void onCurrentMachineChanged(int machineId); private slots: - void on_pushButtonConfigureMouse_clicked(); - void on_comboBoxJoystick_currentIndexChanged(int index); void on_comboBoxMouse_currentIndexChanged(int index); + void on_pushButtonConfigureMouse_clicked(); + + void on_comboBoxJoystick_currentIndexChanged(int index); void on_pushButtonJoystick1_clicked(); void on_pushButtonJoystick2_clicked(); void on_pushButtonJoystick3_clicked(); void on_pushButtonJoystick4_clicked(); + void on_tableKeys_cellDoubleClicked(int row, int col); + void on_tableKeys_currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn); + + void on_pushButtonClearBind_clicked(); + void on_pushButtonBind_clicked(); + private: Ui::SettingsInput *ui; int machineId = 0; + void refreshInputList(); }; #endif // QT_SETTINGSINPUT_HPP diff --git a/src/qt/qt_settingsinput.ui b/src/qt/qt_settingsinput.ui index 839461119..6ac6cf38a 100644 --- a/src/qt/qt_settingsinput.ui +++ b/src/qt/qt_settingsinput.ui @@ -23,61 +23,23 @@ 0 - - - - Joystick 2... - - - - - - - Joystick: - - - - - - - Joystick 4... - - - - + Mouse: - - - - Joystick 3... + + + + + 0 + 0 + - - - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 20 - 40 - - - - - - - - Joystick 1... + + 30 @@ -94,16 +56,10 @@ - - - - 30 - - - - 0 - 0 - + + + + Joystick: @@ -114,6 +70,80 @@ + + + + Joystick 1... + + + + + + + Joystick 2... + + + + + + + Joystick 3... + + + + + + + Joystick 4... + + + + + + + Key Bindings: + + + + + + + QAbstractItemView::EditTrigger::NoEditTriggers + + + false + + + false + + + true + + + QAbstractItemView::SelectionBehavior::SelectRows + + + + + + + false + + + Clear binding + + + + + + + false + + + Bind + + + diff --git a/src/qt/qt_settingsmachine.cpp b/src/qt/qt_settingsmachine.cpp index 771f1cbec..fb5576f69 100644 --- a/src/qt/qt_settingsmachine.cpp +++ b/src/qt/qt_settingsmachine.cpp @@ -32,13 +32,9 @@ extern "C" { #include <86box/config.h> #include <86box/device.h> #include <86box/machine.h> +#include <86box/nvr.h> } -// from nvr.h, which we can't import into CPP code -#define TIME_SYNC_DISABLED 0 -#define TIME_SYNC_ENABLED 1 -#define TIME_SYNC_UTC 2 - #include "qt_deviceconfig.hpp" #include "qt_models_common.hpp" @@ -73,7 +69,7 @@ SettingsMachine::SettingsMachine(QWidget *parent) waitStatesModel->setData(idx, 0, Qt::UserRole); for (int i = 0; i < 8; ++i) { idx = waitStatesModel->index(i + 1, 0); - waitStatesModel->setData(idx, QString::asprintf(tr("%i Wait state(s)").toUtf8().constData(), i), Qt::DisplayRole); + waitStatesModel->setData(idx, tr("%1 Wait state(s)").arg(i), Qt::DisplayRole); waitStatesModel->setData(idx, i + 1, Qt::UserRole); } @@ -92,20 +88,31 @@ SettingsMachine::SettingsMachine(QWidget *parent) ui->comboBoxPitMode->setCurrentIndex(-1); ui->comboBoxPitMode->setCurrentIndex(pit_mode + 1); - int selectedMachineType = 0; - auto *machineTypesModel = ui->comboBoxMachineType->model(); - for (int i = 1; i < MACHINE_TYPE_MAX; ++i) { - int j = 0; - while (machine_get_internal_name_ex(j) != nullptr) { - if (machine_available(j) && (machine_get_type(j) == i)) { + int selectedMachineType = 0; + auto * machineTypesModel = ui->comboBoxMachineType->model(); + int i = -1; + int j = 0; + int cur_j = 0; + const void *miname; + do { + miname = machine_get_internal_name_ex(j); + + if ((miname == nullptr) || (machine_get_type(j) != i)) { + if ((i != -1) && (cur_j != 0)) { int row = Models::AddEntry(machineTypesModel, machine_types[i].name, machine_types[i].id); if (machine_types[i].id == machine_get_type(machine)) selectedMachineType = row; - break; } - j++; + + i = machine_get_type(j); + cur_j = 0; } - } + + if (machine_available(j)) + cur_j++; + + j++; + } while (miname != nullptr); ui->comboBoxMachineType->setCurrentIndex(-1); ui->comboBoxMachineType->setCurrentIndex(selectedMachineType); @@ -340,7 +347,7 @@ SettingsMachine::on_pushButtonConfigure_clicked() // deviceconfig_inst_open int machineId = ui->comboBoxMachine->currentData().toInt(); const auto *device = machine_get_device(machineId); - DeviceConfig::ConfigureDevice(device, 0, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(device); } void SettingsMachine::on_checkBoxFPUSoftfloat_stateChanged(int state) { @@ -351,4 +358,4 @@ void SettingsMachine::on_checkBoxFPUSoftfloat_stateChanged(int state) { ui->softFloatWarningIcon->setVisible(false); ui->softFloatWarningText->setVisible(false); } -} \ No newline at end of file +} diff --git a/src/qt/qt_settingsmachine.hpp b/src/qt/qt_settingsmachine.hpp index 7e89d7fa4..864894447 100644 --- a/src/qt/qt_settingsmachine.hpp +++ b/src/qt/qt_settingsmachine.hpp @@ -18,22 +18,13 @@ public: signals: void currentMachineChanged(int machineId); + private slots: void on_pushButtonConfigure_clicked(); - -private slots: void on_comboBoxFPU_currentIndexChanged(int index); - -private slots: void on_comboBoxSpeed_currentIndexChanged(int index); - -private slots: void on_comboBoxCPU_currentIndexChanged(int index); - -private slots: void on_comboBoxMachine_currentIndexChanged(int index); - -private slots: void on_comboBoxMachineType_currentIndexChanged(int index); void on_checkBoxFPUSoftfloat_stateChanged(int state); diff --git a/src/qt/qt_settingsmachine.ui b/src/qt/qt_settingsmachine.ui index 0c9c2708e..e3b3cdbde 100644 --- a/src/qt/qt_settingsmachine.ui +++ b/src/qt/qt_settingsmachine.ui @@ -41,6 +41,7 @@ 0 + @@ -48,6 +49,7 @@ + @@ -55,6 +57,7 @@ + @@ -62,6 +65,7 @@ + @@ -69,6 +73,7 @@ + @@ -79,6 +84,7 @@ + @@ -86,6 +92,7 @@ + @@ -93,6 +100,7 @@ + @@ -121,6 +129,7 @@ + @@ -131,6 +140,7 @@ + @@ -147,6 +157,7 @@ + @@ -154,6 +165,7 @@ + @@ -161,6 +173,7 @@ + @@ -183,6 +196,7 @@ + @@ -199,6 +213,7 @@ + @@ -253,6 +268,7 @@ + @@ -270,6 +286,7 @@ + @@ -285,6 +302,7 @@ + @@ -292,6 +310,7 @@ + @@ -314,6 +333,7 @@ + diff --git a/src/qt/qt_settingsnetwork.cpp b/src/qt/qt_settingsnetwork.cpp index 4411d4d4c..e5bb67db0 100644 --- a/src/qt/qt_settingsnetwork.cpp +++ b/src/qt/qt_settingsnetwork.cpp @@ -35,27 +35,70 @@ SettingsNetwork::enableElements(Ui::SettingsNetwork *ui) for (int i = 0; i < NET_CARD_MAX; ++i) { auto *nic_cbox = findChild(QString("comboBoxNIC%1").arg(i + 1)); auto *net_type_cbox = findChild(QString("comboBoxNet%1").arg(i + 1)); + + auto *intf_label = findChild(QString("labelIntf%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 *net_type_conf_btn = findChild(QString("pushButtonNetTypeConf%1").arg(i + 1)); + + auto *vde_socket_label = findChild(QString("labelSocketVDENIC%1").arg(i + 1)); auto *socket_line = findChild(QString("socketVDENIC%1").arg(i + 1)); + auto *bridge_line = findChild(QString("bridgeTAPNIC%1").arg(i + 1)); - int netType = net_type_cbox->currentData().toInt(); - bool adaptersEnabled = netType == NET_TYPE_NONE - || netType == NET_TYPE_SLIRP - || netType == NET_TYPE_VDE - || (netType == NET_TYPE_PCAP && intf_cbox->currentData().toInt() > 0) - || netType == NET_TYPE_TAP; + + auto *option_list_label = findChild(QString("labelOptionList%1").arg(i + 1)); + auto *option_list_line = findChild(QString("lineOptionList%1").arg(i + 1)); intf_cbox->setEnabled(net_type_cbox->currentData().toInt() == NET_TYPE_PCAP); - nic_cbox->setEnabled(adaptersEnabled); - int netCard = nic_cbox->currentData().toInt(); - if ((i == 0) && (netCard == NET_INTERNAL)) - conf_btn->setEnabled(adaptersEnabled && machine_has_flags(machineId, MACHINE_NIC) && - device_has_config(machine_get_net_device(machineId))); - else - conf_btn->setEnabled(adaptersEnabled && network_card_has_config(nic_cbox->currentData().toInt())); - socket_line->setEnabled(net_type_cbox->currentData().toInt() == NET_TYPE_VDE); + conf_btn->setEnabled(network_card_has_config(nic_cbox->currentData().toInt())); +// net_type_conf_btn->setEnabled(network_type_has_config(netType)); + + // Option list label and line + option_list_label->setVisible(false); + option_list_line->setVisible(false); + + // VDE + vde_socket_label->setVisible(false); + socket_line->setVisible(false); + + // TAP bridge_line->setEnabled(net_type_cbox->currentData().toInt() == NET_TYPE_TAP); + + // PCAP + intf_cbox->setVisible(false); + intf_label->setVisible(false); + + // Don't enable anything unless there's a nic selected + if(nic_cbox->currentData().toInt() != 0) { + // Then only enable as needed based on network type + switch (net_type_cbox->currentData().toInt()) { + case NET_TYPE_VDE: + // option_list_label->setText("VDE Options"); + option_list_label->setVisible(true); + option_list_line->setVisible(true); + + vde_socket_label->setVisible(true); + socket_line->setVisible(true); + break; + + case NET_TYPE_PCAP: + // option_list_label->setText("PCAP Options"); + option_list_label->setVisible(true); + option_list_line->setVisible(true); + + intf_cbox->setVisible(true); + intf_label->setVisible(true); + break; + + case NET_TYPE_TAP: + bridge_line->setVisible(true); + + case NET_TYPE_SLIRP: + default: + break; + } + } } } @@ -94,13 +137,12 @@ SettingsNetwork::save() 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)); - if (net_cards_conf[i].net_type == NET_TYPE_PCAP) { + 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) { + 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)); - } else if (net_cards_conf[i].net_type == NET_TYPE_TAP) { + else if (net_cards_conf[i].net_type == NET_TYPE_TAP) strncpy(net_cards_conf[i].host_dev_name, bridge_line->text().toUtf8().constData(), sizeof(net_cards_conf[i].host_dev_name)); - } } } @@ -109,57 +151,68 @@ SettingsNetwork::onCurrentMachineChanged(int machineId) { this->machineId = machineId; - int c = 0; - int selectedRow = 0; + int c = 0; + int selectedRow = 0; - for (int i = 0; i < NET_CARD_MAX; ++i) { - auto *cbox = findChild(QString("comboBoxNIC%1").arg(i + 1)); - auto *model = cbox->model(); - auto removeRows = model->rowCount(); - c = 0; - selectedRow = 0; + // Network Card + QComboBox *cbox_[NET_CARD_MAX] = { 0 }; + QAbstractItemModel *models[NET_CARD_MAX] = { 0 }; + int removeRows_[NET_CARD_MAX] = { 0 }; + int selectedRows[NET_CARD_MAX] = { 0 }; + int m_has_net = machine_has_flags(machineId, MACHINE_NIC); - while (true) { - /* Skip "internal" if machine doesn't have it or this is not the primary card. */ - if ((c == 1) && ((i > 0) || (machine_has_flags(machineId, MACHINE_NIC) == 0))) { - c++; - continue; - } + for (uint8_t i = 0; i < NET_CARD_MAX; ++i) { + cbox_[i] = findChild(QString("comboBoxNIC%1").arg(i + 1)); + models[i] = cbox_[i]->model(); + removeRows_[i] = models[i]->rowCount(); + } - auto name = DeviceConfig::DeviceName(network_card_getdevice(c), network_card_get_internal_name(c), 1); - if (name.isEmpty()) { - break; - } + c = 0; + while (true) { + const QString name = DeviceConfig::DeviceName(network_card_getdevice(c), + network_card_get_internal_name(c), 1); - if (network_card_available(c) && device_is_valid(network_card_getdevice(c), machineId)) { - int row = Models::AddEntry(model, name, c); - if (c == net_cards_conf[i].device_num) { - selectedRow = row - removeRows; + if (name.isEmpty()) + break; + + if (network_card_available(c)) { + if (device_is_valid(network_card_getdevice(c), machineId)) { + for (uint8_t i = 0; i < NET_CARD_MAX; ++i) { + if ((c != 1) || ((i == 0) && m_has_net)) { + int row = Models::AddEntry(models[i], name, c); + + if (c == net_cards_conf[i].device_num) + selectedRows[i] = row - removeRows_[i]; + } } } - c++; } - model->removeRows(0, removeRows); - cbox->setEnabled(model->rowCount() > 0); - cbox->setCurrentIndex(-1); - cbox->setCurrentIndex(selectedRow); + c++; + } - cbox = findChild(QString("comboBoxNet%1").arg(i + 1)); - model = cbox->model(); - removeRows = model->rowCount(); + for (uint8_t i = 0; i < NET_CARD_MAX; ++i) { + models[i]->removeRows(0, removeRows_[i]); + cbox_[i]->setEnabled(models[i]->rowCount() > 1); + cbox_[i]->setCurrentIndex(-1); + cbox_[i]->setCurrentIndex(selectedRows[i]); + + auto cbox = findChild(QString("comboBoxNet%1").arg(i + 1)); + auto model = cbox->model(); + auto removeRows = model->rowCount(); Models::AddEntry(model, tr("Null Driver"), NET_TYPE_NONE); Models::AddEntry(model, "SLiRP", NET_TYPE_SLIRP); - if (network_ndev > 1) { + if (network_ndev > 1) Models::AddEntry(model, "PCap", NET_TYPE_PCAP); - } - if (network_devmap.has_vde) { + + if (network_devmap.has_vde) Models::AddEntry(model, "VDE", NET_TYPE_VDE); - } + Models::AddEntry(model, "TAP", NET_TYPE_TAP); + model->removeRows(0, removeRows); - cbox->setCurrentIndex(net_cards_conf[i].net_type); + cbox->setCurrentIndex(cbox->findData(net_cards_conf[i].net_type)); selectedRow = 0; @@ -177,6 +230,7 @@ SettingsNetwork::onCurrentMachineChanged(int machineId) 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)); @@ -193,9 +247,8 @@ SettingsNetwork::onCurrentMachineChanged(int machineId) void SettingsNetwork::on_comboIndexChanged(int index) { - if (index < 0) { + if (index < 0) return; - } enableElements(ui); } @@ -203,33 +256,33 @@ SettingsNetwork::on_comboIndexChanged(int index) void SettingsNetwork::on_pushButtonConf1_clicked() { - int netCard = ui->comboBoxNIC1->currentData().toInt(); - auto *device = network_card_getdevice(netCard); + int netCard = ui->comboBoxNIC1->currentData().toInt(); + auto *device = network_card_getdevice(netCard); if (netCard == NET_INTERNAL) device = machine_get_net_device(machineId); - DeviceConfig::ConfigureDevice(device, 1, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(device, 1); } void SettingsNetwork::on_pushButtonConf2_clicked() { - int netCard = ui->comboBoxNIC2->currentData().toInt(); - auto *device = network_card_getdevice(netCard); - DeviceConfig::ConfigureDevice(device, 2, qobject_cast(Settings::settings)); + int netCard = ui->comboBoxNIC2->currentData().toInt(); + auto *device = network_card_getdevice(netCard); + DeviceConfig::ConfigureDevice(device, 2); } void SettingsNetwork::on_pushButtonConf3_clicked() { - int netCard = ui->comboBoxNIC3->currentData().toInt(); - auto *device = network_card_getdevice(netCard); - DeviceConfig::ConfigureDevice(device, 3, qobject_cast(Settings::settings)); + int netCard = ui->comboBoxNIC3->currentData().toInt(); + auto *device = network_card_getdevice(netCard); + DeviceConfig::ConfigureDevice(device, 3); } void SettingsNetwork::on_pushButtonConf4_clicked() { - int netCard = ui->comboBoxNIC4->currentData().toInt(); - auto *device = network_card_getdevice(netCard); - DeviceConfig::ConfigureDevice(device, 4, qobject_cast(Settings::settings)); + int netCard = ui->comboBoxNIC4->currentData().toInt(); + auto *device = network_card_getdevice(netCard); + DeviceConfig::ConfigureDevice(device, 4); } diff --git a/src/qt/qt_settingsnetwork.ui b/src/qt/qt_settingsnetwork.ui index efb25a16a..7aff676d6 100644 --- a/src/qt/qt_settingsnetwork.ui +++ b/src/qt/qt_settingsnetwork.ui @@ -27,17 +27,17 @@ 0 - + 0 - + Network Card #1 - + - + 0 @@ -45,11 +45,11 @@ - Mode + Mode: - + 30 @@ -63,7 +63,7 @@ - + 0 @@ -71,41 +71,12 @@ - Interface + Adapter: - - - - 30 - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - Adapter - - - - + - - 30 - 0 @@ -115,9 +86,12 @@ QComboBox::AdjustToContents + + 30 + - + @@ -130,36 +104,73 @@ - - + + - VDE Socket + Options - + + + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + Interface: + + + + + + + + 0 + 0 + + + + + + + + VDE Socket: + + + + 127 - + TAP Bridge Device - + 127 - - + + Qt::Vertical @@ -173,13 +184,13 @@ - + Network Card #2 - + - + 0 @@ -187,11 +198,11 @@ - Mode + Mode: - + 30 @@ -205,7 +216,7 @@ - + 0 @@ -213,41 +224,12 @@ - Interface + Adapter: - - - - 30 - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - Adapter - - - - + - - 30 - 0 @@ -257,45 +239,91 @@ QComboBox::AdjustToContents + + 30 + - + + + + 0 + 0 + + Configure - - + + - VDE Socket + Options - - - - 127 + + + + Qt::Horizontal - + + + + + 0 + 0 + + + + Interface: + + + + + + + + 0 + 0 + + + + + + + + VDE Socket: + + + + 127 - + TAP Bridge Device - - + + + + 127 + + + + + Qt::Vertical @@ -309,13 +337,13 @@ - + Network Card #3 - + - + 0 @@ -323,11 +351,11 @@ - Mode + Mode: - + 30 @@ -341,7 +369,7 @@ - + 0 @@ -349,41 +377,12 @@ - Interface + Adapter: - - - - 30 - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - Adapter - - - - + - - 30 - 0 @@ -393,9 +392,12 @@ QComboBox::AdjustToContents + + 30 + - + @@ -408,36 +410,73 @@ - - + + - VDE Socket + Options - + + + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + Interface: + + + + + + + + 0 + 0 + + + + + + + + VDE Socket: + + + + 127 - + TAP Bridge Device - + 127 - - + + Qt::Vertical @@ -451,13 +490,13 @@ - + Network Card #4 - + - + 0 @@ -465,11 +504,11 @@ - Mode + Mode: - + 30 @@ -483,7 +522,7 @@ - + 0 @@ -491,41 +530,12 @@ - Interface + Adapter: - - - - 30 - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - Adapter - - - - + - - 30 - 0 @@ -535,9 +545,12 @@ QComboBox::AdjustToContents + + 30 + - + @@ -550,36 +563,73 @@ - - + + - VDE Socket + Options - + + + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + Interface: + + + + + + + + 0 + 0 + + + + + + + + VDE Socket: + + + + 127 - + TAP Bridge Device - + 127 - - + + Qt::Vertical diff --git a/src/qt/qt_settingsotherperipherals.cpp b/src/qt/qt_settingsotherperipherals.cpp index a7db551ad..0ecdc30d3 100644 --- a/src/qt/qt_settingsotherperipherals.cpp +++ b/src/qt/qt_settingsotherperipherals.cpp @@ -11,8 +11,10 @@ * * * Authors: Joakim L. Gilje + * Jasmine Iwanek * * Copyright 2021 Joakim L. Gilje + * Copyright 2025 Jasmine Iwanek */ #include "qt_settingsotherperipherals.hpp" #include "ui_qt_settingsotherperipherals.h" @@ -22,6 +24,7 @@ extern "C" { #include <86box/device.h> #include <86box/machine.h> #include <86box/isamem.h> +#include <86box/isarom.h> #include <86box/isartc.h> #include <86box/unittester.h> #include <86box/novell_cardkey.h> @@ -44,70 +47,131 @@ SettingsOtherPeripherals::onCurrentMachineChanged(int machineId) this->machineId = machineId; bool machineHasIsa = (machine_has_bus(machineId, MACHINE_BUS_ISA) > 0); + + ui->pushButtonConfigureRTC->setEnabled(machineHasIsa); + ui->comboBoxRTC->setEnabled(machineHasIsa); + ui->checkBoxISABugger->setEnabled(machineHasIsa); + ui->pushButtonConfigureUT->setEnabled(unittester_enabled > 0); + ui->checkBoxKeyCard->setEnabled(machineHasIsa); + ui->pushButtonConfigureKeyCard->setEnabled(novell_keycard_enabled > 0); + ui->checkBoxISABugger->setChecked((machineHasIsa && (bugger_enabled > 0)) ? true : false); ui->checkBoxPOSTCard->setChecked(postcard_enabled > 0 ? true : false); ui->checkBoxUnitTester->setChecked(unittester_enabled > 0 ? true : false); ui->checkBoxKeyCard->setChecked((machineHasIsa && (novell_keycard_enabled > 0)) ? true : false); - ui->checkBoxISABugger->setEnabled(machineHasIsa); - ui->checkBoxKeyCard->setEnabled(machineHasIsa); - ui->pushButtonConfigureKeyCard->setEnabled(novell_keycard_enabled > 0); - ui->pushButtonConfigureUT->setEnabled(unittester_enabled > 0); - ui->comboBoxRTC->setEnabled(machineHasIsa); - ui->pushButtonConfigureRTC->setEnabled(machineHasIsa); - ui->comboBoxCard1->clear(); - ui->comboBoxCard2->clear(); - ui->comboBoxCard3->clear(); - ui->comboBoxCard4->clear(); ui->comboBoxRTC->clear(); - auto *model = ui->comboBoxRTC->model(); - int d = 0; + for (uint8_t i = 0; i < ISAMEM_MAX; ++i) + if (auto *cb = findChild(QString("comboBoxIsaMemCard%1").arg(i + 1))) + cb->clear(); + + for (uint8_t i = 0; i < ISAROM_MAX; ++i) + if (auto *cb = findChild(QString("comboBoxIsaRomCard%1").arg(i + 1))) + cb->clear(); + + int c = 0; int selectedRow = 0; + + // ISA RTC Cards + auto *model = ui->comboBoxRTC->model(); while (true) { - QString name = DeviceConfig::DeviceName(isartc_get_device(d), isartc_get_internal_name(d), 0); - if (name.isEmpty()) { + const QString name = DeviceConfig::DeviceName(isartc_get_device(c), isartc_get_internal_name(c), 0); + if (name.isEmpty()) break; - } - if (!device_is_valid(isartc_get_device(d), machineId)) { + if (!device_is_valid(isartc_get_device(c), machineId)) break; - } - int row = Models::AddEntry(model, name, d); - if (d == isartc_type) { + int row = Models::AddEntry(model, name, c); + if (c == isartc_type) selectedRow = row; - } - ++d; + + ++c; } ui->comboBoxRTC->setCurrentIndex(selectedRow); ui->pushButtonConfigureRTC->setEnabled((isartc_type != 0) && isartc_has_config(isartc_type) && machineHasIsa); - for (int c = 0; c < ISAMEM_MAX; c++) { - auto *cbox = findChild(QString("comboBoxCard%1").arg(c + 1)); - model = cbox->model(); - d = 0; - selectedRow = 0; - while (true) { - QString name = DeviceConfig::DeviceName(isamem_get_device(d), isamem_get_internal_name(d), 0); - if (name.isEmpty()) { - break; - } + // ISA Memory Expansion Cards + QComboBox *isamem_cbox[ISAMEM_MAX] = { 0 }; + QAbstractItemModel *isamem_models[ISAMEM_MAX] = { 0 }; + int isamem_removeRows_[ISAMEM_MAX] = { 0 }; + int isamem_selectedRows[ISAMEM_MAX] = { 0 }; - if (!device_is_valid(isamem_get_device(d), machineId)) { - break; - } + for (uint8_t i = 0; i < ISAMEM_MAX; ++i) { + isamem_cbox[i] = findChild(QString("comboBoxIsaMemCard%1").arg(i + 1)); + isamem_models[i] = isamem_cbox[i]->model(); + isamem_removeRows_[i] = isamem_models[i]->rowCount(); + } - int row = Models::AddEntry(model, name, d); - if (d == isamem_type[c]) { - selectedRow = row; + c = 0; + while (true) { + const QString name = DeviceConfig::DeviceName(isamem_get_device(c), + isamem_get_internal_name(c), 0); + + if (name.isEmpty()) + break; + + if (device_is_valid(isamem_get_device(c), machineId)) { + for (uint8_t i = 0; i < ISAMEM_MAX; ++i) { + int row = Models::AddEntry(isamem_models[i], name, c); + + if (c == isamem_type[i]) + isamem_selectedRows[i] = row - isamem_removeRows_[i]; } - ++d; } - cbox->setCurrentIndex(-1); - cbox->setCurrentIndex(selectedRow); - cbox->setEnabled(machineHasIsa); - findChild(QString("pushButtonConfigureCard%1").arg(c + 1))->setEnabled((isamem_type[c] != 0) && isamem_has_config(isamem_type[c]) && machineHasIsa); + + c++; + } + + for (uint8_t i = 0; i < ISAMEM_MAX; ++i) { + isamem_models[i]->removeRows(0, isamem_removeRows_[i]); + isamem_cbox[i]->setEnabled(isamem_models[i]->rowCount() > 1); + isamem_cbox[i]->setCurrentIndex(-1); + isamem_cbox[i]->setCurrentIndex(isamem_selectedRows[i]); + findChild(QString("pushButtonConfigureIsaMemCard%1").arg(i + 1))->setEnabled((isamem_type[i] != 0) && + isamem_has_config(isamem_type[i]) && machineHasIsa); + } + + // ISA ROM Expansion Cards + QComboBox *isarom_cbox[ISAROM_MAX] = { 0 }; + QAbstractItemModel *isarom_models[ISAROM_MAX] = { 0 }; + int isarom_removeRows_[ISAROM_MAX] = { 0 }; + int isarom_selectedRows[ISAROM_MAX] = { 0 }; + + for (uint8_t i = 0; i < ISAROM_MAX; ++i) { + isarom_cbox[i] = findChild(QString("comboBoxIsaRomCard%1").arg(i + 1)); + isarom_models[i] = isarom_cbox[i]->model(); + isarom_removeRows_[i] = isarom_models[i]->rowCount(); + } + + c = 0; + while (true) { + const QString name = DeviceConfig::DeviceName(isarom_get_device(c), + isarom_get_internal_name(c), 0); + + if (name.isEmpty()) + break; + + if (device_is_valid(isarom_get_device(c), machineId)) { + for (uint8_t i = 0; i < ISAROM_MAX; ++i) { + int row = Models::AddEntry(isarom_models[i], name, c); + + if (c == isarom_type[i]) + isarom_selectedRows[i] = row - isarom_removeRows_[i]; + } + } + + c++; + } + + for (uint8_t i = 0; i < ISAROM_MAX; ++i) { + isarom_models[i]->removeRows(0, isarom_removeRows_[i]); + isarom_cbox[i]->setEnabled(isarom_models[i]->rowCount() > 1); + isarom_cbox[i]->setCurrentIndex(-1); + isarom_cbox[i]->setCurrentIndex(isarom_selectedRows[i]); + findChild(QString("pushButtonConfigureIsaRomCard%1").arg(i + 1))->setEnabled((isarom_type[i] != 0) && + isarom_has_config(isarom_type[i]) && machineHasIsa); } } @@ -120,92 +184,158 @@ void SettingsOtherPeripherals::save() { /* Other peripherals category */ + isartc_type = ui->comboBoxRTC->currentData().toInt(); bugger_enabled = ui->checkBoxISABugger->isChecked() ? 1 : 0; postcard_enabled = ui->checkBoxPOSTCard->isChecked() ? 1 : 0; unittester_enabled = ui->checkBoxUnitTester->isChecked() ? 1 : 0; novell_keycard_enabled = ui->checkBoxKeyCard->isChecked() ? 1 : 0; - isartc_type = ui->comboBoxRTC->currentData().toInt(); /* ISA memory boards. */ for (int i = 0; i < ISAMEM_MAX; i++) { - auto *cbox = findChild(QString("comboBoxCard%1").arg(i + 1)); + auto *cbox = findChild(QString("comboBoxIsaMemCard%1").arg(i + 1)); isamem_type[i] = cbox->currentData().toInt(); } + + /* ISA ROM boards. */ + for (int i = 0; i < ISAROM_MAX; i++) { + auto *cbox = findChild(QString("comboBoxIsaRomCard%1").arg(i + 1)); + isarom_type[i] = cbox->currentData().toInt(); + } } void SettingsOtherPeripherals::on_comboBoxRTC_currentIndexChanged(int index) { - if (index < 0) { + if (index < 0) return; - } + ui->pushButtonConfigureRTC->setEnabled((index != 0) && isartc_has_config(index) && machine_has_bus(machineId, MACHINE_BUS_ISA)); } void SettingsOtherPeripherals::on_pushButtonConfigureRTC_clicked() { - DeviceConfig::ConfigureDevice(isartc_get_device(ui->comboBoxRTC->currentData().toInt()), 0, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(isartc_get_device(ui->comboBoxRTC->currentData().toInt())); } void -SettingsOtherPeripherals::on_comboBoxCard1_currentIndexChanged(int index) +SettingsOtherPeripherals::on_comboBoxIsaMemCard1_currentIndexChanged(int index) { - if (index < 0) { + if (index < 0) return; - } - ui->pushButtonConfigureCard1->setEnabled((index != 0) && isamem_has_config(index) && machine_has_bus(machineId, MACHINE_BUS_ISA)); + + ui->pushButtonConfigureIsaMemCard1->setEnabled((index != 0) && isamem_has_config(index) && machine_has_bus(machineId, MACHINE_BUS_ISA)); } void -SettingsOtherPeripherals::on_pushButtonConfigureCard1_clicked() +SettingsOtherPeripherals::on_pushButtonConfigureIsaMemCard1_clicked() { - DeviceConfig::ConfigureDevice(isamem_get_device(ui->comboBoxCard1->currentData().toInt()), 1, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(isamem_get_device(ui->comboBoxIsaMemCard1->currentData().toInt()), 1); } void -SettingsOtherPeripherals::on_comboBoxCard2_currentIndexChanged(int index) +SettingsOtherPeripherals::on_comboBoxIsaMemCard2_currentIndexChanged(int index) { - if (index < 0) { + if (index < 0) return; - } - ui->pushButtonConfigureCard2->setEnabled((index != 0) && isamem_has_config(index) && machine_has_bus(machineId, MACHINE_BUS_ISA)); + + ui->pushButtonConfigureIsaMemCard2->setEnabled((index != 0) && isamem_has_config(index) && machine_has_bus(machineId, MACHINE_BUS_ISA)); } void -SettingsOtherPeripherals::on_pushButtonConfigureCard2_clicked() +SettingsOtherPeripherals::on_pushButtonConfigureIsaMemCard2_clicked() { - DeviceConfig::ConfigureDevice(isamem_get_device(ui->comboBoxCard2->currentData().toInt()), 2, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(isamem_get_device(ui->comboBoxIsaMemCard2->currentData().toInt()), 2); } void -SettingsOtherPeripherals::on_comboBoxCard3_currentIndexChanged(int index) +SettingsOtherPeripherals::on_comboBoxIsaMemCard3_currentIndexChanged(int index) { - if (index < 0) { + if (index < 0) return; - } - ui->pushButtonConfigureCard3->setEnabled((index != 0) && isamem_has_config(index) && machine_has_bus(machineId, MACHINE_BUS_ISA)); + + ui->pushButtonConfigureIsaMemCard3->setEnabled((index != 0) && isamem_has_config(index) && machine_has_bus(machineId, MACHINE_BUS_ISA)); } void -SettingsOtherPeripherals::on_pushButtonConfigureCard3_clicked() +SettingsOtherPeripherals::on_pushButtonConfigureIsaMemCard3_clicked() { - DeviceConfig::ConfigureDevice(isamem_get_device(ui->comboBoxCard3->currentData().toInt()), 3, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(isamem_get_device(ui->comboBoxIsaMemCard3->currentData().toInt()), 3); } void -SettingsOtherPeripherals::on_comboBoxCard4_currentIndexChanged(int index) +SettingsOtherPeripherals::on_comboBoxIsaMemCard4_currentIndexChanged(int index) { - if (index < 0) { + if (index < 0) return; - } - ui->pushButtonConfigureCard4->setEnabled((index != 0) && isamem_has_config(index) && machine_has_bus(machineId, MACHINE_BUS_ISA)); + + ui->pushButtonConfigureIsaMemCard4->setEnabled((index != 0) && isamem_has_config(index) && machine_has_bus(machineId, MACHINE_BUS_ISA)); } void -SettingsOtherPeripherals::on_pushButtonConfigureCard4_clicked() +SettingsOtherPeripherals::on_pushButtonConfigureIsaMemCard4_clicked() { - DeviceConfig::ConfigureDevice(isamem_get_device(ui->comboBoxCard4->currentData().toInt()), 4, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(isamem_get_device(ui->comboBoxIsaMemCard4->currentData().toInt()), 4); +} + +void +SettingsOtherPeripherals::on_comboBoxIsaRomCard1_currentIndexChanged(int index) +{ + if (index < 0) + return; + + ui->pushButtonConfigureIsaRomCard1->setEnabled((index != 0) && isarom_has_config(index) && machine_has_bus(machineId, MACHINE_BUS_ISA)); +} + +void +SettingsOtherPeripherals::on_pushButtonConfigureIsaRomCard1_clicked() +{ + DeviceConfig::ConfigureDevice(isarom_get_device(ui->comboBoxIsaRomCard1->currentData().toInt()), 1); +} + +void +SettingsOtherPeripherals::on_comboBoxIsaRomCard2_currentIndexChanged(int index) +{ + if (index < 0) + return; + + ui->pushButtonConfigureIsaRomCard2->setEnabled((index != 0) && isarom_has_config(index) && machine_has_bus(machineId, MACHINE_BUS_ISA)); +} + +void +SettingsOtherPeripherals::on_pushButtonConfigureIsaRomCard2_clicked() +{ + DeviceConfig::ConfigureDevice(isarom_get_device(ui->comboBoxIsaRomCard2->currentData().toInt()), 2); +} + +void +SettingsOtherPeripherals::on_comboBoxIsaRomCard3_currentIndexChanged(int index) +{ + if (index < 0) + return; + + ui->pushButtonConfigureIsaRomCard3->setEnabled((index != 0) && isarom_has_config(index) && machine_has_bus(machineId, MACHINE_BUS_ISA)); +} + +void +SettingsOtherPeripherals::on_pushButtonConfigureIsaRomCard3_clicked() +{ + DeviceConfig::ConfigureDevice(isarom_get_device(ui->comboBoxIsaRomCard3->currentData().toInt()), 3); +} + +void +SettingsOtherPeripherals::on_comboBoxIsaRomCard4_currentIndexChanged(int index) +{ + if (index < 0) + return; + + ui->pushButtonConfigureIsaRomCard4->setEnabled((index != 0) && isarom_has_config(index) && machine_has_bus(machineId, MACHINE_BUS_ISA)); +} + +void +SettingsOtherPeripherals::on_pushButtonConfigureIsaRomCard4_clicked() +{ + DeviceConfig::ConfigureDevice(isarom_get_device(ui->comboBoxIsaRomCard4->currentData().toInt()), 4); } void @@ -220,13 +350,12 @@ SettingsOtherPeripherals::on_pushButtonConfigureUT_clicked() DeviceConfig::ConfigureDevice(&unittester_device); } -void SettingsOtherPeripherals::on_pushButtonConfigureKeyCard_clicked() -{ - DeviceConfig::ConfigureDevice(&novell_keycard_device); -} - void SettingsOtherPeripherals::on_checkBoxKeyCard_stateChanged(int arg1) { ui->pushButtonConfigureKeyCard->setEnabled(arg1 != 0); } +void SettingsOtherPeripherals::on_pushButtonConfigureKeyCard_clicked() +{ + DeviceConfig::ConfigureDevice(&novell_keycard_device); +} diff --git a/src/qt/qt_settingsotherperipherals.hpp b/src/qt/qt_settingsotherperipherals.hpp index d5804a68b..991759259 100644 --- a/src/qt/qt_settingsotherperipherals.hpp +++ b/src/qt/qt_settingsotherperipherals.hpp @@ -20,22 +20,32 @@ public slots: void onCurrentMachineChanged(int machineId); private slots: - void on_pushButtonConfigureCard4_clicked(); - void on_comboBoxCard4_currentIndexChanged(int index); - void on_pushButtonConfigureCard3_clicked(); - void on_comboBoxCard3_currentIndexChanged(int index); - void on_pushButtonConfigureCard2_clicked(); - void on_comboBoxCard2_currentIndexChanged(int index); - void on_pushButtonConfigureCard1_clicked(); - void on_comboBoxCard1_currentIndexChanged(int index); - void on_pushButtonConfigureRTC_clicked(); void on_comboBoxRTC_currentIndexChanged(int index); + void on_pushButtonConfigureRTC_clicked(); + + void on_comboBoxIsaMemCard1_currentIndexChanged(int index); + void on_pushButtonConfigureIsaMemCard1_clicked(); + void on_comboBoxIsaMemCard2_currentIndexChanged(int index); + void on_pushButtonConfigureIsaMemCard2_clicked(); + void on_comboBoxIsaMemCard3_currentIndexChanged(int index); + void on_pushButtonConfigureIsaMemCard3_clicked(); + void on_comboBoxIsaMemCard4_currentIndexChanged(int index); + void on_pushButtonConfigureIsaMemCard4_clicked(); + + void on_comboBoxIsaRomCard1_currentIndexChanged(int index); + void on_pushButtonConfigureIsaRomCard1_clicked(); + void on_comboBoxIsaRomCard2_currentIndexChanged(int index); + void on_pushButtonConfigureIsaRomCard2_clicked(); + void on_comboBoxIsaRomCard3_currentIndexChanged(int index); + void on_pushButtonConfigureIsaRomCard3_clicked(); + void on_comboBoxIsaRomCard4_currentIndexChanged(int index); + void on_pushButtonConfigureIsaRomCard4_clicked(); + void on_checkBoxUnitTester_stateChanged(int arg1); void on_pushButtonConfigureUT_clicked(); - void on_pushButtonConfigureKeyCard_clicked(); - void on_checkBoxKeyCard_stateChanged(int arg1); + void on_pushButtonConfigureKeyCard_clicked(); private: Ui::SettingsOtherPeripherals *ui; diff --git a/src/qt/qt_settingsotherperipherals.ui b/src/qt/qt_settingsotherperipherals.ui index 41df2deac..5c6b8fbf0 100644 --- a/src/qt/qt_settingsotherperipherals.ui +++ b/src/qt/qt_settingsotherperipherals.ui @@ -27,9 +27,9 @@ 0 - + - + ISA RTC: @@ -58,20 +58,74 @@ - + ISA Memory Expansion - - - + + + + + Card 1: + + + + + + + + 0 + 0 + + + + 30 + + + + + Configure + + + + Card 2: + + + - + + + + 0 + 0 + + + + 30 + + + + + + + Configure + + + + + + + Card 3: + + + + + 0 @@ -84,68 +138,21 @@ - + Configure - - + + - Card 2: - - - - - - - Card 3: - - - - - - - Configure - - - - - - - - 0 - 0 - - - - 30 - - - - - - - Card 1: - - - - - - - - 0 - 0 - - - - 30 + Card 4: - + 0 @@ -158,24 +165,134 @@ - + Configure - - - - Card 4: - - - - + + + ISA ROM Cards + + + + + + Card 1: + + + + + + + + 0 + 0 + + + + 30 + + + + + + + Configure + + + + + + + Card 2: + + + + + + + + 0 + 0 + + + + 30 + + + + + + + Configure + + + + + + + Card 3: + + + + + + + + 0 + 0 + + + + 30 + + + + + + + Configure + + + + + + + Card 4: + + + + + + + + 0 + 0 + + + + 30 + + + + + + + Configure + + + + + + + + @@ -193,7 +310,7 @@ - + @@ -217,7 +334,7 @@ - + 0 diff --git a/src/qt/qt_settingsotherremovable.cpp b/src/qt/qt_settingsotherremovable.cpp index 1a6dceacb..8a810a4fb 100644 --- a/src/qt/qt_settingsotherremovable.cpp +++ b/src/qt/qt_settingsotherremovable.cpp @@ -46,11 +46,11 @@ setMOBus(QAbstractItemModel *model, const QModelIndex &idx, uint8_t bus, uint8_t QIcon icon; switch (bus) { case MO_BUS_DISABLED: - icon = ProgSettings::loadIcon("/mo_disabled.ico"); + icon = QIcon(":/settings/qt/icons/mo_disabled.ico"); break; case MO_BUS_ATAPI: case MO_BUS_SCSI: - icon = ProgSettings::loadIcon("/mo.ico"); + icon = QIcon(":/settings/qt/icons/mo.ico"); break; default: @@ -81,11 +81,11 @@ setZIPBus(QAbstractItemModel *model, const QModelIndex &idx, uint8_t bus, uint8_ QIcon icon; switch (bus) { case ZIP_BUS_DISABLED: - icon = ProgSettings::loadIcon("/zip_disabled.ico"); + icon = QIcon(":/settings/qt/icons/zip_disabled.ico"); break; case ZIP_BUS_ATAPI: case ZIP_BUS_SCSI: - icon = ProgSettings::loadIcon("/zip.ico"); + icon = QIcon(":/settings/qt/icons/zip.ico"); break; default: diff --git a/src/qt/qt_settingsotherremovable.hpp b/src/qt/qt_settingsotherremovable.hpp index cea1d202b..1459ed043 100644 --- a/src/qt/qt_settingsotherremovable.hpp +++ b/src/qt/qt_settingsotherremovable.hpp @@ -21,33 +21,19 @@ public: signals: void moChannelChanged(); void zipChannelChanged(); -private slots: - void on_checkBoxZIP250_stateChanged(int arg1); - -private slots: - void on_comboBoxZIPChannel_activated(int index); - -private slots: - void on_comboBoxZIPBus_activated(int index); - -private slots: - void on_comboBoxZIPBus_currentIndexChanged(int index); - -private slots: - void on_comboBoxMOType_activated(int index); - -private slots: - void on_comboBoxMOChannel_activated(int index); - -private slots: - void on_comboBoxMOBus_activated(int index); - -private slots: - void on_comboBoxMOBus_currentIndexChanged(int index); private slots: void onMORowChanged(const QModelIndex ¤t); + void on_comboBoxMOBus_currentIndexChanged(int index); + void on_comboBoxMOBus_activated(int index); + void on_comboBoxMOChannel_activated(int index); + void on_comboBoxMOType_activated(int index); + void onZIPRowChanged(const QModelIndex ¤t); + void on_comboBoxZIPBus_currentIndexChanged(int index); + void on_comboBoxZIPBus_activated(int index); + void on_comboBoxZIPChannel_activated(int index); + void on_checkBoxZIP250_stateChanged(int arg1); private: Ui::SettingsOtherRemovable *ui; diff --git a/src/qt/qt_settingsotherremovable.ui b/src/qt/qt_settingsotherremovable.ui index 8962184fc..ae7839e54 100644 --- a/src/qt/qt_settingsotherremovable.ui +++ b/src/qt/qt_settingsotherremovable.ui @@ -27,7 +27,7 @@ 0 - + MO drives: @@ -68,19 +68,12 @@ - + Bus: - - - - Channel: - - - @@ -88,6 +81,13 @@ + + + + Channel: + + + @@ -96,7 +96,7 @@ - + Type: @@ -113,7 +113,7 @@ - + ZIP drives: @@ -154,7 +154,7 @@ - + Bus: @@ -168,7 +168,7 @@ - + Channel: diff --git a/src/qt/qt_settingsports.cpp b/src/qt/qt_settingsports.cpp index 9679c9e21..ddebd28e8 100644 --- a/src/qt/qt_settingsports.cpp +++ b/src/qt/qt_settingsports.cpp @@ -38,51 +38,7 @@ SettingsPorts::SettingsPorts(QWidget *parent) , ui(new Ui::SettingsPorts) { ui->setupUi(this); - - for (int i = 0; i < PARALLEL_MAX; i++) { - auto *cbox = findChild(QString("comboBoxLpt%1").arg(i + 1)); - auto *model = cbox->model(); - int c = 0; - int selectedRow = 0; - while (true) { - const char *lptName = lpt_device_get_name(c); - if (lptName == nullptr) { - break; - } - - Models::AddEntry(model, tr(lptName), c); - if (c == lpt_ports[i].device) { - selectedRow = c; - } - c++; - } - cbox->setCurrentIndex(selectedRow); - - auto *checkBox = findChild(QString("checkBoxParallel%1").arg(i + 1)); - if (checkBox != NULL) - checkBox->setChecked(lpt_ports[i].enabled > 0); - if (cbox != NULL) - cbox->setEnabled(lpt_ports[i].enabled > 0); - } - - for (int i = 0; i < SERIAL_MAX; i++) { - auto *checkBox = findChild(QString("checkBoxSerial%1").arg(i + 1)); - auto *checkBoxPass = findChild(QString("checkBoxSerialPassThru%1").arg(i + 1)); - if (checkBox != NULL) - checkBox->setChecked(com_ports[i].enabled > 0); - if (checkBoxPass != NULL) - checkBoxPass->setChecked(serial_passthrough_enabled[i]); - } - - ui->pushButtonSerialPassThru1->setEnabled(serial_passthrough_enabled[0]); - ui->pushButtonSerialPassThru2->setEnabled(serial_passthrough_enabled[1]); - ui->pushButtonSerialPassThru3->setEnabled(serial_passthrough_enabled[2]); - ui->pushButtonSerialPassThru4->setEnabled(serial_passthrough_enabled[3]); -#if 0 - ui->pushButtonSerialPassThru5->setEnabled(serial_passthrough_enabled[4]); - ui->pushButtonSerialPassThru6->setEnabled(serial_passthrough_enabled[5]); - ui->pushButtonSerialPassThru7->setEnabled(serial_passthrough_enabled[6]); -#endif + onCurrentMachineChanged(machine); } SettingsPorts::~SettingsPorts() @@ -95,14 +51,14 @@ SettingsPorts::save() { for (int i = 0; i < PARALLEL_MAX; i++) { auto *cbox = findChild(QString("comboBoxLpt%1").arg(i + 1)); - auto *checkBox = findChild(QString("checkBoxParallel%1").arg(i + 1)); + auto *checkBox = findChild(QString("checkBoxParallel%1").arg(i + 1)); if (cbox != NULL) lpt_ports[i].device = cbox->currentData().toInt(); if (checkBox != NULL) lpt_ports[i].enabled = checkBox->isChecked() ? 1 : 0; } - for (int i = 0; i < SERIAL_MAX; i++) { + for (int i = 0; i < (SERIAL_MAX - 1); i++) { auto *checkBox = findChild(QString("checkBoxSerial%1").arg(i + 1)); auto *checkBoxPass = findChild(QString("checkBoxSerialPassThru%1").arg(i + 1)); if (checkBox != NULL) @@ -112,6 +68,70 @@ SettingsPorts::save() } } +void +SettingsPorts::onCurrentMachineChanged(int machineId) +{ + this->machineId = machineId; + + int c = 0; + + // LPT Device + QComboBox * cbox[PARALLEL_MAX] = { 0 }; + QAbstractItemModel *models[PARALLEL_MAX] = { 0 }; + int removeRows_[PARALLEL_MAX] = { 0 }; + int selectedRows[PARALLEL_MAX] = { 0 }; + + for (uint8_t i = 0; i < PARALLEL_MAX; ++i) { + cbox[i] = findChild(QString("comboBoxLpt%1").arg(i + 1)); + models[i] = cbox[i]->model(); + removeRows_[i] = models[i]->rowCount(); + } + + while (true) { + const char *lptName = lpt_device_get_name(c); + + if (lptName == nullptr) + break; + + const QString name = tr(lptName); + + for (uint8_t i = 0; i < PARALLEL_MAX; ++i) { + int row = Models::AddEntry(models[i], name, c); + + if (c == lpt_ports[i].device) + selectedRows[i] = row - removeRows_[i]; + } + + c++; + } + + for (uint8_t i = 0; i < PARALLEL_MAX; ++i) { + models[i]->removeRows(0, removeRows_[i]); + cbox[i]->setEnabled(models[i]->rowCount() > 1); + cbox[i]->setCurrentIndex(-1); + cbox[i]->setCurrentIndex(selectedRows[i]); + + auto *checkBox = findChild(QString("checkBoxParallel%1").arg(i + 1)); + if (checkBox != NULL) + checkBox->setChecked(lpt_ports[i].enabled > 0); + if (cbox[i] != NULL) + cbox[i]->setEnabled(lpt_ports[i].enabled > 0); + } + + for (int i = 0; i < (SERIAL_MAX - 1); i++) { + auto *checkBox = findChild(QString("checkBoxSerial%1").arg(i + 1)); + auto *checkBoxPass = findChild(QString("checkBoxSerialPassThru%1").arg(i + 1)); + auto *buttonPass = findChild(QString("pushButtonSerialPassThru%1").arg(i + 1)); + if (checkBox != NULL) + checkBox->setChecked(com_ports[i].enabled > 0); + if (checkBoxPass != NULL) { + checkBoxPass->setEnabled(com_ports[i].enabled > 0); + checkBoxPass->setChecked(serial_passthrough_enabled[i]); + buttonPass->setEnabled((com_ports[i].enabled > 0) && serial_passthrough_enabled[i]); + } + } +} + void SettingsPorts::on_checkBoxParallel1_stateChanged(int state) { @@ -136,90 +156,141 @@ SettingsPorts::on_checkBoxParallel4_stateChanged(int state) ui->comboBoxLpt4->setEnabled(state == Qt::Checked); } +void +SettingsPorts::on_checkBoxSerial1_stateChanged(int state) +{ + ui->checkBoxSerialPassThru1->setEnabled(state == Qt::Checked); + ui->pushButtonSerialPassThru1->setEnabled((state == Qt::Checked) && ui->checkBoxSerialPassThru1->isChecked()); +} + +void +SettingsPorts::on_checkBoxSerial2_stateChanged(int state) +{ + ui->checkBoxSerialPassThru2->setEnabled(state == Qt::Checked); + ui->pushButtonSerialPassThru2->setEnabled((state == Qt::Checked) && ui->checkBoxSerialPassThru2->isChecked()); +} + +void +SettingsPorts::on_checkBoxSerial3_stateChanged(int state) +{ + ui->checkBoxSerialPassThru3->setEnabled(state == Qt::Checked); + ui->pushButtonSerialPassThru3->setEnabled((state == Qt::Checked) && ui->checkBoxSerialPassThru3->isChecked()); +} + +void +SettingsPorts::on_checkBoxSerial4_stateChanged(int state) +{ + ui->checkBoxSerialPassThru4->setEnabled(state == Qt::Checked); + ui->pushButtonSerialPassThru4->setEnabled((state == Qt::Checked) && ui->checkBoxSerialPassThru4->isChecked()); +} + +#if 0 +void +SettingsPorts::on_checkBoxSerial5_stateChanged(int state) +{ + ui->checkBoxSerialPassThru5->setEnabled(state == Qt::Checked); + ui->pushButtonSerialPassThru5->setEnabled((state == Qt::Checked) && ui->checkBoxSerialPassThru5->isChecked()); +} + +void +SettingsPorts::on_checkBoxSerial6_stateChanged(int state) +{ + ui->checkBoxSerialPassThru6->setEnabled(state == Qt::Checked); + ui->pushButtonSerialPassThru6->setEnabled((state == Qt::Checked) && ui->checkBoxSerialPassThru6->isChecked()); +} + +void +SettingsPorts::on_checkBoxSerial7_stateChanged(int state) +{ + ui->checkBoxSerialPassThru7->setEnabled(state == Qt::Checked); + ui->pushButtonSerialPassThru7->setEnabled((state == Qt::Checked) && ui->checkBoxSerialPassThru7->isChecked()); +} +#endif + +void +SettingsPorts::on_checkBoxSerialPassThru1_stateChanged(int state) +{ + ui->pushButtonSerialPassThru1->setEnabled(state == Qt::Checked); +} + +void +SettingsPorts::on_checkBoxSerialPassThru2_stateChanged(int state) +{ + ui->pushButtonSerialPassThru2->setEnabled(state == Qt::Checked); +} + +void +SettingsPorts::on_checkBoxSerialPassThru3_stateChanged(int state) +{ + ui->pushButtonSerialPassThru3->setEnabled(state == Qt::Checked); +} + +void +SettingsPorts::on_checkBoxSerialPassThru4_stateChanged(int state) +{ + ui->pushButtonSerialPassThru4->setEnabled(state == Qt::Checked); +} + +#if 0 +void +SettingsPorts::on_checkBoxSerialPassThru5_stateChanged(int state) +{ + ui->pushButtonSerialPassThru5->setEnabled(state == Qt::Checked); +} + +void +SettingsPorts::on_checkBoxSerialPassThru6_stateChanged(int state) +{ + ui->pushButtonSerialPassThru6->setEnabled(state == Qt::Checked); +} + +void +SettingsPorts::on_checkBoxSerialPassThru7_stateChanged(int state) +{ + ui->pushButtonSerialPassThru7->setEnabled(state == Qt::Checked); +} +#endif + void SettingsPorts::on_pushButtonSerialPassThru1_clicked() { - DeviceConfig::ConfigureDevice(&serial_passthrough_device, 1, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(&serial_passthrough_device, 1); } void SettingsPorts::on_pushButtonSerialPassThru2_clicked() { - DeviceConfig::ConfigureDevice(&serial_passthrough_device, 2, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(&serial_passthrough_device, 2); } void SettingsPorts::on_pushButtonSerialPassThru3_clicked() { - DeviceConfig::ConfigureDevice(&serial_passthrough_device, 3, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(&serial_passthrough_device, 3); } void SettingsPorts::on_pushButtonSerialPassThru4_clicked() { - DeviceConfig::ConfigureDevice(&serial_passthrough_device, 4, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(&serial_passthrough_device, 4); } #if 0 void SettingsPorts::on_pushButtonSerialPassThru5_clicked() { - DeviceConfig::ConfigureDevice(&serial_passthrough_device, 5, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(&serial_passthrough_device, 5); } void SettingsPorts::on_pushButtonSerialPassThru6_clicked() { - DeviceConfig::ConfigureDevice(&serial_passthrough_device, 6, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(&serial_passthrough_device, 6); } void SettingsPorts::on_pushButtonSerialPassThru7_clicked() { - DeviceConfig::ConfigureDevice(&serial_passthrough_device, 7, qobject_cast(Settings::settings)); -} -#endif - -void -SettingsPorts::on_checkBoxSerialPassThru1_clicked(bool checked) -{ - ui->pushButtonSerialPassThru1->setEnabled(checked); -} - -void -SettingsPorts::on_checkBoxSerialPassThru2_clicked(bool checked) -{ - ui->pushButtonSerialPassThru2->setEnabled(checked); -} - -void -SettingsPorts::on_checkBoxSerialPassThru3_clicked(bool checked) -{ - ui->pushButtonSerialPassThru3->setEnabled(checked); -} - -void -SettingsPorts::on_checkBoxSerialPassThru4_clicked(bool checked) -{ - ui->pushButtonSerialPassThru4->setEnabled(checked); -} - -#if 0 -void -SettingsPorts::on_checkBoxSerialPassThru5_clicked(bool checked) -{ - ui->pushButtonSerialPassThru5->setEnabled(checked); -} - -void -SettingsPorts::on_checkBoxSerialPassThru6_clicked(bool checked) -{ - ui->pushButtonSerialPassThru6->setEnabled(checked); -} - -void -SettingsPorts::on_checkBoxSerialPassThru7_clicked(bool checked) -{ - ui->pushButtonSerialPassThru7->setEnabled(checked); + DeviceConfig::ConfigureDevice(&serial_passthrough_device, 7); } #endif diff --git a/src/qt/qt_settingsports.hpp b/src/qt/qt_settingsports.hpp index fb9cdb343..8be1f0491 100644 --- a/src/qt/qt_settingsports.hpp +++ b/src/qt/qt_settingsports.hpp @@ -16,36 +16,50 @@ public: void save(); -#if 0 -private slots: - void on_checkBoxSerialPassThru7_clicked(bool checked); - void on_checkBoxSerialPassThru6_clicked(bool checked); - void on_checkBoxSerialPassThru5_clicked(bool checked); -#endif - void on_checkBoxSerialPassThru4_clicked(bool checked); - void on_checkBoxSerialPassThru3_clicked(bool checked); - void on_checkBoxSerialPassThru2_clicked(bool checked); - void on_checkBoxSerialPassThru1_clicked(bool checked); +public slots: + void onCurrentMachineChanged(int machineId); private slots: + void on_checkBoxParallel1_stateChanged(int state); + void on_checkBoxParallel2_stateChanged(int state); + void on_checkBoxParallel3_stateChanged(int state); + void on_checkBoxParallel4_stateChanged(int state); + + void on_checkBoxSerial1_stateChanged(int state); + void on_checkBoxSerial2_stateChanged(int state); + void on_checkBoxSerial3_stateChanged(int state); + void on_checkBoxSerial4_stateChanged(int state); #if 0 - void on_pushButtonSerialPassThru7_clicked(); - void on_pushButtonSerialPassThru6_clicked(); - void on_pushButtonSerialPassThru5_clicked(); + void on_checkBoxSerial5_stateChanged(int state); + void on_checkBoxSerial6_stateChanged(int state); + void on_checkBoxSerial7_stateChanged(int state); #endif - void on_pushButtonSerialPassThru4_clicked(); - void on_pushButtonSerialPassThru3_clicked(); - void on_pushButtonSerialPassThru2_clicked(); + void on_checkBoxSerialPassThru1_stateChanged(int state); void on_pushButtonSerialPassThru1_clicked(); -private slots: - void on_checkBoxParallel4_stateChanged(int arg1); - void on_checkBoxParallel3_stateChanged(int arg1); - void on_checkBoxParallel2_stateChanged(int arg1); - void on_checkBoxParallel1_stateChanged(int arg1); + void on_checkBoxSerialPassThru2_stateChanged(int state); + void on_pushButtonSerialPassThru2_clicked(); + + void on_checkBoxSerialPassThru3_stateChanged(int state); + void on_pushButtonSerialPassThru3_clicked(); + + void on_checkBoxSerialPassThru4_stateChanged(int state); + void on_pushButtonSerialPassThru4_clicked(); + +#if 0 + void on_checkBoxSerialPassThru5_stateChanged(int state); + void on_pushButtonSerialPassThru5_clicked(); + + void on_checkBoxSerialPassThru6_stateChanged(int state); + void on_pushButtonSerialPassThru6_clicked(); + + void on_checkBoxSerialPassThru7_stateChanged(int state); + void on_pushButtonSerialPassThru7_clicked(); +#endif private: Ui::SettingsPorts *ui; + int machineId = 0; }; #endif // QT_SETTINGSPORTS_HPP diff --git a/src/qt/qt_settingsports.ui b/src/qt/qt_settingsports.ui index bca870e5d..92420f2df 100644 --- a/src/qt/qt_settingsports.ui +++ b/src/qt/qt_settingsports.ui @@ -29,7 +29,7 @@ - + LPT1 Device: @@ -43,7 +43,7 @@ - + LPT2 Device: @@ -57,7 +57,7 @@ - + LPT3 Device: @@ -71,7 +71,7 @@ - + LPT4 Device: @@ -88,27 +88,6 @@ - - - - Parallel port 2 - - - - - - - Parallel port 3 - - - - - - - Serial port 3 - - - @@ -116,20 +95,6 @@ - - - - Parallel port 4 - - - - - - - Serial port 2 - - - @@ -137,6 +102,34 @@ + + + + Serial port 2 + + + + + + + Parallel port 2 + + + + + + + Serial port 3 + + + + + + + Parallel port 3 + + + @@ -144,13 +137,76 @@ + + + + Parallel port 4 + + + - + QLayout::SetDefaultConstraint + + + + Serial port passthrough 1 + + + + + + + Configure + + + + + + + Serial port passthrough 2 + + + + + + + Configure + + + + + + + Serial port passthrough 3 + + + + + + + Configure + + + + + + + Serial port passthrough 4 + + + + + + + Configure + + + @@ -164,13 +220,6 @@ - - - - Serial port passthrough 3 - - - @@ -184,55 +233,6 @@ - - - - Configure - - - - - - - Serial port passthrough 1 - - - - - - - Serial port passthrough 2 - - - - - - - Serial port passthrough 4 - - - - - - - Configure - - - - - - - Configure - - - - - - - Configure - - - diff --git a/src/qt/qt_settingssound.cpp b/src/qt/qt_settingssound.cpp index e0572c3d8..57e278515 100644 --- a/src/qt/qt_settingssound.cpp +++ b/src/qt/qt_settingssound.cpp @@ -14,7 +14,7 @@ * Jasmine Iwanek * * Copyright 2021 Joakim L. Gilje - * Copyright 2022-2023 Jasmine Iwanek + * Copyright 2022-2025 Jasmine Iwanek */ #include "qt_settingssound.hpp" #include "ui_qt_settingssound.h" @@ -50,13 +50,15 @@ void SettingsSound::save() { for (uint8_t i = 0; i < SOUND_CARD_MAX; ++i) { - auto *cbox = findChild(QString("comboBoxSoundCard%1").arg(i + 1)); - sound_card_current[i] = cbox->currentData().toInt(); + QComboBox *cbox = findChild(QString("comboBoxSoundCard%1").arg(i + 1)); + sound_card_current[i] = cbox->currentData().toInt(); } midi_output_device_current = ui->comboBoxMidiOut->currentData().toInt(); - midi_input_device_current = ui->comboBoxMidiIn->currentData().toInt(); - mpu401_standalone_enable = ui->checkBoxMPU401->isChecked() ? 1 : 0; + + midi_input_device_current = ui->comboBoxMidiIn->currentData().toInt(); + + mpu401_standalone_enable = ui->checkBoxMPU401->isChecked() ? 1 : 0; sound_is_float = ui->checkBoxFloat32->isChecked() ? 1 : 0; @@ -71,93 +73,110 @@ SettingsSound::onCurrentMachineChanged(const int machineId) { this->machineId = machineId; - int c; - int selectedRow; + int c; + int selectedRow; + + // Sound Cards + QComboBox *cbox[SOUND_CARD_MAX] = { 0 }; + QAbstractItemModel *models[SOUND_CARD_MAX] = { 0 }; + int removeRows_[SOUND_CARD_MAX] = { 0 }; + int selectedRows[SOUND_CARD_MAX] = { 0 }; + int m_has_snd = machine_has_flags(machineId, MACHINE_SOUND); for (uint8_t i = 0; i < SOUND_CARD_MAX; ++i) { - auto * cbox = findChild(QString("comboBoxSoundCard%1").arg(i + 1)); - auto * model = cbox->model(); - const auto removeRows = model->rowCount(); - c = 0; - selectedRow = 0; - - while (true) { - /* Skip "internal" if machine doesn't have it or this is not the primary card. */ - if ((c == 1) && ((i > 0) || (machine_has_flags(machineId, MACHINE_SOUND) == 0))) { - c++; - continue; - } - - auto name = DeviceConfig::DeviceName(sound_card_getdevice(c), sound_card_get_internal_name(c), 1); - if (name.isEmpty()) { - break; - } - - if (sound_card_available(c) && device_is_valid(sound_card_getdevice(c), machineId)) { - int row = Models::AddEntry(model, name, c); - if (c == sound_card_current[i]) { - selectedRow = row - removeRows; - } - } - c++; - } - - model->removeRows(0, removeRows); - cbox->setEnabled(model->rowCount() > 0); - cbox->setCurrentIndex(-1); - cbox->setCurrentIndex(selectedRow); + cbox[i] = findChild(QString("comboBoxSoundCard%1").arg(i + 1)); + models[i] = cbox[i]->model(); + removeRows_[i] = models[i]->rowCount(); } - auto model = ui->comboBoxMidiOut->model(); - auto removeRows = model->rowCount(); - c = 0; - selectedRow = 0; + c = 0; while (true) { - QString name = DeviceConfig::DeviceName(midi_out_device_getdevice(c), midi_out_device_get_internal_name(c), 0); - if (name.isEmpty()) { + const QString name = DeviceConfig::DeviceName(sound_card_getdevice(c), + sound_card_get_internal_name(c), 1); + + if (name.isEmpty()) break; + + if (sound_card_available(c)) { + if (device_is_valid(sound_card_getdevice(c), machineId)) { + for (uint8_t i = 0; i < SOUND_CARD_MAX; ++i) { + if ((c != 1) || ((i == 0) && m_has_snd)) { + int row = Models::AddEntry(models[i], name, c); + + if (c == sound_card_current[i]) + selectedRows[i] = row - removeRows_[i]; + } + } + } } + c++; + } + + for (uint8_t i = 0; i < SOUND_CARD_MAX; ++i) { + models[i]->removeRows(0, removeRows_[i]); + cbox[i]->setEnabled(models[i]->rowCount() > 1); + cbox[i]->setCurrentIndex(-1); + cbox[i]->setCurrentIndex(selectedRows[i]); + } + + // Midi Out + c = 0; + auto *model = ui->comboBoxMidiOut->model(); + auto removeRows = model->rowCount(); + selectedRow = 0; + + while (true) { + const QString name = DeviceConfig::DeviceName(midi_out_device_getdevice(c), midi_out_device_get_internal_name(c), 0); + if (name.isEmpty()) + break; + if (midi_out_device_available(c)) { int row = Models::AddEntry(model, name, c); - if (c == midi_output_device_current) { + if (c == midi_output_device_current) selectedRow = row - removeRows; - } } + c++; } + model->removeRows(0, removeRows); ui->comboBoxMidiOut->setEnabled(model->rowCount() > 0); ui->comboBoxMidiOut->setCurrentIndex(-1); ui->comboBoxMidiOut->setCurrentIndex(selectedRow); + // Midi In + c = 0; model = ui->comboBoxMidiIn->model(); removeRows = model->rowCount(); - c = 0; selectedRow = 0; + while (true) { - QString name = DeviceConfig::DeviceName(midi_in_device_getdevice(c), midi_in_device_get_internal_name(c), 0); - if (name.isEmpty()) { + const QString name = DeviceConfig::DeviceName(midi_in_device_getdevice(c), midi_in_device_get_internal_name(c), 0); + if (name.isEmpty()) break; - } if (midi_in_device_available(c)) { int row = Models::AddEntry(model, name, c); - if (c == midi_input_device_current) { + if (c == midi_input_device_current) selectedRow = row - removeRows; - } } c++; } + model->removeRows(0, removeRows); ui->comboBoxMidiIn->setEnabled(model->rowCount() > 0); ui->comboBoxMidiIn->setCurrentIndex(-1); ui->comboBoxMidiIn->setCurrentIndex(selectedRow); + // Standalone MPU401 ui->checkBoxMPU401->setChecked(mpu401_standalone_enable > 0); + + // Float32 Sound ui->checkBoxFloat32->setChecked(sound_is_float > 0); + // FM Driver switch (fm_driver) { case FM_DRV_YMFM: ui->radioButtonYMFM->setChecked(true); @@ -175,13 +194,11 @@ allowMpu401(Ui::SettingsSound *ui) QString midiOut = midi_out_device_get_internal_name(ui->comboBoxMidiOut->currentData().toInt()); QString midiIn = midi_in_device_get_internal_name(ui->comboBoxMidiIn->currentData().toInt()); - if (midiOut.isEmpty()) { + if (midiOut.isEmpty()) return false; - } - if (midiOut == QStringLiteral("none") && midiIn == QStringLiteral("none")) { + if (midiOut == QStringLiteral("none") && midiIn == QStringLiteral("none")) return false; - } return true; } @@ -189,10 +206,11 @@ allowMpu401(Ui::SettingsSound *ui) void SettingsSound::on_comboBoxSoundCard1_currentIndexChanged(int index) { - if (index < 0) { + if (index < 0) return; - } + int sndCard = ui->comboBoxSoundCard1->currentData().toInt(); + if (sndCard == SOUND_INTERNAL) ui->pushButtonConfigureSoundCard1->setEnabled(machine_has_flags(machineId, MACHINE_SOUND) && device_has_config(machine_get_snd_device(machineId))); @@ -203,73 +221,79 @@ SettingsSound::on_comboBoxSoundCard1_currentIndexChanged(int index) void SettingsSound::on_pushButtonConfigureSoundCard1_clicked() { - int sndCard = ui->comboBoxSoundCard1->currentData().toInt(); - auto *device = sound_card_getdevice(sndCard); + int sndCard = ui->comboBoxSoundCard1->currentData().toInt(); + auto *device = sound_card_getdevice(sndCard); + if (sndCard == SOUND_INTERNAL) device = machine_get_snd_device(machineId); - DeviceConfig::ConfigureDevice(device, 1, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(device, 1); } void SettingsSound::on_comboBoxSoundCard2_currentIndexChanged(int index) { - if (index < 0) { + if (index < 0) return; - } + int sndCard = ui->comboBoxSoundCard2->currentData().toInt(); + ui->pushButtonConfigureSoundCard2->setEnabled(sound_card_has_config(sndCard)); } void SettingsSound::on_pushButtonConfigureSoundCard2_clicked() { - int sndCard = ui->comboBoxSoundCard2->currentData().toInt(); - auto *device = sound_card_getdevice(sndCard); - DeviceConfig::ConfigureDevice(device, 2, qobject_cast(Settings::settings)); + int sndCard = ui->comboBoxSoundCard2->currentData().toInt(); + const device_t *device = sound_card_getdevice(sndCard); + DeviceConfig::ConfigureDevice(device, 2); } void SettingsSound::on_comboBoxSoundCard3_currentIndexChanged(int index) { - if (index < 0) { + if (index < 0) return; - } + int sndCard = ui->comboBoxSoundCard3->currentData().toInt(); + ui->pushButtonConfigureSoundCard3->setEnabled(sound_card_has_config(sndCard)); } void SettingsSound::on_pushButtonConfigureSoundCard3_clicked() { - int sndCard = ui->comboBoxSoundCard3->currentData().toInt(); - auto *device = sound_card_getdevice(sndCard); - DeviceConfig::ConfigureDevice(device, 3, qobject_cast(Settings::settings)); + int sndCard = ui->comboBoxSoundCard3->currentData().toInt(); + const device_t *device = sound_card_getdevice(sndCard); + + DeviceConfig::ConfigureDevice(device, 3); } void SettingsSound::on_comboBoxSoundCard4_currentIndexChanged(int index) { - if (index < 0) { + if (index < 0) return; - } + int sndCard = ui->comboBoxSoundCard4->currentData().toInt(); + ui->pushButtonConfigureSoundCard4->setEnabled(sound_card_has_config(sndCard)); } void SettingsSound::on_pushButtonConfigureSoundCard4_clicked() { - int sndCard = ui->comboBoxSoundCard4->currentData().toInt(); - auto *device = sound_card_getdevice(sndCard); - DeviceConfig::ConfigureDevice(device, 4, qobject_cast(Settings::settings)); + int sndCard = ui->comboBoxSoundCard4->currentData().toInt(); + const device_t *device = sound_card_getdevice(sndCard); + + DeviceConfig::ConfigureDevice(device, 4); } void SettingsSound::on_comboBoxMidiOut_currentIndexChanged(int index) { - if (index < 0) { + if (index < 0) return; - } + ui->pushButtonConfigureMidiOut->setEnabled(midi_out_device_has_config(ui->comboBoxMidiOut->currentData().toInt())); ui->checkBoxMPU401->setEnabled(allowMpu401(ui) && (machine_has_bus(machineId, MACHINE_BUS_ISA) || machine_has_bus(machineId, MACHINE_BUS_MCA))); ui->pushButtonConfigureMPU401->setEnabled(allowMpu401(ui) && ui->checkBoxMPU401->isChecked()); @@ -278,16 +302,15 @@ SettingsSound::on_comboBoxMidiOut_currentIndexChanged(int index) void SettingsSound::on_pushButtonConfigureMidiOut_clicked() { - DeviceConfig::ConfigureDevice(midi_out_device_getdevice(ui->comboBoxMidiOut->currentData().toInt()), 0, - qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(midi_out_device_getdevice(ui->comboBoxMidiOut->currentData().toInt())); } void SettingsSound::on_comboBoxMidiIn_currentIndexChanged(int index) { - if (index < 0) { + if (index < 0) return; - } + ui->pushButtonConfigureMidiIn->setEnabled(midi_in_device_has_config(ui->comboBoxMidiIn->currentData().toInt())); ui->checkBoxMPU401->setEnabled(allowMpu401(ui) && (machine_has_bus(machineId, MACHINE_BUS_ISA) || machine_has_bus(machineId, MACHINE_BUS_MCA))); ui->pushButtonConfigureMPU401->setEnabled(allowMpu401(ui) && ui->checkBoxMPU401->isChecked()); @@ -296,8 +319,7 @@ SettingsSound::on_comboBoxMidiIn_currentIndexChanged(int index) void SettingsSound::on_pushButtonConfigureMidiIn_clicked() { - DeviceConfig::ConfigureDevice(midi_in_device_getdevice(ui->comboBoxMidiIn->currentData().toInt()), 0, - qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(midi_in_device_getdevice(ui->comboBoxMidiIn->currentData().toInt())); } void @@ -310,7 +332,7 @@ void SettingsSound::on_pushButtonConfigureMPU401_clicked() { if (machine_has_bus(machineId, MACHINE_BUS_MCA) > 0) - DeviceConfig::ConfigureDevice(&mpu401_mca_device, 0, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(&mpu401_mca_device); else - DeviceConfig::ConfigureDevice(&mpu401_device, 0, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(&mpu401_device); } diff --git a/src/qt/qt_settingssound.hpp b/src/qt/qt_settingssound.hpp index 92b700c92..cc2926d5d 100644 --- a/src/qt/qt_settingssound.hpp +++ b/src/qt/qt_settingssound.hpp @@ -20,20 +20,26 @@ public slots: void onCurrentMachineChanged(int machineId); private slots: - void on_pushButtonConfigureMPU401_clicked(); - void on_checkBoxMPU401_stateChanged(int arg1); - void on_pushButtonConfigureMidiIn_clicked(); - void on_pushButtonConfigureMidiOut_clicked(); - void on_comboBoxMidiIn_currentIndexChanged(int index); - void on_comboBoxMidiOut_currentIndexChanged(int index); - void on_pushButtonConfigureSoundCard1_clicked(); void on_comboBoxSoundCard1_currentIndexChanged(int index); - void on_pushButtonConfigureSoundCard2_clicked(); + void on_pushButtonConfigureSoundCard1_clicked(); + void on_comboBoxSoundCard2_currentIndexChanged(int index); - void on_pushButtonConfigureSoundCard3_clicked(); + void on_pushButtonConfigureSoundCard2_clicked(); + void on_comboBoxSoundCard3_currentIndexChanged(int index); - void on_pushButtonConfigureSoundCard4_clicked(); + void on_pushButtonConfigureSoundCard3_clicked(); + void on_comboBoxSoundCard4_currentIndexChanged(int index); + void on_pushButtonConfigureSoundCard4_clicked(); + + void on_comboBoxMidiOut_currentIndexChanged(int index); + void on_pushButtonConfigureMidiOut_clicked(); + + void on_comboBoxMidiIn_currentIndexChanged(int index); + void on_pushButtonConfigureMidiIn_clicked(); + + void on_checkBoxMPU401_stateChanged(int arg1); + void on_pushButtonConfigureMPU401_clicked(); private: Ui::SettingsSound *ui; diff --git a/src/qt/qt_settingssound.ui b/src/qt/qt_settingssound.ui index 1d5ab0050..97ef7c3ff 100644 --- a/src/qt/qt_settingssound.ui +++ b/src/qt/qt_settingssound.ui @@ -26,17 +26,23 @@ 0 - - + + - MIDI In Device: + Sound card #1: - - - - Sound card #1: + + + + 30 + + + + 0 + 0 + @@ -48,12 +54,25 @@ - + Sound card #2: + + + + 30 + + + + 0 + 0 + + + + @@ -62,12 +81,25 @@ - + Sound card #3: + + + + 30 + + + + 0 + 0 + + + + @@ -75,14 +107,26 @@ - - + Sound card #4: + + + + 30 + + + + 0 + 0 + + + + @@ -90,49 +134,13 @@ - - - - - - 30 - - - - 0 - 0 - - - - - + MIDI Out Device: - - - - Standalone MPU-401 - - - - - - - Configure - - - - - - - Configure - - - @@ -153,6 +161,47 @@ + + + + MIDI In Device: + + + + + + + 30 + + + + 0 + 0 + + + + + + + + Configure + + + + + + + Standalone MPU-401 + + + + + + + Configure + + + @@ -171,7 +220,7 @@ FM synth driver - + @@ -202,58 +251,6 @@ - - - - 30 - - - - 0 - 0 - - - - - - - - 30 - - - - 0 - 0 - - - - - - - - 30 - - - - 0 - 0 - - - - - - - - 30 - - - - 0 - 0 - - - - diff --git a/src/qt/qt_settingsstoragecontrollers.cpp b/src/qt/qt_settingsstoragecontrollers.cpp index a86362909..b3d827fa2 100644 --- a/src/qt/qt_settingsstoragecontrollers.cpp +++ b/src/qt/qt_settingsstoragecontrollers.cpp @@ -52,12 +52,12 @@ void SettingsStorageControllers::save() { /* Storage devices category */ - for (int i = 0; i < SCSI_CARD_MAX; ++i) { - auto *cbox = findChild(QString("comboBoxSCSI%1").arg(i + 1)); + for (uint8_t i = 0; i < SCSI_CARD_MAX; ++i) { + QComboBox *cbox = findChild(QString("comboBoxSCSI%1").arg(i + 1)); scsi_card_current[i] = cbox->currentData().toInt(); } - hdc_current[0] = ui->comboBoxHD->currentData().toInt(); fdc_current[0] = ui->comboBoxFD->currentData().toInt(); + hdc_current[0] = ui->comboBoxHD->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; @@ -71,10 +71,11 @@ SettingsStorageControllers::onCurrentMachineChanged(int machineId) this->machineId = machineId; /*HD controller config*/ + int c = 0; auto *model = ui->comboBoxHD->model(); auto removeRows = model->rowCount(); - int c = 0; int selectedRow = 0; + while (true) { /* Skip "internal" if machine doesn't have it. */ if ((c == 1) && (machine_has_flags(machineId, MACHINE_HDC) == 0)) { @@ -83,18 +84,16 @@ SettingsStorageControllers::onCurrentMachineChanged(int machineId) } QString name = DeviceConfig::DeviceName(hdc_get_device(c), hdc_get_internal_name(c), 1); - if (name.isEmpty()) { + if (name.isEmpty()) break; - } if (hdc_available(c)) { - auto *hdc_dev = hdc_get_device(c); + const device_t *hdc_dev = hdc_get_device(c); if (device_is_valid(hdc_dev, machineId)) { int row = Models::AddEntry(model, name, c); - if (c == hdc_current[0]) { + if (c == hdc_current[0]) selectedRow = row - removeRows; - } } } c++; @@ -104,7 +103,7 @@ SettingsStorageControllers::onCurrentMachineChanged(int machineId) ui->comboBoxHD->setCurrentIndex(-1); ui->comboBoxHD->setCurrentIndex(selectedRow); - /*FD controller config*/ + /* FD controller config */ model = ui->comboBoxFD->model(); removeRows = model->rowCount(); c = 0; @@ -124,7 +123,7 @@ SettingsStorageControllers::onCurrentMachineChanged(int machineId) } if (fdc_card_available(c)) { - auto *fdc_dev = fdc_card_getdevice(c); + const device_t *fdc_dev = fdc_card_getdevice(c); if (device_is_valid(fdc_dev, machineId)) { int row = Models::AddEntry(model, name, c); @@ -141,10 +140,20 @@ SettingsStorageControllers::onCurrentMachineChanged(int machineId) ui->comboBoxFD->setCurrentIndex(selectedRow); /*CD interface controller config*/ - model = ui->comboBoxCDInterface->model(); - removeRows = model->rowCount(); - c = 0; +#ifdef USE_CDROM_MITSUMI + ui->labelCDInterface->setVisible(true); + ui->comboBoxCDInterface->setVisible(true); + ui->pushButtonCDInterface->setVisible(true); +#else + ui->labelCDInterface->setVisible(false); + ui->comboBoxCDInterface->setVisible(false); + ui->pushButtonCDInterface->setVisible(false); +#endif + c = 0; + model = ui->comboBoxCDInterface->model(); + removeRows = model->rowCount(); selectedRow = 0; + while (true) { /* Skip "internal" if machine doesn't have it. */ QString name = DeviceConfig::DeviceName(cdrom_interface_get_device(c), cdrom_interface_get_internal_name(c), 1); @@ -153,7 +162,7 @@ SettingsStorageControllers::onCurrentMachineChanged(int machineId) } if (cdrom_interface_available(c)) { - auto *cdrom_interface_dev = cdrom_interface_get_device(c); + const device_t *cdrom_interface_dev = cdrom_interface_get_device(c); if (device_is_valid(cdrom_interface_dev, machineId)) { int row = Models::AddEntry(model, name, c); @@ -169,35 +178,45 @@ SettingsStorageControllers::onCurrentMachineChanged(int machineId) ui->comboBoxCDInterface->setCurrentIndex(-1); ui->comboBoxCDInterface->setCurrentIndex(selectedRow); - for (int i = 0; i < SCSI_CARD_MAX; ++i) { - auto *cbox = findChild(QString("comboBoxSCSI%1").arg(i + 1)); - model = cbox->model(); - removeRows = model->rowCount(); - c = 0; - selectedRow = 0; + // SCSI Card + QComboBox * cbox[SCSI_CARD_MAX] = { 0 }; + QAbstractItemModel *models[SCSI_CARD_MAX] = { 0 }; + int removeRows_[SCSI_CARD_MAX] = { 0 }; + int selectedRows[SCSI_CARD_MAX] = { 0 }; - while (true) { - auto name = DeviceConfig::DeviceName(scsi_card_getdevice(c), scsi_card_get_internal_name(c), 1); - if (name.isEmpty()) { - break; - } + for (uint8_t i = 0; i < SCSI_CARD_MAX; ++i) { + cbox[i] = findChild(QString("comboBoxSCSI%1").arg(i + 1)); + models[i] = cbox[i]->model(); + removeRows_[i] = models[i]->rowCount(); + } - if (scsi_card_available(c)) { - auto *scsi_dev = scsi_card_getdevice(c); - if (device_is_valid(scsi_dev, machineId)) { - int row = Models::AddEntry(model, name, c); - if (c == scsi_card_current[i]) { - selectedRow = row - removeRows; - } + c = 0; + while (true) { + const QString name = DeviceConfig::DeviceName(scsi_card_getdevice(c), + scsi_card_get_internal_name(c), 1); + + if (name.isEmpty()) + break; + + if (scsi_card_available(c)) { + if (device_is_valid(scsi_card_getdevice(c), machineId)) { + for (uint8_t i = 0; i < SCSI_CARD_MAX; ++i) { + int row = Models::AddEntry(models[i], name, c); + + if (c == scsi_card_current[i]) + selectedRows[i] = row - removeRows_[i]; } } - c++; } - model->removeRows(0, removeRows); - cbox->setEnabled(model->rowCount() > 0); - cbox->setCurrentIndex(-1); - cbox->setCurrentIndex(selectedRow); + c++; + } + + for (uint8_t i = 0; i < SCSI_CARD_MAX; ++i) { + models[i]->removeRows(0, removeRows_[i]); + cbox[i]->setEnabled(models[i]->rowCount() > 1); + cbox[i]->setCurrentIndex(-1); + cbox[i]->setCurrentIndex(selectedRows[i]); } int is_at = IS_AT(machineId); @@ -218,29 +237,30 @@ SettingsStorageControllers::onCurrentMachineChanged(int machineId) ui->pushButtonConfigureLbaEnhancer->setEnabled(ui->checkBoxLbaEnhancer->isChecked()); } +void +SettingsStorageControllers::on_comboBoxFD_currentIndexChanged(int index) +{ + if (index < 0) + return; + + ui->pushButtonFD->setEnabled(hdc_has_config(ui->comboBoxFD->currentData().toInt()) > 0); +} + void SettingsStorageControllers::on_comboBoxHD_currentIndexChanged(int index) { - if (index < 0) { + if (index < 0) return; - } + ui->pushButtonHD->setEnabled(hdc_has_config(ui->comboBoxHD->currentData().toInt()) > 0); } void -SettingsStorageControllers::on_comboBoxFD_currentIndexChanged(int index) +SettingsStorageControllers::on_comboBoxCDInterface_currentIndexChanged(int index) { - if (index < 0) { + if (index < 0) return; - } - ui->pushButtonFD->setEnabled(hdc_has_config(ui->comboBoxFD->currentData().toInt()) > 0); -} -void SettingsStorageControllers::on_comboBoxCDInterface_currentIndexChanged(int index) -{ - if (index < 0) { - return; - } ui->pushButtonCDInterface->setEnabled(cdrom_interface_has_config(ui->comboBoxCDInterface->currentData().toInt()) > 0); } @@ -257,103 +277,103 @@ SettingsStorageControllers::on_checkBoxQuaternaryIDE_stateChanged(int arg1) } void -SettingsStorageControllers::on_pushButtonHD_clicked() +SettingsStorageControllers::on_pushButtonFD_clicked() { - DeviceConfig::ConfigureDevice(hdc_get_device(ui->comboBoxHD->currentData().toInt()), 0, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(fdc_card_getdevice(ui->comboBoxFD->currentData().toInt())); } void -SettingsStorageControllers::on_pushButtonFD_clicked() +SettingsStorageControllers::on_pushButtonHD_clicked() { - DeviceConfig::ConfigureDevice(fdc_card_getdevice(ui->comboBoxFD->currentData().toInt()), 0, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(hdc_get_device(ui->comboBoxHD->currentData().toInt())); } void SettingsStorageControllers::on_pushButtonCDInterface_clicked() { - DeviceConfig::ConfigureDevice(cdrom_interface_get_device(ui->comboBoxCDInterface->currentData().toInt()), 0, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(cdrom_interface_get_device(ui->comboBoxCDInterface->currentData().toInt())); } void SettingsStorageControllers::on_pushButtonTertiaryIDE_clicked() { - DeviceConfig::ConfigureDevice(&ide_ter_device, 0, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(&ide_ter_device); } void SettingsStorageControllers::on_pushButtonQuaternaryIDE_clicked() { - DeviceConfig::ConfigureDevice(&ide_qua_device, 0, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(&ide_qua_device); } void SettingsStorageControllers::on_comboBoxSCSI1_currentIndexChanged(int index) { - if (index < 0) { + if (index < 0) return; - } + ui->pushButtonSCSI1->setEnabled(scsi_card_has_config(ui->comboBoxSCSI1->currentData().toInt()) > 0); } void SettingsStorageControllers::on_comboBoxSCSI2_currentIndexChanged(int index) { - if (index < 0) { + if (index < 0) return; - } + ui->pushButtonSCSI2->setEnabled(scsi_card_has_config(ui->comboBoxSCSI2->currentData().toInt()) > 0); } void SettingsStorageControllers::on_comboBoxSCSI3_currentIndexChanged(int index) { - if (index < 0) { + if (index < 0) return; - } + ui->pushButtonSCSI3->setEnabled(scsi_card_has_config(ui->comboBoxSCSI3->currentData().toInt()) > 0); } void SettingsStorageControllers::on_comboBoxSCSI4_currentIndexChanged(int index) { - if (index < 0) { + if (index < 0) return; - } + ui->pushButtonSCSI4->setEnabled(scsi_card_has_config(ui->comboBoxSCSI4->currentData().toInt()) > 0); } void SettingsStorageControllers::on_pushButtonSCSI1_clicked() { - DeviceConfig::ConfigureDevice(scsi_card_getdevice(ui->comboBoxSCSI1->currentData().toInt()), 1, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(scsi_card_getdevice(ui->comboBoxSCSI1->currentData().toInt()), 1); } void SettingsStorageControllers::on_pushButtonSCSI2_clicked() { - DeviceConfig::ConfigureDevice(scsi_card_getdevice(ui->comboBoxSCSI2->currentData().toInt()), 2, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(scsi_card_getdevice(ui->comboBoxSCSI2->currentData().toInt()), 2); } void SettingsStorageControllers::on_pushButtonSCSI3_clicked() { - DeviceConfig::ConfigureDevice(scsi_card_getdevice(ui->comboBoxSCSI3->currentData().toInt()), 3, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(scsi_card_getdevice(ui->comboBoxSCSI3->currentData().toInt()), 3); } void SettingsStorageControllers::on_pushButtonSCSI4_clicked() { - DeviceConfig::ConfigureDevice(scsi_card_getdevice(ui->comboBoxSCSI4->currentData().toInt()), 4, qobject_cast(Settings::settings)); + DeviceConfig::ConfigureDevice(scsi_card_getdevice(ui->comboBoxSCSI4->currentData().toInt()), 4); } -void SettingsStorageControllers::on_checkBoxLbaEnhancer_stateChanged(int arg1) +void +SettingsStorageControllers::on_checkBoxLbaEnhancer_stateChanged(int arg1) { ui->pushButtonConfigureLbaEnhancer->setEnabled(arg1 != 0); } - -void SettingsStorageControllers::on_pushButtonConfigureLbaEnhancer_clicked() +void +SettingsStorageControllers::on_pushButtonConfigureLbaEnhancer_clicked() { DeviceConfig::ConfigureDevice(&lba_enhancer_device); } - diff --git a/src/qt/qt_settingsstoragecontrollers.hpp b/src/qt/qt_settingsstoragecontrollers.hpp index c50a94574..7c1c56086 100644 --- a/src/qt/qt_settingsstoragecontrollers.hpp +++ b/src/qt/qt_settingsstoragecontrollers.hpp @@ -20,27 +20,31 @@ public slots: void onCurrentMachineChanged(int machineId); private slots: - void on_pushButtonSCSI4_clicked(); - void on_pushButtonSCSI3_clicked(); - void on_pushButtonSCSI2_clicked(); - void on_pushButtonSCSI1_clicked(); - void on_comboBoxSCSI4_currentIndexChanged(int index); - void on_comboBoxSCSI3_currentIndexChanged(int index); - void on_comboBoxSCSI2_currentIndexChanged(int index); - void on_comboBoxSCSI1_currentIndexChanged(int index); - void on_pushButtonQuaternaryIDE_clicked(); - void on_pushButtonTertiaryIDE_clicked(); - void on_pushButtonFD_clicked(); - void on_pushButtonHD_clicked(); - void on_pushButtonCDInterface_clicked(); - void on_checkBoxQuaternaryIDE_stateChanged(int arg1); - void on_checkBoxTertiaryIDE_stateChanged(int arg1); void on_comboBoxFD_currentIndexChanged(int index); + void on_pushButtonFD_clicked(); + void on_comboBoxHD_currentIndexChanged(int index); + void on_pushButtonHD_clicked(); + void on_comboBoxCDInterface_currentIndexChanged(int index); + void on_pushButtonCDInterface_clicked(); + + void on_checkBoxTertiaryIDE_stateChanged(int arg1); + void on_pushButtonTertiaryIDE_clicked(); + + void on_checkBoxQuaternaryIDE_stateChanged(int arg1); + void on_pushButtonQuaternaryIDE_clicked(); + + void on_comboBoxSCSI1_currentIndexChanged(int index); + void on_pushButtonSCSI1_clicked(); + void on_comboBoxSCSI2_currentIndexChanged(int index); + void on_pushButtonSCSI2_clicked(); + void on_comboBoxSCSI3_currentIndexChanged(int index); + void on_pushButtonSCSI3_clicked(); + void on_comboBoxSCSI4_currentIndexChanged(int index); + void on_pushButtonSCSI4_clicked(); void on_checkBoxLbaEnhancer_stateChanged(int arg1); - void on_pushButtonConfigureLbaEnhancer_clicked(); private: diff --git a/src/qt/qt_settingsstoragecontrollers.ui b/src/qt/qt_settingsstoragecontrollers.ui index 16d6e2494..cd1bf9baf 100644 --- a/src/qt/qt_settingsstoragecontrollers.ui +++ b/src/qt/qt_settingsstoragecontrollers.ui @@ -29,13 +29,20 @@ - + - HD Controller: + FD Controller: - + + + + 30 + + + + Configure @@ -43,43 +50,13 @@ - + - FD Controller: + HD Controller: - - - - false - - - CD-ROM Controller: - - - - - - - false - - - 30 - - - - - - - false - - - Configure - - - - + @@ -92,20 +69,34 @@ - + Configure - - + + + + CD-ROM Controller: + + + + + 30 + + + + Configure + + + @@ -113,13 +104,6 @@ - - - - Quaternary IDE Controller - - - @@ -130,6 +114,13 @@ + + + + Quaternary IDE Controller + + + @@ -143,29 +134,15 @@ - + SCSI - - - + + + - Configure - - - - - - - Configure - - - - - - - Controller 3: + Controller 1: @@ -189,6 +166,13 @@ + + + + Controller 2: + + + @@ -202,6 +186,20 @@ + + + + Configure + + + + + + + Controller 3: + + + @@ -215,6 +213,20 @@ + + + + Configure + + + + + + + Controller 4: + + + @@ -228,29 +240,8 @@ - - - - Controller 1: - - - - - - - Controller 2: - - - - - - - Controller 4: - - - - - + + Configure diff --git a/src/qt/qt_singlekeyseqedit.cpp b/src/qt/qt_singlekeyseqedit.cpp new file mode 100644 index 000000000..f17d2164f --- /dev/null +++ b/src/qt/qt_singlekeyseqedit.cpp @@ -0,0 +1,20 @@ +#include "qt_singlekeyseqedit.hpp" + +/* + This subclass of QKeySequenceEdit restricts the input to only a single + shortcut instead of an unlimited number with a fixed timeout. +*/ + +singleKeySequenceEdit::singleKeySequenceEdit(QWidget *parent) : QKeySequenceEdit(parent) {} + +void singleKeySequenceEdit::keyPressEvent(QKeyEvent *event) +{ + QKeySequenceEdit::keyPressEvent(event); + if (this->keySequence().count() > 0) { + QKeySequenceEdit::setKeySequence(this->keySequence()); + + // This could have unintended consequences since it will happen + // every single time the user presses a key. + emit editingFinished(); + } +} \ No newline at end of file diff --git a/src/qt/qt_singlekeyseqedit.hpp b/src/qt/qt_singlekeyseqedit.hpp new file mode 100644 index 000000000..43ebe70b2 --- /dev/null +++ b/src/qt/qt_singlekeyseqedit.hpp @@ -0,0 +1,16 @@ +#ifndef SINGLEKEYSEQUENCEEDIT_H +#define SINGLEKEYSEQUENCEEDIT_H + +#include +#include + +class singleKeySequenceEdit : public QKeySequenceEdit +{ + Q_OBJECT +public: + singleKeySequenceEdit(QWidget *parent = nullptr); + + void keyPressEvent(QKeyEvent *) override; +}; + +#endif // SINGLEKEYSEQUENCEEDIT_H diff --git a/src/qt/qt_styleoverride.cpp b/src/qt/qt_styleoverride.cpp index 7ec5a341c..0bade8fa6 100644 --- a/src/qt/qt_styleoverride.cpp +++ b/src/qt/qt_styleoverride.cpp @@ -18,6 +18,16 @@ #include #include +#include +#include +#include + +#ifdef Q_OS_WINDOWS +#include +#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE +#define DWMWA_USE_IMMERSIVE_DARK_MODE 20 +#endif +#endif int StyleOverride::styleHint( @@ -48,9 +58,51 @@ StyleOverride::polish(QWidget *widget) widget->setWindowFlag(Qt::MSWindowsFixedSizeDialogHint, true); } widget->setWindowFlag(Qt::WindowContextHelpButtonHint, false); +#ifdef Q_OS_WINDOWS + extern bool windows_is_light_theme(); + BOOL DarkMode = !windows_is_light_theme(); + DwmSetWindowAttribute((HWND)widget->winId(), DWMWA_USE_IMMERSIVE_DARK_MODE, (LPCVOID)&DarkMode, sizeof(DarkMode)); +#endif } if (qobject_cast(widget)) { qobject_cast(widget)->view()->setMinimumWidth(widget->minimumSizeHint().width()); } } + +QPixmap +StyleOverride::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *option) const +{ + if (iconMode != QIcon::Disabled) { + return QProxyStyle::generatedIconPixmap(iconMode, pixmap, option); + } + + auto image = pixmap.toImage(); + + for (int y = 0; y < image.height(); y++) { + for (int x = 0; x < image.width(); x++) { + // checkerboard transparency + if (((x ^ y) & 1) == 0) { + image.setPixelColor(x, y, Qt::transparent); + continue; + } + + auto color = image.pixelColor(x, y); + + // convert to grayscale using the NTSC formula + auto avg = 0.0; + avg += color.blueF() * 0.114; + avg += color.greenF() * 0.587; + avg += color.redF() * 0.299; + + color.setRedF(avg); + color.setGreenF(avg); + color.setBlueF(avg); + + image.setPixelColor(x, y, color); + + } + } + + return QPixmap::fromImage(image); +} diff --git a/src/qt/qt_styleoverride.hpp b/src/qt/qt_styleoverride.hpp index c04d01a12..840aa6ad6 100644 --- a/src/qt/qt_styleoverride.hpp +++ b/src/qt/qt_styleoverride.hpp @@ -4,6 +4,9 @@ #include #include #include +#include +#include +#include class StyleOverride : public QProxyStyle { public: @@ -14,6 +17,7 @@ public: QStyleHintReturn *returnData = nullptr) const override; void polish(QWidget *widget) override; + QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *option) const override; }; #endif diff --git a/src/qt/qt_translations.qrc.in b/src/qt/qt_translations.qrc.in index 655323563..c050747c0 100644 --- a/src/qt/qt_translations.qrc.in +++ b/src/qt/qt_translations.qrc.in @@ -20,6 +20,7 @@ 86box_ru-RU.qm 86box_sk-SK.qm 86box_sl-SI.qm + 86box_sv-SE.qm 86box_tr-TR.qm 86box_uk-UA.qm 86box_vi-VN.qm diff --git a/src/qt/qt_ui.cpp b/src/qt/qt_ui.cpp index b9253663b..6e0b3cfbb 100644 --- a/src/qt/qt_ui.cpp +++ b/src/qt/qt_ui.cpp @@ -23,6 +23,7 @@ #include #include +#include #include "qt_mainwindow.hpp" #include "qt_machinestatus.hpp" @@ -122,6 +123,10 @@ plat_resize(int w, int h, int monitor_index) main_window->resizeContents(w, h); } +#if defined _WIN32 +extern HWND rw_hwnd; +#endif + void plat_mouse_capture(int on) { @@ -129,6 +134,26 @@ plat_mouse_capture(int on) return; main_window->setMouseCapture(on > 0 ? true : false); + +#if defined _WIN32 + if (on) { + QCursor cursor(Qt::BlankCursor); + + QApplication::setOverrideCursor(cursor); + QApplication::changeOverrideCursor(cursor); + + RECT rect; + + GetWindowRect(rw_hwnd, &rect); + + ClipCursor(&rect); + + } else { + ClipCursor(NULL); + + QApplication::restoreOverrideCursor(); + } +#endif } int @@ -141,12 +166,18 @@ ui_msgbox_header(int flags, void *header, void *message) // any error in early init if (main_window == nullptr) { - QMessageBox msgBox(QMessageBox::Icon::Critical, hdr, msg); - msgBox.setTextFormat(Qt::TextFormat::RichText); + auto msgicon = QMessageBox::Icon::Critical; + if (flags & MBX_INFO) + msgicon = QMessageBox::Icon::Information; + else if (flags & MBX_QUESTION) + msgicon = QMessageBox::Icon::Question; + else if (flags & MBX_WARNING) + msgicon = QMessageBox::Icon::Warning; + QMessageBox msgBox(msgicon, hdr, msg); msgBox.exec(); } else { // else scope it to main_window - main_window->showMessage(flags, hdr, msg); + main_window->showMessage(flags, hdr, msg, false); } return 0; } @@ -308,4 +339,41 @@ ui_sb_update_icon(int tag, int active) break; } } + +void +ui_sb_update_icon_write(int tag, int write) +{ + const auto temp = static_cast(tag); + const int category = static_cast(temp & 0xfffffff0); + const int item = tag & 0xf; + + switch (category) { + default: + case SB_CASSETTE: + case SB_CARTRIDGE: + break; + case SB_FLOPPY: + machine_status.fdd[item].write_active = write > 0 ? true : false; + break; + case SB_CDROM: + machine_status.cdrom[item].write_active = write > 0 ? true : false; + break; + case SB_ZIP: + machine_status.zip[item].write_active = write > 0 ? true : false; + break; + case SB_MO: + machine_status.mo[item].write_active = write > 0 ? true : false; + break; + case SB_HDD: + machine_status.hdd[item].write_active = write > 0 ? true : false; + break; + case SB_NETWORK: + machine_status.net[item].write_active = write > 0 ? true : false; + break; + case SB_SOUND: + case SB_TEXT: + break; + } +} + } diff --git a/src/qt/qt_updatecheck.cpp b/src/qt/qt_updatecheck.cpp new file mode 100644 index 000000000..83e2b34d9 --- /dev/null +++ b/src/qt/qt_updatecheck.cpp @@ -0,0 +1,360 @@ +/* + * 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. + * + * Update check module + * + * + * + * Authors: cold-brewed + * + * Copyright 2024 cold-brewed + */ + +#include +#include +#include +#include +#include + +#include "qt_updatecheck.hpp" +#include "qt_downloader.hpp" +#include "qt_updatedetails.hpp" + +extern "C" { +#include <86box/version.h> +} + +UpdateCheck:: +UpdateCheck(const UpdateChannel channel, QObject *parent) : QObject(parent) +{ + updateChannel = channel; + currentVersion = getCurrentVersion(channel); +} + +UpdateCheck::~ +UpdateCheck() + = default; + +void +UpdateCheck::checkForUpdates() +{ + if (updateChannel == UpdateChannel::Stable) { + const auto githubDownloader = new Downloader(Downloader::DownloadLocation::Temp); + connect(githubDownloader, &Downloader::downloadCompleted, this, &UpdateCheck::githubDownloadComplete); + connect(githubDownloader, &Downloader::errorOccurred, this, &UpdateCheck::generalDownloadError); + githubDownloader->download(QUrl(githubReleaseApi), "github_releases.json"); + } else { + const auto jenkinsDownloader = new Downloader(Downloader::DownloadLocation::Temp); + connect(jenkinsDownloader, &Downloader::downloadCompleted, this, &UpdateCheck::jenkinsDownloadComplete); + connect(jenkinsDownloader, &Downloader::errorOccurred, this, &UpdateCheck::generalDownloadError); + jenkinsDownloader->download(jenkinsLatestNReleasesUrl(10), "jenkins_list.json"); + } +} + +void +UpdateCheck::jenkinsDownloadComplete(const QString &filename, const QVariant &varData) +{ + auto generalError = tr("Unable to determine release information"); + auto jenkinsReleaseListResult = parseJenkinsJson(filename); + auto latestVersion = 0; // NOLINT (Default value as a fallback) + + if(!jenkinsReleaseListResult.has_value() || jenkinsReleaseListResult.value().isEmpty()) { + generalDownloadError(generalError); + return; + } + const auto jenkinsReleaseList = jenkinsReleaseListResult.value(); + latestVersion = jenkinsReleaseListResult->first().buildNumber; + + // If we can't determine the local build (blank current version), always show an update as available. + // Callers can adjust accordingly. + // Otherwise, do a comparison with EMU_BUILD_NUM + bool updateAvailable = false; + bool upToDate = true; + if(currentVersion.isEmpty() || EMU_BUILD_NUM < latestVersion) { + updateAvailable = true; + upToDate = false; + } + + const auto updateResult = UpdateResult { + .channel = updateChannel, + .updateAvailable = updateAvailable, + .upToDate = upToDate, + .currentVersion = currentVersion, + .latestVersion = QString::number(latestVersion), + .githubInfo = {}, + .jenkinsInfo = jenkinsReleaseList, + }; + + emit updateCheckComplete(updateResult); +} + +void +UpdateCheck::generalDownloadError(const QString &error) +{ + emit updateCheckError(error); +} + +void +UpdateCheck::githubDownloadComplete(const QString &filename, const QVariant &varData) +{ + const auto generalError = tr("Unable to determine release information"); + const auto githubReleaseListResult = parseGithubJson(filename); + QString latestVersion = "0.0"; + if(!githubReleaseListResult.has_value() || githubReleaseListResult.value().isEmpty()) { + generalDownloadError(generalError); + } + auto githubReleaseList = githubReleaseListResult.value(); + // Warning: this check (using the tag name) relies on a consistent naming scheme: "v" + // where is the release number. For example, 4.2 from v4.2 as the tag name. + // Another option would be parsing the name field which is generally "86Box " but + // either option requires a consistent naming scheme. + latestVersion = githubReleaseList.first().tag_name.replace("v", ""); + for (const auto &release: githubReleaseList) { + qDebug().noquote().nospace() << release.name << ": " << release.html_url << " (" << release.created_at << ")"; + } + + // const auto updateDetails = new UpdateDetails(githubReleaseList, currentVersion); + bool updateAvailable = false; + bool upToDate = true; + if(currentVersion.isEmpty() || (versionCompare(currentVersion, latestVersion) < 0)) { + updateAvailable = true; + upToDate = false; + } + + const auto updateResult = UpdateResult { + .channel = updateChannel, + .updateAvailable = updateAvailable, + .upToDate = upToDate, + .currentVersion = currentVersion, + .latestVersion = latestVersion, + .githubInfo = githubReleaseList, + .jenkinsInfo = {}, + }; + + emit updateCheckComplete(updateResult); + +} + +QUrl +UpdateCheck::jenkinsLatestNReleasesUrl(const int &count) +{ + const auto urlPath = QString("https://ci.86box.net/job/86box/api/json?tree=builds[number,result,timestamp,changeSets[items[commitId,affectedPaths,author[fullName],msg,id]]]{0,%1}").arg(count); + return { urlPath }; +} + +QString +UpdateCheck::getCurrentVersion(const UpdateChannel &updateChannel) +{ + if (updateChannel == UpdateChannel::Stable) { + return {EMU_VERSION}; + } + // If EMU_BUILD_NUM is anything other than the default of zero it was set by the build process + if constexpr (EMU_BUILD_NUM != 0) { + return QString::number(EMU_BUILD_NUM); // NOLINT because EMU_BUILD_NUM is defined as 0 by default and is set at build time + } + // EMU_BUILD_NUM is not set, most likely a local build + return {}; // NOLINT (Having EMU_BUILD_NUM assigned to a default number throws off the linter) +} + +std::optional> +UpdateCheck::parseJenkinsJson(const QString &filename) +{ + QList releaseInfoList; + QFile json_file(filename); + if (!json_file.open(QIODevice::ReadOnly | QIODevice::Text)) { + qWarning() << "Couldn't open the json file: error" << json_file.error(); + return std::nullopt; + } + + const QString read_file = json_file.readAll(); + json_file.close(); + + const auto json_doc = QJsonDocument::fromJson(read_file.toUtf8()); + + if (json_doc.isNull()) { + qWarning("Failed to create QJsonDocument, possibly invalid JSON"); + return std::nullopt; + } + + if (!json_doc.isObject()) { + qWarning("JSON does not have the expected format (object in root), cannot continue"); + return std::nullopt; + } + + auto json_object = json_doc.object(); + + // The json contains multiple release + if(json_object.contains("builds") && json_object["builds"].isArray()) { + + QJsonArray builds = json_object["builds"].toArray(); + for (const auto &each_build: builds) { + if (auto build = parseJenkinsRelease(each_build.toObject()); build.has_value() && build.value().result == "SUCCESS") { + releaseInfoList.append(build.value()); + } + } + } else if(json_object.contains("changeSets") && json_object["changeSets"].isArray()) { + // The json contains only one release, as obtained by the lastSuccessfulBuild api + if (const auto build = parseJenkinsRelease(json_object); build.has_value()) { + releaseInfoList.append(build.value()); + } + } else { + qWarning("JSON is missing data or has invalid data, cannot continue"); + qDebug() << json_object; + return std::nullopt; + } + + return releaseInfoList; +} + +std::optional +UpdateCheck::parseJenkinsRelease(const QJsonObject &json) +{ + // The root should contain number, result, and timestamp. + if (!json.contains("number") || !json.contains("result") || !json.contains("timestamp")) { + return std::nullopt; + } + + auto releaseInfo = JenkinsReleaseInfo { + .buildNumber = json["number"].toInt(), + .result = json["result"].toString(), + .timestamp = static_cast(json["timestamp"].toDouble()) + }; + + // Overview + // Each build should contain a changeSets object with an array. Only the first element is needed. + // The first element should be an object containing an items object with an array. + // Each array element in the items object has information releated to the build. More or less: commit data + // In jq parlance it would be similar to `builds[].changeSets[0].items[]` + + // To break down the somewhat complicated if-init statement below: + // * Get the object for `changeSets` + // * Convert the value to array + // * Grab the first element in the array + // Proceed if + // * the element (first in changeSets) is an object that contains the key `items` + if (const auto changeSet = json["changeSets"].toArray().first(); changeSet.isObject() && changeSet.toObject().contains("items")) { + // Then proceed to process each `items` array element + for (const auto &item : changeSet.toObject()["items"].toArray()) { + auto itemObject = item.toObject(); + // Basic validation + if (!itemObject.contains("commitId") || !itemObject.contains("msg") || !itemObject.contains("affectedPaths")) { + return std::nullopt; + } + // Convert the paths for each commit to a string list + QStringList paths; + for (const auto &each_path : itemObject["affectedPaths"].toArray().toVariantList()) { + if (each_path.type() == QVariant::String) { + paths.append(each_path.toString()); + } + } + // Build the structure + const auto releaseItem = JenkinsChangeSetItem { + .buildId = itemObject["commitId"].toString(), + .author = itemObject["author"].toObject()["fullName"].toString(), + .message = itemObject["msg"].toString(), + .affectedPaths = paths, + }; + releaseInfo.changeSetItems.append(releaseItem); + } + } else { + qWarning("Could not parse release information, possibly invalid JSON"); + } + return releaseInfo; +} + +std::optional> +UpdateCheck::parseGithubJson(const QString &filename) +{ + QList releaseInfoList; + QFile json_file(filename); + if (!json_file.open(QIODevice::ReadOnly | QIODevice::Text)) { + qWarning("Couldn't open the json file: error %d", json_file.error()); + return std::nullopt; + } + + const QString read_file = json_file.readAll(); + json_file.close(); + + const auto json_doc = QJsonDocument::fromJson(read_file.toUtf8()); + + if (json_doc.isNull()) { + qWarning("Failed to create QJsonDocument, possibly invalid JSON"); + return std::nullopt; + } + + if (!json_doc.isArray()) { + qWarning("JSON does not have the expected format (array in root), cannot continue"); + return std::nullopt; + } + + auto release_array = json_doc.array(); + + for (const auto &each_release: release_array) { + if (auto release = parseGithubRelease(each_release.toObject()); release.has_value()) { + releaseInfoList.append(release.value()); + } + } + return releaseInfoList; +} +std::optional +UpdateCheck::parseGithubRelease(const QJsonObject &json) +{ + // Perform some basic validation + if (!json.contains("name") || !json.contains("tag_name") || !json.contains("html_url")) { + return std::nullopt; + } + + auto githubRelease = GithubReleaseInfo { + .name = json["name"].toString(), + .tag_name = json["tag_name"].toString(), + .html_url = json["html_url"].toString(), + .target_commitish = json["target_commitish"].toString(), + .created_at = json["created_at"].toString(), + .published_at = json["published_at"].toString(), + .body = json["body"].toString(), + }; + + return githubRelease; +} + +// A simple method to compare version numbers +// Should work for comparing x.y.z and x.y. Missing +// values (parts) will be treated as zeroes +int +UpdateCheck::versionCompare(const QString &version1, const QString &version2) +{ + // Split both + QStringList v1List = version1.split('.'); + QStringList v2List = version2.split('.'); + + // Out of the two versions get the maximum amount of "parts" + const int maxParts = std::max(v1List.size(), v2List.size()); + + // Initialize both with zeros + QVector v1Parts(maxParts, 0); + QVector v2Parts(maxParts, 0); + + for (int i = 0; i < v1List.size(); ++i) { + v1Parts[i] = v1List[i].toInt(); + } + + for (int i = 0; i < v2List.size(); ++i) { + v2Parts[i] = v2List[i].toInt(); + } + + for (int i = 0; i < maxParts; ++i) { + // First version is greater + if (v1Parts[i] > v2Parts[i]) + return 1; + // First version is less + if (v1Parts[i] < v2Parts[i]) + return -1; + } + // They are equal + return 0; +} diff --git a/src/qt/qt_updatecheck.hpp b/src/qt/qt_updatecheck.hpp new file mode 100644 index 000000000..2c04993fc --- /dev/null +++ b/src/qt/qt_updatecheck.hpp @@ -0,0 +1,104 @@ +/* + * 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. + * + * Header for the update check module + * + * + * + * Authors: cold-brewed + * + * Copyright 2024 cold-brewed + */ + +#ifndef QT_UPDATECHECK_HPP +#define QT_UPDATECHECK_HPP + +#include +#include +#include +#include + +#include + +class UpdateCheck final : public QObject { + Q_OBJECT +public: + enum class UpdateChannel { + Stable, + CI, + }; + + struct JenkinsChangeSetItem { + QString buildId; // sha hash + QString author; // github username + QString message; // commit message + QStringList affectedPaths; // list of files in the change + }; + + struct JenkinsReleaseInfo { + int buildNumber = 0; + QString result; + qint64 timestamp = 0; + QList changeSetItems; + }; + + struct GithubReleaseInfo { + QString name; + QString tag_name; + QString html_url; + QString target_commitish; + QString created_at; + QString published_at; + QString body; + }; + + struct UpdateResult { + UpdateChannel channel; + bool updateAvailable = false; + bool upToDate = false; + QString currentVersion; + QString latestVersion; + QList githubInfo; + QList jenkinsInfo; + }; + + explicit UpdateCheck(UpdateChannel channel, QObject *parent = nullptr); + ~UpdateCheck() override; + void checkForUpdates(); + static int versionCompare(const QString &version1, const QString &version2); + [[nodiscard]] static QString getCurrentVersion(const UpdateChannel &updateChannel = UpdateChannel::Stable); + +signals: + // void updateCheckComplete(const UpdateCheck::UpdateChannel &channel, const QVariant &updateData); + void updateCheckComplete(const UpdateCheck::UpdateResult &result); + void updateCheckError(const QString &errorMsg); + +private: + UpdateChannel updateChannel = UpdateChannel::Stable; + + const QUrl githubReleaseApi = QUrl("https://api.github.com/repos/86box/86Box/releases"); + const QUrl jenkinsLatestApi = QUrl("https://ci.86box.net/job/86box/lastSuccessfulBuild/api/json"); + QString jenkinsLatestVersion; + QString currentVersion; + + static QUrl jenkinsLatestNReleasesUrl(const int &count); + + static std::optional> parseJenkinsJson(const QString &filename); + static std::optional parseJenkinsRelease(const QJsonObject &json); + + static std::optional> parseGithubJson(const QString &filename); + static std::optional parseGithubRelease(const QJsonObject &json); + + +private slots: + void jenkinsDownloadComplete(const QString &filename, const QVariant& varData); + void githubDownloadComplete(const QString &filename, const QVariant& varData); + void generalDownloadError(const QString &error); +}; + +#endif // QT_UPDATECHECK_HPP diff --git a/src/qt/qt_updatecheckdialog.cpp b/src/qt/qt_updatecheckdialog.cpp new file mode 100644 index 000000000..d0cb6941d --- /dev/null +++ b/src/qt/qt_updatecheckdialog.cpp @@ -0,0 +1,90 @@ +/* + * 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. + * + * Update check dialog module + * + * + * + * Authors: cold-brewed + * + * Copyright 2024 cold-brewed + */ + +#include +#include + +#include "qt_updatecheckdialog.hpp" +#include "ui_qt_updatecheckdialog.h" +#include "qt_updatedetails.hpp" + +extern "C" { +#include <86box/version.h> +} + +UpdateCheckDialog:: +UpdateCheckDialog(const UpdateCheck::UpdateChannel channel, QWidget *parent) : QDialog(parent), ui(new Ui::UpdateCheckDialog), updateCheck(new UpdateCheck(channel)) +{ + ui->setupUi(this); + setWindowTitle(tr("Update check")); + ui->statusLabel->setHidden(true); + updateChannel = channel; + currentVersion = UpdateCheck::getCurrentVersion(updateChannel); + connect(updateCheck, &UpdateCheck::updateCheckError, [=](const QString &errorMsg) { + generalDownloadError(errorMsg); + }); + connect(updateCheck, &UpdateCheck::updateCheckComplete, this, &UpdateCheckDialog::downloadComplete); + + QTimer::singleShot(0, [this] { + updateCheck->checkForUpdates(); + }); +} + +UpdateCheckDialog::~ +UpdateCheckDialog() + = default; + +void +UpdateCheckDialog::generalDownloadError(const QString &error) const +{ + ui->progressBar->setMaximum(100); + ui->progressBar->setValue(100); + ui->statusLabel->setVisible(true); + const auto statusText = tr("There was an error checking for updates:\n\n%1\n\nPlease try again later.").arg(error); + ui->statusLabel->setText(statusText); + ui->buttonBox->setStandardButtons(QDialogButtonBox::Ok); +} + +void +UpdateCheckDialog::downloadComplete(const UpdateCheck::UpdateResult &result) +{ + if (result.upToDate) { + upToDate(); + return; + } + + const auto updateDetails = new UpdateDetails(result); + connect(updateDetails, &QDialog::accepted, [this] { + accept(); + }); + connect(updateDetails, &QDialog::rejected, [this] { + reject(); + }); + updateDetails->exec(); +} + +void +UpdateCheckDialog::upToDate() +{ + ui->titleLabel->setText(tr("Update check complete")); + ui->progressBar->setMaximum(100); + ui->progressBar->setValue(100); + ui->statusLabel->setVisible(true); + const auto statusText = tr("You are running the latest %1 version of 86Box: %2").arg(updateChannel == UpdateCheck::UpdateChannel::Stable ? "stable" : "beta", currentVersion); + ui->statusLabel->setText(statusText); + ui->buttonBox->setStandardButtons(QDialogButtonBox::Ok); +} diff --git a/src/qt/qt_updatecheckdialog.hpp b/src/qt/qt_updatecheckdialog.hpp new file mode 100644 index 000000000..0f1c0dfa8 --- /dev/null +++ b/src/qt/qt_updatecheckdialog.hpp @@ -0,0 +1,47 @@ +/* + * 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. + * + * Header for the update check dialog module + * + * + * + * Authors: cold-brewed + * + * Copyright 2024 cold-brewed + */ + +#ifndef QT_UPDATECHECKDIALOG_HPP +#define QT_UPDATECHECKDIALOG_HPP + +#include + +#include + +namespace Ui { +class UpdateCheckDialog; +} + +class UpdateCheckDialog final : public QDialog { + Q_OBJECT +public: + explicit UpdateCheckDialog(UpdateCheck::UpdateChannel channel, QWidget *parent = nullptr); + ~UpdateCheckDialog() override; + +private: + Ui::UpdateCheckDialog *ui; + UpdateCheck::UpdateChannel updateChannel = UpdateCheck::UpdateChannel::Stable; + UpdateCheck *updateCheck; + QString currentVersion; + void upToDate(); + +private slots: + void downloadComplete(const UpdateCheck::UpdateResult &result); + void generalDownloadError(const QString &error) const; +}; + +#endif // QT_UPDATECHECKDIALOG_HPP diff --git a/src/qt/qt_updatecheckdialog.ui b/src/qt/qt_updatecheckdialog.ui new file mode 100644 index 000000000..e50a541bb --- /dev/null +++ b/src/qt/qt_updatecheckdialog.ui @@ -0,0 +1,106 @@ + + + UpdateCheckDialog + + + + 0 + 0 + 350 + 134 + + + + + 0 + 0 + + + + Dialog + + + + + + + 0 + 0 + + + + Checking for updates.. + + + Qt::AlignCenter + + + + + + + 0 + + + -1 + + + + + + + Status text here + + + + + + + true + + + Qt::Horizontal + + + QDialogButtonBox::Cancel + + + + + + + + + buttonBox + accepted() + UpdateCheckDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + UpdateCheckDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/qt/qt_updatedetails.cpp b/src/qt/qt_updatedetails.cpp new file mode 100644 index 000000000..1328da732 --- /dev/null +++ b/src/qt/qt_updatedetails.cpp @@ -0,0 +1,111 @@ +/* + * 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. + * + * Update details module + * + * + * + * Authors: cold-brewed + * + * Copyright 2024 cold-brewed + */ + +#include "qt_updatedetails.hpp" +#include "ui_qt_updatedetails.h" + +#include +#include + + +UpdateDetails:: +UpdateDetails(const UpdateCheck::UpdateResult &updateResult, QWidget *parent) : ui(new Ui::UpdateDetails) +{ + ui->setupUi(this); + setWindowTitle("86Box Update"); + ui->updateTitle->setText("An update to 86Box is available!"); + QString currentVersionText; + QString releaseType = updateResult.channel == UpdateCheck::UpdateChannel::Stable ? tr("version") : tr("build"); + if(!updateResult.currentVersion.isEmpty()) { + currentVersionText = tr("You are currently running %1 %2. ").arg(releaseType, updateResult.currentVersion); + } + + const auto updateDetailsText = tr("%1 %2 is now available. %3Would you like to visit the download page?").arg(releaseType[0].toUpper() + releaseType.mid(1), updateResult.latestVersion, currentVersionText); + ui->updateDetails->setText(updateDetailsText); + + if(updateResult.channel == UpdateCheck::UpdateChannel::Stable) { + ui->updateText->setMarkdown(githubUpdateToMarkdown(updateResult.githubInfo)); + } else { + ui->updateText->setMarkdown(jenkinsUpdateToMarkdown(updateResult.jenkinsInfo)); + } + + const auto downloadButton = new QPushButton(tr("Visit download page")); + ui->buttonBox->addButton(downloadButton, QDialogButtonBox::AcceptRole); + // Override accepted to mean "I want to visit the download page" + connect(ui->buttonBox, &QDialogButtonBox::accepted, [this, updateResult] { + visitDownloadPage(updateResult.channel); + }); + const auto logo = QPixmap(":/assets/86box.png").scaled(QSize(64, 64), Qt::KeepAspectRatio, Qt::SmoothTransformation); + + ui->icon->setPixmap(logo); +} + +UpdateDetails::~ +UpdateDetails() + = default; + +QString +UpdateDetails::jenkinsUpdateToMarkdown(const QList &releaseInfoList) +{ + QStringList fullText; + for (const auto &update : releaseInfoList) { + fullText.append(QString("### Build %1").arg(update.buildNumber)); + fullText.append("Changes:"); + for (const auto &item : update.changeSetItems) { + fullText.append(QString("* %1").arg(item.message)); + } + fullText.append("\n\n\n---\n\n\n"); + } + // pop off the last hr + fullText.removeLast(); + // return fullText.join("\n\n---\n\n"); + return fullText.join("\n"); +} + +QString +UpdateDetails::githubUpdateToMarkdown(const QList &releaseInfoList) +{ + // The github release info can be rather large so we'll only + // display the most recent one + QList singleRelease; + if (!releaseInfoList.isEmpty()) { + singleRelease.append(releaseInfoList.first()); + } + QStringList fullText; + for (const auto &release : singleRelease) { + fullText.append(QString("#### %1").arg(release.name)); + // Github body text should already be in markdown and can just + // be placed here as-is + fullText.append(release.body); + fullText.append("\n\n\n---\n\n\n"); + } + // pop off the last hr + fullText.removeLast(); + return fullText.join("\n"); +} +void +UpdateDetails::visitDownloadPage(const UpdateCheck::UpdateChannel &channel) +{ + switch (channel) { + case UpdateCheck::UpdateChannel::Stable: + QDesktopServices::openUrl(QUrl("https://ci.86box.net/job/86Box/lastSuccessfulBuild/artifact/")); + break; + case UpdateCheck::UpdateChannel::CI: + QDesktopServices::openUrl(QUrl("https://github.com/86Box/86Box/releases/latest")); + break; + } +} diff --git a/src/qt/qt_updatedetails.hpp b/src/qt/qt_updatedetails.hpp new file mode 100644 index 000000000..8c3528e11 --- /dev/null +++ b/src/qt/qt_updatedetails.hpp @@ -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. + * + * Header for the update details module + * + * + * + * Authors: cold-brewed + * + * Copyright 2024 cold-brewed + */ + +#ifndef QT_UPDATEDETAILS_HPP +#define QT_UPDATEDETAILS_HPP + +#include +#include +#include "qt_updatecheck.hpp" + +namespace Ui { +class UpdateDetails; +} + +class UpdateDetails final : public QDialog { + Q_OBJECT +public: + explicit UpdateDetails(const UpdateCheck::UpdateResult &updateResult, QWidget *parent = nullptr); + ~UpdateDetails() override; +private: + Ui::UpdateDetails *ui; + static QString jenkinsUpdateToMarkdown(const QList &releaseInfoList); + static QString githubUpdateToMarkdown(const QList &releaseInfoList); +private slots: + static void visitDownloadPage(const UpdateCheck::UpdateChannel &channel); +}; + + +#endif // QT_UPDATEDETAILS_HPP diff --git a/src/qt/qt_updatedetails.ui b/src/qt/qt_updatedetails.ui new file mode 100644 index 000000000..7b9c0aa2a --- /dev/null +++ b/src/qt/qt_updatedetails.ui @@ -0,0 +1,192 @@ + + + UpdateDetails + + + + 0 + 0 + 700 + 500 + + + + + 600 + 400 + + + + Dialog + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 12 + + + 12 + + + 12 + + + 0 + + + + + + 0 + 0 + + + + + 32 + 0 + + + + + 64 + 16777215 + + + + + + + false + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Title + + + + + + + Details + + + true + + + + + + + Release notes: + + + + + + + true + + + true + + + false + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel + + + + + + + + + buttonBox + accepted() + UpdateDetails + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + UpdateDetails + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/qt/qt_util.cpp b/src/qt/qt_util.cpp index 5c9059272..5baaaaacf 100644 --- a/src/qt/qt_util.cpp +++ b/src/qt/qt_util.cpp @@ -26,6 +26,19 @@ #include #include "qt_util.hpp" +#ifdef Q_OS_WINDOWS +# include +# ifndef DWMWA_WINDOW_CORNER_PREFERENCE +# define DWMWA_WINDOW_CORNER_PREFERENCE 33 +# endif +# ifndef DWMWCP_DEFAULT +# define DWMWCP_DEFAULT 0 +# endif +# ifndef DWMWCP_DONOTROUND +# define DWMWCP_DONOTROUND 1 +# endif +#endif + extern "C" { #include <86box/86box.h> #include <86box/config.h> @@ -48,6 +61,15 @@ screenOfWidget(QWidget *widget) #endif } +#ifdef Q_OS_WINDOWS +void +setWin11RoundedCorners(WId hwnd, bool enable) +{ + auto cornerPreference = (enable ? DWMWCP_DEFAULT : DWMWCP_DONOTROUND); + DwmSetWindowAttribute((HWND) hwnd, DWMWA_WINDOW_CORNER_PREFERENCE, (LPCVOID) &cornerPreference, sizeof(cornerPreference)); +} +#endif + QString DlgFilter(std::initializer_list extensions, bool last) { @@ -70,6 +92,29 @@ DlgFilter(std::initializer_list extensions, bool last) return " (" % temp.join(' ') % ")" % (!last ? ";;" : ""); } +QString +DlgFilter(QStringList extensions, bool last) +{ + QStringList temp; + + for (auto ext : extensions) { +#ifdef Q_OS_UNIX + if (ext == "*") { + temp.append("*"); + continue; + } + temp.append("*." % ext.toUpper()); +#endif + temp.append("*." % ext); + } + +#ifdef Q_OS_UNIX + temp.removeDuplicates(); +#endif + return " (" % temp.join(' ') % ")" % (!last ? ";;" : ""); +} + + QString currentUuid() { auto configPath = QFileInfo(cfg_path).dir().canonicalPath(); diff --git a/src/qt/qt_util.hpp b/src/qt/qt_util.hpp index 6a0bdc30b..e0d2648d0 100644 --- a/src/qt/qt_util.hpp +++ b/src/qt/qt_util.hpp @@ -11,8 +11,12 @@ namespace util { static constexpr auto UUID_MIN_LENGTH = 36; /* Creates extension list for qt filedialog */ QString DlgFilter(std::initializer_list extensions, bool last = false); +QString DlgFilter(QStringList extensions, bool last = false); /* Returns screen the widget is on */ QScreen *screenOfWidget(QWidget *widget); +#ifdef Q_OS_WINDOWS +void setWin11RoundedCorners(WId hwnd, bool enable); +#endif QString currentUuid(); void storeCurrentUuid(); bool compareUuid(); diff --git a/src/qt/qt_vmmanager_addmachine.cpp b/src/qt/qt_vmmanager_addmachine.cpp new file mode 100644 index 000000000..db40972a1 --- /dev/null +++ b/src/qt/qt_vmmanager_addmachine.cpp @@ -0,0 +1,361 @@ +/* +* 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. +* +* 86Box VM manager add machine wizard +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#include +#include +#include +#include +#include +#include +#include + +#include "qt_vmmanager_addmachine.hpp" + +extern "C" { +#include <86box/86box.h> +} + +// Implementation note: There are several classes in this file: +// One for the main Wizard class and one for each page of the wizard + +VMManagerAddMachine:: +VMManagerAddMachine(QWidget *parent) : QWizard(parent) +{ + setPage(Page_Intro, new IntroPage); + setPage(Page_WithExistingConfig, new WithExistingConfigPage); + setPage(Page_NameAndLocation, new NameAndLocationPage); + setPage(Page_Conclusion, new ConclusionPage); + + // Need to create a better image + // QPixmap originalPixmap(":/assets/86box.png"); + // QPixmap scaledPixmap = originalPixmap.scaled(150, 150, Qt::KeepAspectRatio); + QPixmap wizardPixmap(":/assets/86box-wizard.png"); + +#ifndef Q_OS_MACOS + setWizardStyle(ModernStyle); + // setPixmap(LogoPixmap, scaledPixmap); + // setPixmap(LogoPixmap, wizardPixmap); + // setPixmap(WatermarkPixmap, scaledPixmap); + setPixmap(WatermarkPixmap, wizardPixmap); +#else + // macos + // setPixmap(BackgroundPixmap, scaledPixmap); + setPixmap(BackgroundPixmap, wizardPixmap); +#endif + + // Wizard wants to resize based on image. This keeps the size + setMinimumSize(size()); + setOption(HaveHelpButton, true); + // setPixmap(LogoPixmap, QPixmap(":/settings/qt/icons/86Box-gray.ico")); + + connect(this, &QWizard::helpRequested, this, &VMManagerAddMachine::showHelp); + + setWindowTitle(tr("Add new system wizard")); +} + +void +VMManagerAddMachine::showHelp() +{ + // TBD + static QString lastHelpMessage; + + QString message; + + // Help will depend on the current page + switch (currentId()) { + case Page_Intro: + message = tr("This is the into page."); + break; + default: + message = tr("No help has been added yet, you're on your own."); + break; + } + + if (lastHelpMessage == message) { + message = tr("Did you click help twice?"); + } + + QMessageBox::information(this, tr("Add new system wizard help"), message); + lastHelpMessage = message; +} + +IntroPage:: +IntroPage(QWidget *parent) +{ + setTitle(tr("Introduction")); + + setPixmap(QWizard::WatermarkPixmap, QPixmap(":/assets/qt/assets/86box.png")); + + topLabel = new QLabel(tr("This will help you add a new system to 86Box.")); + // topLabel = new QLabel(tr("This will help you add a new system to 86Box.\n\n Choose \"New configuration\" if you'd like to create a new machine.\n\nChoose \"Use existing configuration\" if you'd like to paste in an existing configuration from elsewhere.")); + topLabel->setWordWrap(true); + + newConfigRadioButton = new QRadioButton(tr("New configuration")); + // auto newDescription = new QLabel(tr("Choose this option to start with a fresh configuration.")); + existingConfigRadioButton = new QRadioButton(tr("Use existing configuraion")); + // auto existingDescription = new QLabel(tr("Use this option if you'd like to paste in the configuration file from an existing system.")); + newConfigRadioButton->setChecked(true); + + const auto layout = new QVBoxLayout(); + layout->addWidget(topLabel); + layout->addWidget(newConfigRadioButton); + // layout->addWidget(newDescription); + layout->addWidget(existingConfigRadioButton); + // layout->addWidget(existingDescription); + + setLayout(layout); +} + +int +IntroPage::nextId() const +{ + if (newConfigRadioButton->isChecked()) { + return VMManagerAddMachine::Page_NameAndLocation; + } else { + return VMManagerAddMachine::Page_WithExistingConfig; + } +} + +WithExistingConfigPage:: +WithExistingConfigPage(QWidget *parent) +{ + setTitle(tr("Use existing configuration")); + + const auto topLabel = new QLabel(tr("Paste the contents of the existing configuration file into the box below.")); + topLabel->setWordWrap(true); + + existingConfiguration = new QPlainTextEdit(); + connect(existingConfiguration, &QPlainTextEdit::textChanged, this, &WithExistingConfigPage::completeChanged); + registerField("existingConfiguration*", this, "configuration"); + + const auto layout = new QVBoxLayout(); + layout->addWidget(topLabel); + layout->addWidget(existingConfiguration); + const auto loadFileButton = new QPushButton(); + const auto loadFileLabel = new QLabel(tr("Load configuration from file")); + const auto hLayout = new QHBoxLayout(); + loadFileButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_FileIcon)); + loadFileButton->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); + connect(loadFileButton, &QPushButton::clicked, this, &WithExistingConfigPage::chooseExistingConfigFile); + hLayout->addWidget(loadFileButton); + hLayout->addWidget(loadFileLabel); + layout->addLayout(hLayout); + setLayout(layout); +} + +void +WithExistingConfigPage::chooseExistingConfigFile() +{ + // TODO: FIXME: This is using the CLI arg and needs to instead use a proper variable + const auto startDirectory = QString(vmm_path); + const auto selectedConfigFile = QFileDialog::getOpenFileName(this, tr("Choose configuration file"), + startDirectory, + tr("86Box configuration files (86box.cfg)")); + // Empty value means the dialog was canceled + if (!selectedConfigFile.isEmpty()) { + QFile configFile(selectedConfigFile); + if (!configFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + QMessageBox::critical(this, tr("Configuration read failed"), tr("Unable to open the selected configuration file for reading: %1").arg(configFile.errorString())); + return; + } + const QString configFileContents = configFile.readAll(); + existingConfiguration->setPlainText(configFileContents); + configFile.close(); + emit completeChanged(); + } +} + +QString +WithExistingConfigPage::configuration() const +{ + return existingConfiguration->toPlainText(); +} +void +WithExistingConfigPage::setConfiguration(const QString &configuration) +{ + if (configuration != existingConfiguration->toPlainText()) { + existingConfiguration->setPlainText(configuration); + emit configurationChanged(configuration); + } +} + +int +WithExistingConfigPage::nextId() const +{ + return VMManagerAddMachine::Page_NameAndLocation; +} + +bool +WithExistingConfigPage::isComplete() const +{ + return !existingConfiguration->toPlainText().isEmpty(); +} + +NameAndLocationPage:: +NameAndLocationPage(QWidget *parent) +{ + setTitle(tr("System name and location")); + + dirValidate = QRegularExpression(R"(^[^\\/:*?"<>|\s]+$)"); + + const auto topLabel = new QLabel(tr("Enter the name of the system and choose the location")); + topLabel->setWordWrap(true); + + const auto chooseDirectoryButton = new QPushButton(); + chooseDirectoryButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_DirIcon)); + + const auto systemNameLabel = new QLabel(tr("System Name")); + systemName = new QLineEdit(); + // Special event filter to override enter key + systemName->installEventFilter(this); + registerField("systemName*", systemName); + systemNameValidation = new QLabel(); + + const auto systemLocationLabel = new QLabel(tr("System Location")); + systemLocation = new QLineEdit(); + // TODO: FIXME: This is using the CLI arg and needs to instead use a proper variable + systemLocation->setText(QDir::toNativeSeparators(vmm_path)); + registerField("systemLocation*", systemLocation); + systemLocationValidation = new QLabel(); + systemLocationValidation->setWordWrap(true); + + const auto layout = new QGridLayout(); + layout->addWidget(topLabel, 0, 0, 1, -1); + // Spacer row + layout->setRowMinimumHeight(1, 20); + layout->addWidget(systemNameLabel, 2, 0); + layout->addWidget(systemName, 2, 1); + // Validation text, appears only as necessary + layout->addWidget(systemNameValidation, 3, 0, 1, -1); + // Set height on validation because it may not always be present + layout->setRowMinimumHeight(3, 20); + + // Another spacer + layout->setRowMinimumHeight(4, 20); + layout->addWidget(systemLocationLabel, 5, 0); + layout->addWidget(systemLocation, 5, 1); + layout->addWidget(chooseDirectoryButton, 5, 2); + // Validation text + layout->addWidget(systemLocationValidation, 6, 0, 1, -1); + layout->setRowMinimumHeight(6, 20); + + setLayout(layout); + + + connect(chooseDirectoryButton, &QPushButton::clicked, this, &NameAndLocationPage::chooseDirectoryLocation); +} + +int +NameAndLocationPage::nextId() const +{ + return VMManagerAddMachine::Page_Conclusion; +} + +void +NameAndLocationPage::chooseDirectoryLocation() +{ + // TODO: FIXME: This is pulling in the CLI directory! Needs to be set properly elsewhere + const auto directory = QFileDialog::getExistingDirectory(this, "Choose directory", QDir(vmm_path).path()); + systemLocation->setText(QDir::toNativeSeparators(directory)); + emit completeChanged(); +} +bool +NameAndLocationPage::isComplete() const +{ + bool nameValid = false; + bool locationValid = false; + // return true if complete + if (systemName->text().isEmpty()) { + systemNameValidation->setText(tr("Please enter a system name")); + } else if (!systemName->text().contains(dirValidate)) { + systemNameValidation->setText(tr("System name cannot contain a space or certain characters")); + } else if (const QDir newDir = QDir::cleanPath(systemLocation->text() + "/" + systemName->text()); newDir.exists()) { + systemNameValidation->setText(tr("System name already exists")); + } else { + systemNameValidation->clear(); + nameValid = true; + } + + if (systemLocation->text().isEmpty()) { + systemLocationValidation->setText(tr("Please enter a directory for the system")); + } else if (const auto dir = QDir(systemLocation->text()); !dir.exists()) { + systemLocationValidation->setText(tr("Directory does not exist")); + } else { + systemLocationValidation->setText("A new directory for the system will be created in the selected directory above"); + locationValid = true; + } + + return nameValid && locationValid; +} +bool +NameAndLocationPage::eventFilter(QObject *watched, QEvent *event) +{ + // Override the enter key to hit the next wizard button + // if the validator (isComplete) is satisfied + if (event->type() == QEvent::KeyPress) { + const auto keyEvent = dynamic_cast(event); + if (keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return) { + // Only advance if the validator is satisfied (isComplete) + if(const auto wizard = qobject_cast(this->wizard())) { + if (wizard->currentPage()->isComplete()) { + wizard->next(); + } + } + // Discard the key event + return true; + } + } + return QWizardPage::eventFilter(watched, event); +} + +ConclusionPage:: +ConclusionPage(QWidget *parent) +{ + setTitle(tr("Complete")); + + topLabel = new QLabel(tr("The wizard will now launch the configuration for the new system.")); + topLabel->setWordWrap(true); + + const auto systemNameLabel = new QLabel(tr("System name:")); + systemNameLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); + systemName = new QLabel(); + const auto systemLocationLabel = new QLabel(tr("System location:")); + systemLocationLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); + systemLocation = new QLabel(); + + const auto layout = new QGridLayout(); + layout->addWidget(topLabel, 0, 0, 1, -1); + layout->setRowMinimumHeight(1, 20); + layout->addWidget(systemNameLabel, 2, 0); + layout->addWidget(systemName, 2, 1); + layout->addWidget(systemLocationLabel, 3, 0); + layout->addWidget(systemLocation, 3, 1); + + setLayout(layout); +} + +// initializePage() runs after the page has been created with the constructor +void +ConclusionPage::initializePage() +{ + const auto finalPath = QDir::cleanPath(field("systemLocation").toString() + "/" + field("systemName").toString()); + const auto nativePath = QDir::toNativeSeparators(finalPath); + const auto systemNameDisplay = field("systemName").toString(); + + systemName->setText(systemNameDisplay); + systemLocation->setText(nativePath); +} diff --git a/src/qt/qt_vmmanager_addmachine.hpp b/src/qt/qt_vmmanager_addmachine.hpp new file mode 100644 index 000000000..c1355b471 --- /dev/null +++ b/src/qt/qt_vmmanager_addmachine.hpp @@ -0,0 +1,115 @@ +/* +* 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. +* +* Header for 86Box VM manager add machine wizard +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#ifndef QT_VMMANAGER_ADDMACHINE_H +#define QT_VMMANAGER_ADDMACHINE_H + +#include +#include +#include +#include +#include +#include + +// Implementation note: There are several classes in this header: +// One for the main Wizard class and one for each page of the wizard + +class VMManagerAddMachine final : public QWizard { + Q_OBJECT + +public: + enum { + Page_Intro, + Page_Fresh, + Page_WithExistingConfig, + Page_NameAndLocation, + Page_Conclusion + }; + + explicit VMManagerAddMachine(QWidget *parent = nullptr); + +private slots: + void showHelp(); +}; + +class IntroPage : public QWizardPage { + Q_OBJECT + +public: + explicit IntroPage(QWidget *parent = nullptr); + [[nodiscard]] int nextId() const override; + +private: + QLabel *topLabel; + QRadioButton *newConfigRadioButton; + QRadioButton *existingConfigRadioButton; +}; + +class WithExistingConfigPage final : public QWizardPage { + Q_OBJECT + Q_PROPERTY(QString configuration READ configuration WRITE setConfiguration NOTIFY configurationChanged) + +public: + explicit WithExistingConfigPage(QWidget *parent = nullptr); + // These extra functions are required to register QPlainTextEdit fields + [[nodiscard]] QString configuration() const; + void setConfiguration(const QString &configuration); +signals: + void configurationChanged(const QString &configuration); +private: + QPlainTextEdit *existingConfiguration; +private slots: + void chooseExistingConfigFile(); +protected: + [[nodiscard]] int nextId() const override; + [[nodiscard]] bool isComplete() const override; + +}; + +class NameAndLocationPage final : public QWizardPage { + Q_OBJECT + +public: + explicit NameAndLocationPage(QWidget *parent = nullptr); + [[nodiscard]] int nextId() const override; +private: + QLineEdit *systemName; + QLineEdit *systemLocation; + QLabel *systemNameValidation; + QLabel *systemLocationValidation; + QRegularExpression dirValidate; +private slots: + void chooseDirectoryLocation(); +protected: + [[nodiscard]] bool isComplete() const override; + bool eventFilter(QObject *watched, QEvent *event) override; + +}; + +class ConclusionPage final : public QWizardPage { + Q_OBJECT +public: + explicit ConclusionPage(QWidget *parent = nullptr); +private: + QLabel *topLabel; + QLabel *systemName; + QLabel *systemLocation; +protected: + void initializePage() override; +}; + +#endif // QT_VMMANAGER_ADDMACHINE_H \ No newline at end of file diff --git a/src/qt/qt_vmmanager_clientsocket.cpp b/src/qt/qt_vmmanager_clientsocket.cpp new file mode 100644 index 000000000..1035a846c --- /dev/null +++ b/src/qt/qt_vmmanager_clientsocket.cpp @@ -0,0 +1,236 @@ +/* +* 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. +* +* 86Box VM manager client socket module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#include "qt_vmmanager_clientsocket.hpp" +#include "qt_vmmanager_protocol.hpp" +#include +#include +#include + +extern "C" { +#include "86box/plat.h" +} + +VMManagerClientSocket::VMManagerClientSocket(QObject* obj) : server_connected(false) +{ + socket = new QLocalSocket; + +} + +void +VMManagerClientSocket::dataReady() +{ + // emit signal? + QDataStream stream(socket); + stream.setVersion(QDataStream::Qt_5_7); + QByteArray jsonData; + for (;;) { + // start a transaction + stream.startTransaction(); + // try to read the data + stream >> jsonData; + if (stream.commitTransaction()) { + // first try to successfully read some data + // need to also make sure it's valid json + QJsonParseError parse_error{}; + // try to create a document with the data received + const QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData, &parse_error); + if (parse_error.error == QJsonParseError::NoError) { + // the data received was valid json + if (jsonDoc.isObject()) { + // and is a valid json object + // parse the json + jsonReceived(jsonDoc.object()); + } + } + // If the received data isn't valid json, + // loop and try to read more if available + } else { + // read failed, socket is reverted to its previous state (before the transaction) + // Exit the loop and wait for more data to become available + break; + } + } + +} + +bool +VMManagerClientSocket::IPCConnect(const QString &server) +{ + server_name = server; + connect(socket, &QLocalSocket::connected, this, &VMManagerClientSocket::connected); + connect(socket, &QLocalSocket::disconnected, this, &VMManagerClientSocket::disconnected); + connect(socket, &QLocalSocket::errorOccurred, this, &VMManagerClientSocket::connectionError); + connect(socket, &QLocalSocket::readyRead, this, &VMManagerClientSocket::dataReady); + + socket->connectToServer(server_name); + + if(!socket->isValid()) { + qInfo("Could not connect to server: %s", qPrintable(socket->errorString())); + return false; + } + + qInfo("Connection Successful"); + return true; +} + +void +VMManagerClientSocket::connected() const +{ + // TODO: signal + qDebug("Connected to %s", qPrintable(server_name)); +} + +void +VMManagerClientSocket::disconnected() const +{ + // TODO: signal + qDebug("Disconnected from %s", qPrintable(server_name)); +} + +void +VMManagerClientSocket::sendMessage(const VMManagerProtocol::ClientMessage protocol_message) const +{ + sendMessageFull(protocol_message, QStringList(), QJsonObject()); +} + +void +VMManagerClientSocket::sendMessageWithList(const VMManagerProtocol::ClientMessage protocol_message, const QStringList &list) const +{ + sendMessageFull(protocol_message, list, QJsonObject()); +} + +void +VMManagerClientSocket::sendMessageWithObject(const VMManagerProtocol::ClientMessage protocol_message, const QJsonObject &json) const +{ + sendMessageFull(protocol_message, QStringList(), json); +} + +void +VMManagerClientSocket::sendMessageFull(const VMManagerProtocol::ClientMessage protocol_message, const QStringList &list, const QJsonObject &json) const +{ + QDataStream clientStream(socket); + clientStream.setVersion(QDataStream::Qt_5_7); + auto packet = new VMManagerProtocol(VMManagerProtocol::Sender::Client); + auto jsonMessage = packet->protocolClientMessage(protocol_message); + if (!list.isEmpty()) { + jsonMessage["list"] = QJsonArray::fromStringList(list); + } + // TODO: Add the logic for including objects + if(!json.isEmpty()) { + jsonMessage["params"] = json; + } + clientStream << QJsonDocument(jsonMessage).toJson(QJsonDocument::Compact); +} + +void +VMManagerClientSocket::jsonReceived(const QJsonObject &json) +{ + // The serialization portion has already validated the message as json. + // Ensure it has the required fields + if (!VMManagerProtocol::hasRequiredFields(json)) { + // TODO: Error handling of some sort, emit signals + qDebug("Invalid message received from client: required fields missing. Object:"); + qDebug() << json; + return; + } + // qDebug() << Q_FUNC_INFO << json; + + // Parsing happens here. When adding new types, make sure to first add them + // to VMManagerProtocol::ManagerMessage and then add it to the list here. + // If a signal needs to be emitted, add that as well and connect to slots + // as appropriate. + + switch (VMManagerProtocol::getManagerMessageType(json)) { + case VMManagerProtocol::ManagerMessage::Pause: + qDebug("Pause command received from manager"); + emit pause(); + break; + case VMManagerProtocol::ManagerMessage::ResetVM: + qDebug("Reset VM command received from manager"); + emit resetVM(); + break; + case VMManagerProtocol::ManagerMessage::ShowSettings: + qDebug("Show settings command received from manager"); + emit showsettings(); + break; + case VMManagerProtocol::ManagerMessage::CtrlAltDel: + qDebug("CtrlAltDel command received from manager"); + emit ctrlaltdel(); + break; + case VMManagerProtocol::ManagerMessage::RequestShutdown: + qDebug("RequestShutdown command received from manager"); + emit request_shutdown(); + break; + case VMManagerProtocol::ManagerMessage::ForceShutdown: + qDebug("ForceShutdown command received from manager"); + emit force_shutdown(); + break; + case VMManagerProtocol::ManagerMessage::RequestStatus: + qDebug("Status request command received from manager"); + break; + default: + qDebug("Unknown client message type received:"); + qDebug() << json; + break; + } +} + +void +VMManagerClientSocket::connectionError(const QLocalSocket::LocalSocketError socketError) +{ + qInfo("A connection error has occurred: "); + switch (socketError) { + case QLocalSocket::ServerNotFoundError: + qInfo("Server not found"); + break; + case QLocalSocket::ConnectionRefusedError: + qInfo("Connection refused"); + break; + case QLocalSocket::PeerClosedError: + qInfo("Peer closed"); + break; + default: + qInfo() << "QLocalSocket::LocalSocketError " << socketError; + break; + } +} + +bool +VMManagerClientSocket::eventFilter(QObject *obj, QEvent *event) +{ + if (socket->state() == QLocalSocket::ConnectedState) { + VMManagerProtocol::RunningState running_state; + if (event->type() == QEvent::WindowBlocked) { + running_state = dopause ? VMManagerProtocol::RunningState::PausedWaiting : VMManagerProtocol::RunningState::RunningWaiting; + clientRunningStateChanged(running_state); + } else if (event->type() == QEvent::WindowUnblocked) { + running_state = dopause ? VMManagerProtocol::RunningState::Paused : VMManagerProtocol::RunningState::Running; + clientRunningStateChanged(running_state); + } + } + return QObject::eventFilter(obj, event); +} + +void +VMManagerClientSocket::clientRunningStateChanged(VMManagerProtocol::RunningState state) const +{ + QJsonObject extra_object; + extra_object["status"] = static_cast(state); + sendMessageWithObject(VMManagerProtocol::ClientMessage::RunningStateChanged, extra_object); + +} diff --git a/src/qt/qt_vmmanager_clientsocket.hpp b/src/qt/qt_vmmanager_clientsocket.hpp new file mode 100644 index 000000000..10a053347 --- /dev/null +++ b/src/qt/qt_vmmanager_clientsocket.hpp @@ -0,0 +1,71 @@ +/* +* 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. +* +* Header file for 86Box VM manager client socket module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#ifndef QT_VMMANAGER_CLIENTSOCKET_HPP +#define QT_VMMANAGER_CLIENTSOCKET_HPP + +#include "qt_vmmanager_protocol.hpp" +#include +#include +#include +#include + +class VMManagerClientSocket final : public QObject { + Q_OBJECT + +public: + explicit VMManagerClientSocket(QObject* object = nullptr); + bool IPCConnect(const QString &server); + +signals: + void pause(); + void ctrlaltdel(); + void showsettings(); + void resetVM(); + void request_shutdown(); + void force_shutdown(); + void dialogstatus(bool open); + +public slots: + void clientRunningStateChanged(VMManagerProtocol::RunningState state) const; + +private: + QString server_name; + QLocalSocket *socket; + bool server_connected; + void connected() const; + void disconnected() const; + static void connectionError(QLocalSocket::LocalSocketError socketError); + + // Main convenience send function + void sendMessage(VMManagerProtocol::ClientMessage protocol_message) const; + // Send message with optional params array convenience function + void sendMessageWithList(VMManagerProtocol::ClientMessage protocol_message, const QStringList &list) const; + // Send message with optional json object convenience function + void sendMessageWithObject(VMManagerProtocol::ClientMessage protocol_message, const QJsonObject &json) const; + // Full send message function called by all convenience functions + void sendMessageFull(VMManagerProtocol::ClientMessage protocol_message, const QStringList &list, const QJsonObject &json) const; + void jsonReceived(const QJsonObject &json); + + void dataReady(); + +protected: + bool eventFilter(QObject *obj, QEvent *event) override; + +}; + +#endif // QT_VMMANAGER_CLIENTSOCKET_HPP diff --git a/src/qt/qt_vmmanager_config.cpp b/src/qt/qt_vmmanager_config.cpp new file mode 100644 index 000000000..08bf4e7c4 --- /dev/null +++ b/src/qt/qt_vmmanager_config.cpp @@ -0,0 +1,76 @@ +/* +* 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. +* +* 86Box VM manager configuration module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#include +#include +#include "qt_vmmanager_config.hpp" + +extern "C" { +#include <86box/plat.h> +} + +VMManagerConfig::VMManagerConfig(const ConfigType type, const QString& section) +{ + char BUF[256]; + plat_get_global_config_dir(BUF, 255); + const auto configDir = QString(BUF); + const auto configFile = QDir::cleanPath(configDir + "/" + "vmm.ini"); + + config_type = type; + + settings = new QSettings(configFile, QSettings::IniFormat, this); + settings->setFallbacksEnabled(false); + if(type == ConfigType::System && !section.isEmpty()) { + settings->beginGroup(section); + } +} + +VMManagerConfig::~VMManagerConfig() { + settings->endGroup(); +} + +QString +VMManagerConfig::getStringValue(const QString& key) const +{ + const auto value = settings->value(key); + // An invalid QVariant with toString will give a default QString value which is blank. + // Therefore any variables that do not exist will return blank strings + return value.toString(); +} + +void +VMManagerConfig::setStringValue(const QString &key, const QString &value) const +{ + if (value.isEmpty()) { + remove(key); + return; + } + settings->setValue(key, value); +} + +void +VMManagerConfig::remove(const QString &key) const +{ + settings->remove(key); +} + +void +VMManagerConfig::sync() const +{ + settings->sync(); +} + diff --git a/src/qt/qt_vmmanager_config.hpp b/src/qt/qt_vmmanager_config.hpp new file mode 100644 index 000000000..bc63aaa03 --- /dev/null +++ b/src/qt/qt_vmmanager_config.hpp @@ -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. +* +* Header for the 86Box VM manager configuration module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#ifndef QT_VMMANAGER_CONFIG_H +#define QT_VMMANAGER_CONFIG_H + +#include + +class VMManagerConfig : QObject { + Q_OBJECT + +public: + enum class ConfigType { + General, + System, + }; + Q_ENUM(ConfigType); + + explicit VMManagerConfig(ConfigType type, const QString& section = {}); + ~VMManagerConfig() override; + [[nodiscard]] QString getStringValue(const QString& key) const; + void setStringValue(const QString& key, const QString& value) const; + void remove(const QString &key) const; + + void sync() const; + + QSettings *settings; + ConfigType config_type; + QString system_name; +}; + +#endif // QT_VMMANAGER_CONFIG_H \ No newline at end of file diff --git a/src/qt/qt_vmmanager_details.cpp b/src/qt/qt_vmmanager_details.cpp new file mode 100644 index 000000000..a834e35f8 --- /dev/null +++ b/src/qt/qt_vmmanager_details.cpp @@ -0,0 +1,400 @@ +/* +* 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. +* +* 86Box VM manager system details module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#include +#include +#include + +#include "qt_vmmanager_details.hpp" +#include "ui_qt_vmmanager_details.h" + +#ifdef Q_OS_WINDOWS +extern bool windows_is_light_theme(); +#endif + +using namespace VMManager; + +VMManagerDetails::VMManagerDetails(QWidget *parent) : + QWidget(parent), ui(new Ui::VMManagerDetails) { + ui->setupUi(this); + + const auto leftColumnLayout = qobject_cast(ui->leftColumn->layout()); + + // Each section here gets its own VMManagerDetailSection, named in the constructor. + // When a system is selected in the list view it is updated through this object + // See updateData() for the implementation + + systemSection = new VMManagerDetailSection(tr("System", "Header for System section in VM Manager Details")); + ui->leftColumn->layout()->addWidget(systemSection); + // These horizontal lines are used for the alternate layout which may possibly + // be a preference one day. + // ui->leftColumn->layout()->addWidget(createHorizontalLine()); + + videoSection = new VMManagerDetailSection(tr("Display", "Header for Display section in VM Manager Details")); + ui->leftColumn->layout()->addWidget(videoSection); + // ui->leftColumn->layout()->addWidget(createHorizontalLine()); + + storageSection = new VMManagerDetailSection(tr("Storage", "Header for Storage section in VM Manager Details")); + ui->leftColumn->layout()->addWidget(storageSection); + // ui->leftColumn->layout()->addWidget(createHorizontalLine()); + + audioSection = new VMManagerDetailSection(tr("Audio", "Header for Audio section in VM Manager Details")); + ui->leftColumn->layout()->addWidget(audioSection); + // ui->leftColumn->layout()->addWidget(createHorizontalLine()); + + networkSection = new VMManagerDetailSection(tr("Network", "Header for Network section in VM Manager Details")); + ui->leftColumn->layout()->addWidget(networkSection); + // ui->leftColumn->layout()->addWidget(createHorizontalLine()); + + inputSection = new VMManagerDetailSection(tr("Input Devices", "Header for Input section in VM Manager Details")); + ui->leftColumn->layout()->addWidget(inputSection); + // ui->leftColumn->layout()->addWidget(createHorizontalLine()); + + portsSection = new VMManagerDetailSection(tr("Ports", "Header for Input section in VM Manager Details")); + ui->leftColumn->layout()->addWidget(portsSection); + + // This is like adding a spacer + leftColumnLayout->addStretch(); + + // Event filter for the notes to save when it loses focus + ui->notesTextEdit->installEventFilter(this); + + // Default screenshot label and thumbnail (image inside the label) sizes + screenshotThumbnailSize = QSize(240, 160); + + // Set the icons for the screenshot navigation buttons + ui->screenshotNext->setIcon(QApplication::style()->standardIcon(QStyle::SP_ArrowRight)); + ui->screenshotPrevious->setIcon(QApplication::style()->standardIcon(QStyle::SP_ArrowLeft)); + ui->screenshotNextTB->setIcon(QApplication::style()->standardIcon(QStyle::SP_ArrowRight)); + ui->screenshotPreviousTB->setIcon(QApplication::style()->standardIcon(QStyle::SP_ArrowLeft)); + // Disabled by default + ui->screenshotNext->setEnabled(false); + ui->screenshotPrevious->setEnabled(false); + ui->screenshotNextTB->setEnabled(false); + ui->screenshotPreviousTB->setEnabled(false); + // Connect their signals + connect(ui->screenshotNext, &QPushButton::clicked, this, &VMManagerDetails::nextScreenshot); + connect(ui->screenshotNextTB, &QToolButton::clicked, this, &VMManagerDetails::nextScreenshot); + connect(ui->screenshotPreviousTB, &QToolButton::clicked, this, &VMManagerDetails::previousScreenshot); + connect(ui->screenshotPrevious, &QPushButton::clicked, this, &VMManagerDetails::previousScreenshot); + // These push buttons can be taken out if the tool buttons stay + ui->screenshotNext->setVisible(false); + ui->screenshotPrevious->setVisible(false); + QString toolButtonStyleSheet; + // Simple method to try and determine if light mode is enabled +#ifdef Q_OS_WINDOWS + const bool lightMode = windows_is_light_theme(); +#else + const bool lightMode = QApplication::palette().window().color().value() > QApplication::palette().windowText().color().value(); +#endif + if (lightMode) { + toolButtonStyleSheet = "QToolButton {background: transparent; border: none; padding: 5px} QToolButton:hover {background: palette(midlight)} QToolButton:pressed {background: palette(mid)}"; + } else { +#ifndef Q_OS_WINDOWS + toolButtonStyleSheet = "QToolButton {background: transparent; border: none; padding: 5px} QToolButton:hover {background: palette(dark)} QToolButton:pressed {background: palette(mid)}"; +#else + toolButtonStyleSheet = "QToolButton {padding: 5px}"; +#endif + } + ui->ssNavTBHolder->setStyleSheet(toolButtonStyleSheet); + + // Experimenting + startPauseButton = new QToolButton(); + startPauseButton->setIcon(QIcon(":/menuicons/qt/icons/run.ico")); + startPauseButton->setAutoRaise(true); + startPauseButton->setEnabled(false); + startPauseButton->setToolTip(tr("Start")); + ui->toolButtonHolder->setStyleSheet(toolButtonStyleSheet); + resetButton = new QToolButton(); + resetButton->setIcon(QIcon(":/menuicons/qt/icons/hard_reset.ico")); + resetButton->setEnabled(false); + resetButton->setToolTip(tr("Hard reset")); + stopButton = new QToolButton(); + stopButton->setIcon(QIcon(":/menuicons/qt/icons/acpi_shutdown.ico")); + stopButton->setEnabled(false); + stopButton->setToolTip(tr("Force shutdown")); + configureButton = new QToolButton(); + configureButton->setIcon(QIcon(":/menuicons/qt/icons/settings.ico")); + configureButton->setEnabled(false); + configureButton->setToolTip(tr("Settings...")); + cadButton = new QToolButton(); + cadButton->setIcon(QIcon(":menuicons/qt/icons/send_cad.ico")); + cadButton->setEnabled(false); + cadButton->setToolTip(tr("Ctrl+Alt+Del")); + + ui->toolButtonHolder->layout()->addWidget(configureButton); + ui->toolButtonHolder->layout()->addWidget(resetButton); + ui->toolButtonHolder->layout()->addWidget(stopButton); + ui->toolButtonHolder->layout()->addWidget(startPauseButton); + ui->toolButtonHolder->layout()->addWidget(cadButton); + + ui->notesTextEdit->setEnabled(false); + + sysconfig = new VMManagerSystem(); +} + +VMManagerDetails::~VMManagerDetails() { + delete ui; +} + +void +VMManagerDetails::updateData(VMManagerSystem *passed_sysconfig) { + + // Set the scrollarea background but also set the scroll bar to none. Otherwise it will also + // set the scrollbar background to the same. +#ifdef Q_OS_WINDOWS + extern bool windows_is_light_theme(); + if (windows_is_light_theme()) +#endif + { + ui->scrollArea->setStyleSheet("QWidget {background-color: palette(light)} QScrollBar{ background-color: none }"); + ui->systemLabel->setStyleSheet("background-color: palette(midlight);"); + } + // Margins are a little different on macos +#ifdef Q_OS_MACOS + ui->systemLabel->setMargin(15); +#else + ui->systemLabel->setMargin(10); +#endif + + // disconnect old signals before assigning the passed systemconfig object + disconnect(startPauseButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::startButtonPressed); + disconnect(startPauseButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::pauseButtonPressed); + disconnect(resetButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::restartButtonPressed); + disconnect(stopButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::shutdownForceButtonPressed); + disconnect(configureButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::launchSettings); + disconnect(cadButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::cadButtonPressed); + + sysconfig = passed_sysconfig; + connect(resetButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::restartButtonPressed); + connect(stopButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::shutdownForceButtonPressed); + connect(configureButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::launchSettings); + connect(cadButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::cadButtonPressed); + cadButton->setEnabled(true); + + bool running = sysconfig->getProcessStatus() == VMManagerSystem::ProcessStatus::Running || + sysconfig->getProcessStatus() == VMManagerSystem::ProcessStatus::RunningWaiting; + if(running) { + startPauseButton->setIcon(QIcon(":/menuicons/qt/icons/pause.ico")); + connect(startPauseButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::pauseButtonPressed); + } else { + startPauseButton->setIcon(QIcon(":/menuicons/qt/icons/run.ico")); + connect(startPauseButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::startButtonPressed); + } + startPauseButton->setEnabled(true); + configureButton->setEnabled(true); + + // Each detail section here has its own VMManagerDetailSection. + // When a system is selected in the list view it is updated here, through this object: + // * First you clear it with VMManagerDetailSection::clear() + // * Then you add each line with VMManagerDetailSection::addSection() + + // System + systemSection->clear(); + systemSection->addSection("Machine", passed_sysconfig->getDisplayValue(Display::Name::Machine)); + systemSection->addSection("CPU", passed_sysconfig->getDisplayValue(Display::Name::CPU)); + systemSection->addSection("Memory", passed_sysconfig->getDisplayValue(Display::Name::Memory)); + + // Video + videoSection->clear(); + videoSection->addSection("Video", passed_sysconfig->getDisplayValue(Display::Name::Video)); + if(!passed_sysconfig->getDisplayValue(Display::Name::Voodoo).isEmpty()) { + videoSection->addSection("Voodoo", passed_sysconfig->getDisplayValue(Display::Name::Voodoo)); + } + + // Disks + storageSection->clear(); + storageSection->addSection("Disks", passed_sysconfig->getDisplayValue(Display::Name::Disks)); + storageSection->addSection("Floppy", passed_sysconfig->getDisplayValue(Display::Name::Floppy)); + storageSection->addSection("CD-ROM", passed_sysconfig->getDisplayValue(Display::Name::CD)); + storageSection->addSection("SCSI", passed_sysconfig->getDisplayValue(Display::Name::SCSIController)); + + // Audio + audioSection->clear(); + audioSection->addSection("Audio", passed_sysconfig->getDisplayValue(Display::Name::Audio)); + audioSection->addSection("MIDI Out", passed_sysconfig->getDisplayValue(Display::Name::MidiOut)); + + // Network + networkSection->clear(); + networkSection->addSection("NIC", passed_sysconfig->getDisplayValue(Display::Name::NIC)); + + // Input + inputSection->clear(); + inputSection->addSection(tr("Mouse"), passed_sysconfig->getDisplayValue(Display::Name::Mouse)); + inputSection->addSection(tr("Joystick"), passed_sysconfig->getDisplayValue(Display::Name::Joystick)); + + // Ports + portsSection->clear(); + portsSection->addSection(tr("Serial Ports"), passed_sysconfig->getDisplayValue(Display::Name::Serial)); + portsSection->addSection(tr("Parallel Ports"), passed_sysconfig->getDisplayValue(Display::Name::Parallel)); + + // Disable screenshot navigation buttons by default + ui->screenshotNext->setEnabled(false); + ui->screenshotPrevious->setEnabled(false); + ui->screenshotNextTB->setEnabled(false); + ui->screenshotPreviousTB->setEnabled(false); + + // Different actions are taken depending on the existence and number of screenshots + screenshots = passed_sysconfig->getScreenshots(); + if (!screenshots.empty()) { + ui->screenshot->setFrameStyle(QFrame::NoFrame); + ui->screenshot->setEnabled(true); + if(screenshots.size() > 1) { + ui->screenshotNext->setEnabled(true); + ui->screenshotPrevious->setEnabled(true); + ui->screenshotNextTB->setEnabled(true); + ui->screenshotPreviousTB->setEnabled(true); + } +#ifdef Q_OS_WINDOWS + ui->screenshot->setStyleSheet(""); +#endif + if(QFileInfo::exists(screenshots.last().filePath())) { + screenshotIndex = screenshots.size() - 1; + const QPixmap pic(screenshots.at(screenshotIndex).filePath()); + ui->screenshot->setPixmap(pic.scaled(240, 160, Qt::KeepAspectRatio, Qt::SmoothTransformation)); + } + } else { + ui->screenshotNext->setEnabled(false); + ui->screenshotPrevious->setEnabled(false); + ui->screenshotNextTB->setEnabled(false); + ui->screenshotPreviousTB->setEnabled(false); + ui->screenshot->setPixmap(QString()); + ui->screenshot->setFixedSize(240, 160); + ui->screenshot->setFrameStyle(QFrame::Box | QFrame::Sunken); + ui->screenshot->setText(tr("No screenshot")); + ui->screenshot->setEnabled(false); + ui->screenshot->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); +#ifdef Q_OS_WINDOWS + if (!windows_is_light_theme()) { + ui->screenshot->setStyleSheet("QLabel { border: 1px solid gray }"); + } else { + ui->screenshot->setStyleSheet(""); + } +#endif + } + + ui->systemLabel->setText(passed_sysconfig->displayName); + ui->statusLabel->setText(sysconfig->process->processId() == 0 ? + tr("Not running") : + QString("%1: PID %2").arg(tr("Running"), QString::number(sysconfig->process->processId()))); + ui->notesTextEdit->setPlainText(passed_sysconfig->notes); + ui->notesTextEdit->setEnabled(true); + + disconnect(sysconfig->process, &QProcess::stateChanged, this, &VMManagerDetails::updateProcessStatus); + connect(sysconfig->process, &QProcess::stateChanged, this, &VMManagerDetails::updateProcessStatus); + + disconnect(sysconfig, &VMManagerSystem::windowStatusChanged, this, &VMManagerDetails::updateWindowStatus); + connect(sysconfig, &VMManagerSystem::windowStatusChanged, this, &VMManagerDetails::updateWindowStatus); + + disconnect(sysconfig, &VMManagerSystem::clientProcessStatusChanged, this, &VMManagerDetails::updateProcessStatus); + connect(sysconfig, &VMManagerSystem::clientProcessStatusChanged, this, &VMManagerDetails::updateProcessStatus); + + updateProcessStatus(); +} + +void +VMManagerDetails::updateProcessStatus() { + const bool running = sysconfig->process->state() == QProcess::ProcessState::Running; + QString status_text = running ? + QString("%1: PID %2").arg(tr("Running"), QString::number(sysconfig->process->processId())) : + tr("Not running"); + status_text.append(sysconfig->window_obscured ? QString(" (%1)").arg(tr("waiting")) : ""); + ui->statusLabel->setText(status_text); + resetButton->setEnabled(running); + stopButton->setEnabled(running); + cadButton->setEnabled(running); + if(running) { + if(sysconfig->getProcessStatus() == VMManagerSystem::ProcessStatus::Running) { + startPauseButton->setIcon(QIcon(":/menuicons/qt/icons/pause.ico")); + startPauseButton->setToolTip(tr("Pause")); + } else { + startPauseButton->setIcon(QIcon(":/menuicons/qt/icons/run.ico")); + startPauseButton->setToolTip(tr("Continue")); + } + + disconnect(startPauseButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::pauseButtonPressed); + disconnect(startPauseButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::startButtonPressed); + connect(startPauseButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::pauseButtonPressed); + } else { + startPauseButton->setIcon(QIcon(":/menuicons/qt/icons/run.ico")); + disconnect(startPauseButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::pauseButtonPressed); + disconnect(startPauseButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::startButtonPressed); + connect(startPauseButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::startButtonPressed); + startPauseButton->setToolTip(tr("Start")); + } +} + +void +VMManagerDetails::updateWindowStatus() +{ + qInfo("Window status changed: %i", sysconfig->window_obscured); + updateProcessStatus(); +} + +QWidget * +VMManagerDetails::createHorizontalLine(const int leftSpacing, const int rightSpacing) +{ + const auto container = new QWidget; + const auto hLayout = new QHBoxLayout(container); + + hLayout->addSpacing(leftSpacing); + + const auto line = new QFrame(); + line->setFrameShape(QFrame::HLine); + line->setFrameShadow(QFrame::Sunken); + + hLayout->addWidget(line); + hLayout->addSpacing(rightSpacing); + hLayout->setContentsMargins(0, 5, 0, 5); + + return container; +} + +void +VMManagerDetails::saveNotes() const +{ + sysconfig->setNotes(ui->notesTextEdit->toPlainText()); +} + +void +VMManagerDetails::nextScreenshot() +{ + screenshotIndex = (screenshotIndex + 1) % screenshots.size(); + const QPixmap pic(screenshots.at(screenshotIndex).filePath()); + ui->screenshot->setPixmap(pic.scaled(240, 160, Qt::KeepAspectRatio, Qt::SmoothTransformation)); +} + +void +VMManagerDetails::previousScreenshot() +{ + screenshotIndex = screenshotIndex == 0 ? screenshots.size() - 1 : screenshotIndex - 1; + const QPixmap pic(screenshots.at(screenshotIndex).filePath()); + ui->screenshot->setPixmap(pic.scaled(240, 160, Qt::KeepAspectRatio, Qt::SmoothTransformation)); +} + +bool +VMManagerDetails::eventFilter(QObject *watched, QEvent *event) +{ + if (watched->isWidgetType() && event->type() == QEvent::FocusOut) { + // Make sure it's the textedit + if (const auto *textEdit = qobject_cast(watched); textEdit) { + saveNotes(); + } + } + return QWidget::eventFilter(watched, event); +} + diff --git a/src/qt/qt_vmmanager_details.hpp b/src/qt/qt_vmmanager_details.hpp new file mode 100644 index 000000000..5d3bfa8a4 --- /dev/null +++ b/src/qt/qt_vmmanager_details.hpp @@ -0,0 +1,90 @@ +/* +* 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. +* +* Header for 86Box VM manager system details module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#ifndef QT_VMMANAGER_DETAILS_H +#define QT_VMMANAGER_DETAILS_H + +#include +#include "qt_vmmanager_system.hpp" +// #include "qt_vmmanager_details_section.hpp" +#include "qt_vmmanager_detailsection.hpp" + + +QT_BEGIN_NAMESPACE +//namespace Ui { class VMManagerDetails; class CollapseButton;} +namespace Ui { class VMManagerDetails;} +QT_END_NAMESPACE + +class VMManagerDetails : public QWidget { + Q_OBJECT + +public: + explicit VMManagerDetails(QWidget *parent = nullptr); + + ~VMManagerDetails() override; + + void updateData(VMManagerSystem *passed_sysconfig); + + void updateProcessStatus(); + + void updateWindowStatus(); +// CollapseButton *systemCollapseButton; + +private: + Ui::VMManagerDetails *ui; + VMManagerSystem *sysconfig; + + VMManagerDetailSection *systemSection; + VMManagerDetailSection *videoSection; + VMManagerDetailSection *storageSection; + VMManagerDetailSection *audioSection; + VMManagerDetailSection *networkSection; + VMManagerDetailSection *inputSection; + VMManagerDetailSection *portsSection; + + QFileInfoList screenshots; + int screenshotIndex = 0; + QSize screenshotLabelSize; + QSize screenshotThumbnailSize; + + QToolButton *startPauseButton; + QToolButton *resetButton; + QToolButton *stopButton; + QToolButton *configureButton; + QToolButton *cadButton; + + static QWidget* createHorizontalLine(int leftSpacing = 25, int rightSpacing = 25); + // QVBoxLayout *detailsLayout; +private slots: + void saveNotes() const; + void nextScreenshot(); + void previousScreenshot(); + +protected: + bool eventFilter(QObject *watched, QEvent *event) override; + +// CollapseButton *systemCollapseButton; +// QFrame *systemFrame; +// CollapseButton *displayCollapseButton; +// QFrame *displayFrame; +// CollapseButton *storageCollapseButton; +// QFrame *storageFrame; +}; + + + +#endif //QT_VMMANAGER_DETAILS_H diff --git a/src/qt/qt_vmmanager_details.ui b/src/qt/qt_vmmanager_details.ui new file mode 100644 index 000000000..9b4fbbe8b --- /dev/null +++ b/src/qt/qt_vmmanager_details.ui @@ -0,0 +1,293 @@ + + + VMManagerDetails + + + + 0 + 0 + 497 + 444 + + + + VMManagerDetails + + + + 0 + + + 0 + + + + + + 18 + + + + No Machines Found! + + + Qt::AlignCenter + + + + + + + + 0 + + + 0 + + + + + QFrame::StyledPanel + + + true + + + + + 0 + 0 + 139 + 388 + + + + + 0 + + + 12 + + + 12 + + + 12 + + + 12 + + + + + + + + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 240 + 160 + + + + + 240 + 160 + + + + + + + Qt::AlignCenter + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + + + false + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + ... + + + + + + + ... + + + true + + + + + + + + + + + 0 + 0 + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Type some notes here + + + + + + + Qt::Vertical + + + + 20 + 0 + + + + + + + + + 0 + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + Qt::AlignCenter + + + + + + + + + + + + + + diff --git a/src/qt/qt_vmmanager_detailsection.cpp b/src/qt/qt_vmmanager_detailsection.cpp new file mode 100644 index 000000000..ce42ae281 --- /dev/null +++ b/src/qt/qt_vmmanager_detailsection.cpp @@ -0,0 +1,309 @@ +/* +* 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. +* +* 86Box VM manager system details section module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#include "qt_vmmanager_detailsection.hpp" +#include "ui_qt_vmmanager_detailsection.h" + +#include + +const QString VMManagerDetailSection::sectionSeparator = ";"; +using namespace VMManager; + +VMManagerDetailSection:: +VMManagerDetailSection(const QString §ionName) + : mainLayout(new QVBoxLayout()) + , buttonLayout(new QHBoxLayout()) + , frame(new QFrame()) + , ui(new Ui::DetailSection) +{ + ui->setupUi(this); + + frameGridLayout = new QGridLayout(); + // Create the collapse button, set the name and add it to the layout + collapseButton = new CollapseButton(); + setSectionName(sectionName); + ui->collapseButtonHolder->setContentsMargins(getMargins(MarginSection::ToolButton)); + + // Simple method to try and determine if light mode is enabled on the host +#ifdef Q_OS_WINDOWS + extern bool windows_is_light_theme(); + const bool lightMode = windows_is_light_theme(); +#else + const bool lightMode = QApplication::palette().window().color().value() > QApplication::palette().windowText().color().value(); +#endif + // Alternate layout + if ( lightMode) { + ui->collapseButtonHolder->setStyleSheet("background-color: palette(midlight);"); + } else { +#ifdef Q_OS_WINDOWS + ui->outerFrame->setStyleSheet("background-color: #272727;"); + ui->collapseButtonHolder->setStyleSheet("background-color: #616161;"); +#else + ui->collapseButtonHolder->setStyleSheet("background-color: palette(mid);"); +#endif + } + const auto sectionLabel = new QLabel(sectionName); + sectionLabel->setStyleSheet(sectionLabel->styleSheet().append("font-weight: bold;")); + ui->collapseButtonHolder->setContentsMargins(QMargins(3, 2, 0, 2)); + ui->collapseButtonHolder->layout()->addWidget(sectionLabel); + + // ui->collapseButtonHolder->layout()->addWidget(collapseButton); + collapseButton->setContent(ui->detailFrame); + // Horizontal line added after the section name / button + // const auto hLine = new QFrame(); + // hLine->setFrameShape(QFrame::HLine); + // hLine->setFrameShadow(QFrame::Sunken); + // hLine->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); + // ui->collapseButtonHolder->layout()->addWidget(hLine); + const auto hSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); + ui->collapseButtonHolder->layout()->addItem(hSpacer); + // collapseButton->setContent(frame); + // ui->sectionName->setVisible(false); + setVisible(false); +} + +VMManagerDetailSection:: +VMManagerDetailSection(const QVariant &varSectionName) : ui(new Ui::DetailSection) +{ + const auto sectionName = varSectionName.toString(); + + // Initialize even though they will get wiped out + // (to keep clang-tidy happy) + frameGridLayout = new QGridLayout(); + const auto outerFrame = new QFrame(); + // for the CSS + outerFrame->setObjectName("outer_frame"); + outerFrame->setContentsMargins(QMargins(0, 0, 0, 0)); + const auto innerFrameLayout = new QVBoxLayout(); + + outerFrame->setLayout(innerFrameLayout); + auto *outerFrameLayout = new QVBoxLayout(); + outerFrameLayout->addWidget(outerFrame); + outerFrameLayout->setContentsMargins(QMargins(0, 0, 0, 0)); + + const auto buttonWidget = new QWidget(this); + + mainLayout = new QVBoxLayout(); + buttonLayout = new QHBoxLayout(); + buttonWidget->setLayout(buttonLayout); + + collapseButton = new CollapseButton(); + setSectionName(sectionName); + buttonLayout->setContentsMargins(getMargins(MarginSection::ToolButton)); + buttonLayout->addWidget(collapseButton); + + // buttonLayout->addStretch(); + auto *hLine = new QFrame(); + hLine->setFrameShape(QFrame::HLine); + hLine->setFrameShadow(QFrame::Sunken); + hLine->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); + buttonLayout->addWidget(hLine); + + mainLayout->addLayout(buttonLayout); + + frame = new QFrame(); + frame->setFrameShape(QFrame::Box); + frame->setFrameStyle(QFrame::NoFrame); + collapseButton->setContent(frame); + + mainLayout->addWidget(frame); + innerFrameLayout->addWidget(buttonWidget); + innerFrameLayout->addWidget(frame); + setLayout(outerFrameLayout); +} + +VMManagerDetailSection::~VMManagerDetailSection() += default; + +void +VMManagerDetailSection::setSectionName(const QString &name) +{ + sectionName = name; + collapseButton->setButtonText(" " + sectionName); + // Bold the section headers + collapseButton->setStyleSheet(collapseButton->styleSheet().append("font-weight: bold;")); +} + +void +VMManagerDetailSection::addSection(const QString &name, const QString &value, Display::Name displayField) +{ + const auto new_section = DetailSection { name, value}; + sections.push_back(new_section); + setSections(); +} + +void +VMManagerDetailSection::setupMainLayout() +{ + // clang-tidy says I don't need to check before deleting + delete mainLayout; + mainLayout = new QVBoxLayout; +} +void +VMManagerDetailSection::clearContentsSetupGrid() +{ + // Clear everything out + if(frameGridLayout) { + while(frameGridLayout->count()) { + QLayoutItem * cur_item = frameGridLayout->takeAt(0); + if(cur_item->widget()) + delete cur_item->widget(); + delete cur_item; + } + } + + delete frameGridLayout; + frameGridLayout = new QGridLayout(); + qint32 *left = nullptr, *top = nullptr, *right = nullptr, *bottom = nullptr; + frameGridLayout->getContentsMargins(left, top, right, bottom); + frameGridLayout->setContentsMargins(getMargins(MarginSection::DisplayGrid)); + ui->detailFrame->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); + ui->detailFrame->setLayout(frameGridLayout); +} +void +VMManagerDetailSection::setSections() +{ + clearContentsSetupGrid(); + int row = 0; + + + for ( const auto& section : sections) { + // if the string contains the separator (defined elsewhere) then split and + // add each entry on a new line. Otherwise, just add the one. + QStringList sectionsToAdd; + if(section.value.contains(sectionSeparator)) { + sectionsToAdd = section.value.split(sectionSeparator); + } else { + sectionsToAdd.push_back(section.value); + } + bool keyAdded = false; + for(const auto&line : sectionsToAdd) { + if(line.isEmpty()) { + // Don't bother adding entries if the values are blank + continue; + } + const auto labelKey = new QLabel(); + labelKey->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); + const auto labelValue = new QLabel(); + labelKey->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); + labelValue->setTextInteractionFlags(labelValue->textInteractionFlags() | Qt::TextSelectableByMouse); + labelKey->setTextInteractionFlags(labelValue->textInteractionFlags() | Qt::TextSelectableByMouse); + + // Reduce the text size for the label + // First, get the existing font + auto smaller_font = labelValue->font(); + // Get a smaller size + // Not sure if I like the smaller size, back to regular for now + // auto smaller_size = 0.85 * smaller_font.pointSize(); + const auto smaller_size = 1 * smaller_font.pointSize(); + // Set the font to the smaller size + smaller_font.setPointSizeF(smaller_size); + // Assign that new, smaller font to the label + labelKey->setFont(smaller_font); + labelValue->setFont(smaller_font); + + labelKey->setText(section.name + ":"); + labelValue->setText(line); + if(!keyAdded) { + frameGridLayout->addWidget(labelKey, row, 0, Qt::AlignLeft); + keyAdded = true; + } + frameGridLayout->addWidget(labelValue, row, 1, Qt::AlignLeft); + const auto hSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); + frameGridLayout->addItem(hSpacer, row, 2); + row++; + } + } + collapseButton->setContent(ui->detailFrame); + if (sections.size()) + setVisible(true); +} +void +VMManagerDetailSection::clear() +{ + sections.clear(); + setVisible(false); +} + +// QT for Linux and Windows doesn't have the same default margins as QT on MacOS. +// For consistency in appearance we'll have to return the margins on a per-OS basis +QMargins +VMManagerDetailSection::getMargins(const MarginSection section) +{ + switch (section) { + case MarginSection::ToolButton: +#if defined(Q_OS_WINDOWS) or defined(Q_OS_LINUX) + return {10, 0, 5, 0}; +#else + return {0, 0, 5, 0}; +#endif + case MarginSection::DisplayGrid: +#if defined(Q_OS_WINDOWS) or defined(Q_OS_LINUX) + return {10, 0, 0, 10}; +#else + return {0, 0, 0, 10}; +#endif + default: + return {}; + } +} + +// CollapseButton Class + +CollapseButton::CollapseButton(QWidget *parent) : QToolButton(parent), content_(nullptr) { + setCheckable(true); + setStyleSheet("background:none; border:none;"); + setIconSize(QSize(8, 8)); + setFont(QApplication::font()); + setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + connect(this, &QToolButton::toggled, [=](const bool checked) { + setArrowType(checked ? Qt::ArrowType::DownArrow : Qt::ArrowType::RightArrow); + content_ != nullptr && checked ? showContent() : hideContent(); + }); + setChecked(true); +} + +void CollapseButton::setButtonText(const QString &text) { + setText(" " + text); +} + +void CollapseButton::setContent(QWidget *content) { + assert(content != nullptr); + content_ = content; + const auto animation_ = new QPropertyAnimation(content_, "maximumHeight"); // QObject with auto delete + animation_->setStartValue(0); + animation_->setEasingCurve(QEasingCurve::InOutQuad); + animation_->setDuration(300); + animation_->setEndValue(content->geometry().height() + 50); + // qDebug() << "section" << text() << "has a height of" << content->geometry().height(); + animator_.clear(); + animator_.addAnimation(animation_); + if (!isChecked()) { + content->setMaximumHeight(0); + } +} + +void CollapseButton::hideContent() { + animator_.setDirection(QAbstractAnimation::Backward); + animator_.start(); +} + +void CollapseButton::showContent() { + animator_.setDirection(QAbstractAnimation::Forward); + animator_.start(); +} + diff --git a/src/qt/qt_vmmanager_detailsection.hpp b/src/qt/qt_vmmanager_detailsection.hpp new file mode 100644 index 000000000..7619a476c --- /dev/null +++ b/src/qt/qt_vmmanager_detailsection.hpp @@ -0,0 +1,101 @@ +/* +* 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. +* +* 86Box VM manager system details section module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed + */ + +#ifndef QT_VMMANAGER_DETAILSECTION_H +#define QT_VMMANAGER_DETAILSECTION_H + +#include +#include +#include +#include +#include +#include +#include "qt_vmmanager_system.hpp" + +QT_BEGIN_NAMESPACE +namespace Ui { class DetailSection; } +QT_END_NAMESPACE + +class CollapseButton final : public QToolButton { + Q_OBJECT + +public: + explicit CollapseButton(QWidget *parent = nullptr); + + void setButtonText(const QString &text); + + void setContent(QWidget *content); + + void hideContent(); + + void showContent(); + +private: + QWidget *content_; + QString text_; + QParallelAnimationGroup animator_; +}; + +class VMManagerDetailSection final : public QWidget { + Q_OBJECT + +public: + explicit VMManagerDetailSection(const QString §ionName); + explicit VMManagerDetailSection(const QVariant &varSectionName); + // explicit VMManagerDetailSection(); + + ~VMManagerDetailSection() override; + + void addSection(const QString &name, const QString &value, VMManager::Display::Name displayField = VMManager::Display::Name::Unknown); + void clear(); + + CollapseButton *collapseButton; +// QGridLayout *buttonGridLayout; + QGridLayout *frameGridLayout; + QVBoxLayout *mainLayout; + QHBoxLayout *buttonLayout; + QFrame *frame; + + static const QString sectionSeparator; + + +private: + enum class MarginSection { + ToolButton, + DisplayGrid, + }; + + void setSectionName(const QString &name); + void setupMainLayout(); + void clearContentsSetupGrid(); + void setSections(); + + static QMargins getMargins(MarginSection section); + + QString sectionName; + + struct DetailSection { + QString name; + QString value; + }; + + QVector sections; + Ui::DetailSection *ui; + +}; + +#endif // QT_VMMANAGER_DETAILSECTION_H diff --git a/src/qt/qt_vmmanager_detailsection.ui b/src/qt/qt_vmmanager_detailsection.ui new file mode 100644 index 000000000..18e89ee65 --- /dev/null +++ b/src/qt/qt_vmmanager_detailsection.ui @@ -0,0 +1,91 @@ + + + DetailSection + + + + 0 + 0 + 348 + 151 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + + + + + + + + diff --git a/src/qt/qt_vmmanager_listviewdelegate.cpp b/src/qt/qt_vmmanager_listviewdelegate.cpp new file mode 100644 index 000000000..28820a044 --- /dev/null +++ b/src/qt/qt_vmmanager_listviewdelegate.cpp @@ -0,0 +1,249 @@ +/* +* 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. +* +* 86Box VM manager list view delegate module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + + +#include + +#include "qt_vmmanager_listviewdelegate.hpp" +#include "qt_vmmanager_model.hpp" + +#ifdef Q_OS_WINDOWS +extern bool windows_is_light_theme(); +#endif + + +// Thanks to scopchanov https://github.com/scopchanov/SO-MessageLog +// from https://stackoverflow.com/questions/53105343/is-it-possible-to-add-a-custom-widget-into-a-qlistview + + +VMManagerListViewDelegate::VMManagerListViewDelegate(QObject *parent) + : QStyledItemDelegate(parent), + m_ptr(new VMManagerListViewDelegateStyle) +{ +} + +VMManagerListViewDelegate::~VMManagerListViewDelegate() += default; + +void VMManagerListViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const { + bool windows_light_mode = true; +#ifdef Q_OS_WINDOWS + windows_light_mode = windows_is_light_theme(); +#endif + QStyleOptionViewItem opt(option); + initStyleOption(&opt, index); + const QPalette &palette(opt.palette); + // opt.rect = opt.rect.adjusted(0, 0, 0, 20); + const QRect &rect(opt.rect); + const QRect &contentRect(rect.adjusted(m_ptr->margins.left(), + m_ptr->margins.top(), + -m_ptr->margins.right(), + -m_ptr->margins.bottom())); + + // The status icon represents the current state of the vm. Initially set to a default state. + QIcon status_icon = QApplication::style()->standardIcon(QStyle::SP_MediaStop); + auto process_variant = index.data(VMManagerModel::Roles::ProcessStatus); + auto process_status = process_variant.value(); + // The main icon, configurable. Falls back to default if it cannot be loaded. + auto customIcom = index.data(VMManagerModel::Roles::Icon).toString(); + opt.icon = QIcon(":/settings/qt/icons/86Box-gray.ico"); + if(!customIcom.isEmpty()) { + if (const auto customPixmap = QPixmap(customIcom); !customPixmap.isNull()) { + opt.icon = customPixmap; + } + } + // opt.icon = QIcon(":/settings/qt/icons/86Box-gray.ico"); + + // Set the status icon based on the process status + switch(process_status) { + case VMManagerSystem::ProcessStatus::Running: + status_icon = QIcon(":/menuicons/qt/icons/run.ico"); + break; + case VMManagerSystem::ProcessStatus::Stopped: + status_icon = QIcon(":/menuicons/qt/icons/acpi_shutdown.ico"); + break; + case VMManagerSystem::ProcessStatus::PausedWaiting: + case VMManagerSystem::ProcessStatus::RunningWaiting: + case VMManagerSystem::ProcessStatus::Paused: + status_icon = QIcon(":/menuicons/qt/icons/pause.ico"); + break; + default: + status_icon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxQuestion); + } + + + // Used to determine if the horizontal separator should be drawn + const bool lastIndex = (index.model()->rowCount() - 1) == index.row(); + const bool hasIcon = !opt.icon.isNull(); + const int bottomEdge = rect.bottom(); + QFont f(opt.font); + + f.setPointSizeF(m_ptr->statusFontPointSize(opt.font)); + + painter->save(); + painter->setClipping(true); + painter->setClipRect(rect); + painter->setFont(opt.font); + + // Draw the background + if (opt.state & QStyle::State_Selected) { + // When selected, only draw the highlighted part until the horizontal separator + int offset = 2; + auto highlightRect = rect.adjusted(0, 0, 0, -offset); + painter->fillRect(highlightRect, windows_light_mode ? palette.highlight().color() : QColor("#616161")); + // Then fill the remainder with the normal color + auto regularRect = rect.adjusted(0, rect.height()-offset, 0, 0); + painter->fillRect(regularRect, windows_light_mode ? palette.light().color() : QColor("#272727")); + } else { + // Otherwise just draw the background color as usual + painter->fillRect(rect, windows_light_mode ? palette.light().color() : QColor("#272727")); + } + + // Draw bottom line. Last line gets a different color + painter->setPen(lastIndex ? palette.dark().color() + : palette.mid().color()); + painter->drawLine(lastIndex ? rect.left() : m_ptr->margins.left(), + bottomEdge, rect.right(), bottomEdge); + + // Draw system icon + if (hasIcon) { + painter->drawPixmap(contentRect.left(), contentRect.top(), + opt.icon.pixmap(m_ptr->iconSize)); + } + + // System name + QRect systemNameRect(m_ptr->systemNameBox(opt, index)); + + systemNameRect.moveTo(m_ptr->margins.left() + m_ptr->iconSize.width() + + m_ptr->spacingHorizontal, contentRect.top()); + // If desired, font can be changed here +// painter->setFont(f); + painter->setFont(opt.font); + painter->setPen(palette.text().color()); + painter->drawText(systemNameRect, Qt::TextSingleLine, opt.text); + + // Draw status icon + painter->drawPixmap(systemNameRect.left(), systemNameRect.bottom() + + m_ptr->spacingVertical, + status_icon.pixmap(m_ptr->smallIconSize)); + + // This rectangle is around the status icon + // auto point = QPoint(systemNameRect.left(), systemNameRect.bottom() + // + m_ptr->spacingVertical); + // auto point2 = QPoint(point.x() + m_ptr->smallIconSize.width(), point.y() + m_ptr->smallIconSize.height()); + // auto arect = QRect(point, point2); + // painter->drawRect(arect); + + // Draw status text + QRect statusRect(m_ptr->statusBox(opt, index)); + int extraaa = 2; + statusRect.moveTo(systemNameRect.left() + m_ptr->margins.left() + m_ptr->smallIconSize.width(), + systemNameRect.bottom() + m_ptr->spacingVertical + extraaa + (m_ptr->smallIconSize.height() - systemNameRect.height() )); + +// painter->setFont(opt.font); + painter->setFont(f); + painter->setPen(palette.windowText().color()); + painter->drawText(statusRect, Qt::TextSingleLine, + index.data(VMManagerModel::Roles::ProcessStatusString).toString()); + + painter->restore(); + +} + +QMargins VMManagerListViewDelegate::contentsMargins() const +{ + return m_ptr->margins; +} + +void VMManagerListViewDelegate::setContentsMargins(const int left, const int top, const int right, const int bottom) const +{ + m_ptr->margins = QMargins(left, top, right, bottom); +} + +int VMManagerListViewDelegate::horizontalSpacing() const +{ + return m_ptr->spacingHorizontal; +} + +void VMManagerListViewDelegate::setHorizontalSpacing(const int spacing) const +{ + m_ptr->spacingHorizontal = spacing; +} + +int VMManagerListViewDelegate::verticalSpacing() const +{ + return m_ptr->spacingVertical; +} + +void VMManagerListViewDelegate::setVerticalSpacing(const int spacing) const +{ + m_ptr->spacingVertical = spacing; +} + + +QSize VMManagerListViewDelegate::sizeHint(const QStyleOptionViewItem &option, + const QModelIndex &index) const +{ + QStyleOptionViewItem opt(option); + initStyleOption(&opt, index); + + const int textHeight = m_ptr->systemNameBox(opt, index).height() + + m_ptr->spacingVertical + m_ptr->statusBox(opt, index).height(); + const int iconHeight = m_ptr->iconSize.height(); + const int h = textHeight > iconHeight ? textHeight : iconHeight; + + // return the same width + // for height, add margins on top and bottom *plus* either the text or icon height, whichever is greater + // Note: text height is the combined value of the system name and the status just below the name + return {opt.rect.width(), m_ptr->margins.top() + h + + m_ptr->margins.bottom()}; +} + +VMManagerListViewDelegateStyle::VMManagerListViewDelegateStyle() : + iconSize(32, 32), + smallIconSize(16, 16), + // bottom gets a little more than the top because of the custom separator + margins(4, 10, 8, 12), + // Spacing between icon and text + spacingHorizontal(8), + spacingVertical(4) +{ + +} + +QRect VMManagerListViewDelegateStyle::statusBox(const QStyleOptionViewItem &option, + const QModelIndex &index) const +{ + QFont f(option.font); + + f.setPointSizeF(statusFontPointSize(option.font)); + + return QFontMetrics(f).boundingRect(index.data(VMManagerModel::Roles::ProcessStatusString).toString()) + .adjusted(0, 0, 1, 1); +} + +qreal VMManagerListViewDelegateStyle::statusFontPointSize(const QFont &f) const +{ + return 0.75*f.pointSize(); +// return 1*f.pointSize(); +} + +QRect VMManagerListViewDelegateStyle::systemNameBox(const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + return option.fontMetrics.boundingRect(option.text).adjusted(0, 0, 1, 1); +} diff --git a/src/qt/qt_vmmanager_listviewdelegate.hpp b/src/qt/qt_vmmanager_listviewdelegate.hpp new file mode 100644 index 000000000..84325086d --- /dev/null +++ b/src/qt/qt_vmmanager_listviewdelegate.hpp @@ -0,0 +1,67 @@ +/* +* 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. +* +* Header for 86Box VM manager list view delegate module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#ifndef QT_VMMANAGER_LISTVIEWDELEGATE_H +#define QT_VMMANAGER_LISTVIEWDELEGATE_H + +#include +#include +#include "qt_vmmanager_system.hpp" + +class VMManagerListViewDelegateStyle +{ + VMManagerListViewDelegateStyle(); + + [[nodiscard]] inline QRect systemNameBox(const QStyleOptionViewItem &option, + const QModelIndex &index) const; + [[nodiscard]] inline qreal statusFontPointSize(const QFont &f) const; + [[nodiscard]] inline QRect statusBox(const QStyleOptionViewItem &option, const QModelIndex &index) const; + + QSize iconSize; + QSize smallIconSize; + QMargins margins; + int spacingHorizontal; + int spacingVertical; + + friend class VMManagerListViewDelegate; +}; + +class VMManagerListViewDelegate final : public QStyledItemDelegate { + Q_OBJECT + +public: + explicit VMManagerListViewDelegate(QObject *parent = nullptr); + ~VMManagerListViewDelegate() override; + using QStyledItemDelegate::QStyledItemDelegate; + + [[nodiscard]] QMargins contentsMargins() const; + void setContentsMargins(int left, int top, int right, int bottom) const; + + [[nodiscard]] int horizontalSpacing() const; + void setHorizontalSpacing(int spacing) const; + + [[nodiscard]] int verticalSpacing() const; + void setVerticalSpacing(int spacing) const; + + void paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const override; + [[nodiscard]] QSize sizeHint(const QStyleOptionViewItem &option, + const QModelIndex &index) const override; +private: + VMManagerListViewDelegateStyle *m_ptr; +}; +#endif // QT_VMMANAGER_LISTVIEWDELEGATE_H \ No newline at end of file diff --git a/src/qt/qt_vmmanager_main.cpp b/src/qt/qt_vmmanager_main.cpp new file mode 100644 index 000000000..8c83b549f --- /dev/null +++ b/src/qt/qt_vmmanager_main.cpp @@ -0,0 +1,521 @@ +/* +* 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. +* +* 86Box VM manager main module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "qt_vmmanager_main.hpp" +#include "ui_qt_vmmanager_main.h" +#include "qt_vmmanager_model.hpp" +#include "qt_vmmanager_addmachine.hpp" + +VMManagerMain::VMManagerMain(QWidget *parent) : + QWidget(parent), ui(new Ui::VMManagerMain), selected_sysconfig(new VMManagerSystem) { + ui->setupUi(this); + this->setWindowTitle("86Box VM Manager"); + + // Set up the main listView + ui->listView->setItemDelegate(new VMManagerListViewDelegate); + vm_model = new VMManagerModel; + proxy_model = new StringListProxyModel(this); + proxy_model->setSourceModel(vm_model); + ui->listView->setModel(proxy_model); + proxy_model->setSortCaseSensitivity(Qt::CaseInsensitive); + ui->listView->model()->sort(0, Qt::AscendingOrder); + + // Connect the model signal + connect(vm_model, &VMManagerModel::systemDataChanged, this, &VMManagerMain::modelDataChange); + + // Set up the context menu for the list view + ui->listView->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->listView, &QListView::customContextMenuRequested, [this](const QPoint &pos) { + const auto indexAt = ui->listView->indexAt(pos); + if (indexAt.isValid()) { + QMenu contextMenu(tr("Context Menu"), ui->listView); + + QAction nameChangeAction(tr("Change display name")); + contextMenu.addAction(&nameChangeAction); + // Use a lambda to call a function so indexAt can be passed + connect(&nameChangeAction, &QAction::triggered, ui->listView, [this, indexAt] { + updateDisplayName(indexAt); + }); + + QAction openSystemFolderAction(tr("Open folder")); + contextMenu.addAction(&openSystemFolderAction); + connect(&openSystemFolderAction, &QAction::triggered, [this, indexAt] { + if (const auto configDir = indexAt.data(VMManagerModel::Roles::ConfigDir).toString(); !configDir.isEmpty()) { + QDir dir(configDir); + if (!dir.exists()) + dir.mkpath("."); + + QDesktopServices::openUrl(QUrl(QString("file:///") + dir.canonicalPath())); + } + }); + + QAction convertToP3(tr("Convert system to PIII")); + contextMenu.addAction(&convertToP3); + convertToP3.setEnabled(false); + + QAction setSystemIcon(tr("Set icon")); + contextMenu.addAction(&setSystemIcon); + connect(&setSystemIcon, &QAction::triggered, [this, indexAt] { + IconSelectionDialog dialog(":/systemicons/"); + if(dialog.exec() == QDialog::Accepted) { + const QString iconName = dialog.getSelectedIconName(); + // A Blank iconName will cause setIcon to reset to the default + selected_sysconfig->setIcon(iconName); + } + }); + + contextMenu.addSeparator(); + + QAction showRawConfigFile(tr("Show config file")); + contextMenu.addAction(&showRawConfigFile); + connect(&showRawConfigFile, &QAction::triggered, [this, indexAt] { + if (const auto configFile = indexAt.data(VMManagerModel::Roles::ConfigFile).toString(); !configFile.isEmpty()) { + showTextFileContents(indexAt.data(Qt::DisplayRole).toString(), configFile); + } + }); + + contextMenu.exec(ui->listView->viewport()->mapToGlobal(pos)); + } + }); + + // Initial default details view + vm_details = new VMManagerDetails(); + ui->detailsArea->layout()->addWidget(vm_details); + const QItemSelectionModel *selection_model = ui->listView->selectionModel(); + + connect(selection_model, &QItemSelectionModel::currentChanged, this, &VMManagerMain::currentSelectionChanged); + // If there are items in the model, make sure to select the first item by default. + // When settings are loaded, the last selected item will be selected (if available) + if (proxy_model->rowCount(QModelIndex()) > 0) { + const QModelIndex first_index = proxy_model->index(0, 0); + ui->listView->setCurrentIndex(first_index); + } + + // Load and apply settings + loadSettings(); + + // Set up search bar + connect(ui->searchBar, &QLineEdit::textChanged, this, &VMManagerMain::searchSystems); + // Create the completer + auto *completer = new QCompleter(this); + completer->setCaseSensitivity(Qt::CaseInsensitive); + completer->setFilterMode(Qt::MatchContains); + // Get the completer list + const auto allStrings = getSearchCompletionList(); + // Set up the completer + auto *completerModel = new QStringListModel(allStrings, completer); + completer->setModel(completerModel); + ui->searchBar->setCompleter(completer); + + // Set initial status bar after the event loop starts + QTimer::singleShot(0, this, [this] { + emit updateStatusRight(totalCountString()); + }); + + // Start update check after a slight delay + QTimer::singleShot(1000, this, [this] { + if(updateCheck) { + backgroundUpdateCheckStart(); + } + }); +} + +VMManagerMain::~VMManagerMain() { + delete ui; + delete vm_model; +} + +void +VMManagerMain::currentSelectionChanged(const QModelIndex ¤t, + const QModelIndex &previous) +{ + if(!current.isValid()) { + return; + } + + const auto mapped_index = proxy_model->mapToSource(current); + selected_sysconfig = vm_model->getConfigObjectForIndex(mapped_index); + vm_details->updateData(selected_sysconfig); + + // Emit that the selection changed, include with the process state + emit selectionChanged(current, selected_sysconfig->process->state()); + +} + +void +VMManagerMain::settingsButtonPressed() { + if(!currentSelectionIsValid()) { + return; + } + selected_sysconfig->launchSettings(); + // If the process is already running, the system will be instructed to open its settings window. + // Otherwise the process will be launched and will need to be tracked here. + if (!selected_sysconfig->isProcessRunning()) { + connect(selected_sysconfig->process, QOverload::of(&QProcess::finished), + [=](const int exitCode, const QProcess::ExitStatus exitStatus){ + if (exitCode != 0 || exitStatus != QProcess::NormalExit) { + qInfo().nospace().noquote() << "Abnormal program termination while launching settings: exit code " << exitCode << ", exit status " << exitStatus; + return; + } + selected_sysconfig->reloadConfig(); + vm_details->updateData(selected_sysconfig); + }); + } +} + +void +VMManagerMain::startButtonPressed() const +{ + if(!currentSelectionIsValid()) { + return; + } + selected_sysconfig->startButtonPressed(); +} + +void +VMManagerMain::restartButtonPressed() const +{ + if(!currentSelectionIsValid()) { + return; + } + selected_sysconfig->restartButtonPressed(); + +} + +void +VMManagerMain::pauseButtonPressed() const +{ + if(!currentSelectionIsValid()) { + return; + } + selected_sysconfig->pauseButtonPressed(); +} + +void +VMManagerMain::shutdownRequestButtonPressed() const +{ + if (!currentSelectionIsValid()) { + return; + } + selected_sysconfig->shutdownRequestButtonPressed(); +} + +void +VMManagerMain::shutdownForceButtonPressed() const +{ + if (!currentSelectionIsValid()) { + return; + } + selected_sysconfig->shutdownForceButtonPressed(); +} + +// This function doesn't appear to be needed any longer +void +VMManagerMain::refresh() +{ + const auto current_index = ui->listView->currentIndex(); + emit selectionChanged(current_index, selected_sysconfig->process->state()); + + // if(!selected_sysconfig->config_file.path().isEmpty()) { + if(!selected_sysconfig->isValid()) { + // what was happening here? + } +} + +void +VMManagerMain::updateDisplayName(const QModelIndex &index) +{ + QDialog dialog; + dialog.setMinimumWidth(400); + dialog.setWindowTitle(tr("Set display name")); + const auto layout = new QVBoxLayout(&dialog); + const auto label = new QLabel(tr("Enter the new display name (blank to reset)")); + label->setAlignment(Qt::AlignHCenter); + label->setContentsMargins(QMargins(0, 0, 0, 5)); + layout->addWidget(label); + const auto lineEdit = new QLineEdit(index.data().toString(), &dialog); + layout->addWidget(lineEdit); + lineEdit->selectAll(); + + const auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, &dialog); + layout->addWidget(buttonBox); + + connect(buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept); + connect(buttonBox, &QDialogButtonBox::rejected, &dialog, &QDialog::reject); + + if (const bool accepted = dialog.exec() == QDialog::Accepted; accepted) { + const auto mapped_index = proxy_model->mapToSource(index); + vm_model->updateDisplayName(mapped_index, lineEdit->text()); + selected_sysconfig = vm_model->getConfigObjectForIndex(mapped_index); + vm_details->updateData(selected_sysconfig); + ui->listView->scrollTo(ui->listView->currentIndex(), QAbstractItemView::PositionAtCenter); + } +} + +void +VMManagerMain::loadSettings() +{ + const auto config = new VMManagerConfig(VMManagerConfig::ConfigType::General); + const auto lastSelection = config->getStringValue("last_selection"); + updateCheck = config->getStringValue("update_check").toInt(); + regexSearch = config->getStringValue("regex_search").toInt(); + + const auto matches = ui->listView->model()->match(vm_model->index(0, 0), VMManagerModel::Roles::ConfigName, QVariant::fromValue(lastSelection)); + if (!matches.empty()) { + ui->listView->setCurrentIndex(matches.first()); + ui->listView->scrollTo(ui->listView->currentIndex(), QAbstractItemView::PositionAtCenter); + } +} +bool +VMManagerMain::currentSelectionIsValid() const +{ + return ui->listView->currentIndex().isValid() && selected_sysconfig->isValid(); +} + +// Used from MainWindow during app exit to obtain and persist the current selection +QString +VMManagerMain::getCurrentSelection() const +{ + return ui->listView->currentIndex().data(VMManagerModel::Roles::ConfigName).toString(); +} + +void +VMManagerMain::searchSystems(const QString &text) const +{ + // Escape the search text string unless regular expression searching is enabled. + // When escaped, the search string functions as a plain text match. + const auto searchText = regexSearch ? text : QRegularExpression::escape(text); + const QRegularExpression regex(searchText, QRegularExpression::CaseInsensitiveOption); + if (!regex.isValid()) { + qDebug() << "Skipping, invalid regex"; + return; + } + proxy_model->setFilterRegularExpression(regex); + // Searching (filtering) can cause the list view to change. If there is still a valid selection, + // make sure to scroll to it + if (ui->listView->currentIndex().isValid()) { + ui->listView->scrollTo(ui->listView->currentIndex(), QAbstractItemView::PositionAtCenter); + } +} + +void +VMManagerMain::newMachineWizard() +{ + const auto wizard = new VMManagerAddMachine(this); + if (wizard->exec() == QDialog::Accepted) { + const auto newName = wizard->field("systemName").toString(); + const auto systemDir = wizard->field("systemLocation").toString(); + const auto existingConfiguration = wizard->field("existingConfiguration").toString(); + addNewSystem(newName, systemDir, existingConfiguration); + } +} + +void +VMManagerMain::addNewSystem(const QString &name, const QString &dir, const QString &configFile) +{ + const auto newSytemDirectory = QDir(QDir::cleanPath(dir + "/" + name)); + + // qt replaces `/` with native separators + const auto newSystemConfigFile = QFileInfo(newSytemDirectory.path() + "/" + "86box.cfg"); + if (newSystemConfigFile.exists() || newSytemDirectory.exists()) { + QMessageBox::critical(this, tr("Directory in use"), tr("The selected directory is already in use. Please select a different directory.")); + return; + } + // Create the directory + const QDir qmkdir; + if (const bool mkdirResult = qmkdir.mkdir(newSytemDirectory.path()); !mkdirResult) { + QMessageBox::critical(this, tr("Create directory failed"), tr("Unable to create the directory for the new system")); + return; + } + // If specified, write the contents of the configuration file before starting + if (!configFile.isEmpty()) { + const auto configPath = newSystemConfigFile.absoluteFilePath(); + const auto file = new QFile(configPath); + if (!file->open(QIODevice::WriteOnly)) { + qWarning() << "Unable to open file " << configPath; + QMessageBox::critical(this, tr("Configuration write failed"), tr("Unable to open the configuration file at %1 for writing").arg(configPath)); + return; + } + file->write(configFile.toUtf8()); + file->flush(); + file->close(); + } + + const auto new_system = new VMManagerSystem(newSystemConfigFile.absoluteFilePath()); + new_system->launchSettings(); + // Handle this in a closure so we can capture the temporary new_system object + connect(new_system->process, QOverload::of(&QProcess::finished), + [=](const int exitCode, const QProcess::ExitStatus exitStatus) { + if (exitCode != 0 || exitStatus != QProcess::NormalExit) { + qInfo().nospace().noquote() << "Abnormal program termination while creating new system: exit code " << exitCode << ", exit status " << exitStatus; + qInfo() << "Not adding system due to errors"; + QMessageBox::critical(this, tr("Error adding system"), + tr("Abnormal program termination while creating new system: exit code %1, exit status %2.\n\nThe system will not be added.").arg(QString::number(exitCode), exitStatus)); + delete new_system; + return; + } + // Create a new QFileInfo because the info from the old one may be cached + if (const auto fi = QFileInfo(new_system->config_file.absoluteFilePath()); !fi.exists()) { + // No config file which means the cancel button was pressed in the settings dialog + // Attempt to clean up the directory that was created + const QDir qrmdir; + if (const bool result = qrmdir.rmdir(newSytemDirectory.path()); !result) { + qWarning() << "Error cleaning up the old directory for canceled operation. Continuing anyway."; + } + delete new_system; + return; + } + const auto current_index = ui->listView->currentIndex(); + vm_model->reload(this); + const auto created_object = vm_model->getIndexForConfigFile(new_system->config_file); + if (created_object.row() < 0) { + // For some reason the index of the new object couldn't be determined. Fall back to the old index. + ui->listView->setCurrentIndex(current_index); + delete new_system; + return; + } + // Get the index of the newly-created system and select it + const QModelIndex mapped_index = proxy_model->mapFromSource(created_object); + ui->listView->setCurrentIndex(mapped_index); + delete new_system; + }); +} + +QStringList +VMManagerMain::getSearchCompletionList() const +{ + QSet uniqueStrings; + for (int row = 0; row < vm_model->rowCount(QModelIndex()); ++row) { + QModelIndex index = vm_model->index(row, 0); + auto fullList = vm_model->data(index, VMManagerModel::Roles::SearchList).toStringList(); + QSet uniqueSet(fullList.begin(), fullList.end()); + uniqueStrings.unite(uniqueSet); + } + // Convert the set back to a QStringList + QStringList allStrings = uniqueStrings.values(); + return allStrings; +} + +QString +VMManagerMain::totalCountString() const +{ + const auto count = vm_model->rowCount(QModelIndex()); + return QString("%1 %2").arg(QString::number(count), tr("total")); +} + +void +VMManagerMain::modelDataChange() +{ + // Model data has changed. This includes process status. + // Update the counts / totals accordingly + auto modelStats = vm_model->getProcessStats(); + QStringList stats; + for (auto it = modelStats.constBegin(); it != modelStats.constEnd(); ++it) { + const auto &key = it.key(); + stats.append(QString("%1 %2").arg(QString::number(modelStats[key]), key)); + } + auto states = stats.join(", "); + if (!modelStats.isEmpty()) { + states.append(", "); + } + + emit updateStatusRight(states + totalCountString()); +} + +void +VMManagerMain::onPreferencesUpdated() +{ + // Only reload values that we care about + const auto config = new VMManagerConfig(VMManagerConfig::ConfigType::General); + const auto oldRegexSearch = regexSearch; + regexSearch = config->getStringValue("regex_search").toInt(); + if (oldRegexSearch != regexSearch) { + ui->searchBar->clear(); + } +} + +void +VMManagerMain::backgroundUpdateCheckStart() const +{ + auto updateChannel = UpdateCheck::UpdateChannel::CI; +#ifdef RELEASE_BUILD + updateChannel = UpdateCheck::UpdateChannel::Stable; +#endif + const auto updateCheck = new UpdateCheck(updateChannel); + connect(updateCheck, &UpdateCheck::updateCheckComplete, this, &VMManagerMain::backgroundUpdateCheckComplete); + connect(updateCheck, &UpdateCheck::updateCheckError, this, &VMManagerMain::backgroundUpdateCheckError); + updateCheck->checkForUpdates(); +} + +void +VMManagerMain::backgroundUpdateCheckComplete(const UpdateCheck::UpdateResult &result) +{ + qDebug() << "Check complete: update available?" << result.updateAvailable; + auto type = result.channel == UpdateCheck::UpdateChannel::CI ? tr("Build") : tr("Version"); + const auto updateMessage = QString("%1: %2 %3").arg( tr("An update to 86Box is available"), type, result.latestVersion); + emit updateStatusLeft(updateMessage); +} + +void +VMManagerMain::backgroundUpdateCheckError(const QString &errorMsg) +{ + qDebug() << "Update check failed with the following error:" << errorMsg; + // TODO: Update the status bar +} + +void +VMManagerMain::showTextFileContents(const QString &title, const QString &path) +{ + // Make sure we can open the file + const auto fi = QFileInfo(path); + if(!fi.exists()) { + qWarning("Requested file does not exist: %s", path.toUtf8().constData()); + return; + } + // Read the file + QFile displayFile(path); + if (!displayFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + qWarning("Couldn't open the file: error %d", displayFile.error()); + return; + } + const QString configFileContents = displayFile.readAll(); + displayFile.close(); + + const auto textDisplayDialog = new QDialog(this); + textDisplayDialog->setFixedSize(QSize(540, 360)); + textDisplayDialog->setWindowTitle(QString("%1 - %2").arg(title, fi.fileName())); + + const auto textEdit = new QPlainTextEdit(); + textEdit->setReadOnly(true); + textEdit->setPlainText(configFileContents); + const auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok); + connect(buttonBox, &QDialogButtonBox::accepted, textDisplayDialog, &QDialog::accept); + const auto layout = new QVBoxLayout(); + textDisplayDialog->setLayout(layout); + textDisplayDialog->layout()->addWidget(textEdit); + textDisplayDialog->layout()->addWidget(buttonBox); + textDisplayDialog->exec(); +} diff --git a/src/qt/qt_vmmanager_main.hpp b/src/qt/qt_vmmanager_main.hpp new file mode 100644 index 000000000..c3c541b4f --- /dev/null +++ b/src/qt/qt_vmmanager_main.hpp @@ -0,0 +1,167 @@ +/* +* 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. +* +* Header for 86Box VM manager main module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#ifndef QT_VMMANAGER_MAIN_H +#define QT_VMMANAGER_MAIN_H + +#include "qt_updatecheck.hpp" + +#include +#include "qt_vmmanager_model.hpp" +#include "qt_vmmanager_details.hpp" +#include "qt_vmmanager_listviewdelegate.hpp" + +#include + +extern "C" { +#include <86box/86box.h> // for vmm_path +} + + +QT_BEGIN_NAMESPACE +namespace Ui { class VMManagerMain; } +QT_END_NAMESPACE + +class VMManagerMain final : public QWidget { + Q_OBJECT + +public: + explicit VMManagerMain(QWidget *parent = nullptr); + ~VMManagerMain() override; + // Used to save the current selection + [[nodiscard]] QString getCurrentSelection() const; + + enum class ToolbarButton { + Start, + Pause, + StartPause, + Shutdown, + Reset, + CtrlAltDel, + Settings, + }; +signals: + void selectionChanged(const QModelIndex ¤tSelection, QProcess::ProcessState processState); + void updateStatusLeft(const QString &text); + void updateStatusRight(const QString &text); + +public slots: + void startButtonPressed() const; + void settingsButtonPressed(); + void restartButtonPressed() const; + void pauseButtonPressed() const; + void shutdownRequestButtonPressed() const; + void shutdownForceButtonPressed() const; + void searchSystems(const QString &text) const; + void newMachineWizard(); + void addNewSystem(const QString &name, const QString &dir, const QString &configFile = {}); + [[nodiscard]] QStringList getSearchCompletionList() const; + void modelDataChange(); + void onPreferencesUpdated(); + +private: + Ui::VMManagerMain *ui; + + VMManagerModel *vm_model; + VMManagerDetails *vm_details; + VMManagerSystem *selected_sysconfig; + // VMManagerConfig *config; + QSortFilterProxyModel *proxy_model; + bool updateCheck = false; + bool regexSearch = false; + + // void updateSelection(const QItemSelection &selected, + // const QItemSelection &deselected); + void currentSelectionChanged(const QModelIndex ¤t, + const QModelIndex &previous); + void refresh(); + void updateDisplayName(const QModelIndex &index); + void loadSettings(); + [[nodiscard]] bool currentSelectionIsValid() const; + [[nodiscard]] QString totalCountString() const; + void backgroundUpdateCheckStart() const; + void showTextFileContents(const QString &title, const QString &path); +private slots: + void backgroundUpdateCheckComplete(const UpdateCheck::UpdateResult &result); + void backgroundUpdateCheckError(const QString &errorMsg); +}; + +#include +#include +#include +#include + +class IconSelectionDialog final : public QDialog { + Q_OBJECT + +public: + explicit IconSelectionDialog(QString assetPath, QWidget *parent = nullptr) : QDialog(parent), listWidget(new QListWidget) { + // Set the list widget to icon mode + listWidget->setViewMode(QListWidget::IconMode); + setFixedSize(QSize(540, 360)); + listWidget->setGridSize(QSize(96, 96)); + listWidget->setIconSize(QSize(64, 64)); + // Read in all the assets from the given path + const QDir iconsDir(assetPath); + if (!assetPath.endsWith("/")) { + assetPath.append("/"); + } + setWindowTitle(tr("Select an icon")); + + // Loop on all files and add them as items (icons) in QListWidget + for(const QString& iconName : iconsDir.entryList()) { + const auto item = new QListWidgetItem(QIcon(assetPath + iconName), iconName); + // Set the UserRole to the resource bundle path + item->setData(Qt::UserRole, assetPath + iconName); + listWidget->addItem(item); + } + + // Dialog buttons + const auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Reset); + // Use the reset button for resetting the icon to the default + const QPushButton* resetButton = buttonBox->button(QDialogButtonBox::Reset); + + // Connect the buttons signals + connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); + connect(listWidget, &QListWidget::doubleClicked, this, &QDialog::accept); + connect(resetButton, &QPushButton::clicked, [this] { + // For reset, set the index to invalid so the caller will receive a blank string + listWidget->setCurrentIndex(QModelIndex()); + // Then accept + QDialog::accept(); + }); + + const auto layout = new QVBoxLayout(this); + layout->addWidget(listWidget); + layout->addWidget(buttonBox); + } + + public slots: + [[nodiscard]] QString getSelectedIconName() const { + if (listWidget->currentIndex().isValid()) { + return listWidget->currentItem()->data(Qt::UserRole).toString(); + } + // Index is invalid because the reset button was pressed + return {}; + } + +private: + QListWidget* listWidget; +}; + +#endif //QT_VMMANAGER_MAIN_H diff --git a/src/qt/qt_vmmanager_main.ui b/src/qt/qt_vmmanager_main.ui new file mode 100644 index 000000000..c19094345 --- /dev/null +++ b/src/qt/qt_vmmanager_main.ui @@ -0,0 +1,119 @@ + + + VMManagerMain + + + + 0 + 0 + 815 + 472 + + + + + 0 + 0 + + + + VMManagerMain + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 200 + 0 + + + + + 200 + 16777215 + + + + + + + + Qt::ClickFocus + + + Search + + + true + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + diff --git a/src/qt/qt_vmmanager_mainwindow.cpp b/src/qt/qt_vmmanager_mainwindow.cpp new file mode 100644 index 000000000..767bbcef2 --- /dev/null +++ b/src/qt/qt_vmmanager_mainwindow.cpp @@ -0,0 +1,178 @@ +/* +* 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. +* +* 86Box VM manager main window +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#include "qt_vmmanager_mainwindow.hpp" +#include "qt_vmmanager_main.hpp" +#include "qt_vmmanager_preferences.hpp" +#include "ui_qt_vmmanager_mainwindow.h" +#include "qt_updatecheckdialog.hpp" + +#include +#include +#include + +VMManagerMainWindow:: +VMManagerMainWindow(QWidget *parent) + : ui(new Ui::VMManagerMainWindow) + , vmm(new VMManagerMain(this)) + , statusLeft(new QLabel) + , statusRight(new QLabel) +{ + ui->setupUi(this); + + // Connect signals from the VMManagerMain widget + connect(vmm, &VMManagerMain::selectionChanged, this, &VMManagerMainWindow::vmmSelectionChanged); + + setWindowTitle(tr("86Box VM Manager")); + setCentralWidget(vmm); + + // Set up the buttons + connect(ui->actionStartPause, &QAction::triggered, vmm, &VMManagerMain::startButtonPressed); + connect(ui->actionSettings, &QAction::triggered, vmm, &VMManagerMain::settingsButtonPressed); + connect(ui->actionHard_Reset, &QAction::triggered, vmm, &VMManagerMain::restartButtonPressed); + connect(ui->actionForce_Shutdown, &QAction::triggered, vmm, &VMManagerMain::shutdownForceButtonPressed); + connect(ui->actionNew_Machine, &QAction::triggered, vmm, &VMManagerMain::newMachineWizard); + + // Set up menu actions + connect(ui->actionCheck_for_updates, &QAction::triggered, this, &VMManagerMainWindow::checkForUpdatesTriggered); + + // TODO: Remove all of this (all the way to END REMOVE) once certain the search will no longer be in the toolbar. + // BEGIN REMOVE + // Everything is still setup here for it but it is all hidden. None of it will be + // needed if the search stays in VMManagerMain + ui->actionStartPause->setEnabled(true); + ui->actionStartPause->setIcon(QIcon(":/menuicons/qt/icons/run.ico")); + ui->actionStartPause->setText(tr("Start")); + ui->actionStartPause->setToolTip(tr("Start")); + ui->actionHard_Reset->setEnabled(false); + ui->actionForce_Shutdown->setEnabled(false); + ui->actionCtrl_Alt_Del->setEnabled(false); + + const auto searchBar = new QLineEdit(); + searchBar->setMinimumWidth(150); + searchBar->setPlaceholderText(" " + tr("Search")); + searchBar->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); + searchBar->setClearButtonEnabled(true); + // Spacer to make the search go all the way to the right + const auto spacer = new QWidget(); + spacer->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); + ui->toolBar->addWidget(spacer); + ui->toolBar->addWidget(searchBar); + // Connect signal for search + connect(searchBar, &QLineEdit::textChanged, vmm, &VMManagerMain::searchSystems); + // Preferences + connect(ui->actionPreferences, &QAction::triggered, this, &VMManagerMainWindow::preferencesTriggered); + + // Create a completer for the search bar + auto *completer = new QCompleter(this); + completer->setCaseSensitivity(Qt::CaseInsensitive); + completer->setFilterMode(Qt::MatchContains); + // Get the completer list + const auto allStrings = vmm->getSearchCompletionList(); + // Set up the completer + auto *completerModel = new QStringListModel(allStrings, completer); + completer->setModel(completerModel); + searchBar->setCompleter(completer); + ui->toolBar->setVisible(false); + // END REMOVE + + // Status bar widgets + statusLeft->setAlignment(Qt::AlignLeft); + statusRight->setAlignment(Qt::AlignRight); + ui->statusbar->addPermanentWidget(statusLeft, 1); + ui->statusbar->addPermanentWidget(statusRight, 1); + connect(vmm, &VMManagerMain::updateStatusLeft, this, &VMManagerMainWindow::setStatusLeft); + connect(vmm, &VMManagerMain::updateStatusRight, this, &VMManagerMainWindow::setStatusRight); + + // Inform the main view when preferences are updated + connect(this, &VMManagerMainWindow::preferencesUpdated, vmm, &VMManagerMain::onPreferencesUpdated); + +} + +VMManagerMainWindow::~ +VMManagerMainWindow() + = default; + +void +VMManagerMainWindow::vmmSelectionChanged(const QModelIndex ¤tSelection, const QProcess::ProcessState processState) const +{ + if (processState == QProcess::Running) { + ui->actionStartPause->setEnabled(true); + ui->actionStartPause->setIcon(QIcon(":/menuicons/qt/icons/pause.ico")); + ui->actionStartPause->setText(tr("Pause")); + ui->actionStartPause->setToolTip(tr("Pause")); + ui->actionHard_Reset->setEnabled(true); + ui->actionForce_Shutdown->setEnabled(true); + ui->actionCtrl_Alt_Del->setEnabled(true); + } else { + ui->actionStartPause->setEnabled(true); + ui->actionStartPause->setIcon(QIcon(":/menuicons/qt/icons/run.ico")); + ui->actionStartPause->setText(tr("Start")); + ui->actionStartPause->setToolTip(tr("Start")); + ui->actionHard_Reset->setEnabled(false); + ui->actionForce_Shutdown->setEnabled(false); + ui->actionCtrl_Alt_Del->setEnabled(false); + } +} +void +VMManagerMainWindow::preferencesTriggered() +{ + const auto prefs = new VMManagerPreferences(); + if (prefs->exec() == QDialog::Accepted) { + emit preferencesUpdated(); + } +} + +void +VMManagerMainWindow::saveSettings() const +{ + const auto currentSelection = vmm->getCurrentSelection(); + const auto config = new VMManagerConfig(VMManagerConfig::ConfigType::General); + config->setStringValue("last_selection", currentSelection); + // Sometimes required to ensure the settings save before the app exits + config->sync(); +} + +void +VMManagerMainWindow::closeEvent(QCloseEvent *event) +{ + saveSettings(); + QMainWindow::closeEvent(event); +} + +void +VMManagerMainWindow::setStatusLeft(const QString &text) const +{ + statusLeft->setText(text); +} + +void +VMManagerMainWindow::setStatusRight(const QString &text) const +{ + statusRight->setText(text); +} + +void +VMManagerMainWindow::checkForUpdatesTriggered() +{ + auto updateChannel = UpdateCheck::UpdateChannel::CI; +#ifdef RELEASE_BUILD + updateChannel = UpdateCheck::UpdateChannel::Stable; +#endif + const auto updateCheck = new UpdateCheckDialog(updateChannel); + updateCheck->exec(); +} diff --git a/src/qt/qt_vmmanager_mainwindow.hpp b/src/qt/qt_vmmanager_mainwindow.hpp new file mode 100644 index 000000000..764ed5ef8 --- /dev/null +++ b/src/qt/qt_vmmanager_mainwindow.hpp @@ -0,0 +1,59 @@ +/* +* 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. +* +* Header for 86Box VM manager main window +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#ifndef VMM_MAINWINDOW_H +#define VMM_MAINWINDOW_H + +#include "qt_vmmanager_main.hpp" + +#include +#include +#include + +namespace Ui { +class VMManagerMainWindow; +} + +class VMManagerMainWindow final : public QMainWindow +{ + Q_OBJECT +public: + explicit VMManagerMainWindow(QWidget *parent = nullptr); + ~VMManagerMainWindow() override; +signals: + void preferencesUpdated(); + +private: + Ui::VMManagerMainWindow *ui; + VMManagerMain *vmm; + void saveSettings() const; + QLabel *statusLeft; + QLabel *statusRight; +public slots: + void setStatusLeft(const QString &text) const; + void setStatusRight(const QString &text) const; + +private slots: + void vmmSelectionChanged(const QModelIndex ¤tSelection, QProcess::ProcessState processState) const; + void preferencesTriggered(); + static void checkForUpdatesTriggered(); + +protected: + void closeEvent(QCloseEvent *event) override; +}; + +#endif // VMM_MAINWINDOW_H diff --git a/src/qt/qt_vmmanager_mainwindow.ui b/src/qt/qt_vmmanager_mainwindow.ui new file mode 100644 index 000000000..e3e0a242d --- /dev/null +++ b/src/qt/qt_vmmanager_mainwindow.ui @@ -0,0 +1,212 @@ + + + VMManagerMainWindow + + + + 0 + 0 + 900 + 600 + + + + MainWindow + + + + + + 0 + 0 + 900 + 21 + + + + + Tools + + + + + + + File + + + + + + + + + + toolBar + + + false + + + + 16 + 16 + + + + Qt::ToolButtonStyle::ToolButtonIconOnly + + + TopToolBarArea + + + false + + + + + + + + + + + Do something + + + + + true + + + + :/menuicons/qt/icons/run.ico:/menuicons/qt/icons/run.ico + + + Start + + + false + + + + + + :/menuicons/qt/icons/hard_reset.ico:/menuicons/qt/icons/hard_reset.ico + + + &Hard Reset... + + + false + + + + + true + + + + :/menuicons/qt/icons/acpi_shutdown.ico:/menuicons/qt/icons/acpi_shutdown.ico + + + Force shutdown + + + Force shutdown + + + true + + + false + + + + + false + + + + :/menuicons/qt/icons/send_cad.ico:/menuicons/qt/icons/send_cad.ico + + + &Ctrl+Alt+Del + + + Ctrl+Alt+Del + + + false + + + false + + + false + + + + + + :/menuicons/qt/icons/settings.ico:/menuicons/qt/icons/settings.ico + + + &Settings... + + + QAction::MenuRole::NoRole + + + false + + + + + + :/settings/qt/icons/86Box-yellow.ico:/settings/qt/icons/86Box-yellow.ico + + + New Machine + + + New Machine + + + + + Preferences + + + Preferences + + + QAction::MenuRole::PreferencesRole + + + + + true + + + + :/menuicons/qt/icons/run.ico:/menuicons/qt/icons/run.ico + + + Start + + + false + + + + + Check for updates + + + + + + + + diff --git a/src/qt/qt_vmmanager_model.cpp b/src/qt/qt_vmmanager_model.cpp new file mode 100644 index 000000000..848970f80 --- /dev/null +++ b/src/qt/qt_vmmanager_model.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. +* +* 86Box VM manager model module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed + */ + +#include +#include "qt_vmmanager_model.hpp" + +VMManagerModel::VMManagerModel() { + auto machines_vec = VMManagerSystem::scanForConfigs(); + for ( const auto& each_config : machines_vec) { + machines.append(each_config); + connect(each_config, &VMManagerSystem::itemDataChanged, this, &VMManagerModel::modelDataChanged); + } +} + +VMManagerModel::~VMManagerModel() { + for ( auto machine : machines) { + delete machine; + } +} + +int +VMManagerModel::rowCount(const QModelIndex &parent) const { + return machines.size(); +} + +QVariant +VMManagerModel::data(const QModelIndex &index, int role) const { + if (!index.isValid()) + return {}; + + if (index.row() >= machines.size()) + return {}; + + switch (role) { + case Qt::DisplayRole: + return machines.at(index.row())->displayName; + case ConfigName: + return machines.at(index.row())->config_name; + case ConfigDir: + return machines.at(index.row())->config_dir; + case ConfigFile: + return machines.at(index.row())->config_file.canonicalFilePath(); + case UUID: + return machines.at(index.row())->uuid; + case Notes: + return machines.at(index.row())->notes; + case SearchList: + return machines.at(index.row())->searchTerms; + case LastUsed: + return machines.at(index.row())->timestamp(); + case Icon: + return machines.at(index.row())->icon; + case Qt::ToolTipRole: + return machines.at(index.row())->shortened_dir; + case Qt::UserRole: + return machines.at(index.row())->getAll("General"); + case ProcessStatusString: + return machines.at(index.row())->getProcessStatusString(); + case ProcessStatus: + return QVariant::fromValue(machines.at(index.row())->getProcessStatus()); + default: + return {}; + } +} + +QVariant +VMManagerModel::headerData(int section, Qt::Orientation orientation, int role) const { + + if (role != Qt::DisplayRole) + return {}; + + if (orientation == Qt::Horizontal) + return QStringLiteral("Column %1").arg(section); + else + return QStringLiteral("Row %1").arg(section); +} + +VMManagerSystem * +VMManagerModel::getConfigObjectForIndex(const QModelIndex &index) const +{ + return machines.at(index.row()); +} +void +VMManagerModel::reload(QWidget* parent) +{ + // Scan for configs + auto machines_vec = VMManagerSystem::scanForConfigs(parent); + for (const auto &scanned_config : machines_vec) { + int found = 0; + for (const auto &existing_config : machines) { + if (*scanned_config == *existing_config) { + found = 1; + } + } + if (!found) { + addConfigToModel(scanned_config); + } + } + // TODO: Remove missing configs +} + +QModelIndex +VMManagerModel::getIndexForConfigFile(const QFileInfo& config_file) +{ + int object_index = 0; + for (const auto& config_object: machines) { + if (config_object->config_file == config_file) { + return this->index(object_index); + } + object_index++; + } + return {}; +} + +void +VMManagerModel::addConfigToModel(VMManagerSystem *system_config) +{ + beginInsertRows(QModelIndex(), this->rowCount(QModelIndex()), this->rowCount(QModelIndex())); + machines.append(system_config); + connect(system_config, &VMManagerSystem::itemDataChanged, this, &VMManagerModel::modelDataChanged); + endInsertRows(); +} +void +VMManagerModel::modelDataChanged() +{ + // Inform the model + emit dataChanged(this->index(0), this->index(machines.size()-1)); + // Inform any interested observers + emit systemDataChanged(); +} + +void +VMManagerModel::updateDisplayName(const QModelIndex &index, const QString &newDisplayName) +{ + machines.at(index.row())->setDisplayName(newDisplayName); + modelDataChanged(); +} +QHash +VMManagerModel::getProcessStats() +{ + QHash stats; + for (const auto& system: machines) { + if (system->getProcessStatus() != VMManagerSystem::ProcessStatus::Stopped) { + auto statusString = system->getProcessStatusString(); + stats[statusString] += 1; + } + } + return stats; +} \ No newline at end of file diff --git a/src/qt/qt_vmmanager_model.hpp b/src/qt/qt_vmmanager_model.hpp new file mode 100644 index 000000000..bc13cc16f --- /dev/null +++ b/src/qt/qt_vmmanager_model.hpp @@ -0,0 +1,91 @@ +/* +* 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. +* +* Header for 86Box VM manager model module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed + */ + +#ifndef QT_VMMANAGER_MODEL_H +#define QT_VMMANAGER_MODEL_H + + +#include "qt_vmmanager_system.hpp" + +#include + +class VMManagerModel final : public QAbstractListModel { + + Q_OBJECT + +public: + // VMManagerModel(const QStringList &strings, QObject *parent = nullptr) + // : QAbstractListModel(parent), machines(strings) {} + VMManagerModel(); + ~VMManagerModel() override; + enum Roles { + ProcessStatusString = Qt::UserRole + 1, + ProcessStatus, + DisplayName, + ConfigName, + ConfigDir, + ConfigFile, + LastUsed, + UUID, + Notes, + SearchList, + Icon + }; + + [[nodiscard]] int rowCount(const QModelIndex &parent) const override; + [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override; + [[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, + int role) const override; + void addConfigToModel(VMManagerSystem *system_config); + + [[nodiscard]] VMManagerSystem * getConfigObjectForIndex(const QModelIndex &index) const; + QModelIndex getIndexForConfigFile(const QFileInfo& config_file); + void reload(QWidget* parent = nullptr); + void updateDisplayName(const QModelIndex &index, const QString &newDisplayName); + QHash getProcessStats(); +signals: + void systemDataChanged(); + +private: + QVector machines; + void modelDataChanged(); + +}; + +// Note: Custom QSortFilterProxyModel is included here instead of its own file as +// its only use is in this model + +class StringListProxyModel final : public QSortFilterProxyModel { +public: + explicit StringListProxyModel(QObject *parent = nullptr) : QSortFilterProxyModel(parent) {} + +protected: + [[nodiscard]] bool filterAcceptsRow(const int sourceRow, const QModelIndex &sourceParent) const override { + const QModelIndex index = sourceModel()->index(sourceRow, filterKeyColumn(), sourceParent); + + QStringList stringList = sourceModel()->data(index, VMManagerModel::Roles::SearchList).toStringList(); + + const QRegularExpression regex = filterRegularExpression(); + + const auto result = std::any_of(stringList.begin(), stringList.end(), [®ex](const QString &string) { + return regex.match(string).hasMatch(); + }); + return result; + } +}; + +#endif //QT_VMMANAGER_MODEL_H diff --git a/src/qt/qt_vmmanager_preferences.cpp b/src/qt/qt_vmmanager_preferences.cpp new file mode 100644 index 000000000..0730f875b --- /dev/null +++ b/src/qt/qt_vmmanager_preferences.cpp @@ -0,0 +1,82 @@ +/* +* 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. +* +* 86Box VM manager preferences module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#include +#include + +#include "qt_vmmanager_preferences.hpp" +#include "qt_vmmanager_config.hpp" +#include "ui_qt_vmmanager_preferences.h" + +extern "C" { +#include <86box/86box.h> +} + +VMManagerPreferences:: +VMManagerPreferences(QWidget *parent) : ui(new Ui::VMManagerPreferences) +{ + ui->setupUi(this); + ui->dirSelectButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_DirIcon)); + connect(ui->dirSelectButton, &QPushButton::clicked, this, &VMManagerPreferences::chooseDirectoryLocation); + + const auto config = new VMManagerConfig(VMManagerConfig::ConfigType::General); + const auto configSystemDir = config->getStringValue("system_directory"); + if(!configSystemDir.isEmpty()) { + // Prefer this one + ui->systemDirectory->setText(configSystemDir); + } else if(!QString(vmm_path).isEmpty()) { + // If specified on command line + ui->systemDirectory->setText(QDir(vmm_path).path()); + } + + // TODO: Defaults + const auto configUpdateCheck = config->getStringValue("update_check").toInt(); + ui->updateCheckBox->setChecked(configUpdateCheck); + const auto useRegexSearch = config->getStringValue("regex_search").toInt(); + ui->regexSearchCheckBox->setChecked(useRegexSearch); + + +} + +VMManagerPreferences::~ +VMManagerPreferences() + = default; + +// Bad copy pasta from machine add +void +VMManagerPreferences::chooseDirectoryLocation() +{ + // TODO: FIXME: This is pulling in the CLI directory! Needs to be set properly elsewhere + const auto directory = QFileDialog::getExistingDirectory(this, "Choose directory", QDir(vmm_path).path()); + ui->systemDirectory->setText(QDir::toNativeSeparators(directory)); +} + +void +VMManagerPreferences::accept() +{ + const auto config = new VMManagerConfig(VMManagerConfig::ConfigType::General); + config->setStringValue("system_directory", ui->systemDirectory->text()); + config->setStringValue("update_check", ui->updateCheckBox->isChecked() ? "1" : "0"); + config->setStringValue("regex_search", ui->regexSearchCheckBox->isChecked() ? "1" : "0"); + QDialog::accept(); +} + +void +VMManagerPreferences::reject() +{ + QDialog::reject(); +} \ No newline at end of file diff --git a/src/qt/qt_vmmanager_preferences.hpp b/src/qt/qt_vmmanager_preferences.hpp new file mode 100644 index 000000000..aedba862a --- /dev/null +++ b/src/qt/qt_vmmanager_preferences.hpp @@ -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. +* +* Header for 86Box VM manager preferences module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#ifndef VMMANAGER_PREFERENCES_H +#define VMMANAGER_PREFERENCES_H + +#include + +QT_BEGIN_NAMESPACE +namespace Ui { class VMManagerPreferences; } +QT_END_NAMESPACE + + +class VMManagerPreferences final : public QDialog +{ + Q_OBJECT +public: + explicit VMManagerPreferences(QWidget *parent = nullptr); + ~VMManagerPreferences() override; + +private: + Ui::VMManagerPreferences *ui; + QString settingsFile; +private slots: + void chooseDirectoryLocation(); +protected: + void accept() override; + void reject() override; + +}; + +#endif // VMMANAGER_PREFERENCES_H diff --git a/src/qt/qt_vmmanager_preferences.ui b/src/qt/qt_vmmanager_preferences.ui new file mode 100644 index 000000000..1743a0bfb --- /dev/null +++ b/src/qt/qt_vmmanager_preferences.ui @@ -0,0 +1,130 @@ + + + VMManagerPreferences + + + + 0 + 0 + 400 + 300 + + + + Preferences + + + + + + System Directory: + + + + + + + + 0 + + + 0 + + + + + + + + + + + + + 0 + 0 + + + + + + + + + + + + + + Check for updates on startup + + + + + + + Use regular expressions in search box + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + VMManagerPreferences + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + VMManagerPreferences + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/qt/qt_vmmanager_protocol.cpp b/src/qt/qt_vmmanager_protocol.cpp new file mode 100644 index 000000000..26f8a1f93 --- /dev/null +++ b/src/qt/qt_vmmanager_protocol.cpp @@ -0,0 +1,131 @@ +/* +* 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. +* +* 86Box VM manager protocol module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed + */ + +#include "qt_vmmanager_protocol.hpp" +#include +#include +VMManagerProtocol::VMManagerProtocol(VMManagerProtocol::Sender sender) +{ + message_class = sender; +} + +VMManagerProtocol::~VMManagerProtocol() += default; + +QJsonObject +VMManagerProtocol::protocolManagerMessage(VMManagerProtocol::ManagerMessage message_type) +{ + auto json_message = constructDefaultObject(VMManagerProtocol::Sender::Manager); + json_message["message"] = managerMessageTypeToString(message_type); + return json_message; +} + +QJsonObject +VMManagerProtocol::protocolClientMessage(VMManagerProtocol::ClientMessage message_type) +{ + auto json_message = constructDefaultObject(VMManagerProtocol::Sender::Client); + json_message["message"] = clientMessageTypeToString(message_type); + return json_message; +} + +QString +VMManagerProtocol::managerMessageTypeToString(VMManagerProtocol::ManagerMessage message) +{ + QMetaEnum qme = QMetaEnum::fromType(); + return qme.valueToKey(static_cast(message)); +} + +QString +VMManagerProtocol::clientMessageTypeToString(VMManagerProtocol::ClientMessage message) +{ + QMetaEnum qme = QMetaEnum::fromType(); + return qme.valueToKey(static_cast(message)); +} + +QJsonObject +VMManagerProtocol::constructDefaultObject(VMManagerProtocol::Sender type) +{ + QJsonObject json_message; + QString sender_type = ( type == VMManagerProtocol::Sender::Client ) ? "Client" : "VMManager"; + json_message["type"] = QString(sender_type); + json_message["version"] = QStringLiteral(EMU_VERSION); + return json_message; +} +bool +VMManagerProtocol::hasRequiredFields(const QJsonObject& json_document) +{ + for (const auto& field : ProtocolRequiredFields) { + if (!json_document.contains(field)) { + qDebug("Received json missing field \"%s\"", qPrintable(field)); + return false; + } + } + return true; +} +VMManagerProtocol::ClientMessage +VMManagerProtocol::getClientMessageType(const QJsonObject &json_document) +{ + // FIXME: This key ("message") is hardcoded here. Make a hash which maps these + // required values. + QString message_type = json_document.value("message").toString(); + // Can't use switch with strings, manual compare + if (message_type == "Status") { + return VMManagerProtocol::ClientMessage::Status; + } else if (message_type == "WindowBlocked") { + return VMManagerProtocol::ClientMessage::WindowBlocked; + } else if (message_type == "WindowUnblocked") { + return VMManagerProtocol::ClientMessage::WindowUnblocked; + } else if (message_type == "RunningStateChanged") { + return VMManagerProtocol::ClientMessage::RunningStateChanged; + } + return VMManagerProtocol::ClientMessage::UnknownMessage; +} +VMManagerProtocol::ManagerMessage +VMManagerProtocol::getManagerMessageType(const QJsonObject &json_document) +{ + // FIXME: This key ("message") is hardcoded here. Make a hash which maps these + // required values. + QString message_type = json_document.value("message").toString(); + // Can't use switch with strings, manual compare + if (message_type == "RequestStatus") { + return VMManagerProtocol::ManagerMessage::RequestStatus; + } else if (message_type == "Pause") { + return VMManagerProtocol::ManagerMessage::Pause; + } if (message_type == "CtrlAltDel") { + return VMManagerProtocol::ManagerMessage::CtrlAltDel; + } if (message_type == "ShowSettings") { + return VMManagerProtocol::ManagerMessage::ShowSettings; + } if (message_type == "ResetVM") { + return VMManagerProtocol::ManagerMessage::ResetVM; + } if (message_type == "RequestShutdown") { + return VMManagerProtocol::ManagerMessage::RequestShutdown; + } if (message_type == "ForceShutdown") { + return VMManagerProtocol::ManagerMessage::ForceShutdown; + } + return VMManagerProtocol::ManagerMessage::UnknownMessage; +} +QJsonObject +VMManagerProtocol::getParams(const QJsonObject &json_document) +{ + // FIXME: This key ("params") is hardcoded here. Make a hash which maps these + // required values. + auto params_object = json_document.value("params"); + if (params_object.type() != QJsonValue::Object) { + return {}; + } + return params_object.toObject(); +} diff --git a/src/qt/qt_vmmanager_protocol.hpp b/src/qt/qt_vmmanager_protocol.hpp new file mode 100644 index 000000000..48f0a2d8f --- /dev/null +++ b/src/qt/qt_vmmanager_protocol.hpp @@ -0,0 +1,93 @@ +/* +* 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. +* +* Header for 86Box VM manager protocol module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed + */ + +#ifndef QT_VMMANAGER_PROTOCOL_H +#define QT_VMMANAGER_PROTOCOL_H + +#include +extern "C" { +#include <86box/version.h> +} + +static QVector ProtocolRequiredFields = { "type", "message" }; + +class VMManagerProtocol : QObject { + Q_OBJECT + +public: + enum class Sender { + Manager, + Client, + }; + Q_ENUM(Sender); + + enum class ManagerMessage { + RequestStatus, + Pause, + CtrlAltDel, + ShowSettings, + ResetVM, + RequestShutdown, + ForceShutdown, + UnknownMessage, + }; + + // This macro allows us to do a reverse lookup of the enum with `QMetaEnum` + Q_ENUM(ManagerMessage); + + enum class ClientMessage { + Status, + WindowBlocked, + WindowUnblocked, + RunningStateChanged, + UnknownMessage, + }; + Q_ENUM(ClientMessage); + + enum class WindowStatus { + WindowUnblocked = 0, + WindowBlocked, + }; + + enum class RunningState { + Running = 0, + Paused, + RunningWaiting, + PausedWaiting, + Unknown, + }; + Q_ENUM(RunningState); + + explicit VMManagerProtocol(Sender sender); + ~VMManagerProtocol(); + + QJsonObject protocolManagerMessage(ManagerMessage message_type); + QJsonObject protocolClientMessage(ClientMessage message_type); + static QString managerMessageTypeToString(ManagerMessage message); + static QString clientMessageTypeToString(ClientMessage message); + + static bool hasRequiredFields(const QJsonObject &json_document); + static QJsonObject getParams(const QJsonObject &json_document); + static ClientMessage getClientMessageType(const QJsonObject &json_document); + static ManagerMessage getManagerMessageType(const QJsonObject &json_document); + +private: + Sender message_class; + static QJsonObject constructDefaultObject(VMManagerProtocol::Sender type); +}; + +#endif // QT_VMMANAGER_PROTOCOL_H diff --git a/src/qt/qt_vmmanager_serversocket.cpp b/src/qt/qt_vmmanager_serversocket.cpp new file mode 100644 index 000000000..50ff352d6 --- /dev/null +++ b/src/qt/qt_vmmanager_serversocket.cpp @@ -0,0 +1,207 @@ +/* +* 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. +* +* 86Box VM manager server socket module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed + */ + +#include "qt_vmmanager_serversocket.hpp" +#include +#include +#include +#include +#include +#include + +VMManagerServerSocket::VMManagerServerSocket(const QFileInfo &config_path, const ServerType type) +{ + server_type = type; + config_file = config_path; + serverIsRunning = false; + socket = nullptr; + server = new QLocalServer; + setupVars(); +} + +VMManagerServerSocket::~VMManagerServerSocket() +{ + delete server; +} + +bool +VMManagerServerSocket::startServer() { + + // Remove socket file (if it exists) in order to start a new one + qInfo("Socket path is %s", qPrintable(socket_path.filePath())); + if (socket_path.exists() and !socket_path.isDir()) { + auto socket_file = new QFile(socket_path.filePath()); + if (!socket_file->remove()) { + qInfo("Failed to remove the old socket file (Error %i): %s", socket_file->error(), qPrintable(socket_file->errorString())); + return false; + } + } + + if (server->listen(socket_path.fileName())) { + serverIsRunning = true; + connect(server, &QLocalServer::newConnection, this, &VMManagerServerSocket::serverConnectionReceived); + return true; + } else { + qInfo("Failed to start server: %s", qPrintable(server->errorString())); + serverIsRunning = false; + return false; + } +} + +void +VMManagerServerSocket::serverConnectionReceived() { + qDebug("Connection received on %s", qPrintable(socket_path.fileName())); + socket = server->nextPendingConnection(); + if(!socket) { + qInfo("Invalid socket when trying to receive the connection"); + return; + } + connect(socket, &QLocalSocket::readyRead, this, &VMManagerServerSocket::serverReceivedMessage); + connect(socket, &QLocalSocket::disconnected, this, &VMManagerServerSocket::serverDisconnected); +} + +void +VMManagerServerSocket::serverReceivedMessage() { + + // Handle legacy socket connections first. These connections only receive + // information on window status + if(server_type == VMManagerServerSocket::ServerType::Legacy) { + QByteArray tempString = socket->read(1); + int window_obscured = tempString.toInt(); + emit windowStatusChanged(window_obscured); + return; + } + + // Normal connections here + QDataStream stream(socket); + stream.setVersion(QDataStream::Qt_5_7); + QByteArray jsonData; + for (;;) { + // Start a transaction + stream.startTransaction(); + // Try to read the data + stream >> jsonData; + if (stream.commitTransaction()) { + QJsonParseError parse_error{}; + // Validate the received data to make sure it's valid json + const QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData, &parse_error); + if (parse_error.error == QJsonParseError::NoError) { + // The data received was valid json + if (jsonDoc.isObject()) { + // The data is a valid json object + emit dataReceived(); + jsonReceived(jsonDoc.object()); + } + } + // The data was not valid json. + // Loop and try to read more data + } else { + // read failed, socket is reverted to its previous state (before the transaction) + // exit the loop and wait for more data to become available + break; + } + } +} + +void +VMManagerServerSocket::serverSendMessage(VMManagerProtocol::ManagerMessage protocol_message, const QStringList& arguments) const { + if(!socket) { + qInfo("Cannot send message: Invalid socket"); + return; + } + + // Regular connection + QDataStream stream(socket); + stream.setVersion(QDataStream::Qt_5_7); + auto packet = new VMManagerProtocol(VMManagerProtocol::Sender::Manager); + auto jsonMessage = packet->protocolManagerMessage(protocol_message); + stream << QJsonDocument(jsonMessage).toJson(QJsonDocument::Compact); +} + +void +VMManagerServerSocket::serverDisconnected() +{ + qInfo("Connection disconnected"); +} +void +VMManagerServerSocket::jsonReceived(const QJsonObject &json) +{ + // The serialization portion has already validated the message as json. + // Now ensure it has the required fields. + if (!VMManagerProtocol::hasRequiredFields(json)) { + // TODO: Error handling of some sort, emit signals + qDebug("Invalid message received from client: required fields missing. Object:"); + qDebug() << json; + return; + } +// qDebug().noquote() << Q_FUNC_INFO << json; + QJsonObject params_object; + + auto message_type = VMManagerProtocol::getClientMessageType(json); + switch (message_type) { + case VMManagerProtocol::ClientMessage::Status: + qDebug("Status message received from client"); + break; + case VMManagerProtocol::ClientMessage::WindowBlocked: + qDebug("Window blocked message received from client"); + emit windowStatusChanged(static_cast(VMManagerProtocol::WindowStatus::WindowBlocked)); + break; + case VMManagerProtocol::ClientMessage::WindowUnblocked: + qDebug("Window unblocked received from client"); + emit windowStatusChanged(static_cast(VMManagerProtocol::WindowStatus::WindowUnblocked)); + break; + case VMManagerProtocol::ClientMessage::RunningStateChanged: + qDebug("Running state change received from client"); + params_object = VMManagerProtocol::getParams(json); + if (!params_object.isEmpty()) { + // valid object + if(params_object.value("status").type() == QJsonValue::Double) { + // has status key, value is an int (qt assigns it as Double) + emit runningStatusChanged(static_cast(params_object.value("status").toInt())); + } + } + break; + default: + qDebug("Unknown client message type received:"); + qDebug() << json; + return; + } +} + +void +VMManagerServerSocket::setupVars() +{ + QString unique_name = QCryptographicHash::hash(config_file.path().toUtf8().constData(), QCryptographicHash::Algorithm::Sha256).toHex().right(6); + socket_path.setFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/" + QApplication::applicationName() + ".socket." + unique_name); +} + +QString +VMManagerServerSocket::getSocketPath() const +{ + if (server) { + return server->fullServerName(); + } + return {}; +} + +QString +VMManagerServerSocket::serverTypeToString(VMManagerServerSocket::ServerType server_type_lookup) +{ + QMetaEnum qme = QMetaEnum::fromType(); + return qme.valueToKey(static_cast(server_type_lookup)); + +} diff --git a/src/qt/qt_vmmanager_serversocket.hpp b/src/qt/qt_vmmanager_serversocket.hpp new file mode 100644 index 000000000..3e6e43a80 --- /dev/null +++ b/src/qt/qt_vmmanager_serversocket.hpp @@ -0,0 +1,82 @@ +/* +* 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. +* +* Header for 86Box VM manager server socket module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed + */ + +#ifndef QT_VMMANAGER_SERVERSOCKET_H +#define QT_VMMANAGER_SERVERSOCKET_H + +#include +#include +#include +#include +#include +#include "qt_vmmanager_protocol.hpp" + +// This macro helps give us the required `qHash()` function in order to use the +// enum as a hash key +#define QHASH_FOR_CLASS_ENUM(T) \ +inline uint qHash(const T &t, uint seed) { \ + return ::qHash(static_cast::type>(t), seed); \ +} + +class VMManagerServerSocket : public QWidget { + + Q_OBJECT + +public: + + enum class ServerType { + Standard, + Legacy, + }; + // This macro allows us to do a reverse lookup of the enum with `QMetaEnum` + Q_ENUM(ServerType) + + QHASH_FOR_CLASS_ENUM(ServerType) + + explicit VMManagerServerSocket(const QFileInfo &config_path, ServerType type = ServerType::Standard); + ~VMManagerServerSocket() override; + + QFileInfo socket_path; + QFileInfo config_file; + + QLocalServer *server; + QLocalSocket *socket; + ServerType server_type; + bool serverIsRunning; + + // Server functions + bool startServer(); + void serverConnectionReceived(); + void serverReceivedMessage(); + void serverSendMessage(VMManagerProtocol::ManagerMessage protocol_message, const QStringList& arguments = QStringList()) const; + static void serverDisconnected(); + void jsonReceived(const QJsonObject &json); + QString getSocketPath() const; + + static QString serverTypeToString(ServerType server_type_lookup); + + void setupVars(); + +signals: + void dataReceived(); + void windowStatusChanged(int status); + void runningStatusChanged(VMManagerProtocol::RunningState state); + + +}; + +#endif // QT_VMMANAGER_SERVERSOCKET_H diff --git a/src/qt/qt_vmmanager_system.cpp b/src/qt/qt_vmmanager_system.cpp new file mode 100644 index 000000000..0a7382094 --- /dev/null +++ b/src/qt/qt_vmmanager_system.cpp @@ -0,0 +1,924 @@ +/* +* 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. +* +* 86Box VM manager system module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "qt_vmmanager_system.hpp" +// #include "qt_vmmanager_details_section.hpp" +#include "qt_vmmanager_detailsection.hpp" + + +extern "C" { +#include <86box/86box.h> +#include <86box/device.h> +#include <86box/video.h> +// #include <86box/vid_xga_device.h> +#include <86box/machine.h> +#include <86box/plat.h> +#include <86box/sound.h> +#include +#include <86box/thread.h> // required for network.h +#include <86box/timer.h> // required for network.h and fdd.h +#include <86box/cdrom.h> +#include <86box/scsi.h> +#include <86box/fdd.h> +#include <86box/gameport.h> +#include <86box/midi.h> +#include <86box/network.h> +#include <86box/mouse.h> +} + +using namespace VMManager; + +VMManagerSystem::VMManagerSystem(const QString &sysconfig_file) { + + // The 86Box configuration file + config_file = QFileInfo(sysconfig_file); + // The default name of the system. This is the name of the directory + // that contains the 86box configuration file + config_name = config_file.dir().dirName(); + // The full path of the directory that contains the 86box configuration file + config_dir = shortened_dir = config_file.dir().path(); + process_status = ProcessStatus::Stopped; + // Main 86Box uses usr_path for UUID which includes the trailing slash. + // Make sure to append the slash here so the UUIDs will match + auto uuid_path = config_dir; + if (!uuid_path.endsWith("/")) { + uuid_path.append("/"); + } + // In the configuration file the UUID is used as a unique value + uuid = QUuid::createUuidV5(QUuid{}, uuid_path).toString(QUuid::WithoutBraces); + // That unique value is used to map the information to each individual system. + config_settings = new VMManagerConfig(VMManagerConfig::ConfigType::System, uuid); + + // On non-windows platforms, shortened_dir will replace the home directory path with ~ + // and be used as the tool tip in the list view +#if not defined(Q_OS_WINDOWS) + if (config_dir.startsWith(QDir::homePath())) { + shortened_dir.replace(QDir::homePath(), "~"); + } +#endif + loadSettings(); + setupPaths(); + // Paths must be setup before vars! + setupVars(); + + serverIsRunning = false; + window_obscured = false; + + find86BoxBinary(); + platform = QApplication::platformName(); + process = new QProcess(); + connect(process, &QProcess::stateChanged, this, &VMManagerSystem::processStatusChanged); + + // Server type for this instance (Standard should always be used instead of Legacy) + socket_server_type = VMManagerServerSocket::ServerType::Standard; + socket_server = new VMManagerServerSocket(config_file, socket_server_type); + + // NOTE: When unique names or UUIDs are written to the individual VM config file, use that + // here instead of the auto-generated unique_name + // Save settings once everything is initialized + saveSettings(); +} + +VMManagerSystem::~VMManagerSystem() { + delete socket_server; +} + +QVector +VMManagerSystem::scanForConfigs(QWidget* parent, const QString &searchPath) +{ + QProgressDialog progDialog(parent); + unsigned int found = 0; + progDialog.setCancelButton(nullptr); + progDialog.setWindowTitle(tr("Searching for VMs...")); + progDialog.setMinimumDuration(0); + progDialog.setValue(0); + progDialog.setMinimum(0); + progDialog.setMaximum(0); + progDialog.setWindowFlags(progDialog.windowFlags() & ~Qt::WindowCloseButtonHint); + QElapsedTimer scanTimer; + scanTimer.start(); + QVector system_configs; + + const auto config = new VMManagerConfig(VMManagerConfig::ConfigType::General); + auto systemDirConfig = config->getStringValue("system_directory"); + + const auto config_file_name = QString("86box.cfg"); + const QStringList filters = {config_file_name}; + QStringList matches; + // TODO: Preferences. Once I get the CLI args worked out. + // For now it just takes vmm_path from the CLI + QString search_directory; + // if(searchPath.isEmpty()) { + // // If the location isn't specified in function call, use the one loaded + // // from the config file + // search_directory = systemDirConfig; + // } else { + // search_directory = searchPath; + // } + + search_directory = searchPath.isEmpty()? vmm_path : searchPath; + + if(!QDir(search_directory).exists()) { + //qWarning() << "Path" << search_directory << "does not exist. Cannot continue"; + QDir(search_directory).mkpath("."); + //return {}; + } + + QDirIterator dir_iterator(search_directory, filters, QDir::Files, QDirIterator::Subdirectories); + + qInfo("Searching %s for %s", qPrintable(search_directory), qPrintable(config_file_name)); + + QElapsedTimer timer; + timer.start(); + while (dir_iterator.hasNext()) { + found++; + progDialog.setLabelText(tr("Found %1").arg(QString::number(found))); + QApplication::processEvents(); + QString filename = dir_iterator.next(); + matches.append(filename); + } + + const auto scanElapsed = timer.elapsed(); + qDebug().noquote().nospace() << "Found " << matches.size() << " configs in " << search_directory <<". Scan took " << scanElapsed << " ms"; + + timer.restart(); + // foreach (QFileInfo hit, matches) { + // system_configs.append(new VMManagerSystem(hit)); + // } + progDialog.setMaximum(found); + progDialog.setValue(0); + unsigned int appended = 0; + for (const auto &filename : matches) { + system_configs.append(new VMManagerSystem(filename)); + appended++; + progDialog.setLabelText(system_configs.last()->displayName); + progDialog.setValue(appended); + QApplication::processEvents(); + } + if (matches.size()) { + auto elapsed = timer.elapsed(); + qDebug() << "Load loop took" << elapsed << "ms for" << matches.size() << "loads"; + qDebug() << "Overall scan time was" << scanTimer.elapsed() << "ms, average" << elapsed / matches.size() << "ms / load"; + } + return system_configs; +} + +QString +VMManagerSystem::generateTemporaryFilename() +{ + QTemporaryFile tempFile; + // File will be closed once the QTemporaryFile object goes out of scope + tempFile.setAutoRemove(true); + tempFile.open(); + return tempFile.fileName(); +} + +QFileInfoList +VMManagerSystem::getScreenshots() { + + // Don't bother unless the directory exists + if(!screenshot_directory.exists()) { + return {}; + } + + auto screen_scan_dir = QDir(screenshot_directory.path(), "Monitor_1*", QDir::SortFlag::LocaleAware | QDir::SortFlag::IgnoreCase, QDir::Files); + auto screenshot_files = screen_scan_dir.entryInfoList(); + return screenshot_files; +} + +void +VMManagerSystem::loadSettings() +{ + // First, load the information from the 86box.cfg + QSettings settings(config_file.filePath(), QSettings::IniFormat); + if (settings.status() != QSettings::NoError) { + qWarning() << "Error loading" << config_file.path() << " status:" << settings.status(); + } + // qInfo() << "Loaded "<< config_file.filePath() << "status:" << settings.status(); + + // Clear out the config hash in case the config is reloaded + for (const auto &outer_key : config_hash.keys()) { + config_hash[outer_key].clear(); + } + + // General + for (const auto &key_name : settings.childKeys()) { + config_hash["General"][key_name] = settings.value(key_name).toString(); + } + + for (auto &group_name : settings.childGroups()) { + settings.beginGroup(group_name); + for (const auto &key_name : settings.allKeys()) { + QString setting_value; + // QSettings will interpret lines with commas as QStringList. + // Check for it and join them back to a string. + if (settings.value(key_name).type() == QVariant::StringList) { + setting_value = settings.value(key_name).toStringList().join(", "); + } else { + setting_value = settings.value(key_name).toString(); + } + config_hash[group_name][key_name] = setting_value; + } + settings.endGroup(); + } + + // Next, load the information from the vmm config for this system + // Display name + auto loadedDisplayName = config_settings->getStringValue("display_name"); + if (!loadedDisplayName.isEmpty()) { + displayName = loadedDisplayName; + } else { + displayName = config_name; + } + // Notes + auto loadedNotes = config_settings->getStringValue("notes"); + if (!loadedNotes.isEmpty()) { + notes = loadedNotes; + } + // Timestamp + auto loadedTimestamp = config_settings->getStringValue("timestamp"); + if (!loadedTimestamp.isEmpty()) { + // Make sure it is valid + if (auto newTimestamp = QDateTime::fromString(loadedTimestamp, Qt::ISODate); newTimestamp.isValid()) { + lastUsedTimestamp = newTimestamp; + } + } + // Icon + auto loadedIcon = config_settings->getStringValue("icon"); + if (!loadedIcon.isEmpty()) { + icon = loadedIcon; + } +} +void +VMManagerSystem::saveSettings() +{ + if(!isValid()) { + return; + } + config_settings->setStringValue("system_name", config_name); + config_settings->setStringValue("config_file", config_file.canonicalFilePath()); + config_settings->setStringValue("config_dir", config_file.canonicalPath()); + if (displayName != config_name) { + config_settings->setStringValue("display_name", displayName); + } else { + config_settings->remove("display_name"); + } + + config_settings->setStringValue("notes", notes); + if(lastUsedTimestamp.isValid()) { + config_settings->setStringValue("timestamp", lastUsedTimestamp.toString(Qt::ISODate)); + } + config_settings->setStringValue("icon", icon); + generateSearchTerms(); +} +void +VMManagerSystem::generateSearchTerms() +{ + searchTerms.clear(); + for (const auto &config_key : config_hash.keys()) { + // searchTerms.append(config_hash[config_key].values()); + // brute force temporarily don't add paths + for(const auto &value: config_hash[config_key].values()) { + if(!value.startsWith("/")) { + searchTerms.append(value); + } + } + } + searchTerms.append(display_table.values()); + searchTerms.append(displayName); + searchTerms.append(config_name); + QRegularExpression whitespaceRegex("\\s+"); + searchTerms.append(notes.split(whitespaceRegex)); +} +void +VMManagerSystem::updateTimestamp() +{ + lastUsedTimestamp = QDateTime::currentDateTimeUtc(); + saveSettings(); +} + +QString +VMManagerSystem::getAll(const QString& category) const { + auto value = config_hash[category].keys().join(", "); + return value; +} + +QHash> +VMManagerSystem::getConfigHash() const +{ + return config_hash; +} + +void +VMManagerSystem::setDisplayName(const QString &newDisplayName) +{ + // If blank, reset to the default + if (newDisplayName.isEmpty()) { + displayName = config_name; + } else { + displayName = newDisplayName; + } + saveSettings(); +} +void +VMManagerSystem::setNotes(const QString &newNotes) +{ + notes = newNotes; + saveSettings(); +} +bool +VMManagerSystem::isValid() const +{ + return config_file.exists() && config_file.isFile() && config_file.size() != 0; +} + +bool +VMManagerSystem::isProcessRunning() const +{ + return process->processId() != 0; +} + +qint64 +VMManagerSystem::processId() const +{ + return process->processId(); +} + +QHash +VMManagerSystem::getCategory(const QString &category) const { + return config_hash[category]; +} + +void +VMManagerSystem::find86BoxBinary() { + // We'll use our own self to launch the VMs + main_binary = QFileInfo(QCoreApplication::applicationFilePath()); +} + +bool +VMManagerSystem::has86BoxBinary() { + return main_binary.exists(); +} + +void +VMManagerSystem::launchMainProcess() { + + if(!has86BoxBinary()) { + qWarning("No binary found! returning"); + return; + } + + // start the server first to get the socket name + if (!serverIsRunning) { + if(!startServer()) { + // FIXME: Better error handling + qInfo("Failed to start VM Manager server"); + return; + } + } + setProcessEnvVars(); + QString program = main_binary.filePath(); + QStringList args; + args << "-P" << config_dir; + args << "--vmname" << displayName; + process->setProgram(program); + process->setArguments(args); + qDebug() << Q_FUNC_INFO << " Full Command:" << process->program() << " " << process->arguments(); + process->start(); + updateTimestamp(); +} + +void +VMManagerSystem::startButtonPressed() { + launchMainProcess(); +} + +void +VMManagerSystem::launchSettings() { + if(!has86BoxBinary()) { + qWarning("No binary found! returning"); + return; + } + + // If the system is already running, instruct it to show settings + if (process->processId() != 0) { + socket_server->serverSendMessage(VMManagerProtocol::ManagerMessage::ShowSettings); + return; + } + + // Otherwise, launch the system with the settings parameter + setProcessEnvVars(); + QString program = main_binary.filePath(); + QStringList open_command_args; + QStringList args; + args << "-P" << config_dir << "-S"; + process->setProgram(program); + process->setArguments(args); + qDebug() << Q_FUNC_INFO << " Full Command:" << process->program() << " " << process->arguments(); + process->start(); +} + +void +VMManagerSystem::setupPaths() { + // application_temp_directory.setPath(QStandardPaths::writableLocation(QStandardPaths::TempLocation)); + // standard_temp_directory.setPath(QStandardPaths::writableLocation(QStandardPaths::TempLocation)); + // QString temp_subdir = QApplication::applicationName(); + // if (!application_temp_directory.exists(temp_subdir)) { + // // FIXME: error checking + // application_temp_directory.mkdir(temp_subdir); + // } + // // QT always replaces `/` with native separators, so it is safe to use here for all platforms + // application_temp_directory.setPath(application_temp_directory.path() + "/" + temp_subdir); + // app_data_directory.setPath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); + // // TODO: come back here and update with the new plat_get_global_* + // if (!app_data_directory.exists()) { + // // FIXME: Error checking + // app_data_directory.mkpath(app_data_directory.path()); + // } + screenshot_directory.setPath(config_dir + "/" + "screenshots"); +} + +void +VMManagerSystem::setupVars() { + unique_name = QCryptographicHash::hash(config_file.path().toUtf8().constData(), QCryptographicHash::Algorithm::Sha256).toHex().right(9); + // unique_name = "aaaaaa"; + // Set up the display vars + // This will likely get moved out to its own class + // This will likely get moved out to its own class + auto machine_config = getCategory("Machine"); + auto video_config = getCategory("Video"); + auto disk_config = getCategory("Hard disks"); + auto audio_config = getCategory("Sound"); + auto network_config = getCategory("Network"); + auto input_config = getCategory("Input devices"); + auto floppy_cdrom_config = getCategory("Floppy and CD-ROM drives"); + auto scsi_config = getCategory("Storage controllers"); + auto ports_config = getCategory("Ports (COM & LPT)"); + // auto general_config = getCategory("General"); + // auto config_uuid = QString("Not set"); + // if(!general_config["uuid"].isEmpty()) { + // config_uuid = general_config["uuid"]; + // qDebug() << "btw config dir:" << config_dir; + // } + // qDebug() << "Generated UUID:" << uuid; + // qDebug() << "Config file UUID:" << config_uuid; + auto machine_name = QString(); + int i = 0; + int ram_granularity = 0; + // Machine + for (int ci = 0; ci < machine_count(); ++ci) { + if (machine_available(ci)) { + if (machines[ci].internal_name == machine_config["machine"]) { + machine_name = machines[ci].name; + ram_granularity = machines[ci].ram.step; + } + } + } + display_table[Display::Name::Machine] = machine_name; + + // CPU: Combine name with speed + auto cpu_name = QString(); + while (cpu_families[i].package != 0) { + if (cpu_families[i].internal_name == machine_config["cpu_family"]) { + cpu_name = QString("%1 %2").arg(cpu_families[i].manufacturer, cpu_families[i].name); + } + i++; + } + int speed_display = machine_config["cpu_speed"].toInt() / 1000000; + cpu_name.append(QString::number(speed_display).prepend(" / ")); + cpu_name.append(QCoreApplication::translate("", "MHz").prepend(' ')); + display_table[Display::Name::CPU] = cpu_name; + + // Memory + int divisor = (ram_granularity < 1024) ? 1 : 1024; + QString display_unit = (divisor == 1) ? "KB" : "MB"; + auto mem_display = QString::number(machine_config["mem_size"].toInt() / divisor); + mem_display.append(QCoreApplication::translate("", display_unit.toUtf8().constData()).prepend(' ')); + display_table[Display::Name::Memory] = mem_display; + + // Video card + int video_int = video_get_video_from_internal_name(video_config["gfxcard"].toUtf8().data()); + const device_t* video_dev = video_card_getdevice(video_int); + display_table[Display::Name::Video] = DeviceConfig::DeviceName(video_dev, video_get_internal_name(video_int), 1); + if (!video_config["voodoo"].isEmpty()) { + // FIXME: Come back to this later to add more for secondary video +// display_table[Display::Name::Video].append(" (with voodoo)"); + display_table[Display::Name::Voodoo] = "Voodoo enabled"; + } + + // Drives + // First the number of disks + QMap disks; + for(const auto& key: disk_config.keys()) { + // Assuming the format hdd_NN_* + QStringList pieces = key.split('_'); + QString disk = QString("%1_%2").arg(pieces.at(0), pieces.at(1)); + if(!disk.isEmpty()) { + disks[disk] = 1; + } + } + // Next, the types + QHash bus_types; + for (const auto& key: disks.keys()) { + auto disk_parameter_key = QString("%1_parameters").arg(key); + QStringList pieces = disk_config[disk_parameter_key].split(","); + QString bus_type = pieces.value(pieces.length() - 1).trimmed(); + bus_types[bus_type] = 1; + } + QString disks_display = tr("%n disk(s)", "", disks.count()); + if (disks.count()) { + disks_display.append(" / ").append(bus_types.keys().join(", ").toUpper()); + } +// display_table[Display::Name::Disks] = disks_display; + + // Drives + QString new_disk_display; + for (const auto& key: disks.keys()) { + auto disk_parameter_key = QString("%1_parameters").arg(key); + // Converting a string to an int back to a string to remove the zero (e.g. 01 to 1) + auto disk_number = QString::number(key.split("_").last().toInt()); + QStringList pieces = disk_config[disk_parameter_key].split(","); + QString sectors = pieces.value(0).trimmed(); + QString heads = pieces.value(1).trimmed(); + QString cylinders = pieces.value(2).trimmed(); + QString bus_type = pieces.value(pieces.length() - 1).trimmed(); + // Add separator for each subsequent value, skipping the first + if(!new_disk_display.isEmpty()) { + new_disk_display.append(QString("%1").arg(VMManagerDetailSection::sectionSeparator)); + } + int diskSizeRaw = (cylinders.toInt() * heads.toInt() * sectors.toInt()) >> 11; + QString diskSizeFinal; + QString unit = "MiB"; + if(diskSizeRaw > 1000) { + unit = "GiB"; + diskSizeFinal = QString::number(diskSizeRaw * 1.0 / 1000, 'f', 1); + } else { + diskSizeFinal = QString::number(diskSizeRaw); + } + // Only prefix each disk when there are multiple disks + QString diskNumberDisplay = disks.count() > 1 ? QString("Disk %1: ").arg(disk_number) : ""; + new_disk_display.append(QString("%1%2 %3 (%4)").arg(diskNumberDisplay, diskSizeFinal, unit, bus_type.toUpper())); + } + if(new_disk_display.isEmpty()) { + new_disk_display = "No disks"; + } + display_table[Display::Name::Disks] = new_disk_display; + + // Floppy & CD-ROM + QStringList floppyDevices; + QStringList cdromDevices; + static auto floppy_match = QRegularExpression("fdd_\\d\\d_type", QRegularExpression::CaseInsensitiveOption); + static auto cdrom_match = QRegularExpression("cdrom_\\d\\d_type", QRegularExpression::CaseInsensitiveOption); + for(const auto& key: floppy_cdrom_config.keys()) { + if(key.contains(floppy_match)) { + // auto device_number = key.split("_").at(1); + auto floppy_internal_name = QString(floppy_cdrom_config[key]); + // Not interested in the nones + if(floppy_internal_name == "none") { + continue; + } + auto floppy_type = fdd_get_from_internal_name(floppy_internal_name.toUtf8().data()); + if(auto fddName = QString(fdd_getname(floppy_type)); !fddName.isEmpty()) { + floppyDevices.append(fddName); + } + } + if(key.contains(cdrom_match)) { + auto device_number = key.split("_").at(1); + auto cdrom_internal_name = QString(floppy_cdrom_config[key]); + auto cdrom_type = cdrom_get_from_internal_name(cdrom_internal_name.toUtf8().data()); + + auto cdrom_speed_key = QString("cdrom_%1_speed").arg(device_number); + auto cdrom_parameters_key = QString("cdrom_%1_parameters").arg(device_number); + auto cdrom_speed = QString(floppy_cdrom_config[cdrom_speed_key]); + auto cdrom_parameters = QString(floppy_cdrom_config[cdrom_parameters_key]); + auto cdrom_bus = cdrom_parameters.split(",").at(1).trimmed().toUpper(); + + if(cdrom_type != -1) { + if(!cdrom_speed.isEmpty()) { + cdrom_speed = QString("%1x ").arg(cdrom_speed); + } + if(!cdrom_bus.isEmpty()) { + cdrom_bus = QString(" (%1)").arg(cdrom_bus); + } + cdromDevices.append(QString("%1%2 %3 %4%5").arg(cdrom_speed, cdrom_drive_types[cdrom_type].vendor, cdrom_drive_types[cdrom_type].model, cdrom_drive_types[cdrom_type].revision, cdrom_bus)); + } + } + } + + display_table[Display::Name::Floppy] = floppyDevices.join(VMManagerDetailSection::sectionSeparator); + display_table[Display::Name::CD] = cdromDevices.join(VMManagerDetailSection::sectionSeparator); + + // SCSI controllers + QStringList scsiControllers; + static auto scsi_match = QRegularExpression("scsicard_\\d", QRegularExpression::CaseInsensitiveOption); + for(const auto& key: scsi_config.keys()) { + if(key.contains(scsi_match)) { + auto device_number = key.split("_").at(1); + auto scsi_internal_name = QString(scsi_config[key]); + auto scsi_id = scsi_card_get_from_internal_name(scsi_internal_name.toUtf8().data()); + auto scsi_device = scsi_card_getdevice(scsi_id); + auto scsi_name = QString(scsi_device->name); + if(!scsi_name.isEmpty()) { + scsiControllers.append(scsi_name); + } + } + } + display_table[Display::Name::SCSIController] = scsiControllers.join(VMManagerDetailSection::sectionSeparator); + + // Audio + int sound_int = sound_card_get_from_internal_name(audio_config["sndcard"].toUtf8().data()); + const device_t* audio_dev = sound_card_getdevice(sound_int); + display_table[Display::Name::Audio] = DeviceConfig::DeviceName(audio_dev, sound_card_get_internal_name(sound_int), 1); + + // MIDI + QString midiOutDev; + if(auto midi_out_device = QString(audio_config["midi_device"]); !midi_out_device.isEmpty()) { + auto midi_device_int = midi_out_device_get_from_internal_name(midi_out_device.toUtf8().data()); + auto midi_out = midi_out_device_getdevice(midi_device_int); + if(auto midiDevName = QString(midi_out->name); !midiDevName.isEmpty()) { + midiOutDev = midiDevName; + } + } + display_table[Display::Name::MidiOut] = midiOutDev; + + // midi_device = mt32 (output) + // mpu401_standalone = 1 + // midi_in_device (input) + + // Network + QString nicList; + static auto nic_match = QRegularExpression("net_\\d\\d_card", QRegularExpression::CaseInsensitiveOption); + for(const auto& key: network_config.keys()) { + if(key.contains(nic_match)) { + auto device_number = key.split("_").at(1); + auto nic_internal_name = QString(network_config[key]); + auto nic_id = network_card_get_from_internal_name(nic_internal_name.toUtf8().data()); + auto nic = network_card_getdevice(nic_id); + auto nic_name = QString(nic->name); + // Add separator for each subsequent value, skipping the first + if(!nicList.isEmpty()) { + nicList.append(QString("%1").arg(VMManagerDetailSection::sectionSeparator)); + } + auto net_type_key = QString("net_%1_net_type").arg(device_number); + auto net_type = network_config[net_type_key]; + if (!net_type.isEmpty()) { + nicList.append(nic_name + " (" + net_type + ")"); + } else { + nicList.append(nic_name); + } + + } + } + if(nicList.isEmpty()) { + nicList = "None"; + } + display_table[Display::Name::NIC] = nicList; + + // Input (Mouse) + auto mouse_internal_name = input_config["mouse_type"]; + auto mouse_dev = mouse_get_from_internal_name(mouse_internal_name.toUtf8().data()); + auto mouse_dev_name = mouse_get_name(mouse_dev); + display_table[Display::Name::Mouse] = mouse_dev_name; + + // Input (joystick) + QString joystickDevice; + if(auto joystick_internal = QString(input_config["joystick_type"]); !joystick_internal.isEmpty()) { + auto joystick_dev = joystick_get_from_internal_name(joystick_internal.toUtf8().data()); + if (auto joystickName = QString(joystick_get_name(joystick_dev)); !joystickName.isEmpty()) { + joystickDevice = joystickName; + } + } + display_table[Display::Name::Joystick] = joystickDevice; + + // # Ports + // Serial + // By default serial 1 and 2 are enabled unless otherwise specified + static auto serial_match = QRegularExpression("serial\\d_enabled", QRegularExpression::CaseInsensitiveOption); + QList serial_enabled = {true, true, false, false, false, false, false, false}; + // Parallel + // By default lpt 1 is enabled unless otherwise specified + static auto lpt_match = QRegularExpression("lpt\\d_enabled", QRegularExpression::CaseInsensitiveOption); + QList lpt_enabled = {true, false, false, false}; + for (const auto &key: ports_config.keys()) { + if (key.contains(serial_match)) { + if (auto serial_dev = key.split("_").at(0); !serial_dev.isEmpty()) { + auto serial_num = serial_dev.at(serial_dev.size() - 1); + // qDebug() << "serial is set" << key << ":" << ports_config[key]; + if(serial_num.isDigit() && serial_num.digitValue() >= 1 && serial_num.digitValue() <= 4) { + // Already verified that it is a digit with isDigit() + serial_enabled[serial_num.digitValue() - 1] = ports_config[key].toInt() == 1; + } + } + } + if (key.contains(lpt_match)) { + if (auto lpt_dev = key.split("_").at(0); !lpt_dev.isEmpty()) { + auto lpt_num = lpt_dev.at(lpt_dev.size() - 1); + // qDebug() << "lpt is set" << key << ":" << ports_config[key]; + if (lpt_num.isDigit() && lpt_num.digitValue() >= 1 && lpt_num.digitValue() <= 4) { + lpt_enabled[lpt_num.digitValue() - 1] = ports_config[key].toInt() == 1; + } + } + } + } + // qDebug() << "ports final" << serial_enabled << lpt_enabled; + QStringList serialFinal; + QStringList lptFinal; + int portIndex = 0; + while (true) { + if (serial_enabled[portIndex]) + serialFinal.append(QString("COM%1").arg(portIndex + 1)); + ++portIndex; + if (portIndex == SERIAL_MAX) + break; + } + portIndex = 0; + while (true) { + if (lpt_enabled[portIndex]) + lptFinal.append(QString("LPT%1").arg(portIndex + 1)); + ++portIndex; + if (portIndex == PARALLEL_MAX) + break; + } + display_table[Display::Name::Serial] = serialFinal.empty() ? tr("None") : serialFinal.join(", "); + display_table[Display::Name::Parallel] = lptFinal.empty() ? tr("None") : lptFinal.join(", "); + +} + +bool +VMManagerSystem::startServer() { + if (socket_server->startServer()) { + serverIsRunning = true; + connect(socket_server, &VMManagerServerSocket::dataReceived, this, &VMManagerSystem::dataReceived); + connect(socket_server, &VMManagerServerSocket::windowStatusChanged, this, &VMManagerSystem::windowStatusChangeReceived); + connect(socket_server, &VMManagerServerSocket::runningStatusChanged, this, &VMManagerSystem::runningStatusChangeReceived); + return true; + } else { + return false; + } +} + +void +VMManagerSystem::setProcessEnvVars() { + QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); + QString env_var_name = (socket_server_type == VMManagerServerSocket::ServerType::Standard) ? "VMM_86BOX_SOCKET" : "86BOX_MANAGER_SOCKET"; + env.insert(env_var_name, socket_server->getSocketPath()); + process->setProcessEnvironment(env); +} + +void +VMManagerSystem::restartButtonPressed() { + socket_server->serverSendMessage(VMManagerProtocol::ManagerMessage::ResetVM); + +} + +void +VMManagerSystem::pauseButtonPressed() { + socket_server->serverSendMessage(VMManagerProtocol::ManagerMessage::Pause); +} +void +VMManagerSystem::dataReceived() +{ + qInfo() << Q_FUNC_INFO << "Note: Respond to data received events here."; +} +void +VMManagerSystem::windowStatusChangeReceived(int status) +{ + window_obscured = status; + emit windowStatusChanged(); + processStatusChanged(); +} +QString +VMManagerSystem::getDisplayValue(Display::Name key) +{ + return (display_table.contains(key)) ? display_table[key] : ""; +} + +void +VMManagerSystem::shutdownRequestButtonPressed() +{ + socket_server->serverSendMessage(VMManagerProtocol::ManagerMessage::RequestShutdown); +} + +void +VMManagerSystem::shutdownForceButtonPressed() +{ + socket_server->serverSendMessage(VMManagerProtocol::ManagerMessage::ForceShutdown); +} + +void +VMManagerSystem::cadButtonPressed() +{ + socket_server->serverSendMessage(VMManagerProtocol::ManagerMessage::CtrlAltDel); +} + +void +VMManagerSystem::processStatusChanged() +{ + // set to running if the process is running and the state is stopped + if (process->state() == QProcess::ProcessState::Running) { + if (process_status == VMManagerSystem::ProcessStatus::Stopped) { + process_status = VMManagerSystem::ProcessStatus::Running; + } + } else if (process->state() == QProcess::ProcessState::NotRunning) { + process_status = VMManagerSystem::ProcessStatus::Stopped; + } + emit itemDataChanged(); + emit clientProcessStatusChanged(); +} +void +VMManagerSystem::statusRefresh() +{ + processStatusChanged(); +} +QString +VMManagerSystem::processStatusToString(VMManagerSystem::ProcessStatus status) +{ +// QMetaEnum qme = QMetaEnum::fromType(); +// return qme.valueToKey(static_cast(status)); + switch (status) { + case VMManagerSystem::ProcessStatus::Stopped: + return tr("Powered Off"); + case VMManagerSystem::ProcessStatus::Running: + return tr("Running"); + case VMManagerSystem::ProcessStatus::Paused: + return tr("Paused"); + case VMManagerSystem::ProcessStatus::PausedWaiting: + case VMManagerSystem::ProcessStatus::RunningWaiting: + return tr("Paused (Waiting)"); + default: + return tr("Unknown Status"); + } +} + +QString +VMManagerSystem::getProcessStatusString() const +{ + return processStatusToString(process_status); +} + +VMManagerSystem::ProcessStatus +VMManagerSystem::getProcessStatus() const +{ + return process_status; +} +// Maps VMManagerProtocol::RunningState to VMManagerSystem::ProcessStatus +void +VMManagerSystem::runningStatusChangeReceived(VMManagerProtocol::RunningState state) +{ + if(state == VMManagerProtocol::RunningState::Running) { + process_status = VMManagerSystem::ProcessStatus::Running; + } else if(state == VMManagerProtocol::RunningState::Paused) { + process_status = VMManagerSystem::ProcessStatus::Paused; + } else if(state == VMManagerProtocol::RunningState::RunningWaiting) { + process_status = VMManagerSystem::ProcessStatus::RunningWaiting; + } else if(state == VMManagerProtocol::RunningState::PausedWaiting) { + process_status = VMManagerSystem::ProcessStatus::PausedWaiting; + } else { + process_status = VMManagerSystem::ProcessStatus::Unknown; + } + processStatusChanged(); +} +void +VMManagerSystem::reloadConfig() +{ + loadSettings(); + setupVars(); +} + +QDateTime +VMManagerSystem::timestamp() +{ + return lastUsedTimestamp; +} +void +VMManagerSystem::setIcon(const QString &newIcon) +{ + icon = newIcon; + saveSettings(); + emit itemDataChanged(); +} diff --git a/src/qt/qt_vmmanager_system.hpp b/src/qt/qt_vmmanager_system.hpp new file mode 100644 index 000000000..6ac0a7635 --- /dev/null +++ b/src/qt/qt_vmmanager_system.hpp @@ -0,0 +1,194 @@ +/* +* 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. +* +* Header for 86Box VM manager system module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#ifndef QT_VMMANAGER_SYSTEM_H +#define QT_VMMANAGER_SYSTEM_H + +#include +#include +#include +#include +#include +#include "qt_vmmanager_serversocket.hpp" +#include "qt_vmmanager_config.hpp" +#include "qt_deviceconfig.hpp" + +// This macro helps give us the required `qHash()` function in order to use the +// enum as a hash key +#define QHASH_FOR_CLASS_ENUM(T) \ +inline uint qHash(const T &t, uint seed) { \ + return ::qHash(static_cast::type>(t), seed); \ +} + +namespace VMManager { +Q_NAMESPACE +namespace Display { +Q_NAMESPACE +enum class Name { + Machine, + CPU, + Memory, + Video, + Disks, + Floppy, + CD, + SCSIController, + MidiOut, + Joystick, + Serial, + Parallel, + Audio, + Voodoo, + NIC, + Mouse, + Unknown +}; +Q_ENUM_NS(Name) +QHASH_FOR_CLASS_ENUM(Name) +} +} + +class VMManagerSystem : public QWidget { + Q_OBJECT + + typedef QHash display_table_t; + typedef QHash > config_hash_t; + +public: + + enum class ProcessStatus { + Stopped, + Running, + Paused, + PausedWaiting, + RunningWaiting, + Unknown, + }; + Q_ENUM(ProcessStatus); + + explicit VMManagerSystem(const QString &sysconfig_file); + // Default constructor will generate a temporary filename as the config file + // but it will not be valid (isValid() will return false) + VMManagerSystem() : VMManagerSystem(generateTemporaryFilename()) {} + + ~VMManagerSystem() override; + + static QVector scanForConfigs(QWidget* parent = nullptr, const QString &searchPath = {}); + static QString generateTemporaryFilename(); + + QFileInfo config_file; + QString config_name; + QString config_dir; + QString shortened_dir; + QString uuid; + QString displayName; + QString notes; + QString icon; + QStringList searchTerms; + + config_hash_t config_hash; + + [[nodiscard]] QString getAll(const QString& category) const; + [[nodiscard]] QHash getCategory(const QString& category) const; + [[nodiscard]] QHash > getConfigHash() const; + + void setDisplayName(const QString& newDisplayName); + void setNotes(const QString& newNotes); + + [[nodiscard]] bool isValid() const; + [[nodiscard]] bool isProcessRunning() const; + [[nodiscard]] qint64 processId() const; +public slots: + void launchMainProcess(); + void launchSettings(); + void startButtonPressed(); + void restartButtonPressed(); + void pauseButtonPressed(); + void shutdownRequestButtonPressed(); + void shutdownForceButtonPressed(); + void cadButtonPressed(); + void reloadConfig(); +public: + QDateTime timestamp(); + void setIcon(const QString &newIcon); + + QProcess *process = new QProcess(); + + bool window_obscured; + + QString getDisplayValue(VMManager::Display::Name key); + QFileInfoList getScreenshots(); + + inline bool operator==(const VMManagerSystem &rhs) const + { + return config_file.filePath() == rhs.config_file.filePath(); + } + + static QString + processStatusToString(VMManagerSystem::ProcessStatus status) ; + ProcessStatus process_status; + [[nodiscard]] QString getProcessStatusString() const; + [[nodiscard]] ProcessStatus getProcessStatus() const; + +signals: + void windowStatusChanged(); + void itemDataChanged(); + void clientProcessStatusChanged(); + +private: + void loadSettings(); + void saveSettings(); + void generateSearchTerms(); + void updateTimestamp(); + + display_table_t display_table; + + QFileInfo main_binary; + QString platform; + + // QDir application_temp_directory; + // QDir standard_temp_directory; + // QDir app_data_directory; + QDir screenshot_directory; + + QString unique_name; + QDateTime lastUsedTimestamp; + + VMManagerServerSocket *socket_server; + VMManagerServerSocket::ServerType socket_server_type; + + // Configuration file settings + VMManagerConfig *config_settings; + + bool serverIsRunning; + bool startServer(); + + bool has86BoxBinary(); + void find86BoxBinary(); + void setupPaths(); + void setupVars(); + void setProcessEnvVars(); + + void dataReceived(); + void windowStatusChangeReceived(int status); + void runningStatusChangeReceived(VMManagerProtocol::RunningState state); + void processStatusChanged(); + void statusRefresh(); +}; + + +#endif //QT_VMMANAGER_SYSTEM_H diff --git a/src/qt/qt_vulkanrenderer.cpp b/src/qt/qt_vulkanrenderer.cpp index 9227cdcb3..2306661ec 100644 --- a/src/qt/qt_vulkanrenderer.cpp +++ b/src/qt/qt_vulkanrenderer.cpp @@ -30,10 +30,11 @@ ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ** ****************************************************************************/ +#include "qt_vulkanrenderer.hpp" #include #include -#include "qt_vulkanrenderer.hpp" + #if QT_CONFIG(vulkan) # include @@ -676,7 +677,7 @@ VulkanRenderer2::initResources() v_texcoord = texcoord; gl_Position = ubuf.mvp * position; } -#endif +#endif /* 0 */ VkShaderModule vertShaderModule = createShader(QStringLiteral(":/texture_vert.spv")); #if 0 #version 440 @@ -691,7 +692,7 @@ VulkanRenderer2::initResources() { fragColor = texture(tex, v_texcoord); } -#endif +#endif /* 0 */ VkShaderModule fragShaderModule = createShader(QStringLiteral(":/texture_frag.spv")); // Graphics pipeline @@ -969,10 +970,11 @@ VulkanRenderer2::startNextFrame() 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.x = destination.x(); + viewport.y = destination.y(); + viewport.width = destination.width(); + viewport.height = destination.height(); + viewport.minDepth = 0; viewport.maxDepth = 1; m_devFuncs->vkCmdSetViewport(cb, 0, 1, &viewport); @@ -1009,4 +1011,4 @@ VulkanRenderer2::startNextFrame() m_window->frameReady(); m_window->requestUpdate(); // render continuously, throttled by the presentation rate } -#endif +#endif /* QT_CONFIG(vulkan) */ diff --git a/src/qt/qt_vulkanrenderer.hpp b/src/qt/qt_vulkanrenderer.hpp index d4580d848..2c131e5d7 100644 --- a/src/qt/qt_vulkanrenderer.hpp +++ b/src/qt/qt_vulkanrenderer.hpp @@ -31,6 +31,8 @@ ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ** ****************************************************************************/ +#ifndef VULKANRENDERER_HPP +#define VULKANRENDERER_HPP #include #include @@ -90,4 +92,6 @@ private: QMatrix4x4 m_proj; }; -#endif +#endif // QT_CONFIG(vulkan) + +#endif // VULKANRENDERER_HPP diff --git a/src/qt/qt_vulkanwindowrenderer.cpp b/src/qt/qt_vulkanwindowrenderer.cpp index 60ad5be96..d0fbb39a3 100644 --- a/src/qt/qt_vulkanwindowrenderer.cpp +++ b/src/qt/qt_vulkanwindowrenderer.cpp @@ -1,3 +1,35 @@ +/**************************************************************************** +** +** 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 "qt_vulkanwindowrenderer.hpp" #include @@ -697,7 +729,7 @@ public: # if VK_HEADER_VERSION >= 135 && VK_HEADER_VERSION < 162 case VK_ERROR_INCOMPATIBLE_VERSION_KHR: return "VK_ERROR_INCOMPATIBLE_VERSION_KHR"; -# endif +# endif /* VK_HEADER_VERSION >= 135 && VK_HEADER_VERSION < 162 */ case VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT: return "VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT"; case VK_ERROR_NOT_PERMITTED_EXT: @@ -788,7 +820,7 @@ public: m_devFuncs->vkDeviceWaitIdle(m_window->device()); } }; -# endif +# endif /* 0*/ VulkanWindowRenderer::VulkanWindowRenderer(QWidget *parent) : QVulkanWindow(parent->windowHandle()) @@ -814,6 +846,7 @@ VulkanWindowRenderer::createRenderer() void VulkanWindowRenderer::resizeEvent(QResizeEvent *event) { + this->pixelRatio = devicePixelRatio(); onResize(width(), height()); QVulkanWindow::resizeEvent(event); @@ -836,8 +869,10 @@ VulkanWindowRenderer::onBlit(int buf_idx, int x, int y, int w, int h) if (isExposed()) requestUpdate(); buf_usage[0].clear(); - if (origSource != source) + if (origSource != source) { + this->pixelRatio = devicePixelRatio(); onResize(this->width(), this->height()); + } } uint32_t @@ -851,4 +886,4 @@ VulkanWindowRenderer::getBuffers() { return std::vector { std::make_tuple((uint8_t *) renderer->mappedPtr, &this->buf_usage[0]) }; } -#endif +#endif /* QT_CONFIG(vulkan) */ diff --git a/src/qt/qt_vulkanwindowrenderer.hpp b/src/qt/qt_vulkanwindowrenderer.hpp index 828d091e6..de9f46b6f 100644 --- a/src/qt/qt_vulkanwindowrenderer.hpp +++ b/src/qt/qt_vulkanwindowrenderer.hpp @@ -35,6 +35,6 @@ private: VulkanRenderer2 *renderer; }; -#endif +#endif // QT_CONFIG(vulkan) #endif // VULKANWINDOWRENDERER_HPP diff --git a/src/qt/qt_winrawinputfilter.cpp b/src/qt/qt_winrawinputfilter.cpp index a1da0af61..a62d71920 100644 --- a/src/qt/qt_winrawinputfilter.cpp +++ b/src/qt/qt_winrawinputfilter.cpp @@ -34,15 +34,27 @@ #include "qt_winrawinputfilter.hpp" #include +#include +#include +#include +#include #include #include +#include +#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE +#define DWMWA_USE_IMMERSIVE_DARK_MODE 20 +#endif #include <86box/keyboard.h> #include <86box/mouse.h> #include <86box/plat.h> #include <86box/86box.h> +#include <86box/cdrom.h> +#include <86box/video.h> +#include +#include extern void win_keyboard_handle(uint32_t scancode, int up, int e0, int e1); @@ -50,20 +62,55 @@ extern void win_keyboard_handle(uint32_t scancode, int up, int e0, int e1); #include #include "qt_rendererstack.hpp" +#include "ui_qt_mainwindow.h" + +static bool NewDarkMode = FALSE; + +bool windows_is_light_theme() { + // based on https://stackoverflow.com/questions/51334674/how-to-detect-windows-10-light-dark-mode-in-win32-application + + // The value is expected to be a REG_DWORD, which is a signed 32-bit little-endian + auto buffer = std::vector(4); + auto cbData = static_cast(buffer.size() * sizeof(char)); + auto res = RegGetValueW( + HKEY_CURRENT_USER, + L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", + L"AppsUseLightTheme", + RRF_RT_REG_DWORD, // expected value type + nullptr, + buffer.data(), + &cbData); + + if (res != ERROR_SUCCESS) { + return 1; + } + + // convert bytes written to our buffer to an int, assuming little-endian + auto i = int(buffer[3] << 24 | + buffer[2] << 16 | + buffer[1] << 8 | + buffer[0]); + + return i == 1; +} extern "C" void win_joystick_handle(PRAWINPUT); std::unique_ptr WindowsRawInputFilter::Register(MainWindow *window) { RAWINPUTDEVICE rid[2] = { - {.usUsagePage = 0x01, - .usUsage = 0x06, - .dwFlags = RIDEV_NOHOTKEYS, - .hwndTarget = nullptr}, - { .usUsagePage = 0x01, - .usUsage = 0x02, - .dwFlags = 0, - .hwndTarget = nullptr} + { + .usUsagePage = 0x01, + .usUsage = 0x06, + .dwFlags = RIDEV_NOHOTKEYS, + .hwndTarget = nullptr + }, + { + .usUsagePage = 0x01, + .usUsage = 0x02, + .dwFlags = 0, + .hwndTarget = nullptr + } }; if (hook_enabled && (RegisterRawInputDevices(&(rid[1]), 1, sizeof(rid[0])) == FALSE)) @@ -89,14 +136,18 @@ WindowsRawInputFilter::WindowsRawInputFilter(MainWindow *window) WindowsRawInputFilter::~WindowsRawInputFilter() { RAWINPUTDEVICE rid[2] = { - {.usUsagePage = 0x01, - .usUsage = 0x06, - .dwFlags = RIDEV_REMOVE, - .hwndTarget = NULL}, - { .usUsagePage = 0x01, - .usUsage = 0x02, - .dwFlags = RIDEV_REMOVE, - .hwndTarget = NULL} + { + .usUsagePage = 0x01, + .usUsage = 0x06, + .dwFlags = RIDEV_REMOVE, + .hwndTarget = NULL + }, + { + .usUsagePage = 0x01, + .usUsage = 0x02, + .dwFlags = RIDEV_REMOVE, + .hwndTarget = NULL + } }; if (hook_enabled) @@ -105,34 +156,133 @@ WindowsRawInputFilter::~WindowsRawInputFilter() RegisterRawInputDevices(rid, 2, sizeof(rid[0])); } +static void +notify_drives(ULONG unitmask, int empty) +{ + if (unitmask & cdrom_assigned_letters) for (int i = 0; i < CDROM_NUM; i++) { + cdrom_t *dev = &(cdrom[i]); + + if ((dev->host_letter != 0xff) && + (unitmask & (1 << dev->host_letter))) { + if (empty) + cdrom_set_empty(dev); + else + cdrom_update_status(dev); + } + } +} + +static void +device_change(WPARAM wParam, LPARAM lParam) +{ + PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR) lParam; + + switch(wParam) { + case DBT_DEVICEARRIVAL: + case DBT_DEVICEREMOVECOMPLETE: + /* Check whether a CD or DVD was inserted into a drive. */ + if (lpdb->dbch_devicetype == DBT_DEVTYP_VOLUME) { + PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME) lpdb; + + if (lpdbv->dbcv_flags & DBTF_MEDIA) + notify_drives(lpdbv->dbcv_unitmask, + (wParam == DBT_DEVICEREMOVECOMPLETE)); + } + break; + + default: + /* + Process other WM_DEVICECHANGE notifications for other + devices or reasons. + */ + break; + } +} + bool WindowsRawInputFilter::nativeEventFilter(const QByteArray &eventType, void *message, result_t *result) { if (eventType == "windows_generic_MSG") { 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; + if (msg != nullptr) switch(msg->message) { + case 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; - } - - /* Stop processing of Alt-F4 */ - if (msg->message == WM_SYSKEYDOWN) { - if (msg->wParam == 0x73) { return true; - } + case WM_SETTINGCHANGE: + if ((((void *) msg->lParam) != nullptr) && + (wcscmp(L"ImmersiveColorSet", (wchar_t*)msg->lParam) == 0)) { + + bool OldDarkMode = NewDarkMode; +#if 0 + if (do_auto_pause && !dopause) { + auto_paused = 1; + plat_pause(1); + } +#endif + + if (!windows_is_light_theme()) { + QFile f(":qdarkstyle/dark/darkstyle.qss"); + + if (!f.exists()) + printf("Unable to set stylesheet, file not found\n"); + else { + f.open(QFile::ReadOnly | QFile::Text); + QTextStream ts(&f); + qApp->setStyleSheet(ts.readAll()); + } + NewDarkMode = TRUE; + } else { + qApp->setStyleSheet(""); + NewDarkMode = FALSE; + } + + if (NewDarkMode != OldDarkMode) QTimer::singleShot(1000, [this] () { + BOOL DarkMode = NewDarkMode; + DwmSetWindowAttribute((HWND) window->winId(), + DWMWA_USE_IMMERSIVE_DARK_MODE, + (LPCVOID) &DarkMode, + sizeof(DarkMode)); + + window->resizeContents(monitors[0].mon_scrnsz_x, + monitors[0].mon_scrnsz_y); + + for (int i = 1; i < MONITORS_NUM; i++) { + auto mon = &(monitors[i]); + + if ((window->renderers[i] != nullptr) && + !window->renderers[i]->isHidden()) + window->resizeContentsMonitor(mon->mon_scrnsz_x, + mon->mon_scrnsz_y, i); + } + +#if 0 + if (auto_paused) { + plat_pause(0); + auto_paused = 0; + } +#endif + }); + } + break; + case WM_SYSKEYDOWN: + /* Stop processing of Alt-F4 */ + if (msg->wParam == 0x73) + return true; + break; + case WM_DEVICECHANGE: + if (msg->hwnd == (HWND) window->winId()) + device_change(msg->wParam, msg->lParam); + break; } } @@ -184,6 +334,7 @@ WindowsRawInputFilter::mouse_handle(PRAWINPUT raw) static int x, delta_x; static int y, delta_y; static int b, delta_z; + static int delta_w; b = mouse_get_buttons_ex(); @@ -221,6 +372,12 @@ WindowsRawInputFilter::mouse_handle(PRAWINPUT raw) } else delta_z = 0; + if (state.usButtonFlags & RI_MOUSE_HWHEEL) { + delta_w = (SHORT) state.usButtonData / 120; + mouse_set_w(delta_w); + } else + delta_w = 0; + if (state.usFlags & MOUSE_MOVE_ABSOLUTE) { /* absolute mouse, i.e. RDP or VNC * seems to work fine for RDP on Windows 10 @@ -238,7 +395,7 @@ WindowsRawInputFilter::mouse_handle(PRAWINPUT raw) mouse_scale(delta_x, delta_y); - HWND wnd = (HWND)window->winId(); + /* HWND wnd = (HWND)window->winId(); RECT rect; @@ -247,5 +404,5 @@ WindowsRawInputFilter::mouse_handle(PRAWINPUT raw) int left = rect.left + (rect.right - rect.left) / 2; int top = rect.top + (rect.bottom - rect.top) / 2; - SetCursorPos(left, top); + SetCursorPos(left, top); */ } diff --git a/src/qt/sdl_joystick.c b/src/qt/sdl_joystick.c index d56612872..83a2a67b1 100644 --- a/src/qt/sdl_joystick.c +++ b/src/qt/sdl_joystick.c @@ -8,13 +8,13 @@ * * SDL2 joystick interface. * - * - * * Authors: Sarah Walker, - * Joakim L. Gilje + * Joakim L. Gilje, + * Jasmine Iwanek, jriwanek@gmail.com> * - * Copyright 2017-2021 Sarah Walker - * Copyright 2021 Joakim L. Gilje + * Copyright 2017-2021 Sarah Walker. + * Copyright 2021 Joakim L. Gilje. + * Copyright 2021-2025 Jasmine Iwanek. */ #include @@ -33,8 +33,8 @@ #include <86box/gameport.h> #include <86box/plat_unused.h> -int joysticks_present; -joystick_t joystick_state[MAX_JOYSTICKS]; +int joysticks_present = 0; +joystick_t joystick_state[GAMEPORT_MAX][MAX_JOYSTICKS]; plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS]; static SDL_Joystick *sdl_joy[MAX_PLAT_JOYSTICKS]; @@ -54,28 +54,26 @@ joystick_init(void) joysticks_present = SDL_NumJoysticks(); memset(sdl_joy, 0, sizeof(sdl_joy)); - for (int c = 0; c < joysticks_present; c++) { - sdl_joy[c] = SDL_JoystickOpen(c); + for (int js = 0; js < joysticks_present; js++) { + sdl_joy[js] = SDL_JoystickOpen(js); - if (sdl_joy[c]) { - int d; + if (sdl_joy[js]) { + strncpy(plat_joystick_state[js].name, SDL_JoystickNameForIndex(js), 64); + plat_joystick_state[js].nr_axes = MIN(SDL_JoystickNumAxes(sdl_joy[js]), MAX_JOY_AXES); + plat_joystick_state[js].nr_buttons = MIN(SDL_JoystickNumButtons(sdl_joy[js]), MAX_JOY_BUTTONS); + plat_joystick_state[js].nr_povs = MIN(SDL_JoystickNumHats(sdl_joy[js]), MAX_JOY_POVS); - strncpy(plat_joystick_state[c].name, SDL_JoystickNameForIndex(c), 64); - plat_joystick_state[c].nr_axes = MIN(SDL_JoystickNumAxes(sdl_joy[c]), MAX_JOY_AXES); - plat_joystick_state[c].nr_buttons = MIN(SDL_JoystickNumButtons(sdl_joy[c]), MAX_JOY_BUTTONS); - plat_joystick_state[c].nr_povs = MIN(SDL_JoystickNumHats(sdl_joy[c]), MAX_JOY_POVS); - - for (d = 0; d < plat_joystick_state[c].nr_axes; d++) { - snprintf(plat_joystick_state[c].axis[d].name, sizeof(plat_joystick_state[c].axis[d].name), "Axis %i", d); - plat_joystick_state[c].axis[d].id = d; + for (int axis_nr = 0; axis_nr < plat_joystick_state[js].nr_axes; axis_nr++) { + snprintf(plat_joystick_state[js].axis[axis_nr].name, sizeof(plat_joystick_state[js].axis[axis_nr].name), "Axis %i", axis_nr); + plat_joystick_state[js].axis[axis_nr].id = axis_nr; } - for (d = 0; d < plat_joystick_state[c].nr_buttons; d++) { - snprintf(plat_joystick_state[c].button[d].name, sizeof(plat_joystick_state[c].button[d].name), "Button %i", d); - plat_joystick_state[c].button[d].id = d; + for (int button_nr = 0; button_nr < plat_joystick_state[js].nr_buttons; button_nr++) { + snprintf(plat_joystick_state[js].button[button_nr].name, sizeof(plat_joystick_state[js].button[button_nr].name), "Button %i", button_nr); + plat_joystick_state[js].button[button_nr].id = button_nr; } - for (d = 0; d < plat_joystick_state[c].nr_povs; d++) { - snprintf(plat_joystick_state[c].pov[d].name, sizeof(plat_joystick_state[c].pov[d].name), "POV %i", d); - plat_joystick_state[c].pov[d].id = d; + for (int pov_nr = 0; pov_nr < plat_joystick_state[js].nr_povs; pov_nr++) { + snprintf(plat_joystick_state[js].pov[pov_nr].name, sizeof(plat_joystick_state[js].pov[pov_nr].name), "POV %i", pov_nr); + plat_joystick_state[js].pov[pov_nr].id = pov_nr; } } } @@ -84,16 +82,14 @@ joystick_init(void) void joystick_close(void) { - int c; - - for (c = 0; c < joysticks_present; c++) { - if (sdl_joy[c]) - SDL_JoystickClose(sdl_joy[c]); + for (int js = 0; js < joysticks_present; js++) { + if (sdl_joy[js]) + SDL_JoystickClose(sdl_joy[js]); } } static int -joystick_get_axis(int joystick_nr, int mapping) +joystick_get_axis(int gameport, int joystick_nr, int mapping) { if (mapping & POV_X) { switch (plat_joystick_state[joystick_nr].p[mapping & 3]) { @@ -132,57 +128,60 @@ joystick_get_axis(int joystick_nr, int mapping) void joystick_process(void) { - int c; - int d; - if (!joystick_type) return; SDL_JoystickUpdate(); - for (c = 0; c < joysticks_present; c++) { - int b; + for (int js = 0; js < joysticks_present; js++) { + for (int axis_nr = 0; axis_nr < plat_joystick_state[js].nr_axes; axis_nr++) + plat_joystick_state[js].a[axis_nr] = SDL_JoystickGetAxis(sdl_joy[js], axis_nr); - for (b = 0; b < plat_joystick_state[c].nr_axes; b++) - plat_joystick_state[c].a[b] = SDL_JoystickGetAxis(sdl_joy[c], b); + for (int button_nr = 0; button_nr < plat_joystick_state[js].nr_buttons; button_nr++) + plat_joystick_state[js].b[button_nr] = SDL_JoystickGetButton(sdl_joy[js], button_nr); - for (b = 0; b < plat_joystick_state[c].nr_buttons; b++) - plat_joystick_state[c].b[b] = SDL_JoystickGetButton(sdl_joy[c], b); + for (int pov_nr = 0; pov_nr < plat_joystick_state[js].nr_povs; pov_nr++) + plat_joystick_state[js].p[pov_nr] = SDL_JoystickGetHat(sdl_joy[js], pov_nr); - for (b = 0; b < plat_joystick_state[c].nr_povs; b++) - plat_joystick_state[c].p[b] = SDL_JoystickGetHat(sdl_joy[c], b); - // pclog("joystick %i - x=%i y=%i b[0]=%i b[1]=%i %i\n", c, joystick_state[c].x, joystick_state[c].y, joystick_state[c].b[0], joystick_state[c].b[1], joysticks_present); +#if 0 + pclog("joystick %i - x=%i y=%i b[0]=%i b[1]=%i %i\n", js, + joystick_state[0][js].x, + joystick_state[0][js].y, + joystick_state[0][js].b[0], + joystick_state[0][js].b[1], + joysticks_present); +#endif } - for (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; + for (int js = 0; js < joystick_get_max_joysticks(joystick_type); js++) { + if (joystick_state[0][js].plat_joystick_nr) { + int joystick_nr = joystick_state[0][js].plat_joystick_nr - 1; - for (d = 0; d < joystick_get_axis_count(joystick_type); d++) - joystick_state[c].axis[d] = joystick_get_axis(joystick_nr, joystick_state[c].axis_mapping[d]); - for (d = 0; d < joystick_get_button_count(joystick_type); d++) - 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; + for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) + joystick_state[0][js].axis[axis_nr] = joystick_get_axis(0, joystick_nr, joystick_state[0][js].axis_mapping[axis_nr]); - 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]); + for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) + joystick_state[0][js].button[button_nr] = plat_joystick_state[joystick_nr].b[joystick_state[0][js].button_mapping[button_nr]]; - angle = (atan2((double) y, (double) x) * 360.0) / (2 * M_PI); - magnitude = sqrt((double) x * (double) x + (double) y * (double) y); + for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) { + int x = joystick_get_axis(0, joystick_nr, joystick_state[0][js].pov_mapping[pov_nr][0]); + int y = joystick_get_axis(0, joystick_nr, joystick_state[0][js].pov_mapping[pov_nr][1]); + double angle = (atan2((double) y, (double) x) * 360.0) / (2 * M_PI); + double magnitude = sqrt((double) x * (double) x + (double) y * (double) y); if (magnitude < 16384) - joystick_state[c].pov[d] = -1; + joystick_state[0][js].pov[pov_nr] = -1; else - joystick_state[c].pov[d] = ((int) angle + 90 + 360) % 360; + joystick_state[0][js].pov[pov_nr] = ((int) angle + 90 + 360) % 360; } } else { - for (d = 0; d < joystick_get_axis_count(joystick_type); d++) - joystick_state[c].axis[d] = 0; - for (d = 0; d < joystick_get_button_count(joystick_type); d++) - joystick_state[c].button[d] = 0; - for (d = 0; d < joystick_get_pov_count(joystick_type); d++) - joystick_state[c].pov[d] = -1; + for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) + joystick_state[0][js].axis[axis_nr] = 0; + + for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) + joystick_state[0][js].button[button_nr] = 0; + + for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) + joystick_state[0][js].pov[pov_nr] = -1; } } } diff --git a/src/qt/win_cdrom_ioctl.c b/src/qt/win_cdrom_ioctl.c index 9d82d68cc..ff72e58fe 100644 --- a/src/qt/win_cdrom_ioctl.c +++ b/src/qt/win_cdrom_ioctl.c @@ -19,142 +19,133 @@ #define UNICODE #define BITMAP WINDOWS_BITMAP #include -#include #undef BITMAP #include -#include #include "ntddcdrm.h" #include "ntddscsi.h" +#ifdef ENABLE_IOCTL_LOG #include -#include +#endif #include #include #include #include +#include #include -#define HAVE_STDARG_H #include <86box/86box.h> -#include <86box/scsi_device.h> #include <86box/cdrom.h> -#include <86box/plat_unused.h> -#include <86box/plat_cdrom.h> +#include <86box/log.h> +#include <86box/plat_cdrom_ioctl.h> +#include <86box/scsi_device.h> -/* 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. */ -#define MSFtoLBA(m, s, f) ((((m * 60) + s) * 75) + f) - -typedef struct win_cdrom_ioctl_t { - int toc_valid; - uint8_t cur_toc[65536]; - CDROM_READ_TOC_EX cur_read_toc_ex; +typedef struct ioctl_t { + cdrom_t *dev; + void *log; + int is_dvd; + int has_audio; int blocks_num; uint8_t cur_rti[65536]; HANDLE handle; WCHAR path[256]; - WCHAR old_path[256]; -} win_cdrom_ioctl_t; +} ioctl_t; -#ifdef ENABLE_WIN_CDROM_IOCTL_LOG -int win_cdrom_ioctl_do_log = ENABLE_WIN_CDROM_IOCTL_LOG; +static int ioctl_read_dvd_structure(const void *local, uint8_t layer, uint8_t format, + uint8_t *buffer, uint32_t *info); + +#ifdef ENABLE_IOCTL_LOG +int ioctl_do_log = ENABLE_IOCTL_LOG; void -win_cdrom_ioctl_log(const char *fmt, ...) +ioctl_log(void *priv, const char *fmt, ...) { - va_list ap; - - if (win_cdrom_ioctl_do_log) { + if (ioctl_do_log) { + va_list ap; va_start(ap, fmt); - pclog_ex(fmt, ap); + log_out(priv, fmt, ap); va_end(ap); } } #else -# define win_cdrom_ioctl_log(fmt, ...) +# define ioctl_log(priv, fmt, ...) #endif +/* Internal functions. */ static void -plat_cdrom_close_handle(win_cdrom_ioctl_t *ioctl) +ioctl_close_handle(const ioctl_t *ioctl) { if (ioctl->handle != NULL) CloseHandle(ioctl->handle); } static int -plat_cdrom_open(void *local) +ioctl_open_handle(ioctl_t *ioctl) { - win_cdrom_ioctl_t *ioctl = (win_cdrom_ioctl_t *) local; - - plat_cdrom_close_handle(local); - + ioctl_log(ioctl->log, "ioctl->path = \"%ls\"\n", ioctl->path); ioctl->handle = CreateFileW((LPCWSTR) ioctl->path, GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); - win_cdrom_ioctl_log("handle=%p, error=%x\n", ioctl->handle, (unsigned int) GetLastError()); + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, + OPEN_EXISTING, 0, NULL); + + ioctl_log(ioctl->log, "handle=%p, error=%x\n", + ioctl->handle, (unsigned int) GetLastError()); + + if (ioctl->handle != INVALID_HANDLE_VALUE) { + CDROM_SET_SPEED set_speed = { 0 }; + + set_speed.RequestType = CdromSetSpeed; + set_speed.ReadSpeed = 0xffff; + set_speed.WriteSpeed = 0xffff; + set_speed.RotationControl = CdromDefaultRotation; + + (void) DeviceIoControl(ioctl->handle, IOCTL_CDROM_SET_SPEED, + &set_speed, sizeof(set_speed), + NULL, 0, + 0, NULL); + } return (ioctl->handle != INVALID_HANDLE_VALUE); } static int -plat_cdrom_load(void *local) +ioctl_read_normal_toc(ioctl_t *ioctl, uint8_t *toc_buf, int32_t *tracks_num) { - win_cdrom_ioctl_t *ioctl = (win_cdrom_ioctl_t *) local; - - plat_cdrom_close(local); - - ioctl->handle = CreateFileW((LPCWSTR) ioctl->path, GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); - win_cdrom_ioctl_log("handle=%p, error=%x\n", ioctl->handle, (unsigned int) GetLastError()); - if (ioctl->handle != INVALID_HANDLE_VALUE) { - long size; - DeviceIoControl(ioctl->handle, IOCTL_STORAGE_LOAD_MEDIA, NULL, 0, NULL, 0, (LPDWORD) &size, NULL); - return 1; - } - return 0; -} - -static int -plat_cdrom_read_normal_toc(win_cdrom_ioctl_t *ioctl, uint8_t *toc_buf) -{ - long size = 0; - PCDROM_TOC_FULL_TOC_DATA cur_full_toc = NULL; + long size = 0; + PCDROM_TOC_FULL_TOC_DATA cur_full_toc = NULL; + CDROM_READ_TOC_EX cur_read_toc_ex = { 0 }; + *tracks_num = 0; memset(toc_buf, 0x00, 65536); cur_full_toc = (PCDROM_TOC_FULL_TOC_DATA) calloc(1, 65536); - if (ioctl->blocks_num != 0) { - memset(ioctl->cur_rti, 0x00, ioctl->blocks_num * 11); - ioctl->blocks_num = 0; - } - ioctl->cur_read_toc_ex.Format = CDROM_READ_TOC_EX_FORMAT_TOC; - win_cdrom_ioctl_log("cur_read_toc_ex.Format = %i\n", ioctl->cur_read_toc_ex.Format); - ioctl->cur_read_toc_ex.Msf = 1; - ioctl->cur_read_toc_ex.SessionTrack = 0; + cur_read_toc_ex.Format = CDROM_READ_TOC_EX_FORMAT_TOC; + ioctl_log(ioctl->log, "cur_read_toc_ex.Format = %i\n", cur_read_toc_ex.Format); + cur_read_toc_ex.Msf = 1; + cur_read_toc_ex.SessionTrack = 1; - plat_cdrom_open(ioctl); - int temp = DeviceIoControl(ioctl->handle, IOCTL_CDROM_READ_TOC_EX, &ioctl->cur_read_toc_ex, 65535, - cur_full_toc, 65535, (LPDWORD) &size, NULL); - plat_cdrom_close(ioctl); - win_cdrom_ioctl_log("temp = %i\n", temp); + const int temp = DeviceIoControl(ioctl->handle, IOCTL_CDROM_READ_TOC_EX, + &cur_read_toc_ex, sizeof(CDROM_READ_TOC_EX), + cur_full_toc, 65535, + (LPDWORD) &size, NULL); + ioctl_log(ioctl->log, "temp = %i\n", temp); if (temp != 0) { - int length = ((cur_full_toc->Length[0] << 8) | cur_full_toc->Length[1]) + 2; + const int length = ((cur_full_toc->Length[0] << 8) | cur_full_toc->Length[1]) + 2; memcpy(toc_buf, cur_full_toc, length); + *tracks_num = (length - 4) / 8; } free(cur_full_toc); -#ifdef ENABLE_WIN_CDROM_IOCTL_LOG +#ifdef ENABLE_IOCTL_LOG PCDROM_TOC toc = (PCDROM_TOC) toc_buf; - const int tracks_num = (((toc->Length[0] << 8) | toc->Length[1]) - 2) / 8; - win_cdrom_ioctl_log("%i tracks: %02X %02X %02X %02X\n", - tracks_num, toc_buf[0], toc_buf[1], toc_buf[2], toc_buf[3]); + ioctl_log(ioctl->log, "%i tracks: %02X %02X %02X %02X\n", + *tracks_num, toc_buf[0], toc_buf[1], toc_buf[2], toc_buf[3]); - for (int i = 0; i < tracks_num; i++) { - uint8_t *t = (uint8_t *) &toc->TrackData[i]; - win_cdrom_ioctl_log("Track %03i: %02X %02X %02X %02X %02X %02X %02X %02X\n", - i, t[0], t[1], t[2], t[3], t[4], t[5], t[6], t[7]); + for (int i = 0; i < *tracks_num; i++) { + const uint8_t *t = (const uint8_t *) &toc->TrackData[i]; + ioctl_log(ioctl->log, "Track %03i: %02X %02X %02X %02X %02X %02X %02X %02X\n", + i, t[0], t[1], t[2], t[3], t[4], t[5], t[6], t[7]); } #endif @@ -162,427 +153,669 @@ plat_cdrom_read_normal_toc(win_cdrom_ioctl_t *ioctl, uint8_t *toc_buf) } static void -plat_cdrom_read_raw_toc(win_cdrom_ioctl_t *ioctl) +ioctl_read_raw_toc(ioctl_t *ioctl) { - long size = 0; - PCDROM_TOC_FULL_TOC_DATA cur_full_toc = NULL; + PCDROM_TOC_FULL_TOC_DATA cur_full_toc = NULL; + long size = 0; + raw_track_info_t *rti = (raw_track_info_t *) ioctl->cur_rti; + uint8_t *buffer = (uint8_t *) calloc (1, 2052); + int status = 0; + CDROM_READ_TOC_EX cur_read_toc_ex = { 0 }; + ioctl->is_dvd = (ioctl_read_dvd_structure(ioctl, 0, 0, buffer, NULL) > 0); + free(buffer); + + ioctl->has_audio = 0; + ioctl->blocks_num = 0; memset(ioctl->cur_rti, 0x00, 65536); cur_full_toc = (PCDROM_TOC_FULL_TOC_DATA) calloc(1, 65536); - if (ioctl->blocks_num != 0) { - memset(ioctl->cur_rti, 0x00, ioctl->blocks_num * 11); - ioctl->blocks_num = 0; + + cur_read_toc_ex.Format = CDROM_READ_TOC_EX_FORMAT_FULL_TOC; + ioctl_log(ioctl->log, "cur_read_toc_ex.Format = %i\n", cur_read_toc_ex.Format); + cur_read_toc_ex.Msf = 1; + cur_read_toc_ex.SessionTrack = 1; + + if (!ioctl->is_dvd) { + status = DeviceIoControl(ioctl->handle, IOCTL_CDROM_READ_TOC_EX, + &cur_read_toc_ex, sizeof(CDROM_READ_TOC_EX), + cur_full_toc, 65535, + (LPDWORD) &size, NULL); + ioctl_log(ioctl->log, "status = %i\n", status); } - ioctl->cur_read_toc_ex.Format = CDROM_READ_TOC_EX_FORMAT_FULL_TOC; - win_cdrom_ioctl_log("cur_read_toc_ex.Format = %i\n", ioctl->cur_read_toc_ex.Format); - ioctl->cur_read_toc_ex.Msf = 1; - ioctl->cur_read_toc_ex.SessionTrack = 0; + if (status == 0) { + /* + This is needed because in some circumstances (eg. a DVD .MDS + mounted in Daemon Tools), reading the raw TOC fails but + reading the cooked TOC does not, so we have to construct the + raw TOC from the cooked TOC. + */ + uint8_t cur_toc[65536] = { 0 }; + int32_t tracks_num = 0; - plat_cdrom_open(ioctl); - int status = DeviceIoControl(ioctl->handle, IOCTL_CDROM_READ_TOC_EX, &ioctl->cur_read_toc_ex, 65535, - cur_full_toc, 65535, (LPDWORD) &size, NULL); - plat_cdrom_close(ioctl); - win_cdrom_ioctl_log("status = %i\n", status); + const CDROM_TOC * toc = (const CDROM_TOC *) cur_toc; - if (status != 0) { - ioctl->blocks_num = (((cur_full_toc->Length[0] << 8) | cur_full_toc->Length[1]) - 2) / 11; + status = ioctl_read_normal_toc(ioctl, cur_toc, &tracks_num); + + const TRACK_DATA *ct = &(toc->TrackData[tracks_num - 1]); + + if ((status > 0) && (tracks_num >= 1)) { + rti[0].adr_ctl = ((ct->Adr & 0xf) << 4) | (ct->Control & 0xf); + rti[0].point = 0xa0; + rti[0].pm = toc->FirstTrack; + + rti[1].adr_ctl = rti[0].adr_ctl; + rti[1].point = 0xa1; + rti[1].pm = toc->LastTrack; + + rti[2].adr_ctl = rti[0].adr_ctl; + rti[2].point = 0xa2; + rti[2].pm = ct->Address[1]; + rti[2].ps = ct->Address[2]; + rti[2].pf = ct->Address[3]; + + ioctl->blocks_num = 3; + + for (int i = 0; i < (tracks_num - 1); i++) { + raw_track_info_t *crt = &(rti[ioctl->blocks_num]); + + ct = &(toc->TrackData[i]); + + crt->adr_ctl = ((ct->Adr & 0xf) << 4) | (ct->Control & 0xf); + crt->point = ct->TrackNumber; + crt->pm = ct->Address[1]; + crt->ps = ct->Address[2]; + crt->pf = ct->Address[3]; + + ioctl->blocks_num++; + } + } else if (status > 0) + /* Announce that we've had a failure. */ + status = 0; + } else if (status != 0) { + ioctl->blocks_num = (((cur_full_toc->Length[0] << 8) | + cur_full_toc->Length[1]) - 2) / 11; memcpy(ioctl->cur_rti, cur_full_toc->Descriptors, ioctl->blocks_num * 11); } -#ifdef ENABLE_WIN_CDROM_IOCTL_LOG - uint8_t *u = (uint8_t *) cur_full_toc; + if (ioctl->blocks_num) for (int i = 0; i < ioctl->blocks_num; i++) { + const raw_track_info_t *crt = &(rti[i]); - win_cdrom_ioctl_log("%i blocks: %02X %02X %02X %02X\n", - ioctl->blocks_num, u[0], u[1], u[2], u[3]); + if ((crt->point >= 1) && (crt->point <= 99) && !(crt->adr_ctl & 0x04)) { + ioctl->has_audio = 1; + break; + } + } + +#ifdef ENABLE_IOCTL_LOG + uint8_t *u = (uint8_t *) cur_full_toc; + + ioctl_log(ioctl->log, "%i blocks: %02X %02X %02X %02X\n", + ioctl->blocks_num, u[0], u[1], u[2], u[3]); - raw_track_info_t *rti = (raw_track_info_t *) ioctl->cur_rti; for (int i = 0; i < ioctl->blocks_num; i++) { uint8_t *t = (uint8_t *) &rti[i]; - win_cdrom_ioctl_log("Block %03i: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n", - i, t[0], t[1], t[2], t[3], t[4], t[5], t[6], t[7], t[8], t[9], t[10]); + ioctl_log(ioctl->log, "Block %03i: %02X %02X %02X %02X %02X %02X %02X %02X " + "%02X %02X %02X\n", + i, t[0], t[1], t[2], t[3], t[4], t[5], t[6], t[7], t[8], + t[9], t[10]); } #endif free(cur_full_toc); } -void -plat_cdrom_get_raw_track_info(void *local, int *num, raw_track_info_t *rti) +static int +ioctl_get_track(const ioctl_t *ioctl, const uint32_t sector) { + raw_track_info_t *rti = (raw_track_info_t *) ioctl->cur_rti; + int track = -1; + + for (int i = (ioctl->blocks_num - 1); i >= 0; i--) { + const raw_track_info_t *ct = &(rti[i]); + const uint32_t start = (ct->pm * 60 * 75) + (ct->ps * 75) + ct->pf - 150; + + ioctl_log(ioctl->log, "ioctl_get_track(): ct: %02X, %08X\n", + ct->point, start); + + if ((ct->point >= 1) && (ct->point <= 99) && (sector >= start)) { + track = i; + ioctl_log(ioctl->log, "ioctl_get_track(): found track: %i\n", i); + break; + } + } + + return track; +} + +static int +ioctl_is_track_audio(const ioctl_t *ioctl, const uint32_t pos) { - win_cdrom_ioctl_t *ioctl = (win_cdrom_ioctl_t *) local; + const raw_track_info_t *rti = (const raw_track_info_t *) ioctl->cur_rti; + int ret = 0; + + if (ioctl->has_audio && !ioctl->is_dvd) { + const int track = ioctl_get_track(ioctl, pos); + const int control = rti[track].adr_ctl; + + ret = !(control & 0x04); + + ioctl_log(ioctl->log, "ioctl_is_track_audio(%08X, %02X): %i\n", pos, track, ret); + } + + return ret; +} + +/* Shared functions. */ +static int +ioctl_get_track_info(const void *local, const uint32_t track, + int end, track_info_t *ti) +{ + const ioctl_t * ioctl = (const ioctl_t *) local; + const raw_track_info_t *rti = (const raw_track_info_t *) ioctl->cur_rti; + int ret = 1; + int trk = -1; + + if ((track >= 1) && (track < 99)) + for (int i = 0; i < ioctl->blocks_num; i++) + if (rti[i].point == track) { + trk = i; + break; + } + + if ((track == 0xaa) || (trk == -1)) { + ioctl_log(ioctl->log, "ioctl_get_track_info(%02i)\n", track); + ret = 0; + } else { + ti->m = rti[trk].pm; + ti->s = rti[trk].ps; + ti->f = rti[trk].pf; + + ti->number = rti[trk].point; + ti->attr = rti[trk].adr_ctl; + + ioctl_log(ioctl->log, "ioctl_get_track_info(%02i): %02i:%02i:%02i, %02i, %02X\n", + track, ti->m, ti->s, ti->f, ti->number, ti->attr); + } + + return ret; +} + +static void +ioctl_get_raw_track_info(const void *local, int *num, uint8_t *rti) +{ + const ioctl_t *ioctl = (const ioctl_t *) local; *num = ioctl->blocks_num; memcpy(rti, ioctl->cur_rti, ioctl->blocks_num * 11); } -static void -plat_cdrom_read_toc(win_cdrom_ioctl_t *ioctl) +static int +ioctl_is_track_pre(const void *local, const uint32_t sector) { - if (!ioctl->toc_valid) { - ioctl->toc_valid = 1; - (void) plat_cdrom_read_normal_toc(ioctl, ioctl->cur_toc); - plat_cdrom_read_raw_toc(ioctl); + const ioctl_t *ioctl = (const ioctl_t *) local; + const raw_track_info_t *rti = (const raw_track_info_t *) ioctl->cur_rti; + int ret = 0; + + if (ioctl->has_audio && !ioctl->is_dvd) { + const int track = ioctl_get_track(ioctl, sector); + const int control = rti[track].adr_ctl; + + ret = control & 0x01; + + ioctl_log(ioctl->log, "ioctl_is_track_pre(%08X, %02X): %i\n", sector, track, ret); } -} - -int -plat_cdrom_is_track_audio(void *local, uint32_t sector) -{ - win_cdrom_ioctl_t *ioctl = (win_cdrom_ioctl_t *) local; - PCDROM_TOC toc = (PCDROM_TOC) ioctl->cur_toc; - int control = 0; - uint32_t cur_addr = 0; - uint32_t next_addr = 0; - - plat_cdrom_read_toc(ioctl); - - for (int c = 0; toc->TrackData[c].TrackNumber != 0xaa; c++) { - PTRACK_DATA cur_td = &toc->TrackData[c]; - PTRACK_DATA next_td = &toc->TrackData[c + 1]; - - cur_addr = MSFtoLBA(cur_td->Address[1], cur_td->Address[2], cur_td->Address[3]) - 150; - next_addr = MSFtoLBA(next_td->Address[1], next_td->Address[2], next_td->Address[3]) - 150; - - win_cdrom_ioctl_log("F: %i, L: %i, C: %i (%i), c: %02X, A: %08X, S: %08X\n", - toc->FirstTrack, toc->LastTrack, cur_td->TrackNumber, c, - cur_td->Control, cur_addr, sector); - - if ((cur_td->TrackNumber >= toc->FirstTrack) && (cur_td->TrackNumber <= toc->LastTrack) && - (sector >= cur_addr) && (sector < next_addr)) { - control = cur_td->Control; - break; - } - } - - const int ret = !(control & 0x04); - - win_cdrom_ioctl_log("plat_cdrom_is_track_audio(%08X): %i\n", sector, ret); return ret; } -int -plat_cdrom_is_track_pre(void *local, uint32_t sector) -{ - win_cdrom_ioctl_t *ioctl = (win_cdrom_ioctl_t *) local; - PCDROM_TOC toc = (PCDROM_TOC) ioctl->cur_toc; - int control = 0; - uint32_t cur_addr = 0; - uint32_t next_addr = 0; - - plat_cdrom_read_toc(ioctl); - - for (int c = 0; toc->TrackData[c].TrackNumber != 0xaa; c++) { - PTRACK_DATA cur_td = &toc->TrackData[c]; - PTRACK_DATA next_td = &toc->TrackData[c + 1]; - - cur_addr = MSFtoLBA(cur_td->Address[1], cur_td->Address[2], cur_td->Address[3]) - 150; - next_addr = MSFtoLBA(next_td->Address[1], next_td->Address[2], next_td->Address[3]) - 150; - - win_cdrom_ioctl_log("F: %i, L: %i, C: %i (%i), c: %02X, A: %08X, S: %08X\n", - toc->FirstTrack, toc->LastTrack, cur_td->TrackNumber, c, - cur_td->Control, cur_addr, sector); - - if ((cur_td->TrackNumber >= toc->FirstTrack) && (cur_td->TrackNumber <= toc->LastTrack) && - (sector >= cur_addr) && (sector < next_addr)) { - control = cur_td->Control; - break; - } - } - - const int ret = (control & 0x01); - - win_cdrom_ioctl_log("plat_cdrom_is_track_audio(%08X): %i\n", sector, ret); - - return ret; -} - -uint32_t -plat_cdrom_get_track_start(void *local, uint32_t sector, uint8_t *attr, uint8_t *track) -{ - win_cdrom_ioctl_t *ioctl = (win_cdrom_ioctl_t *) local; - PCDROM_TOC toc = (PCDROM_TOC) ioctl->cur_toc; - uint32_t cur_addr = 0; - uint32_t next_addr = 0; - - plat_cdrom_read_toc(ioctl); - - for (int c = 0; toc->TrackData[c].TrackNumber != 0xaa; c++) { - PTRACK_DATA cur_td = &toc->TrackData[c]; - PTRACK_DATA next_td = &toc->TrackData[c + 1]; - - cur_addr = MSFtoLBA(cur_td->Address[1], cur_td->Address[2], cur_td->Address[3]) - 150; - next_addr = MSFtoLBA(next_td->Address[1], next_td->Address[2], next_td->Address[3]) - 150; - - win_cdrom_ioctl_log("F: %i, L: %i, C: %i (%i), c: %02X, a: %02X, A: %08X, S: %08X\n", - toc->FirstTrack, toc->LastTrack, cur_td->TrackNumber, c, - cur_td->Control, cur_td->Adr, cur_addr, sector); - - if ((cur_td->TrackNumber >= toc->FirstTrack) && (cur_td->TrackNumber <= toc->LastTrack) && - (sector >= cur_addr) && (sector < next_addr)) { - *track = cur_td->TrackNumber; - *attr = cur_td->Control; - *attr |= ((cur_td->Adr << 4) & 0xf0); - break; - } - } - - win_cdrom_ioctl_log("plat_cdrom_get_track_start(%08X): %i\n", sector, cur_addr); - - return cur_addr; -} - -uint32_t -plat_cdrom_get_last_block(void *local) -{ - win_cdrom_ioctl_t *ioctl = (win_cdrom_ioctl_t *) local; - PCDROM_TOC toc = (PCDROM_TOC) ioctl->cur_toc; - uint32_t lb = 0; - uint32_t address = 0; - - plat_cdrom_read_toc(ioctl); - - for (int c = 0; c <= toc->LastTrack; c++) { - PTRACK_DATA td = &toc->TrackData[c]; - - address = MSFtoLBA(td->Address[1], td->Address[2], td->Address[3]) - 150; - - if (address > lb) - lb = address; - } - - win_cdrom_ioctl_log("LBCapacity=%d\n", lb); - - return lb; -} - -int -plat_cdrom_ext_medium_changed(void *local) -{ - win_cdrom_ioctl_t *ioctl = (win_cdrom_ioctl_t *) local; - PCDROM_TOC toc = (PCDROM_TOC) ioctl->cur_toc; - uint8_t new_toc_buf[65536] = { 0 }; - PCDROM_TOC new_toc = (PCDROM_TOC) new_toc_buf; - int ret = 0; - int temp = plat_cdrom_read_normal_toc(ioctl, new_toc_buf); - PTRACK_DATA cur_ltd = &toc->TrackData[toc->LastTrack]; - - if (temp != 0) - plat_cdrom_read_raw_toc(ioctl); - - PTRACK_DATA new_ltd = &new_toc->TrackData[new_toc->LastTrack]; - - if (temp == 0) - /* There has been some kind of error - not a medium change, but a not ready - condition. */ - ret = -1; - else if (!ioctl->toc_valid || (memcmp(ioctl->path, ioctl->old_path, sizeof(ioctl->path)) != 0)) { - /* Changed to a different host drive - we already detect such medium changes. */ - ioctl->toc_valid = 1; - memcpy(toc, new_toc, 65535); - if (memcmp(ioctl->path, ioctl->old_path, sizeof(ioctl->path)) != 0) - memcpy(ioctl->old_path, ioctl->path, sizeof(ioctl->path)); - } else if (memcmp(&(new_ltd->Address[1]), &(cur_ltd->Address[1]), 3)) { - /* The TOC has changed. */ - ioctl->toc_valid = 1; - memcpy(toc, new_toc, 65535); - if (memcmp(ioctl->path, ioctl->old_path, sizeof(ioctl->path)) != 0) - memcpy(ioctl->old_path, ioctl->path, sizeof(ioctl->path)); - ret = 1; - } - - win_cdrom_ioctl_log("plat_cdrom_ext_medium_changed(): %i\n", ret); - - return ret; -} - -/* This replaces both Info and EndInfo, they are specified by a variable. */ -int -plat_cdrom_get_audio_track_info(void *local, UNUSED(int end), int track, int *track_num, TMSF *start, uint8_t *attr) -{ - win_cdrom_ioctl_t *ioctl = (win_cdrom_ioctl_t *) local; - PCDROM_TOC toc = (PCDROM_TOC) ioctl->cur_toc; - - plat_cdrom_read_toc(ioctl); - - if ((track < 1) || (track == 0xaa) || (track > (toc->LastTrack + 1))) { - win_cdrom_ioctl_log("plat_cdrom_get_audio_track_info(%02i)\n", track); - return 0; - } - - PTRACK_DATA td = &toc->TrackData[track - 1]; - - start->min = td->Address[1]; - start->sec = td->Address[2]; - start->fr = td->Address[3]; - - *track_num = td->TrackNumber; - *attr = td->Control; - *attr |= ((td->Adr << 4) & 0xf0); - - win_cdrom_ioctl_log("plat_cdrom_get_audio_track_info(%02i): %02i:%02i:%02i, %02i, %02X\n", - track, start->min, start->sec, start->fr, *track_num, *attr); - - return 1; -} - -/* TODO: See if track start is adjusted by 150 or not. */ -int -plat_cdrom_get_audio_sub(void *local, UNUSED(uint32_t sector), uint8_t *attr, uint8_t *track, uint8_t *index, - TMSF *rel_pos, TMSF *abs_pos) -{ - win_cdrom_ioctl_t * ioctl = (win_cdrom_ioctl_t *) local; - CDROM_SUB_Q_DATA_FORMAT insub; - SUB_Q_CHANNEL_DATA sub; - long size = 0; - - insub.Format = IOCTL_CDROM_CURRENT_POSITION; - - plat_cdrom_open(ioctl); - DeviceIoControl(ioctl->handle, IOCTL_CDROM_READ_Q_CHANNEL, &insub, sizeof(insub), &sub, sizeof(sub), - (LPDWORD) &size, NULL); - plat_cdrom_close(ioctl); - - if (sub.CurrentPosition.TrackNumber < 1) - return 0; - - *track = sub.CurrentPosition.TrackNumber; - *attr = sub.CurrentPosition.Control; - *attr |= ((sub.CurrentPosition.ADR << 4) & 0xf0); - *index = sub.CurrentPosition.IndexNumber; - - rel_pos->min = sub.CurrentPosition.TrackRelativeAddress[1]; - rel_pos->sec = sub.CurrentPosition.TrackRelativeAddress[2]; - rel_pos->fr = sub.CurrentPosition.TrackRelativeAddress[3]; - abs_pos->min = sub.CurrentPosition.AbsoluteAddress[1]; - abs_pos->sec = sub.CurrentPosition.AbsoluteAddress[2]; - abs_pos->fr = sub.CurrentPosition.AbsoluteAddress[3]; - - win_cdrom_ioctl_log("plat_cdrom_get_audio_sub(): %02i, %02X, %02i, %02i:%02i:%02i, %02i:%02i:%02i\n", - *track, *attr, *index, rel_pos->min, rel_pos->sec, rel_pos->fr, abs_pos->min, abs_pos->sec, - abs_pos->fr); - - return 1; -} - -int -plat_cdrom_get_sector_size(void *local, UNUSED(uint32_t sector)) -{ - win_cdrom_ioctl_t * ioctl = (win_cdrom_ioctl_t *) local; - long size; - DISK_GEOMETRY dgCDROM; - - plat_cdrom_open(ioctl); - DeviceIoControl(ioctl->handle, IOCTL_CDROM_GET_DRIVE_GEOMETRY, NULL, 0, &dgCDROM, sizeof(dgCDROM), - (LPDWORD) &size, NULL); - plat_cdrom_close(ioctl); - - win_cdrom_ioctl_log("BytesPerSector=%d\n", dgCDROM.BytesPerSector); - return dgCDROM.BytesPerSector; -} - -int -plat_cdrom_read_sector(void *local, uint8_t *buffer, uint32_t sector) +static int +ioctl_read_sector(const void *local, uint8_t *buffer, uint32_t const sector) { typedef struct SCSI_PASS_THROUGH_DIRECT_BUF { SCSI_PASS_THROUGH_DIRECT spt; ULONG Filler; - UCHAR SenseBuf[32]; + UCHAR SenseBuf[64]; } SCSI_PASS_THROUGH_DIRECT_BUF; - win_cdrom_ioctl_t * ioctl = (win_cdrom_ioctl_t *) local; - int sc_offs = (sector == 0xffffffff) ? 0 : 2352; - unsigned long int unused = 0; + const ioctl_t * ioctl = (const ioctl_t *) local; + const raw_track_info_t * rti = (raw_track_info_t *) ioctl->cur_rti; + unsigned long int unused = 0; + const int sc_offs = (sector == 0xffffffff) ? 0 : 2352; + int len = (sector == 0xffffffff) ? 16 : 2368; + int m = 0; + int s = 0; + int f = 0; + uint32_t lba = sector; int ret; SCSI_PASS_THROUGH_DIRECT_BUF req; - memset(&req, 0x00, sizeof(req)); - req.Filler = 0; - req.spt.Length = sizeof(SCSI_PASS_THROUGH_DIRECT); - req.spt.CdbLength = 12; - req.spt.DataIn = SCSI_IOCTL_DATA_IN; - req.spt.SenseInfoOffset = offsetof(SCSI_PASS_THROUGH_DIRECT_BUF, SenseBuf); - req.spt.SenseInfoLength = sizeof(req.SenseBuf); - req.spt.TimeOutValue = 6; - req.spt.DataTransferLength = 2368; - req.spt.DataBuffer = buffer; + if (ioctl->is_dvd) { + int track; - /* Fill in the CDB. */ - req.spt.Cdb[0] = 0xbe; /* READ CD */ - req.spt.Cdb[1] = 0x00; /* DAP = 0, Any Sector Type. */ - req.spt.Cdb[2] = (sector >> 24) & 0xff; - req.spt.Cdb[3] = (sector >> 16) & 0xff; - req.spt.Cdb[4] = (sector >> 8) & 0xff; - req.spt.Cdb[5] = sector & 0xff; /* Starting Logical Block Address. */ - req.spt.Cdb[6] = 0x00; - req.spt.Cdb[7] = 0x00; - req.spt.Cdb[8] = 0x01; /* Transfer Length. */ - /* If sector is FFFFFFFF, only return the subchannel. */ - req.spt.Cdb[9] = (sector == 0xffffffff) ? 0x00 : 0xf8; - req.spt.Cdb[10] = 0x02; - req.spt.Cdb[11] = 0x00; + req.spt.DataTransferLength = 0; + ret = 0; - plat_cdrom_open(ioctl); - ret = DeviceIoControl(ioctl->handle, IOCTL_SCSI_PASS_THROUGH_DIRECT, &req, sizeof(req), &req, sizeof(req), - &unused, NULL); - plat_cdrom_close(ioctl); + if (lba == 0xffffffff) { + lba = ioctl->dev->seek_pos; + track = ioctl_get_track(ioctl, lba); + + if (track != -1) { + req.spt.DataTransferLength = len; + ret = 1; + } + } else { + len = COOKED_SECTOR_SIZE; + track = ioctl_get_track(ioctl, lba); + + if (track != -1) { + DWORD newPos = SetFilePointer(ioctl->handle, (long) lba * COOKED_SECTOR_SIZE, + 0, FILE_BEGIN); + + if (newPos != 0xffffffff) + ret = ReadFile(ioctl->handle, &(buffer[16]), + COOKED_SECTOR_SIZE, (LPDWORD) &req.spt.DataTransferLength, + NULL); + } + } + + if (ret && (req.spt.DataTransferLength >= len) && (track != -1)) { + const raw_track_info_t *ct = &(rti[track]); + const uint32_t start = (ct->pm * 60 * 75) + (ct->ps * 75) + ct->pf; + + m = s = f = 0; + + /* Construct sector header and sub-header. */ + if (sector != 0xffffffff) { + /* Sync bytes. */ + buffer[0] = 0x00; + memset(&(buffer[1]), 0xff, 10); + buffer[11] = 0x00; + + /* Sector header. */ + FRAMES_TO_MSF(lba + 150, &m, &s, &f); + buffer[12] = bin2bcd(m); + buffer[13] = bin2bcd(s); + buffer[14] = bin2bcd(f); + + /* Mode 1 data. */ + buffer[15] = 0x01; + } + + /* Construct Q. */ + buffer[sc_offs + 0] = (ct->adr_ctl >> 4) | ((ct->adr_ctl & 0xf) << 4); + buffer[sc_offs + 1] = bin2bcd(ct->point); + buffer[sc_offs + 2] = 1; + FRAMES_TO_MSF((int32_t) (lba + 150 - start), &m, &s, &f); + buffer[sc_offs + 3] = bin2bcd(m); + buffer[sc_offs + 4] = bin2bcd(s); + buffer[sc_offs + 5] = bin2bcd(f); + FRAMES_TO_MSF(lba + 150, &m, &s, &f); + buffer[sc_offs + 7] = bin2bcd(m); + buffer[sc_offs + 8] = bin2bcd(s); + buffer[sc_offs + 9] = bin2bcd(f); + } + } else { + memset(&req, 0x00, sizeof(SCSI_PASS_THROUGH_DIRECT_BUF)); + req.spt.Length = sizeof(SCSI_PASS_THROUGH_DIRECT); + req.spt.PathId = 0; + req.spt.TargetId = 1; + req.spt.Lun = 0; + req.spt.CdbLength = 12; + req.spt.DataIn = SCSI_IOCTL_DATA_IN; + req.spt.SenseInfoLength = sizeof(req.SenseBuf); + req.spt.DataTransferLength = len; + req.spt.TimeOutValue = 6; + req.spt.DataBuffer = buffer; + req.spt.SenseInfoOffset = offsetof(SCSI_PASS_THROUGH_DIRECT_BUF, SenseBuf); + + /* Fill in the CDB. */ + req.spt.Cdb[0] = 0xbe; /* READ CD */ + req.spt.Cdb[1] = 0x00; + req.spt.Cdb[2] = (sector >> 24) & 0xff; + req.spt.Cdb[3] = (sector >> 16) & 0xff; + req.spt.Cdb[4] = (sector >> 8) & 0xff; + req.spt.Cdb[5] = sector & 0xff; /* Starting Logical Block Address. */ + req.spt.Cdb[6] = 0x00; + req.spt.Cdb[7] = 0x00; + req.spt.Cdb[8] = 0x01; /* Transfer Length. */ + /* If sector is FFFFFFFF, only return the subchannel. */ + req.spt.Cdb[9] = (sector == 0xffffffff) ? 0x00 : 0xf8; + req.spt.Cdb[10] = 0x02; + req.spt.Cdb[11] = 0x00; + DWORD length = sizeof(SCSI_PASS_THROUGH_DIRECT_BUF); + +#ifdef ENABLE_IOCTL_LOG + uint8_t *cdb = (uint8_t *) req.spt.Cdb; + ioctl_log(ioctl->log, "Host CDB: %02X %02X %02X %02X %02X %02X " + "%02X %02X %02X %02X %02X %02X\n", + ioctl->dev->id, cdb[0], cdb[1], cdb[2], cdb[3], cdb[4], cdb[5], + cdb[6], cdb[7], cdb[8], cdb[9], cdb[10], cdb[11]); +#endif + + ret = DeviceIoControl(ioctl->handle, IOCTL_SCSI_PASS_THROUGH_DIRECT, + &req, length, + &req, length, &unused, NULL); + } + + ioctl_log(ioctl->log, "ioctl_read_sector: ret = %d, req.spt.DataTransferLength = %lu\n", + ret, req.spt.DataTransferLength); + ioctl_log(ioctl->log, "Sense: %08X, %08X\n", req.spt.SenseInfoLength, req.spt.SenseInfoOffset); + if (req.spt.SenseInfoLength >= 16) { + uint8_t *cdb = (uint8_t *) req.SenseBuf; + if ((cdb[2] == 0x03) && (cdb[12] == 0x11)) + /* Treat this as an error to corectly indicate CIRC error to the guest. */ + ret = 0; + ioctl_log(ioctl->log, "Host sense: %02X %02X %02X %02X %02X %02X %02X %02X\n", + cdb[0], cdb[1], cdb[ 2], cdb[ 3], cdb[ 4], cdb[ 5], cdb[ 6], cdb[ 7]); + ioctl_log(ioctl->log, " %02X %02X %02X %02X %02X %02X %02X %02X\n", + cdb[8], cdb[9], cdb[10], cdb[11], cdb[12], cdb[13], cdb[14], cdb[15]); + } + + ret = (!!ret > 0) ? (req.spt.DataTransferLength >= len) : -1; + ioctl_log(ioctl->log, "iocl_read_sector: final ret = %i\n", ret); /* Construct raw subchannel data from Q only. */ - if (ret && (req.spt.DataTransferLength >= 2368)) + if ((ret > 0) && (req.spt.DataTransferLength >= len)) for (int i = 11; i >= 0; i--) for (int j = 7; j >= 0; j--) buffer[2352 + (i * 8) + j] = ((buffer[sc_offs + i] >> (7 - j)) & 0x01) << 6; - win_cdrom_ioctl_log("plat_cdrom_read_scsi_direct: ret = %d, req.spt.DataTransferLength = %lu\n", - ret, req.spt.DataTransferLength); - win_cdrom_ioctl_log("Sense: %08X, %08X\n", req.spt.SenseInfoLength, req.spt.SenseInfoOffset); - return ret && (req.spt.DataTransferLength >= 2368); + return ret; } -void -plat_cdrom_eject(void *local) +static uint8_t +ioctl_get_track_type(const void *local, const uint32_t sector) { - win_cdrom_ioctl_t *ioctl = (win_cdrom_ioctl_t *) local; - long size; + ioctl_t * ioctl = (ioctl_t *) local; + int track = ioctl_get_track(ioctl, sector); + raw_track_info_t * rti = (raw_track_info_t *) ioctl->cur_rti; + const raw_track_info_t *trk = &(rti[track]); + uint8_t ret = 0x00; - plat_cdrom_open(ioctl); - DeviceIoControl(ioctl->handle, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, (LPDWORD) &size, NULL); - plat_cdrom_close(ioctl); + if (ioctl_is_track_audio(ioctl, sector)) + ret = CD_TRACK_AUDIO; + else if (track != -1) for (int i = 0; i < ioctl->blocks_num; i++) { + const raw_track_info_t *ct = &(rti[i]); + const raw_track_info_t *nt = &(rti[i + 1]); + + if (ct->point == 0xa0) { + uint8_t first = ct->pm; + uint8_t last = nt->pm; + + if ((trk->point >= first) && (trk->point <= last)) { + ret = ct->ps; + break; + } + } + } + + return ret; } -void -plat_cdrom_close(void *local) +static uint32_t +ioctl_get_last_block(const void *local) { - win_cdrom_ioctl_t *ioctl = (win_cdrom_ioctl_t *) local; + const ioctl_t * ioctl = (const ioctl_t *) local; + raw_track_info_t *rti = (raw_track_info_t *) ioctl->cur_rti; + uint32_t lb = 0; - plat_cdrom_close_handle(ioctl); + for (int i = (ioctl->blocks_num - 1); i >= 0; i--) + if (rti[i].point == 0xa2) { + lb = MSFtoLBA(rti[i].pm, rti[i].ps, rti[i].pf) - 151; + break; + } + + ioctl_log(ioctl->log, "LBCapacity=%d\n", lb); + + return lb; +} + +static int +ioctl_read_dvd_structure(const void *local, const uint8_t layer, const uint8_t format, + uint8_t *buffer, uint32_t *info) +{ + typedef struct SCSI_PASS_THROUGH_DIRECT_BUF { + SCSI_PASS_THROUGH_DIRECT spt; + ULONG Filler; + UCHAR SenseBuf[64]; + } SCSI_PASS_THROUGH_DIRECT_BUF; + + const ioctl_t * ioctl = (const ioctl_t *) local; + unsigned long int unused = 0; + const int len = 2052; + SCSI_PASS_THROUGH_DIRECT_BUF req; + + memset(&req, 0x00, sizeof(SCSI_PASS_THROUGH_DIRECT_BUF)); + req.spt.Length = sizeof(SCSI_PASS_THROUGH_DIRECT); + req.spt.PathId = 0; + req.spt.TargetId = 1; + req.spt.Lun = 0; + req.spt.CdbLength = 12; + req.spt.DataIn = SCSI_IOCTL_DATA_IN; + req.spt.SenseInfoLength = sizeof(req.SenseBuf); + req.spt.DataTransferLength = len; + req.spt.TimeOutValue = 6; + req.spt.DataBuffer = buffer; + req.spt.SenseInfoOffset = offsetof(SCSI_PASS_THROUGH_DIRECT_BUF, SenseBuf); + + /* Fill in the CDB. */ + req.spt.Cdb[0] = 0xad; + req.spt.Cdb[1] = 0x00; + req.spt.Cdb[2] = 0x00; + req.spt.Cdb[3] = 0x00; + req.spt.Cdb[4] = 0x00; + req.spt.Cdb[5] = 0x00; + req.spt.Cdb[6] = layer; /* Layer Number */ + req.spt.Cdb[7] = format; /* Format */ + req.spt.Cdb[8] = 0x08; /* Allocation Length */ + req.spt.Cdb[9] = 0x04; + req.spt.Cdb[10] = 0x00; /* AGID */ + req.spt.Cdb[11] = 0x00; + + DWORD length = sizeof(SCSI_PASS_THROUGH_DIRECT_BUF); + +#ifdef ENABLE_IOCTL_LOG + uint8_t *cdb = (uint8_t *) req.spt.Cdb; + ioctl_log(ioctl->log, "Host CDB: %02X %02X %02X %02X %02X %02X " + "%02X %02X %02X %02X %02X %02X\n", + cdb[0], cdb[1], cdb[2], cdb[3], cdb[4], cdb[5], + cdb[6], cdb[7], cdb[8], cdb[9], cdb[10], cdb[11]); +#endif + + int ret = DeviceIoControl(ioctl->handle, IOCTL_SCSI_PASS_THROUGH_DIRECT, + &req, length, + &req, length, + &unused, NULL); + + ioctl_log(ioctl->log, "ioctl_read_dvd_structure(): ret = %d, " + "req.spt.DataTransferLength = %lu\n", + ret, req.spt.DataTransferLength); + ioctl_log(ioctl->log, "Sense: %08X, %08X\n", req.spt.SenseInfoLength, + req.spt.SenseInfoOffset); + + if (req.spt.SenseInfoLength >= 16) { + uint8_t *sb = (uint8_t *) req.SenseBuf; + /* Return sense to the host as is. */ + ret = -((sb[2] << 16) | (sb[12] << 8) | sb[13]); + if (info != NULL) + *info = *(uint32_t *) &(sb[3]); + ioctl_log(ioctl->log, "Host sense: %02X %02X %02X %02X %02X %02X %02X %02X\n", + sb[0], sb[1], sb[ 2], sb[ 3], sb[ 4], sb[ 5], sb[ 6], sb[ 7]); + ioctl_log(ioctl->log, " %02X %02X %02X %02X %02X %02X %02X %02X\n", + sb[8], sb[9], sb[10], sb[11], sb[12], sb[13], sb[14], sb[15]); + } else + ret = ret ? (req.spt.DataTransferLength >= len) : 0; + + return ret; +} + +static int +ioctl_is_dvd(const void *local) +{ + const ioctl_t *ioctl = (const ioctl_t *) local; + + return ioctl->is_dvd; +} + +static int +ioctl_has_audio(const void *local) +{ + const ioctl_t *ioctl = (const ioctl_t *) local; + + return ioctl->has_audio; +} + +static int +ioctl_is_empty(const void *local) +{ + typedef struct SCSI_PASS_THROUGH_DIRECT_BUF { + SCSI_PASS_THROUGH_DIRECT spt; + ULONG Filler; + UCHAR SenseBuf[64]; + } SCSI_PASS_THROUGH_DIRECT_BUF; + + const ioctl_t * ioctl = (const ioctl_t *) local; + unsigned long int unused = 0; + SCSI_PASS_THROUGH_DIRECT_BUF req; + + memset(&req, 0x00, sizeof(SCSI_PASS_THROUGH_DIRECT_BUF)); + req.spt.Length = sizeof(SCSI_PASS_THROUGH_DIRECT); + req.spt.PathId = 0; + req.spt.TargetId = 1; + req.spt.Lun = 0; + req.spt.CdbLength = 12; + req.spt.DataIn = SCSI_IOCTL_DATA_IN; + req.spt.SenseInfoLength = sizeof(req.SenseBuf); + req.spt.DataTransferLength = 0; + req.spt.TimeOutValue = 6; + req.spt.DataBuffer = NULL; + req.spt.SenseInfoOffset = offsetof(SCSI_PASS_THROUGH_DIRECT_BUF, SenseBuf); + + /* Fill in the CDB. */ + req.spt.Cdb[0] = 0x00; + req.spt.Cdb[1] = 0x00; + req.spt.Cdb[2] = 0x00; + req.spt.Cdb[3] = 0x00; + req.spt.Cdb[4] = 0x00; + req.spt.Cdb[5] = 0x00; + req.spt.Cdb[6] = 0x00; + req.spt.Cdb[7] = 0x00; + req.spt.Cdb[8] = 0x00; + req.spt.Cdb[9] = 0x00; + req.spt.Cdb[10] = 0x00; + req.spt.Cdb[11] = 0x00; + + DWORD length = sizeof(SCSI_PASS_THROUGH_DIRECT_BUF); + +#ifdef ENABLE_IOCTL_LOG + uint8_t *cdb = (uint8_t *) req.spt.Cdb; + ioctl_log(ioctl->log, "Host CDB: %02X %02X %02X %02X %02X %02X " + "%02X %02X %02X %02X %02X %02X\n", + cdb[0], cdb[1], cdb[2], cdb[3], cdb[4], cdb[5], + cdb[6], cdb[7], cdb[8], cdb[9], cdb[10], cdb[11]); +#endif + + int ret = DeviceIoControl(ioctl->handle, IOCTL_SCSI_PASS_THROUGH_DIRECT, + &req, length, + &req, length, + &unused, NULL); + + ioctl_log(ioctl->log, "ioctl_read_dvd_structure(): ret = %d, " + "req.spt.DataTransferLength = %lu\n", + ret, req.spt.DataTransferLength); + ioctl_log(ioctl->log, "Sense: %08X, %08X\n", req.spt.SenseInfoLength, + req.spt.SenseInfoOffset); + + if (req.spt.SenseInfoLength >= 16) { + uint8_t *sb = (uint8_t *) req.SenseBuf; + /* Return sense to the host as is. */ + ret = ((sb[2] == SENSE_NOT_READY) && (sb[12] == ASC_MEDIUM_NOT_PRESENT)); + ioctl_log(ioctl->log, "Host sense: %02X %02X %02X %02X %02X %02X %02X %02X\n", + sb[0], sb[1], sb[ 2], sb[ 3], sb[ 4], sb[ 5], sb[ 6], sb[ 7]); + ioctl_log(ioctl->log, " %02X %02X %02X %02X %02X %02X %02X %02X\n", + sb[8], sb[9], sb[10], sb[11], sb[12], sb[13], sb[14], sb[15]); + } else + ret = 0; + + return ret; +} + +static void +ioctl_close(void *local) +{ + ioctl_t *ioctl = (ioctl_t *) local; + + ioctl_close_handle(ioctl); ioctl->handle = NULL; + + ioctl_log(ioctl->log, "Log closed\n"); + + log_close(ioctl->log); + ioctl->log = NULL; + + cdrom_assigned_letters &= ~(1 << ioctl->dev->host_letter); + ioctl->dev->host_letter = 0xff; + + free(ioctl); } -int -plat_cdrom_set_drive(void *local, const char *drv) +static void +ioctl_load(const void *local) { - win_cdrom_ioctl_t *ioctl = (win_cdrom_ioctl_t *) local; + const ioctl_t *ioctl = (const ioctl_t *) local; - plat_cdrom_close(ioctl); + if ((ioctl->handle != NULL) || ioctl_open_handle((ioctl_t *) ioctl)) { + long size = 0; + (void) DeviceIoControl(ioctl->handle, IOCTL_STORAGE_LOAD_MEDIA, + NULL, 0, NULL, 0, + (LPDWORD) &size, NULL); - memcpy(ioctl->old_path, ioctl->path, sizeof(ioctl->path)); - memset(ioctl->path, 0x00, sizeof(ioctl->path)); - - wsprintf(ioctl->path, L"%S", drv); - win_cdrom_ioctl_log("Path is %S\n", ioctl->path); - - ioctl->toc_valid = 0; - - plat_cdrom_load(ioctl); - - return 1; + ioctl_read_raw_toc((ioctl_t *) ioctl); + } } -int -plat_cdrom_get_local_size(void) +static const cdrom_ops_t ioctl_ops = { + ioctl_get_track_info, + ioctl_get_raw_track_info, + ioctl_is_track_pre, + ioctl_read_sector, + ioctl_get_track_type, + ioctl_get_last_block, + ioctl_read_dvd_structure, + ioctl_is_dvd, + ioctl_has_audio, + ioctl_is_empty, + ioctl_close, + ioctl_load +}; + +/* Public functions. */ +void * +ioctl_open(cdrom_t *dev, const char *drv) { - return sizeof(win_cdrom_ioctl_t); + ioctl_t *ioctl = (ioctl_t *) calloc(1, sizeof(ioctl_t)); + + if (ioctl != NULL) { + char n[1024] = { 0 }; + + sprintf(n, "CD-ROM %i IOCtl", dev->id + 1); + ioctl->log = log_open(n); + + memset(ioctl->path, 0x00, sizeof(ioctl->path)); + + wsprintf(ioctl->path, L"%S", &(drv[8])); + ioctl_log(ioctl->log, "Path is %S\n", ioctl->path); + + ioctl->dev = dev; + + dev->ops = &ioctl_ops; + + dev->host_letter = (drv[12] & 0xdf) - 0x41; + cdrom_assigned_letters |= (1 << dev->host_letter); + + ioctl_load(ioctl); + } + + return ioctl; } diff --git a/src/qt/win_dynld.c b/src/qt/win_dynld.c index 88fb632bc..e4d9d5a13 100644 --- a/src/qt/win_dynld.c +++ b/src/qt/win_dynld.c @@ -51,7 +51,7 @@ dynld_module(const char *name, dllimp_t *table) void *func; /* See if we can load the desired module. */ - if ((h = LoadLibrary(name)) == NULL) { + if ((h = LoadLibraryA(name)) == NULL) { dynld_log("DynLd(\"%s\"): library not found! (%08X)\n", name, GetLastError()); return (NULL); } diff --git a/src/qt/win_joystick_rawinput.c b/src/qt/win_joystick_rawinput.c index bb05c3f5c..5173d4f05 100644 --- a/src/qt/win_joystick_rawinput.c +++ b/src/qt/win_joystick_rawinput.c @@ -8,15 +8,13 @@ * * RawInput joystick interface. * - * - * * Authors: Miran Grca, * GH Cao, - * Jasmine Iwanek, + * Jasmine Iwanek, * * Copyright 2016-2018 Miran Grca. * Copyright 2020 GH Cao. - * Copyright 2021-2023 Jasmine Iwanek. + * Copyright 2021-2025 Jasmine Iwanek. */ #include #include @@ -98,9 +96,9 @@ typedef struct { } pov[MAX_JOY_POVS]; } raw_joystick_t; -plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS]; -joystick_t joystick_state[MAX_JOYSTICKS]; int joysticks_present = 0; +joystick_t joystick_state[GAMEPORT_MAX][MAX_JOYSTICKS]; +plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS]; raw_joystick_t raw_joystick_state[MAX_PLAT_JOYSTICKS]; @@ -412,21 +410,21 @@ win_joystick_handle(PRAWINPUT raw) /* Read buttons */ USAGE usage_list[128] = { 0 }; ULONG usage_length = plat_joystick_state[j].nr_buttons; - memset(plat_joystick_state[j].b, 0, 32 * sizeof(int)); + memset(plat_joystick_state[j].b, 0, MAX_JOY_BUTTONS * sizeof(int)); r = HidP_GetUsages(HidP_Input, HID_USAGE_PAGE_BUTTON, 0, usage_list, &usage_length, raw_joystick_state[j].data, (PCHAR) raw->data.hid.bRawData, raw->data.hid.dwSizeHid); if (r == HIDP_STATUS_SUCCESS) { for (int i = 0; i < usage_length; i++) { - int button = raw_joystick_state[j].usage_button[usage_list[i]]; + int button = raw_joystick_state[j].usage_button[usage_list[i]]; plat_joystick_state[j].b[button] = 128; } } /* Read axes */ - for (int a = 0; a < plat_joystick_state[j].nr_axes; a++) { - const struct raw_axis_t *axis = &raw_joystick_state[j].axis[a]; + for (int axis_nr = 0; axis_nr < plat_joystick_state[j].nr_axes; axis_nr++) { + const struct raw_axis_t *axis = &raw_joystick_state[j].axis[axis_nr]; ULONG uvalue = 0; LONG value = 0; LONG center = (axis->max - axis->min + 1) / 2; @@ -453,15 +451,15 @@ win_joystick_handle(PRAWINPUT raw) value = value * 32768 / center; } - plat_joystick_state[j].a[a] = value; + plat_joystick_state[j].a[axis_nr] = value; #if 0 - joystick_log("%s %-06d ", plat_joystick_state[j].axis[a].name, plat_joystick_state[j].a[a]); + joystick_log("%s %-06d ", plat_joystick_state[0][j].axis[axis_nr].name, plat_joystick_state[j].a[axis_nr]); #endif } /* read povs */ - for (int p = 0; p < plat_joystick_state[j].nr_povs; p++) { - const struct raw_pov_t *pov = &raw_joystick_state[j].pov[p]; + for (int pov_nr = 0; pov_nr < plat_joystick_state[j].nr_povs; pov_nr++) { + const struct raw_pov_t *pov = &raw_joystick_state[j].pov[pov_nr]; ULONG uvalue = 0; LONG value = -1; @@ -474,10 +472,10 @@ win_joystick_handle(PRAWINPUT raw) value %= 36000; } - plat_joystick_state[j].p[p] = value; + plat_joystick_state[j].p[pov_nr] = value; #if 0 - joystick_log("%s %-3d ", plat_joystick_state[j].pov[p].name, plat_joystick_state[j].p[p]); + joystick_log("%s %-3d ", plat_joystick_state[0][j].pov[pov_nr].name, plat_joystick_state[j].p[pov_nr]); #endif } #if 0 @@ -508,44 +506,39 @@ joystick_get_axis(int joystick_nr, int mapping) void joystick_process(void) { - int d; - if (joystick_type == JS_TYPE_NONE) return; - 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; + for (int js = 0; js < joystick_get_max_joysticks(joystick_type); js++) { + if (joystick_state[0][js].plat_joystick_nr) { + int joystick_nr = joystick_state[0][js].plat_joystick_nr - 1; - for (d = 0; d < joystick_get_axis_count(joystick_type); d++) - joystick_state[c].axis[d] = joystick_get_axis(joystick_nr, joystick_state[c].axis_mapping[d]); - for (d = 0; d < joystick_get_button_count(joystick_type); d++) - joystick_state[c].button[d] = plat_joystick_state[joystick_nr].b[joystick_state[c].button_mapping[d]]; + for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) + joystick_state[0][js].axis[axis_nr] = joystick_get_axis(joystick_nr, joystick_state[0][js].axis_mapping[axis_nr]); - for (d = 0; d < joystick_get_pov_count(joystick_type); d++) { - int x; - int y; - double angle; - double magnitude; + for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) + joystick_state[0][js].button[button_nr] = plat_joystick_state[joystick_nr].b[joystick_state[0][js].button_mapping[button_nr]]; - 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]); - - angle = (atan2((double) y, (double) x) * 360.0) / (2 * M_PI); - magnitude = sqrt((double) x * (double) x + (double) y * (double) y); + for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) { + int x = joystick_get_axis(joystick_nr, joystick_state[0][js].pov_mapping[pov_nr][0]); + int y = joystick_get_axis(joystick_nr, joystick_state[0][js].pov_mapping[pov_nr][1]); + double angle = (atan2((double) y, (double) x) * 360.0) / (2 * M_PI); + double magnitude = sqrt((double) x * (double) x + (double) y * (double) y); if (magnitude < 16384) - joystick_state[c].pov[d] = -1; + joystick_state[0][js].pov[pov_nr] = -1; else - joystick_state[c].pov[d] = ((int) angle + 90 + 360) % 360; + joystick_state[0][js].pov[pov_nr] = ((int) angle + 90 + 360) % 360; } } else { - for (d = 0; d < joystick_get_axis_count(joystick_type); d++) - joystick_state[c].axis[d] = 0; - for (d = 0; d < joystick_get_button_count(joystick_type); d++) - joystick_state[c].button[d] = 0; - for (d = 0; d < joystick_get_pov_count(joystick_type); d++) - joystick_state[c].pov[d] = -1; + for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) + joystick_state[0][js].axis[axis_nr] = 0; + + for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) + joystick_state[0][js].button[button_nr] = 0; + + for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) + joystick_state[0][js].pov[pov_nr] = -1; } } } diff --git a/src/qt/win_netsocket.c b/src/qt/win_netsocket.c index 55a84d414..d7d467c07 100644 --- a/src/qt/win_netsocket.c +++ b/src/qt/win_netsocket.c @@ -82,10 +82,12 @@ SOCKET plat_netsocket_accept(SOCKET socket) { SOCKET clientsocket = accept(socket, NULL, NULL); + u_long yes = 1; if (clientsocket == INVALID_SOCKET) return -1; + ioctlsocket(clientsocket, FIONBIO, &yes); return clientsocket; } diff --git a/src/qt/win_opendir.c b/src/qt/win_opendir.c index 051ed20bb..46c7eb21e 100644 --- a/src/qt/win_opendir.c +++ b/src/qt/win_opendir.c @@ -40,21 +40,19 @@ opendir(const char *name) DIR *p; /* Create a new control structure. */ - p = (DIR *) malloc(sizeof(DIR)); + p = (DIR *) calloc(1, sizeof(DIR)); if (p == NULL) return (NULL); - memset(p, 0x00, sizeof(DIR)); p->flags = (DIR_F_LOWER | DIR_F_SANE); p->offset = 0; p->sts = 0; /* Create a work area. */ - p->dta = (char *) malloc(sizeof(FINDATA)); + p->dta = (char *) calloc(1, sizeof(FINDATA)); if (p->dta == NULL) { free(p); return (NULL); } - memset(p->dta, 0x00, sizeof(struct _finddata_t)); /* Add search filespec. */ strcpy(p->dir, name); diff --git a/src/qt/win_serial_passthrough.c b/src/qt/win_serial_passthrough.c index 2b77bd219..c1802ce73 100644 --- a/src/qt/win_serial_passthrough.c +++ b/src/qt/win_serial_passthrough.c @@ -88,7 +88,7 @@ plat_serpt_set_params(void *priv) const serial_passthrough_t *dev = (serial_passthrough_t *) priv; if (dev->mode == SERPT_MODE_HOSTSER) { - DCB serialattr = {}; + DCB serialattr = { 0 }; GetCommState((HANDLE) dev->master_fd, &serialattr); #define BAUDRATE_RANGE(baud_rate, min, max) \ if (baud_rate >= min && baud_rate < max) { \ diff --git a/src/qt/wl_mouse.cpp b/src/qt/wl_mouse.cpp index 5d6d95a0a..9201c4ec8 100644 --- a/src/qt/wl_mouse.cpp +++ b/src/qt/wl_mouse.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -30,10 +31,12 @@ extern "C" { #include <86box/plat.h> } -static zwp_relative_pointer_manager_v1 *rel_manager = nullptr; -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 zwp_relative_pointer_manager_v1 *rel_manager = nullptr; +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 zwp_keyboard_shortcuts_inhibit_manager_v1 *kbd_manager = nullptr; +static zwp_keyboard_shortcuts_inhibitor_v1 *kbd_inhibitor = nullptr; static bool wl_init_ok = false; @@ -47,6 +50,12 @@ static struct zwp_relative_pointer_v1_listener rel_listener = { rel_mouse_event }; +static struct zwp_keyboard_shortcuts_inhibitor_v1_listener kbd_listener +{ + [](void *data, struct zwp_keyboard_shortcuts_inhibitor_v1 *zwp_keyboard_shortcuts_inhibitor_v1) -> void {}, + [](void *data, struct zwp_keyboard_shortcuts_inhibitor_v1 *zwp_keyboard_shortcuts_inhibitor_v1) -> void {} +}; + static void display_handle_global(void *data, struct wl_registry *registry, uint32_t id, const char *interface, uint32_t version) @@ -57,16 +66,25 @@ display_handle_global(void *data, struct wl_registry *registry, uint32_t id, if (!strcmp(interface, "zwp_pointer_constraints_v1")) { conf_pointer_interface = (zwp_pointer_constraints_v1 *) wl_registry_bind(registry, id, &zwp_pointer_constraints_v1_interface, version); } + if (!strcmp(interface, "zwp_keyboard_shortcuts_inhibit_manager_v1")) { + kbd_manager = (zwp_keyboard_shortcuts_inhibit_manager_v1 *) wl_registry_bind(registry, id, &zwp_keyboard_shortcuts_inhibit_manager_v1_interface, version); + } } static void display_global_remove(void *data, struct wl_registry *wl_registry, uint32_t name) { plat_mouse_capture(0); + if (kbd_inhibitor) { + zwp_keyboard_shortcuts_inhibitor_v1_destroy(kbd_inhibitor); + kbd_inhibitor = nullptr; + } + zwp_keyboard_shortcuts_inhibit_manager_v1_destroy(kbd_manager); zwp_relative_pointer_manager_v1_destroy(rel_manager); zwp_pointer_constraints_v1_destroy(conf_pointer_interface); rel_manager = nullptr; conf_pointer_interface = nullptr; + kbd_manager = nullptr; } static const struct wl_registry_listener registry_listener = { @@ -90,9 +108,20 @@ wl_init() } } +void +wl_keyboard_grab(QWindow *window) +{ + if (!kbd_inhibitor && kbd_manager) { + kbd_inhibitor = zwp_keyboard_shortcuts_inhibit_manager_v1_inhibit_shortcuts(kbd_manager, (wl_surface *) QGuiApplication::platformNativeInterface()->nativeResourceForWindow("surface", window), (wl_seat *) QGuiApplication::platformNativeInterface()->nativeResourceForIntegration("wl_seat")); + } +} + void wl_mouse_capture(QWindow *window) { + if (!kbd_inhibitor) { + kbd_inhibitor = zwp_keyboard_shortcuts_inhibit_manager_v1_inhibit_shortcuts(kbd_manager, (wl_surface *) QGuiApplication::platformNativeInterface()->nativeResourceForWindow("surface", window), (wl_seat *) QGuiApplication::platformNativeInterface()->nativeResourceForIntegration("wl_seat")); + } if (rel_manager) { rel_pointer = zwp_relative_pointer_manager_v1_get_relative_pointer(rel_manager, (wl_pointer *) QGuiApplication::platformNativeInterface()->nativeResourceForIntegration("wl_pointer")); zwp_relative_pointer_v1_add_listener(rel_pointer, &rel_listener, nullptr); diff --git a/src/qt_resources.qrc b/src/qt_resources.qrc index 1f6341786..51518b8f6 100644 --- a/src/qt_resources.qrc +++ b/src/qt_resources.qrc @@ -1,16 +1,9 @@ qt/icons/cartridge.ico - qt/icons/cartridge_empty.ico qt/icons/cassette.ico - qt/icons/cassette_active.ico - qt/icons/cassette_empty.ico - qt/icons/cassette_empty_active.ico qt/icons/cdrom.ico - qt/icons/cdrom_active.ico qt/icons/cdrom_disabled.ico - qt/icons/cdrom_empty.ico - qt/icons/cdrom_empty_active.ico qt/icons/cdrom_mute.ico qt/icons/cdrom_unmute.ico qt/icons/cdrom_image.ico @@ -18,41 +11,37 @@ qt/icons/cdrom_host.ico qt/icons/display.ico qt/icons/floppy_35.ico - qt/icons/floppy_35_active.ico - qt/icons/floppy_35_empty.ico - qt/icons/floppy_35_empty_active.ico qt/icons/floppy_525.ico - qt/icons/floppy_525_active.ico - qt/icons/floppy_525_empty.ico - qt/icons/floppy_525_empty_active.ico qt/icons/floppy_and_cdrom_drives.ico qt/icons/floppy_disabled.ico qt/icons/hard_disk.ico - qt/icons/hard_disk_active.ico qt/icons/input_devices.ico qt/icons/machine.ico qt/icons/mo.ico - qt/icons/mo_active.ico qt/icons/mo_disabled.ico - qt/icons/mo_empty.ico - qt/icons/mo_empty_active.ico qt/icons/network.ico - qt/icons/network_active.ico - qt/icons/network_empty.ico qt/icons/other_peripherals.ico qt/icons/other_removable_devices.ico qt/icons/ports.ico qt/icons/sound.ico qt/icons/storage_controllers.ico qt/icons/zip.ico - qt/icons/zip_active.ico qt/icons/zip_disabled.ico - qt/icons/zip_empty.ico - qt/icons/zip_empty_active.ico + qt/icons/active.ico + qt/icons/write_active.ico + qt/icons/disabled.ico qt/icons/86Box-gray.ico qt/icons/86Box-green.ico qt/icons/86Box-red.ico qt/icons/86Box-yellow.ico + qt/icons/caps_lock_off.ico + qt/icons/caps_lock_on.ico + qt/icons/kana_lock_off.ico + qt/icons/kana_lock_on.ico + qt/icons/num_lock_off.ico + qt/icons/num_lock_on.ico + qt/icons/scroll_lock_off.ico + qt/icons/scroll_lock_on.ico qt/icons/acpi_shutdown.ico @@ -70,4 +59,95 @@ qt/texture_vert.spv qt/texture_frag.spv + + qt/assets/86Box-green.png + qt/assets/86box-rb.png + qt/assets/86box-red.png + qt/assets/86box-yellow.png + qt/assets/86box.png + qt/assets/86box-wizard.png + + + qt/assets/systemicons/cpq_deskpro.png + qt/assets/systemicons/cpq_port_386.png + qt/assets/systemicons/cpq_port_II.png + qt/assets/systemicons/cpq_port_III.png + qt/assets/systemicons/cpq_portable.png + qt/assets/systemicons/cpq_pres_2240.png + qt/assets/systemicons/cpq_pres_4500.png + qt/assets/systemicons/ibm330.png + qt/assets/systemicons/ibm_at.png + qt/assets/systemicons/ibm_pc_81.png + qt/assets/systemicons/ibm_pc_82.png + qt/assets/systemicons/ibm_pcjr.png + qt/assets/systemicons/ibm_ps2_m70.png + qt/assets/systemicons/ibm_ps2_m80.png + qt/assets/systemicons/ibm_psvp_486.png + qt/assets/systemicons/ibm_psvp_p60.png + qt/assets/systemicons/ibm_xt_82.png + qt/assets/systemicons/ibm_xt_86.png + qt/assets/systemicons/olivetti_m19.png + qt/assets/systemicons/olivetti_m21.png + qt/assets/systemicons/olivetti_m24.png + qt/assets/systemicons/olivetti_m24sp.png + qt/assets/systemicons/os_archlinux_x2.png + qt/assets/systemicons/os_cloud_x2.png + qt/assets/systemicons/os_debian_x2.png + qt/assets/systemicons/os_dos_x2.png + qt/assets/systemicons/os_fedora_x2.png + qt/assets/systemicons/os_freebsd_x2.png + qt/assets/systemicons/os_gentoo_x2.png + qt/assets/systemicons/os_jrockitve_x2.png + qt/assets/systemicons/os_l4_x2.png + qt/assets/systemicons/os_linux22_x2.png + qt/assets/systemicons/os_linux24_x2.png + qt/assets/systemicons/os_linux26_x2.png + qt/assets/systemicons/os_linux_x2.png + qt/assets/systemicons/os_macosx_x2.png + qt/assets/systemicons/os_mandriva_x2.png + qt/assets/systemicons/os_netbsd_x2.png + qt/assets/systemicons/os_netware_x2.png + qt/assets/systemicons/os_openbsd_x2.png + qt/assets/systemicons/os_opensuse_x2.png + qt/assets/systemicons/os_oracle_x2.png + qt/assets/systemicons/os_oraclesolaris_x2.png + qt/assets/systemicons/os_os2_other_x2.png + qt/assets/systemicons/os_os2ecs_x2.png + qt/assets/systemicons/os_os2warp3_x2.png + qt/assets/systemicons/os_os2warp45_x2.png + qt/assets/systemicons/os_os2warp4_x2.png + qt/assets/systemicons/os_other_x2.png + qt/assets/systemicons/os_qnx_x2.png + qt/assets/systemicons/os_redhat_x2.png + qt/assets/systemicons/os_solaris_x2.png + qt/assets/systemicons/os_turbolinux_x2.png + qt/assets/systemicons/os_ubuntu_x2.png + qt/assets/systemicons/os_win10_x2.png + qt/assets/systemicons/os_win2k3_x2.png + qt/assets/systemicons/os_win2k8_x2.png + qt/assets/systemicons/os_win2k_x2.png + qt/assets/systemicons/os_win31_x2.png + qt/assets/systemicons/os_win7_x2.png + qt/assets/systemicons/os_win81_x2.png + qt/assets/systemicons/os_win8_x2.png + qt/assets/systemicons/os_win95_x2.png + qt/assets/systemicons/os_win98_x2.png + qt/assets/systemicons/os_win_other_x2.png + qt/assets/systemicons/os_winme_x2.png + qt/assets/systemicons/os_winnt4_x2.png + qt/assets/systemicons/os_winvista_x2.png + qt/assets/systemicons/os_winxp_x2.png + qt/assets/systemicons/os_xandros_x2.png + qt/assets/systemicons/pb_bora_pro.png + qt/assets/systemicons/pb_pb410.png + qt/assets/systemicons/pb_pb640.png + qt/assets/systemicons/pb_pb680.png + qt/assets/systemicons/tandy_1000.png + qt/assets/systemicons/tandy_1000_hx.png + qt/assets/systemicons/tandy_1000_sl2.png + qt/assets/systemicons/toshiba_t1000.png + qt/assets/systemicons/toshiba_t1200.png + qt/assets/systemicons/toshiba_t1200_hdd.png + + diff --git a/src/scsi/scsi.c b/src/scsi/scsi.c index bbce63651..0b0ca7211 100644 --- a/src/scsi/scsi.c +++ b/src/scsi/scsi.c @@ -54,6 +54,14 @@ typedef const struct { static SCSI_CARD scsi_cards[] = { // clang-format off { &device_none, }, + /* ISA/Sidecar */ + { &scsi_ls2000_device, }, + /* ISA */ + { &scsi_lcs6821n_device, }, + { &scsi_rt1000b_device, }, + { &scsi_t128_device, }, + { &scsi_t130b_device, }, + /* ISA16 */ { &aha154xa_device, }, { &aha154xb_device, }, { &aha154xc_device, }, @@ -63,18 +71,19 @@ static SCSI_CARD scsi_cards[] = { { &buslogic_542bh_device, }, { &buslogic_545s_device, }, { &buslogic_545c_device, }, - { &scsi_ls2000_device, }, - { &scsi_lcs6821n_device, }, - { &scsi_rt1000b_device, }, - { &scsi_rt1000mc_device, }, - { &scsi_t128_device, }, - { &scsi_t228_device, }, - { &scsi_t130b_device, }, + /* MCA */ { &aha1640_device, }, { &buslogic_640a_device, }, - { &ncr53c90a_mca_device, }, { &spock_device, }, { &tribble_device, }, + { &ncr53c90a_mca_device, }, + { &scsi_rt1000mc_device, }, + { &scsi_t228_device, }, + /* VLB */ + { &buslogic_445s_device, }, + { &buslogic_445c_device, }, + /* PCI */ + { &am53c974_pci_device, }, { &buslogic_958d_pci_device, }, { &ncr53c810_pci_device, }, { &ncr53c815_pci_device, }, @@ -82,10 +91,7 @@ static SCSI_CARD scsi_cards[] = { { &ncr53c825a_pci_device, }, { &ncr53c860_pci_device, }, { &ncr53c875_pci_device, }, - { &am53c974_pci_device, }, { &dc390_pci_device, }, - { &buslogic_445s_device, }, - { &buslogic_445c_device, }, { NULL, }, // clang-format on }; diff --git a/src/scsi/scsi_aha154x.c b/src/scsi/scsi_aha154x.c index 58779e7ac..7c887e28b 100644 --- a/src/scsi/scsi_aha154x.c +++ b/src/scsi/scsi_aha154x.c @@ -925,8 +925,7 @@ aha_setnvr(x54x_t *dev) return; /* Allocate and initialize the EEPROM. */ - dev->nvr = (uint8_t *) malloc(NVR_SIZE); - memset(dev->nvr, 0x00, NVR_SIZE); + dev->nvr = (uint8_t *) calloc(1, NVR_SIZE); fp = nvr_fopen(dev->nvr_path, "rb"); if (fp) { @@ -1159,14 +1158,14 @@ aha_init(const device_t *info) // clang-format off static const device_config_t aha_154xb_config[] = { { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x334, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x334, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "None", .value = 0 }, { .description = "0x330", .value = 0x330 }, { .description = "0x334", .value = 0x334 }, @@ -1176,16 +1175,17 @@ static const device_config_t aha_154xb_config[] = { { .description = "0x134", .value = 0x134 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 11, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 11, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "IRQ 9", .value = 9 }, { .description = "IRQ 10", .value = 10 }, { .description = "IRQ 11", .value = 11 }, @@ -1194,31 +1194,33 @@ static const device_config_t aha_154xb_config[] = { { .description = "IRQ 15", .value = 15 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "dma", - .description = "DMA", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 6, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "dma", + .description = "DMA", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 6, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "DMA 5", .value = 5 }, { .description = "DMA 6", .value = 6 }, { .description = "DMA 7", .value = 7 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "hostid", - .description = "Host ID", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 7, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "hostid", + .description = "Host ID", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 7, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "0", .value = 0 }, { .description = "1", .value = 1 }, { .description = "2", .value = 2 }, @@ -1229,16 +1231,17 @@ static const device_config_t aha_154xb_config[] = { { .description = "7", .value = 7 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "bios_addr", - .description = "BIOS Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "bios_addr", + .description = "BIOS Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Disabled", .value = 0 }, { .description = "C800H", .value = 0xc8000 }, { .description = "D000H", .value = 0xd0000 }, @@ -1246,20 +1249,21 @@ static const device_config_t aha_154xb_config[] = { { .description = "DC00H", .value = 0xdc000 }, { .description = "" } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t aha_154x_config[] = { { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x334, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x334, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "None", .value = 0 }, { .description = "0x330", .value = 0x330 }, { .description = "0x334", .value = 0x334 }, @@ -1269,16 +1273,17 @@ static const device_config_t aha_154x_config[] = { { .description = "0x134", .value = 0x134 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 11, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 11, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "IRQ 9", .value = 9 }, { .description = "IRQ 10", .value = 10 }, { .description = "IRQ 11", .value = 11 }, @@ -1287,52 +1292,55 @@ static const device_config_t aha_154x_config[] = { { .description = "IRQ 15", .value = 15 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "dma", - .description = "DMA", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 6, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "dma", + .description = "DMA", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 6, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "DMA 5", .value = 5 }, { .description = "DMA 6", .value = 6 }, { .description = "DMA 7", .value = 7 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "bios_addr", - .description = "BIOS Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "bios_addr", + .description = "BIOS Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Disabled", .value = 0 }, { .description = "C800H", .value = 0xc8000 }, { .description = "D000H", .value = 0xd0000 }, { .description = "D800H", .value = 0xd8000 }, { .description = "DC00H", .value = 0xdc000 }, { .description = "" } - }, }, + .bios = { { 0 } } + }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t aha_154xcf_config[] = { { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x334, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x334, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "None", .value = 0 }, { .description = "0x330", .value = 0x330 }, { .description = "0x334", .value = 0x334 }, @@ -1342,16 +1350,17 @@ static const device_config_t aha_154xcf_config[] = { { .description = "0x134", .value = 0x134 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 11, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 11, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "IRQ 9", .value = 9 }, { .description = "IRQ 10", .value = 10 }, { .description = "IRQ 11", .value = 11 }, @@ -1360,31 +1369,33 @@ static const device_config_t aha_154xcf_config[] = { { .description = "IRQ 15", .value = 15 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "dma", - .description = "DMA", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 6, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "dma", + .description = "DMA", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 6, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "DMA 5", .value = 5 }, { .description = "DMA 6", .value = 6 }, { .description = "DMA 7", .value = 7 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "bios_addr", - .description = "BIOS Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "bios_addr", + .description = "BIOS Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Disabled", .value = 0 }, { .description = "C800H", .value = 0xc8000 }, { .description = "CC00H", .value = 0xcc000 }, @@ -1394,44 +1405,64 @@ static const device_config_t aha_154xcf_config[] = { { .description = "DC00H", .value = 0xdc000 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "fdc_addr", - .description = "FDC Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "fdc_addr", + .description = "FDC Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "None", .value = 0 }, { .description = "0x3f0", .value = FDC_PRIMARY_ADDR }, { .description = "0x370", .value = FDC_SECONDARY_ADDR }, { .description = "" } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t aha_154xcp_config[] = { { - .name = "bios_rev", - .description = "BIOS Revision", - .type = CONFIG_BIOS, + .name = "bios_rev", + .description = "BIOS Revision", + .type = CONFIG_BIOS, .default_string = "v1_02_en", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, /*W1*/ - .bios = { - { .name = "Version 1.02 (English)", .internal_name = "v1_02_en", .bios_type = BIOS_NORMAL, - .files_no = 2, .local = 0, .size = 32768, .files = { "roms/scsi/adaptec/aha1542cp102.bin", - "roms/scsi/adaptec/908301-00_f_mcode_17c9.u12", "" } }, - { .name = "Version 1.02 (German)", .internal_name = "v1_02_de", .bios_type = BIOS_NORMAL, - .files_no = 2, .local = 0, .size = 32768, .files = { "roms/scsi/adaptec/buff_1-0_bios.bin", - "roms/scsi/adaptec/buff_1-0_mcode.bin", "" } }, - { .name = "Version 1.03 (English)", .internal_name = "v1_03_en", .bios_type = BIOS_NORMAL, - .files_no = 2, .local = 0, .size = 32768, .files = { "roms/scsi/adaptec/aha1542cp103.bin", - "roms/scsi/adaptec/908301-00_g_mcode_144c.u12.bin", "" } }, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .bios = { + { + .name = "Version 1.02 (English)", + .internal_name = "v1_02_en", + .bios_type = BIOS_NORMAL, + .files_no = 2, + .local = 0, + .size = 32768, + .files = { "roms/scsi/adaptec/aha1542cp102.bin", "roms/scsi/adaptec/908301-00_f_mcode_17c9.u12", "" } + }, + { + .name = "Version 1.02 (German)", + .internal_name = "v1_02_de", + .bios_type = BIOS_NORMAL, + .files_no = 2, + .local = 0, + .size = 32768, + .files = { "roms/scsi/adaptec/buff_1-0_bios.bin", "roms/scsi/adaptec/buff_1-0_mcode.bin", "" } + }, + { + .name = "Version 1.03 (English)", + .internal_name = "v1_03_en", + .bios_type = BIOS_NORMAL, + .files_no = 2, + .local = 0, + .size = 32768, + .files = { "roms/scsi/adaptec/aha1542cp103.bin", "roms/scsi/adaptec/908301-00_g_mcode_144c.u12.bin", "" } + }, { .files_no = 0 } }, }, @@ -1442,12 +1473,12 @@ static const device_config_t aha_154xcp_config[] = { const device_t aha154xa_device = { .name = "Adaptec AHA-154xA", .internal_name = "aha154xa", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = AHA_154xA, .init = aha_init, .close = x54x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = aha_154xb_config @@ -1456,12 +1487,12 @@ const device_t aha154xa_device = { const device_t aha154xb_device = { .name = "Adaptec AHA-154xB", .internal_name = "aha154xb", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = AHA_154xB, .init = aha_init, .close = x54x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = aha_154xb_config @@ -1470,12 +1501,12 @@ const device_t aha154xb_device = { const device_t aha154xc_device = { .name = "Adaptec AHA-154xC", .internal_name = "aha154xc", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = AHA_154xC, .init = aha_init, .close = x54x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = aha_154x_config @@ -1484,12 +1515,12 @@ const device_t aha154xc_device = { const device_t aha154xcf_device = { .name = "Adaptec AHA-154xCF", .internal_name = "aha154xcf", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = AHA_154xCF, .init = aha_init, .close = x54x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = aha_154xcf_config @@ -1498,12 +1529,12 @@ const device_t aha154xcf_device = { const device_t aha154xcp_device = { .name = "Adaptec AHA-154xCP", .internal_name = "aha154xcp", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = AHA_154xCP, .init = aha_init, .close = aha1542cp_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = aha_154xcp_config @@ -1517,7 +1548,7 @@ const device_t aha1640_device = { .init = aha_init, .close = x54x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/scsi/scsi_buslogic.c b/src/scsi/scsi_buslogic.c index b0aeedfa4..0e8954aff 100644 --- a/src/scsi/scsi_buslogic.c +++ b/src/scsi/scsi_buslogic.c @@ -256,6 +256,8 @@ buslogic_log(const char *fmt, ...) # define buslogic_log(fmt, ...) #endif +static x54x_t reset_state = { 0 }; + static char * BuslogicGetNVRFileName(buslogic_data_t *bl) { @@ -1084,7 +1086,7 @@ buslogic_interrupt_type(void *priv) } static void -buslogic_reset(void *priv) +buslogic_ven_reset(void *priv) { x54x_t *dev = (x54x_t *) priv; buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; @@ -1525,6 +1527,41 @@ BuslogicDeviceReset(void *priv) BuslogicInitializeAutoSCSIRam(dev); } +static void +buslogic_reset(void *priv) +{ + x54x_t *dev = (x54x_t *) priv; + buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; + + x54x_io_remove(dev, dev->Base, 4); + + if (bl->chip == CHIP_BUSLOGIC_PCI_958D_1995_12_30) { + x54x_mem_init(dev, 0xfffd0000); + x54x_mem_disable(dev); + } + + timer_disable(&dev->timer); + timer_disable(&dev->ResetCB); + + reset_state.mmio_mapping = dev->mmio_mapping; + + reset_state.bios.mapping = dev->bios.mapping; + reset_state.uppersck.mapping = dev->uppersck.mapping; + + reset_state.timer = dev->timer; + reset_state.ResetCB = dev->ResetCB; + + reset_state.pci_slot = dev->pci_slot; + + memcpy(dev, &reset_state, sizeof(x54x_t)); + + dev->timer.period = 10.0; + timer_set_delay_u64(&dev->timer, (uint64_t) (dev->timer.period * ((double) TIMER_USEC))); + + if ((dev->Base != 0) && !(dev->card_bus & DEVICE_MCA) && !(dev->card_bus & DEVICE_PCI)) + x54x_io_set(dev, dev->Base, 4); +} + static void * buslogic_init(const device_t *info) { @@ -1546,8 +1583,7 @@ buslogic_init(const device_t *info) dev = x54x_init(info); dev->bus = scsi_get_bus(); - dev->ven_data = malloc(sizeof(buslogic_data_t)); - memset(dev->ven_data, 0x00, sizeof(buslogic_data_t)); + dev->ven_data = calloc(1, sizeof(buslogic_data_t)); bl = (buslogic_data_t *) dev->ven_data; @@ -1587,7 +1623,7 @@ buslogic_init(const device_t *info) dev->interrupt_type = buslogic_interrupt_type; dev->is_aggressive_mode = buslogic_is_aggressive_mode; dev->get_ven_data = buslogic_setup_data; - dev->ven_reset = buslogic_reset; + dev->ven_reset = buslogic_ven_reset; strcpy(dev->vendor, "BusLogic"); @@ -1775,20 +1811,22 @@ buslogic_init(const device_t *info) BuslogicInitializeAutoSCSIRam(dev); } + memcpy(&reset_state, dev, sizeof(x54x_t)); + return dev; } // clang-format off static const device_config_t BT_ISA_Config[] = { { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x334, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x334, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "0x330", .value = 0x330 }, { .description = "0x334", .value = 0x334 }, { .description = "0x230", .value = 0x230 }, @@ -1797,16 +1835,17 @@ static const device_config_t BT_ISA_Config[] = { { .description = "0x134", .value = 0x134 }, { .description = "", .value = 0 } }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 11, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 11, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "IRQ 9", .value = 9 }, { .description = "IRQ 10", .value = 10 }, { .description = "IRQ 11", .value = 11 }, @@ -1815,48 +1854,55 @@ static const device_config_t BT_ISA_Config[] = { { .description = "IRQ 15", .value = 15 }, { .description = "", 0 } }, + .bios = { { 0 } } }, { - .name = "dma", - .description = "DMA", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 6, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "dma", + .description = "DMA", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 6, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "DMA 5", .value = 5 }, { .description = "DMA 6", .value = 6 }, { .description = "DMA 7", .value = 7 }, { .description = "", .value = 0 } }, + .bios = { { 0 } } }, { - .name = "bios_addr", - .description = "BIOS Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "bios_addr", + .description = "BIOS Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Disabled", .value = 0 }, { .description = "C800H", .value = 0xc8000 }, { .description = "D000H", .value = 0xd0000 }, { .description = "D800H", .value = 0xd8000 }, { .description = "", .value = 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t BT958D_Config[] = { { - .name = "bios", - .description = "Enable BIOS", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "bios", + .description = "Enable BIOS", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; @@ -1865,12 +1911,12 @@ static const device_config_t BT958D_Config[] = { const device_t buslogic_542b_device = { .name = "BusLogic BT-542B ISA", .internal_name = "bt542b", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = CHIP_BUSLOGIC_ISA_542B_1991_12_14, .init = buslogic_init, .close = x54x_close, - .reset = NULL, - { .available = NULL }, + .reset = buslogic_reset, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = BT_ISA_Config @@ -1879,12 +1925,12 @@ const device_t buslogic_542b_device = { const device_t buslogic_545s_device = { .name = "BusLogic BT-545S ISA", .internal_name = "bt545s", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = CHIP_BUSLOGIC_ISA_545S_1992_10_05, .init = buslogic_init, .close = x54x_close, - .reset = NULL, - { .available = NULL }, + .reset = buslogic_reset, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = BT_ISA_Config @@ -1893,12 +1939,12 @@ const device_t buslogic_545s_device = { const device_t buslogic_542bh_device = { .name = "BusLogic BT-542BH ISA", .internal_name = "bt542bh", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = CHIP_BUSLOGIC_ISA_542BH_1993_05_23, .init = buslogic_init, .close = x54x_close, - .reset = NULL, - { .available = NULL }, + .reset = buslogic_reset, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = BT_ISA_Config @@ -1907,12 +1953,12 @@ const device_t buslogic_542bh_device = { const device_t buslogic_545c_device = { .name = "BusLogic BT-545C ISA", .internal_name = "bt545c", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = CHIP_BUSLOGIC_ISA_545C_1994_12_01, .init = buslogic_init, .close = x54x_close, - .reset = NULL, - { .available = NULL }, + .reset = buslogic_reset, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = BT_ISA_Config @@ -1925,8 +1971,8 @@ const device_t buslogic_640a_device = { .local = CHIP_BUSLOGIC_MCA_640A_1993_05_23, .init = buslogic_init, .close = x54x_close, - .reset = NULL, - { .available = NULL }, + .reset = buslogic_reset, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -1939,8 +1985,8 @@ const device_t buslogic_445s_device = { .local = CHIP_BUSLOGIC_VLB_445S_1993_11_16, .init = buslogic_init, .close = x54x_close, - .reset = NULL, - { .available = NULL }, + .reset = buslogic_reset, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = BT_ISA_Config @@ -1953,8 +1999,8 @@ const device_t buslogic_445c_device = { .local = CHIP_BUSLOGIC_VLB_445C_1994_12_01, .init = buslogic_init, .close = x54x_close, - .reset = NULL, - { .available = NULL }, + .reset = buslogic_reset, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = BT_ISA_Config @@ -1967,8 +2013,8 @@ const device_t buslogic_958d_pci_device = { .local = CHIP_BUSLOGIC_PCI_958D_1995_12_30, .init = buslogic_init, .close = x54x_close, - .reset = NULL, - { .available = NULL }, + .reset = buslogic_reset, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = BT958D_Config diff --git a/src/scsi/scsi_cdrom.c b/src/scsi/scsi_cdrom.c index ad7f0d1c0..95c8c3640 100644 --- a/src/scsi/scsi_cdrom.c +++ b/src/scsi/scsi_cdrom.c @@ -9,46 +9,41 @@ * Implementation of the CD-ROM drive with SCSI(-like) * commands, for both ATAPI and SCSI usage. * - * - * * Authors: Miran Grca, * - * Copyright 2016-2020 Miran Grca. + * Copyright 2016-2025 Miran Grca. */ -#include #include #include +#ifdef ENABLE_SCSI_CDROM_LOG +#include +#endif #include #include #include #include -#include -#define HAVE_STDARG_H #include <86box/86box.h> -#include <86box/config.h> #include <86box/timer.h> +#include <86box/cdrom.h> #include <86box/device.h> -#include <86box/scsi.h> -#include <86box/scsi_device.h> +#include <86box/log.h> #include <86box/machine.h> #include <86box/nvr.h> -#include <86box/hdc.h> -#include <86box/hdc_ide.h> -#include <86box/sound.h> #include <86box/plat.h> -#include <86box/ui.h> -#include <86box/cdrom.h> +#include <86box/scsi.h> +#include <86box/scsi_device.h> +#include <86box/hdc_ide.h> #include <86box/scsi_cdrom.h> -#include <86box/version.h> +#include <86box/ui.h> #define IDE_ATAPI_IS_EARLY id->sc->pad0 #pragma pack(push, 1) typedef struct gesn_cdb_t { - uint8_t opcode; - uint8_t polled; - uint8_t reserved2[2]; - uint8_t class; + uint8_t opcode; + uint8_t polled; + uint8_t reserved2[2]; + uint8_t class; uint8_t reserved3[2]; uint16_t len; uint8_t control; @@ -61,411 +56,193 @@ typedef struct gesn_event_header_t { } gesn_event_header_t; #pragma pack(pop) -/* Table of all SCSI commands and their flags, needed for the new disc change / not ready handler. */ +// clang-format off +/* + Table of all SCSI commands and their flags, needed for the new disc change / + not ready handler. + */ uint8_t scsi_cdrom_command_flags[0x100] = { - IMPLEMENTED | CHECK_READY | NONDATA, /* 0x00 */ - IMPLEMENTED | ALLOW_UA | NONDATA | SCSI_ONLY, /* 0x01 */ - 0, /* 0x02 */ - IMPLEMENTED | ALLOW_UA, /* 0x03 */ - 0, 0, 0, 0, /* 0x04-0x07 */ - IMPLEMENTED | CHECK_READY, /* 0x08 */ - 0, 0, /* 0x09-0x0A */ - IMPLEMENTED | CHECK_READY | NONDATA, /* 0x0B */ - 0, /* 0x0C */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0x0D */ - 0, 0, 0, 0, /* 0x0E-0x11 */ - IMPLEMENTED | ALLOW_UA, /* 0x12 */ - IMPLEMENTED | CHECK_READY | NONDATA | SCSI_ONLY, /* 0x13 */ - 0, /* 0x14 */ - IMPLEMENTED, /* 0x15 */ - 0, 0, 0, 0, /* 0x16-0x19 */ - IMPLEMENTED, /* 0x1A */ - IMPLEMENTED | CHECK_READY, /* 0x1B */ - 0, 0, /* 0x1C-0x1D */ - IMPLEMENTED | CHECK_READY, /* 0x1E */ - 0, 0, 0, /* 0x1F-0x21*/ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0x22*/ - 0, 0, /* 0x23-0x24 */ - IMPLEMENTED | CHECK_READY, /* 0x25 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0x26 */ - 0, /* 0x27 */ - IMPLEMENTED | CHECK_READY, /* 0x28 */ - 0, 0, /* 0x29-0x2A */ - IMPLEMENTED | CHECK_READY | NONDATA, /* 0x2B */ - 0, 0, 0, /* 0x2C-0x2E */ - IMPLEMENTED | CHECK_READY | NONDATA | SCSI_ONLY, /* 0x2F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x30-0x3F */ - 0, 0, /* 0x40-0x41 */ - IMPLEMENTED | CHECK_READY, /* 0x42 */ - IMPLEMENTED | CHECK_READY, /* 0x43 - Read TOC - can get through UNIT_ATTENTION, per VIDE-CDD.SYS - NOTE: The ATAPI reference says otherwise, but I think this is a question of - interpreting things right - the UNIT ATTENTION condition we have here - is a tradition from not ready to ready, by definition the drive - eventually becomes ready, make the condition go away. */ - IMPLEMENTED | CHECK_READY, /* 0x44 */ - IMPLEMENTED | CHECK_READY, /* 0x45 */ - IMPLEMENTED | ALLOW_UA, /* 0x46 */ - IMPLEMENTED | CHECK_READY, /* 0x47 */ - IMPLEMENTED | CHECK_READY, /* 0x48 */ - IMPLEMENTED | CHECK_READY, /* 0x49 */ - IMPLEMENTED | ALLOW_UA, /* 0x4A */ - IMPLEMENTED | CHECK_READY, /* 0x4B */ - 0, 0, /* 0x4C-0x4D */ - IMPLEMENTED | CHECK_READY, /* 0x4E */ - 0, 0, /* 0x4F-0x50 */ - IMPLEMENTED | CHECK_READY, /* 0x51 */ - IMPLEMENTED | CHECK_READY, /* 0x52 */ - 0, 0, /* 0x53-0x54 */ - IMPLEMENTED, /* 0x55 */ - 0, 0, 0, 0, /* 0x56-0x59 */ - IMPLEMENTED, /* 0x5A */ - 0, 0, 0, 0, 0, /* 0x5B-0x5F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60-0x6F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x70-0x7F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x80-0x8F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x90-0x9F */ - 0, 0, 0, 0, 0, /* 0xA0-0xA4 */ - IMPLEMENTED | CHECK_READY, /* 0xA5 */ - 0, 0, /* 0xA6-0xA7 */ - IMPLEMENTED | CHECK_READY, /* 0xA8 */ - IMPLEMENTED | CHECK_READY, /* 0xA9 */ - 0, 0, 0, /* 0xAA-0xAC */ - IMPLEMENTED | CHECK_READY, /* 0xAD */ - 0, /* 0xAE */ - IMPLEMENTED | CHECK_READY | NONDATA | SCSI_ONLY, /* 0xAF */ - 0, 0, 0, 0, /* 0xB0-0xB3 */ - IMPLEMENTED | CHECK_READY | ATAPI_ONLY, /* 0xB4 */ - 0, 0, 0, /* 0xB5-0xB7 */ - IMPLEMENTED | CHECK_READY | ATAPI_ONLY, /* 0xB8 */ - IMPLEMENTED | CHECK_READY, /* 0xB9 */ - IMPLEMENTED | CHECK_READY, /* 0xBA */ - IMPLEMENTED, /* 0xBB */ - IMPLEMENTED | CHECK_READY, /* 0xBC */ - IMPLEMENTED, /* 0xBD */ - IMPLEMENTED | CHECK_READY, /* 0xBE */ - IMPLEMENTED | CHECK_READY, /* 0xBF */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xC0 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xC1 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xC2 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xC3 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xC4 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xC5 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xC6 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xC7 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xC8 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xC9 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xCA */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xCB */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xCC */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xCD */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xCE-0xD7 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xD8 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xD9 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xDA */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xDB */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xDC */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xDD */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xDE */ - 0, /* 0xDF */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xE0 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xE1 */ - 0, /* 0xE2 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xE3 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xE4 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xE5 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xE6 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xE7 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xE8 */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xE9 */ - 0, /* 0xEA */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xEB */ - 0, /* 0xEC */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xED */ - IMPLEMENTED | CHECK_READY | SCSI_ONLY, /* 0xEE */ - 0, /* 0xEF */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 0xF0-0xFF */ + [0x00] = IMPLEMENTED | CHECK_READY, + [0x01] = IMPLEMENTED | ALLOW_UA | SCSI_ONLY, + [0x03] = IMPLEMENTED | ALLOW_UA, + [0x08] = IMPLEMENTED | CHECK_READY, + [0x0b] = IMPLEMENTED | CHECK_READY, + [0x0d] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0x12] = IMPLEMENTED | ALLOW_UA, + [0x13] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0x15] = IMPLEMENTED, + [0x1a] = IMPLEMENTED, + [0x1b] = IMPLEMENTED | CHECK_READY, + [0x1e] = IMPLEMENTED | CHECK_READY, + [0x22] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0x25] = IMPLEMENTED | CHECK_READY, + [0x26] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0x28] = IMPLEMENTED | CHECK_READY, + [0x2b] = IMPLEMENTED | CHECK_READY, + [0x2f] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0x42] = IMPLEMENTED | CHECK_READY, + /* + Read TOC/PMA/ATIP - can get through UNIT_ATTENTION, per VIDE-CDD.SYS. + + NOTE: The ATAPI reference says otherwise, but I think this is a question of + interpreting things right - the UNIT ATTENTION condition we have here + is a tradition from not ready to ready, by definition the drive + eventually becomes ready, make the condition go away. + */ + [0x43 ... 0x45] = IMPLEMENTED | CHECK_READY, + [0x46] = IMPLEMENTED | ALLOW_UA, + [0x47 ... 0x49] = IMPLEMENTED | CHECK_READY, + [0x4a] = IMPLEMENTED | ALLOW_UA, + [0x4b] = IMPLEMENTED | CHECK_READY, + [0x4e] = IMPLEMENTED | CHECK_READY, + [0x51 ... 0x52] = IMPLEMENTED | CHECK_READY, + [0x55] = IMPLEMENTED, + [0x5a] = IMPLEMENTED, + [0xa5] = IMPLEMENTED | CHECK_READY, + [0xa8 ... 0xa9] = IMPLEMENTED | CHECK_READY, + [0xad] = IMPLEMENTED, + [0xaf] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0xb4] = IMPLEMENTED | CHECK_READY | ATAPI_ONLY, + [0xb8] = IMPLEMENTED | CHECK_READY | ATAPI_ONLY, + [0xb9 ... 0xba] = IMPLEMENTED | CHECK_READY, + [0xbb] = IMPLEMENTED, + [0xbc] = IMPLEMENTED | CHECK_READY, + [0xbd] = IMPLEMENTED, + [0xbe ... 0xbf] = IMPLEMENTED | CHECK_READY, + [0xc0 ... 0xcd] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0xd5] = IMPLEMENTED | CHECK_READY, + [0xd8 ... 0xde] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0xe0 ... 0xe1] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0xe3 ... 0xe9] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0xeb] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0xed ... 0xee] = IMPLEMENTED | CHECK_READY | SCSI_ONLY }; -static uint64_t scsi_cdrom_mode_sense_page_flags = (GPMODEP_UNIT_ATN_PAGE | GPMODEP_R_W_ERROR_PAGE | GPMODEP_DISCONNECT_PAGE | GPMODEP_FORMAT_DEVICE_PAGE | GPMODEP_CDROM_PAGE | GPMODEP_CDROM_AUDIO_PAGE | (1ULL << 0x0fULL) | GPMODEP_CAPABILITIES_PAGE | GPMODEP_ALL_PAGES); -static uint64_t scsi_cdrom_mode_sense_page_flags_sony = (GPMODEP_R_W_ERROR_PAGE | GPMODEP_DISCONNECT_PAGE | GPMODEP_CDROM_PAGE_SONY | GPMODEP_CDROM_AUDIO_PAGE_SONY | (1ULL << 0x0fULL) | GPMODEP_CAPABILITIES_PAGE | GPMODEP_ALL_PAGES); -static uint64_t scsi_cdrom_drive_status_page_flags = ((1ULL << 0x01ULL) | (1ULL << 0x02ULL) | (1ULL << 0x0fULL) | GPMODEP_ALL_PAGES); +static uint64_t scsi_cdrom_ms_page_flags = (GPMODEP_R_W_ERROR_PAGE | GPMODEP_CDROM_PAGE | + GPMODEP_CDROM_AUDIO_PAGE | (1ULL << 0x0fULL) | + GPMODEP_CAPABILITIES_PAGE | GPMODEP_ALL_PAGES); +static uint64_t scsi_cdrom_ms_page_flags_scsi = (GPMODEP_UNIT_ATN_PAGE | GPMODEP_R_W_ERROR_PAGE | + GPMODEP_DISCONNECT_PAGE | GPMODEP_FORMAT_DEVICE_PAGE | + GPMODEP_CDROM_PAGE | GPMODEP_CDROM_AUDIO_PAGE | + (1ULL << 0x0fULL) | GPMODEP_CAPABILITIES_PAGE | + GPMODEP_ALL_PAGES); +static uint64_t scsi_cdrom_ms_page_flags_sony_scsi = (GPMODEP_R_W_ERROR_PAGE | GPMODEP_DISCONNECT_PAGE | + GPMODEP_CDROM_PAGE_SONY | GPMODEP_CDROM_AUDIO_PAGE_SONY | + (1ULL << 0x0fULL) | GPMODEP_CAPABILITIES_PAGE | + GPMODEP_ALL_PAGES); + +static uint64_t scsi_cdrom_drive_status_page_flags = ((1ULL << 0x01ULL) | (1ULL << 0x02ULL) | + (1ULL << 0x0fULL) | GPMODEP_ALL_PAGES); static const mode_sense_pages_t scsi_cdrom_drive_status_pages = { - {{ 0, 0 }, - { 0x01, 0, 2, 0x0f, 0xbf }, /*Drive Status Data Format*/ - { 0x02, 0, 1, 0 }, /*Audio Play Status Format*/ - { 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 }} + { [0x01] = { 0x01, 0x00, 0x02, 0x0f, 0xbf }, /* Drive Status Data Format */ + [0x02] = { 0x02, 0x00, 0x01, 0x00 } } /* Audio Play Status Format */ }; -static const mode_sense_pages_t scsi_cdrom_mode_sense_pages_default = { - {{ 0, 0 }, - { GPMODE_R_W_ERROR_PAGE, 6, 0, 5, 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 }, - { GPMODE_CDROM_PAGE, 6, 0, 1, 0, 60, 0, 75 }, - { GPMODE_CDROM_AUDIO_PAGE | 0x80, 0xE, 4, 0, 0, 0, 0, 75, 1, 255, 2, 255, 0, 0, 0, 0 }, - { 0x0F, 0x14, 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 }, - { GPMODE_CAPABILITIES_PAGE, 0x12, 7, 0, 0x3f, 1, 0x0d, 3, 2, 0xC2, 1, 0, 0, 0, 2, 0xC2, 0, 0, 0, 0 }} +static const mode_sense_pages_t scsi_cdrom_ms_pages_default = { + { [0x01] = { GPMODE_R_W_ERROR_PAGE, 0x06, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00 }, + [0x0d] = { GPMODE_CDROM_PAGE, 0x06, 0x00, 0x01, 0x00, 0x3c, 0x00, 0x4b }, + [0x0e] = { GPMODE_CDROM_AUDIO_PAGE | 0x80, 0x0e, 0x04, 0x00, 0x00, 0x00, 0x00, 0x4b, + 0x01, 0xff, 0x02, 0xff, 0x00, 0x00, 0x00, 0x00 }, + [0x0f] = { 0x0f, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x2a] = { GPMODE_CAPABILITIES_PAGE, 0x12, 0x07, 0x00, 0x7f, 0x01, 0x0d, 0x03, + 0x02, 0xc2, 0x01, 0x00, 0x00, 0x00, 0x02, 0xc2, + 0x00, 0x00, 0x00, 0x00 } } }; -static const mode_sense_pages_t scsi_cdrom_mode_sense_pages_default_scsi = { - {{ GPMODE_UNIT_ATN_PAGE, 6, 0, 0, 0, 0, 0, 0 }, /*Guess-work*/ - { GPMODE_R_W_ERROR_PAGE, 6, 0, 5, 0, 0, 0, 0 }, - { GPMODE_DISCONNECT_PAGE, 0x0e, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { GPMODE_FORMAT_DEVICE_PAGE, 0x16, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 2, 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 }, - { GPMODE_CDROM_PAGE, 6, 0, 1, 0, 60, 0, 75 }, - { GPMODE_CDROM_AUDIO_PAGE | 0x80, 0xE, 5, 4, 0, 128, 0, 75, 1, 255, 2, 255, 0, 0, 0, 0 }, - { 0x0F, 0x14, 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 }, - { GPMODE_CAPABILITIES_PAGE, 0x12, 7, 0, 0x3f, 1, 0x0d, 3, 2, 0xC2, 1, 0, 0, 0, 2, 0xC2, 0, 0, 0, 0 }} +static const mode_sense_pages_t scsi_cdrom_ms_pages_default_scsi = { + { [0x00] = { GPMODE_UNIT_ATN_PAGE, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* Guesswork */ + [0x01] = { GPMODE_R_W_ERROR_PAGE, 0x06, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00 }, + [0x02] = { GPMODE_DISCONNECT_PAGE, 0x0e, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x03] = { GPMODE_FORMAT_DEVICE_PAGE, 0x16, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, + 0x00, 0x01, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x0d] = { GPMODE_CDROM_PAGE, 0x06, 0x00, 0x01, 0x00, 0x3c, 0x00, 0x4b }, + [0x0e] = { GPMODE_CDROM_AUDIO_PAGE | 0x80, 0x0e, 0x05, 0x04, 0x00, 0x80, 0x00, 0x4b, + 0x01, 0xff, 0x02, 0xff, 0x00, 0x00, 0x00, 0x00 }, + [0x0f] = { 0x0f, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x2a] = { GPMODE_CAPABILITIES_PAGE, 0x12, 0x07, 0x00, 0x7f, 0x01, 0x0d, 0x03, + 0x02, 0xc2, 0x01, 0x00, 0x00, 0x00, 0x02, 0xc2, + 0x00, 0x00, 0x00, 0x00 } } }; -static const mode_sense_pages_t scsi_cdrom_mode_sense_pages_default_sony_scsi = { - {{ 0, 0 }, - { GPMODE_R_W_ERROR_PAGE, 6, 0, 5, 0, 0, 0, 0 }, - { GPMODE_DISCONNECT_PAGE, 0x0e, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_CDROM_PAGE_SONY, 2, 0, 5 }, - { GPMODE_CDROM_AUDIO_PAGE_SONY | 0x80, 0xE, 5, 0, 0, 0, 0, 0, 1, 255, 2, 255, 0, 0, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_CDROM_PAGE, 6, 0, 1, 0, 60, 0, 75 }, - { GPMODE_CDROM_AUDIO_PAGE | 0x80, 0xE, 5, 4, 0, 128, 0, 75, 1, 255, 2, 255, 0, 0, 0, 0 }, - { 0x0F, 0x14, 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 }, - { GPMODE_CAPABILITIES_PAGE, 0x12, 7, 0, 0x3f, 1, 0x0d, 3, 2, 0xC2, 1, 0, 0, 0, 2, 0xC2, 0, 0, 0, 0 }} +static const mode_sense_pages_t scsi_cdrom_ms_pages_default_sony_scsi = { + { { 0, 0 }, + [0x01] = { GPMODE_R_W_ERROR_PAGE, 0x06, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00 }, + [0x02] = { GPMODE_DISCONNECT_PAGE, 0x0e, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x08] = { GPMODE_CDROM_PAGE_SONY, 0x02, 0x00, 0x05 }, + [0x09] = { GPMODE_CDROM_AUDIO_PAGE_SONY | 0x80, 0x0e, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0xff, 0x02, 0xff, 0x00, 0x00, 0x00, 0x00 }, + [0x0d] = { GPMODE_CDROM_PAGE, 0x06, 0x00, 0x01, 0x00, 0x3c, 0x00, 0x4b }, + [0x0e] = { GPMODE_CDROM_AUDIO_PAGE | 0x80, 0x0e, 0x05, 0x04, 0x00, 0x80, 0x00, 0x4b, + 0x01, 0xff, 0x02, 0xff, 0x00, 0x00, 0x00, 0x00 }, + [0x0f] = { 0x0f, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x2a] = { GPMODE_CAPABILITIES_PAGE, 0x12, 0x07, 0x00, 0x7f, 0x01, 0x0d, 0x03, + 0x02, 0xc2, 0x01, 0x00, 0x00, 0x00, 0x02, 0xc2, + 0x00, 0x00, 0x00, 0x00 } } }; -static const mode_sense_pages_t scsi_cdrom_mode_sense_pages_changeable = { - {{ GPMODE_UNIT_ATN_PAGE, 6, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, /*Guess-work*/ - { GPMODE_R_W_ERROR_PAGE, 6, 0xFF, 0xFF, 0, 0, 0, 0 }, - { GPMODE_DISCONNECT_PAGE, 0x0E, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0 }, - { GPMODE_FORMAT_DEVICE_PAGE, 0x16, 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 }, - { GPMODE_CDROM_PAGE, 6, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, - { GPMODE_CDROM_AUDIO_PAGE | 0x80, 0xE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, - { 0x0F, 0x14, 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 }, - { GPMODE_CAPABILITIES_PAGE, 0x12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }} +static const mode_sense_pages_t scsi_cdrom_ms_pages_changeable = { + { [0x01] = { GPMODE_R_W_ERROR_PAGE, 0x06, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }, + [0x02] = { GPMODE_DISCONNECT_PAGE, 0x0e, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }, + [0x0d] = { GPMODE_CDROM_PAGE, 0x06, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, + [0x0e] = { GPMODE_CDROM_AUDIO_PAGE | 0x80, 0x0e, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, + [0x0f] = { 0x0f, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x2a] = { GPMODE_CAPABILITIES_PAGE, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00 } } }; -static const mode_sense_pages_t scsi_cdrom_mode_sense_pages_changeable_sony = { - {{ 0, 0 }, - { GPMODE_R_W_ERROR_PAGE, 6, 0xFF, 0xFF, 0, 0, 0, 0 }, - { GPMODE_DISCONNECT_PAGE, 0x0E, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_CDROM_PAGE_SONY, 2, 0xFF, 0xFF }, - { GPMODE_CDROM_AUDIO_PAGE_SONY | 0x80, 0xE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { GPMODE_CDROM_PAGE, 6, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, - { GPMODE_CDROM_AUDIO_PAGE | 0x80, 0xE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, - { 0x0F, 0x14, 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 }, - { GPMODE_CAPABILITIES_PAGE, 0x12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }} +static const mode_sense_pages_t scsi_cdrom_ms_pages_changeable_scsi = { + { [0x00] = { GPMODE_UNIT_ATN_PAGE, 0x06, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, /* Guesswork */ + [0x01] = { GPMODE_R_W_ERROR_PAGE, 0x06, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }, + [0x02] = { GPMODE_DISCONNECT_PAGE, 0x0e, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }, + [0x03] = { GPMODE_FORMAT_DEVICE_PAGE, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x0d] = { GPMODE_CDROM_PAGE, 0x06, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, + [0x0e] = { GPMODE_CDROM_AUDIO_PAGE | 0x80, 0x0e, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, + [0x0f] = { 0x0f, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x2a] = { GPMODE_CAPABILITIES_PAGE, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00 } } }; +static const mode_sense_pages_t scsi_cdrom_ms_pages_changeable_sony_scsi = { + { [0x01] = { GPMODE_R_W_ERROR_PAGE, 0x06, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }, + [0x02] = { GPMODE_DISCONNECT_PAGE, 0x0e, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }, + [0x08] = { GPMODE_CDROM_PAGE_SONY, 0x02, 0xff, 0xff }, + [0x09] = { GPMODE_CDROM_AUDIO_PAGE_SONY | 0x80, 0x0e, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, + [0x0d] = { GPMODE_CDROM_PAGE, 0x06, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, + [0x0e] = { GPMODE_CDROM_AUDIO_PAGE | 0x80, 0x0e, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, + [0x0f] = { 0x0f, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x2a] = { GPMODE_CAPABILITIES_PAGE, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 } } +}; +// clang-format on + static gesn_cdb_t *gesn_cdb; static gesn_event_header_t *gesn_event_header; @@ -480,22 +257,21 @@ static void scsi_cdrom_init(scsi_cdrom_t *dev); int scsi_cdrom_do_log = ENABLE_SCSI_CDROM_LOG; static void -scsi_cdrom_log(const char *format, ...) +scsi_cdrom_log(void *priv, const char *format, ...) { - va_list ap; - if (scsi_cdrom_do_log) { + va_list ap; va_start(ap, format); - pclog_ex(format, ap); + log_out(priv, format, ap); va_end(ap); } } #else -# define scsi_cdrom_log(format, ...) +# define scsi_cdrom_log(priv, format, ...) #endif static void -scsi_cdrom_set_callback(scsi_cdrom_t *dev) +scsi_cdrom_set_callback(const scsi_cdrom_t *dev) { if (dev && dev->drv && (dev->drv->bus_type != CDROM_BUS_SCSI)) ide_set_callback(ide_drives[dev->drv->ide_channel], dev->callback); @@ -504,47 +280,50 @@ scsi_cdrom_set_callback(scsi_cdrom_t *dev) static void scsi_cdrom_init(scsi_cdrom_t *dev) { - if (!dev) - return; + if (dev != NULL) { + /* Do a reset (which will also rezero it). */ + scsi_cdrom_reset((scsi_common_t *) dev); - /* Do a reset (which will also rezero it). */ - scsi_cdrom_reset((scsi_common_t *) dev); + /* Configure the drive. */ + dev->requested_blocks = 1; - /* Configure the drive. */ - dev->requested_blocks = 1; + dev->drv->bus_mode = 0; + if (dev->drv->bus_type >= CDROM_BUS_ATAPI) + dev->drv->bus_mode |= 2; + if (dev->drv->bus_type < CDROM_BUS_SCSI) + dev->drv->bus_mode |= 1; + scsi_cdrom_log(dev->log, "Bus type %i, bus mode %i\n", + dev->drv->bus_type, dev->drv->bus_mode); - dev->drv->bus_mode = 0; - if (dev->drv->bus_type >= CDROM_BUS_ATAPI) - dev->drv->bus_mode |= 2; - if (dev->drv->bus_type < CDROM_BUS_SCSI) - dev->drv->bus_mode |= 1; - scsi_cdrom_log("CD-ROM %i: Bus type %i, bus mode %i\n", - dev->id, dev->drv->bus_type, dev->drv->bus_mode); + dev->sense[0] = 0xf0; + dev->sense[7] = 10; + /* NEC only */ + if (dev->drv->is_early) + dev->tf->status = READY_STAT | DSC_STAT; + else + dev->tf->status = 0; + dev->tf->pos = 0; + dev->packet_status = PHASE_NONE; + scsi_cdrom_sense_key = scsi_cdrom_asc = + scsi_cdrom_ascq = dev->unit_attention = 0; + scsi_cdrom_info = 0x00000000; + dev->drv->cd_status &= ~CD_STATUS_TRANSITION; + dev->drv->cur_speed = dev->drv->real_speed; + scsi_cdrom_mode_sense_load(dev); - dev->sense[0] = 0xf0; - dev->sense[7] = 10; - /* NEC only */ - if ((dev->drv->type == CDROM_TYPE_NEC_260_100) || (dev->drv->type == CDROM_TYPE_NEC_260_101)) - dev->tf->status = READY_STAT | DSC_STAT; - else - dev->tf->status = 0; - dev->tf->pos = 0; - dev->packet_status = PHASE_NONE; - scsi_cdrom_sense_key = scsi_cdrom_asc = scsi_cdrom_ascq = dev->unit_attention = 0; - dev->drv->cur_speed = dev->drv->speed; - scsi_cdrom_mode_sense_load(dev); - if (dev->drv->type == CDROM_TYPE_PIONEER_DRM604X_2403) - scsi_cdrom_drive_status_load(dev); + if ((dev->drv->bus_type == CDROM_BUS_SCSI) && dev->drv->is_pioneer) + scsi_cdrom_drive_status_load(dev); + } } /* Returns: 0 for none, 1 for PIO, 2 for DMA. */ static int -scsi_cdrom_current_mode(scsi_cdrom_t *dev) +scsi_cdrom_current_mode(const scsi_cdrom_t *dev) { if (dev->drv->bus_type == CDROM_BUS_SCSI) return 2; else if (dev->drv->bus_type == CDROM_BUS_ATAPI) { - scsi_cdrom_log("CD-ROM %i: ATAPI drive, setting to %s\n", dev->id, + scsi_cdrom_log(dev->log, "ATAPI drive, setting to %s\n", (dev->tf->features & 1) ? "DMA" : "PIO", dev->id); return (dev->tf->features & 1) ? 2 : 1; @@ -554,50 +333,25 @@ scsi_cdrom_current_mode(scsi_cdrom_t *dev) } static uint32_t -scsi_cdrom_get_channel(void *priv, int channel) +scsi_cdrom_get_channel(void *priv, const int channel) { const scsi_cdrom_t *dev = (scsi_cdrom_t *) priv; - uint32_t ret; + uint32_t ret = channel + 1; - if (!dev) - return channel + 1; - - switch (dev->drv->type) { - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - ret = dev->ms_pages_saved_sony.pages[dev->sony_vendor ? - GPMODE_CDROM_AUDIO_PAGE_SONY : GPMODE_CDROM_AUDIO_PAGE] - [channel ? 10 : 8]; - break; - default: - ret = dev->ms_pages_saved.pages[GPMODE_CDROM_AUDIO_PAGE][channel ? 10 : 8]; - break; - } + if (dev != NULL) + ret = dev->ms_pages_saved.pages[GPMODE_CDROM_AUDIO_PAGE][channel ? 10 : 8] & 0x0f; return ret; } static uint32_t -scsi_cdrom_get_volume(void *priv, int channel) +scsi_cdrom_get_volume(void *priv, const int channel) { const scsi_cdrom_t *dev = (scsi_cdrom_t *) priv; - uint32_t ret; + uint32_t ret = 255; - if (!dev) - return 255; - - switch (dev->drv->type) { - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - ret = dev->ms_pages_saved_sony.pages[dev->sony_vendor ? GPMODE_CDROM_AUDIO_PAGE_SONY : - GPMODE_CDROM_AUDIO_PAGE][channel ? 11 : 9]; - break; - default: - ret = dev->ms_pages_saved.pages[GPMODE_CDROM_AUDIO_PAGE][channel ? 11 : 9]; - break; - } + if (dev != NULL) + ret = dev->ms_pages_saved.pages[GPMODE_CDROM_AUDIO_PAGE][channel ? 11 : 9]; return ret; } @@ -605,129 +359,90 @@ scsi_cdrom_get_volume(void *priv, int channel) static void scsi_cdrom_mode_sense_load(scsi_cdrom_t *dev) { - FILE *fp; - char file_name[512]; + char file_name[512] = { 0 }; - switch (dev->drv->type) { - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - memset(&dev->ms_pages_saved_sony, 0, sizeof(mode_sense_pages_t)); - memcpy(&dev->ms_pages_saved_sony, &scsi_cdrom_mode_sense_pages_default_sony_scsi, - sizeof(mode_sense_pages_t)); + memset(&dev->ms_pages_saved, 0x00, sizeof(mode_sense_pages_t)); + memcpy(&dev->ms_pages_saved, &dev->ms_pages_default, + sizeof(mode_sense_pages_t)); - memset(file_name, 0, 512); - sprintf(file_name, "scsi_cdrom_%02i_mode_sense_sony_bin", dev->id); - fp = plat_fopen(nvr_path(file_name), "rb"); - if (fp) { - if (fread(dev->ms_pages_saved_sony.pages[GPMODE_CDROM_AUDIO_PAGE_SONY], 1, - 0x10, fp) != 0x10) - fatal("scsi_cdrom_mode_sense_load(): Error reading data\n"); - fclose(fp); - } - break; - default: - memset(&dev->ms_pages_saved, 0, sizeof(mode_sense_pages_t)); - if (dev->drv->bus_type == CDROM_BUS_SCSI) - memcpy(&dev->ms_pages_saved, &scsi_cdrom_mode_sense_pages_default_scsi, - sizeof(mode_sense_pages_t)); - else - memcpy(&dev->ms_pages_saved, &scsi_cdrom_mode_sense_pages_default, - sizeof(mode_sense_pages_t)); - - memset(file_name, 0, 512); - if (dev->drv->bus_type == CDROM_BUS_SCSI) - sprintf(file_name, "scsi_cdrom_%02i_mode_sense_bin", dev->id); - else - sprintf(file_name, "cdrom_%02i_mode_sense_bin", dev->id); - fp = plat_fopen(nvr_path(file_name), "rb"); - if (fp) { - if (fread(dev->ms_pages_saved.pages[GPMODE_CDROM_AUDIO_PAGE], 1, 0x10, fp) != 0x10) - fatal("scsi_cdrom_mode_sense_load(): Error reading data\n"); - fclose(fp); - } - break; + if (dev->drv->bus_type == CDROM_BUS_SCSI) + sprintf(file_name, "scsi_cdrom_%02i_mode_sense_bin", dev->id); + else + sprintf(file_name, "cdrom_%02i_mode_sense_bin", dev->id); + FILE *fp = plat_fopen(nvr_path(file_name), "rb"); + if (fp) { + if (fread(dev->ms_pages_saved.pages[GPMODE_CDROM_AUDIO_PAGE], 1, 0x10, fp) != 0x10) + log_fatal(dev->log, "scsi_cdrom_mode_sense_load(): Error reading data\n"); + (void) !fread(dev->ms_pages_saved.pages[GPMODE_CDROM_AUDIO_PAGE_SONY], 1, + 0x10, fp); + fclose(fp); } } static void -scsi_cdrom_mode_sense_save(scsi_cdrom_t *dev) +scsi_cdrom_mode_sense_save(const scsi_cdrom_t *dev) { - FILE *fp; - char file_name[512]; + char file_name[512] = { 0 }; - memset(file_name, 0, 512); - - switch (dev->drv->type) { - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - sprintf(file_name, "scsi_cdrom_%02i_mode_sense_sony_bin", dev->id); - fp = plat_fopen(nvr_path(file_name), "wb"); - if (fp) { - fwrite(dev->ms_pages_saved_sony.pages[GPMODE_CDROM_AUDIO_PAGE_SONY], 1, 0x10, fp); - fclose(fp); - } - break; - default: - if (dev->drv->bus_type == CDROM_BUS_SCSI) - sprintf(file_name, "scsi_cdrom_%02i_mode_sense_bin", dev->id); - else - sprintf(file_name, "cdrom_%02i_mode_sense_bin", dev->id); - fp = plat_fopen(nvr_path(file_name), "wb"); - if (fp) { - fwrite(dev->ms_pages_saved.pages[GPMODE_CDROM_AUDIO_PAGE], 1, 0x10, fp); - fclose(fp); - } - break; + if (dev->drv->bus_type == CDROM_BUS_SCSI) + sprintf(file_name, "scsi_cdrom_%02i_mode_sense_bin", dev->id); + else + sprintf(file_name, "cdrom_%02i_mode_sense_bin", dev->id); + FILE *fp = plat_fopen(nvr_path(file_name), "wb"); + if (fp) { + fwrite(dev->ms_pages_saved.pages[GPMODE_CDROM_AUDIO_PAGE], 1, 0x10, fp); + fwrite(dev->ms_pages_saved.pages[GPMODE_CDROM_AUDIO_PAGE_SONY], 1, 0x10, fp); + fclose(fp); } } -/*SCSI Drive Status (Pioneer only)*/ +/* SCSI Drive Status (Pioneer only). */ static void scsi_cdrom_drive_status_load(scsi_cdrom_t *dev) { - memset(&dev->ms_drive_status_pages_saved, 0, sizeof(mode_sense_pages_t)); - memcpy(&dev->ms_drive_status_pages_saved, &scsi_cdrom_drive_status_pages, sizeof(mode_sense_pages_t)); + memset(&dev->ms_drive_status_pages_saved, 0x00, sizeof(mode_sense_pages_t)); + memcpy(&dev->ms_drive_status_pages_saved, &scsi_cdrom_drive_status_pages, + sizeof(mode_sense_pages_t)); } static uint8_t -scsi_cdrom_drive_status_read(scsi_cdrom_t *dev, UNUSED(uint8_t page_control), uint8_t page, uint8_t pos) +scsi_cdrom_drive_status_read(const scsi_cdrom_t *dev, const uint8_t page, + const uint8_t pos) { return dev->ms_drive_status_pages_saved.pages[page][pos]; } static uint32_t -scsi_cdrom_drive_status(scsi_cdrom_t *dev, uint8_t *buf, uint32_t pos, uint8_t page) +scsi_cdrom_drive_status(const scsi_cdrom_t *dev, uint8_t *buf, uint8_t page) { - uint8_t page_control = (page >> 6) & 3; - uint16_t msplen; + uint32_t pos = 0; page &= 0x3f; 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); - msplen = (scsi_cdrom_drive_status_read(dev, page_control, i, 1) << 8); - msplen |= scsi_cdrom_drive_status_read(dev, page_control, i, 2); - 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 (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*/ - if (dev->drv->ops) /*Bit 11 of Drive Status, */ - buf[pos] &= ~0x08; /*Disc is present*/ - else - buf[pos] |= 0x08; /*Disc not present*/ - } - } else if ((i == 0x02) && (j == 0)) { - buf[pos++] = ((dev->drv->cd_status == CD_STATUS_PLAYING) ? 0x01 : 0x00); - } else - buf[pos++] = scsi_cdrom_drive_status_read(dev, page_control, i, 3 + j); - } + if ((page == i) && (scsi_cdrom_drive_status_page_flags & + (1LL << ((uint64_t) (page & 0x3f))))) { + buf[pos++] = scsi_cdrom_drive_status_read(dev, i, 0); + uint16_t len = (scsi_cdrom_drive_status_read(dev, i, 1) << 8); + len |= scsi_cdrom_drive_status_read(dev, i, 2); + buf[pos++] = (len >> 8) & 0xff; + buf[pos++] = len & 0xff; + scsi_cdrom_log(dev->log, "CD-ROM %i: DRIVE STATUS: Page [%02X] length %i\n", + i, len); + for (uint16_t j = 0; j < len; j++) { + if (i == 0x01) { + buf[pos++] = scsi_cdrom_drive_status_read(dev, i, 3 + j); + if (!(j & 1)) { /* MSB of Drive Status. */ + if (dev->drv->ops) /* Bit 11 of Drive Status, */ + buf[pos] &= ~0x08; /* Disc is present. */ + else + buf[pos] |= 0x08; /* Disc not present. */ + } + } else if ((i == 0x02) && (j == 0)) + buf[pos++] = ((dev->drv->cd_status == CD_STATUS_PLAYING) ? + 0x01 : 0x00); + else + buf[pos++] = scsi_cdrom_drive_status_read(dev, i, 3 + j); } } } @@ -737,52 +452,36 @@ scsi_cdrom_drive_status(scsi_cdrom_t *dev, uint8_t *buf, uint32_t pos, uint8_t p /*SCSI Mode Sense 6/10*/ static uint8_t -scsi_cdrom_mode_sense_read(scsi_cdrom_t *dev, uint8_t page_control, uint8_t page, uint8_t pos) +scsi_cdrom_mode_sense_read(const scsi_cdrom_t *dev, const uint8_t pgctl, + const uint8_t page, const uint8_t pos) { - switch (dev->drv->type) { - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - switch (page_control) { - case 0: - case 3: - return dev->ms_pages_saved_sony.pages[page][pos]; - case 1: - return scsi_cdrom_mode_sense_pages_changeable_sony.pages[page][pos]; - case 2: - return scsi_cdrom_mode_sense_pages_default_sony_scsi.pages[page][pos]; + uint8_t ret = 0; - default: - break; - } + switch (pgctl) { + case 0: case 3: + ret = dev->ms_pages_saved.pages[page][pos]; break; + + case 1: + ret = dev->ms_pages_changeable.pages[page][pos]; + break; + + case 2: + ret = dev->ms_pages_default.pages[page][pos]; + break; + default: - switch (page_control) { - case 0: - case 3: - return dev->ms_pages_saved.pages[page][pos]; - case 1: - return scsi_cdrom_mode_sense_pages_changeable.pages[page][pos]; - 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]; + break; + } - default: - break; - } - break; - } - - return 0; + return ret; } 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) +scsi_cdrom_mode_sense(const scsi_cdrom_t *dev, uint8_t *buf, uint32_t pos, + uint8_t page, const uint8_t block_descriptor_len) { - uint8_t page_control = (page >> 6) & 3; - uint8_t msplen; + const uint8_t pgctl = (page >> 6) & 3; page &= 0x3f; @@ -799,45 +498,46 @@ scsi_cdrom_mode_sense(scsi_cdrom_t *dev, uint8_t *buf, uint32_t pos, uint8_t pag 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); + if (dev->ms_page_flags & (1LL << ((uint64_t) (page & 0x3f)))) { + const uint8_t msplen = scsi_cdrom_mode_sense_read(dev, pgctl, i, 1); + + buf[pos++] = scsi_cdrom_mode_sense_read(dev, pgctl, i, 0); + buf[pos++] = msplen; + + scsi_cdrom_log(dev->log, "MODE SENSE: Page [%02X] length %i\n", + i, msplen); + 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) - buf[pos++] = scsi_cdrom_mode_sense_read(dev, page_control, i, 2 + j); + /* + If we are returning changeable values, always return + them from the page, so they are all correct. + */ + if (pgctl == 1) + buf[pos++] = scsi_cdrom_mode_sense_read(dev, pgctl, i, 2 + j); else { if ((i == GPMODE_CAPABILITIES_PAGE) && (j == 4)) { - buf[pos] = scsi_cdrom_mode_sense_read(dev, page_control, i, 2 + j) & 0x1f; - /* The early CD-ROM drives we emulate (NEC CDR-260 for ATAPI and - early vendor SCSI CD-ROM models) are caddy drives, the later - ones are tray drives. */ - if (dev->drv->bus_type == CDROM_BUS_SCSI) - buf[pos++] |= ((dev->drv->type == CDROM_TYPE_86BOX_100) ? 0x20 : 0x00); - else - buf[pos++] |= ((dev->drv->type == CDROM_TYPE_NEC_260_100) || - ((dev->drv->type == CDROM_TYPE_NEC_260_101)) ? 0x00 : 0x20); - } else if ((i == GPMODE_CAPABILITIES_PAGE) && (j >= 6) && (j <= 7)) { + buf[pos] = scsi_cdrom_mode_sense_read(dev, pgctl, i, 2 + j) & 0x1f; + buf[pos++] |= (cdrom_is_caddy(dev->drv->type) ? 0x00 : 0x20); + } else if ((i == GPMODE_CAPABILITIES_PAGE) && (j >= 6) && + (j <= 7)) { if (j & 1) - buf[pos++] = ((dev->drv->speed * 176) & 0xff); + buf[pos++] = ((dev->drv->real_speed * 176) & 0xff); else - buf[pos++] = ((dev->drv->speed * 176) >> 8); - } else if ((i == GPMODE_CAPABILITIES_PAGE) && (j >= 8) && (j <= 9) && - (dev->drv->type == CDROM_TYPE_PIONEER_DRM604X_2403)) { - if (j & 1) - buf[pos++] = ((dev->drv->speed * 176) & 0xff); - else - buf[pos++] = ((dev->drv->speed * 176) >> 8); - } else if ((i == GPMODE_CAPABILITIES_PAGE) && (j >= 12) && (j <= 13)) { + buf[pos++] = ((dev->drv->real_speed * 176) >> 8); + } else if ((i == GPMODE_CAPABILITIES_PAGE) && (j >= 12) && + (j <= 13)) { if (j & 1) buf[pos++] = ((dev->drv->cur_speed * 176) & 0xff); else buf[pos++] = ((dev->drv->cur_speed * 176) >> 8); - } else - buf[pos++] = scsi_cdrom_mode_sense_read(dev, page_control, i, 2 + j); + } else if (dev->drv->is_sony && + (i == GPMODE_CDROM_AUDIO_PAGE_SONY) && + (j >= 6) && (j <= 13)) + buf[pos++] = scsi_cdrom_mode_sense_read(dev, pgctl, + GPMODE_CDROM_AUDIO_PAGE, 2 + j); + else + buf[pos++] = scsi_cdrom_mode_sense_read(dev, pgctl, + i, 2 + j); } } } @@ -848,38 +548,53 @@ 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) +scsi_cdrom_update_request_length(scsi_cdrom_t *dev, int len, const int block_len) { - int32_t bt; int32_t min_len = 0; - double dlen; + int32_t bt; dev->max_transfer_len = dev->tf->request_length; - /* For media access commands, make sure the requested DRQ length matches the block length. */ + /* + For media access commands, make sure the requested DRQ length + matches the block length. + */ switch (dev->current_cdb[0]) { + case 0xbc: + if (!dev->drv->is_early) { + dev->packet_len = len; + break; + } + fallthrough; case 0x08: case 0x28: case 0xa8: + case 0xb8: case 0xb9: case 0xbe: + case 0xd5: /* Round it to the nearest (block length) bytes. */ - if ((dev->current_cdb[0] == 0xb9) || (dev->current_cdb[0] == 0xbe)) { - /* READ CD MSF and READ CD: Round the request length to the sector size - the device must ensure - that a media access comand does not DRQ in the middle of a sector. One of the drivers that - relies on the correctness of this behavior is MTMCDAI.SYS (the Mitsumi CD-ROM driver) for DOS - which uses the READ CD command to read data on some CD types. */ + if (dev->current_cdb[0] >= 0xb8) { + /* + READ CD MSF and READ CD: Round the request length to the sector size - the + device must ensure that a media access comand does not DRQ in the middle + of a sector. One of the drivers that relies on the correctness of this + behavior is MTMCDAI.SYS (the Mitsumi CD-ROM driver) for DOS which uses + the READ CD command to read data on some CD types. + */ /* Round to sector length. */ - dlen = ((double) dev->max_transfer_len) / ((double) block_len); + const double dlen = ((double) dev->max_transfer_len) / ((double) block_len); dev->max_transfer_len = ((uint16_t) floor(dlen)) * block_len; } else { /* Round it to the nearest 2048 bytes. */ - dev->max_transfer_len = (dev->max_transfer_len >> 11) << 11; + dev->max_transfer_len = (dev->max_transfer_len / dev->drv->sector_size) * dev->drv->sector_size; } - /* Make sure total length is not bigger than sum of the lengths of - all the requested blocks. */ + /* + Make sure total length is not bigger than sum of the lengths of + all the requested blocks. + */ bt = (dev->requested_blocks * block_len); if (len > bt) len = bt; @@ -895,16 +610,25 @@ scsi_cdrom_update_request_length(scsi_cdrom_t *dev, int len, int block_len) break; } } + + if ((dev->drv->bus_type != CDROM_BUS_SCSI) && (dev->block_len != 0)) + dev->requested_blocks = (dev->packet_len / dev->block_len); fallthrough; default: - dev->packet_len = len; + dev->packet_len = len; break; } - /* If the DRQ length is odd, and the total remaining length is bigger, make sure it's even. */ + /* + If the DRQ length is odd, and the total remaining length is bigger, + make sure it's even. + */ if ((dev->max_transfer_len & 1) && (dev->max_transfer_len < len)) dev->max_transfer_len &= 0xfffe; - /* If the DRQ length is smaller or equal in size to the total remaining length, set it to that. */ + /* + If the DRQ length is smaller or equal in size to the total remaining length, + set it to that. + */ if (!dev->max_transfer_len) dev->max_transfer_len = 65534; @@ -932,130 +656,71 @@ scsi_cdrom_bus_speed(scsi_cdrom_t *dev) dev->callback = -1.0; return 0.0; } else - return ret * 1000000.0; + return 1000000.0 / ret; } } +static void +scsi_cdrom_set_period(scsi_cdrom_t *dev) +{ + scsi_cdrom_log(dev->log, "Current speed: %ix\n", dev->drv->cur_speed); + + dev->callback = 0; + + if (dev->packet_status != PHASE_COMPLETE) { + double bytes_per_second; + double period; + + if (dev->was_cached != -1) { + if (dev->was_cached) { + dev->callback += 512.0; + scsi_cdrom_set_callback(dev); + return; + } + + /* Seek time is in us. */ + period = cdrom_seek_time(dev->drv); + scsi_cdrom_log(dev->log, "Seek period: %lf us\n", period); + dev->callback += period; + + /* 44100 * 16 bits * 2 channels = 176400 bytes per second */ + bytes_per_second = 176400.0; + bytes_per_second *= (double) dev->drv->cur_speed; + } else { + bytes_per_second = scsi_cdrom_bus_speed(dev); + if (bytes_per_second == 0.0) { + dev->callback = -1; /* Speed depends on SCSI controller */ + return; + } + } + + period = 1000000.0 / bytes_per_second; + scsi_cdrom_log(dev->log, "Byte transfer period: %lf us\n", period); + if (dev->was_cached == -1) + period *= (double) dev->packet_len; + else { + const int num = ((dev->drv->bus_type == CDROM_BUS_SCSI) || + (dev->block_len == 0)) ? dev->sectors_num : + ((scsi_cdrom_current_mode(dev) == 2) ? 1 : dev->sectors_num); + + period *= ((double) num) * 2352.0; + } + scsi_cdrom_log(dev->log, "Sector transfer period: %lf us\n", period); + dev->callback += period; + } + scsi_cdrom_set_callback(dev); +} + static void scsi_cdrom_command_common(scsi_cdrom_t *dev) { - double bytes_per_second = 0.0; - double period; - /* MAP: BUSY_STAT, no DRQ, phase 1. */ dev->tf->status = BUSY_STAT; dev->tf->phase = 1; dev->tf->pos = 0; dev->callback = 0; - scsi_cdrom_log("CD-ROM %i: Current speed: %ix\n", dev->id, dev->drv->cur_speed); - - if (dev->packet_status == PHASE_COMPLETE) - dev->callback = 0; - else { - switch (dev->current_cdb[0]) { - case GPCMD_REZERO_UNIT: - case 0x0b: - case 0x2b: - /* Seek time is in us. */ - period = cdrom_seek_time(dev->drv); - scsi_cdrom_log("CD-ROM %i: Seek period: %" PRIu64 " us\n", - dev->id, (uint64_t) period); - dev->callback += period; - scsi_cdrom_set_callback(dev); - return; - case 0x08: - case 0x28: - case 0xa8: - /* Seek time is in us. */ - period = cdrom_seek_time(dev->drv); - scsi_cdrom_log("CD-ROM %i: Seek period: %" PRIu64 " us\n", - dev->id, (uint64_t) period); - scsi_cdrom_log("CD-ROM %i: Seek period: %" PRIu64 " us, speed: %" PRIu64 " bytes per second, " - "should be: %" PRIu64 " bytes per second\n", - dev->id, (uint64_t) period, (uint64_t) (1000000.0 / period), - (uint64_t) (176400.0 * (double) dev->drv->cur_speed)); - dev->callback += period; - fallthrough; - case 0x25: - case 0x42 ... 0x44: - case 0x51 ... 0x52: - case 0xad: - case 0xb8 ... 0xb9: - case 0xbe: - if (dev->current_cdb[0] == 0x42) - dev->callback += 40.0; - /* Account for seek time. */ - /* 44100 * 16 bits * 2 channels = 176400 bytes per second */ - bytes_per_second = 176400.0; - bytes_per_second *= (double) dev->drv->cur_speed; - break; - case 0xc6 ... 0xc7: - switch (dev->drv->type) { - case CDROM_TYPE_TOSHIBA_XM_3433 ... CDROM_TYPE_TOSHIBA_SDM1401_1008: - bytes_per_second = 176400.0; - bytes_per_second *= (double) dev->drv->cur_speed; - break; - } - case 0xc0: - switch (dev->drv->type) { - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - /* 44100 * 16 bits * 2 channels = 176400 bytes per second */ - bytes_per_second = 176400.0; - bytes_per_second *= (double) dev->drv->cur_speed; - break; - } - case 0xc1: - switch (dev->drv->type) { - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_PIONEER_DRM604X_2403: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - /* 44100 * 16 bits * 2 channels = 176400 bytes per second */ - bytes_per_second = 176400.0; - bytes_per_second *= (double) dev->drv->cur_speed; - break; - } - case 0xc2 ... 0xc3: - switch (dev->drv->type) { - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_PIONEER_DRM604X_2403: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - if (dev->current_cdb[0] == 0xc2) - dev->callback += 40.0; - /* 44100 * 16 bits * 2 channels = 176400 bytes per second */ - bytes_per_second = 176400.0; - bytes_per_second *= (double) dev->drv->cur_speed; - break; - } - case 0xdd ... 0xde: - switch (dev->drv->type) { - case CDROM_TYPE_NEC_25_10a ... CDROM_TYPE_NEC_464_105: - /* 44100 * 16 bits * 2 channels = 176400 bytes per second */ - bytes_per_second = 176400.0; - bytes_per_second *= (double) dev->drv->cur_speed; - break; - } - fallthrough; - default: - bytes_per_second = scsi_cdrom_bus_speed(dev); - if (bytes_per_second == 0.0) { - dev->callback = -1; /* Speed depends on SCSI controller */ - return; - } - break; - } - - period = 1000000.0 / bytes_per_second; - scsi_cdrom_log("CD-ROM %i: Byte transfer period: %" PRIu64 " us\n", dev->id, (uint64_t) period); - period = period * (double) (dev->packet_len); - scsi_cdrom_log("CD-ROM %i: Sector transfer period: %" PRIu64 " us\n", dev->id, (uint64_t) period); - dev->callback += period; - } - scsi_cdrom_set_callback(dev); + scsi_cdrom_set_period(dev); } static void @@ -1096,16 +761,18 @@ scsi_cdrom_command_write_dma(scsi_cdrom_t *dev) scsi_cdrom_command_common(dev); } -/* id = Current CD-ROM device ID; +/* + dev = Pointer to current CD-ROM device; len = Total transfer length; block_len = Length of a single block (it matters because media access commands on ATAPI); alloc_len = Allocated transfer length; - direction = Transfer direction (0 = read from host, 1 = write to host). */ + direction = Transfer direction (0 = read from host, 1 = write to host). + */ static void scsi_cdrom_data_command_finish(scsi_cdrom_t *dev, int len, int block_len, int alloc_len, int direction) { - scsi_cdrom_log("CD-ROM %i: Finishing command (%02X): %i, %i, %i, %i, %i\n", - dev->id, dev->current_cdb[0], len, block_len, alloc_len, direction, + scsi_cdrom_log(dev->log, "Finishing command (%02X): %i, %i, %i, %i, %i\n", + dev->current_cdb[0], len, block_len, alloc_len, direction, dev->tf->request_length); dev->tf->pos = 0; if (alloc_len >= 0) { @@ -1128,79 +795,84 @@ scsi_cdrom_data_command_finish(scsi_cdrom_t *dev, int len, int block_len, int al scsi_cdrom_command_write_dma(dev); } else { scsi_cdrom_update_request_length(dev, len, block_len); - if (direction == 0) + if ((dev->drv->bus_type != CDROM_BUS_SCSI) && + (dev->tf->request_length == 0)) + scsi_cdrom_command_complete(dev); + else if (direction == 0) scsi_cdrom_command_read(dev); else scsi_cdrom_command_write(dev); } } - scsi_cdrom_log("CD-ROM %i: Status: %i, cylinder %i, packet length: %i, position: %i, phase: %i\n", - dev->id, dev->packet_status, dev->tf->request_length, dev->packet_len, dev->tf->pos, - dev->tf->phase); + scsi_cdrom_log(dev->log, "Status: %i, cylinder %i, packet length: %i, position: %i, " + "phase: %i\n", dev->packet_status, dev->tf->request_length, dev->packet_len, + dev->tf->pos, dev->tf->phase); } static void scsi_cdrom_sense_clear(scsi_cdrom_t *dev, UNUSED(int command)) { scsi_cdrom_sense_key = scsi_cdrom_asc = scsi_cdrom_ascq = 0; + scsi_cdrom_info = 0x00000000; } static void -scsi_cdrom_set_phase(scsi_cdrom_t *dev, uint8_t phase) +scsi_cdrom_set_phase(const scsi_cdrom_t *dev, const uint8_t phase) { - uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; - uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; + const uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; + const uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; - if (dev->drv->bus_type != CDROM_BUS_SCSI) - return; - - scsi_devices[scsi_bus][scsi_id].phase = phase; + if (dev->drv->bus_type == CDROM_BUS_SCSI) + scsi_devices[scsi_bus][scsi_id].phase = phase; } static void scsi_cdrom_cmd_error(scsi_cdrom_t *dev) { scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - dev->tf->error = ((scsi_cdrom_sense_key & 0xf) << 4) | ABRT_ERR; - dev->tf->status = READY_STAT | ERR_STAT; - dev->tf->phase = 3; - dev->tf->pos = 0; - dev->packet_status = PHASE_ERROR; - dev->callback = 50.0 * CDROM_TIME; - scsi_cdrom_set_callback(dev); - ui_sb_update_icon(SB_CDROM | dev->id, 0); - scsi_cdrom_log("CD-ROM %i: ERROR: %02X/%02X/%02X\n", dev->id, scsi_cdrom_sense_key, scsi_cdrom_asc, scsi_cdrom_ascq); -} - -static void -scsi_cdrom_unit_attention(scsi_cdrom_t *dev) -{ - scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - dev->tf->error = (SENSE_UNIT_ATTENTION << 4) | ABRT_ERR; - dev->tf->status = READY_STAT | ERR_STAT; + dev->tf->error = ((scsi_cdrom_sense_key & 0xf) << 4) | ABRT_ERR; + dev->tf->status = READY_STAT | ERR_STAT; dev->tf->phase = 3; dev->tf->pos = 0; dev->packet_status = PHASE_ERROR; dev->callback = 50.0 * CDROM_TIME; scsi_cdrom_set_callback(dev); ui_sb_update_icon(SB_CDROM | dev->id, 0); - scsi_cdrom_log("CD-ROM %i: UNIT ATTENTION\n", dev->id); + scsi_cdrom_log(dev->log, "ERROR: %02X/%02X/%02X\n", scsi_cdrom_sense_key, + scsi_cdrom_asc, scsi_cdrom_ascq); } static void -scsi_cdrom_buf_alloc(scsi_cdrom_t *dev, uint32_t len) +scsi_cdrom_unit_attention(scsi_cdrom_t *dev) { - if (!dev->buffer) + scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); + dev->tf->error = (SENSE_UNIT_ATTENTION << 4) | ABRT_ERR; + dev->tf->status = READY_STAT | ERR_STAT; + dev->tf->phase = 3; + dev->tf->pos = 0; + dev->packet_status = PHASE_ERROR; + dev->callback = 50.0 * CDROM_TIME; + scsi_cdrom_set_callback(dev); + ui_sb_update_icon(SB_CDROM | dev->id, 0); + scsi_cdrom_log(dev->log, "UNIT ATTENTION\n"); +} + +static void +scsi_cdrom_buf_alloc(scsi_cdrom_t *dev, const uint32_t len) +{ + if (dev->buffer == NULL) dev->buffer = (uint8_t *) malloc(len); - scsi_cdrom_log("CD-ROM %i: Allocated buffer length: %i, buffer = %p\n", dev->id, len, dev->buffer); + + scsi_cdrom_log(dev->log, "Allocated buffer length: %i, buffer = %p\n", + len, dev->buffer); } static void scsi_cdrom_buf_free(scsi_cdrom_t *dev) { if (dev->buffer) { - scsi_cdrom_log("CD-ROM %i: Freeing buffer...\n", dev->id); + scsi_cdrom_log(dev->log, "Freeing buffer...\n"); free(dev->buffer); dev->buffer = NULL; } @@ -1211,336 +883,270 @@ scsi_cdrom_bus_master_error(scsi_common_t *sc) { scsi_cdrom_t *dev = (scsi_cdrom_t *) sc; - scsi_cdrom_log("CD-ROM %i: Bus master error\n", dev->id); + scsi_cdrom_log(dev->log, "Bus master error\n"); scsi_cdrom_buf_free(dev); scsi_cdrom_sense_key = scsi_cdrom_asc = scsi_cdrom_ascq = 0; + scsi_cdrom_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); + scsi_cdrom_cmd_error(dev); +} + +static void +scsi_cdrom_error_common(scsi_cdrom_t *dev, uint8_t sense_key, uint8_t asc, uint8_t ascq, uint32_t info) +{ + scsi_cdrom_log(dev->log, "Medium not present\n"); + scsi_cdrom_sense_key = sense_key; + scsi_cdrom_asc = asc; + scsi_cdrom_ascq = ascq; + scsi_cdrom_info = info; scsi_cdrom_cmd_error(dev); } static void scsi_cdrom_not_ready(scsi_cdrom_t *dev) { - scsi_cdrom_log("CD-ROM %i: Medium not present\n", dev->id); + scsi_cdrom_log(dev->log, "Medium not present\n"); scsi_cdrom_sense_key = SENSE_NOT_READY; scsi_cdrom_asc = ASC_MEDIUM_NOT_PRESENT; scsi_cdrom_ascq = 0; + scsi_cdrom_info = 0x00000000; scsi_cdrom_cmd_error(dev); } static void scsi_cdrom_circ_error(scsi_cdrom_t *dev) { - scsi_cdrom_log("CD-ROM %i: CIRC unrecovered error\n", dev->id); + scsi_cdrom_log(dev->log, "CIRC unrecovered error\n"); scsi_cdrom_sense_key = SENSE_MEDIUM_ERROR; scsi_cdrom_asc = ASC_UNRECOVERED_READ_ERROR; scsi_cdrom_ascq = ASCQ_CIRC_UNRECOVERED_ERROR; + scsi_cdrom_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); scsi_cdrom_cmd_error(dev); } static void -scsi_cdrom_invalid_lun(scsi_cdrom_t *dev) +scsi_cdrom_invalid_lun(scsi_cdrom_t *dev, const uint8_t lun) { - scsi_cdrom_log("CD-ROM %i: Invalid LUN\n", dev->id); + scsi_cdrom_log(dev->log, "Invalid LUN\n"); scsi_cdrom_sense_key = SENSE_ILLEGAL_REQUEST; scsi_cdrom_asc = ASC_INV_LUN; scsi_cdrom_ascq = 0; + scsi_cdrom_info = lun << 24; scsi_cdrom_cmd_error(dev); } static void -scsi_cdrom_illegal_opcode(scsi_cdrom_t *dev) +scsi_cdrom_illegal_opcode(scsi_cdrom_t *dev, const uint8_t opcode) { - scsi_cdrom_log("CD-ROM %i: Illegal opcode\n", dev->id); + scsi_cdrom_log(dev->log, "Illegal opcode: %02X\n", opcode); scsi_cdrom_sense_key = SENSE_ILLEGAL_REQUEST; scsi_cdrom_asc = ASC_ILLEGAL_OPCODE; scsi_cdrom_ascq = 0; + scsi_cdrom_info = opcode << 24; scsi_cdrom_cmd_error(dev); } static void scsi_cdrom_lba_out_of_range(scsi_cdrom_t *dev) { - scsi_cdrom_log("CD-ROM %i: LBA out of range\n", dev->id); + scsi_cdrom_log(dev->log, "LBA out of range: %08X\n", dev->sector_pos); scsi_cdrom_sense_key = SENSE_ILLEGAL_REQUEST; scsi_cdrom_asc = ASC_LBA_OUT_OF_RANGE; scsi_cdrom_ascq = 0; + scsi_cdrom_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); scsi_cdrom_cmd_error(dev); } static void -scsi_cdrom_invalid_field(scsi_cdrom_t *dev) +scsi_cdrom_invalid_field(scsi_cdrom_t *dev, const uint32_t field) { - scsi_cdrom_log("CD-ROM %i: Invalid field in command packet\n", dev->id); + scsi_cdrom_log(dev->log, "Invalid field in command packet\n"); scsi_cdrom_sense_key = SENSE_ILLEGAL_REQUEST; scsi_cdrom_asc = ASC_INV_FIELD_IN_CMD_PACKET; scsi_cdrom_ascq = 0; + scsi_cdrom_info = (field >> 24) | + ((field >> 16) << 8) | + ((field >> 8) << 16) | + ( field << 24); scsi_cdrom_cmd_error(dev); dev->tf->status = 0x53; } static void -scsi_cdrom_invalid_field_pl(scsi_cdrom_t *dev) +scsi_cdrom_invalid_field_pl(scsi_cdrom_t *dev, const uint32_t field) { - scsi_cdrom_log("CD-ROM %i: Invalid field in parameter list\n", dev->id); + scsi_cdrom_log(dev->log, "Invalid field in parameter list\n"); scsi_cdrom_sense_key = SENSE_ILLEGAL_REQUEST; scsi_cdrom_asc = ASC_INV_FIELD_IN_PARAMETER_LIST; scsi_cdrom_ascq = 0; + scsi_cdrom_info = (field >> 24) | + ((field >> 16) << 8) | + ((field >> 8) << 16) | + ( field << 24); scsi_cdrom_cmd_error(dev); dev->tf->status = 0x53; } +static void +scsi_cdrom_incompatible_format(scsi_cdrom_t *dev, const uint32_t val) +{ + scsi_cdrom_log(dev->log, "Incompatible format\n"); + scsi_cdrom_sense_key = SENSE_ILLEGAL_REQUEST; + scsi_cdrom_asc = ASC_INCOMPATIBLE_FORMAT; + scsi_cdrom_ascq = 2; + scsi_cdrom_info = (val >> 24) | + ((val >> 16) << 8) | + ((val >> 8) << 16) | + ( val << 24); + scsi_cdrom_cmd_error(dev); +} + +static void +scsi_cdrom_data_phase_error(scsi_cdrom_t *dev, const uint32_t info) +{ + scsi_cdrom_log(dev->log, "Data phase error\n"); + scsi_cdrom_sense_key = SENSE_ILLEGAL_REQUEST; + scsi_cdrom_asc = ASC_DATA_PHASE_ERROR; + scsi_cdrom_ascq = 0; + scsi_cdrom_info = (info >> 24) | + ((info >> 16) << 8) | + ((info >> 8) << 16) | + ( info << 24); + scsi_cdrom_cmd_error(dev); +} + static void scsi_cdrom_illegal_mode(scsi_cdrom_t *dev) { - scsi_cdrom_log("CD-ROM %i: Illegal mode for this track\n", dev->id); + scsi_cdrom_log(dev->log, "Illegal mode for this track\n"); scsi_cdrom_sense_key = SENSE_ILLEGAL_REQUEST; scsi_cdrom_asc = ASC_ILLEGAL_MODE_FOR_THIS_TRACK; scsi_cdrom_ascq = 0; - scsi_cdrom_cmd_error(dev); -} - -static void -scsi_cdrom_incompatible_format(scsi_cdrom_t *dev) -{ - scsi_cdrom_log("CD-ROM %i: Incompatible format\n", dev->id); - scsi_cdrom_sense_key = SENSE_ILLEGAL_REQUEST; - scsi_cdrom_asc = ASC_INCOMPATIBLE_FORMAT; - scsi_cdrom_ascq = 2; - scsi_cdrom_cmd_error(dev); -} - -static void -scsi_cdrom_data_phase_error(scsi_cdrom_t *dev) -{ - scsi_cdrom_log("CD-ROM %i: Data phase error\n", dev->id); - scsi_cdrom_sense_key = SENSE_ILLEGAL_REQUEST; - scsi_cdrom_asc = ASC_DATA_PHASE_ERROR; - scsi_cdrom_ascq = 0; + scsi_cdrom_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); scsi_cdrom_cmd_error(dev); } static int -scsi_cdrom_read_data(scsi_cdrom_t *dev, int msf, int type, int flags, int32_t *len, int vendor_type) +scsi_cdrom_read_data(scsi_cdrom_t *dev, const int msf, const int type, const int flags, + const int vendor_type) { - int ret = 0; - int data_pos = 0; - int temp_len = 0; - uint32_t cdsize = 0; + int temp_len = 0; + int ret = 0; + int num = (dev->drv->bus_type == CDROM_BUS_SCSI) ? + dev->requested_blocks : 1; - if (dev->drv->cd_status == CD_STATUS_EMPTY) { + dev->sectors_num = 0; + + if (dev->drv->cd_status == CD_STATUS_EMPTY) scsi_cdrom_not_ready(dev); - return 0; - } - - cdsize = dev->drv->cdrom_capacity; - - if (dev->sector_pos >= cdsize) { - scsi_cdrom_log("CD-ROM %i: Trying to read from beyond the end of disc (%i >= %i)\n", dev->id, - dev->sector_pos, cdsize); + else if (dev->sector_pos > dev->drv->cdrom_capacity) { scsi_cdrom_lba_out_of_range(dev); - return -1; - } + ret = -1; + } else { + ret = 1; + for (int i = 0; (i < num) && (ret > 0) && (dev->sector_len > 0); i++) { + ret = cdrom_readsector_raw(dev->drv, dev->buffer + dev->buffer_pos, + dev->sector_pos, msf, type, + flags, &temp_len, vendor_type); -/* FIXME: Temporarily disabled this because the Triones ATAPI DMA driver seems to - always request a 4-sector read but sets the DMA bus master to transfer less - data than that. */ -#if 0 - if ((dev->sector_pos + dev->sector_len - 1) >= cdsize) { - scsi_cdrom_log("CD-ROM %i: Trying to read to beyond the end of disc (%i >= %i)\n", dev->id, - (dev->sector_pos + dev->sector_len - 1), cdsize); - scsi_cdrom_lba_out_of_range(dev); - return -1; - } -#endif + if (ret < 0) + scsi_cdrom_circ_error(dev); + else if (ret == 0) + scsi_cdrom_illegal_mode(dev); + else { + if (dev->block_len == 0xffffffff) { + dev->block_len = temp_len; - dev->old_len = 0; - *len = 0; + if ((dev->drv->bus_type != CDROM_BUS_SCSI) && + (scsi_cdrom_current_mode(dev) != 2)) { + num = (dev->tf->request_length < dev->block_len) ? + dev->block_len : dev->tf->request_length; + num = (num / dev->block_len) * dev->block_len; + if (num > dev->sector_len) + num = dev->sector_len; + } + } - 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); + dev->sector_pos++; + dev->drv->seek_pos = dev->sector_pos; - data_pos += temp_len; - dev->old_len += temp_len; + dev->sector_len--; + dev->sectors_num++; - *len += temp_len; - - if (!ret) { - scsi_cdrom_illegal_mode(dev); - return 0; - } else if (ret < 0) { - scsi_cdrom_circ_error(dev); - return -1; + dev->buffer_pos += temp_len; + } } } - return 1; + if ((ret < 1) || (dev->sector_len == 0)) + dev->wait = 0; + + return ret; } static int -scsi_cdrom_read_blocks(scsi_cdrom_t *dev, int32_t *len, int first_batch, int vendor_type) +scsi_cdrom_read_blocks(scsi_cdrom_t *dev) { - int ret = 0; + int ret = 1; int msf = 0; - int type = 0; - int flags = 0; + int type = dev->sector_type; + int flags = dev->sector_flags; +#ifdef ENABLE_SCSI_CDROM_LOG + int num = (dev->drv->bus_type == CDROM_BUS_SCSI) ? + dev->requested_blocks : 1; +#endif switch (dev->current_cdb[0]) { case GPCMD_READ_CD_MSF_OLD: case GPCMD_READ_CD_MSF: msf = 1; fallthrough; + case GPCMD_PLAY_CD: case GPCMD_READ_CD_OLD: case GPCMD_READ_CD: type = (dev->current_cdb[1] >> 2) & 7; flags = dev->current_cdb[9] | (((uint32_t) dev->current_cdb[10]) << 8); break; + case GPCMD_READ_HEADER: + case GPCMD_READ_HEADER_SONY: + type = 0x00; + flags = 0x20; + break; default: - type = 8; /* Internal type code indicating both Mode 1 and Mode 2 Form 1 are allowed. */ - flags = (dev->drv->sector_size == 2340) ? 0x78 : 0x10; + if (dev->sector_type == 0xff) { + scsi_cdrom_illegal_mode(dev); + ret = 0; + } break; } - if (!dev->sector_len) { - scsi_cdrom_command_complete(dev); - return -1; + if (ret) { + if (dev->sector_len == 0) { + scsi_cdrom_command_complete(dev); + return -1; + } + + scsi_cdrom_log(dev->log, "Reading %i blocks starting from %i...\n", + num, dev->sector_pos); + + ret = scsi_cdrom_read_data(dev, msf, type, flags, dev->vendor_type); + + scsi_cdrom_log(dev->log, "Read %i bytes of blocks (ret = %i)...\n", + dev->block_len, ret); } - scsi_cdrom_log("Reading %i blocks starting from %i...\n", dev->requested_blocks, dev->sector_pos); - - ret = scsi_cdrom_read_data(dev, msf, type, flags, len, vendor_type); - - scsi_cdrom_log("Read %i bytes of blocks...\n", *len); - - if (ret == -1) - return ret; - else if (!ret || (!first_batch && (dev->old_len != *len))) { - if (!first_batch && (dev->old_len != *len)) - scsi_cdrom_illegal_mode(dev); - - return 0; - } - - dev->sector_pos += dev->requested_blocks; - dev->drv->seek_pos = dev->sector_pos; - dev->sector_len -= dev->requested_blocks; - return 1; -} - -/*SCSI Read DVD Structure*/ -static int -scsi_cdrom_read_dvd_structure(scsi_cdrom_t *dev, int format, const uint8_t *packet, uint8_t *buf) -{ - int layer = packet[6]; - uint64_t total_sectors = 0; - - switch (format) { - case 0x00: /* Physical format information */ - if (dev->drv->cd_status == CD_STATUS_EMPTY) { - scsi_cdrom_not_ready(dev); - return 0; - } - - total_sectors = (uint64_t) dev->drv->cdrom_capacity; - - if (layer != 0) { - scsi_cdrom_invalid_field(dev); - return 0; - } - - total_sectors >>= 2; - if (total_sectors == 0) { - /* return -ASC_MEDIUM_NOT_PRESENT; */ - scsi_cdrom_not_ready(dev); - return 0; - } - - buf[4] = 18; /* Length of Layer Information */ - buf[5] = 0; - - buf[6] = 1; /* DVD-ROM, part version 1 */ - buf[7] = 0xf; /* 120mm disc, minimum rate unspecified */ - buf[8] = 1; /* one layer, read-only (per MMC-2 spec) */ - buf[9] = 0; /* default densities */ - - /* FIXME: 0x30000 per spec? */ - buf[10] = 0x00; - buf[11] = 0x03; - buf[12] = buf[13] = 0; /* start sector */ - - buf[14] = 0x00; - buf[15] = (total_sectors >> 16) & 0xff; /* end sector */ - buf[16] = (total_sectors >> 8) & 0xff; - buf[17] = total_sectors & 0xff; - - buf[18] = 0x00; - buf[19] = (total_sectors >> 16) & 0xff; /* l0 end sector */ - buf[20] = (total_sectors >> 8) & 0xff; - buf[21] = total_sectors & 0xff; - - /* 20 bytes of data + 4 byte header */ - return (20 + 4); - - case 0x01: /* DVD copyright information */ - buf[4] = 0; /* no copyright data */ - buf[5] = 0; /* no region restrictions */ - - /* Size of buffer, not including 2 byte size field */ - buf[0] = ((4 + 2) >> 8) & 0xff; - buf[1] = (4 + 2) & 0xff; - - /* 4 byte header + 4 byte data */ - return (4 + 4); - - case 0x03: /* BCA information - invalid field for no BCA info */ - scsi_cdrom_invalid_field(dev); - return 0; - - case 0x04: /* DVD disc manufacturing information */ - /* Size of buffer, not including 2 byte size field */ - buf[0] = ((2048 + 2) >> 8) & 0xff; - buf[1] = (2048 + 2) & 0xff; - - /* 2k data + 4 byte header */ - return (2048 + 4); - - case 0xff: - /* - * This lists all the command capabilities above. Add new ones - * in order and update the length and buffer return values. - */ - - buf[4] = 0x00; /* Physical format */ - buf[5] = 0x40; /* Not writable, is readable */ - buf[6] = ((20 + 4) >> 8) & 0xff; - buf[7] = (20 + 4) & 0xff; - - buf[8] = 0x01; /* Copyright info */ - buf[9] = 0x40; /* Not writable, is readable */ - buf[10] = ((4 + 4) >> 8) & 0xff; - buf[11] = (4 + 4) & 0xff; - - buf[12] = 0x03; /* BCA info */ - buf[13] = 0x40; /* Not writable, is readable */ - buf[14] = ((188 + 4) >> 8) & 0xff; - buf[15] = (188 + 4) & 0xff; - - buf[16] = 0x04; /* Manufacturing info */ - buf[17] = 0x40; /* Not writable, is readable */ - buf[18] = ((2048 + 4) >> 8) & 0xff; - buf[19] = (2048 + 4) & 0xff; - - /* Size of buffer, not including 2 byte size field */ - buf[6] = ((16 + 2) >> 8) & 0xff; - buf[7] = (16 + 2) & 0xff; - - /* data written + 4 byte header */ - return (16 + 4); - - default: /* TODO: formats beyond DVD-ROM requires */ - scsi_cdrom_invalid_field(dev); - return 0; - } + return ret; } static void @@ -1554,104 +1160,77 @@ scsi_cdrom_insert(void *priv) if (dev->drv->ops == NULL) { dev->unit_attention = 0; dev->drv->cd_status = CD_STATUS_EMPTY; - scsi_cdrom_log("CD-ROM %i: Media removal\n", dev->id); + scsi_cdrom_log(dev->log, "Media removal\n"); } else if (dev->drv->cd_status & CD_STATUS_TRANSITION) { dev->unit_attention = 1; /* Turn off the medium changed status. */ dev->drv->cd_status &= ~CD_STATUS_TRANSITION; - scsi_cdrom_log("CD-ROM %i: Media insert\n", dev->id); + scsi_cdrom_log(dev->log, "Media insert\n"); } else { dev->unit_attention = 0; dev->drv->cd_status |= CD_STATUS_TRANSITION; - scsi_cdrom_log("CD-ROM %i: Media transition\n", dev->id); - } -} - -static void -scsi_cdrom_ext_insert(void *priv, int ext_medium_changed) -{ - scsi_cdrom_t *dev = (scsi_cdrom_t *) priv; - - if ((dev == NULL) || (dev->drv == NULL)) - return; - - if ((dev->drv->ops == NULL) || (ext_medium_changed == -1)) { - dev->unit_attention = 0; - dev->drv->cd_status = CD_STATUS_EMPTY; - scsi_cdrom_log("CD-ROM %i: External media removal\n", dev->id); - } else if (ext_medium_changed == 1) { - dev->unit_attention = 0; - dev->drv->cd_status |= CD_STATUS_TRANSITION; - scsi_cdrom_log("CD-ROM %i: External media transition\n", dev->id); + scsi_cdrom_log(dev->log, "Media transition\n"); } } static int -scsi_command_check_ready(scsi_cdrom_t *dev, uint8_t *cdb) +scsi_command_check_ready(const scsi_cdrom_t *dev, const uint8_t *cdb) { int ret = 0; if (scsi_cdrom_command_flags[cdb[0]] & CHECK_READY) { - /*Note by TC1995: Some vendor commands from X vendor don't really check for ready status - but they do on Y vendor. Quite confusing I know.*/ - if (scsi_cdrom_command_flags[cdb[0]] & SCSI_ONLY) switch (dev->drv->type) { - default: - ret = 1; - break; - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - if (cdb[0] == 0xc0) - break; - ret = 1; - break; - } else + /* + Note by TC1995: Some vendor commands from X vendor don't really + check for ready status but they do on Y vendor. + Quite confusing I know. + */ + if (!dev->drv->is_sony || (cdb[0] != 0xc0)) ret = 1; - } + } else if ((cdb[0] == GPCMD_READ_DVD_STRUCTURE) && (cdb[7] < 0xc0)) + ret = 1; return ret; } static int -scsi_cdrom_pre_execution_check(scsi_cdrom_t *dev, uint8_t *cdb) +scsi_cdrom_pre_execution_check(scsi_cdrom_t *dev, const uint8_t *cdb) { - int ready = 0; - int ext_medium_changed = 0; + int ready; - if (dev->drv && dev->drv->ops && dev->drv->ops->ext_medium_changed) - ext_medium_changed = dev->drv->ops->ext_medium_changed(dev->drv); - - if ((cdb[0] != GPCMD_REQUEST_SENSE) && (dev->cur_lun == SCSI_LUN_USE_CDB) && (cdb[1] & 0xe0)) { - scsi_cdrom_log("CD-ROM %i: Attempting to execute a unknown command targeted at SCSI LUN %i\n", - dev->id, ((dev->tf->request_length >> 5) & 7)); - scsi_cdrom_invalid_lun(dev); + if ((cdb[0] != GPCMD_REQUEST_SENSE) && (dev->cur_lun == SCSI_LUN_USE_CDB) && + (cdb[1] & 0xe0)) { + scsi_cdrom_log(dev->log, "Attempting to execute a unknown command targeted " + "at SCSI LUN %i\n", ((dev->tf->request_length >> 5) & 7)); + scsi_cdrom_invalid_lun(dev, cdb[1] >> 5); return 0; } if (!(scsi_cdrom_command_flags[cdb[0]] & IMPLEMENTED)) { - scsi_cdrom_log("CD-ROM %i: Attempting to execute unknown command %02X over %s\n", dev->id, cdb[0], - (dev->drv->bus_type == CDROM_BUS_SCSI) ? "SCSI" : "ATAPI"); + scsi_cdrom_log(dev->log, "Attempting to execute unknown command %02X over %s\n", + cdb[0], (dev->drv->bus_type == CDROM_BUS_SCSI) ? "SCSI" : "ATAPI"); - scsi_cdrom_illegal_opcode(dev); + scsi_cdrom_illegal_opcode(dev, cdb[0]); return 0; } - if ((dev->drv->bus_type < CDROM_BUS_SCSI) && (scsi_cdrom_command_flags[cdb[0]] & SCSI_ONLY)) { - scsi_cdrom_log("CD-ROM %i: Attempting to execute SCSI-only command %02X over ATAPI\n", dev->id, cdb[0]); - scsi_cdrom_illegal_opcode(dev); + if ((dev->drv->bus_type < CDROM_BUS_SCSI) && + (scsi_cdrom_command_flags[cdb[0]] & SCSI_ONLY)) { + scsi_cdrom_log(dev->log, "Attempting to execute SCSI-only command %02X over " + "ATAPI\n", cdb[0]); + scsi_cdrom_illegal_opcode(dev, cdb[0]); return 0; } - if ((dev->drv->bus_type == CDROM_BUS_SCSI) && (scsi_cdrom_command_flags[cdb[0]] & ATAPI_ONLY)) { - scsi_cdrom_log("CD-ROM %i: Attempting to execute ATAPI-only command %02X over SCSI\n", dev->id, cdb[0]); - scsi_cdrom_illegal_opcode(dev); + if ((dev->drv->bus_type == CDROM_BUS_SCSI) && + (scsi_cdrom_command_flags[cdb[0]] & ATAPI_ONLY)) { + scsi_cdrom_log(dev->log, "Attempting to execute ATAPI-only command %02X over " + "SCSI\n", cdb[0]); + scsi_cdrom_illegal_opcode(dev, cdb[0]); return 0; } - if (ext_medium_changed != 0) - scsi_cdrom_ext_insert((void *) dev, ext_medium_changed); - - if ((dev->drv->cd_status == CD_STATUS_PLAYING) || (dev->drv->cd_status == CD_STATUS_PAUSED)) { + if ((dev->drv->cd_status == CD_STATUS_PLAYING) || + (dev->drv->cd_status == CD_STATUS_PAUSED)) { ready = 1; goto skip_ready_check; } @@ -1660,105 +1239,175 @@ scsi_cdrom_pre_execution_check(scsi_cdrom_t *dev, uint8_t *cdb) if ((cdb[0] == GPCMD_TEST_UNIT_READY) || (cdb[0] == GPCMD_REQUEST_SENSE)) ready = 0; else { - if ((ext_medium_changed != 0) || !(scsi_cdrom_command_flags[cdb[0]] & ALLOW_UA)) { - scsi_cdrom_log("(ext_medium_changed != 0): scsi_cdrom_insert()\n"); + if (!(scsi_cdrom_command_flags[cdb[0]] & ALLOW_UA)) scsi_cdrom_insert((void *) dev); - } - ready = (dev->drv->cd_status != CD_STATUS_EMPTY) || (ext_medium_changed == -1); + ready = (dev->drv->cd_status != CD_STATUS_EMPTY); } } else ready = (dev->drv->cd_status != CD_STATUS_EMPTY); skip_ready_check: - /* If the drive is not ready, there is no reason to keep the + /* + If the drive is not ready, there is no reason to keep the UNIT ATTENTION condition present, as we only use it to mark - disc changes. */ + disc changes. + */ if (!ready && (dev->unit_attention > 0)) dev->unit_attention = 0; - /* If the UNIT ATTENTION condition is set and the command does not allow - execution under it, error out and report the condition. */ + /* + If the UNIT ATTENTION condition is set and the command does not allow + execution under it, error out and report the condition. + */ if (dev->unit_attention == 1) { - /* Only increment the unit attention phase if the command can not pass through it. */ + /* + Only increment the unit attention phase if the command can + not pass through it. + */ if (!(scsi_cdrom_command_flags[cdb[0]] & ALLOW_UA)) { - scsi_cdrom_log("CD-ROM %i: Unit attention now 2\n", dev->id); + scsi_cdrom_log(dev->log, "Unit attention now 2\n"); dev->unit_attention++; - scsi_cdrom_log("CD-ROM %i: UNIT ATTENTION: Command %02X not allowed to pass through\n", - dev->id, cdb[0]); + scsi_cdrom_log(dev->log, "UNIT ATTENTION: Command %02X not allowed to " + "pass through\n", cdb[0]); scsi_cdrom_unit_attention(dev); return 0; } } else if (dev->unit_attention == 2) { if (cdb[0] != GPCMD_REQUEST_SENSE) { - scsi_cdrom_log("CD-ROM %i: Unit attention now 0\n", dev->id); + scsi_cdrom_log(dev->log, "Unit attention now 0\n"); dev->unit_attention = 0; } } - /* Unless the command is REQUEST SENSE, clear the sense. This will *NOT* clear - the UNIT ATTENTION condition if it's set. */ + /* + Unless the command is REQUEST SENSE, clear the sense. This will *NOT* clear + the UNIT ATTENTION condition if it's set. + */ if (cdb[0] != GPCMD_REQUEST_SENSE) scsi_cdrom_sense_clear(dev, cdb[0]); - /* Next it's time for NOT READY. */ - if (ready) - dev->media_status = dev->unit_attention ? MEC_NEW_MEDIA : MEC_NO_CHANGE; - else - dev->media_status = MEC_MEDIA_REMOVAL; - if (!ready && scsi_command_check_ready(dev, cdb)) { - scsi_cdrom_log("CD-ROM %i: Not ready (%02X)\n", dev->id, cdb[0]); + scsi_cdrom_log(dev->log, "Not ready (%02X)\n", cdb[0]); scsi_cdrom_not_ready(dev); return 0; } - scsi_cdrom_log("CD-ROM %i: Continuing with command %02X\n", dev->id, cdb[0]); + scsi_cdrom_log(dev->log, "Continuing with command %02X\n", cdb[0]); return 1; } static void scsi_cdrom_rezero(scsi_cdrom_t *dev) { + dev->drv->seek_diff = ABS(dev->sector_pos); dev->sector_pos = dev->sector_len = 0; cdrom_seek(dev->drv, 0, 0); } +static int +scsi_cdrom_update_sector_flags(scsi_cdrom_t *dev) +{ + int ret = 0; + + switch (dev->drv->sector_size) { + default: + dev->sector_type = 0xff; + scsi_cdrom_log(dev->log, "Invalid sector size: %i\n", dev->drv->sector_size); + scsi_cdrom_invalid_field_pl(dev, dev->drv->sector_size); + ret = 1; + break; + case 128: case 256: case 512: case 2048: + /* + Internal type code indicating both Mode 1 and Mode 2 Form 1 are allowed. + Upper 4 bits indicate the divisor. + */ + dev->sector_type = 0x08 | ((2048 / dev->drv->sector_size) << 4); + dev->sector_flags = 0x0010; + break; + case 2056: + dev->sector_type = 0x18; + dev->sector_flags = 0x0050; + break; + case 2324: case 2328: + dev->sector_type = (dev->drv->sector_size == 2328) ? 0x1a : 0x1b; + dev->sector_flags = 0x0018; + break; + case 2332: case 2336: + dev->sector_type = (dev->drv->sector_size == 2336) ? 0x1c : 0x1d; + dev->sector_flags = 0x0058; + break; + case 2340: + dev->sector_type = 0x18; + dev->sector_flags = 0x0078; + break; + case 2352: + dev->sector_type = 0x00; + dev->sector_flags = 0x00f8; + break; + case 2368: + dev->sector_type = 0x00; + dev->sector_flags = 0x01f8; + break; + case 2448: + dev->sector_type = 0x00; + dev->sector_flags = 0x02f8; + break; + case 2646: + dev->sector_type = 0x00; + dev->sector_flags = 0x00fa; + break; + } + + return ret; +} + void scsi_cdrom_reset(scsi_common_t *sc) { scsi_cdrom_t *dev = (scsi_cdrom_t *) sc; - if (!dev) - return; + if (dev != NULL) { + scsi_cdrom_rezero(dev); + dev->tf->status = 0; + dev->callback = 0.0; + scsi_cdrom_set_callback(dev); + dev->tf->phase = 1; + dev->tf->request_length = 0xeb14; + dev->packet_status = PHASE_NONE; + dev->unit_attention = 0xff; + dev->cur_lun = SCSI_LUN_USE_CDB; - scsi_cdrom_rezero(dev); - dev->tf->status = 0; - dev->callback = 0.0; - scsi_cdrom_set_callback(dev); - dev->tf->phase = 1; - dev->tf->request_length = 0xeb14; - dev->packet_status = PHASE_NONE; - dev->unit_attention = 0xff; - dev->cur_lun = SCSI_LUN_USE_CDB; + dev->drv->sector_size = 2048; + (void) scsi_cdrom_update_sector_flags(dev); + + scsi_cdrom_sense_key = scsi_cdrom_asc = scsi_cdrom_ascq = dev->unit_attention = 0; + scsi_cdrom_info = 0x00000000; + dev->drv->cd_status &= ~CD_STATUS_TRANSITION; + dev->drv->cached_sector = -1; + dev->toc_cached = 0; + } } static void scsi_cdrom_request_sense(scsi_cdrom_t *dev, uint8_t *buffer, uint8_t alloc_length) { - /*Will return 18 bytes of 0*/ + /* Will return 18 bytes of 0x00. */ if (alloc_length != 0) { - memset(buffer, 0, alloc_length); + memset(buffer, 0x00, alloc_length); memcpy(buffer, dev->sense, alloc_length); } - buffer[0] = 0x70; + buffer[0] = 0xf0; + buffer[7] = 0x0a; if ((scsi_cdrom_sense_key > 0) && (dev->drv->cd_status == CD_STATUS_PLAYING_COMPLETED)) { buffer[2] = SENSE_ILLEGAL_REQUEST; buffer[12] = ASC_AUDIO_PLAY_OPERATION; buffer[13] = ASCQ_AUDIO_PLAY_OPERATION_COMPLETED; - } else if ((scsi_cdrom_sense_key == 0) && ((dev->drv->cd_status == CD_STATUS_PAUSED) || ((dev->drv->cd_status >= CD_STATUS_PLAYING) && (dev->drv->cd_status != CD_STATUS_STOPPED)))) { + } else if ((scsi_cdrom_sense_key == 0) && + ((dev->drv->cd_status == CD_STATUS_PAUSED) || ((dev->drv->cd_status >= CD_STATUS_PLAYING) && + (dev->drv->cd_status != CD_STATUS_STOPPED)))) { buffer[2] = SENSE_ILLEGAL_REQUEST; buffer[12] = ASC_AUDIO_PLAY_OPERATION; buffer[13] = (dev->drv->cd_status == CD_STATUS_PLAYING) ? ASCQ_AUDIO_PLAY_OPERATION_IN_PROGRESS : ASCQ_AUDIO_PLAY_OPERATION_PAUSED; @@ -1768,7 +1417,8 @@ scsi_cdrom_request_sense(scsi_cdrom_t *dev, uint8_t *buffer, uint8_t alloc_lengt buffer[13] = 0; } - scsi_cdrom_log("CD-ROM %i: Reporting sense: %02X %02X %02X\n", dev->id, buffer[2], buffer[12], buffer[13]); + scsi_cdrom_log(dev->log, "Reporting sense: %02X %02X %02X\n", buffer[2], buffer[12], + buffer[13]); if (buffer[2] == SENSE_UNIT_ATTENTION) { /* If the last remaining sense is unit attention, clear @@ -1777,7 +1427,7 @@ scsi_cdrom_request_sense(scsi_cdrom_t *dev, uint8_t *buffer, uint8_t alloc_lengt } if (dev->drv->cd_status & CD_STATUS_TRANSITION) { - scsi_cdrom_log("CD_STATUS_TRANSITION: scsi_cdrom_insert()\n"); + scsi_cdrom_log(dev->log, "CD_STATUS_TRANSITION: scsi_cdrom_insert()\n"); scsi_cdrom_insert((void *) dev); } } @@ -1786,18 +1436,12 @@ void scsi_cdrom_request_sense_for_scsi(scsi_common_t *sc, uint8_t *buffer, uint8_t alloc_length) { scsi_cdrom_t *dev = (scsi_cdrom_t *) sc; - int ext_medium_changed = 0; - - if (dev->drv && dev->drv->ops && dev->drv->ops->ext_medium_changed) - ext_medium_changed = dev->drv->ops->ext_medium_changed(dev->drv); - - if (ext_medium_changed != 0) - scsi_cdrom_ext_insert((void *) dev, ext_medium_changed); if ((dev->drv->cd_status == CD_STATUS_EMPTY) && dev->unit_attention) { - /* If the drive is not ready, there is no reason to keep the - UNIT ATTENTION condition present, as we only use it to mark - disc changes. */ + /* + If the drive is not ready, there is no reason to keep the UNIT ATTENTION + condition present, as we only use it to mark disc changes. + */ dev->unit_attention = 0; } @@ -1806,7 +1450,7 @@ scsi_cdrom_request_sense_for_scsi(scsi_common_t *sc, uint8_t *buffer, uint8_t al } static void -scsi_cdrom_set_buf_len(scsi_cdrom_t *dev, int32_t *BufLen, int32_t *src_len) +scsi_cdrom_set_buf_len(const scsi_cdrom_t *dev, int32_t *BufLen, int32_t *src_len) { if (dev->drv->bus_type == CDROM_BUS_SCSI) { if (*BufLen == -1) @@ -1815,50 +1459,57 @@ scsi_cdrom_set_buf_len(scsi_cdrom_t *dev, int32_t *BufLen, int32_t *src_len) *BufLen = MIN(*src_len, *BufLen); *src_len = *BufLen; } - scsi_cdrom_log("CD-ROM %i: Actual transfer length: %i\n", dev->id, *BufLen); + scsi_cdrom_log(dev->log, "Actual transfer length: %i\n", *BufLen); } } static void -scsi_cdrom_stop(scsi_common_t *sc) +scsi_cdrom_stop(const scsi_common_t *sc) { - scsi_cdrom_t *dev = (scsi_cdrom_t *) sc; + const scsi_cdrom_t *dev = (const scsi_cdrom_t *) sc; cdrom_stop(dev->drv); + + ui_sb_update_icon(SB_CDROM | dev->id, 0); } static void -scsi_cdrom_set_speed(scsi_cdrom_t *dev, uint8_t *cdb) +scsi_cdrom_set_speed(scsi_cdrom_t *dev, const uint8_t *cdb) { + /* Stop the audio playing. */ + cdrom_stop(dev->drv); + dev->drv->cur_speed = (cdb[3] | (cdb[2] << 8)) / 176; if (dev->drv->cur_speed < 1) dev->drv->cur_speed = 1; - else if (dev->drv->cur_speed > dev->drv->speed) - dev->drv->cur_speed = dev->drv->speed; + else if (dev->drv->cur_speed > dev->drv->real_speed) + dev->drv->cur_speed = dev->drv->real_speed; scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); scsi_cdrom_command_complete(dev); } static uint8_t -scsi_cdrom_command_chinon(void *sc, uint8_t *cdb, int32_t *BufLen) +scsi_cdrom_command_chinon(void *sc, const uint8_t *cdb, UNUSED(int32_t *BufLen)) { scsi_cdrom_t *dev = (scsi_cdrom_t *) sc; uint8_t cmd_stat = 0x00; switch (cdb[0]) { + default: + break; + case GPCMD_UNKNOWN_CHINON: - if (dev->drv->type == CDROM_TYPE_CHINON_CDS431_H42) { - scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - scsi_cdrom_stop(sc); - scsi_cdrom_command_complete(dev); - cmd_stat = 0x01; - } + scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); + scsi_cdrom_stop(sc); + scsi_cdrom_command_complete(dev); + cmd_stat = 0x01; break; case GPCMD_EJECT_CHINON: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); scsi_cdrom_stop(sc); cdrom_eject(dev->id); + dev->toc_cached = 0; scsi_cdrom_command_complete(dev); cmd_stat = 0x01; break; @@ -1874,23 +1525,73 @@ scsi_cdrom_command_chinon(void *sc, uint8_t *cdb, int32_t *BufLen) return cmd_stat; } +static void +scsi_cdrom_cache_toc(scsi_cdrom_t *dev) +{ + if (!dev->toc_cached) { + dev->toc_cached = 1; + dev->drv->seek_diff = dev->drv->seek_pos + 150; + dev->sector_pos = -150; + dev->drv->seek_pos = -150; + dev->requested_blocks = 150; + dev->drv->cached_sector = -1; + } +} + +static void +scsi_cdrom_one_sector_seek(scsi_cdrom_t *dev) +{ + if (!dev->was_cached) { + dev->drv->seek_diff = 0; + dev->requested_blocks = 1; + } +} + +static void +scsi_cdrom_media_access_complete(scsi_cdrom_t *dev, const int ret) +{ + ui_sb_update_icon(SB_CDROM | dev->id, 0); + scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); + dev->packet_status = (ret < 0) ? PHASE_ERROR : PHASE_COMPLETE; + dev->callback = 20.0 * CDROM_TIME; + scsi_cdrom_set_callback(dev); +} + +static void +scsi_cdrom_read(scsi_common_t *sc) +{ + scsi_cdrom_t *dev = (scsi_cdrom_t *) sc; + const int osl = dev->sector_len; + const int ret = scsi_cdrom_read_blocks(dev); + + dev->drv->seek_diff = 0; + + if (ret > 0) { + if (osl > 0) + scsi_cdrom_set_period(dev); + + ui_sb_update_icon(SB_CDROM | dev->id, + (dev->packet_status != PHASE_COMPLETE)); + } else + scsi_cdrom_media_access_complete(dev, ret); +} + static uint8_t -scsi_cdrom_command_dec_sony_texel(void *sc, uint8_t *cdb, int32_t *BufLen) +scsi_cdrom_command_dec_sony_texel(void *sc, const uint8_t *cdb, int32_t *BufLen) { scsi_cdrom_t *dev = (scsi_cdrom_t *) sc; - int msf = 0; - int pos = dev->drv->seek_pos; int ret = 1; uint8_t cmd_stat = 0x00; + int msf; int len; int max_len; - int alloc_length; - int real_pos; switch (cdb[0]) { + default: + break; + case GPCMD_SET_ADDRESS_FORMAT_SONY: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - dev->sony_vendor = 1; dev->drv->sony_msf = cdb[8] & 1; scsi_cdrom_command_complete(dev); cmd_stat = 0x01; @@ -1898,8 +1599,9 @@ scsi_cdrom_command_dec_sony_texel(void *sc, uint8_t *cdb, int32_t *BufLen) case GPCMD_READ_TOC_SONY: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); - msf = dev->drv->sony_msf; - dev->sony_vendor = 1; + dev->was_cached = dev->toc_cached; + + msf = dev->drv->sony_msf; max_len = cdb[7]; max_len <<= 8; @@ -1907,15 +1609,17 @@ scsi_cdrom_command_dec_sony_texel(void *sc, uint8_t *cdb, int32_t *BufLen) scsi_cdrom_buf_alloc(dev, 65536); - if (!dev->drv->ops) + if (dev->drv->ops == NULL) scsi_cdrom_not_ready(dev); else { len = cdrom_read_toc_sony(dev->drv, dev->buffer, cdb[5], msf, max_len); if (len == -1) /* If the returned length is -1, this means cdrom_read_toc_sony() has encountered an error. */ - scsi_cdrom_invalid_field(dev); + scsi_cdrom_invalid_field(dev, dev->drv->inv_field); else { + scsi_cdrom_cache_toc(dev); + scsi_cdrom_set_buf_len(dev, BufLen, &len); scsi_cdrom_data_command_finish(dev, len, len, len, 0); } @@ -1925,27 +1629,28 @@ scsi_cdrom_command_dec_sony_texel(void *sc, uint8_t *cdb, int32_t *BufLen) case GPCMD_READ_SUBCHANNEL_SONY: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); - dev->sony_vendor = 1; + dev->was_cached = (dev->drv->cached_sector != -1); max_len = cdb[7]; max_len <<= 8; max_len |= cdb[8]; msf = dev->drv->sony_msf; - scsi_cdrom_log("CD-ROM %i: Getting sub-channel type (%s), code-q = %02x\n", - dev->id, msf ? "MSF" : "LBA", cdb[2] & 0x40); + scsi_cdrom_log(dev->log, "Getting sub-channel type (%s), code-q = %02x\n", + msf ? "MSF" : "LBA", cdb[2] & 0x40); if (cdb[2] & 0x40) { scsi_cdrom_buf_alloc(dev, 9); memset(dev->buffer, 0, 9); len = 9; cdrom_get_current_subchannel_sony(dev->drv, dev->buffer, msf); + scsi_cdrom_one_sector_seek(dev); len = MIN(len, max_len); scsi_cdrom_set_buf_len(dev, BufLen, &len); scsi_cdrom_data_command_finish(dev, len, len, len, 0); } else { scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - scsi_cdrom_log("CD-ROM %i: Drive Status All done - callback set\n", dev->id); + scsi_cdrom_log(dev->log, "Drive Status All done - callback set\n"); dev->packet_status = PHASE_COMPLETE; dev->callback = 20.0 * CDROM_TIME; scsi_cdrom_set_callback(dev); @@ -1955,31 +1660,60 @@ scsi_cdrom_command_dec_sony_texel(void *sc, uint8_t *cdb, int32_t *BufLen) case GPCMD_READ_HEADER_SONY: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); - dev->sony_vendor = 1; - alloc_length = ((cdb[7] << 8) | cdb[8]); - scsi_cdrom_buf_alloc(dev, 4); + len = (cdb[7] << 8) | cdb[8]; + dev->sector_len = 1; + dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | + (cdb[4] << 8) | cdb[5]; + dev->was_cached = (dev->drv->cached_sector == dev->sector_pos); + scsi_cdrom_log(dev->log, "READ HEADER SONY: Length: %i, LBA: %i\n", + dev->sector_len, dev->sector_pos); - dev->sector_len = 1; - dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; - real_pos = cdrom_lba_to_msf_accurate(dev->sector_pos); - dev->buffer[0] = ((real_pos >> 16) & 0xff); - dev->buffer[1] = ((real_pos >> 8) & 0xff); - dev->buffer[2] = real_pos & 0xff; - dev->buffer[3] = 1; /*2048 bytes user data*/ + if (len > 0) { + max_len = 1; + dev->requested_blocks = 1; - len = 4; - len = MIN(len, alloc_length); + dev->packet_len = len; + scsi_cdrom_buf_alloc(dev, 2352); - scsi_cdrom_set_buf_len(dev, BufLen, &len); + scsi_cdrom_one_sector_seek(dev); - scsi_cdrom_data_command_finish(dev, len, len, len, 0); + /* Any of these commands stop the audio playing. */ + cdrom_stop(dev->drv); + + dev->vendor_type = 0x00; + + dev->buffer_pos = 0x00000000; + + ret = scsi_cdrom_read_blocks(dev); + + if (ret > 0) { + len = MIN(4, len); + + scsi_cdrom_set_buf_len(dev, BufLen, &len); + + scsi_cdrom_data_command_finish(dev, len, len, + len, 0); + + ui_sb_update_icon(SB_CDROM | dev->id, 0); + } else { + scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); + dev->packet_status = (ret < 0) ? PHASE_ERROR : PHASE_COMPLETE; + dev->callback = 20.0 * CDROM_TIME; + scsi_cdrom_set_callback(dev); + } + } else { + scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); + /* scsi_cdrom_log(dev->log, "All done - callback set\n"); */ + dev->packet_status = PHASE_COMPLETE; + dev->callback = 20.0 * CDROM_TIME; + scsi_cdrom_set_callback(dev); + } cmd_stat = 0x01; break; case GPCMD_PLAYBACK_STATUS_SONY: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); - dev->sony_vendor = 1; max_len = cdb[7]; max_len <<= 8; @@ -1999,7 +1733,7 @@ scsi_cdrom_command_dec_sony_texel(void *sc, uint8_t *cdb, int32_t *BufLen) &dev->buffer[6], msf); dev->buffer[5] = 0x00; - scsi_cdrom_log("Audio Status = %02x\n", dev->buffer[4]); + scsi_cdrom_log(dev->log, "Audio Status = %02x\n", dev->buffer[4]); len = MIN(len, max_len); scsi_cdrom_set_buf_len(dev, BufLen, &len); @@ -2010,7 +1744,6 @@ scsi_cdrom_command_dec_sony_texel(void *sc, uint8_t *cdb, int32_t *BufLen) case GPCMD_PAUSE_SONY: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - dev->sony_vendor = 1; cdrom_audio_pause_resume(dev->drv, !(cdb[1] & 0x10)); scsi_cdrom_command_complete(dev); cmd_stat = 0x01; @@ -2018,19 +1751,23 @@ scsi_cdrom_command_dec_sony_texel(void *sc, uint8_t *cdb, int32_t *BufLen) case GPCMD_PLAY_TRACK_SONY: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - dev->sony_vendor = 1; msf = 3; if ((cdb[5] != 1) || (cdb[8] != 1)) scsi_cdrom_illegal_mode(dev); else { - pos = cdb[4]; + const int pos = cdb[4]; - if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DATA_ONLY)) + if ((dev->drv->image_path[0] == 0x00) || + (dev->drv->cd_status <= CD_STATUS_DVD)) scsi_cdrom_illegal_mode(dev); else { /* In this case, len is unused so just pass a fixed value of 1 intead. */ - ret = cdrom_audio_play(dev->drv, pos, 1 /*len*/, msf); + const int ret = cdrom_audio_play(dev->drv, pos, 1, msf); + dev->requested_blocks = 0; + + dev->drv->seek_diff = ABS(dev->sector_pos - dev->drv->seek_pos); + dev->sector_pos = dev->drv->seek_pos; if (ret) scsi_cdrom_command_complete(dev); @@ -2042,27 +1779,29 @@ scsi_cdrom_command_dec_sony_texel(void *sc, uint8_t *cdb, int32_t *BufLen) break; case GPCMD_PLAY_MSF_SONY: - cdb[0] = GPCMD_PLAY_AUDIO_MSF; - dev->current_cdb[0] = cdb[0]; - dev->sony_vendor = 1; - /* Keep cmd_stat at 0x00, therefore, it's going to process it as GPCMD_PLAY_AUDIO_MSF. */ + dev->current_cdb[0] = GPCMD_PLAY_AUDIO_MSF; + /* + Keep cmd_stat at 0x00, therefore, it's going to process it + as GPCMD_PLAY_AUDIO_MSF. + */ break; case GPCMD_PLAY_AUDIO_SONY: - cdb[0] = GPCMD_PLAY_AUDIO_10; - dev->current_cdb[0] = cdb[0]; - dev->sony_vendor = 1; - /* Keep cmd_stat at 0x00, therefore, it's going to process it as GPCMD_PLAY_AUDIO_10. */ + dev->current_cdb[0] = GPCMD_PLAY_AUDIO_10; + /* + Keep cmd_stat at 0x00, therefore, it's going to process it + as GPCMD_PLAY_AUDIO_10. + */ break; case GPCMD_PLAYBACK_CONTROL_SONY: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_OUT); - dev->sony_vendor = 1; len = (cdb[7] << 8) | cdb[8]; if (len == 0) { scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - scsi_cdrom_log("CD-ROM %i: PlayBack Control Sony All done - callback set\n", dev->id); + scsi_cdrom_log(dev->log, "PlayBack Control Sony All done - " + "callback set\n"); dev->packet_status = PHASE_COMPLETE; dev->callback = 20.0 * CDROM_TIME; scsi_cdrom_set_callback(dev); @@ -2072,6 +1811,7 @@ scsi_cdrom_command_dec_sony_texel(void *sc, uint8_t *cdb, int32_t *BufLen) scsi_cdrom_set_buf_len(dev, BufLen, &len); scsi_cdrom_data_command_finish(dev, len, len, len, 1); } + cmd_stat = 0x01; break; } @@ -2079,70 +1819,93 @@ scsi_cdrom_command_dec_sony_texel(void *sc, uint8_t *cdb, int32_t *BufLen) } static uint8_t -scsi_cdrom_command_matsushita(void *sc, uint8_t *cdb, int32_t *BufLen) +scsi_cdrom_command_matsushita(void *sc, const uint8_t *cdb, UNUSED(int32_t *BufLen)) { - scsi_cdrom_t *dev = (scsi_cdrom_t *) sc; - uint8_t cmd_stat = 0x00; + scsi_cdrom_t *dev = (scsi_cdrom_t *) sc; + const uint8_t cmd_stat = 0x00; switch (cdb[0]) { + default: + break; + case GPCMD_READ_SUBCHANNEL_MATSUSHITA: - cdb[0] = GPCMD_READ_SUBCHANNEL; - dev->current_cdb[0] = cdb[0]; - /* Keep cmd_stat at 0x00, therefore, it's going to process it as GPCMD_READ_SUBCHANNEL. */ + dev->current_cdb[0] = GPCMD_READ_SUBCHANNEL; + /* + Keep cmd_stat at 0x00, therefore, it's going to process it + as GPCMD_READ_SUBCHANNEL. + */ break; case GPCMD_READ_TOC_MATSUSHITA: - cdb[0] = GPCMD_READ_TOC_PMA_ATIP; - dev->current_cdb[0] = cdb[0]; - /* Keep cmd_stat at 0x00, therefore, it's going to process it as GPCMD_READ_TOC_PMA_ATIP. */ + dev->current_cdb[0] = GPCMD_READ_TOC_PMA_ATIP; + /* + Keep cmd_stat at 0x00, therefore, it's going to process it + as GPCMD_READ_TOC_PMA_ATIP. + */ break; case GPCMD_READ_HEADER_MATSUSHITA: - cdb[0] = GPCMD_READ_HEADER; - dev->current_cdb[0] = cdb[0]; - /* Keep cmd_stat at 0x00, therefore, it's going to process it as GPCMD_READ_HEADER. */ + dev->current_cdb[0] = GPCMD_READ_HEADER; + /* + Keep cmd_stat at 0x00, therefore, it's going to process it + as GPCMD_READ_HEADER. + */ break; case GPCMD_PLAY_AUDIO_MATSUSHITA: - cdb[0] = GPCMD_PLAY_AUDIO_10; - dev->current_cdb[0] = cdb[0]; - /* Keep cmd_stat at 0x00, therefore, it's going to process it as GPCMD_PLAY_AUDIO_10. */ + dev->current_cdb[0] = GPCMD_PLAY_AUDIO_10; + /* + Keep cmd_stat at 0x00, therefore, it's going to process it + as GPCMD_PLAY_AUDIO_10. + */ break; case GPCMD_PLAY_AUDIO_MSF_MATSUSHITA: - cdb[0] = GPCMD_PLAY_AUDIO_MSF; - dev->current_cdb[0] = cdb[0]; - /* Keep cmd_stat at 0x00, therefore, it's going to process it as GPCMD_PLAY_AUDIO_MSF. */ + dev->current_cdb[0] = GPCMD_PLAY_AUDIO_MSF; + /* + Keep cmd_stat at 0x00, therefore, it's going to process it + as GPCMD_PLAY_AUDIO_MSF. + */ break; case GPCMD_PLAY_AUDIO_TRACK_INDEX_MATSUSHITA: - cdb[0] = GPCMD_PLAY_AUDIO_TRACK_INDEX; - dev->current_cdb[0] = cdb[0]; - /* Keep cmd_stat at 0x00, therefore, it's going to process it as GPCMD_PLAY_AUDIO_TRACK_INDEX. */ + dev->current_cdb[0] = GPCMD_PLAY_AUDIO_TRACK_INDEX; + /* + Keep cmd_stat at 0x00, therefore, it's going to process it + as GPCMD_PLAY_AUDIO_TRACK_INDEX. + */ break; case GPCMD_PLAY_AUDIO_TRACK_RELATIVE_10_MATSUSHITA: - cdb[0] = GPCMD_PLAY_AUDIO_TRACK_RELATIVE_10; - dev->current_cdb[0] = cdb[0]; - /* Keep cmd_stat at 0x00, therefore, it's going to process it as GPCMD_PLAY_AUDIO_TRACK_RELATIVE_10. */ + dev->current_cdb[0] = GPCMD_PLAY_AUDIO_TRACK_RELATIVE_10; + /* + Keep cmd_stat at 0x00, therefore, it's going to process it + as GPCMD_PLAY_AUDIO_TRACK_RELATIVE_10. + */ break; case GPCMD_PAUSE_RESUME_MATSUSHITA: - cdb[0] = GPCMD_PAUSE_RESUME; - dev->current_cdb[0] = cdb[0]; - /* Keep cmd_stat at 0x00, therefore, it's going to process it as GPCMD_PAUSE_RESUME. */ + dev->current_cdb[0] = GPCMD_PAUSE_RESUME; + /* + Keep cmd_stat at 0x00, therefore, it's going to process it + as GPCMD_PAUSE_RESUME. + */ break; case GPCMD_PLAY_AUDIO_12_MATSUSHITA: - cdb[0] = GPCMD_PLAY_AUDIO_12; - dev->current_cdb[0] = cdb[0]; - /* Keep cmd_stat at 0x00, therefore, it's going to process it as GPCMD_PLAY_AUDIO_12. */ + dev->current_cdb[0] = GPCMD_PLAY_AUDIO_12; + /* + Keep cmd_stat at 0x00, therefore, it's going to process it + as GPCMD_PLAY_AUDIO_12. + */ break; case GPCMD_PLAY_AUDIO_TRACK_RELATIVE_12_MATSUSHITA: - cdb[0] = GPCMD_PLAY_AUDIO_TRACK_RELATIVE_12; - dev->current_cdb[0] = cdb[0]; - /* Keep cmd_stat at 0x00, therefore, it's going to process it as GPCMD_PLAY_AUDIO_TRACK_RELATIVE_12. */ + dev->current_cdb[0] = GPCMD_PLAY_AUDIO_TRACK_RELATIVE_12; + /* + Keep cmd_stat at 0x00, therefore, it's going to process it + as GPCMD_PLAY_AUDIO_TRACK_RELATIVE_12. + */ break; } @@ -2150,16 +1913,19 @@ scsi_cdrom_command_matsushita(void *sc, uint8_t *cdb, int32_t *BufLen) } static uint8_t -scsi_cdrom_command_nec(void *sc, uint8_t *cdb, int32_t *BufLen) +scsi_cdrom_command_nec(void *sc, const uint8_t *cdb, int32_t *BufLen) { scsi_cdrom_t *dev = (scsi_cdrom_t *) sc; - int pos = dev->drv->seek_pos; - int ret = 1; uint8_t cmd_stat = 0x00; + int pos; + int ret; int len; int alloc_length; switch (cdb[0]) { + default: + break; + case GPCMD_NO_OPERATION_NEC: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); scsi_cdrom_command_complete(dev); @@ -2174,12 +1940,16 @@ scsi_cdrom_command_nec(void *sc, uint8_t *cdb, int32_t *BufLen) case GPCMD_AUDIO_TRACK_SEARCH_NEC: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DATA_ONLY)) + dev->was_cached = 0; + + if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DVD)) scsi_cdrom_illegal_mode(dev); else { - pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; - ret = cdrom_audio_track_search(dev->drv, pos, cdb[9] & 0xc0, cdb[1] & 1); - dev->drv->audio_op = (cdb[1] & 1) ? 0x03 : 0x02; + pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; + ret = cdrom_audio_track_search(dev->drv, pos, cdb[9] & 0xc0, cdb[1] & 1); + + dev->drv->seek_diff = ABS(dev->sector_pos - dev->drv->seek_pos); + dev->sector_pos = dev->drv->seek_pos; if (ret) scsi_cdrom_command_complete(dev); @@ -2191,7 +1961,7 @@ scsi_cdrom_command_nec(void *sc, uint8_t *cdb, int32_t *BufLen) case GPCMD_PLAY_AUDIO_NEC: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DATA_ONLY)) + if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DVD)) ret = 0; else { pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; @@ -2209,7 +1979,6 @@ scsi_cdrom_command_nec(void *sc, uint8_t *cdb, int32_t *BufLen) case GPCMD_STILL_NEC: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); cdrom_audio_pause_resume(dev->drv, 0x00); - dev->drv->audio_op = 0x01; scsi_cdrom_command_complete(dev); cmd_stat = 0x01; break; @@ -2224,21 +1993,23 @@ scsi_cdrom_command_nec(void *sc, uint8_t *cdb, int32_t *BufLen) scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); scsi_cdrom_stop(sc); cdrom_eject(dev->id); + dev->toc_cached = 0; scsi_cdrom_command_complete(dev); cmd_stat = 0x01; break; case GPCMD_READ_SUBCODEQ_PLAYING_STATUS_NEC: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); + dev->was_cached = (dev->drv->cached_sector == -1); alloc_length = cdb[1] & 0x1f; len = 10; - if (!dev->drv->ops) + if (dev->drv->ops == NULL) scsi_cdrom_not_ready(dev); else if (alloc_length <= 0) { scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - scsi_cdrom_log("CD-ROM %i: Subcode Q All done - callback set\n", dev->id); + scsi_cdrom_log(dev->log, "Subcode Q All done - callback set\n"); dev->packet_status = PHASE_COMPLETE; dev->callback = 20.0 * CDROM_TIME; scsi_cdrom_set_callback(dev); @@ -2248,7 +2019,7 @@ scsi_cdrom_command_nec(void *sc, uint8_t *cdb, int32_t *BufLen) memset(dev->buffer, 0, len); dev->buffer[0] = cdrom_get_current_subcodeq_playstatus(dev->drv, &dev->buffer[1]); - scsi_cdrom_log("Audio Status = %02x\n", dev->buffer[0]); + scsi_cdrom_log(dev->log, "Audio Status = %02x\n", dev->buffer[0]); scsi_cdrom_set_buf_len(dev, BufLen, &alloc_length); scsi_cdrom_data_command_finish(dev, len, len, len, 0); @@ -2258,23 +2029,24 @@ scsi_cdrom_command_nec(void *sc, uint8_t *cdb, int32_t *BufLen) case GPCMD_READ_DISC_INFORMATION_NEC: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); + dev->was_cached = dev->toc_cached; + /* NEC manual claims 4 bytes but the Linux kernel (namely sr_vendor.c) actually states otherwise. */ scsi_cdrom_buf_alloc(dev, 22); - if (!dev->drv->ops) - scsi_cdrom_not_ready(dev); - else { - ret = cdrom_read_disc_info_toc(dev->drv, dev->buffer, cdb[2], cdb[1] & 3); - len = 22; - if (ret) { - scsi_cdrom_set_buf_len(dev, BufLen, &len); - scsi_cdrom_data_command_finish(dev, len, len, len, 0); - } else - scsi_cdrom_invalid_field(dev); - } + ret = cdrom_read_disc_info_toc(dev->drv, dev->buffer, cdb[2], cdb[1] & 3); + len = 22; + if (ret) { + scsi_cdrom_cache_toc(dev); + + scsi_cdrom_set_buf_len(dev, BufLen, &len); + scsi_cdrom_data_command_finish(dev, len, len, len, 0); + } else + scsi_cdrom_invalid_field(dev, dev->drv->inv_field); + cmd_stat = 0x01; break; } @@ -2283,55 +2055,64 @@ scsi_cdrom_command_nec(void *sc, uint8_t *cdb, int32_t *BufLen) } static uint8_t -scsi_cdrom_command_pioneer(void *sc, uint8_t *cdb, int32_t *BufLen) +scsi_cdrom_command_pioneer(void *sc, const uint8_t *cdb, int32_t *BufLen) { scsi_cdrom_t *dev = (scsi_cdrom_t *) sc; - int pos = dev->drv->seek_pos; - int ret = 1; uint8_t cmd_stat = 0x00; + int pos; + int ret; int len; int max_len; int alloc_length; switch (cdb[0]) { + default: + break; + case GPCMD_MAGAZINE_EJECT_PIONEER: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); scsi_cdrom_stop(sc); cdrom_eject(dev->id); + dev->toc_cached = 0; scsi_cdrom_command_complete(dev); cmd_stat = 0x01; break; case GPCMD_READ_TOC_PIONEER: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); + dev->was_cached = dev->toc_cached; + scsi_cdrom_buf_alloc(dev, 4); - if (!dev->drv->ops) + if (dev->drv->ops == NULL) scsi_cdrom_not_ready(dev); else { ret = cdrom_read_disc_info_toc(dev->drv, dev->buffer, cdb[2], cdb[1] & 3); len = 4; if (ret) { + scsi_cdrom_cache_toc(dev); + scsi_cdrom_set_buf_len(dev, BufLen, &len); scsi_cdrom_data_command_finish(dev, len, len, len, 0); } else - scsi_cdrom_invalid_field(dev); + scsi_cdrom_invalid_field(dev, dev->drv->inv_field); } cmd_stat = 0x01; break; case GPCMD_READ_SUBCODEQ_PIONEER: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); + dev->was_cached = (dev->drv->cached_sector != -1); alloc_length = cdb[1] & 0x1f; len = 9; - if (!dev->drv->ops) + if (dev->drv->ops == NULL) scsi_cdrom_not_ready(dev); else if (!alloc_length) { scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - scsi_cdrom_log("CD-ROM %i: Subcode Q All done - callback set\n", dev->id); + scsi_cdrom_log(dev->log, "Subcode Q All done - callback set\n"); dev->packet_status = PHASE_COMPLETE; dev->callback = 20.0 * CDROM_TIME; scsi_cdrom_set_callback(dev); @@ -2341,7 +2122,8 @@ scsi_cdrom_command_pioneer(void *sc, uint8_t *cdb, int32_t *BufLen) memset(dev->buffer, 0, len); cdrom_get_current_subcodeq(dev->drv, &dev->buffer[1]); - scsi_cdrom_log("Audio Status = %02x\n", dev->buffer[0]); + scsi_cdrom_one_sector_seek(dev); + scsi_cdrom_log(dev->log, "Audio Status = %02x\n", dev->buffer[0]); scsi_cdrom_set_buf_len(dev, BufLen, &alloc_length); scsi_cdrom_data_command_finish(dev, len, len, len, 0); @@ -2351,15 +2133,18 @@ scsi_cdrom_command_pioneer(void *sc, uint8_t *cdb, int32_t *BufLen) case GPCMD_AUDIO_TRACK_SEARCH_PIONEER: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DATA_ONLY)) + dev->was_cached = 0; + + if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DVD)) ret = 0; else { pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; ret = cdrom_audio_track_search_pioneer(dev->drv, pos, cdb[1] & 1); - - dev->drv->audio_op = (cdb[1] & 1) ? 0x03 : 0x02; } + dev->drv->seek_diff = ABS(dev->sector_pos - dev->drv->seek_pos); + dev->sector_pos = dev->drv->seek_pos; + if (ret) scsi_cdrom_command_complete(dev); else @@ -2370,7 +2155,7 @@ scsi_cdrom_command_pioneer(void *sc, uint8_t *cdb, int32_t *BufLen) case GPCMD_PLAY_AUDIO_PIONEER: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DATA_ONLY)) + if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DVD)) ret = 0; else { pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; @@ -2412,7 +2197,7 @@ scsi_cdrom_command_pioneer(void *sc, uint8_t *cdb, int32_t *BufLen) memset(dev->buffer, 0, 6); dev->buffer[0] = cdrom_get_audio_status_pioneer(dev->drv, &dev->buffer[1]); /*Audio status*/ - scsi_cdrom_log("Audio Status = %02x\n", dev->buffer[4]); + scsi_cdrom_log(dev->log, "Audio Status = %02x\n", dev->buffer[4]); len = MIN(len, max_len); scsi_cdrom_set_buf_len(dev, BufLen, &len); @@ -2428,10 +2213,10 @@ scsi_cdrom_command_pioneer(void *sc, uint8_t *cdb, int32_t *BufLen) scsi_cdrom_buf_alloc(dev, 65536); if (!(scsi_cdrom_drive_status_page_flags & (1LL << (uint64_t) (cdb[2] & 0x3f)))) - scsi_cdrom_invalid_field(dev); + scsi_cdrom_invalid_field(dev, cdb[2]); else if (len <= 0) { scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - scsi_cdrom_log("CD-ROM %i: Drive Status All done - callback set\n", dev->id); + scsi_cdrom_log(dev->log, "Drive Status All done - callback set\n"); dev->packet_status = PHASE_COMPLETE; dev->callback = 20.0 * CDROM_TIME; scsi_cdrom_set_callback(dev); @@ -2439,12 +2224,13 @@ scsi_cdrom_command_pioneer(void *sc, uint8_t *cdb, int32_t *BufLen) memset(dev->buffer, 0, len); alloc_length = len; - len = scsi_cdrom_drive_status(dev, dev->buffer, 0, cdb[2]); + len = scsi_cdrom_drive_status(dev, dev->buffer, cdb[2]); len = MIN(len, alloc_length); scsi_cdrom_set_buf_len(dev, BufLen, &len); - scsi_cdrom_log("CD-ROM %i: Reading drive status page: %02X...\n", dev->id, cdb[2]); + scsi_cdrom_log(dev->log, "Reading drive status page: %02X...\n", + cdb[2]); scsi_cdrom_data_command_finish(dev, len, len, alloc_length, 0); } @@ -2456,16 +2242,19 @@ scsi_cdrom_command_pioneer(void *sc, uint8_t *cdb, int32_t *BufLen) } static uint8_t -scsi_cdrom_command_toshiba(void *sc, uint8_t *cdb, int32_t *BufLen) +scsi_cdrom_command_toshiba(void *sc, const uint8_t *cdb, int32_t *BufLen) { scsi_cdrom_t *dev = (scsi_cdrom_t *) sc; - int pos = dev->drv->seek_pos; - int ret = 1; uint8_t cmd_stat = 0x00; + int pos; + int ret; int len; int alloc_length; switch (cdb[0]) { + default: + break; + case GPCMD_NO_OPERATION_TOSHIBA: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); scsi_cdrom_command_complete(dev); @@ -2474,13 +2263,17 @@ scsi_cdrom_command_toshiba(void *sc, uint8_t *cdb, int32_t *BufLen) case GPCMD_AUDIO_TRACK_SEARCH_TOSHIBA: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DATA_ONLY)) { + dev->was_cached = 0; + + if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DVD)) { scsi_cdrom_illegal_mode(dev); break; } - pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; - ret = cdrom_audio_track_search(dev->drv, pos, cdb[9] & 0xc0, cdb[1] & 1); - dev->drv->audio_op = (cdb[1] & 1) ? 0x03 : 0x02; + pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; + ret = cdrom_audio_track_search(dev->drv, pos, cdb[9] & 0xc0, cdb[1] & 1); + + dev->drv->seek_diff = ABS(dev->sector_pos - dev->drv->seek_pos); + dev->sector_pos = dev->drv->seek_pos; if (ret) scsi_cdrom_command_complete(dev); @@ -2492,7 +2285,7 @@ scsi_cdrom_command_toshiba(void *sc, uint8_t *cdb, int32_t *BufLen) case GPCMD_PLAY_AUDIO_TOSHIBA: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DATA_ONLY)) + if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DVD)) scsi_cdrom_illegal_mode(dev); else { pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; @@ -2509,7 +2302,6 @@ scsi_cdrom_command_toshiba(void *sc, uint8_t *cdb, int32_t *BufLen) case GPCMD_STILL_TOSHIBA: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); cdrom_audio_pause_resume(dev->drv, 0x00); - dev->drv->audio_op = 0x01; scsi_cdrom_command_complete(dev); cmd_stat = 0x01; break; @@ -2524,21 +2316,23 @@ scsi_cdrom_command_toshiba(void *sc, uint8_t *cdb, int32_t *BufLen) scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); scsi_cdrom_stop(sc); cdrom_eject(dev->id); + dev->toc_cached = 0; scsi_cdrom_command_complete(dev); cmd_stat = 0x01; break; case GPCMD_READ_SUBCODEQ_PLAYING_STATUS_TOSHIBA: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); + dev->was_cached = (dev->drv->cached_sector != -1); alloc_length = cdb[1] & 0x1f; len = 10; - if (!dev->drv->ops) + if (dev->drv->ops == NULL) scsi_cdrom_not_ready(dev); else if (alloc_length <= 0) { scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - scsi_cdrom_log("CD-ROM %i: Subcode Q All done - callback set\n", dev->id); + scsi_cdrom_log(dev->log, "Subcode Q All done - callback set\n"); dev->packet_status = PHASE_COMPLETE; dev->callback = 20.0 * CDROM_TIME; scsi_cdrom_set_callback(dev); @@ -2548,7 +2342,8 @@ scsi_cdrom_command_toshiba(void *sc, uint8_t *cdb, int32_t *BufLen) memset(dev->buffer, 0, len); dev->buffer[0] = cdrom_get_current_subcodeq_playstatus(dev->drv, &dev->buffer[1]); - scsi_cdrom_log("Audio Status = %02x\n", dev->buffer[0]); + scsi_cdrom_one_sector_seek(dev); + scsi_cdrom_log(dev->log, "Audio Status = %02x\n", dev->buffer[0]); scsi_cdrom_set_buf_len(dev, BufLen, &alloc_length); scsi_cdrom_data_command_finish(dev, len, len, len, 0); @@ -2558,43 +2353,63 @@ scsi_cdrom_command_toshiba(void *sc, uint8_t *cdb, int32_t *BufLen) case GPCMD_READ_DISC_INFORMATION_TOSHIBA: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); + dev->was_cached = dev->toc_cached; + scsi_cdrom_buf_alloc(dev, 4); - if (!dev->drv->ops) + if (dev->drv->ops == NULL) scsi_cdrom_not_ready(dev); else { ret = cdrom_read_disc_info_toc(dev->drv, dev->buffer, cdb[2], cdb[1] & 3); len = 4; if (ret) { + scsi_cdrom_cache_toc(dev); + scsi_cdrom_set_buf_len(dev, BufLen, &len); scsi_cdrom_data_command_finish(dev, len, len, len, 0); } else - scsi_cdrom_invalid_field(dev); + scsi_cdrom_invalid_field(dev, dev->drv->inv_field); } cmd_stat = 0x01; break; + + case GPCMD_READ_CDROM_MODE_TOSHIBA: + scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); + dev->was_cached = (dev->drv->cached_sector != -1); + + scsi_cdrom_buf_alloc(dev, 1); + + alloc_length = 1; + + len = alloc_length; + dev->buffer[0] = cdrom_get_current_mode(dev->drv); + + scsi_cdrom_one_sector_seek(dev); + + scsi_cdrom_set_buf_len(dev, BufLen, &len); + scsi_cdrom_data_command_finish(dev, len, len, len, 0); + + cmd_stat = 0x01; + break; } return cmd_stat; } void -scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) +scsi_cdrom_command(scsi_common_t *sc, const uint8_t *cdb) { scsi_cdrom_t *dev = (scsi_cdrom_t *) sc; - int msf = 0; int pos = dev->drv->seek_pos; int idx = 0; - int block_desc = 0; int ret = 1; - int format = 0; - 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; uint32_t profiles[2] = { MMC_PROFILE_CD_ROM, MMC_PROFILE_DVD_ROM }; uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; + char model[2048] = { 0 }; + int msf; + int block_desc; int len; int max_len; int used_len; @@ -2603,9 +2418,10 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) uint32_t feature; unsigned preamble_len; int toc_format; - int real_pos; int32_t *BufLen; - uint8_t *b; + + dev->was_cached = -1; + dev->sectors_num = 1; if (dev->drv->bus_type == CDROM_BUS_SCSI) { BufLen = &scsi_devices[scsi_bus][scsi_id].buffer_length; @@ -2618,33 +2434,32 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) dev->packet_len = 0; dev->request_pos = 0; - device_identify[7] = dev->id + 0x30; - - device_identify_ex[7] = dev->id + 0x30; - device_identify_ex[10] = EMU_VERSION_EX[0]; - device_identify_ex[12] = EMU_VERSION_EX[2]; - device_identify_ex[13] = EMU_VERSION_EX[3]; + dev->block_len = 0; memcpy(dev->current_cdb, cdb, 12); - dev->sony_vendor = 0; - // if (cdb[0] != 0) { - scsi_cdrom_log("CD-ROM %i: Command 0x%02X, Sense Key %02X, Asc %02X, Ascq %02X, Unit attention: %i\n", - dev->id, cdb[0], scsi_cdrom_sense_key, scsi_cdrom_asc, scsi_cdrom_ascq, - dev->unit_attention); - scsi_cdrom_log("CD-ROM %i: Request length: %04X\n", dev->id, dev->tf->request_length); +#if ENABLE_SCSI_CDROM_LOG == 2 + scsi_cdrom_log(dev->log, "Command 0x%02X, Sense Key %02X, Asc %02X, Ascq %02X, " + "Unit attention: %i\n", cdb[0], scsi_cdrom_sense_key, scsi_cdrom_asc, + scsi_cdrom_ascq, dev->unit_attention); + scsi_cdrom_log(dev->log, "Request length: %04X\n", dev->tf->request_length); - scsi_cdrom_log("CD-ROM %i: CDB: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n", - dev->id, cdb[0], cdb[1], cdb[2], cdb[3], cdb[4], cdb[5], cdb[6], cdb[7], + scsi_cdrom_log(dev->log, "CDB: %02X %02X %02X %02X %02X %02X %02X " + "%02X %02X %02X %02X %02X\n", + cdb[0], cdb[1], cdb[2], cdb[3], cdb[4], cdb[5], cdb[6], cdb[7], cdb[8], cdb[9], cdb[10], cdb[11]); - // } +#endif - msf = cdb[1] & 2; - dev->sector_len = 0; + msf = cdb[1] & 2; + dev->sector_len = 0; + dev->requested_blocks = 0; scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - /* This handles the Not Ready/Unit Attention check if it has to be handled at this point. */ + /* + This handles the Not Ready/Unit Attention check if it has to be + handled at this point. + */ if (scsi_cdrom_pre_execution_check(dev, cdb) == 0) return; @@ -2653,23 +2468,25 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) scsi_cdrom_sense_clear(dev, cdb[0]); } - if ((dev->ven_cmd == NULL) || (dev->ven_cmd(sc, cdb, BufLen) == 0x00)) switch (cdb[0]) { + if ((dev->ven_cmd == NULL) || + (dev->ven_cmd(sc, cdb, BufLen) == 0x00)) switch (dev->current_cdb[0]) { case GPCMD_TEST_UNIT_READY: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); scsi_cdrom_command_complete(dev); break; case GPCMD_REZERO_UNIT: + dev->was_cached = 0; scsi_cdrom_stop(sc); - dev->sector_pos = dev->sector_len = 0; + dev->requested_blocks = 0; dev->drv->seek_diff = dev->drv->seek_pos; cdrom_seek(dev->drv, 0, 0); + dev->sector_pos = dev->drv->seek_pos; + dev->drv->cached_sector = -1; scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); break; case GPCMD_REQUEST_SENSE: - /* If there's a unit attention condition and there's a buffered not ready, a standalone REQUEST SENSE - should forget about the not ready, and report unit attention straight away. */ scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); max_len = cdb[4]; @@ -2694,14 +2511,19 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) case GPCMD_SCAN_PIONEER: case GPCMD_AUDIO_SCAN: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); + dev->was_cached = 0; - if ((dev->drv->image_path[0] == 0x00) || (dev->drv->cd_status <= CD_STATUS_DATA_ONLY)) { + if ((dev->drv->image_path[0] == 0x00) || + (dev->drv->cd_status <= CD_STATUS_DVD)) { scsi_cdrom_illegal_mode(dev); break; } pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; - ret = cdrom_audio_scan(dev->drv, pos, 0); + ret = cdrom_audio_scan(dev->drv, pos); + + dev->drv->seek_diff = ABS(dev->sector_pos - dev->drv->seek_pos); + dev->sector_pos = dev->drv->seek_pos; if (ret) scsi_cdrom_command_complete(dev); @@ -2725,6 +2547,7 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) case GPCMD_READ_TOC_PMA_ATIP: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); + dev->was_cached = dev->toc_cached; max_len = cdb[7]; max_len <<= 8; @@ -2737,24 +2560,33 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) if (toc_format == 0) toc_format = (cdb[9] >> 6) & 3; - if (!dev->drv->ops) { + if (dev->drv->ops == NULL) scsi_cdrom_not_ready(dev); - return; - } - - if (toc_format < 3) { + else if (toc_format < 3) { len = cdrom_read_toc(dev->drv, dev->buffer, toc_format, cdb[6], msf, max_len); /* If the returned length is -1, this means cdrom_read_toc() has encountered an error. */ if (len == -1) - scsi_cdrom_invalid_field(dev); + scsi_cdrom_invalid_field(dev, dev->drv->inv_field); else { + scsi_cdrom_cache_toc(dev); + scsi_cdrom_set_buf_len(dev, BufLen, &len); scsi_cdrom_data_command_finish(dev, len, len, len, 0); } } else - scsi_cdrom_invalid_field(dev); + scsi_cdrom_invalid_field(dev, toc_format); break; + case GPCMD_PLAY_CD: + /* + According to the ATAPI specification, this was actually READ CD + on early drives. + */ + if (!dev->drv->is_early) { + scsi_cdrom_illegal_opcode(dev, dev->current_cdb[0]); + break; + } + fallthrough; case GPCMD_READ_6: case GPCMD_READ_10: case GPCMD_READ_12: @@ -2763,37 +2595,63 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) case GPCMD_READ_CD: case GPCMD_READ_CD_MSF: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); - alloc_length = 2048; + dev->was_cached = 0; - switch (cdb[0]) { + alloc_length = dev->drv->sector_size; + + switch (dev->current_cdb[0]) { case GPCMD_READ_6: dev->sector_len = cdb[4]; - /* For READ (6) and WRITE (6), a length of 0 indicates a transfer of 256 sectors. */ + /* + For READ (6) and WRITE (6), a length of 0 indicates a transfer of + 256 sectors. + */ if (dev->sector_len == 0) dev->sector_len = 256; - dev->sector_pos = ((((uint32_t) cdb[1]) & 0x1f) << 16) | (((uint32_t) cdb[2]) << 8) | - ((uint32_t) cdb[3]); - scsi_cdrom_log("CD-ROM %i: READ (6): Length: %i, LBA: %i\n", dev->id, dev->sector_len, - dev->sector_pos); + dev->sector_pos = ((((uint32_t) cdb[1]) & 0x1f) << 16) | + (((uint32_t) cdb[2]) << 8) | ((uint32_t) cdb[3]); + if (cdrom_is_track_audio(dev->drv, dev->sector_pos, msf, + dev->sector_type, 0x00)) { + scsi_cdrom_illegal_mode(dev); + ret = 0; + } + scsi_cdrom_log(dev->log, "READ (6): Length: %i, LBA: %i\n", + dev->sector_len, dev->sector_pos); break; case GPCMD_READ_10: dev->sector_len = (cdb[7] << 8) | cdb[8]; - dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; - scsi_cdrom_log("CD-ROM %i: READ (10): Length: %i, LBA: %i\n", dev->id, dev->sector_len, - dev->sector_pos); + dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | + (cdb[4] << 8) | cdb[5]; + if (cdrom_is_track_audio(dev->drv, dev->sector_pos, msf, + dev->sector_type, dev->use_cdb_9 ? + (cdb[9] & 0xc0) : 0x00)) { + scsi_cdrom_illegal_mode(dev); + ret = 0; + } + scsi_cdrom_log(dev->log, "READ (10): Length: %i, LBA: %i\n", + dev->sector_len, dev->sector_pos); break; case GPCMD_READ_12: - dev->sector_len = (((uint32_t) cdb[6]) << 24) | (((uint32_t) cdb[7]) << 16) | + 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) | + dev->sector_pos = (((uint32_t) cdb[2]) << 24) | + (((uint32_t) cdb[3]) << 16) | (((uint32_t) cdb[4]) << 8) | ((uint32_t) cdb[5]); - scsi_cdrom_log("CD-ROM %i: READ (12): Length: %i, LBA: %i\n", dev->id, dev->sector_len, - dev->sector_pos); + if (cdrom_is_track_audio(dev->drv, dev->sector_pos, msf, + dev->sector_type, dev->use_cdb_9 ? + (cdb[9] & 0xc0) : 0x00)) { + scsi_cdrom_illegal_mode(dev); + ret = 0; + } + scsi_cdrom_log(dev->log, "READ (12): Length: %i, LBA: %i\n", + dev->sector_len, dev->sector_pos); break; case GPCMD_READ_CD_MSF_OLD: case GPCMD_READ_CD_MSF: msf = 1; fallthrough; + case GPCMD_PLAY_CD: case GPCMD_READ_CD_OLD: case GPCMD_READ_CD: alloc_length = 2856; @@ -2806,15 +2664,20 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) dev->sector_len++; } else { dev->sector_len = (cdb[6] << 16) | (cdb[7] << 8) | cdb[8]; - dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; + dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | + (cdb[4] << 8) | cdb[5]; } - if (((cdb[9] & 0xf8) == 0x08) || ((cdb[9] == 0x00) && ((cdb[10] & 0x07) != 0x00))) { + if (((cdb[9] & 0xf8) == 0x08) || ((cdb[9] == 0x00) && + ((cdb[10] & 0x07) != 0x00))) { /* Illegal mode */ - scsi_cdrom_invalid_field(dev); + scsi_cdrom_invalid_field(dev, cdb[9]); ret = 0; } else if ((cdb[9] == 0x00) && ((cdb[10] & 0x07) == 0x00)) - /* If all the flag bits are cleared, then treat it as a non-data command. */ + /* + If all the flag bits are cleared, then treat it as a + non-data command. + */ dev->sector_len = 0; break; @@ -2825,39 +2688,38 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) if (ret) { if (dev->sector_len > 0) { max_len = dev->sector_len; - dev->requested_blocks = max_len; /* - If we're reading all blocks in one go for DMA, - why not also for PIO, it should NOT matter - anyway, this step should be identical and only - the way the read dat is transferred to the host - should be different. - */ + dev->requested_blocks = max_len; dev->packet_len = max_len * alloc_length; scsi_cdrom_buf_alloc(dev, dev->packet_len); dev->drv->seek_diff = ABS((int) (pos - dev->sector_pos)); + dev->drv->seek_pos = dev->sector_pos; - if ((cdb[0] == GPCMD_READ_10) || (cdb[0] == GPCMD_READ_12)) { - switch (dev->drv->type) { - case CDROM_TYPE_NEC_25_10a ... CDROM_TYPE_NEC_464_105: - case CDROM_TYPE_TOSHIBA_XM_3433 ... CDROM_TYPE_TOSHIBA_SDM1401_1008: - ret = scsi_cdrom_read_blocks(dev, &alloc_length, 1, cdb[9] & 0xc0); - break; - default: - ret = scsi_cdrom_read_blocks(dev, &alloc_length, 1, 0); - break; - } - } else - ret = scsi_cdrom_read_blocks(dev, &alloc_length, 1, 0); + /* Any of these commands stop the audio playing. */ + cdrom_stop(dev->drv); + + if (dev->use_cdb_9 && + ((dev->current_cdb[0] == GPCMD_READ_10) || + (dev->current_cdb[0] == GPCMD_READ_12))) + dev->vendor_type = cdb[9] & 0xc0; + else + dev->vendor_type = 0x00; + + dev->block_len = 0xffffffff; + dev->buffer_pos = 0x00000000; + + ret = scsi_cdrom_read_blocks(dev); + alloc_length = dev->requested_blocks * dev->block_len; if (ret > 0) { - dev->requested_blocks = max_len; dev->packet_len = alloc_length; - scsi_cdrom_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); + scsi_cdrom_set_buf_len(dev, BufLen, + (int32_t *) &dev->packet_len); - scsi_cdrom_data_command_finish(dev, alloc_length, alloc_length / dev->requested_blocks, + scsi_cdrom_data_command_finish(dev, alloc_length, + dev->block_len, alloc_length, 0); if (dev->packet_status != PHASE_COMPLETE) @@ -2872,7 +2734,7 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) } } else { scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - /* scsi_cdrom_log("CD-ROM %i: All done - callback set\n", dev->id); */ + /* scsi_cdrom_log(dev->log, "All done - callback set\n"); */ dev->packet_status = PHASE_COMPLETE; dev->callback = 20.0 * CDROM_TIME; scsi_cdrom_set_callback(dev); @@ -2883,40 +2745,89 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) case GPCMD_READ_HEADER: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); - alloc_length = ((cdb[7] << 8) | cdb[8]); - scsi_cdrom_buf_alloc(dev, 8); + alloc_length = 2352; - dev->sector_len = 1; - dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; - if (msf) - real_pos = cdrom_lba_to_msf_accurate(dev->sector_pos); - else - real_pos = dev->sector_pos; - dev->buffer[0] = 1; /*2048 bytes user data*/ - dev->buffer[1] = dev->buffer[2] = dev->buffer[3] = 0; - dev->buffer[4] = (real_pos >> 24); - dev->buffer[5] = ((real_pos >> 16) & 0xff); - dev->buffer[6] = ((real_pos >> 8) & 0xff); - dev->buffer[7] = real_pos & 0xff; + len = (cdb[7] << 8) | cdb[8]; + dev->sector_len = 1; + dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | + (cdb[4] << 8) | cdb[5]; + dev->was_cached = (dev->drv->cached_sector == dev->sector_pos); + scsi_cdrom_log(dev->log, "READ HEADER: Length: %i, LBA: %i\n", + dev->sector_len, dev->sector_pos); - len = 8; - len = MIN(len, alloc_length); + if (len > 0) { + max_len = 1; + dev->requested_blocks = max_len; - scsi_cdrom_set_buf_len(dev, BufLen, &len); + dev->packet_len = len; + scsi_cdrom_buf_alloc(dev, 2352); - scsi_cdrom_data_command_finish(dev, len, len, len, 0); + scsi_cdrom_one_sector_seek(dev); + + /* Any of these commands stop the audio playing. */ + cdrom_stop(dev->drv); + + dev->vendor_type = 0x00; + + dev->buffer_pos = 0x00000000; + ret = scsi_cdrom_read_blocks(dev); + + if (ret > 0) { + uint8_t header[4] = { 0 }; + + memcpy(header, dev->buffer, 4); + + dev->buffer[0] = header[3]; + + if (cdb[1] & 0x02) { + memset(&(dev->buffer[1]), 0x00, 4); + dev->buffer[5] = header[0]; + dev->buffer[6] = header[1]; + dev->buffer[7] = header[2]; + } else { + memset(&(dev->buffer[1]), 0x00, 3); + uint32_t lba = ((header[0] * 60 * 75) + + (header[1] * 75) + + header[2]) - 150; + dev->buffer[4] = (lba >> 24) & 0xff; + dev->buffer[5] = (lba >> 16) & 0xff; + dev->buffer[6] = (lba >> 8) & 0xff; + dev->buffer[7] = lba & 0xff; + } + + len = MIN(8, len); + + scsi_cdrom_set_buf_len(dev, BufLen, &len); + + scsi_cdrom_data_command_finish(dev, len, len, + len, 0); + + ui_sb_update_icon(SB_CDROM | dev->id, 0); + } else { + scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); + dev->packet_status = (ret < 0) ? PHASE_ERROR : PHASE_COMPLETE; + dev->callback = 20.0 * CDROM_TIME; + scsi_cdrom_set_callback(dev); + } + } else { + scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); + /* scsi_cdrom_log(dev->log, "All done - callback set\n"); */ + dev->packet_status = PHASE_COMPLETE; + dev->callback = 20.0 * CDROM_TIME; + scsi_cdrom_set_callback(dev); + } break; case GPCMD_MODE_SENSE_6: case GPCMD_MODE_SENSE_10: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); - if (dev->drv->bus_type == CDROM_BUS_SCSI) - block_desc = ((cdb[1] >> 3) & 1) ? 0 : 1; - else + if (dev->drv->bus_type == CDROM_BUS_ATAPI) block_desc = 0; + else + block_desc = !((cdb[1] >> 3) & 1); - if (cdb[0] == GPCMD_MODE_SENSE_6) { + if (dev->current_cdb[0] == GPCMD_MODE_SENSE_6) { len = cdb[4]; scsi_cdrom_buf_alloc(dev, 256); } else { @@ -2924,39 +2835,30 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) scsi_cdrom_buf_alloc(dev, 65536); } - switch (dev->drv->type) { - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - if (!(scsi_cdrom_mode_sense_page_flags_sony & (1LL << (uint64_t) (cdb[2] & 0x3f)))) - ret = 0; - break; - default: - if (!(scsi_cdrom_mode_sense_page_flags & (1LL << (uint64_t) (cdb[2] & 0x3f)))) - ret = 0; - break; - } + if (!(dev->ms_page_flags & (1LL << (uint64_t) (cdb[2] & 0x3f)))) + ret = 0; if (ret == 1) { memset(dev->buffer, 0, len); alloc_length = len; - /* This determines the media type ID to return - this is - a SCSI/ATAPI-specific thing, so it makes the most sense - to keep this here. - Also, the max_len variable is reused as this command - does otherwise not use it, to avoid having to declare - another variable. */ + /* + This determines the media type ID to return which is a SCSI/ATAPI-specific + thing, so it makes the most sense to keep this here. + + Also, the max_len variable is reused as this command does otherwise not + use it, to avoid having to declare another variable. + */ if (dev->drv->cd_status == CD_STATUS_EMPTY) max_len = 70; /* No media inserted. */ - else if (dev->drv->cdrom_capacity > CD_MAX_SECTORS) + else if (dev->drv->cd_status == CD_STATUS_DVD) max_len = 65; /* DVD. */ else if (dev->drv->cd_status == CD_STATUS_DATA_ONLY) max_len = 1; /* Data CD. */ else max_len = 3; /* Audio or mixed-mode CD. */ - if (cdb[0] == GPCMD_MODE_SENSE_6) { + if (dev->current_cdb[0] == GPCMD_MODE_SENSE_6) { len = scsi_cdrom_mode_sense(dev, dev->buffer, 4, cdb[2], block_desc); len = MIN(len, alloc_length); dev->buffer[0] = len - 1; @@ -2964,7 +2866,8 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) if (block_desc) dev->buffer[3] = 8; } else { - len = scsi_cdrom_mode_sense(dev, dev->buffer, 8, cdb[2], block_desc); + len = scsi_cdrom_mode_sense(dev, dev->buffer, 8, + cdb[2], block_desc); len = MIN(len, alloc_length); dev->buffer[0] = (len - 2) >> 8; dev->buffer[1] = (len - 2) & 255; @@ -2977,18 +2880,18 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) scsi_cdrom_set_buf_len(dev, BufLen, &alloc_length); - scsi_cdrom_log("CD-ROM %i: Reading mode page: %02X...\n", dev->id, cdb[2]); + scsi_cdrom_log(dev->log, "Reading mode page: %02X...\n", cdb[2]); scsi_cdrom_data_command_finish(dev, len, len, alloc_length, 0); } else - scsi_cdrom_invalid_field(dev); + scsi_cdrom_invalid_field(dev, cdb[2]); break; case GPCMD_MODE_SELECT_6: case GPCMD_MODE_SELECT_10: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_OUT); - if (cdb[0] == GPCMD_MODE_SELECT_6) { + if (dev->current_cdb[0] == GPCMD_MODE_SELECT_6) { len = cdb[4]; scsi_cdrom_buf_alloc(dev, 256); } else { @@ -3014,21 +2917,17 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) /* Only feature 0 is supported */ if ((feature > 3) && (feature != 0x010) && (feature != 0x1d) && (feature != 0x01e) && (feature != 0x01f) && (feature != 0x103)) - scsi_cdrom_invalid_field(dev); + scsi_cdrom_invalid_field(dev, feature); else { scsi_cdrom_buf_alloc(dev, 65536); memset(dev->buffer, 0, max_len); - alloc_length = 0; - b = dev->buffer; + uint8_t *b = dev->buffer; + + alloc_length = 0; - /* - The number of sectors from the media tells us which profile - to use as current. 0 means there is no media. - */ if (dev->drv->cd_status != CD_STATUS_EMPTY) { - len = dev->drv->cdrom_capacity; - if (len > CD_MAX_SECTORS) { + if (dev->drv->cd_status == CD_STATUS_DVD) { b[6] = (MMC_PROFILE_DVD_ROM >> 8) & 0xff; b[7] = MMC_PROFILE_DVD_ROM & 0xff; ret = 1; @@ -3044,7 +2943,8 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) b += 8; if ((feature == 0) || ((cdb[1] & 3) < 2)) { - b[2] = (0 << 2) | 0x02 | 0x01; /* persistent and current */ + /* Persistent and current. */ + b[2] = (0 << 2) | 0x02 | 0x01; b[3] = 8; alloc_length += 4; @@ -3062,8 +2962,9 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) } } if ((feature == 1) || ((cdb[1] & 3) < 2)) { + /* Persistent and current. */ b[1] = 1; - b[2] = (2 << 2) | 0x02 | 0x01; /* persistent and current */ + b[2] = (2 << 2) | 0x02 | 0x01; b[3] = 8; if (dev->drv->bus_type == CDROM_BUS_SCSI) @@ -3086,25 +2987,18 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) } if ((feature == 3) || ((cdb[1] & 3) < 2)) { b[1] = 2; - b[2] = (0 << 2) | 0x02 | 0x01; /* persistent and current */ + /* Persistent and current. */ + b[2] = (0 << 2) | 0x02 | 0x01; b[3] = 4; - b[4] = 0x0d; - - /* The early CD-ROM drives we emulate (NEC CDR-260 for ATAPI and - early vendor SCSI CD-ROM models) are caddy drives, the later - ones are tray drives. */ - if (dev->drv->bus_type == CDROM_BUS_SCSI) - b[4] |= ((dev->drv->type == CDROM_TYPE_86BOX_100) ? 0x20 : 0x00); - else - b[4] |= ((dev->drv->type == CDROM_TYPE_NEC_260_100) || - ((dev->drv->type == CDROM_TYPE_NEC_260_101)) ? 0x00 : 0x20); + b[4] = 0x0d | (cdrom_is_caddy(dev->drv->type) ? 0x00 : 0x20); alloc_length += 8; b += 8; } if ((feature == 0x10) || ((cdb[1] & 3) < 2)) { b[1] = 0x10; - b[2] = (0 << 2) | 0x02 | 0x01; /* persistent and current */ + /* Persistent and current. */ + b[2] = (0 << 2) | 0x02 | 0x01; b[3] = 8; b[6] = 8; @@ -3115,7 +3009,8 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) } if ((feature == 0x1d) || ((cdb[1] & 3) < 2)) { b[1] = 0x1d; - b[2] = (0 << 2) | 0x02 | 0x01; /* persistent and current */ + /* Persistent and current. */ + b[2] = (0 << 2) | 0x02 | 0x01; b[3] = 0; alloc_length += 4; @@ -3123,7 +3018,8 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) } if ((feature == 0x1e) || ((cdb[1] & 3) < 2)) { b[1] = 0x1e; - b[2] = (2 << 2) | 0x02 | 0x01; /* persistent and current */ + /* Persistent and current. */ + b[2] = (2 << 2) | 0x02 | 0x01; b[3] = 4; b[4] = 0; @@ -3141,14 +3037,14 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) if ((feature == 0x103) || ((cdb[1] & 3) < 2)) { b[0] = 1; b[1] = 3; - b[2] = (0 << 2) | 0x02 | 0x01; /* persistent and current */ + /* Persistent and current. */ + b[2] = (0 << 2) | 0x02 | 0x01; b[3] = 0; b[4] = 7; b[6] = 1; alloc_length += 8; - b += 8; } dev->buffer[0] = ((alloc_length - 4) >> 24) & 0xff; @@ -3160,7 +3056,8 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) scsi_cdrom_set_buf_len(dev, BufLen, &alloc_length); - scsi_cdrom_data_command_finish(dev, alloc_length, alloc_length, alloc_length, 0); + scsi_cdrom_data_command_finish(dev, alloc_length, alloc_length, + alloc_length, 0); } break; @@ -3174,37 +3071,43 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) if (gesn_cdb->polled & 0x01) { /* - * These are the supported events. - * - * We currently only support requests of the 'media' type. - * Notification class requests and supported event classes are bitmasks, - * but they are built from the same values as the "notification class" - * field. + These are the supported events. + + We currently only support requests of the 'media' type. + Notification class requests and supported event classes are bitmasks, + but they are built from the same values as the "notification class" + field. */ gesn_event_header->supported_events = 1 << GESN_MEDIA; /* - * We use |= below to set the class field; other bits in this byte - * are reserved now but this is useful to do if we have to use the - * reserved fields later. + We use |= below to set the class field; other bits in this byte + are reserved now but this is useful to do if we have to use the + reserved fields later. */ gesn_event_header->notification_class = 0; /* - * Responses to requests are to be based on request priority. The - * notification_class_request_type enum above specifies the - * priority: upper elements are higher prio than lower ones. + Responses to requests are to be based on request priority. The + notification_class_request_type enum above specifies the + priority: upper elements are higher prio than lower ones. */ if (gesn_cdb->class & (1 << GESN_MEDIA)) { gesn_event_header->notification_class |= GESN_MEDIA; - dev->buffer[4] = dev->media_status; /* Bits 7-4 = Reserved, Bits 4-1 = Media Status */ - dev->buffer[5] = 1; /* Power Status (1 = Active) */ + /* Bits 7-4 = Reserved, Bits 4-1 = Media Status. */ + if (dev->drv->cd_status == CD_STATUS_EMPTY) + dev->buffer[4] = MEC_MEDIA_REMOVAL; + else + dev->buffer[4] = dev->unit_attention ? MEC_NEW_MEDIA : MEC_NO_CHANGE; + /* Power Status (1 = Active). */ + dev->buffer[5] = 1; dev->buffer[6] = 0; dev->buffer[7] = 0; used_len = 8; } else { - gesn_event_header->notification_class = 0x80; /* No event available */ + /* No event available. */ + gesn_event_header->notification_class = 0x80; used_len = sizeof(*gesn_event_header); } gesn_event_header->len = used_len - sizeof(*gesn_event_header); @@ -3214,18 +3117,17 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) scsi_cdrom_set_buf_len(dev, BufLen, &used_len); scsi_cdrom_data_command_finish(dev, used_len, used_len, used_len, 0); - } else { + } else /* Only polling is supported, asynchronous mode is not. It is fine by the MMC spec to not support async mode operations. */ - scsi_cdrom_invalid_field(dev); - scsi_cdrom_buf_free(dev); - } + scsi_cdrom_invalid_field(dev, gesn_cdb->polled); break; case GPCMD_READ_DISC_INFORMATION: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); + dev->was_cached = dev->toc_cached; max_len = cdb[7]; max_len <<= 8; @@ -3233,16 +3135,11 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) scsi_cdrom_buf_alloc(dev, 65536); - memset(dev->buffer, 0, 34); - memset(dev->buffer, 1, 9); - dev->buffer[0] = 0; - dev->buffer[1] = 32; - dev->buffer[2] = 0xe; /* last session complete, disc finalized */ - dev->buffer[7] = 0x20; /* unrestricted use */ - dev->buffer[8] = 0x00; /* CD-ROM */ + cdrom_read_disc_information(dev->drv, dev->buffer); - len = 34; - len = MIN(len, max_len); + len = MIN(34, max_len); + + scsi_cdrom_cache_toc(dev); scsi_cdrom_set_buf_len(dev, BufLen, &len); @@ -3251,6 +3148,7 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) case GPCMD_READ_TRACK_INFORMATION: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); + dev->was_cached = dev->toc_cached; max_len = cdb[7]; max_len <<= 8; @@ -3258,32 +3156,10 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) scsi_cdrom_buf_alloc(dev, 65536); - track = ((uint32_t) cdb[2]) << 24; - track |= ((uint32_t) cdb[3]) << 16; - track |= ((uint32_t) cdb[4]) << 8; - track |= (uint32_t) cdb[5]; + ret = cdrom_read_track_information(dev->drv, cdb, dev->buffer); - if (((cdb[1] & 0x03) != 1) || (track != 1)) - scsi_cdrom_invalid_field(dev); - else { - len = 36; - - memset(dev->buffer, 0, 36); - dev->buffer[0] = 0; - dev->buffer[1] = 34; - dev->buffer[2] = 1; /* track number (LSB) */ - dev->buffer[3] = 1; /* session number (LSB) */ - dev->buffer[5] = (0 << 5) | (0 << 4) | (4 << 0); /* not damaged, primary copy, data track */ - dev->buffer[6] = (0 << 7) | (0 << 6) | (0 << 5) | /* not reserved track, not blank, */ - (0 << 6) | (1 << 0); /* not packet writing, not fixed packet, */ - /* data mode 1 */ - dev->buffer[7] = (0 << 1) | (0 << 0); /* last recorded address not valid, */ - /* next recordable address not valid */ - - dev->buffer[24] = ((dev->drv->cdrom_capacity - 1) >> 24) & 0xff; /* track size */ - dev->buffer[25] = ((dev->drv->cdrom_capacity - 1) >> 16) & 0xff; /* track size */ - dev->buffer[26] = ((dev->drv->cdrom_capacity - 1) >> 8) & 0xff; /* track size */ - dev->buffer[27] = (dev->drv->cdrom_capacity - 1) & 0xff; /* track size */ + if (ret > 0) { + len = ret; if (len > max_len) { len = max_len; @@ -3291,9 +3167,12 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) dev->buffer[1] = (max_len - 2) & 0xff; } + scsi_cdrom_cache_toc(dev); + scsi_cdrom_set_buf_len(dev, BufLen, &len); scsi_cdrom_data_command_finish(dev, len, len, max_len, 0); - } + } else + scsi_cdrom_invalid_field(dev, -ret); break; case GPCMD_PLAY_AUDIO_10: @@ -3306,7 +3185,7 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) len = 0; - switch (cdb[0]) { + switch (dev->current_cdb[0]) { case GPCMD_PLAY_AUDIO_10: msf = 0; pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; @@ -3345,9 +3224,12 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) break; } - if (ret && (dev->drv->image_path[0] != 0x00) && (dev->drv->cd_status > CD_STATUS_DATA_ONLY)) - ret = cdrom_audio_play(dev->drv, pos, len, msf); - else + if (ret && (dev->drv->image_path[0] != 0x00) && + (dev->drv->cd_status > CD_STATUS_DVD)) { + ret = cdrom_audio_play(dev->drv, pos, len, msf); + + dev->sector_pos = dev->drv->seek_pos; + } else ret = 0; if (ret) @@ -3358,21 +3240,23 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) case GPCMD_READ_SUBCHANNEL: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); + dev->was_cached = (dev->drv->cached_sector != -1); max_len = cdb[7]; max_len <<= 8; max_len |= cdb[8]; msf = (cdb[1] >> 1) & 1; - scsi_cdrom_buf_alloc(dev, 32); + scsi_cdrom_buf_alloc(dev, 128); - scsi_cdrom_log("CD-ROM %i: Getting page %i (%s)\n", dev->id, cdb[3], msf ? "MSF" : "LBA"); + scsi_cdrom_log(dev->log, "Getting page %i (%s)\n", cdb[3], + msf ? "MSF" : "LBA"); - if (cdb[3] > 3) { - /* scsi_cdrom_log("CD-ROM %i: Read subchannel check condition %02X\n", dev->id, - cdb[3]); */ - scsi_cdrom_invalid_field(dev); - } else if (max_len <= 0) { + if (cdb[3] > 3) + scsi_cdrom_invalid_field(dev, cdb[3]); + else if ((cdb[3] != 3) && (cdb[6] != 0)) + scsi_cdrom_invalid_field(dev, cdb[6]); + else if (max_len <= 0) { scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); dev->packet_status = PHASE_COMPLETE; dev->callback = 20.0 * CDROM_TIME; @@ -3382,7 +3266,7 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) alloc_length = 4; else switch (cdb[3]) { case 0: - /* SCSI-2: Q-type subchannel, ATAPI: reserved */ + /* SCSI-2: Q-type subchannel, ATAPI: reserved. */ alloc_length = (dev->drv->bus_type == CDROM_BUS_SCSI) ? 48 : 4; break; case 1: @@ -3395,41 +3279,23 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) len = alloc_length; - memset(dev->buffer, 0, 24); - pos = 0x00; - dev->buffer[pos++] = 0x00; - dev->buffer[pos++] = 0x00; /* Audio status */ - dev->buffer[pos++] = 0x00; - dev->buffer[pos++] = 0x00; /* Subchannel length */ - dev->buffer[pos++] = cdb[3]; /* Format code */ - - if (alloc_length != 4) { - dev->buffer[1] = cdrom_get_current_status(dev->drv); + memset(dev->buffer, 0x00, 128); + if (alloc_length > 4) { + dev->buffer[4] = cdb[3]; /* Format code */ cdrom_get_current_subchannel(dev->drv, &dev->buffer[4], msf); - dev->buffer[2] = alloc_length - 4; + alloc_length = MIN(max_len, alloc_length); + + dev->buffer[3] = (alloc_length - 4) & 0xff; + dev->buffer[4] = cdb[3]; /* Format code */ } - switch (dev->drv->cd_status) { - case CD_STATUS_PLAYING: - dev->buffer[1] = 0x11; - break; - case CD_STATUS_PAUSED: - dev->buffer[1] = ((dev->drv->type == CDROM_TYPE_CHINON_CDS431_H42) || - (dev->drv->type == CDROM_TYPE_CHINON_CDX435_M62)) ? 0x15 : 0x12; - break; - case CD_STATUS_DATA_ONLY: - dev->buffer[1] = ((dev->drv->type == CDROM_TYPE_CHINON_CDS431_H42) || - (dev->drv->type == CDROM_TYPE_CHINON_CDX435_M62)) ? 0x00 : 0x15; - break; - default: - dev->buffer[1] = ((dev->drv->type == CDROM_TYPE_CHINON_CDS431_H42) || - (dev->drv->type == CDROM_TYPE_CHINON_CDX435_M62)) ? 0x00 : 0x13; - break; - } + dev->buffer[1] = cdrom_get_current_status(dev->drv); - scsi_cdrom_log("Audio Status = %02x\n", dev->buffer[1]); + scsi_cdrom_log(dev->log, "Audio status: %02X\n", dev->buffer[1]); + + scsi_cdrom_one_sector_seek(dev); len = MIN(len, max_len); scsi_cdrom_set_buf_len(dev, BufLen, &len); @@ -3442,26 +3308,31 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); alloc_length = (((uint32_t) cdb[8]) << 8) | ((uint32_t) cdb[9]); - scsi_cdrom_buf_alloc(dev, alloc_length); - if ((cdb[7] < 0xc0) && (dev->drv->cdrom_capacity <= CD_MAX_SECTORS)) - scsi_cdrom_incompatible_format(dev); + if ((cdb[7] < 0xc0) && (dev->drv->cd_status != CD_STATUS_DVD)) + scsi_cdrom_incompatible_format(dev, cdb[7]); else { memset(dev->buffer, 0, alloc_length); if ((cdb[7] <= 0x7f) || (cdb[7] == 0xff)) { + uint32_t info = 0x00000000; + if (cdb[1] == 0) { - format = cdb[7]; - ret = scsi_cdrom_read_dvd_structure(dev, format, cdb, dev->buffer); - dev->buffer[0] = (ret >> 8); - dev->buffer[1] = (ret & 0xff); - dev->buffer[2] = dev->buffer[3] = 0x00; - if (ret) { + ret = cdrom_read_dvd_structure(dev->drv, cdb[6], cdb[7], dev->buffer, &info); + if (ret > 0) { + dev->buffer[0] = (ret >> 8); + dev->buffer[1] = (ret & 0xff); + dev->buffer[2] = dev->buffer[3] = 0x00; + scsi_cdrom_set_buf_len(dev, BufLen, &alloc_length); - scsi_cdrom_data_command_finish(dev, alloc_length, alloc_length, + scsi_cdrom_data_command_finish(dev, alloc_length, + alloc_length, alloc_length, 0); - } else { + } else if (ret < 0) + scsi_cdrom_error_common(dev, (ret >> 16) & 0xff, + (ret >> 8) & 0xff, ret & 0xff, info); + else { scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); dev->packet_status = PHASE_COMPLETE; dev->callback = 20.0 * CDROM_TIME; @@ -3469,7 +3340,7 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) } } } else - scsi_cdrom_invalid_field(dev); + scsi_cdrom_invalid_field(dev, cdb[7]); } break; @@ -3481,12 +3352,17 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) scsi_cdrom_stop(sc); break; case 1: /* Start the disc and read the TOC. */ - /* This makes no sense under emulation as this would do - absolutely nothing, so just break. */ + /* + This makes no sense under emulation as this would do + absolutely nothing, so just break. + */ + dev->toc_cached = 0; + scsi_cdrom_cache_toc(dev); break; case 2: /* Eject the disc if possible. */ scsi_cdrom_stop(sc); cdrom_eject(dev->id); + dev->toc_cached = 0; break; case 3: /* Load the disc (close tray). */ cdrom_reload(dev->id); @@ -3512,11 +3388,15 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) preamble_len = 4; size_idx = 3; - dev->buffer[idx++] = 5; - dev->buffer[idx++] = cdb[2]; - dev->buffer[idx++] = 0; + if ((cdb[1] & 0xe0) || ((dev->cur_lun > 0x00) && (dev->cur_lun < 0xff))) + dev->buffer[idx++] = 0x7f; /* No physical device on this LUN */ + else + dev->buffer[idx++] = 0x05; /* CD-ROM */ - idx++; + dev->buffer[idx++] = cdb[2]; + + dev->buffer[idx++] = 0x00; + dev->buffer[idx++] = 0x00; switch (cdb[2]) { case 0x00: @@ -3525,7 +3405,7 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) break; case 0x83: if (idx + 24 > max_len) { - scsi_cdrom_data_phase_error(dev); + scsi_cdrom_data_phase_error(dev, idx + 24); scsi_cdrom_buf_free(dev); return; } @@ -3533,37 +3413,33 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) dev->buffer[idx++] = 0x02; dev->buffer[idx++] = 0x00; dev->buffer[idx++] = 0x00; - dev->buffer[idx++] = 20; - ide_padstr8(dev->buffer + idx, 20, "53R141"); /* Serial */ + dev->buffer[idx++] = 0x14; + ide_padstr8(dev->buffer + idx, 20, "53R141"); /* Serial */ idx += 20; if (idx + 72 > cdb[4]) goto atapi_out; + dev->buffer[idx++] = 0x02; dev->buffer[idx++] = 0x01; dev->buffer[idx++] = 0x00; - dev->buffer[idx++] = 68; - - if (dev->drv->type == CDROM_TYPE_86BOX_100) - ide_padstr8(dev->buffer + idx, 8, EMU_NAME); /* Vendor */ - else - ide_padstr8(dev->buffer + idx, 8, cdrom_drive_types[dev->drv->type].vendor); /* Vendor */ + dev->buffer[idx++] = 34; + ide_padstr8(dev->buffer + idx, 8, + cdrom_get_vendor(dev->drv->type)); /* Vendor */ idx += 8; - if (dev->drv->type == CDROM_TYPE_86BOX_100) - 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 */ + cdrom_get_model(dev->drv->type, model, dev->id); + ide_padstr8(dev->buffer + idx, 16, model); /* Product */ + idx += 16; - idx += 40; - ide_padstr8(dev->buffer + idx, 20, "53R141"); /* Serial */ - idx += 20; + ide_padstr8(dev->buffer + idx, 10, "53R141"); /* Serial */ + idx += 10; break; default: - scsi_cdrom_log("INQUIRY: Invalid page: %02X\n", cdb[2]); - scsi_cdrom_invalid_field(dev); + scsi_cdrom_log(dev->log, "INQUIRY: Invalid page: %02X\n", cdb[2]); + scsi_cdrom_invalid_field(dev, cdb[2]); scsi_cdrom_buf_free(dev); return; } @@ -3575,99 +3451,45 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) if ((cdb[1] & 0xe0) || ((dev->cur_lun > 0x00) && (dev->cur_lun < 0xff))) dev->buffer[0] = 0x7f; /* No physical device on this LUN */ else - dev->buffer[0] = 5; /* CD-ROM */ + dev->buffer[0] = 0x05; /* CD-ROM */ + dev->buffer[1] = 0x80; /* Removable */ if (dev->drv->bus_type == CDROM_BUS_SCSI) { - dev->buffer[3] = 0x02; - switch (dev->drv->type) { - case CDROM_TYPE_CHINON_CDS431_H42: - case CDROM_TYPE_CHINON_CDX435_M62: - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_MATSHITA_501_10b: - case CDROM_TYPE_ShinaKen_DM3x1S_104: - case CDROM_TYPE_SONY_CDU541_10i: - case CDROM_TYPE_TEXEL_DM3024_100: - dev->buffer[2] = 0x00; - dev->buffer[3] = 0x01; /* SCSI-1 compliant */ - break; - case CDROM_TYPE_TEXEL_DM3028_106: - dev->buffer[2] = 0x02; - dev->buffer[3] = 0x01; /* SCSI-2 compliant */ - break; - case CDROM_TYPE_NEC_25_10a: - case CDROM_TYPE_NEC_75_103: - case CDROM_TYPE_NEC_77_106: - dev->buffer[3] = 0x00; /* SCSI unknown version per NEC manuals */ - break; - case CDROM_TYPE_TOSHIBA_XM3201B_3232: - dev->buffer[2] = 0x01; - dev->buffer[3] = 0x01; /* SCSI-1 compliant */ - break; - default: - dev->buffer[2] = 0x02; /* SCSI-2 compliant */ - break; - } + dev->buffer[2] = (dev->ven_cmd == scsi_cdrom_command_nec) ? + 0x00 : cdrom_get_scsi_std(dev->drv->type); + + if (dev->drv->is_toshiba) + /* Linked Command and Relative Addressing supported */ + dev->buffer[7] = 0x88; } else { dev->buffer[2] = 0x00; dev->buffer[3] = 0x21; } - dev->buffer[4] = 31; - if (dev->drv->bus_type == CDROM_BUS_SCSI) { - switch (dev->drv->type) { - case CDROM_TYPE_TOSHIBA_XM_3433 ... CDROM_TYPE_TOSHIBA_XM5701TA_3136: - dev->buffer[4] = 91; /* - Always 91 on Toshiba SCSI-1 (or SCSI-2) - CD-ROM drives from 1989-1990 - */ - dev->buffer[7] = 0x88; /* Linked Command and Relative Addressing supported */ - break; - case CDROM_TYPE_PIONEER_DRM604X_2403: - dev->buffer[4] = 42; - break; - case CDROM_TYPE_NEC_25_10a: - case CDROM_TYPE_NEC_38_103: - case CDROM_TYPE_NEC_75_103: - case CDROM_TYPE_NEC_77_106: - break; - default: - dev->buffer[6] = 0x01; /* 16-bit transfers supported */ - dev->buffer[7] = 0x20; /* Wide bus supported */ - break; - } + if (cdrom_is_generic(dev->drv->type)) { + dev->buffer[6] = 0x01; /* 16-bit transfers supported */ + dev->buffer[7] = 0x20; /* Wide bus supported */ } - if (dev->drv->type == CDROM_TYPE_86BOX_100) { - 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 */ - } else { - 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 (dev->drv->type == CDROM_TYPE_PIONEER_DRM604X_2403) { - dev->buffer[36] = 0x20; - ide_padstr8(dev->buffer + 37, 10, "1991/01/01"); /* Date */ - } + ide_padstr8(dev->buffer + 8, 8, + cdrom_get_vendor(dev->drv->type)); /* Vendor */ + cdrom_get_model(dev->drv->type, model, dev->id); + ide_padstr8(dev->buffer + 16, 16, model); /* Product */ + ide_padstr8(dev->buffer + 32, 4, + cdrom_get_revision(dev->drv->type)); /* Revision */ + + if (dev->drv->is_pioneer) { + dev->buffer[36] = 0x20; + ide_padstr8(dev->buffer + 37, 10, "1991/01/01"); /* Date */ } - idx = 36; - if (dev->drv->type == CDROM_TYPE_PIONEER_DRM604X_2403) - idx = 47; - else { - switch (dev->drv->type) { - case CDROM_TYPE_TOSHIBA_XM_3433 ... CDROM_TYPE_TOSHIBA_XM5701TA_3136: - idx = 96; - break; - default: - if (max_len == 96) { - dev->buffer[4] = 91; - idx = 96; - } - break; - } - } + if (max_len == 96) + idx = 96; + else + idx = cdrom_get_inquiry_len(dev->drv->bus_type); + + dev->buffer[4] = idx - 5; } atapi_out: @@ -3677,7 +3499,8 @@ atapi_out: len = MIN(len, max_len); scsi_cdrom_set_buf_len(dev, BufLen, &max_len); - scsi_cdrom_log("Inquiry = %d, max = %d, BufLen = %d.\n", len, max_len, *BufLen); + scsi_cdrom_log(dev->log, "Inquiry = %d, max = %d, BufLen = %d.\n", len, + max_len, *BufLen); scsi_cdrom_data_command_finish(dev, len, len, max_len, 0); break; @@ -3690,15 +3513,15 @@ atapi_out: case GPCMD_PAUSE_RESUME: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); cdrom_audio_pause_resume(dev->drv, cdb[8] & 0x01); - dev->drv->audio_op = (cdb[8] & 0x01) ? 0x03 : 0x01; scsi_cdrom_command_complete(dev); break; case GPCMD_SEEK_6: case GPCMD_SEEK_10: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); + dev->was_cached = 0; - switch (cdb[0]) { + switch (dev->current_cdb[0]) { case GPCMD_SEEK_6: pos = (cdb[2] << 8) | cdb[3]; break; @@ -3712,24 +3535,23 @@ atapi_out: dev->drv->seek_diff = ABS((int) (pos - dev->drv->seek_pos)); - if (cdb[0] == GPCMD_SEEK_10) { - switch (dev->drv->type) { - case CDROM_TYPE_NEC_25_10a ... CDROM_TYPE_NEC_464_105: - case CDROM_TYPE_TOSHIBA_XM_3433 ... CDROM_TYPE_TOSHIBA_SDM1401_1008: - cdrom_seek(dev->drv, pos, cdb[9] & 0xc0); - break; - default: - cdrom_seek(dev->drv, pos, 0); - break; - } - } else + /* Stop the audio playing. */ + cdrom_stop(dev->drv); + + if (dev->use_cdb_9 && (dev->current_cdb[0] == GPCMD_SEEK_10)) + cdrom_seek(dev->drv, pos, cdb[9] & 0xc0); + else cdrom_seek(dev->drv, pos, 0); + dev->sector_pos = dev->drv->seek_pos; + dev->drv->cached_sector = -1; + scsi_cdrom_command_complete(dev); break; case GPCMD_READ_CDROM_CAPACITY: scsi_cdrom_set_phase(dev, SCSI_PHASE_DATA_IN); + dev->was_cached = dev->toc_cached; scsi_cdrom_buf_alloc(dev, 8); @@ -3742,7 +3564,10 @@ atapi_out: dev->buffer[6] = 8; len = 8; - scsi_cdrom_log("CD-ROM Capacity=%x.\n", dev->drv->cdrom_capacity - 1); + scsi_cdrom_log(dev->log, "CD-ROM Capacity: %08X\n", + dev->drv->cdrom_capacity - 1); + + scsi_cdrom_cache_toc(dev); scsi_cdrom_set_buf_len(dev, BufLen, &len); scsi_cdrom_data_command_finish(dev, len, len, len, 0); @@ -3751,7 +3576,7 @@ atapi_out: case GPCMD_STOP_PLAY_SCAN: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - if (dev->drv->cd_status <= CD_STATUS_DATA_ONLY) { + if (dev->drv->cd_status <= CD_STATUS_DVD) { scsi_cdrom_illegal_mode(dev); break; } @@ -3761,11 +3586,11 @@ atapi_out: break; default: - scsi_cdrom_illegal_opcode(dev); + scsi_cdrom_illegal_opcode(dev, dev->current_cdb[0]); break; } - /* scsi_cdrom_log("CD-ROM %i: Phase: %02X, request length: %i\n", dev->tf->phase, + /* scsi_cdrom_log(dev->log, "Phase: %02X, request length: %i\n", dev->tf->phase, dev->tf->request_length); */ if ((dev->packet_status == PHASE_COMPLETE) || (dev->packet_status == PHASE_ERROR)) @@ -3789,15 +3614,14 @@ scsi_cdrom_phase_data_out(scsi_common_t *sc) uint16_t block_desc_len; uint16_t pos; uint16_t param_list_len; - uint16_t i = 0; - - uint8_t error = 0; - uint8_t page; - uint8_t page_len; - uint8_t hdr_len; - uint8_t val; - uint8_t old_val; - uint8_t ch; + uint16_t i; + uint8_t error = 0; + 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: @@ -3817,7 +3641,8 @@ scsi_cdrom_phase_data_out(scsi_common_t *sc) block_desc_len = dev->buffer[2]; block_desc_len <<= 8; block_desc_len |= dev->buffer[3]; - scsi_cdrom_log("BlockDescLen (6)=%d, ParamListLen (6)=%d.\n", block_desc_len, param_list_len); + scsi_cdrom_log(dev->log, "BlockDescLen (6): %d, " + "ParamListLen (6): %d\n", block_desc_len, param_list_len); } else { block_desc_len = dev->buffer[6]; block_desc_len <<= 8; @@ -3829,21 +3654,28 @@ scsi_cdrom_phase_data_out(scsi_common_t *sc) if (block_desc_len >= 8) { pos = hdr_len + 5; - dev->drv->sector_size = (dev->drv->sector_size & 0x0000ffff) | (dev->buffer[pos++] << 16); - dev->drv->sector_size = (dev->drv->sector_size & 0x00ff00ff) | (dev->buffer[pos++] << 8); - dev->drv->sector_size = (dev->drv->sector_size & 0x00ffff00) | (dev->buffer[pos++]); - scsi_cdrom_log("CD-ROM %i: Sector size now %i bytes\n", dev->id, dev->drv->sector_size); + dev->drv->sector_size = (dev->drv->sector_size & 0x0000ffff) | + (dev->buffer[pos++] << 16); + dev->drv->sector_size = (dev->drv->sector_size & 0x00ff00ff) | + (dev->buffer[pos++] << 8); + dev->drv->sector_size = (dev->drv->sector_size & 0x00ffff00) | + (dev->buffer[pos]); + scsi_cdrom_log(dev->log, "Sector size now %i bytes\n", + dev->drv->sector_size); + + error |= scsi_cdrom_update_sector_flags(dev); } pos = hdr_len + block_desc_len; #ifdef ENABLE_SCSI_CDROM_LOG for (uint16_t j = 0; j < pos; j++) - scsi_cdrom_log("Buffer Mode Select, pos=%d, data=%02x.\n", j, dev->buffer[j]); + scsi_cdrom_log(dev->log, "Buffer Mode Select, pos=%d, data=%02x.\n", + j, dev->buffer[j]); #endif - while (1) { + if (!error) while (1) { if (pos >= param_list_len) { - scsi_cdrom_log("CD-ROM %i: Buffer has only block descriptor\n", dev->id); + scsi_cdrom_log(dev->log, "Buffer has only block descriptor\n"); break; } @@ -3852,71 +3684,50 @@ scsi_cdrom_phase_data_out(scsi_common_t *sc) pos += 2; - switch (dev->drv->type) { - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - if ((page == 0x08) && (page_len == 0x02)) - dev->drv->sony_msf = dev->buffer[pos] & 0x01; + /* Ignore any page codes with zero length. */ + if (page_len == 0) + continue; - if (!(scsi_cdrom_mode_sense_page_flags_sony & (1LL << ((uint64_t) page)))) { - scsi_cdrom_log("CD-ROM %i: Unimplemented page %02X\n", dev->id, page); - error |= 1; - } else { - for (i = 0; i < page_len; i++) { - ch = scsi_cdrom_mode_sense_pages_changeable_sony.pages[page][i + 2]; - val = dev->buffer[pos + i]; - old_val = dev->ms_pages_saved_sony.pages[page][i + 2]; - if (val != old_val) { - if (ch) - dev->ms_pages_saved_sony.pages[page][i + 2] = val; - else { - scsi_cdrom_log("CD-ROM %i: Unchangeable value on position " - "%02X on page %02X\n", dev->id, i + 2, page); - error |= 1; - } - } - } - } - break; - default: - if (!(scsi_cdrom_mode_sense_page_flags & (1LL << ((uint64_t) page)))) { - scsi_cdrom_log("CD-ROM %i: Unimplemented page %02X\n", dev->id, page); - error |= 1; - } else { - for (i = 0; i < page_len; i++) { - ch = scsi_cdrom_mode_sense_pages_changeable.pages[page][i + 2]; - val = dev->buffer[pos + i]; - old_val = dev->ms_pages_saved.pages[page][i + 2]; - if (val != old_val) { - if (ch) - dev->ms_pages_saved.pages[page][i + 2] = val; - else { - scsi_cdrom_log("CD-ROM %i: Unchangeable value on position " - "%02X on page %02X\n", dev->id, i + 2, page); - error |= 1; - } - } + if (dev->drv->is_sony && (page == 0x08) && (page_len == 0x02)) + dev->drv->sony_msf = dev->buffer[pos] & 0x01; + + if (!(dev->ms_page_flags & (1LL << ((uint64_t) page)))) { + scsi_cdrom_log(dev->log, "Unimplemented page %02X\n", page); + error |= 1; + break; + } else { + for (i = 0; i < page_len; i++) { + uint8_t pg = page; + + if (dev->drv->is_sony && + (page == GPMODE_CDROM_AUDIO_PAGE_SONY) && + (i >= 6) && (i <= 13)) + pg = GPMODE_CDROM_AUDIO_PAGE; + + ch = dev->ms_pages_changeable.pages[pg][i + 2]; + val = dev->buffer[pos + i]; + old_val = dev->ms_pages_saved.pages[pg][i + 2]; + if (val != old_val) { + if (ch) + dev->ms_pages_saved.pages[pg][i + 2] = val; + else { + scsi_cdrom_log(dev->log, "Unchangeable value on position " + "%02X on page %02X\n", i + 2, page); + scsi_cdrom_invalid_field_pl(dev, val); + error |= 1; + break; } } + } + + if (error) break; } pos += page_len; - switch (dev->drv->type) { - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - val = scsi_cdrom_mode_sense_pages_default_sony_scsi.pages[page][0] & 0x80; - break; - default: - if (dev->drv->bus_type == CDROM_BUS_SCSI) - val = scsi_cdrom_mode_sense_pages_default_scsi.pages[page][0] & 0x80; - else - val = scsi_cdrom_mode_sense_pages_default.pages[page][0] & 0x80; - break; - } + val = dev->ms_pages_default.pages[page][0] & 0x80; + if (dev->do_page_save && val) scsi_cdrom_mode_sense_save(dev); @@ -3925,21 +3736,21 @@ scsi_cdrom_phase_data_out(scsi_common_t *sc) } if (error) { - scsi_cdrom_invalid_field_pl(dev); scsi_cdrom_buf_free(dev); + scsi_cdrom_command_stop((scsi_common_t *) dev); return 0; } break; - case 0xC9: - switch (dev->drv->type) { - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - for (i = 0; i < 18; i++) - dev->ms_pages_saved_sony.pages[GPMODE_CDROM_AUDIO_PAGE_SONY][i] = dev->buffer[i]; - break; - default: - break; + case 0xc9: + if (dev->drv->is_sony) { + for (i = 0; i < 18; i++) { + if ((i >= 8) && (i <= 15)) + dev->ms_pages_saved.pages[GPMODE_CDROM_AUDIO_PAGE][i] = + dev->buffer[i]; + else + dev->ms_pages_saved.pages[GPMODE_CDROM_AUDIO_PAGE_SONY][i] = + dev->buffer[i]; + } } break; @@ -3956,30 +3767,31 @@ scsi_cdrom_close(void *priv) { scsi_cdrom_t *dev = (scsi_cdrom_t *) priv; - if (dev->tf) - free(dev->tf); + if (dev != NULL) { + if (dev->tf != NULL) + free(dev->tf); + + if (dev->log != NULL) { + scsi_cdrom_log(dev->log, "Log closed\n"); + + log_close(dev->log); + dev->log = NULL; + } - if (dev) free(dev); + } } static int -scsi_cdrom_get_max(int ide_has_dma, int type) +scsi_cdrom_get_max(const ide_t *ide, UNUSED(const int ide_has_dma), const int type) { - int ret; + const scsi_cdrom_t *dev = (scsi_cdrom_t *) ide->sc; + int ret; switch (type) { - case TYPE_PIO: - ret = ide_has_dma ? 4 : 0; - break; - case TYPE_SDMA: - ret = ide_has_dma ? 2 : -1; - break; - case TYPE_MDMA: - ret = ide_has_dma ? 2 : -1; - break; - case TYPE_UDMA: - ret = ide_has_dma ? 5 : -1; + case TYPE_PIO: case TYPE_SDMA: + case TYPE_MDMA: case TYPE_UDMA: + ret = cdrom_get_transfer_max(dev->drv->type, type); break; default: ret = -1; @@ -3990,16 +3802,18 @@ scsi_cdrom_get_max(int ide_has_dma, int type) } static int -scsi_cdrom_get_timings(int ide_has_dma, int type) +scsi_cdrom_get_timings(const ide_t *ide, UNUSED(const int ide_has_dma), const int type) { - int ret; + const scsi_cdrom_t *dev = (scsi_cdrom_t *) ide->sc; + int has_dma = cdrom_has_dma(dev->drv->type); + int ret; switch (type) { case TIMINGS_DMA: - ret = ide_has_dma ? 120 : 0; + ret = has_dma ? 120 : 0; break; case TIMINGS_PIO: - ret = ide_has_dma ? 120 : 0; + ret = has_dma ? 120 : 0; break; case TIMINGS_PIO_FC: ret = 0; @@ -4016,114 +3830,29 @@ scsi_cdrom_get_timings(int ide_has_dma, int type) * Fill in ide->buffer with the output of the "IDENTIFY PACKET DEVICE" command */ static void -scsi_cdrom_identify(ide_t *ide, int ide_has_dma) +scsi_cdrom_identify(const ide_t *ide, UNUSED(const int ide_has_dma)) { - const scsi_cdrom_t *dev; - char device_identify[9] = { '8', '6', 'B', '_', 'C', 'D', '0', '0', 0 }; + const scsi_cdrom_t *dev = (scsi_cdrom_t *) ide->sc; + char model[2048] = { 0 }; + const int has_dma = cdrom_has_dma(dev->drv->type); - dev = (scsi_cdrom_t *) ide->sc; + cdrom_get_identify_model(dev->drv->type, model, dev->id); - device_identify[7] = dev->id + 0x30; - scsi_cdrom_log("ATAPI Identify: %s\n", device_identify); + scsi_cdrom_log(dev->log, "ATAPI Identify: %s\n", model); - if ((dev->drv->type == CDROM_TYPE_NEC_260_100) || (dev->drv->type == CDROM_TYPE_NEC_260_101)) /*NEC only*/ + if (dev->drv->is_early) ide->buffer[0] = 0x8000 | (5 << 8) | 0x80 | (1 << 5); /* ATAPI device, CD-ROM drive, removable media, interrupt DRQ */ else 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 */ + ide_padstr((char *) (ide->buffer + 10), "", 20); /* Serial Number */ - if (dev->drv->type == CDROM_TYPE_86BOX_100) { - ide_padstr((char *) (ide->buffer + 23), EMU_VERSION_EX, 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), device_identify, 40); /* Model */ - } else { - switch (dev->drv->type) { - case CDROM_TYPE_AZT_CDA46802I_115: - ide_padstr((char *) (ide->buffer + 23), "1.15 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "AZT CDA46802I ", 40); /* Model */ - break; - case CDROM_TYPE_BTC_BCD36XH_U10: - ide_padstr((char *) (ide->buffer + 23), "U1.0 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "BTC CD-ROM BCD36XH ", 40); /* Model */ - break; - case CDROM_TYPE_GOLDSTAR_CRD_8160B_314: - ide_padstr((char *) (ide->buffer + 23), "3.14 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "GOLDSTAR CRD-8160B ", 40); /* Model */ - break; - case CDROM_TYPE_HITACHI_CDR_8130_0020: - ide_padstr((char *) (ide->buffer + 23), "0020 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "HITACHI CDR-8130 ", 40); /* Model */ - break; - case CDROM_TYPE_KENWOOD_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 */ - break; - case CDROM_TYPE_MATSHITA_587_7S13: - ide_padstr((char *) (ide->buffer + 23), "7S13 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "MATSHITA CD-ROM CR-587 ", 40); /* Model */ - break; - case CDROM_TYPE_MATSHITA_588_LS15: - ide_padstr((char *) (ide->buffer + 23), "LS15 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "MATSHITA CD-ROM CR-588 ", 40); /* Model */ - break; - case CDROM_TYPE_MATSHITA_571_10e: - ide_padstr((char *) (ide->buffer + 23), "1.0e ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "MATSHITA CR-571 ", 40); /* Model */ - break; - case CDROM_TYPE_MATSHITA_572_10j: - ide_padstr((char *) (ide->buffer + 23), "1.0j ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "MATSHITA CR-572 ", 40); /* Model */ - break; - case CDROM_TYPE_MITSUMI_FX4820T_D02A: - ide_padstr((char *) (ide->buffer + 23), "D02A ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "MITSUMI CRMC-FX4820T ", 40); /* Model */ - break; - case CDROM_TYPE_NEC_260_100: - ide_padstr((char *) (ide->buffer + 23), ".100 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "EN C DCR-MOD IREV2:06 ", 40); /* Model */ - break; - case CDROM_TYPE_NEC_260_101: - ide_padstr((char *) (ide->buffer + 23), ".110 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "EN C DCR-MOD IREV2:06 ", 40); /* Model */ - break; - case CDROM_TYPE_NEC_273_420: - ide_padstr((char *) (ide->buffer + 23), "4.20 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "NEC CD-ROM DRIVE:273 ", 40); /* Model */ - break; - case CDROM_TYPE_NEC_280_105: - ide_padstr((char *) (ide->buffer + 23), "1.05 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "NEC CD-ROM DRIVE:280 ", 40); /* Model */ - break; - case CDROM_TYPE_NEC_280_308: - ide_padstr((char *) (ide->buffer + 23), "3.08 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "NEC CD-ROM DRIVE:280 ", 40); /* Model */ - break; - case CDROM_TYPE_PHILIPS_PCA403CD_U31P: - ide_padstr((char *) (ide->buffer + 23), "U31P ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "PHILIPS CD-ROM PCA403CD ", 40); /* Model */ - break; - case CDROM_TYPE_SONY_CDU76_10i: - ide_padstr((char *) (ide->buffer + 23), "1.0i ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "SONY CD-ROM CDU76 ", 40); /* Model */ - break; - case CDROM_TYPE_SONY_CDU311_30h: - ide_padstr((char *) (ide->buffer + 23), "3.0h ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "SONY CD-ROM CDU311 ", 40); /* Model */ - break; - case CDROM_TYPE_TOSHIBA_5302TA_0305: - ide_padstr((char *) (ide->buffer + 23), "0305 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "TOSHIBA CD-ROM XM-5302TA ", 40); /* Model */ - break; - case CDROM_TYPE_TOSHIBA_5702B_TA70: - ide_padstr((char *) (ide->buffer + 23), "TA70 ", 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), "TOSHIBA CD-ROM XM-5702B ", 40); /* Model */ - break; - } - } + ide_padstr((char *) (ide->buffer + 23), cdrom_get_revision(dev->drv->type), 8); /* Firmware */ + ide_padstr((char *) (ide->buffer + 27), model, 40); /* Model */ ide->buffer[49] = 0x200; /* LBA supported */ ide->buffer[126] = 0xfffe; /* Interpret zero byte count limit as maximum length */ - if (ide_has_dma) { + if (has_dma) { ide->buffer[71] = 30; ide->buffer[72] = 30; ide->buffer[80] = 0x7e; /*ATA-1 to ATA-6 supported*/ @@ -4132,14 +3861,11 @@ scsi_cdrom_identify(ide_t *ide, int ide_has_dma) } void -scsi_cdrom_drive_reset(int c) +scsi_cdrom_drive_reset(const int c) { cdrom_t *drv = &cdrom[c]; - scsi_cdrom_t *dev; - scsi_device_t *sd; - ide_t *id; - uint8_t scsi_bus = (drv->scsi_device_id >> 4) & 0x0f; - uint8_t scsi_id = drv->scsi_device_id & 0x0f; + const uint8_t scsi_bus = (drv->scsi_device_id >> 4) & 0x0f; + const uint8_t scsi_id = drv->scsi_device_id & 0x0f; uint8_t valid = 0; if (drv->bus_type == CDROM_BUS_SCSI) { @@ -4156,98 +3882,130 @@ scsi_cdrom_drive_reset(int c) if ((drv->bus_type == CDROM_BUS_ATAPI) && (drv->ide_channel > 7)) return; - if (!drv->priv) { - drv->priv = (scsi_cdrom_t *) malloc(sizeof(scsi_cdrom_t)); - memset(drv->priv, 0, sizeof(scsi_cdrom_t)); + if (drv->priv == NULL) { + drv->priv = (scsi_cdrom_t *) calloc(1, sizeof(scsi_cdrom_t)); + scsi_cdrom_t *dev = (scsi_cdrom_t *) drv->priv; + + char n[1024] = { 0 }; + + sprintf(n, "CD-ROM %i SCSI ", c + 1); + dev->log = log_open(n); } - dev = (scsi_cdrom_t *) drv->priv; + scsi_cdrom_t *dev = (scsi_cdrom_t *) drv->priv; dev->id = c; dev->drv = drv; - dev->cur_lun = SCSI_LUN_USE_CDB; + dev->cur_lun = SCSI_LUN_USE_CDB; - drv->insert = scsi_cdrom_insert; - drv->get_volume = scsi_cdrom_get_volume; - drv->get_channel = scsi_cdrom_get_channel; - drv->close = scsi_cdrom_close; + dev->toc_cached = 0; + drv->cached_sector = -1; + + drv->insert = scsi_cdrom_insert; + drv->get_volume = scsi_cdrom_get_volume; + drv->get_channel = scsi_cdrom_get_channel; + drv->close = scsi_cdrom_close; drv->sector_size = 2048; + (void) scsi_cdrom_update_sector_flags(dev); if (drv->bus_type == CDROM_BUS_SCSI) { - valid = 1; + char *vendor = cdrom_get_vendor(dev->drv->type); - if (!dev->tf) - dev->tf = (ide_tf_t *) calloc(1, sizeof(ide_tf_t)); + dev->ven_cmd = NULL; + memset(dev->ven_cmd_is_data, 0x00, sizeof(dev->ven_cmd_is_data)); + dev->use_cdb_9 = 0; + dev->ms_page_flags = scsi_cdrom_ms_page_flags_scsi; + dev->ms_pages_default = scsi_cdrom_ms_pages_default_scsi; + dev->ms_pages_changeable = scsi_cdrom_ms_pages_changeable_scsi; + + if (dev->drv->is_chinon) + dev->ven_cmd = scsi_cdrom_command_chinon; + else if (dev->drv->is_sony) { + dev->ven_cmd = scsi_cdrom_command_dec_sony_texel; + dev->ven_cmd_is_data[0xc0] = 1; + dev->ven_cmd_is_data[0xc1] = 1; + dev->ven_cmd_is_data[0xc2] = 1; + dev->ven_cmd_is_data[0xc3] = 1; + dev->ms_page_flags = scsi_cdrom_ms_page_flags_sony_scsi; + dev->ms_pages_default = scsi_cdrom_ms_pages_default_sony_scsi; + dev->ms_pages_changeable = scsi_cdrom_ms_pages_changeable_sony_scsi; + } else if (!strcmp(vendor, "MATSHITA")) + dev->ven_cmd = scsi_cdrom_command_matsushita; + else if (!strcmp(vendor, "NEC")) { + dev->ven_cmd = scsi_cdrom_command_nec; + dev->ven_cmd_is_data[0xdd] = 1; + dev->ven_cmd_is_data[0xde] = 1; + } else if (dev->drv->is_pioneer) { + dev->ven_cmd = scsi_cdrom_command_pioneer; + dev->ven_cmd_is_data[0xc1] = 1; + dev->ven_cmd_is_data[0xc2] = 1; + dev->ven_cmd_is_data[0xc3] = 1; + } else if (dev->drv->is_toshiba) { + dev->ven_cmd = scsi_cdrom_command_toshiba; + dev->ven_cmd_is_data[0xc6] = 1; + dev->ven_cmd_is_data[0xc7] = 1; + dev->use_cdb_9 = 1; + } + + if (dev->tf == NULL) + dev->tf = (ide_tf_t *) calloc(1, sizeof(ide_tf_t)); /* SCSI CD-ROM, attach to the SCSI bus. */ - sd = &scsi_devices[scsi_bus][scsi_id]; + scsi_device_t *sd = &scsi_devices[scsi_bus][scsi_id]; - sd->sc = (scsi_common_t *) dev; - sd->command = scsi_cdrom_command; - sd->request_sense = scsi_cdrom_request_sense_for_scsi; - sd->reset = scsi_cdrom_reset; - sd->phase_data_out = scsi_cdrom_phase_data_out; - sd->command_stop = scsi_cdrom_command_stop; - sd->type = SCSI_REMOVABLE_CDROM; + sd->sc = (scsi_common_t *) dev; + sd->command = scsi_cdrom_command; + sd->request_sense = scsi_cdrom_request_sense_for_scsi; + sd->reset = scsi_cdrom_reset; + sd->phase_data_out = scsi_cdrom_phase_data_out; + sd->command_stop = scsi_cdrom_command_stop; + sd->type = SCSI_REMOVABLE_CDROM; - scsi_cdrom_log("SCSI CD-ROM drive %i attached to SCSI ID %i\n", c, cdrom[c].scsi_device_id); + valid = 1; + + scsi_cdrom_log(dev->log, "SCSI CD-ROM drive %i attached to SCSI ID %i\n", + c, cdrom[c].scsi_device_id); } else if (drv->bus_type == CDROM_BUS_ATAPI) { /* ATAPI CD-ROM, attach to the IDE bus. */ - id = ide_get_drive(drv->ide_channel); - /* If the IDE channel is initialized, we attach to it, - otherwise, we do nothing - it's going to be a drive - that's not attached to anything. */ - if (id) { - valid = 1; + ide_t *id = ide_get_drive(drv->ide_channel); - id->sc = (scsi_common_t *) dev; - dev->tf = id->tf; - if ((dev->drv->type == CDROM_TYPE_NEC_260_100) || (dev->drv->type == CDROM_TYPE_NEC_260_101)) - IDE_ATAPI_IS_EARLY = 1; - id->get_max = scsi_cdrom_get_max; - id->get_timings = scsi_cdrom_get_timings; - id->identify = scsi_cdrom_identify; - id->stop = scsi_cdrom_stop; - id->packet_command = scsi_cdrom_command; - id->device_reset = scsi_cdrom_reset; - id->phase_data_out = scsi_cdrom_phase_data_out; - id->command_stop = scsi_cdrom_command_stop; - id->bus_master_error = scsi_cdrom_bus_master_error; - id->interrupt_drq = ((dev->drv->type == CDROM_TYPE_NEC_260_100) || - (dev->drv->type == CDROM_TYPE_NEC_260_101)); + /* + If the IDE channel is initialized, we attach to it, otherwise, we do + nothing - it's going to be a drive that's not attached to anything. + */ + if (id) { + dev->ven_cmd = NULL; + memset(dev->ven_cmd_is_data, 0x00, sizeof(dev->ven_cmd_is_data)); + dev->use_cdb_9 = 0; + dev->ms_page_flags = scsi_cdrom_ms_page_flags; + dev->ms_pages_default = scsi_cdrom_ms_pages_default; + dev->ms_pages_changeable = scsi_cdrom_ms_pages_changeable; + + id->sc = (scsi_common_t *) dev; + dev->tf = id->tf; + IDE_ATAPI_IS_EARLY = dev->drv->is_early; + id->get_max = scsi_cdrom_get_max; + id->get_timings = scsi_cdrom_get_timings; + id->identify = scsi_cdrom_identify; + id->stop = scsi_cdrom_stop; + id->packet_command = scsi_cdrom_command; + id->device_reset = scsi_cdrom_reset; + id->phase_data_out = scsi_cdrom_phase_data_out; + id->command_stop = scsi_cdrom_command_stop; + id->bus_master_error = scsi_cdrom_bus_master_error; + id->read = scsi_cdrom_read; + id->write = NULL; + id->interrupt_drq = dev->drv->is_early; + + valid = 1; ide_atapi_attach(id); } - scsi_cdrom_log("ATAPI CD-ROM drive %i attached to IDE channel %i\n", c, cdrom[c].ide_channel); - } - - switch (dev->drv->type) { - case CDROM_TYPE_CHINON_CDS431_H42: - dev->ven_cmd = scsi_cdrom_command_chinon; - break; - case CDROM_TYPE_DEC_RRD45_0436: - case CDROM_TYPE_ShinaKen_DM3x1S_104 ... CDROM_TYPE_SONY_CDU76S_100: - case CDROM_TYPE_TEXEL_DM3024_100 ... CDROM_TYPE_TEXEL_DM3028_106: - dev->ven_cmd = scsi_cdrom_command_dec_sony_texel; - break; - case CDROM_TYPE_MATSHITA_501_10b: - dev->ven_cmd = scsi_cdrom_command_matsushita; - break; - case CDROM_TYPE_NEC_25_10a ... CDROM_TYPE_NEC_464_105: - dev->ven_cmd = scsi_cdrom_command_nec; - break; - case CDROM_TYPE_PIONEER_DRM604X_2403: - dev->ven_cmd = scsi_cdrom_command_pioneer; - break; - case CDROM_TYPE_TOSHIBA_XM_3433 ... CDROM_TYPE_TOSHIBA_SDM1401_1008: - dev->ven_cmd = scsi_cdrom_command_toshiba; - break; - default: - dev->ven_cmd = NULL; - break; + scsi_cdrom_log(dev->log, "ATAPI CD-ROM drive %i attached to IDE channel %i\n", + c, cdrom[c].ide_channel); } if (valid) diff --git a/src/scsi/scsi_device.c b/src/scsi/scsi_device.c index 4442b2680..33d3fa89a 100644 --- a/src/scsi/scsi_device.c +++ b/src/scsi/scsi_device.c @@ -16,10 +16,14 @@ * Copyright 2016-2018 Miran Grca. * Copyright 2017-2018 Fred N. van Kempen. */ +#include #include #include #include +#include +#include #include +#define HAVE_STDARG_H #include <86box/86box.h> #include <86box/device.h> #include <86box/hdd.h> @@ -29,9 +33,29 @@ #include <86box/plat_unused.h> scsi_device_t scsi_devices[SCSI_BUS_MAX][SCSI_ID_MAX]; - +int scsi_command_length[8] = { 6, 10, 10, 6, 16, 12, 10, 6 }; uint8_t scsi_null_device_sense[18] = { 0x70, 0, SENSE_ILLEGAL_REQUEST, 0, 0, 0, 0, 0, 0, 0, 0, 0, ASC_INV_LUN, 0, 0, 0, 0, 0 }; +#define SET_BUS_STATE(scsi_bus, state) scsi_bus->bus_out = (scsi_bus->bus_out & ~(SCSI_PHASE_MESSAGE_IN)) | (state & (SCSI_PHASE_MESSAGE_IN)) + +#ifdef ENABLE_SCSI_DEVICE_LOG +int scsi_device_do_log = ENABLE_SCSI_DEVICE_LOG; + +static void +scsi_device_log(const char *fmt, ...) +{ + va_list ap; + + if (scsi_device_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define scsi_device_log(fmt, ...) +#endif + static uint8_t scsi_device_target_command(scsi_device_t *dev, uint8_t *cdb) { @@ -189,3 +213,311 @@ scsi_device_init(void) } } } + +int +scsi_device_get_id(uint8_t data) +{ + for (uint8_t c = 0; c < SCSI_ID_MAX; c++) { + if (data & (1 << c)) + return c; + } + + return -1; +} + + +static int +scsi_device_get_msg(uint8_t *msgp, int len) +{ + uint8_t msg = msgp[0]; + if ((msg == 0) || ((msg >= 0x02) && (msg <= 0x1f)) || (msg >= 0x80)) + return 1; + + if ((msg >= 0x20) && (msg <= 0x2f)) + return 2; + + if (len < 2) + return 3; + + return msgp[1]; +} + +int +scsi_bus_read(scsi_bus_t *scsi_bus) +{ + scsi_device_t *dev; + int phase; + + /*Wait processes to handle bus requests*/ + if (scsi_bus->clear_req) { + scsi_bus->clear_req--; + if (!scsi_bus->clear_req) { + scsi_device_log("Prelude to command data\n"); + SET_BUS_STATE(scsi_bus, scsi_bus->bus_phase); + scsi_bus->bus_out |= BUS_REQ; + } + } + + if (scsi_bus->wait_data) { + scsi_bus->wait_data--; + if (!scsi_bus->wait_data) { + dev = &scsi_devices[scsi_bus->bus_device][scsi_bus->target_id]; + SET_BUS_STATE(scsi_bus, scsi_bus->bus_phase); + phase = scsi_bus->bus_out & SCSI_PHASE_MESSAGE_IN; + + switch (phase) { + case SCSI_PHASE_DATA_IN: + scsi_device_log("DataIn.\n"); + scsi_bus->state = STATE_DATAIN; + if ((dev->sc != NULL) && (dev->sc->temp_buffer != NULL)) + scsi_bus->data = dev->sc->temp_buffer[scsi_bus->data_pos++]; + + scsi_bus->bus_out = (scsi_bus->bus_out & ~BUS_DATAMASK) | BUS_SETDATA(scsi_bus->data) | BUS_DBP; + break; + case SCSI_PHASE_DATA_OUT: + if (scsi_bus->bus_phase & BUS_IDLE) { + scsi_device_log("Bus Idle.\n"); + scsi_bus->state = STATE_IDLE; + scsi_bus->bus_out &= ~BUS_BSY; + scsi_bus->timer(scsi_bus->priv, 0.0); + } else { + scsi_device_log("DataOut.\n"); + scsi_bus->state = STATE_DATAOUT; + } + break; + case SCSI_PHASE_STATUS: + scsi_device_log("Status.\n"); + scsi_bus->bus_out |= BUS_REQ; + scsi_bus->state = STATE_STATUS; + scsi_bus->bus_out = (scsi_bus->bus_out & ~BUS_DATAMASK) | BUS_SETDATA(dev->status) | BUS_DBP; + break; + case SCSI_PHASE_MESSAGE_IN: + scsi_device_log("Message In.\n"); + scsi_bus->state = STATE_MESSAGEIN; + scsi_bus->bus_out = (scsi_bus->bus_out & ~BUS_DATAMASK) | BUS_SETDATA(0) | BUS_DBP; + break; + case SCSI_PHASE_MESSAGE_OUT: + scsi_device_log("Message Out.\n"); + scsi_bus->bus_out |= BUS_REQ; + scsi_bus->state = STATE_MESSAGEOUT; + scsi_bus->bus_out = (scsi_bus->bus_out & ~BUS_DATAMASK) | BUS_SETDATA(scsi_bus->target_id >> 5) | BUS_DBP; + break; + default: + break; + } + } + } + + if (scsi_bus->wait_complete) { + scsi_bus->wait_complete--; + if (!scsi_bus->wait_complete) + scsi_bus->bus_out |= BUS_REQ; + } + + return scsi_bus->bus_out; +} + +void +scsi_bus_update(scsi_bus_t *scsi_bus, int bus) +{ + scsi_device_t *dev = &scsi_devices[scsi_bus->bus_device][scsi_bus->target_id]; + double p; + uint8_t sel_data; + int msglen; + + /*Start the SCSI command layer, which will also make the timings*/ + if (bus & BUS_ARB) + scsi_bus->state = STATE_IDLE; + + scsi_device_log("State = %i\n", scsi_bus->state); + + switch (scsi_bus->state) { + case STATE_IDLE: + scsi_bus->clear_req = scsi_bus->wait_data = scsi_bus->wait_complete = 0; + if ((bus & BUS_SEL) && !(bus & BUS_BSY)) { + sel_data = BUS_GETDATA(bus); + + scsi_bus->target_id = scsi_device_get_id(sel_data); + + /*Once the device has been found and selected, mark it as busy*/ + if ((scsi_bus->target_id != (uint8_t) -1) && scsi_device_present(&scsi_devices[scsi_bus->bus_device][scsi_bus->target_id])) { + scsi_bus->bus_out |= BUS_BSY; + scsi_bus->state = STATE_SELECT; + scsi_device_log("Select - target ID = %i, moving to state = %d.\n", scsi_bus->target_id, scsi_bus->state); + } else { + scsi_device_log("Device not found at ID %i, Current Bus BSY=%02x\n", scsi_bus->target_id, scsi_bus->bus_out); + scsi_bus->bus_out = 0; + } + } + break; + case STATE_SELECT: + if (!(bus & BUS_SEL)) { + if (!(bus & BUS_ATN)) { + if ((scsi_bus->target_id != (uint8_t) -1) && scsi_device_present(&scsi_devices[scsi_bus->bus_device][scsi_bus->target_id])) { + scsi_device_log("Device found at ID %i, Current Bus BSY=%02x\n", scsi_bus->target_id, scsi_bus->bus_out); + scsi_bus->state = STATE_COMMAND; + scsi_bus->bus_out = BUS_BSY | BUS_REQ; + scsi_bus->command_pos = 0; + SET_BUS_STATE(scsi_bus, SCSI_PHASE_COMMAND); + } else { + scsi_device_log("Device not found at ID %i again.\n", scsi_bus->target_id); + scsi_bus->state = STATE_IDLE; + scsi_bus->bus_out = 0; + } + } else { + scsi_device_log("Set to SCSI Message Out\n"); + scsi_bus->bus_phase = SCSI_PHASE_MESSAGE_OUT; + scsi_bus->wait_data = 4; + scsi_bus->msgout_pos = 0; + scsi_bus->is_msgout = 1; + } + } + break; + case STATE_COMMAND: + if ((bus & BUS_ACK) && !(scsi_bus->bus_in & BUS_ACK)) { + /*Write command byte to the output data register*/ + scsi_bus->command[scsi_bus->command_pos++] = BUS_GETDATA(bus); + scsi_bus->clear_req = 3; + scsi_bus->bus_phase = scsi_bus->bus_out & SCSI_PHASE_MESSAGE_IN; + scsi_bus->bus_out &= ~BUS_REQ; + + scsi_device_log("Command pos=%i, output data=%02x\n", scsi_bus->command_pos, BUS_GETDATA(bus)); + + if (scsi_bus->command_pos == scsi_command_length[(scsi_bus->command[0] >> 5) & 7]) { + if (scsi_bus->is_msgout) { + scsi_bus->is_msgout = 0; +#if 0 + scsi_bus->command[1] = (scsi_bus->command[1] & 0x1f) | (scsi_bus->msglun << 5); +#endif + } + + /*Reset data position to default*/ + scsi_bus->data_pos = 0; + + dev = &scsi_devices[scsi_bus->bus_device][scsi_bus->target_id]; + + scsi_device_log("SCSI Command 0x%02X for ID %d, status code=%02x\n", scsi_bus->command[0], scsi_bus->target_id, dev->status); + dev->buffer_length = -1; + scsi_device_command_phase0(dev, scsi_bus->command); + scsi_device_log("SCSI ID %i: Command %02X: Buffer Length %i, SCSI Phase %02X\n", scsi_bus->target_id, scsi_bus->command[0], dev->buffer_length, dev->phase); + + scsi_bus->period = 1.0; + scsi_bus->wait_data = 4; + scsi_bus->data_wait = 0; + scsi_bus->command_issued = 1; + + if (dev->status == SCSI_STATUS_OK) { + /*If the SCSI phase is Data In or Data Out, allocate the SCSI buffer based on the transfer length of the command*/ + if (dev->buffer_length && ((dev->phase == SCSI_PHASE_DATA_IN) || (dev->phase == SCSI_PHASE_DATA_OUT))) { + p = scsi_device_get_callback(dev); + scsi_bus->period = (p > 0.0) ? ((p / scsi_bus->divider) * scsi_bus->multi) : (((double) dev->buffer_length) * scsi_bus->speed); + scsi_device_log("SCSI ID %i: command 0x%02x for p = %lf, update = %lf, len = %i, dmamode = %x\n", scsi_bus->target_id, scsi_bus->command[0], scsi_device_get_callback(dev), scsi_bus->period, dev->buffer_length, scsi_bus->tx_mode); + } + } + scsi_bus->bus_phase = dev->phase; + } + } + break; + case STATE_DATAIN: + dev = &scsi_devices[scsi_bus->bus_device][scsi_bus->target_id]; + if ((bus & BUS_ACK) && !(scsi_bus->bus_in & BUS_ACK)) { + if (scsi_bus->data_pos >= dev->buffer_length) { + scsi_bus->bus_out &= ~BUS_REQ; + scsi_device_command_phase1(dev); + scsi_bus->bus_phase = SCSI_PHASE_STATUS; + scsi_bus->wait_data = 4; + scsi_bus->wait_complete = 8; + } else { + if ((dev->sc != NULL) && (dev->sc->temp_buffer != NULL)) + scsi_bus->data = dev->sc->temp_buffer[scsi_bus->data_pos++]; + + scsi_device_log("TXMode DataIn=%x, cmd=%02x.\n", scsi_bus->tx_mode, scsi_bus->command[0]); + scsi_bus->bus_out = (scsi_bus->bus_out & ~BUS_DATAMASK) | BUS_SETDATA(scsi_bus->data) | BUS_DBP | BUS_REQ; + if (scsi_bus->tx_mode == PIO_TX_BUS) { /*If a data in command that is not read 6/10 has been issued*/ + scsi_device_log("DMA mode idle IN=%d.\n", scsi_bus->data_pos); + scsi_bus->data_wait |= 1; + scsi_bus->timer(scsi_bus->priv, scsi_bus->period); + } else { + scsi_device_log("DMA mode IN=%d.\n", scsi_bus->data_pos); + scsi_bus->clear_req = 3; + } + scsi_bus->bus_out &= ~BUS_REQ; + scsi_bus->bus_phase = SCSI_PHASE_DATA_IN; + } + } + break; + case STATE_DATAOUT: + dev = &scsi_devices[scsi_bus->bus_device][scsi_bus->target_id]; + if ((bus & BUS_ACK) && !(scsi_bus->bus_in & BUS_ACK)) { + if ((dev->sc != NULL) && (dev->sc->temp_buffer != NULL)) + dev->sc->temp_buffer[scsi_bus->data_pos++] = BUS_GETDATA(bus); + + if (scsi_bus->data_pos >= dev->buffer_length) { + scsi_bus->bus_out &= ~BUS_REQ; + scsi_device_command_phase1(dev); + scsi_bus->bus_phase = SCSI_PHASE_STATUS; + scsi_bus->wait_data = 4; + scsi_bus->wait_complete = 8; + } else { + /*More data is to be transferred, place a request*/ + if (scsi_bus->tx_mode == PIO_TX_BUS) { /*If a data in command that is not write 6/10 has been issued*/ + scsi_device_log("DMA mode idle OUT=%d.\n", scsi_bus->data_pos); + scsi_bus->data_wait |= 1; + scsi_bus->timer(scsi_bus->priv, scsi_bus->period); + scsi_bus->bus_out &= ~BUS_REQ; + } else { + scsi_device_log("DMA mode OUT=%d.\n", scsi_bus->data_pos); + scsi_bus->bus_out |= BUS_REQ; + } + } + } + break; + case STATE_STATUS: + if ((bus & BUS_ACK) && !(scsi_bus->bus_in & BUS_ACK)) { + /*All transfers done, wait until next transfer*/ + scsi_device_identify(&scsi_devices[scsi_bus->bus_device][scsi_bus->target_id], SCSI_LUN_USE_CDB); + scsi_bus->bus_out &= ~BUS_REQ; + scsi_bus->bus_phase = SCSI_PHASE_MESSAGE_IN; + scsi_bus->wait_data = 4; + scsi_bus->wait_complete = 8; + scsi_bus->command_issued = 0; + } + break; + case STATE_MESSAGEIN: + if ((bus & BUS_ACK) && !(scsi_bus->bus_in & BUS_ACK)) { + scsi_bus->bus_out &= ~BUS_REQ; + scsi_bus->bus_phase = BUS_IDLE; + scsi_bus->wait_data = 4; + } + break; + case STATE_MESSAGEOUT: + if ((bus & BUS_ACK) && !(scsi_bus->bus_in & BUS_ACK)) { + scsi_bus->msgout[scsi_bus->msgout_pos++] = BUS_GETDATA(bus); + msglen = scsi_device_get_msg(scsi_bus->msgout, scsi_bus->msgout_pos); + if (scsi_bus->msgout_pos >= msglen) { + if ((scsi_bus->msgout[0] & (0x80 | 0x20)) == 0x80) + scsi_bus->msglun = scsi_bus->msgout[0] & 7; + + scsi_bus->bus_out &= ~BUS_REQ; + scsi_bus->state = STATE_MESSAGE_ID; + } + } + break; + case STATE_MESSAGE_ID: + if ((scsi_bus->target_id != (uint8_t) -1) && scsi_device_present(&scsi_devices[scsi_bus->bus_device][scsi_bus->target_id])) { + scsi_device_log("Device found at ID %i on MSGOUT, Current Bus BSY=%02x\n", scsi_bus->target_id, scsi_bus->bus_out); + scsi_device_identify(&scsi_devices[scsi_bus->bus_device][scsi_bus->target_id], scsi_bus->msglun); + scsi_bus->state = STATE_COMMAND; + scsi_bus->bus_out = BUS_BSY | BUS_REQ; + scsi_bus->command_pos = 0; + SET_BUS_STATE(scsi_bus, SCSI_PHASE_COMMAND); + } + break; + + default: + break; + } + + scsi_bus->bus_in = bus; +} + diff --git a/src/scsi/scsi_disk.c b/src/scsi/scsi_disk.c index 10fdf04a6..8c09a30a1 100644 --- a/src/scsi/scsi_disk.c +++ b/src/scsi/scsi_disk.c @@ -12,26 +12,24 @@ * * Copyright 2017-2018 Miran Grca. */ -#include #include #include -#include +#ifdef ENABLE_SCSI_DISK_LOG +#include +#endif #include +#include #include #include -#include -#define HAVE_STDARG_H #include <86box/86box.h> -#include <86box/config.h> #include <86box/timer.h> #include <86box/device.h> +#include <86box/log.h> #include <86box/scsi.h> #include <86box/scsi_device.h> #include <86box/machine.h> #include <86box/nvr.h> -#include <86box/hdc.h> #include <86box/hdc_ide.h> -#include <86box/sound.h> #include <86box/plat.h> #include <86box/ui.h> #include <86box/hdd.h> @@ -42,86 +40,71 @@ #define scsi_disk_sense_error dev->sense[0] #define scsi_disk_sense_key dev->sense[2] +#define scsi_disk_info *(uint32_t *) &(dev->sense[3]) #define scsi_disk_asc dev->sense[12] #define scsi_disk_ascq dev->sense[13] -/* Table of all SCSI commands and their flags, needed for the new disc change / not ready handler. */ +// clang-format off +/* + Table of all SCSI commands and their flags, needed for the new disc change / + not ready handler. + */ const uint8_t scsi_disk_command_flags[0x100] = { - IMPLEMENTED | CHECK_READY | NONDATA, /* 0x00 */ - IMPLEMENTED | ALLOW_UA | NONDATA | SCSI_ONLY, /* 0x01 */ - 0, - IMPLEMENTED | ALLOW_UA, /* 0x03 */ - IMPLEMENTED | CHECK_READY | ALLOW_UA | NONDATA | SCSI_ONLY, /* 0x04 */ - 0, 0, 0, - IMPLEMENTED | CHECK_READY, /* 0x08 */ - 0, - IMPLEMENTED | CHECK_READY, /* 0x0A */ - IMPLEMENTED | CHECK_READY | NONDATA, /* 0x0B */ - 0, 0, 0, 0, 0, 0, - IMPLEMENTED | ALLOW_UA, /* 0x12 */ - IMPLEMENTED | CHECK_READY | NONDATA | SCSI_ONLY, /* 0x13 */ - 0, - IMPLEMENTED, /* 0x15 */ - IMPLEMENTED | SCSI_ONLY, /* 0x16 */ - IMPLEMENTED | SCSI_ONLY, /* 0x17 */ - 0, 0, - IMPLEMENTED, /* 0x1A */ - 0, 0, - IMPLEMENTED, /* 0x1D */ - IMPLEMENTED | CHECK_READY, /* 0x1E */ - 0, 0, 0, 0, 0, 0, - IMPLEMENTED | CHECK_READY, /* 0x25 */ - 0, 0, - IMPLEMENTED | CHECK_READY, /* 0x28 */ - 0, - IMPLEMENTED | CHECK_READY, /* 0x2A */ - IMPLEMENTED | CHECK_READY | NONDATA, /* 0x2B */ - 0, 0, - IMPLEMENTED | CHECK_READY, /* 0x2E */ - IMPLEMENTED | CHECK_READY | NONDATA | SCSI_ONLY, /* 0x2F */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, - IMPLEMENTED | CHECK_READY, /* 0x41 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, - IMPLEMENTED, /* 0x55 */ - 0, 0, 0, 0, - IMPLEMENTED, /* 0x5A */ - 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, - IMPLEMENTED | CHECK_READY, /* 0xA8 */ - 0, - IMPLEMENTED | CHECK_READY, /* 0xAA */ - 0, 0, 0, - IMPLEMENTED | CHECK_READY, /* 0xAE */ - IMPLEMENTED | CHECK_READY | NONDATA | SCSI_ONLY, /* 0xAF */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - IMPLEMENTED, /* 0xBD */ - 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 + [0x00] = IMPLEMENTED | CHECK_READY, + [0x01] = IMPLEMENTED | ALLOW_UA | SCSI_ONLY, + [0x03] = IMPLEMENTED | ALLOW_UA, + [0x04] = IMPLEMENTED | CHECK_READY | ALLOW_UA | SCSI_ONLY, + [0x08] = IMPLEMENTED | CHECK_READY, + [0x0a ... 0x0b] = IMPLEMENTED | CHECK_READY, + [0x12] = IMPLEMENTED | ALLOW_UA, + [0x13] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0x15] = IMPLEMENTED, + [0x16 ... 0x17] = IMPLEMENTED | SCSI_ONLY, + [0x1a] = IMPLEMENTED, + [0x1d] = IMPLEMENTED, + [0x1e] = IMPLEMENTED | CHECK_READY, + [0x25] = IMPLEMENTED | CHECK_READY, + [0x28] = IMPLEMENTED | CHECK_READY, + [0x2a ... 0x2b] = IMPLEMENTED | CHECK_READY, + [0x2e] = IMPLEMENTED | CHECK_READY, + [0x2f] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0x41] = IMPLEMENTED | CHECK_READY, + [0x55] = IMPLEMENTED, + [0x5a] = IMPLEMENTED, + [0xa8] = IMPLEMENTED | CHECK_READY, + [0xaa] = IMPLEMENTED | CHECK_READY, + [0xae] = IMPLEMENTED | CHECK_READY, + [0xaf] = IMPLEMENTED | CHECK_READY | SCSI_ONLY, + [0xbd] = IMPLEMENTED }; -uint64_t scsi_disk_mode_sense_page_flags = (GPMODEP_FORMAT_DEVICE_PAGE | GPMODEP_RIGID_DISK_PAGE | GPMODEP_UNK_VENDOR_PAGE | GPMODEP_ALL_PAGES); +uint64_t scsi_disk_mode_sense_page_flags = (GPMODEP_FORMAT_DEVICE_PAGE | GPMODEP_RIGID_DISK_PAGE | + GPMODEP_UNK_VENDOR_PAGE | GPMODEP_ALL_PAGES); -/* This should be done in a better way but for time being, it's been done this way so it's not as huge and more readable. */ static const mode_sense_pages_t scsi_disk_mode_sense_pages_default = { - {[GPMODE_FORMAT_DEVICE_PAGE] = { GPMODE_FORMAT_DEVICE_PAGE, 0x16, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - [GPMODE_RIGID_DISK_PAGE] = { GPMODE_RIGID_DISK_PAGE, 0x16, 0, 0x10, 0, 64, 0, 0, 0, 0, 0, 0, 0, 200, 0xff, 0xff, 0xff, 0, 0, 0, 0x15, 0x18, 0, 0 }, - [GPMODE_UNK_VENDOR_PAGE] = { 0xB0, 0x16, '8', '6', 'B', 'o', 'x', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }} + { [0x03] = { GPMODE_FORMAT_DEVICE_PAGE, 0x16, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, + 0x00, 0x01, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x04] = { GPMODE_RIGID_DISK_PAGE, 0x16, 0x00, 0x10, 0x00, 0x40, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0xff, 0xff, + 0xff, 0x00, 0x00, 0x00, 0x15, 0x18, 0x00, 0x00 }, + [0x30] = { GPMODE_UNK_VENDOR_PAGE | 0x80, 0x16, '8' , '6' , 'B' , 'o' , 'x' , ' ' , + ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , + ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' } } }; static const mode_sense_pages_t scsi_disk_mode_sense_pages_changeable = { - {[GPMODE_FORMAT_DEVICE_PAGE] = { GPMODE_FORMAT_DEVICE_PAGE, 0x16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - [GPMODE_RIGID_DISK_PAGE] = { GPMODE_RIGID_DISK_PAGE, 0x16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - [GPMODE_UNK_VENDOR_PAGE] = { 0xB0, 0x16, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }} + { [0x03] = { GPMODE_FORMAT_DEVICE_PAGE, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x04] = { GPMODE_RIGID_DISK_PAGE, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + [0x30] = { GPMODE_UNK_VENDOR_PAGE | 0x80, 0x16, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } } }; +// clang-format on static void scsi_disk_command_complete(scsi_disk_t *dev); @@ -133,116 +116,116 @@ static void scsi_disk_init(scsi_disk_t *dev); int scsi_disk_do_log = ENABLE_SCSI_DISK_LOG; static void -scsi_disk_log(const char *fmt, ...) +scsi_disk_log(void *priv, const char *fmt, ...) { va_list ap; if (scsi_disk_do_log) { va_start(ap, fmt); - pclog_ex(fmt, ap); + log_out(priv, fmt, ap); va_end(ap); } } #else -# define scsi_disk_log(fmt, ...) +# define scsi_disk_log(priv, fmt, ...) #endif static void -scsi_disk_set_callback(scsi_disk_t *dev) +scsi_disk_set_callback(const scsi_disk_t *dev) { - if (dev->drv->bus != HDD_BUS_SCSI) + if (dev->drv->bus_type != HDD_BUS_SCSI) ide_set_callback(ide_drives[dev->drv->ide_channel], dev->callback); } static void scsi_disk_init(scsi_disk_t *dev) { - if (!dev) - return; + if (dev != NULL) { + /* Do a reset (which will also rezero it). */ + scsi_disk_reset((scsi_common_t *) dev); - /* Do a reset (which will also rezero it). */ - scsi_disk_reset((scsi_common_t *) dev); + /* Configure the drive. */ + dev->requested_blocks = 1; - /* Configure the drive. */ - dev->requested_blocks = 1; + dev->drv->bus_mode = 0; + if (dev->drv->bus_type >= HDD_BUS_ATAPI) + dev->drv->bus_mode |= 2; + if (dev->drv->bus_type < HDD_BUS_SCSI) + dev->drv->bus_mode |= 1; + scsi_disk_log(dev->log, "Bus type %i, bus mode %i\n", + dev->drv->bus_type, dev->drv->bus_mode); - dev->drv->bus_mode = 0; - if (dev->drv->bus >= HDD_BUS_ATAPI) - dev->drv->bus_mode |= 2; - if (dev->drv->bus < HDD_BUS_SCSI) - dev->drv->bus_mode |= 1; - scsi_disk_log("SCSI HDD %i: Bus type %i, bus mode %i\n", - dev->id, dev->drv->bus, dev->drv->bus_mode); + dev->sense[0] = 0xf0; + dev->sense[7] = 10; - dev->sense[0] = 0xf0; - dev->sense[7] = 10; - /* NEC only */ - dev->tf->status = 0; - dev->tf->pos = 0; - dev->packet_status = PHASE_NONE; - scsi_disk_sense_key = scsi_disk_asc = scsi_disk_ascq = dev->unit_attention = 0; - scsi_disk_mode_sense_load(dev); + dev->tf->status = 0; + dev->tf->pos = 0; + dev->packet_status = PHASE_NONE; + scsi_disk_sense_key = scsi_disk_asc = scsi_disk_ascq = dev->unit_attention = 0; + scsi_disk_info = 0x00; + scsi_disk_mode_sense_load(dev); + } } /* Returns: 0 for none, 1 for PIO, 2 for DMA. */ static int -scsi_disk_current_mode(scsi_disk_t *dev) +scsi_disk_current_mode(const scsi_disk_t *dev) { - if (dev->drv->bus == HDD_BUS_SCSI) - return 2; - else if (dev->drv->bus == HDD_BUS_ATAPI) { - scsi_disk_log("SCSI DISK %i: ATAPI drive, setting to %s\n", dev->id, + int ret = 0; + + if (dev->drv->bus_type == HDD_BUS_SCSI) + ret = 2; + else if (dev->drv->bus_type == HDD_BUS_ATAPI) { + scsi_disk_log(dev->log, "ATAPI drive, setting to %s\n", (dev->tf->features & 1) ? "DMA" : "PIO", dev->id); - return (dev->tf->features & 1) ? 2 : 1; + ret = (dev->tf->features & 1) ? 2 : 1; } - return 0; + return ret; } -void +static void scsi_disk_mode_sense_load(scsi_disk_t *dev) { - FILE *fp; - char file_name[512]; + char file_name[512] = { 0 }; memset(&dev->ms_pages_saved, 0, sizeof(mode_sense_pages_t)); - memcpy(&dev->ms_pages_saved, &scsi_disk_mode_sense_pages_default, sizeof(mode_sense_pages_t)); + memcpy(&dev->ms_pages_saved, &scsi_disk_mode_sense_pages_default, + sizeof(mode_sense_pages_t)); - memset(file_name, 0, 512); sprintf(file_name, "scsi_disk_%02i_mode_sense.bin", dev->id); - fp = plat_fopen(nvr_path(file_name), "rb"); + FILE *fp = plat_fopen(nvr_path(file_name), "rb"); if (fp) { if (fread(dev->ms_pages_saved.pages[0x30], 1, 0x18, fp) != 0x18) - fatal("scsi_disk_mode_sense_load(): Error reading data\n"); + log_fatal(dev->log, "scsi_disk_mode_sense_load(): Error reading data\n"); fclose(fp); } } -void -scsi_disk_mode_sense_save(scsi_disk_t *dev) +static void +scsi_disk_mode_sense_save(const scsi_disk_t *dev) { - FILE *fp; - char file_name[512]; + char file_name[512] = { 0 }; - memset(file_name, 0, 512); sprintf(file_name, "scsi_disk_%02i_mode_sense.bin", dev->id); - fp = plat_fopen(nvr_path(file_name), "wb"); + FILE *fp = plat_fopen(nvr_path(file_name), "wb"); if (fp) { fwrite(dev->ms_pages_saved.pages[0x30], 1, 0x18, fp); fclose(fp); } } -/*SCSI Mode Sense 6/10*/ +/* SCSI Mode Sense 6/10 */ uint8_t -scsi_disk_mode_sense_read(scsi_disk_t *dev, uint8_t page_control, uint8_t page, uint8_t pos) +scsi_disk_mode_sense_read(const scsi_disk_t *dev, const uint8_t pgctl, + const uint8_t page, const uint8_t pos) { - if (page_control == 1) + if (pgctl == 1) return scsi_disk_mode_sense_pages_changeable.pages[page][pos]; if (page == GPMODE_RIGID_DISK_PAGE) - switch (page_control) { + switch (pgctl) { /* Rigid disk geometry page. */ case 0: case 2: @@ -272,7 +255,7 @@ scsi_disk_mode_sense_read(scsi_disk_t *dev, uint8_t page_control, uint8_t page, break; } else if (page == GPMODE_FORMAT_DEVICE_PAGE) - switch (page_control) { + switch (pgctl) { /* Format device page. */ case 0: case 2: @@ -293,7 +276,7 @@ scsi_disk_mode_sense_read(scsi_disk_t *dev, uint8_t page_control, uint8_t page, break; } else - switch (page_control) { + switch (pgctl) { case 0: case 3: return dev->ms_pages_saved.pages[page][pos]; @@ -308,16 +291,13 @@ 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) +scsi_disk_mode_sense(const scsi_disk_t *dev, uint8_t *buf, uint32_t pos, + uint8_t page, const uint8_t block_descriptor_len) { - uint8_t msplen; - uint8_t page_control = (page >> 6) & 3; - int size = 0; + int size = hdd_image_get_last_sector(dev->id); page &= 0x3f; - size = hdd_image_get_last_sector(dev->id); - if (block_descriptor_len) { buf[pos++] = 1; /* Density code. */ buf[pos++] = (size >> 16) & 0xff; /* Number of blocks (0 = all). */ @@ -332,12 +312,14 @@ scsi_disk_mode_sense(scsi_disk_t *dev, uint8_t *buf, uint32_t pos, uint8_t page, 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); + const uint8_t pgctl = (page >> 6) & 3; + const uint8_t msplen = scsi_disk_mode_sense_read(dev, pgctl, i, 1); + buf[pos++] = scsi_disk_mode_sense_read(dev, pgctl, i, 0); + buf[pos++] = msplen; + scsi_disk_log(dev->log, "MODE SENSE: Page [%02X] length %i\n", + i, msplen); for (uint8_t j = 0; j < msplen; j++) - buf[pos++] = scsi_disk_mode_sense_read(dev, page_control, i, 2 + j); + buf[pos++] = scsi_disk_mode_sense_read(dev, pgctl, i, 2 + j); } } } @@ -346,7 +328,7 @@ scsi_disk_mode_sense(scsi_disk_t *dev, uint8_t *buf, uint32_t pos, uint8_t page, } static void -scsi_disk_update_request_length(scsi_disk_t *dev, int len, int block_len) +scsi_disk_update_request_length(scsi_disk_t *dev, int len, const int block_len) { int bt; int min_len = 0; @@ -407,7 +389,7 @@ scsi_disk_bus_speed(scsi_disk_t *dev) { double ret = -1.0; - if (dev && dev->drv && (dev->drv->bus == HDD_BUS_SCSI)) { + if (dev && dev->drv && (dev->drv->bus_type == HDD_BUS_SCSI)) { dev->callback = -1.0; /* Speed depends on SCSI controller */ return 0.0; } else { @@ -418,14 +400,15 @@ scsi_disk_bus_speed(scsi_disk_t *dev) dev->callback = -1.0; return 0.0; } else - return ret * 1000000.0; + /* We get bytes per µs, so divide 1000000.0 by it. */ + return 1000000.0 / ret; } } void scsi_disk_command_common(scsi_disk_t *dev) { - double bytes_per_second = 0.0; + double bytes_per_second; double period; /* MAP: BUSY_STAT, no DRQ, phase 1. */ @@ -435,6 +418,7 @@ scsi_disk_command_common(scsi_disk_t *dev) dev->callback = 0; if (dev->packet_status == PHASE_COMPLETE) { + switch (dev->current_cdb[0]) { case GPCMD_VERIFY_6: case GPCMD_VERIFY_10: @@ -446,18 +430,19 @@ scsi_disk_command_common(scsi_disk_t *dev) case GPCMD_WRITE_AND_VERIFY_12: case GPCMD_WRITE_SAME_10: /* Seek time is in us. */ - period = hdd_timing_write(dev->drv, dev->drv->seek_pos, dev->drv->seek_len); - scsi_disk_log("SCSI HD %i: Seek period: %" PRIu64 " us\n", - dev->id, (uint64_t) period); + period = hdd_timing_write(dev->drv, dev->drv->seek_pos, + dev->drv->seek_len); + scsi_disk_log(dev->log, "Seek period: %" PRIu64 " us\n", + (uint64_t) period); dev->callback += period; /* Account for seek time. */ bytes_per_second = scsi_bus_get_speed(dev->drv->scsi_id >> 4); period = 1000000.0 / bytes_per_second; - scsi_disk_log("SCSI HD %i: Byte transfer period: %" PRIu64 " us\n", dev->id, + scsi_disk_log(dev->log, "Byte transfer period: %" PRIu64 " us\n", (uint64_t) period); period = period * (double) (dev->packet_len); - scsi_disk_log("CD-ROM %i: Sector transfer period: %" PRIu64 " us\n", dev->id, + scsi_disk_log(dev->log, "Sector transfer period: %" PRIu64 " us\n", (uint64_t) period); dev->callback += period; break; @@ -473,8 +458,8 @@ scsi_disk_command_common(scsi_disk_t *dev) /* Seek time is in us. */ period = hdd_seek_get_time(dev->drv, (dev->current_cdb[0] == GPCMD_REZERO_UNIT) ? 0 : dev->sector_pos, HDD_OP_SEEK, 0, 0.0); - scsi_disk_log("SCSI HD %i: Seek period: %" PRIu64 " us\n", - dev->id, (uint64_t) period); + scsi_disk_log(dev->log, "Seek period: %" PRIu64 " us\n", + (uint64_t) period); dev->callback += period; scsi_disk_set_callback(dev); return; @@ -482,9 +467,10 @@ scsi_disk_command_common(scsi_disk_t *dev) case 0x28: case 0xa8: /* Seek time is in us. */ - period = hdd_timing_read(dev->drv, dev->drv->seek_pos, dev->drv->seek_len); - scsi_disk_log("SCSI HD %i: Seek period: %" PRIu64 " us\n", - dev->id, (uint64_t) period); + period = hdd_timing_read(dev->drv, dev->drv->seek_pos, + dev->drv->seek_len); + scsi_disk_log(dev->log, "Seek period: %" PRIu64 " us\n", + (uint64_t) period); dev->callback += period; /* Account for seek time. */ bytes_per_second = scsi_bus_get_speed(dev->drv->scsi_id >> 4); @@ -499,10 +485,16 @@ scsi_disk_command_common(scsi_disk_t *dev) break; } + /* + For ATAPI, this will be 1000000.0 / µs_per_byte, and this will + convert it back to µs_per_byte. + */ period = 1000000.0 / bytes_per_second; - scsi_disk_log("SCSI HD %i: Byte transfer period: %" PRIu64 " us\n", dev->id, (uint64_t) period); + scsi_disk_log(dev->log, "Byte transfer period: %" PRIu64 " us\n", + (uint64_t) period); period = period * (double) (dev->packet_len); - scsi_disk_log("SCSI HD %i: Sector transfer period: %" PRIu64 " us\n", dev->id, (uint64_t) period); + scsi_disk_log(dev->log, "Sector transfer period: %" PRIu64 " us\n", + (uint64_t) period); dev->callback += period; } scsi_disk_set_callback(dev); @@ -543,16 +535,19 @@ scsi_disk_command_write_dma(scsi_disk_t *dev) scsi_disk_command_common(dev); } -/* id = Current ZIP device ID; +/* + dev = Pointer to current SCSI disk device; len = Total transfer length; block_len = Length of a single block (why does it matter?!); alloc_len = Allocated transfer length; - direction = Transfer direction (0 = read from host, 1 = write to host). */ + direction = Transfer direction (0 = read from host, 1 = write to host). + */ 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, const int block_len, + const int alloc_len, const 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, + scsi_disk_log(dev->log, "Finishing command (%02X): %i, %i, %i, %i, %i\n", + dev->current_cdb[0], len, block_len, alloc_len, direction, dev->tf->request_length); dev->tf->pos = 0; if (alloc_len >= 0) { @@ -560,13 +555,13 @@ scsi_disk_data_command_finish(scsi_disk_t *dev, int len, int block_len, int allo len = alloc_len; } if ((len == 0) || (scsi_disk_current_mode(dev) == 0)) { - if (dev->drv->bus != HDD_BUS_SCSI) + if (dev->drv->bus_type != HDD_BUS_SCSI) dev->packet_len = 0; scsi_disk_command_complete(dev); } else { if (scsi_disk_current_mode(dev) == 2) { - if (dev->drv->bus != HDD_BUS_SCSI) + if (dev->drv->bus_type != HDD_BUS_SCSI) dev->packet_len = alloc_len; if (direction == 0) @@ -575,34 +570,37 @@ scsi_disk_data_command_finish(scsi_disk_t *dev, int len, int block_len, int allo scsi_disk_command_write_dma(dev); } else { scsi_disk_update_request_length(dev, len, block_len); - if (direction == 0) + if ((dev->drv->bus_type != HDD_BUS_SCSI) && + (dev->tf->request_length == 0)) + scsi_disk_command_complete(dev); + else if (direction == 0) scsi_disk_command_read(dev); else scsi_disk_command_write(dev); } } - scsi_disk_log("SCSI HD %i: Status: %i, cylinder %i, packet length: %i, position: %i, phase: %i\n", - dev->id, dev->packet_status, dev->tf->request_length, dev->packet_len, dev->tf->pos, - dev->tf->phase); + scsi_disk_log(dev->log, "Status: %i, cylinder %i, packet length: %i, position: %i, " + "phase: %i\n", + dev->packet_status, dev->tf->request_length, dev->packet_len, + dev->tf->pos, dev->tf->phase); } static void scsi_disk_sense_clear(scsi_disk_t *dev, UNUSED(int command)) { scsi_disk_sense_key = scsi_disk_asc = scsi_disk_ascq = 0; + scsi_disk_info = 0x00000000; } static void -scsi_disk_set_phase(scsi_disk_t *dev, uint8_t phase) +scsi_disk_set_phase(const scsi_disk_t *dev, const uint8_t phase) { - uint8_t scsi_bus = (dev->drv->scsi_id >> 4) & 0x0f; - uint8_t scsi_id = dev->drv->scsi_id & 0x0f; + const uint8_t scsi_bus = (dev->drv->scsi_id >> 4) & 0x0f; + const uint8_t scsi_id = dev->drv->scsi_id & 0x0f; - if (dev->drv->bus != HDD_BUS_SCSI) - return; - - scsi_devices[scsi_bus][scsi_id].phase = phase; + if (dev->drv->bus_type == HDD_BUS_SCSI) + scsi_devices[scsi_bus][scsi_id].phase = phase; } static void @@ -615,15 +613,17 @@ scsi_disk_cmd_error(scsi_disk_t *dev) dev->packet_status = PHASE_ERROR; dev->callback = 50.0 * SCSI_TIME; scsi_disk_set_callback(dev); - ui_sb_update_icon(SB_HDD | dev->drv->bus, 0); - scsi_disk_log("SCSI HD %i: ERROR: %02X/%02X/%02X\n", dev->id, scsi_disk_sense_key, scsi_disk_asc, scsi_disk_ascq); + ui_sb_update_icon(SB_HDD | dev->drv->bus_type, 0); + ui_sb_update_icon_write(SB_HDD | dev->drv->bus_type, 0); + scsi_disk_log(dev->log, "ERROR: %02X/%02X/%02X\n", scsi_disk_sense_key, + scsi_disk_asc, scsi_disk_ascq); } static void scsi_disk_buf_alloc(scsi_disk_t *dev, uint32_t len) { - scsi_disk_log("SCSI HD %i: Allocated buffer length: %i\n", dev->id, len); - if (!dev->temp_buffer) + scsi_disk_log(dev->log, "Allocated buffer length: %i\n", len); + if (dev->temp_buffer == NULL) dev->temp_buffer = (uint8_t *) malloc(len); } @@ -631,7 +631,7 @@ static void scsi_disk_buf_free(scsi_disk_t *dev) { if (dev->temp_buffer) { - scsi_disk_log("SCSI HD %i: Freeing buffer...\n", dev->id); + scsi_disk_log(dev->log, "Freeing buffer...\n"); free(dev->temp_buffer); dev->temp_buffer = NULL; } @@ -644,6 +644,10 @@ scsi_disk_bus_master_error(scsi_common_t *sc) scsi_disk_buf_free(dev); scsi_disk_sense_key = scsi_disk_asc = scsi_disk_ascq = 0; + scsi_disk_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); scsi_disk_cmd_error(dev); } @@ -653,6 +657,10 @@ scsi_disk_write_error(scsi_disk_t *dev) scsi_disk_sense_key = SENSE_MEDIUM_ERROR; scsi_disk_asc = ASC_WRITE_ERROR; scsi_disk_ascq = 0; + scsi_disk_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); scsi_disk_cmd_error(dev); } @@ -662,25 +670,31 @@ scsi_disk_read_error(scsi_disk_t *dev) scsi_disk_sense_key = SENSE_MEDIUM_ERROR; scsi_disk_asc = ASC_UNRECOVERED_READ_ERROR; scsi_disk_ascq = 0; + scsi_disk_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); scsi_disk_cmd_error(dev); } static void -scsi_disk_invalid_lun(scsi_disk_t *dev) +scsi_disk_invalid_lun(scsi_disk_t *dev, const uint8_t lun) { scsi_disk_sense_key = SENSE_ILLEGAL_REQUEST; scsi_disk_asc = ASC_INV_LUN; scsi_disk_ascq = 0; scsi_disk_set_phase(dev, SCSI_PHASE_STATUS); + scsi_disk_info = lun << 24; scsi_disk_cmd_error(dev); } static void -scsi_disk_illegal_opcode(scsi_disk_t *dev) +scsi_disk_illegal_opcode(scsi_disk_t *dev, const uint8_t opcode) { scsi_disk_sense_key = SENSE_ILLEGAL_REQUEST; scsi_disk_asc = ASC_ILLEGAL_OPCODE; scsi_disk_ascq = 0; + scsi_disk_info = opcode << 24; scsi_disk_cmd_error(dev); } @@ -690,54 +704,72 @@ scsi_disk_lba_out_of_range(scsi_disk_t *dev) scsi_disk_sense_key = SENSE_ILLEGAL_REQUEST; scsi_disk_asc = ASC_LBA_OUT_OF_RANGE; scsi_disk_ascq = 0; + scsi_disk_info = (dev->sector_pos >> 24) | + ((dev->sector_pos >> 16) << 8) | + ((dev->sector_pos >> 8) << 16) | + ( dev->sector_pos << 24); scsi_disk_cmd_error(dev); } static void -scsi_disk_invalid_field(scsi_disk_t *dev) +scsi_disk_invalid_field(scsi_disk_t *dev, const uint32_t field) { scsi_disk_sense_key = SENSE_ILLEGAL_REQUEST; scsi_disk_asc = ASC_INV_FIELD_IN_CMD_PACKET; scsi_disk_ascq = 0; + scsi_disk_info = (field >> 24) | + ((field >> 16) << 8) | + ((field >> 8) << 16) | + ( field << 24); scsi_disk_cmd_error(dev); dev->tf->status = 0x53; } static void -scsi_disk_invalid_field_pl(scsi_disk_t *dev) +scsi_disk_invalid_field_pl(scsi_disk_t *dev, const uint32_t field) { scsi_disk_sense_key = SENSE_ILLEGAL_REQUEST; scsi_disk_asc = ASC_INV_FIELD_IN_PARAMETER_LIST; scsi_disk_ascq = 0; + scsi_disk_info = (field >> 24) | + ((field >> 16) << 8) | + ((field >> 8) << 16) | + ( field << 24); scsi_disk_cmd_error(dev); dev->tf->status = 0x53; } static void -scsi_disk_data_phase_error(scsi_disk_t *dev) +scsi_disk_data_phase_error(scsi_disk_t *dev, const uint32_t info) { scsi_disk_sense_key = SENSE_ILLEGAL_REQUEST; scsi_disk_asc = ASC_DATA_PHASE_ERROR; scsi_disk_ascq = 0; + scsi_disk_info = (info >> 24) | + ((info >> 16) << 8) | + ((info >> 8) << 16) | + ( info << 24); scsi_disk_cmd_error(dev); } static int -scsi_disk_blocks(scsi_disk_t *dev, int32_t *len, UNUSED(int first_batch), int out) +scsi_disk_blocks(scsi_disk_t *dev, int32_t *len, UNUSED(int first_batch), const int out) { + const uint32_t medium_size = hdd_image_get_last_sector(dev->id) + 1; + *len = 0; - uint32_t medium_size = hdd_image_get_last_sector(dev->id) + 1; if (!dev->sector_len) { scsi_disk_command_complete(dev); return -1; } - scsi_disk_log("%sing %i blocks starting from %i...\n", out ? "Writ" : "Read", + scsi_disk_log(dev->log, "%sing %i blocks starting from %i...\n", out ? "Writ" : "Read", dev->requested_blocks, dev->sector_pos); if (dev->sector_pos >= medium_size) { - scsi_disk_log("SCSI HD %i: Trying to %s beyond the end of disk\n", dev->id, out ? "write" : "read"); + scsi_disk_log(dev->log, "Trying to %s beyond the end of disk\n", + out ? "write" : "read"); scsi_disk_lba_out_of_range(dev); return 0; } @@ -746,68 +778,90 @@ scsi_disk_blocks(scsi_disk_t *dev, int32_t *len, UNUSED(int first_batch), int ou for (int i = 0; i < dev->requested_blocks; i++) { if (out) { - if (hdd_image_write(dev->id, dev->sector_pos + i, 1, dev->temp_buffer + (i << 9)) < 0) { + if (hdd_image_write(dev->id, dev->sector_pos, 1, dev->temp_buffer + + (i << 9)) < 0) { scsi_disk_write_error(dev); return -1; } } else { - if (hdd_image_read(dev->id, dev->sector_pos + i, 1, dev->temp_buffer + (i << 9)) < 0) { + if (hdd_image_read(dev->id, dev->sector_pos, 1, dev->temp_buffer + + (i << 9)) < 0) { scsi_disk_read_error(dev); return -1; } } + dev->sector_pos++; } - scsi_disk_log("%s %i bytes of blocks...\n", out ? "Written" : "Read", *len); + scsi_disk_log(dev->log, "%s %i bytes of blocks...\n", out ? "Written" : "Read", *len); - dev->sector_pos += dev->requested_blocks; dev->sector_len -= dev->requested_blocks; return 1; } static int -scsi_disk_pre_execution_check(scsi_disk_t *dev, uint8_t *cdb) +scsi_disk_pre_execution_check(scsi_disk_t *dev, const uint8_t *cdb) { - if ((cdb[0] != GPCMD_REQUEST_SENSE) && (dev->cur_lun == SCSI_LUN_USE_CDB) && (cdb[1] & 0xe0)) { - scsi_disk_log("SCSI HD %i: Attempting to execute a unknown command targeted at SCSI LUN %i\n", - dev->id, ((dev->tf->request_length >> 5) & 7)); - scsi_disk_invalid_lun(dev); + if ((cdb[0] != GPCMD_REQUEST_SENSE) && (dev->cur_lun == SCSI_LUN_USE_CDB) && + (cdb[1] & 0xe0)) { + scsi_disk_log(dev->log, "Attempting to execute a unknown command " + "targeted at SCSI LUN %i\n", + ((dev->tf->request_length >> 5) & 7)); + scsi_disk_invalid_lun(dev, cdb[1] >> 5); return 0; } if (!(scsi_disk_command_flags[cdb[0]] & IMPLEMENTED)) { - scsi_disk_log("SCSI HD %i: Attempting to execute unknown command %02X over %s\n", dev->id, cdb[0], - (dev->drv->bus == HDD_BUS_SCSI) ? "SCSI" : "ATAPI"); - scsi_disk_illegal_opcode(dev); + scsi_disk_log(dev->log, "Attempting to execute unknown " + "command %02X over %s\n", cdb[0], + (dev->drv->bus_type == HDD_BUS_SCSI) ? "SCSI" : "ATAPI"); + scsi_disk_illegal_opcode(dev, cdb[0]); return 0; } - /* Unless the command is REQUEST SENSE, clear the sense. This will *NOT* - the UNIT ATTENTION condition if it's set. */ + if ((dev->drv->bus_type < HDD_BUS_SCSI) && + (scsi_disk_command_flags[cdb[0]] & SCSI_ONLY)) { + scsi_disk_log(dev->log, "Attempting to execute SCSI-only command %02X " + "over ATAPI\n", cdb[0]); + scsi_disk_illegal_opcode(dev, cdb[0]); + return 0; + } + + if ((dev->drv->bus_type == HDD_BUS_SCSI) && + (scsi_disk_command_flags[cdb[0]] & ATAPI_ONLY)) { + scsi_disk_log(dev->log, "Attempting to execute ATAPI-only command %02X " + "over SCSI\n", cdb[0]); + scsi_disk_illegal_opcode(dev, cdb[0]); + return 0; + } + + /* + Unless the command is REQUEST SENSE, clear the sense. This will *NOT* + the UNIT ATTENTION condition if it's set. + */ if (cdb[0] != GPCMD_REQUEST_SENSE) scsi_disk_sense_clear(dev, cdb[0]); - scsi_disk_log("SCSI HD %i: Continuing with command\n", dev->id); + scsi_disk_log(dev->log, "Continuing with command %02X\n", cdb[0]); return 1; } static void -scsi_disk_seek(scsi_disk_t *dev, uint32_t pos) +scsi_disk_seek(const scsi_disk_t *dev, const uint32_t pos) { - /* scsi_disk_log("SCSI HD %i: Seek %08X\n", dev->id, pos); */ + /* scsi_disk_log(dev->log, "Seek %08X\n", pos); */ hdd_image_seek(dev->id, pos); } static void scsi_disk_rezero(scsi_disk_t *dev) { - if (dev->id == 0xff) - return; - - dev->sector_pos = dev->sector_len = 0; - scsi_disk_seek(dev, 0); + if (dev->id != 0xff) { + dev->sector_pos = dev->sector_len = 0; + scsi_disk_seek(dev, 0); + } } void @@ -824,34 +878,38 @@ scsi_disk_reset(scsi_common_t *sc) dev->packet_status = PHASE_NONE; dev->unit_attention = 0; dev->cur_lun = SCSI_LUN_USE_CDB; + scsi_disk_sense_key = scsi_disk_asc = scsi_disk_ascq = dev->unit_attention = 0; + scsi_disk_info = 0x00; } void -scsi_disk_request_sense(scsi_disk_t *dev, uint8_t *buffer, uint8_t alloc_length, int desc) +scsi_disk_request_sense(scsi_disk_t *dev, uint8_t *buffer, + const uint8_t alloc_length, const int desc) { - /*Will return 18 bytes of 0*/ + /* Will return 18 bytes of 0. */ if (alloc_length != 0) { memset(buffer, 0, alloc_length); - if (!desc) - memcpy(buffer, dev->sense, alloc_length); - else { + if (desc) { buffer[1] = scsi_disk_sense_key; buffer[2] = scsi_disk_asc; buffer[3] = scsi_disk_ascq; - } - } else - return; + } else + memcpy(buffer, dev->sense, alloc_length); - buffer[0] = 0x70; + buffer[0] = desc ? 0x70 : 0xf0; + buffer[7] = 10; - scsi_disk_log("SCSI HD %i: Reporting sense: %02X %02X %02X\n", dev->id, buffer[2], buffer[12], buffer[13]); + scsi_disk_log(dev->log, "Reporting sense: %02X %02X %02X\n", + buffer[2], buffer[12], buffer[13]); - /* Clear the sense stuff as per the spec. */ - scsi_disk_sense_clear(dev, GPCMD_REQUEST_SENSE); + /* Clear the sense stuff as per the spec. */ + scsi_disk_sense_clear(dev, GPCMD_REQUEST_SENSE); + } } static void -scsi_disk_request_sense_for_scsi(scsi_common_t *sc, uint8_t *buffer, uint8_t alloc_length) +scsi_disk_request_sense_for_scsi(scsi_common_t *sc, uint8_t *buffer, + const uint8_t alloc_length) { scsi_disk_t *dev = (scsi_disk_t *) sc; @@ -859,41 +917,42 @@ 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(const scsi_disk_t *dev, int32_t *BufLen, int32_t *src_len) { - if (dev->drv->bus == HDD_BUS_SCSI) { + if (dev->drv->bus_type == HDD_BUS_SCSI) { if (*BufLen == -1) *BufLen = *src_len; else { *BufLen = MIN(*src_len, *BufLen); *src_len = *BufLen; } - scsi_disk_log("SCSI HD %i: Actual transfer length: %i\n", dev->id, *BufLen); + scsi_disk_log(dev->log, "Actual transfer length: %i\n", *BufLen); } } static void -scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) +scsi_disk_command(scsi_common_t *sc, const uint8_t *cdb) { - scsi_disk_t *dev = (scsi_disk_t *) sc; - int ret; - int32_t blen = 0; - int32_t *BufLen; - int32_t len; - int32_t max_len; - int32_t alloc_length; - int pos = 0; - int idx = 0; - 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 }; - int block_desc = 0; - uint8_t scsi_bus = (dev->drv->scsi_id >> 4) & 0x0f; - uint8_t scsi_id = dev->drv->scsi_id & 0x0f; + 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 }; + scsi_disk_t * dev = (scsi_disk_t *) sc; + const uint32_t last_sector = hdd_image_get_last_sector(dev->id); + const uint8_t scsi_bus = (dev->drv->scsi_id >> 4) & 0x0f; + const uint8_t scsi_id = dev->drv->scsi_id & 0x0f; + int32_t blen = 0; + int pos = 0; + int idx = 0; + int block_desc; + int ret; + int32_t * BufLen; + int32_t len; + int32_t max_len; + int32_t alloc_length; + unsigned size_idx; + unsigned preamble_len; - if (dev->drv->bus == HDD_BUS_SCSI) { + if (dev->drv->bus_type == HDD_BUS_SCSI) { BufLen = &scsi_devices[scsi_bus][scsi_id].buffer_length; dev->tf->status &= ~ERR_STAT; } else { @@ -901,8 +960,6 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) dev->tf->error = 0; } - last_sector = hdd_image_get_last_sector(dev->id); - dev->packet_len = 0; dev->request_pos = 0; @@ -918,11 +975,12 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) memcpy(dev->current_cdb, cdb, 12); if (cdb[0] != 0) { - scsi_disk_log("SCSI HD %i: Command 0x%02X, Sense Key %02X, Asc %02X, Ascq %02X\n", - dev->id, cdb[0], scsi_disk_sense_key, scsi_disk_asc, scsi_disk_ascq); - scsi_disk_log("SCSI HD %i: Request length: %04X\n", dev->id, dev->tf->request_length); + scsi_disk_log(dev->log, "Command 0x%02X, Sense Key %02X, Asc %02X, Ascq %02X\n", + cdb[0], scsi_disk_sense_key, scsi_disk_asc, scsi_disk_ascq); + scsi_disk_log(dev->log, "Request length: %04X\n", dev->tf->request_length); - scsi_disk_log("SCSI HD %i: CDB: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n", dev->id, + scsi_disk_log(dev->log, "CDB: %02X %02X %02X %02X %02X %02X %02X %02X " + "%02X %02X %02X %02X\n", cdb[0], cdb[1], cdb[2], cdb[3], cdb[4], cdb[5], cdb[6], cdb[7], cdb[8], cdb[9], cdb[10], cdb[11]); } @@ -931,14 +989,17 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) scsi_disk_set_phase(dev, SCSI_PHASE_STATUS); - /* This handles the Not Ready/Unit Attention check if it has to be handled at this point. */ + /* + This handles the Not Ready/Unit Attention check if it has to be + handled at this point. + */ if (scsi_disk_pre_execution_check(dev, cdb) == 0) return; switch (cdb[0]) { case GPCMD_SEND_DIAGNOSTIC: if (!(cdb[1] & (1 << 2))) { - scsi_disk_invalid_field(dev); + scsi_disk_invalid_field(dev, cdb[1]); return; } fallthrough; @@ -961,9 +1022,6 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) break; case GPCMD_REQUEST_SENSE: - /* If there's a unit attention condition and there's a buffered not - ready, a standalone REQUEST SENSE should forget about the not - ready, and report unit attention straight away. */ len = cdb[4]; if (!len) { @@ -977,14 +1035,11 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) scsi_disk_buf_alloc(dev, 256); scsi_disk_set_buf_len(dev, BufLen, &len); - if (*BufLen < cdb[4]) - cdb[4] = *BufLen; - len = (cdb[1] & 1) ? 8 : 18; scsi_disk_request_sense(dev, dev->temp_buffer, *BufLen, cdb[1] & 1); scsi_disk_set_phase(dev, SCSI_PHASE_DATA_IN); - scsi_disk_data_command_finish(dev, len, len, cdb[4], 0); + scsi_disk_data_command_finish(dev, len, len, *BufLen, 0); break; case GPCMD_MECHANISM_STATUS: @@ -1020,12 +1075,15 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) break; case GPCMD_READ_10: dev->sector_len = (cdb[7] << 8) | cdb[8]; - dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; + dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | + (cdb[4] << 8) | cdb[5]; break; case GPCMD_READ_12: - dev->sector_len = (((uint32_t) cdb[6]) << 24) | (((uint32_t) cdb[7]) << 16) | + 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) | + dev->sector_pos = (((uint32_t) cdb[2]) << 24) | + (((uint32_t) cdb[3]) << 16) | (((uint32_t) cdb[4]) << 8) | ((uint32_t) cdb[5]); break; @@ -1033,54 +1091,47 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) break; } - if (dev->sector_pos > last_sector) { + if (dev->sector_pos > last_sector) scsi_disk_lba_out_of_range(dev); - return; + else { + if (dev->sector_len) { + max_len = dev->sector_len; + dev->requested_blocks = max_len; + + dev->packet_len = max_len * alloc_length; + scsi_disk_buf_alloc(dev, dev->packet_len); + + dev->drv->seek_pos = dev->sector_pos; + dev->drv->seek_len = dev->sector_len; + + ret = scsi_disk_blocks(dev, &alloc_length, 1, 0); + alloc_length = dev->requested_blocks * 512; + + if (ret > 0) { + dev->requested_blocks = max_len; + dev->packet_len = alloc_length; + + scsi_disk_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); + + scsi_disk_data_command_finish(dev, alloc_length, 512, alloc_length, 0); + + ui_sb_update_icon(SB_HDD | dev->drv->bus_type, dev->packet_status != PHASE_COMPLETE); + } else { + scsi_disk_set_phase(dev, SCSI_PHASE_STATUS); + dev->packet_status = (ret < 0) ? PHASE_ERROR : PHASE_COMPLETE; + dev->callback = 20.0 * SCSI_TIME; + scsi_disk_set_callback(dev); + scsi_disk_buf_free(dev); + } + } else { + scsi_disk_set_phase(dev, SCSI_PHASE_STATUS); + scsi_disk_log(dev->log, "All done - callback set\n"); + dev->packet_status = PHASE_COMPLETE; + dev->callback = 20.0 * SCSI_TIME; + scsi_disk_set_callback(dev); + } } - - if (!dev->sector_len) { - scsi_disk_set_phase(dev, SCSI_PHASE_STATUS); - scsi_disk_log("SCSI HD %i: All done - callback set\n", dev->id); - dev->packet_status = PHASE_COMPLETE; - dev->callback = 20.0 * SCSI_TIME; - scsi_disk_set_callback(dev); - break; - } - - max_len = dev->sector_len; - /* - If we're reading all blocks in one go for DMA, why not also for - PIO, it should NOT matter anyway, this step should be identical - and only the way the read dat is transferred to the host should - be different. - */ - dev->requested_blocks = max_len; - - dev->packet_len = max_len * alloc_length; - scsi_disk_buf_alloc(dev, dev->packet_len); - - dev->drv->seek_pos = dev->sector_pos; - dev->drv->seek_len = dev->sector_len; - - ret = scsi_disk_blocks(dev, &alloc_length, 1, 0); - if (ret <= 0) { - scsi_disk_set_phase(dev, SCSI_PHASE_STATUS); - dev->packet_status = (ret < 0) ? PHASE_ERROR : PHASE_COMPLETE; - dev->callback = 20.0 * SCSI_TIME; - scsi_disk_set_callback(dev); - scsi_disk_buf_free(dev); - return; - } - - dev->requested_blocks = max_len; - dev->packet_len = alloc_length; - - scsi_disk_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); - - scsi_disk_data_command_finish(dev, alloc_length, 512, alloc_length, 0); - - ui_sb_update_icon(SB_HDD | dev->drv->bus, dev->packet_status != PHASE_COMPLETE); - return; + break; case GPCMD_VERIFY_6: case GPCMD_VERIFY_10: @@ -1111,23 +1162,26 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) dev->sector_len = 256; dev->sector_pos = ((((uint32_t) cdb[1]) & 0x1f) << 16) | (((uint32_t) cdb[2]) << 8) | ((uint32_t) cdb[3]); - scsi_disk_log("SCSI HD %i: Length: %i, LBA: %i\n", dev->id, + scsi_disk_log(dev->log, "Length: %i, LBA: %i\n", dev->sector_len, dev->sector_pos); break; case GPCMD_VERIFY_10: case GPCMD_WRITE_10: case GPCMD_WRITE_AND_VERIFY_10: dev->sector_len = (cdb[7] << 8) | cdb[8]; - dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; - scsi_disk_log("SCSI HD %i: Length: %i, LBA: %i\n", dev->id, + dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | + (cdb[4] << 8) | cdb[5]; + scsi_disk_log(dev->log, "Length: %i, LBA: %i\n", dev->sector_len, dev->sector_pos); break; case GPCMD_VERIFY_12: case GPCMD_WRITE_12: case GPCMD_WRITE_AND_VERIFY_12: - dev->sector_len = (((uint32_t) cdb[6]) << 24) | (((uint32_t) cdb[7]) << 16) | + 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) | + dev->sector_pos = (((uint32_t) cdb[2]) << 24) | + (((uint32_t) cdb[3]) << 16) | (((uint32_t) cdb[4]) << 8) | ((uint32_t) cdb[5]); break; @@ -1135,90 +1189,79 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) break; } - if (dev->sector_pos > last_sector) { + if (dev->sector_pos > last_sector) scsi_disk_lba_out_of_range(dev); - return; + else { + if (dev->sector_len) { + dev->drv->seek_pos = dev->sector_pos; + dev->drv->seek_len = dev->sector_len; + + max_len = dev->sector_len; + dev->requested_blocks = max_len; + + dev->packet_len = max_len * alloc_length; + scsi_disk_buf_alloc(dev, dev->packet_len); + + dev->requested_blocks = max_len; + dev->packet_len = max_len << 9; + + scsi_disk_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); + + scsi_disk_data_command_finish(dev, dev->packet_len, 512, dev->packet_len, 1); + + ui_sb_update_icon_write(SB_HDD | dev->drv->bus_type, dev->packet_status != PHASE_COMPLETE); + } else { + scsi_disk_set_phase(dev, SCSI_PHASE_STATUS); + scsi_disk_log(dev->log, "All done - callback set\n"); + dev->packet_status = PHASE_COMPLETE; + dev->callback = 20.0 * SCSI_TIME; + scsi_disk_set_callback(dev); + } } - - if (!dev->sector_len) { - scsi_disk_set_phase(dev, SCSI_PHASE_STATUS); - scsi_disk_log("SCSI HD %i: All done - callback set\n", dev->id); - dev->packet_status = PHASE_COMPLETE; - dev->callback = 20.0 * SCSI_TIME; - scsi_disk_set_callback(dev); - break; - } - - dev->drv->seek_pos = dev->sector_pos; - dev->drv->seek_len = dev->sector_len; - - max_len = dev->sector_len; - /* - If we're writing all blocks in one go for DMA, why not also for - PIO, it should NOT matter anyway, this step should be identical - and only the way the read dat is transferred to the host should - be different. - */ - dev->requested_blocks = max_len; - - dev->packet_len = max_len * alloc_length; - scsi_disk_buf_alloc(dev, dev->packet_len); - - dev->requested_blocks = max_len; - dev->packet_len = max_len << 9; - - scsi_disk_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); - - scsi_disk_data_command_finish(dev, dev->packet_len, 512, dev->packet_len, 1); - - ui_sb_update_icon(SB_HDD | dev->drv->bus, dev->packet_status != PHASE_COMPLETE); - return; + break; case GPCMD_WRITE_SAME_10: alloc_length = 512; - if ((cdb[1] & 6) == 6) { - scsi_disk_invalid_field(dev); - return; + if ((cdb[1] & 6) == 6) + scsi_disk_invalid_field(dev, cdb[1]); + else { + dev->sector_len = (cdb[7] << 8) | cdb[8]; + dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; + + if (dev->sector_pos > last_sector) + scsi_disk_lba_out_of_range(dev); + else { + if (dev->sector_len) { + scsi_disk_buf_alloc(dev, alloc_length); + scsi_disk_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); + + dev->requested_blocks = 1; + + dev->packet_len = alloc_length; + + scsi_disk_set_phase(dev, SCSI_PHASE_DATA_OUT); + + scsi_disk_data_command_finish(dev, 512, 512, alloc_length, 1); + + ui_sb_update_icon_write(SB_HDD | dev->drv->bus_type, + dev->packet_status != PHASE_COMPLETE); + } else { + scsi_disk_set_phase(dev, SCSI_PHASE_STATUS); + scsi_disk_log(dev->log, "All done - callback set\n"); + dev->packet_status = PHASE_COMPLETE; + dev->callback = 20.0 * SCSI_TIME; + scsi_disk_set_callback(dev); + } + } } - - dev->sector_len = (cdb[7] << 8) | cdb[8]; - dev->sector_pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; - - if (dev->sector_pos > last_sector) { - scsi_disk_lba_out_of_range(dev); - return; - } - - if (!dev->sector_len) { - scsi_disk_set_phase(dev, SCSI_PHASE_STATUS); - scsi_disk_log("SCSI HD %i: All done - callback set\n", dev->id); - dev->packet_status = PHASE_COMPLETE; - dev->callback = 20.0 * SCSI_TIME; - scsi_disk_set_callback(dev); - break; - } - - scsi_disk_buf_alloc(dev, alloc_length); - scsi_disk_set_buf_len(dev, BufLen, (int32_t *) &dev->packet_len); - - max_len = 1; - dev->requested_blocks = 1; - - dev->packet_len = alloc_length; - - scsi_disk_set_phase(dev, SCSI_PHASE_DATA_OUT); - - scsi_disk_data_command_finish(dev, 512, 512, alloc_length, 1); - - ui_sb_update_icon(SB_HDD | dev->drv->bus, dev->packet_status != PHASE_COMPLETE); - return; + break; case GPCMD_MODE_SENSE_6: case GPCMD_MODE_SENSE_10: scsi_disk_set_phase(dev, SCSI_PHASE_DATA_IN); - if (dev->drv->bus == HDD_BUS_SCSI) + if (dev->drv->bus_type == HDD_BUS_SCSI) block_desc = ((cdb[1] >> 3) & 1) ? 0 : 1; else block_desc = 0; @@ -1235,7 +1278,8 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) alloc_length = len; if (cdb[0] == GPCMD_MODE_SENSE_6) { - len = scsi_disk_mode_sense(dev, dev->temp_buffer, 4, cdb[2], block_desc); + len = scsi_disk_mode_sense(dev, dev->temp_buffer, 4, + cdb[2], block_desc); if (len > alloc_length) len = alloc_length; dev->temp_buffer[0] = len - 1; @@ -1261,10 +1305,10 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) alloc_length = len; scsi_disk_set_buf_len(dev, BufLen, &alloc_length); - scsi_disk_log("SCSI HDD %i: Reading mode page: %02X...\n", dev->id, cdb[2]); + scsi_disk_log(dev->log, "Reading mode page: %02X...\n", cdb[2]); scsi_disk_data_command_finish(dev, len, len, alloc_length, 0); - return; + break; case GPCMD_MODE_SELECT_6: case GPCMD_MODE_SELECT_10: @@ -1282,7 +1326,7 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) dev->total_length = len; dev->do_page_save = cdb[1] & 1; scsi_disk_data_command_finish(dev, len, len, len, 1); - return; + break; case GPCMD_INQUIRY: max_len = cdb[3]; @@ -1291,7 +1335,7 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) if ((!max_len) || (*BufLen == 0)) { scsi_disk_set_phase(dev, SCSI_PHASE_STATUS); - /* scsi_disk_log("SCSI HD %i: All done - callback set\n", dev->id); */ + /* scsi_disk_log(dev->log, "All done - callback set\n"); */ dev->packet_status = PHASE_COMPLETE; dev->callback = 20.0 * SCSI_TIME; break; @@ -1317,7 +1361,7 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) case 0x83: if (idx + 24 > max_len) { scsi_disk_buf_free(dev); - scsi_disk_data_phase_error(dev); + scsi_disk_data_phase_error(dev, idx + 24); return; } @@ -1325,7 +1369,8 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) dev->temp_buffer[idx++] = 0x00; dev->temp_buffer[idx++] = 0x00; dev->temp_buffer[idx++] = 20; - ide_padstr8(dev->temp_buffer + idx, 20, "53R141"); /* Serial */ + /* Serial */ + ide_padstr8(dev->temp_buffer + idx, 20, "53R141"); idx += 20; if (idx + 72 > cdb[4]) @@ -1334,16 +1379,19 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) dev->temp_buffer[idx++] = 0x01; dev->temp_buffer[idx++] = 0x00; dev->temp_buffer[idx++] = 68; - ide_padstr8(dev->temp_buffer + idx, 8, EMU_NAME); /* Vendor */ + /* Vendor */ + ide_padstr8(dev->temp_buffer + idx, 8, EMU_NAME); idx += 8; - ide_padstr8(dev->temp_buffer + idx, 40, device_identify_ex); /* Product */ + /* Product */ + ide_padstr8(dev->temp_buffer + idx, 40, device_identify_ex); idx += 40; - ide_padstr8(dev->temp_buffer + idx, 20, "53R141"); /* Product */ + /* Product */ + ide_padstr8(dev->temp_buffer + idx, 20, "53R141"); idx += 20; break; default: - scsi_disk_log("INQUIRY: Invalid page: %02X\n", cdb[2]); - scsi_disk_invalid_field(dev); + scsi_disk_log(dev->log, "INQUIRY: Invalid page: %02X\n", cdb[2]); + scsi_disk_invalid_field(dev, cdb[2]); scsi_disk_buf_free(dev); return; } @@ -1353,19 +1401,23 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) memset(dev->temp_buffer, 0, 8); if ((cdb[1] & 0xe0) || ((dev->cur_lun > 0x00) && (dev->cur_lun < 0xff))) - dev->temp_buffer[0] = 0x7f; /*No physical device on this LUN*/ + dev->temp_buffer[0] = 0x7f; /* No physical device on this LUN */ else - dev->temp_buffer[0] = 0; /*SCSI HD*/ - dev->temp_buffer[1] = 0; /*Fixed*/ - dev->temp_buffer[2] = (dev->drv->bus == HDD_BUS_SCSI) ? 0x02 : 0x00; /*SCSI-2 compliant*/ - dev->temp_buffer[3] = (dev->drv->bus == HDD_BUS_SCSI) ? 0x02 : 0x21; + dev->temp_buffer[0] = 0; /* SCSI HD */ + dev->temp_buffer[1] = 0; /* Fixed */ + /* SCSI-2 compliant */ + dev->temp_buffer[2] = (dev->drv->bus_type == HDD_BUS_SCSI) ? 0x02 : 0x00; + dev->temp_buffer[3] = (dev->drv->bus_type == HDD_BUS_SCSI) ? 0x02 : 0x21; dev->temp_buffer[4] = 31; - dev->temp_buffer[6] = 1; /* 16-bit transfers supported */ - dev->temp_buffer[7] = 0x20; /* Wide bus supported */ + dev->temp_buffer[6] = 1; /* 16-bit transfers supported */ + dev->temp_buffer[7] = 0x20; /* Wide bus supported */ - ide_padstr8(dev->temp_buffer + 8, 8, EMU_NAME); /* Vendor */ - ide_padstr8(dev->temp_buffer + 16, 16, device_identify); /* Product */ - ide_padstr8(dev->temp_buffer + 32, 4, EMU_VERSION_EX); /* Revision */ + /* Vendor */ + ide_padstr8(dev->temp_buffer + 8, 8, EMU_NAME); + /* Product */ + ide_padstr8(dev->temp_buffer + 16, 16, device_identify); + /* Revision */ + ide_padstr8(dev->temp_buffer + 32, 4, EMU_VERSION_EX); idx = 36; if (max_len == 96) { @@ -1437,12 +1489,12 @@ atapi_out: break; default: - scsi_disk_illegal_opcode(dev); + scsi_disk_illegal_opcode(dev, cdb[0]); break; } - /* scsi_disk_log("SCSI HD %i: Phase: %02X, request length: %i\n", dev->id, dev->tf->phase, - dev->tf->request_length); */ + /* scsi_disk_log(dev->log, "Phase: %02X, request length: %i\n", + dev->tf->phase, dev->tf->request_length); */ if ((dev->packet_status == PHASE_COMPLETE) || (dev->packet_status == PHASE_ERROR)) scsi_disk_buf_free(dev); @@ -1460,35 +1512,30 @@ 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; + scsi_disk_t *dev = (scsi_disk_t *) sc; + const uint8_t scsi_bus = (dev->drv->scsi_id >> 4) & 0x0f; + const uint8_t scsi_id = dev->drv->scsi_id & 0x0f; + const int32_t *BufLen = &scsi_devices[scsi_bus][scsi_id].buffer_length; + const uint32_t last_sector = hdd_image_get_last_sector(dev->id); + int len = 0; + uint8_t error = 0; + int ret = 1; 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; - int len = 0; - uint32_t last_to_write = 0; + uint32_t last_to_write; 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) { + if (!*BufLen) scsi_disk_set_phase(dev, SCSI_PHASE_STATUS); + else switch (dev->current_cdb[0]) { + default: + log_fatal(dev->log, "Bad Command for phase 2 (%02X)\n", dev->current_cdb[0]); + ret = 0; + break; - return 1; - } - - switch (dev->current_cdb[0]) { case GPCMD_VERIFY_6: case GPCMD_VERIFY_10: case GPCMD_VERIFY_12: @@ -1514,9 +1561,9 @@ scsi_disk_phase_data_out(scsi_common_t *sc) dev->temp_buffer[2] = (i >> 8) & 0xff; dev->temp_buffer[3] = i & 0xff; } else if (dev->current_cdb[1] & 4) { - s = (i % dev->drv->spt); - h = ((i - s) / dev->drv->spt) % dev->drv->hpc; - c = ((i - s) / dev->drv->spt) / dev->drv->hpc; + uint32_t s = (i % dev->drv->spt); + uint32_t h = ((i - s) / dev->drv->spt) % dev->drv->hpc; + uint32_t c = ((i - s) / dev->drv->spt) / dev->drv->hpc; dev->temp_buffer[0] = (c >> 16) & 0xff; dev->temp_buffer[1] = (c >> 8) & 0xff; dev->temp_buffer[2] = c & 0xff; @@ -1542,7 +1589,7 @@ scsi_disk_phase_data_out(scsi_common_t *sc) param_list_len = dev->current_cdb[4]; } - if (dev->drv->bus == HDD_BUS_SCSI) { + if (dev->drv->bus_type == HDD_BUS_SCSI) { if (dev->current_cdb[0] == GPCMD_MODE_SELECT_6) { block_desc_len = dev->temp_buffer[2]; block_desc_len <<= 8; @@ -1559,27 +1606,29 @@ scsi_disk_phase_data_out(scsi_common_t *sc) while (1) { if (pos >= param_list_len) { - scsi_disk_log("SCSI HD %i: Buffer has only block descriptor\n", dev->id); + scsi_disk_log(dev->log, "Buffer has only block descriptor\n"); break; } - page = dev->temp_buffer[pos] & 0x3F; - page_len = dev->temp_buffer[pos + 1]; + const uint8_t page = dev->temp_buffer[pos] & 0x3f; + const uint8_t page_len = dev->temp_buffer[pos + 1]; pos += 2; if (!(scsi_disk_mode_sense_page_flags & (1LL << ((uint64_t) page)))) error |= 1; - else { - for (i = 0; i < page_len; i++) { - ch = scsi_disk_mode_sense_pages_changeable.pages[page][i + 2]; - val = dev->temp_buffer[pos + i]; - old_val = dev->ms_pages_saved.pages[page][i + 2]; - if (val != old_val) { - if (ch) - dev->ms_pages_saved.pages[page][i + 2] = val; - else - error |= 1; + else for (i = 0; i < page_len; i++) { + const uint8_t old = dev->ms_pages_saved.pages[page][i + 2]; + const uint8_t ch = scsi_disk_mode_sense_pages_changeable.pages[page][i + 2]; + + val = dev->temp_buffer[pos + i]; + + if (val != old) { + if (ch) + dev->ms_pages_saved.pages[page][i + 2] = val; + else { + scsi_disk_invalid_field_pl(dev, val); + error |= 1; } } } @@ -1594,22 +1643,17 @@ scsi_disk_phase_data_out(scsi_common_t *sc) break; } - if (error) { + if (error) scsi_disk_buf_free(dev); - scsi_disk_invalid_field_pl(dev); - } - break; - default: - fatal("SCSI HDD %i: Bad Command for phase 2 (%02X)\n", dev->id, dev->current_cdb[0]); break; } scsi_disk_command_stop((scsi_common_t *) dev); - return 1; + return ret; } static int -scsi_disk_get_max(int ide_has_dma, int type) +scsi_disk_get_max(UNUSED(const ide_t *ide), int ide_has_dma, const int type) { int ret; @@ -1635,7 +1679,7 @@ scsi_disk_get_max(int ide_has_dma, int type) } static int -scsi_disk_get_timings(int ide_has_dma, int type) +scsi_disk_get_timings(UNUSED(const ide_t *ide), const int ide_has_dma, const int type) { int ret; @@ -1657,29 +1701,28 @@ scsi_disk_get_timings(int ide_has_dma, int type) return ret; } -/** - * Fill in ide->buffer with the output of the "IDENTIFY PACKET DEVICE" command +/* + Fill in ide->buffer with the output of the "IDENTIFY PACKET DEVICE" command */ static void -scsi_disk_identify(ide_t *ide, int ide_has_dma) +scsi_disk_identify(const ide_t *ide, const int ide_has_dma) { - const scsi_disk_t *dev; - char device_identify[9] = { '8', '6', 'B', '_', 'H', 'D', '0', '0', 0 }; - - dev = (scsi_disk_t *) ide->sc; + const scsi_disk_t *dev = (scsi_disk_t *) ide->sc; + char device_identify[9] = { '8', '6', 'B', '_', 'H', 'D', '0', '0', 0 }; device_identify[7] = dev->id + 0x30; - scsi_disk_log("ATAPI Identify: %s\n", device_identify); + scsi_disk_log(dev->log, "ATAPI Identify: %s\n", device_identify); /* ATAPI device, direct-access device, non-removable media, accelerated DRQ */ ide->buffer[0] = 0x8000 | (0 << 8) | 0x00 | (2 << 5); - ide_padstr((char *) (ide->buffer + 10), "", 20); /* Serial Number */ + ide_padstr((char *) (ide->buffer + 10), "", 20); /* Serial Number */ - ide_padstr((char *) (ide->buffer + 23), EMU_VERSION_EX, 8); /* Firmware */ - ide_padstr((char *) (ide->buffer + 27), device_identify, 40); /* Model */ + ide_padstr((char *) (ide->buffer + 23), EMU_VERSION_EX, 8); /* Firmware */ + ide_padstr((char *) (ide->buffer + 27), device_identify, 40); /* Model */ - ide->buffer[49] = 0x200; /* LBA supported */ - ide->buffer[126] = 0xfffe; /* Interpret zero byte count limit as maximum length */ + ide->buffer[49] = 0x200; /* LBA supported */ + /* Interpret zero byte count limit as maximum length. */ + ide->buffer[126] = 0xfffe; if (ide_has_dma) { ide->buffer[71] = 30; @@ -1693,19 +1736,13 @@ void scsi_disk_hard_reset(void) { scsi_disk_t *dev; - scsi_device_t *sd; - ide_t *id; - uint8_t scsi_bus; - uint8_t scsi_id; - uint8_t valid = 0; for (uint8_t c = 0; c < HDD_NUM; c++) { - valid = 0; - if (hdd[c].bus == HDD_BUS_SCSI) { - scsi_disk_log("SCSI disk hard_reset drive=%d\n", c); + uint8_t valid = 0; - scsi_bus = (hdd[c].scsi_id >> 4) & 0x0f; - scsi_id = hdd[c].scsi_id & 0x0f; + if (hdd[c].bus_type == HDD_BUS_SCSI) { + const uint8_t scsi_bus = (hdd[c].scsi_id >> 4) & 0x0f; + const uint8_t scsi_id = hdd[c].scsi_id & 0x0f; /* Make sure to ignore any SCSI disk that has an out of range SCSI bus. */ if (scsi_bus >= SCSI_BUS_MAX) @@ -1727,16 +1764,25 @@ scsi_disk_hard_reset(void) hdd_preset_apply(c); - if (!hdd[c].priv) - hdd[c].priv = (scsi_disk_t *) calloc(1, sizeof(scsi_disk_t)); + if (hdd[c].priv == NULL) { + hdd[c].priv = (scsi_disk_t *) calloc(1, sizeof(scsi_disk_t)); + dev = (scsi_disk_t *) hdd[c].priv; + + char n[1024] = { 0 }; + + sprintf(n, "HDD %i SCSI ", c + 1); + dev->log = log_open(n); + } dev = (scsi_disk_t *) hdd[c].priv; - if (!dev->tf) + scsi_disk_log(dev->log, "SCSI disk hard_reset drive=%d\n", c); + + if (dev->tf == NULL) dev->tf = (ide_tf_t *) calloc(1, sizeof(ide_tf_t)); /* SCSI disk, attach to the SCSI bus. */ - sd = &scsi_devices[scsi_bus][scsi_id]; + scsi_device_t *sd = &scsi_devices[scsi_bus][scsi_id]; sd->sc = (scsi_common_t *) dev; sd->command = scsi_disk_command; @@ -1746,18 +1792,22 @@ scsi_disk_hard_reset(void) sd->command_stop = scsi_disk_command_stop; sd->type = SCSI_FIXED_DISK; - scsi_disk_log("SCSI disk %i attached to SCSI ID %i\n", c, hdd[c].scsi_id); - } else if (hdd[c].bus == HDD_BUS_ATAPI) { + scsi_disk_log(dev->log, "SCSI disk %i attached to SCSI ID %i\n", c, hdd[c].scsi_id); + } else if (hdd[c].bus_type == HDD_BUS_ATAPI) { /* Make sure to ignore any SCSI disk whose image file name is empty. */ if (strlen(hdd[c].fn) == 0) continue; /* Make sure to ignore any SCSI disk whose image fails to load. */ + /* ATAPI hard disk, attach to the IDE bus. */ - id = ide_get_drive(hdd[c].ide_channel); - /* If the IDE channel is initialized, we attach to it, + ide_t *id = ide_get_drive(hdd[c].ide_channel); + + /* + If the IDE channel is initialized, we attach to it, otherwise, we do nothing - it's going to be a drive - that's not attached to anything. */ + that's not attached to anything. + */ if (id) { if (!hdd_image_load(c)) continue; @@ -1766,7 +1816,7 @@ scsi_disk_hard_reset(void) hdd_preset_apply(c); - if (!hdd[c].priv) + if (hdd[c].priv == NULL) hdd[c].priv = (scsi_disk_t *) calloc(1, sizeof(scsi_disk_t)); dev = (scsi_disk_t *) hdd[c].priv; @@ -1786,12 +1836,15 @@ scsi_disk_hard_reset(void) id->interrupt_drq = 0; ide_atapi_attach(id); - } - scsi_disk_log("ATAPI hard disk drive %i attached to IDE channel %i\n", c, hdd[c].ide_channel); + scsi_disk_log(dev->log, "ATAPI hard disk drive %i attached to IDE channel %i\n", + c, hdd[c].ide_channel); + } } if (valid) { + dev = (scsi_disk_t *) hdd[c].priv; + dev->id = c; dev->drv = &hdd[c]; @@ -1807,28 +1860,32 @@ scsi_disk_hard_reset(void) void scsi_disk_close(void) { - scsi_disk_t *dev; - uint8_t scsi_bus; - uint8_t scsi_id; - for (uint8_t c = 0; c < HDD_NUM; c++) { - if ((hdd[c].bus == HDD_BUS_SCSI) || (hdd[c].bus == HDD_BUS_ATAPI)) { - if (hdd[c].bus == HDD_BUS_SCSI) { - scsi_bus = (hdd[c].scsi_id >> 4) & 0x0f; - scsi_id = hdd[c].scsi_id & 0x0f; + if ((hdd[c].bus_type == HDD_BUS_SCSI) || (hdd[c].bus_type == HDD_BUS_ATAPI)) { + if (hdd[c].bus_type == HDD_BUS_SCSI) { + const uint8_t scsi_bus = (hdd[c].scsi_id >> 4) & 0x0f; + const uint8_t scsi_id = hdd[c].scsi_id & 0x0f; memset(&scsi_devices[scsi_bus][scsi_id], 0x00, sizeof(scsi_device_t)); } hdd_image_close(c); - dev = hdd[c].priv; + scsi_disk_t *dev = hdd[c].priv; if (dev) { if (dev->tf) free(dev->tf); + if (dev->log != NULL) { + scsi_disk_log(dev->log, "Log closed\n"); + + log_close(dev->log); + dev->log = NULL; + } + free(dev); + hdd[c].priv = NULL; } } diff --git a/src/scsi/scsi_ncr5380.c b/src/scsi/scsi_ncr5380.c index 527ff373f..132fade37 100644 --- a/src/scsi/scsi_ncr5380.c +++ b/src/scsi/scsi_ncr5380.c @@ -42,8 +42,6 @@ #include <86box/scsi_device.h> #include <86box/scsi_ncr5380.h> -int ncr5380_cmd_len[8] = { 6, 10, 10, 6, 16, 12, 10, 6 }; - #ifdef ENABLE_NCR5380_LOG int ncr5380_do_log = ENABLE_NCR5380_LOG; @@ -62,8 +60,6 @@ ncr5380_log(const char *fmt, ...) # define ncr5380_log(fmt, ...) #endif -#define SET_BUS_STATE(ncr, state) ncr->cur_bus = (ncr->cur_bus & ~(SCSI_PHASE_MESSAGE_IN)) | (state & (SCSI_PHASE_MESSAGE_IN)) - void ncr5380_irq(ncr_t *ncr, int set_irq) { @@ -86,51 +82,29 @@ ncr5380_set_irq(ncr_t *ncr, int irq) ncr->irq = irq; } -static int -ncr5380_get_dev_id(uint8_t data) -{ - for (uint8_t c = 0; c < SCSI_ID_MAX; c++) { - if (data & (1 << c)) - return c; - } - - return -1; -} - -static int -ncr5380_getmsglen(uint8_t *msgp, int len) -{ - uint8_t msg = msgp[0]; - if (msg == 0 || (msg >= 0x02 && msg <= 0x1f) || msg >= 0x80) - return 1; - if (msg >= 0x20 && msg <= 0x2f) - return 2; - if (len < 2) - return 3; - return msgp[1]; -} - static void ncr5380_reset(ncr_t *ncr) { - ncr->command_pos = 0; - ncr->data_pos = 0; - ncr->state = STATE_IDLE; - ncr->clear_req = 0; - ncr->cur_bus = 0; - ncr->tx_data = 0; + scsi_bus_t *scsi_bus = &ncr->scsibus; + ncr->output_data = 0; - ncr->data_wait = 0; ncr->mode = 0; ncr->tcr = 0; ncr->icr = 0; - ncr->dma_mode = DMA_IDLE; ncr5380_log("NCR Reset\n"); ncr->timer(ncr->priv, 0.0); - for (int i = 0; i < 8; i++) - scsi_device_reset(&scsi_devices[ncr->bus][i]); + scsi_bus->state = STATE_IDLE; + scsi_bus->clear_req = 0; + scsi_bus->wait_complete = 0; + scsi_bus->wait_data = 0; + scsi_bus->bus_in = 0; + scsi_bus->bus_out = 0; + scsi_bus->command_pos = 0; + scsi_bus->data_wait = 0; + scsi_bus->data = 0; + scsi_bus->command_issued = 0; ncr5380_irq(ncr, 0); } @@ -173,283 +147,29 @@ ncr5380_get_bus_host(ncr_t *ncr) return (bus_host | BUS_SETDATA(ncr->output_data)); } -void -ncr5380_bus_read(ncr_t *ncr) -{ - const scsi_device_t *dev; - int phase; - - /*Wait processes to handle bus requests*/ - if (ncr->clear_req) { - ncr->clear_req--; - if (!ncr->clear_req) { - ncr5380_log("Prelude to command data\n"); - SET_BUS_STATE(ncr, ncr->new_phase); - ncr->cur_bus |= BUS_REQ; - } - } - - if (ncr->wait_data) { - ncr->wait_data--; - if (!ncr->wait_data) { - dev = &scsi_devices[ncr->bus][ncr->target_id]; - SET_BUS_STATE(ncr, ncr->new_phase); - phase = (ncr->cur_bus & SCSI_PHASE_MESSAGE_IN); - - if (phase == SCSI_PHASE_DATA_IN) { - ncr->tx_data = dev->sc->temp_buffer[ncr->data_pos++]; - ncr->state = STATE_DATAIN; - ncr->cur_bus = (ncr->cur_bus & ~BUS_DATAMASK) | BUS_SETDATA(ncr->tx_data) | BUS_DBP; - } else if (phase == SCSI_PHASE_DATA_OUT) { - if (ncr->new_phase & BUS_IDLE) { - ncr->state = STATE_IDLE; - ncr->cur_bus &= ~BUS_BSY; - } else - ncr->state = STATE_DATAOUT; - } else if (phase == SCSI_PHASE_STATUS) { - ncr->cur_bus |= BUS_REQ; - ncr->state = STATE_STATUS; - ncr->cur_bus = (ncr->cur_bus & ~BUS_DATAMASK) | BUS_SETDATA(dev->status) | BUS_DBP; - } else if (phase == SCSI_PHASE_MESSAGE_IN) { - ncr->state = STATE_MESSAGEIN; - ncr->cur_bus = (ncr->cur_bus & ~BUS_DATAMASK) | BUS_SETDATA(0) | BUS_DBP; - } else if (phase == SCSI_PHASE_MESSAGE_OUT) { - ncr->cur_bus |= BUS_REQ; - ncr->state = STATE_MESSAGEOUT; - ncr->cur_bus = (ncr->cur_bus & ~BUS_DATAMASK) | BUS_SETDATA(ncr->target_id >> 5) | BUS_DBP; - } - } - } - - if (ncr->wait_complete) { - ncr->wait_complete--; - if (!ncr->wait_complete) - ncr->cur_bus |= BUS_REQ; - } -} - -void -ncr5380_bus_update(ncr_t *ncr, int bus) -{ - scsi_device_t *dev = &scsi_devices[ncr->bus][ncr->target_id]; - double p; - uint8_t sel_data; - int msglen; - - /*Start the SCSI command layer, which will also make the timings*/ - if (bus & BUS_ARB) - ncr->state = STATE_IDLE; - - ncr5380_log("State = %i\n", ncr->state); - - switch (ncr->state) { - case STATE_IDLE: - ncr->clear_req = ncr->wait_data = ncr->wait_complete = 0; - if ((bus & BUS_SEL) && !(bus & BUS_BSY)) { - ncr5380_log("Selection phase\n"); - sel_data = BUS_GETDATA(bus); - - ncr->target_id = ncr5380_get_dev_id(sel_data); - - ncr5380_log("Select - target ID = %i\n", ncr->target_id); - - /*Once the device has been found and selected, mark it as busy*/ - if ((ncr->target_id != (uint8_t) -1) && scsi_device_present(&scsi_devices[ncr->bus][ncr->target_id])) { - ncr->cur_bus |= BUS_BSY; - ncr->state = STATE_SELECT; - } else { - ncr5380_log("Device not found at ID %i, Current Bus BSY=%02x\n", ncr->target_id, ncr->cur_bus); - ncr->cur_bus = 0; - } - } - break; - case STATE_SELECT: - if (!(bus & BUS_SEL)) { - if (!(bus & BUS_ATN)) { - if ((ncr->target_id != (uint8_t) -1) && scsi_device_present(&scsi_devices[ncr->bus][ncr->target_id])) { - ncr5380_log("Device found at ID %i, Current Bus BSY=%02x\n", ncr->target_id, ncr->cur_bus); - ncr->state = STATE_COMMAND; - ncr->cur_bus = BUS_BSY | BUS_REQ; - ncr5380_log("CurBus BSY|REQ=%02x\n", ncr->cur_bus); - ncr->command_pos = 0; - SET_BUS_STATE(ncr, SCSI_PHASE_COMMAND); - } else { - ncr->state = STATE_IDLE; - ncr->cur_bus = 0; - } - } else { - ncr5380_log("Set to SCSI Message Out\n"); - ncr->new_phase = SCSI_PHASE_MESSAGE_OUT; - ncr->wait_data = 4; - ncr->msgout_pos = 0; - ncr->is_msgout = 1; - } - } - break; - case STATE_COMMAND: - if ((bus & BUS_ACK) && !(ncr->bus_in & BUS_ACK)) { - /*Write command byte to the output data register*/ - ncr->command[ncr->command_pos++] = BUS_GETDATA(bus); - ncr->clear_req = 3; - ncr->new_phase = ncr->cur_bus & SCSI_PHASE_MESSAGE_IN; - ncr->cur_bus &= ~BUS_REQ; - - ncr5380_log("Command pos=%i, output data=%02x\n", ncr->command_pos, BUS_GETDATA(bus)); - - if (ncr->command_pos == ncr5380_cmd_len[(ncr->command[0] >> 5) & 7]) { - if (ncr->is_msgout) { - ncr->is_msgout = 0; -#if 0 - ncr->command[1] = (ncr->command[1] & 0x1f) | (ncr->msglun << 5); -#endif - } - - /*Reset data position to default*/ - ncr->data_pos = 0; - - dev = &scsi_devices[ncr->bus][ncr->target_id]; - - ncr5380_log("SCSI Command 0x%02X for ID %d, status code=%02x\n", ncr->command[0], ncr->target_id, dev->status); - dev->buffer_length = -1; - scsi_device_command_phase0(dev, ncr->command); - ncr5380_log("SCSI ID %i: Command %02X: Buffer Length %i, SCSI Phase %02X\n", ncr->target_id, ncr->command[0], dev->buffer_length, dev->phase); - - ncr->period = 1.0; - ncr->wait_data = 4; - ncr->data_wait = 0; - - if (dev->status == SCSI_STATUS_OK) { - /*If the SCSI phase is Data In or Data Out, allocate the SCSI buffer based on the transfer length of the command*/ - if (dev->buffer_length && ((dev->phase == SCSI_PHASE_DATA_IN) || (dev->phase == SCSI_PHASE_DATA_OUT))) { - p = scsi_device_get_callback(dev); - ncr->period = (p > 0.0) ? p : (((double) dev->buffer_length) * 0.2); - ncr5380_log("SCSI ID %i: command 0x%02x for p = %lf, update = %lf, len = %i, dmamode = %x\n", ncr->target_id, ncr->command[0], scsi_device_get_callback(dev), ncr->period, dev->buffer_length, ncr->dma_mode); - } - } - ncr->new_phase = dev->phase; - } - } - break; - case STATE_DATAIN: - dev = &scsi_devices[ncr->bus][ncr->target_id]; - if ((bus & BUS_ACK) && !(ncr->bus_in & BUS_ACK)) { - if (ncr->data_pos >= dev->buffer_length) { - ncr->cur_bus &= ~BUS_REQ; - scsi_device_command_phase1(dev); - ncr->new_phase = SCSI_PHASE_STATUS; - ncr->wait_data = 4; - ncr->wait_complete = 8; - } else { - ncr->tx_data = dev->sc->temp_buffer[ncr->data_pos++]; - ncr->cur_bus = (ncr->cur_bus & ~BUS_DATAMASK) | BUS_SETDATA(ncr->tx_data) | BUS_DBP | BUS_REQ; - if (ncr->dma_mode == DMA_IDLE) { /*If a data in command that is not read 6/10 has been issued*/ - ncr->data_wait |= 1; - ncr5380_log("DMA mode idle in\n"); - ncr->timer(ncr->priv, ncr->period); - } else { - ncr5380_log("DMA mode IN.\n"); - ncr->clear_req = 3; - } - - ncr->cur_bus &= ~BUS_REQ; - ncr->new_phase = SCSI_PHASE_DATA_IN; - } - } - break; - case STATE_DATAOUT: - dev = &scsi_devices[ncr->bus][ncr->target_id]; - if ((bus & BUS_ACK) && !(ncr->bus_in & BUS_ACK)) { - dev->sc->temp_buffer[ncr->data_pos++] = BUS_GETDATA(bus); - - if (ncr->data_pos >= dev->buffer_length) { - ncr->cur_bus &= ~BUS_REQ; - scsi_device_command_phase1(dev); - ncr->new_phase = SCSI_PHASE_STATUS; - ncr->wait_data = 4; - ncr->wait_complete = 8; - } else { - /*More data is to be transferred, place a request*/ - if (ncr->dma_mode == DMA_IDLE) { /*If a data out command that is not write 6/10 has been issued*/ - ncr->data_wait |= 1; - ncr5380_log("DMA mode idle out\n"); - ncr->timer(ncr->priv, ncr->period); - } else - ncr->clear_req = 3; - - ncr->cur_bus &= ~BUS_REQ; - ncr5380_log("CurBus ~REQ_DataOut=%02x\n", ncr->cur_bus); - } - } - break; - case STATE_STATUS: - if ((bus & BUS_ACK) && !(ncr->bus_in & BUS_ACK)) { - /*All transfers done, wait until next transfer*/ - scsi_device_identify(&scsi_devices[ncr->bus][ncr->target_id], SCSI_LUN_USE_CDB); - ncr->cur_bus &= ~BUS_REQ; - ncr->new_phase = SCSI_PHASE_MESSAGE_IN; - ncr->wait_data = 4; - ncr->wait_complete = 8; - } - break; - case STATE_MESSAGEIN: - if ((bus & BUS_ACK) && !(ncr->bus_in & BUS_ACK)) { - ncr->cur_bus &= ~BUS_REQ; - ncr->new_phase = BUS_IDLE; - ncr->wait_data = 4; - } - break; - case STATE_MESSAGEOUT: - ncr5380_log("Ack on MSGOUT = %02x\n", (bus & BUS_ACK)); - if ((bus & BUS_ACK) && !(ncr->bus_in & BUS_ACK)) { - ncr->msgout[ncr->msgout_pos++] = BUS_GETDATA(bus); - msglen = ncr5380_getmsglen(ncr->msgout, ncr->msgout_pos); - if (ncr->msgout_pos >= msglen) { - if ((ncr->msgout[0] & (0x80 | 0x20)) == 0x80) - ncr->msglun = ncr->msgout[0] & 7; - ncr->cur_bus &= ~BUS_REQ; - ncr->state = STATE_MESSAGE_ID; - } - } - break; - case STATE_MESSAGE_ID: - if ((ncr->target_id != (uint8_t) -1) && scsi_device_present(&scsi_devices[ncr->bus][ncr->target_id])) { - ncr5380_log("Device found at ID %i on MSGOUT, Current Bus BSY=%02x\n", ncr->target_id, ncr->cur_bus); - scsi_device_identify(&scsi_devices[ncr->bus][ncr->target_id], ncr->msglun); - ncr->state = STATE_COMMAND; - ncr->cur_bus = BUS_BSY | BUS_REQ; - ncr5380_log("CurBus BSY|REQ=%02x\n", ncr->cur_bus); - ncr->command_pos = 0; - SET_BUS_STATE(ncr, SCSI_PHASE_COMMAND); - } - break; - - default: - break; - } - - ncr->bus_in = bus; -} - void ncr5380_write(uint16_t port, uint8_t val, ncr_t *ncr) { + scsi_bus_t *scsi_bus = &ncr->scsibus; int bus_host = 0; ncr5380_log("NCR5380 write(%04x,%02x)\n", port & 7, val); switch (port & 7) { case 0: /* Output data register */ - ncr5380_log("Write: Output data register, val = %02x\n", val); + ncr5380_log("[%04X:%08X]: Write: Output data register, val=%02x\n", CS, cpu_state.pc, val); ncr->output_data = val; break; case 1: /* Initiator Command Register */ - ncr5380_log("Write: Initiator command register\n"); + ncr5380_log("[%04X:%08X]: Write: Initiator command register, val=%02x.\n", CS, cpu_state.pc, val); if ((val & 0x80) && !(ncr->icr & 0x80)) { ncr5380_log("Resetting the 5380\n"); ncr5380_reset(ncr); + ncr5380_irq(ncr, 1); } ncr->icr = val; + ncr5380_log("ICR WaitData=%d, ClearReq=%d.\n", scsi_bus->wait_data, scsi_bus->clear_req); break; case 2: /* Mode register */ @@ -458,14 +178,12 @@ ncr5380_write(uint16_t port, uint8_t val, ncr_t *ncr) ncr->icr &= ~ICR_ARB_LOST; ncr->icr |= ICR_ARB_IN_PROGRESS; } - ncr->mode = val; - - ncr->dma_mode_ext(ncr, ncr->priv); + ncr->dma_mode_ext(ncr, ncr->priv, val); break; case 3: /* Target Command Register */ - ncr5380_log("Write: Target Command register\n"); + ncr5380_log("Write: Target Command register, val=%02x.\n", val); ncr->tcr = val; break; @@ -476,15 +194,15 @@ ncr5380_write(uint16_t port, uint8_t val, ncr_t *ncr) case 5: /* start DMA Send */ ncr5380_log("Write: start DMA send register\n"); /*a Write 6/10 has occurred, start the timer when the block count is loaded*/ - ncr->dma_mode = DMA_SEND; + scsi_bus->tx_mode = DMA_OUT_TX_BUS; if (ncr->dma_send_ext) ncr->dma_send_ext(ncr, ncr->priv); break; case 7: /* start DMA Initiator Receive */ - ncr5380_log("Write: start DMA initiator receive register, dma? = %02x\n", ncr->mode & MODE_DMA); + ncr5380_log("[%04X:%08X]: Write: start DMA initiator receive register, waitdata=%d, clearreq=%d.\n", CS, cpu_state.pc, scsi_bus->wait_data, scsi_bus->clear_req); /*a Read 6/10 has occurred, start the timer when the block count is loaded*/ - ncr->dma_mode = DMA_INITIATOR_RECEIVE; + scsi_bus->tx_mode = DMA_IN_TX_BUS; if (ncr->dma_initiator_receive_ext) ncr->dma_initiator_receive_ext(ncr, ncr->priv); break; @@ -495,12 +213,13 @@ ncr5380_write(uint16_t port, uint8_t val, ncr_t *ncr) } bus_host = ncr5380_get_bus_host(ncr); - ncr5380_bus_update(ncr, bus_host); + scsi_bus_update(scsi_bus, bus_host); } uint8_t ncr5380_read(uint16_t port, ncr_t *ncr) { + scsi_bus_t *scsi_bus = &ncr->scsibus; uint8_t ret = 0xff; int bus; int bus_state; @@ -510,13 +229,18 @@ ncr5380_read(uint16_t port, ncr_t *ncr) ncr5380_log("Read: Current SCSI data register\n"); if (ncr->icr & ICR_DBP) { /*Return the data from the output register if on data bus phase from ICR*/ - ncr5380_log("Data Bus Phase, ret = %02x\n", ncr->output_data); - ret = ncr->output_data; + if (scsi_bus->command_issued) { + bus = scsi_bus_read(scsi_bus); + ret = BUS_GETDATA(bus); + } else + ret = ncr->output_data; + + ncr5380_log("[%04X:%08X]: Data Bus Phase, CMDissued=%d, ret=%02x, clearreq=%d, waitdata=%x, txmode=%x.\n", CS, cpu_state.pc, scsi_bus->command_issued, ret, scsi_bus->clear_req, scsi_bus->wait_data, scsi_bus->tx_mode); } else { /*Return the data from the SCSI bus*/ - ncr5380_bus_read(ncr); - ncr5380_log("NCR GetData=%02x\n", BUS_GETDATA(ncr->cur_bus)); - ret = BUS_GETDATA(ncr->cur_bus); + bus = scsi_bus_read(scsi_bus); + ret = BUS_GETDATA(bus); + ncr5380_log("[%04X:%08X]: NCR Get SCSI bus data=%02x.\n", CS, cpu_state.pc, ret); } break; @@ -538,15 +262,12 @@ ncr5380_read(uint16_t port, ncr_t *ncr) case 4: /* Current SCSI Bus status */ ncr5380_log("Read: SCSI bus status register\n"); ret = 0; - ncr5380_bus_read(ncr); - ncr5380_log("NCR cur bus stat=%02x\n", ncr->cur_bus & 0xff); - ret |= (ncr->cur_bus & 0xff); + bus = scsi_bus_read(scsi_bus); + ret |= (bus & 0xff); if (ncr->icr & ICR_SEL) ret |= BUS_SEL; if (ncr->icr & ICR_BSY) ret |= BUS_BSY; - // if ((ret & SCSI_PHASE_MESSAGE_IN) == SCSI_PHASE_MESSAGE_IN) - // ret &= ~BUS_REQ; break; case 5: /* Bus and Status register */ @@ -557,13 +278,12 @@ ncr5380_read(uint16_t port, ncr_t *ncr) ncr5380_log("Get host from Interrupt\n"); /*Check if the phase in process matches with TCR's*/ - if ((bus & SCSI_PHASE_MESSAGE_IN) == (ncr->cur_bus & SCSI_PHASE_MESSAGE_IN)) { + if ((bus & SCSI_PHASE_MESSAGE_IN) == (scsi_bus->bus_out & SCSI_PHASE_MESSAGE_IN)) { ncr5380_log("Phase match\n"); ret |= STATUS_PHASE_MATCH; } - ncr5380_bus_read(ncr); - bus = ncr->cur_bus; + bus = scsi_bus_read(scsi_bus); if ((bus & BUS_ACK) || (ncr->icr & ICR_ACK)) ret |= STATUS_ACK; @@ -592,10 +312,13 @@ ncr5380_read(uint16_t port, ncr_t *ncr) ret |= STATUS_BUSY_ERROR; } ret |= (ncr->isr & (STATUS_INT | STATUS_END_OF_DMA)); + ncr->isr_reg = ret; break; case 6: - ret = ncr->tx_data; + ncr5380_log("Read: Input Data.\n"); + bus = scsi_bus_read(scsi_bus); + ret = BUS_GETDATA(bus); break; case 7: /* reset Parity/Interrupt */ diff --git a/src/scsi/scsi_ncr53c400.c b/src/scsi/scsi_ncr53c400.c index bea918660..7a87b4ac9 100644 --- a/src/scsi/scsi_ncr53c400.c +++ b/src/scsi/scsi_ncr53c400.c @@ -29,11 +29,11 @@ #define HAVE_STDARG_H #include <86box/86box.h> #include <86box/io.h> -#include <86box/timer.h> #include <86box/dma.h> #include <86box/pic.h> #include <86box/mca.h> #include <86box/mem.h> +#include <86box/timer.h> #include <86box/rom.h> #include <86box/device.h> #include <86box/nvr.h> @@ -41,6 +41,7 @@ #include <86box/scsi.h> #include <86box/scsi_device.h> #include <86box/scsi_ncr5380.h> +#include "cpu.h" #define LCS6821N_ROM "roms/scsi/ncr5380/Longshine LCS-6821N - BIOS version 1.04.bin" #define COREL_LS2000_ROM "roms/scsi/ncr5380/Corel LS2000 - BIOS ROM - Ver 1.65.bin" @@ -80,6 +81,7 @@ typedef struct ncr53c400_t { int buffer_host_pos; int busy; + int reset; uint8_t pos_regs[8]; pc_timer_t timer; @@ -121,10 +123,14 @@ ncr53c400_write(uint32_t addr, uint8_t val, void *priv) { ncr53c400_t *ncr400 = (ncr53c400_t *) priv; ncr_t *ncr = &ncr400->ncr; - scsi_device_t *dev = &scsi_devices[ncr->bus][ncr->target_id]; + scsi_bus_t *scsi_bus = &ncr->scsibus; + scsi_device_t *dev = &scsi_devices[ncr->bus][scsi_bus->target_id]; addr &= 0x3fff; + if (addr >= 0x3880) + ncr53c400_log("%04X:%08X: memio_write(%04x)=%02x\n", CS, cpu_state.pc, addr, val); + if (addr >= 0x3a00) ncr400->ext_ram[addr - 0x3a00] = val; else { @@ -146,15 +152,29 @@ ncr53c400_write(uint32_t addr, uint8_t val, void *priv) if (ncr400->buffer_host_pos == MIN(128, dev->buffer_length)) { ncr400->status_ctrl |= STATUS_BUFFER_NOT_READY; ncr400->busy = 1; - if (!(ncr->mode & MODE_MONITOR_BUSY) && ((scsi_device_get_callback(dev) > 0.0))) - timer_on_auto(&ncr400->timer, ncr->period / 250.0); + if (ncr400->type != ROM_T130B) + timer_on_auto(&ncr400->timer, 1.0); } - } + } else + ncr53c400_log("No Write.\n"); break; case 0x3980: switch (addr) { case 0x3980: /* Control */ + /*Parity bits*/ + /*This is to avoid RTBios 8.10R BIOS problems with the hard disk and detection.*/ + /*If the parity bits are set, bit 0 of the 53c400 status port should be set as well.*/ + /*Required by RTASPI10.SYS otherwise it won't initialize.*/ + if (val & 0x80) { + if (ncr->mode & 0x30) { + if (!(ncr->mode & MODE_DMA)) { + ncr->mode = 0x00; + ncr400->reset = 1; + } + } + } + ncr53c400_log("NCR 53c400 control=%02x, mode=%02x.\n", val, ncr->mode); if ((val & CTRL_DATA_DIR) && !(ncr400->status_ctrl & CTRL_DATA_DIR)) { ncr400->buffer_host_pos = MIN(128, dev->buffer_length); @@ -167,7 +187,7 @@ ncr53c400_write(uint32_t addr, uint8_t val, void *priv) break; case 0x3981: /* block counter register */ - ncr53c400_log("Write block counter register: val=%d, dma mode=%x, period=%lf.\n", val, ncr->dma_mode, ncr->period); + ncr53c400_log("Write block counter register: val=%d, dma mode=%x, period=%lf.\n", val, scsi_bus->tx_mode, scsi_bus->period); ncr400->block_count = val; ncr400->block_count_loaded = 1; @@ -180,15 +200,11 @@ ncr53c400_write(uint32_t addr, uint8_t val, void *priv) } if ((ncr->mode & MODE_DMA) && (dev->buffer_length > 0)) { memset(ncr400->buffer, 0, MIN(128, dev->buffer_length)); - if (ncr->mode & MODE_MONITOR_BUSY) - timer_on_auto(&ncr400->timer, ncr->period); - else if (scsi_device_get_callback(dev) > 0.0) - timer_on_auto(&ncr400->timer, 40.0); - else - timer_on_auto(&ncr400->timer, ncr->period); - - ncr53c400_log("DMA timer on=%02x, callback=%lf, scsi buflen=%d, waitdata=%d, waitcomplete=%d, clearreq=%d, datawait=%d, enabled=%d.\n", ncr->mode & MODE_MONITOR_BUSY, scsi_device_get_callback(dev), dev->buffer_length, ncr->wait_complete, ncr->wait_data, ncr->wait_complete, ncr->clear_req, ncr->data_wait, timer_is_enabled(&ncr400->timer)); - } + timer_on_auto(&ncr400->timer, 10.0); + ncr53c400_log("DMA timer on=%02x, callback=%lf, scsi buflen=%d, waitdata=%d, waitcomplete=%d, clearreq=%d, p=%lf enabled=%d.\n", + ncr->mode & MODE_MONITOR_BUSY, scsi_device_get_callback(dev), dev->buffer_length, scsi_bus->wait_data, scsi_bus->wait_complete, scsi_bus->clear_req, scsi_bus->period, timer_is_enabled(&ncr400->timer)); + } else + ncr53c400_log("No Timer.\n"); break; default: @@ -208,7 +224,8 @@ ncr53c400_read(uint32_t addr, void *priv) { ncr53c400_t *ncr400 = (ncr53c400_t *) priv; ncr_t *ncr = &ncr400->ncr; - scsi_device_t *dev = &scsi_devices[ncr->bus][ncr->target_id]; + scsi_bus_t *scsi_bus = &ncr->scsibus; + scsi_device_t *dev = &scsi_devices[ncr->bus][scsi_bus->target_id]; uint8_t ret = 0xff; addr &= 0x3fff; @@ -232,7 +249,7 @@ ncr53c400_read(uint32_t addr, void *priv) break; case 0x3900: - if (ncr400->buffer_host_pos >= MIN(128, dev->buffer_length) || (!(ncr400->status_ctrl & CTRL_DATA_DIR))) { + if ((ncr400->buffer_host_pos >= MIN(128, dev->buffer_length)) || (!(ncr400->status_ctrl & CTRL_DATA_DIR))) { ret = 0xff; ncr53c400_log("No Read.\n"); } else { @@ -241,9 +258,20 @@ ncr53c400_read(uint32_t addr, void *priv) if (ncr400->buffer_host_pos == MIN(128, dev->buffer_length)) { ncr400->status_ctrl |= STATUS_BUFFER_NOT_READY; - ncr53c400_log("Transfer busy read, status = %02x.\n", ncr400->status_ctrl); - if (!(ncr->mode & MODE_MONITOR_BUSY) && (scsi_device_get_callback(dev) > 0.0)) - timer_on_auto(&ncr400->timer, ncr->period / 250.0); + if (ncr400->type != ROM_T130B) { + if (!ncr400->block_count_loaded) { + scsi_bus->tx_mode = PIO_TX_BUS; + ncr53c400_log("IO End of read transfer\n"); + ncr->isr |= STATUS_END_OF_DMA; + if (ncr->mode & MODE_ENA_EOP_INT) { + ncr53c400_log("NCR read irq\n"); + ncr5380_irq(ncr, 1); + } + } else if (!timer_is_enabled(&ncr400->timer)) { + ncr53c400_log("Timer re-enabled.\n"); + timer_on_auto(&ncr400->timer, 1.0); + } + } } } break; @@ -255,11 +283,10 @@ ncr53c400_read(uint32_t addr, void *priv) ncr53c400_log("NCR status ctrl read=%02x.\n", ncr400->status_ctrl & STATUS_BUFFER_NOT_READY); if (!ncr400->busy) ret |= STATUS_5380_ACCESSIBLE; - if (ncr->mode & 0x30) { /*Parity bits*/ - if (!(ncr->mode & MODE_DMA)) { /*This is to avoid RTBios 8.10R BIOS problems with the hard disk and detection.*/ - ret |= 0x01; /*If the parity bits are set, bit 0 of the 53c400 status port should be set as well.*/ - ncr->mode = 0; /*Required by RTASPI10.SYS otherwise it won't initialize.*/ - } + + if (ncr400->reset) { + ncr400->reset = 0; + ret |= 0x01; } ncr53c400_log("NCR 53c400 status=%02x.\n", ret); break; @@ -270,7 +297,10 @@ ncr53c400_read(uint32_t addr, void *priv) break; case 0x3982: /* switch register read */ - ret = 0xff; + if (ncr->irq != -1) { + ret = 0xf8; + ret += ncr->irq; + } ncr53c400_log("Switches read=%02x.\n", ret); break; @@ -285,7 +315,7 @@ ncr53c400_read(uint32_t addr, void *priv) } if (addr >= 0x3880) - ncr53c400_log("memio_read(%08x)=%02x\n", addr, ret); + ncr53c400_log("%04X:%08X: memio_read(%04x)=%02x\n", CS, cpu_state.pc, addr, ret); return ret; } @@ -397,42 +427,52 @@ t130b_in(uint16_t port, void *priv) } static void -ncr53c400_dma_mode_ext(void *priv, UNUSED(void *ext_priv)) +ncr53c400_dma_mode_ext(void *priv, void *ext_priv, uint8_t val) { - ncr_t *ncr = (ncr_t *) priv; + ncr53c400_t *ncr400 = (ncr53c400_t *) ext_priv; + ncr_t *ncr = (ncr_t *) priv; + scsi_bus_t *scsi_bus = &ncr->scsibus; /*When a pseudo-DMA transfer has completed (Send or Initiator Receive), mark it as complete and idle the status*/ - if (!(ncr->mode & MODE_DMA)) { - ncr53c400_log("No DMA mode\n"); - ncr->tcr &= ~TCR_LAST_BYTE_SENT; - ncr->isr &= ~STATUS_END_OF_DMA; - ncr->dma_mode = DMA_IDLE; + ncr53c400_log("NCR 53c400: Loaded?=%d, DMA mode enabled=%02x, valDMA=%02x.\n", ncr400->block_count_loaded, ncr->mode & MODE_DMA, val & MODE_DMA); + if (!ncr400->block_count_loaded) { + if (!(val & MODE_DMA)) { + ncr->tcr &= ~TCR_LAST_BYTE_SENT; + ncr->isr &= ~STATUS_END_OF_DMA; + scsi_bus->tx_mode = PIO_TX_BUS; + } } } static void ncr53c400_callback(void *priv) { - ncr53c400_t *ncr400 = (void *) priv; + ncr53c400_t *ncr400 = (ncr53c400_t *) priv; ncr_t *ncr = &ncr400->ncr; - scsi_device_t *dev = &scsi_devices[ncr->bus][ncr->target_id]; + scsi_bus_t *scsi_bus = &ncr->scsibus; + scsi_device_t *dev = &scsi_devices[ncr->bus][scsi_bus->target_id]; int bus; uint8_t c; uint8_t temp; + uint8_t status; - if (ncr->dma_mode != DMA_IDLE) - timer_on_auto(&ncr400->timer, 1.0); - - if (ncr->data_wait & 1) { - ncr->clear_req = 3; - ncr->data_wait &= ~1; + if (scsi_bus->tx_mode != PIO_TX_BUS) { + ncr53c400_log("PERIOD T130B DMA=%lf.\n", scsi_bus->period / 225.0); + timer_on_auto(&ncr400->timer, scsi_bus->period / 225.0); } - if (ncr->dma_mode == DMA_IDLE) - return; + if (scsi_bus->data_wait & 1) { + scsi_bus->clear_req = 3; + scsi_bus->data_wait &= ~1; + } - switch (ncr->dma_mode) { - case DMA_SEND: + if (scsi_bus->tx_mode == PIO_TX_BUS) { + ncr53c400_log("Timer CMD=%02x.\n", scsi_bus->command[0]); + return; + } + + switch (scsi_bus->tx_mode) { + case DMA_OUT_TX_BUS: if (ncr400->status_ctrl & CTRL_DATA_DIR) { ncr53c400_log("DMA_SEND with DMA direction set wrong\n"); break; @@ -450,8 +490,8 @@ ncr53c400_callback(void *priv) while (1) { for (c = 0; c < 10; c++) { - ncr5380_bus_read(ncr); - if (ncr->cur_bus & BUS_REQ) + status = scsi_bus_read(scsi_bus); + if (status & BUS_REQ) break; } /* Data ready. */ @@ -460,8 +500,8 @@ ncr53c400_callback(void *priv) bus = ncr5380_get_bus_host(ncr) & ~BUS_DATAMASK; bus |= BUS_SETDATA(temp); - ncr5380_bus_update(ncr, bus | BUS_ACK); - ncr5380_bus_update(ncr, bus & ~BUS_ACK); + scsi_bus_update(scsi_bus, bus | BUS_ACK); + scsi_bus_update(scsi_bus, bus & ~BUS_ACK); ncr400->buffer_pos++; ncr53c400_log("NCR 53c400 Buffer pos for writing = %d\n", ncr400->buffer_pos); @@ -474,6 +514,7 @@ ncr53c400_callback(void *priv) ncr400->block_count = (ncr400->block_count - 1) & 0xff; ncr53c400_log("NCR 53c400 Remaining blocks to be written=%d\n", ncr400->block_count); if (!ncr400->block_count) { + scsi_bus->tx_mode = PIO_TX_BUS; ncr400->block_count_loaded = 0; ncr53c400_log("IO End of write transfer\n"); ncr->tcr |= TCR_LAST_BYTE_SENT; @@ -488,7 +529,7 @@ ncr53c400_callback(void *priv) } break; - case DMA_INITIATOR_RECEIVE: + case DMA_IN_TX_BUS: if (!(ncr400->status_ctrl & CTRL_DATA_DIR)) { ncr53c400_log("DMA_INITIATOR_RECEIVE with DMA direction set wrong\n"); break; @@ -504,18 +545,18 @@ ncr53c400_callback(void *priv) while (1) { for (c = 0; c < 10; c++) { - ncr5380_bus_read(ncr); - if (ncr->cur_bus & BUS_REQ) + status = scsi_bus_read(scsi_bus); + if (status & BUS_REQ) break; } /* Data ready. */ - ncr5380_bus_read(ncr); - temp = BUS_GETDATA(ncr->cur_bus); + bus = scsi_bus_read(scsi_bus); + temp = BUS_GETDATA(bus); bus = ncr5380_get_bus_host(ncr); - ncr5380_bus_update(ncr, bus | BUS_ACK); - ncr5380_bus_update(ncr, bus & ~BUS_ACK); + scsi_bus_update(scsi_bus, bus | BUS_ACK); + scsi_bus_update(scsi_bus, bus & ~BUS_ACK); ncr400->buffer[ncr400->buffer_pos++] = temp; ncr53c400_log("NCR 53c400 Buffer pos for reading = %d\n", ncr400->buffer_pos); @@ -528,12 +569,16 @@ ncr53c400_callback(void *priv) ncr53c400_log("NCR 53c400 Remaining blocks to be read=%d\n", ncr400->block_count); if (!ncr400->block_count) { ncr400->block_count_loaded = 0; - ncr53c400_log("IO End of read transfer\n"); - ncr->isr |= STATUS_END_OF_DMA; - if (ncr->mode & MODE_ENA_EOP_INT) { - ncr53c400_log("NCR read irq\n"); - ncr5380_irq(ncr, 1); - } + if (ncr400->type == ROM_T130B) { + scsi_bus->tx_mode = PIO_TX_BUS; + ncr53c400_log("IO End of read transfer\n"); + ncr->isr |= STATUS_END_OF_DMA; + if (ncr->mode & MODE_ENA_EOP_INT) { + ncr53c400_log("NCR read irq\n"); + ncr5380_irq(ncr, 1); + } + } else + timer_on_auto(&ncr400->timer, 1.0); } break; } @@ -544,12 +589,12 @@ ncr53c400_callback(void *priv) break; } - ncr5380_bus_read(ncr); + status = scsi_bus_read(scsi_bus); - if (!(ncr->cur_bus & BUS_BSY) && (ncr->mode & MODE_MONITOR_BUSY)) { + if (!(status & BUS_BSY) && (ncr->mode & MODE_MONITOR_BUSY)) { ncr53c400_log("Updating DMA\n"); ncr->mode &= ~MODE_DMA; - ncr->dma_mode = DMA_IDLE; + scsi_bus->tx_mode = PIO_TX_BUS; ncr400->block_count_loaded = 0; } } @@ -620,16 +665,14 @@ ncr53c400_init(const device_t *info) { const char *bios_ver = NULL; const char *fn; - ncr53c400_t *ncr400; - ncr_t *ncr; - - ncr400 = malloc(sizeof(ncr53c400_t)); - memset(ncr400, 0x00, sizeof(ncr53c400_t)); - ncr = &ncr400->ncr; + ncr53c400_t *ncr400 = calloc(1, sizeof(ncr53c400_t)); + ncr_t *ncr = &ncr400->ncr; + scsi_bus_t *scsi_bus; ncr400->type = info->local; ncr->bus = scsi_get_bus(); + scsi_bus = &ncr->scsibus; switch (ncr400->type) { case ROM_LCS6821N: /* Longshine LCS6821N */ @@ -713,11 +756,25 @@ ncr53c400_init(const device_t *info) ncr->dma_send_ext = NULL; ncr->dma_initiator_receive_ext = NULL; ncr->timer = ncr53c400_timer_on_auto; - ncr400->status_ctrl = STATUS_BUFFER_NOT_READY; + scsi_bus->bus_device = ncr->bus; + scsi_bus->timer = ncr->timer; + scsi_bus->priv = ncr->priv; + ncr400->status_ctrl = 0x00; ncr400->buffer_host_pos = 128; timer_add(&ncr400->timer, ncr53c400_callback, ncr400, 0); scsi_bus_set_speed(ncr->bus, 5000000.0); + scsi_bus->speed = 0.2; + if (ncr400->type == ROM_T130B) { + scsi_bus->divider = 2.0; + scsi_bus->multi = 1.750; + } else { + scsi_bus->divider = 1.0; + scsi_bus->multi = 1.0; + } + + for (int i = 0; i < 8; i++) + scsi_device_reset(&scsi_devices[ncr->bus][i]); return ncr400; } @@ -763,14 +820,14 @@ corel_ls2000_available(void) // clang-format off static const device_config_t ncr53c400_mmio_config[] = { { - .name = "bios_addr", - .description = "BIOS Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0xD8000, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "bios_addr", + .description = "BIOS Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0xD8000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "C800H", .value = 0xc8000 }, { .description = "CC00H", .value = 0xcc000 }, { .description = "D000H", .value = 0xd0000 }, @@ -779,36 +836,69 @@ static const device_config_t ncr53c400_mmio_config[] = { { .description = "DC00H", .value = 0xdc000 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 5, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 5, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "None", .value = -1 }, - { .description = "IRQ 3", .value = 3 }, - { .description = "IRQ 5", .value = 5 }, - { .description = "IRQ 7", .value = 7 }, - { .description = "" } + { .description = "IRQ 3", .value = 3 }, + { .description = "IRQ 5", .value = 5 }, + { .description = "IRQ 7", .value = 7 }, + { .description = "" } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t rt1000b_config[] = { { - .name = "bios_addr", - .description = "BIOS Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0xD8000, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "bios_ver", + .description = "BIOS Revision", + .type = CONFIG_BIOS, + .default_string = "v8_10r", + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { + { + .name = "Version 8.10R", + .internal_name = "v8_10r", + .bios_type = BIOS_NORMAL, + .files_no = 1, + .local = 0, + .size = 8192, + .files = { RT1000B_810R_ROM, "" } + }, + { + .name = "Version 8.20R", + .internal_name = "v8_20r", + .bios_type = BIOS_NORMAL, + .files_no = 1, + .local = 0, + .size = 8192, + .files = { RT1000B_820R_ROM, "" } + }, + { .files_no = 0 } + }, + }, + { + .name = "bios_addr", + .description = "BIOS Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0xD8000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "C800H", .value = 0xc8000 }, { .description = "CC00H", .value = 0xcc000 }, { .description = "D000H", .value = 0xd0000 }, @@ -817,72 +907,59 @@ static const device_config_t rt1000b_config[] = { { .description = "DC00H", .value = 0xdc000 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 5, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 5, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "None", .value = -1 }, - { .description = "IRQ 3", .value = 3 }, - { .description = "IRQ 5", .value = 5 }, - { .description = "IRQ 7", .value = 7 }, - { .description = "" } - }, - }, - { - .name = "bios_ver", - .description = "BIOS Revision", - .type = CONFIG_BIOS, - .default_string = "v8_10r", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, /*W1*/ - .bios = { - { .name = "Version 8.10R", .internal_name = "v8_10r", .bios_type = BIOS_NORMAL, - .files_no = 1, .local = 0, .size = 8192, .files = { RT1000B_810R_ROM, "" } }, - { .name = "Version 8.20R", .internal_name = "v8_20r", .bios_type = BIOS_NORMAL, - .files_no = 1, .local = 0, .size = 8192, .files = { RT1000B_820R_ROM, "" } }, - { .files_no = 0 } + { .description = "IRQ 3", .value = 3 }, + { .description = "IRQ 5", .value = 5 }, + { .description = "IRQ 7", .value = 7 }, + { .description = "" } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t rt1000b_mc_config[] = { { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 5, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 5, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "None", .value = -1 }, - { .description = "IRQ 3", .value = 3 }, - { .description = "IRQ 5", .value = 5 }, - { .description = "IRQ 7", .value = 7 }, - { .description = "" } + { .description = "IRQ 3", .value = 3 }, + { .description = "IRQ 5", .value = 5 }, + { .description = "IRQ 7", .value = 7 }, + { .description = "" } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t t130b_config[] = { { - .name = "bios_addr", - .description = "BIOS Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0xD8000, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "bios_addr", + .description = "BIOS Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0xD8000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Disabled", .value = 0 }, { .description = "C800H", .value = 0xc8000 }, { .description = "CC00H", .value = 0xcc000 }, @@ -890,38 +967,41 @@ static const device_config_t t130b_config[] = { { .description = "DC00H", .value = 0xdc000 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x0350, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x0350, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "240H", .value = 0x0240 }, { .description = "250H", .value = 0x0250 }, { .description = "340H", .value = 0x0340 }, { .description = "350H", .value = 0x0350 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 5, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 5, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "None", .value = -1 }, - { .description = "IRQ 3", .value = 3 }, - { .description = "IRQ 5", .value = 5 }, - { .description = "IRQ 7", .value = 7 }, - { .description = "" } + { .description = "IRQ 3", .value = 3 }, + { .description = "IRQ 5", .value = 5 }, + { .description = "IRQ 7", .value = 7 }, + { .description = "" } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; @@ -935,7 +1015,7 @@ const device_t scsi_lcs6821n_device = { .init = ncr53c400_init, .close = ncr53c400_close, .reset = NULL, - { .available = lcs6821n_available }, + .available = lcs6821n_available, .speed_changed = NULL, .force_redraw = NULL, .config = ncr53c400_mmio_config @@ -949,7 +1029,7 @@ const device_t scsi_rt1000b_device = { .init = ncr53c400_init, .close = ncr53c400_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = rt1000b_config @@ -963,7 +1043,7 @@ const device_t scsi_rt1000mc_device = { .init = ncr53c400_init, .close = ncr53c400_close, .reset = NULL, - { .available = rt1000b_mc_available }, + .available = rt1000b_mc_available, .speed_changed = NULL, .force_redraw = NULL, .config = rt1000b_mc_config @@ -977,7 +1057,7 @@ const device_t scsi_t130b_device = { .init = ncr53c400_init, .close = ncr53c400_close, .reset = NULL, - { .available = t130b_available }, + .available = t130b_available, .speed_changed = NULL, .force_redraw = NULL, .config = t130b_config @@ -986,12 +1066,12 @@ const device_t scsi_t130b_device = { const device_t scsi_ls2000_device = { .name = "Corel LS2000", .internal_name = "ls2000", - .flags = DEVICE_ISA, + .flags = DEVICE_ISA | DEVICE_SIDECAR, .local = ROM_LS2000, .init = ncr53c400_init, .close = ncr53c400_close, .reset = NULL, - { .available = corel_ls2000_available }, + .available = corel_ls2000_available, .speed_changed = NULL, .force_redraw = NULL, .config = ncr53c400_mmio_config diff --git a/src/scsi/scsi_ncr53c8xx.c b/src/scsi/scsi_ncr53c8xx.c index 1425f468b..f87f22452 100644 --- a/src/scsi/scsi_ncr53c8xx.c +++ b/src/scsi/scsi_ncr53c8xx.c @@ -2530,10 +2530,7 @@ ncr53c8xx_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) static void * ncr53c8xx_init(const device_t *info) { - ncr53c8xx_t *dev; - - dev = malloc(sizeof(ncr53c8xx_t)); - memset(dev, 0x00, sizeof(ncr53c8xx_t)); + ncr53c8xx_t *dev = calloc(1, sizeof(ncr53c8xx_t)); dev->bus = scsi_get_bus(); @@ -2666,19 +2663,20 @@ ncr53c8xx_close(void *priv) static const device_config_t ncr53c8xx_pci_config[] = { // clang-format off { - .name = "bios", - .description = "BIOS Revision", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 1, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "bios", + .description = "BIOS Revision", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "SDMS 4.x BIOS", .value = 2 }, { .description = "SDMS 3.x BIOS", .value = 1 }, { .description = "Disable BIOS", .value = 0 }, { .description = "" } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -2692,7 +2690,7 @@ const device_t ncr53c810_pci_device = { .init = ncr53c8xx_init, .close = ncr53c8xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2706,7 +2704,7 @@ const device_t ncr53c810_onboard_pci_device = { .init = ncr53c8xx_init, .close = ncr53c8xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2720,7 +2718,7 @@ const device_t ncr53c815_pci_device = { .init = ncr53c8xx_init, .close = ncr53c8xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, ncr53c8xx_pci_config @@ -2734,7 +2732,7 @@ const device_t ncr53c820_pci_device = { .init = ncr53c8xx_init, .close = ncr53c8xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2748,7 +2746,7 @@ const device_t ncr53c825a_pci_device = { .init = ncr53c8xx_init, .close = ncr53c8xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ncr53c8xx_pci_config @@ -2762,7 +2760,7 @@ const device_t ncr53c860_pci_device = { .init = ncr53c8xx_init, .close = ncr53c8xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ncr53c8xx_pci_config @@ -2776,7 +2774,7 @@ const device_t ncr53c875_pci_device = { .init = ncr53c8xx_init, .close = ncr53c8xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = ncr53c8xx_pci_config diff --git a/src/scsi/scsi_pcscsi.c b/src/scsi/scsi_pcscsi.c index c2e5c9168..7c991bdb1 100644 --- a/src/scsi/scsi_pcscsi.c +++ b/src/scsi/scsi_pcscsi.c @@ -2204,10 +2204,7 @@ esp_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) static void * dc390_init(UNUSED(const device_t *info)) { - esp_t *dev; - - dev = malloc(sizeof(esp_t)); - memset(dev, 0x00, sizeof(esp_t)); + esp_t *dev = calloc(1, sizeof(esp_t)); dev->bus = scsi_get_bus(); @@ -2419,10 +2416,7 @@ ncr53c9x_mca_feedb(void *priv) static void * ncr53c9x_mca_init(const device_t *info) { - esp_t *dev; - - dev = malloc(sizeof(esp_t)); - memset(dev, 0x00, sizeof(esp_t)); + esp_t *dev = calloc(1, sizeof(esp_t)); dev->bus = scsi_get_bus(); @@ -2464,11 +2458,15 @@ esp_close(void *priv) static const device_config_t bios_enable_config[] = { // clang-format off { - .name = "bios", - .description = "Enable BIOS", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "bios", + .description = "Enable BIOS", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -2482,7 +2480,7 @@ const device_t dc390_pci_device = { .init = dc390_init, .close = esp_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = bios_enable_config @@ -2496,7 +2494,7 @@ const device_t am53c974_pci_device = { .init = dc390_init, .close = esp_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -2510,7 +2508,7 @@ const device_t ncr53c90a_mca_device = { .init = ncr53c9x_mca_init, .close = esp_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/scsi/scsi_spock.c b/src/scsi/scsi_spock.c index e308d0788..0bb2d70ba 100644 --- a/src/scsi/scsi_spock.c +++ b/src/scsi/scsi_spock.c @@ -130,6 +130,7 @@ typedef struct { int adapter_id; int assign; int present[8]; + int id_connected; int cmd_status; int cir_status; @@ -196,6 +197,7 @@ typedef struct { #define CMD_UNKNOWN_1C11 0x1c11 #define CMD_WRITE_DATA 0x1c02 #define CMD_VERIFY 0x1c03 +#define CMD_WRITE_VERIFY 0x1c04 #define IRQ_TYPE_NONE 0x0 #define IRQ_TYPE_SCB_COMPLETE 0x1 @@ -205,7 +207,6 @@ typedef struct { #define IRQ_TYPE_COMMAND_FAIL 0xc #define IRQ_TYPE_COMMAND_ERROR 0xe #define IRQ_TYPE_SW_SEQ_ERROR 0xf -#define IRQ_TYPE_RESET_COMPLETE 0x10 #ifdef ENABLE_SPOCK_LOG int spock_do_log = ENABLE_SPOCK_LOG; @@ -225,7 +226,9 @@ spock_log(const char *fmt, ...) # define spock_log(fmt, ...) #endif -static void +static void spock_reset(void *priv); + +static __inline void spock_rethink_irqs(spock_t *scsi) { int irq_pending = 0; @@ -235,7 +238,7 @@ spock_rethink_irqs(spock_t *scsi) if (scsi->irq_requests[c] != IRQ_TYPE_NONE) { /* Found IRQ */ scsi->irq_status = c | (scsi->irq_requests[c] << 4); - spock_log("Found IRQ: status = %02x\n", scsi->irq_status); + spock_log("Found IRQ: status=%02x.\n", scsi->irq_status); scsi->status |= STATUS_IRQ; irq_pending = 1; break; @@ -244,38 +247,37 @@ spock_rethink_irqs(spock_t *scsi) } else irq_pending = 1; + spock_log("spock_rethink_irqs: irqstat=%02x, ctrl=%02x, irqpend=%d.\n", scsi->irq_status, scsi->basic_ctrl, irq_pending); if (scsi->basic_ctrl & CTRL_IRQ_ENA) { if (irq_pending) { spock_log("IRQ issued\n"); - scsi->irq_inactive = 0; + scsi->status |= STATUS_IRQ; picint(1 << scsi->irq); } else { /* No IRQs pending, clear IRQ state */ spock_log("IRQ cleared\n"); - scsi->irq_status = 0; - scsi->irq_inactive = 1; - scsi->status &= ~STATUS_IRQ; picintc(1 << scsi->irq); } } else { - spock_log("IRQ disabled\n"); - picintc(1 << scsi->irq); + spock_log("IRQ disabled, pending=%d.\n", irq_pending); + if (irq_pending) + scsi->status |= STATUS_IRQ; } } -static __inline void +static void spock_set_irq(spock_t *scsi, int id, int type) { - spock_log("spock_set_irq id=%i type=%x %02x\n", id, type, scsi->irq_status); + spock_log("spock_set_irq: id=%i, type=%x, irqstat=%02x\n", id, type, scsi->irq_status); scsi->irq_requests[id] = type; if (!scsi->irq_status) /* Don't change IRQ status if one is currently being processed */ spock_rethink_irqs(scsi); } -static __inline void +static void spock_clear_irq(spock_t *scsi, int id) { - spock_log("spock_clear_irq id=%i\n", id); + spock_log("spock_clear_irq: id=%i.\n", id); scsi->irq_requests[id] = IRQ_TYPE_NONE; spock_rethink_irqs(scsi); } @@ -291,7 +293,7 @@ spock_write(uint16_t port, uint8_t val, void *priv) { spock_t *scsi = (spock_t *) priv; - spock_log("spock_write: port=%04x val=%02x %04x:%04x\n", port, val, CS, cpu_state.pc); + spock_log("%04X:%08X: spock_writeb: port=%04x, val=%02x.\n", CS, cpu_state.pc, port & 7, val); switch (port & 7) { case 0: @@ -307,16 +309,14 @@ spock_write(uint16_t port, uint8_t val, void *priv) case 4: /*Attention Register*/ scsi->attention_pending = val; - scsi->attention_wait = 2; + scsi->attention_wait = 2; scsi->status |= STATUS_BUSY; break; case 5: /*Basic Control Register*/ - if ((scsi->basic_ctrl & CTRL_RESET) && !(val & CTRL_RESET)) { + if (!(scsi->basic_ctrl & CTRL_RESET) && (val & CTRL_RESET)) { spock_log("Spock: SCSI reset and busy\n"); - scsi->in_reset = 1; - scsi->cmd_timer = SPOCK_TIME * 2; - scsi->status |= STATUS_BUSY; + spock_reset(scsi); } scsi->basic_ctrl = val; spock_rethink_irqs(scsi); @@ -332,6 +332,8 @@ spock_writew(uint16_t port, uint16_t val, void *priv) { spock_t *scsi = (spock_t *) priv; + spock_log("%04X:%08X: spock_writew: port=%04x, val=%04x.\n", CS, cpu_state.pc, port & 7, val); + switch (port & 7) { case 0: /*Command Interface Register*/ scsi->cir_pending[0] = val & 0xff; @@ -347,8 +349,6 @@ spock_writew(uint16_t port, uint16_t val, void *priv) default: break; } - - spock_log("spock_writew: port=%04x val=%04x\n", port, val); } static uint8_t @@ -390,7 +390,7 @@ spock_read(uint16_t port, void *priv) break; } - spock_log("spock_read: port=%04x val=%02x %04x(%05x):%04x.\n", port, temp, CS, cs, cpu_state.pc); + spock_log("%04X:%08X: spock_readb: port=%04x, temp=%02x.\n", CS, cpu_state.pc, port & 7, temp); return temp; } @@ -412,7 +412,7 @@ spock_readw(uint16_t port, void *priv) break; } - spock_log("spock_readw: port=%04x val=%04x\n", port, temp); + spock_log("spock_readw: port=%04x, val=%04x, %04x:%04x.\n", port & 7, temp, CS, cpu_state.pc); return temp; } @@ -441,16 +441,14 @@ spock_get_len(spock_t *scsi, scb_t *scb) DataToTransfer += scb->sge.sys_buf_byte_count; } return DataToTransfer; - } else { - return (scsi->data_len); } + return (scsi->data_len); } static void spock_process_imm_cmd(spock_t *scsi) { int i; - int j = 0; int adapter_id; int phys_id; int lun_id; @@ -469,14 +467,23 @@ spock_process_imm_cmd(spock_t *scsi) if (scsi->command & (1 << 23)) { spock_log("Assign: adapter id=%d\n", adapter_id); scsi->dev_id[adapter_id].phys_id = -1; + scsi->id_connected = 0; spock_set_irq(scsi, scsi->attention & 0x0f, IRQ_TYPE_IMM_CMD_COMPLETE); } else { if (phys_id != scsi->adapter_id) { scsi->dev_id[adapter_id].phys_id = phys_id; scsi->dev_id[adapter_id].lun_id = lun_id; - spock_log("Assign: adapter dev=%x scsi ID=%i LUN=%i.\n", adapter_id, scsi->dev_id[adapter_id].phys_id, scsi->dev_id[adapter_id].lun_id); + if (scsi_device_present(&scsi_devices[scsi->bus][phys_id])) { + scsi->present[scsi->id_connected] = 1; + if (lun_id == 0) + scsi->id_connected++; + } else + scsi->present[scsi->id_connected] = 0; + + spock_log("Assign: adapter dev=%d, scsi ID=%i, LUN=%i, attention devsel=%d, present=%d, connected=%d.\n", adapter_id, scsi->dev_id[adapter_id].phys_id, scsi->dev_id[adapter_id].lun_id, scsi->attention & 0x0f, scsi->present[scsi->id_connected], scsi->id_connected); spock_set_irq(scsi, scsi->attention & 0x0f, IRQ_TYPE_IMM_CMD_COMPLETE); } else { /*Can not assign adapter*/ + scsi->id_connected = 0; spock_log("Assign: PUN=%d, cannot assign adapter.\n", phys_id); spock_set_irq(scsi, scsi->attention & 0x0f, IRQ_TYPE_COMMAND_FAIL); } @@ -493,30 +500,20 @@ spock_process_imm_cmd(spock_t *scsi) spock_set_irq(scsi, scsi->attention & 0x0f, IRQ_TYPE_IMM_CMD_COMPLETE); break; case CMD_INVALID_412: - spock_log("Invalid 412\n"); + spock_log("Invalid 412.\n"); spock_set_irq(scsi, scsi->attention & 0x0f, IRQ_TYPE_IMM_CMD_COMPLETE); break; case CMD_RESET: - spock_log("Reset Command, attention = %d.\n", scsi->attention & 0x0f); + scsi->id_connected = 0; + spock_log("Reset command, attention=%02x.\n", scsi->attention & 0x0f); if ((scsi->attention & 0x0f) == 0x0f) { /*Adapter reset*/ - for (i = 0; i < 8; i++) { + for (i = 0; i < 8; i++) scsi_device_reset(&scsi_devices[scsi->bus][i]); - } - for (i = 6; i > -1; i--) { - if (scsi_device_present(&scsi_devices[scsi->bus][i])) { - spock_log("Adapter Reset, SCSI reset present devices=%d, phys ID=%d, type=%04x.\n", j, scsi->dev_id[i].phys_id, scsi_devices[scsi->bus][i].type); - scsi->present[j] = i; - j++; - } else { - scsi->present[j] = 0xff; - spock_log("Adapter Reset, SCSI reset not present devices=%d, phys ID=%d, type=%04x.\n", j, scsi->dev_id[i].phys_id, scsi_devices[scsi->bus][i].type); - } - } - - scsi->scb_state = 0; - } + } else if ((scsi->attention & 0x0f) < 7) /*Device reset*/ + scsi_device_reset(&scsi_devices[scsi->bus][scsi->attention & 0x0f]); + scsi->scb_state = 0; spock_set_irq(scsi, scsi->attention & 0x0f, IRQ_TYPE_IMM_CMD_COMPLETE); break; @@ -530,23 +527,13 @@ static void spock_execute_cmd(spock_t *scsi, scb_t *scb) { int c; - int j = 0; int old_scb_state; if (scsi->in_reset) { - spock_log("Reset type = %d\n", scsi->in_reset); - scsi->status &= ~STATUS_BUSY; - scsi->irq_status = 0; - for (c = 0; c < SCSI_ID_MAX; c++) - spock_clear_irq(scsi, c); - - if (scsi->in_reset == 1) { - scsi->basic_ctrl |= CTRL_IRQ_ENA; - } - - spock_set_irq(scsi, 0x0f, IRQ_TYPE_RESET_COMPLETE); + scsi->irq_status = 0x0f; + spock_rethink_irqs(scsi); /*Reset device mappings*/ for (c = 0; c < 7; c++) { @@ -557,17 +544,7 @@ spock_execute_cmd(spock_t *scsi, scb_t *scb) scsi->dev_id[c].phys_id = -1; scsi->in_reset = 0; - - for (c = 6; c > -1; c--) { - if (scsi_device_present(&scsi_devices[scsi->bus][c])) { - spock_log("Reset, SCSI reset present devices=%d, phys ID=%d, type=%04x.\n", j, scsi->dev_id[c].phys_id, scsi_devices[scsi->bus][c].type); - scsi->present[j] = c; - j++; - } else { - scsi->present[j] = 0xff; - spock_log("Reset, SCSI reset not present devices=%d, phys ID=%d, type=%04x.\n", j, scsi->dev_id[c].phys_id, scsi_devices[scsi->bus][c].type); - } - } + spock_log("Reset.\n"); return; } @@ -585,6 +562,7 @@ spock_execute_cmd(spock_t *scsi, scb_t *scb) switch (scsi->scb_state) { case 0: /* Idle */ + spock_log("Start Idle.\n"); break; case 1: /* Select */ @@ -677,7 +655,7 @@ spock_execute_cmd(spock_t *scsi, scb_t *scb) get_pos_info->pos = scsi->spock_16bit ? 0x8efe : 0x8eff; get_pos_info->pos1 = scsi->pos_regs[3] | (scsi->pos_regs[2] << 8); get_pos_info->pos2 = scsi->irq | (scsi->pos_regs[4] << 8); - get_pos_info->pos3 = 1 << 12; + get_pos_info->pos3 = scsi->spock_16bit ? (1 << 12) : (0 << 12); get_pos_info->pos4 = (7 << 8) | 8; get_pos_info->pos5 = (16 << 8) | scsi->pacing; get_pos_info->pos6 = (30 << 8) | 1; @@ -698,12 +676,15 @@ spock_execute_cmd(spock_t *scsi, scb_t *scb) break; case CMD_DEVICE_INQUIRY: - if (scsi->present[scsi->scb_id] != 0xff) + if (scsi->scb_id != 15) { + if (scsi->present[scsi->scb_id]) + scsi->cdb_id = scsi->dev_id[scsi->scb_id].phys_id; + else + scsi->cdb_id = 0xff; + } else scsi->cdb_id = scsi->dev_id[scsi->scb_id].phys_id; - else - scsi->cdb_id = 0xff; - spock_log("Device Inquiry, ID=%d\n", scsi->cdb_id); + spock_log("Device Inquiry, ID=%d, connected=%d, present=%d.\n", scsi->cdb_id, scsi->id_connected, scsi->present[scsi->scb_id + 1]); scsi->cdb[0] = GPCMD_INQUIRY; scsi->cdb[1] = scsi->dev_id[scsi->scb_id].lun_id << 5; /*LUN*/ scsi->cdb[2] = 0; /*Page code*/ @@ -718,13 +699,16 @@ spock_execute_cmd(spock_t *scsi, scb_t *scb) return; case CMD_SEND_OTHER_SCSI: - if (scsi->present[scsi->scb_id] != 0xff) + if (scsi->scb_id != 15) { + if (scsi->present[scsi->scb_id]) + scsi->cdb_id = scsi->dev_id[scsi->scb_id].phys_id; + else + scsi->cdb_id = 0xff; + } else scsi->cdb_id = scsi->dev_id[scsi->scb_id].phys_id; - else - scsi->cdb_id = 0xff; dma_bm_read(scsi->scb_addr + 0x18, scsi->cdb, 12, 2); - spock_log("Send Other SCSI, SCB ID=%d, PHYS ID=%d, CDB[0]=%02x, CDB_ID=%d, ID Present=%d.\n", scsi->scb_id, scsi->dev_id[scsi->scb_id].phys_id, scsi->cdb[0], scsi->cdb_id, scsi->present[scsi->scb_id]); + spock_log("Send Other SCSI, SCB ID=%d, PHYS ID=%d, LUN=%d, CDB[0]=%02x, CDB_ID=%d, ID Present=%d.\n", scsi->scb_id, scsi->dev_id[scsi->scb_id].phys_id, scsi->dev_id[scsi->scb_id].lun_id, scsi->cdb[0], scsi->cdb_id, scsi->present[scsi->scb_id + 1]); scsi->cdb[1] = (scsi->cdb[1] & 0x1f) | (scsi->dev_id[scsi->scb_id].lun_id << 5); /*Patch correct LUN into command*/ scsi->cdb_len = (scb->lba_addr & 0xff) ? (scb->lba_addr & 0xff) : 6; scsi->scsi_state = SCSI_STATE_SELECT; @@ -732,10 +716,13 @@ spock_execute_cmd(spock_t *scsi, scb_t *scb) return; case CMD_READ_DEVICE_CAPACITY: - if (scsi->present[scsi->scb_id] != 0xff) + if (scsi->scb_id != 15) { + if (scsi->present[scsi->scb_id]) + scsi->cdb_id = scsi->dev_id[scsi->scb_id].phys_id; + else + scsi->cdb_id = 0xff; + } else scsi->cdb_id = scsi->dev_id[scsi->scb_id].phys_id; - else - scsi->cdb_id = 0xff; spock_log("Device Capacity, SCB ID=%d, PHYS ID=%d\n", scsi->scb_id, scsi->dev_id[scsi->scb_id].phys_id); scsi->cdb[0] = GPCMD_READ_CDROM_CAPACITY; @@ -754,10 +741,13 @@ spock_execute_cmd(spock_t *scsi, scb_t *scb) return; case CMD_READ_DATA: - if (scsi->present[scsi->scb_id] != 0xff) + if (scsi->scb_id != 15) { + if (scsi->present[scsi->scb_id]) + scsi->cdb_id = scsi->dev_id[scsi->scb_id].phys_id; + else + scsi->cdb_id = 0xff; + } else scsi->cdb_id = scsi->dev_id[scsi->scb_id].phys_id; - else - scsi->cdb_id = 0xff; spock_log("Device Read Data, SCB ID=%d, PHYS ID=%d\n", scsi->scb_id, scsi->dev_id[scsi->scb_id].phys_id); scsi->cdb[0] = GPCMD_READ_10; @@ -776,10 +766,13 @@ spock_execute_cmd(spock_t *scsi, scb_t *scb) return; case CMD_WRITE_DATA: - if (scsi->present[scsi->scb_id] != 0xff) + if (scsi->scb_id != 15) { + if (scsi->present[scsi->scb_id]) + scsi->cdb_id = scsi->dev_id[scsi->scb_id].phys_id; + else + scsi->cdb_id = 0xff; + } else scsi->cdb_id = scsi->dev_id[scsi->scb_id].phys_id; - else - scsi->cdb_id = 0xff; spock_log("Device Write Data\n"); scsi->cdb[0] = GPCMD_WRITE_10; @@ -798,10 +791,13 @@ spock_execute_cmd(spock_t *scsi, scb_t *scb) return; case CMD_VERIFY: - if (scsi->present[scsi->scb_id] != 0xff) + if (scsi->scb_id != 15) { + if (scsi->present[scsi->scb_id]) + scsi->cdb_id = scsi->dev_id[scsi->scb_id].phys_id; + else + scsi->cdb_id = 0xff; + } else scsi->cdb_id = scsi->dev_id[scsi->scb_id].phys_id; - else - scsi->cdb_id = 0xff; spock_log("Device Verify\n"); scsi->cdb[0] = GPCMD_VERIFY_10; @@ -820,11 +816,39 @@ spock_execute_cmd(spock_t *scsi, scb_t *scb) scsi->scb_state = 2; return; - case CMD_REQUEST_SENSE: - if (scsi->present[scsi->scb_id] != 0xff) + case CMD_WRITE_VERIFY: + if (scsi->scb_id != 15) { + if (scsi->present[scsi->scb_id]) + scsi->cdb_id = scsi->dev_id[scsi->scb_id].phys_id; + else + scsi->cdb_id = 0xff; + } else + scsi->cdb_id = scsi->dev_id[scsi->scb_id].phys_id; + + spock_log("Device Write with Verify\n"); + scsi->cdb[0] = GPCMD_WRITE_AND_VERIFY_10; + scsi->cdb[1] = scsi->dev_id[scsi->scb_id].lun_id << 5; /*LUN*/ + scsi->cdb[2] = (scb->lba_addr >> 24) & 0xff; /*LBA*/ + scsi->cdb[3] = (scb->lba_addr >> 16) & 0xff; + scsi->cdb[4] = (scb->lba_addr >> 8) & 0xff; + scsi->cdb[5] = scb->lba_addr & 0xff; + scsi->cdb[6] = 0; /*Reserved*/ + scsi->cdb[7] = (scb->block_count >> 8) & 0xff; + scsi->cdb[8] = scb->block_count & 0xff; + scsi->cdb[9] = 0; /*Control*/ + scsi->cdb_len = 10; + scsi->scsi_state = SCSI_STATE_SELECT; + scsi->scb_state = 2; + return; + + case CMD_REQUEST_SENSE: + if (scsi->scb_id != 15) { + if (scsi->present[scsi->scb_id]) + scsi->cdb_id = scsi->dev_id[scsi->scb_id].phys_id; + else + scsi->cdb_id = 0xff; + } else scsi->cdb_id = scsi->dev_id[scsi->scb_id].phys_id; - else - scsi->cdb_id = 0xff; spock_log("Device Request Sense, ID=%d\n", scsi->cdb_id); scsi->cdb[0] = GPCMD_REQUEST_SENSE; @@ -848,7 +872,7 @@ spock_execute_cmd(spock_t *scsi, scb_t *scb) if (scsi_device_present(&scsi_devices[scsi->bus][scsi->cdb_id]) && (scsi->cdb_id != 0xff)) { if (scsi->last_status == SCSI_STATUS_OK) { scsi->scb_state = 3; - spock_log("Status is Good on device ID %d, cdb id = %d.\n", scsi->scb_id, scsi->cdb_id); + spock_log("Status is Good on device ID %d, cdb id = %d, devsel = %d.\n", scsi->scb_id, scsi->cdb_id, scsi->attention & 0x0f); } else if (scsi->last_status == SCSI_STATUS_CHECK_CONDITION) { uint16_t term_stat_block_addr7 = (0xc << 8) | 2; uint16_t term_stat_block_addr8 = 0x20; @@ -883,7 +907,7 @@ spock_execute_cmd(spock_t *scsi, scb_t *scb) } else { spock_set_irq(scsi, scsi->scb_id, IRQ_TYPE_SCB_COMPLETE); scsi->scb_state = 0; - spock_log("Complete SCB ID = %d.\n", scsi->attention & 0x0f); + spock_log("Complete SCB ID = %d.\n", scsi->scb_id); } break; @@ -942,8 +966,10 @@ spock_process_scsi(spock_t *scsi, scb_t *scb) else sd->buffer_length = spock_get_len(scsi, scb); + scsi_device_identify(sd, scsi->temp_cdb[1] >> 5); + scsi_device_command_phase0(sd, scsi->temp_cdb); - spock_log("SCSI ID %i: Current CDB[0] = %02x, LUN = %i, data len = %i, max len = %i, phase val = %02x\n", scsi->cdb_id, scsi->temp_cdb[0], scsi->temp_cdb[1] >> 5, sd->buffer_length, spock_get_len(scsi, scb), sd->phase); + spock_log("SCSI ID %i: Current CDB[0]=%02x, LUN=%i, buffer len=%i, max len=%i, phase val=%02x, data len=%d, enable bit 10=%03x\n", scsi->cdb_id, scsi->temp_cdb[0], scsi->temp_cdb[1] >> 5, sd->buffer_length, spock_get_len(scsi, scb), sd->phase, scsi->data_len, scb->enable & 0x400); if ((sd->phase != SCSI_PHASE_STATUS) && (sd->buffer_length > 0)) { p = scsi_device_get_callback(sd); @@ -995,8 +1021,12 @@ spock_process_scsi(spock_t *scsi, scb_t *scb) break; case SCSI_STATE_END_PHASE: + sd = &scsi_devices[scsi->bus][scsi->cdb_id]; scsi->scsi_state = SCSI_STATE_IDLE; + if (sd->type != SCSI_NONE) + scsi_device_identify(sd, SCSI_LUN_USE_CDB); + spock_log("State to idle, cmd timer %d\n", scsi->cmd_timer); if (!scsi->cmd_timer) scsi->cmd_timer = 1; @@ -1018,12 +1048,11 @@ spock_callback(void *priv) if (scsi->cmd_timer) { scsi->cmd_timer--; - if (!scsi->cmd_timer) { + if (!scsi->cmd_timer) spock_execute_cmd(scsi, scb); - } } - if (scsi->attention_wait && (scsi->scb_state == 0 || (scsi->attention_pending & 0xf0) == 0xe0)) { + if (scsi->attention_wait && ((scsi->scb_state == 0) || (scsi->attention_pending & 0xf0) == 0xe0)) { scsi->attention_wait--; if (!scsi->attention_wait) { scsi->attention = scsi->attention_pending; @@ -1057,10 +1086,10 @@ spock_callback(void *priv) case 4: case 0x0f: /*Start SCB*/ scsi->cmd_status = 1; - scsi->scb_addr = scsi->cir[0] | (scsi->cir[1] << 8) | (scsi->cir[2] << 16) | (scsi->cir[3] << 24); - scsi->scb_id = scsi->attention & 0x0f; + scsi->scb_addr = scsi->cir[0] | (scsi->cir[1] << 8) | (scsi->cir[2] << 16) | (scsi->cir[3] << 24); + scsi->scb_id = scsi->attention & 0x0f; scsi->cmd_timer = SPOCK_TIME * 2; - spock_log("Start SCB at ID = %d, attention = %02x\n", scsi->scb_id, scsi->attention >> 4); + spock_log("Start SCB at ID = %d, attention = %02x, cdb_id = %d\n", scsi->scb_id, scsi->attention >> 4, scsi->cdb_id); scsi->scb_state = 1; break; @@ -1072,6 +1101,7 @@ spock_callback(void *priv) case 0x0e: /*EOI*/ scsi->irq_status = 0; + scsi->status &= ~STATUS_IRQ; spock_clear_irq(scsi, scsi->attention & 0x0f); break; @@ -1096,23 +1126,30 @@ spock_mca_write(int port, uint8_t val, void *priv) if (port < 0x102) return; - io_removehandler((((scsi->pos_regs[2] >> 1) & 7) * 8) + 0x3540, 0x0008, spock_read, spock_readw, NULL, spock_write, spock_writew, NULL, scsi); + io_removehandler((((scsi->pos_regs[2] >> 1) & 7) << 3) + 0x3540, 0x0008, spock_read, spock_readw, NULL, spock_write, spock_writew, NULL, scsi); mem_mapping_disable(&scsi->bios_rom.mapping); scsi->pos_regs[port & 7] = val; scsi->adapter_id = (scsi->pos_regs[3] & 0xe0) >> 5; - if (scsi->pos_regs[2] & 1) { - io_sethandler((((scsi->pos_regs[2] >> 1) & 7) * 8) + 0x3540, 0x0008, spock_read, spock_readw, NULL, spock_write, spock_writew, NULL, scsi); - if (scsi->pos_regs[4] & 2) { - if (((scsi->pos_regs[2] >> 4) & 0x0f) != 0x0f) { - mem_mapping_set_addr(&scsi->bios_rom.mapping, ((scsi->pos_regs[2] >> 4) * 0x2000) + 0xc0000, 0x8000); - mem_mapping_enable(&scsi->bios_rom.mapping); + if (scsi->pos_regs[2] & 0x01) { + io_sethandler((((scsi->pos_regs[2] >> 1) & 7) << 3) + 0x3540, 0x0008, spock_read, spock_readw, NULL, spock_write, spock_writew, NULL, scsi); + if (scsi->pos_regs[4] & 0x02) { + if (scsi->pos_regs[4] & 0x80) { + if (((scsi->pos_regs[2] >> 4) & 0x0f) != 0x0f) { + mem_mapping_set_addr(&scsi->bios_rom.mapping, ((scsi->pos_regs[2] >> 4) * 0x2000) + 0xc0000, 0x8000); + mem_mapping_enable(&scsi->bios_rom.mapping); + } + } else { + if (((scsi->pos_regs[2] >> 4) & 0x0f) != 0x0f) { + mem_mapping_set_addr(&scsi->bios_rom.mapping, ((scsi->pos_regs[2] >> 4) * 0x2000) + 0xc0000, 0x4000); + mem_mapping_enable(&scsi->bios_rom.mapping); + } } } } - spock_log("[%04X:%08X]: POS Write Port = %x, val = %02x, rom addr = %05x\n", CS, cpu_state.pc, port & 7, val, ((scsi->pos_regs[2] >> 4) * 0x2000) + 0xc0000); + spock_log("%04X:%08X: POS Write Port=%x, val=%02x.\n", CS, cpu_state.pc, port & 7, val); } static uint8_t @@ -1120,7 +1157,7 @@ spock_mca_read(int port, void *priv) { const spock_t *scsi = (spock_t *) priv; - spock_log("[%04X:%08X]: POS Read Port = %x, val = %02x\n", CS, cpu_state.pc, + spock_log("%04X:%08X: POS Read Port=%x, temp=%02x.\n", CS, cpu_state.pc, port & 7, scsi->pos_regs[port & 7]); return scsi->pos_regs[port & 7]; } @@ -1133,12 +1170,13 @@ spock_mca_feedb(void *priv) return (scsi->pos_regs[2] & 0x01); } + static void -spock_mca_reset(void *priv) +spock_reset(void *priv) { spock_t *scsi = (spock_t *) priv; - scsi->in_reset = 2; + scsi->in_reset = 1; scsi->cmd_timer = SPOCK_TIME * 50; scsi->status = STATUS_BUSY; scsi->scsi_state = SCSI_STATE_IDLE; @@ -1146,14 +1184,17 @@ spock_mca_reset(void *priv) scsi->in_invalid = 0; scsi->attention_wait = 0; scsi->basic_ctrl = 0; + scsi->id_connected = 0; - /* Reset all devices on controller reset. */ - for (uint8_t i = 0; i < 8; i++) { - scsi_device_reset(&scsi_devices[scsi->bus][i]); - scsi->present[i] = 0xff; - } + spock_log("Actual Reset.\n"); +} - spock_log("Reset.\n"); +static void +spock_mca_reset(void *priv) +{ + spock_t *scsi = (spock_t *) priv; + + spock_reset(scsi); mem_mapping_disable(&scsi->bios_rom.mapping); scsi->pos_regs[4] = 0x02; spock_mca_write(0x102, 0, scsi); @@ -1162,8 +1203,7 @@ spock_mca_reset(void *priv) static void * spock_init(const device_t *info) { - spock_t *scsi = malloc(sizeof(spock_t)); - memset(scsi, 0x00, sizeof(spock_t)); + spock_t *scsi = calloc(1, sizeof(spock_t)); scsi->bus = scsi_get_bus(); @@ -1192,10 +1232,6 @@ spock_init(const device_t *info) scsi->pos_regs[4] = 0x02; mca_add(spock_mca_read, spock_mca_write, spock_mca_feedb, spock_mca_reset, scsi); - scsi->in_reset = 2; - scsi->cmd_timer = SPOCK_TIME * 50; - scsi->status = STATUS_BUSY; - for (uint8_t c = 0; c < (SCSI_ID_MAX - 1); c++) scsi->dev_id[c].phys_id = -1; @@ -1209,6 +1245,8 @@ spock_init(const device_t *info) scsi_bus_set_speed(scsi->bus, 5000000.0); + spock_reset(scsi); + return scsi; } @@ -1232,18 +1270,19 @@ spock_available(void) static const device_config_t spock_rom_config[] = { // clang-format off { - .name = "bios_ver", - .description = "BIOS Revision", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 1, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "bios_ver", + .description = "BIOS Revision", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "1991 BIOS (>1GB)", .value = 1 }, { .description = "1990 BIOS", .value = 0 }, { .description = "" } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -1256,8 +1295,8 @@ const device_t spock_device = { .local = 0, .init = spock_init, .close = spock_close, - .reset = NULL, - { .available = spock_available }, + .reset = spock_reset, + .available = spock_available, .speed_changed = NULL, .force_redraw = NULL, .config = spock_rom_config @@ -1270,8 +1309,8 @@ const device_t tribble_device = { .local = 1, .init = spock_init, .close = spock_close, - .reset = NULL, - { .available = spock_available }, + .reset = spock_reset, + .available = spock_available, .speed_changed = NULL, .force_redraw = NULL, .config = spock_rom_config diff --git a/src/scsi/scsi_t128.c b/src/scsi/scsi_t128.c index c878bbb91..c5a1c4e67 100644 --- a/src/scsi/scsi_t128.c +++ b/src/scsi/scsi_t128.c @@ -29,6 +29,7 @@ #define HAVE_STDARG_H #include <86box/86box.h> #include <86box/io.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/dma.h> #include <86box/pic.h> @@ -69,34 +70,35 @@ t128_write(uint32_t addr, uint8_t val, void *priv) { t128_t *t128 = (t128_t *) priv; ncr_t *ncr = &t128->ncr; - const scsi_device_t *dev = &scsi_devices[ncr->bus][ncr->target_id]; + scsi_bus_t *scsi_bus = &ncr->scsibus; + const scsi_device_t *dev = &scsi_devices[ncr->bus][scsi_bus->target_id]; addr &= 0x3fff; if ((addr >= 0x1800) && (addr < 0x1880)) t128->ext_ram[addr & 0x7f] = val; else if ((addr >= 0x1c00) && (addr < 0x1c20)) { - if ((val & 0x02) && !(t128->ctrl & 0x02)) - t128->status |= 0x02; - + t128_log("T128 ctrl write=%02x, mode=%02x.\n", val, ncr->mode & MODE_DMA); t128->ctrl = val; - t128_log("T128 ctrl write=%02x\n", val); } else if ((addr >= 0x1d00) && (addr < 0x1e00)) ncr5380_write((addr - 0x1d00) >> 5, val, ncr); else if ((addr >= 0x1e00) && (addr < 0x2000)) { if ((t128->host_pos < MIN(512, dev->buffer_length)) && - (ncr->dma_mode == DMA_SEND)) { + (scsi_bus->tx_mode == DMA_OUT_TX_BUS)) { t128->buffer[t128->host_pos] = val; t128->host_pos++; - t128_log("T128 Write transfer, addr = %i, pos = %i, val = %02x\n", - addr & 0x1ff, t128->host_pos, val); + t128_log("T128 Write transfer: pos=%i, addr=%x.\n", + t128->host_pos, addr & 0x1ff); if (t128->host_pos == MIN(512, dev->buffer_length)) { + t128_log("T128 Transfer busy write, status=%02x, period=%lf, enabled=%d, loaded=%d.\n", + t128->status, scsi_bus->period, timer_is_enabled(&t128->timer), t128->block_loaded); + t128->status &= ~0x04; - t128_log("Transfer busy write, status = %02x\n", t128->status); - timer_on_auto(&t128->timer, 0.02); + timer_on_auto(&t128->timer, 1.0); } - } + } else + t128_log("Write not allowed.\n"); } } @@ -106,7 +108,8 @@ t128_read(uint32_t addr, void *priv) { t128_t *t128 = (t128_t *) priv; ncr_t *ncr = &t128->ncr; - scsi_device_t *dev = &scsi_devices[ncr->bus][ncr->target_id]; + scsi_bus_t *scsi_bus = &ncr->scsibus; + scsi_device_t *dev = &scsi_devices[ncr->bus][scsi_bus->target_id]; uint8_t ret = 0xff; addr &= 0x3fff; @@ -116,31 +119,43 @@ t128_read(uint32_t addr, void *priv) ret = t128->ext_ram[addr & 0x7f]; else if ((addr >= 0x1c00) && (addr < 0x1c20)) { ret = t128->ctrl; - t128_log("T128 ctrl read=%02x, dma=%02x\n", ret, ncr->mode & MODE_DMA); + t128_log("T128 ctrl read=%02x, dma=%02x, load=%d, cnt=%d.\n", ret, ncr->mode & MODE_DMA, t128->block_loaded, t128->block_count); } else if ((addr >= 0x1c20) && (addr < 0x1c40)) { ret = t128->status; - t128_log("T128 status read=%02x, dma=%02x\n", ret, ncr->mode & MODE_DMA); + t128_log("T128 status read=%02x, dma=%02x, blockload=%d, timer=%d.\n", ret, ncr->mode & MODE_DMA, t128->block_loaded, timer_is_enabled(&t128->timer)); } else if ((addr >= 0x1d00) && (addr < 0x1e00)) ret = ncr5380_read((addr - 0x1d00) >> 5, ncr); else if (addr >= 0x1e00 && addr < 0x2000) { - if ((t128->host_pos >= MIN(512, dev->buffer_length)) || - (ncr->dma_mode != DMA_INITIATOR_RECEIVE)) - ret = 0xff; - else { + if ((scsi_bus->tx_mode == DMA_IN_TX_BUS) && + (t128->host_pos < MIN(512, dev->buffer_length))) { ret = t128->buffer[t128->host_pos++]; - t128_log("T128 Read transfer, addr = %i, pos = %i\n", addr & 0x1ff, - t128->host_pos); + t128_log("T128 Read transfer: pos=%i, addr=%x, enabled timer=%d.\n", + t128->host_pos, addr & 0x1ff, timer_is_enabled(&t128->timer)); if (t128->host_pos == MIN(512, dev->buffer_length)) { + t128_log("T128 Transfer busy read, status=%02x, period=%lf, enabled=%d, block=%d.\n", + t128->status, scsi_bus->period, timer_is_enabled(&t128->timer), scsi_bus->data_pos); + t128->status &= ~0x04; - t128_log("T128 Transfer busy read, status = %02x, period = %lf\n", - t128->status, ncr->period); - if ((ncr->period == 0.2) || (ncr->period == 0.02)) - timer_on_auto(&t128->timer, 40.2); - } else if ((t128->host_pos < MIN(512, dev->buffer_length)) && - (scsi_device_get_callback(dev) > 100.0)) - cycles += 100; /*Needed to avoid timer de-syncing with transfers.*/ + if (!t128->block_loaded) { + ncr->isr |= STATUS_END_OF_DMA; + if (ncr->mode & MODE_ENA_EOP_INT) { + t128_log("T128 read irq\n"); + ncr5380_irq(ncr, 1); + } + scsi_bus->bus_out |= BUS_CD; + scsi_bus->tx_mode = PIO_TX_BUS; + timer_stop(&t128->timer); + } else if (!timer_is_enabled(&t128->timer)) + timer_on_auto(&t128->timer, 1.0); + } + } else { + /*According to the WinNT DDK sources, just get the status timeout bit from here.*/ + if (!(t128->status & 0x02)) + t128->status |= 0x02; + + t128_log("Read not allowed.\n"); } } @@ -148,23 +163,20 @@ t128_read(uint32_t addr, void *priv) } static void -t128_dma_mode_ext(void *priv, void *ext_priv) +t128_dma_mode_ext(void *priv, void *ext_priv, uint8_t val) { t128_t *t128 = (t128_t *) ext_priv; ncr_t *ncr = (ncr_t *) priv; - - /*Don't stop the timer until it finishes the transfer*/ - if (t128->block_loaded && (ncr->mode & MODE_DMA)) { - t128_log("Continuing DMA mode\n"); - timer_on_auto(&t128->timer, ncr->period + 1.0); - } + scsi_bus_t *scsi_bus = &ncr->scsibus; /*When a pseudo-DMA transfer has completed (Send or Initiator Receive), mark it as complete and idle the status*/ - if (!t128->block_loaded && !(ncr->mode & MODE_DMA)) { - t128_log("No DMA mode\n"); - ncr->tcr &= ~TCR_LAST_BYTE_SENT; - ncr->isr &= ~STATUS_END_OF_DMA; - ncr->dma_mode = DMA_IDLE; + if (!t128->block_loaded) { + if (!(val & MODE_DMA)) { + ncr->tcr &= ~TCR_LAST_BYTE_SENT; + ncr->isr &= ~STATUS_END_OF_DMA; + scsi_bus->tx_mode = PIO_TX_BUS; + t128_log("End of DMA.\n"); + } } } @@ -173,18 +185,16 @@ t128_dma_send_ext(void *priv, void *ext_priv) { t128_t *t128 = (t128_t *) ext_priv; ncr_t *ncr = (ncr_t *) priv; - scsi_device_t *dev = &scsi_devices[ncr->bus][ncr->target_id]; + scsi_bus_t *scsi_bus = &ncr->scsibus; + scsi_device_t *dev = &scsi_devices[ncr->bus][scsi_bus->target_id]; - if ((ncr->mode & MODE_DMA) && !timer_is_on(&t128->timer) && (dev->buffer_length > 0)) { + if ((ncr->mode & MODE_DMA) && (dev->buffer_length > 0)) { + t128_log("T128 DMA OUT, len=%d.\n", dev->buffer_length); memset(t128->buffer, 0, MIN(512, dev->buffer_length)); - t128->status |= 0x04; t128->host_pos = 0; - t128->block_count = dev->buffer_length >> 9; - - if (dev->buffer_length < 512) - t128->block_count = 1; t128->block_loaded = 1; + t128->status |= 0x04; } return 1; } @@ -194,19 +204,17 @@ t128_dma_initiator_receive_ext(void *priv, void *ext_priv) { t128_t *t128 = (t128_t *) ext_priv; ncr_t *ncr = (ncr_t *) priv; - scsi_device_t *dev = &scsi_devices[ncr->bus][ncr->target_id]; + scsi_bus_t *scsi_bus = &ncr->scsibus; + scsi_device_t *dev = &scsi_devices[ncr->bus][scsi_bus->target_id]; - if ((ncr->mode & MODE_DMA) && !timer_is_on(&t128->timer) && (dev->buffer_length > 0)) { + if ((ncr->mode & MODE_DMA) && (dev->buffer_length > 0)) { + t128_log("T128 DMA IN, len=%d.\n", dev->buffer_length); memset(t128->buffer, 0, MIN(512, dev->buffer_length)); - t128->status |= 0x04; t128->host_pos = MIN(512, dev->buffer_length); - t128->block_count = dev->buffer_length >> 9; - - if (dev->buffer_length < 512) - t128->block_count = 1; t128->block_loaded = 1; - timer_on_auto(&t128->timer, 0.02); + t128->status &= ~0x04; + timer_on_auto(&t128->timer, 10.0); } return 1; } @@ -216,157 +224,145 @@ t128_timer_on_auto(void *ext_priv, double period) { t128_t *t128 = (t128_t *) ext_priv; - if (period == 0.0) + if (period <= 0.0) timer_stop(&t128->timer); - else + else if ((period > 0.0) && !timer_is_enabled(&t128->timer)) timer_on_auto(&t128->timer, period); } void t128_callback(void *priv) { - t128_t *t128 = (void *) priv; + t128_t *t128 = (t128_t *) priv; ncr_t *ncr = &t128->ncr; - scsi_device_t *dev = &scsi_devices[ncr->bus][ncr->target_id]; - int bus; - uint8_t c; - uint8_t temp; + scsi_bus_t *scsi_bus = &ncr->scsibus; + scsi_device_t *dev = &scsi_devices[ncr->bus][scsi_bus->target_id]; + int bus; + uint8_t c; + uint8_t temp; + uint8_t status; + double period = scsi_bus->period / 60.0; - if ((ncr->dma_mode != DMA_IDLE) && (ncr->mode & MODE_DMA) && t128->block_loaded) { - if ((t128->host_pos == MIN(512, dev->buffer_length)) && t128->block_count) - t128->status |= 0x04; - - timer_on_auto(&t128->timer, ncr->period / 55.0); + if (scsi_bus->tx_mode != PIO_TX_BUS) { + if (period >= 10.0) + timer_on_auto(&t128->timer, period); + else + timer_on_auto(&t128->timer, 10.0); } - if (ncr->data_wait & 1) { - ncr->clear_req = 3; - ncr->data_wait &= ~1; - if (ncr->dma_mode == DMA_IDLE) - return; + if (scsi_bus->data_wait & 1) { + scsi_bus->clear_req = 3; + scsi_bus->data_wait &= ~1; } - switch (ncr->dma_mode) { - case DMA_SEND: - if (!(t128->status & 0x04)) { - t128_log("Write status busy, block count = %i, host pos = %i\n", t128->block_count, t128->host_pos); - break; - } - - if (!t128->block_loaded) { - t128_log("Write block not loaded\n"); - break; - } + if (scsi_bus->tx_mode == PIO_TX_BUS) { + t128_log("Timer CMD=%02x.\n", scsi_bus->command[0]); + return; + } + switch (scsi_bus->tx_mode) { + case DMA_OUT_TX_BUS: if (t128->host_pos < MIN(512, dev->buffer_length)) break; -write_again: - for (c = 0; c < 10; c++) { - ncr5380_bus_read(ncr); - if (ncr->cur_bus & BUS_REQ) - break; - } - - /* Data ready. */ - temp = t128->buffer[t128->pos]; - - bus = ncr5380_get_bus_host(ncr) & ~BUS_DATAMASK; - bus |= BUS_SETDATA(temp); - - ncr5380_bus_update(ncr, bus | BUS_ACK); - ncr5380_bus_update(ncr, bus & ~BUS_ACK); - - t128->pos++; - t128_log("T128 Buffer pos for writing = %d\n", t128->pos); - - if (t128->pos == MIN(512, dev->buffer_length)) { - t128->pos = 0; - t128->host_pos = 0; - t128->status &= ~0x02; - t128->block_count = (t128->block_count - 1) & 0xff; - t128_log("T128 Remaining blocks to be written=%d\n", t128->block_count); - if (!t128->block_count) { - t128->block_loaded = 0; - t128_log("IO End of write transfer\n"); - ncr->tcr |= TCR_LAST_BYTE_SENT; - ncr->isr |= STATUS_END_OF_DMA; - timer_stop(&t128->timer); - if (ncr->mode & MODE_ENA_EOP_INT) { - t128_log("T128 write irq\n"); - ncr5380_irq(ncr, 1); - } - } + if (!t128->block_loaded) break; - } else - goto write_again; + + while (1) { + for (c = 0; c < 10; c++) { + status = scsi_bus_read(scsi_bus); + if (status & BUS_REQ) + break; + } + + /* Data ready. */ + temp = t128->buffer[t128->pos]; + + bus = ncr5380_get_bus_host(ncr) & ~BUS_DATAMASK; + bus |= BUS_SETDATA(temp); + + scsi_bus_update(scsi_bus, bus | BUS_ACK); + scsi_bus_update(scsi_bus, bus & ~BUS_ACK); + + t128->pos++; + t128_log("T128 Buffer pos for writing = %d\n", t128->pos); + + if (t128->pos == MIN(512, dev->buffer_length)) { + t128->status |= 0x04; + t128->status &= ~0x02; + t128->pos = 0; + t128->host_pos = 0; + t128_log("T128 Remaining blocks to be written=%d\n", t128->block_count); + if (scsi_bus->data_pos >= dev->buffer_length) { + t128->block_loaded = 0; + ncr->tcr |= TCR_LAST_BYTE_SENT; + ncr->isr |= STATUS_END_OF_DMA; + if (ncr->mode & MODE_ENA_EOP_INT) { + t128_log("T128 write irq\n"); + ncr5380_irq(ncr, 1); + } + scsi_bus->tx_mode = PIO_TX_BUS; + timer_stop(&t128->timer); + t128_log("IO End of write transfer\n"); + } + break; + } + } break; - case DMA_INITIATOR_RECEIVE: - if (!(t128->status & 0x04)) { - t128_log("Read status busy, block count = %i, host pos = %i\n", t128->block_count, t128->host_pos); - break; - } - - if (!t128->block_loaded) { - t128_log("Read block not loaded\n"); - break; - } - + case DMA_IN_TX_BUS: if (t128->host_pos < MIN(512, dev->buffer_length)) break; -read_again: - for (c = 0; c < 10; c++) { - ncr5380_bus_read(ncr); - if (ncr->cur_bus & BUS_REQ) - break; - } - - /* Data ready. */ - ncr5380_bus_read(ncr); - temp = BUS_GETDATA(ncr->cur_bus); - - bus = ncr5380_get_bus_host(ncr); - - ncr5380_bus_update(ncr, bus | BUS_ACK); - ncr5380_bus_update(ncr, bus & ~BUS_ACK); - - t128->buffer[t128->pos++] = temp; - t128_log("T128 Buffer pos for reading=%d, temp=%02x, len=%d.\n", t128->pos, temp, dev->buffer_length); - - if (t128->pos == MIN(512, dev->buffer_length)) { - t128->pos = 0; - t128->host_pos = 0; - t128->status &= ~0x02; - t128->block_count = (t128->block_count - 1) & 0xff; - t128_log("T128 Remaining blocks to be read=%d, status=%02x, len=%i, cdb[0] = %02x\n", t128->block_count, t128->status, dev->buffer_length, ncr->command[0]); - if (!t128->block_count) { - t128->block_loaded = 0; - t128_log("IO End of read transfer\n"); - ncr->isr |= STATUS_END_OF_DMA; - timer_stop(&t128->timer); - if (ncr->mode & MODE_ENA_EOP_INT) { - t128_log("NCR read irq\n"); - ncr5380_irq(ncr, 1); - } - } + if (!t128->block_loaded) break; - } else - goto read_again; + + while (1) { + for (c = 0; c < 10; c++) { + status = scsi_bus_read(scsi_bus); + if (status & BUS_REQ) + break; + } + /* Data ready. */ + bus = scsi_bus_read(scsi_bus); + temp = BUS_GETDATA(bus); + + bus = ncr5380_get_bus_host(ncr); + + scsi_bus_update(scsi_bus, bus | BUS_ACK); + scsi_bus_update(scsi_bus, bus & ~BUS_ACK); + + t128->buffer[t128->pos++] = temp; + t128_log("T128 Buffer pos for reading = %d\n", t128->pos); + + if (t128->pos == MIN(512, dev->buffer_length)) { + t128->status |= 0x04; + t128->status &= ~0x02; + t128->pos = 0; + t128->host_pos = 0; + t128_log("T128 blocks read=%d, total len=%d\n", scsi_bus->data_pos, dev->buffer_length); + if (scsi_bus->data_pos >= dev->buffer_length) { + scsi_bus->bus_out |= BUS_REQ; + t128->block_loaded = 0; + timer_on_auto(&t128->timer, 10.0); + t128_log("IO End of read transfer\n"); + } + break; + } + } break; default: break; } - ncr5380_bus_read(ncr); + status = scsi_bus_read(scsi_bus); - if (!(ncr->cur_bus & BUS_BSY) && (ncr->mode & MODE_MONITOR_BUSY)) { + if (!(status & BUS_BSY) && (ncr->mode & MODE_MONITOR_BUSY)) { t128_log("Updating DMA\n"); ncr->mode &= ~MODE_DMA; - ncr->dma_mode = DMA_IDLE; - timer_on_auto(&t128->timer, 10.0); + scsi_bus->tx_mode = PIO_TX_BUS; + t128->block_loaded = 0; } } @@ -465,14 +461,13 @@ t228_feedb(void *priv) static void * t128_init(const device_t *info) { - t128_t *t128; - ncr_t *ncr; - - t128 = malloc(sizeof(t128_t)); - memset(t128, 0x00, sizeof(t128_t)); - ncr = &t128->ncr; + t128_t *t128 = calloc(1, sizeof(t128_t)); + ncr_t *ncr = &t128->ncr; + scsi_bus_t *scsi_bus; ncr->bus = scsi_get_bus(); + scsi_bus = &ncr->scsibus; + t128->type = info->local; if (info->flags & DEVICE_MCA) { rom_init(&t128->bios_rom, T128_ROM, @@ -504,7 +499,10 @@ t128_init(const device_t *info) ncr->dma_send_ext = t128_dma_send_ext; ncr->dma_initiator_receive_ext = t128_dma_initiator_receive_ext; ncr->timer = t128_timer_on_auto; - t128->status = 0x00 /*0x04*/; + scsi_bus->bus_device = ncr->bus; + scsi_bus->timer = ncr->timer; + scsi_bus->priv = ncr->priv; + t128->status = 0x00; t128->host_pos = 512; if (!t128->bios_enabled && !(info->flags & DEVICE_MCA)) t128->status |= 0x80; @@ -516,6 +514,12 @@ t128_init(const device_t *info) timer_add(&t128->timer, t128_callback, t128, 0); scsi_bus_set_speed(ncr->bus, 5000000.0); + scsi_bus->speed = 0.2; + scsi_bus->divider = 1.0; + scsi_bus->multi = 1.0; + + for (int i = 0; i < 8; i++) + scsi_device_reset(&scsi_devices[ncr->bus][i]); return t128; } @@ -543,43 +547,53 @@ t128_available(void) // clang-format off static const device_config_t t128_config[] = { { - .name = "bios_addr", - .description = "BIOS Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0xD8000, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "bios_addr", + .description = "BIOS Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0xD8000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "C800H", .value = 0xc8000 }, { .description = "CC00H", .value = 0xcc000 }, { .description = "D800H", .value = 0xd8000 }, { .description = "DC00H", .value = 0xdc000 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 5, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 5, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "None", .value = -1 }, { .description = "IRQ 3", .value = 3 }, { .description = "IRQ 5", .value = 5 }, { .description = "IRQ 7", .value = 7 }, + { .description = "IRQ 10", .value = 10 }, + { .description = "IRQ 12", .value = 12 }, + { .description = "IRQ 14", .value = 14 }, + { .description = "IRQ 15", .value = 15 }, { .description = "" } }, + .bios = { { 0 } } }, { - .name = "boot", - .description = "Enable BIOS", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "boot", + .description = "Enable BIOS", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; @@ -593,13 +607,12 @@ const device_t scsi_t128_device = { .init = t128_init, .close = t128_close, .reset = NULL, - { .available = t128_available }, + .available = t128_available, .speed_changed = NULL, .force_redraw = NULL, .config = t128_config }; - const device_t scsi_t228_device = { .name = "Trantor T228", .internal_name = "t228", @@ -608,7 +621,7 @@ const device_t scsi_t228_device = { .init = t128_init, .close = t128_close, .reset = NULL, - { .available = t128_available }, + .available = t128_available, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -622,7 +635,7 @@ const device_t scsi_pas_device = { .init = t128_init, .close = t128_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/scsi/scsi_x54x.c b/src/scsi/scsi_x54x.c index 6876e4385..c248fbe92 100644 --- a/src/scsi/scsi_x54x.c +++ b/src/scsi/scsi_x54x.c @@ -287,10 +287,9 @@ x54x_bios_scsi_command(scsi_device_t *dev, uint8_t *cdb, uint8_t *buf, int len, static uint8_t x54x_bios_read_capacity(scsi_device_t *sd, uint8_t *buf, int transfer_size) { - uint8_t *cdb; + uint8_t *cdb = (uint8_t *) malloc(12);; uint8_t ret; - cdb = (uint8_t *) malloc(12); memset(cdb, 0, 12); cdb[0] = GPCMD_READ_CDROM_CAPACITY; @@ -305,10 +304,9 @@ x54x_bios_read_capacity(scsi_device_t *sd, uint8_t *buf, int transfer_size) static uint8_t x54x_bios_inquiry(scsi_device_t *sd, uint8_t *buf, int transfer_size) { - uint8_t *cdb; + uint8_t *cdb = (uint8_t *) malloc(12); uint8_t ret; - cdb = (uint8_t *) malloc(12); memset(cdb, 0, 12); cdb[0] = GPCMD_INQUIRY; cdb[4] = 36; @@ -324,14 +322,13 @@ x54x_bios_inquiry(scsi_device_t *sd, uint8_t *buf, int transfer_size) static uint8_t x54x_bios_command_08(scsi_device_t *sd, uint8_t *buffer, int transfer_size) { - uint8_t *rcbuf; + uint8_t *rcbuf = (uint8_t *) malloc(8); uint8_t ret; int i; memset(buffer, 0x00, 6); - rcbuf = (uint8_t *) malloc(8); - ret = x54x_bios_read_capacity(sd, rcbuf, transfer_size); + ret = x54x_bios_read_capacity(sd, rcbuf, transfer_size); if (ret) { free(rcbuf); return ret; @@ -353,13 +350,12 @@ x54x_bios_command_08(scsi_device_t *sd, uint8_t *buffer, int transfer_size) static int x54x_bios_command_15(scsi_device_t *sd, uint8_t *buffer, int transfer_size) { - uint8_t *inqbuf; + uint8_t *inqbuf = (uint8_t *) malloc(36); uint8_t *rcbuf; uint8_t ret; memset(buffer, 0x00, 6); - inqbuf = (uint8_t *) malloc(36); ret = x54x_bios_inquiry(sd, inqbuf, transfer_size); if (ret) { free(inqbuf); @@ -1896,13 +1892,11 @@ x54x_mem_disable(x54x_t *dev) void * x54x_init(const device_t *info) { - x54x_t *dev; + x54x_t *dev = calloc(1, sizeof(x54x_t)); /* Allocate control block and set up basic stuff. */ - dev = malloc(sizeof(x54x_t)); if (dev == NULL) return dev; - memset(dev, 0x00, sizeof(x54x_t)); dev->type = info->local; dev->card_bus = info->flags; diff --git a/src/sio/sio_82091aa.c b/src/sio/sio_82091aa.c index cbe89c682..71f8749f2 100644 --- a/src/sio/sio_82091aa.c +++ b/src/sio/sio_82091aa.c @@ -78,7 +78,7 @@ lpt1_handler(i82091aa_t *dev) } if ((dev->regs[0x20] & 0x01) && lpt_port) - lpt1_init(lpt_port); + lpt1_setup(lpt_port); lpt1_irq((dev->regs[0x20] & 0x08) ? LPT1_IRQ : LPT2_IRQ); } @@ -257,8 +257,7 @@ i82091aa_close(void *priv) static void * i82091aa_init(const device_t *info) { - i82091aa_t *dev = (i82091aa_t *) malloc(sizeof(i82091aa_t)); - memset(dev, 0, sizeof(i82091aa_t)); + i82091aa_t *dev = (i82091aa_t *) calloc(1, sizeof(i82091aa_t)); dev->fdc = device_add(&fdc_at_device); @@ -290,7 +289,21 @@ const device_t i82091aa_device = { .init = i82091aa_init, .close = i82091aa_close, .reset = NULL, - { .available = NULL }, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t i82091aa_26e_device = { + .name = "Intel 82091AA Super I/O (Port 26Eh)", + .internal_name = "i82091aa_26e", + .flags = 0, + .local = 0x140, + .init = i82091aa_init, + .close = i82091aa_close, + .reset = NULL, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -304,7 +317,7 @@ const device_t i82091aa_398_device = { .init = i82091aa_init, .close = i82091aa_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -318,7 +331,7 @@ const device_t i82091aa_ide_pri_device = { .init = i82091aa_init, .close = i82091aa_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -332,7 +345,7 @@ const device_t i82091aa_ide_device = { .init = i82091aa_init, .close = i82091aa_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_acc3221.c b/src/sio/sio_acc3221.c index 275d9ae2e..203b1c1f1 100644 --- a/src/sio/sio_acc3221.c +++ b/src/sio/sio_acc3221.c @@ -305,7 +305,7 @@ acc3221_lpt_handle(acc3221_t *dev) lpt1_remove(); if (!(dev->regs[0xbe] & REG_BE_LPT1_DISABLE)) - lpt1_init(dev->regs[0xbf] << 2); + lpt1_setup(dev->regs[0xbf] << 2); } static void @@ -437,7 +437,7 @@ acc3221_reset(acc3221_t *dev) serial_setup(dev->uart[1], COM2_ADDR, COM2_IRQ); lpt1_remove(); - lpt1_init(LPT1_ADDR); + lpt1_setup(LPT1_ADDR); lpt1_irq(LPT1_IRQ); fdc_reset(dev->fdc); @@ -454,8 +454,7 @@ acc3221_close(void *priv) static void * acc3221_init(UNUSED(const device_t *info)) { - acc3221_t *dev = (acc3221_t *) malloc(sizeof(acc3221_t)); - memset(dev, 0, sizeof(acc3221_t)); + acc3221_t *dev = (acc3221_t *) calloc(1, sizeof(acc3221_t)); dev->fdc = device_add(&fdc_at_device); @@ -477,7 +476,7 @@ const device_t acc3221_device = { .init = acc3221_init, .close = acc3221_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_ali5123.c b/src/sio/sio_ali5123.c index 78c585c11..436e425d2 100644 --- a/src/sio/sio_ali5123.c +++ b/src/sio/sio_ali5123.c @@ -85,15 +85,22 @@ ali5123_lpt_handler(ali5123_t *dev) uint8_t global_enable = !(dev->regs[0x22] & (1 << 3)); uint8_t local_enable = !!dev->ld_regs[3][0x30]; uint8_t lpt_irq = dev->ld_regs[3][0x70]; + uint8_t lpt_dma = dev->ld_regs[3][0x74]; if (lpt_irq > 15) lpt_irq = 0xff; + if (lpt_dma == 4) + lpt_dma = 0xff; + lpt1_remove(); + lpt_set_epp(0, !!(dev->ld_regs[3][0xf0] & 0x01)); + lpt_set_ecp(0, !!(dev->ld_regs[3][0xf0] & 0x02)); + lpt_set_ext(0, !(dev->ld_regs[3][0xf0] & 0x04) || !!(dev->ld_regs[3][0xf1] & 0x80)); if (global_enable && local_enable) { ld_port = make_port(dev, 3) & 0xFFFC; if ((ld_port >= 0x0100) && (ld_port <= 0x0FFC)) - lpt1_init(ld_port); + lpt1_setup(ld_port); } lpt1_irq(lpt_irq); } @@ -133,8 +140,10 @@ ali5123_serial_handler(ali5123_t *dev, int uart) } static void -ali5123_reset(ali5123_t *dev) +ali5123_reset(void *priv) { + ali5123_t *dev = (ali5123_t *) priv; + memset(dev->regs, 0, 48); dev->regs[0x20] = 0x43; @@ -245,7 +254,7 @@ ali5123_write(uint16_t port, uint8_t val, void *priv) dev->regs[dev->cur_reg] = val; } else { valxor = val ^ dev->ld_regs[cur_ld][dev->cur_reg]; - if (((dev->cur_reg & 0xf0) == 0x70) && (cur_ld < 4)) + if (((dev->cur_reg & 0xf0) == 0x70) && (cur_ld < 4) && (cur_ld != 3)) return; /* Block writes to some logical devices. */ if (cur_ld > 0x0c) @@ -355,6 +364,9 @@ ali5123_write(uint16_t port, uint8_t val, void *priv) case 0x60: case 0x61: case 0x70: + case 0x74: + case 0xf0: + case 0xf1: if ((dev->cur_reg == 0x30) && (val & 0x01)) dev->regs[0x22] &= ~0x08; if (valxor) @@ -463,8 +475,7 @@ ali5123_close(void *priv) static void * ali5123_init(const device_t *info) { - ali5123_t *dev = (ali5123_t *) malloc(sizeof(ali5123_t)); - memset(dev, 0, sizeof(ali5123_t)); + ali5123_t *dev = (ali5123_t *) calloc(1, sizeof(ali5123_t)); dev->fdc = device_add(&fdc_at_ali_device); @@ -491,8 +502,8 @@ const device_t ali5123_device = { .local = 0x40, .init = ali5123_init, .close = ali5123_close, - .reset = NULL, - { .available = NULL }, + .reset = ali5123_reset, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_detect.c b/src/sio/sio_detect.c index 38faf3c2c..d36522fe0 100644 --- a/src/sio/sio_detect.c +++ b/src/sio/sio_detect.c @@ -47,11 +47,12 @@ sio_detect_write(uint16_t port, uint8_t val, void *priv) static uint8_t sio_detect_read(uint16_t port, void *priv) { - const sio_detect_t *dev = (sio_detect_t *) priv; + /*const sio_detect_t *dev = (sio_detect_t *) priv*/; + uint8_t ret = 0xff /*dev->regs[port & 1]*/; - pclog("sio_detect_read : port=%04x = %02X\n", port, dev->regs[port & 1]); + pclog("sio_detect_read : port=%04x = %02X\n", port, ret); - return 0xff /*dev->regs[port & 1]*/; + return ret; } static void @@ -65,8 +66,7 @@ sio_detect_close(void *priv) static void * 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)); + sio_detect_t *dev = (sio_detect_t *) calloc(1, sizeof(sio_detect_t)); device_add(&fdc_at_smc_device); @@ -110,7 +110,7 @@ const device_t sio_detect_device = { .init = sio_detect_init, .close = sio_detect_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_f82c710.c b/src/sio/sio_f82c710.c index d4afb11da..a7aa101c6 100644 --- a/src/sio/sio_f82c710.c +++ b/src/sio/sio_f82c710.c @@ -104,7 +104,7 @@ f82c710_update_ports(upc_t *dev, int set) if (dev->regs[0] & 8) { lpt_addr = dev->regs[6] * 4; - lpt1_init(lpt_addr); + lpt1_setup(lpt_addr); if ((lpt_addr == LPT1_ADDR) || (lpt_addr == LPT_MDA_ADDR)) lpt1_irq(LPT1_IRQ); else if (lpt_addr == LPT2_ADDR) @@ -215,7 +215,7 @@ f82c606_update_ports(upc_t *dev, int set) } if (dev->regs[0] & 8) { - lpt1_init(((uint16_t) dev->regs[6]) << 2); + lpt1_setup(((uint16_t) dev->regs[6]) << 2); lpt1_irq(lpt1_int); f82c710_log("LPT1 at %04X, IRQ %i\n", ((uint16_t) dev->regs[6]) << 2, lpt1_int); } @@ -364,8 +364,7 @@ f82c710_close(void *priv) static void * f82c710_init(const device_t *info) { - upc_t *dev = (upc_t *) malloc(sizeof(upc_t)); - memset(dev, 0, sizeof(upc_t)); + upc_t *dev = (upc_t *) calloc(1, sizeof(upc_t)); dev->local = info->local; if (dev->local == 606) { @@ -393,7 +392,7 @@ const device_t f82c606_device = { .init = f82c710_init, .close = f82c710_close, .reset = f82c710_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -407,7 +406,7 @@ const device_t f82c710_device = { .init = f82c710_init, .close = f82c710_close, .reset = f82c710_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_fdc37c669.c b/src/sio/sio_fdc37c669.c index 0cd686991..3be28c6ba 100644 --- a/src/sio/sio_fdc37c669.c +++ b/src/sio/sio_fdc37c669.c @@ -107,7 +107,7 @@ fdc37c669_lpt_handler(fdc37c669_t *dev) lpt_port_remove(dev->id); if ((dev->regs[0x01] & 0x04) && (dev->regs[0x23] >= 0x40)) - lpt_port_init(dev->id, ((uint16_t) (dev->regs[0x23] & mask)) << 2); + lpt_port_setup(dev->id, ((uint16_t) (dev->regs[0x23] & mask)) << 2); } static void @@ -335,8 +335,7 @@ fdc37c669_close(void *priv) static void * fdc37c669_init(const device_t *info) { - fdc37c669_t *dev = (fdc37c669_t *) malloc(sizeof(fdc37c669_t)); - memset(dev, 0, sizeof(fdc37c669_t)); + fdc37c669_t *dev = (fdc37c669_t *) calloc(1, sizeof(fdc37c669_t)); dev->id = next_id; @@ -364,7 +363,7 @@ const device_t fdc37c669_device = { .init = fdc37c669_init, .close = fdc37c669_close, .reset = fdc37c669_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -378,7 +377,7 @@ const device_t fdc37c669_370_device = { .init = fdc37c669_init, .close = fdc37c669_close, .reset = fdc37c669_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_fdc37c67x.c b/src/sio/sio_fdc37c67x.c index 871f3b1c8..931734048 100644 --- a/src/sio/sio_fdc37c67x.c +++ b/src/sio/sio_fdc37c67x.c @@ -134,7 +134,7 @@ fdc37c67x_lpt_handler(fdc37c67x_t *dev) if (global_enable && local_enable) { ld_port = make_port(dev, 3) & 0xFFFC; if ((ld_port >= 0x0100) && (ld_port <= 0x0FFC)) - lpt1_init(ld_port); + lpt1_setup(ld_port); } lpt1_irq(lpt_irq); } @@ -591,8 +591,7 @@ fdc37c67x_close(void *priv) static void * fdc37c67x_init(const device_t *info) { - fdc37c67x_t *dev = (fdc37c67x_t *) malloc(sizeof(fdc37c67x_t)); - memset(dev, 0, sizeof(fdc37c67x_t)); + fdc37c67x_t *dev = (fdc37c67x_t *) calloc(1, sizeof(fdc37c67x_t)); dev->fdc = device_add(&fdc_at_smc_device); @@ -625,7 +624,7 @@ const device_t fdc37c67x_device = { .init = fdc37c67x_init, .close = fdc37c67x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_fdc37c6xx.c b/src/sio/sio_fdc37c6xx.c index c1fb2c1a5..aa66af883 100644 --- a/src/sio/sio_fdc37c6xx.c +++ b/src/sio/sio_fdc37c6xx.c @@ -111,16 +111,16 @@ lpt1_handler(fdc37c6xx_t *dev) lpt1_remove(); switch (dev->regs[1] & 3) { case 1: - lpt1_init(LPT_MDA_ADDR); - lpt1_irq(7); + lpt1_setup(LPT_MDA_ADDR); + lpt1_irq(LPT_MDA_IRQ); break; case 2: - lpt1_init(LPT1_ADDR); - lpt1_irq(7 /*5*/); + lpt1_setup(LPT1_ADDR); + lpt1_irq(LPT1_IRQ /*LPT2_IRQ*/); break; case 3: - lpt1_init(LPT2_ADDR); - lpt1_irq(7 /*5*/); + lpt1_setup(LPT2_ADDR); + lpt1_irq(LPT1_IRQ /*LPT2_IRQ*/); break; default: @@ -232,7 +232,7 @@ fdc37c6xx_read(uint16_t port, void *priv) uint8_t ret = 0xff; if (dev->tries == 2) { - if (port == 0x3f1) + if ((port == 0x3f1) && (dev->cur_reg <= dev->max_reg)) ret = dev->regs[dev->cur_reg]; } @@ -252,7 +252,7 @@ fdc37c6xx_reset(fdc37c6xx_t *dev) serial_setup(dev->uart[1], COM2_ADDR, COM2_IRQ); lpt1_remove(); - lpt1_init(LPT1_ADDR); + lpt1_setup(LPT1_ADDR); fdc_reset(dev->fdc); fdc_remove(dev->fdc); @@ -312,10 +312,12 @@ fdc37c6xx_close(void *priv) static void * fdc37c6xx_init(const device_t *info) { - fdc37c6xx_t *dev = (fdc37c6xx_t *) malloc(sizeof(fdc37c6xx_t)); - memset(dev, 0, sizeof(fdc37c6xx_t)); + fdc37c6xx_t *dev = (fdc37c6xx_t *) calloc(1, sizeof(fdc37c6xx_t)); - dev->fdc = device_add(&fdc_at_smc_device); + if (dev->chip_id >= 0x63) + dev->fdc = device_add(&fdc_at_smc_device); + else + dev->fdc = device_add(&fdc_at_smc_661_device); dev->chip_id = info->local & 0xff; dev->has_ide = (info->local >> 8) & 0xff; @@ -346,7 +348,7 @@ const device_t fdc37c651_device = { .init = fdc37c6xx_init, .close = fdc37c6xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -360,7 +362,7 @@ const device_t fdc37c651_ide_device = { .init = fdc37c6xx_init, .close = fdc37c6xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -374,7 +376,7 @@ const device_t fdc37c661_device = { .init = fdc37c6xx_init, .close = fdc37c6xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -388,7 +390,7 @@ const device_t fdc37c661_ide_device = { .init = fdc37c6xx_init, .close = fdc37c6xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -402,7 +404,7 @@ const device_t fdc37c661_ide_sec_device = { .init = fdc37c6xx_init, .close = fdc37c6xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -416,7 +418,7 @@ const device_t fdc37c663_device = { .init = fdc37c6xx_init, .close = fdc37c6xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -430,7 +432,7 @@ const device_t fdc37c663_ide_device = { .init = fdc37c6xx_init, .close = fdc37c6xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -444,7 +446,7 @@ const device_t fdc37c665_device = { .init = fdc37c6xx_init, .close = fdc37c6xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -458,7 +460,7 @@ const device_t fdc37c665_ide_device = { .init = fdc37c6xx_init, .close = fdc37c6xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -472,7 +474,7 @@ const device_t fdc37c665_ide_pri_device = { .init = fdc37c6xx_init, .close = fdc37c6xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -486,7 +488,7 @@ const device_t fdc37c665_ide_sec_device = { .init = fdc37c6xx_init, .close = fdc37c6xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -500,7 +502,7 @@ const device_t fdc37c666_device = { .init = fdc37c6xx_init, .close = fdc37c6xx_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_fdc37c93x.c b/src/sio/sio_fdc37c93x.c index a0152c34a..dce5b11dc 100644 --- a/src/sio/sio_fdc37c93x.c +++ b/src/sio/sio_fdc37c93x.c @@ -15,8 +15,9 @@ * * Copyright 2016-2018 Miran Grca. */ -#include +#include #include +#include #include #include #include @@ -25,6 +26,7 @@ #include <86box/timer.h> #include <86box/device.h> #include <86box/pci.h> +#include <86box/pic.h> #include <86box/lpt.h> #include <86box/serial.h> #include <86box/hdc.h> @@ -35,77 +37,90 @@ #include <86box/machine.h> #include <86box/nvr.h> #include <86box/apm.h> +#include <86box/access_bus.h> #include <86box/acpi.h> -#include <86box/sio.h> +#include <86box/plat.h> #include <86box/plat_unused.h> - -#define AB_RST 0x80 - -typedef struct access_bus_t { - uint8_t control; - uint8_t status; - uint8_t own_addr; - uint8_t data; - uint8_t clock; - uint16_t base; -} access_bus_t; +#include <86box/video.h> +#include <86box/sio.h> +#include "cpu.h" typedef struct fdc37c93x_t { uint8_t chip_id; uint8_t is_apm; + uint8_t is_compaq; uint8_t has_nvr; + uint8_t max_ld; uint8_t tries; uint8_t port_370; - uint8_t gpio_regs[2]; + uint8_t gpio_reg; + uint8_t gpio_regs[256]; + uint8_t gpio_pulldn[8]; uint8_t auxio_reg; uint8_t regs[48]; + uint8_t alt_regs[3][8]; uint8_t ld_regs[11][256]; + uint16_t kbc_type; uint16_t superio_base; + uint16_t fdc_base; + uint16_t lpt_base; + uint16_t nvr_pri_base; + uint16_t nvr_sec_base; + uint16_t kbc_base; uint16_t gpio_base; /* Set to EA */ uint16_t auxio_base; - uint16_t nvr_sec_base; + uint16_t uart_base[2]; int locked; int cur_reg; fdc_t *fdc; - serial_t *uart[2]; access_bus_t *access_bus; nvr_t *nvr; acpi_t *acpi; void *kbc; + serial_t *uart[2]; } fdc37c93x_t; static void fdc37c93x_write(uint16_t port, uint8_t val, void *priv); static uint8_t fdc37c93x_read(uint16_t port, void *priv); -static uint16_t -make_port_superio(fdc37c93x_t *dev) -{ - uint16_t r0 = dev->regs[0x26]; - uint16_t r1 = dev->regs[0x27]; +static uint8_t gp_func_regs[8][8] = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, /* GP00-GP07 */ + { 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7 }, /* GP10-GP17 */ + { 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef }, /* GP20-GP27 */ + { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, /* GP30-GP37 */ + { 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7 }, /* GP40-GP47 */ + { 0xc8, 0xc9, 0xff, 0xcb, 0xcc, 0xff, 0xff, 0xff }, /* GP50-GP57 */ + { 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7 }, /* GP60-GP67 */ + { 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf } }; /* GP70-GP77 */ - uint16_t p = (r1 << 8) + r0; +static uint16_t +make_port_superio(const fdc37c93x_t *dev) +{ + const uint16_t r0 = dev->regs[0x26]; + const uint16_t r1 = dev->regs[0x27]; + + const uint16_t p = (r1 << 8) + r0; return p; } static uint16_t -make_port(fdc37c93x_t *dev, uint8_t ld) +make_port(const fdc37c93x_t *dev, const uint8_t ld) { - uint16_t r0 = dev->ld_regs[ld][0x60]; - uint16_t r1 = dev->ld_regs[ld][0x61]; + const uint16_t r0 = dev->ld_regs[ld][0x60]; + const uint16_t r1 = dev->ld_regs[ld][0x61]; - uint16_t p = (r0 << 8) + r1; + const uint16_t p = (r0 << 8) + r1; return p; } static uint16_t -make_port_sec(fdc37c93x_t *dev, uint8_t ld) +make_port_sec(const fdc37c93x_t *dev, const uint8_t ld) { - uint16_t r0 = dev->ld_regs[ld][0x62]; - uint16_t r1 = dev->ld_regs[ld][0x63]; + const uint16_t r0 = dev->ld_regs[ld][0x62]; + const uint16_t r1 = dev->ld_regs[ld][0x63]; - uint16_t p = (r0 << 8) + r1; + const uint16_t p = (r0 << 8) + r1; return p; } @@ -126,14 +141,562 @@ fdc37c93x_auxio_write(UNUSED(uint16_t port), uint8_t val, void *priv) dev->auxio_reg = val; } +static __inline uint8_t +fdc37c93x_do_read_gp(fdc37c93x_t *dev, int reg, int bit) +{ + /* Update bit 2 on the Acer V35N according to the selected graphics card type. */ + if ((reg == 2) && (strstr(machine_get_internal_name(), "acer") != NULL)) + dev->gpio_pulldn[reg] = (dev->gpio_pulldn[reg] & 0xfb) | (video_is_mda() ? 0x00 : 0x04); + + return dev->gpio_regs[reg] & dev->gpio_pulldn[reg] & (1 << bit); +} + +static __inline uint8_t +fdc37c93x_do_read_alt(const fdc37c93x_t *dev, int alt, int reg, int bit) +{ + return dev->alt_regs[alt][reg] & (1 << bit); +} + +static uint8_t +fdc37c93x_read_gp(const fdc37c93x_t *dev, int reg, int bit) +{ + uint8_t gp_reg = gp_func_regs[reg][bit]; + uint8_t gp_func_reg = dev->ld_regs[0x08][gp_reg]; + uint8_t gp_func; + uint8_t ret = 1 << bit; + + if (gp_func_reg & 0x01) switch (reg) { + default: + /* Do nothing, this GP does not exist. */ + break; + case 1: + switch (bit) { + default: + gp_func = (gp_func_reg >> 3) & 0x01; + if (gp_func == 0x00) + ret = fdc37c93x_do_read_gp((fdc37c93x_t *) dev, reg, bit); + else + ret = fdc37c93x_do_read_alt(dev, 0, reg, bit); + break; + case 1: + gp_func = (gp_func_reg >> 3) & 0x03; + if (!(gp_func & 0x01)) { + if (gp_func & 0x02) + ret = fdc37c93x_do_read_alt(dev, 0, reg, bit); + else + ret = fdc37c93x_do_read_gp((fdc37c93x_t *) dev, reg, bit); + } + break; + case 3: + gp_func = (gp_func_reg >> 3) & 0x01; + if (gp_func == 0x01) + /* TODO: Write to power LED if it's ever implemented. */ + ret = fdc37c93x_do_read_alt(dev, 0, reg, bit); + else + ret = fdc37c93x_do_read_gp((fdc37c93x_t *) dev, reg, bit); + break; + case 6: + gp_func = (gp_func_reg >> 3) & 0x03; + switch (gp_func) { + case 0: + ret = fdc37c93x_do_read_gp((fdc37c93x_t *) dev, reg, bit); + break; + case 1 ... 3: + ret = fdc37c93x_do_read_alt(dev, gp_func - 1, reg, bit); + break; + } + break; + } + break; + case 2: + switch (bit) { + default: + gp_func = (gp_func_reg >> 3) & 0x01; + if (gp_func == 0x00) + ret = fdc37c93x_do_read_gp((fdc37c93x_t *) dev, reg, bit); + else + ret = fdc37c93x_do_read_alt(dev, 0, reg, bit); + break; + case 0: + gp_func = (gp_func_reg >> 3) & 0x03; + switch (gp_func) { + case 0: + ret = fdc37c93x_do_read_gp((fdc37c93x_t *) dev, reg, bit); + break; + case 1: + ret = fdc37c93x_do_read_alt(dev, 0, reg, bit); + break; + case 2: + ret = kbc_at_read_p(dev->kbc, 2, 0x01) ? (1 << bit) : 0x00; + break; + } + break; + case 1: case 2: + gp_func = (gp_func_reg >> 3) & 0x03; + switch (gp_func) { + case 0: + ret = fdc37c93x_do_read_gp((fdc37c93x_t *) dev, reg, bit); + break; + case 1: case 2: + ret = fdc37c93x_do_read_alt(dev, gp_func - 1, reg, bit); + break; + } + break; + case 5: + gp_func = (gp_func_reg >> 3) & 0x01; + if (gp_func == 0x00) + ret = fdc37c93x_do_read_gp((fdc37c93x_t *) dev, reg, bit); + else + ret = kbc_at_read_p(dev->kbc, 2, 0x02) ? (1 << bit) : 0x00; + break; + case 6: case 7: + /* Do nothing, these bits do not exist. */ + break; + } + break; + case 4: + gp_func = (gp_func_reg >> 3) & 0x03; + switch (bit) { + default: + switch (gp_func) { + case 0: + ret = fdc37c93x_do_read_alt(dev, 0, reg, bit); + break; + case 1: + ret = fdc37c93x_do_read_gp((fdc37c93x_t *) dev, reg, bit); + break; + } + break; + case 0: case 1: + switch (gp_func) { + case 0: + ret = fdc_get_media_id(dev->fdc, bit ^ 1) ? (1 << bit) : 0x00; + break; + case 1: + ret = fdc37c93x_do_read_gp((fdc37c93x_t *) dev, reg, bit); + break; + } + break; + case 6: + switch (gp_func) { + case 0: + ret = fdc37c93x_do_read_alt(dev, 0, reg, bit); + break; + case 1: + ret = fdc37c93x_do_read_gp((fdc37c93x_t *) dev, reg, bit); + break; + case 2: + /* TODO: Write to power LED if it's ever implemented. */ + ret = fdc37c93x_do_read_alt(dev, 1, reg, bit); + break; + case 3: + ret = fdc37c93x_do_read_alt(dev, 2, reg, bit); + break; + } + break; + case 7: + switch (gp_func) { + case 0: + ret = fdc37c93x_do_read_alt(dev, 0, reg, bit); + break; + case 1: + ret = fdc37c93x_do_read_gp((fdc37c93x_t *) dev, reg, bit); + break; + case 2: + ret = fdc37c93x_do_read_alt(dev, 1, reg, bit); + break; + } + break; + } + break; + case 5: + gp_func = (gp_func_reg >> 3) & 0x03; + switch (bit) { + default: + break; + case 0: case 3: case 4: + switch (gp_func) { + case 0: + ret = fdc37c93x_do_read_alt(dev, 0, reg, bit); + break; + case 1: + ret = fdc37c93x_do_read_gp((fdc37c93x_t *) dev, reg, bit); + break; + } + break; + case 1: + switch (gp_func) { + case 0: + ret = fdc37c93x_do_read_alt(dev, 0, reg, bit); + break; + case 1: + ret = fdc37c93x_do_read_gp((fdc37c93x_t *) dev, reg, bit); + break; + } + break; + } + break; + case 6: + gp_func = (gp_func_reg >> 3) & 0x03; + switch (bit) { + default: + switch (gp_func) { + case 0: + ret = fdc37c93x_do_read_alt(dev, 0, reg, bit); + break; + case 1: + ret = fdc37c93x_do_read_gp((fdc37c93x_t *) dev, reg, bit); + break; + case 2: + ret = kbc_at_read_p(dev->kbc, 1, 1 << bit); + break; + } + break; + case 0: + switch (gp_func) { + case 0: + ret = fdc37c93x_do_read_alt(dev, 0, reg, bit); + break; + case 1: + ret = fdc37c93x_do_read_gp((fdc37c93x_t *) dev, reg, bit); + break; + case 2: + /* TODO: Write to power LED if it's ever implemented. */ + ret = fdc37c93x_do_read_alt(dev, 1, reg, bit); + break; + } + break; + case 1: + switch (gp_func) { + case 0: + ret = fdc37c93x_do_read_alt(dev, 0, reg, bit); + break; + case 1: + ret = fdc37c93x_do_read_gp((fdc37c93x_t *) dev, reg, bit); + break; + case 2: + ret = fdc37c93x_do_read_alt(dev, 1, reg, bit); + break; + } + break; + } + break; + case 7: + gp_func = (gp_func_reg >> 3) & 0x03; + switch (bit) { + default: + switch (gp_func) { + case 0: + ret = fdc37c93x_do_read_alt(dev, 0, reg, bit); + break; + case 1: + ret = fdc37c93x_do_read_gp((fdc37c93x_t *) dev, reg, bit); + break; + } + break; + } + break; + } + + if (gp_func_reg & 0x02) + ret ^= (1 << bit); + + return ret; +} + +static __inline void +fdc37c93x_do_write_gp(fdc37c93x_t *dev, int reg, int bit, int set) +{ + dev->gpio_regs[reg] = (dev->gpio_regs[reg] & ~(1 << bit)) | + (set << bit); +} + +static __inline void +fdc37c93x_do_write_alt(fdc37c93x_t *dev, int alt, int reg, int bit, int set) +{ + dev->alt_regs[alt][reg] = (dev->alt_regs[alt][reg] & ~(1 << bit)) | + (set << bit); +} + +static void +fdc37c93x_write_gp(fdc37c93x_t *dev, int reg, int bit, int set) +{ + uint8_t gp_func_reg = dev->ld_regs[0x08][gp_func_regs[reg][bit]]; + uint8_t gp_func; + + if (gp_func_reg & 0x02) + set = !set; + + if (!(gp_func_reg & 0x01)) switch (reg) { + default: + /* Do nothing, this GP does not exist. */ + break; + case 1: + switch (bit) { + default: + gp_func = (gp_func_reg >> 3) & 0x01; + if (gp_func == 0x00) + fdc37c93x_do_write_gp(dev, reg, bit, set); + else + fdc37c93x_do_write_alt(dev, 0, reg, bit, set); + break; + case 1: + gp_func = (gp_func_reg >> 3) & 0x03; + if (!(gp_func & 0x01)) { + if (gp_func & 0x02) { + set ? picint(1 << 13) : picintc(1 << 13); + fdc37c93x_do_write_alt(dev, 0, reg, bit, set); + } else + fdc37c93x_do_write_gp(dev, reg, bit, set); + } + break; + case 3: + gp_func = (gp_func_reg >> 3) & 0x01; + if (gp_func == 0x01) + /* TODO: Write to power LED if it's ever implemented. */ + fdc37c93x_do_write_alt(dev, 0, reg, bit, set); + else + fdc37c93x_do_write_gp(dev, reg, bit, set); + break; + case 6: + gp_func = (gp_func_reg >> 3) & 0x03; + switch (gp_func) { + case 0: + fdc37c93x_do_write_gp(dev, reg, bit, set); + break; + case 1 ... 3: + fdc37c93x_do_write_alt(dev, gp_func - 1, reg, bit, set); + break; + } + break; + } + break; + case 2: + switch (bit) { + default: + gp_func = (gp_func_reg >> 3) & 0x01; + if (gp_func == 0x00) + fdc37c93x_do_write_gp(dev, reg, bit, set); + else + fdc37c93x_do_write_alt(dev, 0, reg, bit, set); + break; + case 0: + gp_func = (gp_func_reg >> 3) & 0x03; + switch (gp_func) { + case 0: + fdc37c93x_do_write_gp(dev, reg, bit, set); + break; + case 1: + fdc37c93x_do_write_alt(dev, 0, reg, bit, set); + break; + case 2: + kbc_at_write_p(dev->kbc, 2, 0xfe, set); + break; + } + break; + case 1: case 2: + gp_func = (gp_func_reg >> 3) & 0x03; + switch (gp_func) { + case 0: + fdc37c93x_do_write_gp(dev, reg, bit, set); + break; + case 1: case 2: + fdc37c93x_do_write_alt(dev, gp_func - 1, reg, bit, set); + break; + } + break; + case 5: + gp_func = (gp_func_reg >> 3) & 0x01; + if (gp_func == 0x00) + fdc37c93x_do_write_gp(dev, reg, bit, set); + else + kbc_at_write_p(dev->kbc, 2, 0xfd, set << 1); + break; + case 6: case 7: + /* Do nothing, these bits do not exist. */ + break; + } + break; + case 4: + gp_func = (gp_func_reg >> 3) & 0x03; + switch (bit) { + default: + switch (gp_func) { + case 0: + fdc37c93x_do_write_alt(dev, 0, reg, bit, set); + break; + case 1: + fdc37c93x_do_write_gp(dev, reg, bit, set); + break; + } + break; + case 0: case 1: + switch (gp_func) { + case 0: + fdc_set_media_id(dev->fdc, bit ^ 1, set); + break; + case 1: + fdc37c93x_do_write_gp(dev, reg, bit, set); + break; + } + break; + case 6: + switch (gp_func) { + case 0: + fdc37c93x_do_write_alt(dev, 0, reg, bit, set); + break; + case 1: + fdc37c93x_do_write_gp(dev, reg, bit, set); + break; + case 2: + /* TODO: Write to power LED if it's ever implemented. */ + fdc37c93x_do_write_alt(dev, 1, reg, bit, set); + break; + case 3: + fdc37c93x_do_write_alt(dev, 2, reg, bit, set); + break; + } + break; + case 7: + switch (gp_func) { + case 0: + fdc37c93x_do_write_alt(dev, 0, reg, bit, set); + break; + case 1: + fdc37c93x_do_write_gp(dev, reg, bit, set); + break; + case 2: + fdc37c93x_do_write_alt(dev, 1, reg, bit, set); + if (!set) + smi_raise(); + break; + } + break; + } + break; + case 5: + gp_func = (gp_func_reg >> 3) & 0x03; + switch (bit) { + default: + break; + case 0: case 3: case 4: + switch (gp_func) { + case 0: + fdc37c93x_do_write_alt(dev, 0, reg, bit, set); + break; + case 1: + fdc37c93x_do_write_gp(dev, reg, bit, set); + break; + } + break; + case 1: + switch (gp_func) { + case 0: + fdc37c93x_do_write_alt(dev, 0, reg, bit, set); + if (set) + plat_power_off(); + break; + case 1: + fdc37c93x_do_write_gp(dev, reg, bit, set); + break; + } + break; + } + break; + case 6: + gp_func = (gp_func_reg >> 3) & 0x03; + switch (bit) { + default: + switch (gp_func) { + case 0: + fdc37c93x_do_write_alt(dev, 0, reg, bit, set); + break; + case 1: + fdc37c93x_do_write_gp(dev, reg, bit, set); + break; + case 2: + kbc_at_write_p(dev->kbc, 1, ~(1 << bit), set << bit); + break; + } + break; + case 0: + switch (gp_func) { + case 0: + fdc37c93x_do_write_alt(dev, 0, reg, bit, set); + break; + case 1: + fdc37c93x_do_write_gp(dev, reg, bit, set); + break; + case 2: + /* TODO: Write to power LED if it's ever implemented. */ + fdc37c93x_do_write_alt(dev, 1, reg, bit, set); + break; + } + break; + case 1: + switch (gp_func) { + case 0: + fdc37c93x_do_write_alt(dev, 0, reg, bit, set); + break; + case 1: + fdc37c93x_do_write_gp(dev, reg, bit, set); + break; + case 2: + fdc37c93x_do_write_alt(dev, 1, reg, bit, set); + break; + } + break; + } + break; + case 7: + gp_func = (gp_func_reg >> 3) & 0x03; + switch (bit) { + default: + switch (gp_func) { + case 0: + fdc37c93x_do_write_alt(dev, 0, reg, bit, set); + break; + case 1: + fdc37c93x_do_write_gp(dev, reg, bit, set); + break; + } + break; + } + break; + } +} + static uint8_t fdc37c93x_gpio_read(uint16_t port, void *priv) { const fdc37c93x_t *dev = (fdc37c93x_t *) priv; uint8_t ret = 0xff; - if (strcmp(machine_get_internal_name(), "vectra54")) - ret = dev->gpio_regs[port & 1]; + if (dev->locked) { + if (dev->is_compaq) + ret = fdc37c93x_read(port & 0x0001, priv); + } else if (port & 0x0001) switch (dev->gpio_reg) { + case 0x01: case 0x02: + ret = 0x00; + for (uint8_t i = 0; i < 8; i++) + ret |= fdc37c93x_read_gp(dev, dev->gpio_reg, i); + break; + case 0x03: + ret = dev->ld_regs[0x08][0xf4]; + break; + case 0x04 ... 0x07: + if (dev->chip_id >= FDC37C93X_FR) { + ret = 0x00; + for (uint8_t i = 0; i < 8; i++) + ret |= fdc37c93x_read_gp(dev, dev->gpio_reg, i); + } + break; + case 0x08 ... 0x0f: + if (dev->chip_id >= FDC37C93X_FR) + ret = dev->ld_regs[0x08][0xb0 + dev->gpio_reg - 0x08]; + break; + } else + ret = dev->gpio_reg; return ret; } @@ -143,73 +706,149 @@ fdc37c93x_gpio_write(uint16_t port, uint8_t val, void *priv) { fdc37c93x_t *dev = (fdc37c93x_t *) priv; - if (!(port & 1)) - dev->gpio_regs[0] = (dev->gpio_regs[0] & 0xfc) | (val & 0x03); + if (dev->locked) { + if (dev->is_compaq) + fdc37c93x_write(port & 0x0001, val, priv); + } else if (port & 0x0001) switch (dev->gpio_reg) { + case 0x01: case 0x02: + for (uint8_t i = 0; i < 8; i++) + fdc37c93x_write_gp(dev, dev->gpio_reg, i, val & (1 << i)); + break; + case 0x03: + if (dev->chip_id >= FDC37C93X_FR) + dev->ld_regs[0x08][0xf4] = val & 0xef; + else + dev->ld_regs[0x08][0xf4] = val & 0x0f; + break; + case 0x04 ... 0x07: + if (dev->chip_id >= FDC37C93X_FR) + for (uint8_t i = 0; i < 8; i++) + fdc37c93x_write_gp(dev, dev->gpio_reg, i, val & (1 << i)); + break; + case 0x08: case 0x0a: + case 0x0c: case 0x0e: + if (dev->chip_id >= FDC37C93X_FR) + dev->ld_regs[0x08][0xb0 + dev->gpio_reg - 0x08] = val; + break; + case 0x09: + if (dev->chip_id >= FDC37C93X_FR) + dev->ld_regs[0x08][0xb0 + dev->gpio_reg - 0x08] = val & 0xd3; + break; + case 0x0b: + if (dev->chip_id >= FDC37C93X_FR) + dev->ld_regs[0x08][0xb0 + dev->gpio_reg - 0x08] = val & 0x17; + break; + case 0x0d: + if (dev->chip_id == FDC37C93X_APM) + dev->ld_regs[0x08][0xb0 + dev->gpio_reg - 0x08] = val; + else if (dev->chip_id == FDC37C93X_FR) + dev->ld_regs[0x08][0xb0 + dev->gpio_reg - 0x08] = val & 0xbf; + break; + case 0x0f: + if (dev->chip_id == FDC37C93X_APM) + dev->ld_regs[0x08][0xb0 + dev->gpio_reg - 0x08] = val & 0x7f; + else if (dev->chip_id == FDC37C93X_FR) + dev->ld_regs[0x08][0xb0 + dev->gpio_reg - 0x08] = val & 0x3f; + break; + } else + dev->gpio_reg = val; } static void fdc37c93x_superio_handler(fdc37c93x_t *dev) { - io_removehandler(dev->superio_base, 0x0002, - fdc37c93x_read, NULL, NULL, fdc37c93x_write, NULL, NULL, dev); - dev->superio_base = make_port_superio(dev); - io_sethandler(dev->superio_base, 0x0002, - fdc37c93x_read, NULL, NULL, fdc37c93x_write, NULL, NULL, dev); + if (!dev->is_compaq) { + if (dev->superio_base != 0x0000) + io_removehandler(dev->superio_base, 0x0002, + fdc37c93x_read, NULL, NULL, fdc37c93x_write, NULL, NULL, dev); + dev->superio_base = make_port_superio(dev); + if (dev->superio_base != 0x0000) + io_sethandler(dev->superio_base, 0x0002, + fdc37c93x_read, NULL, NULL, fdc37c93x_write, NULL, NULL, dev); + } } static void fdc37c93x_fdc_handler(fdc37c93x_t *dev) { - uint16_t ld_port = 0; - uint8_t global_enable = !!(dev->regs[0x22] & (1 << 0)); - uint8_t local_enable = !!dev->ld_regs[0][0x30]; + const uint8_t global_enable = !!(dev->regs[0x22] & (1 << 0)); + const uint8_t local_enable = !!dev->ld_regs[0][0x30]; + const uint16_t old_base = dev->fdc_base; - fdc_remove(dev->fdc); - if (global_enable && local_enable) { - ld_port = make_port(dev, 0) & 0xFFF8; - if ((ld_port >= 0x0100) && (ld_port <= 0x0FF8)) - fdc_set_base(dev->fdc, ld_port); + dev->fdc_base = 0x0000; + + if (global_enable && local_enable) + dev->fdc_base = make_port(dev, 0) & 0xfff8; + + if (dev->fdc_base != old_base) { + if ((old_base >= 0x0100) && (old_base <= 0x0ff8)) + fdc_remove(dev->fdc); + + if ((dev->fdc_base >= 0x0100) && (dev->fdc_base <= 0x0ff8)) + fdc_set_base(dev->fdc, dev->fdc_base); } } static void fdc37c93x_lpt_handler(fdc37c93x_t *dev) { - uint16_t ld_port = 0; - uint8_t global_enable = !!(dev->regs[0x22] & (1 << 3)); - uint8_t local_enable = !!dev->ld_regs[3][0x30]; - uint8_t lpt_irq = dev->ld_regs[3][0x70]; + const uint8_t global_enable = !!(dev->regs[0x22] & (1 << 3)); + const uint8_t local_enable = !!dev->ld_regs[3][0x30]; + uint8_t lpt_irq = dev->ld_regs[3][0x70]; + const uint16_t old_base = dev->lpt_base; if (lpt_irq > 15) lpt_irq = 0xff; - lpt1_remove(); - if (global_enable && local_enable) { - ld_port = make_port(dev, 3) & 0xFFFC; - if ((ld_port >= 0x0100) && (ld_port <= 0x0FFC)) - lpt1_init(ld_port); + dev->lpt_base = 0x0000; + + if (global_enable && local_enable) + dev->lpt_base = make_port(dev, 3) & 0xfffc; + + if (dev->lpt_base != old_base) { + if ((old_base >= 0x0100) && (old_base <= 0x0ffc)) + lpt1_remove(); + + if ((dev->lpt_base >= 0x0100) && (dev->lpt_base <= 0x0ffc)) + lpt1_setup(dev->lpt_base); } + lpt1_irq(lpt_irq); } static void -fdc37c93x_serial_handler(fdc37c93x_t *dev, int uart) +fdc37c93x_serial_handler(fdc37c93x_t *dev, const int uart) { - uint16_t ld_port = 0; - uint8_t uart_no = 4 + uart; - uint8_t global_enable = !!(dev->regs[0x22] & (1 << uart_no)); - uint8_t local_enable = !!dev->ld_regs[uart_no][0x30]; + const uint8_t uart_no = 4 + uart; + const uint8_t global_enable = !!(dev->regs[0x22] & (1 << uart_no)); + const uint8_t local_enable = !!dev->ld_regs[uart_no][0x30]; + const uint16_t old_base = dev->uart_base[uart]; - serial_remove(dev->uart[uart]); - if (global_enable && local_enable) { - ld_port = make_port(dev, uart_no) & 0xFFF8; - if ((ld_port >= 0x0100) && (ld_port <= 0x0FF8)) - serial_setup(dev->uart[uart], ld_port, dev->ld_regs[uart_no][0x70]); + dev->uart_base[uart] = 0x0000; + + if (global_enable && local_enable) + dev->uart_base[uart] = make_port(dev, uart_no) & 0xfff8; + + if (dev->uart_base[uart] != old_base) { + if ((old_base >= 0x0100) && (old_base <= 0x0ff8)) + serial_remove(dev->uart[uart]); + + if ((dev->uart_base[uart] >= 0x0100) && (dev->uart_base[uart] <= 0x0ff8)) + serial_setup(dev->uart[uart], dev->uart_base[uart], dev->ld_regs[uart_no][0x70]); } + + /* + TODO: If UART 2's own IRQ pin is also enabled when shared, + it should also be asserted. + */ + if ((dev->chip_id >= FDC37C93X_FR) && (dev->ld_regs[4][0xf0] & 0x80)) + serial_irq(dev->uart[uart], dev->ld_regs[4][0x70]); + else + serial_irq(dev->uart[uart], dev->ld_regs[uart_no][0x70]); } static void -fdc37c93x_nvr_pri_handler(fdc37c93x_t *dev) +fdc37c93x_nvr_pri_handler(const fdc37c93x_t *dev) { uint8_t local_enable = !!dev->ld_regs[6][0x30]; @@ -224,18 +863,24 @@ fdc37c93x_nvr_pri_handler(fdc37c93x_t *dev) static void fdc37c93x_nvr_sec_handler(fdc37c93x_t *dev) { - uint16_t ld_port = 0; - uint8_t local_enable = !!dev->ld_regs[6][0x30]; + uint8_t local_enable = !!dev->ld_regs[6][0x30]; + const uint16_t old_base = dev->nvr_sec_base; local_enable &= (((dev->ld_regs[6][0xf0] & 0xe0) == 0x80) || ((dev->ld_regs[6][0xf0] & 0xe0) == 0xe0)); - nvr_at_sec_handler(0, dev->nvr_sec_base, dev->nvr); - if (local_enable) { - dev->nvr_sec_base = ld_port = make_port_sec(dev, 6) & 0xFFFE; + dev->nvr_sec_base = 0x0000; + + if (local_enable) + dev->nvr_sec_base = make_port_sec(dev, 6) & 0xfffe; + + if (dev->nvr_sec_base != old_base) { + if ((old_base > 0x0000) && (old_base <= 0x0ffe)) + nvr_at_sec_handler(0, dev->nvr_sec_base, dev->nvr); + /* Datasheet erratum: First it says minimum address is 0x0100, but later implies that it's 0x0000 and that default is 0x0070, same as (unrelocatable) primary NVR. */ - if (ld_port <= 0x0FFE) + if ((dev->nvr_sec_base > 0x0000) && (dev->nvr_sec_base <= 0x0ffe)) nvr_at_sec_handler(1, dev->nvr_sec_base, dev->nvr); } } @@ -243,22 +888,32 @@ fdc37c93x_nvr_sec_handler(fdc37c93x_t *dev) static void fdc37c93x_kbc_handler(fdc37c93x_t *dev) { - uint8_t local_enable = !!dev->ld_regs[7][0x30]; + const uint8_t local_enable = !!dev->ld_regs[7][0x30]; + const uint16_t old_base = dev->kbc_base; - kbc_at_handler(local_enable, dev->kbc); + dev->kbc_base = local_enable ? 0x0060 : 0x0000; + + if (dev->kbc_base != old_base) + kbc_at_handler(local_enable, dev->kbc_base, dev->kbc); } static void fdc37c93x_auxio_handler(fdc37c93x_t *dev) { - uint16_t ld_port = 0; - uint8_t local_enable = !!dev->ld_regs[8][0x30]; + const uint8_t local_enable = !!dev->ld_regs[8][0x30]; + const uint16_t old_base = dev->auxio_base; - io_removehandler(dev->auxio_base, 0x0001, - fdc37c93x_auxio_read, NULL, NULL, fdc37c93x_auxio_write, NULL, NULL, dev); - if (local_enable) { - dev->auxio_base = ld_port = make_port(dev, 8); - if ((ld_port >= 0x0100) && (ld_port <= 0x0FFF)) + if (local_enable) + dev->auxio_base = make_port(dev, 8); + else + dev->auxio_base = 0x0000; + + if (dev->auxio_base != old_base) { + if ((old_base >= 0x0100) && (old_base <= 0x0fff)) + io_removehandler(old_base, 0x0001, + fdc37c93x_auxio_read, NULL, NULL, fdc37c93x_auxio_write, NULL, NULL, dev); + + if ((dev->auxio_base >= 0x0100) && (dev->auxio_base <= 0x0fff)) io_sethandler(dev->auxio_base, 0x0001, fdc37c93x_auxio_read, NULL, NULL, fdc37c93x_auxio_write, NULL, NULL, dev); } @@ -267,113 +922,56 @@ fdc37c93x_auxio_handler(fdc37c93x_t *dev) static void fdc37c93x_gpio_handler(fdc37c93x_t *dev) { - uint16_t ld_port = 0; - uint8_t local_enable; + const uint8_t local_enable = !!(dev->regs[0x03] & 0x80) || + (dev->is_compaq && dev->locked); + const uint16_t old_base = dev->gpio_base; - local_enable = !!(dev->regs[0x03] & 0x80); + dev->gpio_base = 0x0000; - io_removehandler(dev->gpio_base, 0x0002, - fdc37c93x_gpio_read, NULL, NULL, fdc37c93x_gpio_write, NULL, NULL, dev); - if (local_enable) { - switch (dev->regs[0x03] & 0x03) { - case 0: - ld_port = 0xe0; - break; - case 1: - ld_port = 0xe2; - break; - case 2: - ld_port = 0xe4; - break; - case 3: - ld_port = 0xea; /* Default */ - break; + if (local_enable) switch (dev->regs[0x03] & 0x03) { + default: + break; + case 0: + dev->gpio_base = 0x00e0; + break; + case 1: + dev->gpio_base = 0x00e2; + break; + case 2: + dev->gpio_base = 0x00e4; + break; + case 3: + dev->gpio_base = 0x00ea; /* Default */ + break; + } - default: - break; - } - dev->gpio_base = ld_port; - if (ld_port > 0x0000) + if (dev->gpio_base != old_base) { + if (old_base != 0x0000) + io_removehandler(old_base, 0x0002, + fdc37c93x_gpio_read, NULL, NULL, fdc37c93x_gpio_write, NULL, NULL, dev); + + if (dev->gpio_base > 0x0000) io_sethandler(dev->gpio_base, 0x0002, fdc37c93x_gpio_read, NULL, NULL, fdc37c93x_gpio_write, NULL, NULL, dev); } } -static uint8_t -fdc37c93x_access_bus_read(uint16_t port, void *priv) -{ - const access_bus_t *dev = (access_bus_t *) priv; - uint8_t ret = 0xff; - - switch (port & 3) { - case 0: - ret = (dev->status & 0xBF); - break; - case 1: - ret = (dev->own_addr & 0x7F); - break; - case 2: - ret = dev->data; - break; - case 3: - ret = (dev->clock & 0x87); - break; - - default: - break; - } - - return ret; -} - -static void -fdc37c93x_access_bus_write(uint16_t port, uint8_t val, void *priv) -{ - access_bus_t *dev = (access_bus_t *) priv; - - switch (port & 3) { - case 0: - dev->control = (val & 0xCF); - break; - case 1: - dev->own_addr = (val & 0x7F); - break; - case 2: - dev->data = val; - break; - case 3: - dev->clock &= 0x80; - dev->clock |= (val & 0x07); - break; - - default: - break; - } -} - static void fdc37c93x_access_bus_handler(fdc37c93x_t *dev) { - uint16_t ld_port = 0; - uint8_t global_enable = !!(dev->regs[0x22] & (1 << 6)); - uint8_t local_enable = !!dev->ld_regs[9][0x30]; + const uint8_t global_enable = !!(dev->regs[0x22] & (1 << 6)); + const uint8_t local_enable = !!dev->ld_regs[9][0x30]; + const uint16_t ld_port = dev->access_bus->base = make_port(dev, 9); - io_removehandler(dev->access_bus->base, 0x0004, - fdc37c93x_access_bus_read, NULL, NULL, fdc37c93x_access_bus_write, NULL, NULL, dev->access_bus); - if (global_enable && local_enable) { - dev->access_bus->base = ld_port = make_port(dev, 9); - if ((ld_port >= 0x0100) && (ld_port <= 0x0FFC)) - io_sethandler(dev->access_bus->base, 0x0004, - fdc37c93x_access_bus_read, NULL, NULL, fdc37c93x_access_bus_write, NULL, NULL, dev->access_bus); - } + access_bus_handler(dev->access_bus, global_enable && local_enable, ld_port); } static void fdc37c93x_acpi_handler(fdc37c93x_t *dev) { - uint16_t ld_port = 0; - uint8_t local_enable = !!dev->ld_regs[0x0a][0x30]; - uint8_t sci_irq = dev->ld_regs[0x0a][0x70]; + uint16_t ld_port; + const uint8_t local_enable = !!dev->ld_regs[0x0a][0x30]; + const uint8_t sci_irq = dev->ld_regs[0x0a][0x70]; acpi_update_io_mapping(dev->acpi, 0x0000, local_enable); if (local_enable) { @@ -392,362 +990,508 @@ fdc37c93x_acpi_handler(fdc37c93x_t *dev) acpi_set_irq_line(dev->acpi, sci_irq); } +static void +fdc37c93x_state_change(fdc37c93x_t *dev, const uint8_t locked) +{ + dev->locked = locked; + fdc_3f1_enable(dev->fdc, !locked); + fdc37c93x_gpio_handler(dev); +} + static void 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; - uint8_t keep = 0x00; + uint8_t index = !(port & 1); + uint8_t valxor; - /* Compaq Presario 4500: Unlock at FB, Register at EA, Data at EB, Lock at F9. */ - if ((port == 0xea) || (port == 0xf9) || (port == 0xfb)) - index = 1; - else if (port == 0xeb) - index = 0; - - if (index) { - if ((val == 0x55) && !dev->locked) { + if (port == 0x00fb) { + fdc37c93x_state_change(dev, 1); + dev->tries = 0; + } else if (port == 0x00f9) + fdc37c93x_state_change(dev, 0); + else if (index) { + if ((!dev->is_compaq) && (val == 0x55) && !dev->locked) { if (dev->tries) { - dev->locked = 1; - fdc_3f1_enable(dev->fdc, 0); + fdc37c93x_state_change(dev, 1); dev->tries = 0; } else dev->tries++; - } else { - if (dev->locked) { - if (val == 0xaa) { - dev->locked = 0; - fdc_3f1_enable(dev->fdc, 1); - return; - } + } else if (dev->locked) { + if ((!dev->is_compaq) && (val == 0xaa)) + fdc37c93x_state_change(dev, 0); + else dev->cur_reg = val; - } else { - if (dev->tries) - dev->tries = 0; - } - } - return; - } else { - if (dev->locked) { - if (dev->cur_reg < 48) { - valxor = val ^ dev->regs[dev->cur_reg]; - if ((val == 0x20) || (val == 0x21)) - return; - dev->regs[dev->cur_reg] = val; - } else { - valxor = val ^ dev->ld_regs[dev->regs[7]][dev->cur_reg]; - if (((dev->cur_reg & 0xF0) == 0x70) && (dev->regs[7] < 4)) - return; - /* Block writes to some logical devices. */ - if (dev->regs[7] > 0x0a) - return; - else - switch (dev->regs[7]) { - // case 0x01: - // case 0x02: - // return; - case 0x06: - if (!dev->has_nvr) - return; - /* Bits 0 to 3 of logical device 6 (RTC) register F0h must stay set - once they are set. */ - else if (dev->cur_reg == 0xf0) - keep = dev->ld_regs[dev->regs[7]][dev->cur_reg] & 0x0f; - break; - case 0x09: - /* If we're on the FDC37C935, return as this is not a valid - logical device there. */ - if (!dev->is_apm && (dev->chip_id == 0x02)) - return; - break; - case 0x0a: - /* If we're not on the FDC37C931APM, return as this is not a - valid logical device there. */ - if (!dev->is_apm) - return; - break; + } else if ((!dev->is_compaq) && dev->tries) + dev->tries = 0; + } else if (dev->locked) { + if (dev->cur_reg < 0x30) { + valxor = val ^ dev->regs[dev->cur_reg]; - default: - break; - } - dev->ld_regs[dev->regs[7]][dev->cur_reg] = val | keep; - } - } else - return; - } - - if (dev->cur_reg < 48) { - switch (dev->cur_reg) { - case 0x03: - if (valxor & 0x83) - fdc37c93x_gpio_handler(dev); - dev->regs[0x03] &= 0x83; - break; - case 0x22: - if (valxor & 0x01) - fdc37c93x_fdc_handler(dev); - if (valxor & 0x08) - fdc37c93x_lpt_handler(dev); - if (valxor & 0x10) - fdc37c93x_serial_handler(dev, 0); - if (valxor & 0x20) - fdc37c93x_serial_handler(dev, 1); - if ((valxor & 0x40) && (dev->chip_id != 0x02)) - fdc37c93x_access_bus_handler(dev); - break; - - case 0x27: - if (dev->chip_id != 0x02) - fdc37c93x_superio_handler(dev); - break; - - default: - break; - } - - return; - } - - switch (dev->regs[7]) { - case 0: - /* FDD */ switch (dev->cur_reg) { - case 0x30: - case 0x60: - case 0x61: - if ((dev->cur_reg == 0x30) && (val & 0x01)) - dev->regs[0x22] |= 0x01; - if (valxor) - fdc37c93x_fdc_handler(dev); + case 0x02: + dev->regs[dev->cur_reg] = val; + if (val == 0x02) + fdc37c93x_state_change(dev, 0); break; - case 0xF0: + case 0x03: + dev->regs[dev->cur_reg] = val & 0x83; + break; + case 0x07: case 0x26: + case 0x2e ... 0x2f: + dev->regs[dev->cur_reg] = val; + break; + case 0x22: + if (dev->chip_id >= FDC37C93X_FR) + dev->regs[dev->cur_reg] = val & 0x7f; + else + dev->regs[dev->cur_reg] = val & 0x6f; + if (valxor & 0x01) - fdc_update_enh_mode(dev->fdc, val & 0x01); - if (valxor & 0x10) - fdc_set_swap(dev->fdc, (val & 0x10) >> 4); - break; - case 0xF1: - if (valxor & 0xC) - fdc_update_densel_force(dev->fdc, (val & 0xc) >> 2); - break; - case 0xF2: - if (valxor & 0xC0) - fdc_update_rwc(dev->fdc, 3, (val & 0xc0) >> 6); - if (valxor & 0x30) - fdc_update_rwc(dev->fdc, 2, (val & 0x30) >> 4); - if (valxor & 0x0C) - fdc_update_rwc(dev->fdc, 1, (val & 0x0c) >> 2); - if (valxor & 0x03) - fdc_update_rwc(dev->fdc, 0, (val & 0x03)); - break; - case 0xF4: - if (valxor & 0x18) - fdc_update_drvrate(dev->fdc, 0, (val & 0x18) >> 3); - break; - case 0xF5: - if (valxor & 0x18) - fdc_update_drvrate(dev->fdc, 1, (val & 0x18) >> 3); - break; - case 0xF6: - if (valxor & 0x18) - fdc_update_drvrate(dev->fdc, 2, (val & 0x18) >> 3); - break; - case 0xF7: - if (valxor & 0x18) - fdc_update_drvrate(dev->fdc, 3, (val & 0x18) >> 3); - break; - - default: - break; - } - break; - case 3: - /* Parallel port */ - switch (dev->cur_reg) { - case 0x30: - case 0x60: - case 0x61: - case 0x70: - if ((dev->cur_reg == 0x30) && (val & 0x01)) - dev->regs[0x22] |= 0x08; - if (valxor) + fdc37c93x_fdc_handler(dev); + if (valxor & 0x08) fdc37c93x_lpt_handler(dev); - break; - - default: - break; - } - break; - case 4: - /* Serial port 1 */ - switch (dev->cur_reg) { - case 0x30: - case 0x60: - case 0x61: - case 0x70: - if ((dev->cur_reg == 0x30) && (val & 0x01)) - dev->regs[0x22] |= 0x10; - if (valxor) + if (valxor & 0x10) fdc37c93x_serial_handler(dev, 0); - break; - - default: - break; - } - break; - case 5: - /* Serial port 2 */ - switch (dev->cur_reg) { - case 0x30: - case 0x60: - case 0x61: - case 0x70: - if ((dev->cur_reg == 0x30) && (val & 0x01)) - dev->regs[0x22] |= 0x20; - if (valxor) + if (valxor & 0x20) fdc37c93x_serial_handler(dev, 1); - break; - - default: - break; - } - break; - case 6: - /* RTC/NVR */ - if (!dev->has_nvr) - return; - switch (dev->cur_reg) { - case 0x30: - if (valxor) { - fdc37c93x_nvr_pri_handler(dev); - if (dev->chip_id != 0x02) - fdc37c93x_nvr_sec_handler(dev); - } - break; - case 0x62: - case 0x63: - if ((dev->chip_id != 0x02) && valxor) - fdc37c93x_nvr_sec_handler(dev); - break; - case 0xf0: - if (valxor) { - nvr_lock_set(0x80, 0x20, !!(dev->ld_regs[6][dev->cur_reg] & 0x01), dev->nvr); - nvr_lock_set(0xa0, 0x20, !!(dev->ld_regs[6][dev->cur_reg] & 0x02), dev->nvr); - nvr_lock_set(0xc0, 0x20, !!(dev->ld_regs[6][dev->cur_reg] & 0x04), dev->nvr); - nvr_lock_set(0xe0, 0x20, !!(dev->ld_regs[6][dev->cur_reg] & 0x08), dev->nvr); - if ((dev->chip_id == 0x02) && (dev->ld_regs[6][dev->cur_reg] & 0x80)) - nvr_bank_set(0, 1, dev->nvr); - else if ((dev->chip_id != 0x02) && (dev->ld_regs[6][dev->cur_reg] & 0x80)) - switch ((dev->ld_regs[6][dev->cur_reg] >> 4) & 0x07) { - default: - case 0x00: - nvr_bank_set(0, 0xff, dev->nvr); - nvr_bank_set(1, 1, dev->nvr); - break; - case 0x01: - nvr_bank_set(0, 0, dev->nvr); - nvr_bank_set(1, 1, dev->nvr); - break; - case 0x02: - case 0x04: - nvr_bank_set(0, 0xff, dev->nvr); - nvr_bank_set(1, 0xff, dev->nvr); - break; - case 0x03: - case 0x05: - nvr_bank_set(0, 0, dev->nvr); - nvr_bank_set(1, 0xff, dev->nvr); - break; - case 0x06: - nvr_bank_set(0, 0xff, dev->nvr); - nvr_bank_set(1, 2, dev->nvr); - break; - case 0x07: - nvr_bank_set(0, 0, dev->nvr); - nvr_bank_set(1, 2, dev->nvr); - break; - } - else { - nvr_bank_set(0, 0, dev->nvr); - if (dev->chip_id != 0x02) - nvr_bank_set(1, 0xff, dev->nvr); - } - - fdc37c93x_nvr_pri_handler(dev); - if (dev->chip_id != 0x02) - fdc37c93x_nvr_sec_handler(dev); - } - break; - - default: - break; - } - break; - case 7: - /* Keyboard */ - switch (dev->cur_reg) { - case 0x30: - if (valxor) - fdc37c93x_kbc_handler(dev); - break; - - default: - break; - } - break; - case 8: - /* Auxiliary I/O */ - switch (dev->cur_reg) { - case 0x30: - case 0x60: - case 0x61: - case 0x70: - if (valxor) - fdc37c93x_auxio_handler(dev); - break; - - default: - break; - } - break; - case 9: - /* Access bus (FDC37C932FR and FDC37C931APM only) */ - switch (dev->cur_reg) { - case 0x30: - case 0x60: - case 0x61: - case 0x70: - if ((dev->cur_reg == 0x30) && (val & 0x01)) - dev->regs[0x22] |= 0x40; - if (valxor) + if ((dev->chip_id >= FDC37C93X_FR) && (valxor & 0x40)) fdc37c93x_access_bus_handler(dev); break; + case 0x23: + if (dev->chip_id >= FDC37C93X_FR) + dev->regs[dev->cur_reg] = val & 0x7f; + else + dev->regs[dev->cur_reg] = val & 0x6f; + break; + case 0x24: + if (dev->chip_id >= FDC37C93X_FR) + dev->regs[dev->cur_reg] = val & 0xcf; + else + dev->regs[dev->cur_reg] = val & 0xcc; + + if ((dev->chip_id >= FDC37C93X_FR) && (valxor & 0x01)) { + serial_set_clock_src(dev->uart[0], (val & 0x01) ? + 48000000.0 : 24000000.0); + serial_set_clock_src(dev->uart[1], (val & 0x01) ? + 48000000.0 : 24000000.0); + } + break; + case 0x27: + if (dev->chip_id >= FDC37C93X_FR) { + dev->regs[dev->cur_reg] = val; + + fdc37c93x_superio_handler(dev); + } + break; + case 0x28: + if (dev->chip_id >= FDC37C93X_FR) + dev->regs[dev->cur_reg] = val & 0x1f; + break; default: break; } - break; - case 10: - /* Access bus (FDC37C931APM only) */ - switch (dev->cur_reg) { - case 0x30: - case 0x60: - case 0x61: - case 0x62: - case 0x63: - case 0x70: - if (valxor) - fdc37c93x_acpi_handler(dev); - break; + } else { + valxor = val ^ dev->ld_regs[dev->regs[7]][dev->cur_reg]; - default: + if ((dev->regs[7] <= dev->max_ld) && ((dev->regs[7] != 0x08) || + (dev->cur_reg < 0xb0) || (dev->cur_reg > 0xdf) || + (dev->chip_id >= FDC37C93X_FR))) switch (dev->regs[7]) { + case 0x00: /* FDD */ + switch (dev->cur_reg) { + case 0x30: + case 0x60: case 0x61: + case 0x70: + case 0x74: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val; + + if ((dev->cur_reg == 0x30) && (val & 0x01)) + dev->regs[0x22] |= 0x01; + if (valxor) + fdc37c93x_fdc_handler(dev); + break; + case 0xf0: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0x1f; + + if (valxor & 0x01) + fdc_update_enh_mode(dev->fdc, val & 0x01); + if (valxor & 0x10) + fdc_set_swap(dev->fdc, (val & 0x10) >> 4); + break; + case 0xf1: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0xfc; + + if (valxor & 0x0c) + fdc_update_densel_force(dev->fdc, (val & 0xc) >> 2); + break; + case 0xf2: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val; + + if (valxor & 0xc0) + fdc_update_rwc(dev->fdc, 3, (val & 0xc0) >> 6); + if (valxor & 0x30) + fdc_update_rwc(dev->fdc, 2, (val & 0x30) >> 4); + if (valxor & 0x0c) + fdc_update_rwc(dev->fdc, 1, (val & 0x0c) >> 2); + if (valxor & 0x03) + fdc_update_rwc(dev->fdc, 0, (val & 0x03)); + break; + case 0xf4 ... 0xf7: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0x5b; + + if (valxor & 0x18) + fdc_update_drvrate(dev->fdc, dev->cur_reg - 0xf4, + (val & 0x18) >> 3); + break; + } + break; + case 0x01: /* IDE1 */ + switch (dev->cur_reg) { + case 0x30: + case 0x60: case 0x61: + case 0x62: case 0x63: + case 0x70: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val; + + if ((dev->cur_reg == 0x30) && (val & 0x01)) + dev->regs[0x22] |= 0x02; + break; + case 0xf0: case 0xf1: + if (dev->chip_id >= FDC37C93X_FR) + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0x1f; + else if (dev->cur_reg == 0xf0) + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val; + break; + } + break; + case 0x02: /* IDE2 */ + switch (dev->cur_reg) { + case 0x30: + case 0x60: case 0x61: + case 0x62: case 0x63: + case 0x70: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val; + + if ((dev->cur_reg == 0x30) && (val & 0x01)) + dev->regs[0x22] |= 0x04; + break; + case 0xf0: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0x01; + break; + } + break; + case 0x03: /* Parallel Port */ + switch (dev->cur_reg) { + case 0x30: + case 0x60: case 0x61: + case 0x70: + case 0x74: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val; + + if ((dev->cur_reg == 0x30) && (val & 0x01)) + dev->regs[0x22] |= 0x08; + if (valxor) + fdc37c93x_lpt_handler(dev); + break; + case 0xf0: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val; + break; + case 0xf1: + if (dev->chip_id >= FDC37C93X_FR) + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0x03; + break; + } + break; + case 0x04: /* Serial port 1 */ + switch (dev->cur_reg) { + case 0x30: + case 0x60: case 0x61: + case 0x70: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val; + + if ((dev->cur_reg == 0x30) && (val & 0x01)) + dev->regs[0x22] |= 0x10; + if (valxor) + fdc37c93x_serial_handler(dev, 0); + break; + /* TODO: Bit 0 = MIDI Mode, Bit 1 = High speed. */ + case 0xf0: + if (dev->chip_id >= FDC37C93X_FR) { + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0x83; + } else + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0x03; + + if (valxor & 0x83) { + fdc37c93x_serial_handler(dev, 0); + fdc37c93x_serial_handler(dev, 1); + } + break; + } + break; + case 0x05: /* Serial port 2 */ + switch (dev->cur_reg) { + case 0x30: + case 0x60: case 0x61: + case 0x62: case 0x63: + case 0x70: + case 0x74: + if (((dev->cur_reg != 0x62) && (dev->cur_reg != 0x63)) || + (dev->chip_id == FDC37C93X_FR)) { + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val; + + if ((dev->cur_reg == 0x30) && (val & 0x01)) + dev->regs[0x22] |= 0x20; + if (valxor) + fdc37c93x_serial_handler(dev, 1); + } + break; + /* TODO: Bit 0 = MIDI Mode, Bit 1 = High speed. */ + case 0xf0: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0x03; + + if (valxor & 0x03) { + fdc37c93x_serial_handler(dev, 0); + fdc37c93x_serial_handler(dev, 1); + } + break; + case 0xf1: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0x7f; + break; + case 0xf2: + if (dev->chip_id >= FDC37C93X_FR) + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val; + break; + } + break; + case 0x06: /* RTC */ + switch (dev->cur_reg) { + case 0x30: + // case 0x60: case 0x61: + case 0x62: case 0x63: + case 0x70: + if (((dev->cur_reg != 0x62) && (dev->cur_reg != 0x63)) || + (dev->chip_id >= FDC37C93X_FR)) { + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val; + + if (valxor) { + fdc37c93x_nvr_pri_handler(dev); + + if (dev->chip_id >= FDC37C93X_FR) + fdc37c93x_nvr_sec_handler(dev); + } + } + break; + case 0xf0: + if (dev->chip_id >= FDC37C93X_FR) + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val; + else + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0x8f; + + if (valxor) { + nvr_lock_set(0x80, 0x20, !!(dev->ld_regs[6][dev->cur_reg] & 0x01), dev->nvr); + nvr_lock_set(0xa0, 0x20, !!(dev->ld_regs[6][dev->cur_reg] & 0x02), dev->nvr); + nvr_lock_set(0xc0, 0x20, !!(dev->ld_regs[6][dev->cur_reg] & 0x04), dev->nvr); + nvr_lock_set(0xe0, 0x20, !!(dev->ld_regs[6][dev->cur_reg] & 0x08), dev->nvr); + if (dev->ld_regs[6][dev->cur_reg] & 0x80) { + if (dev->chip_id == FDC37C93X_NORMAL) + nvr_bank_set(0, 1, dev->nvr); + else switch ((dev->ld_regs[6][dev->cur_reg] >> 4) & 0x07) { + case 0x00: + default: + nvr_bank_set(0, 0xff, dev->nvr); + nvr_bank_set(1, 1, dev->nvr); + break; + case 0x01: + nvr_bank_set(0, 0, dev->nvr); + nvr_bank_set(1, 1, dev->nvr); + break; + case 0x02: case 0x04: + nvr_bank_set(0, 0xff, dev->nvr); + nvr_bank_set(1, 0xff, dev->nvr); + break; + case 0x03: case 0x05: + nvr_bank_set(0, 0, dev->nvr); + nvr_bank_set(1, 0xff, dev->nvr); + break; + case 0x06: + nvr_bank_set(0, 0xff, dev->nvr); + nvr_bank_set(1, 2, dev->nvr); + break; + case 0x07: + nvr_bank_set(0, 0, dev->nvr); + nvr_bank_set(1, 2, dev->nvr); + break; + } + } else { + nvr_bank_set(0, 0, dev->nvr); + if (dev->chip_id >= FDC37C93X_FR) + nvr_bank_set(1, 0xff, dev->nvr); + } + + fdc37c93x_nvr_pri_handler(dev); + if (dev->chip_id >= FDC37C93X_FR) + fdc37c93x_nvr_sec_handler(dev); + } + break; + case 0xf1: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0x1f; + break; + case 0xf2: case 0xf3: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val; + break; + case 0xf4: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0x83; + break; + } + break; + case 0x07: /* Keyboard */ + switch (dev->cur_reg) { + case 0x30: + case 0x70: case 0x71: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val; + + if (valxor) + fdc37c93x_kbc_handler(dev); + break; + case 0xf0: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0x87; + break; + } + break; + case 0x08: /* Aux. I/O */ + switch (dev->cur_reg) { + case 0x30: + case 0x60: case 0x61: + case 0x62: case 0x63: + case 0x70: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val; + + if (valxor) + fdc37c93x_auxio_handler(dev); + break; + case 0xb0: case 0xb2: + case 0xb4: case 0xb6: + case 0xe0: case 0xe1: + case 0xe9: case 0xf2: + case 0xf3: + case 0xc0 ... 0xc9: + case 0xcb ... 0xcc: + case 0xd0 ... 0xdf: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val; + break; + case 0xb1: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0xd3; + break; + case 0xb3: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0x17; + break; + case 0xb5: + if (dev->chip_id == FDC37C93X_APM) + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val; + else + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0xbf; + break; + case 0xb7: + if (dev->chip_id == FDC37C93X_APM) + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0x7f; + else + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0x3f; + break; + case 0xb8: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0x3f; + break; + case 0x18: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0x18; + break; + case 0xe2 ... 0xe5: + case 0xe7: + case 0xeb ... 0xed: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0x0f; + break; + case 0xe6: case 0xe8: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0x1f; + break; + case 0xea: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0x9f; + break; + case 0xef: + if (dev->chip_id >= FDC37C93X_FR) + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0xf8; + break; + case 0xf1: + if (dev->chip_id >= FDC37C93X_FR) + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0x83; + else + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0x03; + break; + case 0xf4: + if (dev->chip_id >= FDC37C93X_FR) + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0xef; + else + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val & 0x0f; + break; + case 0xf6: + if (dev->chip_id >= FDC37C93X_FR) + for (uint8_t i = 0; i < 8; i++) + fdc37c93x_write_gp(dev, 1, i, val & (1 << i)); + break; + case 0xf7: + if (dev->chip_id >= FDC37C93X_FR) + for (uint8_t i = 0; i < 8; i++) + fdc37c93x_write_gp(dev, 2, i, val & (1 << i)); + break; + case 0xf8: + if (dev->chip_id >= FDC37C93X_FR) + for (uint8_t i = 0; i < 8; i++) + fdc37c93x_write_gp(dev, 4, i, val & (1 << i)); + break; + case 0xf9: + if (dev->chip_id >= FDC37C93X_FR) + for (uint8_t i = 0; i < 8; i++) + fdc37c93x_write_gp(dev, 5, i, val & (1 << i)); + break; + case 0xfa: + if (dev->chip_id >= FDC37C93X_FR) + for (uint8_t i = 0; i < 8; i++) + fdc37c93x_write_gp(dev, 6, i, val & (1 << i)); + break; + case 0xfb: + if (dev->chip_id >= FDC37C93X_FR) + for (uint8_t i = 0; i < 8; i++) + fdc37c93x_write_gp(dev, 7, i, val & (1 << i)); + break; + } + break; + case 0x09: /* Access.Bus */ + switch (dev->cur_reg) { + case 0x30: + case 0x60: case 0x61: + case 0x70: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val; + + if ((dev->cur_reg == 0x30) && (val & 0x01)) + dev->regs[0x22] |= 0x40; + if (valxor) + fdc37c93x_access_bus_handler(dev); + break; + } + break; + case 0x0a: /* ACPI */ + switch (dev->cur_reg) { + case 0x30: + case 0x60: case 0x61: + case 0x62: case 0x63: + case 0x70: + dev->ld_regs[dev->regs[7]][dev->cur_reg] = val; + + if (valxor) + fdc37c93x_acpi_handler(dev); + break; + } break; } - break; - - default: - break; + } } } @@ -773,11 +1517,58 @@ fdc37c93x_read(uint16_t port, void *priv) ret = dev->chip_id; else ret = dev->regs[dev->cur_reg]; - } else { - if ((dev->regs[7] == 0) && (dev->cur_reg == 0xF2)) { - ret = (fdc_get_rwc(dev->fdc, 0) | (fdc_get_rwc(dev->fdc, 1) << 2) | (fdc_get_rwc(dev->fdc, 2) << 4) | (fdc_get_rwc(dev->fdc, 3) << 6)); - } else + } else if (dev->regs[7] <= dev->max_ld) { + if ((dev->regs[7] == 0x00) && (dev->cur_reg == 0xf2)) + ret = (fdc_get_rwc(dev->fdc, 0) | (fdc_get_rwc(dev->fdc, 1) << 2) | + (fdc_get_rwc(dev->fdc, 2) << 4) | (fdc_get_rwc(dev->fdc, 3) << 6)); + else if ((dev->regs[7] != 0x06) || (dev->cur_reg != 0xf3)) ret = dev->ld_regs[dev->regs[7]][dev->cur_reg]; + else if ((dev->regs[7] == 0x08) && (dev->cur_reg >= 0xf6) && + (dev->cur_reg <= 0xfb) && + (dev->chip_id >= FDC37C93X_FR)) switch (dev->cur_reg) { + case 0xf6: + if (dev->chip_id >= FDC37C93X_FR) { + ret = 0x00; + for (uint8_t i = 0; i < 8; i++) + ret |= fdc37c93x_read_gp(dev, 1, i); + } + break; + case 0xf7: + if (dev->chip_id >= FDC37C93X_FR) { + ret = 0x00; + for (uint8_t i = 0; i < 8; i++) + ret |= fdc37c93x_read_gp(dev, 2, i); + } + break; + case 0xf8: + if (dev->chip_id >= FDC37C93X_FR) { + ret = 0x00; + for (uint8_t i = 0; i < 8; i++) + ret |= fdc37c93x_read_gp(dev, 4, i); + } + break; + case 0xf9: + if (dev->chip_id >= FDC37C93X_FR) { + ret = 0x00; + for (uint8_t i = 0; i < 8; i++) + ret |= fdc37c93x_read_gp(dev, 5, i); + } + break; + case 0xfa: + if (dev->chip_id >= FDC37C93X_FR) { + ret = 0x00; + for (uint8_t i = 0; i < 8; i++) + ret |= fdc37c93x_read_gp(dev, 6, i); + } + break; + case 0xfb: + if (dev->chip_id >= FDC37C93X_FR) { + ret = 0x00; + for (uint8_t i = 0; i < 8; i++) + ret |= fdc37c93x_read_gp(dev, 7, i); + } + break; + } } } } @@ -788,91 +1579,117 @@ fdc37c93x_read(uint16_t port, void *priv) static void fdc37c93x_reset(fdc37c93x_t *dev) { - memset(dev->regs, 0, 48); + memset(dev->regs, 0x00, sizeof(dev->regs)); dev->regs[0x03] = 0x03; dev->regs[0x20] = dev->chip_id; dev->regs[0x21] = 0x01; dev->regs[0x22] = 0x39; dev->regs[0x24] = 0x04; - if (dev->chip_id != 0x02) { - dev->regs[0x26] = dev->port_370 ? 0x70 : 0xF0; - dev->regs[0x27] = 0x03; - } + if (dev->chip_id >= FDC37C93X_FR) + dev->regs[0x26] = dev->port_370 ? 0x70 : 0xf0; + dev->regs[0x27] = 0x03; - for (uint8_t i = 0; i < 11; i++) - memset(dev->ld_regs[i], 0, 256); + for (uint8_t i = 0; i <= 0x0a; i++) + memset(dev->ld_regs[i], 0x00, 256); /* Logical device 0: FDD */ - dev->ld_regs[0][0x30] = 0; - dev->ld_regs[0][0x60] = 3; - dev->ld_regs[0][0x61] = 0xF0; - dev->ld_regs[0][0x70] = 6; - dev->ld_regs[0][0x74] = 2; - dev->ld_regs[0][0xF0] = 0xE; - dev->ld_regs[0][0xF2] = 0xFF; + dev->ld_regs[0x00][0x30] = 0x00; + dev->ld_regs[0x00][0x60] = 0x03; + dev->ld_regs[0x00][0x61] = 0xf0; + dev->ld_regs[0x00][0x70] = 0x06; + dev->ld_regs[0x00][0x74] = 0x02; + dev->ld_regs[0x00][0xf0] = 0x0e; + dev->ld_regs[0x00][0xf2] = 0xff; /* Logical device 1: IDE1 */ - dev->ld_regs[1][0x30] = 0; - dev->ld_regs[1][0x60] = 1; - dev->ld_regs[1][0x61] = 0xF0; - dev->ld_regs[1][0x62] = 3; - dev->ld_regs[1][0x63] = 0xF6; - dev->ld_regs[1][0x70] = 0xE; - dev->ld_regs[1][0xF0] = 0xC; + dev->ld_regs[0x01][0x30] = 0x00; + dev->ld_regs[0x01][0x60] = 0x01; + dev->ld_regs[0x01][0x61] = 0xf0; + dev->ld_regs[0x01][0x62] = 0x03; + dev->ld_regs[0x01][0x63] = 0xf6; + dev->ld_regs[0x01][0x70] = 0x0e; + if (dev->chip_id >= FDC37C93X_FR) + dev->ld_regs[0x01][0xf0] = 0x0c; /* Logical device 2: IDE2 */ - dev->ld_regs[2][0x30] = 0; - dev->ld_regs[2][0x60] = 1; - dev->ld_regs[2][0x61] = 0x70; - dev->ld_regs[2][0x62] = 3; - dev->ld_regs[2][0x63] = 0x76; - dev->ld_regs[2][0x70] = 0xF; + dev->ld_regs[0x02][0x30] = 0x00; + dev->ld_regs[0x02][0x60] = 0x01; + dev->ld_regs[0x02][0x61] = 0x70; + dev->ld_regs[0x02][0x62] = 0x03; + dev->ld_regs[0x02][0x63] = 0x76; + dev->ld_regs[0x02][0x70] = 0x0f; /* Logical device 3: Parallel Port */ - dev->ld_regs[3][0x30] = 0; - dev->ld_regs[3][0x60] = 3; - dev->ld_regs[3][0x61] = 0x78; - dev->ld_regs[3][0x70] = 7; - dev->ld_regs[3][0x74] = 4; - dev->ld_regs[3][0xF0] = 0x3C; + dev->ld_regs[0x03][0x30] = 0x00; + dev->ld_regs[0x03][0x60] = 0x03; + dev->ld_regs[0x03][0x61] = 0x78; + dev->ld_regs[0x03][0x70] = 0x07; + dev->ld_regs[0x03][0x74] = 0x04; + dev->ld_regs[0x03][0xf0] = 0x3c; /* Logical device 4: Serial Port 1 */ - dev->ld_regs[4][0x30] = 0; - dev->ld_regs[4][0x60] = 3; - dev->ld_regs[4][0x61] = 0xf8; - dev->ld_regs[4][0x70] = 4; - dev->ld_regs[4][0xF0] = 3; - serial_setup(dev->uart[0], COM1_ADDR, dev->ld_regs[4][0x70]); + dev->ld_regs[0x04][0x30] = 0x00; + dev->ld_regs[0x04][0x60] = 0x03; + dev->ld_regs[0x04][0x61] = 0xf8; + dev->ld_regs[0x04][0x70] = 0x04; + dev->ld_regs[0x04][0xf0] = 0x03; + serial_irq(dev->uart[0], dev->ld_regs[4][0x70]); /* Logical device 5: Serial Port 2 */ - dev->ld_regs[5][0x30] = 0; - dev->ld_regs[5][0x60] = 2; - dev->ld_regs[5][0x61] = 0xf8; - dev->ld_regs[5][0x70] = 3; - dev->ld_regs[5][0x74] = 4; - dev->ld_regs[5][0xF1] = 2; - dev->ld_regs[5][0xF2] = 3; - serial_setup(dev->uart[1], COM2_ADDR, dev->ld_regs[5][0x70]); + dev->ld_regs[0x05][0x30] = 0x00; + dev->ld_regs[0x05][0x60] = 0x02; + dev->ld_regs[0x05][0x61] = 0xf8; + dev->ld_regs[0x05][0x70] = 0x03; + dev->ld_regs[0x05][0x74] = 0x04; + dev->ld_regs[0x05][0xf1] = 0x02; + if (dev->chip_id >= FDC37C93X_FR) + dev->ld_regs[0x05][0xf2] = 0x03; + serial_irq(dev->uart[1], dev->ld_regs[5][0x70]); /* Logical device 6: RTC */ - dev->ld_regs[6][0x30] = 0; - dev->ld_regs[6][0x60] = 0x70; - if (dev->chip_id != 0x02) - dev->ld_regs[6][0x63] = (dev->has_nvr) ? 0x70 : 0x00; - dev->ld_regs[6][0xF0] = 0; - dev->ld_regs[6][0xF4] = 3; + dev->ld_regs[0x06][0x30] = 0x00; + dev->ld_regs[0x06][0x63] = (dev->has_nvr) ? 0x70 : 0x00; + dev->ld_regs[0x06][0xf0] = 0x00; + dev->ld_regs[0x06][0xf4] = 0x03; /* Logical device 7: Keyboard */ - dev->ld_regs[7][0x30] = 0; - dev->ld_regs[7][0x61] = 0x60; - dev->ld_regs[7][0x70] = 1; + dev->ld_regs[0x07][0x30] = 0x00; + dev->ld_regs[0x07][0x61] = 0x60; + dev->ld_regs[0x07][0x70] = 0x01; /* Logical device 8: Auxiliary I/O */ + dev->ld_regs[0x08][0x30] = 0x00; + dev->ld_regs[0x08][0x60] = 0x00; + dev->ld_regs[0x08][0x61] = 0x00; + if (dev->chip_id >= FDC37C93X_FR) { + dev->ld_regs[0x08][0xb1] = 0x80; + dev->ld_regs[0x08][0xc0] = 0x01; + dev->ld_regs[0x08][0xc1] = 0x01; + dev->ld_regs[0x08][0xc5] = 0x01; + dev->ld_regs[0x08][0xc6] = 0x01; + dev->ld_regs[0x08][0xc7] = 0x01; + dev->ld_regs[0x08][0xc8] = 0x01; + dev->ld_regs[0x08][0xc9] = 0x80; + dev->ld_regs[0x08][0xcb] = 0x01; + dev->ld_regs[0x08][0xcc] = 0x01; + memset(&(dev->ld_regs[0x08][0xd0]), 0x01, 16); + } + memset(&(dev->ld_regs[0x08][0xe0]), 0x01, 14); /* Logical device 9: ACCESS.bus */ + if (dev->chip_id >= FDC37C93X_FR) { + dev->ld_regs[0x09][0x30] = 0x00; + dev->ld_regs[0x09][0x60] = 0x00; + dev->ld_regs[0x09][0x61] = 0x00; + } /* Logical device A: ACPI */ + if (dev->chip_id == FDC37C93X_APM) { + dev->ld_regs[0x0a][0x30] = 0x00; + dev->ld_regs[0x0a][0x60] = 0x00; + dev->ld_regs[0x0a][0x61] = 0x00; + } fdc37c93x_gpio_handler(dev); fdc37c93x_lpt_handler(dev); @@ -904,40 +1721,65 @@ fdc37c93x_reset(fdc37c93x_t *dev) if (dev->chip_id != 0x02) fdc37c93x_superio_handler(dev); + if (dev->chip_id >= FDC37C93X_FR) { + serial_set_clock_src(dev->uart[0], 24000000.0); + serial_set_clock_src(dev->uart[1], 24000000.0); + } + + memset(dev->gpio_regs, 0xff, 256); + memset(dev->gpio_pulldn, 0xff, 8); + + /* Acer V62X requires bit 0 to be clear to not be stuck in "clear password" mode. */ + if (!strcmp(machine_get_internal_name(), "vectra54")) { + dev->gpio_pulldn[1] = 0x40; + + /* + HP Vectra VL/5 Series 4 GPIO + (TODO: Find how multipliers > 3.0 are defined): + + Bit 6: 1 = can boot, 0 = no; + Bit 7, 1 = multiplier (00 = 2.5, 01 = 2.0, + 10 = 3.0, 11 = 1.5); + Bit 5, 4 = bus speed (00 = 50 MHz, 01 = 66 MHz, + 10 = 60 MHz, 11 = ????): + Bit 7, 5, 4, 1: 0000 = 125 MHz, 0010 = 166 MHz, + 0100 = 150 MHz, 0110 = ??? MHz; + 0001 = 100 MHz, 0011 = 133 MHz, + 0101 = 120 MHz, 0111 = ??? MHz; + 1000 = 150 MHz, 1010 = 200 MHz, + 1100 = 180 MHz, 1110 = ??? MHz; + 1001 = 75 MHz, 1011 = 100 MHz, + 1101 = 90 MHz, 1111 = ??? MHz + */ + if (cpu_busspeed <= 40000000) + dev->gpio_pulldn[1] |= 0x30; + else if ((cpu_busspeed > 40000000) && (cpu_busspeed <= 50000000)) + dev->gpio_pulldn[1] |= 0x00; + else if ((cpu_busspeed > 50000000) && (cpu_busspeed <= 60000000)) + dev->gpio_pulldn[1] |= 0x20; + else if (cpu_busspeed > 60000000) + dev->gpio_pulldn[1] |= 0x10; + + if (cpu_dmulti <= 1.5) + dev->gpio_pulldn[1] |= 0x82; + else if ((cpu_dmulti > 1.5) && (cpu_dmulti <= 2.0)) + dev->gpio_pulldn[1] |= 0x02; + else if ((cpu_dmulti > 2.0) && (cpu_dmulti <= 2.5)) + dev->gpio_pulldn[1] |= 0x00; + else if (cpu_dmulti > 2.5) + dev->gpio_pulldn[1] |= 0x80; + } else if (!strcmp(machine_get_internal_name(), "acerv62x")) + dev->gpio_pulldn[1] = 0xfe; + else + dev->gpio_pulldn[1] = (dev->chip_id == 0x30) ? 0xff : 0xfd; + + if (strstr(machine_get_internal_name(), "acer") != NULL) + /* Bit 2 on the Acer V35N is the text/graphics toggle, bits 1 and 3 = ????. */ + dev->gpio_pulldn[2] = 0x10; + dev->locked = 0; } -static void -access_bus_close(void *priv) -{ - access_bus_t *dev = (access_bus_t *) priv; - - free(dev); -} - -static void * -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)); - - return dev; -} - -static const device_t access_bus_device = { - .name = "SMC FDC37C932FR ACCESS.bus", - .internal_name = "access_bus", - .flags = 0, - .local = 0x03, - .init = access_bus_init, - .close = access_bus_close, - .reset = NULL, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - static void fdc37c93x_close(void *priv) { @@ -949,50 +1791,76 @@ fdc37c93x_close(void *priv) static void * fdc37c93x_init(const device_t *info) { - int is_compaq; - fdc37c93x_t *dev = (fdc37c93x_t *) malloc(sizeof(fdc37c93x_t)); - memset(dev, 0, sizeof(fdc37c93x_t)); + fdc37c93x_t *dev = (fdc37c93x_t *) calloc(1, sizeof(fdc37c93x_t)); dev->fdc = device_add(&fdc_at_smc_device); - dev->uart[0] = device_add_inst(&ns16550_device, 1); - dev->uart[1] = device_add_inst(&ns16550_device, 2); + dev->uart[0] = device_add_inst(&ns16550_device, 1); + dev->uart[1] = device_add_inst(&ns16550_device, 2); - dev->chip_id = info->local & 0xff; - dev->is_apm = (info->local >> 8) & 0x01; - is_compaq = (info->local >> 8) & 0x02; - dev->has_nvr = !((info->local >> 8) & 0x04); - dev->port_370 = ((info->local >> 8) & 0x08); + dev->chip_id = info->local & FDC37C93X_CHIP_ID; + dev->kbc_type = info->local & FDC37C93X_KBC; - dev->gpio_regs[0] = 0xff; -#if 0 - dev->gpio_regs[1] = (info->local == 0x0030) ? 0xff : 0xfd; -#endif - dev->gpio_regs[1] = (dev->chip_id == 0x30) ? 0xff : 0xfd; + dev->is_apm = (dev->chip_id == FDC37C93X_APM); + dev->is_compaq = (dev->kbc_type == FDC37C931); + + dev->has_nvr = !(info->local & FDC37C93X_NO_NVR); + dev->port_370 = !!(info->local & FDC37C93X_370); if (dev->has_nvr) { - dev->nvr = device_add(&at_nvr_device); + dev->nvr = device_add(&amstrad_megapc_nvr_device); nvr_bank_set(0, 0, dev->nvr); nvr_bank_set(1, 0xff, dev->nvr); } - if (dev->is_apm || (dev->chip_id == 0x03)) + dev->max_ld = 8; + + if (dev->chip_id >= FDC37C93X_FR) { dev->access_bus = device_add(&access_bus_device); + dev->max_ld++; + } - if (dev->is_apm) + if (dev->chip_id == FDC37C93X_APM) { dev->acpi = device_add(&acpi_smc_device); + dev->max_ld++; + } - if (is_compaq) { - io_sethandler(0x0ea, 0x0002, - fdc37c93x_read, NULL, NULL, fdc37c93x_write, NULL, NULL, dev); + if (dev->is_compaq) { io_sethandler(0x0f9, 0x0001, fdc37c93x_read, NULL, NULL, fdc37c93x_write, NULL, NULL, dev); io_sethandler(0x0fb, 0x0001, fdc37c93x_read, NULL, NULL, fdc37c93x_write, NULL, NULL, dev); } - dev->kbc = device_add(&keyboard_ps2_ami_pci_device); + switch (dev->kbc_type) { + case FDC37C931: + dev->kbc = device_add(&keyboard_ps2_compaq_device); + break; + case FDC37C932: + dev->kbc = device_add(&keyboard_ps2_intel_ami_pci_device); + break; + case FDC37C933: + default: + dev->kbc = device_add(&keyboard_ps2_pci_device); + break; + case FDC37C935: + dev->kbc = device_add(&keyboard_ps2_phoenix_device); + break; + case FDC37C937: + dev->kbc = device_add(&keyboard_ps2_phoenix_pci_device); + break; + } + + /* Set the defaults here so the ports can be removed by fdc37c93x_reset(). */ + dev->fdc_base = 0x03f0; + dev->lpt_base = 0x0378; + dev->uart_base[0] = 0x03f8; + dev->uart_base[1] = 0x02f8; + dev->nvr_pri_base = 0x0070; + dev->nvr_sec_base = 0x0070; + dev->kbc_base = 0x0060; + dev->gpio_base = 0x00ea; fdc37c93x_reset(dev); @@ -1006,115 +1874,16 @@ fdc37c93x_init(const device_t *info) return dev; } -const device_t fdc37c931apm_device = { - .name = "SMC FDC37C931APM Super I/O", - .internal_name = "fdc37c931apm", +const device_t fdc37c93x_device = { + .name = "SMC FDC37C93x Super I/O", + .internal_name = "fdc37c93x", .flags = 0, - .local = 0x130, /* Share the same ID with the 932QF. */ + .local = 0, .init = fdc37c93x_init, .close = fdc37c93x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL }; - -const device_t fdc37c931apm_compaq_device = { - .name = "SMC FDC37C931APM Super I/O (Compaq Presario 4500)", - .internal_name = "fdc37c931apm_compaq", - .flags = 0, - .local = 0x330, /* Share the same ID with the 932QF. */ - .init = fdc37c93x_init, - .close = fdc37c93x_close, - .reset = NULL, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -const device_t fdc37c932_device = { - .name = "SMC FDC37C932 Super I/O", - .internal_name = "fdc37c932", - .flags = 0, - .local = 0x02, - .init = fdc37c93x_init, - .close = fdc37c93x_close, - .reset = NULL, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -const device_t fdc37c932fr_device = { - .name = "SMC FDC37C932FR Super I/O", - .internal_name = "fdc37c932fr", - .flags = 0, - .local = 0x03, - .init = fdc37c93x_init, - .close = fdc37c93x_close, - .reset = NULL, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -const device_t fdc37c932qf_device = { - .name = "SMC FDC37C932QF Super I/O", - .internal_name = "fdc37c932qf", - .flags = 0, - .local = 0x30, - .init = fdc37c93x_init, - .close = fdc37c93x_close, - .reset = NULL, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -const device_t fdc37c935_device = { - .name = "SMC FDC37C935 Super I/O", - .internal_name = "fdc37c935", - .flags = 0, - .local = 0x02, - .init = fdc37c93x_init, - .close = fdc37c93x_close, - .reset = NULL, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -const device_t fdc37c935_370_device = { - .name = "SMC FDC37C935 Super I/O (Port 370h)", - .internal_name = "fdc37c935_370", - .flags = 0, - .local = 0x802, - .init = fdc37c93x_init, - .close = fdc37c93x_close, - .reset = NULL, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -const device_t fdc37c935_no_nvr_device = { - .name = "SMC FDC37C935 Super I/O", - .internal_name = "fdc37c935", - .flags = 0, - .local = 0x402, - .init = fdc37c93x_init, - .close = fdc37c93x_close, - .reset = NULL, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - diff --git a/src/sio/sio_fdc37m60x.c b/src/sio/sio_fdc37m60x.c index 38a163538..11d2f3349 100644 --- a/src/sio/sio_fdc37m60x.c +++ b/src/sio/sio_fdc37m60x.c @@ -216,7 +216,7 @@ fdc37m60x_lpt_handler(fdc37m60x_t *dev) lpt1_remove(); if (ENABLED(3) || (POWER_CONTROL & 0x08)) { - lpt1_init(BASE_ADDRESS(3)); + lpt1_setup(BASE_ADDRESS(3)); lpt1_irq(IRQ(3) & 0xf); fdc37m60x_log("SMC60x-LPT: BASE %04x IRQ %d\n", BASE_ADDRESS(3), IRQ(3) & 0xf); } @@ -306,8 +306,7 @@ fdc37m60x_close(void *priv) static void * fdc37m60x_init(const device_t *info) { - fdc37m60x_t *dev = (fdc37m60x_t *) malloc(sizeof(fdc37m60x_t)); - memset(dev, 0, sizeof(fdc37m60x_t)); + fdc37m60x_t *dev = (fdc37m60x_t *) calloc(1, sizeof(fdc37m60x_t)); SIO_INDEX_PORT = info->local; dev->fdc = device_add(&fdc_at_smc_device); @@ -329,7 +328,7 @@ const device_t fdc37m60x_device = { .init = fdc37m60x_init, .close = fdc37m60x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -343,7 +342,7 @@ const device_t fdc37m60x_370_device = { .init = fdc37m60x_init, .close = fdc37m60x_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_it86x1f.c b/src/sio/sio_it86x1f.c index 00524863a..b3553bf54 100644 --- a/src/sio/sio_it86x1f.c +++ b/src/sio/sio_it86x1f.c @@ -294,7 +294,7 @@ it8661f_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *pri if (config->activate && (config->io[0].base != ISAPNP_IO_DISABLED)) { it86x1f_log("IT86x1F: LPT enabled at port %04X IRQ %d\n", config->io[0].base, config->irq[0].irq); - lpt1_init(config->io[0].base); + lpt1_setup(config->io[0].base); } else { it86x1f_log("IT86x1F: LPT disabled\n"); } @@ -602,7 +602,7 @@ it86x1f_pnp_write_vendor_reg(uint8_t ld, uint8_t reg, uint8_t val, void *priv) } static void -it86x1f_write_addr(uint16_t port, uint8_t val, void *priv) +it86x1f_write_addr(UNUSED(uint16_t port), uint8_t val, void *priv) { it86x1f_t *dev = (it86x1f_t *) priv; @@ -623,7 +623,7 @@ it86x1f_write_addr(uint16_t port, uint8_t val, void *priv) } static void -it86x1f_write_data(uint16_t port, uint8_t val, void *priv) +it86x1f_write_data(UNUSED(uint16_t port), uint8_t val, void *priv) { it86x1f_t *dev = (it86x1f_t *) priv; @@ -659,7 +659,7 @@ it86x1f_write_data(uint16_t port, uint8_t val, void *priv) } static uint8_t -it86x1f_read_addr(uint16_t port, void *priv) +it86x1f_read_addr(UNUSED(uint16_t port), void *priv) { it86x1f_t *dev = (it86x1f_t *) priv; uint8_t ret = dev->locked ? 0xff : dev->cur_reg; @@ -670,7 +670,7 @@ it86x1f_read_addr(uint16_t port, void *priv) } static uint8_t -it86x1f_read_data(uint16_t port, void *priv) +it86x1f_read_data(UNUSED(uint16_t port), void *priv) { it86x1f_t *dev = (it86x1f_t *) priv; uint8_t ret = 0xff; @@ -799,8 +799,7 @@ it86x1f_close(void *priv) static void * it86x1f_init(UNUSED(const device_t *info)) { - it86x1f_t *dev = (it86x1f_t *) malloc(sizeof(it86x1f_t)); - memset(dev, 0, sizeof(it86x1f_t)); + it86x1f_t *dev = (it86x1f_t *) calloc(1, sizeof(it86x1f_t)); uint8_t i; for (i = 0; i < (sizeof(it86x1f_models) / sizeof(it86x1f_models[0])); i++) { @@ -844,7 +843,7 @@ const device_t it8661f_device = { .init = it86x1f_init, .close = it86x1f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -858,7 +857,7 @@ const device_t it8671f_device = { .init = it86x1f_init, .close = it86x1f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_pc87306.c b/src/sio/sio_pc87306.c index ab7f8597e..e42c48ab4 100644 --- a/src/sio/sio_pc87306.c +++ b/src/sio/sio_pc87306.c @@ -68,7 +68,7 @@ pc87306_gpio_write(uint16_t port, uint8_t val, void *priv) } uint8_t -pc87306_gpio_read(uint16_t port, void *priv) +pc87306_gpio_read(uint16_t port, UNUSED(void *priv)) { uint32_t ret = machine_handle_gpio(0, 0xffffffff); @@ -121,6 +121,10 @@ lpt1_handler(pc87306_t *dev) uint16_t lptba; uint16_t lpt_port = LPT1_ADDR; uint8_t lpt_irq = LPT2_IRQ; + uint8_t lpt_dma = ((dev->regs[0x18] & 0x06) >> 1); + + if (lpt_dma == 0x00) + lpt_dma = 0xff; temp = dev->regs[0x01] & 3; lptba = ((uint16_t) dev->regs[0x19]) << 2; @@ -154,9 +158,16 @@ lpt1_handler(pc87306_t *dev) lpt_irq = (dev->regs[0x1b] & 0x20) ? 7 : 5; if (lpt_port) - lpt1_init(lpt_port); + lpt1_setup(lpt_port); lpt1_irq(lpt_irq); + + lpt_port_dma(0, lpt_dma); + + lpt_set_ext(0, !!(dev->regs[0x02] & 0x80)); + + lpt_set_epp(0, !!(dev->regs[0x04] & 0x01)); + lpt_set_ecp(0, !!(dev->regs[0x04] & 0x04)); } static void @@ -169,7 +180,7 @@ serial_handler(pc87306_t *dev, int uart) uint8_t pnp_shift; uint8_t irq; - temp = (dev->regs[1] >> (2 << uart)) & 3; + temp = (dev->regs[0x01] >> (2 << uart)) & 3; fer_shift = 2 << uart; /* 2 for UART 1, 4 for UART 2 */ pnp_shift = 2 + (uart << 2); /* 2 for UART 1, 6 for UART 2 */ @@ -188,7 +199,7 @@ serial_handler(pc87306_t *dev, int uart) serial_setup(dev->uart[uart], COM2_ADDR, irq); break; case 2: - switch ((dev->regs[1] >> 6) & 3) { + switch ((dev->regs[0x01] >> 6) & 3) { case 0: serial_setup(dev->uart[uart], COM3_ADDR, irq); break; @@ -207,7 +218,7 @@ serial_handler(pc87306_t *dev, int uart) } break; case 3: - switch ((dev->regs[1] >> 6) & 3) { + switch ((dev->regs[0x01] >> 6) & 3) { case 0: serial_setup(dev->uart[uart], COM4_ADDR, irq); break; @@ -264,69 +275,74 @@ pc87306_write(uint16_t port, uint8_t val, void *priv) switch (dev->cur_reg) { case 0x00: - if (valxor & 1) { + if (valxor & 0x01) { lpt1_remove(); - if ((val & 1) && !(dev->regs[2] & 1)) + if ((val & 1) && !(dev->regs[0x02] & 1)) lpt1_handler(dev); } - if (valxor & 2) { - serial_remove(dev->uart[0]); - if ((val & 2) && !(dev->regs[2] & 1)) + if (valxor & 0x02) { + serial_remove(dev->uart[0x00]); + if ((val & 2) && !(dev->regs[0x02] & 1)) serial_handler(dev, 0); } - if (valxor & 4) { - serial_remove(dev->uart[1]); - if ((val & 4) && !(dev->regs[2] & 1)) + if (valxor & 0x04) { + serial_remove(dev->uart[0x01]); + if ((val & 4) && !(dev->regs[0x02] & 1)) serial_handler(dev, 1); } if (valxor & 0x28) { fdc_remove(dev->fdc); - if ((val & 8) && !(dev->regs[2] & 1)) + if ((val & 8) && !(dev->regs[0x02] & 1)) fdc_set_base(dev->fdc, (val & 0x20) ? FDC_SECONDARY_ADDR : FDC_PRIMARY_ADDR); } break; case 0x01: - if (valxor & 3) { + if (valxor & 0x03) { lpt1_remove(); - if ((dev->regs[0] & 1) && !(dev->regs[2] & 1)) + if ((dev->regs[0x00] & 1) && !(dev->regs[0x02] & 1)) lpt1_handler(dev); } if (valxor & 0xcc) { - serial_remove(dev->uart[0]); - if ((dev->regs[0] & 2) && !(dev->regs[2] & 1)) + serial_remove(dev->uart[0x00]); + if ((dev->regs[0x00] & 2) && !(dev->regs[0x02] & 1)) serial_handler(dev, 0); } if (valxor & 0xf0) { - serial_remove(dev->uart[1]); - if ((dev->regs[0] & 4) && !(dev->regs[2] & 1)) + serial_remove(dev->uart[0x01]); + if ((dev->regs[0x00] & 4) && !(dev->regs[0x02] & 1)) serial_handler(dev, 1); } break; case 0x02: - if (valxor & 1) { + if (valxor & 0x01) { lpt1_remove(); - serial_remove(dev->uart[0]); - serial_remove(dev->uart[1]); + serial_remove(dev->uart[0x00]); + serial_remove(dev->uart[0x01]); fdc_remove(dev->fdc); if (!(val & 1)) { - if (dev->regs[0] & 1) + if (dev->regs[0x00] & 0x01) lpt1_handler(dev); - if (dev->regs[0] & 2) + if (dev->regs[0x00] & 0x02) serial_handler(dev, 0); - if (dev->regs[0] & 4) + if (dev->regs[0x00] & 0x04) serial_handler(dev, 1); - if (dev->regs[0] & 8) - fdc_set_base(dev->fdc, (dev->regs[0] & 0x20) ? FDC_SECONDARY_ADDR : FDC_PRIMARY_ADDR); + if (dev->regs[0x00] & 0x08) + fdc_set_base(dev->fdc, (dev->regs[0x00] & 0x20) ? FDC_SECONDARY_ADDR : FDC_PRIMARY_ADDR); } } - if (valxor & 8) { + if (valxor & 0x08) { lpt1_remove(); - if ((dev->regs[0] & 1) && !(dev->regs[2] & 1)) + if ((dev->regs[0x00] & 1) && !(dev->regs[0x02] & 1)) lpt1_handler(dev); } break; case 0x04: + if (valxor & (0x05)) { + lpt1_remove(); + if ((dev->regs[0x00] & 0x01) && !(dev->regs[0x02] & 0x01)) + lpt1_handler(dev); + } if (valxor & 0x80) nvr_lock_set(0x00, 256, !!(val & 0x80), dev->nvr); break; @@ -352,30 +368,37 @@ pc87306_write(uint16_t port, uint8_t val, void *priv) if (valxor & 0x30) pc87306_gpio_handler(dev); break; - case 0x19: - if (valxor) { + case 0x18: + if (valxor & (0x06)) { lpt1_remove(); - if ((dev->regs[0] & 1) && !(dev->regs[2] & 1)) + if ((dev->regs[0x00] & 0x01) && !(dev->regs[0x02] & 0x01)) lpt1_handler(dev); } break; - case 0x1B: + case 0x19: + if (valxor) { + lpt1_remove(); + if ((dev->regs[0x00] & 1) && !(dev->regs[0x02] & 1)) + lpt1_handler(dev); + } + break; + case 0x1b: if (valxor & 0x70) { lpt1_remove(); if (!(val & 0x40)) dev->regs[0x19] = 0xEF; - if ((dev->regs[0] & 1) && !(dev->regs[2] & 1)) + if ((dev->regs[0x00] & 1) && !(dev->regs[0x02] & 1)) lpt1_handler(dev); } break; - case 0x1C: + case 0x1c: if (valxor) { - serial_remove(dev->uart[0]); - serial_remove(dev->uart[1]); + serial_remove(dev->uart[0x00]); + serial_remove(dev->uart[0x01]); - if ((dev->regs[0] & 2) && !(dev->regs[2] & 1)) + if ((dev->regs[0x00] & 2) && !(dev->regs[0x02] & 1)) serial_handler(dev, 0); - if ((dev->regs[0] & 4) && !(dev->regs[2] & 1)) + if ((dev->regs[0x00] & 4) && !(dev->regs[0x02] & 1)) serial_handler(dev, 1); } break; @@ -432,8 +455,8 @@ pc87306_reset_common(void *priv) */ lpt1_remove(); lpt1_handler(dev); - serial_remove(dev->uart[0]); - serial_remove(dev->uart[1]); + serial_remove(dev->uart[0x00]); + serial_remove(dev->uart[0x01]); serial_handler(dev, 0); serial_handler(dev, 1); fdc_reset(dev->fdc); @@ -467,13 +490,12 @@ pc87306_close(void *priv) static void * pc87306_init(UNUSED(const device_t *info)) { - pc87306_t *dev = (pc87306_t *) malloc(sizeof(pc87306_t)); - memset(dev, 0, sizeof(pc87306_t)); + pc87306_t *dev = (pc87306_t *) calloc(1, sizeof(pc87306_t)); dev->fdc = device_add(&fdc_at_nsc_device); - dev->uart[0] = device_add_inst(&ns16550_device, 1); - dev->uart[1] = device_add_inst(&ns16550_device, 2); + dev->uart[0x00] = device_add_inst(&ns16550_device, 1); + dev->uart[0x01] = device_add_inst(&ns16550_device, 2); dev->nvr = device_add(&at_mb_nvr_device); @@ -495,7 +517,7 @@ const device_t pc87306_device = { .init = pc87306_init, .close = pc87306_close, .reset = pc87306_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_pc87307.c b/src/sio/sio_pc87307.c index cb772aa5b..7e51c5975 100644 --- a/src/sio/sio_pc87307.c +++ b/src/sio/sio_pc87307.c @@ -8,61 +8,105 @@ * * Emulation of the NatSemi PC87307 Super I/O chip. * - * - * * Authors: Miran Grca, * - * Copyright 2020 Miran Grca. + * Copyright 2020-2025 Miran Grca. */ +#include #include #include #include #include #include +#define HAVE_STDARG_H #include <86box/86box.h> #include <86box/io.h> #include <86box/timer.h> #include <86box/device.h> #include <86box/lpt.h> +#include <86box/machine.h> #include <86box/mem.h> #include <86box/nvr.h> #include <86box/pci.h> #include <86box/rom.h> #include <86box/serial.h> -#include <86box/hdc.h> -#include <86box/hdc_ide.h> #include <86box/fdd.h> #include <86box/fdc.h> +#include <86box/keyboard.h> #include <86box/sio.h> #include <86box/plat_fallthrough.h> +#include "cpu.h" typedef struct pc87307_t { uint8_t id; + uint8_t baddr; 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 gpio[2][8]; uint8_t pm[8]; + uint16_t superio_base; uint16_t gpio_base; uint16_t gpio_base2; uint16_t pm_base; int cur_reg; + void *kbc; fdc_t *fdc; serial_t *uart[2]; } pc87307_t; -static void fdc_handler(pc87307_t *dev); -static void lpt1_handler(pc87307_t *dev); -static void serial_handler(pc87307_t *dev, int uart); +enum { + LD_KBD = 0, + LD_MOUSE, + LD_RTC, + LD_FDC, + LD_LPT, + LD_UART2, + LD_UART1, + LD_GPIO, + LD_PM +} pc87307_ld_t; + +#define LD_MIN LD_KBD +#define LD_MAX LD_PM + +static void fdc_handler(pc87307_t *dev); +static void lpt1_handler(pc87307_t *dev); +static void serial_handler(pc87307_t *dev, int uart); +static void kbc_handler(pc87307_t *dev); +static void pc87307_write(uint16_t port, uint8_t val, void *priv); +static uint8_t pc87307_read(uint16_t port, void *priv); + +#ifdef ENABLE_PC87307_LOG +int pc87307_do_log = ENABLE_PC87307_LOG; + +static void +pc87307_log(const char *fmt, ...) +{ + va_list ap; + + if (pc87307_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define pc87307_log(fmt, ...) +#endif static void pc87307_gpio_write(uint16_t port, uint8_t val, void *priv) { pc87307_t *dev = (pc87307_t *) priv; - uint8_t bank = ((port & 0xfffc) == dev->gpio_base2); + uint8_t bank = !!(dev->regs[0x22] & 0x80); - dev->gpio[bank][port & 3] = val; + /* Bit 7 of SCNF2 = bank. */ + pc87307_log("[%04X:%08X] [W] (%04X) Bank %i = %02X\n", + CS, cpu_state.pc, port, bank, val); + + dev->gpio[bank][port & 0x0007] = val; } uint8_t @@ -70,20 +114,36 @@ pc87307_gpio_read(uint16_t port, void *priv) { const pc87307_t *dev = (pc87307_t *) priv; uint8_t pins = 0xff; - uint8_t bank = ((port & 0xfffc) == dev->gpio_base2); - uint8_t mask; - uint8_t ret = dev->gpio[bank][port & 0x0003]; + uint8_t bank = !!(dev->regs[0x22] & 0x80); + uint8_t ret = dev->gpio[bank][port & 0x0007]; switch (port & 0x0003) { case 0x0000: - mask = dev->gpio[bank][0x0001]; - ret = (ret & mask) | (pins & ~mask); + if (bank == 0) { + uint8_t mask = dev->gpio[0][1]; + pins = 0x7f; + ret = (ret & mask) | (pins & ~mask); + } + break; + case 0x0004: + if (bank == 0) { + uint8_t mask = dev->gpio[0][5]; + pins = 0xfb; + ret = (ret & mask) | (pins & ~mask); + } else + ret = 0xff; break; default: + if (bank == 1) + ret = 0xff; break; } + /* Bit 7 of SCNF2 = bank. */ + pc87307_log("[%04X:%08X] [R] (%04X) Bank %i = %02X\n", + CS, cpu_state.pc, port, bank, ret); + return ret; } @@ -123,6 +183,7 @@ pc87307_pm_write(uint16_t port, uint8_t val, void *priv) dev->pm[dev->pm_idx] = val; else { dev->pm_idx = val & 0x07; + switch (dev->pm_idx) { case 0x00: fdc_handler(dev); @@ -167,20 +228,49 @@ pc87307_pm_init(pc87307_t *dev, uint16_t addr) pc87307_pm_read, NULL, NULL, pc87307_pm_write, NULL, NULL, dev); } +static void +kbc_handler(pc87307_t *dev) +{ + uint8_t active = (dev->ld_regs[LD_KBD][0x00] & 0x01) && + (dev->pm[0x00] & 0x01); + uint8_t active_2 = dev->ld_regs[LD_MOUSE][0x00] & 0x01; + uint8_t irq = (dev->ld_regs[LD_KBD][0x40] & 0x0f); + uint8_t irq_2 = (dev->ld_regs[LD_MOUSE][0x40] & 0x0f); + uint16_t addr = (dev->ld_regs[LD_KBD][0x30] << 8) | + dev->ld_regs[LD_KBD][0x31]; + uint16_t addr_2 = (dev->ld_regs[LD_KBD][0x32] << 8) | + dev->ld_regs[LD_KBD][0x33]; + + pc87307_log("%02X, %02X, %02X, %02X, %04X, %04X\n", + active, active_2, irq, irq_2, addr, addr_2); + + if (addr <= 0xfff8) { + pc87307_log("Enabling KBC #1 on %04X...\n", addr); + kbc_at_port_handler(0, active, addr, dev->kbc); + } + + if (addr_2 <= 0xfff8) { + pc87307_log("Enabling KBC #2 on %04X...\n", addr_2); + kbc_at_port_handler(1, active, addr_2, dev->kbc); + } + + kbc_at_set_irq(0, active ? irq : 0xffff, dev->kbc); + kbc_at_set_irq(1, (active && active_2) ? irq_2 : 0xffff, dev->kbc); +} + static void fdc_handler(pc87307_t *dev) { - uint8_t irq; - uint8_t active; - uint16_t addr; - fdc_remove(dev->fdc); - active = (dev->ld_regs[0x03][0x00] & 0x01) && (dev->pm[0x00] & 0x08); - addr = ((dev->ld_regs[0x03][0x30] << 8) | dev->ld_regs[0x03][0x31]) - 0x0002; - irq = (dev->ld_regs[0x03][0x40] & 0x0f); + uint8_t active = (dev->ld_regs[LD_FDC][0x00] & 0x01) && + (dev->pm[0x00] & 0x08); + uint8_t irq = (dev->ld_regs[LD_FDC][0x40] & 0x0f); + uint16_t addr = ((dev->ld_regs[LD_FDC][0x30] << 8) | + dev->ld_regs[LD_FDC][0x31]) & 0xfff8; if (active && (addr <= 0xfff8)) { + pc87307_log("Enabling FDC on %04X, IRQ %i...\n", addr, irq); fdc_set_base(dev->fdc, addr); fdc_set_irq(dev->fdc, irq); } @@ -189,268 +279,405 @@ fdc_handler(pc87307_t *dev) static void lpt1_handler(pc87307_t *dev) { - uint8_t irq; - uint8_t active; - uint16_t addr; - - lpt1_remove(); - - active = (dev->ld_regs[0x04][0x00] & 0x01) && (dev->pm[0x00] & 0x10); - addr = (dev->ld_regs[0x04][0x30] << 8) | dev->ld_regs[0x04][0x31]; - irq = (dev->ld_regs[0x04][0x40] & 0x0f); + uint8_t active = (dev->ld_regs[LD_LPT][0x00] & 0x01) && + (dev->pm[0x00] & 0x10); + uint8_t irq = (dev->ld_regs[LD_LPT][0x40] & 0x0f); + uint16_t addr = (dev->ld_regs[LD_LPT][0x30] << 8) | + dev->ld_regs[LD_LPT][0x31]; if (active && (addr <= 0xfffc)) { - lpt1_init(addr); - lpt1_irq(irq); - } + pc87307_log("Enabling LPT1 on %04X...\n", addr); + lpt1_setup(addr); + } else + lpt1_setup(0xffff); + + lpt1_irq(irq); } static void serial_handler(pc87307_t *dev, int uart) { - uint8_t irq; - uint8_t active; - uint16_t addr; - serial_remove(dev->uart[uart]); - active = (dev->ld_regs[0x06 - uart][0x00] & 0x01) && (dev->pm[0x00] & (1 << (6 - uart))); - addr = (dev->ld_regs[0x06 - uart][0x30] << 8) | dev->ld_regs[0x06 - uart][0x31]; - irq = (dev->ld_regs[0x06 - uart][0x40] & 0x0f); + uint8_t active = (dev->ld_regs[LD_UART1 - uart][0x00] & 0x01) && + (dev->pm[0x00] & (1 << (6 - uart))); + uint8_t irq = (dev->ld_regs[LD_UART1 - uart][0x40] & 0x0f); + uint16_t addr = (dev->ld_regs[LD_UART1 - uart][0x30] << 8) | + dev->ld_regs[LD_UART1 - uart][0x31]; - if (active && (addr <= 0xfff8)) + if (active && (addr <= 0xfff8)) { + pc87307_log("Enabling COM%i on %04X...\n", uart + 1, addr); serial_setup(dev->uart[uart], addr, irq); + } else + serial_setup(dev->uart[uart], 0x0000, irq); } static void gpio_handler(pc87307_t *dev) { - uint8_t active; - uint16_t addr; - pc87307_gpio_remove(dev); - active = (dev->ld_regs[0x07][0x00] & 0x01); - addr = (dev->ld_regs[0x07][0x30] << 8) | dev->ld_regs[0x07][0x31]; + uint8_t active = (dev->ld_regs[LD_GPIO][0x00] & 0x01); + uint16_t addr = (dev->ld_regs[LD_GPIO][0x30] << 8) | + dev->ld_regs[LD_GPIO][0x31]; + uint16_t addr_2 = (dev->ld_regs[LD_GPIO][0x32] << 8) | + dev->ld_regs[LD_GPIO][0x33]; - if (active) + if (active) { + pc87307_log("Enabling GPIO #1 on %04X...\n", addr); pc87307_gpio_init(dev, 0, addr); - - addr = (dev->ld_regs[0x07][0x32] << 8) | dev->ld_regs[0x07][0x33]; - - if (active) - pc87307_gpio_init(dev, 1, addr); + pc87307_log("Enabling GPIO #2 on %04X...\n", addr_2); + pc87307_gpio_init(dev, 1, addr_2); + } } static void pm_handler(pc87307_t *dev) { - uint8_t active; - uint16_t addr; - pc87307_pm_remove(dev); - active = (dev->ld_regs[0x08][0x00] & 0x01); - addr = (dev->ld_regs[0x08][0x30] << 8) | dev->ld_regs[0x08][0x31]; + uint8_t active = (dev->ld_regs[LD_PM][0x00] & 0x01); + uint16_t addr = (dev->ld_regs[LD_PM][0x30] << 8) | + dev->ld_regs[LD_PM][0x31]; - if (active) + if (active) { + pc87307_log("Enabling power management on %04X...\n", addr); pc87307_pm_init(dev, addr); + } +} + +static void +superio_handler(pc87307_t *dev) +{ + if (dev->superio_base != 0x0000) + io_removehandler(dev->superio_base, 0x0002, + pc87307_read, NULL, NULL, + pc87307_write, NULL, NULL, dev); + + switch (dev->regs[0x22] & 0x03) { + default: + dev->superio_base = 0x0000; + break; case 0x02: + dev->superio_base = 0x015c; + break; + case 0x03: + dev->superio_base = 0x002e; + break; + } + + if (dev->superio_base != 0x0000) { + pc87307_log("Enabling Super I/O on %04X...\n", dev->superio_base); + io_sethandler(dev->superio_base, 0x0002, + pc87307_read, NULL, NULL, + pc87307_write, NULL, NULL, dev); + } } static void pc87307_write(uint16_t port, uint8_t val, void *priv) { - pc87307_t *dev = (pc87307_t *) priv; - uint8_t index; - - index = (port & 1) ? 0 : 1; + pc87307_t *dev = (pc87307_t *) priv; + uint8_t ld = dev->regs[0x07]; + uint8_t reg = dev->cur_reg - 0x30; + uint8_t index = (port & 1) ? 0 : 1; + uint8_t old = dev->regs[dev->cur_reg]; if (index) { dev->cur_reg = val; return; } else { +#ifdef ENABLE_PC87307_LOG + if (dev->cur_reg >= 0x30) + pc87307_log("[%04X:%08X] [W] (%04X) %02X:%02X = %02X\n", + CS, cpu_state.pc, port, ld, dev->cur_reg, val); + else + pc87307_log("[%04X:%08X] [W] (%04X) %02X = %02X\n", + CS, cpu_state.pc, port, dev->cur_reg, val); +#endif switch (dev->cur_reg) { case 0x00: - case 0x02: - case 0x03: - case 0x06: - case 0x07: - case 0x21: + case 0x02: case 0x03: + case 0x06: case 0x07: dev->regs[dev->cur_reg] = val; break; + case 0x21: + dev->regs[dev->cur_reg] = val; + fdc_toggle_flag(dev->fdc, FDC_FLAG_PS2_MCA, !(val & 0x04)); + break; case 0x22: - dev->regs[dev->cur_reg] = val & 0x7f; + dev->regs[dev->cur_reg] = val; + superio_handler(dev); break; case 0x23: - dev->regs[dev->cur_reg] = val & 0x0f; + dev->regs[dev->cur_reg] = (old & 0xf0) | (val & 0x0f); break; case 0x24: dev->pcregs[dev->regs[0x23]] = val; break; default: - if (dev->cur_reg >= 0x30) { - if ((dev->regs[0x07] != 0x06) || !(dev->regs[0x21] & 0x10)) - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val; - } + if (dev->cur_reg >= 0x30) + old = dev->ld_regs[ld][reg]; break; } } switch (dev->cur_reg) { case 0x30: - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0x01; - switch (dev->regs[0x07]) { - case 0x03: + switch (ld) { + default: + break; + case LD_KBD: case LD_MOUSE: + dev->ld_regs[ld][reg] = val; + kbc_handler(dev); + break; + case LD_RTC: + dev->ld_regs[ld][reg] = val; + break; + case LD_FDC: + dev->ld_regs[ld][reg] = val; fdc_handler(dev); break; - case 0x04: + case LD_LPT: + dev->ld_regs[ld][reg] = val; lpt1_handler(dev); break; - case 0x05: + case LD_UART2: + dev->ld_regs[ld][reg] = val; serial_handler(dev, 1); break; - case 0x06: + case LD_UART1: + dev->ld_regs[ld][reg] = val; serial_handler(dev, 0); break; - case 0x07: + case LD_GPIO: + dev->ld_regs[ld][reg] = val; gpio_handler(dev); break; - case 0x08: + case LD_PM: + dev->ld_regs[ld][reg] = val; pm_handler(dev); break; - - default: - break; } break; + /* I/O Range Check. */ + case 0x31: + switch (ld) { + default: + break; + case LD_MIN ... LD_MAX: + if (ld != LD_MOUSE) + dev->ld_regs[ld][reg] = val; + break; + } + break; + /* Base Address 0 MSB. */ case 0x60: - if (dev->regs[0x07] == 0x04) { - val &= 0x03; - } - fallthrough; - case 0x62: - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val; - if ((dev->cur_reg == 0x62) && (dev->regs[0x07] != 0x07)) - break; - switch (dev->regs[0x07]) { - case 0x03: + switch (ld) { + default: + break; + case LD_KBD: + dev->ld_regs[ld][reg] = val; + kbc_handler(dev); + break; + case LD_RTC: + dev->ld_regs[ld][reg] = val; + break; + case LD_FDC: + dev->ld_regs[ld][reg] = val; fdc_handler(dev); break; - case 0x04: + case LD_LPT: + dev->ld_regs[ld][reg] = (old & 0xfc) | (val & 0x03); lpt1_handler(dev); break; - case 0x05: + case LD_UART2: + dev->ld_regs[ld][reg] = val; serial_handler(dev, 1); break; - case 0x06: + case LD_UART1: + dev->ld_regs[ld][reg] = val; serial_handler(dev, 0); break; - case 0x07: + case LD_GPIO: + dev->ld_regs[ld][reg] = val; gpio_handler(dev); break; - case 0x08: + case LD_PM: + dev->ld_regs[ld][reg] = val; pm_handler(dev); break; - - default: - break; } break; + /* Base Address 0 LSB. */ case 0x61: - switch (dev->regs[0x07]) { - case 0x00: - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0xfb; + switch (ld) { + default: break; - case 0x03: - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = (val & 0xfa) | 0x02; + case LD_KBD: + dev->ld_regs[ld][reg] = (old & 0x04) | (val & 0xfb); + kbc_handler(dev); + break; + case LD_RTC: + dev->ld_regs[ld][reg] = (old & 0x01) | (val & 0xfe); + break; + case LD_FDC: + dev->ld_regs[ld][reg] = (old & 0x07) | (val & 0xf8); fdc_handler(dev); break; - case 0x04: - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0xfc; + case LD_LPT: + dev->ld_regs[ld][reg] = (old & 0x03) | (val & 0xfc); lpt1_handler(dev); break; - case 0x05: - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0xf8; + case LD_UART2: + dev->ld_regs[ld][reg] = (old & 0x07) | (val & 0xf8); serial_handler(dev, 1); break; - case 0x06: - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0xf8; + case LD_UART1: + dev->ld_regs[ld][reg] = (old & 0x07) | (val & 0xf8); serial_handler(dev, 0); break; - case 0x07: - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0xf8; + case LD_GPIO: + dev->ld_regs[ld][reg] = (old & 0x07) | (val & 0xf8); gpio_handler(dev); break; - case 0x08: - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0xfe; + case LD_PM: + dev->ld_regs[ld][reg] = (old & 0x01) | (val & 0xfe); pm_handler(dev); break; - - default: - break; } break; + /* Base Address 1 MSB (undocumented for Logical Device 7). */ + case 0x62: + switch (ld) { + default: + break; + case LD_KBD: + dev->ld_regs[ld][reg] = val; + kbc_handler(dev); + break; + case LD_GPIO: + dev->ld_regs[ld][reg] = val; + gpio_handler(dev); + break; + } + break; + /* Base Address 1 LSB (undocumented for Logical Device 7). */ case 0x63: - if (dev->regs[0x07] == 0x00) - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = (val & 0xfb) | 0x04; - else if (dev->regs[0x07] == 0x07) { - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0xfe; - gpio_handler(dev); - } - break; - case 0x70: - case 0x74: - case 0x75: - switch (dev->regs[0x07]) { - case 0x03: - fdc_handler(dev); - break; - case 0x04: - lpt1_handler(dev); - break; - case 0x05: - serial_handler(dev, 1); - break; - case 0x06: - serial_handler(dev, 0); - break; - case 0x07: - gpio_handler(dev); - break; - case 0x08: - pm_handler(dev); - break; - + switch (ld) { default: break; + case LD_KBD: + dev->ld_regs[ld][reg] = (old & 0x04) | (val & 0xfb); + kbc_handler(dev); + break; + case LD_GPIO: + dev->ld_regs[ld][reg] = (old & 0x01) | (val & 0xfe); + gpio_handler(dev); + break; } break; - case 0xf0: - switch (dev->regs[0x07]) { - case 0x00: - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0xc1; + /* Interrupt Select. */ + case 0x70: + switch (ld) { + default: break; - case 0x03: - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0xe1; + case LD_KBD: case LD_MOUSE: + dev->ld_regs[ld][reg] = val; + kbc_handler(dev); + break; + case LD_RTC: + dev->ld_regs[ld][reg] = val; + break; + case LD_FDC: + dev->ld_regs[ld][reg] = val; + fdc_handler(dev); + break; + case LD_LPT: + dev->ld_regs[ld][reg] = val; + lpt1_handler(dev); + break; + case LD_UART2: + dev->ld_regs[ld][reg] = val; + serial_handler(dev, 1); + break; + case LD_UART1: + dev->ld_regs[ld][reg] = val; + serial_handler(dev, 0); + break; + } + break; + /* Interrupt Type. */ + case 0x71: + switch (ld) { + default: + break; + case LD_MIN ... LD_MAX: + if ((ld == LD_KBD) || (ld == LD_MOUSE)) + dev->ld_regs[ld][reg] = (old & 0xfc) | (val & 0x03); + else + dev->ld_regs[ld][reg] = (old & 0xfd) | (val & 0x02); + break; + } + break; + /* DMA Channel Select 0. */ + case 0x74: + switch (ld) { + default: + break; + case LD_FDC: + dev->ld_regs[ld][reg] = val; + fdc_handler(dev); + break; + case LD_LPT: + dev->ld_regs[ld][reg] = val; + lpt1_handler(dev); + break; + case LD_UART2: + dev->ld_regs[ld][reg] = val; + break; + } + break; + /* DMA Channel Select 1. */ + case 0x75: + switch (ld) { + default: + break; + case LD_UART2: + dev->ld_regs[ld][reg] = val; + break; + } + break; + /* Configuration Register 0. */ + case 0xf0: + switch (ld) { + default: + break; + case LD_KBD: + dev->ld_regs[ld][reg] = val; + break; + case LD_FDC: + dev->ld_regs[ld][reg] = val; fdc_update_densel_polarity(dev->fdc, (val & 0x20) ? 1 : 0); fdc_update_enh_mode(dev->fdc, (val & 0x40) ? 1 : 0); break; - case 0x04: - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0xf3; + case LD_LPT: + dev->ld_regs[ld][reg] = val; lpt1_handler(dev); break; - case 0x05: - case 0x06: - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0x87; - break; - - default: + case LD_UART2: case LD_UART1: + dev->ld_regs[ld][reg] = val; break; } break; + /* Configuration Register 1. */ case 0xf1: - if (dev->regs[0x07] == 0x03) - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0x0f; + switch (ld) { + default: + break; + case LD_FDC: + dev->ld_regs[ld][reg] = val; + break; + } break; default: @@ -458,32 +685,46 @@ pc87307_write(uint16_t port, uint8_t val, void *priv) } } -uint8_t +static uint8_t pc87307_read(uint16_t port, void *priv) { - const pc87307_t *dev = (pc87307_t *) priv; - uint8_t ret = 0xff; - uint8_t index; - - index = (port & 1) ? 0 : 1; + const pc87307_t *dev = (pc87307_t *) priv; + uint8_t ld = dev->regs[0x07]; + uint8_t reg = dev->cur_reg - 0x30; + uint8_t index = (port & 1) ? 0 : 1; + uint8_t ret = 0xff; if (index) ret = dev->cur_reg; else { if (dev->cur_reg >= 0x30) - ret = dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30]; + ret = dev->ld_regs[ld][reg]; else if (dev->cur_reg == 0x24) ret = dev->pcregs[dev->regs[0x23]]; + /* Write-only registers. */ + else if ((dev->cur_reg == 0x00) || + (dev->cur_reg == 0x02) || (dev->cur_reg == 0x03)) + ret = 0x00; else ret = dev->regs[dev->cur_reg]; +#ifdef EANBLE_PC87307_LOG + if (dev->cur_reg >= 0x30) + pc87307_log("[%04X:%08X] [R] (%04X) %02X:%02X = %02X\n", + CS, cpu_state.pc, port, ld, dev->cur_reg, ret); + else + pc87307_log("[%04X:%08X] [R] (%04X) %02X = %02X\n", + CS, cpu_state.pc, port, dev->cur_reg, ret); +#endif } return ret; } void -pc87307_reset(pc87307_t *dev) +pc87307_reset(void *priv) { + pc87307_t *dev = (pc87307_t *) priv; + memset(dev->regs, 0x00, 0x30); for (uint16_t i = 0; i < 256; i++) memset(dev->ld_regs[i], 0x00, 0xd0); @@ -493,77 +734,77 @@ pc87307_reset(pc87307_t *dev) dev->regs[0x20] = dev->id; dev->regs[0x21] = 0x04; + dev->regs[0x22] = dev->baddr; - dev->ld_regs[0x00][0x01] = 0x01; - dev->ld_regs[0x00][0x31] = 0x60; - dev->ld_regs[0x00][0x33] = 0x64; - dev->ld_regs[0x00][0x40] = 0x01; - dev->ld_regs[0x00][0x41] = 0x02; - dev->ld_regs[0x00][0x44] = 0x04; - dev->ld_regs[0x00][0x45] = 0x04; - dev->ld_regs[0x00][0xc0] = 0x40; + dev->ld_regs[LD_KBD ][0x00] = 0x01; + dev->ld_regs[LD_KBD ][0x31] = 0x60; + dev->ld_regs[LD_KBD ][0x33] = 0x64; + dev->ld_regs[LD_KBD ][0x40] = 0x01; + dev->ld_regs[LD_KBD ][0x41] = 0x02; + dev->ld_regs[LD_KBD ][0x44] = 0x04; + dev->ld_regs[LD_KBD ][0x45] = 0x04; + dev->ld_regs[LD_KBD ][0xc0] = 0x40; - dev->ld_regs[0x01][0x40] = 0x0c; - dev->ld_regs[0x01][0x41] = 0x02; - dev->ld_regs[0x01][0x44] = 0x04; - dev->ld_regs[0x01][0x45] = 0x04; + dev->ld_regs[LD_MOUSE][0x40] = 0x0c; + dev->ld_regs[LD_MOUSE][0x41] = 0x02; + dev->ld_regs[LD_MOUSE][0x44] = 0x04; + dev->ld_regs[LD_MOUSE][0x45] = 0x04; - dev->ld_regs[0x02][0x00] = 0x01; - dev->ld_regs[0x02][0x31] = 0x70; - dev->ld_regs[0x02][0x40] = 0x08; - dev->ld_regs[0x02][0x44] = 0x04; - dev->ld_regs[0x02][0x45] = 0x04; + dev->ld_regs[LD_RTC ][0x00] = 0x01; + dev->ld_regs[LD_RTC ][0x31] = 0x70; + dev->ld_regs[LD_RTC ][0x40] = 0x08; + dev->ld_regs[LD_RTC ][0x44] = 0x04; + dev->ld_regs[LD_RTC ][0x45] = 0x04; - dev->ld_regs[0x03][0x01] = 0x01; - dev->ld_regs[0x03][0x30] = 0x03; - dev->ld_regs[0x03][0x31] = 0xf2; - dev->ld_regs[0x03][0x40] = 0x06; - dev->ld_regs[0x03][0x41] = 0x03; - dev->ld_regs[0x03][0x44] = 0x02; - dev->ld_regs[0x03][0x45] = 0x04; - dev->ld_regs[0x03][0xc0] = 0x02; + dev->ld_regs[LD_FDC ][0x01] = 0x01; + dev->ld_regs[LD_FDC ][0x30] = 0x03; + dev->ld_regs[LD_FDC ][0x31] = 0xf0; + dev->ld_regs[LD_FDC ][0x32] = 0x03; + dev->ld_regs[LD_FDC ][0x33] = 0xf7; + dev->ld_regs[LD_FDC ][0x40] = 0x06; + dev->ld_regs[LD_FDC ][0x41] = 0x03; + dev->ld_regs[LD_FDC ][0x44] = 0x02; + dev->ld_regs[LD_FDC ][0x45] = 0x04; + dev->ld_regs[LD_FDC ][0xc0] = 0x02; - dev->ld_regs[0x04][0x30] = 0x02; - dev->ld_regs[0x04][0x31] = 0x78; - dev->ld_regs[0x04][0x40] = 0x07; - dev->ld_regs[0x04][0x44] = 0x04; - dev->ld_regs[0x04][0x45] = 0x04; - dev->ld_regs[0x04][0xc0] = 0xf2; + dev->ld_regs[LD_LPT ][0x30] = 0x02; + dev->ld_regs[LD_LPT ][0x31] = 0x78; + dev->ld_regs[LD_LPT ][0x40] = 0x07; + dev->ld_regs[LD_LPT ][0x44] = 0x04; + dev->ld_regs[LD_LPT ][0x45] = 0x04; + dev->ld_regs[LD_LPT ][0xc0] = 0xf2; - dev->ld_regs[0x05][0x30] = 0x02; - dev->ld_regs[0x05][0x31] = 0xf8; - dev->ld_regs[0x05][0x40] = 0x03; - dev->ld_regs[0x05][0x41] = 0x03; - dev->ld_regs[0x05][0x44] = 0x04; - dev->ld_regs[0x05][0x45] = 0x04; - dev->ld_regs[0x05][0xc0] = 0x02; + dev->ld_regs[LD_UART2][0x30] = 0x02; + dev->ld_regs[LD_UART2][0x31] = 0xf8; + dev->ld_regs[LD_UART2][0x40] = 0x03; + dev->ld_regs[LD_UART2][0x41] = 0x03; + dev->ld_regs[LD_UART2][0x44] = 0x04; + dev->ld_regs[LD_UART2][0x45] = 0x04; + dev->ld_regs[LD_UART2][0xc0] = 0x02; - dev->ld_regs[0x06][0x30] = 0x03; - dev->ld_regs[0x06][0x31] = 0xf8; - dev->ld_regs[0x06][0x40] = 0x04; - dev->ld_regs[0x06][0x41] = 0x03; - dev->ld_regs[0x06][0x44] = 0x04; - dev->ld_regs[0x06][0x45] = 0x04; - dev->ld_regs[0x06][0xc0] = 0x02; + dev->ld_regs[LD_UART1][0x30] = 0x03; + dev->ld_regs[LD_UART1][0x31] = 0xf8; + dev->ld_regs[LD_UART1][0x40] = 0x04; + dev->ld_regs[LD_UART1][0x41] = 0x03; + dev->ld_regs[LD_UART1][0x44] = 0x04; + dev->ld_regs[LD_UART1][0x45] = 0x04; + dev->ld_regs[LD_UART1][0xc0] = 0x02; - dev->ld_regs[0x07][0x44] = 0x04; - dev->ld_regs[0x07][0x45] = 0x04; + dev->ld_regs[LD_GPIO ][0x44] = 0x04; + dev->ld_regs[LD_GPIO ][0x45] = 0x04; - dev->ld_regs[0x08][0x44] = 0x04; - dev->ld_regs[0x08][0x45] = 0x04; + dev->ld_regs[LD_PM ][0x44] = 0x04; + dev->ld_regs[LD_PM ][0x45] = 0x04; -#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; dev->gpio[0][3] = 0xff; - dev->gpio[1][0] = 0xff; + dev->gpio[0][4] = 0xff; + dev->gpio[0][5] = 0x00; + dev->gpio[0][6] = 0x00; + dev->gpio[0][7] = 0xff; dev->gpio[1][1] = 0x00; - dev->gpio[1][2] = 0x00; - dev->gpio[1][3] = 0xff; dev->pm[0] = 0xff; dev->pm[1] = 0xff; @@ -576,10 +817,17 @@ pc87307_reset(pc87307_t *dev) 0 = 360 rpm @ 500 kbps for 3.5" 1 = Default, 300 rpm @ 500, 300, 250, 1000 kbps for 3.5" */ - lpt1_remove(); - serial_remove(dev->uart[0]); - serial_remove(dev->uart[1]); + fdc_toggle_flag(dev->fdc, FDC_FLAG_PS2_MCA, 0); fdc_reset(dev->fdc); + + kbc_handler(dev); + fdc_handler(dev); + lpt1_handler(dev); + serial_handler(dev, 0); + serial_handler(dev, 1); + gpio_handler(dev); + pm_handler(dev); + superio_handler(dev); } static void @@ -593,8 +841,7 @@ pc87307_close(void *priv) static void * pc87307_init(const device_t *info) { - pc87307_t *dev = (pc87307_t *) malloc(sizeof(pc87307_t)); - memset(dev, 0, sizeof(pc87307_t)); + pc87307_t *dev = (pc87307_t *) calloc(1, sizeof(pc87307_t)); dev->id = info->local & 0xff; @@ -603,16 +850,26 @@ pc87307_init(const device_t *info) dev->uart[0] = device_add_inst(&ns16550_device, 1); dev->uart[1] = device_add_inst(&ns16550_device, 2); - pc87307_reset(dev); + switch (info->local & PCX730X_KBC) { + default: + case PCX730X_AMI: + dev->kbc = device_add(&keyboard_ps2_intel_ami_pci_device); + break; + /* Optiplex! */ + case PCX730X_PHOENIX_42: + dev->kbc = device_add(&keyboard_ps2_phoenix_device); + break; + case PCX730X_PHOENIX_42I: + dev->kbc = device_add(&keyboard_ps2_phoenix_pci_device); + break; + } - if (info->local & 0x100) { - io_sethandler(0x02e, 0x0002, - pc87307_read, NULL, NULL, pc87307_write, NULL, NULL, dev); - } - if (info->local & 0x200) { - io_sethandler(0x15c, 0x0002, - pc87307_read, NULL, NULL, pc87307_write, NULL, NULL, dev); - } + if (info->local & PCX730X_15C) + dev->baddr = 0x02; + else + dev->baddr = 0x03; + + pc87307_reset(dev); return dev; } @@ -624,8 +881,8 @@ const device_t pc87307_device = { .local = 0x1c0, .init = pc87307_init, .close = pc87307_close, - .reset = NULL, - { .available = NULL }, + .reset = pc87307_reset, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -638,8 +895,8 @@ const device_t pc87307_15c_device = { .local = 0x2c0, .init = pc87307_init, .close = pc87307_close, - .reset = NULL, - { .available = NULL }, + .reset = pc87307_reset, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -652,8 +909,8 @@ const device_t pc87307_both_device = { .local = 0x3c0, .init = pc87307_init, .close = pc87307_close, - .reset = NULL, - { .available = NULL }, + .reset = pc87307_reset, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -666,8 +923,8 @@ const device_t pc97307_device = { .local = 0x1cf, .init = pc87307_init, .close = pc87307_close, - .reset = NULL, - { .available = NULL }, + .reset = pc87307_reset, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_pc87309.c b/src/sio/sio_pc87309.c index d10cb3e0b..5a3f0d828 100644 --- a/src/sio/sio_pc87309.c +++ b/src/sio/sio_pc87309.c @@ -8,56 +8,97 @@ * * Emulation of the NatSemi PC87309 Super I/O chip. * - * - * * Authors: Miran Grca, * - * Copyright 2020 Miran Grca. + * Copyright 2020-2025 Miran Grca. */ +#include #include #include #include #include #include +#define HAVE_STDARG_H #include <86box/86box.h> #include <86box/io.h> #include <86box/timer.h> #include <86box/device.h> #include <86box/lpt.h> +#include <86box/machine.h> #include <86box/mem.h> #include <86box/nvr.h> #include <86box/pci.h> #include <86box/rom.h> #include <86box/serial.h> -#include <86box/hdc.h> -#include <86box/hdc_ide.h> #include <86box/fdd.h> #include <86box/fdc.h> +#include <86box/keyboard.h> #include <86box/sio.h> +#include <86box/plat_fallthrough.h> +#include "cpu.h" typedef struct pc87309_t { uint8_t id; + uint8_t baddr; uint8_t pm_idx; uint8_t regs[48]; uint8_t ld_regs[256][208]; uint8_t pm[8]; + uint16_t superio_base; uint16_t pm_base; int cur_reg; + void *kbc; fdc_t *fdc; serial_t *uart[2]; } pc87309_t; -static void fdc_handler(pc87309_t *dev); -static void lpt1_handler(pc87309_t *dev); -static void serial_handler(pc87309_t *dev, int uart); +enum { + LD_FDC = 0, + LD_LPT, + LD_UART2, + LD_UART1, + LD_PM, + LD_MOUSE, + LD_KBD +} pc87309_ld_t; + +#define LD_MIN LD_FDC +#define LD_MAX LD_MOUSE + +static void fdc_handler(pc87309_t *dev); +static void lpt1_handler(pc87309_t *dev); +static void serial_handler(pc87309_t *dev, int uart); +static void kbc_handler(pc87309_t *dev); +static void pc87309_write(uint16_t port, uint8_t val, void *priv); +static uint8_t pc87309_read(uint16_t port, void *priv); + +#ifdef ENABLE_PC87309_LOG +int pc87309_do_log = ENABLE_PC87309_LOG; + +static void +pc87309_log(const char *fmt, ...) +{ + va_list ap; + + if (pc87309_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define pc87309_log(fmt, ...) +#endif static void pc87309_pm_write(uint16_t port, uint8_t val, void *priv) { pc87309_t *dev = (pc87309_t *) priv; - if (port & 1) { + if (port & 1) dev->pm[dev->pm_idx] = val; + else { + dev->pm_idx = val & 0x07; switch (dev->pm_idx) { case 0x00: @@ -70,8 +111,7 @@ pc87309_pm_write(uint16_t port, uint8_t val, void *priv) default: break; } - } else - dev->pm_idx = val & 0x07; + } } uint8_t @@ -104,20 +144,49 @@ pc87309_pm_init(pc87309_t *dev, uint16_t addr) pc87309_pm_read, NULL, NULL, pc87309_pm_write, NULL, NULL, dev); } +static void +kbc_handler(pc87309_t *dev) +{ + uint8_t active = (dev->ld_regs[LD_KBD][0x00] & 0x01) && + (dev->pm[0x00] & 0x01); + uint8_t active_2 = dev->ld_regs[LD_MOUSE][0x00] & 0x01; + uint8_t irq = (dev->ld_regs[LD_KBD][0x40] & 0x0f); + uint8_t irq_2 = (dev->ld_regs[LD_MOUSE][0x40] & 0x0f); + uint16_t addr = (dev->ld_regs[LD_KBD][0x30] << 8) | + dev->ld_regs[LD_KBD][0x31]; + uint16_t addr_2 = (dev->ld_regs[LD_KBD][0x32] << 8) | + dev->ld_regs[LD_KBD][0x33]; + + pc87309_log("%02X, %02X, %02X, %02X, %04X, %04X\n", + active, active_2, irq, irq_2, addr, addr_2); + + if (addr <= 0xfff8) { + pc87309_log("Enabling KBC #1 on %04X...\n", addr); + kbc_at_port_handler(0, active, addr, dev->kbc); + } + + if (addr_2 <= 0xfff8) { + pc87309_log("Enabling KBC #2 on %04X...\n", addr_2); + kbc_at_port_handler(1, active, addr_2, dev->kbc); + } + + kbc_at_set_irq(0, active ? irq : 0xffff, dev->kbc); + kbc_at_set_irq(1, (active && active_2) ? irq_2 : 0xffff, dev->kbc); +} + static void fdc_handler(pc87309_t *dev) { - uint8_t irq; - uint8_t active; - uint16_t addr; - fdc_remove(dev->fdc); - active = (dev->ld_regs[0x00][0x00] & 0x01) && (dev->pm[0x00] & 0x08); - addr = ((dev->ld_regs[0x00][0x30] << 8) | dev->ld_regs[0x00][0x31]) - 0x0002; - irq = (dev->ld_regs[0x00][0x40] & 0x0f); + uint8_t active = (dev->ld_regs[LD_FDC][0x00] & 0x01) && + (dev->pm[0x00] & 0x08); + uint8_t irq = (dev->ld_regs[LD_FDC][0x40] & 0x0f); + uint16_t addr = ((dev->ld_regs[LD_FDC][0x30] << 8) | + dev->ld_regs[LD_FDC][0x31]) & 0xfff8; - if (active) { + if (active && (addr <= 0xfff8)) { + pc87309_log("Enabling FDC on %04X, IRQ %i...\n", addr, irq); fdc_set_base(dev->fdc, addr); fdc_set_irq(dev->fdc, irq); } @@ -126,221 +195,351 @@ fdc_handler(pc87309_t *dev) static void lpt1_handler(pc87309_t *dev) { - uint8_t irq; - uint8_t active; - uint16_t addr; + uint8_t active = (dev->ld_regs[LD_LPT][0x00] & 0x01) && + (dev->pm[0x00] & 0x10); + uint8_t irq = (dev->ld_regs[LD_LPT][0x40] & 0x0f); + uint16_t addr = (dev->ld_regs[LD_LPT][0x30] << 8) | + dev->ld_regs[LD_LPT][0x31]; - lpt1_remove(); + if (active && (addr <= 0xfffc)) { + pc87309_log("Enabling LPT1 on %04X...\n", addr); + lpt1_setup(addr); + } else + lpt1_setup(0xffff); - active = (dev->ld_regs[0x01][0x00] & 0x01) && (dev->pm[0x00] & 0x10); - addr = (dev->ld_regs[0x01][0x30] << 8) | dev->ld_regs[0x01][0x31]; - irq = (dev->ld_regs[0x01][0x40] & 0x0f); - - if (active) { - lpt1_init(addr); - lpt1_irq(irq); - } + lpt1_irq(irq); } static void serial_handler(pc87309_t *dev, int uart) { - uint8_t irq; - uint8_t active; - uint16_t addr; - serial_remove(dev->uart[uart]); - active = (dev->ld_regs[0x03 - uart][0x00] & 0x01) && (dev->pm[0x00] & (1 << (6 - uart))); - addr = (dev->ld_regs[0x03 - uart][0x30] << 8) | dev->ld_regs[0x03 - uart][0x31]; - irq = (dev->ld_regs[0x03 - uart][0x40] & 0x0f); + uint8_t active = (dev->ld_regs[LD_UART1 - uart][0x00] & 0x01) && + (dev->pm[0x00] & (1 << (6 - uart))); + uint8_t irq = (dev->ld_regs[LD_UART1 - uart][0x40] & 0x0f); + uint16_t addr = (dev->ld_regs[LD_UART1 - uart][0x30] << 8) | + dev->ld_regs[LD_UART1 - uart][0x31]; - if (active) + if (active && (addr <= 0xfff8)) { + pc87309_log("Enabling COM%i on %04X...\n", uart + 1, addr); serial_setup(dev->uart[uart], addr, irq); + } else + serial_setup(dev->uart[uart], 0x0000, irq); } static void pm_handler(pc87309_t *dev) { - uint8_t active; - uint16_t addr; - pc87309_pm_remove(dev); - active = (dev->ld_regs[0x04][0x00] & 0x01); - addr = (dev->ld_regs[0x04][0x30] << 8) | dev->ld_regs[0x04][0x31]; + uint8_t active = (dev->ld_regs[LD_PM][0x00] & 0x01); + uint16_t addr = (dev->ld_regs[LD_PM][0x30] << 8) | + dev->ld_regs[LD_PM][0x31]; - if (active) + if (active) { + pc87309_log("Enabling power management on %04X...\n", addr); pc87309_pm_init(dev, addr); + } +} + +static void +superio_handler(pc87309_t *dev) +{ + if (dev->superio_base != 0x0000) + io_removehandler(dev->superio_base, 0x0002, + pc87309_read, NULL, NULL, + pc87309_write, NULL, NULL, dev); + + switch (dev->regs[0x21] & 0x0b) { + default: + dev->superio_base = 0x0000; + break; + case 0x02: + case 0x08: case 0x0a: + dev->superio_base = 0x015c; + break; + case 0x03: + case 0x09: case 0x0b: + dev->superio_base = 0x002e; + break; + } + + if (dev->superio_base != 0x0000) { + pc87309_log("Enabling Super I/O on %04X...\n", dev->superio_base); + io_sethandler(dev->superio_base, 0x0002, + pc87309_read, NULL, NULL, + pc87309_write, NULL, NULL, dev); + } } static void pc87309_write(uint16_t port, uint8_t val, void *priv) { - pc87309_t *dev = (pc87309_t *) priv; - uint8_t index; - - index = (port & 1) ? 0 : 1; + pc87309_t *dev = (pc87309_t *) priv; + uint8_t ld = dev->regs[0x07]; + uint8_t reg = dev->cur_reg - 0x30; + uint8_t index = (port & 1) ? 0 : 1; + uint8_t old = dev->regs[dev->cur_reg]; if (index) { dev->cur_reg = val; return; } else { +#ifdef ENABLE_PC87309_LOG + if (dev->cur_reg >= 0x30) + pc87309_log("[%04X:%08X] [W] (%04X) %02X:%02X = %02X\n", + CS, cpu_state.pc, port, ld, dev->cur_reg, val); + else + pc87309_log("[%04X:%08X] [W] (%04X) %02X = %02X\n", + CS, cpu_state.pc, port, dev->cur_reg, val); +#endif switch (dev->cur_reg) { case 0x00: - case 0x02: - case 0x03: - case 0x06: - case 0x07: - case 0x21: + case 0x02: case 0x03: + case 0x06: case 0x07: dev->regs[dev->cur_reg] = val; break; + case 0x21: + dev->regs[dev->cur_reg] = val; + fdc_toggle_flag(dev->fdc, FDC_FLAG_PS2_MCA, !(val & 0x04)); + superio_handler(dev); + break; case 0x22: - dev->regs[dev->cur_reg] = val & 0x7f; + dev->regs[dev->cur_reg] = val; break; default: - if (dev->cur_reg >= 0x30) { - if ((dev->regs[0x07] != 0x06) || !(dev->regs[0x21] & 0x10)) - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val; - } + if (dev->cur_reg >= 0x30) + old = dev->ld_regs[ld][reg]; break; } } switch (dev->cur_reg) { case 0x30: - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0x01; - switch (dev->regs[0x07]) { - case 0x00: + switch (ld) { + default: + break; + case LD_KBD: case LD_MOUSE: + dev->ld_regs[ld][reg] = val; + kbc_handler(dev); + break; + case LD_FDC: + dev->ld_regs[ld][reg] = val; fdc_handler(dev); break; - case 0x01: + case LD_LPT: + dev->ld_regs[ld][reg] = val; lpt1_handler(dev); break; - case 0x02: + case LD_UART2: + dev->ld_regs[ld][reg] = val; serial_handler(dev, 1); break; - case 0x03: + case LD_UART1: + dev->ld_regs[ld][reg] = val; serial_handler(dev, 0); break; - case 0x04: + case LD_PM: + dev->ld_regs[ld][reg] = val; pm_handler(dev); break; - - default: - break; } break; + /* I/O Range Check. */ + case 0x31: + switch (ld) { + default: + break; + case LD_MIN ... LD_MAX: + if (ld != LD_MOUSE) + dev->ld_regs[ld][reg] = val; + break; + } + break; + /* Base Address 0 MSB. */ case 0x60: - case 0x62: - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0x07; - if (dev->cur_reg == 0x62) - break; - switch (dev->regs[0x07]) { - case 0x00: + switch (ld) { + default: + break; + case LD_KBD: + dev->ld_regs[ld][reg] = val; + kbc_handler(dev); + break; + case LD_FDC: + dev->ld_regs[ld][reg] = val; fdc_handler(dev); break; - case 0x01: + case LD_LPT: + dev->ld_regs[ld][reg] = (old & 0xfc) | (val & 0x03); lpt1_handler(dev); break; - case 0x02: + case LD_UART2: + dev->ld_regs[ld][reg] = val; serial_handler(dev, 1); break; - case 0x03: + case LD_UART1: + dev->ld_regs[ld][reg] = val; serial_handler(dev, 0); break; - case 0x04: + case LD_PM: + dev->ld_regs[ld][reg] = val; pm_handler(dev); break; - - default: - break; } break; - case 0x63: - if (dev->regs[0x07] == 0x06) - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = (val & 0xf8) | 0x04; - break; + /* Base Address 0 LSB. */ case 0x61: - switch (dev->regs[0x07]) { - case 0x00: - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = (val & 0xfa) | 0x02; + switch (ld) { + default: + break; + case LD_KBD: + dev->ld_regs[ld][reg] = (old & 0x04) | (val & 0xfb); + kbc_handler(dev); + break; + case LD_FDC: + dev->ld_regs[ld][reg] = (old & 0x07) | (val & 0xf8); fdc_handler(dev); break; - case 0x01: - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0xfc; + case LD_LPT: + dev->ld_regs[ld][reg] = (old & 0x03) | (val & 0xfc); lpt1_handler(dev); break; - case 0x02: - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0xf8; + case LD_UART2: + dev->ld_regs[ld][reg] = (old & 0x07) | (val & 0xf8); serial_handler(dev, 1); break; - case 0x03: - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0xf8; + case LD_UART1: + dev->ld_regs[ld][reg] = (old & 0x07) | (val & 0xf8); serial_handler(dev, 0); break; - case 0x04: - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0xfe; + case LD_PM: + dev->ld_regs[ld][reg] = (old & 0x01) | (val & 0xfe); pm_handler(dev); break; - case 0x06: - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0xf8; - break; - - default: - break; } break; + /* Base Address 1 MSB (undocumented for Logical Device 7). */ + case 0x62: + switch (ld) { + default: + break; + case LD_KBD: + dev->ld_regs[ld][reg] = val; + kbc_handler(dev); + break; + } + break; + /* Base Address 1 LSB (undocumented for Logical Device 7). */ + case 0x63: + switch (ld) { + default: + break; + case LD_KBD: + dev->ld_regs[ld][reg] = (old & 0x04) | (val & 0xfb); + kbc_handler(dev); + break; + } + break; + /* Interrupt Select. */ case 0x70: - case 0x74: - case 0x75: - switch (dev->regs[0x07]) { - case 0x00: + switch (ld) { + default: + break; + case LD_KBD: case LD_MOUSE: + dev->ld_regs[ld][reg] = val; + kbc_handler(dev); + break; + case LD_FDC: + dev->ld_regs[ld][reg] = val; fdc_handler(dev); break; - case 0x01: + case LD_LPT: + dev->ld_regs[ld][reg] = val; lpt1_handler(dev); break; - case 0x02: + case LD_UART2: + dev->ld_regs[ld][reg] = val; serial_handler(dev, 1); break; - case 0x03: + case LD_UART1: + dev->ld_regs[ld][reg] = val; serial_handler(dev, 0); break; - case 0x04: - pm_handler(dev); - break; - - default: - break; } break; + /* Interrupt Type. */ + case 0x71: + switch (ld) { + default: + break; + case LD_MIN ... LD_MAX: + if ((ld == LD_KBD) || (ld == LD_MOUSE)) + dev->ld_regs[ld][reg] = (old & 0xfc) | (val & 0x03); + else + dev->ld_regs[ld][reg] = (old & 0xfd) | (val & 0x02); + break; + } + break; + /* DMA Channel Select 0. */ + case 0x74: + switch (ld) { + default: + break; + case LD_FDC: + dev->ld_regs[ld][reg] = val; + fdc_handler(dev); + break; + case LD_LPT: + dev->ld_regs[ld][reg] = val; + lpt1_handler(dev); + break; + case LD_UART2: + dev->ld_regs[ld][reg] = val; + break; + } + break; + /* DMA Channel Select 1. */ + case 0x75: + switch (ld) { + default: + break; + case LD_UART2: + dev->ld_regs[ld][reg] = val; + break; + } + break; + /* Configuration Register 0. */ case 0xf0: - switch (dev->regs[0x07]) { - case 0x00: - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0xe1; + switch (ld) { + default: + break; + case LD_KBD: + dev->ld_regs[ld][reg] = val; + break; + case LD_FDC: + dev->ld_regs[ld][reg] = val; fdc_update_densel_polarity(dev->fdc, (val & 0x20) ? 1 : 0); fdc_update_enh_mode(dev->fdc, (val & 0x40) ? 1 : 0); break; - case 0x01: - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0xf3; + case LD_LPT: + dev->ld_regs[ld][reg] = val; lpt1_handler(dev); break; - case 0x02: - case 0x03: - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0x87; - break; - case 0x06: - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0xc1; - break; - - default: + case LD_UART2: case LD_UART1: + dev->ld_regs[ld][reg] = val; break; } break; + /* Configuration Register 1. */ case 0xf1: - if (dev->regs[0x07] == 0x00) - dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30] = val & 0x0f; + switch (ld) { + default: + break; + case LD_FDC: + dev->ld_regs[ld][reg] = val; + break; + } break; default: @@ -348,97 +547,102 @@ pc87309_write(uint16_t port, uint8_t val, void *priv) } } -uint8_t +static uint8_t pc87309_read(uint16_t port, void *priv) { - const pc87309_t *dev = (pc87309_t *) priv; - uint8_t ret = 0xff; - uint8_t index; - - index = (port & 1) ? 0 : 1; + const pc87309_t *dev = (pc87309_t *) priv; + uint8_t ld = dev->regs[0x07]; + uint8_t reg = dev->cur_reg - 0x30; + uint8_t index = (port & 1) ? 0 : 1; + uint8_t ret = 0xff; if (index) - ret = dev->cur_reg & 0x1f; + ret = dev->cur_reg; else { if (dev->cur_reg >= 0x30) - ret = dev->ld_regs[dev->regs[0x07]][dev->cur_reg - 0x30]; + ret = dev->ld_regs[ld][reg]; + /* Write-only registers. */ + else if ((dev->cur_reg == 0x00) || + (dev->cur_reg == 0x02) || (dev->cur_reg == 0x03)) + ret = 0x00; else ret = dev->regs[dev->cur_reg]; +#ifdef ENABLE_PC87309_LOG + if (dev->cur_reg >= 0x30) + pc87309_log("[%04X:%08X] [R] (%04X) %02X:%02X = %02X\n", + CS, cpu_state.pc, port, ld, dev->cur_reg, ret); + else + pc87309_log("[%04X:%08X] [R] (%04X) %02X = %02X\n", + CS, cpu_state.pc, port, dev->cur_reg, ret); +#endif } return ret; } void -pc87309_reset(pc87309_t *dev) +pc87309_reset(void *priv) { + pc87309_t *dev = (pc87309_t *) priv; + memset(dev->regs, 0x00, 0x30); for (uint16_t i = 0; i < 256; i++) memset(dev->ld_regs[i], 0x00, 0xd0); memset(dev->pm, 0x00, 0x08); dev->regs[0x20] = dev->id; - dev->regs[0x21] = 0x04; + dev->regs[0x21] = 0x04 | dev->baddr; - dev->ld_regs[0x00][0x01] = 0x01; - dev->ld_regs[0x00][0x30] = 0x03; - dev->ld_regs[0x00][0x31] = 0xf2; - dev->ld_regs[0x00][0x40] = 0x06; - dev->ld_regs[0x00][0x41] = 0x03; - dev->ld_regs[0x00][0x44] = 0x02; - dev->ld_regs[0x00][0x45] = 0x04; - dev->ld_regs[0x00][0xc0] = 0x02; + dev->ld_regs[LD_KBD ][0x00] = 0x01; + dev->ld_regs[LD_KBD ][0x31] = 0x60; + dev->ld_regs[LD_KBD ][0x33] = 0x64; + dev->ld_regs[LD_KBD ][0x40] = 0x01; + dev->ld_regs[LD_KBD ][0x41] = 0x02; + dev->ld_regs[LD_KBD ][0x44] = 0x04; + dev->ld_regs[LD_KBD ][0x45] = 0x04; + dev->ld_regs[LD_KBD ][0xc0] = 0x40; - dev->ld_regs[0x01][0x30] = 0x02; - dev->ld_regs[0x01][0x31] = 0x78; - dev->ld_regs[0x01][0x40] = 0x07; - dev->ld_regs[0x01][0x44] = 0x04; - dev->ld_regs[0x01][0x45] = 0x04; - dev->ld_regs[0x01][0xc0] = 0xf2; + dev->ld_regs[LD_MOUSE][0x40] = 0x0c; + dev->ld_regs[LD_MOUSE][0x41] = 0x02; + dev->ld_regs[LD_MOUSE][0x44] = 0x04; + dev->ld_regs[LD_MOUSE][0x45] = 0x04; - dev->ld_regs[0x02][0x30] = 0x02; - dev->ld_regs[0x02][0x31] = 0xf8; - dev->ld_regs[0x02][0x40] = 0x03; - dev->ld_regs[0x02][0x41] = 0x03; - dev->ld_regs[0x02][0x44] = 0x04; - dev->ld_regs[0x02][0x45] = 0x04; - dev->ld_regs[0x02][0xc0] = 0x02; + dev->ld_regs[LD_FDC ][0x01] = 0x01; + dev->ld_regs[LD_FDC ][0x30] = 0x03; + dev->ld_regs[LD_FDC ][0x31] = 0xf0; + dev->ld_regs[LD_FDC ][0x32] = 0x03; + dev->ld_regs[LD_FDC ][0x33] = 0xf7; + dev->ld_regs[LD_FDC ][0x40] = 0x06; + dev->ld_regs[LD_FDC ][0x41] = 0x03; + dev->ld_regs[LD_FDC ][0x44] = 0x02; + dev->ld_regs[LD_FDC ][0x45] = 0x04; + dev->ld_regs[LD_FDC ][0xc0] = 0x02; - dev->ld_regs[0x03][0x30] = 0x03; - dev->ld_regs[0x03][0x31] = 0xf8; - dev->ld_regs[0x03][0x40] = 0x04; - dev->ld_regs[0x03][0x41] = 0x03; - dev->ld_regs[0x03][0x44] = 0x04; - dev->ld_regs[0x03][0x45] = 0x04; - dev->ld_regs[0x03][0xc0] = 0x02; + dev->ld_regs[LD_LPT ][0x30] = 0x02; + dev->ld_regs[LD_LPT ][0x31] = 0x78; + dev->ld_regs[LD_LPT ][0x40] = 0x07; + dev->ld_regs[LD_LPT ][0x44] = 0x04; + dev->ld_regs[LD_LPT ][0x45] = 0x04; + dev->ld_regs[LD_LPT ][0xc0] = 0xf2; - dev->ld_regs[0x04][0x44] = 0x04; - dev->ld_regs[0x04][0x45] = 0x04; + dev->ld_regs[LD_UART2][0x30] = 0x02; + dev->ld_regs[LD_UART2][0x31] = 0xf8; + dev->ld_regs[LD_UART2][0x40] = 0x03; + dev->ld_regs[LD_UART2][0x41] = 0x03; + dev->ld_regs[LD_UART2][0x44] = 0x04; + dev->ld_regs[LD_UART2][0x45] = 0x04; + dev->ld_regs[LD_UART2][0xc0] = 0x02; - dev->ld_regs[0x05][0x40] = 0x0c; - dev->ld_regs[0x05][0x41] = 0x02; - dev->ld_regs[0x05][0x44] = 0x04; - dev->ld_regs[0x05][0x45] = 0x04; + dev->ld_regs[LD_UART1][0x30] = 0x03; + dev->ld_regs[LD_UART1][0x31] = 0xf8; + dev->ld_regs[LD_UART1][0x40] = 0x04; + dev->ld_regs[LD_UART1][0x41] = 0x03; + dev->ld_regs[LD_UART1][0x44] = 0x04; + dev->ld_regs[LD_UART1][0x45] = 0x04; + dev->ld_regs[LD_UART1][0xc0] = 0x02; - dev->ld_regs[0x06][0x01] = 0x01; - dev->ld_regs[0x06][0x31] = 0x60; - dev->ld_regs[0x06][0x33] = 0x64; - dev->ld_regs[0x06][0x40] = 0x01; - dev->ld_regs[0x06][0x41] = 0x02; - dev->ld_regs[0x06][0x44] = 0x04; - dev->ld_regs[0x06][0x45] = 0x04; - dev->ld_regs[0x06][0xc0] = 0x40; - - dev->regs[0x00] = 0x0B; - dev->regs[0x01] = 0x01; - dev->regs[0x03] = 0x01; - dev->regs[0x05] = 0x0D; - dev->regs[0x08] = 0x70; - dev->regs[0x09] = 0xC0; - dev->regs[0x0b] = 0x80; - dev->regs[0x0f] = 0x1E; - dev->regs[0x12] = 0x30; - dev->regs[0x19] = 0xEF; + dev->ld_regs[LD_PM ][0x44] = 0x04; + dev->ld_regs[LD_PM ][0x45] = 0x04; dev->pm[0] = 0x79; dev->pm[4] = 0x0e; @@ -449,10 +653,16 @@ pc87309_reset(pc87309_t *dev) 0 = 360 rpm @ 500 kbps for 3.5" 1 = Default, 300 rpm @ 500, 300, 250, 1000 kbps for 3.5" */ - lpt1_remove(); - serial_remove(dev->uart[0]); - serial_remove(dev->uart[1]); + fdc_toggle_flag(dev->fdc, FDC_FLAG_PS2_MCA, 0); fdc_reset(dev->fdc); + + kbc_handler(dev); + fdc_handler(dev); + lpt1_handler(dev); + serial_handler(dev, 0); + serial_handler(dev, 1); + pm_handler(dev); + superio_handler(dev); } static void @@ -466,8 +676,7 @@ pc87309_close(void *priv) static void * pc87309_init(const device_t *info) { - pc87309_t *dev = (pc87309_t *) malloc(sizeof(pc87309_t)); - memset(dev, 0, sizeof(pc87309_t)); + pc87309_t *dev = (pc87309_t *) calloc(1, sizeof(pc87309_t)); dev->id = info->local & 0xff; @@ -476,16 +685,27 @@ pc87309_init(const device_t *info) dev->uart[0] = device_add_inst(&ns16550_device, 1); dev->uart[1] = device_add_inst(&ns16550_device, 2); - pc87309_reset(dev); - - if (info->local & 0x100) { - io_sethandler(0x15c, 0x0002, - pc87309_read, NULL, NULL, pc87309_write, NULL, NULL, dev); - } else { - io_sethandler(0x02e, 0x0002, - pc87309_read, NULL, NULL, pc87309_write, NULL, NULL, dev); + switch (info->local & PCX730X_KBC) { + default: + case PCX730X_AMI: + dev->kbc = device_add(&keyboard_ps2_intel_ami_pci_device); + break; + /* Optiplex! */ + case PCX730X_PHOENIX_42: + dev->kbc = device_add(&keyboard_ps2_phoenix_device); + break; + case PCX730X_PHOENIX_42I: + dev->kbc = device_add(&keyboard_ps2_phoenix_pci_device); + break; } + if (info->local & PCX730X_15C) + dev->baddr = 0x0a; + else + dev->baddr = 0x0b; + + pc87309_reset(dev); + return dev; } @@ -493,25 +713,11 @@ const device_t pc87309_device = { .name = "National Semiconductor PC87309 Super I/O", .internal_name = "pc87309", .flags = 0, - .local = 0xe0, + .local = 0, .init = pc87309_init, .close = pc87309_close, - .reset = NULL, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -const device_t pc87309_15c_device = { - .name = "National Semiconductor PC87309 Super I/O (Port 15Ch)", - .internal_name = "pc87309_15c", - .flags = 0, - .local = 0x1e0, - .init = pc87309_init, - .close = pc87309_close, - .reset = NULL, - { .available = NULL }, + .reset = pc87309_reset, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_pc87310.c b/src/sio/sio_pc87310.c index 075b819ff..5bd595f05 100644 --- a/src/sio/sio_pc87310.c +++ b/src/sio/sio_pc87310.c @@ -106,7 +106,7 @@ lpt1_handler(pc87310_t *dev) } if (lpt_port) - lpt1_init(lpt_port); + lpt1_setup(lpt_port); lpt1_irq(lpt_irq); } @@ -309,7 +309,7 @@ const device_t pc87310_device = { .init = pc87310_init, .close = pc87310_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -323,7 +323,7 @@ const device_t pc87310_ide_device = { .init = pc87310_init, .close = pc87310_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -337,7 +337,7 @@ const device_t ali5105_device = { .init = pc87310_init, .close = pc87310_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_pc87311.c b/src/sio/sio_pc87311.c index 9740753d1..b560ef425 100644 --- a/src/sio/sio_pc87311.c +++ b/src/sio/sio_pc87311.c @@ -220,7 +220,7 @@ pc87311_lpt_handler(pc87311_t *dev) default: break; } - lpt1_init(dev->base); + lpt1_setup(dev->base); lpt1_irq(dev->irq); pc87311_log("PC87311-LPT: BASE %04x IRQ %01x\n", dev->base, dev->irq); } @@ -269,8 +269,7 @@ pc87311_close(void *priv) static void * pc87311_init(const device_t *info) { - pc87311_t *dev = (pc87311_t *) malloc(sizeof(pc87311_t)); - memset(dev, 0, sizeof(pc87311_t)); + pc87311_t *dev = (pc87311_t *) calloc(1, sizeof(pc87311_t)); /* Avoid conflicting with machines that make no use of the PC87311 Internal IDE */ HAS_IDE_FUNCTIONALITY = info->local; @@ -298,7 +297,7 @@ const device_t pc87311_device = { .init = pc87311_init, .close = pc87311_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -312,7 +311,7 @@ const device_t pc87311_ide_device = { .init = pc87311_init, .close = pc87311_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_pc87332.c b/src/sio/sio_pc87332.c index 5cbf9f694..d9fb0b211 100644 --- a/src/sio/sio_pc87332.c +++ b/src/sio/sio_pc87332.c @@ -77,7 +77,7 @@ lpt1_handler(pc87332_t *dev) } if (lpt_port) - lpt1_init(lpt_port); + lpt1_setup(lpt_port); lpt1_irq(lpt_irq); } @@ -323,8 +323,7 @@ pc87332_close(void *priv) static void * pc87332_init(const device_t *info) { - pc87332_t *dev = (pc87332_t *) malloc(sizeof(pc87332_t)); - memset(dev, 0, sizeof(pc87332_t)); + pc87332_t *dev = (pc87332_t *) calloc(1, sizeof(pc87332_t)); dev->fdc = device_add(&fdc_at_nsc_device); @@ -354,7 +353,7 @@ const device_t pc87332_device = { .init = pc87332_init, .close = pc87332_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -368,7 +367,7 @@ const device_t pc87332_398_device = { .init = pc87332_init, .close = pc87332_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -382,7 +381,7 @@ const device_t pc87332_398_ide_device = { .init = pc87332_init, .close = pc87332_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -396,7 +395,7 @@ const device_t pc87332_398_ide_sec_device = { .init = pc87332_init, .close = pc87332_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -410,7 +409,7 @@ const device_t pc87332_398_ide_fdcon_device = { .init = pc87332_init, .close = pc87332_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_prime3b.c b/src/sio/sio_prime3b.c index c93630516..1cc0be3aa 100644 --- a/src/sio/sio_prime3b.c +++ b/src/sio/sio_prime3b.c @@ -176,7 +176,7 @@ prime3b_lpt_handler(prime3b_t *dev) { uint16_t lpt_base = (ASR & 2) ? LPT_MDA_ADDR : (!(ASR & 1) ? LPT1_ADDR : LPT2_ADDR); lpt1_remove(); - lpt1_init(lpt_base); + lpt1_setup(lpt_base); lpt1_irq(LPT1_IRQ); prime3b_log("Prime3B-LPT: Enabled with base %03x\n", lpt_base); } @@ -257,8 +257,7 @@ prime3b_close(void *priv) static void * prime3b_init(const device_t *info) { - prime3b_t *dev = (prime3b_t *) malloc(sizeof(prime3b_t)); - memset(dev, 0, sizeof(prime3b_t)); + prime3b_t *dev = (prime3b_t *) calloc(1, sizeof(prime3b_t)); /* Avoid conflicting with machines that make no use of the Prime3B Internal IDE */ HAS_IDE_FUNCTIONALITY = info->local; @@ -290,7 +289,7 @@ const device_t prime3b_device = { .init = prime3b_init, .close = prime3b_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -304,7 +303,7 @@ const device_t prime3b_ide_device = { .init = prime3b_init, .close = prime3b_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_prime3c.c b/src/sio/sio_prime3c.c index b19f861bf..f70f9f372 100644 --- a/src/sio/sio_prime3c.c +++ b/src/sio/sio_prime3c.c @@ -241,7 +241,7 @@ prime3c_lpt_handler(prime3c_t *dev) lpt1_remove(); if (!(FUNCTION_SELECT & 0x03)) { - lpt1_init(LPT_BASE_ADDRESS << 2); + lpt1_setup(LPT_BASE_ADDRESS << 2); lpt1_irq(FDC_LPT_IRQ & 0xf); prime3c_log("Prime3C-LPT: BASE %04x IRQ %02x\n", LPT_BASE_ADDRESS << 2, FDC_LPT_IRQ & 0xf); } @@ -296,8 +296,7 @@ prime3c_close(void *priv) static void * prime3c_init(const device_t *info) { - prime3c_t *dev = (prime3c_t *) malloc(sizeof(prime3c_t)); - memset(dev, 0, sizeof(prime3c_t)); + prime3c_t *dev = (prime3c_t *) calloc(1, sizeof(prime3c_t)); /* Avoid conflicting with machines that make no use of the Prime3C Internal IDE */ HAS_IDE_FUNCTIONALITY = info->local; @@ -335,7 +334,7 @@ const device_t prime3c_device = { .init = prime3c_init, .close = prime3c_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -349,7 +348,7 @@ const device_t prime3c_ide_device = { .init = prime3c_init, .close = prime3c_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_um8663f.c b/src/sio/sio_um8663f.c index 7391b029f..6075fe3e7 100644 --- a/src/sio/sio_um8663f.c +++ b/src/sio/sio_um8663f.c @@ -106,12 +106,12 @@ um8663f_lpt_handler(um8663f_t *dev) if (dev->regs[0] & 0x08) { switch ((dev->regs[1] >> 3) & 0x01) { case 0x01: - lpt1_init(LPT1_ADDR); - lpt1_irq(7); + lpt1_setup(LPT1_ADDR); + lpt1_irq(LPT1_IRQ); break; case 0x00: - lpt1_init(LPT2_ADDR); - lpt1_irq(5); + lpt1_setup(LPT2_ADDR); + lpt1_irq(LPT2_IRQ); break; default: @@ -231,7 +231,7 @@ um8663f_reset(void *priv) serial_setup(dev->uart[1], COM2_ADDR, COM2_IRQ); lpt1_remove(); - lpt1_init(LPT1_ADDR); + lpt1_setup(LPT1_ADDR); fdc_reset(dev->fdc); fdc_remove(dev->fdc); @@ -274,13 +274,70 @@ um8663f_init(UNUSED(const device_t *info)) dev->max_reg = info->local >> 8; - io_sethandler(0x0108, 0x0002, um8663f_read, NULL, NULL, um8663f_write, NULL, NULL, dev); + if (dev->max_reg != 0x00) + io_sethandler(0x0108, 0x0002, um8663f_read, NULL, NULL, um8663f_write, NULL, NULL, dev); um8663f_reset(dev); return dev; } +const device_t um82c862f_device = { + .name = "UMC UM82C862F Super I/O", + .internal_name = "um82c862f", + .flags = 0, + .local = 0x0000, + .init = um8663f_init, + .close = um8663f_close, + .reset = um8663f_reset, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t um82c862f_ide_device = { + .name = "UMC UM82C862F Super I/O (With IDE)", + .internal_name = "um82c862f_ide", + .flags = 0, + .local = 0x0001, + .init = um8663f_init, + .close = um8663f_close, + .reset = um8663f_reset, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t um82c863f_device = { + .name = "UMC UM82C863F Super I/O", + .internal_name = "um82c863f", + .flags = 0, + .local = 0xc100, + .init = um8663f_init, + .close = um8663f_close, + .reset = um8663f_reset, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t um82c863f_ide_device = { + .name = "UMC UM82C863F Super I/O (With IDE)", + .internal_name = "um82c863f_ide", + .flags = 0, + .local = 0xc101, + .init = um8663f_init, + .close = um8663f_close, + .reset = um8663f_reset, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + const device_t um8663af_device = { .name = "UMC UM8663AF Super I/O", .internal_name = "um8663af", @@ -289,7 +346,7 @@ const device_t um8663af_device = { .init = um8663f_init, .close = um8663f_close, .reset = um8663f_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -303,7 +360,7 @@ const device_t um8663af_ide_device = { .init = um8663f_init, .close = um8663f_close, .reset = um8663f_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -317,7 +374,7 @@ const device_t um8663af_ide_sec_device = { .init = um8663f_init, .close = um8663f_close, .reset = um8663f_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -331,7 +388,7 @@ const device_t um8663bf_device = { .init = um8663f_init, .close = um8663f_close, .reset = um8663f_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -345,7 +402,7 @@ const device_t um8663bf_ide_device = { .init = um8663f_init, .close = um8663f_close, .reset = um8663f_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -359,7 +416,7 @@ const device_t um8663bf_ide_sec_device = { .init = um8663f_init, .close = um8663f_close, .reset = um8663f_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_um8669f.c b/src/sio/sio_um8669f.c index 136b1add6..6da9ef6e9 100644 --- a/src/sio/sio_um8669f.c +++ b/src/sio/sio_um8669f.c @@ -207,7 +207,7 @@ um8669f_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *pri if (config->activate && (config->io[0].base != ISAPNP_IO_DISABLED)) { um8669f_log("UM8669F: LPT enabled at port %04X IRQ %d\n", config->io[0].base, config->irq[0].irq); - lpt1_init(config->io[0].base); + lpt1_setup(config->io[0].base); } else { um8669f_log("UM8669F: LPT disabled\n"); } @@ -328,8 +328,7 @@ um8669f_init(const device_t *info) { um8669f_log("UM8669F: init(%02X)\n", info->local); - um8669f_t *dev = (um8669f_t *) malloc(sizeof(um8669f_t)); - memset(dev, 0, sizeof(um8669f_t)); + um8669f_t *dev = (um8669f_t *) calloc(1, sizeof(um8669f_t)); dev->pnp_card = isapnp_add_card(um8669f_pnp_rom, sizeof(um8669f_pnp_rom), um8669f_pnp_config_changed, NULL, NULL, NULL, dev); for (uint8_t i = 0; i < (sizeof(um8669f_pnp_defaults) / sizeof(isapnp_device_config_t)); i++) @@ -362,7 +361,7 @@ const device_t um8669f_device = { .init = um8669f_init, .close = um8669f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -376,7 +375,7 @@ const device_t um8669f_ide_device = { .init = um8669f_init, .close = um8669f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -390,7 +389,7 @@ const device_t um8669f_ide_sec_device = { .init = um8669f_init, .close = um8669f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_vl82c113.c b/src/sio/sio_vl82c113.c index 6a02ef359..b000fe5dd 100644 --- a/src/sio/sio_vl82c113.c +++ b/src/sio/sio_vl82c113.c @@ -22,8 +22,10 @@ #include <86box/timer.h> #include <86box/device.h> #include <86box/keyboard.h> +#include <86box/machine.h> #include <86box/nvr.h> #include <86box/sio.h> +#include <86box/plat_unused.h> typedef struct vl82c113_t { uint8_t index; @@ -128,11 +130,14 @@ vl82c113_close(void *priv) } static void * -vl82c113_init(const device_t *info) +vl82c113_init(UNUSED(const device_t *info)) { vl82c113_t *dev = (vl82c113_t *) calloc(1, sizeof(vl82c113_t)); - dev->nvr = device_add(&at_nvr_device); + if (!strcmp(machine_get_internal_name(), "martin")) + dev->nvr = device_add(&martin_nvr_device); + else + dev->nvr = device_add(&amstrad_megapc_nvr_device); dev->nvr_enabled = 1; dev->nvr_base = 0x0070; @@ -155,7 +160,7 @@ const device_t vl82c113_device = { .init = vl82c113_init, .close = vl82c113_close, .reset = vl82c113_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_vt82c686.c b/src/sio/sio_vt82c686.c index f22af07df..0e874210d 100644 --- a/src/sio/sio_vt82c686.c +++ b/src/sio/sio_vt82c686.c @@ -86,7 +86,7 @@ vt82c686_lpt_handler(vt82c686_t *dev) lpt1_remove(); if (((dev->regs[0x02] & 0x03) != 0x03) && !(dev->regs[0x0f] & 0x11) && (io_base >= 0x100) && (io_base <= io_mask)) - lpt1_init(io_base); + lpt1_setup(io_base); if (dev->lpt_irq) { lpt1_irq(dev->lpt_irq); @@ -287,8 +287,7 @@ vt82c686_close(void *priv) static void * vt82c686_init(UNUSED(const device_t *info)) { - vt82c686_t *dev = (vt82c686_t *) malloc(sizeof(vt82c686_t)); - memset(dev, 0, sizeof(vt82c686_t)); + vt82c686_t *dev = (vt82c686_t *) calloc(1, sizeof(vt82c686_t)); dev->fdc = device_add(&fdc_at_smc_device); dev->fdc_dma = 2; @@ -311,7 +310,7 @@ const device_t via_vt82c686_sio_device = { .init = vt82c686_init, .close = vt82c686_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_w83787f.c b/src/sio/sio_w83787f.c index 2e4b82059..f4971ddce 100644 --- a/src/sio/sio_w83787f.c +++ b/src/sio/sio_w83787f.c @@ -197,7 +197,7 @@ w83787f_lpt_handler(w83787f_t *dev) lpt1_remove(); if (enable) { - lpt1_init(addr); + lpt1_setup(addr); lpt1_irq(irq); } } @@ -378,7 +378,7 @@ w83787f_reset(w83787f_t *dev) uint16_t hefere = dev->reg_init & 0x0100; lpt1_remove(); - lpt1_init(LPT1_ADDR); + lpt1_setup(LPT1_ADDR); lpt1_irq(LPT1_IRQ); memset(dev->regs, 0, 0x2A); @@ -443,8 +443,7 @@ w83787f_close(void *priv) static void * w83787f_init(const device_t *info) { - w83787f_t *dev = (w83787f_t *) malloc(sizeof(w83787f_t)); - memset(dev, 0, sizeof(w83787f_t)); + w83787f_t *dev = (w83787f_t *) calloc(1, sizeof(w83787f_t)); HAS_IDE_FUNCTIONALITY = (info->local & 0x30); @@ -474,7 +473,7 @@ const device_t w83787f_88h_device = { .init = w83787f_init, .close = w83787f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -488,7 +487,7 @@ const device_t w83787f_device = { .init = w83787f_init, .close = w83787f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -502,7 +501,7 @@ const device_t w83787f_ide_device = { .init = w83787f_init, .close = w83787f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -516,7 +515,7 @@ const device_t w83787f_ide_en_device = { .init = w83787f_init, .close = w83787f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -530,7 +529,7 @@ const device_t w83787f_ide_sec_device = { .init = w83787f_init, .close = w83787f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_w83877f.c b/src/sio/sio_w83877f.c index c9a437630..7c92d6e71 100644 --- a/src/sio/sio_w83877f.c +++ b/src/sio/sio_w83877f.c @@ -168,7 +168,7 @@ w83877f_lpt_handler(w83877f_t *dev) lpt1_remove(); if (!(dev->regs[4] & 0x80) && (dev->regs[0x23] & 0xc0)) - lpt1_init(make_port(dev, 0x23)); + lpt1_setup(make_port(dev, 0x23)); lpt_irq = 0xff; @@ -444,8 +444,7 @@ w83877f_close(void *priv) static void * w83877f_init(const device_t *info) { - w83877f_t *dev = (w83877f_t *) malloc(sizeof(w83877f_t)); - memset(dev, 0, sizeof(w83877f_t)); + w83877f_t *dev = (w83877f_t *) calloc(1, sizeof(w83877f_t)); dev->fdc = device_add(&fdc_at_winbond_device); @@ -467,7 +466,7 @@ const device_t w83877f_device = { .init = w83877f_init, .close = w83877f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -481,7 +480,7 @@ const device_t w83877f_president_device = { .init = w83877f_init, .close = w83877f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -495,7 +494,7 @@ const device_t w83877tf_device = { .init = w83877f_init, .close = w83877f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -509,7 +508,7 @@ const device_t w83877tf_acorp_device = { .init = w83877f_init, .close = w83877f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sio/sio_w83977f.c b/src/sio/sio_w83977f.c index 063f0ca69..fd177bc19 100644 --- a/src/sio/sio_w83977f.c +++ b/src/sio/sio_w83977f.c @@ -112,14 +112,14 @@ w83977f_lpt_handler(w83977f_t *dev) lpt2_remove(); if ((dev->dev_regs[1][0x00] & 0x01) && (dev->regs[0x22] & 0x08) && (io_base >= 0x100) && (io_base <= io_mask)) - lpt2_init(io_base); + lpt2_setup(io_base); lpt2_irq(dev->dev_regs[1][0x40] & 0x0f); } else { lpt1_remove(); if ((dev->dev_regs[1][0x00] & 0x01) && (dev->regs[0x22] & 0x08) && (io_base >= 0x100) && (io_base <= io_mask)) - lpt1_init(io_base); + lpt1_setup(io_base); lpt1_irq(dev->dev_regs[1][0x40] & 0x0f); } @@ -593,8 +593,7 @@ w83977f_close(void *priv) static void * w83977f_init(const device_t *info) { - w83977f_t *dev = (w83977f_t *) malloc(sizeof(w83977f_t)); - memset(dev, 0, sizeof(w83977f_t)); + w83977f_t *dev = (w83977f_t *) calloc(1, sizeof(w83977f_t)); dev->type = info->local & 0x0f; dev->hefras = info->local & 0x40; @@ -624,7 +623,7 @@ const device_t w83977f_device = { .init = w83977f_init, .close = w83977f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -638,7 +637,7 @@ const device_t w83977f_370_device = { .init = w83977f_init, .close = w83977f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -652,7 +651,7 @@ const device_t w83977tf_device = { .init = w83977f_init, .close = w83977f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -666,7 +665,7 @@ const device_t w83977ef_device = { .init = w83977f_init, .close = w83977f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -680,7 +679,7 @@ const device_t w83977ef_370_device = { .init = w83977f_init, .close = w83977f_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/sound/CMakeLists.txt b/src/sound/CMakeLists.txt index a381051ba..66a0ee4e3 100644 --- a/src/sound/CMakeLists.txt +++ b/src/sound/CMakeLists.txt @@ -41,6 +41,7 @@ add_library(snd OBJECT snd_sb.c snd_sb_dsp.c snd_emu8k.c + snd_mmb.c snd_mpu401.c snd_pas16.c snd_sn76489.c @@ -48,12 +49,28 @@ add_library(snd OBJECT snd_wss.c snd_ym7128.c snd_optimc.c - esfmu/esfm.c - esfmu/esfm_registers.c snd_opl_esfm.c ) -if(OPENAL) +# TODO: Should platform-specific audio driver be here? +if(AUDIO4) + target_sources(snd PRIVATE audio4.c) +elseif(SNDIO) + target_sources(snd PRIVATE sndio.c) + find_package(PkgConfig REQUIRED) + + pkg_check_modules(SNDIO IMPORTED_TARGET sndio) + if(SNDIO_FOUND) + target_link_libraries(86Box PkgConfig::SNDIO) + else() + find_path(SNDIO_INCLUDE_DIR NAMES "sndio.h") + find_library(SNDIO_LIBRARY sndio) + + target_link_libraries(86Box ${SNDIO_LIBRARY}) + endif() + + include_directories(${SNDIO_INCLUDE_DIRS}) +elseif(OPENAL) if(VCPKG_TOOLCHAIN) find_package(OpenAL CONFIG REQUIRED) elseif(MINGW) @@ -159,20 +176,22 @@ if(MUNT) endif() endif() +add_subdirectory(ayumi) +target_link_libraries(86Box ayumi) + +add_subdirectory(esfmu) +target_link_libraries(86Box esfmu) + add_subdirectory(ymfm) target_link_libraries(86Box ymfm) -if(GUSMAX) - target_compile_definitions(snd PRIVATE USE_GUSMAX) -endif() - if(OPL4ML) target_compile_definitions(snd PRIVATE USE_OPL4ML) target_sources(snd PRIVATE midi_opl4.c midi_opl4_yrw801.c) endif() -find_package(PkgConfig ) -pkg_check_modules(SERIALPORT libserialport) +find_package(PkgConfig) +pkg_check_modules(SERIALPORT libserialport) if(SERIALPORT_FOUND OR DEFINED LIBSERIALPORT_ROOT) add_compile_definitions(USE_LIBSERIALPORT=1) diff --git a/src/sound/audio4.c b/src/sound/audio4.c new file mode 100644 index 000000000..4e74d2c0c --- /dev/null +++ b/src/sound/audio4.c @@ -0,0 +1,161 @@ +/* + * 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. + * + * Interface to audio(4) for NetBSD/OpenBSD. + * + * + * Authors: Nishi + * + * Copyright 2025 Nishi. + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include <86box/86box.h> +#include <86box/sound.h> +#include <86box/plat_unused.h> + +#if defined(OpenBSD) && OpenBSD >= 201709 +#define USE_NEW_API +#endif + +#define I_NORMAL 0 +#define I_MUSIC 1 +#define I_WT 2 +#define I_CD 3 +#define I_MIDI 4 + +static int audio[5] = {-1, -1, -1, -1, -1}; +#ifdef USE_NEW_API +static struct audio_swpar info[5]; +#else +static audio_info_t info[5]; +#endif +static int freqs[5] = {SOUND_FREQ, MUSIC_FREQ, WT_FREQ, CD_FREQ, 0}; + +void closeal(void){ + int i; + for(i = 0; i < sizeof(audio) / sizeof(audio[0]); i++){ + if(audio[i] != -1){ + close(audio[i]); + } + audio[i] = -1; + } +} + +void inital(void){ + int i; + for(i = 0; i < sizeof(audio) / sizeof(audio[0]); i++){ + audio[i] = open("/dev/audio", O_WRONLY); + if(audio[i] == -1) audio[i] = open("/dev/audio0", O_WRONLY); + if(audio[i] != -1){ +#ifdef USE_NEW_API + AUDIO_INITPAR(&info[i]); + ioctl(audio[i], AUDIO_GETPAR, &info[i]); + info[i].sig = 1; + info[i].bits = 16; + info[i].pchan = 2; + info[i].bps = 2; + ioctl(audio[i], AUDIO_SETPAR, &info[i]); +#else + AUDIO_INITINFO(&info[i]); +#if defined(__NetBSD__) && (__NetBSD_Version__ >= 900000000) + ioctl(audio[i], AUDIO_GETFORMAT, &info[i]); +#else + ioctl(audio[i], AUDIO_GETINFO, &info[i]); +#endif + info[i].play.channels = 2; + info[i].play.precision = 16; + info[i].play.encoding = AUDIO_ENCODING_SLINEAR; + info[i].hiwat = 5; + info[i].lowat = 3; + ioctl(audio[i], AUDIO_SETINFO, &info[i]); +#endif + } + } +} + +void givealbuffer_common(const void *buf, const uint8_t src, const int size){ + const int freq = freqs[src]; + int16_t* output; + int output_size; + int16_t* conv; + int conv_size; + int i; + double gain; + int target_rate; + if(audio[src] == -1) return; + + gain = sound_muted ? 0.0 : pow(10.0, (double) sound_gain / 20.0); + + if(sound_is_float){ + float* input = (float*)buf; + conv_size = sizeof(int16_t) * size; + conv = malloc(conv_size); + for(i = 0; i < conv_size / sizeof(int16_t); i++){ + conv[i] = 32767 * input[i]; + } + }else{ + conv_size = size * sizeof(int16_t); + conv = malloc(conv_size); + memcpy(conv, buf, conv_size); + } + +#ifdef USE_NEW_API + target_rate = info[src].rate; +#else + target_rate = info[src].play.sample_rate; +#endif + + output_size = (double)conv_size * target_rate / freq; + output_size -= output_size % 4; + output = malloc(output_size); + + for(i = 0; i < output_size / sizeof(int16_t) / 2; i++){ + int ind = i * freq / target_rate * 2; + output[i * 2 + 0] = conv[ind + 0] * gain; + output[i * 2 + 1] = conv[ind + 1] * gain; + } + + write(audio[src], output, output_size); + + free(conv); + free(output); +} + +void givealbuffer(const void *buf){ + givealbuffer_common(buf, I_NORMAL, SOUNDBUFLEN << 1); +} + +void givealbuffer_music(const void *buf){ + givealbuffer_common(buf, I_MUSIC, MUSICBUFLEN << 1); +} + +void givealbuffer_wt(const void *buf){ + givealbuffer_common(buf, I_WT, WTBUFLEN << 1); +} + +void givealbuffer_cd(const void *buf){ + givealbuffer_common(buf, I_CD, CD_BUFLEN << 1); +} +void givealbuffer_midi(const void *buf, const uint32_t size){ + givealbuffer_common(buf, I_MIDI, (int) size); +} + +void al_set_midi(const int freq, UNUSED(const int buf_size)){ + freqs[I_MIDI] = freq; +} diff --git a/src/sound/ayumi/CMakeLists.txt b/src/sound/ayumi/CMakeLists.txt new file mode 100644 index 000000000..f3e4b18c7 --- /dev/null +++ b/src/sound/ayumi/CMakeLists.txt @@ -0,0 +1,14 @@ +# +# 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. +# + +add_library(ayumi STATIC + ayumi.c +) diff --git a/src/sound/ayumi/LICENSE b/src/sound/ayumi/LICENSE new file mode 100644 index 000000000..25371edc6 --- /dev/null +++ b/src/sound/ayumi/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) Peter Sovietov, http://sovietov.com + +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. \ No newline at end of file diff --git a/src/sound/ayumi/ayumi.c b/src/sound/ayumi/ayumi.c new file mode 100644 index 000000000..861b0fd45 --- /dev/null +++ b/src/sound/ayumi/ayumi.c @@ -0,0 +1,338 @@ +/* Author: Peter Sovietov */ + +#include +#include +#include "ayumi.h" + +static const double AY_dac_table[] = { + 0.0, 0.0, + 0.00999465934234, 0.00999465934234, + 0.0144502937362, 0.0144502937362, + 0.0210574502174, 0.0210574502174, + 0.0307011520562, 0.0307011520562, + 0.0455481803616, 0.0455481803616, + 0.0644998855573, 0.0644998855573, + 0.107362478065, 0.107362478065, + 0.126588845655, 0.126588845655, + 0.20498970016, 0.20498970016, + 0.292210269322, 0.292210269322, + 0.372838941024, 0.372838941024, + 0.492530708782, 0.492530708782, + 0.635324635691, 0.635324635691, + 0.805584802014, 0.805584802014, + 1.0, 1.0 +}; + +static const double YM_dac_table[] = { + 0.0, 0.0, + 0.00465400167849, 0.00772106507973, + 0.0109559777218, 0.0139620050355, + 0.0169985503929, 0.0200198367285, + 0.024368657969, 0.029694056611, + 0.0350652323186, 0.0403906309606, + 0.0485389486534, 0.0583352407111, + 0.0680552376593, 0.0777752346075, + 0.0925154497597, 0.111085679408, + 0.129747463188, 0.148485542077, + 0.17666895552, 0.211551079576, + 0.246387426566, 0.281101701381, + 0.333730067903, 0.400427252613, + 0.467383840696, 0.53443198291, + 0.635172045472, 0.75800717174, + 0.879926756695, 1.0 +}; + +static void reset_segment(struct ayumi* ay); + +static int update_tone(struct ayumi* ay, int index) { + struct tone_channel* ch = &ay->channels[index]; + ch->tone_counter += 1; + if (ch->tone_counter >= ch->tone_period) { + ch->tone_counter = 0; + ch->tone ^= 1; + } + return ch->tone; +} + +static int update_noise(struct ayumi* ay) { + int bit0x3; + ay->noise_counter += 1; + if (ay->noise_counter >= (ay->noise_period << 1)) { + ay->noise_counter = 0; + bit0x3 = ((ay->noise ^ (ay->noise >> 3)) & 1); + ay->noise = (ay->noise >> 1) | (bit0x3 << 16); + } + return ay->noise & 1; +} + +static void slide_up(struct ayumi* ay) { + ay->envelope += 1; + if (ay->envelope > 31) { + ay->envelope_segment ^= 1; + reset_segment(ay); + } +} + +static void slide_down(struct ayumi* ay) { + ay->envelope -= 1; + if (ay->envelope < 0) { + ay->envelope_segment ^= 1; + reset_segment(ay); + } +} + +static void hold_top(struct ayumi* ay) { + (void) ay; +} + +static void hold_bottom(struct ayumi* ay) { + (void) ay; +} + +static void (* const Envelopes[][2])(struct ayumi*) = { + {slide_down, hold_bottom}, + {slide_down, hold_bottom}, + {slide_down, hold_bottom}, + {slide_down, hold_bottom}, + {slide_up, hold_bottom}, + {slide_up, hold_bottom}, + {slide_up, hold_bottom}, + {slide_up, hold_bottom}, + {slide_down, slide_down}, + {slide_down, hold_bottom}, + {slide_down, slide_up}, + {slide_down, hold_top}, + {slide_up, slide_up}, + {slide_up, hold_top}, + {slide_up, slide_down}, + {slide_up, hold_bottom} +}; + +static void reset_segment(struct ayumi* ay) { + if (Envelopes[ay->envelope_shape][ay->envelope_segment] == slide_down + || Envelopes[ay->envelope_shape][ay->envelope_segment] == hold_top) { + ay->envelope = 31; + return; + } + ay->envelope = 0; +} + +int update_envelope(struct ayumi* ay) { + ay->envelope_counter += 1; + if (ay->envelope_counter >= ay->envelope_period) { + ay->envelope_counter = 0; + Envelopes[ay->envelope_shape][ay->envelope_segment](ay); + } + return ay->envelope; +} + +static void update_mixer(struct ayumi* ay) { + int i; + int out; + int noise = update_noise(ay); + int envelope = update_envelope(ay); + ay->left = 0; + ay->right = 0; + for (i = 0; i < TONE_CHANNELS; i += 1) { + out = (update_tone(ay, i) | ay->channels[i].t_off) & (noise | ay->channels[i].n_off); + out *= ay->channels[i].e_on ? envelope : ay->channels[i].volume * 2 + 1; + ay->left += ay->dac_table[out] * ay->channels[i].pan_left; + ay->right += ay->dac_table[out] * ay->channels[i].pan_right; + } +} + +int ayumi_configure(struct ayumi* ay, int is_ym, double clock_rate, int sr) { + int i; + memset(ay, 0, sizeof(struct ayumi)); + ay->step = clock_rate / (sr * 8 * DECIMATE_FACTOR); + ay->dac_table = is_ym ? YM_dac_table : AY_dac_table; + ay->noise = 1; + ayumi_set_envelope(ay, 1); + for (i = 0; i < TONE_CHANNELS; i += 1) { + ayumi_set_tone(ay, i, 1); + } + return ay->step < 1; +} + +void ayumi_set_pan(struct ayumi* ay, int index, double pan, int is_eqp) { + if (is_eqp) { + ay->channels[index].pan_left = sqrt(1 - pan); + ay->channels[index].pan_right = sqrt(pan); + } else { + ay->channels[index].pan_left = 1 - pan; + ay->channels[index].pan_right = pan; + } +} + +void ayumi_set_tone(struct ayumi* ay, int index, int period) { + period &= 0xfff; + ay->channels[index].tone_period = (period == 0) | period; +} + +void ayumi_set_noise(struct ayumi* ay, int period) { + period &= 0x1f; + ay->noise_period = (period == 0) | period; +} + +void ayumi_set_mixer(struct ayumi* ay, int index, int t_off, int n_off, int e_on) { + ay->channels[index].t_off = t_off & 1; + ay->channels[index].n_off = n_off & 1; + ay->channels[index].e_on = e_on; +} + +void ayumi_set_volume(struct ayumi* ay, int index, int volume) { + ay->channels[index].volume = volume & 0xf; +} + +void ayumi_set_envelope(struct ayumi* ay, int period) { + period &= 0xffff; + ay->envelope_period = (period == 0) | period; +} + +void ayumi_set_envelope_shape(struct ayumi* ay, int shape) { + ay->envelope_shape = shape & 0xf; + ay->envelope_counter = 0; + ay->envelope_segment = 0; + reset_segment(ay); +} + +static double decimate(double* x) { + double y = -0.0000046183113992051936 * (x[1] + x[191]) + + -0.00001117761640887225 * (x[2] + x[190]) + + -0.000018610264502005432 * (x[3] + x[189]) + + -0.000025134586135631012 * (x[4] + x[188]) + + -0.000028494281690666197 * (x[5] + x[187]) + + -0.000026396828793275159 * (x[6] + x[186]) + + -0.000017094212558802156 * (x[7] + x[185]) + + 0.000023798193576966866 * (x[9] + x[183]) + + 0.000051281160242202183 * (x[10] + x[182]) + + 0.00007762197826243427 * (x[11] + x[181]) + + 0.000096759426664120416 * (x[12] + x[180]) + + 0.00010240229300393402 * (x[13] + x[179]) + + 0.000089344614218077106 * (x[14] + x[178]) + + 0.000054875700118949183 * (x[15] + x[177]) + + -0.000069839082210680165 * (x[17] + x[175]) + + -0.0001447966132360757 * (x[18] + x[174]) + + -0.00021158452917708308 * (x[19] + x[173]) + + -0.00025535069106550544 * (x[20] + x[172]) + + -0.00026228714374322104 * (x[21] + x[171]) + + -0.00022258805927027799 * (x[22] + x[170]) + + -0.00013323230495695704 * (x[23] + x[169]) + + 0.00016182578767055206 * (x[25] + x[167]) + + 0.00032846175385096581 * (x[26] + x[166]) + + 0.00047045611576184863 * (x[27] + x[165]) + + 0.00055713851457530944 * (x[28] + x[164]) + + 0.00056212565121518726 * (x[29] + x[163]) + + 0.00046901918553962478 * (x[30] + x[162]) + + 0.00027624866838952986 * (x[31] + x[161]) + + -0.00032564179486838622 * (x[33] + x[159]) + + -0.00065182310286710388 * (x[34] + x[158]) + + -0.00092127787309319298 * (x[35] + x[157]) + + -0.0010772534348943575 * (x[36] + x[156]) + + -0.0010737727700273478 * (x[37] + x[155]) + + -0.00088556645390392634 * (x[38] + x[154]) + + -0.00051581896090765534 * (x[39] + x[153]) + + 0.00059548767193795277 * (x[41] + x[151]) + + 0.0011803558710661009 * (x[42] + x[150]) + + 0.0016527320270369871 * (x[43] + x[149]) + + 0.0019152679330965555 * (x[44] + x[148]) + + 0.0018927324805381538 * (x[45] + x[147]) + + 0.0015481870327877937 * (x[46] + x[146]) + + 0.00089470695834941306 * (x[47] + x[145]) + + -0.0010178225878206125 * (x[49] + x[143]) + + -0.0020037400552054292 * (x[50] + x[142]) + + -0.0027874356824117317 * (x[51] + x[141]) + + -0.003210329988021943 * (x[52] + x[140]) + + -0.0031540624117984395 * (x[53] + x[139]) + + -0.0025657163651900345 * (x[54] + x[138]) + + -0.0014750752642111449 * (x[55] + x[137]) + + 0.0016624165446378462 * (x[57] + x[135]) + + 0.0032591192839069179 * (x[58] + x[134]) + + 0.0045165685815867747 * (x[59] + x[133]) + + 0.0051838984346123896 * (x[60] + x[132]) + + 0.0050774264697459933 * (x[61] + x[131]) + + 0.0041192521414141585 * (x[62] + x[130]) + + 0.0023628575417966491 * (x[63] + x[129]) + + -0.0026543507866759182 * (x[65] + x[127]) + + -0.0051990251084333425 * (x[66] + x[126]) + + -0.0072020238234656924 * (x[67] + x[125]) + + -0.0082672928192007358 * (x[68] + x[124]) + + -0.0081033739572956287 * (x[69] + x[123]) + + -0.006583111539570221 * (x[70] + x[122]) + + -0.0037839040415292386 * (x[71] + x[121]) + + 0.0042781252851152507 * (x[73] + x[119]) + + 0.0084176358598320178 * (x[74] + x[118]) + + 0.01172566057463055 * (x[75] + x[117]) + + 0.013550476647788672 * (x[76] + x[116]) + + 0.013388189369997496 * (x[77] + x[115]) + + 0.010979501242341259 * (x[78] + x[114]) + + 0.006381274941685413 * (x[79] + x[113]) + + -0.007421229604153888 * (x[81] + x[111]) + + -0.01486456304340213 * (x[82] + x[110]) + + -0.021143584622178104 * (x[83] + x[109]) + + -0.02504275058758609 * (x[84] + x[108]) + + -0.025473530942547201 * (x[85] + x[107]) + + -0.021627310017882196 * (x[86] + x[106]) + + -0.013104323383225543 * (x[87] + x[105]) + + 0.017065133989980476 * (x[89] + x[103]) + + 0.036978919264451952 * (x[90] + x[102]) + + 0.05823318062093958 * (x[91] + x[101]) + + 0.079072012081405949 * (x[92] + x[100]) + + 0.097675998716952317 * (x[93] + x[99]) + + 0.11236045936950932 * (x[94] + x[98]) + + 0.12176343577287731 * (x[95] + x[97]) + + 0.125 * x[96]; + memcpy(&x[FIR_SIZE - DECIMATE_FACTOR], x, DECIMATE_FACTOR * sizeof(double)); + return y; +} + +void ayumi_process(struct ayumi* ay) { + int i; + double y1; + double* c_left = ay->interpolator_left.c; + double* y_left = ay->interpolator_left.y; + double* c_right = ay->interpolator_right.c; + double* y_right = ay->interpolator_right.y; + double* fir_left = &ay->fir_left[FIR_SIZE - ay->fir_index * DECIMATE_FACTOR]; + double* fir_right = &ay->fir_right[FIR_SIZE - ay->fir_index * DECIMATE_FACTOR]; + ay->fir_index = (ay->fir_index + 1) % (FIR_SIZE / DECIMATE_FACTOR - 1); + for (i = DECIMATE_FACTOR - 1; i >= 0; i -= 1) { + ay->x += ay->step; + if (ay->x >= 1) { + ay->x -= 1; + y_left[0] = y_left[1]; + y_left[1] = y_left[2]; + y_left[2] = y_left[3]; + y_right[0] = y_right[1]; + y_right[1] = y_right[2]; + y_right[2] = y_right[3]; + update_mixer(ay); + y_left[3] = ay->left; + y_right[3] = ay->right; + y1 = y_left[2] - y_left[0]; + c_left[0] = 0.5 * y_left[1] + 0.25 * (y_left[0] + y_left[2]); + c_left[1] = 0.5 * y1; + c_left[2] = 0.25 * (y_left[3] - y_left[1] - y1); + y1 = y_right[2] - y_right[0]; + c_right[0] = 0.5 * y_right[1] + 0.25 * (y_right[0] + y_right[2]); + c_right[1] = 0.5 * y1; + c_right[2] = 0.25 * (y_right[3] - y_right[1] - y1); + } + fir_left[i] = (c_left[2] * ay->x + c_left[1]) * ay->x + c_left[0]; + fir_right[i] = (c_right[2] * ay->x + c_right[1]) * ay->x + c_right[0]; + } + ay->left = decimate(fir_left); + ay->right = decimate(fir_right); +} + +static double dc_filter(struct dc_filter* dc, int index, double x) { + dc->sum += -dc->delay[index] + x; + dc->delay[index] = x; + return x - dc->sum / DC_FILTER_SIZE; +} + +void ayumi_remove_dc(struct ayumi* ay) { + ay->left = dc_filter(&ay->dc_left, ay->dc_index, ay->left); + ay->right = dc_filter(&ay->dc_right, ay->dc_index, ay->right); + ay->dc_index = (ay->dc_index + 1) & (DC_FILTER_SIZE - 1); +} diff --git a/src/sound/ayumi/ayumi.h b/src/sound/ayumi/ayumi.h new file mode 100644 index 000000000..f15939514 --- /dev/null +++ b/src/sound/ayumi/ayumi.h @@ -0,0 +1,71 @@ +/* Author: Peter Sovietov */ + +#ifndef AYUMI_H +#define AYUMI_H + +enum { + TONE_CHANNELS = 3, + DECIMATE_FACTOR = 8, + FIR_SIZE = 192, + DC_FILTER_SIZE = 1024 +}; + +struct tone_channel { + int tone_period; + int tone_counter; + int tone; + int t_off; + int n_off; + int e_on; + int volume; + double pan_left; + double pan_right; +}; + +struct interpolator { + double c[4]; + double y[4]; +}; + +struct dc_filter { + double sum; + double delay[DC_FILTER_SIZE]; +}; + +struct ayumi { + struct tone_channel channels[TONE_CHANNELS]; + int noise_period; + int noise_counter; + int noise; + int envelope_counter; + int envelope_period; + int envelope_shape; + int envelope_segment; + int envelope; + const double* dac_table; + double step; + double x; + struct interpolator interpolator_left; + struct interpolator interpolator_right; + double fir_left[FIR_SIZE * 2]; + double fir_right[FIR_SIZE * 2]; + int fir_index; + struct dc_filter dc_left; + struct dc_filter dc_right; + int dc_index; + double left; + double right; +}; + +int ayumi_configure(struct ayumi* ay, int is_ym, double clock_rate, int sr); +void ayumi_set_pan(struct ayumi* ay, int index, double pan, int is_eqp); +void ayumi_set_tone(struct ayumi* ay, int index, int period); +void ayumi_set_noise(struct ayumi* ay, int period); +void ayumi_set_mixer(struct ayumi* ay, int index, int t_off, int n_off, int e_on); +void ayumi_set_volume(struct ayumi* ay, int index, int volume); +void ayumi_set_envelope(struct ayumi* ay, int period); +void ayumi_set_envelope_shape(struct ayumi* ay, int shape); +void ayumi_process(struct ayumi* ay); +void ayumi_remove_dc(struct ayumi* ay); + +#endif diff --git a/src/sound/esfmu/CMakeLists.txt b/src/sound/esfmu/CMakeLists.txt new file mode 100644 index 000000000..2505038f1 --- /dev/null +++ b/src/sound/esfmu/CMakeLists.txt @@ -0,0 +1,15 @@ +# +# 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. +# + +add_library(esfmu STATIC + esfm.c + esfm_registers.c +) diff --git a/src/sound/midi.c b/src/sound/midi.c index 78794ef24..9f83e88dc 100644 --- a/src/sound/midi.c +++ b/src/sound/midi.c @@ -71,7 +71,7 @@ typedef struct const device_t *device; } MIDI_OUT_DEVICE, MIDI_IN_DEVICE; -static const MIDI_OUT_DEVICE devices[] = { +static const MIDI_OUT_DEVICE midi_out_devices[] = { // clang-format off { &device_none }, #ifdef USE_FLUIDSYNTH @@ -106,8 +106,8 @@ static const MIDI_IN_DEVICE midi_in_devices[] = { int midi_out_device_available(int card) { - if (devices[card].device) - return device_available(devices[card].device); + if (midi_out_devices[card].device) + return device_available(midi_out_devices[card].device); return 1; } @@ -115,21 +115,21 @@ midi_out_device_available(int card) const device_t * midi_out_device_getdevice(int card) { - return devices[card].device; + return midi_out_devices[card].device; } int midi_out_device_has_config(int card) { - if (!devices[card].device) + if (!midi_out_devices[card].device) return 0; - return devices[card].device->config ? 1 : 0; + return midi_out_devices[card].device->config ? 1 : 0; } const char * midi_out_device_get_internal_name(int card) { - return device_get_internal_name(devices[card].device); + return device_get_internal_name(midi_out_devices[card].device); } int @@ -137,8 +137,8 @@ midi_out_device_get_from_internal_name(char *s) { int c = 0; - while (devices[c].device != NULL) { - if (!strcmp(devices[c].device->internal_name, s)) + while (midi_out_devices[c].device != NULL) { + if (!strcmp(midi_out_devices[c].device->internal_name, s)) return c; c++; } @@ -149,16 +149,15 @@ midi_out_device_get_from_internal_name(char *s) void midi_out_device_init(void) { - if ((midi_output_device_current > 0) && devices[midi_output_device_current].device) - device_add(devices[midi_output_device_current].device); + if ((midi_output_device_current > 0) && midi_out_devices[midi_output_device_current].device) + device_add(midi_out_devices[midi_output_device_current].device); midi_output_device_last = midi_output_device_current; } void midi_out_init(midi_device_t *device) { - midi_out = (midi_t *) malloc(sizeof(midi_t)); - memset(midi_out, 0, sizeof(midi_t)); + midi_out = (midi_t *) calloc(1, sizeof(midi_t)); midi_out->m_out_device = device; } @@ -166,8 +165,7 @@ midi_out_init(midi_device_t *device) void midi_in_init(midi_device_t *device, midi_t **mididev) { - *mididev = (midi_t *) malloc(sizeof(midi_t)); - memset(*mididev, 0, sizeof(midi_t)); + *mididev = (midi_t *) calloc(1, sizeof(midi_t)); (*mididev)->m_in_device = device; } @@ -394,8 +392,7 @@ midi_in_handler(int set, void (*msg)(void *priv, uint8_t *msg, uint32_t len), in if ((mih_first != NULL) && (mih_last == NULL)) fatal("First MIDI IN handler present with no last MIDI IN handler\n"); - temp = (midi_in_handler_t *) malloc(sizeof(midi_in_handler_t)); - memset(temp, 0, sizeof(midi_in_handler_t)); + temp = (midi_in_handler_t *) calloc(1, sizeof(midi_in_handler_t)); temp->msg = msg; temp->sysex = sysex; temp->priv = priv; diff --git a/src/sound/midi_fluidsynth.c b/src/sound/midi_fluidsynth.c index ccedb8c41..1afefd905 100644 --- a/src/sound/midi_fluidsynth.c +++ b/src/sound/midi_fluidsynth.c @@ -161,6 +161,7 @@ fluidsynth_init(UNUSED(const device_t *info)) fluid_settings_setnum(data->settings, "synth.sample-rate", 44100); fluid_settings_setnum(data->settings, "synth.gain", device_get_config_int("output_gain") / 100.0f); + fluid_settings_setint(data->settings, "synth.dynamic-sample-loading", device_get_config_int("dynamic_sample_loading")); data->synth = new_fluid_synth(data->settings); @@ -262,8 +263,7 @@ fluidsynth_init(UNUSED(const device_t *info)) al_set_midi(data->samplerate, data->buf_size); - dev = malloc(sizeof(midi_device_t)); - memset(dev, 0, sizeof(midi_device_t)); + dev = calloc(1, sizeof(midi_device_t)); dev->play_msg = fluidsynth_msg; dev->play_sysex = fluidsynth_sysex; @@ -320,164 +320,206 @@ fluidsynth_close(void *priv) static const device_config_t fluidsynth_config[] = { // clang-format off { - .name = "sound_font", - .description = "SoundFont", - .type = CONFIG_FNAME, - .default_string = "", - .file_filter = "SF2 Sound Fonts (*.sf2)|*.sf2" + .name = "sound_font", + .description = "SoundFont", + .type = CONFIG_FNAME, + .default_string = NULL, + .default_int = 0, + .file_filter = "SoundFont files (*.sf2 *.sf3)|*.sf2,*.sf3", + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "output_gain", - .description = "Output Gain", - .type = CONFIG_SPINNER, - .spinner = - { - .min = 0, + .name = "output_gain", + .description = "Output Gain", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 100, + .file_filter = NULL, + .spinner = { + .min = 0, .max = 100 }, - .default_int = 100 + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "chorus", - .description = "Chorus", - .type = CONFIG_BINARY, - .default_int = 1 + .name = "chorus", + .description = "Chorus", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "chorus_voices", - .description = "Chorus Voices", - .type = CONFIG_SPINNER, - .spinner = - { - .min = 0, + .name = "chorus_voices", + .description = "Chorus Voices", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 3, + .file_filter = NULL, + .spinner = { + .min = 0, .max = 99 }, - .default_int = 3 + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "chorus_level", - .description = "Chorus Level", - .type = CONFIG_SPINNER, - .spinner = - { - .min = 0, + .name = "chorus_level", + .description = "Chorus Level", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 20, + .file_filter = NULL, + .spinner = { + .min = 0, .max = 100 }, - .default_int = 20 + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "chorus_speed", - .description = "Chorus Speed", - .type = CONFIG_SPINNER, - .spinner = - { - .min = 10, + .name = "chorus_speed", + .description = "Chorus Speed", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 30, + .file_filter = NULL, + .spinner = { + .min = 10, .max = 500 }, - .default_int = 30 + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "chorus_depth", - .description = "Chorus Depth", - .type = CONFIG_SPINNER, - .spinner = - { - .min = 0, + .name = "chorus_depth", + .description = "Chorus Depth", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 80, + .file_filter = NULL, + .spinner = { + .min = 0, .max = 2560 }, - .default_int = 80 + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "chorus_waveform", - .description = "Chorus Waveform", - .type = CONFIG_SELECTION, - .selection = - { - { - .description = "Sine", - .value = 0 - }, - { - .description = "Triangle", - .value = 1 - } + .name = "chorus_waveform", + .description = "Chorus Waveform", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Sine", .value = 0 }, + { .description = "Triangle", .value = 1 }, + { .description = "" } }, - .default_int = 0 + .bios = { { 0 } } }, { - .name = "reverb", - .description = "Reverb", - .type = CONFIG_BINARY, - .default_int = 1 + .name = "reverb", + .description = "Reverb", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "reverb_room_size", - .description = "Reverb Room Size", - .type = CONFIG_SPINNER, - .spinner = - { - .min = 0, + .name = "reverb_room_size", + .description = "Reverb Room Size", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 20, + .file_filter = NULL, + .spinner = { + .min = 0, .max = 100 }, - .default_int = 20 + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "reverb_damping", - .description = "Reverb Damping", - .type = CONFIG_SPINNER, - .spinner = - { - .min = 0, + .name = "reverb_damping", + .description = "Reverb Damping", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { + .min = 0, .max = 100 }, - .default_int = 0 + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "reverb_width", - .description = "Reverb Width", - .type = CONFIG_SPINNER, - .spinner = - { - .min = 0, + .name = "reverb_width", + .description = "Reverb Width", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 5, + .file_filter = NULL, + .spinner = { + .min = 0, .max = 1000 }, - .default_int = 5 + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "reverb_level", - .description = "Reverb Level", - .type = CONFIG_SPINNER, - .spinner = - { - .min = 0, + .name = "reverb_level", + .description = "Reverb Level", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 90, + .file_filter = NULL, + .spinner = { + .min = 0, .max = 100 }, - .default_int = 90 + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "interpolation", - .description = "Interpolation Method", - .type = CONFIG_SELECTION, - .selection = - { - { - .description = "None", - .value = 0 - }, - { - .description = "Linear", - .value = 1 - }, - { - .description = "4th Order", - .value = 2 - }, - { - .description = "7th Order", - .value = 3 - } + .name = "interpolation", + .description = "Interpolation Method", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "None", .value = 0 }, + { .description = "Linear", .value = 1 }, + { .description = "4th Order", .value = 2 }, + { .description = "7th Order", .value = 3 }, + { .description = "" } }, - .default_int = 2 + .bios = { { 0 } } + }, + { + .name = "dynamic_sample_loading", + .description = "Dynamic Sample Loading", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -496,4 +538,3 @@ const device_t fluidsynth_device = { .force_redraw = NULL, .config = fluidsynth_config }; - diff --git a/src/sound/midi_mt32.c b/src/sound/midi_mt32.c index f95445540..67f1d26c8 100644 --- a/src/sound/midi_mt32.c +++ b/src/sound/midi_mt32.c @@ -298,8 +298,7 @@ mt32emu_init(char *control_rom, char *pcm_rom) al_set_midi(samplerate, buf_size); - dev = malloc(sizeof(midi_device_t)); - memset(dev, 0, sizeof(midi_device_t)); + dev = calloc(1, sizeof(midi_device_t)); dev->play_msg = mt32_msg; dev->play_sysex = mt32_sysex; @@ -378,42 +377,60 @@ mt32_close(void *priv) static const device_config_t mt32_config[] = { // clang-format off { - .name = "output_gain", - .description = "Output Gain", - .type = CONFIG_SPINNER, - .spinner = { + .name = "output_gain", + .description = "Output Gain", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 100, + .file_filter = NULL, + .spinner = { + .min = 0, + .max = 100 + }, + .selection = { { 0 } } + }, + { + .name = "reverb", + .description = "Reverb", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } } + }, + { + .name = "reverb_output_gain", + .description = "Reverb Output Gain", + .type = CONFIG_SPINNER, + .default_string = NULL, + .default_int = 100, + .file_filter = NULL, + .spinner = { .min = 0, .max = 100 }, - .default_int = 100 + .selection = { { 0 } } }, { - .name = "reverb", - .description = "Reverb", - .type = CONFIG_BINARY, - .default_int = 1 + .name = "reversed_stereo", + .description = "Reversed stereo", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } } }, { - .name = "reverb_output_gain", - .description = "Reverb Output Gain", - .type = CONFIG_SPINNER, - .spinner = { - .min = 0, - .max = 100 - }, - .default_int = 100 - }, - { - .name = "reversed_stereo", - .description = "Reversed stereo", - .type = CONFIG_BINARY, - .default_int = 0 - }, - { - .name = "nice_ramp", - .description = "Nice ramp", - .type = CONFIG_BINARY, - .default_int = 1 + .name = "nice_ramp", + .description = "Nice ramp", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on diff --git a/src/sound/midi_opl4.c b/src/sound/midi_opl4.c index cf99e092d..5ec15cc7c 100644 --- a/src/sound/midi_opl4.c +++ b/src/sound/midi_opl4.c @@ -557,7 +557,7 @@ program_change(uint8_t midi_channel, uint8_t program, opl4_midi_t *opl4_midi) } static void -opl4_midi_thread(void *arg) +opl4_midi_thread(UNUSED(void *arg)) { opl4_midi_t *opl4_midi = opl4_midi_cur; uint32_t i = 0; @@ -648,18 +648,18 @@ opl4_midi_msg(uint8_t *val) } void -opl4_midi_sysex(uint8_t *data, unsigned int len) +opl4_midi_sysex(UNUSED(uint8_t *data), UNUSED(unsigned int len)) { + // } void * -opl4_init(const device_t *info) +opl4_init(UNUSED(const device_t *info)) { midi_device_t *dev; extern void al_set_midi(int freq, int buf_size); - dev = malloc(sizeof(midi_device_t)); - memset(dev, 0, sizeof(midi_device_t)); + dev = calloc(1, sizeof(midi_device_t)); dev->play_msg = opl4_midi_msg; dev->play_sysex = opl4_midi_sysex; diff --git a/src/sound/midi_rtmidi.cpp b/src/sound/midi_rtmidi.cpp index e2458c9fe..11203c3f2 100644 --- a/src/sound/midi_rtmidi.cpp +++ b/src/sound/midi_rtmidi.cpp @@ -73,8 +73,7 @@ rtmidi_play_sysex(uint8_t *sysex, unsigned int len) void * 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)); + midi_device_t *dev = (midi_device_t *) calloc(1, sizeof(midi_device_t)); dev->play_msg = rtmidi_play_msg; dev->play_sysex = rtmidi_play_sysex; @@ -156,8 +155,7 @@ rtmidi_input_callback(UNUSED(double timeStamp), std::vector *mess void * 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)); + midi_device_t *dev = (midi_device_t *) calloc(1, sizeof(midi_device_t)); try { if (!midiin) @@ -233,11 +231,15 @@ rtmidi_in_get_dev_name(int num, char *s) static const device_config_t system_midi_config[] = { // clang-format off { - .name = "midi", - .description = "MIDI Output Device", - .type = CONFIG_MIDI_OUT, - .default_string = "", - .default_int = 0 + .name = "midi", + .description = "MIDI Output Device", + .type = CONFIG_MIDI_OUT, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -246,32 +248,48 @@ static const device_config_t system_midi_config[] = { static const device_config_t midi_input_config[] = { // clang-format off { - .name = "midi_input", - .description = "MIDI Input Device", - .type = CONFIG_MIDI_IN, - .default_string = "", - .default_int = 0 + .name = "midi_input", + .description = "MIDI Input Device", + .type = CONFIG_MIDI_IN, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "realtime", - .description = "MIDI Real time", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "realtime", + .description = "MIDI Real time", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "thruchan", - .description = "MIDI Thru", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "thruchan", + .description = "MIDI Thru", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "clockout", - .description = "MIDI Clockout", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "clockout", + .description = "MIDI Clockout", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on diff --git a/src/sound/openal.c b/src/sound/openal.c index a41199b23..90f626362 100644 --- a/src/sound/openal.c +++ b/src/sound/openal.c @@ -278,7 +278,7 @@ givealbuffer_common(const void *buf, const uint8_t src, const int size, const in alGetSourcei(source[src], AL_BUFFERS_PROCESSED, &processed); if (processed >= 1) { - const double gain = pow(10.0, (double) sound_gain / 20.0); + const double gain = sound_muted ? 0.0 : pow(10.0, (double) sound_gain / 20.0); alListenerf(AL_GAIN, (float) gain); alSourceUnqueueBuffers(source[src], 1, &buffer); diff --git a/src/sound/resid-fp/SID.cpp b/src/sound/resid-fp/SID.cpp index 5b5506bc3..4db69af0c 100644 --- a/src/sound/resid-fp/SID.cpp +++ b/src/sound/resid-fp/SID.cpp @@ -107,8 +107,10 @@ constexpr unsigned int OSC_DAC_BITS = 12; * On my 6581R4AR has 0x3A as the only value giving the same output level as 1.prg */ //@{ +#ifdef USE_RESID_UNUSED constexpr unsigned int OFFSET_6581 = 0x380; constexpr unsigned int OFFSET_8580 = 0x9c0; +#endif //@} /** diff --git a/src/sound/resid-fp/WaveformGenerator.cpp b/src/sound/resid-fp/WaveformGenerator.cpp index be0738bba..847560f2a 100644 --- a/src/sound/resid-fp/WaveformGenerator.cpp +++ b/src/sound/resid-fp/WaveformGenerator.cpp @@ -43,7 +43,9 @@ namespace reSIDfp constexpr unsigned int FLOATING_OUTPUT_TTL_6581R3 = 54000; constexpr unsigned int FLOATING_OUTPUT_FADE_6581R3 = 1400; // ~1s +#ifdef USE_RESID_UNUSED constexpr unsigned int FLOATING_OUTPUT_TTL_6581R4 = 1000000; +#endif // ~1s constexpr unsigned int FLOATING_OUTPUT_TTL_8580R5 = 800000; constexpr unsigned int FLOATING_OUTPUT_FADE_8580R5 = 50000; @@ -61,7 +63,9 @@ constexpr unsigned int FLOATING_OUTPUT_FADE_8580R5 = 50000; constexpr unsigned int SHIFT_REGISTER_RESET_6581R3 = 50000; constexpr unsigned int SHIFT_REGISTER_FADE_6581R3 = 15000; // ~2.15s +#ifdef USE_RESID_UNUSED constexpr unsigned int SHIFT_REGISTER_RESET_6581R4 = 2150000; +#endif // ~2.8s constexpr unsigned int SHIFT_REGISTER_RESET_8580R5 = 986000; constexpr unsigned int SHIFT_REGISTER_FADE_8580R5 = 314300; diff --git a/src/sound/resid-fp/siddefs-fp.h b/src/sound/resid-fp/siddefs-fp.h index 9411b1694..22e40f4fb 100644 --- a/src/sound/resid-fp/siddefs-fp.h +++ b/src/sound/resid-fp/siddefs-fp.h @@ -24,7 +24,11 @@ #define RESID_BRANCH_HINTS true // Compiler specifics. +#ifndef _MSC_VER #define HAVE_BUILTIN_EXPECT true +#else +#define HAVE_BUILTIN_EXPECT false +#endif // Branch prediction macros, lifted off the Linux kernel. #if RESID_BRANCH_HINTS && HAVE_BUILTIN_EXPECT diff --git a/src/sound/snd_ac97_codec.c b/src/sound/snd_ac97_codec.c index f6c01c4ea..1b28a8aab 100644 --- a/src/sound/snd_ac97_codec.c +++ b/src/sound/snd_ac97_codec.c @@ -68,7 +68,6 @@ static const struct { .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, .pcsr_mask = 0x7f, .vendor_regs = (const ac97_vendor_reg_t[]) {{0, 0x5a, 0x0301, 0x0000}, {0}} }, @@ -100,15 +99,18 @@ static const struct { { .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 = &w83971d_device, + .misc_flags = AC97_MASTER_6B | AC97_MONOOUT | AC97_MONOOUT_6B | AC97_PCBEEP | AC97_PHONE | AC97_VIDEO | AC97_AUXIN | AC97_MS | AC97_LPBK, + .reset_flags = (27 << AC97_3D_SHIFT), .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, .pcsr_mask = 0x3f } // clang-format on @@ -284,8 +286,9 @@ line_gain: case 0x22: /* 3D Control */ switch (ac97_codecs[dev->model].reset_flags >> AC97_3D_SHIFT) { - case 1: /* Analog Devices */ - case 6: /* Crystal */ + case 1: /* Analog Devices */ + case 6: /* Crystal */ + case 27: /* Winbond */ val &= 0x000f; break; @@ -577,8 +580,7 @@ ac97_codec_getrate(void *priv, uint8_t reg) static void * ac97_codec_init(const device_t *info) { - ac97_codec_t *dev = malloc(sizeof(ac97_codec_t)); - memset(dev, 0, sizeof(ac97_codec_t)); + ac97_codec_t *dev = calloc(1, sizeof(ac97_codec_t)); for (; dev->model < (sizeof(ac97_codecs) / sizeof(ac97_codecs[0])); dev->model++) { if (ac97_codecs[dev->model].device->local == info->local) @@ -765,6 +767,20 @@ const device_t tr28023_device = { .config = NULL }; +const device_t w83971d_device = { + .name = "Winbond W83971D", + .internal_name = "w83971d", + .flags = DEVICE_AC97, + .local = AC97_CODEC_W83971D, + .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 e3fa9d2e4..2d994b08f 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -24,6 +24,7 @@ #include <86box/86box.h> #include <86box/device.h> #include <86box/io.h> +#include <86box/dma.h> #include <86box/mem.h> #include <86box/pci.h> #include <86box/pic.h> @@ -31,10 +32,13 @@ #include <86box/sound.h> #include <86box/timer.h> #include <86box/plat_unused.h> +#include "cpu.h" typedef struct ac97_via_sgd_t { uint8_t id; uint8_t always_run; + uint8_t modem; + uint8_t pad; struct _ac97_via_ *dev; uint32_t entry_ptr; @@ -63,7 +67,7 @@ typedef struct _ac97_via_ { uint16_t audio_codec_base; uint16_t modem_sgd_base; uint16_t modem_codec_base; - uint8_t sgd_regs[256]; + uint8_t sgd_regs[2][256]; uint8_t pcm_enabled : 1; uint8_t fm_enabled : 1; uint8_t vsr_enabled : 1; @@ -78,7 +82,7 @@ typedef struct _ac97_via_ { int irq_pin; ac97_codec_t *codec[2][2]; - ac97_via_sgd_t sgd[6]; + ac97_via_sgd_t sgd[2][6]; int master_vol_l; int master_vol_r; @@ -105,7 +109,7 @@ ac97_via_log(const char *fmt, ...) #endif static void ac97_via_sgd_process(void *priv); -static void ac97_via_update_codec(ac97_via_t *dev); +static void ac97_via_update_codec(ac97_via_t *dev, int modem); static void ac97_via_speed_changed(void *priv); static void ac97_via_filter_cd_audio(int channel, double *buffer, void *priv); @@ -160,29 +164,29 @@ ac97_via_write_control(void *priv, uint8_t modem, uint8_t val) /* Start or stop PCM playback. */ i = (val & 0xf4) == 0xc4; if (i && !dev->pcm_enabled) - timer_advance_u64(&dev->sgd[0].poll_timer, dev->sgd[0].timer_latch); + timer_advance_u64(&dev->sgd[0][0].poll_timer, dev->sgd[0][0].timer_latch); dev->pcm_enabled = i; /* Start or stop FM playback. */ i = (val & 0xf2) == 0xc2; if (i && !dev->fm_enabled) - timer_advance_u64(&dev->sgd[2].poll_timer, dev->sgd[2].timer_latch); + timer_advance_u64(&dev->sgd[0][2].poll_timer, dev->sgd[0][2].timer_latch); dev->fm_enabled = i; /* Update primary audio codec state. */ if (dev->codec[0][0]) - ac97_via_update_codec(dev); + ac97_via_update_codec(dev, 0); } } static void -ac97_via_update_irqs(ac97_via_t *dev) +ac97_via_update_irqs(ac97_via_t *dev, int modem) { /* Check interrupt flags in all SGDs. */ for (uint8_t i = 0x00; i < ((sizeof(dev->sgd) / sizeof(dev->sgd[0])) << 4); i += 0x10) { /* Stop immediately if any flag is set. Doing it this way optimizes rising edges for the playback SGD (0 - first to be checked). */ - if (dev->sgd_regs[i] & (dev->sgd_regs[i | 0x2] & 0x03)) { + if (dev->sgd_regs[modem][i] & (dev->sgd_regs[modem][i | 0x2] & 0x03)) { pci_set_irq(dev->pci_slot, dev->irq_pin, &dev->irq_state); return; } @@ -192,15 +196,15 @@ ac97_via_update_irqs(ac97_via_t *dev) } static void -ac97_via_update_codec(ac97_via_t *dev) +ac97_via_update_codec(ac97_via_t *dev, int modem) { /* Get primary audio codec. */ - ac97_codec_t *codec = dev->codec[0][0]; + ac97_codec_t *codec = dev->codec[modem][0]; /* 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, 0x18, &dev->sgd[modem][0].vol_l, &dev->sgd[modem][0].vol_r); + ac97_codec_getattn(codec, 0x18, &dev->sgd[modem][2].vol_l, &dev->sgd[modem][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. */ @@ -211,9 +215,9 @@ uint8_t ac97_via_sgd_read(uint16_t addr, void *priv) { const ac97_via_t *dev = (ac97_via_t *) priv; -#ifdef ENABLE_AC97_VIA_LOG +// #ifdef ENABLE_AC97_VIA_LOG uint8_t modem = (addr & 0xff00) == dev->modem_sgd_base; -#endif +// #endif addr &= 0xff; uint8_t ret; @@ -221,83 +225,83 @@ ac97_via_sgd_read(uint16_t addr, void *priv) /* Process SGD channel registers. */ switch (addr & 0xf) { case 0x4: - ret = dev->sgd[addr >> 4].entry_ptr; + ret = dev->sgd[modem][addr >> 4].entry_ptr; break; case 0x5: - ret = dev->sgd[addr >> 4].entry_ptr >> 8; + ret = dev->sgd[modem][addr >> 4].entry_ptr >> 8; break; case 0x6: - ret = dev->sgd[addr >> 4].entry_ptr >> 16; + ret = dev->sgd[modem][addr >> 4].entry_ptr >> 16; break; case 0x7: - ret = dev->sgd[addr >> 4].entry_ptr >> 24; + ret = dev->sgd[modem][addr >> 4].entry_ptr >> 24; break; case 0xc: - ret = dev->sgd[addr >> 4].sample_count; + ret = dev->sgd[modem][addr >> 4].sample_count; break; case 0xd: - ret = dev->sgd[addr >> 4].sample_count >> 8; + ret = dev->sgd[modem][addr >> 4].sample_count >> 8; break; case 0xe: - ret = dev->sgd[addr >> 4].sample_count >> 16; + ret = dev->sgd[modem][addr >> 4].sample_count >> 16; break; default: - ret = dev->sgd_regs[addr]; + ret = dev->sgd_regs[modem][addr]; break; } } else { /* Process regular registers. */ switch (addr) { case 0x84: - ret = (dev->sgd_regs[0x00] & 0x01); - ret |= (dev->sgd_regs[0x10] & 0x01) << 1; - ret |= (dev->sgd_regs[0x20] & 0x01) << 2; + ret = (dev->sgd_regs[modem][0x00] & 0x01); + ret |= (dev->sgd_regs[modem][0x10] & 0x01) << 1; + ret |= (dev->sgd_regs[modem][0x20] & 0x01) << 2; - ret |= (dev->sgd_regs[0x00] & 0x02) << 3; - ret |= (dev->sgd_regs[0x10] & 0x02) << 4; - ret |= (dev->sgd_regs[0x20] & 0x02) << 5; + ret |= (dev->sgd_regs[modem][0x00] & 0x02) << 3; + ret |= (dev->sgd_regs[modem][0x10] & 0x02) << 4; + ret |= (dev->sgd_regs[modem][0x20] & 0x02) << 5; break; case 0x85: - ret = (dev->sgd_regs[0x00] & 0x04) >> 2; - ret |= (dev->sgd_regs[0x10] & 0x04) >> 1; - ret |= (dev->sgd_regs[0x20] & 0x04); + ret = (dev->sgd_regs[modem][0x00] & 0x04) >> 2; + ret |= (dev->sgd_regs[modem][0x10] & 0x04) >> 1; + ret |= (dev->sgd_regs[modem][0x20] & 0x04); - ret |= (dev->sgd_regs[0x00] & 0x80) >> 3; - ret |= (dev->sgd_regs[0x10] & 0x80) >> 2; - ret |= (dev->sgd_regs[0x20] & 0x80) >> 1; + ret |= (dev->sgd_regs[modem][0x00] & 0x80) >> 3; + ret |= (dev->sgd_regs[modem][0x10] & 0x80) >> 2; + ret |= (dev->sgd_regs[modem][0x20] & 0x80) >> 1; break; case 0x86: - ret = (dev->sgd_regs[0x40] & 0x01); - ret |= (dev->sgd_regs[0x50] & 0x01) << 1; + ret = (dev->sgd_regs[modem][0x40] & 0x01); + ret |= (dev->sgd_regs[modem][0x50] & 0x01) << 1; - ret |= (dev->sgd_regs[0x40] & 0x02) << 3; - ret |= (dev->sgd_regs[0x50] & 0x02) << 4; + ret |= (dev->sgd_regs[modem][0x40] & 0x02) << 3; + ret |= (dev->sgd_regs[modem][0x50] & 0x02) << 4; break; case 0x87: - ret = (dev->sgd_regs[0x40] & 0x04) >> 2; - ret |= (dev->sgd_regs[0x50] & 0x04) >> 1; + ret = (dev->sgd_regs[modem][0x40] & 0x04) >> 2; + ret |= (dev->sgd_regs[modem][0x50] & 0x04) >> 1; - ret |= (dev->sgd_regs[0x40] & 0x80) >> 3; - ret |= (dev->sgd_regs[0x50] & 0x80) >> 2; + ret |= (dev->sgd_regs[modem][0x40] & 0x80) >> 3; + ret |= (dev->sgd_regs[modem][0x50] & 0x80) >> 2; break; default: - ret = dev->sgd_regs[addr]; + ret = dev->sgd_regs[modem][addr]; break; } } - ac97_via_log("AC97 VIA %d: sgd_read(%02X) = %02X\n", modem, addr, ret); + ac97_via_log("[%04X:%08X] [%i] AC97 VIA %d: sgd_read(%02X) = %02X\n", CS, cpu_state.pc, msw & 1, modem, addr, ret); return ret; } @@ -311,7 +315,9 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) ac97_codec_t *codec; addr &= 0xff; - ac97_via_log("AC97 VIA %d: sgd_write(%02X, %02X)\n", modem, addr, val); + ac97_via_log("[%04X:%08X] [%i] AC97 VIA %d: sgd_write(%02X, %02X)\n", CS, cpu_state.pc, msw & 1, modem, addr, val); + + // if ((CS == 0x10000) && (cpu_state.pc == 0x000073d1)) /* Check function-specific read only registers. */ if ((addr >= (modem ? 0x00 : 0x40)) && (addr < (modem ? 0x40 : 0x60))) @@ -324,42 +330,42 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) switch (addr & 0xf) { case 0x0: /* Clear RWC status bits. */ - dev->sgd_regs[addr] &= ~(val & 0x07); + dev->sgd_regs[modem][addr] &= ~(val & 0x07); /* Update status interrupts. */ - ac97_via_update_irqs(dev); + ac97_via_update_irqs(dev, modem); return; case 0x1: /* Start SGD if requested. */ if (val & 0x80) { - if (dev->sgd_regs[addr & 0xf0] & 0x80) { + if (dev->sgd_regs[modem][addr & 0xf0] & 0x80) { /* Queue SGD trigger if already running. */ - dev->sgd_regs[addr & 0xf0] |= 0x08; + dev->sgd_regs[modem][addr & 0xf0] |= 0x08; } else { /* Start SGD immediately. */ - dev->sgd_regs[addr & 0xf0] = (dev->sgd_regs[addr & 0xf0] & ~0x47) | 0x80; + dev->sgd_regs[modem][addr & 0xf0] = (dev->sgd_regs[modem][addr & 0xf0] & ~0x47) | 0x80; /* Start at the specified entry pointer. */ - dev->sgd[addr >> 4].entry_ptr = *((uint32_t *) &dev->sgd_regs[(addr & 0xf0) | 0x4]) & 0xfffffffe; - dev->sgd[addr >> 4].restart = 2; + dev->sgd[modem][addr >> 4].entry_ptr = *((uint32_t *) &dev->sgd_regs[modem][(addr & 0xf0) | 0x4]) & 0xfffffffe; + dev->sgd[modem][addr >> 4].restart = 2; /* Start the actual SGD process. */ - ac97_via_sgd_process(&dev->sgd[addr >> 4]); + ac97_via_sgd_process(&dev->sgd[modem][addr >> 4]); } } /* Stop SGD if requested. */ if (val & 0x40) - dev->sgd_regs[addr & 0xf0] &= ~0x88; + dev->sgd_regs[modem][addr & 0xf0] &= ~0x88; val &= 0x08; /* (Un)pause SGD if requested. */ if (val & 0x08) - dev->sgd_regs[addr & 0xf0] |= 0x40; + dev->sgd_regs[modem][addr & 0xf0] |= 0x40; else - dev->sgd_regs[addr & 0xf0] &= ~0x40; + dev->sgd_regs[modem][addr & 0xf0] &= ~0x40; break; @@ -387,7 +393,7 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) case 0x82: /* Determine the selected codec. */ - i = !!(dev->sgd_regs[0x83] & 0x40); + i = !!(dev->sgd_regs[modem][0x83] & 0x40); codec = dev->codec[modem][i]; /* Keep value in register if this codec is not present. */ @@ -395,20 +401,20 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) /* Read from or write to codec. */ if (val & 0x80) { if (val & 1) { /* return 0x0000 on unaligned reads (real 686B behavior) */ - dev->sgd_regs[0x80] = dev->sgd_regs[0x81] = 0x00; + dev->sgd_regs[modem][0x80] = dev->sgd_regs[modem][0x81] = 0x00; } else { - *((uint16_t *) &dev->codec_shadow[modem].regs_codec[i][val & 0x7f]) = *((uint16_t *) &dev->sgd_regs[0x80]) = ac97_codec_readw(codec, val); + *((uint16_t *) &dev->codec_shadow[modem].regs_codec[i][val & 0x7f]) = *((uint16_t *) &dev->sgd_regs[modem][0x80]) = ac97_codec_readw(codec, val); } /* Flag data/status/index for this codec as valid. */ - dev->sgd_regs[0x83] |= 0x02 << (i << 1); + dev->sgd_regs[modem][0x83] |= 0x02 << (i << 1); } else if (!(val & 1)) { /* do nothing on unaligned writes */ ac97_codec_writew(codec, val, - *((uint16_t *) &dev->codec_shadow[modem].regs_codec[i][val & 0x7f]) = *((uint16_t *) &dev->sgd_regs[0x80])); + *((uint16_t *) &dev->codec_shadow[modem].regs_codec[i][val & 0x7f]) = *((uint16_t *) &dev->sgd_regs[modem][0x80])); /* Update primary audio codec state if that codec was written to. */ if (!modem && !i) { - ac97_via_update_codec(dev); + ac97_via_update_codec(dev, 0); /* Set up CD audio filter if CD volume was written to. Setting it up at init prevents CD audio from working on other cards, but @@ -424,9 +430,9 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) case 0x83: /* Clear RWC status bits. */ #if 0 /* race condition with Linux accessing a register and clearing status bits on the same dword write */ - val = (dev->sgd_regs[addr] & ~(val & 0x0a)) | (val & 0xc0); + val = ((dev->sgd_regs[modem][addr] & 0x3f) & ~(val & 0x0a)) | (val & 0xc0); #else - val = dev->sgd_regs[addr] | (val & 0xc0); + val = (dev->sgd_regs[modem][addr] & 0x3f) | (val & 0xc0); #endif break; @@ -435,7 +441,7 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) } } - dev->sgd_regs[addr] = val; + dev->sgd_regs[modem][addr] = val; } void @@ -479,6 +485,8 @@ ac97_via_codec_read(uint16_t addr, void *priv) ac97_via_log("AC97 VIA %d: codec_read(%02X) = %02X\n", modem, addr, ret); + ac97_via_log("[%04X:%08X] [%i] AC97 VIA %d: codec_read(%02X) = %02X\n", CS, cpu_state.pc, msw & 1, modem, addr, ret); + return ret; } @@ -489,6 +497,8 @@ ac97_via_codec_write(uint16_t addr, uint8_t val, void *priv) uint8_t modem = (addr & 0xff00) == dev->modem_codec_base; addr &= 0xff; + ac97_via_log("[%04X:%08X] [%i] AC97 VIA %d: codec_write(%02X, %02X)\n", CS, cpu_state.pc, msw & 1, modem, addr, val); + ac97_via_log("AC97 VIA %d: codec_write(%02X, %02X)\n", modem, addr, val); /* Unknown behavior, maybe it does write to the shadow registers? */ @@ -501,12 +511,12 @@ ac97_via_remap_audio_codec(void *priv, uint16_t new_io_base, uint8_t enable) ac97_via_t *dev = (ac97_via_t *) priv; if (dev->audio_codec_base) - io_removehandler(dev->audio_codec_base, 256, ac97_via_codec_read, NULL, NULL, ac97_via_codec_write, NULL, NULL, dev); + io_removehandler(dev->audio_codec_base, 4, ac97_via_codec_read, NULL, NULL, ac97_via_codec_write, NULL, NULL, dev); dev->audio_codec_base = new_io_base; if (dev->audio_codec_base && enable) - io_sethandler(dev->audio_codec_base, 256, ac97_via_codec_read, NULL, NULL, ac97_via_codec_write, NULL, NULL, dev); + io_sethandler(dev->audio_codec_base, 4, ac97_via_codec_read, NULL, NULL, ac97_via_codec_write, NULL, NULL, dev); } void @@ -515,19 +525,24 @@ ac97_via_remap_modem_codec(void *priv, uint16_t new_io_base, uint8_t enable) ac97_via_t *dev = (ac97_via_t *) priv; if (dev->modem_codec_base) - io_removehandler(dev->modem_codec_base, 256, ac97_via_codec_read, NULL, NULL, ac97_via_codec_write, NULL, NULL, dev); + io_removehandler(dev->modem_codec_base, 4, ac97_via_codec_read, NULL, NULL, ac97_via_codec_write, NULL, NULL, dev); dev->modem_codec_base = new_io_base; if (dev->modem_codec_base && enable) - io_sethandler(dev->modem_codec_base, 256, ac97_via_codec_read, NULL, NULL, ac97_via_codec_write, NULL, NULL, dev); + io_sethandler(dev->modem_codec_base, 4, ac97_via_codec_read, NULL, NULL, ac97_via_codec_write, NULL, NULL, dev); } static void ac97_via_update_stereo(ac97_via_t *dev, ac97_via_sgd_t *sgd) { +#ifdef OLD_CODE 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; +#else + int32_t l = (((sgd->out_l * sgd->vol_l) / 208925) * dev->master_vol_l) >> 15; + int32_t r = (((sgd->out_r * sgd->vol_r) / 208925) * dev->master_vol_r) >> 15; +#endif if (l < -32768) l = -32768; @@ -551,12 +566,12 @@ ac97_via_sgd_process(void *priv) ac97_via_t *dev = sgd->dev; /* Stop if this SGD is not active. */ - uint8_t sgd_status = dev->sgd_regs[sgd->id] & 0xc4; + uint8_t sgd_status = dev->sgd_regs[sgd->modem][sgd->id] & 0xc4; if (!(sgd_status & 0x80)) return; /* Schedule next run. */ - timer_on_auto(&sgd->dma_timer, 10.0); + timer_on_auto(&sgd->dma_timer, 1.0); /* Process SGD if it's active, and the FIFO has room or is disabled. */ if (((sgd_status & 0xc7) == 0x80) && (sgd->always_run || ((sgd->fifo_end - sgd->fifo_pos) <= (sizeof(sgd->fifo) - 4)))) { @@ -564,13 +579,15 @@ ac97_via_sgd_process(void *priv) 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->entry_ptr = *((uint32_t *) &dev->sgd_regs[sgd->modem][sgd->id | 0x4]) & 0xfffffffe; /* TODO: probe real hardware - does "even addr" actually mean dword aligned? */ sgd->restart = 0; /* Read entry. */ - sgd->sample_ptr = mem_readl_phys(sgd->entry_ptr); + // sgd->sample_ptr = mem_readl_phys(sgd->entry_ptr); + dma_bm_read(sgd->entry_ptr, (uint8_t *) &sgd->sample_ptr, 4, 4); sgd->entry_ptr += 4; - sgd->sample_count = mem_readl_phys(sgd->entry_ptr); + // sgd->sample_count = mem_readl_phys(sgd->entry_ptr); + dma_bm_read(sgd->entry_ptr, (uint8_t *) &sgd->sample_count, 4, 4); sgd->entry_ptr += 4; #ifdef ENABLE_AC97_VIA_LOG if (((sgd->sample_ptr == 0xffffffff) && (sgd->sample_count == 0xffffffff)) || ((sgd->sample_ptr == 0x00000000) && (sgd->sample_count == 0x00000000))) @@ -588,10 +605,12 @@ ac97_via_sgd_process(void *priv) if (sgd->id & 0x10) { /* Write channel: read data from FIFO. */ - mem_writel_phys(sgd->sample_ptr, *((uint32_t *) &sgd->fifo[sgd->fifo_end & (sizeof(sgd->fifo) - 1)])); + // mem_writel_phys(sgd->sample_ptr, *((uint32_t *) &sgd->fifo[sgd->fifo_end & (sizeof(sgd->fifo) - 1)])); + dma_bm_write(sgd->sample_ptr, &sgd->fifo[sgd->fifo_end & (sizeof(sgd->fifo) - 1)], 4, 4); } else { /* Read channel: write data to FIFO. */ - *((uint32_t *) &sgd->fifo[sgd->fifo_end & (sizeof(sgd->fifo) - 1)]) = mem_readl_phys(sgd->sample_ptr); + // *((uint32_t *) &sgd->fifo[sgd->fifo_end & (sizeof(sgd->fifo) - 1)]) = mem_readl_phys(sgd->sample_ptr); + dma_bm_read(sgd->sample_ptr, &sgd->fifo[sgd->fifo_end & (sizeof(sgd->fifo) - 1)], 4, 4); } sgd->fifo_end += 4; sgd->sample_ptr += 4; @@ -608,17 +627,17 @@ ac97_via_sgd_process(void *priv) ac97_via_log(" with STOP"); /* Raise STOP to pause SGD. */ - dev->sgd_regs[sgd->id] |= 0x04; + dev->sgd_regs[sgd->modem][sgd->id] |= 0x04; } if (sgd->entry_flags & 0x40) { ac97_via_log(" with FLAG"); /* Raise FLAG to pause SGD. */ - dev->sgd_regs[sgd->id] |= 0x01; + dev->sgd_regs[sgd->modem][sgd->id] |= 0x01; #ifdef ENABLE_AC97_VIA_LOG - if (dev->sgd_regs[sgd->id | 0x2] & 0x01) + if (dev->sgd_regs[sgd->modem][sgd->id | 0x2] & 0x01) ac97_via_log(" interrupt"); #endif } @@ -627,19 +646,19 @@ ac97_via_sgd_process(void *priv) ac97_via_log(" with EOL"); /* Raise EOL. */ - dev->sgd_regs[sgd->id] |= 0x02; + dev->sgd_regs[sgd->modem][sgd->id] |= 0x02; #ifdef ENABLE_AC97_VIA_LOG - if (dev->sgd_regs[sgd->id | 0x2] & 0x02) + if (dev->sgd_regs[sgd->modem][sgd->id | 0x2] & 0x02) ac97_via_log(" interrupt"); #endif /* Restart SGD if a trigger is queued or auto-start is enabled. */ - if ((dev->sgd_regs[sgd->id] & 0x08) || (dev->sgd_regs[sgd->id | 0x2] & 0x80)) { + if ((dev->sgd_regs[sgd->modem][sgd->id] & 0x08) || (dev->sgd_regs[sgd->modem][sgd->id | 0x2] & 0x80)) { ac97_via_log(" restart"); /* Un-queue trigger. */ - dev->sgd_regs[sgd->id] &= ~0x08; + dev->sgd_regs[sgd->modem][sgd->id] &= ~0x08; /* Go back to the starting block on the next run. */ sgd->restart = 2; @@ -647,13 +666,13 @@ ac97_via_sgd_process(void *priv) ac97_via_log(" finish"); /* Terminate SGD. */ - dev->sgd_regs[sgd->id] &= ~0x80; + dev->sgd_regs[sgd->modem][sgd->id] &= ~0x80; } } ac97_via_log("\n"); /* Fire any requested status interrupts. */ - ac97_via_update_irqs(dev); + ac97_via_update_irqs(dev, sgd->modem); } } } @@ -662,7 +681,7 @@ static void ac97_via_poll_stereo(void *priv) { ac97_via_t *dev = (ac97_via_t *) priv; - ac97_via_sgd_t *sgd = &dev->sgd[0]; /* Audio Read */ + ac97_via_sgd_t *sgd = &dev->sgd[0][0]; /* Audio Read */ /* Schedule next run if PCM playback is enabled. */ if (dev->pcm_enabled) @@ -672,7 +691,7 @@ ac97_via_poll_stereo(void *priv) ac97_via_update_stereo(dev, sgd); /* Feed next sample from the FIFO. */ - switch (dev->sgd_regs[sgd->id | 0x2] & 0x30) { + switch (dev->sgd_regs[0][sgd->id | 0x2] & 0x30) { case 0x00: /* Mono, 8-bit PCM */ if ((sgd->fifo_end - sgd->fifo_pos) >= 1) { sgd->out_l = sgd->out_r = (sgd->fifo[sgd->fifo_pos++ & (sizeof(sgd->fifo) - 1)] ^ 0x80) << 8; @@ -718,7 +737,7 @@ static void ac97_via_poll_fm(void *priv) { ac97_via_t *dev = (ac97_via_t *) priv; - ac97_via_sgd_t *sgd = &dev->sgd[2]; /* FM Read */ + ac97_via_sgd_t *sgd = &dev->sgd[0][2]; /* FM Read */ /* Schedule next run if FM playback is enabled. */ if (dev->fm_enabled) @@ -746,15 +765,15 @@ ac97_via_get_buffer(int32_t *buffer, int len, void *priv) { ac97_via_t *dev = (ac97_via_t *) priv; - ac97_via_update_stereo(dev, &dev->sgd[0]); - ac97_via_update_stereo(dev, &dev->sgd[2]); + ac97_via_update_stereo(dev, &dev->sgd[0][0]); + ac97_via_update_stereo(dev, &dev->sgd[0][2]); for (int c = 0; c < len * 2; c++) { - buffer[c] += dev->sgd[0].buffer[c] / 2; - buffer[c] += dev->sgd[2].buffer[c] / 2; + buffer[c] += dev->sgd[0][0].buffer[c] / 2; + buffer[c] += dev->sgd[0][2].buffer[c] / 2; } - dev->sgd[0].pos = dev->sgd[2].pos = 0; + dev->sgd[0][0].pos = dev->sgd[0][2].pos = 0; } static void @@ -780,15 +799,14 @@ ac97_via_speed_changed(void *priv) else 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)); /* FM operates at a fixed 24 KHz */ + dev->sgd[0][0].timer_latch = (uint64_t) ((double) TIMER_USEC * (1000000.0 / freq)); + dev->sgd[0][2].timer_latch = (uint64_t) ((double) TIMER_USEC * (1000000.0 / 24000.0)); /* FM operates at a fixed 24 KHz */ } static void * ac97_via_init(UNUSED(const device_t *info)) { - ac97_via_t *dev = malloc(sizeof(ac97_via_t)); - memset(dev, 0, sizeof(ac97_via_t)); + ac97_via_t *dev = calloc(1, sizeof(ac97_via_t)); ac97_via_log("AC97 VIA: init()\n"); @@ -800,19 +818,23 @@ ac97_via_init(UNUSED(const device_t *info)) /* Set up SGD channels. */ for (uint8_t i = 0; i < (sizeof(dev->sgd) / sizeof(dev->sgd[0])); i++) { - dev->sgd[i].id = i << 4; - dev->sgd[i].dev = dev; + for (uint8_t j = 0; j < 2; j++) { + dev->sgd[j][i].id = i << 4; + dev->sgd[j][i].dev = dev; - /* Disable the FIFO on SGDs we don't care about. */ - if ((i != 0) && (i != 2)) - dev->sgd[i].always_run = 1; + dev->sgd[j][i].modem = j; - timer_add(&dev->sgd[i].dma_timer, ac97_via_sgd_process, &dev->sgd[i], 0); + /* Disable the FIFO on SGDs we don't care about. */ + if ((i != 0) && (i != 2)) + dev->sgd[j][i].always_run = 1; + + timer_add(&dev->sgd[j][i].dma_timer, ac97_via_sgd_process, &dev->sgd[j][i], 0); + } } /* Set up playback pollers. */ - timer_add(&dev->sgd[0].poll_timer, ac97_via_poll_stereo, dev, 0); - timer_add(&dev->sgd[2].poll_timer, ac97_via_poll_fm, dev, 0); + timer_add(&dev->sgd[0][0].poll_timer, ac97_via_poll_stereo, dev, 0); + timer_add(&dev->sgd[0][2].poll_timer, ac97_via_poll_fm, dev, 0); ac97_via_speed_changed(dev); /* Set up playback handler. */ diff --git a/src/sound/snd_ad1848.c b/src/sound/snd_ad1848.c index 4b7941959..e9a4390c0 100644 --- a/src/sound/snd_ad1848.c +++ b/src/sound/snd_ad1848.c @@ -16,14 +16,15 @@ * * Copyright 2008-2020 Sarah Walker. * Copyright 2018-2020 TheCollector1995. - * Copyright 2021-2022 RichardG. + * Copyright 2021-2025 RichardG. */ #include +#include #include #include #include #include - +#define HAVE_STDARG_H #include <86box/86box.h> #include <86box/dma.h> #include <86box/pic.h> @@ -33,8 +34,27 @@ #include <86box/plat_fallthrough.h> #define CS4231 0x80 +#define CS4232 0x02 #define CS4236 0x03 +#ifdef ENABLE_AD1848_LOG +int ad1848_do_log = ENABLE_AD1848_LOG; + +static void +ad1848_log(const char *fmt, ...) +{ + va_list ap; + + if (ad1848_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define ad1848_log(fmt, ...) +#endif + static int ad1848_vols_7bits[128]; static double ad1848_vols_5bits_aux_gain[32]; @@ -45,22 +65,25 @@ extern uint8_t adjustMap4[64]; void ad1848_setirq(ad1848_t *ad1848, int irq) { + ad1848_log("AD1848: setirq(%d)\n", irq); ad1848->irq = irq; } void ad1848_setdma(ad1848_t *ad1848, int newdma) { + ad1848_log("AD1848: setdma(%d)\n", newdma); ad1848->dma = newdma; } void ad1848_updatevolmask(ad1848_t *ad1848) { - if ((ad1848->type >= AD1848_TYPE_CS4235) && ((ad1848->xregs[4] & 0x10) || ad1848->wten)) - ad1848->wave_vol_mask = 0x3f; - else + if ((ad1848->type == AD1848_TYPE_CS4236B) && !(ad1848->xregs[4] & 0x10) && !ad1848->wten) ad1848->wave_vol_mask = 0x7f; + else + ad1848->wave_vol_mask = 0x3f; + ad1848_log("AD1848: updatevolmask(%02X)\n", ad1848->wave_vol_mask); } static double @@ -98,6 +121,8 @@ ad1848_get_default_freq(ad1848_t *ad1848) break; } + ad1848_log("AD1848: Frequency %f through default path\n", freq); + return freq; } @@ -106,8 +131,8 @@ ad1848_updatefreq(ad1848_t *ad1848) { double freq; - if (ad1848->type >= AD1848_TYPE_CS4235) { - if (ad1848->xregs[11] & 0x20) { + if (ad1848->type >= AD1848_TYPE_CS4232) { + if (ad1848->xregs[11] & 0x20) { /* CS4236B+ only */ freq = 16934400.0; switch (ad1848->xregs[13]) { default: @@ -135,6 +160,8 @@ ad1848_updatefreq(ad1848_t *ad1848) freq /= 2558.0; break; } + + ad1848_log("AD1848: Frequency %f through CS4236B+ path\n", freq); } else if (ad1848->regs[22] & 0x80) { const uint8_t set = (ad1848->regs[22] >> 1) & 0x3f; freq = (ad1848->regs[22] & 1) ? 33868800.0 : 49152000.0; @@ -152,6 +179,8 @@ ad1848_updatefreq(ad1848_t *ad1848) freq /= 256 * set; break; } + + ad1848_log("AD1848: Frequency %f through CS4232+ path\n", freq); } else freq = ad1848_get_default_freq(ad1848); } else @@ -166,6 +195,7 @@ ad1848_read(uint16_t addr, void *priv) { ad1848_t *ad1848 = (ad1848_t *) priv; uint8_t ret = 0xff; + uint8_t temp = 0; switch (addr & 3) { case 0: /* Index */ @@ -180,36 +210,61 @@ ad1848_read(uint16_t addr, void *priv) ad1848->regs[ad1848->index] = ret; break; - case 18: - case 19: - if (ad1848->type >= AD1848_TYPE_CS4235) { + case 18 ... 19: + if (ad1848->type >= AD1848_TYPE_CS4236B) { if ((ad1848->xregs[4] & 0x14) == 0x14) /* FM remapping */ - ret = ad1848->xregs[ad1848->index - 12]; /* real FM volume on registers 6 and 7 */ + ret = ad1848->xregs[6 | (ad1848->index & 1)]; /* real FM volume on registers 6 and 7 */ else if (ad1848->wten && !(ad1848->xregs[4] & 0x08)) /* wavetable remapping */ - ret = ad1848->xregs[ad1848->index - 2]; /* real wavetable volume on registers 16 and 17 */ + ret = ad1848->xregs[16 | (ad1848->index & 1)]; /* real wavetable volume on registers 16 and 17 */ } break; - case 20: - case 21: - /* Backdoor to the Control/RAM registers on CS4235. */ - if ((ad1848->type == AD1848_TYPE_CS4235) && (ad1848->xregs[18] & 0x80)) + case 20 ... 21: + /* Backdoor to the Control/RAM registers on CS4235+. */ + if ((ad1848->type >= AD1848_TYPE_CS4235) && (ad1848->xregs[18] & 0x80)) ret = ad1848->cram_read(ad1848->index - 15, ad1848->cram_priv); break; case 23: - if ((ad1848->type >= AD1848_TYPE_CS4235) && (ad1848->regs[23] & 0x08)) { - if ((ad1848->xindex & 0xfe) == 0x00) /* remapped line volume */ - ret = ad1848->regs[18 + ad1848->xindex]; - else - ret = ad1848->xregs[ad1848->xindex]; + if ((ad1848->type >= AD1848_TYPE_CS4236B) && (ad1848->regs[23] & 0x08)) { + ret = ad1848->xregs[ad1848->xindex]; + switch (ad1848->xindex) { + case 0 ... 1: + /* Remapped line volume. */ + ret = ad1848->regs[18 + ad1848->xindex]; + break; + + case 23 ... 24: + case 29: + /* Backdoor to control indirect registers on CS4235+. */ + if (ad1848->type >= AD1848_TYPE_CS4235) { + temp = ad1848->cram_read(3, ad1848->cram_priv); + ad1848->cram_write(3, (ad1848->xindex == 23) ? 2 : ((ad1848->xindex == 24) ? 8 : 9), ad1848->cram_priv); + ret = ad1848->cram_read(4, ad1848->cram_priv); + ad1848->cram_write(3, temp, ad1848->cram_priv); + } + break; + + case 26 ... 28: + case 30: + /* Backdoor to control registers on CS4235+. */ + if (ad1848->type >= AD1848_TYPE_CS4235) + ret = ad1848->cram_read((ad1848->xindex == 30) ? 7 : (ad1848->xindex - 26), ad1848->cram_priv); + break; + + default: + break; + } + ad1848_log("AD1848: read(X%d) = %02X\n", ad1848->xindex, ret); + return ret; } break; default: break; } - break; + ad1848_log("AD1848: read(I%d) = %02X\n", ad1848->index, ret); + return ret; case 2: ret = ad1848->status; @@ -219,6 +274,8 @@ ad1848_read(uint16_t addr, void *priv) break; } + ad1848_log("AD1848: read(%04X) = %02X\n", addr, ret); + return ret; } @@ -235,7 +292,7 @@ ad1848_write(uint16_t addr, uint8_t val, void *priv) ad1848->index = val & 0x1f; /* cs4231a extended mode enabled */ else ad1848->index = val & 0x0f; /* ad1848/cs4248 mode TODO: some variants/clones DO NOT mirror, just ignore the writes? */ - if (ad1848->type >= AD1848_TYPE_CS4235) + if (ad1848->type >= AD1848_TYPE_CS4236B) ad1848->regs[23] &= ~0x08; /* clear XRAE */ ad1848->trd = val & 0x20; ad1848->mce = val & 0x40; @@ -244,7 +301,7 @@ ad1848_write(uint16_t addr, uint8_t val, void *priv) case 1: switch (ad1848->index) { case 10: - if (ad1848->type < AD1848_TYPE_CS4235) + if (ad1848->type < AD1848_TYPE_CS4232) break; fallthrough; @@ -269,50 +326,56 @@ ad1848_write(uint16_t addr, uint8_t val, void *priv) break; case 11: - return; + goto readonly_i; case 12: - if (ad1848->type != AD1848_TYPE_DEFAULT) - ad1848->regs[12] = ((ad1848->regs[12] & 0x0f) + (val & 0xf0)) | 0x80; - return; + if (ad1848->type >= AD1848_TYPE_CS4248) { + ad1848->regs[12] = 0x80 | (val & 0x70) | (ad1848->regs[12] & 0x0f); + if ((ad1848->type >= AD1848_TYPE_CS4231) && (ad1848->type < AD1848_TYPE_CS4235)) { + if (val & 0x40) + ad1848->fmt_mask |= 0x80; + else + ad1848->fmt_mask &= ~0x80; + } + } + goto readonly_i; case 14: ad1848->count = ad1848->regs[15] | (val << 8); break; - case 17: - /* Enable additional data formats on modes 2 and 3 where supported. */ - if ((ad1848->type == AD1848_TYPE_CS4231) || (ad1848->type == AD1848_TYPE_CS4236)) - ad1848->fmt_mask = (val & 0x40) ? 0xf0 : 0x70; - break; + case 18 ... 19: + if (ad1848->type >= AD1848_TYPE_CS4236B) { + if (ad1848->type >= AD1848_TYPE_CS4235) { + if (ad1848->xregs[18] & 0x20) /* AUX1 remapping */ + ad1848->regs[ad1848->index & 3] = val; /* also controls AUX1 on registers 2 and 3 */ + } else { + temp = 0; + if ((ad1848->xregs[4] & 0x14) == 0x14) { /* FM remapping */ + ad1848->xregs[6 | (ad1848->index & 1)] = val; /* real FM volume on extended registers 6 and 7 */ + temp = 1; - case 18: - case 19: - if (ad1848->type >= AD1848_TYPE_CS4235) { - if ((ad1848->xregs[4] & 0x14) == 0x14) { /* FM remapping */ - ad1848->xregs[ad1848->index - 12] = val; /* real FM volume on extended registers 6 and 7 */ - temp = 1; - - if (ad1848->index == 18) { - if (val & 0x80) - ad1848->fm_vol_l = 0; - else - ad1848->fm_vol_l = ad1848_vols_7bits[val & 0x3f]; - } else { - if (val & 0x80) - ad1848->fm_vol_r = 0; - else - ad1848->fm_vol_r = ad1848_vols_7bits[val & 0x3f]; + if (ad1848->index == 18) { + if (val & 0x80) + ad1848->fm_vol_l = 0; + else + ad1848->fm_vol_l = ad1848_vols_7bits[val & 0x3f]; + } else { + if (val & 0x80) + ad1848->fm_vol_r = 0; + else + ad1848->fm_vol_r = ad1848_vols_7bits[val & 0x3f]; + } + } + if (ad1848->wten && !(ad1848->xregs[4] & 0x08)) { /* wavetable remapping */ + ad1848->xregs[16 | (ad1848->index & 1)] = val; /* real wavetable volume on extended registers 16 and 17 */ + temp = 1; } - } - if (ad1848->wten && !(ad1848->xregs[4] & 0x08)) { /* wavetable remapping */ - ad1848->xregs[ad1848->index - 2] = val; /* real wavetable volume on extended registers 16 and 17 */ - temp = 1; - } - /* Stop here if any remapping is enabled. */ - if (temp) - return; + /* Stop here if any remapping is enabled. */ + if (temp) + goto readonly_i; + } /* HACK: the Windows 9x driver's "Synth" control writes to this register with no remapping, even if internal FM is enabled. */ @@ -330,10 +393,9 @@ ad1848_write(uint16_t addr, uint8_t val, void *priv) } break; - case 20: - case 21: - /* Backdoor to the Control/RAM registers on CS4235. */ - if ((ad1848->type == AD1848_TYPE_CS4235) && (ad1848->xregs[18] & 0x80)) { + case 20 ... 21: + /* Backdoor to the Control/RAM registers on CS4235+. */ + if ((ad1848->type >= AD1848_TYPE_CS4235) && (ad1848->xregs[18] & 0x80)) { ad1848->cram_write(ad1848->index - 15, val, ad1848->cram_priv); val = ad1848->regs[ad1848->index]; } @@ -344,17 +406,19 @@ ad1848_write(uint16_t addr, uint8_t val, void *priv) break; case 23: - if ((ad1848->type >= AD1848_TYPE_CS4235) && ((ad1848->regs[12] & 0x60) == 0x60)) { + if ((ad1848->type >= AD1848_TYPE_CS4236B) && ((ad1848->regs[12] & 0x60) == 0x60)) { if (!(ad1848->regs[23] & 0x08)) { /* existing (not new) XRAE is clear */ ad1848->xindex = ((val & 0x04) << 2) | (val >> 4); break; } switch (ad1848->xindex) { - case 0: - case 1: /* remapped line volume */ - ad1848->regs[18 + ad1848->xindex] = val; - return; + case 0 ... 1: + if (ad1848->type < AD1848_TYPE_CS4235) { + /* Remapped line volume. */ + ad1848->regs[18 | ad1848->xindex] = val; + } + break; case 6: if (val & 0x80) @@ -375,8 +439,26 @@ ad1848_write(uint16_t addr, uint8_t val, void *priv) updatefreq = 1; break; + case 23 ... 24: + case 29: + /* Backdoor to control indirect registers on CS4235+. */ + if (ad1848->type >= AD1848_TYPE_CS4235) { + temp = ad1848->cram_read(3, ad1848->cram_priv); + ad1848->cram_write(3, (ad1848->xindex == 23) ? 2 : ((ad1848->xindex == 24) ? 8 : 9), ad1848->cram_priv); + ad1848->cram_write(4, val, ad1848->cram_priv); + ad1848->cram_write(3, temp, ad1848->cram_priv); + } + break; + case 25: - return; + goto readonly_x; + + case 26 ... 28: + case 30: + /* Backdoor to control registers on CS4235+. */ + if (ad1848->type >= AD1848_TYPE_CS4235) + ad1848->cram_write((ad1848->xindex == 30) ? 7 : (ad1848->xindex - 26), val, ad1848->cram_priv); + break; default: break; @@ -386,6 +468,8 @@ ad1848_write(uint16_t addr, uint8_t val, void *priv) if (updatefreq) ad1848_updatefreq(ad1848); +readonly_x: + ad1848_log("AD1848: write(X%d, %02X)\n", ad1848->xindex, val); return; } break; @@ -399,10 +483,14 @@ ad1848_write(uint16_t addr, uint8_t val, void *priv) break; case 25: - return; + goto readonly_i; case 27: - if (ad1848->type != AD1848_TYPE_DEFAULT) - return; + if ((ad1848->type != AD1848_TYPE_CS4232) && (ad1848->type != AD1848_TYPE_CS4236)) + goto readonly_i; + break; + case 29: + if ((ad1848->type != AD1848_TYPE_CS4232) && (ad1848->type != AD1848_TYPE_CS4236)) + goto readonly_i; break; default: @@ -424,7 +512,9 @@ ad1848_write(uint16_t addr, uint8_t val, void *priv) else ad1848->cd_vol_r = ad1848_vols_5bits_aux_gain[ad1848->regs[temp] & 0x1f]; - break; +readonly_i: + ad1848_log("AD1848: write(I%d, %02X)\n", ad1848->index, val); + return; case 2: ad1848->status &= 0xfe; @@ -434,6 +524,8 @@ ad1848_write(uint16_t addr, uint8_t val, void *priv) default: break; } + + ad1848_log("AD1848: write(%04X, %02X)\n", addr, val); } void @@ -456,17 +548,13 @@ ad1848_process_mulaw(uint8_t byte) { byte = ~byte; int temp = (((byte & 0x0f) << 3) + 0x84); - int16_t dec; temp <<= ((byte & 0x70) >> 4); temp = (byte & 0x80) ? (0x84 - temp) : (temp - 0x84); if (temp > 32767) - dec = 32767; + return 32767; else if (temp < -32768) - dec = -32768; - else - dec = (int16_t) temp; - - return dec; + return -32768; + return (int16_t) temp; } static int16_t @@ -489,8 +577,7 @@ ad1848_process_alaw(uint8_t byte) dec |= 0x108; break; } - dec = (byte & 0x80) ? dec : -dec; - return (int16_t) dec; + return (int16_t) ((byte & 0x80) ? dec : -dec); } static uint32_t @@ -644,9 +731,11 @@ ad1848_poll(void *priv) if (!(ad1848->status & 0x01)) { ad1848->status |= 0x01; ad1848->regs[24] |= 0x10; - if (ad1848->regs[10] & 2) - picint(1 << ad1848->irq); } + if (ad1848->regs[10] & 2) + picint(1 << ad1848->irq); + else + picintc(1 << ad1848->irq); } if (!(ad1848->adpcm_pos & 7)) /* ADPCM counts down every 4 bytes */ @@ -692,6 +781,8 @@ ad1848_init(ad1848_t *ad1848, uint8_t type) uint8_t c; double attenuation; + ad1848_log("AD1848: init(%02X)\n", type); + ad1848->status = 0xcc; ad1848->index = ad1848->trd = 0; ad1848->mce = 0x40; @@ -704,10 +795,7 @@ ad1848_init(ad1848_t *ad1848, uint8_t type) ad1848->regs[8] = 0; ad1848->regs[9] = 0x08; ad1848->regs[10] = ad1848->regs[11] = 0; - if ((type == AD1848_TYPE_CS4248) || (type == AD1848_TYPE_CS4231) || (type >= AD1848_TYPE_CS4235)) - ad1848->regs[12] = 0x8a; - else - ad1848->regs[12] = 0xa; + ad1848->regs[12] = (type >= AD1848_TYPE_CS4248) ? 0x8a : 0xa; ad1848->regs[13] = 0; ad1848->regs[14] = ad1848->regs[15] = 0; @@ -719,27 +807,30 @@ ad1848_init(ad1848_t *ad1848, uint8_t type) ad1848->regs[25] = CS4231; ad1848->regs[26] = 0x80; ad1848->regs[29] = 0x80; - } else if (type >= AD1848_TYPE_CS4235) { + } else if (type >= AD1848_TYPE_CS4232) { ad1848->regs[16] = ad1848->regs[17] = 0; ad1848->regs[18] = ad1848->regs[19] = 0; ad1848->regs[20] = ad1848->regs[21] = 0; ad1848->regs[22] = ad1848->regs[23] = 0; ad1848->regs[24] = 0; - ad1848->regs[25] = CS4236; + ad1848->regs[25] = (type == AD1848_TYPE_CS4232) ? CS4232 : CS4236; ad1848->regs[26] = 0xa0; ad1848->regs[27] = ad1848->regs[29] = 0; ad1848->regs[30] = ad1848->regs[31] = 0; - ad1848->xregs[0] = ad1848->xregs[1] = 0xe8; - ad1848->xregs[2] = ad1848->xregs[3] = 0xcf; - ad1848->xregs[4] = 0x84; - ad1848->xregs[5] = 0; - ad1848->xregs[6] = ad1848->xregs[7] = 0x80; - ad1848->xregs[8] = ad1848->xregs[9] = 0; - ad1848->xregs[10] = 0x3f; - ad1848->xregs[11] = 0xc0; - ad1848->xregs[14] = ad1848->xregs[15] = 0; - ad1848->xregs[16] = ad1848->xregs[17] = 0; + if (type >= AD1848_TYPE_CS4236B) { + if (type < AD1848_TYPE_CS4235) + ad1848->xregs[0] = ad1848->xregs[1] = 0xe8; + ad1848->xregs[2] = ad1848->xregs[3] = 0xcf; + ad1848->xregs[4] = 0x84; + ad1848->xregs[5] = 0; + ad1848->xregs[6] = ad1848->xregs[7] = 0x80; + ad1848->xregs[8] = ad1848->xregs[9] = 0; + ad1848->xregs[10] = 0x3f; + ad1848->xregs[11] = 0xc0; + ad1848->xregs[14] = ad1848->xregs[15] = 0; + ad1848->xregs[16] = ad1848->xregs[17] = 0; + } } ad1848_updatefreq(ad1848); @@ -747,7 +838,7 @@ ad1848_init(ad1848_t *ad1848, uint8_t type) ad1848->out_l = ad1848->out_r = 0; ad1848->fm_vol_l = ad1848->fm_vol_r = 65536; ad1848_updatevolmask(ad1848); - if (type == AD1848_TYPE_CS4235) + if (type >= AD1848_TYPE_CS4235) ad1848->fmt_mask = 0x50; else ad1848->fmt_mask = 0x70; diff --git a/src/sound/snd_adlib.c b/src/sound/snd_adlib.c index 983ccf7d3..17990e842 100644 --- a/src/sound/snd_adlib.c +++ b/src/sound/snd_adlib.c @@ -103,8 +103,7 @@ adlib_mca_feedb(void *priv) void * adlib_init(UNUSED(const device_t *info)) { - adlib_t *adlib = malloc(sizeof(adlib_t)); - memset(adlib, 0, sizeof(adlib_t)); + adlib_t *adlib = calloc(1, sizeof(adlib_t)); adlib_log("adlib_init\n"); fm_driver_get(FM_YM3812, &adlib->opl); @@ -146,7 +145,7 @@ adlib_close(void *priv) const device_t adlib_device = { .name = "AdLib", .internal_name = "adlib", - .flags = DEVICE_ISA, + .flags = DEVICE_ISA | DEVICE_SIDECAR, .local = 0, .init = adlib_init, .close = adlib_close, diff --git a/src/sound/snd_adlibgold.c b/src/sound/snd_adlibgold.c index 7b5deaac5..360da3fec 100644 --- a/src/sound/snd_adlibgold.c +++ b/src/sound/snd_adlibgold.c @@ -1066,8 +1066,7 @@ adgold_init(UNUSED(const device_t *info)) FILE *fp; int c; double out; - adgold_t *adgold = malloc(sizeof(adgold_t)); - memset(adgold, 0, sizeof(adgold_t)); + adgold_t *adgold = calloc(1, sizeof(adgold_t)); adgold->dma = device_get_config_int("dma"); adgold->irq = device_get_config_int("irq"); @@ -1193,73 +1192,69 @@ adgold_close(void *priv) static const device_config_t adgold_config[] = { // clang-format off { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 7, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "IRQ 3", - .value = 3 - }, - { - .description = "IRQ 4", - .value = 4 - }, - { - .description = "IRQ 5", - .value = 5 - }, - { - .description = "IRQ 7", - .value = 7 - }, - { .description = "" } - } + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 7, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "IRQ 3", .value = 3 }, + { .description = "IRQ 4", .value = 4 }, + { .description = "IRQ 5", .value = 5 }, + { .description = "IRQ 7", .value = 7 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "dma", - .description = "Low DMA", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 1, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "DMA 1", - .value = 1 - }, - { - .description = "DMA 3", - .value = 3 - }, - { .description = "" } - } + .name = "dma", + .description = "Low DMA", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "DMA 1", .value = 1 }, + { .description = "DMA 3", .value = 3 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "gameport", - .description = "Enable Game port", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "gameport", + .description = "Enable Game port", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "surround", - .description = "Surround module", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "surround", + .description = "Surround module", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on diff --git a/src/sound/snd_audiopci.c b/src/sound/snd_audiopci.c index 07add5062..1ca547650 100644 --- a/src/sound/snd_audiopci.c +++ b/src/sound/snd_audiopci.c @@ -39,6 +39,7 @@ #include <86box/pci.h> #include <86box/snd_ac97.h> #include <86box/sound.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/plat_unused.h> #include <86box/snd_akm4531.h> @@ -489,7 +490,10 @@ es137x_reset(void *priv) /* Serial Interface Control Register, Address 20H Addressable as byte, word, longword */ - dev->si_cr = 0xff800000; + if (dev->type == AUDIOPCI_ES1370) + dev->si_cr = 0x00000000; + else + dev->si_cr = 0xff800000; /* DAC1 Channel Sample Count Register, Address 24H Addressable as word, longword */ @@ -2645,8 +2649,7 @@ static void es137x_speed_changed(void *priv); static void * es1370_init(const device_t *info) { - es137x_t *dev = malloc(sizeof(es137x_t)); - memset(dev, 0x00, sizeof(es137x_t)); + es137x_t *dev = calloc(1, sizeof(es137x_t)); dev->type = info->local; if (device_get_config_int("receive_input")) @@ -2689,8 +2692,7 @@ es1370_init(const device_t *info) static void * es1371_init(const device_t *info) { - es137x_t *dev = malloc(sizeof(es137x_t)); - memset(dev, 0x00, sizeof(es137x_t)); + es137x_t *dev = calloc(1, sizeof(es137x_t)); dev->type = info->local & 0xffffff00; if (device_get_config_int("receive_input")) @@ -2739,11 +2741,15 @@ es137x_speed_changed(void *priv) static const device_config_t es1370_config[] = { // clang-format off { - .name = "receive_input", - .description = "Receive input (MIDI)", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -2752,28 +2758,30 @@ static const device_config_t es1370_config[] = { static const device_config_t es1371_config[] = { // clang-format off { - .name = "codec", - .description = "Codec", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "Asahi Kasei AK4540", - .value = AC97_CODEC_AK4540 - }, - { - .description = "TriTech TR28023 / Creative CT1297", - .value = AC97_CODEC_TR28023 - }, - { .description = "" } + .name = "codec", + .description = "Codec", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = AC97_CODEC_TR28023, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Asahi Kasei AK4540", .value = AC97_CODEC_AK4540 }, + { .description = "TriTech TR28023 / Creative CT1297", .value = AC97_CODEC_TR28023 }, + { .description = "" } }, - .default_int = AC97_CODEC_TR28023 + .bios = { { 0 } } }, { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -2782,32 +2790,31 @@ static const device_config_t es1371_config[] = { static const device_config_t es1373_config[] = { // clang-format off { - .name = "codec", - .description = "Codec", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "Crystal CS4297A", - .value = AC97_CODEC_CS4297A - }, - { - .description = "SigmaTel STAC9721T", - .value = AC97_CODEC_STAC9721 - }, - { - .description = "TriTech TR28023 / Creative CT1297", - .value = AC97_CODEC_TR28023 - }, + .name = "codec", + .description = "Codec", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = AC97_CODEC_CS4297A, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Crystal CS4297A", .value = AC97_CODEC_CS4297A }, + { .description = "SigmaTel STAC9721T", .value = AC97_CODEC_STAC9721 }, + { .description = "TriTech TR28023 / Creative CT1297", .value = AC97_CODEC_TR28023 }, { .description = "" } }, - .default_int = AC97_CODEC_CS4297A + .bios = { { 0 } } }, { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -2816,32 +2823,31 @@ static const device_config_t es1373_config[] = { static const device_config_t ct5880_config[] = { // clang-format off { - .name = "codec", - .description = "Codec", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "SigmaTel STAC9708T", - .value = AC97_CODEC_STAC9708 - }, - { - .description = "SigmaTel STAC9721T (stereo)", - .value = AC97_CODEC_STAC9721 - }, - { - .description = "TriTech TR28023 / Creative CT1297", - .value = AC97_CODEC_TR28023 - }, - { .description = "" } + .name = "codec", + .description = "Codec", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = AC97_CODEC_STAC9708, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "SigmaTel STAC9708T", .value = AC97_CODEC_STAC9708 }, + { .description = "SigmaTel STAC9721T (stereo)", .value = AC97_CODEC_STAC9721 }, + { .description = "TriTech TR28023 / Creative CT1297", .value = AC97_CODEC_TR28023 }, + { .description = "" } }, - .default_int = AC97_CODEC_STAC9708 + .bios = { { 0 } } }, { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -2850,11 +2856,14 @@ static const device_config_t ct5880_config[] = { static const device_config_t es1371_onboard_config[] = { // clang-format off { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on diff --git a/src/sound/snd_azt2316a.c b/src/sound/snd_azt2316a.c index cf05203f3..76bf1b24f 100644 --- a/src/sound/snd_azt2316a.c +++ b/src/sound/snd_azt2316a.c @@ -974,8 +974,7 @@ azt_init(const device_t *info) int loaded_from_eeprom = 0; uint16_t addr_setting; uint8_t read_eeprom[AZTECH_EEPROM_SIZE]; - azt2316a_t *azt2316a = malloc(sizeof(azt2316a_t)); - memset(azt2316a, 0, sizeof(azt2316a_t)); + azt2316a_t *azt2316a = calloc(1, sizeof(azt2316a_t)); azt2316a->type = info->local; @@ -1226,8 +1225,7 @@ azt_init(const device_t *info) 2x4 to 2x5 -> Mixer interface 2x6, 2xA, 2xC, 2xE -> DSP chip 2x8, 2x9, 388 and 389 FM chip (9 voices).*/ - azt2316a->sb = malloc(sizeof(sb_t)); - memset(azt2316a->sb, 0, sizeof(sb_t)); + azt2316a->sb = calloc(1, sizeof(sb_t)); azt2316a->sb->opl_enabled = device_get_config_int("opl"); @@ -1259,8 +1257,7 @@ azt_init(const device_t *info) sound_set_cd_audio_filter(sbpro_filter_cd_audio, azt2316a->sb); if (azt2316a->cur_mpu401_enabled) { - azt2316a->mpu = (mpu_t *) malloc(sizeof(mpu_t)); - memset(azt2316a->mpu, 0, sizeof(mpu_t)); + azt2316a->mpu = (mpu_t *) calloc(1, sizeof(mpu_t)); mpu401_init(azt2316a->mpu, azt2316a->cur_mpu401_addr, azt2316a->cur_mpu401_irq, M_UART, device_get_config_int("receive_input401")); } else azt2316a->mpu = NULL; @@ -1318,142 +1315,127 @@ azt_speed_changed(void *priv) static const device_config_t azt1605_config[] = { // clang-format off { - .name = "codec", - .description = "CODEC", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "CS4248", - .value = AD1848_TYPE_CS4248 - }, - { - .description = "CS4231", - .value = AD1848_TYPE_CS4231 - }, + .name = "codec", + .description = "CODEC", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = AD1848_TYPE_CS4248, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "CS4248", .value = AD1848_TYPE_CS4248 }, + { .description = "CS4231", .value = AD1848_TYPE_CS4231 }, + { .description = "" } }, - .default_int = AD1848_TYPE_CS4248 + .bios = { { 0 } } }, { - .name = "wss_interrupt_after_config", - .description = "Raise CODEC interrupt on CODEC setup (needed by some drivers)", - .type = CONFIG_BINARY, - .default_int = 0 + .name = "wss_interrupt_after_config", + .description = "Raise CODEC interrupt on CODEC setup (needed by some drivers)", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "addr", - .description = "SB Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "0x220", - .value = 0x220 - }, - { - .description = "0x240", - .value = 0x240 - }, - { - .description = "Use EEPROM setting", - .value = 0 - }, - { - .description = "" - } - } - }, - { - .name = "sb_dma8", - .description = "SB low DMA", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "DMA 0", - .value = 0 - }, - { - .description = "DMA 1", - .value = 1 - }, - { - .description = "DMA 3", - .value = 3 - }, - { - .description = "" - } + .name = "addr", + .description = "SB Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "0x220", .value = 0x220 }, + { .description = "0x240", .value = 0x240 }, + { .description = "Use EEPROM setting", .value = 0 }, + { .description = "" } }, - .default_int = 1 + .bios = { { 0 } } }, { - .name = "wss_irq", - .description = "WSS IRQ", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "IRQ 11", - .value = 11 - }, - { - .description = "IRQ 10", - .value = 10 - }, - { - .description = "IRQ 7", - .value = 7 - }, - { - .description = "" - } + .name = "sb_dma8", + .description = "SB low DMA", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "DMA 0", .value = 0 }, + { .description = "DMA 1", .value = 1 }, + { .description = "DMA 3", .value = 3 }, + { .description = "" } }, - .default_int = 10 + .bios = { { 0 } } }, - { - .name = "wss_dma", - .description = "WSS DMA", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "DMA 0", - .value = 0 - }, - { - .description = "DMA 1", - .value = 1 - }, - { - .description = "DMA 3", - .value = 3 - }, - { - .description = "" - } - }, - .default_int = 0 + { + .name = "wss_irq", + .description = "WSS IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 10, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "IRQ 11", .value = 11 }, + { .description = "IRQ 10", .value = 10 }, + { .description = "IRQ 7", .value = 7 }, + { .description = "" } }, - { - .name = "opl", - .description = "Enable OPL", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .bios = { { 0 } } }, { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "wss_dma", + .description = "WSS DMA", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "DMA 0", .value = 0 }, + { .description = "DMA 1", .value = 1 }, + { .description = "DMA 3", .value = 3 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "receive_input401", - .description = "Receive MIDI input (MPU-401)", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "opl", + .description = "Enable OPL", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { + .name = "receive_input401", + .description = "Receive MIDI input (MPU-401)", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -1462,119 +1444,111 @@ static const device_config_t azt1605_config[] = { static const device_config_t azt2316a_config[] = { // clang-format off { - .name = "codec", - .description = "CODEC", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "CS4248", - .value = AD1848_TYPE_CS4248 - }, - { - .description = "CS4231", - .value = AD1848_TYPE_CS4231 - }, + .name = "codec", + .description = "CODEC", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = AD1848_TYPE_CS4248, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "CS4248", .value = AD1848_TYPE_CS4248 }, + { .description = "CS4231", .value = AD1848_TYPE_CS4231 }, + { .description = "" } }, - .default_int = AD1848_TYPE_CS4248 + .bios = { { 0 } } }, { - .name = "wss_interrupt_after_config", - .description = "Raise CODEC interrupt on CODEC setup (needed by some drivers)", - .type = CONFIG_BINARY, - .default_int = 0 + .name = "wss_interrupt_after_config", + .description = "Raise CODEC interrupt on CODEC setup (needed by some drivers)", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "addr", - .description = "SB Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "0x220", - .value = 0x220 - }, - { - .description = "0x240", - .value = 0x240 - }, - { - .description = "Use EEPROM setting", - .value = 0 - }, - { - .description = "" - } - } - }, - { - .name = "wss_irq", - .description = "WSS IRQ", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "IRQ 11", - .value = 11 - }, - { - .description = "IRQ 10", - .value = 10 - }, - { - .description = "IRQ 7", - .value = 7 - }, - { - .description = "" - } + .name = "addr", + .description = "SB Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "0x220", .value = 0x220 }, + { .description = "0x240", .value = 0x240 }, + { .description = "Use EEPROM setting", .value = 0 }, + { .description = "" } }, - .default_int = 10 + .bios = { { 0 } } }, { - .name = "wss_dma", - .description = "WSS DMA", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "DMA 0", - .value = 0 - }, - { - .description = "DMA 1", - .value = 1 - }, - { - .description = "DMA 3", - .value = 3 - }, - { - .description = "" - } + .name = "wss_irq", + .description = "WSS IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 10, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "IRQ 11", .value = 11 }, + { .description = "IRQ 10", .value = 10 }, + { .description = "IRQ 7", .value = 7 }, + { .description = "" } }, - .default_int = 0 + .bios = { { 0 } } }, { - .name = "opl", - .description = "Enable OPL", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "wss_dma", + .description = "WSS DMA", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "DMA 0", .value = 0 }, + { .description = "DMA 1", .value = 1 }, + { .description = "DMA 3", .value = 3 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "opl", + .description = "Enable OPL", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input401", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { + .name = "receive_input401", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -1583,7 +1557,7 @@ static const device_config_t azt2316a_config[] = { const device_t azt2316a_device = { .name = "Aztech Sound Galaxy Pro 16 AB (Washington)", .internal_name = "azt2316a", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = SB_SUBTYPE_CLONE_AZT2316A_0X11, .init = azt_init, .close = azt_close, @@ -1597,7 +1571,7 @@ const device_t azt2316a_device = { const device_t azt1605_device = { .name = "Aztech Sound Galaxy Nova 16 Extra (Clinton)", .internal_name = "azt1605", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = SB_SUBTYPE_CLONE_AZT1605_0X0C, .init = azt_init, .close = azt_close, diff --git a/src/sound/snd_cmi8x38.c b/src/sound/snd_cmi8x38.c index 833124bb2..a41f53865 100644 --- a/src/sound/snd_cmi8x38.c +++ b/src/sound/snd_cmi8x38.c @@ -1434,8 +1434,7 @@ cmi8x38_reset(void *priv) static void * cmi8x38_init(const device_t *info) { - cmi8x38_t *dev = malloc(sizeof(cmi8x38_t)); - memset(dev, 0, sizeof(cmi8x38_t)); + cmi8x38_t *dev = calloc(1, sizeof(cmi8x38_t)); /* Set the chip type. */ if ((info->local == CMEDIA_CMI8738_6CH) && !device_get_config_int("six_channel")) @@ -1509,11 +1508,15 @@ cmi8x38_close(void *priv) static const device_config_t cmi8x38_config[] = { // clang-format off { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -1522,18 +1525,26 @@ static const device_config_t cmi8x38_config[] = { static const device_config_t cmi8738_config[] = { // clang-format off { - .name = "six_channel", - .description = "6CH variant (6-channel)", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "six_channel", + .description = "6CH variant (6-channel)", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on diff --git a/src/sound/snd_cms.c b/src/sound/snd_cms.c index 2ec81b53d..66dff80f3 100644 --- a/src/sound/snd_cms.c +++ b/src/sound/snd_cms.c @@ -181,8 +181,7 @@ cms_read(uint16_t addr, void *priv) void * cms_init(UNUSED(const device_t *info)) { - cms_t *cms = malloc(sizeof(cms_t)); - memset(cms, 0, sizeof(cms_t)); + cms_t *cms = calloc(1, sizeof(cms_t)); uint16_t addr = device_get_config_hex16("base"); io_sethandler(addr, 0x0010, cms_read, NULL, NULL, cms_write, NULL, NULL, cms); @@ -201,42 +200,23 @@ cms_close(void *priv) static const device_config_t cms_config[] = { // clang-format off { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x220, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "0x210", - .value = 0x210 - }, - { - .description = "0x220", - .value = 0x220 - }, - { - .description = "0x230", - .value = 0x230 - }, - { - .description = "0x240", - .value = 0x240 - }, - { - .description = "0x250", - .value = 0x250 - }, - { - .description = "0x260", - .value = 0x260 - }, - { - .description = "" - } - } + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x220, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "0x210", .value = 0x210 }, + { .description = "0x220", .value = 0x220 }, + { .description = "0x230", .value = 0x230 }, + { .description = "0x240", .value = 0x240 }, + { .description = "0x250", .value = 0x250 }, + { .description = "0x260", .value = 0x260 }, + { .description = "" } + }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on diff --git a/src/sound/snd_cs423x.c b/src/sound/snd_cs423x.c index f28be9778..74382a53b 100644 --- a/src/sound/snd_cs423x.c +++ b/src/sound/snd_cs423x.c @@ -12,15 +12,16 @@ * * Authors: RichardG, * - * Copyright 2021-2022 RichardG. + * Copyright 2021-2025 RichardG. */ #include +#include #include #include #include #include #include - +#define HAVE_STDARG_H #include <86box/86box.h> #include <86box/device.h> #include <86box/dma.h> @@ -46,10 +47,19 @@ #define CRYSTAL_NOEEPROM 0x100 enum { - CRYSTAL_CS4235 = 0xdd, - CRYSTAL_CS4236B = 0xcb, + CRYSTAL_CS4232 = 0x32, /* no chip ID; dummy value */ + CRYSTAL_CS4236 = 0x36, /* no chip ID; dummy value */ + CRYSTAL_CS4236B = 0xab, /* report an older revision ID to make the values nice and incremental */ CRYSTAL_CS4237B = 0xc8, - CRYSTAL_CS4238B = 0xc9 + CRYSTAL_CS4238B = 0xc9, + CRYSTAL_CS4235 = 0xdd, + CRYSTAL_CS4239 = 0xde +}; +enum { + CRYSTAL_RAM_CMD = 0, + CRYSTAL_RAM_ADDR_LO = 1, + CRYSTAL_RAM_ADDR_HI = 2, + CRYSTAL_RAM_DATA = 3 }; enum { CRYSTAL_SLAM_NONE = 0, @@ -58,27 +68,43 @@ enum { CRYSTAL_SLAM_BYTE2 = 3 }; +#ifdef ENABLE_CS423X_LOG +int cs423x_do_log = ENABLE_CS423X_LOG; + +static void +cs423x_log(const char *fmt, ...) +{ + va_list ap; + + if (cs423x_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define cs423x_log(fmt, ...) +#endif + static const uint8_t slam_init_key[32] = { 0x96, 0x35, 0x9A, 0xCD, 0xE6, 0xF3, 0x79, 0xBC, 0x5E, 0xAF, 0x57, 0x2B, 0x15, 0x8A, 0xC5, 0xE2, 0xF1, 0xF8, 0x7C, 0x3E, 0x9F, 0x4F, 0x27, 0x13, 0x09, 0x84, 0x42, 0xA1, 0xD0, 0x68, 0x34, 0x1A }; -static const uint8_t cs4236b_eeprom[8224] = { +static const uint8_t cs4236_default[] = { // clang-format off /* Chip configuration */ - 0x55, 0xbb, /* magic */ - 0x00, 0x00, /* length */ 0x00, 0x03, /* CD-ROM and modem decode */ 0x80, /* misc. config */ 0x80, /* global config */ - 0x0b, /* chip ID */ + 0x0b, /* [code base byte (CS4236B+)] / reserved (CS4236) */ 0x20, 0x04, 0x08, 0x10, 0x80, 0x00, 0x00, /* reserved */ 0x00, /* external decode length */ 0x48, /* reserved */ 0x75, 0xb9, 0xfc, /* IRQ routing */ 0x10, 0x03, /* DMA routing */ - /* PnP resources */ - 0x00 + /* Default PnP data */ + 0x0e, 0x63, 0x42, 0x36, 0xff, 0xff, 0xff, 0xff, 0x00 /* hinted by documentation to be just the header */ // clang-format on }; @@ -97,6 +123,7 @@ typedef struct cs423x_t { uint16_t ram_addr; uint16_t eeprom_size : 11; uint16_t pnp_offset; + uint16_t pnp_size; uint8_t type; uint8_t ad1848_type; uint8_t regs[8]; @@ -117,8 +144,10 @@ typedef struct cs423x_t { } cs423x_t; static void cs423x_slam_enable(cs423x_t *dev, uint8_t enable); +static void cs423x_ctxswitch_write(uint16_t addr, UNUSED(uint8_t val), void *priv); static void cs423x_pnp_enable(cs423x_t *dev, uint8_t update_rom, uint8_t update_hwconfig); static void cs423x_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *priv); +static void cs423x_reset(void *priv); static void cs423x_nvram(cs423x_t *dev, uint8_t save) @@ -130,6 +159,8 @@ cs423x_nvram(cs423x_t *dev, uint8_t save) else (void) !fread(dev->eeprom_data, sizeof(dev->eeprom_data), 1, fp); fclose(fp); + } else { + cs423x_log("CS423x: EEPROM data %s failed\n", save ? "save" : "load"); } } @@ -147,17 +178,32 @@ cs423x_read(uint16_t addr, void *priv) ret |= 0x04; break; - case 4: /* Control Indirect Data Register */ - ret = dev->indirect_regs[dev->regs[3]]; + case 3: /* Control Indirect Access Register (CS4236B+) */ + /* Intel VS440FX BIOS tells CS4236 from CS4232 through the upper bits. Setting them is enough. */ + if (dev->type >= CRYSTAL_CS4236) + ret |= 0xf0; + break; + + case 4: /* Control Indirect Data Register (CS4236B+) / Control Data Register (CS4236) */ + if (dev->type >= CRYSTAL_CS4236B) + ret = dev->indirect_regs[dev->regs[3]]; break; case 5: /* Control/RAM Access */ - /* Reading RAM is undocumented; the Windows drivers do so. */ - if (dev->ram_dl == 3) - ret = dev->ram_data[dev->ram_addr++]; + /* Reading RAM is undocumented, but performed by: + - Windows drivers (unknown purpose) + - Intel VS440FX BIOS (PnP ROM checksum recalculation) */ + if (dev->ram_dl == CRYSTAL_RAM_DATA) { + ret = dev->ram_data[dev->ram_addr]; + cs423x_log("CS423x: RAM read(%04X) = %02X\n", dev->ram_addr, ret); + dev->ram_addr++; + } break; - case 7: /* Global Status */ + case 7: /* Global Status (CS4236+) */ + if (dev->type < CRYSTAL_CS4236) + break; + /* Context switching: take active context and interrupt flag, then clear interrupt flag. */ ret &= 0xc0; dev->regs[7] &= 0x80; @@ -175,6 +221,8 @@ cs423x_read(uint16_t addr, void *priv) break; } + cs423x_log("CS423x: read(%X) = %02X\n", reg, ret); + return ret; } @@ -182,53 +230,86 @@ static void cs423x_write(uint16_t addr, uint8_t val, void *priv) { cs423x_t *dev = (cs423x_t *) priv; - uint8_t reg = addr & 0x07; + uint8_t reg = addr & 7; + + cs423x_log("CS423x: write(%X, %02X)\n", reg, val); switch (reg) { + case 0: /* Joystick and Power Control */ + if (dev->type <= CRYSTAL_CS4232) + val &= 0xeb; + if ((dev->type >= CRYSTAL_CS4235) && (addr == 0) && (val & 0x08)) { + /* CS4235+ through X26 backdoor only (hence the addr check): WSS off (one-way trip?) */ + io_removehandler(dev->wss_base, 4, ad1848_read, NULL, NULL, ad1848_write, NULL, NULL, &dev->ad1848); + io_removehandler(dev->wss_base, 4, NULL, NULL, NULL, cs423x_ctxswitch_write, NULL, NULL, dev); + dev->wss_base = 0; + } + break; + case 1: /* EEPROM Interface */ + if (dev->type <= CRYSTAL_CS4232) + val &= 0x37; if (val & 0x04) i2c_gpio_set(dev->i2c, val & 0x01, val & 0x02); break; - case 3: /* Control Indirect Access Register */ + case 2: /* Block Power Down (CS4236+) */ + if (dev->type < CRYSTAL_CS4236) + return; + break; + + case 3: /* Control Indirect Access Register (CS4236B+) */ + if (dev->type < CRYSTAL_CS4236) /* must be writable on CS4236 for the aforementioned VS440FX BIOS check */ + return; val &= 0x0f; break; - case 4: /* Control Indirect Data Register */ + case 4: /* Control Indirect Data Register (CS4236B+) / Control Data Register (CS4236) */ + if (dev->type < CRYSTAL_CS4236) { + return; + } else if (dev->type == CRYSTAL_CS4236) { + val &= 0x40; + break; + } switch (dev->regs[3] & 0x0f) { case 0: /* WSS Master Control */ - if (val & 0x80) + if ((dev->type < CRYSTAL_CS4235) && (val & 0x80)) ad1848_init(&dev->ad1848, dev->ad1848_type); val = 0x00; break; - case 1: /* Version / Chip ID */ - case 7: /* Reserved */ - case 9 ... 15: /* unspecified */ + case 1: /* Version / Chip ID */ + case 7: /* Reserved */ + case 10 ... 15: /* unspecified */ return; - case 2: /* 3D Space and {Center|Volume} */ - case 6: /* Upper Channel Status */ + case 2: /* 3D Space and {Center|Volume} (CS4237B+) */ if (dev->type < CRYSTAL_CS4237B) return; break; - case 3: /* 3D Enable */ + case 3: /* 3D Enable (CS4237B+) */ if (dev->type < CRYSTAL_CS4237B) return; val &= 0xe0; break; - case 4: /* Consumer Serial Port Enable */ + case 4: /* Consumer Serial Port Enable (CS423[78]B, unused on CS4235+) */ if (dev->type < CRYSTAL_CS4237B) return; val &= 0xf0; break; - case 5: /* Lower Channel Status */ + case 5: /* Lower Channel Status (CS423[78]B, unused on CS4235+) */ + if (dev->type < CRYSTAL_CS4237B) + return; + if (dev->type < CRYSTAL_CS4235) /* bit 0 changed from reserved to unused on CS4235 */ + val &= 0xfe; + break; + + case 6: /* Upper Channel Status (CS423[78]B, unused on CS4235+) */ if (dev->type < CRYSTAL_CS4237B) return; - val &= 0xfe; break; case 8: /* CS9236 Wavetable Control */ @@ -240,6 +321,16 @@ cs423x_write(uint16_t addr, uint8_t val, void *priv) ad1848_updatevolmask(&dev->ad1848); break; + case 9: /* Power Management (CS4235+) */ + if (dev->type < CRYSTAL_CS4235) + return; + if ((dev->indirect_regs[dev->regs[3]] & 0x80) && !(val & 0x80)) { + cs423x_reset(dev); + return; + } + val &= 0x83; + break; + default: break; } @@ -248,7 +339,7 @@ cs423x_write(uint16_t addr, uint8_t val, void *priv) case 5: /* Control/RAM Access */ switch (dev->ram_dl) { - case 0: /* commands */ + case CRYSTAL_RAM_CMD: /* commands */ switch (val) { case 0x55: /* Disable PnP Key */ dev->pnp_enable = 0; @@ -266,7 +357,7 @@ cs423x_write(uint16_t addr, uint8_t val, void *priv) break; case 0xaa: /* Download RAM */ - dev->ram_dl = 1; + dev->ram_dl = CRYSTAL_RAM_ADDR_LO; break; default: @@ -274,17 +365,19 @@ cs423x_write(uint16_t addr, uint8_t val, void *priv) } break; - case 1: /* low address byte */ + case CRYSTAL_RAM_ADDR_LO: /* low address byte */ dev->ram_addr = val; - dev->ram_dl++; + dev->ram_dl = CRYSTAL_RAM_ADDR_HI; break; - case 2: /* high address byte */ - dev->ram_addr |= (val << 8); - dev->ram_dl++; + case CRYSTAL_RAM_ADDR_HI: /* high address byte */ + dev->ram_addr |= val << 8; + dev->ram_dl = CRYSTAL_RAM_DATA; + cs423x_log("CS423x: RAM start(%04X)\n", dev->ram_addr); break; - case 3: /* data */ + case CRYSTAL_RAM_DATA: /* data */ + cs423x_log("CS423x: RAM write(%04X, %02X)\n", dev->ram_addr, val); dev->ram_data[dev->ram_addr++] = val; break; @@ -296,14 +389,16 @@ cs423x_write(uint16_t addr, uint8_t val, void *priv) case 6: /* RAM Access End */ /* TriGem Delhi-III BIOS writes undocumented value 0x40 instead of 0x00. */ if ((val == 0x00) || (val == 0x40)) { - dev->ram_dl = 0; + cs423x_log("CS423x: RAM end\n"); + dev->ram_dl = CRYSTAL_RAM_CMD; /* Update PnP state and resource data. */ + dev->pnp_size = (dev->type >= CRYSTAL_CS4236) ? 384 : 256; /* we don't know the length */ cs423x_pnp_enable(dev, 1, 0); } break; - case 7: /* Global Status */ + case 7: /* Global Status (CS4236+) */ return; default: @@ -319,6 +414,9 @@ cs423x_slam_write(UNUSED(uint16_t addr), uint8_t val, void *priv) cs423x_t *dev = (cs423x_t *) priv; uint8_t idx; + if ((dev->slam_state != CRYSTAL_SLAM_NONE) || (val == slam_init_key[dev->key_pos])) /* cut down on ISAPnP-related noise */ + cs423x_log("CS423x: slam_write(%02X)\n", val); + switch (dev->slam_state) { case CRYSTAL_SLAM_NONE: /* Not in SLAM: read and compare Crystal key. */ @@ -333,6 +431,7 @@ cs423x_slam_write(UNUSED(uint16_t addr), uint8_t val, void *priv) } /* Enter SLAM. */ + cs423x_log("CS423x: SLAM unlocked\n"); dev->slam_state = CRYSTAL_SLAM_INDEX; } } else { @@ -343,6 +442,8 @@ cs423x_slam_write(UNUSED(uint16_t addr), uint8_t val, void *priv) case CRYSTAL_SLAM_INDEX: /* Intercept the Activate Audio Device command. */ if (val == 0x79) { + cs423x_log("CS423x: Exiting SLAM\n"); + /* Apply the last logical device's configuration. */ if (dev->slam_config) { cs423x_pnp_config_changed(dev->slam_ld, dev->slam_config, dev); @@ -363,6 +464,7 @@ cs423x_slam_write(UNUSED(uint16_t addr), uint8_t val, void *priv) case CRYSTAL_SLAM_BYTE1: case CRYSTAL_SLAM_BYTE2: /* Write register value: two bytes for I/O ports, single byte otherwise. */ + cs423x_log("CS423x: SLAM write(%02X, %02X)\n", dev->slam_reg, val); switch (dev->slam_reg) { case 0x06: /* Card Select Number */ isapnp_set_csn(dev->pnp_card, val); @@ -373,10 +475,9 @@ cs423x_slam_write(UNUSED(uint16_t addr), uint8_t val, void *priv) if (dev->slam_config) cs423x_pnp_config_changed(dev->slam_ld, dev->slam_config, dev); else - dev->slam_config = (isapnp_device_config_t *) malloc(sizeof(isapnp_device_config_t)); + dev->slam_config = (isapnp_device_config_t *) calloc(1, sizeof(isapnp_device_config_t)); /* Start new logical device. */ - memset(dev->slam_config, 0, sizeof(isapnp_device_config_t)); dev->slam_ld = val; break; @@ -433,7 +534,7 @@ cs423x_slam_write(UNUSED(uint16_t addr), uint8_t val, void *priv) break; } - /* Prepare for the next register, unless a two-byte read returns above. */ + /* Prepare for the next register, unless a two-byte write returns above. */ dev->slam_state = CRYSTAL_SLAM_INDEX; break; @@ -454,8 +555,11 @@ cs423x_slam_enable(cs423x_t *dev, uint8_t enable) /* Enable SLAM if the CKD bit is not set. */ if (enable && !(dev->ram_data[0x4002] & 0x10)) { + cs423x_log("CS423x: Enabling SLAM\n"); dev->slam_enable = 1; io_sethandler(0x279, 1, NULL, NULL, NULL, cs423x_slam_write, NULL, NULL, dev); + } else { + cs423x_log("CS423x: Disabling SLAM\n"); } } @@ -471,6 +575,7 @@ cs423x_ctxswitch_write(uint16_t addr, UNUSED(uint8_t val), void *priv) /* Flip context bit. */ dev->regs[7] ^= 0x80; ctx ^= 0x80; + cs423x_log("CS423x: Context switch to %s\n", ctx ? "WSS" : "SBPro"); /* Update CD audio filter. FIXME: not thread-safe: filter function TOCTTOU in sound_cd_thread! */ @@ -501,8 +606,8 @@ cs423x_get_buffer(int32_t *buffer, int len, void *priv) /* Output audio from the WSS codec, and also the OPL if we're in charge of it. */ ad1848_update(&dev->ad1848); - /* Don't output anything if the analog section is powered down. */ - if (!(dev->indirect_regs[2] & 0xa4)) { + /* Don't output anything if the analog section or DAC is powered down. */ + if (!(dev->regs[2] & 0xb4) && !(dev->indirect_regs[9] & 0x04)) { for (int c = 0; c < len * 2; c += 2) { buffer[c] += dev->ad1848.buffer[c] / 2; buffer[c + 1] += dev->ad1848.buffer[c + 1] / 2; @@ -515,45 +620,37 @@ cs423x_get_buffer(int32_t *buffer, int len, void *priv) static void cs423x_get_music_buffer(int32_t *buffer, int len, void *priv) { - cs423x_t *dev = (cs423x_t *) priv; - int opl_wss = dev->opl_wss; - const int32_t *opl_buf = NULL; + cs423x_t *dev = (cs423x_t *) priv; /* Output audio from the WSS codec, and also the OPL if we're in charge of it. */ - if (opl_wss) - opl_buf = dev->sb->opl.update(dev->sb->opl.priv); + if (dev->opl_wss) { + const int32_t *opl_buf = dev->sb->opl.update(dev->sb->opl.priv); - /* Don't output anything if the analog section is powered down. */ - if (!(dev->indirect_regs[2] & 0xa4)) { - for (int c = 0; c < len * 2; c += 2) { - if (opl_wss) { + /* Don't output anything if the analog section, DAC (DAC2 instead on CS4235+) or FM synth is powered down. */ + uint8_t bpd_mask = (dev->type >= CRYSTAL_CS4235) ? 0xb1 : 0xb5; + if (!(dev->regs[2] & bpd_mask) && !(dev->indirect_regs[9] & 0x06)) { + for (int c = 0; c < len * 2; c += 2) { buffer[c] += (opl_buf[c] * dev->ad1848.fm_vol_l) >> 16; buffer[c + 1] += (opl_buf[c + 1] * dev->ad1848.fm_vol_r) >> 16; } } - } - if (opl_wss) dev->sb->opl.reset_buffer(dev->sb->opl.priv); + } } static void cs423x_pnp_enable(cs423x_t *dev, uint8_t update_rom, uint8_t update_hwconfig) { + cs423x_log("CS423x: Updating PnP ROM=%d hwconfig=%d\n", update_rom, update_hwconfig); + if (dev->pnp_card) { /* Update PnP resource data if requested. */ if (update_rom) - isapnp_update_card_rom(dev->pnp_card, &dev->ram_data[dev->pnp_offset], 384); + isapnp_update_card_rom(dev->pnp_card, &dev->ram_data[dev->pnp_offset], dev->pnp_size); /* Disable PnP key if the PKD bit is set, or if it was disabled by command 0x55. */ - /* 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. */ -#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"); } /* Update some register bits based on the config data in RAM if requested. */ @@ -568,7 +665,7 @@ cs423x_pnp_enable(cs423x_t *dev, uint8_t update_rom, uint8_t update_hwconfig) } /* Update SPS. */ - if (dev->type != CRYSTAL_CS4235) { + if ((dev->type >= CRYSTAL_CS4236B) && (dev->type <= CRYSTAL_CS4238B)) { if (dev->ram_data[0x4003] & 0x04) dev->indirect_regs[8] |= 0x04; else @@ -581,6 +678,20 @@ cs423x_pnp_enable(cs423x_t *dev, uint8_t update_rom, uint8_t update_hwconfig) else dev->ad1848.xregs[4] &= ~0x10; + if (dev->type == CRYSTAL_CS4236) { + /* Update VCEN. */ + if (dev->ram_data[0x4002] & 0x04) + dev->regs[4] |= 0x40; + else + dev->regs[4] &= ~0x40; + } + + if (dev->type >= CRYSTAL_CS4235) { + /* Update X18 and X19 values. */ + dev->ad1848.xregs[18] = (dev->ad1848.xregs[18] & ~0x3e) | (dev->ram_data[0x400b] & 0x3e); + dev->ad1848.xregs[19] = dev->ram_data[0x4005]; + } + /* Inform WSS codec of the changes. */ ad1848_updatevolmask(&dev->ad1848); } @@ -689,6 +800,34 @@ cs423x_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *priv } } +static void +cs423x_load_defaults(cs423x_t *dev, uint8_t *dest) +{ + switch (dev->type) { + case CRYSTAL_CS4236: + case CRYSTAL_CS4236B: + case CRYSTAL_CS4237B: + case CRYSTAL_CS4238B: + case CRYSTAL_CS4235: + case CRYSTAL_CS4239: + memcpy(dest, cs4236_default, sizeof(cs4236_default)); + dev->pnp_size = 9; /* header-only PnP ROM size */ + + switch (dev->type) { + case CRYSTAL_CS4236: + dest[4] = 0x43; /* code base byte */ + break; + + case CRYSTAL_CS4235: + case CRYSTAL_CS4239: + dest[4] = 0x05; /* code base byte */ + dest[12] = 0x08; /* external decode length */ + break; + } + break; + } +} + static void cs423x_reset(void *priv) { @@ -697,9 +836,20 @@ cs423x_reset(void *priv) /* Clear RAM. */ memset(dev->ram_data, 0, sizeof(dev->ram_data)); + /* Load default configuration data to RAM. */ + cs423x_load_defaults(dev, &dev->ram_data[0x4000]); + if (dev->eeprom) { - /* Load EEPROM data to RAM. */ - memcpy(&dev->ram_data[0x4000], &dev->eeprom_data[4], MIN(384, ((dev->eeprom_data[2] << 8) | dev->eeprom_data[3]) - 4)); + /* Load EEPROM data to RAM if the magic bytes are present. */ + if ((dev->eeprom_data[0] == 0x55) && (dev->eeprom_data[1] == 0xbb)) { + cs423x_log("CS423x: EEPROM data valid, loading to RAM\n"); + dev->pnp_size = (dev->eeprom_data[2] << 8) | dev->eeprom_data[3]; + if (dev->pnp_size > 384) + dev->pnp_size = 384; + memcpy(&dev->ram_data[0x4000], &dev->eeprom_data[4], sizeof(dev->eeprom_data) - 4); + } else { + cs423x_log("CS423x: EEPROM data invalid, ignoring\n"); + } /* Save EEPROM contents to file. */ cs423x_nvram(dev, 1); @@ -729,45 +879,60 @@ cs423x_reset(void *priv) static void * cs423x_init(const device_t *info) { - cs423x_t *dev = malloc(sizeof(cs423x_t)); - memset(dev, 0, sizeof(cs423x_t)); + cs423x_t *dev = calloc(1, sizeof(cs423x_t)); /* Initialize model-specific data. */ dev->type = info->local & 0xff; + cs423x_log("CS423x: init(%02X)\n", dev->type); switch (dev->type) { - case CRYSTAL_CS4235: + case CRYSTAL_CS4236: case CRYSTAL_CS4236B: case CRYSTAL_CS4237B: case CRYSTAL_CS4238B: - /* Same WSS codec and EEPROM structure. */ - dev->ad1848_type = (dev->type == CRYSTAL_CS4235) ? AD1848_TYPE_CS4235 : AD1848_TYPE_CS4236; - dev->pnp_offset = 0x4013; + case CRYSTAL_CS4235: + case CRYSTAL_CS4239: + /* Different WSS codec families. */ + dev->ad1848_type = (dev->type >= CRYSTAL_CS4235) ? AD1848_TYPE_CS4235 : ((dev->type >= CRYSTAL_CS4236B) ? AD1848_TYPE_CS4236B : AD1848_TYPE_CS4236); - /* Different Chip Version and ID registers, which shouldn't be reset by ad1848_init */ + /* Different Chip Version and ID values (N/A on CS4236), which shouldn't be reset by ad1848_init. */ dev->ad1848.xregs[25] = dev->type; - if (!(info->local & CRYSTAL_NOEEPROM)) { - /* Load EEPROM contents from template. */ - memcpy(dev->eeprom_data, cs4236b_eeprom, sizeof(cs4236b_eeprom)); + /* Same EEPROM structure. */ + dev->pnp_offset = 0x4013; + if (!(info->local & CRYSTAL_NOEEPROM)) { + /* Start a new EEPROM with the default configuration data. */ + cs423x_load_defaults(dev, &dev->eeprom_data[4]); + + /* Load PnP resource data ROM. */ FILE *fp = rom_fopen(PNP_ROM_CS4236B, "rb"); if (fp) { - (void) !fread(&(dev->eeprom_data[23]), 1, 8201, fp); + uint16_t eeprom_pnp_offset = (dev->pnp_offset & 0x1ff) + 4; + /* This is wrong. The header field only indicates PnP resource data length, and real chips use + it to locate the firmware patch area, but we don't need any of that, so we can get away + with pretending the whole ROM is PnP data, at least until we can get full EEPROM dumps. */ + dev->pnp_size = fread(&dev->eeprom_data[eeprom_pnp_offset], 1, sizeof(dev->eeprom_data) - eeprom_pnp_offset, fp); fclose(fp); + } else { + dev->pnp_size = 0; } - /* Set content size. */ - dev->eeprom_data[2] = sizeof(cs4236b_eeprom) >> 8; - dev->eeprom_data[3] = sizeof(cs4236b_eeprom) & 0xff; + /* Populate EEPROM header if the PnP ROM was loaded. */ + if (dev->pnp_size) { + dev->eeprom_data[0] = 0x55; + dev->eeprom_data[1] = 0xbb; + dev->eeprom_data[2] = dev->pnp_size >> 8; + dev->eeprom_data[3] = dev->pnp_size; + } - /* Set PnP card ID and EEPROM file name. */ + /* Patch PnP ROM and set EEPROM file name. */ switch (dev->type) { - case CRYSTAL_CS4235: - dev->eeprom_data[8] = 0x05; - dev->eeprom_data[16] = 0x08; - dev->eeprom_data[26] = 0x25; - dev->eeprom_data[44] = '5'; - dev->nvr_path = "cs4235.nvr"; + case CRYSTAL_CS4236: + if (dev->pnp_size) { + dev->eeprom_data[26] = 0x36; + dev->eeprom_data[45] = ' '; + } + dev->nvr_path = "cs4236.nvr"; break; case CRYSTAL_CS4236B: @@ -775,15 +940,37 @@ cs423x_init(const device_t *info) break; case CRYSTAL_CS4237B: - dev->eeprom_data[26] = 0x37; - dev->eeprom_data[44] = '7'; - dev->nvr_path = "cs4237b.nvr"; + if (dev->pnp_size) { + dev->eeprom_data[26] = 0x37; + dev->eeprom_data[44] = '7'; + } + dev->nvr_path = "cs4237b.nvr"; break; case CRYSTAL_CS4238B: - dev->eeprom_data[26] = 0x38; - dev->eeprom_data[44] = '8'; - dev->nvr_path = "cs4238b.nvr"; + if (dev->pnp_size) { + dev->eeprom_data[26] = 0x38; + dev->eeprom_data[44] = '8'; + } + dev->nvr_path = "cs4238b.nvr"; + break; + + case CRYSTAL_CS4235: + if (dev->pnp_size) { + dev->eeprom_data[26] = 0x25; + dev->eeprom_data[44] = '5'; + dev->eeprom_data[45] = ' '; + } + dev->nvr_path = "cs4235.nvr"; + break; + + case CRYSTAL_CS4239: + if (dev->pnp_size) { + dev->eeprom_data[26] = 0x29; + dev->eeprom_data[44] = '9'; + dev->eeprom_data[45] = ' '; + } + dev->nvr_path = "cs4239.nvr"; break; default: @@ -794,9 +981,9 @@ cs423x_init(const device_t *info) cs423x_nvram(dev, 0); } - /* Initialize game port. The '7B and '8B game port only responds to 6 I/O ports; the remaining - 2 ports are reserved on those chips, and probably connected to the Digital Assist feature. */ - dev->gameport = gameport_add(((dev->type == CRYSTAL_CS4235) || (dev->type == CRYSTAL_CS4236B)) ? &gameport_pnp_device : &gameport_pnp_6io_device); + /* Initialize game port. The game port on all B chips only + responds to 6 I/O ports; the remaining 2 are reserved. */ + dev->gameport = gameport_add((dev->ad1848_type == CRYSTAL_CS4236B) ? &gameport_pnp_6io_device : &gameport_pnp_device); break; @@ -807,8 +994,8 @@ cs423x_init(const device_t *info) /* Initialize I2C bus for the EEPROM. */ dev->i2c = i2c_gpio_init("nvr_cs423x"); - /* Initialize I2C EEPROM if the contents are valid. */ - if ((dev->eeprom_data[0] == 0x55) && (dev->eeprom_data[1] == 0xbb)) + /* Initialize I2C EEPROM if enabled. */ + if (!(info->local & CRYSTAL_NOEEPROM)) dev->eeprom = i2c_eeprom_init(i2c_gpio_get_bus(dev->i2c), 0x50, dev->eeprom_data, sizeof(dev->eeprom_data), 1); /* Initialize ISAPnP. */ @@ -836,6 +1023,8 @@ cs423x_close(void *priv) { cs423x_t *dev = (cs423x_t *) priv; + cs423x_log("CS423x: close()\n"); + /* Save EEPROM contents to file. */ if (dev->eeprom) { cs423x_nvram(dev, 1); @@ -864,7 +1053,7 @@ cs423x_speed_changed(void *priv) const device_t cs4235_device = { .name = "Crystal CS4235", .internal_name = "cs4235", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = CRYSTAL_CS4235, .init = cs423x_init, .close = cs423x_close, @@ -878,7 +1067,7 @@ const device_t cs4235_device = { const device_t cs4235_onboard_device = { .name = "Crystal CS4235 (On-Board)", .internal_name = "cs4235_onboard", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = CRYSTAL_CS4235 | CRYSTAL_NOEEPROM, .init = cs423x_init, .close = cs423x_close, @@ -889,10 +1078,24 @@ const device_t cs4235_onboard_device = { .config = NULL }; +const device_t cs4236_onboard_device = { + .name = "Crystal CS4236 (On-Board)", + .internal_name = "cs4236_onboard", + .flags = DEVICE_ISA16, + .local = CRYSTAL_CS4236 | CRYSTAL_NOEEPROM, + .init = cs423x_init, + .close = cs423x_close, + .reset = cs423x_reset, + .available = cs423x_available, + .speed_changed = cs423x_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + const device_t cs4236b_device = { .name = "Crystal CS4236B", .internal_name = "cs4236b", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = CRYSTAL_CS4236B, .init = cs423x_init, .close = cs423x_close, @@ -903,10 +1106,24 @@ const device_t cs4236b_device = { .config = NULL }; +const device_t cs4236b_onboard_device = { + .name = "Crystal CS4236B", + .internal_name = "cs4236b", + .flags = DEVICE_ISA16, + .local = CRYSTAL_CS4236B | CRYSTAL_NOEEPROM, + .init = cs423x_init, + .close = cs423x_close, + .reset = cs423x_reset, + .available = cs423x_available, + .speed_changed = cs423x_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + const device_t cs4237b_device = { .name = "Crystal CS4237B", .internal_name = "cs4237b", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = CRYSTAL_CS4237B, .init = cs423x_init, .close = cs423x_close, @@ -920,7 +1137,7 @@ const device_t cs4237b_device = { const device_t cs4238b_device = { .name = "Crystal CS4238B", .internal_name = "cs4238b", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = CRYSTAL_CS4238B, .init = cs423x_init, .close = cs423x_close, diff --git a/src/sound/snd_emu8k.c b/src/sound/snd_emu8k.c index 5f13d2f8e..822abeeaa 100644 --- a/src/sound/snd_emu8k.c +++ b/src/sound/snd_emu8k.c @@ -328,7 +328,7 @@ emu8k_log(const char *fmt, ...) static inline int16_t EMU8K_READ(emu8k_t *emu8k, uint32_t addr) { - const register emu8k_mem_pointers_t addrmem = { { addr } }; + register const emu8k_mem_pointers_t addrmem = { { addr } }; return emu8k->ram_pointers[addrmem.hb_address][addrmem.lw_address]; } @@ -2171,8 +2171,7 @@ emu8k_init(emu8k_t *emu8k, uint16_t emu_addr, int onboard_ram) emu8k->rom[0x7ffff] = 0; } - emu8k->empty = malloc(2 * BLOCK_SIZE_WORDS); - memset(emu8k->empty, 0, 2 * BLOCK_SIZE_WORDS); + emu8k->empty = calloc(2, BLOCK_SIZE_WORDS); int j = 0; for (; j < 0x8; j++) { @@ -2186,8 +2185,7 @@ emu8k_init(emu8k_t *emu8k, uint16_t emu_addr, int onboard_ram) /*Clip to 28MB, since that's the max that we can address. */ if (onboard_ram > 0x7000) onboard_ram = 0x7000; - emu8k->ram = malloc(onboard_ram * 1024); - memset(emu8k->ram, 0, onboard_ram * 1024); + emu8k->ram = calloc(1024, onboard_ram); const int i_end = onboard_ram >> 7; int i = 0; for (; i < i_end; i++, j++) { diff --git a/src/sound/snd_gus.c b/src/sound/snd_gus.c index b39d77708..5044c6f54 100644 --- a/src/sound/snd_gus.c +++ b/src/sound/snd_gus.c @@ -15,10 +15,9 @@ #include <86box/nmi.h> #include <86box/pic.h> #include <86box/sound.h> +#include "cpu.h" #include <86box/timer.h> -#ifdef USE_GUSMAX -# include <86box/snd_ad1848.h> -#endif /*USE_GUSMAX */ +#include <86box/snd_ad1848.h> #include <86box/plat_fallthrough.h> #include <86box/plat_unused.h> @@ -144,11 +143,9 @@ typedef struct gus_t { uint8_t usrr; -#ifdef USE_GUSMAX uint8_t max_ctrl; ad1848_t ad1848; -#endif /*USE_GUSMAX */ } gus_t; static int gus_gf1_irqs[8] = { -1, 2, 5, 3, 7, 11, 12, 15 }; @@ -256,9 +253,7 @@ writegus(uint16_t addr, uint8_t val, void *priv) int d; int old; uint16_t port; -#ifdef USE_GUSMAX uint16_t csioport; -#endif /*USE_GUSMAX */ if ((addr == 0x388) || (addr == 0x389)) port = addr; @@ -606,10 +601,9 @@ writegus(uint16_t addr, uint8_t val, void *priv) gus->irq_midi = gus->irq; } else gus->irq_midi = gus_midi_irqs[(val >> 3) & 7]; -#ifdef USE_GUSMAX + if (gus->type == GUS_MAX) ad1848_setirq(&gus->ad1848, gus->irq); -#endif /*USE_GUSMAX */ gus->sb_nmi = val & 0x80; } else { @@ -622,10 +616,9 @@ writegus(uint16_t addr, uint8_t val, void *priv) gus->dma2 = gus->dma; } else gus->dma2 = gus_dmas[(val >> 3) & 7]; -#ifdef USE_GUSMAX + if (gus->type == GUS_MAX) ad1848_setdma(&gus->ad1848, gus->dma2); -#endif /*USE_GUSMAX */ } break; case 1: @@ -683,7 +676,6 @@ writegus(uint16_t addr, uint8_t val, void *priv) break; case 0x306: case 0x706: -#ifdef USE_GUSMAX if (gus->type == GUS_MAX) { if (gus->dma >= 4) val |= 0x10; @@ -703,7 +695,6 @@ writegus(uint16_t addr, uint8_t val, void *priv) } } } -#endif /*USE_GUSMAX */ break; default: @@ -755,11 +746,9 @@ readgus(uint16_t addr, void *priv) return val; case 0x20F: -#ifdef USE_GUSMAX if (gus->type == GUS_MAX) val = 0x02; else -#endif /*USE_GUSMAX */ val = 0x00; break; @@ -878,11 +867,9 @@ readgus(uint16_t addr, void *priv) break; case 0x306: case 0x706: -#ifdef USE_GUSMAX if (gus->type == GUS_MAX) val = 0x0a; /* GUS MAX */ else -#endif /*USE_GUSMAX */ val = 0xff; /*Pre 3.7 - no mixer*/ break; @@ -1182,24 +1169,20 @@ gus_get_buffer(int32_t *buffer, int len, void *priv) { gus_t *gus = (gus_t *) priv; -#ifdef USE_GUSMAX if ((gus->type == GUS_MAX) && (gus->max_ctrl)) ad1848_update(&gus->ad1848); -#endif /*USE_GUSMAX */ + gus_update(gus); for (int c = 0; c < len * 2; c++) { -#ifdef USE_GUSMAX if ((gus->type == GUS_MAX) && (gus->max_ctrl)) buffer[c] += (int32_t) (gus->ad1848.buffer[c] / 2); -#endif /*USE_GUSMAX */ buffer[c] += (int32_t) gus->buffer[c & 1][c >> 1]; } -#ifdef USE_GUSMAX if ((gus->type == GUS_MAX) && (gus->max_ctrl)) gus->ad1848.pos = 0; -#endif /*USE_GUSMAX */ + gus->pos = 0; } @@ -1332,9 +1315,7 @@ gus_reset(void *priv) gus->usrr = 0; -#ifdef USE_GUSMAX gus->max_ctrl = 0; -#endif /*USE_GUSMAX */ gus->irq_state = 0; gus->midi_irq_state = 0; @@ -1348,12 +1329,10 @@ gus_init(UNUSED(const device_t *info)) int c; double out = 1.0; uint8_t gus_ram = device_get_config_int("gus_ram"); - gus_t *gus = malloc(sizeof(gus_t)); - memset(gus, 0x00, sizeof(gus_t)); + gus_t *gus = calloc(1, sizeof(gus_t)); gus->gus_end_ram = 1 << (18 + gus_ram); - gus->ram = (uint8_t *) malloc(gus->gus_end_ram); - memset(gus->ram, 0x00, (gus->gus_end_ram)); + gus->ram = (uint8_t *) calloc(1, gus->gus_end_ram); for (c = 0; c < 32; c++) { gus->ctrl[c] = 1; @@ -1374,7 +1353,7 @@ gus_init(UNUSED(const device_t *info)) gus->uart_out = 1; - gus->type = device_get_config_int("type"); + gus->type = info->local; gus->base = device_get_config_hex16("base"); @@ -1383,7 +1362,6 @@ gus_init(UNUSED(const device_t *info)) io_sethandler(0x0506 + gus->base, 0x0001, readgus, NULL, NULL, writegus, NULL, NULL, gus); io_sethandler(0x0388, 0x0002, readgus, NULL, NULL, writegus, NULL, NULL, gus); -#ifdef USE_GUSMAX if (gus->type == GUS_MAX) { ad1848_init(&gus->ad1848, AD1848_TYPE_CS4231); ad1848_setirq(&gus->ad1848, 5); @@ -1391,7 +1369,6 @@ gus_init(UNUSED(const device_t *info)) io_sethandler(0x10C + gus->base, 4, ad1848_read, NULL, NULL, ad1848_write, NULL, NULL, &gus->ad1848); } -#endif /*USE_GUSMAX */ timer_add(&gus->samp_timer, gus_poll_wave, gus, 1); timer_add(&gus->timer_1, gus_poll_timer_1, gus, 1); @@ -1424,101 +1401,57 @@ gus_speed_changed(void *priv) else gus->samp_latch = (uint64_t) (TIMER_USEC * (1000000.0 / gusfreqs[gus->voices - 14])); -#ifdef USE_GUSMAX if ((gus->type == GUS_MAX) && (gus->max_ctrl)) ad1848_speed_changed(&gus->ad1848); -#endif /*USE_GUSMAX */ } static const device_config_t gus_config[] = { // clang-format off { - .name = "type", - .description = "GUS type", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "Classic", - .value = GUS_CLASSIC - }, -#ifdef USE_GUSMAX - { - .description = "MAX", - .value = GUS_MAX - }, -#endif /*USE_GUSMAX */ - { NULL } + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x220, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "210H", .value = 0x210 }, + { .description = "220H", .value = 0x220 }, + { .description = "230H", .value = 0x230 }, + { .description = "240H", .value = 0x240 }, + { .description = "250H", .value = 0x250 }, + { .description = "260H", .value = 0x260 }, + { NULL } }, + .bios = { { 0 } } }, { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x220, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "210H", - .value = 0x210 - }, - { - .description = "220H", - .value = 0x220 - }, - { - .description = "230H", - .value = 0x230 - }, - { - .description = "240H", - .value = 0x240 - }, - { - .description = "250H", - .value = 0x250 - }, - { - .description = "260H", - .value = 0x260 - }, + .name = "gus_ram", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "256 KB", .value = 0 }, + { .description = "512 KB", .value = 1 }, + { .description = "1 MB", .value = 2 }, + { NULL } }, + .bios = { { 0 } } }, { - .name = "gus_ram", - "Memory size", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "256 KB", - .value = 0 - }, - { - .description = "512 KB", - .value = 1 - }, - { - .description = "1 MB", - .value = 2 - }, - { NULL } - } - }, - { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format off @@ -1527,8 +1460,22 @@ static const device_config_t gus_config[] = { const device_t gus_device = { .name = "Gravis UltraSound", .internal_name = "gus", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 0, + .flags = DEVICE_ISA16, + .local = GUS_CLASSIC, + .init = gus_init, + .close = gus_close, + .reset = gus_reset, + .available = NULL, + .speed_changed = gus_speed_changed, + .force_redraw = NULL, + .config = gus_config +}; + +const device_t gus_max_device = { + .name = "Gravis UltraSound MAX", + .internal_name = "gusmax", + .flags = DEVICE_ISA16, + .local = GUS_MAX, .init = gus_init, .close = gus_close, .reset = gus_reset, diff --git a/src/sound/snd_lpt_dac.c b/src/sound/snd_lpt_dac.c index 8fb526f14..13a430c91 100644 --- a/src/sound/snd_lpt_dac.c +++ b/src/sound/snd_lpt_dac.c @@ -7,10 +7,10 @@ #include "cpu.h" #include <86box/86box.h> #include <86box/filters.h> +#include <86box/timer.h> #include <86box/lpt.h> #include <86box/machine.h> #include <86box/sound.h> -#include <86box/timer.h> #include <86box/plat_unused.h> typedef struct lpt_dac_t { @@ -50,6 +50,14 @@ dac_write_data(uint8_t val, void *priv) dac_update(lpt_dac); } +static void +dac_strobe(uint8_t old, uint8_t val, void *priv) +{ + lpt_dac_t *lpt_dac = (lpt_dac_t *) priv; + + lpt_dac->channel = val; +} + static void dac_write_ctrl(uint8_t val, void *priv) { @@ -82,8 +90,7 @@ dac_get_buffer(int32_t *buffer, int len, void *priv) static void * dac_init(void *lpt) { - lpt_dac_t *lpt_dac = malloc(sizeof(lpt_dac_t)); - memset(lpt_dac, 0, sizeof(lpt_dac_t)); + lpt_dac_t *lpt_dac = calloc(1, sizeof(lpt_dac_t)); lpt_dac->lpt = lpt; @@ -110,25 +117,31 @@ dac_close(void *priv) } const lpt_device_t lpt_dac_device = { - .name = "LPT DAC / Covox Speech Thing", - .internal_name = "lpt_dac", - .init = dac_init, - .close = dac_close, - .write_data = dac_write_data, - .write_ctrl = dac_write_ctrl, - .read_data = NULL, - .read_status = dac_read_status, - .read_ctrl = NULL + .name = "LPT DAC / Covox Speech Thing", + .internal_name = "lpt_dac", + .init = dac_init, + .close = dac_close, + .write_data = dac_write_data, + .write_ctrl = dac_write_ctrl, + .autofeed = NULL, + .strobe = dac_strobe, + .read_status = dac_read_status, + .read_ctrl = NULL, + .epp_write_data = NULL, + .epp_request_read = NULL }; const lpt_device_t lpt_dac_stereo_device = { - .name = "Stereo LPT DAC", - .internal_name = "lpt_dac_stereo", - .init = dac_stereo_init, - .close = dac_close, - .write_data = dac_write_data, - .write_ctrl = dac_write_ctrl, - .read_data = NULL, - .read_status = dac_read_status, - .read_ctrl = NULL + .name = "Stereo LPT DAC", + .internal_name = "lpt_dac_stereo", + .init = dac_stereo_init, + .close = dac_close, + .write_data = dac_write_data, + .write_ctrl = dac_write_ctrl, + .autofeed = NULL, + .strobe = dac_strobe, + .read_status = dac_read_status, + .read_ctrl = NULL, + .epp_write_data = NULL, + .epp_request_read = NULL }; diff --git a/src/sound/snd_lpt_dss.c b/src/sound/snd_lpt_dss.c index bd794fffb..b609e3add 100644 --- a/src/sound/snd_lpt_dss.c +++ b/src/sound/snd_lpt_dss.c @@ -7,10 +7,10 @@ #include "cpu.h" #include <86box/86box.h> #include <86box/filters.h> +#include <86box/timer.h> #include <86box/lpt.h> #include <86box/machine.h> #include <86box/sound.h> -#include <86box/timer.h> #include <86box/plat_unused.h> typedef struct dss_t { @@ -115,8 +115,7 @@ dss_callback(void *priv) static void * dss_init(void *lpt) { - dss_t *dss = malloc(sizeof(dss_t)); - memset(dss, 0, sizeof(dss_t)); + dss_t *dss = calloc(1, sizeof(dss_t)); dss->lpt = lpt; @@ -134,13 +133,16 @@ dss_close(void *priv) } const lpt_device_t dss_device = { - .name = "Disney Sound Source", - .internal_name = "dss", - .init = dss_init, - .close = dss_close, - .write_data = dss_write_data, - .write_ctrl = dss_write_ctrl, - .read_data = NULL, - .read_status = dss_read_status, - .read_ctrl = NULL + .name = "Disney Sound Source", + .internal_name = "dss", + .init = dss_init, + .close = dss_close, + .write_data = dss_write_data, + .autofeed = NULL, + .strobe = NULL, + .write_ctrl = dss_write_ctrl, + .read_status = dss_read_status, + .read_ctrl = NULL, + .epp_write_data = NULL, + .epp_request_read = NULL }; diff --git a/src/sound/snd_mmb.c b/src/sound/snd_mmb.c new file mode 100644 index 000000000..35a72efbc --- /dev/null +++ b/src/sound/snd_mmb.c @@ -0,0 +1,339 @@ +/* + * 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. + * + * Mindscape Music Board emulation. + * + * Authors: Roy Baer, + * Jasmine Iwanek, + * + * Copyright 2025 Roy Baer. + * Copyright 2025 Jasmine Iwanek. + */ +#include +#include +#include +#include +#include +#define HAVE_STDARG_H +#include <86box/86box.h> +#include <86box/device.h> +#include <86box/io.h> +#include <86box/sound.h> +//#i nclude "cpu.h" +#include "ayumi/ayumi.h" +#include <86box/snd_mmb.h> +#include <86box/plat_unused.h> + +#ifdef ENABLE_MMB_LOG +int mmb_do_log = ENABLE_MMB_LOG; + +static void +mmb_log(const char *fmt, ...) +{ + va_list ap; + + if (mmb_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define mmb_log(fmt, ...) +#endif + +void +mmb_update(mmb_t *mmb) +{ + for (; mmb->pos < sound_pos_global; mmb->pos++) { + ayumi_process(&mmb->first.chip); + ayumi_process(&mmb->second.chip); + + ayumi_remove_dc(&mmb->first.chip); + ayumi_remove_dc(&mmb->second.chip); + + mmb->buffer[mmb->pos << 1] = (mmb->first.chip.left + mmb->second.chip.left) * 16000; + mmb->buffer[(mmb->pos << 1) + 1] = (mmb->first.chip.right + mmb->second.chip.right) * 16000; + } +} + +void +mmb_get_buffer(int32_t *buffer, int len, void *priv) +{ + mmb_t *mmb = (mmb_t *) priv; + + mmb_update(mmb); + + for (int c = 0; c < len * 2; c++) + buffer[c] += mmb->buffer[c]; + + mmb->pos = 0; +} + +void +mmb_write(uint16_t addr, uint8_t val, void *priv) +{ + mmb_t *mmb = (mmb_t *) priv; + + mmb_update(mmb); + + mmb_log("mmb_write(%04X): activity now: %02X\n", addr, val); + + switch (addr & 3) { + case 0: + mmb->first.index = val; + break; + case 2: + mmb->second.index = val; + break; + case 1: + case 3: + { + ay_3_891x_t *ay = ((addr & 2) == 0) ? &mmb->first : &mmb->second; + + switch (ay->index) { + case 0: + ay->regs[0] = val; + ayumi_set_tone(&ay->chip, 0, (ay->regs[1] << 8) | ay->regs[0]); + break; + case 1: + ay->regs[1] = val & 0xf; + ayumi_set_tone(&ay->chip, 0, (ay->regs[1] << 8) | ay->regs[0]); + break; + case 2: + ay->regs[2] = val; + ayumi_set_tone(&ay->chip, 1, (ay->regs[3] << 8) | ay->regs[2]); + break; + case 3: + ay->regs[3] = val & 0xf; + ayumi_set_tone(&ay->chip, 1, (ay->regs[3] << 8) | ay->regs[2]); + break; + case 4: + ay->regs[4] = val; + ayumi_set_tone(&ay->chip, 2, (ay->regs[5] << 8) | ay->regs[4]); + break; + case 5: + ay->regs[5] = val & 0xf; + ayumi_set_tone(&ay->chip, 2, (ay->regs[5] << 8) | ay->regs[4]); + break; + case 6: + ay->regs[6] = val & 0x1f; + ayumi_set_noise(&ay->chip, ay->regs[6]); + break; + case 7: + ay->regs[7] = val; + ayumi_set_mixer(&ay->chip, 0, val & 1, (val >> 3) & 1, (ay->regs[8] >> 4) & 1); + ayumi_set_mixer(&ay->chip, 1, (val >> 1) & 1, (val >> 4) & 1, (ay->regs[9] >> 4) & 1); + ayumi_set_mixer(&ay->chip, 2, (val >> 2) & 1, (val >> 5) & 1, (ay->regs[10] >> 4) & 1); + break; + case 8: + ay->regs[8] = val; + ayumi_set_volume(&ay->chip, 0, val & 0xf); + ayumi_set_mixer(&ay->chip, 0, ay->regs[7] & 1, (ay->regs[7] >> 3) & 1, (val >> 4) & 1); + break; + case 9: + ay->regs[9] = val; + ayumi_set_volume(&ay->chip, 1, val & 0xf); + ayumi_set_mixer(&ay->chip, 1, (ay->regs[7] >> 1) & 1, (ay->regs[7] >> 4) & 1, (val >> 4) & 1); + break; + case 10: + ay->regs[10] = val; + ayumi_set_volume(&ay->chip, 2, val & 0xf); + ayumi_set_mixer(&ay->chip, 2, (ay->regs[7] >> 2) & 1, (ay->regs[7] >> 5) & 1, (val >> 4) & 1); + break; + case 11: + ay->regs[11] = val; + ayumi_set_envelope(&ay->chip, (ay->regs[12] >> 8) | ay->regs[11]); + break; + case 12: + ay->regs[12] = val; + ayumi_set_envelope(&ay->chip, (ay->regs[12] >> 8) | ay->regs[11]); + break; + case 13: + ay->regs[13] = val; + ayumi_set_envelope_shape(&ay->chip, val & 0xf); + break; + case 14: + ay->regs[14] = val; + break; + case 15: + ay->regs[15] = val; + break; + + default: + break; + } + break; + } + + default: + break; + } +} + +uint8_t +mmb_read(uint16_t addr, void *priv) +{ + mmb_t *mmb = (mmb_t *) priv; + ay_3_891x_t *ay = ((addr & 2) == 0) ? &mmb->first : &mmb->second; + uint8_t ret = 0; + + switch (ay->index) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: + ret = ay->regs[ay->index]; + break; + case 14: + if (ay->regs[7] & 0x40) + ret = ay->regs[14]; + break; + case 15: + if (ay->regs[7] & 0x80) + ret = ay->regs[15]; + break; + + default: + break; + } + + mmb_log("mmb_read(%04X): activity now: %02X\n", addr, ret); + + return ret; +} + +void * +mmb_init(UNUSED(const device_t *info)) +{ + mmb_t *mmb = calloc(1, sizeof(mmb_t)); +# if 0 + uint16_t addr = (device_get_config_int("addr96") << 6) | (device_get_config_int("addr52") << 2); +#else + uint16_t addr = 0x300; + +#endif + sound_add_handler(mmb_get_buffer, mmb); + + ayumi_configure(&mmb->first.chip, 0, MMB_CLOCK, MMB_FREQ); + ayumi_configure(&mmb->second.chip, 0, MMB_CLOCK, MMB_FREQ); + + for (uint8_t i = 0; i < 3; i++) { + ayumi_set_pan(&mmb->first.chip, i, 0.5, 1); + ayumi_set_pan(&mmb->second.chip, i, 0.5, 1); + } + + io_sethandler(addr, 0x0004, + mmb_read, NULL, NULL, + mmb_write, NULL, NULL, + mmb); + + return mmb; +} + +void +mmb_close(void *priv) +{ + mmb_t *mmb = (mmb_t *) priv; + + free(mmb); +} + +// clang-format off +#if 0 +static device_config_t mmb_config[] = { + { + .name = "addr96", + .description = "Base address A9...A6", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 12, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "0000", .value = 0 }, + { .description = "0001", .value = 1 }, + { .description = "0010", .value = 2 }, + { .description = "0011", .value = 3 }, + { .description = "0100", .value = 4 }, + { .description = "0101", .value = 5 }, + { .description = "0110", .value = 6 }, + { .description = "0111", .value = 7 }, + { .description = "1000", .value = 8 }, + { .description = "1001", .value = 9 }, + { .description = "1010", .value = 10 }, + { .description = "1011", .value = 11 }, + { .description = "1100", .value = 12 }, + { .description = "1101", .value = 13 }, + { .description = "1110", .value = 14 }, + { .description = "1111", .value = 15 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { + .name = "addr52", + .description = "Base address A5...A2", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "0000", .value = 0 }, + { .description = "0001", .value = 1 }, + { .description = "0010", .value = 2 }, + { .description = "0011", .value = 3 }, + { .description = "0100", .value = 4 }, + { .description = "0101", .value = 5 }, + { .description = "0110", .value = 6 }, + { .description = "0111", .value = 7 }, + { .description = "1000", .value = 8 }, + { .description = "1001", .value = 9 }, + { .description = "1010", .value = 10 }, + { .description = "1011", .value = 11 }, + { .description = "1100", .value = 12 }, + { .description = "1101", .value = 13 }, + { .description = "1110", .value = 14 }, + { .description = "1111", .value = 15 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { .type = CONFIG_END } +}; +#endif +// clang-format on + +const device_t mmb_device = { + .name = "Mindscape Music Board", + .internal_name = "mmb", + .flags = DEVICE_ISA, + .local = 0, + .init = mmb_init, + .close = mmb_close, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, +#if 0 + .config = mmb_config +#else + .config = NULL +#endif +}; diff --git a/src/sound/snd_mpu401.c b/src/sound/snd_mpu401.c index 09d1757eb..bec2ed39c 100644 --- a/src/sound/snd_mpu401.c +++ b/src/sound/snd_mpu401.c @@ -1804,106 +1804,59 @@ mpu401_standalone_close(void *priv) static const device_config_t mpu401_standalone_config[] = { // clang-format off { - .name = "base", - .description = "MPU-401 Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x330, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "0x220", - .value = 0x220 - }, - { - .description = "0x230", - .value = 0x230 - }, - { - .description = "0x240", - .value = 0x240 - }, - { - .description = "0x250", - .value = 0x250 - }, - { - .description = "0x300", - .value = 0x300 - }, - { - .description = "0x320", - .value = 0x320 - }, - { - .description = "0x330", - .value = 0x330 - }, - { - .description = "0x332", - .value = 0x332 - }, - { - .description = "0x334", - .value = 0x334 - }, - { - .description = "0x336", - .value = 0x336 - }, - { - .description = "0x340", - .value = 0x340 - }, - { - .description = "0x350", - .value = 0x350 - }, - { .description = "" } - } + .name = "base", + .description = "MPU-401 Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x330, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "0x220", .value = 0x220 }, + { .description = "0x230", .value = 0x230 }, + { .description = "0x240", .value = 0x240 }, + { .description = "0x250", .value = 0x250 }, + { .description = "0x300", .value = 0x300 }, + { .description = "0x320", .value = 0x320 }, + { .description = "0x330", .value = 0x330 }, + { .description = "0x332", .value = 0x332 }, + { .description = "0x334", .value = 0x334 }, + { .description = "0x336", .value = 0x336 }, + { .description = "0x340", .value = 0x340 }, + { .description = "0x350", .value = 0x350 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "MPU-401 IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 2, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "IRQ 2", - .value = 2 - }, - { - .description = "IRQ 3", - .value = 3 - }, - { - .description = "IRQ 4", - .value = 4 - }, - { - .description = "IRQ 5", - .value = 5 - }, - { - .description = "IRQ 6", - .value = 6 - }, - { - .description = "IRQ 7", - .value = 7 - }, - { .description = "" } - } + .name = "irq", + .description = "MPU-401 IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "IRQ 2", .value = 2 }, + { .description = "IRQ 3", .value = 3 }, + { .description = "IRQ 4", .value = 4 }, + { .description = "IRQ 5", .value = 5 }, + { .description = "IRQ 6", .value = 6 }, + { .description = "IRQ 7", .value = 7 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -1912,46 +1865,34 @@ static const device_config_t mpu401_standalone_config[] = { static const device_config_t mpu401_standalone_mca_config[] = { // clang-format off { - .name = "irq", - .description = "MPU-401 IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 9, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "IRQ 3", - .value = 3 - }, - { - .description = "IRQ 4", - .value = 4 - }, - { - .description = "IRQ 5", - .value = 5 - }, - { - .description = "IRQ 6", - .value = 6 - }, - { - .description = "IRQ 7", - .value = 7 - }, - { - .description = "IRQ 9", - .value = 9 - }, - { .description = "" } - } + .name = "irq", + .description = "MPU-401 IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 9, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "IRQ 3", .value = 3 }, + { .description = "IRQ 4", .value = 4 }, + { .description = "IRQ 5", .value = 5 }, + { .description = "IRQ 6", .value = 6 }, + { .description = "IRQ 7", .value = 7 }, + { .description = "IRQ 9", .value = 9 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on diff --git a/src/sound/snd_opl2board.c b/src/sound/snd_opl2board.c index dea7752d0..632ad85f1 100644 --- a/src/sound/snd_opl2board.c +++ b/src/sound/snd_opl2board.c @@ -124,8 +124,7 @@ opl2board_device_mca_feedb(void *priv) void * opl2board_device_init(UNUSED(const device_t *info)) { - opl2board_device_t *serial = malloc(sizeof(opl2board_device_t)); - memset(serial, 0, sizeof(opl2board_device_t)); + opl2board_device_t *serial = calloc(1, sizeof(opl2board_device_t)); opl2board_device_log("opl2board_device_init\n"); fm_driver_get(FM_OPL2BOARD, &serial->opl); @@ -168,13 +167,15 @@ opl2board_device_close(void *priv) static const device_config_t opl2board_config[] = { { - .name = "host_serial_path", - .description = "Host Serial Device", - .type = CONFIG_SERPORT, + .name = "host_serial_path", + .description = "Host Serial Device", + .type = CONFIG_SERPORT, .default_string = "", - .file_filter = NULL, - .spinner = {}, - .selection = {} + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; diff --git a/src/sound/snd_opl_esfm.c b/src/sound/snd_opl_esfm.c index 993a0ec6b..b80d264d5 100644 --- a/src/sound/snd_opl_esfm.c +++ b/src/sound/snd_opl_esfm.c @@ -32,8 +32,10 @@ #include <86box/86box.h> #include <86box/sound.h> #include <86box/device.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/snd_opl.h> +#include <86box/plat_unused.h> #define RSM_FRAC 10 @@ -175,7 +177,7 @@ esfm_drv_set_do_cycles(void *priv, int8_t do_cycles) } static void * -esfm_drv_init(const device_t *info) +esfm_drv_init(UNUSED(const device_t *info)) { esfm_drv_t *dev = (esfm_drv_t *) calloc(1, sizeof(esfm_drv_t)); dev->flags = FLAG_CYCLES | FLAG_OPL3; diff --git a/src/sound/snd_opl_nuked.c b/src/sound/snd_opl_nuked.c index 03851a589..60f5ed2a6 100644 --- a/src/sound/snd_opl_nuked.c +++ b/src/sound/snd_opl_nuked.c @@ -46,6 +46,7 @@ #define HAVE_STDARG_H #include <86box/86box.h> #include <86box/sound.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/device.h> #include <86box/snd_opl.h> diff --git a/src/sound/snd_optimc.c b/src/sound/snd_optimc.c index d69986d98..d0b05741a 100644 --- a/src/sound/snd_optimc.c +++ b/src/sound/snd_optimc.c @@ -419,8 +419,7 @@ optimc_init(const device_t *info) music_add_handler(sb_get_music_buffer_sbpro, optimc->sb); sound_set_cd_audio_filter(sbpro_filter_cd_audio, optimc->sb); /* CD audio filter for the default context */ - optimc->mpu = (mpu_t *) malloc(sizeof(mpu_t)); - memset(optimc->mpu, 0, sizeof(mpu_t)); + optimc->mpu = (mpu_t *) calloc(1, sizeof(mpu_t)); mpu401_init(optimc->mpu, optimc->cur_mpu401_addr, optimc->cur_mpu401_irq, M_UART, device_get_config_int("receive_input401")); if (device_get_config_int("receive_input")) @@ -457,18 +456,26 @@ mirosound_pcm10_available(void) static const device_config_t optimc_config[] = { // clang-format off { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input401", - .description = "Receive MIDI input (MPU-401)", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "receive_input401", + .description = "Receive MIDI input (MPU-401)", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -477,7 +484,7 @@ static const device_config_t optimc_config[] = { const device_t acermagic_s20_device = { .name = "AcerMagic S20", .internal_name = "acermagic_s20", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0xE3 | OPTIMC_CS4231, .init = optimc_init, .close = optimc_close, @@ -491,7 +498,7 @@ const device_t acermagic_s20_device = { const device_t mirosound_pcm10_device = { .name = "miroSOUND PCM10", .internal_name = "mirosound_pcm10", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0xE3 | OPTIMC_OPL4, .init = optimc_init, .close = optimc_close, diff --git a/src/sound/snd_pas16.c b/src/sound/snd_pas16.c index fab2a6a75..9b82d580d 100644 --- a/src/sound/snd_pas16.c +++ b/src/sound/snd_pas16.c @@ -86,6 +86,7 @@ * Copyright 2008-2024 Sarah Walker. * Copyright 2024 Miran Grca. */ +#define _USE_MATH_DEFINES #include #include #include @@ -705,6 +706,7 @@ static uint8_t pas16_in(uint16_t port, void *priv) { pas16_t *pas16 = (pas16_t *) priv; + scsi_bus_t *scsi_bus = NULL; uint8_t ret = 0xff; port -= pas16->base; @@ -783,9 +785,18 @@ pas16_in(uint16_t port, void *priv) ret = t128_read(0x1e00, pas16->scsi); break; case 0x5c01: - if (pas16->has_scsi) + if (pas16->has_scsi) { + scsi_bus = &pas16->scsi->ncr.scsibus; /* Bits 0-6 must absolutely be set for SCSI hard disk drivers to work. */ - ret = (((pas16->scsi->ncr.dma_mode != DMA_IDLE) && (pas16->scsi->status & 0x04)) << 7) | 0x7f; + ret = (((scsi_bus->tx_mode != PIO_TX_BUS) && (pas16->scsi->status & 0x04)) << 7) | 0x7f; + if ((scsi_bus->tx_mode == PIO_TX_BUS) && !(ret & 0x80)) + ret |= 0x80; + + if ((pas16->scsi->status & 0x06) == 0x00) + ret = 0x00; + + pas16_log("%04X:%08X: Port %04x read ret=%02x, status=%02x, txmode=%x, repeat=%d, total=%d.\n", CS, cpu_state.pc, port + pas16->base, ret, pas16->scsi->status & 0x06, scsi_bus->tx_mode, scsi_bus->data_repeat, MIN(511, scsi_bus->total_len)); + } break; case 0x5c03: if (pas16->has_scsi) @@ -1182,10 +1193,12 @@ pas16_scsi_callback(void *priv) { pas16_t * pas16 = (pas16_t *) priv; t128_t * dev = pas16->scsi; + scsi_bus_t * scsi_bus = &dev->ncr.scsibus; t128_callback(pas16->scsi); - if ((dev->ncr.dma_mode != DMA_IDLE) && (dev->status & 0x04)) { + pas16_log("TimeOutStatus=%02x, t128stat=%02x.\n", pas16->timeout_status, dev->status); + if ((scsi_bus->tx_mode != PIO_TX_BUS) && (dev->status & 0x04)) { timer_stop(&pas16->scsi_timer); pas16->timeout_status &= 0x7f; } @@ -1666,7 +1679,7 @@ pas16_out(uint16_t port, uint8_t val, void *priv) - A 16-bit sample always takes two ctr_clock() ticks. */ static uint16_t -pas16_dma_channel_read(pas16_t *pas16, int channel) +pas16_dma_channel_read(pas16_t *pas16, UNUSED(int channel)) { int status; uint16_t ret; @@ -1739,7 +1752,7 @@ static uint16_t pas16_readdmaw_stereo(pas16_t *pas16) { uint16_t ret; - uint16_t ticks = (pas16->sys_conf_1 & 0x02) ? (1 + (pas16->dma < 5)) : 2; + uint16_t ticks = (pas16->sys_conf_1 & 0x02) ? (1 + (pas16->dma < 5)) : 1; ret = pas16_dma_readw(pas16, ticks); @@ -2315,8 +2328,7 @@ pas16_init(const device_t *info) fm_driver_get(FM_YMF262, &pas16->opl); sb_dsp_set_real_opl(&pas16->dsp, 1); sb_dsp_init(&pas16->dsp, SB_DSP_201, SB_SUBTYPE_DEFAULT, pas16); - pas16->mpu = (mpu_t *) malloc(sizeof(mpu_t)); - memset(pas16->mpu, 0, sizeof(mpu_t)); + pas16->mpu = (mpu_t *) calloc(1, sizeof(mpu_t)); mpu401_init(pas16->mpu, 0, 0, M_UART, device_get_config_int("receive_input401")); sb_dsp_set_mpu(&pas16->dsp, pas16->mpu); @@ -2397,25 +2409,37 @@ pas16_close(void *priv) static const device_config_t pas16_config[] = { { - .name = "control_pc_speaker", - .description = "Control PC speaker", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "control_pc_speaker", + .description = "Control PC speaker", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input401", - .description = "Receive MIDI input (MPU-401)", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "receive_input401", + .description = "Receive MIDI input (MPU-401)", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; @@ -2437,7 +2461,7 @@ const device_t pasplus_device = { const device_t pas16_device = { .name = "Pro Audio Spectrum 16", .internal_name = "pas16", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0x0f, .init = pas16_init, .close = pas16_close, @@ -2451,7 +2475,7 @@ const device_t pas16_device = { const device_t pas16d_device = { .name = "Pro Audio Spectrum 16D", .internal_name = "pas16d", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0x0c, .init = pas16_init, .close = pas16_close, diff --git a/src/sound/snd_ps1.c b/src/sound/snd_ps1.c index 531c2a369..15cad0051 100644 --- a/src/sound/snd_ps1.c +++ b/src/sound/snd_ps1.c @@ -166,8 +166,7 @@ ps1snd_get_buffer(int32_t *buffer, int len, void *priv) static void * ps1snd_init(UNUSED(const device_t *info)) { - ps1snd_t *ps1snd = malloc(sizeof(ps1snd_t)); - memset(ps1snd, 0x00, sizeof(ps1snd_t)); + ps1snd_t *ps1snd = calloc(1, sizeof(ps1snd_t)); sn76489_init(&ps1snd->sn76489, 0x0205, 0x0001, SN76496, 4000000); diff --git a/src/sound/snd_pssj.c b/src/sound/snd_pssj.c index 657f94b01..7de8ec824 100644 --- a/src/sound/snd_pssj.c +++ b/src/sound/snd_pssj.c @@ -193,8 +193,7 @@ pssj_get_buffer(int32_t *buffer, int len, void *priv) void * pssj_init(UNUSED(const device_t *info)) { - pssj_t *pssj = malloc(sizeof(pssj_t)); - memset(pssj, 0, sizeof(pssj_t)); + pssj_t *pssj = calloc(1, sizeof(pssj_t)); sn76489_init(&pssj->sn76489, 0x00c0, 0x0004, PSSJ, 3579545); @@ -208,8 +207,7 @@ pssj_init(UNUSED(const device_t *info)) void * pssj_1e0_init(UNUSED(const device_t *info)) { - pssj_t *pssj = malloc(sizeof(pssj_t)); - memset(pssj, 0, sizeof(pssj_t)); + pssj_t *pssj = calloc(1, sizeof(pssj_t)); sn76489_init(&pssj->sn76489, 0x01e0, 0x0004, PSSJ, 3579545); @@ -223,8 +221,7 @@ pssj_1e0_init(UNUSED(const device_t *info)) void * pssj_isa_init(UNUSED(const device_t *info)) { - pssj_t *pssj = malloc(sizeof(pssj_t)); - memset(pssj, 0, sizeof(pssj_t)); + pssj_t *pssj = calloc(1, sizeof(pssj_t)); uint16_t addr = device_get_config_hex16("base"); @@ -248,40 +245,23 @@ pssj_close(void *priv) static const device_config_t pssj_isa_config[] = { // clang-format off { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x2C0, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "0x0C0", - .value = 0x0C0 - }, - { - .description = "0x0E0", - .value = 0x0E0 - }, - { - .description = "0x1C0", - .value = 0x1C0 - }, - { - .description = "0x1E0", - .value = 0x1E0 - }, - { - .description = "0x2C0", - .value = 0x2C0 - }, - { - .description = "0x2E0", - .value = 0x2E0 - }, - { .description = "" } - } + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x2C0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "0x0C0", .value = 0x0C0 }, + { .description = "0x0E0", .value = 0x0E0 }, + { .description = "0x1C0", .value = 0x1C0 }, + { .description = "0x1E0", .value = 0x1E0 }, + { .description = "0x2C0", .value = 0x2C0 }, + { .description = "0x2E0", .value = 0x2E0 }, + { .description = "" } + }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on diff --git a/src/sound/snd_resid.cpp b/src/sound/snd_resid.cpp index b9895cf7e..b0503cac2 100644 --- a/src/sound/snd_resid.cpp +++ b/src/sound/snd_resid.cpp @@ -87,10 +87,10 @@ sid_write(uint16_t addr, uint8_t val, UNUSED(void *priv)) #define CLOCK_DELTA(n) (int) (((14318180.0 * n) / 16.0) / (float) RESID_FREQ) static void -fillbuf2(int &count, int16_t *buf, int len) +fillbuf2(int &count, int16_t *buf, UNUSED(int len)) { - int c; - c = psid->sid->clock(count, buf); + int c = psid->sid->clock(count, buf); + if (!c) *buf = psid->last_sample; psid->last_sample = *buf; diff --git a/src/sound/snd_sb.c b/src/sound/snd_sb.c index 016e50c40..14726d358 100644 --- a/src/sound/snd_sb.c +++ b/src/sound/snd_sb.c @@ -39,6 +39,7 @@ #include <86box/pic.h> #include <86box/rom.h> #include <86box/sound.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/snd_sb.h> #include <86box/plat_unused.h> @@ -1417,7 +1418,7 @@ sb_ct1745_mixer_reset(sb_t *sb) } static void -ess_base_write(uint16_t addr, uint8_t val, void *priv) +ess_base_write(uint16_t addr, UNUSED(uint8_t val), void *priv) { sb_t *ess = (sb_t *) priv; @@ -1463,7 +1464,7 @@ ess_base_read(uint16_t addr, void *priv) } static void -ess_fm_midi_write(uint16_t addr, uint8_t val, void *priv) +ess_fm_midi_write(UNUSED(uint16_t addr), UNUSED(uint8_t val), void *priv) { sb_t *ess = (sb_t *) priv; @@ -1471,7 +1472,7 @@ ess_fm_midi_write(uint16_t addr, uint8_t val, void *priv) } static uint8_t -ess_fm_midi_read(uint16_t addr, void *priv) +ess_fm_midi_read(UNUSED(uint16_t addr), void *priv) { sb_t *ess = (sb_t *) priv; @@ -1726,6 +1727,7 @@ ess_mixer_read(uint16_t addr, void *priv) case 0x32: case 0x36: case 0x38: + case 0x3a: case 0x3e: ret = mixer->regs[mixer->index]; break; @@ -2089,35 +2091,39 @@ sb_vibra16s_onboard_relocate_base(uint16_t new_addr, void *priv) sb_t *sb = (sb_t *) priv; uint16_t addr = sb->dsp.sb_addr; - io_removehandler(addr, 0x0004, - sb->opl.read, NULL, NULL, - sb->opl.write, NULL, NULL, - sb->opl.priv); - io_removehandler(addr + 8, 0x0002, - sb->opl.read, NULL, NULL, - sb->opl.write, NULL, NULL, - sb->opl.priv); - io_removehandler(addr + 4, 0x0002, - sb_ct1745_mixer_read, NULL, NULL, - sb_ct1745_mixer_write, NULL, NULL, - sb); + if (addr != 0x0000) { + io_removehandler(addr, 0x0004, + sb->opl.read, NULL, NULL, + sb->opl.write, NULL, NULL, + sb->opl.priv); + io_removehandler(addr + 8, 0x0002, + sb->opl.read, NULL, NULL, + sb->opl.write, NULL, NULL, + sb->opl.priv); + io_removehandler(addr + 4, 0x0002, + sb_ct1745_mixer_read, NULL, NULL, + sb_ct1745_mixer_write, NULL, NULL, + sb); + } sb_dsp_setaddr(&sb->dsp, 0); addr = new_addr; - io_sethandler(addr, 0x0004, - sb->opl.read, NULL, NULL, - sb->opl.write, NULL, NULL, - sb->opl.priv); - io_sethandler(addr + 8, 0x0002, - sb->opl.read, NULL, NULL, - sb->opl.write, NULL, NULL, - sb->opl.priv); - io_sethandler(addr + 4, 0x0002, - sb_ct1745_mixer_read, NULL, NULL, - sb_ct1745_mixer_write, NULL, NULL, - sb); + if (addr != 0x0000) { + io_sethandler(addr, 0x0004, + sb->opl.read, NULL, NULL, + sb->opl.write, NULL, NULL, + sb->opl.priv); + io_sethandler(addr + 8, 0x0002, + sb->opl.read, NULL, NULL, + sb->opl.write, NULL, NULL, + sb->opl.priv); + io_sethandler(addr + 4, 0x0002, + sb_ct1745_mixer_read, NULL, NULL, + sb_ct1745_mixer_write, NULL, NULL, + sb); + } sb_dsp_setaddr(&sb->dsp, addr); } @@ -2592,10 +2598,10 @@ ess_soundpiper_mca_write(const int port, const uint8_t val, void *priv) ess->dsp.sb_addr = 0x0000; break; case 0x08: - ess->dsp.sb_addr = 0x0240; + ess->dsp.sb_addr = 0x0220; break; case 0x0c: - ess->dsp.sb_addr = 0x0220; + ess->dsp.sb_addr = 0x0240; break; } @@ -2749,64 +2755,59 @@ ess_chipchat_mca_write(int port, uint8_t val, void *priv) ess->pos_regs[port & 7] = val; - if (ess->pos_regs[2] & 1) { - ess->dsp.sb_addr = (ess->pos_regs[2] == 0x51) ? 0x0220 : 0x0000; + if (ess->pos_regs[2] & 0x01) { + ess->dsp.sb_addr = 0x0220; - if (ess->dsp.sb_addr != 0x0000) { - io_sethandler(ess->dsp.sb_addr, 0x0004, - ess->opl.read, NULL, NULL, - ess->opl.write, NULL, NULL, - ess->opl.priv); - io_sethandler(ess->dsp.sb_addr + 8, 0x0002, - ess->opl.read, NULL, NULL, - ess->opl.write, NULL, NULL, - ess->opl.priv); - io_sethandler(ess->dsp.sb_addr + 8, 0x0002, + io_sethandler(ess->dsp.sb_addr, 0x0004, + ess->opl.read, NULL, NULL, + ess->opl.write, NULL, NULL, + ess->opl.priv); + io_sethandler(ess->dsp.sb_addr + 8, 0x0002, + ess->opl.read, NULL, NULL, + ess->opl.write, NULL, NULL, + ess->opl.priv); + io_sethandler(ess->dsp.sb_addr + 8, 0x0002, + ess_fm_midi_read, NULL, NULL, + ess_fm_midi_write, NULL, NULL, + ess); + io_sethandler(0x0388, 0x0004, + ess->opl.read, NULL, NULL, + ess->opl.write, NULL, NULL, ess->opl.priv); + io_sethandler(0x0388, 0x0004, + ess_fm_midi_read, NULL, NULL, + ess_fm_midi_write, NULL, NULL, + ess); + io_sethandler(ess->dsp.sb_addr + 4, 0x0002, + ess_mixer_read, NULL, NULL, + ess_mixer_write, NULL, NULL, + ess); + + io_sethandler(ess->dsp.sb_addr + 2, 0x0004, + ess_base_read, NULL, NULL, + ess_base_write, NULL, NULL, + ess); + io_sethandler(ess->dsp.sb_addr + 6, 0x0001, + ess_base_read, NULL, NULL, + ess_base_write, NULL, NULL, + ess); + io_sethandler(ess->dsp.sb_addr + 0x0a, 0x0006, + ess_base_read, NULL, NULL, + ess_base_write, NULL, NULL, + ess); + + if (ess->dsp.sb_subtype == SB_SUBTYPE_ESS_ES1688) { + mpu401_change_addr(ess->mpu, 0x0330); + + io_sethandler(0x0330, 0x0002, ess_fm_midi_read, NULL, NULL, ess_fm_midi_write, NULL, NULL, ess); - io_sethandler(0x0388, 0x0004, - ess->opl.read, NULL, NULL, - ess->opl.write, NULL, NULL, ess->opl.priv); - io_sethandler(0x0388, 0x0004, - ess_fm_midi_read, NULL, NULL, - ess_fm_midi_write, NULL, NULL, - ess); - io_sethandler(ess->dsp.sb_addr + 4, 0x0004, - ess_mixer_read, NULL, NULL, - ess_mixer_write, NULL, NULL, - ess); - - io_sethandler(ess->dsp.sb_addr + 2, 0x0004, - ess_base_read, NULL, NULL, - ess_base_write, NULL, NULL, - ess); - io_sethandler(ess->dsp.sb_addr + 6, 0x0001, - ess_base_read, NULL, NULL, - ess_base_write, NULL, NULL, - ess); - io_sethandler(ess->dsp.sb_addr + 0x0a, 0x0006, - ess_base_read, NULL, NULL, - ess_base_write, NULL, NULL, - ess); - - if (ess->dsp.sb_subtype == SB_SUBTYPE_ESS_ES1688) { - mpu401_change_addr(ess->mpu, (ess->pos_regs[2] == 0x51) ? 0x0330 : 0); - - if (ess->pos_regs[2] == 0x51) - io_sethandler(0x0330, 0x0002, - ess_fm_midi_read, NULL, NULL, - ess_fm_midi_write, NULL, NULL, - ess); - } } /* DSP I/O handler is activated in sb_dsp_setaddr */ sb_dsp_setaddr(&ess->dsp, ess->dsp.sb_addr); - gameport_remap(ess->gameport, (ess->pos_regs[2] == 0x51) ? 0x200 : 0); - } + gameport_remap(ess->gameport, 0x0200); - if (ess->pos_regs[2] == 0x51) { sb_dsp_setirq(&ess->dsp, 7); mpu401_setirq(ess->mpu, 7); @@ -4081,211 +4082,165 @@ sb_speed_changed(void *priv) // clang-format off static const device_config_t sb_config[] = { { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x220, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "0x210", - .value = 0x210 - }, - { - .description = "0x220", - .value = 0x220 - }, - { - .description = "0x230", - .value = 0x230 - }, - { - .description = "0x240", - .value = 0x240 - }, - { - .description = "0x250", - .value = 0x250 - }, - { - .description = "0x260", - .value = 0x260 - }, - { .description = "" } - } + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x220, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "0x210", .value = 0x210 }, + { .description = "0x220", .value = 0x220 }, + { .description = "0x230", .value = 0x230 }, + { .description = "0x240", .value = 0x240 }, + { .description = "0x250", .value = 0x250 }, + { .description = "0x260", .value = 0x260 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 7, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "IRQ 2", - .value = 2 - }, - { - .description = "IRQ 3", - .value = 3 - }, - { - .description = "IRQ 5", - .value = 5 - }, - { - .description = "IRQ 7", - .value = 7 - }, - { .description = "" } - } + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 7, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "IRQ 2", .value = 2 }, + { .description = "IRQ 3", .value = 3 }, + { .description = "IRQ 5", .value = 5 }, + { .description = "IRQ 7", .value = 7 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "dma", - .description = "DMA", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 1, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "DMA 1", - .value = 1 - }, - { - .description = "DMA 3", - .value = 3 - }, - { .description = "" } - } + .name = "dma", + .description = "DMA", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "DMA 1", .value = 1 }, + { .description = "DMA 3", .value = 3 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "opl", - .description = "Enable OPL", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "opl", + .description = "Enable OPL", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 - }, + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t sb15_config[] = { { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x220, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "0x210", - .value = 0x210 - }, - { - .description = "0x220", - .value = 0x220 - }, - { - .description = "0x230", - .value = 0x230 - }, - { - .description = "0x240", - .value = 0x240 - }, - { - .description = "0x250", - .value = 0x250 - }, - { - .description = "0x260", - .value = 0x260 - }, - { .description = "" } - } + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x220, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "0x210", .value = 0x210 }, + { .description = "0x220", .value = 0x220 }, + { .description = "0x230", .value = 0x230 }, + { .description = "0x240", .value = 0x240 }, + { .description = "0x250", .value = 0x250 }, + { .description = "0x260", .value = 0x260 }, + { .description = "" } + }, + .bios = { { 0 } } }, { .name = "irq", .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 7, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "IRQ 2", - .value = 2 - }, - { - .description = "IRQ 3", - .value = 3 - }, - { - .description = "IRQ 5", - .value = 5 - }, - { - .description = "IRQ 7", - .value = 7 - }, - { .description = "" } - } + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 7, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "IRQ 2", .value = 2 }, + { .description = "IRQ 3", .value = 3 }, + { .description = "IRQ 5", .value = 5 }, + { .description = "IRQ 7", .value = 7 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "dma", - .description = "DMA", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 1, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "DMA 1", - .value = 1 - }, - { - .description = "DMA 3", - .value = 3 - }, - { .description = "" } - } + .name = "dma", + .description = "DMA", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "DMA 1", .value = 1 }, + { .description = "DMA 3", .value = 3 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "opl", - .description = "Enable OPL", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "opl", + .description = "Enable OPL", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "cms", - .description = "Enable CMS", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "cms", + .description = "Enable CMS", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; @@ -4294,1064 +4249,888 @@ static const device_config_t sb2_config[] = { { .name = "base", .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x220, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "0x220", - .value = 0x220 - }, - { - .description = "0x240", - .value = 0x240 - }, - { .description = "" } - } + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x220, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "0x220", .value = 0x220 }, + { .description = "0x240", .value = 0x240 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "mixaddr", - .description = "Mixer", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "Disabled", - .value = 0 - }, - { - .description = "0x250", - .value = 0x250 - }, - { - .description = "0x260", - .value = 0x260 - }, - { .description = "" } - } + .name = "mixaddr", + .description = "Mixer", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Disabled", .value = 0 }, + { .description = "0x250", .value = 0x250 }, + { .description = "0x260", .value = 0x260 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 5, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "IRQ 2", - .value = 2 - }, - { - .description = "IRQ 3", - .value = 3 - }, - { - .description = "IRQ 5", - .value = 5 - }, - { - .description = "IRQ 7", - .value = 7 - }, - { .description = "" } - } + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 5, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "IRQ 2", .value = 2 }, + { .description = "IRQ 3", .value = 3 }, + { .description = "IRQ 5", .value = 5 }, + { .description = "IRQ 7", .value = 7 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "dma", - .description = "DMA", - .type = CONFIG_SELECTION, + .name = "dma", + .description = "DMA", + .type = CONFIG_SELECTION, .default_string = "", - .default_int = 1, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "DMA 1", - .value = 1 - }, - { - .description = "DMA 3", - .value = 3 - }, - { .description = "" } - } + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "DMA 1", .value = 1 }, + { .description = "DMA 3", .value = 3 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "opl", - .description = "Enable OPL", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "opl", + .description = "Enable OPL", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "cms", - .description = "Enable CMS", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "cms", + .description = "Enable CMS", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t sb_mcv_config[] = { { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 7, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "IRQ 2", - .value = 2 - }, - { - .description = "IRQ 3", - .value = 3 - }, - { - .description = "IRQ 5", - .value = 5 - }, - { - .description = "IRQ 7", - .value = 7 - }, - { .description = "" } - } + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 7, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "IRQ 2", .value = 2 }, + { .description = "IRQ 3", .value = 3 }, + { .description = "IRQ 5", .value = 5 }, + { .description = "IRQ 7", .value = 7 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "dma", - .description = "DMA", - .type = CONFIG_SELECTION, + .name = "dma", + .description = "DMA", + .type = CONFIG_SELECTION, .default_string = "", - .default_int = 1, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "DMA 1", - .value = 1 - }, - { - .description = "DMA 3", - .value = 3 - }, - { .description = "" } - } + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "DMA 1", .value = 1 }, + { .description = "DMA 3", .value = 3 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "opl", - .description = "Enable OPL", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "opl", + .description = "Enable OPL", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t sb_pro_config[] = { { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x220, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "0x220", - .value = 0x220 - }, - { - .description = "0x240", - .value = 0x240 - }, - { .description = "" } - } + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x220, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "0x220", .value = 0x220 }, + { .description = "0x240", .value = 0x240 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 7, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "IRQ 2", - .value = 2 - }, - { - .description = "IRQ 5", - .value = 5 - }, - { - .description = "IRQ 7", - .value = 7 - }, - { - .description = "IRQ 10", - .value = 10 - }, - { .description = "" } - } + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 7, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "IRQ 2", .value = 2 }, + { .description = "IRQ 5", .value = 5 }, + { .description = "IRQ 7", .value = 7 }, + { .description = "IRQ 10", .value = 10 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "dma", - .description = "DMA", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 1, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "DMA 0", - .value = 0 - }, - { - .description = "DMA 1", - .value = 1 - }, - { - .description = "DMA 3", - .value = 3 - }, - { .description = "" } - } + .name = "dma", + .description = "DMA", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "DMA 0", .value = 0 }, + { .description = "DMA 1", .value = 1 }, + { .description = "DMA 3", .value = 3 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "opl", - .description = "Enable OPL", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "opl", + .description = "Enable OPL", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t sb_pro_mcv_config[] = { { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t sb_16_config[] = { { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x220, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "0x220", - .value = 0x220 - }, - { - .description = "0x240", - .value = 0x240 - }, - { - .description = "0x260", - .value = 0x260 - }, - { - .description = "0x280", - .value = 0x280 - }, - { .description = "" } - } + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x220, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "0x220", .value = 0x220 }, + { .description = "0x240", .value = 0x240 }, + { .description = "0x260", .value = 0x260 }, + { .description = "0x280", .value = 0x280 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "base401", - .description = "MPU-401 Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x330, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "Disabled", - .value = 0 - }, - { - .description = "0x300", - .value = 0x300 - }, - { - .description = "0x330", - .value = 0x330 - }, - { .description = "" } - } + .name = "base401", + .description = "MPU-401 Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x330, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Disabled", .value = 0 }, + { .description = "0x300", .value = 0x300 }, + { .description = "0x330", .value = 0x330 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 5, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "IRQ 2", - .value = 2 - }, - { - .description = "IRQ 5", - .value = 5 - }, - { - .description = "IRQ 7", - .value = 7 - }, - { - .description = "IRQ 10", - .value = 10 - }, - { .description = "" } - } + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 5, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "IRQ 2", .value = 2 }, + { .description = "IRQ 5", .value = 5 }, + { .description = "IRQ 7", .value = 7 }, + { .description = "IRQ 10", .value = 10 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "dma", - .description = "Low DMA", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 1, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "DMA 0", - .value = 0 - }, - { - .description = "DMA 1", - .value = 1 - }, - { - .description = "DMA 3", - .value = 3 - }, - { .description = "" } - } + .name = "dma", + .description = "Low DMA", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "DMA 0", .value = 0 }, + { .description = "DMA 1", .value = 1 }, + { .description = "DMA 3", .value = 3 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "dma16", - .description = "High DMA", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 5, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "DMA 5", - .value = 5 - }, - { - .description = "DMA 6", - .value = 6 - }, - { - .description = "DMA 7", - .value = 7 - }, - { .description = "" } - } + .name = "dma16", + .description = "High DMA", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 5, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "DMA 5", .value = 5 }, + { .description = "DMA 6", .value = 6 }, + { .description = "DMA 7", .value = 7 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "opl", - .description = "Enable OPL", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "opl", + .description = "Enable OPL", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "control_pc_speaker", - .description = "Control PC speaker", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "control_pc_speaker", + .description = "Control PC speaker", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input401", - .description = "Receive MIDI input (MPU-401)", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "receive_input401", + .description = "Receive MIDI input (MPU-401)", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t sb_16_pnp_config[] = { { - .name = "control_pc_speaker", - .description = "Control PC speaker", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "control_pc_speaker", + .description = "Control PC speaker", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input401", - .description = "Receive MIDI input (MPU-401)", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "receive_input401", + .description = "Receive MIDI input (MPU-401)", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t sb_goldfinch_config[] = { { - .name = "onboard_ram", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "None", - .value = 0 - }, - { - .description = "512 KB", - .value = 512 - }, - { - .description = "1 MB", - .value = 1024 - }, - { - .description = "2 MB", - .value = 2048 - }, - { - .description = "4 MB", - .value = 4096 - }, - { - .description = "8 MB", - .value = 8192 - }, - { - .description = "16 MB", - .value = 16384 - }, - { - .description = "28 MB", - .value = 28672 - }, - { .description = "" } - } + .name = "onboard_ram", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "None", .value = 0 }, + { .description = "512 KB", .value = 512 }, + { .description = "1 MB", .value = 1024 }, + { .description = "2 MB", .value = 2048 }, + { .description = "4 MB", .value = 4096 }, + { .description = "8 MB", .value = 8192 }, + { .description = "16 MB", .value = 16384 }, + { .description = "28 MB", .value = 28672 }, + { .description = "" } + }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t sb_32_pnp_config[] = { { - .name = "onboard_ram", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "None", - .value = 0 - }, - { - .description = "512 KB", - .value = 512 - }, - { - .description = "2 MB", - .value = 2048 - }, - { - .description = "8 MB", - .value = 8192 - }, - { - .description = "28 MB", - .value = 28672 - }, - { .description = "" } - } + .name = "onboard_ram", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "None", .value = 0 }, + { .description = "512 KB", .value = 512 }, + { .description = "2 MB", .value = 2048 }, + { .description = "8 MB", .value = 8192 }, + { .description = "28 MB", .value = 28672 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "control_pc_speaker", - .description = "Control PC speaker", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "control_pc_speaker", + .description = "Control PC speaker", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input401", - .description = "Receive MIDI input (MPU-401)", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "receive_input401", + .description = "Receive MIDI input (MPU-401)", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t sb_awe32_config[] = { { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x220, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "0x220", - .value = 0x220 - }, - { - .description = "0x240", - .value = 0x240 - }, - { - .description = "0x260", - .value = 0x260 - }, - { - .description = "0x280", - .value = 0x280 - }, - { .description = "" } - } + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x220, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "0x220", .value = 0x220 }, + { .description = "0x240", .value = 0x240 }, + { .description = "0x260", .value = 0x260 }, + { .description = "0x280", .value = 0x280 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "emu_base", - .description = "EMU8000 Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x620, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "0x620", - .value = 0x620 - }, - { - .description = "0x640", - .value = 0x640 - }, - { - .description = "0x660", - .value = 0x660 - }, - { - .description = "0x680", - .value = 0x680 - }, - { .description = ""} - } + .name = "emu_base", + .description = "EMU8000 Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x620, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "0x620", .value = 0x620 }, + { .description = "0x640", .value = 0x640 }, + { .description = "0x660", .value = 0x660 }, + { .description = "0x680", .value = 0x680 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "base401", - .description = "MPU-401 Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x330, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "Disabled", - .value = 0 - }, - { - .description = "0x300", - .value = 0x300 - }, - { - .description = "0x330", - .value = 0x330 - }, - { .description = "" } - } + .name = "base401", + .description = "MPU-401 Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x330, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Disabled", .value = 0 }, + { .description = "0x300", .value = 0x300 }, + { .description = "0x330", .value = 0x330 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "irq", - .description = "IRQ", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 5, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "IRQ 2", - .value = 2 - }, - { - .description = "IRQ 5", - .value = 5 - }, - { - .description = "IRQ 7", - .value = 7 - }, - { - .description = "IRQ 10", - .value = 10 - }, - { .description = "" } - } + .name = "irq", + .description = "IRQ", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 5, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "IRQ 2", .value = 2 }, + { .description = "IRQ 5", .value = 5 }, + { .description = "IRQ 7", .value = 7 }, + { .description = "IRQ 10", .value = 10 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "dma", - .description = "Low DMA", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 1, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "DMA 0", - .value = 0 - }, - { - .description = "DMA 1", - .value = 1 - }, - { - .description = "DMA 3", - .value = 3 - }, - { .description = "" } - } + .name = "dma", + .description = "Low DMA", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "DMA 0", .value = 0 }, + { .description = "DMA 1", .value = 1 }, + { .description = "DMA 3", .value = 3 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "dma16", - .description = "High DMA", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 5, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "DMA 5", - .value = 5 - }, - { - .description = "DMA 6", - .value = 6 - }, - { - .description = "DMA 7", - .value = 7 - }, - { .description = "" } - } + .name = "dma16", + .description = "High DMA", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 5, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "DMA 5", .value = 5 }, + { .description = "DMA 6", .value = 6 }, + { .description = "DMA 7", .value = 7 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "onboard_ram", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 512, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "None", - .value = 0 - }, - { - .description = "512 KB", - .value = 512 - }, - { - .description = "2 MB", - .value = 2048 - }, - { - .description = "8 MB", - .value = 8192 - }, - { - .description = "28 MB", - .value = 28672 - }, - { "" } - } + .name = "onboard_ram", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 512, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "None", .value = 0 }, + { .description = "512 KB", .value = 512 }, + { .description = "2 MB", .value = 2048 }, + { .description = "8 MB", .value = 8192 }, + { .description = "28 MB", .value = 28672 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "opl", - .description = "Enable OPL", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "opl", + .description = "Enable OPL", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "control_pc_speaker", - .description = "Control PC speaker", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "control_pc_speaker", + .description = "Control PC speaker", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input401", - .description = "Receive MIDI input (MPU-401)", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "receive_input401", + .description = "Receive MIDI input (MPU-401)", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t sb_awe32_pnp_config[] = { { - .name = "onboard_ram", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 512, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "None", - .value = 0 - }, - { - .description = "512 KB", - .value = 512 - }, - { - .description = "2 MB", - .value = 2048 - }, - { - .description = "8 MB", - .value = 8192 - }, - { - .description = "28 MB", - .value = 28672 - }, - { .description = "" } - } + .name = "onboard_ram", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 512, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "None", .value = 0 }, + { .description = "512 KB", .value = 512 }, + { .description = "2 MB", .value = 2048 }, + { .description = "8 MB", .value = 8192 }, + { .description = "28 MB", .value = 28672 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "control_pc_speaker", - .description = "Control PC speaker", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "control_pc_speaker", + .description = "Control PC speaker", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input401", - .description = "Receive MIDI input (MPU-401)", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "receive_input401", + .description = "Receive MIDI input (MPU-401)", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t sb_awe64_value_config[] = { { - .name = "onboard_ram", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 512, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "512 KB", - .value = 512 - }, - { - .description = "1 MB", - .value = 1024 - }, - { - .description = "2 MB", - .value = 2048 - }, - { - .description = "4 MB", - .value = 4096 - }, - { - .description = "8 MB", - .value = 8192 - }, - { - .description = "12 MB", - .value = 12288 - }, - { - .description = "16 MB", - .value = 16384 - }, - { - .description = "20 MB", - .value = 20480 - }, - { - .description = "24 MB", - .value = 24576 - }, - { - .description = "28 MB", - .value = 28672 - }, - { .description = "" } - } + .name = "onboard_ram", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 512, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "512 KB", .value = 512 }, + { .description = "1 MB", .value = 1024 }, + { .description = "2 MB", .value = 2048 }, + { .description = "4 MB", .value = 4096 }, + { .description = "8 MB", .value = 8192 }, + { .description = "12 MB", .value = 12288 }, + { .description = "16 MB", .value = 16384 }, + { .description = "20 MB", .value = 20480 }, + { .description = "24 MB", .value = 24576 }, + { .description = "28 MB", .value = 28672 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "control_pc_speaker", - .description = "Control PC speaker", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "control_pc_speaker", + .description = "Control PC speaker", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input401", - .description = "Receive MIDI input (MPU-401)", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "receive_input401", + .description = "Receive MIDI input (MPU-401)", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t sb_awe64_config[] = { { - .name = "onboard_ram", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 1024, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "1 MB", - .value = 1024 - }, - { - .description = "2 MB", - .value = 2048 - }, - { - .description = "4 MB", - .value = 4096 - }, - { - .description = "8 MB", - .value = 8192 - }, - { - .description = "12 MB", - .value = 12288 - }, - { - .description = "16 MB", - .value = 16384 - }, - { - .description = "20 MB", - .value = 20480 - }, - { - .description = "24 MB", - .value = 24576 - }, - { - .description = "28 MB", - .value = 28672 - }, - { .description = "" } - } + .name = "onboard_ram", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 1024, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "1 MB", .value = 1024 }, + { .description = "2 MB", .value = 2048 }, + { .description = "4 MB", .value = 4096 }, + { .description = "8 MB", .value = 8192 }, + { .description = "12 MB", .value = 12288 }, + { .description = "16 MB", .value = 16384 }, + { .description = "20 MB", .value = 20480 }, + { .description = "24 MB", .value = 24576 }, + { .description = "28 MB", .value = 28672 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "control_pc_speaker", - .description = "Control PC speaker", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "control_pc_speaker", + .description = "Control PC speaker", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input401", - .description = "Receive MIDI input (MPU-401)", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "receive_input401", + .description = "Receive MIDI input (MPU-401)", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t sb_awe64_gold_config[] = { { - .name = "onboard_ram", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 4096, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "4 MB", - .value = 4096 - }, - { - .description = "8 MB", - .value = 8192 - }, - { - .description = "12 MB", - .value = 12288 - }, - { - .description = "16 MB", - .value = 16384 - }, - { - .description = "20 MB", - .value = 20480 - }, - { - .description = "24 MB", - .value = 24576 - }, - { - .description = "28 MB", - .value = 28672 - }, - { .description = "" } - } + .name = "onboard_ram", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 4096, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "4 MB", .value = 4096 }, + { .description = "8 MB", .value = 8192 }, + { .description = "12 MB", .value = 12288 }, + { .description = "16 MB", .value = 16384 }, + { .description = "20 MB", .value = 20480 }, + { .description = "24 MB", .value = 24576 }, + { .description = "28 MB", .value = 28672 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "control_pc_speaker", - .description = "Control PC speaker", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "control_pc_speaker", + .description = "Control PC speaker", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input401", - .description = "Receive MIDI input (MPU-401)", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "receive_input401", + .description = "Receive MIDI input (MPU-401)", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; @@ -5361,120 +5140,80 @@ static const device_config_t ess_688_config[] = { .name = "base", .description = "Address", .type = CONFIG_HEX16, - .default_string = "", + .default_string = NULL, .default_int = 0x220, - .file_filter = "", + .file_filter = NULL, .spinner = { 0 }, .selection = { - { - .description = "0x220", - .value = 0x220 - }, - { - .description = "0x230", - .value = 0x230 - }, - { - .description = "0x240", - .value = 0x240 - }, - { - .description = "0x250", - .value = 0x250 - }, - { .description = "" } - } + { .description = "0x220", .value = 0x220 }, + { .description = "0x230", .value = 0x230 }, + { .description = "0x240", .value = 0x240 }, + { .description = "0x250", .value = 0x250 }, + { .description = "" } + }, + .bios = { { 0 } } }, { .name = "irq", .description = "IRQ", .type = CONFIG_SELECTION, - .default_string = "", + .default_string = NULL, .default_int = 5, - .file_filter = "", + .file_filter = NULL, .spinner = { 0 }, .selection = { - { - .description = "IRQ 2", - .value = 2 - }, - { - .description = "IRQ 5", - .value = 5 - }, - { - .description = "IRQ 7", - .value = 7 - }, - { - .description = "IRQ 10", - .value = 10 - }, - { .description = "" } - } + { .description = "IRQ 2", .value = 2 }, + { .description = "IRQ 5", .value = 5 }, + { .description = "IRQ 7", .value = 7 }, + { .description = "IRQ 10", .value = 10 }, + { .description = "" } + }, + .bios = { { 0 } } }, { .name = "dma", .description = "DMA", .type = CONFIG_SELECTION, - .default_string = "", + .default_string = NULL, .default_int = 1, - .file_filter = "", + .file_filter = NULL, .spinner = { 0 }, .selection = { - { - .description = "DMA 0", - .value = 0 - }, - { - .description = "DMA 1", - .value = 1 - }, - { - .description = "DMA 3", - .value = 3 - }, - { .description = "" } - } + { .description = "DMA 0", .value = 0 }, + { .description = "DMA 1", .value = 1 }, + { .description = "DMA 3", .value = 3 }, + { .description = "" } + }, + .bios = { { 0 } } }, { .name = "ide_ctrl", .description = "IDE Controller", .type = CONFIG_HEX16, - .default_string = "", + .default_string = NULL, .default_int = 0x0000, - .file_filter = "", + .file_filter = NULL, .spinner = { 0 }, .selection = { - { - .description = "Disabled", - .value = 0x0000 - }, - { - .description = "0x170, IRQ 15", - .value = 0xf170 - }, - { - .description = "0x1E8, IRQ 11", - .value = 0xb1e8 - }, - { - .description = "0x168, IRQ 9", - .value = 0x9168 - }, - { - .description = "0x168, IRQ 10", - .value = 0xa168 - }, - { .description = "" } - } + { .description = "Disabled", .value = 0x0000 }, + { .description = "0x170, IRQ 15", .value = 0xf170 }, + { .description = "0x1E8, IRQ 11", .value = 0xb1e8 }, + { .description = "0x168, IRQ 9", .value = 0x9168 }, + { .description = "0x168, IRQ 10", .value = 0xa168 }, + { .description = "" } + }, + .bios = { { 0 } } }, { .name = "receive_input", .description = "Receive MIDI input", .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; @@ -5484,170 +5223,154 @@ static const device_config_t ess_1688_config[] = { .name = "base", .description = "Address", .type = CONFIG_HEX16, - .default_string = "", + .default_string = NULL, .default_int = 0x220, - .file_filter = "", + .file_filter = NULL, .spinner = { 0 }, .selection = { - { - .description = "0x220", - .value = 0x220 - }, - { - .description = "0x230", - .value = 0x230 - }, - { - .description = "0x240", - .value = 0x240 - }, - { - .description = "0x250", - .value = 0x250 - }, - { .description = "" } - } + { .description = "0x220", .value = 0x220 }, + { .description = "0x230", .value = 0x230 }, + { .description = "0x240", .value = 0x240 }, + { .description = "0x250", .value = 0x250 }, + { .description = "" } + }, + .bios = { { 0 } } }, { .name = "irq", .description = "IRQ", .type = CONFIG_SELECTION, - .default_string = "", + .default_string = NULL, .default_int = 5, - .file_filter = "", + .file_filter = NULL, .spinner = { 0 }, .selection = { - { - .description = "IRQ 2", - .value = 2 - }, - { - .description = "IRQ 5", - .value = 5 - }, - { - .description = "IRQ 7", - .value = 7 - }, - { - .description = "IRQ 10", - .value = 10 - }, - { .description = "" } - } + { .description = "IRQ 2", .value = 2 }, + { .description = "IRQ 5", .value = 5 }, + { .description = "IRQ 7", .value = 7 }, + { .description = "IRQ 10", .value = 10 }, + { .description = "" } + }, + .bios = { { 0 } } }, { .name = "dma", .description = "DMA", .type = CONFIG_SELECTION, - .default_string = "", + .default_string = NULL, .default_int = 1, - .file_filter = "", + .file_filter = NULL, .spinner = { 0 }, .selection = { - { - .description = "DMA 0", - .value = 0 - }, - { - .description = "DMA 1", - .value = 1 - }, - { - .description = "DMA 3", - .value = 3 - }, - { .description = "" } - } + { .description = "DMA 0", .value = 0 }, + { .description = "DMA 1", .value = 1 }, + { .description = "DMA 3", .value = 3 }, + { .description = "" } + }, + .bios = { { 0 } } }, { .name = "ide_ctrl", .description = "IDE Controller", .type = CONFIG_HEX16, - .default_string = "", + .default_string = NULL, .default_int = 0x0000, - .file_filter = "", + .file_filter = NULL, .spinner = { 0 }, .selection = { - { - .description = "Disabled", - .value = 0x0000 - }, - { - .description = "0x170, IRQ 15", - .value = 0xf170 - }, - { - .description = "0x1E8, IRQ 11", - .value = 0xb1e8 - }, - { - .description = "0x168, IRQ 9", - .value = 0x9168 - }, - { - .description = "0x168, IRQ 10", - .value = 0xa168 - }, - { .description = "" } - } + { .description = "Disabled", .value = 0x0000 }, + { .description = "0x170, IRQ 15", .value = 0xf170 }, + { .description = "0x1E8, IRQ 11", .value = 0xb1e8 }, + { .description = "0x168, IRQ 9", .value = 0x9168 }, + { .description = "0x168, IRQ 10", .value = 0xa168 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "control_pc_speaker", - .description = "Control PC speaker", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "control_pc_speaker", + .description = "Control PC speaker", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input401", - .description = "Receive MIDI input (MPU-401)", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 0 + .name = "receive_input401", + .description = "Receive MIDI input (MPU-401)", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t ess_688_pnp_config[] = { { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t ess_1688_pnp_config[] = { { - .name = "control_pc_speaker", - .description = "Control PC speaker", - .type = CONFIG_BINARY, + .name = "control_pc_speaker", + .description = "Control PC speaker", + .type = CONFIG_BINARY, .default_string = "", - .default_int = 0 + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input", - .description = "Receive MIDI input", - .type = CONFIG_BINARY, + .name = "receive_input", + .description = "Receive MIDI input", + .type = CONFIG_BINARY, .default_string = "", - .default_int = 1 + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "receive_input401", - .description = "Receive MIDI input (MPU-401)", - .type = CONFIG_BINARY, + .name = "receive_input401", + .description = "Receive MIDI input (MPU-401)", + .type = CONFIG_BINARY, .default_string = "", - .default_int = 0 + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } }; @@ -5754,7 +5477,7 @@ const device_t sb_pro_mcv_device = { const device_t sb_pro_compat_device = { .name = "Sound Blaster Pro (Compatibility)", .internal_name = "sbpro_compat", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0, .init = sb_pro_compat_init, .close = sb_close, @@ -5768,7 +5491,7 @@ const device_t sb_pro_compat_device = { const device_t sb_16_device = { .name = "Sound Blaster 16", .internal_name = "sb16", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = FM_YMF262, .init = sb_16_init, .close = sb_close, @@ -5782,7 +5505,7 @@ const device_t sb_16_device = { const device_t sb_vibra16c_onboard_device = { .name = "Sound Blaster ViBRA 16C (On-Board)", .internal_name = "sb_vibra16c_onboard", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = SB_VIBRA16C, .init = sb_vibra16_pnp_init, .close = sb_close, @@ -5796,7 +5519,7 @@ const device_t sb_vibra16c_onboard_device = { const device_t sb_vibra16c_device = { .name = "Sound Blaster ViBRA 16C", .internal_name = "sb_vibra16c", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = SB_VIBRA16C, .init = sb_vibra16_pnp_init, .close = sb_close, @@ -5810,7 +5533,7 @@ const device_t sb_vibra16c_device = { const device_t sb_vibra16cl_onboard_device = { .name = "Sound Blaster ViBRA 16CL (On-Board)", .internal_name = "sb_vibra16cl_onboard", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = SB_VIBRA16CL, .init = sb_vibra16_pnp_init, .close = sb_close, @@ -5824,7 +5547,7 @@ const device_t sb_vibra16cl_onboard_device = { const device_t sb_vibra16cl_device = { .name = "Sound Blaster ViBRA 16CL", .internal_name = "sb_vibra16cl", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = SB_VIBRA16CL, .init = sb_vibra16_pnp_init, .close = sb_close, @@ -5838,7 +5561,7 @@ const device_t sb_vibra16cl_device = { const device_t sb_vibra16s_onboard_device = { .name = "Sound Blaster ViBRA 16S (On-Board)", .internal_name = "sb_vibra16s_onboard", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = FM_YMF289B, .init = sb_16_init, .close = sb_close, @@ -5852,7 +5575,7 @@ const device_t sb_vibra16s_onboard_device = { const device_t sb_vibra16s_device = { .name = "Sound Blaster ViBRA 16S", .internal_name = "sb_vibra16s", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = FM_YMF289B, .init = sb_16_init, .close = sb_close, @@ -5866,7 +5589,7 @@ const device_t sb_vibra16s_device = { const device_t sb_vibra16xv_onboard_device = { .name = "Sound Blaster ViBRA 16XV (On-Board)", .internal_name = "sb_vibra16xv_onboard", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = SB_VIBRA16XV, .init = sb_vibra16_pnp_init, .close = sb_close, @@ -5880,7 +5603,7 @@ const device_t sb_vibra16xv_onboard_device = { const device_t sb_vibra16xv_device = { .name = "Sound Blaster ViBRA 16XV", .internal_name = "sb_vibra16xv", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = SB_VIBRA16XV, .init = sb_vibra16_pnp_init, .close = sb_close, @@ -5908,12 +5631,12 @@ const device_t sb_16_reply_mca_device = { const device_t sb_16_pnp_device = { .name = "Sound Blaster 16 PnP", .internal_name = "sb16_pnp", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = SB_16_PNP_NOIDE, .init = sb_16_pnp_init, .close = sb_close, .reset = NULL, - { .available = sb_16_pnp_noide_available }, + .available = sb_16_pnp_noide_available, .speed_changed = sb_speed_changed, .force_redraw = NULL, .config = sb_16_pnp_config @@ -5922,7 +5645,7 @@ const device_t sb_16_pnp_device = { const device_t sb_16_pnp_ide_device = { .name = "Sound Blaster 16 PnP (IDE)", .internal_name = "sb16_pnp_ide", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = SB_16_PNP_IDE, .init = sb_16_pnp_init, .close = sb_close, @@ -5936,7 +5659,7 @@ const device_t sb_16_pnp_ide_device = { const device_t sb_16_compat_device = { .name = "Sound Blaster 16 (Compatibility)", .internal_name = "sb16_compat", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 1, .init = sb_16_compat_init, .close = sb_close, @@ -5950,7 +5673,7 @@ const device_t sb_16_compat_device = { const device_t sb_16_compat_nompu_device = { .name = "Sound Blaster 16 (Compatibility - MPU-401 Off)", .internal_name = "sb16_compat", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0, .init = sb_16_compat_init, .close = sb_close, @@ -5964,7 +5687,7 @@ const device_t sb_16_compat_nompu_device = { const device_t sb_goldfinch_device = { .name = "Creative EMU8000 PnP (Goldfinch)", .internal_name = "sb_goldfinch", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0, .init = sb_goldfinch_init, .close = sb_goldfinch_close, @@ -5978,7 +5701,7 @@ const device_t sb_goldfinch_device = { const device_t sb_32_pnp_device = { .name = "Sound Blaster 32 PnP", .internal_name = "sb32_pnp", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = SB_32_PNP, .init = sb_awe32_pnp_init, .close = sb_awe32_close, @@ -5992,7 +5715,7 @@ const device_t sb_32_pnp_device = { const device_t sb_awe32_device = { .name = "Sound Blaster AWE32", .internal_name = "sbawe32", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0, .init = sb_awe32_init, .close = sb_awe32_close, @@ -6006,7 +5729,7 @@ const device_t sb_awe32_device = { const device_t sb_awe32_pnp_device = { .name = "Sound Blaster AWE32 PnP", .internal_name = "sbawe32_pnp", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = SB_AWE32_PNP, .init = sb_awe32_pnp_init, .close = sb_awe32_close, @@ -6020,7 +5743,7 @@ const device_t sb_awe32_pnp_device = { const device_t sb_awe64_value_device = { .name = "Sound Blaster AWE64 Value", .internal_name = "sbawe64_value", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = SB_AWE64_VALUE, .init = sb_awe32_pnp_init, .close = sb_awe32_close, @@ -6034,12 +5757,12 @@ const device_t sb_awe64_value_device = { const device_t sb_awe64_device = { .name = "Sound Blaster AWE64", .internal_name = "sbawe64", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = SB_AWE64_NOIDE, .init = sb_awe32_pnp_init, .close = sb_awe32_close, .reset = NULL, - { .available = sb_awe64_noide_available }, + .available = sb_awe64_noide_available, .speed_changed = sb_speed_changed, .force_redraw = NULL, .config = sb_awe64_config @@ -6048,7 +5771,7 @@ const device_t sb_awe64_device = { const device_t sb_awe64_ide_device = { .name = "Sound Blaster AWE64 (IDE)", .internal_name = "sbawe64_ide", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = SB_AWE64_IDE, .init = sb_awe32_pnp_init, .close = sb_awe32_close, @@ -6062,7 +5785,7 @@ const device_t sb_awe64_ide_device = { const device_t sb_awe64_gold_device = { .name = "Sound Blaster AWE64 Gold", .internal_name = "sbawe64_gold", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = SB_AWE64_GOLD, .init = sb_awe32_pnp_init, .close = sb_awe32_close, diff --git a/src/sound/snd_sb_dsp.c b/src/sound/snd_sb_dsp.c index 9ce0b9fb7..10e5601f4 100644 --- a/src/sound/snd_sb_dsp.c +++ b/src/sound/snd_sb_dsp.c @@ -388,6 +388,7 @@ sb_update_status(sb_dsp_t *dsp, int bit, int set) { int masked = 0; + sb_dsp_log("SBIRQ8=%d, irqnum=%d, bit=%x, set=%x.\n", dsp->sb_irq8, dsp->sb_irqnum, bit, set); if (dsp->sb_irq8 || dsp->sb_irq16) return; @@ -423,6 +424,7 @@ sb_update_status(sb_dsp_t *dsp, int bit, int set) } } + sb_dsp_log("Masked=%02x.\n", masked); if (set && !masked) dsp->irq_update(dsp->irq_priv, 1); else if (!set) @@ -1039,6 +1041,8 @@ sb_ess_write_reg(sb_dsp_t *dsp, const uint8_t reg, uint8_t data) { uint8_t chg; + sb_dsp_log("ESS Write reg=%02x, val=%02x.\n", reg, data); + switch (reg) { case 0xA1: /* Extended Mode Sample Rate Generator */ { @@ -1110,6 +1114,7 @@ sb_ess_write_reg(sb_dsp_t *dsp, const uint8_t reg, uint8_t data) dsp->sb_irqnum = 10; break; } + sb_dsp_log("Legacy Audio IRQ control=%d.\n", dsp->sb_irqnum); sb_ess_update_irq_drq_readback_regs(dsp, false); break; case 0xB2: /* DRQ Control */ @@ -1131,6 +1136,7 @@ sb_ess_write_reg(sb_dsp_t *dsp, const uint8_t reg, uint8_t data) dsp->sb_8_dmanum = 3; break; } + sb_dsp_log("Legacy Audio DRQ control=%d, chg=%02x.\n", dsp->sb_8_dmanum, chg); sb_ess_update_irq_drq_readback_regs(dsp, false); if (chg & 0x40) sb_ess_update_dma_status(dsp); @@ -1876,12 +1882,12 @@ sb_write(uint16_t addr, uint8_t val, void *priv) { sb_dsp_t *dsp = (sb_dsp_t *) priv; - sb_dsp_log("[%04X:%08X] DSP: [W] %04X = %02X\n", CS, cpu_state.pc, addr, val); - /* Sound Blasters prior to Sound Blaster 16 alias the I/O ports. */ if ((dsp->sb_type < SB16_DSP_404) && (IS_NOT_ESS(dsp) || ((addr & 0xF) != 0xE))) addr &= 0xfffe; + sb_dsp_log("[%04X:%08X] DSP: [W] %04X = %02X\n", CS, cpu_state.pc, addr, val); + switch (addr & 0xF) { case 6: /* Reset */ sb_do_reset(dsp, val); @@ -1962,7 +1968,7 @@ sb_read(uint16_t addr, void *priv) uint8_t ret = 0x00; /* Sound Blasters prior to Sound Blaster 16 alias the I/O ports. */ - if ((dsp->sb_type < SB16_DSP_404) && (IS_NOT_ESS(dsp) || ((addr & 0xF) != 0xF))) + if ((dsp->sb_type < SB16_DSP_404) && (IS_NOT_ESS(dsp) || ((addr & 0xF) != 0xE))) /* Exception: ESS AudioDrive does not alias port base+0xf */ addr &= 0xfffe; @@ -2085,7 +2091,7 @@ sb_read(uint16_t addr, void *priv) break; } - sb_dsp_log("[%04X:%08X] DSP: [R] %04X = %02X\n", CS, cpu_state.pc, a, ret); + sb_dsp_log("[%04X:%08X] DSP: [R] %04X = %02X\n", CS, cpu_state.pc, addr, ret); return ret; } @@ -2319,6 +2325,7 @@ pollsb(void *priv) if (dsp->sb_8_enable && dsp->sb_pausetime < 0 && dsp->sb_8_output) { sb_dsp_update(dsp); + sb_dsp_log("8-bit format=%02x, pause=%x, length=%d.\n", dsp->sb_8_format, dsp->sb_8_pause, dsp->sb_8_length); switch (dsp->sb_8_format) { case 0x00: /* Mono unsigned */ if (!dsp->sb_8_pause) { diff --git a/src/sound/snd_sn76489.c b/src/sound/snd_sn76489.c index 8fb8db06e..569d698d5 100644 --- a/src/sound/snd_sn76489.c +++ b/src/sound/snd_sn76489.c @@ -228,8 +228,7 @@ sn76489_init(sn76489_t *sn76489, uint16_t base, uint16_t size, int type, int fre void * sn76489_device_init(UNUSED(const device_t *info)) { - sn76489_t *sn76489 = malloc(sizeof(sn76489_t)); - memset(sn76489, 0, sizeof(sn76489_t)); + sn76489_t *sn76489 = calloc(1, sizeof(sn76489_t)); sn76489_init(sn76489, 0x00c0, 0x0008, SN76496, 3579545); @@ -239,8 +238,7 @@ sn76489_device_init(UNUSED(const device_t *info)) void * ncr8496_device_init(UNUSED(const device_t *info)) { - sn76489_t *sn76489 = malloc(sizeof(sn76489_t)); - memset(sn76489, 0, sizeof(sn76489_t)); + sn76489_t *sn76489 = calloc(1, sizeof(sn76489_t)); sn76489_init(sn76489, 0x00c0, 0x0008, NCR8496, 3579545); @@ -250,8 +248,7 @@ ncr8496_device_init(UNUSED(const device_t *info)) void * tndy_device_init(UNUSED(const device_t *info)) { - sn76489_t *sn76489 = malloc(sizeof(sn76489_t)); - memset(sn76489, 0, sizeof(sn76489_t)); + sn76489_t *sn76489 = calloc(1, sizeof(sn76489_t)); uint16_t addr = device_get_config_hex16("base"); @@ -271,40 +268,23 @@ sn76489_device_close(void *priv) static const device_config_t tndy_config[] = { // clang-format off { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x0C0, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "0x0C0", - .value = 0x0C0 - }, - { - .description = "0x0E0", - .value = 0x0E0 - }, - { - .description = "0x1C0", - .value = 0x1C0 - }, - { - .description = "0x1E0", - .value = 0x1E0 - }, - { - .description = "0x2C0", - .value = 0x2C0 - }, - { - .description = "0x2E0", - .value = 0x2E0 - }, - { .description = "" } - } + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x0C0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "0x0C0", .value = 0x0C0 }, + { .description = "0x0E0", .value = 0x0E0 }, + { .description = "0x1C0", .value = 0x1C0 }, + { .description = "0x1E0", .value = 0x1E0 }, + { .description = "0x2C0", .value = 0x2C0 }, + { .description = "0x2E0", .value = 0x2E0 }, + { .description = "" } + }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on diff --git a/src/sound/snd_ssi2001.c b/src/sound/snd_ssi2001.c index e03be6b4c..f1620b817 100644 --- a/src/sound/snd_ssi2001.c +++ b/src/sound/snd_ssi2001.c @@ -70,8 +70,7 @@ ssi2001_write(uint16_t addr, uint8_t val, void *priv) void * ssi2001_init(UNUSED(const device_t *info)) { - ssi2001_t *ssi2001 = malloc(sizeof(ssi2001_t)); - memset(ssi2001, 0, sizeof(ssi2001_t)); + ssi2001_t *ssi2001 = calloc(1, sizeof(ssi2001_t)); ssi2001->psid = sid_init(0); sid_reset(ssi2001->psid); @@ -95,13 +94,13 @@ ssi2001_close(void *priv) } static uint8_t -entertainer_read(uint16_t addr, void *priv) +entertainer_read(UNUSED(uint16_t addr), UNUSED(void *priv)) { return 0xa5; } static void -entertainer_write(uint16_t addr, uint8_t val, void *priv) +entertainer_write(UNUSED(uint16_t addr), uint8_t val, void *priv) { entertainer_t *entertainer = (entertainer_t *) priv; entertainer->regs = val; @@ -110,10 +109,8 @@ entertainer_write(uint16_t addr, uint8_t val, void *priv) void * entertainer_init(UNUSED(const device_t *info)) { - ssi2001_t *ssi2001 = malloc(sizeof(ssi2001_t)); - entertainer_t *entertainer = malloc(sizeof(entertainer_t)); - memset(ssi2001, 0, sizeof(ssi2001_t)); - memset(entertainer, 0, sizeof(entertainer_t)); + ssi2001_t *ssi2001 = calloc(1, sizeof(ssi2001_t)); + entertainer_t *entertainer = calloc(1, sizeof(entertainer_t)); ssi2001->psid = sid_init(0); sid_reset(ssi2001->psid); @@ -139,42 +136,51 @@ entertainer_close(void *priv) static const device_config_t ssi2001_config[] = { // clang-format off { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x280, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "0x280", - .value = 0x280 - }, - { - .description = "0x2A0", - .value = 0x2A0 - }, - { - .description = "0x2C0", - .value = 0x2C0 - }, - { - .description = "0x2E0", - .value = 0x2E0 - }, - { .description = "" } - } + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x280, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "0x280", .value = 0x280 }, + { .description = "0x2A0", .value = 0x2A0 }, + { .description = "0x2C0", .value = 0x2C0 }, + { .description = "0x2E0", .value = 0x2E0 }, + { .description = "" } + }, + .bios = { { 0 } } }, - { "gameport", "Enable Game port", CONFIG_BINARY, "", 1 }, - { "", "", -1 } + { + .name = "gameport", + .description = "Enable Game port", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } // clang-format off }; static const device_config_t entertainer_config[] = { // clang-format off - { "gameport", "Enable Game port", CONFIG_BINARY, "", 1 }, - { "", "", -1 } + { + .name = "gameport", + .description = "Enable Game port", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } // clang-format off }; diff --git a/src/sound/snd_wss.c b/src/sound/snd_wss.c index 833308280..874638a80 100644 --- a/src/sound/snd_wss.c +++ b/src/sound/snd_wss.c @@ -107,8 +107,7 @@ wss_get_music_buffer(int32_t *buffer, int len, void *priv) void * wss_init(UNUSED(const device_t *info)) { - wss_t *wss = malloc(sizeof(wss_t)); - memset(wss, 0, sizeof(wss_t)); + wss_t *wss = calloc(1, sizeof(wss_t)); uint16_t addr = device_get_config_hex16("base"); wss->opl_enabled = device_get_config_int("opl"); @@ -209,8 +208,7 @@ ncr_audio_mca_feedb(void *priv) void * ncr_audio_init(UNUSED(const device_t *info)) { - wss_t *wss = malloc(sizeof(wss_t)); - memset(wss, 0, sizeof(wss_t)); + wss_t *wss = calloc(1, sizeof(wss_t)); fm_driver_get(FM_YMF262, &wss->opl); ad1848_init(&wss->ad1848, AD1848_TYPE_DEFAULT); @@ -247,39 +245,32 @@ wss_speed_changed(void *priv) static const device_config_t wss_config[] = { // clang-format off { - .name = "base", - .description = "Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x530, - .file_filter = "", - .spinner = { 0 }, - .selection = { - { - .description = "0x530", - .value = 0x530 - }, - { - .description = "0x604", - .value = 0x604 - }, - { - .description = "0xe80", - .value = 0xe80 - }, - { - .description = "0xf40", - .value = 0xf40 - }, - { .description = "" } - } + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x530, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "0x530", .value = 0x530 }, + { .description = "0x604", .value = 0x604 }, + { .description = "0xe80", .value = 0xe80 }, + { .description = "0xf40", .value = 0xf40 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "opl", - .description = "Enable OPL", - .type = CONFIG_BINARY, - .default_string = "", - .default_int = 1 + .name = "opl", + .description = "Enable OPL", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -288,7 +279,7 @@ static const device_config_t wss_config[] = { const device_t wss_device = { .name = "Windows Sound System", .internal_name = "wss", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0, .init = wss_init, .close = wss_close, diff --git a/src/sound/sndio.c b/src/sound/sndio.c new file mode 100644 index 000000000..2fe1434df --- /dev/null +++ b/src/sound/sndio.c @@ -0,0 +1,140 @@ +/* + * 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. + * + * Interface to sndio + * + * + * Authors: Nishi + * + * Copyright 2025 Nishi. + */ +#include +#include +#include +#include +#include +#include + +#include + +#include <86box/86box.h> +#include <86box/sound.h> +#include <86box/plat_unused.h> + +#define I_NORMAL 0 +#define I_MUSIC 1 +#define I_WT 2 +#define I_CD 3 +#define I_MIDI 4 + +static struct sio_hdl* audio[5] = {NULL, NULL, NULL, NULL, NULL}; +static struct sio_par info[5]; +static int freqs[5] = {SOUND_FREQ, MUSIC_FREQ, WT_FREQ, CD_FREQ, 0}; + +void closeal(void){ + int i; + for(i = 0; i < sizeof(audio) / sizeof(audio[0]); i++){ + if(audio[i] != NULL){ + sio_close(audio[i]); + } + audio[i] = NULL; + } +} + +void inital(void){ + int i; + for(i = 0; i < sizeof(audio) / sizeof(audio[0]); i++){ + audio[i] = sio_open(SIO_DEVANY, SIO_PLAY, 0); + if(audio[i] != NULL){ + int rate; + int max_frames; + sio_getpar(audio[i], &info[i]); + rate = info[i].rate; + max_frames = info[i].bufsz; + sio_initpar(&info[i]); + info[i].sig = 1; + info[i].bits = 16; + info[i].pchan = 2; + info[i].rate = rate; + info[i].appbufsz = max_frames; + sio_setpar(audio[i], &info[i]); + sio_getpar(audio[i], &info[i]); + if(!sio_start(audio[i])){ + sio_close(audio[i]); + audio[i] = NULL; + } + } + } +} + +void givealbuffer_common(const void *buf, const uint8_t src, const int size){ + const int freq = freqs[src]; + int16_t* output; + int output_size; + int16_t* conv; + int conv_size; + int i; + double gain; + int target_rate; + if(audio[src] == NULL) return; + + gain = sound_muted ? 0.0 : pow(10.0, (double) sound_gain / 20.0); + + if(sound_is_float){ + float* input = (float*)buf; + conv_size = sizeof(int16_t) * size; + conv = malloc(conv_size); + for(i = 0; i < conv_size / sizeof(int16_t); i++){ + conv[i] = 32767 * input[i]; + } + }else{ + conv_size = size * sizeof(int16_t); + conv = malloc(conv_size); + memcpy(conv, buf, conv_size); + } + + target_rate = info[src].rate; + + output_size = (double)conv_size * target_rate / freq; + output_size -= output_size % 4; + output = malloc(output_size); + + for(i = 0; i < output_size / sizeof(int16_t) / 2; i++){ + int ind = i * freq / target_rate * 2; + output[i * 2 + 0] = conv[ind + 0] * gain; + output[i * 2 + 1] = conv[ind + 1] * gain; + } + + sio_write(audio[src], output, output_size); + + free(conv); + free(output); +} + +void givealbuffer(const void *buf){ + givealbuffer_common(buf, I_NORMAL, SOUNDBUFLEN << 1); +} + +void givealbuffer_music(const void *buf){ + givealbuffer_common(buf, I_MUSIC, MUSICBUFLEN << 1); +} + +void givealbuffer_wt(const void *buf){ + givealbuffer_common(buf, I_WT, WTBUFLEN << 1); +} + +void givealbuffer_cd(const void *buf){ + givealbuffer_common(buf, I_CD, CD_BUFLEN << 1); +} +void givealbuffer_midi(const void *buf, const uint32_t size){ + givealbuffer_common(buf, I_MIDI, (int) size); +} + +void al_set_midi(const int freq, UNUSED(const int buf_size)){ + freqs[I_MIDI] = freq; +} diff --git a/src/sound/sound.c b/src/sound/sound.c index 28cb96629..615df88bc 100644 --- a/src/sound/sound.c +++ b/src/sound/sound.c @@ -100,30 +100,45 @@ static const SOUND_CARD sound_cards[] = { // clang-format off { &device_none }, { &device_internal }, - { &acermagic_s20_device }, - { &mirosound_pcm10_device }, - { &adlib_device }, + /* ISA */ { &adgold_device }, - { &azt2316a_device }, - { &azt1605_device }, { &cms_device }, - { &cs4235_device }, - { &cs4236b_device }, { &ess_688_device }, { &ess_ess0100_pnp_device }, { &ess_1688_device }, { &ess_ess0102_pnp_device }, { &ess_ess0968_pnp_device }, - { &gus_device }, + { &ssi2001_device }, + { &mmb_device }, + { &pasplus_device }, { &sb_1_device }, { &sb_15_device }, { &sb_2_device }, { &sb_pro_v1_device }, { &sb_pro_v2_device }, + { &entertainer_device }, + { &pssj_isa_device }, + { &tndy_device }, +#ifdef USE_LIBSERIALPORT /*The following devices required LIBSERIALPORT*/ + { &opl2board_device }, +#endif + /* ISA/Sidecar */ + { &adlib_device }, + /* ISA16 */ + { &acermagic_s20_device }, + { &azt2316a_device }, + { &azt1605_device }, + { &sb_goldfinch_device }, + { &cs4235_device }, + { &cs4236b_device }, + { &gus_device }, + { &gus_max_device }, + { &mirosound_pcm10_device }, + { &pas16_device }, + { &pas16d_device }, { &sb_16_device }, { &sb_16_pnp_device }, { &sb_16_pnp_ide_device }, - { &sb_goldfinch_device }, { &sb_32_pnp_device }, { &sb_awe32_device }, { &sb_awe32_pnp_device }, @@ -135,14 +150,8 @@ static const SOUND_CARD sound_cards[] = { { &sb_vibra16cl_device }, { &sb_vibra16s_device }, { &sb_vibra16xv_device }, - { &ssi2001_device }, - { &entertainer_device }, - { &pasplus_device }, - { &pas16_device }, - { &pas16d_device }, - { &pssj_isa_device }, - { &tndy_device }, { &wss_device }, + /* MCA */ { &adlib_mca_device }, { &ess_chipchat_16_mca_device }, { &ncr_business_audio_device }, @@ -151,17 +160,16 @@ static const SOUND_CARD sound_cards[] = { { &sb_16_reply_mca_device }, { &ess_soundpiper_16_mca_device }, { &ess_soundpiper_32_mca_device }, + /* PCI */ { &cmi8338_device }, { &cmi8738_device }, { &es1370_device }, { &es1371_device }, { &es1373_device }, { &ct5880_device }, + /* AC97 */ { &ad1881_device }, { &cs4297a_device }, -#ifdef USE_LIBSERIALPORT /*The following devices required LIBSERIALPORT*/ - { &opl2board_device }, -#endif { NULL } // clang-format on }; @@ -274,83 +282,89 @@ sound_cd_thread(UNUSED(void *param)) temp_buffer[0] = temp_buffer[1] = 0; for (uint8_t i = 0; i < CDROM_NUM; i++) { - if ((cdrom[i].bus_type == CDROM_BUS_DISABLED) || (cdrom[i].cd_status == CD_STATUS_EMPTY)) + /* Just in case the thread is in a loop when it gets terminated. */ + if (!cdaudioon) + break; + + if ((cdrom[i].bus_type == CDROM_BUS_DISABLED) || + (cdrom[i].cd_status != CD_STATUS_PLAYING)) continue; - const uint32_t lba = cdrom[i].seek_pos; - const int r = cdrom_audio_callback(&(cdrom[i]), cd_buffer[i], CD_BUFLEN * 2); - if (!cdrom[i].sound_on || !r) - continue; - const int pre = cdrom_is_pre(&(cdrom[i]), lba); + const int ret = cdrom_audio_callback(&(cdrom[i]), cd_buffer[i], + CD_BUFLEN * 2); - - if (cdrom[i].get_volume) { - audio_vol_l = cd_audio_volume_lut[cdrom[i].get_volume(cdrom[i].priv, 0)]; - audio_vol_r = cd_audio_volume_lut[cdrom[i].get_volume(cdrom[i].priv, 1)]; - } else { - audio_vol_l = cd_audio_volume_lut[255]; - audio_vol_r = cd_audio_volume_lut[255]; - } - - if (cdrom[i].get_channel) { - channel_select[0] = (int) cdrom[i].get_channel(cdrom[i].priv, 0); - channel_select[1] = (int) cdrom[i].get_channel(cdrom[i].priv, 1); - } else { - channel_select[0] = 1; - channel_select[1] = 2; - } - - for (int c = 0; c < CD_BUFLEN * 2; c += 2) { - /*Apply ATAPI channel select*/ - cd_buffer_temp[0] = cd_buffer_temp[1] = 0.0; - - if ((audio_vol_l != 0.0) && (channel_select[0] != 0)) { - if (channel_select[0] & 1) - cd_buffer_temp[0] += ((double) cd_buffer[i][c]); /* Channel 0 => Port 0 */ - if (channel_select[0] & 2) - cd_buffer_temp[0] += ((double) cd_buffer[i][c + 1]); /* Channel 1 => Port 0 */ - - cd_buffer_temp[0] *= audio_vol_l; /* Multiply Port 0 by Port 0 volume */ - - if (pre) - cd_buffer_temp[0] = deemph_iir(0, cd_buffer_temp[0]); /* De-emphasize if necessary */ - } - - if ((audio_vol_r != 0.0) && (channel_select[1] != 0)) { - if (channel_select[1] & 1) - cd_buffer_temp[1] += ((double) cd_buffer[i][c]); /* Channel 0 => Port 1 */ - if (channel_select[1] & 2) - cd_buffer_temp[1] += ((double) cd_buffer[i][c + 1]); /* Channel 1 => Port 1 */ - - cd_buffer_temp[1] *= audio_vol_r; /* Multiply Port 1 by Port 1 volume */ - - if (pre) - cd_buffer_temp[1] = deemph_iir(1, cd_buffer_temp[1]); /* De-emphasize if necessary */ - } - - /* Apply sound card CD volume and filters */ - if (filter_cd_audio != NULL) { - filter_cd_audio(0, &(cd_buffer_temp[0]), filter_cd_audio_p); - filter_cd_audio(1, &(cd_buffer_temp[1]), filter_cd_audio_p); - } - - if (sound_is_float) { - cd_out_buffer[c] += (float) (cd_buffer_temp[0] / 32768.0); - cd_out_buffer[c + 1] += (float) (cd_buffer_temp[1] / 32768.0); + if (ret) { + if (cdrom[i].get_volume) { + audio_vol_l = cd_audio_volume_lut[cdrom[i].get_volume(cdrom[i].priv, 0)]; + audio_vol_r = cd_audio_volume_lut[cdrom[i].get_volume(cdrom[i].priv, 1)]; } else { - temp_buffer[0] += (int) trunc(cd_buffer_temp[0]); - temp_buffer[1] += (int) trunc(cd_buffer_temp[1]); + audio_vol_l = cd_audio_volume_lut[255]; + audio_vol_r = cd_audio_volume_lut[255]; + } - if (temp_buffer[0] > 32767) - temp_buffer[0] = 32767; - if (temp_buffer[0] < -32768) - temp_buffer[0] = -32768; - if (temp_buffer[1] > 32767) - temp_buffer[1] = 32767; - if (temp_buffer[1] < -32768) - temp_buffer[1] = -32768; + if (cdrom[i].get_channel) { + channel_select[0] = (int) cdrom[i].get_channel(cdrom[i].priv, 0); + channel_select[1] = (int) cdrom[i].get_channel(cdrom[i].priv, 1); + } else { + channel_select[0] = 1; + channel_select[1] = 2; + } - cd_out_buffer_int16[c] = (int16_t) temp_buffer[0]; - cd_out_buffer_int16[c + 1] = (int16_t) temp_buffer[1]; + // uint16_t *cddab = (uint16_t *) cdrom[i].raw_buffer; + for (int c = 0; c < CD_BUFLEN * 2; c += 2) { + /* Apply ATAPI channel select */ + cd_buffer_temp[0] = cd_buffer_temp[1] = 0.0; + + if ((audio_vol_l != 0.0) && (channel_select[0] != 0)) { + if (channel_select[0] & 1) + /* Channel 0 => Port 0 */ + cd_buffer_temp[0] += ((double) cd_buffer[i][c]); + if (channel_select[0] & 2) + /* Channel 1 => Port 0 */ + cd_buffer_temp[0] += ((double) cd_buffer[i][c + 1]); + + /* Multiply Port 0 by Port 0 volume */ + cd_buffer_temp[0] *= audio_vol_l; + } + + if ((audio_vol_r != 0.0) && (channel_select[1] != 0)) { + if (channel_select[1] & 1) + /* Channel 0 => Port 1 */ + cd_buffer_temp[1] += ((double) cd_buffer[i][c]); + if (channel_select[1] & 2) + /* Channel 1 => Port 1 */ + cd_buffer_temp[1] += ((double) cd_buffer[i][c + 1]); + + /* Multiply Port 1 by Port 1 volume */ + cd_buffer_temp[1] *= audio_vol_r; + } + + /* Apply sound card CD volume and filters */ + if (filter_cd_audio != NULL) { + filter_cd_audio(0, &(cd_buffer_temp[0]), + filter_cd_audio_p); + filter_cd_audio(1, &(cd_buffer_temp[1]), + filter_cd_audio_p); + } + + if (sound_is_float) { + cd_out_buffer[c] += (float) (cd_buffer_temp[0] / 32768.0); + cd_out_buffer[c + 1] += (float) (cd_buffer_temp[1] / 32768.0); + } else { + temp_buffer[0] = (int) trunc(cd_buffer_temp[0]); + temp_buffer[1] = (int) trunc(cd_buffer_temp[1]); + + if (temp_buffer[0] > 32767) + temp_buffer[0] = 32767; + if (temp_buffer[0] < -32768) + temp_buffer[0] = -32768; + if (temp_buffer[1] > 32767) + temp_buffer[1] = 32767; + if (temp_buffer[1] < -32768) + temp_buffer[1] = -32768; + + cd_out_buffer_int16[c] += (int16_t) temp_buffer[0]; + cd_out_buffer_int16[c + 1] += (int16_t) temp_buffer[1]; + } } } } diff --git a/src/sound/xaudio2.c b/src/sound/xaudio2.c index 9b341f574..2aee97efc 100644 --- a/src/sound/xaudio2.c +++ b/src/sound/xaudio2.c @@ -245,7 +245,7 @@ givealbuffer_common(const void *buf, IXAudio2SourceVoice *sourcevoice, const siz if (!initialized) return; - (void) IXAudio2MasteringVoice_SetVolume(mastervoice, pow(10.0, (double) sound_gain / 20.0), + (void) IXAudio2MasteringVoice_SetVolume(mastervoice, sound_muted ? 0.0 : pow(10.0, (double) sound_gain / 20.0), XAUDIO2_COMMIT_NOW); XAUDIO2_BUFFER buffer = { 0 }; buffer.Flags = 0; diff --git a/src/timer.c b/src/timer.c index 6ddf8ebb5..03908890f 100644 --- a/src/timer.c +++ b/src/timer.c @@ -3,7 +3,9 @@ #include #include #include <86box/86box.h> +#include "cpu.h" #include <86box/timer.h> +#include <86box/nv/vid_nv_rivatimer.h> uint64_t TIMER_USEC; uint32_t timer_target; @@ -30,7 +32,8 @@ timer_enable(pc_timer_t *timer) timer_disable(timer); if (timer->next || timer->prev) - fatal("timer_enable - timer->next\n"); + fatal("timer_disable(): Attempting to enable a non-isolated " + "timer incorrectly marked as disabled\n"); /*List currently empty - add to head*/ if (!timer_head) { @@ -91,7 +94,8 @@ timer_disable(pc_timer_t *timer) return; if (!timer->next && !timer->prev && timer != timer_head) - fatal("timer_disable - !timer->next\n"); + fatal("timer_disable(): Attempting to disable an isolated " + "non-head timer incorrectly marked as enabled\n"); timer->flags &= ~TIMER_ENABLED; timer->in_callback = 0; @@ -168,6 +172,9 @@ timer_init(void) timer_target = 0ULL; tsc = 0; + /* Initialise the CPU-independent timer */ + rivatimer_init(); + timer_inited = 1; } diff --git a/src/unix/assets/86Box.spec b/src/unix/assets/86Box.spec index 86f380d22..bb9b85b12 100644 --- a/src/unix/assets/86Box.spec +++ b/src/unix/assets/86Box.spec @@ -15,7 +15,7 @@ %global romver 4.1 Name: 86Box -Version: 4.3 +Version: 5.0 Release: 1%{?dist} Summary: Classic PC emulator License: GPLv2+ @@ -121,5 +121,5 @@ popd %{_datadir}/%{name}/roms %changelog -* Sat Aug 31 Jasmine Iwanek 4.3-1 +* Sat Aug 31 Jasmine Iwanek 5.0-1 - Bump release diff --git a/src/unix/assets/net.86box.86Box.metainfo.xml b/src/unix/assets/net.86box.86Box.metainfo.xml index 6618f21d2..4c6a795a7 100644 --- a/src/unix/assets/net.86box.86Box.metainfo.xml +++ b/src/unix/assets/net.86box.86Box.metainfo.xml @@ -11,7 +11,7 @@ net.86box.86Box.desktop - + diff --git a/src/unix/dummy_cdrom_ioctl.c b/src/unix/dummy_cdrom_ioctl.c index 4ed0333a7..bddfabb5b 100644 --- a/src/unix/dummy_cdrom_ioctl.c +++ b/src/unix/dummy_cdrom_ioctl.c @@ -17,236 +17,226 @@ * Copyright 2023 Miran Grca. */ #include +#ifdef ENABLE_IOCTL_LOG #include +#endif #include #include #include #include #include #define HAVE_STDARG_H -#include <86box/86box.h> #include <86box/scsi_device.h> #include <86box/cdrom.h> +#include <86box/log.h> #include <86box/plat_unused.h> -#include <86box/plat_cdrom.h> +#include <86box/plat_cdrom_ioctl.h> /* 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. */ #define MSFtoLBA(m, s, f) ((((m * 60) + s) * 75) + f) -typedef struct dummy_cdrom_ioctl_t { - int toc_valid; -} dummy_cdrom_ioctl_t; +typedef struct ioctl_t { + cdrom_t *dev; + void *log; + void *handle; + char path[256]; +} ioctl_t; -#ifdef ENABLE_DUMMY_CDROM_IOCTL_LOG -int dummy_cdrom_ioctl_do_log = ENABLE_DUMMY_CDROM_IOCTL_LOG; +#ifdef ENABLE_IOCTL_LOG +int ioctl_do_log = ENABLE_IOCTL_LOG; void -dummy_cdrom_ioctl_log(const char *fmt, ...) +ioctl_log(void *priv, const char *fmt, ...) { - va_list ap; - - if (dummy_cdrom_ioctl_do_log) { + if (ioctl_do_log) { + va_list ap; va_start(ap, fmt); - pclog_ex(fmt, ap); + log_out(priv, fmt, ap); va_end(ap); } } #else -# define dummy_cdrom_ioctl_log(fmt, ...) +# define ioctl_log(priv, fmt, ...) #endif -static int -plat_cdrom_open(void *local) +/* Internal functions. */ +static void +ioctl_close_handle(UNUSED(const ioctl_t *ioctl)) { - return 0; } static int -plat_cdrom_load(void *local) +ioctl_open_handle(UNUSED(ioctl_t *ioctl)) { return 0; } static void -plat_cdrom_read_toc(void *local) +ioctl_read_toc(ioctl_t *ioctl) { - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - - if (!ioctl->toc_valid) - ioctl->toc_valid = 1; } -void -plat_cdrom_get_raw_track_info(UNUSED(void *local), int *num, raw_track_info_t *rti) +/* Shared functions. */ +static int +ioctl_get_track_info(UNUSED(const void *local), UNUSED(const uint32_t track), + UNUSED(int end), UNUSED(track_info_t *ti)) +{ + return 0; +} + +static void +ioctl_get_raw_track_info(UNUSED(const void *local), int *num, uint8_t *rti) { *num = 1; memset(rti, 0x00, 11); } -int -plat_cdrom_is_track_audio(void *local, uint32_t sector) +static int +ioctl_is_track_pre(const void *local, UNUSED(const uint32_t sector)) { - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; + ioctl_t *ioctl = (ioctl_t *) local; - plat_cdrom_read_toc(ioctl); - - const int ret = 0; - - dummy_cdrom_ioctl_log("plat_cdrom_is_track_audio(%08X): %i\n", sector, ret); - - return ret; -} - -int -plat_cdrom_is_track_pre(void *local, uint32_t sector) -{ - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - - plat_cdrom_read_toc(ioctl); + ioctl_read_toc(ioctl); const int ret = 0; - dummy_cdrom_ioctl_log("plat_cdrom_is_track_audio(%08X): %i\n", sector, ret); + ioctl_log("ioctl_is_track_audio(%08X): %i\n", sector, ret); return ret; } -uint32_t -plat_cdrom_get_track_start(void *local, uint32_t sector, uint8_t *attr, uint8_t *track) +static int +ioctl_read_sector(const void *local, UNUSED(uint8_t *buffer), UNUSED(uint32_t const sector)) { - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; + ioctl_t *ioctl = (ioctl_t *) local; - plat_cdrom_read_toc(ioctl); + ioctl_open_handle(ioctl); - return 0x00000000; -} + ioctl_close_handle(ioctl); -uint32_t -plat_cdrom_get_last_block(void *local) -{ - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - - plat_cdrom_read_toc(ioctl); - - return 0x00000000; -} - -int -plat_cdrom_ext_medium_changed(void *local) -{ - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - int ret = 0; - - dummy_cdrom_ioctl_log("plat_cdrom_ext_medium_changed(): %i\n", ret); - - return ret; -} - -/* This replaces both Info and EndInfo, they are specified by a variable. */ -int -plat_cdrom_get_audio_track_info(void *local, UNUSED(int end), int track, int *track_num, TMSF *start, uint8_t *attr) -{ - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - - plat_cdrom_read_toc(ioctl); - - if ((track < 1) || (track == 0xaa)) { - dummy_cdrom_ioctl_log("plat_cdrom_get_audio_track_info(%02i)\n", track); - return 0; - } - - start->min = 0; - start->sec = 0; - start->fr = 2; - - *track_num = 1; - *attr = 0x14; - - dummy_cdrom_ioctl_log("plat_cdrom_get_audio_track_info(%02i): %02i:%02i:%02i, %02i, %02X\n", - track, start->min, start->sec, start->fr, *track_num, *attr); - - return 1; -} - -/* TODO: See if track start is adjusted by 150 or not. */ -int -plat_cdrom_get_audio_sub(UNUSED(void *local), UNUSED(uint32_t sector), uint8_t *attr, uint8_t *track, uint8_t *index, - TMSF *rel_pos, TMSF *abs_pos) -{ - *track = 1; - *attr = 0x14; - *index = 1; - - rel_pos->min = 0; - rel_pos->sec = 0; - rel_pos->fr = 0; - abs_pos->min = 0; - abs_pos->sec = 0; - abs_pos->fr = 2; - - dummy_cdrom_ioctl_log("plat_cdrom_get_audio_sub(): %02i, %02X, %02i, %02i:%02i:%02i, %02i:%02i:%02i\n", - *track, *attr, *index, rel_pos->min, rel_pos->sec, rel_pos->fr, abs_pos->min, abs_pos->sec, abs_pos->fr); - - return 1; -} - -int -plat_cdrom_get_sector_size(UNUSED(void *local), UNUSED(uint32_t sector)) -{ - dummy_cdrom_ioctl_log("BytesPerSector=2048\n"); - - return 2048; -} - -int -plat_cdrom_read_sector(void *local, uint8_t *buffer, uint32_t sector) -{ - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - - plat_cdrom_open(ioctl); - - /* Raw */ - dummy_cdrom_ioctl_log("Raw\n"); - - plat_cdrom_close(ioctl); - - dummy_cdrom_ioctl_log("ReadSector sector=%d.\n", sector); + ioctl_log("ReadSector sector=%d.\n", sector); return 0; } -void -plat_cdrom_eject(void *local) +static uint8_t +ioctl_get_track_type(UNUSED(const void *local), UNUSED(const uint32_t sector)) { - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; - - plat_cdrom_open(ioctl); - plat_cdrom_close(ioctl); + return 0x00; } -void -plat_cdrom_close(UNUSED(void *local)) +static uint32_t +ioctl_get_last_block(const void *local) { + ioctl_t *ioctl = (ioctl_t *) local; + + ioctl_read_toc(ioctl); + + return 0x00000000; } -int -plat_cdrom_set_drive(void *local, const char *drv) +static int +ioctl_read_dvd_structure(UNUSED(const void *local), UNUSED(const uint8_t layer), UNUSED(const uint8_t format), + UNUSED(uint8_t *buffer), UNUSED(uint32_t *info)) { - dummy_cdrom_ioctl_t *ioctl = (dummy_cdrom_ioctl_t *) local; + return -0x00052100; +} - plat_cdrom_close(ioctl); +static int +ioctl_is_dvd(UNUSED(const void *local)) +{ + return 0; +} - ioctl->toc_valid = 0; - - plat_cdrom_load(ioctl); +static int +ioctl_has_audio(UNUSED(const void *local)) +{ + return 0; +} +static int +ioctl_is_empty(const void *local) +{ return 1; } -int -plat_cdrom_get_local_size(void) +static int +ioctl_ext_medium_changed(UNUSED(void *local)) { - return sizeof(dummy_cdrom_ioctl_t); +#if 0 + ioctl_t *ioctl = (ioctl_t *) local; +#endif + int ret = 0; + + ioctl_log("ioctl_ext_medium_changed(): %i\n", ret); + + return ret; +} + +static void +ioctl_close(void *local) +{ + ioctl_t *ioctl = (ioctl_t *) local; + + ioctl_close_handle(ioctl); + ioctl->handle = NULL; + + ioctl_log(ioctl->log, "Log closed\n"); + + log_close(ioctl->log); + ioctl->log = NULL; +} + +static void +ioctl_load(const void *local) +{ + const ioctl_t *ioctl = (const ioctl_t *) local; + + if (ioctl_open_handle((ioctl_t *) ioctl)) { + ioctl_close_handle((ioctl_t *) ioctl); + + ioctl_read_toc((ioctl_t *) ioctl); + } +} + +static const cdrom_ops_t ioctl_ops = { + ioctl_get_track_info, + ioctl_get_raw_track_info, + ioctl_is_track_pre, + ioctl_read_sector, + ioctl_get_track_type, + ioctl_get_last_block, + ioctl_read_dvd_structure, + ioctl_is_dvd, + ioctl_has_audio, + ioctl_is_empty, + ioctl_close, + ioctl_load +}; + +/* Public functions. */ +void * +ioctl_open(cdrom_t *dev, const char *drv) +{ + ioctl_t *ioctl = (ioctl_t *) calloc(1, sizeof(ioctl_t)); + + if (ioctl != NULL) { + char n[1024] = { 0 }; + + sprintf(n, "CD-ROM %i IOCtl", dev->id + 1); + ioctl->log = log_open(n); + + memset(ioctl->path, 0x00, sizeof(ioctl->path)); + + sprintf(ioctl->path, "%s", drv); + ioctl_log(ioctl->log, "Path is %s\n", ioctl->path); + + ioctl->dev = dev; + + dev->ops = &ioctl_ops; + } + + return ioctl; } diff --git a/src/unix/unix.c b/src/unix/unix.c index 911905ef2..2e92a90d3 100644 --- a/src/unix/unix.c +++ b/src/unix/unix.c @@ -2,6 +2,9 @@ # define _FILE_OFFSET_BITS 64 # define _LARGEFILE64_SOURCE 1 #endif +#ifdef __HAIKU__ +#include +#endif #include #include #include @@ -38,6 +41,7 @@ #include <86box/device.h> #include <86box/gameport.h> #include <86box/unix_sdl.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/nvr.h> #include <86box/version.h> @@ -61,15 +65,12 @@ int fixed_size_y = 480; extern int title_set; extern wchar_t sdl_win_title[512]; plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS]; -joystick_t joystick_state[MAX_JOYSTICKS]; +joystick_t joystick_state[GAMEPORT_MAX][MAX_JOYSTICKS]; int joysticks_present; SDL_mutex *blitmtx; SDL_threadID eventthread; static int exit_event = 0; static int fullscreen_pending = 0; -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] = { [SDL_SCANCODE_ESCAPE] = 0x01, @@ -301,7 +302,7 @@ path_abs(char *path) } void -path_normalize(char *path) +path_normalize(UNUSED(char *path)) { /* No-op. */ } @@ -459,13 +460,19 @@ plat_remove(char *path) } void -ui_sb_update_icon_state(int tag, int state) +ui_sb_update_icon_state(UNUSED(int tag), UNUSED(int state)) { /* No-op. */ } void -ui_sb_update_icon(int tag, int active) +ui_sb_update_icon(UNUSED(int tag), UNUSED(int active)) +{ + /* No-op. */ +} + +void +ui_sb_update_icon_write(UNUSED(int tag), UNUSED(int active)) { /* No-op. */ } @@ -477,7 +484,7 @@ plat_delay_ms(uint32_t count) } void -ui_sb_update_tip(int arg) +ui_sb_update_tip(UNUSED(int arg)) { /* No-op. */ } @@ -514,8 +521,9 @@ path_get_dirname(char *dest, const char *path) *dest = '\0'; } volatile int cpu_thread_run = 1; + void -ui_sb_set_text_w(wchar_t *wstr) +ui_sb_set_text_w(UNUSED(wchar_t *wstr)) { /* No-op. */ } @@ -533,7 +541,7 @@ strnicmp(const char *s1, const char *s2, size_t n) } void -main_thread(void *param) +main_thread(UNUSED(void *param)) { uint32_t old_time; uint32_t new_time; @@ -707,7 +715,7 @@ plat_power_off(void) } void -ui_sb_bugui(char *str) +ui_sb_bugui(UNUSED(char *str)) { /* No-op. */ } @@ -726,7 +734,7 @@ int real_sdl_w; int real_sdl_h; void -ui_sb_set_ready(int ready) +ui_sb_set_ready(UNUSED(int ready)) { /* No-op. */ } @@ -912,14 +920,14 @@ void (*f_rl_callback_handler_remove)(void) = NULL; #endif uint32_t -timer_onesec(uint32_t interval, void *param) +timer_onesec(uint32_t interval, UNUSED(void *param)) { pc_onesec(); return interval; } void -monitor_thread(void *param) +monitor_thread(UNUSED(void *param)) { #ifndef USE_CLI if (isatty(fileno(stdin)) && isatty(fileno(stdout))) { @@ -1336,9 +1344,6 @@ main(int argc, char **argv) } } } - if (mouse_capture && keyboard_ismsexit()) { - plat_mouse_capture(0); - } if (blitreq) { extern void sdl_blit(int x, int y, int w, int h); sdl_blit(params.x, params.y, params.w, params.h); @@ -1369,14 +1374,14 @@ main(int argc, char **argv) return 0; } char * -plat_vidapi_name(int i) +plat_vidapi_name(UNUSED(int i)) { return "default"; } -/* Sets up the program language before initialization. */ -uint32_t -plat_language_code(char *langcode) +/* Converts the language code string to a numeric language ID */ +int +plat_language_code(UNUSED(char *langcode)) { /* or maybe not */ return 0; @@ -1396,24 +1401,28 @@ plat_set_thread_name(void *thread, const char *name) if (thread) /* Apple pthread can only set self's name */ return; char truncated[64]; -#elif defined(Q_OS_NETBSD) +#elif defined(__NetBSD__) char truncated[64]; +#elif defined(__HAIKU__) + char truncated[32]; #else char truncated[16]; #endif strncpy(truncated, name, sizeof(truncated) - 1); #ifdef __APPLE__ pthread_setname_np(truncated); -#elif defined(Q_OS_NETBSD) +#elif defined(__NetBSD__) pthread_setname_np(thread ? *((pthread_t *) thread) : pthread_self(), truncated, "%s"); +#elif defined(__HAIKU__) + rename_thread(find_thread(NULL), truncated); #else pthread_setname_np(thread ? *((pthread_t *) thread) : pthread_self(), truncated); #endif } -/* Converts back the language code to LCID */ +/* Converts the numeric language ID to a language code string */ void -plat_language_code_r(uint32_t lcid, char *outbuf, int len) +plat_language_code_r(UNUSED(int id), UNUSED(char *outbuf), UNUSED(int len)) { /* or maybe not */ return; @@ -1451,7 +1460,7 @@ endblit(void) /* API */ void -ui_sb_mt32lcd(char *str) +ui_sb_mt32lcd(UNUSED(char *str)) { /* No-op. */ } diff --git a/src/unix/unix_cdrom.c b/src/unix/unix_cdrom.c index 186c7649b..b1096b0b4 100644 --- a/src/unix/unix_cdrom.c +++ b/src/unix/unix_cdrom.c @@ -32,6 +32,7 @@ #include <86box/hdd.h> #include <86box/scsi_device.h> #include <86box/cdrom.h> +#include <86box/cdrom_image.h> #include <86box/mo.h> #include <86box/zip.h> #include <86box/scsi_disk.h> @@ -69,7 +70,7 @@ cassette_eject(void) } void -cartridge_mount(uint8_t id, char *fn, uint8_t wp) +cartridge_mount(uint8_t id, char *fn, UNUSED(uint8_t wp)) { cart_close(id); cart_load(id, fn); @@ -120,7 +121,7 @@ floppy_eject(uint8_t id) } void -plat_cdrom_ui_update(uint8_t id, uint8_t reload) +plat_cdrom_ui_update(uint8_t id, UNUSED(uint8_t reload)) { cdrom_t *drv = &cdrom[id]; @@ -140,13 +141,13 @@ void cdrom_mount(uint8_t id, char *fn) { strcpy(cdrom[id].prev_image_path, cdrom[id].image_path); - if (cdrom[id].ops && cdrom[id].ops->exit) - cdrom[id].ops->exit(&(cdrom[id])); + if (cdrom[id].ops && cdrom[id].ops->close) + cdrom[id].ops->close(cdrom[id].local); cdrom[id].ops = NULL; memset(cdrom[id].image_path, 0, sizeof(cdrom[id].image_path)); if ((fn != NULL) && (strlen(fn) >= 1) && (fn[strlen(fn) - 1] == '\\')) fn[strlen(fn) - 1] = '/'; - cdrom_image_open(&(cdrom[id]), fn); + image_open(&(cdrom[id]), fn); /* Signal media change to the emulated machine. */ if (cdrom[id].insert) cdrom[id].insert(cdrom[id].priv); @@ -187,8 +188,7 @@ mo_mount(uint8_t id, char *fn, uint8_t wp) mo_disk_close(dev); mo_drives[id].read_only = wp; - mo_load(dev, fn); - mo_insert(dev); + mo_load(dev, fn, 0); ui_sb_update_icon_state(SB_MO | id, strlen(mo_drives[id].image_path) ? 0 : 1); #if 0 @@ -245,8 +245,7 @@ zip_mount(uint8_t id, char *fn, uint8_t wp) zip_disk_close(dev); zip_drives[id].read_only = wp; - zip_load(dev, fn); - zip_insert(dev); + zip_load(dev, fn, 0); ui_sb_update_icon_state(SB_ZIP | id, strlen(zip_drives[id].image_path) ? 0 : 1); #if 0 diff --git a/src/unix/unix_netsocket.c b/src/unix/unix_netsocket.c index d626d025b..850fa3c6c 100644 --- a/src/unix/unix_netsocket.c +++ b/src/unix/unix_netsocket.c @@ -94,6 +94,8 @@ plat_netsocket_accept(SOCKET socket) if (clientsocket == -1) return -1; + fcntl(clientsocket, F_SETFL, fcntl(clientsocket, F_GETFL, 0) | O_NONBLOCK); + return clientsocket; } diff --git a/src/unix/unix_sdl.c b/src/unix/unix_sdl.c index 002e33fd6..651822335 100644 --- a/src/unix/unix_sdl.c +++ b/src/unix/unix_sdl.c @@ -533,19 +533,19 @@ ui_window_title(wchar_t *str) } void -ui_init_monitor(int monitor_index) +ui_init_monitor(UNUSED(int monitor_index)) { /* No-op. */ } void -ui_deinit_monitor(int monitor_index) +ui_deinit_monitor(UNUSED(int monitor_index)) { /* No-op. */ } void -plat_resize_request(int w, int h, int monitor_index) +plat_resize_request(UNUSED(int w), UNUSED(int h), int monitor_index) { atomic_store((&doresize_monitors[monitor_index]), 1); } diff --git a/src/unix/unix_serial_passthrough.c b/src/unix/unix_serial_passthrough.c index a12346013..9929f3298 100644 --- a/src/unix/unix_serial_passthrough.c +++ b/src/unix/unix_serial_passthrough.c @@ -26,6 +26,7 @@ #endif #ifdef __NetBSD__ # define _NETBSD_VISIBLE 1 +# define _NETBSD_SOURCE 1 #endif #include #include @@ -149,8 +150,11 @@ plat_serpt_set_params(void *priv) BAUDRATE_RANGE(dev->baudrate, 9600, 19200, B9600); BAUDRATE_RANGE(dev->baudrate, 19200, 38400, B19200); BAUDRATE_RANGE(dev->baudrate, 38400, 57600, B38400); +#ifndef __NetBSD__ + /* nonexistent on NetBSD */ BAUDRATE_RANGE(dev->baudrate, 57600, 115200, B57600); BAUDRATE_RANGE(dev->baudrate, 115200, 0xFFFFFFFF, B115200); +#endif term_attr.c_cflag &= ~CSIZE; switch (dev->data_bits) { diff --git a/src/usb.c b/src/usb.c index 6bdc8e6c0..222062f4f 100644 --- a/src/usb.c +++ b/src/usb.c @@ -433,7 +433,7 @@ const device_t usb_device = { .init = usb_init, .close = usb_close, .reset = usb_reset, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt new file mode 100644 index 000000000..2ffe41f7b --- /dev/null +++ b/src/utils/CMakeLists.txt @@ -0,0 +1,26 @@ +# +# 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, +# Jasmine Iwanek, +# +# Copyright 2020-2021 David Hrdlička. +# Copyright 2024 Jasmine Iwanek. +# + +add_library(utils OBJECT + cJSON.c + crc.c + fifo.c + fifo8.c + ini.c + log.c + random.c +) diff --git a/src/cJSON.c b/src/utils/cJSON.c similarity index 100% rename from src/cJSON.c rename to src/utils/cJSON.c diff --git a/src/utils/crc.c b/src/utils/crc.c new file mode 100644 index 000000000..096a94c72 --- /dev/null +++ b/src/utils/crc.c @@ -0,0 +1,77 @@ +/* + * 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. + * + * CRC implementation. + * + * Authors: Miran Grca, + * + * Copyright 2016-2025 Miran Grca. + */ +#include +#include +#include +#include +#include +#include +#include +#define HAVE_STDARG_H +#include <86box/86box.h> +#include <86box/timer.h> +#include <86box/dma.h> +#include <86box/nvr.h> +#include <86box/random.h> +#include <86box/plat.h> +#include <86box/ui.h> +#include <86box/crc.h> + +#ifdef ENABLE_CRC_LOG +int d86f_do_log = ENABLE_CRC_LOG; + +static void +crc_log(const char *fmt, ...) +{ + va_list ap; + + if (crc_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define crc_log(fmt, ...) +#endif + +void +crc16_setup(uint16_t *crc_table, uint16_t poly) +{ + int c = 256; + int bc; + uint16_t temp; + + while (c--) { + temp = c << 8; + bc = 8; + + while (bc--) { + if (temp & 0x8000) + temp = (temp << 1) ^ poly; + else + temp <<= 1; + + crc_table[c] = temp; + } + } +} + +void +crc16_calc(uint16_t *crc_table, uint8_t byte, crc_t *crc_var) +{ + crc_var->word = (crc_var->word << 8) ^ + crc_table[(crc_var->word >> 8) ^ byte]; +} diff --git a/src/fifo.c b/src/utils/fifo.c similarity index 79% rename from src/fifo.c rename to src/utils/fifo.c index f51809fd8..8afb5640f 100644 --- a/src/fifo.c +++ b/src/utils/fifo.c @@ -10,7 +10,7 @@ * * Authors: Miran Grca, * - * Copyright 2023 Miran Grca. + * Copyright 2023-2025 Miran Grca. */ #include #include @@ -84,6 +84,31 @@ fifo_write(uint8_t val, void *priv) } } +void +fifo_write_tagged(uint8_t tag, uint8_t val, void *priv) +{ + fifo_t *fifo = (fifo_t *) priv; + + fifo->d_full = fifo->d_empty = 0; + fifo->d_ready = fifo->d_overrun = 0; + + if (fifo->full) + fifo->overrun = 1; + else { + fifo->buf[fifo->end] = val; + fifo->tag[fifo->end] = tag; + fifo->end = (fifo->end + 1) % fifo->len; + + if (fifo->end == fifo->start) + fifo->full = 1; + + fifo->empty = 0; + + if (fifo_get_count(fifo) >= fifo->trigger_len) + fifo->ready = 1; + } +} + void fifo_write_evt(uint8_t val, void *priv) { @@ -122,6 +147,45 @@ fifo_write_evt(uint8_t val, void *priv) } } +void +fifo_write_evt_tagged(uint8_t tag, uint8_t val, void *priv) +{ + fifo_t *fifo = (fifo_t *) priv; + + fifo->d_full = fifo->d_empty = 0; + fifo->d_ready = fifo->d_overrun = 0; + + if (fifo->full) { + fifo->d_overrun = (fifo->overrun != 1); + fifo->overrun = 1; + if (fifo->d_overrun && (fifo->d_overrun_evt != NULL)) + fifo->d_overrun_evt(fifo->priv); + } else { + fifo->buf[fifo->end] = val; + fifo->tag[fifo->end] = tag; + fifo->end = (fifo->end + 1) % fifo->len; + + if (fifo->end == fifo->start) { + fifo->d_full = (fifo->full != 1); + fifo->full = 1; + if (fifo->d_full && (fifo->d_full_evt != NULL)) + fifo->d_full_evt(fifo->priv); + } + + fifo->d_empty = (fifo->empty != 0); + fifo->empty = 0; + if (fifo->d_empty && (fifo->d_empty_evt != NULL)) + fifo->d_empty_evt(fifo->priv); + + if (fifo_get_count(fifo) >= fifo->trigger_len) { + fifo->d_ready = (fifo->ready != 1); + fifo->ready = 1; + if (fifo->d_ready && (fifo->d_ready_evt != NULL)) + fifo->d_ready_evt(fifo->priv); + } + } +} + uint8_t fifo_read(void *priv) { @@ -148,6 +212,35 @@ fifo_read(void *priv) return ret; } +uint8_t +fifo_read_tagged(uint8_t *tag, void *priv) +{ + fifo_t *fifo = (fifo_t *) priv; + uint8_t ret = 0x00; + int count; + + if (!fifo->empty) { + ret = fifo->buf[fifo->start]; + *tag = fifo->tag[fifo->start]; + + fifo->start = (fifo->start + 1) % fifo->len; + + fifo->full = 0; + + count = fifo_get_count(fifo); + + if (count < fifo->trigger_len) { + fifo->ready = 0; + + if (count == 0) + fifo->empty = 1; + } + } else + *tag = 0x00; + + return ret; +} + uint8_t fifo_read_evt(void *priv) { @@ -187,6 +280,48 @@ fifo_read_evt(void *priv) return ret; } +uint8_t +fifo_read_evt_tagged(uint8_t *tag, void *priv) +{ + fifo_t *fifo = (fifo_t *) priv; + uint8_t ret = 0x00; + int count; + + fifo->d_full = fifo->d_empty = 0; + fifo->d_ready = 0; + + if (!fifo->empty) { + ret = fifo->buf[fifo->start]; + *tag = fifo->tag[fifo->start]; + + fifo->start = (fifo->start + 1) % fifo->len; + + fifo->d_full = (fifo->full != 0); + fifo->full = 0; + if (fifo->d_full && (fifo->d_full_evt != NULL)) + fifo->d_full_evt(fifo->priv); + + count = fifo_get_count(fifo); + + if (count < fifo->trigger_len) { + fifo->d_ready = (fifo->ready != 0); + fifo->ready = 0; + if (fifo->d_ready && (fifo->d_ready_evt != NULL)) + fifo->d_ready_evt(fifo->priv); + + if (count == 0) { + fifo->d_empty = (fifo->empty != 1); + fifo->empty = 1; + if (fifo->d_empty && (fifo->d_empty_evt != NULL)) + fifo->d_empty_evt(fifo->priv); + } + } + } else + *tag = 0x00; + + return ret; +} + void fifo_clear_overrun(void *priv) { diff --git a/src/fifo8.c b/src/utils/fifo8.c similarity index 100% rename from src/fifo8.c rename to src/utils/fifo8.c diff --git a/src/ini.c b/src/utils/ini.c similarity index 85% rename from src/ini.c rename to src/utils/ini.c index 78c873758..e23f83670 100644 --- a/src/ini.c +++ b/src/utils/ini.c @@ -33,6 +33,7 @@ #include #include #include +#include #define HAVE_STDARG_H #include <86box/86box.h> #include <86box/ini.h> @@ -157,6 +158,22 @@ find_entry(section_t *section, const char *name) return (NULL); } +int +ini_has_entry(ini_section_t self, const char *name) +{ + section_t *section = (section_t *) self; + const entry_t *entry; + + if (section == NULL) + return 0; + + entry = find_entry(section, name); + if (entry == NULL) + return 0; + + return 1; +} + static int entries_num(section_t *section) { @@ -237,9 +254,8 @@ ini_delete_section_if_empty(ini_t ini, ini_section_t section) static section_t * create_section(list_t *head, const char *name) { - section_t *ns = malloc(sizeof(section_t)); + section_t *ns = calloc(1, sizeof(section_t)); - memset(ns, 0x00, sizeof(section_t)); memcpy(ns->name, name, strlen(name) + 1); list_add(&ns->list, head); @@ -262,9 +278,8 @@ ini_find_or_create_section(ini_t ini, const char *name) static entry_t * create_entry(section_t *section, const char *name) { - entry_t *ne = malloc(sizeof(entry_t)); + entry_t *ne = calloc(1, sizeof(entry_t)); - memset(ne, 0x00, sizeof(entry_t)); memcpy(ne->name, name, strlen(name) + 1); list_add(&ne->list, §ion->entry_head); @@ -373,11 +388,8 @@ ini_read(const char *fn) if (fp == NULL) return NULL; - head = malloc(sizeof(list_t)); - memset(head, 0x00, sizeof(list_t)); - - sec = malloc(sizeof(section_t)); - memset(sec, 0x00, sizeof(section_t)); + head = calloc(1, sizeof(list_t)); + sec = calloc(1, sizeof(section_t)); list_add(&sec->list, head); if (bom) @@ -458,7 +470,7 @@ ini_read(const char *fn) d = c; /* Allocate a new variable entry.. */ - ne = malloc(sizeof(entry_t)); + ne = calloc(1, sizeof(entry_t)); memset(ne, 0x00, sizeof(entry_t)); memcpy(ne->name, ename, 128); wcsncpy(ne->wdata, &buff[d], sizeof_w(ne->wdata) - 1); @@ -534,6 +546,103 @@ ini_write(ini_t ini, const char *fn) (void) fclose(fp); } +/* Wide-character version of "trim" */ +wchar_t * +trim_w(wchar_t *str) +{ + size_t len = 0; + wchar_t *frontp = str; + wchar_t *endp = NULL; + + if (str == NULL) { + return NULL; + } + if (str[0] == L'\0') { + return str; + } + + len = wcslen(str); + endp = str + len; + + /* Move the front and back pointers to address the first non-whitespace + * characters from each end. + */ + while (iswspace((wint_t) *frontp)) { + ++frontp; + } + if (endp != frontp) { + while (iswspace((wint_t) *(--endp)) && endp != frontp) { } + } + + if (frontp != str && endp == frontp) + *str = L'\0'; + else if ((str + len - 1) != endp) + *(endp + 1) = L'\0'; + + /* Shift the string so that it starts at str so that if it's dynamically + * allocated, we can still free it on the returned pointer. Note the reuse + * of endp to mean the front of the string buffer now. + */ + endp = str; + if (frontp != str) { + while (*frontp) { + *endp++ = *frontp++; + } + *endp = L'\0'; + } + + return str; +} + +extern char* trim(char* str); + +void +ini_strip_quotes(ini_t ini) +{ + list_t *list = (list_t *) ini; + section_t *sec; + + sec = (section_t *) list->next; + + while (sec != NULL) { + entry_t *ent; + + ent = (entry_t *) sec->entry_head.next; + while (ent != NULL) { + if (ent->name[0] != '\0') { + int trailing_hash = strcspn(ent->data, "#"); + int trailing_quote; + ent->wdata[trailing_hash] = 0; + ent->data[trailing_hash] = 0; + if (ent->wdata[0] == L'\"') { + memmove(ent->wdata, &ent->wdata[1], sizeof(ent->wdata) - sizeof(wchar_t)); + } + if (ent->wdata[wcslen(ent->wdata) - 1] == L'\"') { + ent->wdata[wcslen(ent->wdata) - 1] = 0; + } + + if (ent->data[0] == '\"') { + memmove(ent->data, &ent->data[1], sizeof(ent->data) - sizeof(char)); + } + if (ent->data[strlen(ent->data) - 1] == '\"') { + ent->data[strlen(ent->data) - 1] = 0; + } + + trailing_quote = strcspn(ent->data, "\""); + ent->wdata[trailing_quote] = 0; + ent->data[trailing_quote] = 0; + + trim_w(ent->wdata); + trim(ent->data); + } + + ent = (entry_t *) ent->list.next; + } + + sec = (section_t *) sec->list.next; + } +} + ini_t ini_new(void) { @@ -593,6 +702,11 @@ ini_section_get_int(ini_section_t self, const char *name, int def) if (entry == NULL) return def; + if (stricmp(entry->data, "true") == 0) + return 1; + if (stricmp(entry->data, "false") == 0) + return 0; + sscanf(entry->data, "%i", &value); return value; @@ -642,8 +756,9 @@ double ini_section_get_double(ini_section_t self, const char *name, double def) { section_t *section = (section_t *) self; - const entry_t *entry; - double value = 0; + entry_t *entry; + double value = 0; + int res = 0; if (section == NULL) return def; @@ -652,7 +767,17 @@ ini_section_get_double(ini_section_t self, const char *name, double def) if (entry == NULL) return def; - sscanf(entry->data, "%lg", &value); + res = sscanf(entry->data, "%lg", &value); + if (res == EOF || res <= 0) { + int i = 0; + for (i = 0; i < strlen(entry->data); i++) { + if (entry->data[i] == ',') { + entry->data[i] = '.'; + entry->wdata[i] = L'.'; + } + } + (void)sscanf(entry->data, "%lg", &value); + } return value; } diff --git a/src/utils/log.c b/src/utils/log.c new file mode 100644 index 000000000..257029b51 --- /dev/null +++ b/src/utils/log.c @@ -0,0 +1,364 @@ +/* + * 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. + * + * New logging system handler. + * + * Authors: Miran Grca, + * Fred N. van Kempen, + * Connor Hyde, + * + * Copyright 2021-25 Miran Grca. + * Copyright 2021-25 Fred N. van Kempen. + * Copyright 2025 Connor Hyde. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define HAVE_STDARG_H +#include <86box/86box.h> +#include <86box/config.h> +#include <86box/mem.h> +#include "cpu.h" +#include <86box/plat.h> +#include <86box/version.h> +#include <86box/log.h> + +typedef struct log_t { + char buff[1024]; + char dev_name[1024]; + int seen; + int suppr_seen; + /* Cyclical log buffer. */ + char **cyclic_buff; + int32_t cyclic_last_line; + int32_t log_cycles; +} log_t; + +/* File to log output to. */ +extern FILE *stdlog; +/* Functions only used in this translation unit. */ +void log_ensure_stdlog_open(void); + +void +log_set_dev_name(void *priv, char *dev_name) +{ + log_t *log = (log_t *) priv; + + memcpy(log->dev_name, dev_name, strlen(dev_name) + 1); +} + +static void +log_copy(log_t *log, char *dest, const char *src, size_t dest_size) +{ + memset(dest, 0x00, dest_size * sizeof(char)); + + if ((log != NULL) && strcmp(log->dev_name, "")) { + strcat(dest, log->dev_name); + strcat(dest, ": "); + } + + strcat(dest, src); +} + +#ifndef RELEASE_BUILD +void +log_ensure_stdlog_open(void) +{ + if (stdlog == NULL) { + if (log_path[0] != '\0') { + stdlog = plat_fopen(log_path, "w"); + if (stdlog == NULL) + stdlog = stdout; + } else + stdlog = stdout; + } +} + +void +log_set_suppr_seen(void *priv, int suppr_seen) +{ + log_t *log = (log_t *) priv; + + log->suppr_seen = suppr_seen; +} + +/* + Log something to the logfile or stdout. + + To avoid excessively-large logfiles because some + module repeatedly logs, we keep track of what is + being logged, and catch repeating entries. + */ +void +log_out(void *priv, const char *fmt, va_list ap) +{ + log_t *log = (log_t *) priv; + char temp[1024]; + char fmt2[1024]; + + if (log == NULL) + pclog("WARNING: Logging called with a NULL log pointer\n"); + else if (fmt == NULL) + pclog("WARNING: Logging called with a NULL format pointer\n"); + else if (fmt[0] != '\0') { + log_ensure_stdlog_open(); + + vsprintf(temp, fmt, ap); + if (log->suppr_seen && !strcmp(log->buff, temp)) + log->seen++; + else { + if (log->suppr_seen && log->seen) { + log_copy(log, fmt2, "*** %d repeats ***\n", 1024); + fprintf(stdlog, fmt2, log->seen); + } + log->seen = 0; + strcpy(log->buff, temp); + log_copy(log, fmt2, temp, 1024); + fprintf(stdlog, fmt2, ap); + } + + fflush(stdlog); + } +} + +/* + Starfrost, 7-8 January 2025: + + For RIVA 128 emulation I needed a way to suppress logging if a repeated + pattern of the same set of lines were found. + + Implements a version of the Rabin-Karp algorithm: + https://en.wikipedia.org/wiki/Rabin%E2%80%93Karp_algorithm . +*/ +void +log_out_cyclic(void* priv, const char* fmt, va_list ap) +{ + /* Get our new logging system instance. */ + log_t* log = (log_t*) priv; + + /* Does the log actually exist? */ + if (log == NULL) + pclog("WARNING: Cyclical logging called with a NULL log pointer\n"); + else if (log->cyclic_buff == NULL) + pclog("WARNING: Cyclical logging called with a non-cyclic log\n"); + else if (fmt == NULL) + pclog("WARNING: Cyclical logging called with a NULL format pointer\n"); + /* Is the string empty? */ + else if (fmt[0] != '\0') { + /* Ensure stdlog is open. */ + log_ensure_stdlog_open(); + + char temp[LOG_SIZE_BUFFER] = {0}; + + log->cyclic_last_line %= LOG_SIZE_BUFFER_CYCLIC_LINES; + + vsprintf(temp, fmt, ap); + + log_copy(log, log->cyclic_buff[log->cyclic_last_line], temp, + LOG_SIZE_BUFFER); + + uint32_t hashes[LOG_SIZE_BUFFER_CYCLIC_LINES] = {0}; + + /* Random numbers. */ + uint32_t base = 257; + uint32_t mod = 1000000007; + + uint32_t repeat_order = 0; + bool is_cycle = false; + + /* Compute the set of hashes for the current log buffer. */ + for (int32_t log_line = 0; log_line < LOG_SIZE_BUFFER_CYCLIC_LINES; + log_line++) { + if (log->cyclic_buff[log_line][0] == '\0') + continue; /* Skip. */ + + for (int32_t log_line_char = 0; log_line_char < LOG_SIZE_BUFFER; + log_line_char++) + hashes[log_line] = hashes[log_line] * base + + log->cyclic_buff[log_line][log_line_char] % mod; + } + + /* + Now see if there are real cycles. + We implement a minimum repeat size. + */ + for (int32_t check_size = LOG_MINIMUM_REPEAT_ORDER; + check_size < LOG_SIZE_BUFFER_CYCLIC_LINES / 2; check_size++) { + /* + TODO: Log what we need for cycle 1. + TODO: Command line option that lets us turn off this behaviour. + */ + for (int32_t log_line_to_check = 0; log_line_to_check < check_size; + log_line_to_check++) { + if (hashes[log_line_to_check] == + hashes[(log_line_to_check + check_size) % + LOG_SIZE_BUFFER_CYCLIC_LINES]) { + repeat_order = check_size; + break; + } + } + + is_cycle = (repeat_order != 0); + + /* If there still is a cycle, break. */ + if (is_cycle) + break; + + } + + if (is_cycle) { + if (log->cyclic_last_line % repeat_order == 0) { + log->log_cycles++; + + if (log->log_cycles == 1) { + /* + 'Replay' the last few log entries so they actually + show up. + + TODO: Is this right? + */ + + for (uint32_t index = log->cyclic_last_line - 1; + index > (log->cyclic_last_line - repeat_order); + index--) { + /* *Very important* to prevent out of bounds index. */ + uint32_t real_index = index % + LOG_SIZE_BUFFER_CYCLIC_LINES; + log_copy(log, temp, log->cyclic_buff[real_index], + LOG_SIZE_BUFFER); + + fprintf(stdlog, "%s", log->cyclic_buff[real_index]); + } + + /* Restore the original line. */ + log_copy(log, temp, + log->cyclic_buff[log->cyclic_last_line], + LOG_SIZE_BUFFER); + + /* Allow normal logging. */ + fprintf(stdlog, "%s", temp); + } + + if (log->log_cycles > 1 && log->log_cycles < 100) + fprintf(stdlog, "***** Cyclical Log Repeat of Order %d " + "#%d *****\n", repeat_order, log->log_cycles); + else if (log->log_cycles == 100) + fprintf(stdlog, "Logged the same cycle 100 times... " + "Silence until something interesting happens\n"); + } + } else { + log->log_cycles = 0; + fprintf(stdlog, "%s", temp); + } + + log->cyclic_last_line++; + } +} +#endif + +void +log_fatal(void *priv, const char *fmt, ...) +{ + log_t *log = (log_t *) priv; + char temp[1024]; + char fmt2[1024]; + va_list ap; + + if (log == NULL) + return; + + if (log->cyclic_buff != NULL) { + for (int i = 0; i < LOG_SIZE_BUFFER_CYCLIC_LINES; i++) + if (log->cyclic_buff[i] != NULL) + free(log->cyclic_buff[i]); + free(log->cyclic_buff); + } + + va_start(ap, fmt); + log_copy(log, fmt2, fmt, 1024); + vsprintf(temp, fmt2, ap); + fatal_ex(fmt2, ap); + va_end(ap); + exit(-1); +} + +void +log_warning(void *priv, const char *fmt, ...) +{ + log_t *log = (log_t *) priv; + char temp[1024]; + char fmt2[1024]; + va_list ap; + + if (log == NULL) + return; + + if (log->cyclic_buff != NULL) { + for (int i = 0; i < LOG_SIZE_BUFFER_CYCLIC_LINES; i++) + if (log->cyclic_buff[i] != NULL) + free(log->cyclic_buff[i]); + free(log->cyclic_buff); + } + + va_start(ap, fmt); + log_copy(log, fmt2, fmt, 1024); + vsprintf(temp, fmt2, ap); + warning_ex(fmt2, ap); + va_end(ap); +} + +static void * +log_open_common(const char *dev_name, const int cyclic) +{ + log_t *log = calloc(1, sizeof(log_t)); + + memcpy(log->dev_name, dev_name, strlen(dev_name) + 1); + log->suppr_seen = 1; + log->cyclic_last_line = 0; + log->log_cycles = 0; + + if (cyclic) { + log->cyclic_buff = calloc(LOG_SIZE_BUFFER_CYCLIC_LINES, + sizeof(char *)); + for (int i = 0; i < LOG_SIZE_BUFFER_CYCLIC_LINES; i++) + log->cyclic_buff[i] = calloc(LOG_SIZE_BUFFER, sizeof(char)); + } + + return (void *) log; +} + +void * +log_open(const char *dev_name) +{ + return log_open_common(dev_name, 0); +} + +/* + This is so that not all logs get the 32k cyclical buffer + they may not need. + */ +void * +log_open_cyclic(const char *dev_name) +{ + return log_open_common(dev_name, 1); +} + +void +log_close(void *priv) +{ + log_t *log = (log_t *) priv; + + free(log); +} diff --git a/src/random.c b/src/utils/random.c similarity index 100% rename from src/random.c rename to src/utils/random.c diff --git a/src/video/CMakeLists.txt b/src/video/CMakeLists.txt index bbd329b7e..4cac8b76d 100644 --- a/src/video/CMakeLists.txt +++ b/src/video/CMakeLists.txt @@ -11,23 +11,135 @@ # Authors: David Hrdlička, # # Copyright 2020-2021 David Hrdlička. +# Copyright 2025 starfrost # -add_library(vid OBJECT agpgart.c video.c vid_table.c vid_cga.c vid_cga_comp.c - vid_compaq_cga.c vid_mda.c vid_hercules.c vid_herculesplus.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_mach8.c vid_ati_mach64.c vid_ati68875_ramdac.c - vid_ati68860_ramdac.c vid_bt481_ramdac.c vid_bt48x_ramdac.c vid_chips_69000.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 - vid_rtg310x.c vid_f82c425.c vid_ti_cf62011.c vid_tvga.c vid_tgui9440.c - vid_tkd8001_ramdac.c vid_att20c49x_ramdac.c vid_s3.c vid_s3_virge.c - vid_ibm_rgb528_ramdac.c vid_sdac_ramdac.c vid_ogc.c vid_mga.c vid_nga.c - vid_tvp3026_ramdac.c vid_att2xc498_ramdac.c vid_xga.c - vid_bochs_vbe.c) +add_library(vid OBJECT + + # Video Core + agpgart.c + video.c + vid_table.c + + # RAMDAC (Should this be its own library?) + ramdac/vid_ramdac_ati68860.c + ramdac/vid_ramdac_ati68875.c + ramdac/vid_ramdac_att20c49x.c + ramdac/vid_ramdac_att2xc498.c + ramdac/vid_ramdac_bt48x.c + ramdac/vid_ramdac_bt481.c + ramdac/vid_ramdac_ibm_rgb528.c + ramdac/vid_ramdac_sc1148x.c + ramdac/vid_ramdac_sc1502x.c + ramdac/vid_ramdac_sdac.c + ramdac/vid_ramdac_stg1702.c + ramdac/vid_ramdac_tkd8001.c + ramdac/vid_ramdac_tvp3026.c + + # Clock generator chips + clockgen/vid_clockgen_av9194.c + clockgen/vid_clockgen_icd2061.c + clockgen/vid_clockgen_ics2494.c + clockgen/vid_clockgen_ics2595.c + + # DDC / monitor identification stuff + vid_ddc.c + + # CARDS start here + + # CGA / Super CGA + vid_cga.c + vid_cga_comp.c + vid_cga_compaq.c + vid_cga_compaq_plasma.c + vid_cga_colorplus.c + vid_cga_ncr.c + vid_cga_olivetti.c + vid_cga_toshiba_t1000.c + vid_cga_toshiba_t3100e.c + + # PCJr/Tandy + vid_pcjr.c + vid_tandy.c + vid_mda.c + + # Hercules + vid_hercules.c + vid_hercules_plus.c + vid_hercules_incolor.c + + # Other early CGA-era cards + vid_genius.c + vid_sigma.c + + # PGC / IM1024 / WY700 high-resolution + vid_pgc.c + vid_im1024.c + vid_wy700.c + + # EGA + vid_ega.c + vid_ega_render.c + vid_jega.c + + # (Real IBM) VGA + vid_vga.c + + # Super VGA core + vid_svga.c + vid_svga_render.c + + # 8514/A, XGA and derivatives + vid_8514a.c + vid_xga.c + vid_ps55da2.c + + # ATI Technologies + vid_ati_eeprom.c + vid_ati18800.c + vid_ati28800.c + vid_ati_mach8.c + vid_ati_mach64.c + + # Chips & Technologies + vid_chips_69000.c + + # Cirrus Logic + vid_cl54xx.c + + # Tseng Labs + vid_et3000.c + vid_et4000.c + vid_et4000w32.c + + # Headland + vid_ht216.c + vid_oak_oti.c + + # Paradise + vid_paradise.c + vid_rtg310x.c + vid_f82c425.c + vid_ti_cf62011.c + + # Trident + vid_tvga.c + vid_tgui9440.c + + # S3 Graphics + vid_s3.c + vid_s3_virge.c + + # Matrox + vid_mga.c + + # NVidia (pending) + nv/nv_rivatimer.c + + # Generic + vid_bochs_vbe.c + +) if(G100) target_compile_definitions(vid PRIVATE USE_G100) @@ -37,10 +149,20 @@ if(XL24) target_compile_definitions(vid PRIVATE USE_XL24) endif() -add_library(voodoo OBJECT vid_voodoo.c vid_voodoo_banshee.c - vid_voodoo_banshee_blitter.c vid_voodoo_blitter.c vid_voodoo_display.c - vid_voodoo_fb.c vid_voodoo_fifo.c vid_voodoo_reg.c vid_voodoo_render.c - vid_voodoo_setup.c vid_voodoo_texture.c) +# 3Dfx Voodoo +add_library(voodoo OBJECT + vid_voodoo.c + vid_voodoo_banshee.c + vid_voodoo_banshee_blitter.c + vid_voodoo_blitter.c + vid_voodoo_display.c + vid_voodoo_fb.c + vid_voodoo_fifo.c + vid_voodoo_reg.c + vid_voodoo_render.c + vid_voodoo_setup.c + vid_voodoo_texture.c +) if(NOT MSVC AND (ARCH STREQUAL "i386" OR ARCH STREQUAL "x86_64")) target_compile_options(voodoo PRIVATE "-msse2") diff --git a/src/video/agpgart.c b/src/video/agpgart.c index b8ae2bdc8..bf1976b73 100644 --- a/src/video/agpgart.c +++ b/src/video/agpgart.c @@ -167,7 +167,7 @@ const device_t agpgart_device = { .init = agpgart_init, .close = agpgart_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_av9194.c b/src/video/clockgen/vid_clockgen_av9194.c similarity index 98% rename from src/video/vid_av9194.c rename to src/video/clockgen/vid_clockgen_av9194.c index e7cf75dee..951f3519c 100644 --- a/src/video/vid_av9194.c +++ b/src/video/clockgen/vid_clockgen_av9194.c @@ -103,7 +103,7 @@ const device_t av9194_device = { .init = av9194_init, .close = NULL, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_icd2061.c b/src/video/clockgen/vid_clockgen_icd2061.c similarity index 99% rename from src/video/vid_icd2061.c rename to src/video/clockgen/vid_clockgen_icd2061.c index 4c23d6ec5..7b80a5484 100644 --- a/src/video/vid_icd2061.c +++ b/src/video/clockgen/vid_clockgen_icd2061.c @@ -179,7 +179,7 @@ const device_t icd2061_device = { .init = icd2061_init, .close = icd2061_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -193,7 +193,7 @@ const device_t ics9161_device = { .init = icd2061_init, .close = icd2061_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_ics2494.c b/src/video/clockgen/vid_clockgen_ics2494.c similarity index 98% rename from src/video/vid_ics2494.c rename to src/video/clockgen/vid_clockgen_ics2494.c index e85b4539e..350a490cc 100644 --- a/src/video/vid_ics2494.c +++ b/src/video/clockgen/vid_clockgen_ics2494.c @@ -168,7 +168,7 @@ const device_t ics2494an_305_device = { .init = ics2494_init, .close = ics2494_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -182,7 +182,7 @@ const device_t ati18810_device = { .init = ics2494_init, .close = ics2494_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -196,7 +196,7 @@ const device_t ati18811_0_device = { .init = ics2494_init, .close = ics2494_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -210,7 +210,7 @@ const device_t ati18811_1_device = { .init = ics2494_init, .close = ics2494_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_ics2595.c b/src/video/clockgen/vid_clockgen_ics2595.c similarity index 99% rename from src/video/vid_ics2595.c rename to src/video/clockgen/vid_clockgen_ics2595.c index ecb414f2b..b5da3d7e2 100644 --- a/src/video/vid_ics2595.c +++ b/src/video/clockgen/vid_clockgen_ics2595.c @@ -129,7 +129,7 @@ const device_t ics2595_device = { .init = ics2595_init, .close = ics2595_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/nv/nv_rivatimer.c b/src/video/nv/nv_rivatimer.c new file mode 100644 index 000000000..12d40c026 --- /dev/null +++ b/src/video/nv/nv_rivatimer.c @@ -0,0 +1,274 @@ +/* + * 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. + * + * Fast, high-frequency, CPU-independent timer. + * + * + * + * Authors: Connor Hyde, I need a better email address ;^) + * + * Copyright 2024-2025 starfrost + */ + +/* See vid_nv_rivatimer.h comments for rationale behind not using the regular timer system + +Notes applicable to this file: +Since Windows XP, QueryPerformanceCounter and QueryPerformanceFrequency cannot fail so they are not checked. + +*/ + +#include <86box/nv/vid_nv_rivatimer.h> + +#ifdef _WIN32 +LARGE_INTEGER performance_frequency; +#endif + +rivatimer_t* rivatimer_head; // The head of the rivatimer list. +rivatimer_t* rivatimer_tail; // The tail of the rivatimer list. + +/* Functions only used in this translation unit */ +bool rivatimer_really_exists(rivatimer_t* rivatimer); // Determine if a rivatimer really exists in the linked list. + +void rivatimer_init(void) +{ + // Destroy all the rivatimers. + rivatimer_t* rivatimer_ptr = rivatimer_head; + + if (!rivatimer_ptr) + return; + + while (rivatimer_ptr) + { + // since we are destroing it + rivatimer_t* old_next = rivatimer_ptr->next; + rivatimer_destroy(rivatimer_ptr); + + rivatimer_ptr = old_next; + } + + + #ifdef _WIN32 + // Query the performance frequency. + QueryPerformanceFrequency(&performance_frequency); + #endif +} + +// Creates a rivatimer. +rivatimer_t* rivatimer_create(double period, void (*callback)(double real_time)) +{ + rivatimer_t* new_rivatimer = NULL; + + // See i + if (period <= 0 + || !callback) + { + fatal("Invalid rivatimer_create call: period <= 0 or no callback"); + } + + // If there are no rivatimers, create one + if (!rivatimer_head) + { + rivatimer_head = calloc(1, sizeof(rivatimer_t)); + rivatimer_head->prev = NULL; // indicate this is the first in the list even if we don't strictly need to + rivatimer_tail = rivatimer_head; + new_rivatimer = rivatimer_head; + } + else // Otherwise add a new one to the list + { + rivatimer_tail->next = calloc(1, sizeof(rivatimer_t)); + rivatimer_tail = rivatimer_tail->next; + new_rivatimer = rivatimer_tail; + } + + // sanity check + if (new_rivatimer) + { + new_rivatimer->running = false; + new_rivatimer->period = period; + new_rivatimer->next = NULL; // indicate this is the last in the list + new_rivatimer->callback = callback; + } + + return new_rivatimer; +} + +// Determines if a rivatimer really exists. +bool rivatimer_really_exists(rivatimer_t* rivatimer) +{ + rivatimer_t* current = rivatimer_head; + + if (!current) + return false; + + while (current) + { + if (current == rivatimer) + return true; + + current = current->next; + } + + return false; +} + +// Destroy a rivatimer. +void rivatimer_destroy(rivatimer_t* rivatimer_ptr) +{ + if (!rivatimer_really_exists(rivatimer_ptr)) + fatal("rivatimer_destroy: The timer was already destroyed, or never existed in the first place."); + + // Case: We are destroying the head + if (rivatimer_ptr == rivatimer_head) + { + // This is the only rivatimer + if (rivatimer_ptr->next == NULL) + { + rivatimer_head = NULL; + rivatimer_tail = NULL; + } + // This is not the only rivatimer + else + { + rivatimer_head = rivatimer_ptr->next; + rivatimer_head->prev = NULL; + // This is the only rivatimer and now there is only one + if (!rivatimer_head->next) + rivatimer_tail = rivatimer_head; + } + } + // Case: We are destroying the tail + else if (rivatimer_ptr == rivatimer_tail) + { + // We already covered the case where there is only one item above + rivatimer_tail = rivatimer_ptr->prev; + rivatimer_tail->next = NULL; + } + // Case: This is not the first or last rivatimer, so we don't need to set the head or tail + else + { + // Fix the break in the chain that this + if (rivatimer_ptr->next) + rivatimer_ptr->prev->next = rivatimer_ptr->next; + if (rivatimer_ptr->prev) + rivatimer_ptr->next->prev = rivatimer_ptr->prev; + } + + free(rivatimer_ptr); + rivatimer_ptr = NULL; //explicitly set to null +} + +void rivatimer_update_all(void) +{ + rivatimer_t* rivatimer_ptr = rivatimer_head; + + if (!rivatimer_ptr) + return; + + while (rivatimer_ptr) + { + // if it's not running skip it + if (!rivatimer_ptr->running) + { + rivatimer_ptr = rivatimer_ptr->next; + continue; + } + + #ifdef _WIN32 + LARGE_INTEGER current_time; + + QueryPerformanceCounter(¤t_time); + + double microseconds = ((double)current_time.QuadPart / 1000000.0) - (rivatimer_ptr->starting_time.QuadPart / 1000000.0); + #else + struct timespec current_time; + + clock_gettime(CLOCK_REALTIME, ¤t_time); + + double microseconds = ((double)current_time.tv_sec * 1000000.0) + ((double)current_time.tv_nsec / 1000.0); + #endif + + rivatimer_ptr->time += microseconds; + + // Reset the current time so we can actually restart + #ifdef _WIN32 + QueryPerformanceCounter(&rivatimer_ptr->starting_time); + #else + clock_gettime(CLOCK_REALTIME, &rivatimer_ptr->starting_time); + #endif + + // Time to fire + if (microseconds > rivatimer_ptr->period) + { + if (!rivatimer_ptr->callback) + { + pclog("Eh? No callback in RivaTimer?"); + continue; + } + + rivatimer_ptr->callback(microseconds); + } + + rivatimer_ptr = rivatimer_ptr->next; + } + +} + +void rivatimer_start(rivatimer_t* rivatimer_ptr) +{ + if (!rivatimer_really_exists(rivatimer_ptr)) + fatal("rivatimer_start: The timer has been destroyed, or never existed in the first place."); + + if (rivatimer_ptr->period <= 0) + fatal("rivatimer_start: Zero period!"); + + rivatimer_ptr->running = true; + + // Start off so rivatimer_update_all can actually update. + #ifdef _WIN32 + QueryPerformanceCounter(&rivatimer_ptr->starting_time); + #else + clock_gettime(CLOCK_REALTIME, &rivatimer_ptr->starting_time); + #endif +} + +void rivatimer_stop(rivatimer_t* rivatimer_ptr) +{ + if (!rivatimer_really_exists(rivatimer_ptr)) + fatal("rivatimer_stop: The timer has been destroyed, or never existed in the first place."); + + rivatimer_ptr->running = false; + rivatimer_ptr->time = 0; +} + +// Get the current time value of a rivatimer +double rivatimer_get_time(rivatimer_t* rivatimer_ptr) +{ + if (!rivatimer_really_exists(rivatimer_ptr)) + fatal("rivatimer_get_time: The timer has been destroyed, or never existed in the first place."); + + return rivatimer_ptr->time; +} + +void rivatimer_set_callback(rivatimer_t* rivatimer_ptr, void (*callback)(double real_time)) +{ + if (!rivatimer_really_exists(rivatimer_ptr)) + fatal("rivatimer_set_callback: The timer has been destroyed, or never existed in the first place."); + + if (!callback) + fatal("rivatimer_set_callback: No callback!"); + + rivatimer_ptr->callback = callback; +} + +void rivatimer_set_period(rivatimer_t* rivatimer_ptr, double period) +{ + if (!rivatimer_really_exists(rivatimer_ptr)) + fatal("rivatimer_set_period: The timer has been destroyed, or never existed in the first place."); + + rivatimer_ptr->period = period; +} \ No newline at end of file diff --git a/src/video/vid_ati68860_ramdac.c b/src/video/ramdac/vid_ramdac_ati68860.c similarity index 78% rename from src/video/vid_ati68860_ramdac.c rename to src/video/ramdac/vid_ramdac_ati68860.c index cb6de4353..4411f2ee2 100644 --- a/src/video/vid_ati68860_ramdac.c +++ b/src/video/ramdac/vid_ramdac_ati68860.c @@ -67,23 +67,22 @@ typedef struct ati68860_ramdac_t { } ati68860_ramdac_t; void -ati68860_ramdac_out(uint16_t addr, uint8_t val, void *priv, svga_t *svga) +ati68860_ramdac_out(uint16_t addr, uint8_t val, int is_8514, void *priv, svga_t *svga) { ati68860_ramdac_t *ramdac = (ati68860_ramdac_t *) priv; - const ibm8514_t *dev = (ibm8514_t *) svga->dev8514; switch (addr) { case 0: - svga_out((dev && dev->on) ? 0x2ec : 0x3c8, val, svga); + svga_out(is_8514 ? 0x2ec : 0x3c8, val, svga); break; case 1: - svga_out((dev && dev->on) ? 0x2ed : 0x3c9, val, svga); + svga_out(is_8514 ? 0x2ed : 0x3c9, val, svga); break; case 2: - svga_out((dev && dev->on) ? 0x2ea : 0x3c6, val, svga); + svga_out(is_8514 ? 0x2ea : 0x3c6, val, svga); break; case 3: - svga_out((dev && dev->on) ? 0x2eb : 0x3c7, val, svga); + svga_out(is_8514 ? 0x2eb : 0x3c7, val, svga); break; default: ramdac->regs[addr & 0xf] = val; @@ -173,24 +172,23 @@ ati68860_ramdac_out(uint16_t addr, uint8_t val, void *priv, svga_t *svga) } uint8_t -ati68860_ramdac_in(uint16_t addr, void *priv, svga_t *svga) +ati68860_ramdac_in(uint16_t addr, int is_8514, void *priv, svga_t *svga) { const ati68860_ramdac_t *ramdac = (ati68860_ramdac_t *) priv; - const ibm8514_t *dev = (ibm8514_t *) svga->dev8514; uint8_t temp = 0; switch (addr) { case 0: - temp = svga_in((dev && dev->on) ? 0x2ec : 0x3c8, svga); + temp = svga_in(is_8514 ? 0x2ec : 0x3c8, svga); break; case 1: - temp = svga_in((dev && dev->on) ? 0x2ed : 0x3c9, svga); + temp = svga_in(is_8514 ? 0x2ed : 0x3c9, svga); break; case 2: - temp = svga_in((dev && dev->on) ? 0x2ea : 0x3c6, svga); + temp = svga_in(is_8514 ? 0x2ea : 0x3c6, svga); break; case 3: - temp = svga_in((dev && dev->on) ? 0x2eb : 0x3c7, svga); + temp = svga_in(is_8514 ? 0x2eb : 0x3c7, svga); break; case 4: case 8: @@ -263,38 +261,57 @@ void ati68860_hwcursor_draw(svga_t *svga, int displine) { const ati68860_ramdac_t *ramdac = (ati68860_ramdac_t *) svga->ramdac; + int comb; int offset; - uint8_t dat; + int x_pos; + int y_pos; + int shift = 0; + uint16_t dat; uint32_t col0 = ramdac->pallook[0]; uint32_t col1 = ramdac->pallook[1]; + uint32_t *p; - offset = svga->dac_hwcursor_latch.xoff; - 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; - else if ((dat & 3) == 3) - buffer32->line[displine][svga->dac_hwcursor_latch.x + x + svga->x_add] ^= 0xFFFFFF; - dat >>= 2; - if (!(dat & 2)) - buffer32->line[displine][svga->dac_hwcursor_latch.x + x + svga->x_add + 1] = (dat & 1) ? col1 : col0; - else if ((dat & 3) == 3) - buffer32->line[displine][svga->dac_hwcursor_latch.x + x + svga->x_add + 1] ^= 0xFFFFFF; - dat >>= 2; - if (!(dat & 2)) - buffer32->line[displine][svga->dac_hwcursor_latch.x + x + svga->x_add + 2] = (dat & 1) ? col1 : col0; - else if ((dat & 3) == 3) - buffer32->line[displine][svga->dac_hwcursor_latch.x + x + svga->x_add + 2] ^= 0xFFFFFF; - dat >>= 2; - if (!(dat & 2)) - buffer32->line[displine][svga->dac_hwcursor_latch.x + x + svga->x_add + 3] = (dat & 1) ? col1 : col0; - else if ((dat & 3) == 3) - buffer32->line[displine][svga->dac_hwcursor_latch.x + x + svga->x_add + 3] ^= 0xFFFFFF; - dat >>= 2; - offset += 4; + offset = svga->dac_hwcursor_latch.x - svga->dac_hwcursor_latch.xoff; + if (svga->packed_4bpp) + shift = 1; + + for (int x = 0; x < svga->dac_hwcursor_latch.cur_xsize; x += (8 >> shift)) { + if (shift) { + dat = svga->vram[(svga->dac_hwcursor_latch.addr) & svga->vram_mask] & 0x0f; + dat |= (svga->vram[(svga->dac_hwcursor_latch.addr + 1) & svga->vram_mask] << 4); + dat |= (svga->vram[(svga->dac_hwcursor_latch.addr + 2) & svga->vram_mask] << 8); + dat |= (svga->vram[(svga->dac_hwcursor_latch.addr + 3) & svga->vram_mask] << 12); + } else { + dat = svga->vram[svga->dac_hwcursor_latch.addr & svga->vram_mask]; + dat |= (svga->vram[(svga->dac_hwcursor_latch.addr + 1) & svga->vram_mask] << 8); + } + for (int xx = 0; xx < (8 >> shift); xx++) { + comb = (dat >> (xx << 1)) & 0x03; + + y_pos = displine; + x_pos = offset + svga->x_add; + p = buffer32->line[y_pos]; + + if (offset >= svga->dac_hwcursor_latch.x) { + switch (comb) { + case 0: + p[x_pos] = col0; + break; + case 1: + p[x_pos] = col1; + break; + case 3: + p[x_pos] ^= 0xffffff; + break; + + default: + break; + } + } + offset++; + } + svga->dac_hwcursor_latch.addr += 2; } - - svga->dac_hwcursor_latch.addr += 16; } static void @@ -314,7 +331,7 @@ const device_t ati68860_ramdac_device = { .init = ati68860_ramdac_init, .close = ati68860_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_ati68875_ramdac.c b/src/video/ramdac/vid_ramdac_ati68875.c similarity index 83% rename from src/video/vid_ati68875_ramdac.c rename to src/video/ramdac/vid_ramdac_ati68875.c index 447a8eca8..4de0ed3d9 100644 --- a/src/video/vid_ati68875_ramdac.c +++ b/src/video/ramdac/vid_ramdac_ati68875.c @@ -38,7 +38,7 @@ typedef struct ati68875_ramdac_t { } ati68875_ramdac_t; void -ati68875_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, void *priv, svga_t *svga) +ati68875_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, int is_8514, void *priv, svga_t *svga) { ati68875_ramdac_t *ramdac = (ati68875_ramdac_t *) priv; uint8_t rs = (addr & 0x03); @@ -48,10 +48,16 @@ ati68875_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, void *priv, sv switch (rs) { case 0x00: /* Palette Write Index Register (RS value = 0000) */ + svga_out(is_8514 ? 0x2ec : 0x3c8, val, svga); + break; case 0x01: /* Palette Data Register (RS value = 0001) */ + svga_out(is_8514 ? 0x2ed : 0x3c9, val, svga); + break; case 0x02: /* Pixel Read Mask Register (RS value = 0010) */ - case 0x03: - svga_out(addr, val, svga); + svga_out(is_8514 ? 0x2ea : 0x3c6, val, svga); + break; + case 0x03: /* Palette Read Index Register (RS value = 0011) */ + svga_out(is_8514 ? 0x2eb : 0x3c7, val, svga); break; case 0x08: /* General Control Register (RS value = 1000) */ ramdac->gen_cntl = val; @@ -83,7 +89,7 @@ ati68875_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, void *priv, sv } uint8_t -ati68875_ramdac_in(uint16_t addr, int rs2, int rs3, void *priv, svga_t *svga) +ati68875_ramdac_in(uint16_t addr, int rs2, int rs3, int is_8514, void *priv, svga_t *svga) { const ati68875_ramdac_t *ramdac = (ati68875_ramdac_t *) priv; uint8_t rs = (addr & 0x03); @@ -94,10 +100,16 @@ ati68875_ramdac_in(uint16_t addr, int rs2, int rs3, void *priv, svga_t *svga) switch (rs) { case 0x00: /* Palette Write Index Register (RS value = 0000) */ + temp = svga_in(is_8514 ? 0x2ec : 0x3c8, svga); + break; case 0x01: /* Palette Data Register (RS value = 0001) */ + temp = svga_in(is_8514 ? 0x2ed : 0x3c9, svga); + break; case 0x02: /* Pixel Read Mask Register (RS value = 0010) */ - case 0x03: - temp = svga_in(addr, svga); + temp = svga_in(is_8514 ? 0x2ea : 0x3c6, svga); + break; + case 0x03: /* Palette Read Index Register (RS value = 0011) */ + temp = svga_in(is_8514 ? 0x2eb : 0x3c7, svga); break; case 0x08: /* General Control Register (RS value = 1000) */ temp = ramdac->gen_cntl; @@ -160,7 +172,7 @@ const device_t ati68875_ramdac_device = { .init = ati68875_ramdac_init, .close = ati68875_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_att20c49x_ramdac.c b/src/video/ramdac/vid_ramdac_att20c49x.c similarity index 98% rename from src/video/vid_att20c49x_ramdac.c rename to src/video/ramdac/vid_ramdac_att20c49x.c index f13740d34..7815f79be 100644 --- a/src/video/vid_att20c49x_ramdac.c +++ b/src/video/ramdac/vid_ramdac_att20c49x.c @@ -182,7 +182,7 @@ const device_t att490_ramdac_device = { .init = att49x_ramdac_init, .close = att49x_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -196,7 +196,7 @@ const device_t att491_ramdac_device = { .init = att49x_ramdac_init, .close = att49x_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -210,7 +210,7 @@ const device_t att492_ramdac_device = { .init = att49x_ramdac_init, .close = att49x_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_att2xc498_ramdac.c b/src/video/ramdac/vid_ramdac_att2xc498.c similarity index 99% rename from src/video/vid_att2xc498_ramdac.c rename to src/video/ramdac/vid_ramdac_att2xc498.c index 47eebccae..f52b1432f 100644 --- a/src/video/vid_att2xc498_ramdac.c +++ b/src/video/ramdac/vid_ramdac_att2xc498.c @@ -183,7 +183,7 @@ const device_t att498_ramdac_device = { .init = att498_ramdac_init, .close = att498_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_bt481_ramdac.c b/src/video/ramdac/vid_ramdac_bt481.c similarity index 97% rename from src/video/vid_bt481_ramdac.c rename to src/video/ramdac/vid_ramdac_bt481.c index 6cf5f2b1b..1b81e2dc7 100644 --- a/src/video/vid_bt481_ramdac.c +++ b/src/video/ramdac/vid_ramdac_bt481.c @@ -26,6 +26,7 @@ #include <86box/timer.h> #include <86box/video.h> #include <86box/vid_svga.h> +#include <86box/plat_unused.h> typedef struct bt481_ramdac_t { int state; @@ -128,7 +129,7 @@ bt481_ramdac_in(uint16_t addr, int rs2, void *priv, svga_t *svga) } static void * -bt481_ramdac_init(const device_t *info) +bt481_ramdac_init(UNUSED(const device_t *info)) { bt481_ramdac_t *ramdac = (bt481_ramdac_t *) malloc(sizeof(bt481_ramdac_t)); memset(ramdac, 0, sizeof(bt481_ramdac_t)); @@ -153,7 +154,7 @@ const device_t bt481_ramdac_device = { .init = bt481_ramdac_init, .close = bt481_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_bt48x_ramdac.c b/src/video/ramdac/vid_ramdac_bt48x.c similarity index 99% rename from src/video/vid_bt48x_ramdac.c rename to src/video/ramdac/vid_ramdac_bt48x.c index 6b0ec300b..d608750e3 100644 --- a/src/video/vid_bt48x_ramdac.c +++ b/src/video/ramdac/vid_ramdac_bt48x.c @@ -538,7 +538,7 @@ const device_t bt484_ramdac_device = { .init = bt48x_ramdac_init, .close = bt48x_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -552,7 +552,7 @@ const device_t att20c504_ramdac_device = { .init = bt48x_ramdac_init, .close = bt48x_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -566,7 +566,7 @@ const device_t bt485_ramdac_device = { .init = bt48x_ramdac_init, .close = bt48x_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -580,7 +580,7 @@ const device_t att20c505_ramdac_device = { .init = bt48x_ramdac_init, .close = bt48x_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -594,7 +594,7 @@ const device_t bt485a_ramdac_device = { .init = bt48x_ramdac_init, .close = bt48x_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_ibm_rgb528_ramdac.c b/src/video/ramdac/vid_ramdac_ibm_rgb528.c similarity index 91% rename from src/video/vid_ibm_rgb528_ramdac.c rename to src/video/ramdac/vid_ramdac_ibm_rgb528.c index 1b19a3a0f..cd7d5c1b6 100644 --- a/src/video/vid_ibm_rgb528_ramdac.c +++ b/src/video/ramdac/vid_ramdac_ibm_rgb528.c @@ -104,7 +104,7 @@ ibm_rgb528_render_4bpp(svga_t *svga) if ((svga->displine + svga->y_add) < 0) return; - if (svga->changedvram[svga->ma >> 12] || svga->changedvram[(svga->ma >> 12) + 1] || svga->changedvram[(svga->ma >> 12) + 2] || svga->fullchange) { + if (svga->changedvram[svga->memaddr >> 12] || svga->changedvram[(svga->memaddr >> 12) + 1] || svga->changedvram[(svga->memaddr >> 12) + 2] || svga->fullchange) { p = &buffer32->line[svga->displine + svga->y_add][svga->x_add]; if (svga->firstline_draw == 2000) @@ -114,8 +114,8 @@ ibm_rgb528_render_4bpp(svga_t *svga) for (int x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { if (vram_size == 3) { if (!(x & 31)) { - dat64 = *(uint64_t *) (&svga->vram[svga->ma]); - dat642 = *(uint64_t *) (&svga->vram[svga->ma + 8]); + dat64 = *(uint64_t *) (&svga->vram[svga->memaddr]); + dat642 = *(uint64_t *) (&svga->vram[svga->memaddr + 8]); if (swap_word) { dat64 = (dat64 << 32ULL) | (dat64 >> 32ULL); dat642 = (dat642 << 32ULL) | (dat642 >> 32ULL); @@ -127,7 +127,7 @@ ibm_rgb528_render_4bpp(svga_t *svga) dat = (((x & 16) ? dat642 : dat64) >> (((x & 15) << 2) ^ 4)) & 0xf; } else if (vram_size == 1) { if (!(x & 15)) { - dat64 = *(uint64_t *) (&svga->vram[svga->ma]); + dat64 = *(uint64_t *) (&svga->vram[svga->memaddr]); if (swap_word) dat64 = (dat64 << 32ULL) | (dat64 >> 32ULL); } @@ -137,7 +137,7 @@ ibm_rgb528_render_4bpp(svga_t *svga) dat = (dat64 >> (((x & 15) << 2) ^ 4)) & 0xf; } else { if (!(x & 7)) - dat32 = *(uint32_t *) (&svga->vram[svga->ma]); + dat32 = *(uint32_t *) (&svga->vram[svga->memaddr]); if (swap_nib) dat = (dat32 >> ((x & 7) << 2)) & 0xf; else @@ -156,11 +156,11 @@ ibm_rgb528_render_4bpp(svga_t *svga) p[x] = dat_out.pixel & 0xffffff; if ((vram_size == 3) && ((x & 31) == 31)) - svga->ma = (svga->ma + 16) & svga->vram_display_mask; + svga->memaddr = (svga->memaddr + 16) & svga->vram_display_mask; if ((vram_size == 1) && ((x & 15) == 15)) - svga->ma = (svga->ma + 8) & svga->vram_display_mask; + svga->memaddr = (svga->memaddr + 8) & svga->vram_display_mask; else if ((!vram_size) && ((x & 7) == 7)) - svga->ma = (svga->ma + 4) & svga->vram_display_mask; + svga->memaddr = (svga->memaddr + 4) & svga->vram_display_mask; } } } @@ -182,7 +182,7 @@ ibm_rgb528_render_8bpp(svga_t *svga) if ((svga->displine + svga->y_add) < 0) return; - if (svga->changedvram[svga->ma >> 12] || svga->changedvram[(svga->ma >> 12) + 1] || svga->changedvram[(svga->ma >> 12) + 2] || svga->fullchange) { + if (svga->changedvram[svga->memaddr >> 12] || svga->changedvram[(svga->memaddr >> 12) + 1] || svga->changedvram[(svga->memaddr >> 12) + 2] || svga->fullchange) { p = &buffer32->line[svga->displine + svga->y_add][svga->x_add]; if (svga->firstline_draw == 2000) @@ -192,8 +192,8 @@ ibm_rgb528_render_8bpp(svga_t *svga) for (int x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { if (vram_size == 3) { if (!(x & 15)) { - dat64 = *(uint64_t *) (&svga->vram[svga->ma]); - dat642 = *(uint64_t *) (&svga->vram[svga->ma + 8]); + dat64 = *(uint64_t *) (&svga->vram[svga->memaddr]); + dat642 = *(uint64_t *) (&svga->vram[svga->memaddr + 8]); if (swap_word) { dat64 = (dat64 << 32ULL) | (dat64 >> 32ULL); dat642 = (dat642 << 32ULL) | (dat642 >> 32ULL); @@ -202,14 +202,14 @@ ibm_rgb528_render_8bpp(svga_t *svga) dat = (((x & 8) ? dat642 : dat64) >> ((x & 7) << 3)) & 0xff; } else if (vram_size == 1) { if (!(x & 7)) { - dat64 = *(uint64_t *) (&svga->vram[svga->ma]); + dat64 = *(uint64_t *) (&svga->vram[svga->memaddr]); if (swap_word) dat64 = (dat64 << 32ULL) | (dat64 >> 32ULL); } dat = (dat64 >> ((x & 7) << 3)) & 0xff; } else { if (!(x & 3)) - dat32 = *(uint32_t *) (&svga->vram[svga->ma]); + dat32 = *(uint32_t *) (&svga->vram[svga->memaddr]); dat = (dat32 >> ((x & 3) << 3)) & 0xff; } if (b8_dcol == 0x00) { @@ -225,11 +225,11 @@ ibm_rgb528_render_8bpp(svga_t *svga) p[x] = dat_out.pixel & 0xffffff; if ((vram_size == 3) && ((x & 15) == 15)) - svga->ma = (svga->ma + 16) & svga->vram_display_mask; + svga->memaddr = (svga->memaddr + 16) & svga->vram_display_mask; else if ((vram_size == 1) && ((x & 7) == 7)) - svga->ma = (svga->ma + 8) & svga->vram_display_mask; + svga->memaddr = (svga->memaddr + 8) & svga->vram_display_mask; else if ((!vram_size) && ((x & 3) == 3)) - svga->ma = (svga->ma + 4) & svga->vram_display_mask; + svga->memaddr = (svga->memaddr + 4) & svga->vram_display_mask; } } } @@ -262,7 +262,7 @@ ibm_rgb528_render_15_16bpp(svga_t *svga) if (b555_565 && (b16_dcol != 0x01)) partition &= 0xc0; - if (svga->changedvram[svga->ma >> 12] || svga->changedvram[(svga->ma >> 12) + 1] || svga->changedvram[(svga->ma >> 12) + 2] || svga->fullchange) { + if (svga->changedvram[svga->memaddr >> 12] || svga->changedvram[(svga->memaddr >> 12) + 1] || svga->changedvram[(svga->memaddr >> 12) + 2] || svga->fullchange) { p = &buffer32->line[svga->displine + svga->y_add][svga->x_add]; if (svga->firstline_draw == 2000) @@ -272,8 +272,8 @@ ibm_rgb528_render_15_16bpp(svga_t *svga) for (int x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { if (vram_size == 2) { if (!(x & 7)) { - dat64 = *(uint64_t *) (&svga->vram[svga->ma]); - dat642 = *(uint64_t *) (&svga->vram[svga->ma + 8]); + dat64 = *(uint64_t *) (&svga->vram[svga->memaddr]); + dat642 = *(uint64_t *) (&svga->vram[svga->memaddr + 8]); if (swap_word) { dat64 = (dat64 << 32ULL) | (dat64 >> 32ULL); dat642 = (dat64 << 32ULL) | (dat642 >> 32ULL); @@ -282,14 +282,14 @@ ibm_rgb528_render_15_16bpp(svga_t *svga) dat = (((x & 4) ? dat642 : dat64) >> ((x & 3) << 4)) & 0xffff; } else if (vram_size == 1) { if (!(x & 3)) { - dat64 = *(uint64_t *) (&svga->vram[svga->ma]); + dat64 = *(uint64_t *) (&svga->vram[svga->memaddr]); if (swap_word) dat64 = (dat64 << 32ULL) | (dat64 >> 32ULL); } dat = (dat64 >> ((x & 3) << 4)) & 0xffff; } else { if (!(x & 1)) - dat32 = *(uint32_t *) (&svga->vram[svga->ma]); + dat32 = *(uint32_t *) (&svga->vram[svga->memaddr]); dat = (dat32 >> ((x & 1) << 4)) & 0xffff; } dat_ex = (ibm_rgb528_pixel16_t *) &dat; @@ -350,11 +350,11 @@ ibm_rgb528_render_15_16bpp(svga_t *svga) p[x] = dat_out.pixel & 0xffffff; if ((vram_size == 3) && ((x & 7) == 7)) - svga->ma = (svga->ma + 16) & svga->vram_display_mask; + svga->memaddr = (svga->memaddr + 16) & svga->vram_display_mask; else if ((vram_size == 1) && ((x & 3) == 3)) - svga->ma = (svga->ma + 8) & svga->vram_display_mask; + svga->memaddr = (svga->memaddr + 8) & svga->vram_display_mask; else if (!vram_size && ((x & 1) == 1)) - svga->ma = (svga->ma + 4) & svga->vram_display_mask; + svga->memaddr = (svga->memaddr + 4) & svga->vram_display_mask; } } } @@ -378,7 +378,7 @@ ibm_rgb528_render_24bpp(svga_t *svga) if ((svga->displine + svga->y_add) < 0) return; - if (svga->changedvram[svga->ma >> 12] || svga->changedvram[(svga->ma >> 12) + 1] || svga->changedvram[(svga->ma >> 12) + 2] || svga->fullchange) { + if (svga->changedvram[svga->memaddr >> 12] || svga->changedvram[(svga->memaddr >> 12) + 1] || svga->changedvram[(svga->memaddr >> 12) + 2] || svga->fullchange) { p = &buffer32->line[svga->displine + svga->y_add][svga->x_add]; if (svga->firstline_draw == 2000) @@ -389,12 +389,12 @@ ibm_rgb528_render_24bpp(svga_t *svga) dat_ex = (ibm_rgb528_pixel32_t *) &dat; if (vram_size == 3) { if ((x & 15) == 0) { - dat64[0] = *(uint64_t *) (&svga->vram[svga->ma & svga->vram_display_mask]); - dat64[1] = *(uint64_t *) (&svga->vram[(svga->ma + 8) & svga->vram_display_mask]); - dat64[2] = *(uint64_t *) (&svga->vram[(svga->ma + 16) & svga->vram_display_mask]); - dat64[3] = *(uint64_t *) (&svga->vram[(svga->ma + 24) & svga->vram_display_mask]); - dat64[4] = *(uint64_t *) (&svga->vram[(svga->ma + 32) & svga->vram_display_mask]); - dat64[5] = *(uint64_t *) (&svga->vram[(svga->ma + 40) & svga->vram_display_mask]); + dat64[0] = *(uint64_t *) (&svga->vram[svga->memaddr & svga->vram_display_mask]); + dat64[1] = *(uint64_t *) (&svga->vram[(svga->memaddr + 8) & svga->vram_display_mask]); + dat64[2] = *(uint64_t *) (&svga->vram[(svga->memaddr + 16) & svga->vram_display_mask]); + dat64[3] = *(uint64_t *) (&svga->vram[(svga->memaddr + 24) & svga->vram_display_mask]); + dat64[4] = *(uint64_t *) (&svga->vram[(svga->memaddr + 32) & svga->vram_display_mask]); + dat64[5] = *(uint64_t *) (&svga->vram[(svga->memaddr + 40) & svga->vram_display_mask]); if (swap_word) { dat64[0] = (dat64[0] << 32ULL) | (dat64[0] >> 32ULL); dat64[1] = (dat64[1] << 32ULL) | (dat64[1] >> 32ULL); @@ -407,9 +407,9 @@ ibm_rgb528_render_24bpp(svga_t *svga) 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]); - dat64[1] = *(uint64_t *) (&svga->vram[(svga->ma + 8) & svga->vram_display_mask]); - dat64[2] = *(uint64_t *) (&svga->vram[(svga->ma + 16) & svga->vram_display_mask]); + dat64[0] = *(uint64_t *) (&svga->vram[svga->memaddr & svga->vram_display_mask]); + dat64[1] = *(uint64_t *) (&svga->vram[(svga->memaddr + 8) & svga->vram_display_mask]); + dat64[2] = *(uint64_t *) (&svga->vram[(svga->memaddr + 16) & svga->vram_display_mask]); if (swap_word) { dat64[0] = (dat64[0] << 32ULL) | (dat64[0] >> 32ULL); dat64[1] = (dat64[1] << 32ULL) | (dat64[1] >> 32ULL); @@ -441,9 +441,9 @@ ibm_rgb528_render_24bpp(svga_t *svga) p[x] = dat_ex->pixel & 0xffffff; if ((vram_size == 3) && ((x & 15) == 15)) - svga->ma = (svga->ma + 48) & svga->vram_display_mask; + svga->memaddr = (svga->memaddr + 48) & svga->vram_display_mask; else if ((vram_size == 1) && ((x & 7) == 7)) - svga->ma = (svga->ma + 24) & svga->vram_display_mask; + svga->memaddr = (svga->memaddr + 24) & svga->vram_display_mask; } } } @@ -468,7 +468,7 @@ ibm_rgb528_render_32bpp(svga_t *svga) if ((svga->displine + svga->y_add) < 0) return; - if (svga->changedvram[svga->ma >> 12] || svga->changedvram[(svga->ma >> 12) + 1] || svga->changedvram[(svga->ma >> 12) + 2] || svga->fullchange) { + if (svga->changedvram[svga->memaddr >> 12] || svga->changedvram[(svga->memaddr >> 12) + 1] || svga->changedvram[(svga->memaddr >> 12) + 2] || svga->fullchange) { p = &buffer32->line[svga->displine + svga->y_add][svga->x_add]; if (svga->firstline_draw == 2000) @@ -478,8 +478,8 @@ ibm_rgb528_render_32bpp(svga_t *svga) for (int x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { if (vram_size == 3) { if (!(x & 3)) { - dat64 = *(uint64_t *) (&svga->vram[svga->ma]); - dat642 = *(uint64_t *) (&svga->vram[svga->ma + 8]); + dat64 = *(uint64_t *) (&svga->vram[svga->memaddr]); + dat642 = *(uint64_t *) (&svga->vram[svga->memaddr + 8]); if (swap_word) { dat64 = (dat64 << 32ULL) | (dat64 >> 32ULL); dat642 = (dat642 << 32ULL) | (dat642 >> 32ULL); @@ -488,13 +488,13 @@ ibm_rgb528_render_32bpp(svga_t *svga) dat = (((x & 2) ? dat642 : dat64) >> ((x & 1ULL) << 5ULL)) & 0xffffffff; } else if (vram_size == 1) { if (!(x & 1)) { - dat64 = *(uint64_t *) (&svga->vram[svga->ma]); + dat64 = *(uint64_t *) (&svga->vram[svga->memaddr]); if (swap_word) dat64 = (dat64 << 32ULL) | (dat64 >> 32ULL); } dat = (dat64 >> ((x & 1ULL) << 5ULL)) & 0xffffffff; } else - dat = *(uint32_t *) (&svga->vram[svga->ma]); + dat = *(uint32_t *) (&svga->vram[svga->memaddr]); dat_ex = (ibm_rgb528_pixel32_t *) &dat; if (swaprb) { temp = dat_ex->r; @@ -520,11 +520,11 @@ ibm_rgb528_render_32bpp(svga_t *svga) p[x] = dat_ex->pixel & 0xffffff; if ((vram_size == 3) && ((x & 3) == 3)) - svga->ma = (svga->ma + 16) & svga->vram_display_mask; + svga->memaddr = (svga->memaddr + 16) & svga->vram_display_mask; else if ((vram_size == 1) && ((x & 1) == 1)) - svga->ma = (svga->ma + 8) & svga->vram_display_mask; + svga->memaddr = (svga->memaddr + 8) & svga->vram_display_mask; else if (!vram_size) - svga->ma = (svga->ma + 4) & svga->vram_display_mask; + svga->memaddr = (svga->memaddr + 4) & svga->vram_display_mask; } } } @@ -982,7 +982,7 @@ const device_t ibm_rgb528_ramdac_device = { .init = ibm_rgb528_ramdac_init, .close = ibm_rgb528_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_sc1148x_ramdac.c b/src/video/ramdac/vid_ramdac_sc1148x.c similarity index 98% rename from src/video/vid_sc1148x_ramdac.c rename to src/video/ramdac/vid_ramdac_sc1148x.c index 24ca4aeec..0ebcb49b6 100644 --- a/src/video/vid_sc1148x_ramdac.c +++ b/src/video/ramdac/vid_ramdac_sc1148x.c @@ -156,7 +156,7 @@ const device_t sc11483_ramdac_device = { .init = sc1148x_ramdac_init, .close = sc1148x_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -170,7 +170,7 @@ const device_t sc11487_ramdac_device = { .init = sc1148x_ramdac_init, .close = sc1148x_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -184,7 +184,7 @@ const device_t sc11484_nors2_ramdac_device = { .init = sc1148x_ramdac_init, .close = sc1148x_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -198,7 +198,7 @@ const device_t sc11486_ramdac_device = { .init = sc1148x_ramdac_init, .close = sc1148x_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_sc1502x_ramdac.c b/src/video/ramdac/vid_ramdac_sc1502x.c similarity index 99% rename from src/video/vid_sc1502x_ramdac.c rename to src/video/ramdac/vid_ramdac_sc1502x.c index 7315c65ad..1c7d4014d 100644 --- a/src/video/vid_sc1502x_ramdac.c +++ b/src/video/ramdac/vid_ramdac_sc1502x.c @@ -249,7 +249,7 @@ const device_t sc1502x_ramdac_device = { .init = sc1502x_ramdac_init, .close = sc1502x_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_sdac_ramdac.c b/src/video/ramdac/vid_ramdac_sdac.c similarity index 98% rename from src/video/vid_sdac_ramdac.c rename to src/video/ramdac/vid_ramdac_sdac.c index 83796506e..4e6deacdc 100644 --- a/src/video/vid_sdac_ramdac.c +++ b/src/video/ramdac/vid_ramdac_sdac.c @@ -313,7 +313,7 @@ const device_t gendac_ramdac_device = { .init = sdac_ramdac_init, .close = sdac_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -327,7 +327,7 @@ const device_t tseng_ics5301_ramdac_device = { .init = sdac_ramdac_init, .close = sdac_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -341,7 +341,7 @@ const device_t tseng_ics5341_ramdac_device = { .init = sdac_ramdac_init, .close = sdac_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL @@ -355,7 +355,7 @@ const device_t sdac_ramdac_device = { .init = sdac_ramdac_init, .close = sdac_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_stg_ramdac.c b/src/video/ramdac/vid_ramdac_stg1702.c similarity index 99% rename from src/video/vid_stg_ramdac.c rename to src/video/ramdac/vid_ramdac_stg1702.c index 187139b3b..85d492ce7 100644 --- a/src/video/vid_stg_ramdac.c +++ b/src/video/ramdac/vid_ramdac_stg1702.c @@ -263,7 +263,7 @@ const device_t stg_ramdac_device = { .init = stg_ramdac_init, .close = stg_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_tkd8001_ramdac.c b/src/video/ramdac/vid_ramdac_tkd8001.c similarity index 99% rename from src/video/vid_tkd8001_ramdac.c rename to src/video/ramdac/vid_ramdac_tkd8001.c index 4108b9a4e..c8ad1c421 100644 --- a/src/video/vid_tkd8001_ramdac.c +++ b/src/video/ramdac/vid_ramdac_tkd8001.c @@ -129,7 +129,7 @@ const device_t tkd8001_ramdac_device = { .init = tkd8001_ramdac_init, .close = tkd8001_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_tvp3026_ramdac.c b/src/video/ramdac/vid_ramdac_tvp3026.c similarity index 99% rename from src/video/vid_tvp3026_ramdac.c rename to src/video/ramdac/vid_ramdac_tvp3026.c index 6c001b461..bd5a83fd0 100644 --- a/src/video/vid_tvp3026_ramdac.c +++ b/src/video/ramdac/vid_ramdac_tvp3026.c @@ -733,7 +733,7 @@ const device_t tvp3026_ramdac_device = { .init = tvp3026_ramdac_init, .close = tvp3026_ramdac_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_8514a.c b/src/video/vid_8514a.c index 0e51feae4..97202340d 100644 --- a/src/video/vid_8514a.c +++ b/src/video/vid_8514a.c @@ -15,6 +15,7 @@ * * Copyright 2022-2024 TheCollector1995. */ +#include #include #include #include @@ -32,7 +33,6 @@ #include <86box/mca.h> #include <86box/rom.h> #include <86box/plat.h> -#include <86box/thread.h> #include <86box/video.h> #include <86box/vid_8514a.h> #include <86box/vid_8514a_device.h> @@ -47,7 +47,6 @@ # undef CLAMP #endif - #define BIOS_MACH8_ROM_PATH "roms/video/mach8/11301113140_4k.BIN" static void ibm8514_accel_outb(uint16_t port, uint8_t val, void *priv); @@ -84,14 +83,14 @@ CLAMP(int16_t in, int16_t min, int16_t max) return in; } -#define WRITE8(addr, var, val) \ - switch ((addr) & 1) { \ - case 0: \ - var = (var & 0xff00) | (val); \ - break; \ - case 1: \ - var = (var & 0x00ff) | ((val) << 8); \ - break; \ +#define WRITE8(addr, var, val) \ + switch ((addr) & 1) { \ + case 0: \ + var = (var & 0xff00) | (val); \ + break; \ + case 1: \ + var = (var & 0x00ff) | ((val) << 8); \ + break; \ } #define READ8(addr, var) \ @@ -105,139 +104,129 @@ CLAMP(int16_t in, int16_t min, int16_t max) } -#define READ_PIXTRANS_WORD(cx, n) \ - if ((cmd <= 1) || (cmd == 5)) { \ +#define READ_PIXTRANS_WORD(cx, n) \ + if ((cmd <= 1) || (cmd == 5)) { \ 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); \ - } \ + } 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) \ - if (dev->bpp) \ +#define READ(addr, dat) \ + if (dev->bpp) \ dat = vram_w[(addr) & (dev->vram_mask >> 1)]; \ - else \ + else \ dat = (dev->vram[(addr) & (dev->vram_mask)]); \ -#define READ_HIGH(addr, dat) \ +#define READ_HIGH(addr, dat) \ dat |= (dev->vram[(addr) & (dev->vram_mask)] << 8); -#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) >> 1; \ - break; \ - case 0x16: \ - dest_dat = (src_dat - dest_dat) >> 1; \ - break; \ - case 0x17: \ - dest_dat = (dest_dat + src_dat) >> 1; \ - 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: \ - if (dev->bpp) \ - dest_dat = MIN(0xffff, (dest_dat + src_dat)); \ - else \ - 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: \ - if (dev->bpp) \ - dest_dat = (0xffff < (src_dat + dest_dat)) ? 0xffff : ((src_dat + dest_dat) / 2); \ - else \ - dest_dat = (0xff < (src_dat + dest_dat)) ? 0xff : ((src_dat + dest_dat) / 2); \ - break; \ - } \ +#define MIX(mixmode, dest_dat, src_dat) \ + { \ + switch ((mixmode) ? dev->accel.frgd_mix : dev->accel.bkgd_mix) { \ + 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: \ + case 0x11: \ + dest_dat = ~src_dat | dest_dat; \ + break; \ + case 0x0a: \ + case 0x12: \ + dest_dat = src_dat | ~dest_dat; \ + break; \ + case 0x0b: \ + case 0x13: \ + 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 0x14: \ + dest_dat = MAX(src_dat, dest_dat); \ + break; \ + case 0x15: \ + dest_dat = (src_dat | ~dest_dat) >> 1; \ + break; \ + case 0x16: \ + dest_dat = (~src_dat | dest_dat) >> 1; \ + break; \ + case 0x17: \ + dest_dat = (src_dat | dest_dat) >> 1; \ + break; \ + case 0x18: \ + case 0x19: \ + dest_dat = MAX(0, ~src_dat | dest_dat); \ + break; \ + case 0x1a: \ + dest_dat = MAX(0, src_dat | ~dest_dat); \ + break; \ + case 0x1b: \ + if (dev->bpp) \ + dest_dat = MIN(0xffff, src_dat | dest_dat); \ + else \ + dest_dat = MIN(0xff, src_dat | dest_dat); \ + break; \ + case 0x1c: \ + case 0x1d: \ + dest_dat = MAX(0, ~src_dat | dest_dat) >> 1; \ + break; \ + case 0x1e: \ + dest_dat = MAX(0, src_dat | ~dest_dat) >> 1; \ + break; \ + case 0x1f: \ + if (dev->bpp) \ + dest_dat = (0xffff < (src_dat | dest_dat)) ? 0xffff : ((src_dat | dest_dat) >> 1); \ + else \ + dest_dat = (0xff < (src_dat | dest_dat)) ? 0xff : ((src_dat | dest_dat) >> 1); \ + break; \ + } \ } -#define WRITE(addr, dat) \ - if (dev->bpp) { \ - vram_w[((addr)) & (dev->vram_mask >> 1)] = dat; \ - dev->changedvram[(((addr)) & (dev->vram_mask >> 1)) >> 11] = changeframecount; \ - } else { \ - dev->vram[((addr)) & (dev->vram_mask)] = dat; \ - dev->changedvram[(((addr)) & (dev->vram_mask)) >> 12] = changeframecount; \ +#define WRITE(addr, dat) \ + if (dev->bpp) { \ + vram_w[((addr)) & (dev->vram_mask >> 1)] = dat; \ + dev->changedvram[(((addr)) & (dev->vram_mask >> 1)) >> 11] = svga->monitor->mon_changeframecount; \ + } else { \ + dev->vram[((addr)) & (dev->vram_mask)] = dat; \ + dev->changedvram[(((addr)) & (dev->vram_mask)) >> 12] = svga->monitor->mon_changeframecount; \ } int ibm8514_active = 0; @@ -247,7 +236,7 @@ ibm8514_cpu_src(svga_t *svga) { const ibm8514_t *dev = (ibm8514_t *) svga->dev8514; - if (!(dev->accel.cmd & 0x100)) + if (dev->accel.cmd_back) return 0; if (dev->accel.cmd & 1) @@ -261,7 +250,7 @@ ibm8514_cpu_dest(svga_t *svga) { const ibm8514_t *dev = (ibm8514_t *) svga->dev8514; - if (!(dev->accel.cmd & 0x100)) + if (dev->accel.cmd_back) return 0; if (dev->accel.cmd & 1) @@ -279,11 +268,11 @@ ibm8514_accel_out_pixtrans(svga_t *svga, UNUSED(uint16_t port), uint32_t val, in 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 frgd_mix = dev->accel.frgd_sel; + int bkgd_mix = dev->accel.bkgd_sel; int cmd = dev->accel.cmd >> 13; - if (dev->accel.cmd & 0x100) { + if (!dev->accel.cmd_back) { if (len == 2) { /*Bus size*/ if (dev->accel.cmd & 0x200) /*16-bit*/ @@ -301,7 +290,7 @@ ibm8514_accel_out_pixtrans(svga_t *svga, UNUSED(uint16_t port), uint32_t val, in if ((cmd >= 2) && (dev->accel.cmd & 0x1000)) val = (val >> 8) | (val << 8); } - if ((cmd <= 2) || (cmd == 4) || ((cmd == 6))) { + if ((cmd <= 2) || (cmd == 4) || (cmd == 6)) { if ((dev->accel.cmd & 0x08) && (cmd >= 2)) monoxfer = val; else { @@ -345,27 +334,173 @@ ibm8514_accel_out_fifo(svga_t *svga, uint16_t port, uint32_t val, int len) { ibm8514_t *dev = (ibm8514_t *) svga->dev8514; - if (port != 0x9ae8 && port != 0xe2e8) - ibm8514_log("Port OUT FIFO=%04x, val=%04x, len=%d.\n", port, val, len); + if (port & 0x8000) { + if ((port != 0xe2e8) && (port != 0xe2e9) && (port != 0xe6e8) && (port != 0xe6e9)) { + if (port & 0x4000) + port &= ~0x4000; + } + } switch (port) { + case 0x2e8: + WRITE8(port, dev->htotal, val); + ibm8514_log("IBM 8514/A compatible: (0x%04x): htotal=0x%02x.\n", port, val); + svga_recalctimings(svga); + break; + + case 0x6e8: + /*In preparation to switch from VGA to 8514/A mode*/ + WRITE8(port, dev->hdisped, val); + ibm8514_log("[%04X:%08X]: IBM 8514/A: (0x%04x): hdisp=0x%02x.\n", CS, cpu_state.pc, port, val); + svga_recalctimings(svga); + break; + + case 0x6e9: + WRITE8(port - 1, dev->htotal, val); + ibm8514_log("IBM 8514/A compatible: (0x%04x): htotal=0x%02x.\n", port, val); + svga_recalctimings(svga); + break; + + case 0xae8: + WRITE8(port, dev->hsync_start, val); + ibm8514_log("IBM 8514/A compatible: (0x%04x): val=0x%02x, hsync_start=%d.\n", port, val, (val + 1) << 3); + svga_recalctimings(svga); + break; + + case 0xee8: + WRITE8(port, dev->hsync_width, val); + ibm8514_log("IBM 8514/A compatible: (0x%04x): val=0x%02x, hsync_width=%d, hsyncpol=%02x.\n", port, val & 0x1f, ((val & 0x1f) + 1) << 3, val & 0x20); + svga_recalctimings(svga); + break; + + case 0x12e8: + /*In preparation to switch from VGA to 8514/A mode*/ + if (len == 2) { + dev->v_total_reg = val; + dev->v_total_reg &= 0x1fff; + ibm8514_log("IBM 8514/A compatible: (0x%04x): vtotal=0x%02x.\n", port, val); + svga_recalctimings(svga); + } else { + WRITE8(port, dev->v_total_reg, val); + } + break; + case 0x12e9: + /*In preparation to switch from VGA to 8514/A mode*/ + if (len == 1) { + WRITE8(port, dev->v_total_reg, val >> 8); + dev->v_total_reg &= 0x1fff; + ibm8514_log("IBM 8514/A compatible: (0x%04x): vtotal=0x%02x.\n", port, val); + svga_recalctimings(svga); + } + break; + + case 0x16e8: + /*In preparation to switch from VGA to 8514/A mode*/ + if (len == 2) { + dev->v_disp = val; + dev->v_disp &= 0x1fff; + ibm8514_log("IBM 8514/A: V_DISP write 16E8 = %d\n", dev->v_disp); + ibm8514_log("IBM 8514/A: (0x%04x): vdisp=0x%02x.\n", port, val); + svga_recalctimings(svga); + } else { + WRITE8(port, dev->v_disp, val); + } + break; + case 0x16e9: + /*In preparation to switch from VGA to 8514/A mode*/ + if (len == 1) { + WRITE8(port, dev->v_disp, val >> 8); + dev->v_disp &= 0x1fff; + ibm8514_log("IBM 8514/A: V_DISP write 16E8 = %d\n", dev->v_disp); + ibm8514_log("IBM 8514/A: (0x%04x): vdisp=0x%02x.\n", port, val); + svga_recalctimings(svga); + } + break; + + case 0x1ae8: + /*In preparation to switch from VGA to 8514/A mode*/ + if (len == 2) { + dev->v_sync_start = val; + dev->v_sync_start &= 0x1fff; + ibm8514_log("IBM 8514/A compatible: V_SYNCSTART write 1AE8 = %d\n", dev->v_syncstart); + ibm8514_log("IBM 8514/A compatible: (0x%04x): vsyncstart=0x%02x.\n", port, val); + svga_recalctimings(svga); + } else { + WRITE8(port, dev->v_sync_start, val); + } + break; + case 0x1ae9: + /*In preparation to switch from VGA to 8514/A mode*/ + if (len == 1) { + WRITE8(port, dev->v_sync_start, val >> 8); + dev->v_sync_start &= 0x1fff; + dev->v_syncstart = dev->v_sync_start + 1; + if (dev->interlace) + dev->v_syncstart >>= 1; + + ibm8514_log("IBM 8514/A compatible: V_SYNCSTART write 1AE8 = %d\n", dev->v_syncstart); + ibm8514_log("IBM 8514/A compatible: (0x%04x): vsyncstart=0x%02x.\n", port, val); + svga_recalctimings(svga); + } + break; + + case 0x22e8: + dev->disp_cntl = val; + dev->interlace = !!(dev->disp_cntl & 0x10); + ibm8514_log("IBM 8514/A compatible: DISP_CNTL write %04x=%02x, interlace=%d.\n", port, dev->disp_cntl, dev->interlace); + svga_recalctimings(svga); + break; + + case 0x1ee8: + case 0x1ee9: + ibm8514_log("IBM 8514/A compatible: V_SYNC_WID write 1EE8 = %02x\n", val); + ibm8514_log("IBM 8514/A compatible: (0x%04x): vsyncwidth=0x%02x.\n", port, val); + svga_recalctimings(svga); + break; + + case 0x42e8: + ibm8514_log("VBLANK status=%02x, val=%02x.\n", dev->subsys_stat, val); + if (len == 2) { + dev->subsys_cntl = val; + dev->subsys_stat &= ~val; + if ((val & 0xc000) == 0x8000) { + dev->force_busy = 0; + dev->force_busy2 = 0; + } + } else { + WRITE8(port, dev->subsys_cntl, val); + dev->subsys_stat &= ~val; + } + break; + case 0x42e9: + if (len == 1) { + WRITE8(port, dev->subsys_cntl, val); + if ((val & 0xc0) == 0x80) { + dev->force_busy = 0; + dev->force_busy2 = 0; + } + } + break; + + case 0x4ae8: + WRITE8(port, dev->accel.advfunc_cntl, val); + dev->on = dev->accel.advfunc_cntl & 0x01; + ibm8514_log("[%04X:%08X]: IBM 8514/A: (0x%04x): ON=%d, shadow crt=%x, hdisp=%d, vdisp=%d.\n", CS, cpu_state.pc, port, dev->on, dev->accel.advfunc_cntl & 0x04, dev->hdisp, dev->vdisp); + ibm8514_log("IBM mode set %s resolution.\n", (dev->accel.advfunc_cntl & 0x04) ? "2: 1024x768" : "1: 640x480"); + svga_recalctimings(svga); + break; + case 0x82e8: - case 0xc2e8: - dev->fifo_idx++; if (len == 2) dev->accel.cur_y = val & 0x7ff; break; case 0x86e8: - case 0xc6e8: - dev->fifo_idx++; if (len == 2) dev->accel.cur_x = val & 0x7ff; break; case 0x8ae8: - case 0xcae8: - dev->fifo_idx++; if (len == 2) { dev->accel.desty = val & 0x7ff; dev->accel.desty_axstp = val & 0x3fff; @@ -375,8 +510,6 @@ ibm8514_accel_out_fifo(svga_t *svga, uint16_t port, uint32_t val, int len) break; case 0x8ee8: - case 0xcee8: - dev->fifo_idx++; if (len == 2) { dev->accel.destx = val & 0x7ff; dev->accel.destx_distp = val & 0x3fff; @@ -386,13 +519,8 @@ ibm8514_accel_out_fifo(svga_t *svga, uint16_t port, uint32_t val, int len) break; case 0x92e8: - dev->fifo_idx++; - if (len == 2) - dev->test = val; - fallthrough; - - case 0xd2e8: if (len == 2) { + dev->test = val; dev->accel.err_term = val & 0x3fff; if (val & 0x2000) dev->accel.err_term |= ~0x1fff; @@ -400,8 +528,6 @@ ibm8514_accel_out_fifo(svga_t *svga, uint16_t port, uint32_t val, int len) break; case 0x96e8: - case 0xd6e8: - dev->fifo_idx++; if (len == 2) { dev->accel.maj_axis_pcnt = val & 0x7ff; dev->accel.maj_axis_pcnt_no_limit = val; @@ -409,8 +535,6 @@ ibm8514_accel_out_fifo(svga_t *svga, uint16_t port, uint32_t val, int len) break; case 0x9ae8: - case 0xdae8: - dev->fifo_idx++; dev->accel.ssv_state = 0; if (len == 2) { dev->data_available = 0; @@ -420,18 +544,24 @@ ibm8514_accel_out_fifo(svga_t *svga, uint16_t port, uint32_t val, int len) if (dev->accel.cmd & 0x100) dev->accel.cmd_back = 0; - ibm8514_log("8514/A CMD=%04x, back=%d.\n", dev->accel.cmd, dev->accel.cmd_back); + ibm8514_log("8514/A CMD=%04x, frgd color=%04x, frgdmix=%02x, pixcntl=%02x.\n", dev->accel.cmd, dev->accel.frgd_color, dev->accel.frgd_mix, dev->accel.multifunc[0x0a]); ibm8514_accel_start(-1, 0, -1, 0, svga, len); } break; case 0x9ee8: - case 0xdee8: - dev->fifo_idx++; dev->accel.ssv_state = 1; if (len == 2) { dev->accel.short_stroke = val; + 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->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); @@ -444,7 +574,6 @@ ibm8514_accel_out_fifo(svga_t *svga, uint16_t port, uint32_t val, int len) case 0xa2e8: case 0xe2e8: - dev->fifo_idx++; if (port == 0xe2e8) { if (len == 2) { if (dev->accel.cmd_back) @@ -463,7 +592,6 @@ ibm8514_accel_out_fifo(svga_t *svga, uint16_t port, uint32_t val, int len) case 0xa6e8: case 0xe6e8: - dev->fifo_idx++; if (port == 0xe6e8) { if (len == 2) { if (dev->accel.cmd_back) @@ -481,41 +609,33 @@ ibm8514_accel_out_fifo(svga_t *svga, uint16_t port, uint32_t val, int len) break; case 0xaae8: - case 0xeae8: - dev->fifo_idx++; if (len == 2) dev->accel.wrt_mask = val; break; case 0xaee8: - case 0xeee8: - dev->fifo_idx++; if (len == 2) dev->accel.rd_mask = val; break; case 0xb2e8: - case 0xf2e8: - dev->fifo_idx++; if (len == 2) dev->accel.color_cmp = val; break; case 0xb6e8: - case 0xf6e8: - dev->fifo_idx++; - dev->accel.bkgd_mix = val & 0xff; + dev->accel.bkgd_mix = val & 0x1f; + dev->accel.bkgd_sel = (val >> 5) & 3; + ibm8514_log("Background Mix reg=%02x.\n", val); break; case 0xbae8: - case 0xfae8: - dev->fifo_idx++; - dev->accel.frgd_mix = val & 0xff; + dev->accel.frgd_mix = val & 0x1f; + dev->accel.frgd_sel = (val >> 5) & 3; + ibm8514_log("Foreground Mix reg=%02x.\n", val); break; case 0xbee8: - case 0xfee8: - dev->fifo_idx++; if (len == 2) { dev->accel.multifunc_cntl = val; dev->accel.multifunc[dev->accel.multifunc_cntl >> 12] = dev->accel.multifunc_cntl & 0xfff; @@ -536,7 +656,6 @@ ibm8514_accel_out_fifo(svga_t *svga, uint16_t port, uint32_t val, int len) if ((dev->accel.multifunc_cntl >> 12) == 4) dev->accel.clip_right = dev->accel.multifunc[4] & 0x7ff; - } break; @@ -624,129 +743,15 @@ ibm8514_accel_out(uint16_t port, uint32_t val, svga_t *svga, int len) { ibm8514_t *dev = (ibm8514_t *) svga->dev8514; - if (port & 0x8000) - ibm8514_accel_out_fifo(svga, port, val, len); - else { - switch (port) { - case 0x2e8: - case 0x6e9: - WRITE8(port, dev->htotal, val); - ibm8514_log("IBM 8514/A compatible: (0x%04x): htotal=0x%02x.\n", port, val); - svga_recalctimings(svga); - break; - - case 0x6e8: - /*In preparation to switch from VGA to 8514/A mode*/ - dev->hdisped = val; - dev->hdisp = (dev->hdisped + 1) << 3; - ibm8514_log("[%04X:%08X]: IBM 8514/A: (0x%04x): hdisp=0x%02x.\n", CS, cpu_state.pc, port, val); - svga_recalctimings(svga); - break; - - case 0xae8: - dev->hsync_start = val; - ibm8514_log("IBM 8514/A compatible: (0x%04x): val=0x%02x, hsync_start=%d.\n", port, val, (val + 1) << 3); - svga_recalctimings(svga); - break; - - case 0xee8: - dev->hsync_width = val; - ibm8514_log("IBM 8514/A compatible: (0x%04x): val=0x%02x, hsync_width=%d, hsyncpol=%02x.\n", port, val & 0x1f, ((val & 0x1f) + 1) << 3, val & 0x20); - svga_recalctimings(svga); - break; - - case 0x12e8: - case 0x12e9: - /*In preparation to switch from VGA to 8514/A mode*/ - WRITE8(port, dev->v_total_reg, val); - dev->v_total_reg &= 0x1fff; - dev->v_total = dev->v_total_reg + 1; - if (dev->interlace) - dev->v_total >>= 1; - - ibm8514_log("IBM 8514/A compatible: (0x%04x): vtotal=0x%02x.\n", port, val); - svga_recalctimings(svga); - break; - - case 0x16e8: - case 0x16e9: - /*In preparation to switch from VGA to 8514/A mode*/ - WRITE8(port, dev->v_disp, val); - dev->v_disp &= 0x1fff; - dev->vdisp = (dev->v_disp + 1) >> 1; - ibm8514_log("IBM 8514/A: V_DISP write 16E8 = %d\n", dev->v_disp); - ibm8514_log("IBM 8514/A: (0x%04x): vdisp=0x%02x.\n", port, val); - svga_recalctimings(svga); - break; - - case 0x1ae8: - case 0x1ae9: - /*In preparation to switch from VGA to 8514/A mode*/ - WRITE8(port, dev->v_sync_start, val); - dev->v_sync_start &= 0x1fff; - dev->v_syncstart = dev->v_sync_start + 1; - if (dev->interlace) - dev->v_syncstart >>= 1; - - ibm8514_log("IBM 8514/A compatible: V_SYNCSTART write 1AE8 = %d\n", dev->v_syncstart); - ibm8514_log("IBM 8514/A compatible: (0x%04x): vsyncstart=0x%02x.\n", port, val); - svga_recalctimings(svga); - break; - - case 0x1ee8: - case 0x1ee9: - ibm8514_log("IBM 8514/A compatible: V_SYNC_WID write 1EE8 = %02x\n", val); - ibm8514_log("IBM 8514/A compatible: (0x%04x): vsyncwidth=0x%02x.\n", port, val); - svga_recalctimings(svga); - break; - - case 0x22e8: - dev->disp_cntl = val; - dev->interlace = !!(dev->disp_cntl & 0x10); - ibm8514_log("IBM 8514/A compatible: DISP_CNTL write %04x=%02x, interlace=%d.\n", port, dev->disp_cntl, dev->interlace); - svga_recalctimings(svga); - break; - - case 0x42e8: - if (val & 0x01) - dev->subsys_stat &= ~0x01; - if (val & 0x02) - dev->subsys_stat &= ~0x02; - if (val & 0x04) - dev->subsys_stat &= ~0x04; - if (val & 0x08) - dev->subsys_stat &= ~0x08; - break; - case 0x42e9: - dev->subsys_cntl = val; - if (val & 0x01) - dev->subsys_stat |= 0x01; - if (val & 0x02) - dev->subsys_stat |= 0x02; - if (val & 0x04) - dev->subsys_stat |= 0x04; - if (val & 0x08) - dev->subsys_stat |= 0x08; - - if ((val & 0xc0) == 0xc0) { - dev->fifo_idx = 0; - dev->force_busy = 0; - dev->force_busy2 = 0; - } - break; - - case 0x4ae8: - WRITE8(port, dev->accel.advfunc_cntl, val); - dev->on = dev->accel.advfunc_cntl & 0x01; - ibm8514_log("[%04X:%08X]: IBM 8514/A: (0x%04x): ON=%d, shadow crt=%x, hdisp=%d, vdisp=%d.\n", CS, cpu_state.pc, port, dev->on, dev->accel.advfunc_cntl & 0x04, dev->hdisp, dev->vdisp); - ibm8514_log("IBM mode set %s resolution.\n", (dev->accel.advfunc_cntl & 0x04) ? "2: 1024x768" : "1: 640x480"); - svga_recalctimings(svga); - break; - - default: - break; + if (port & 0x8000) { + if (dev->accel.cmd_back) { + dev->fifo_idx++; + if (dev->fifo_idx > 8) + dev->fifo_idx = 8; } } + + ibm8514_accel_out_fifo(svga, port, val, len); } static void @@ -774,13 +779,11 @@ ibm8514_accel_in_fifo(svga_t *svga, uint16_t port, int len) switch (port) { case 0x82e8: - case 0xc2e8: if (len == 2) temp = dev->accel.cur_y; break; case 0x86e8: - case 0xc6e8: if (len == 2) temp = dev->accel.cur_x; break; @@ -796,42 +799,75 @@ ibm8514_accel_in_fifo(svga_t *svga, uint16_t port, int len) break; case 0x9ae8: - case 0xdae8: - if ((dev->fifo_idx >= 1) && (dev->fifo_idx <= 8)) { - temp |= (1 << (dev->fifo_idx - 1)); - switch (dev->accel.cmd >> 13) { - case 2: - case 3: - case 4: - case 6: - if (dev->accel.sy < 0) - dev->fifo_idx = 0; - break; - default: - if (!dev->accel.sy) - dev->fifo_idx = 0; - break; - } - } if (len == 2) { - if (dev->force_busy) - temp |= 0x200; /*Hardware busy*/ - dev->force_busy = 0; + if (dev->fifo_idx <= 8) { + for (int i = 1; i <= dev->fifo_idx; i++) + temp |= (1 << (7 - (i - 1))); + } else + temp = 0x00ff; + + if (dev->fifo_idx > 0) + dev->fifo_idx--; + + if (dev->force_busy) { + temp |= 0x0200; /*Hardware busy*/ + switch (dev->accel.cmd >> 13) { + case 2: + case 3: + case 4: + case 6: + if (dev->accel.sy < 0) + dev->force_busy = 0; + break; + default: + if (!dev->accel.sy) + dev->force_busy = 0; + break; + } + } + if (dev->data_available) { - temp |= 0x100; /*Read Data available*/ - dev->data_available = 0; + temp |= 0x0100; /*Read Data available*/ + switch (dev->accel.cmd >> 13) { + case 2: + case 3: + case 4: + case 6: + if (dev->accel.sy < 0) + dev->data_available = 0; + break; + default: + if (!dev->accel.sy) + dev->data_available = 0; + break; + } } } break; case 0x9ae9: - case 0xdae9: if (len == 1) { + dev->fifo_idx = 0; + if (dev->force_busy2) temp |= 0x02; /*Hardware busy*/ + dev->force_busy2 = 0; + if (dev->data_available2) { temp |= 0x01; /*Read Data available*/ - dev->data_available2 = 0; + switch (dev->accel.cmd >> 13) { + case 2: + case 3: + case 4: + case 6: + if (dev->accel.sy < 0) + dev->data_available2 = 0; + break; + default: + if (!dev->accel.sy) + dev->data_available2 = 0; + break; + } } } break; @@ -878,7 +914,7 @@ ibm8514_accel_in(uint16_t port, svga_t *svga) if (dev->vc == dev->v_syncstart) temp |= 0x02; - ibm8514_log("0x2E8 read: Display Status=%02x.\n", temp); + ibm8514_log("Read: Display Status1=%02x.\n", temp); break; case 0x6e8: @@ -903,31 +939,35 @@ ibm8514_accel_in(uint16_t port, svga_t *svga) case 0x42e8: case 0x42e9: - if (dev->vc == dev->v_syncstart) - dev->subsys_stat |= 0x01; + if (!(port & 1)) { + if ((dev->subsys_cntl & INT_VSY) && !(dev->subsys_stat & INT_VSY) && (dev->vc == dev->dispend)) + temp |= INT_VSY; - if (cmd == 6) { - if ((dev->accel.dx >= clip_l) && - (dev->accel.dx <= clip_r_ibm) && - (dev->accel.dy >= clip_t) && - (dev->accel.dy <= clip_b_ibm)) - dev->subsys_stat |= 0x02; - } else { - if ((dev->accel.cx >= clip_l) && - (dev->accel.cx <= clip_r_ibm) && - (dev->accel.cy >= clip_t) && - (dev->accel.cy <= clip_b_ibm)) - dev->subsys_stat |= 0x02; - } + if (cmd == 6) { + if ((dev->subsys_cntl & INT_GE_BSY) && + !(dev->subsys_stat & INT_GE_BSY) && + (dev->accel.dx >= clip_l) && + (dev->accel.dx <= clip_r_ibm) && + (dev->accel.dy >= clip_t) && + (dev->accel.dy <= clip_b_ibm)) + temp |= INT_GE_BSY; + } else { + if ((dev->subsys_cntl & INT_GE_BSY) && + !(dev->subsys_stat & INT_GE_BSY) && + (dev->accel.cx >= clip_l) && + (dev->accel.cx <= clip_r_ibm) && + (dev->accel.cy >= clip_t) && + (dev->accel.cy <= clip_b_ibm)) + temp |= INT_GE_BSY; + } - if (!dev->fifo_idx) { - if (!dev->force_busy && !dev->force_busy2) - temp |= 0x08; - } - - if (port & 1) - temp = dev->vram_512k_8514 ? 0x00 : 0x80; - else { + if (!dev->fifo_idx && !dev->on) { + dev->force_busy = 0; + dev->force_busy2 = 0; + dev->data_available = 0; + dev->data_available2 = 0; + temp |= INT_FIFO_EMP; + } temp |= (dev->subsys_stat | (dev->vram_512k_8514 ? 0x00 : 0x80)); temp |= 0x20; } @@ -980,6 +1020,8 @@ ibm8514_short_stroke_start(int count, int cpu_input, uint32_t mix_dat, uint32_t dev->accel.ssv_len_back = dev->accel.ssv_len; if (ibm8514_cpu_src(svga)) { + dev->force_busy = 1; + dev->force_busy2 = 1; dev->data_available = 0; dev->data_available2 = 0; return; /*Wait for data from CPU*/ @@ -1026,13 +1068,8 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat rd_mask_polygon &= 0xff; } - if (dev->accel.cmd & 0x100) { - dev->force_busy = 1; - dev->force_busy2 = 1; - } - - frgd_mix = (dev->accel.frgd_mix >> 5) & 3; - bkgd_mix = (dev->accel.bkgd_mix >> 5) & 3; + frgd_mix = dev->accel.frgd_sel; + bkgd_mix = dev->accel.bkgd_sel; if (cpu_input) { if ((dev->accel.cmd & 0x02) || (pixcntl == 2)) { @@ -1131,24 +1168,16 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat old_mix_dat = mix_dat; - if (cmd == 5 || cmd == 1 || (cmd == 2 && (dev->accel.multifunc[0x0a] & 0x06))) - ibm8514_log("CMD=%d, full=%04x, pixcntl=%d, filling=%02x.\n", cmd, dev->accel.cmd, pixcntl, dev->accel.multifunc[0x0a] & 0x06); + if (cmd != 0) + ibm8514_log("CMD=%d, full=%04x, pixcntl=%d, filling=%02x, ssvdraw=%02x.\n", cmd, dev->accel.cmd, pixcntl, dev->accel.multifunc[0x0a] & 0x06, dev->accel.ssv_draw); /*Bit 4 of the Command register is the draw yes bit, which enables writing to memory/reading from memory when enabled. When this bit is disabled, no writing to memory/reading from memory is allowed. (This bit is almost meaningless on the NOP command)*/ switch (cmd) { case 0: /*NOP (Short Stroke Vectors)*/ - if (dev->accel.ssv_state == 0) { - 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->accel.ssv_state == 0) break; - } if (dev->accel.cmd & 0x08) { while (count-- && dev->accel.ssv_len >= 0) { @@ -1156,6 +1185,7 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat (dev->accel.cx <= clip_r) && (dev->accel.cy >= clip_t) && (dev->accel.cy <= clip_b)) { + dev->subsys_stat |= INT_GE_BSY; switch ((mix_dat & mix_mask) ? frgd_mix : bkgd_mix) { case 0: src_dat = bkgd_color; @@ -1205,6 +1235,11 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat cpu_dat >>= 8; if (!dev->accel.ssv_len) { + if (cpu_input) { + dev->force_busy = 0; + dev->force_busy2 = 0; + } + dev->fifo_idx = 0; dev->accel.cmd_back = 1; break; } @@ -1251,6 +1286,7 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat (dev->accel.cx <= clip_r) && (dev->accel.cy >= clip_t) && (dev->accel.cy <= clip_b)) { + dev->subsys_stat |= INT_GE_BSY; switch ((mix_dat & mix_mask) ? frgd_mix : bkgd_mix) { case 0: src_dat = bkgd_color; @@ -1300,6 +1336,11 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat cpu_dat >>= 8; if (!dev->accel.ssv_len) { + if (cpu_input) { + dev->force_busy = 0; + dev->force_busy2 = 0; + } + dev->fifo_idx = 0; dev->accel.cmd_back = 1; break; } @@ -1364,10 +1405,14 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat dev->accel.output = 1; } } + dev->force_busy = 1; + dev->force_busy2 = 1; dev->data_available = 0; dev->data_available2 = 0; return; /*Wait for data from CPU*/ } else if (ibm8514_cpu_dest(svga)) { + dev->force_busy = 1; + dev->force_busy2 = 1; dev->data_available = 1; dev->data_available2 = 1; return; @@ -1386,6 +1431,7 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat (dev->accel.cx <= clip_r) && (dev->accel.cy >= clip_t) && (dev->accel.cy <= clip_b)) { + dev->subsys_stat |= INT_GE_BSY; if (ibm8514_cpu_dest(svga) && (pixcntl == 0)) { mix_dat = mix_mask; /* Mix data = forced to foreground register. */ } else if (ibm8514_cpu_dest(svga) && (pixcntl == 3)) { @@ -1474,6 +1520,11 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat } if (!dev->accel.sy) { + if (cpu_input) { + dev->force_busy = 0; + dev->force_busy2 = 0; + } + dev->fifo_idx = 0; dev->accel.cmd_back = 1; if (!cpu_input) { dev->accel.cur_x = dev->accel.cx; @@ -1544,6 +1595,7 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat (dev->accel.cx <= clip_r) && (dev->accel.cy >= clip_t) && (dev->accel.cy <= clip_b)) { + dev->subsys_stat |= INT_GE_BSY; if (ibm8514_cpu_dest(svga)) { READ((dev->accel.cy * dev->pitch) + dev->accel.cx, src_dat); } else @@ -1593,6 +1645,11 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat cpu_dat >>= 8; if (!dev->accel.sy) { + if (cpu_input) { + dev->force_busy = 0; + dev->force_busy2 = 0; + } + dev->fifo_idx = 0; dev->accel.cmd_back = 1; break; } @@ -1635,6 +1692,7 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat (dev->accel.cx <= clip_r) && (dev->accel.cy >= clip_t) && (dev->accel.cy <= clip_b)) { + dev->subsys_stat |= INT_GE_BSY; if (ibm8514_cpu_dest(svga) && (pixcntl == 0)) { mix_dat = mix_mask; /* Mix data = forced to foreground register. */ } else if (ibm8514_cpu_dest(svga) && (pixcntl == 3)) { @@ -1695,6 +1753,11 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat cpu_dat >>= 8; if (!dev->accel.sy) { + if (cpu_input) { + dev->force_busy = 0; + dev->force_busy2 = 0; + } + dev->fifo_idx = 0; dev->accel.cmd_back = 1; if (!cpu_input) { dev->accel.cur_x = dev->accel.cx; @@ -1760,12 +1823,7 @@ 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; - if ((dev->accel_bpp == 24) || (dev->accel_bpp <= 8)) - dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); - else if (dev->bpp) - dev->accel.dest = (dev->accel.ge_offset << 1) + (dev->accel.cy * dev->pitch); - else - dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); + dev->accel.dest = dev->accel.ge_offset + (dev->accel.cy * dev->pitch); if (cmd == 4) dev->accel.cmd |= 0x02; @@ -1800,6 +1858,8 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat } } } + dev->force_busy = 1; + dev->force_busy2 = 1; dev->data_available = 0; dev->data_available2 = 0; return; /*Wait for data from CPU*/ @@ -1817,6 +1877,8 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat } } ibm8514_log("INPUT=%d.\n", dev->accel.input); + dev->force_busy = 1; + dev->force_busy2 = 1; dev->data_available = 1; dev->data_available2 = 1; return; /*Wait for data from CPU*/ @@ -1833,6 +1895,7 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat (dev->accel.cx <= clip_r) && (dev->accel.cy >= clip_t) && (dev->accel.cy <= clip_b)) { + dev->subsys_stat |= INT_GE_BSY; switch ((mix_dat & mix_mask) ? frgd_mix : bkgd_mix) { case 0: src_dat = bkgd_color; @@ -1964,18 +2027,17 @@ skip_vector_rect_write: break; } - if ((dev->accel_bpp == 24) || (dev->accel_bpp <= 8)) - dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); - else if (dev->bpp) - dev->accel.dest = (dev->accel.ge_offset << 1) + (dev->accel.cy * dev->pitch); - else - dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); + dev->accel.dest = dev->accel.ge_offset + (dev->accel.cy * dev->pitch); dev->accel.sy--; dev->accel.x_count = 0; - if (dev->accel.sy < 0) + if (dev->accel.sy < 0) { + dev->force_busy = 0; + dev->force_busy2 = 0; + dev->fifo_idx = 0; dev->accel.cmd_back = 1; + } return; } } @@ -1985,11 +2047,13 @@ skip_vector_rect_write: ibm8514_log("Vectored Rectangle with normal processing (TODO).\n"); } else { /*Normal Rectangle*/ if (cpu_input) { + ibm8514_log("Normal Pixel Rectangle Fill Transfer SY=%d.\n", dev->accel.sy); while (count-- && (dev->accel.sy >= 0)) { if ((dev->accel.cx >= clip_l) && (dev->accel.cx <= clip_r) && (dev->accel.cy >= clip_t) && (dev->accel.cy <= clip_b)) { + dev->subsys_stat |= INT_GE_BSY; if (ibm8514_cpu_dest(svga) && (pixcntl == 0)) { mix_dat = mix_mask; /* Mix data = forced to foreground register. */ } else if (ibm8514_cpu_dest(svga) && (pixcntl == 3)) { @@ -2122,18 +2186,17 @@ skip_nibble_rect_write: else dev->accel.cy--; - if ((dev->accel_bpp == 24) || (dev->accel_bpp <= 8)) - dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); - else if (dev->bpp) - dev->accel.dest = (dev->accel.ge_offset << 1) + (dev->accel.cy * dev->pitch); - else - dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); + dev->accel.dest = dev->accel.ge_offset + (dev->accel.cy * dev->pitch); dev->accel.sy--; dev->accel.x_count = 0; - if (dev->accel.sy < 0) + if (dev->accel.sy < 0) { + dev->fifo_idx = 0; dev->accel.cmd_back = 1; + } + dev->force_busy = 0; + dev->force_busy2 = 0; return; } } @@ -2151,6 +2214,7 @@ skip_nibble_rect_write: (dev->accel.cx <= clip_r) && (dev->accel.cy >= clip_t) && (dev->accel.cy <= clip_b)) { + dev->subsys_stat |= INT_GE_BSY; switch ((mix_dat & mix_mask) ? frgd_mix : bkgd_mix) { case 0: src_dat = bkgd_color; @@ -2208,17 +2272,14 @@ skip_nibble_rect_write: else dev->accel.cy--; - if ((dev->accel_bpp == 24) || (dev->accel_bpp <= 8)) - dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); - else if (dev->bpp) - dev->accel.dest = (dev->accel.ge_offset << 1) + (dev->accel.cy * dev->pitch); - else - dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); + dev->accel.dest = dev->accel.ge_offset + (dev->accel.cy * dev->pitch); dev->accel.sy--; - if (dev->accel.sy < 0) + if (dev->accel.sy < 0) { + dev->fifo_idx = 0; dev->accel.cmd_back = 1; + } return; } } @@ -2233,6 +2294,7 @@ skip_nibble_rect_write: (dev->accel.cx <= clip_r) && (dev->accel.cy >= clip_t) && (dev->accel.cy <= clip_b)) { + dev->subsys_stat |= INT_GE_BSY; switch ((mix_dat & 0x01) ? frgd_mix : bkgd_mix) { case 0: src_dat = bkgd_color; @@ -2287,12 +2349,7 @@ skip_nibble_rect_write: else dev->accel.cy--; - if ((dev->accel_bpp == 24) || (dev->accel_bpp <= 8)) - dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); - else if (dev->bpp) - dev->accel.dest = (dev->accel.ge_offset << 1) + (dev->accel.cy * dev->pitch); - else - dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); + dev->accel.dest = dev->accel.ge_offset + (dev->accel.cy * dev->pitch); dev->accel.sy--; @@ -2301,6 +2358,7 @@ skip_nibble_rect_write: dev->accel.cur_x = dev->accel.cx; dev->accel.cur_y = dev->accel.cy; } + dev->fifo_idx = 0; dev->accel.cmd_back = 1; return; } @@ -2314,6 +2372,7 @@ skip_nibble_rect_write: (dev->accel.cx <= clip_r) && (dev->accel.cy >= clip_t) && (dev->accel.cy <= clip_b)) { + dev->subsys_stat |= INT_GE_BSY; switch ((mix_dat & mix_mask) ? frgd_mix : bkgd_mix) { case 0: src_dat = bkgd_color; @@ -2400,36 +2459,31 @@ skip_nibble_rect_write: else dev->accel.cy--; - if ((dev->accel_bpp == 24) || (dev->accel_bpp <= 8)) - dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); - else if (dev->bpp) - dev->accel.dest = (dev->accel.ge_offset << 1) + (dev->accel.cy * dev->pitch); - else - dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); + dev->accel.dest = dev->accel.ge_offset + (dev->accel.cy * dev->pitch); dev->accel.sy--; if (dev->accel.sy < 0) { ibm8514_log(".\n"); - dev->accel.cmd_back = 1; + dev->fifo_idx = 0; dev->accel.cur_x = dev->accel.cx; dev->accel.cur_y = dev->accel.cy; + dev->accel.cmd_back = 1; return; } } } } else { - ibm8514_log("Polygon Draw Type=%02x, CX=%d, CY=%d, SY=%d, CL=%d, CR=%d.\n", dev->accel.multifunc[0x0a] & 0x06, dev->accel.cx, dev->accel.cy, dev->accel.sy, clip_l, clip_r); + ibm8514_log("Polygon Draw Type=%02x, CX=%d, CY=%d, SY=%d, CL=%d, CR=%d, frgdmix=%d, bkgdmix=%d, cmpmode=%02x, pitch=%d.\n", dev->accel.multifunc[0x0a] & 0x06, dev->accel.cx, dev->accel.cy, dev->accel.sy, clip_l, clip_r, frgd_mix, bkgd_mix, compare_mode, dev->pitch); while (count-- && (dev->accel.sy >= 0)) { if ((dev->accel.cx >= clip_l) && (dev->accel.cx <= clip_r) && (dev->accel.cy >= clip_t) && (dev->accel.cy <= clip_b)) { + dev->subsys_stat |= INT_GE_BSY; switch ((mix_dat & mix_mask) ? frgd_mix : bkgd_mix) { case 0: src_dat = bkgd_color; - if (!bkgd_mix && (dev->accel.cmd & 0x40) && ((dev->accel.frgd_mix & 0x1f) == 7) && ((dev->accel.bkgd_mix & 0x1f) == 3) && !dev->bpp && (bkgd_color == 0x00)) /*For some reason, the September 1992 Mach8/32 drivers for Win3.x don't set the background colors properly.*/ - src_dat = frgd_color; break; case 1: src_dat = frgd_color; @@ -2486,12 +2540,7 @@ skip_nibble_rect_write: else dev->accel.cy--; - if ((dev->accel_bpp == 24) || (dev->accel_bpp <= 8)) - dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); - else if (dev->bpp) - dev->accel.dest = (dev->accel.ge_offset << 1) + (dev->accel.cy * dev->pitch); - else - dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); + dev->accel.dest = dev->accel.ge_offset + (dev->accel.cy * dev->pitch); dev->accel.sy--; if (dev->accel.sy < 0) { @@ -2499,6 +2548,7 @@ skip_nibble_rect_write: dev->accel.cur_x = dev->accel.cx; dev->accel.cur_y = dev->accel.cy; } + dev->fifo_idx = 0; dev->accel.cmd_back = 1; return; } @@ -2529,10 +2579,14 @@ skip_nibble_rect_write: ibm8514_log("Polygon Boundary activated=%04x, len=%d, cur(%d,%d), frgdmix=%02x, err=%d, clipping: l=%d, r=%d, t=%d, b=%d, pixcntl=%02x.\n", dev->accel.cmd, dev->accel.sy, dev->accel.cx, dev->accel.cy, dev->accel.frgd_mix & 0x1f, dev->accel.err_term, clip_l, clip_r, clip_t, clip_b, dev->accel.multifunc[0x0a]); if (ibm8514_cpu_src(svga)) { + dev->force_busy = 1; + dev->force_busy2 = 1; dev->data_available = 0; dev->data_available2 = 0; return; /*Wait for data from CPU*/ } else if (ibm8514_cpu_dest(svga)) { + dev->force_busy = 1; + dev->force_busy2 = 1; dev->data_available = 1; dev->data_available2 = 1; return; @@ -2547,6 +2601,7 @@ skip_nibble_rect_write: (dev->accel.cx <= clip_r) && (dev->accel.cy >= clip_t) && (dev->accel.cy <= clip_b)) { + dev->subsys_stat |= INT_GE_BSY; switch ((mix_dat & mix_mask) ? frgd_mix : bkgd_mix) { case 0: src_dat = bkgd_color; @@ -2600,6 +2655,11 @@ skip_nibble_rect_write: cpu_dat >>= 8; if (!dev->accel.sy) { + if (cpu_input) { + dev->force_busy = 0; + dev->force_busy2 = 0; + } + dev->fifo_idx = 0; dev->accel.cmd_back = 1; break; } @@ -2651,9 +2711,10 @@ skip_nibble_rect_write: dev->accel.cx = CLAMP(dev->accel.cx, clip_l, clip_r); if ((dev->accel.cx >= clip_l) && - (dev->accel.cx < clip_r) && + (dev->accel.cx <= clip_r) && (dev->accel.cy >= clip_t) && (dev->accel.cy <= clip_b)) { + dev->subsys_stat |= INT_GE_BSY; switch ((mix_dat & mix_mask) ? frgd_mix : bkgd_mix) { case 0: src_dat = bkgd_color; @@ -2703,6 +2764,11 @@ skip_nibble_rect_write: cpu_dat >>= 8; if (!dev->accel.sy) { + if (cpu_input) { + dev->force_busy = 0; + dev->force_busy2 = 0; + } + dev->fifo_idx = 0; dev->accel.cmd_back = 1; break; } @@ -2769,16 +2835,8 @@ skip_nibble_rect_write: dev->accel.sx = dev->accel.maj_axis_pcnt & 0x7ff; dev->accel.sy = dev->accel.multifunc[0] & 0x7ff; - if ((dev->accel_bpp == 24) || (dev->accel_bpp <= 8)) { - dev->accel.src = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); - dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.dy * dev->pitch); - } else if (dev->bpp) { - dev->accel.src = (dev->accel.ge_offset << 1) + (dev->accel.cy * dev->pitch); - dev->accel.dest = (dev->accel.ge_offset << 1) + (dev->accel.dy * dev->pitch); - } else { - dev->accel.src = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); - dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.dy * dev->pitch); - } + dev->accel.src = dev->accel.ge_offset + (dev->accel.cy * dev->pitch); + dev->accel.dest = dev->accel.ge_offset + (dev->accel.dy * dev->pitch); dev->accel.fill_state = 0; if (ibm8514_cpu_src(svga)) { @@ -2795,17 +2853,21 @@ skip_nibble_rect_write: } } } + dev->force_busy = 1; + dev->force_busy2 = 1; dev->data_available = 0; dev->data_available2 = 0; return; /*Wait for data from CPU*/ } else if (ibm8514_cpu_dest(svga)) { + dev->force_busy = 1; + dev->force_busy2 = 1; dev->data_available = 1; dev->data_available2 = 1; return; /*Wait for data from CPU*/ - } + } else + ibm8514_log("BitBLT normal: Parameters: DX=%d, DY=%d, CX=%d, CY=%d, dstwidth=%d, dstheight=%d, clipl=%d, clipr=%d, clipt=%d, clipb=%d.\n", dev->accel.dx, dev->accel.dy, dev->accel.cx, dev->accel.cy, dev->accel.sx, dev->accel.sy, clip_l, clip_r, clip_t, clip_b); } - ibm8514_log("BitBLT: full=%04x, odd=%d, c(%d,%d), d(%d,%d), xcount=%d, and3=%d, len(%d,%d), CURX=%d, Width=%d, pixcntl=%d, mix_dat=%08x, count=%d, cpu_data=%08x, cpu_input=%d.\n", dev->accel.cmd, dev->accel.input, dev->accel.cx, dev->accel.cy, dev->accel.dx, dev->accel.dy, dev->accel.x_count, and3, dev->accel.sx, dev->accel.sy, dev->accel.cur_x, dev->accel.maj_axis_pcnt, pixcntl, mix_dat, count, cpu_dat, cpu_input); if (cpu_input) { while (count-- && (dev->accel.sy >= 0)) { if ((dev->accel.dx >= clip_l) && @@ -2946,22 +3008,18 @@ skip_nibble_bitblt_write: dev->accel.cy--; } - if ((dev->accel_bpp == 24) || (dev->accel_bpp <= 8)) { - dev->accel.src = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); - dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.dy * dev->pitch); - } else if (dev->bpp) { - dev->accel.src = (dev->accel.ge_offset << 1) + (dev->accel.cy * dev->pitch); - dev->accel.dest = (dev->accel.ge_offset << 1) + (dev->accel.dy * dev->pitch); - } else { - dev->accel.src = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); - dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.dy * dev->pitch); - } + dev->accel.src = dev->accel.ge_offset + (dev->accel.cy * dev->pitch); + dev->accel.dest = dev->accel.ge_offset + (dev->accel.dy * dev->pitch); dev->accel.sy--; dev->accel.x_count = 0; - if (dev->accel.sy < 0) + if (dev->accel.sy < 0) { dev->accel.cmd_back = 1; + dev->force_busy = 0; + dev->force_busy2 = 0; + dev->fifo_idx = 0; + } return; } } @@ -3047,21 +3105,15 @@ skip_nibble_bitblt_write: dev->accel.cy--; } - if ((dev->accel_bpp == 24) || (dev->accel_bpp <= 8)) { - dev->accel.src = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); - dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.dy * dev->pitch); - } else if (dev->bpp) { - dev->accel.src = (dev->accel.ge_offset << 1) + (dev->accel.cy * dev->pitch); - dev->accel.dest = (dev->accel.ge_offset << 1) + (dev->accel.dy * dev->pitch); - } else { - dev->accel.src = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); - dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.dy * dev->pitch); - } + dev->accel.src = dev->accel.ge_offset + (dev->accel.cy * dev->pitch); + dev->accel.dest = dev->accel.ge_offset + (dev->accel.dy * dev->pitch); dev->accel.sy--; - if (dev->accel.sy < 0) + if (dev->accel.sy < 0) { dev->accel.cmd_back = 1; + dev->fifo_idx = 0; + } return; } } @@ -3141,21 +3193,15 @@ skip_nibble_bitblt_write: dev->accel.cy--; } - if ((dev->accel_bpp == 24) || (dev->accel_bpp <= 8)) { - dev->accel.src = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); - dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.dy * dev->pitch); - } else if (dev->bpp) { - dev->accel.src = (dev->accel.ge_offset << 1) + (dev->accel.cy * dev->pitch); - dev->accel.dest = (dev->accel.ge_offset << 1) + (dev->accel.dy * dev->pitch); - } else { - dev->accel.src = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); - dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.dy * dev->pitch); - } + dev->accel.src = dev->accel.ge_offset + (dev->accel.cy * dev->pitch); + dev->accel.dest = dev->accel.ge_offset + (dev->accel.dy * dev->pitch); + dev->accel.sy--; if (dev->accel.sy < 0) { dev->accel.destx = dev->accel.dx; dev->accel.desty = dev->accel.dy; + dev->fifo_idx = 0; dev->accel.cmd_back = 1; return; } @@ -3170,15 +3216,19 @@ skip_nibble_bitblt_write: cx = (int64_t) dev->accel.cx; dx = (int64_t) dev->accel.dx; + dev->accel.src = dev->accel.src_ge_offset + (dev->accel.cy * dev->accel.src_pitch); + dev->accel.dest = dev->accel.dst_ge_offset + (dev->accel.dy * dev->accel.dst_pitch); + while (1) { if ((dx >= (((int64_t)clip_l) * 3)) && (dx <= (((uint64_t)clip_r) * 3)) && (dev->accel.dy >= (clip_t << 1)) && (dev->accel.dy <= (clip_b << 1))) { - READ(dev->accel.src + cx, src_dat); READ(dev->accel.dest + dx, dest_dat); - dest_dat = (src_dat & wrt_mask) | (dest_dat & ~wrt_mask); + 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); WRITE(dev->accel.dest + dx, dest_dat); } @@ -3187,6 +3237,7 @@ skip_nibble_bitblt_write: dev->accel.sx--; if (dev->accel.sx < 0) { + dev->fifo_idx = 0; dev->accel.cmd_back = 1; return; } @@ -3242,13 +3293,8 @@ skip_nibble_bitblt_write: 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 & 0x04) { - if (dev->accel.sx) { - WRITE(dev->accel.dest + dev->accel.dx, dest_dat); - } - } else { - WRITE(dev->accel.dest + dev->accel.dx, dest_dat); - } + WRITE(dev->accel.dest + dev->accel.dx, dest_dat); + ibm8514_log("BitBLT DX=%d, DY=%d, data=%02x, old=%02x, src=%02x, frmix=%02x, bkmix=%02x, pixcntl=%d.\n", dev->accel.dx, dev->accel.dy, dest_dat, old_dest_dat, src_dat, dev->accel.frgd_mix & 0x1f, dev->accel.bkgd_mix & 0x1f, pixcntl); } } @@ -3284,21 +3330,15 @@ skip_nibble_bitblt_write: dev->accel.cy--; } - if ((dev->accel_bpp == 24) || (dev->accel_bpp <= 8)) { - dev->accel.src = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); - dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.dy * dev->pitch); - } else if (dev->bpp) { - dev->accel.src = (dev->accel.ge_offset << 1) + (dev->accel.cy * dev->pitch); - dev->accel.dest = (dev->accel.ge_offset << 1) + (dev->accel.dy * dev->pitch); - } else { - dev->accel.src = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); - dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.dy * dev->pitch); - } + dev->accel.src = dev->accel.ge_offset + (dev->accel.cy * dev->pitch); + dev->accel.dest = dev->accel.ge_offset + (dev->accel.dy * dev->pitch); + dev->accel.sy--; if (dev->accel.sy < 0) { dev->accel.destx = dev->accel.dx; dev->accel.desty = dev->accel.dy; + dev->fifo_idx = 0; dev->accel.cmd_back = 1; return; } @@ -3326,7 +3366,7 @@ ibm8514_render_blank(svga_t *svga) dev->firstline_draw = dev->displine; dev->lastline_draw = dev->displine; - uint32_t *line_ptr = &svga->monitor->target_buffer->line[dev->displine + svga->y_add][svga->x_add]; + uint32_t *line_ptr = &buffer32->line[dev->displine + svga->y_add][svga->x_add]; uint32_t line_width = (uint32_t)(dev->h_disp) * sizeof(uint32_t); if (dev->h_disp > 0) @@ -3343,7 +3383,7 @@ ibm8514_render_8bpp(svga_t *svga) if ((dev->displine + svga->y_add) < 0) return; - if (dev->changedvram[dev->ma >> 12] || dev->changedvram[(dev->ma >> 12) + 1] || svga->fullchange) { + if (dev->changedvram[dev->memaddr >> 12] || dev->changedvram[(dev->memaddr >> 12) + 1] || svga->fullchange) { p = &buffer32->line[dev->displine + svga->y_add][svga->x_add]; if (dev->firstline_draw == 2000) @@ -3351,22 +3391,22 @@ ibm8514_render_8bpp(svga_t *svga) dev->lastline_draw = dev->displine; for (int x = 0; x <= dev->h_disp; x += 8) { - dat = *(uint32_t *) (&dev->vram[dev->ma & dev->vram_mask]); + dat = *(uint32_t *) (&dev->vram[dev->memaddr & dev->vram_mask]); p[0] = dev->pallook[dat & dev->dac_mask & 0xff]; p[1] = dev->pallook[(dat >> 8) & dev->dac_mask & 0xff]; p[2] = dev->pallook[(dat >> 16) & dev->dac_mask & 0xff]; p[3] = dev->pallook[(dat >> 24) & dev->dac_mask & 0xff]; - dat = *(uint32_t *) (&dev->vram[(dev->ma + 4) & dev->vram_mask]); + dat = *(uint32_t *) (&dev->vram[(dev->memaddr + 4) & dev->vram_mask]); p[4] = dev->pallook[dat & dev->dac_mask & 0xff]; p[5] = dev->pallook[(dat >> 8) & dev->dac_mask & 0xff]; p[6] = dev->pallook[(dat >> 16) & dev->dac_mask & 0xff]; p[7] = dev->pallook[(dat >> 24) & dev->dac_mask & 0xff]; - dev->ma += 8; + dev->memaddr += 8; p += 8; } - dev->ma &= dev->vram_mask; + dev->memaddr &= dev->vram_mask; } } @@ -3381,7 +3421,7 @@ ibm8514_render_15bpp(svga_t *svga) if ((dev->displine + svga->y_add) < 0) return; - if (dev->changedvram[dev->ma >> 12] || dev->changedvram[(dev->ma >> 12) + 1] || svga->fullchange) { + if (dev->changedvram[dev->memaddr >> 12] || dev->changedvram[(dev->memaddr >> 12) + 1] || svga->fullchange) { p = &buffer32->line[dev->displine + svga->y_add][svga->x_add]; if (dev->firstline_draw == 2000) @@ -3389,24 +3429,24 @@ ibm8514_render_15bpp(svga_t *svga) dev->lastline_draw = dev->displine; for (x = 0; x <= dev->h_disp; x += 8) { - dat = *(uint32_t *) (&dev->vram[(dev->ma + (x << 1)) & dev->vram_mask]); + dat = *(uint32_t *) (&dev->vram[(dev->memaddr + (x << 1)) & dev->vram_mask]); p[x] = video_15to32[dat & 0xffff]; p[x + 1] = video_15to32[dat >> 16]; - dat = *(uint32_t *) (&dev->vram[(dev->ma + (x << 1) + 4) & dev->vram_mask]); + dat = *(uint32_t *) (&dev->vram[(dev->memaddr + (x << 1) + 4) & dev->vram_mask]); p[x + 2] = video_15to32[dat & 0xffff]; p[x + 3] = video_15to32[dat >> 16]; - dat = *(uint32_t *) (&dev->vram[(dev->ma + (x << 1) + 8) & dev->vram_mask]); + dat = *(uint32_t *) (&dev->vram[(dev->memaddr + (x << 1) + 8) & dev->vram_mask]); p[x + 4] = video_15to32[dat & 0xffff]; p[x + 5] = video_15to32[dat >> 16]; - dat = *(uint32_t *) (&dev->vram[(dev->ma + (x << 1) + 12) & dev->vram_mask]); + dat = *(uint32_t *) (&dev->vram[(dev->memaddr + (x << 1) + 12) & dev->vram_mask]); p[x + 6] = video_15to32[dat & 0xffff]; p[x + 7] = video_15to32[dat >> 16]; } - dev->ma += (x << 1); - dev->ma &= dev->vram_mask; + dev->memaddr += (x << 1); + dev->memaddr &= dev->vram_mask; } } @@ -3421,7 +3461,7 @@ ibm8514_render_16bpp(svga_t *svga) if ((dev->displine + svga->y_add) < 0) return; - if (dev->changedvram[dev->ma >> 12] || dev->changedvram[(dev->ma >> 12) + 1] || svga->fullchange) { + if (dev->changedvram[dev->memaddr >> 12] || dev->changedvram[(dev->memaddr >> 12) + 1] || svga->fullchange) { p = &buffer32->line[dev->displine + svga->y_add][svga->x_add]; if (dev->firstline_draw == 2000) @@ -3429,24 +3469,24 @@ ibm8514_render_16bpp(svga_t *svga) dev->lastline_draw = dev->displine; for (x = 0; x <= dev->h_disp; x += 8) { - dat = *(uint32_t *) (&dev->vram[(dev->ma + (x << 1)) & dev->vram_mask]); + dat = *(uint32_t *) (&dev->vram[(dev->memaddr + (x << 1)) & dev->vram_mask]); p[x] = video_16to32[dat & 0xffff]; p[x + 1] = video_16to32[dat >> 16]; - dat = *(uint32_t *) (&dev->vram[(dev->ma + (x << 1) + 4) & dev->vram_mask]); + dat = *(uint32_t *) (&dev->vram[(dev->memaddr + (x << 1) + 4) & dev->vram_mask]); p[x + 2] = video_16to32[dat & 0xffff]; p[x + 3] = video_16to32[dat >> 16]; - dat = *(uint32_t *) (&dev->vram[(dev->ma + (x << 1) + 8) & dev->vram_mask]); + dat = *(uint32_t *) (&dev->vram[(dev->memaddr + (x << 1) + 8) & dev->vram_mask]); p[x + 4] = video_16to32[dat & 0xffff]; p[x + 5] = video_16to32[dat >> 16]; - dat = *(uint32_t *) (&dev->vram[(dev->ma + (x << 1) + 12) & dev->vram_mask]); + dat = *(uint32_t *) (&dev->vram[(dev->memaddr + (x << 1) + 12) & dev->vram_mask]); p[x + 6] = video_16to32[dat & 0xffff]; p[x + 7] = video_16to32[dat >> 16]; } - dev->ma += (x << 1); - dev->ma &= dev->vram_mask; + dev->memaddr += (x << 1); + dev->memaddr &= dev->vram_mask; } } @@ -3460,7 +3500,7 @@ ibm8514_render_24bpp(svga_t *svga) if ((dev->displine + svga->y_add) < 0) return; - if (dev->changedvram[dev->ma >> 12] || dev->changedvram[(dev->ma >> 12) + 1] || svga->fullchange) { + if (dev->changedvram[dev->memaddr >> 12] || dev->changedvram[(dev->memaddr >> 12) + 1] || svga->fullchange) { p = &buffer32->line[dev->displine + svga->y_add][svga->x_add]; if (dev->firstline_draw == 2000) @@ -3468,21 +3508,21 @@ ibm8514_render_24bpp(svga_t *svga) dev->lastline_draw = dev->displine; for (int x = 0; x <= dev->h_disp; x += 4) { - dat = *(uint32_t *) (&dev->vram[dev->ma & dev->vram_mask]); + dat = *(uint32_t *) (&dev->vram[dev->memaddr & dev->vram_mask]); p[x] = dat & 0xffffff; - dat = *(uint32_t *) (&dev->vram[(dev->ma + 3) & dev->vram_mask]); + dat = *(uint32_t *) (&dev->vram[(dev->memaddr + 3) & dev->vram_mask]); p[x + 1] = dat & 0xffffff; - dat = *(uint32_t *) (&dev->vram[(dev->ma + 6) & dev->vram_mask]); + dat = *(uint32_t *) (&dev->vram[(dev->memaddr + 6) & dev->vram_mask]); p[x + 2] = dat & 0xffffff; - dat = *(uint32_t *) (&dev->vram[(dev->ma + 9) & dev->vram_mask]); + dat = *(uint32_t *) (&dev->vram[(dev->memaddr + 9) & dev->vram_mask]); p[x + 3] = dat & 0xffffff; - dev->ma += 12; + dev->memaddr += 12; } - dev->ma &= dev->vram_mask; + dev->memaddr &= dev->vram_mask; } } @@ -3496,7 +3536,7 @@ ibm8514_render_BGR(svga_t *svga) if ((dev->displine + svga->y_add) < 0) return; - if (dev->changedvram[dev->ma >> 12] || dev->changedvram[(dev->ma >> 12) + 1] || svga->fullchange) { + if (dev->changedvram[dev->memaddr >> 12] || dev->changedvram[(dev->memaddr >> 12) + 1] || svga->fullchange) { p = &buffer32->line[dev->displine + svga->y_add][svga->x_add]; if (dev->firstline_draw == 2000) @@ -3504,21 +3544,21 @@ ibm8514_render_BGR(svga_t *svga) dev->lastline_draw = dev->displine; for (int x = 0; x <= dev->h_disp; x += 4) { - dat = *(uint32_t *) (&dev->vram[dev->ma & dev->vram_mask]); + dat = *(uint32_t *) (&dev->vram[dev->memaddr & dev->vram_mask]); p[x] = ((dat & 0xff0000) >> 16) | (dat & 0x00ff00) | ((dat & 0x0000ff) << 16); - dat = *(uint32_t *) (&dev->vram[(dev->ma + 3) & dev->vram_mask]); + dat = *(uint32_t *) (&dev->vram[(dev->memaddr + 3) & dev->vram_mask]); p[x + 1] = ((dat & 0xff0000) >> 16) | (dat & 0x00ff00) | ((dat & 0x0000ff) << 16); - dat = *(uint32_t *) (&dev->vram[(dev->ma + 6) & dev->vram_mask]); + dat = *(uint32_t *) (&dev->vram[(dev->memaddr + 6) & dev->vram_mask]); p[x + 2] = ((dat & 0xff0000) >> 16) | (dat & 0x00ff00) | ((dat & 0x0000ff) << 16); - dat = *(uint32_t *) (&dev->vram[(dev->ma + 9) & dev->vram_mask]); + dat = *(uint32_t *) (&dev->vram[(dev->memaddr + 9) & dev->vram_mask]); p[x + 3] = ((dat & 0xff0000) >> 16) | (dat & 0x00ff00) | ((dat & 0x0000ff) << 16); - dev->ma += 12; + dev->memaddr += 12; } - dev->ma &= dev->vram_mask; + dev->memaddr &= dev->vram_mask; } } @@ -3533,7 +3573,7 @@ ibm8514_render_ABGR8888(svga_t *svga) if ((dev->displine + svga->y_add) < 0) return; - if (dev->changedvram[dev->ma >> 12] || dev->changedvram[(dev->ma >> 12) + 1] || svga->fullchange) { + if (dev->changedvram[dev->memaddr >> 12] || dev->changedvram[(dev->memaddr >> 12) + 1] || svga->fullchange) { p = &buffer32->line[dev->displine + svga->y_add][svga->x_add]; if (dev->firstline_draw == 2000) @@ -3541,11 +3581,11 @@ ibm8514_render_ABGR8888(svga_t *svga) dev->lastline_draw = dev->displine; for (x = 0; x <= dev->h_disp; x++) { - dat = *(uint32_t *) (&dev->vram[(dev->ma + (x << 2)) & dev->vram_mask]); + dat = *(uint32_t *) (&dev->vram[(dev->memaddr + (x << 2)) & dev->vram_mask]); *p++ = ((dat & 0xff0000) >> 16) | (dat & 0x00ff00) | ((dat & 0x0000ff) << 16); } - dev->ma += (x * 4); - dev->ma &= dev->vram_mask; + dev->memaddr += (x * 4); + dev->memaddr &= dev->vram_mask; } } @@ -3560,7 +3600,7 @@ ibm8514_render_32bpp(svga_t *svga) if ((dev->displine + svga->y_add) < 0) return; - if (dev->changedvram[dev->ma >> 12] || dev->changedvram[(dev->ma >> 12) + 1] || dev->changedvram[(dev->ma >> 12) + 2] || svga->fullchange) { + if (dev->changedvram[dev->memaddr >> 12] || dev->changedvram[(dev->memaddr >> 12) + 1] || dev->changedvram[(dev->memaddr >> 12) + 2] || svga->fullchange) { p = &buffer32->line[dev->displine + svga->y_add][svga->x_add]; if (dev->firstline_draw == 2000) @@ -3568,11 +3608,11 @@ ibm8514_render_32bpp(svga_t *svga) dev->lastline_draw = dev->displine; for (x = 0; x <= dev->h_disp; x++) { - dat = *(uint32_t *) (&dev->vram[(dev->ma + (x << 2)) & dev->vram_mask]); + dat = *(uint32_t *) (&dev->vram[(dev->memaddr + (x << 2)) & dev->vram_mask]); p[x] = dat & 0xffffff; } - dev->ma += (x * 4); - dev->ma &= dev->vram_mask; + dev->memaddr += (x * 4); + dev->memaddr &= dev->vram_mask; } } @@ -3605,6 +3645,12 @@ ibm8514_render_overscan_right(ibm8514_t *dev, svga_t *svga) buffer32->line[dev->displine + svga->y_add][svga->x_add + dev->h_disp + i] = svga->overscan_color; } +void +ibm8514_set_poll(svga_t *svga) +{ + timer_set_callback(&svga->timer, ibm8514_poll); +} + void ibm8514_poll(void *priv) { @@ -3614,7 +3660,7 @@ ibm8514_poll(void *priv) int wx; int wy; - ibm8514_log("IBM 8514/A poll.\n"); + ibm8514_log("IBM 8514/A poll=%x offtime=%" PRIu64 ", ontime=%" PRIu64 ".\n", dev->on, dev->dispofftime, dev->dispontime); if (dev->on) { ibm8514_log("ON!\n"); if (!dev->linepos) { @@ -3635,7 +3681,7 @@ ibm8514_poll(void *priv) if (dev->dispon) { dev->hdisp_on = 1; - dev->ma &= dev->vram_mask; + dev->memaddr &= dev->vram_mask; if (dev->firstline == 2000) { dev->firstline = dev->displine; @@ -3643,14 +3689,14 @@ ibm8514_poll(void *priv) } if (dev->hwcursor_on) - dev->changedvram[dev->ma >> 12] = dev->changedvram[(dev->ma >> 12) + 1] = dev->interlace ? 3 : 2; + dev->changedvram[dev->memaddr >> 12] = dev->changedvram[(dev->memaddr >> 12) + 1] = dev->interlace ? 3 : 2; svga->render8514(svga); - svga->x_add = (overscan_x >> 1); + svga->x_add = svga->left_overscan; ibm8514_render_overscan_left(dev, svga); ibm8514_render_overscan_right(dev, svga); - svga->x_add = (overscan_x >> 1); + svga->x_add = svga->left_overscan; if (dev->hwcursor_on) { if (svga->hwcursor_draw) @@ -3670,7 +3716,7 @@ ibm8514_poll(void *priv) if ((svga->cgastat & 8) && ((dev->displine & 0x0f) == (svga->crtc[0x11] & 0x0f)) && svga->vslines) svga->cgastat &= ~8; svga->vslines++; - if (dev->displine > 1500) + if (dev->displine > 2000) dev->displine = 0; } else { timer_advance_u64(&svga->timer, dev->dispontime); @@ -3680,18 +3726,18 @@ ibm8514_poll(void *priv) dev->linepos = 0; if (dev->dispon) { - if (dev->sc == dev->rowcount) { - dev->sc = 0; - dev->maback += (dev->rowoffset << 3); + if (dev->scanline == dev->rowcount) { + dev->scanline = 0; + dev->memaddr_backup += (dev->rowoffset << 3); if (dev->interlace) - dev->maback += (dev->rowoffset << 3); + dev->memaddr_backup += (dev->rowoffset << 3); - dev->maback &= dev->vram_mask; - dev->ma = dev->maback; + dev->memaddr_backup &= dev->vram_mask; + dev->memaddr = dev->memaddr_backup; } else { - dev->sc++; - dev->sc &= 0x1f; - dev->ma = dev->maback; + dev->scanline++; + dev->scanline &= 0x1f; + dev->memaddr = dev->memaddr_backup; } } @@ -3699,6 +3745,8 @@ ibm8514_poll(void *priv) dev->vc &= 0xfff; if (dev->vc == dev->dispend) { + dev->vblank_start(svga); + ibm8514_log("VBLANK irq.\n"); dev->dispon = 0; for (x = 0; x < ((dev->vram_mask + 1) >> 12); x++) { @@ -3735,20 +3783,20 @@ ibm8514_poll(void *priv) svga->vslines = 0; if (dev->interlace && dev->oddeven) - dev->ma = dev->maback = (dev->rowoffset << 1); + dev->memaddr = dev->memaddr_backup = (dev->rowoffset << 1); else - dev->ma = dev->maback = 0; + dev->memaddr = dev->memaddr_backup = 0; - dev->ma = (dev->ma << 2); - dev->maback = (dev->maback << 2); + dev->memaddr = (dev->memaddr << 2); + dev->memaddr_backup = (dev->memaddr_backup << 2); } if (dev->vc == dev->v_total) { dev->vc = 0; - dev->sc = 0; + dev->scanline = (svga->crtc[0x8] & 0x1f); dev->dispon = 1; dev->displine = (dev->interlace && dev->oddeven) ? 1 : 0; - svga->x_add = (overscan_x >> 1); + svga->x_add = svga->left_overscan; dev->hwcursor_on = 0; dev->hwcursor_latch = dev->hwcursor; @@ -3768,31 +3816,45 @@ ibm8514_recalctimings(svga_t *svga) ati8514_recalctimings(svga); } else { if (dev->on) { + dev->hdisp = (dev->hdisped + 1) << 3; dev->h_total = dev->htotal + 1; + + if (dev->h_total == 1) /*Default to 1024x768 87hz 8514/A htotal timings if it goes to 0.*/ + dev->h_total = 0x9e; + + dev->vdisp = (dev->v_disp + 1) >> 1; + if ((dev->vdisp == 478) || (dev->vdisp == 766)) + dev->vdisp += 2; + + dev->v_total = dev->v_total_reg + 1; + if (dev->interlace) + dev->v_total >>= 1; + + dev->v_syncstart = dev->v_sync_start + 1; + if (dev->interlace) + dev->v_syncstart >>= 1; + dev->rowcount = !!(dev->disp_cntl & 0x08); - if (dev->accel.advfunc_cntl & 0x01) { + if ((dev->hdisp != 640) && (dev->hdisp != 1024)) { if (dev->accel.advfunc_cntl & 0x04) { - dev->h_disp = dev->hdisp; - dev->dispend = dev->vdisp; + dev->hdisp = 1024; + dev->vdisp = 768; } else { - dev->h_disp = 640; - dev->dispend = 480; + dev->hdisp = 640; + dev->vdisp = 480; } - } else { - dev->h_disp = dev->hdisp; - dev->dispend = dev->vdisp; } + dev->h_disp = dev->hdisp; + dev->dispend = dev->vdisp; + if (dev->accel.advfunc_cntl & 0x04) - svga->clock8514 = (cpuclock * (double) (1ULL << 32)) / 44900000.0; + svga->clock_8514 = (cpuclock * (double) (1ULL << 32)) / 44900000.0; else - svga->clock8514 = (cpuclock * (double) (1ULL << 32)) / 25175000.0; + svga->clock_8514 = (cpuclock * (double) (1ULL << 32)) / 25175000.0; - if (dev->dispend == 766) - dev->dispend += 2; - - if (dev->dispend == 478) + if ((dev->dispend == 478) || (dev->dispend == 766)) dev->dispend += 2; if (dev->interlace) @@ -3857,7 +3919,16 @@ ibm8514_mca_reset(void *priv) else ibm8514_mca_write(0x102, 0, svga); - timer_set_callback(&svga->timer, svga_poll); + svga_set_poll(svga); +} + +static void +ibm8514_vblank_start(void *priv) +{ + svga_t *svga = (svga_t *) priv; + ibm8514_t *dev = (ibm8514_t *) svga->dev8514; + + dev->subsys_stat |= INT_VSY; } static void * @@ -3884,6 +3955,7 @@ ibm8514_init(const device_t *info) dev->map8 = dev->pallook; dev->local = 0; dev->accel_bpp = 8; + dev->on = 0; dev->type = info->flags; dev->bpp = 0; @@ -3894,7 +3966,7 @@ ibm8514_init(const device_t *info) bios_addr = 0xc6000; switch (dev->extensions) { - case 1: + case ATI: if (rom_present(BIOS_MACH8_ROM_PATH)) { mach_t * mach = (mach_t *) calloc(1, sizeof(mach_t)); svga->ext8514 = mach; @@ -3905,13 +3977,14 @@ ibm8514_init(const device_t *info) 0, MEM_MAPPING_EXTERNAL); ati8514_init(svga, svga->ext8514, svga->dev8514); - mach->accel.scratch0 = ((((bios_addr >> 7) - 0x1000) >> 4)); + mach->accel.scratch0 = ((bios_addr >> 7) - 0x1000) >> 4; bios_rom_eeprom = mach->accel.scratch0; if (dev->type & DEVICE_MCA) { dev->pos_regs[0] = 0x88; dev->pos_regs[1] = 0x80; mach->eeprom.data[0] = 0x0000; mach->eeprom.data[1] = bios_rom_eeprom | ((bios_rom_eeprom | 0x01) << 8); + ibm8514_log("EEPROM Data1=%04x.\n", mach->eeprom.data[1]); mca_add(ati8514_mca_read, ati8514_mca_write, ibm8514_mca_feedb, ibm8514_mca_reset, svga); ati_eeprom_load_mach8(&mach->eeprom, "ati8514_mca.nvr", 1); mem_mapping_disable(&dev->bios_rom.mapping); @@ -3922,15 +3995,20 @@ ibm8514_init(const device_t *info) fallthrough; default: + dev->extensions = 0; ibm8514_io_set(svga); + dev->accel.cmd_back = 1; if (dev->type & DEVICE_MCA) { dev->pos_regs[0] = 0x7f; dev->pos_regs[1] = 0xef; mca_add(ibm8514_mca_read, ibm8514_mca_write, ibm8514_mca_feedb, ibm8514_mca_reset, svga); } + + dev->vblank_start = ibm8514_vblank_start; break; } + return svga; } @@ -3965,58 +4043,50 @@ ibm8514_force_redraw(void *priv) { svga_t *svga = (svga_t *) priv; - svga->fullchange = changeframecount; + svga->fullchange = svga->monitor->mon_changeframecount; } // clang-format off static const device_config_t isa_ext8514_config[] = { { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 1024, - .selection = { - { - .description = "512 KB", - .value = 512 - }, - { - .description = "1 MB", - .value = 1024 - }, - { - .description = "" - } - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 1024, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "512 KB", .value = 512 }, + { .description = "1 MB", .value = 1024 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "extensions", - .description = "Vendor", - .type = CONFIG_SELECTION, - .default_int = 0, - .selection = { - { - .description = "IBM", - .value = 0 - }, - { - .description = "ATI", - .value = 1 - }, - { - .description = "" - } - } + .name = "extensions", + .description = "Vendor", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = IBM, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "IBM", .value = IBM }, + { .description = "ATI", .value = ATI }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "bios_addr", - .description = "BIOS Address", - .type = CONFIG_HEX20, - .default_string = "", - .default_int = 0xc8000, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "bios_addr", + .description = "BIOS Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0xc8000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "C800h", .value = 0xc8000 }, { .description = "CA00h", .value = 0xca000 }, { .description = "CC00h", .value = 0xcc000 }, @@ -4029,89 +4099,77 @@ static const device_config_t isa_ext8514_config[] = { { .description = "DA00h", .value = 0xda000 }, { .description = "DC00h", .value = 0xdc000 }, { .description = "DE00h", .value = 0xde000 }, - { .description = "" } + { .description = "" } }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; // clang-format off static const device_config_t mca_ext8514_config[] = { { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 1024, - .selection = { - { - .description = "512 KB", - .value = 512 - }, - { - .description = "1 MB", - .value = 1024 - }, - { - .description = "" - } - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 1024, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "512 KB", .value = 512 }, + { .description = "1 MB", .value = 1024 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "extensions", - .description = "Vendor", - .type = CONFIG_SELECTION, - .default_int = 0, - .selection = { - { - .description = "IBM", - .value = 0 - }, - { - .description = "ATI", - .value = 1 - }, - { - .description = "" - } - } + .name = "extensions", + .description = "Vendor", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = IBM, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "IBM", .value = IBM }, + { .description = "ATI", .value = ATI }, + { .description = "" } + }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; // clang-format off const device_t gen8514_isa_device = { - .name = "IBM 8514/A clone (ISA)", + .name = "IBM 8514/A clone (ISA)", .internal_name = "8514_isa", - .flags = DEVICE_AT | DEVICE_ISA, - .local = 0, - .init = ibm8514_init, - .close = ibm8514_close, - .reset = NULL, - { .available = NULL }, + .flags = DEVICE_ISA16, + .local = IBM_8514A_TYPE, + .init = ibm8514_init, + .close = ibm8514_close, + .reset = NULL, + .available = NULL, .speed_changed = ibm8514_speed_changed, - .force_redraw = ibm8514_force_redraw, - .config = isa_ext8514_config + .force_redraw = ibm8514_force_redraw, + .config = isa_ext8514_config }; const device_t ibm8514_mca_device = { - .name = "IBM 8514/A (MCA)", + .name = "IBM 8514/A (MCA)", .internal_name = "8514_mca", - .flags = DEVICE_MCA, - .local = 0, - .init = ibm8514_init, - .close = ibm8514_close, - .reset = NULL, - { .available = NULL }, + .flags = DEVICE_MCA, + .local = IBM_8514A_TYPE, + .init = ibm8514_init, + .close = ibm8514_close, + .reset = NULL, + .available = NULL, .speed_changed = ibm8514_speed_changed, - .force_redraw = ibm8514_force_redraw, - .config = mca_ext8514_config + .force_redraw = ibm8514_force_redraw, + .config = mca_ext8514_config }; - void ibm8514_device_add(void) { diff --git a/src/video/vid_ati18800.c b/src/video/vid_ati18800.c index df41e5d3f..9c87746c6 100644 --- a/src/video/vid_ati18800.c +++ b/src/video/vid_ati18800.c @@ -109,7 +109,7 @@ ati18800_out(uint16_t addr, uint8_t val, void *priv) 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); + svga->memaddr_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5); } else { svga->fullchange = changeframecount; svga_recalctimings(svga); @@ -223,7 +223,7 @@ ati18800_recalctimings(svga_t *svga) else { svga->render = svga_render_8bpp_highres; if (!svga->packed_4bpp) { - svga->ma_latch <<= 1; + svga->memaddr_latch <<= 1; svga->rowoffset <<= 1; } } @@ -329,27 +329,21 @@ ati18800_force_redraw(void *priv) static const device_config_t ati18800_wonder_config[] = { { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 512, + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 512, + .file_filter = NULL, + .spinner = { 0 }, .selection = { - { - .description = "256 KB", - .value = 256 - }, - { - .description = "512 KB", - .value = 512 - }, - { - .description = "" - } - } + { .description = "256 KB", .value = 256 }, + { .description = "512 KB", .value = 512 }, + { .description = "" } + }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; const device_t ati18800_wonder_device = { @@ -360,7 +354,7 @@ const device_t ati18800_wonder_device = { .init = ati18800_init, .close = ati18800_close, .reset = NULL, - { .available = ati18800_wonder_available }, + .available = ati18800_wonder_available, .speed_changed = ati18800_speed_changed, .force_redraw = ati18800_force_redraw, .config = ati18800_wonder_config @@ -374,7 +368,7 @@ const device_t ati18800_vga88_device = { .init = ati18800_init, .close = ati18800_close, .reset = NULL, - { .available = ati18800_vga88_available }, + .available = ati18800_vga88_available, .speed_changed = ati18800_speed_changed, .force_redraw = ati18800_force_redraw, .config = NULL @@ -388,7 +382,7 @@ const device_t ati18800_device = { .init = ati18800_init, .close = ati18800_close, .reset = NULL, - { .available = ati18800_available }, + .available = ati18800_available, .speed_changed = ati18800_speed_changed, .force_redraw = ati18800_force_redraw, .config = NULL diff --git a/src/video/vid_ati28800.c b/src/video/vid_ati28800.c index b3cf8aad1..284abe78c 100644 --- a/src/video/vid_ati28800.c +++ b/src/video/vid_ati28800.c @@ -206,7 +206,7 @@ ati28800_out(uint16_t addr, uint8_t val, void *priv) 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); + svga->memaddr_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5); } else { svga->fullchange = changeframecount; svga_recalctimings(svga); @@ -416,10 +416,10 @@ ati28800_recalctimings(svga_t *svga) ((ati28800->regs[0xb9] & 2) << 1); if (ati28800->regs[0xa3] & 0x10) - svga->ma_latch |= 0x10000; + svga->memaddr_latch |= 0x10000; if (ati28800->regs[0xb0] & 0x40) - svga->ma_latch |= 0x20000; + svga->memaddr_latch |= 0x20000; if (ati28800->regs[0xb8] & 0x40) svga->clock *= 2; @@ -483,7 +483,7 @@ ati28800_recalctimings(svga_t *svga) else { svga->render = svga_render_8bpp_highres; if (!svga->packed_4bpp) { - svga->ma_latch <<= 1; + svga->memaddr_latch <<= 1; svga->rowoffset <<= 1; } } @@ -496,7 +496,7 @@ ati28800_recalctimings(svga_t *svga) svga->hdisp >>= 1; svga->dots_per_clock >>= 1; svga->rowoffset <<= 1; - svga->ma_latch <<= 1; + svga->memaddr_latch <<= 1; } break; default: @@ -744,61 +744,43 @@ ati28800_force_redraw(void *priv) // clang-format off static const device_config_t ati28800_config[] = { { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 512, - .selection = { - { - .description = "256 KB", - .value = 256 - }, - { - .description = "512 KB", - .value = 512 - }, - { - .description = "1 MB", - .value = 1024 - }, - { - .description = "" - } - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 512, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "256 KB", .value = 256 }, + { .description = "512 KB", .value = 512 }, + { .description = "1 MB", .value = 1024 }, + { .description = "" } + }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; #ifdef USE_XL24 static const device_config_t ati28800_wonderxl_config[] = { { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 512, - .selection = { - { - .description = "256 KB", - .value = 256 - }, - { - .description = "512 KB", - .value = 512 - }, - { - .description = "1 MB", - .value = 1024 - }, - { - .description = "" - } - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 512, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "256 KB", .value = 256 }, + { .description = "512 KB", .value = 512 }, + { .description = "1 MB", .value = 1024 }, + { .description = "" } + }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; #endif /* USE_XL24 */ // clang-format on @@ -811,7 +793,7 @@ const device_t ati28800_device = { .init = ati28800_init, .close = ati28800_close, .reset = NULL, - { .available = ati28800_available }, + .available = ati28800_available, .speed_changed = ati28800_speed_changed, .force_redraw = ati28800_force_redraw, .config = ati28800_config @@ -825,7 +807,7 @@ const device_t ati28800k_device = { .init = ati28800k_init, .close = ati28800_close, .reset = NULL, - { .available = ati28800k_available }, + .available = ati28800k_available, .speed_changed = ati28800_speed_changed, .force_redraw = ati28800_force_redraw, .config = ati28800_config @@ -839,7 +821,7 @@ const device_t ati28800k_spc4620p_device = { .init = ati28800k_init, .close = ati28800_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = ati28800_speed_changed, .force_redraw = ati28800_force_redraw, .config = NULL @@ -853,7 +835,7 @@ const device_t ati28800k_spc6033p_device = { .init = ati28800k_init, .close = ati28800_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = ati28800_speed_changed, .force_redraw = ati28800_force_redraw, .config = NULL @@ -867,7 +849,7 @@ const device_t compaq_ati28800_device = { .init = ati28800_init, .close = ati28800_close, .reset = NULL, - { .available = compaq_ati28800_available }, + .available = compaq_ati28800_available, .speed_changed = ati28800_speed_changed, .force_redraw = ati28800_force_redraw, .config = ati28800_config @@ -881,7 +863,7 @@ const device_t ati28800_wonder1024d_xl_plus_device = { .init = ati28800_init, .close = ati28800_close, .reset = NULL, - { .available = ati28800_wonder1024d_xl_plus_available }, + .available = ati28800_wonder1024d_xl_plus_available, .speed_changed = ati28800_speed_changed, .force_redraw = ati28800_force_redraw, .config = NULL @@ -896,7 +878,7 @@ const device_t ati28800_wonderxl24_device = { .init = ati28800_init, .close = ati28800_close, .reset = NULL, - { .available = ati28800_wonderxl24_available }, + .available = ati28800_wonderxl24_available, .speed_changed = ati28800_speed_changed, .force_redraw = ati28800_force_redraw, .config = ati28800_wonderxl_config diff --git a/src/video/vid_ati_mach64.c b/src/video/vid_ati_mach64.c index 1c79ae1d5..2b89bddf4 100644 --- a/src/video/vid_ati_mach64.c +++ b/src/video/vid_ati_mach64.c @@ -28,6 +28,7 @@ #include <86box/device.h> #include <86box/io.h> #include <86box/mem.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/pci.h> #include <86box/rom.h> @@ -93,6 +94,7 @@ typedef struct mach64_t { int type; int pci; + int vlb; uint8_t pci_slot; uint8_t irq_state; @@ -423,7 +425,7 @@ mach64_out(uint16_t addr, uint8_t val, void *priv) case 0x3C8: case 0x3C9: if (mach64->type == MACH64_GX) - ati68860_ramdac_out((addr & 3) | ((mach64->dac_cntl & 3) << 2), val, svga->ramdac, svga); + ati68860_ramdac_out((addr & 3) | ((mach64->dac_cntl & 3) << 2), val, 0, svga->ramdac, svga); else svga_out(addr, val, svga); return; @@ -455,7 +457,7 @@ mach64_out(uint16_t addr, uint8_t val, void *priv) 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); + svga->memaddr_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5); } else { svga->fullchange = svga->monitor->mon_changeframecount; svga_recalctimings(svga); @@ -490,7 +492,7 @@ mach64_in(uint16_t addr, void *priv) case 0x3C8: case 0x3C9: if (mach64->type == MACH64_GX) - return ati68860_ramdac_in((addr & 3) | ((mach64->dac_cntl & 3) << 2), svga->ramdac, svga); + return ati68860_ramdac_in((addr & 3) | ((mach64->dac_cntl & 3) << 2), 0, svga->ramdac, svga); return svga_in(addr, svga); case 0x3D4: @@ -523,14 +525,18 @@ mach64_recalctimings(svga_t *svga) 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->ma_latch = (mach64->crtc_off_pitch & 0x1fffff) * 2; + svga->memaddr_latch = (mach64->crtc_off_pitch & 0x1fffff) * 2; svga->linedbl = svga->rowcount = 0; svga->split = 0xffffff; svga->vblankstart = svga->dispend; svga->rowcount = mach64->crtc_gen_cntl & 1; svga->rowoffset <<= 1; + if (mach64->type == MACH64_GX) ati68860_ramdac_set_render(svga->ramdac, svga); + + svga->packed_4bpp = !!(((mach64->crtc_gen_cntl >> 8) & 7) == BPP_4); + switch ((mach64->crtc_gen_cntl >> 8) & 7) { case BPP_4: if (mach64->type != MACH64_GX) @@ -571,8 +577,9 @@ mach64_recalctimings(svga_t *svga) } svga->vram_display_mask = mach64->vram_mask; - } else + } else { svga->vram_display_mask = (mach64->regs[0x36] & 0x01) ? mach64->vram_mask : 0x3ffff; + } } void @@ -1508,16 +1515,16 @@ mach64_start_line(mach64_t *mach64) mach64->accel.op = OP_LINE; } -#define READ(addr, dat, width) \ - if (width == 0) \ - dat = svga->vram[((addr)) & mach64->vram_mask]; \ - else if (width == 1) \ - dat = *(uint16_t *) &svga->vram[((addr) << 1) & mach64->vram_mask]; \ - else if (width == 2) \ - dat = *(uint32_t *) &svga->vram[((addr) << 2) & mach64->vram_mask]; \ - else if (mach64->dp_pix_width & DP_BYTE_PIX_ORDER) \ - dat = (svga->vram[((addr) >> 3) & mach64->vram_mask] >> ((addr) &7)) & 1; \ - else \ +#define READ(addr, dat, width) \ + if (width == 0) \ + dat = svga->vram[((addr)) & mach64->vram_mask]; \ + else if (width == 1) \ + dat = *(uint16_t *) &svga->vram[((addr) << 1) & mach64->vram_mask]; \ + else if (width == 2) \ + dat = *(uint32_t *) &svga->vram[((addr) << 2) & mach64->vram_mask]; \ + else if (mach64->dp_pix_width & DP_BYTE_PIX_ORDER) \ + dat = (svga->vram[((addr) >> 3) & mach64->vram_mask] >> ((addr) &7)) & 1; \ + else \ dat = (svga->vram[((addr) >> 3) & mach64->vram_mask] >> (7 - ((addr) &7))) & 1; #define MIX \ @@ -1575,29 +1582,29 @@ mach64_start_line(mach64_t *mach64) break; \ } -#define WRITE(addr, width) \ - if (width == 0) { \ - svga->vram[(addr) &mach64->vram_mask] = dest_dat; \ - svga->changedvram[((addr) &mach64->vram_mask) >> 12] = svga->monitor->mon_changeframecount; \ - } else if (width == 1) { \ - *(uint16_t *) &svga->vram[((addr) << 1) & mach64->vram_mask] = dest_dat; \ - svga->changedvram[(((addr) << 1) & mach64->vram_mask) >> 12] = svga->monitor->mon_changeframecount; \ - } else if (width == 2) { \ - *(uint32_t *) &svga->vram[((addr) << 2) & mach64->vram_mask] = dest_dat; \ - svga->changedvram[(((addr) << 2) & mach64->vram_mask) >> 12] = svga->monitor->mon_changeframecount; \ - } else { \ - if (dest_dat & 1) { \ - if (mach64->dp_pix_width & DP_BYTE_PIX_ORDER) \ - svga->vram[((addr) >> 3) & mach64->vram_mask] |= 1 << ((addr) &7); \ - else \ - svga->vram[((addr) >> 3) & mach64->vram_mask] |= 1 << (7 - ((addr) &7)); \ - } else { \ - if (mach64->dp_pix_width & DP_BYTE_PIX_ORDER) \ - svga->vram[((addr) >> 3) & mach64->vram_mask] &= ~(1 << ((addr) &7)); \ - else \ - svga->vram[((addr) >> 3) & mach64->vram_mask] &= ~(1 << (7 - ((addr) &7))); \ - } \ - svga->changedvram[(((addr) >> 3) & mach64->vram_mask) >> 12] = svga->monitor->mon_changeframecount; \ +#define WRITE(addr, width) \ + if (width == 0) { \ + svga->vram[(addr) &mach64->vram_mask] = dest_dat; \ + svga->changedvram[((addr) &mach64->vram_mask) >> 12] = svga->monitor->mon_changeframecount; \ + } else if (width == 1) { \ + *(uint16_t *) &svga->vram[((addr) << 1) & mach64->vram_mask] = dest_dat; \ + svga->changedvram[(((addr) << 1) & mach64->vram_mask) >> 12] = svga->monitor->mon_changeframecount; \ + } else if (width == 2) { \ + *(uint32_t *) &svga->vram[((addr) << 2) & mach64->vram_mask] = dest_dat; \ + svga->changedvram[(((addr) << 2) & mach64->vram_mask) >> 12] = svga->monitor->mon_changeframecount; \ + } else { \ + if (dest_dat & 1) { \ + if (mach64->dp_pix_width & DP_BYTE_PIX_ORDER) \ + svga->vram[((addr) >> 3) & mach64->vram_mask] |= 1 << ((addr) &7); \ + else \ + svga->vram[((addr) >> 3) & mach64->vram_mask] |= 1 << (7 - ((addr) &7)); \ + } else { \ + if (mach64->dp_pix_width & DP_BYTE_PIX_ORDER) \ + svga->vram[((addr) >> 3) & mach64->vram_mask] &= ~(1 << ((addr) &7)); \ + else \ + svga->vram[((addr) >> 3) & mach64->vram_mask] &= ~(1 << (7 - ((addr) &7))); \ + } \ + svga->changedvram[(((addr) >> 3) & mach64->vram_mask) >> 12] = svga->monitor->mon_changeframecount; \ } void @@ -1669,7 +1676,7 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) case MONO_SRC_PAT: if (mach64->dst_cntl & DST_24_ROT_EN) { if (!mach64->accel.xx_count) - mix = mach64->accel.pattern[dst_y & 7][dst_x & 7]; + mix = mach64->accel.pattern[dst_y & 7][(dst_x / 3) & 7]; } else mix = mach64->accel.pattern[dst_y & 7][dst_x & 7]; break; @@ -2309,6 +2316,7 @@ uint8_t mach64_ext_readb(uint32_t addr, void *priv) { mach64_t *mach64 = (mach64_t *) priv; + svga_t *svga = &mach64->svga; uint8_t ret = 0xff; if (!(addr & 0x400)) { @@ -2522,9 +2530,23 @@ mach64_ext_readb(uint32_t addr, void *priv) case 0xc2: case 0xc3: if (mach64->type == MACH64_GX) - ret = ati68860_ramdac_in((addr & 3) | ((mach64->dac_cntl & 3) << 2), mach64->svga.ramdac, &mach64->svga); - else - ret = ati68860_ramdac_in(addr & 3, mach64->svga.ramdac, &mach64->svga); + ret = ati68860_ramdac_in((addr & 3) | ((mach64->dac_cntl & 3) << 2), 0, mach64->svga.ramdac, &mach64->svga); + else { + switch (addr & 3) { + case 0: + ret = svga_in(0x3c8, svga); + break; + case 1: + ret = svga_in(0x3c9, svga); + break; + case 2: + ret = svga_in(0x3c6, svga); + break; + case 3: + ret = svga_in(0x3c7, svga); + break; + } + } break; case 0xc4: case 0xc5: @@ -2961,7 +2983,7 @@ mach64_ext_readl(uint32_t addr, void *priv) uint32_t ret; if (!(addr & 0x400)) { - mach64_log("nmach64_ext_readl: addr=%04x\n", addr); + mach64_log("mach64_ext_readl: addr=%04x\n", addr); ret = 0xffffffff; } else switch (addr & 0x3ff) { @@ -3100,6 +3122,7 @@ mach64_ext_writeb(uint32_t addr, uint8_t val, void *priv) } else if (addr & 0x300) { mach64_queue(mach64, addr & 0x3ff, val, FIFO_WRITE_BYTE); } else { + mach64_log("mach64_ext_writeb: addr=%04x val=%02x\n", addr & 0x3ff, val); switch (addr & 0x3ff) { case 0x00: case 0x01: @@ -3188,39 +3211,48 @@ mach64_ext_writeb(uint32_t addr, uint8_t val, void *priv) case 0x62: case 0x63: WRITE8(addr, mach64->cur_clr0, val); - if (mach64->type == MACH64_VT2) - ati68860_ramdac_set_pallook(mach64->svga.ramdac, 0, makecol32((mach64->cur_clr0 >> 24) & 0xff, (mach64->cur_clr0 >> 16) & 0xff, (mach64->cur_clr0 >> 8) & 0xff)); break; case 0x64: case 0x65: case 0x66: case 0x67: WRITE8(addr, mach64->cur_clr1, val); - if (mach64->type == MACH64_VT2) - ati68860_ramdac_set_pallook(mach64->svga.ramdac, 1, makecol32((mach64->cur_clr1 >> 24) & 0xff, (mach64->cur_clr1 >> 16) & 0xff, (mach64->cur_clr1 >> 8) & 0xff)); break; case 0x68: case 0x69: case 0x6a: case 0x6b: WRITE8(addr, mach64->cur_offset, val); - svga->dac_hwcursor.addr = (mach64->cur_offset & 0xfffff) * 8; + if (mach64->type == MACH64_GX) + svga->dac_hwcursor.addr = (mach64->cur_offset & 0xfffff) << 3; + else + svga->hwcursor.addr = (mach64->cur_offset & 0xfffff) << 3; break; case 0x6c: case 0x6d: case 0x6e: case 0x6f: WRITE8(addr, mach64->cur_horz_vert_posn, val); - svga->dac_hwcursor.x = mach64->cur_horz_vert_posn & 0x7ff; - svga->dac_hwcursor.y = (mach64->cur_horz_vert_posn >> 16) & 0x7ff; + if (mach64->type == MACH64_GX) { + svga->dac_hwcursor.x = mach64->cur_horz_vert_posn & 0x7ff; + svga->dac_hwcursor.y = (mach64->cur_horz_vert_posn >> 16) & 0x7ff; + } else { + svga->hwcursor.x = mach64->cur_horz_vert_posn & 0x7ff; + svga->hwcursor.y = (mach64->cur_horz_vert_posn >> 16) & 0x7ff; + } break; case 0x70: case 0x71: case 0x72: case 0x73: WRITE8(addr, mach64->cur_horz_vert_off, val); - svga->dac_hwcursor.xoff = mach64->cur_horz_vert_off & 0x3f; - svga->dac_hwcursor.yoff = (mach64->cur_horz_vert_off >> 16) & 0x3f; + if (mach64->type == MACH64_GX) { + svga->dac_hwcursor.xoff = mach64->cur_horz_vert_off & 0x3f; + svga->dac_hwcursor.yoff = (mach64->cur_horz_vert_off >> 16) & 0x3f; + } else { + svga->hwcursor.xoff = mach64->cur_horz_vert_off & 0x3f; + svga->hwcursor.yoff = (mach64->cur_horz_vert_off >> 16) & 0x3f; + } break; case 0x80: @@ -3281,9 +3313,23 @@ mach64_ext_writeb(uint32_t addr, uint8_t val, void *priv) case 0xc2: case 0xc3: if (mach64->type == MACH64_GX) - ati68860_ramdac_out((addr & 3) | ((mach64->dac_cntl & 3) << 2), val, svga->ramdac, svga); - else - ati68860_ramdac_out(addr & 3, val, svga->ramdac, svga); + ati68860_ramdac_out((addr & 3) | ((mach64->dac_cntl & 3) << 2), val, 0, svga->ramdac, svga); + else { + switch (addr & 3) { + case 0: + svga_out(0x3c8, val, svga); + break; + case 1: + svga_out(0x3c9, val, svga); + break; + case 2: + svga_out(0x3c6, val, svga); + break; + case 3: + svga_out(0x3c7, val, svga); + break; + } + } break; case 0xc4: case 0xc5: @@ -3293,7 +3339,8 @@ mach64_ext_writeb(uint32_t addr, uint8_t val, void *priv) mach64_log("Ext RAMDAC TYPE write=%x, bit set=%03x.\n", addr & 0x3ff, mach64->dac_cntl & 0x100); if ((addr & 3) >= 1) { svga_set_ramdac_type(svga, !!(mach64->dac_cntl & 0x100)); - ati68860_set_ramdac_type(svga->ramdac, !!(mach64->dac_cntl & 0x100)); + if (mach64->type == MACH64_GX) + ati68860_set_ramdac_type(svga->ramdac, !!(mach64->dac_cntl & 0x100)); } i2c_gpio_set(mach64->i2c, !(mach64->dac_cntl & 0x20000000) || (mach64->dac_cntl & 0x04000000), !(mach64->dac_cntl & 0x10000000) || (mach64->dac_cntl & 0x02000000)); break; @@ -3305,7 +3352,10 @@ mach64_ext_writeb(uint32_t addr, uint8_t val, void *priv) WRITE8(addr, mach64->gen_test_cntl, val); ati_eeprom_write(&mach64->eeprom, mach64->gen_test_cntl & 0x10, mach64->gen_test_cntl & 2, mach64->gen_test_cntl & 1); mach64->gen_test_cntl = (mach64->gen_test_cntl & ~8) | (ati_eeprom_read(&mach64->eeprom) ? 8 : 0); - svga->dac_hwcursor.ena = mach64->gen_test_cntl & 0x80; + if (mach64->type == MACH64_GX) + svga->dac_hwcursor.ena = !!(mach64->gen_test_cntl & 0x80); + else + svga->hwcursor.ena = !!(mach64->gen_test_cntl & 0x80); break; case 0xdc: @@ -3370,6 +3420,7 @@ uint8_t mach64_ext_inb(uint16_t port, void *priv) { mach64_t *mach64 = (mach64_t *) priv; + svga_t *svga = &mach64->svga; uint8_t ret = 0xff; switch (port) { @@ -3383,6 +3434,12 @@ mach64_ext_inb(uint16_t port, void *priv) case 0x7eef: ret = mach64_ext_readb(0x400 | 0x00 | (port & 3), priv); break; + case 0x06ec: + case 0x06ed: + case 0x06ee: + case 0x06ef: + ret = mach64_ext_readb(0x400 | 0x04 | (port & 3), priv); + break; case 0x0aec: case 0x0aed: case 0x0aee: @@ -3517,9 +3574,23 @@ mach64_ext_inb(uint16_t port, void *priv) case 0x5eee: case 0x5eef: if (mach64->type == MACH64_GX) - ret = ati68860_ramdac_in((port & 3) | ((mach64->dac_cntl & 3) << 2), mach64->svga.ramdac, &mach64->svga); - else - ret = ati68860_ramdac_in(port & 3, mach64->svga.ramdac, &mach64->svga); + ret = ati68860_ramdac_in((port & 3) | ((mach64->dac_cntl & 3) << 2), 0, mach64->svga.ramdac, &mach64->svga); + else { + switch (port & 3) { + case 0: + ret = svga_in(0x3c8, svga); + break; + case 1: + ret = svga_in(0x3c9, svga); + break; + case 2: + ret = svga_in(0x3c6, svga); + break; + case 3: + ret = svga_in(0x3c7, svga); + break; + } + } break; case 0x62ec: @@ -3616,6 +3687,12 @@ mach64_ext_outb(uint16_t port, uint8_t val, void *priv) case 0x7eef: mach64_ext_writeb(0x400 | 0x00 | (port & 3), val, priv); break; + case 0x06ec: + case 0x06ed: + case 0x06ee: + case 0x06ef: + mach64_ext_writeb(0x400 | 0x04 | (port & 3), val, priv); + break; case 0x0aec: case 0x0aed: case 0x0aee: @@ -3743,9 +3820,23 @@ mach64_ext_outb(uint16_t port, uint8_t val, void *priv) case 0x5eee: case 0x5eef: if (mach64->type == MACH64_GX) - ati68860_ramdac_out((port & 3) | ((mach64->dac_cntl & 3) << 2), val, svga->ramdac, svga); - else - ati68860_ramdac_out(port & 3, val, svga->ramdac, svga); + ati68860_ramdac_out((port & 3) | ((mach64->dac_cntl & 3) << 2), val, 0, svga->ramdac, svga); + else { + switch (port & 3) { + case 0: + svga_out(0x3c8, val, svga); + break; + case 1: + svga_out(0x3c9, val, svga); + break; + case 2: + svga_out(0x3c6, val, svga); + break; + case 3: + svga_out(0x3c7, val, svga); + break; + } + } break; case 0x62ec: @@ -3767,6 +3858,9 @@ mach64_ext_outb(uint16_t port, uint8_t val, void *priv) case 0x6aee: case 0x6aef: WRITE8(port, mach64->config_cntl, val); + if (mach64->vlb) + mach64->linear_base = (mach64->config_cntl & 0x3ff0) << 18; + mach64_updatemapping(mach64); break; @@ -3901,6 +3995,63 @@ mach64_readl(uint32_t addr, void *priv) return ret; } +void +mach64_int_hwcursor_draw(svga_t *svga, int displine) +{ + const mach64_t *mach64 = (mach64_t *) svga->priv; + int comb; + int offset; + int x_pos; + int y_pos; + int shift = 0; + uint16_t dat; + uint32_t col0 = makecol32((mach64->cur_clr0 >> 24) & 0xff, (mach64->cur_clr0 >> 16) & 0xff, (mach64->cur_clr0 >> 8) & 0xff); + uint32_t col1 = makecol32((mach64->cur_clr1 >> 24) & 0xff, (mach64->cur_clr1 >> 16) & 0xff, (mach64->cur_clr1 >> 8) & 0xff); + uint32_t *p; + + offset = svga->hwcursor_latch.x - svga->hwcursor_latch.xoff; + if (svga->packed_4bpp) + shift = 1; + + for (int x = 0; x < svga->hwcursor_latch.cur_xsize; x += (8 >> shift)) { + if (shift) { + dat = svga->vram[(svga->hwcursor_latch.addr) & svga->vram_mask] & 0x0f; + dat |= (svga->vram[(svga->hwcursor_latch.addr + 1) & svga->vram_mask] << 4); + dat |= (svga->vram[(svga->hwcursor_latch.addr + 2) & svga->vram_mask] << 8); + dat |= (svga->vram[(svga->hwcursor_latch.addr + 3) & svga->vram_mask] << 12); + } else { + dat = svga->vram[svga->hwcursor_latch.addr & svga->vram_mask]; + dat |= (svga->vram[(svga->hwcursor_latch.addr + 1) & svga->vram_mask] << 8); + } + for (int xx = 0; xx < (8 >> shift); xx++) { + comb = (dat >> (xx << 1)) & 0x03; + + y_pos = displine; + x_pos = offset + svga->x_add; + p = buffer32->line[y_pos]; + + if (offset >= svga->hwcursor_latch.x) { + switch (comb) { + case 0: + p[x_pos] = col0; + break; + case 1: + p[x_pos] = col1; + break; + case 3: + p[x_pos] ^= 0xffffff; + break; + + default: + break; + } + } + offset++; + } + svga->hwcursor_latch.addr += 2; + } +} + #define CLAMP(x) \ do { \ if ((x) & ~0xff) \ @@ -4546,15 +4697,22 @@ mach64_common_init(const device_t *info) svga = &mach64->svga; + mach64->type = info->local & 0xff; mach64->vram_size = device_get_config_int("memory"); mach64->vram_mask = (mach64->vram_size << 20) - 1; - svga_init(info, svga, mach64, mach64->vram_size << 20, - mach64_recalctimings, - mach64_in, mach64_out, - NULL, - mach64_overlay_draw); - svga->dac_hwcursor.cur_ysize = 64; + if (mach64->type > MACH64_GX) + svga_init(info, svga, mach64, mach64->vram_size << 20, + mach64_recalctimings, + mach64_in, mach64_out, + mach64_int_hwcursor_draw, + mach64_overlay_draw); + else + svga_init(info, svga, mach64, mach64->vram_size << 20, + mach64_recalctimings, + mach64_in, mach64_out, + NULL, + mach64_overlay_draw); mem_mapping_add(&mach64->linear_mapping, 0, 0, mach64_read_linear, mach64_readw_linear, mach64_readl_linear, mach64_write_linear, mach64_writew_linear, mach64_writel_linear, NULL, MEM_MAPPING_EXTERNAL, svga); mem_mapping_add(&mach64->mmio_linear_mapping, 0, 0, mach64_ext_readb, mach64_ext_readw, mach64_ext_readl, mach64_ext_writeb, mach64_ext_writew, mach64_ext_writel, NULL, MEM_MAPPING_EXTERNAL, mach64); @@ -4572,9 +4730,6 @@ mach64_common_init(const device_t *info) mach64->pci_regs[0x32] = 0x0c; mach64->pci_regs[0x33] = 0x00; - svga->ramdac = device_add(&ati68860_ramdac_device); - svga->dac_hwcursor_draw = ati68860_hwcursor_draw; - svga->clock_gen = device_add(&ics2595_device); mach64->dst_cntl = 3; @@ -4594,20 +4749,27 @@ static void * mach64gx_init(const device_t *info) { mach64_t *mach64 = mach64_common_init(info); + svga_t *svga = &mach64->svga; - if (info->flags & DEVICE_ISA) + svga->ramdac = device_add(&ati68860_ramdac_device); + svga->dac_hwcursor_draw = ati68860_hwcursor_draw; + + svga->dac_hwcursor.cur_ysize = 64; + svga->dac_hwcursor.cur_xsize = 64; + + if (info->flags & DEVICE_ISA16) video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_mach64_isa); else if (info->flags & DEVICE_PCI) video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_mach64_pci); else video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_mach64_vlb); - mach64->type = MACH64_GX; mach64->pci = !!(info->flags & DEVICE_PCI); + mach64->vlb = !!(info->flags & DEVICE_VLB); 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*/ + mach64->config_stat0 = (5 << 9) | (3 << 3); /*ATI 68860, 256Kx16 DRAM*/ if (info->flags & DEVICE_PCI) { mach64->config_stat0 |= 7; /*PCI, 256Kx16 DRAM*/ ati_eeprom_load(&mach64->eeprom, "mach64_pci.nvr", 1); @@ -4617,7 +4779,7 @@ mach64gx_init(const device_t *info) mach64->config_stat0 |= 6; /*VLB, 256Kx16 DRAM*/ ati_eeprom_load(&mach64->eeprom, "mach64_vlb.nvr", 1); rom_init(&mach64->bios_rom, BIOS_VLB_ROM_PATH, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); - } else if (info->flags & DEVICE_ISA) { + } else if (info->flags & DEVICE_ISA16) { mach64->config_stat0 |= 0; /*ISA 16-bit, 256k16 DRAM*/ ati_eeprom_load(&mach64->eeprom, "mach64.nvr", 1); rom_init(&mach64->bios_rom, BIOS_ISA_ROM_PATH, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); @@ -4631,10 +4793,15 @@ mach64vt2_init(const device_t *info) mach64_t *mach64 = mach64_common_init(info); svga_t *svga = &mach64->svga; + svga->dac_hwcursor_draw = NULL; + + svga->hwcursor.cur_ysize = 64; + svga->hwcursor.cur_xsize = 64; + video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_mach64_pci); - mach64->type = MACH64_VT2; mach64->pci = 1; + mach64->vlb = 0; mach64->pci_id = 0x5654; mach64->config_chip_id = 0x40005654; mach64->dac_cntl = 1 << 16; /*Internal 24-bit DAC*/ @@ -4711,68 +4878,53 @@ mach64_force_redraw(void *priv) // clang-format off static const device_config_t mach64gx_config[] = { { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 4, - .selection = { - { - .description = "1 MB", - .value = 1 - }, - { - .description = "2 MB", - .value = 2 - }, - { - .description = "4 MB", - .value = 4 - }, - { - .description = "" - } - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 4, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "1 MB", .value = 1 }, + { .description = "2 MB", .value = 2 }, + { .description = "4 MB", .value = 4 }, + { .description = "" } + }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t mach64vt2_config[] = { { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 4, - .selection = { - { - .description = "2 MB", - .value = 2 - }, - { - .description = "4 MB", - .value = 4 - }, - { - .description = "" - } - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 4, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "2 MB", .value = 2 }, + { .description = "4 MB", .value = 4 }, + { .description = "" } + }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; // clang-format on const device_t mach64gx_isa_device = { .name = "ATI Mach64GX ISA", .internal_name = "mach64gx_isa", - .flags = DEVICE_AT | DEVICE_ISA, - .local = 0, + .flags = DEVICE_ISA16, + .local = MACH64_GX, .init = mach64gx_init, .close = mach64_close, .reset = NULL, - { .available = mach64gx_isa_available }, + .available = mach64gx_isa_available, .speed_changed = mach64_speed_changed, .force_redraw = mach64_force_redraw, .config = mach64gx_config @@ -4782,11 +4934,11 @@ const device_t mach64gx_vlb_device = { .name = "ATI Mach64GX VLB", .internal_name = "mach64gx_vlb", .flags = DEVICE_VLB, - .local = 0, + .local = MACH64_GX, .init = mach64gx_init, .close = mach64_close, .reset = NULL, - { .available = mach64gx_vlb_available }, + .available = mach64gx_vlb_available, .speed_changed = mach64_speed_changed, .force_redraw = mach64_force_redraw, .config = mach64gx_config @@ -4796,11 +4948,11 @@ const device_t mach64gx_pci_device = { .name = "ATI Mach64GX PCI", .internal_name = "mach64gx_pci", .flags = DEVICE_PCI, - .local = 0, + .local = MACH64_GX, .init = mach64gx_init, .close = mach64_close, .reset = NULL, - { .available = mach64gx_available }, + .available = mach64gx_available, .speed_changed = mach64_speed_changed, .force_redraw = mach64_force_redraw, .config = mach64gx_config @@ -4810,11 +4962,11 @@ const device_t mach64vt2_device = { .name = "ATI Mach64VT2", .internal_name = "mach64vt2", .flags = DEVICE_PCI, - .local = 0, + .local = MACH64_VT2, .init = mach64vt2_init, .close = mach64_close, .reset = NULL, - { .available = mach64vt2_available }, + .available = mach64vt2_available, .speed_changed = mach64_speed_changed, .force_redraw = mach64_force_redraw, .config = mach64vt2_config diff --git a/src/video/vid_ati_mach8.c b/src/video/vid_ati_mach8.c index 558f37f5b..46d3d98c1 100644 --- a/src/video/vid_ati_mach8.c +++ b/src/video/vid_ati_mach8.c @@ -15,6 +15,7 @@ * * Copyright 2022-2024 TheCollector1995. */ +#include #include #include #include @@ -27,6 +28,7 @@ #include <86box/device.h> #include <86box/io.h> #include <86box/mem.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/mca.h> #include <86box/pci.h> @@ -49,10 +51,10 @@ #define BIOS_MACH32_MCA_ROM_PATH "roms/video/mach32/MACH32MCA_Olivetti.BIN" #define BIOS_MACH32_PCI_ROM_PATH "roms/video/mach32/intelopt_00000.rom" -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_mca = { .type = VIDEO_MCA, .write_b = 4, .write_w = 5, .write_l = 10, .read_b = 5, .read_w = 5, .read_l = 10 }; -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 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_mca = { .type = VIDEO_MCA, .write_b = 4, .write_w = 5, .write_l = 10, .read_b = 5, .read_w = 5, .read_l = 10 }; +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); @@ -68,7 +70,12 @@ static uint8_t ati8514_accel_inb(uint16_t port, void *priv); static uint16_t ati8514_accel_inw(uint16_t port, void *priv); static uint32_t ati8514_accel_inl(uint16_t port, void *priv); +static void mach_set_resolution(mach_t *mach, svga_t *svga); static void mach32_updatemapping(mach_t *mach, svga_t *svga); +static __inline void mach32_writew_linear(uint32_t addr, uint16_t val, mach_t *mach); +static __inline void mach32_write_common(uint32_t addr, uint8_t val, int linear, mach_t *mach, svga_t *svga); + +static mach_t *reset_state = NULL; #ifdef ENABLE_MACH_LOG int mach_do_log = ENABLE_MACH_LOG; @@ -88,14 +95,14 @@ mach_log(const char *fmt, ...) # define mach_log(fmt, ...) #endif -#define WRITE8(addr, var, val) \ - switch ((addr) & 1) { \ - case 0: \ - var = (var & 0xff00) | (val); \ - break; \ - case 1: \ - var = (var & 0x00ff) | ((val) << 8); \ - break; \ +#define WRITE8(addr, var, val) \ + switch ((addr) & 1) { \ + case 0: \ + var = (var & 0xff00) | (val); \ + break; \ + case 1: \ + var = (var & 0x00ff) | ((val) << 8); \ + break; \ } #define READ8(addr, var) \ @@ -110,166 +117,154 @@ mach_log(const char *fmt, ...) #define READ_PIXTRANS_BYTE_IO(cx, n) \ if ((mach->accel.cmd_type == 2) || (mach->accel.cmd_type == 5)) { \ - if (dev->bpp) { \ - if (n == 0)\ + if (dev->bpp) { \ + if (n == 0) \ mach->accel.pix_trans[(n)] = vram_w[(dev->accel.dest + (cx) + (n)) & (dev->vram_mask >> 1)] & 0xff; \ - else \ - mach->accel.pix_trans[(n)] = vram_w[(dev->accel.dest + (cx) + (n)) & (dev->vram_mask >> 1)] >> 8; \ - \ - } else \ - mach->accel.pix_trans[(n)] = dev->vram[(dev->accel.dest + (cx) + (n)) & dev->vram_mask]; \ - \ + else \ + mach->accel.pix_trans[(n)] = vram_w[(dev->accel.dest + (cx) + (n)) & (dev->vram_mask >> 1)] >> 8; \ + } else \ + mach->accel.pix_trans[(n)] = dev->vram[(dev->accel.dest + (cx) + (n)) & dev->vram_mask]; \ } -#define READ_PIXTRANS_WORD(cx, n) \ - if ((cmd == 0) || (cmd == 1) || (cmd == 5) || (mach->accel.cmd_type == -1)) { \ - if (dev->bpp) \ - temp = vram_w[((dev->accel.cy * dev->pitch) + (cx) + (n)) & (dev->vram_mask >> 1)]; \ - 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 (dev->bpp) \ - temp = vram_w[((dev->accel.dest) + (cx) + (n)) & (dev->vram_mask >> 1)]; \ - 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 ((mach->accel.cmd_type == 3) || (mach->accel.cmd_type == 4)) { \ - if (dev->bpp) \ - temp = vram_w[((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (cx) + (n)) & (dev->vram_mask >> 1)]; \ - 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); \ - } \ +#define READ_PIXTRANS_WORD(cx, n) \ + if ((cmd == 0) || (cmd == 1) || (cmd == 5) || ((mach->accel.cmd_type == -1) && (cmd != 2))) { \ + if (dev->bpp) \ + temp = vram_w[((dev->accel.cy * dev->pitch) + (cx) + (n)) & (dev->vram_mask >> 1)]; \ + 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 (((cmd == 2) && (mach->accel.cmd_type == -1)) || (mach->accel.cmd_type == 2) || (mach->accel.cmd_type == 5)) { \ + if (dev->bpp) \ + temp = vram_w[((dev->accel.dest) + (cx) + (n)) & (dev->vram_mask >> 1)]; \ + 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 ((mach->accel.cmd_type == 3) || (mach->accel.cmd_type == 4)) { \ + if (dev->bpp) \ + temp = vram_w[(mach->accel.dst_ge_offset + ((dev->accel.cy) * (mach->accel.dst_pitch)) + (cx) + (n)) & (dev->vram_mask >> 1)]; \ + else { \ + temp = dev->vram[(mach->accel.dst_ge_offset + ((dev->accel.cy) * (mach->accel.dst_pitch)) + (cx) + (n)) & dev->vram_mask]; \ + temp |= (dev->vram[(mach->accel.dst_ge_offset + ((dev->accel.cy) * (mach->accel.dst_pitch)) + (cx) + (n + 1)) & dev->vram_mask] << 8); \ + } \ } -#define READ(addr, dat) \ - if (dev->bpp) \ +#define READ(addr, dat) \ + if (dev->bpp) \ dat = vram_w[(addr) & (dev->vram_mask >> 1)]; \ - else \ + else \ dat = (dev->vram[(addr) & (dev->vram_mask)]); -#define READ_HIGH(addr, dat) \ +#define READ_HIGH(addr, dat) \ dat |= (dev->vram[(addr) & (dev->vram_mask)] << 8); -#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: \ - if (dev->bpp) \ - dest_dat = MIN(0xffff, (dest_dat + src_dat)); \ - else \ - 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: \ - if (dev->bpp) \ - dest_dat = (0xffff < (src_dat + dest_dat)) ? 0xffff : ((src_dat + dest_dat) / 2); \ - else \ - dest_dat = (0xff < (src_dat + dest_dat)) ? 0xff : ((src_dat + dest_dat) / 2); \ - break; \ - } \ +#define MIX(mixmode, dest_dat, src_dat) \ + { \ + switch ((mixmode) ? dev->accel.frgd_mix : dev->accel.bkgd_mix) { \ + 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: \ + case 0x11: \ + dest_dat = ~src_dat | dest_dat; \ + break; \ + case 0x0a: \ + case 0x12: \ + dest_dat = src_dat | ~dest_dat; \ + break; \ + case 0x0b: \ + case 0x13: \ + 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 0x14: \ + dest_dat = MAX(src_dat, dest_dat); \ + break; \ + case 0x15: \ + dest_dat = (src_dat | ~dest_dat) >> 1; \ + break; \ + case 0x16: \ + dest_dat = (~src_dat | dest_dat) >> 1; \ + break; \ + case 0x17: \ + dest_dat = (src_dat | dest_dat) >> 1; \ + break; \ + case 0x18: \ + case 0x19: \ + dest_dat = MAX(0, ~src_dat | dest_dat); \ + break; \ + case 0x1a: \ + dest_dat = MAX(0, src_dat | ~dest_dat); \ + break; \ + case 0x1b: \ + if (dev->bpp) \ + dest_dat = MIN(0xffff, src_dat | dest_dat); \ + else \ + dest_dat = MIN(0xff, src_dat | dest_dat); \ + break; \ + case 0x1c: \ + case 0x1d: \ + dest_dat = MAX(0, ~src_dat | dest_dat) >> 1; \ + break; \ + case 0x1e: \ + dest_dat = MAX(0, src_dat | ~dest_dat) >> 1; \ + break; \ + case 0x1f: \ + if (dev->bpp) \ + dest_dat = (0xffff < (src_dat | dest_dat)) ? 0xffff : ((src_dat | dest_dat) >> 1); \ + else \ + dest_dat = (0xff < (src_dat | dest_dat)) ? 0xff : ((src_dat | dest_dat) >> 1); \ + break; \ + } \ } -#define WRITE(addr, dat) \ - if (dev->bpp) { \ - vram_w[((addr)) & (dev->vram_mask >> 1)] = dat; \ - dev->changedvram[(((addr)) & (dev->vram_mask >> 1)) >> 11] = changeframecount; \ - } else { \ - dev->vram[((addr)) & (dev->vram_mask)] = dat; \ - dev->changedvram[(((addr)) & (dev->vram_mask)) >> 12] = changeframecount; \ +#define WRITE(addr, dat) \ + if (dev->bpp) { \ + vram_w[((addr)) & (dev->vram_mask >> 1)] = dat; \ + dev->changedvram[(((addr)) & (dev->vram_mask >> 1)) >> 11] = svga->monitor->mon_changeframecount; \ + } else { \ + dev->vram[((addr)) & (dev->vram_mask)] = dat; \ + dev->changedvram[(((addr)) & (dev->vram_mask)) >> 12] = svga->monitor->mon_changeframecount; \ } static int @@ -291,13 +286,15 @@ mach_pixel_read(mach_t *mach) } static void -mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint32_t cpu_dat, svga_t *svga, mach_t *mach, ibm8514_t *dev) +mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint32_t cpu_dat, UNUSED(svga_t *svga), mach_t *mach, ibm8514_t *dev) { int compare_mode; uint16_t 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; + uint16_t frgd_color = dev->accel.frgd_color; + uint16_t bkgd_color = dev->accel.bkgd_color; int frgd_sel; int bkgd_sel; int mono_src; @@ -314,9 +311,16 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 int16_t clip_b = dev->accel.clip_bottom; int16_t clip_r = dev->accel.clip_right; + if (clip_l < 0) + clip_l = 0; + if (clip_t < 0) + clip_t = 0; + if (!dev->bpp) { rd_mask &= 0xff; dest_cmp_clr &= 0xff; + frgd_color &= 0xff; + bkgd_color &= 0xff; } compare_mode = (mach->accel.dest_cmp_fn >> 3) & 7; @@ -324,12 +328,6 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 bkgd_sel = (mach->accel.dp_config >> 7) & 3; mono_src = (mach->accel.dp_config >> 5) & 3; - if ((mono_src == 2) || (bkgd_sel == 2) || (frgd_sel == 2) || mach_pixel_read(mach)) { - mach->force_busy = 1; - dev->force_busy = 1; - dev->force_busy2 = 1; - } - if (cpu_input) { if (dev->bpp) { if ((mach->accel.dp_config & 0x200) && (count == 2)) @@ -337,8 +335,7 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } } - if ((dev->accel_bpp == 8) || (dev->accel_bpp == 15) || (dev->accel_bpp == 16) || (dev->accel_bpp == 24)) - mach_log("RdMask=%04x, DPCONFIG=%04x, Clipping: l=%d, r=%d, t=%d, b=%d, LineDrawOpt=%04x, BPP=%d, CMDType = %d, offs=%08x, cnt = %d, input = %d, mono_src = %d, frgdsel = %d, d(%d,%d), dstxend = %d, pitch = %d, extcrt = %d, rw = %x, monpattern = %x.\n", dev->accel.rd_mask, mach->accel.dp_config, clip_l, clip_r, clip_t, clip_b, mach->accel.linedraw_opt, dev->accel_bpp, cmd_type, mach->accel.ge_offset, count, cpu_input, mono_src, frgd_sel, dev->accel.cur_x, dev->accel.cur_y, mach->accel.dest_x_end, dev->ext_pitch, dev->ext_crt_pitch, mach->accel.dp_config & 1, mach->accel.mono_pattern_enable); + mach_log("cmd_type = %i, frgd_sel = %i, bkgd_sel = %i, mono_src = %i, dpconfig = %04x, cur_x = %d, cur_y = %d, cl = %d, cr = %d, ct = %d, cb = %d, accel_bpp = %d, pitch = %d, hicolbpp = %d, pattlen = %d.\n", cmd_type, frgd_sel, bkgd_sel, mono_src, mach->accel.dp_config, dev->accel.cur_x, dev->accel.cur_y, clip_l, clip_r, clip_t, clip_b, dev->accel_bpp, dev->pitch, dev->bpp, mach->accel.patt_len); switch (cmd_type) { case 1: /*Extended Raw Linedraw from bres_count register (0x96ee)*/ @@ -366,14 +363,24 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 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); + 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 (!dev->accel.cmd_back) { if (mach_pixel_write(mach)) { + mach_log("Extended Bresenham Write pixtrans.\n"); + dev->force_busy = 1; + dev->force_busy2 = 1; + mach->force_busy = 1; dev->data_available = 0; dev->data_available2 = 0; return; } else if (mach_pixel_read(mach)) { + mach_log("Extended Bresenham Read pixtrans.\n"); + dev->force_busy = 1; + dev->force_busy2 = 1; + mach->force_busy = 1; dev->data_available = 1; dev->data_available2 = 1; return; @@ -419,11 +426,7 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } break; case 3: - if (dev->bpp) { - READ((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), mix); - } else { - READ((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), mix); - } + READ(mach->accel.src_ge_offset + (dev->accel.cy * mach->accel.src_pitch) + dev->accel.cx, mix); mix = (mix & rd_mask) == rd_mask; break; @@ -435,12 +438,13 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 (dev->accel.dx <= clip_r) && (dev->accel.dy >= clip_t) && (dev->accel.dy <= clip_b)) { + dev->subsys_stat |= INT_GE_BSY; switch (mix ? frgd_sel : bkgd_sel) { case 0: - src_dat = dev->accel.bkgd_color; + src_dat = bkgd_color; break; case 1: - src_dat = dev->accel.frgd_color; + src_dat = frgd_color; break; case 2: src_dat = cpu_dat; @@ -449,19 +453,16 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 if (mach_pixel_read(mach)) src_dat = cpu_dat; else { - if (dev->bpp) { - READ((mach->accel.ge_offset << 1) + (dev->accel.cy * dev->pitch) + dev->accel.cx, src_dat); - } else { - READ((mach->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch) + dev->accel.cx, src_dat); - } + READ(mach->accel.src_ge_offset + (dev->accel.cy * mach->accel.src_pitch) + dev->accel.cx, src_dat); if (mono_src == 3) src_dat = (src_dat & rd_mask) == rd_mask; } break; case 5: - src_dat = mach->accel.color_pattern[mach->accel.color_pattern_idx]; if (dev->bpp) - src_dat |= (mach->accel.color_pattern[mach->accel.color_pattern_idx + 1] << 8); + src_dat = mach->accel.color_pattern_hicol[mach->accel.color_pattern_idx]; + else + src_dat = mach->accel.color_pattern[mach->accel.color_pattern_idx]; break; default: @@ -469,22 +470,14 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } if (mach->accel.linedraw_opt & 0x02) { - if (dev->bpp) { - READ((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), poly_src); - } else { - READ((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), poly_src); - } + READ(mach->accel.src_ge_offset + (dev->accel.cy * mach->accel.src_pitch) + dev->accel.cx, poly_src); 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)) { - if (dev->bpp) { - READ((mach->accel.ge_offset << 1) + ((dev->accel.dy) * (dev->pitch)) + (dev->accel.dx), dest_dat); - } else { - READ((mach->accel.ge_offset << 2) + ((dev->accel.dy) * (dev->pitch)) + (dev->accel.dx), dest_dat); - } + READ(mach->accel.dst_ge_offset + (dev->accel.dy * mach->accel.dst_pitch) + dev->accel.dx, dest_dat); switch (compare_mode) { case 1: @@ -524,27 +517,31 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 if (mach->accel.dp_config & 0x10) { if (mach->accel.linedraw_opt & 0x04) { if (((mono_src != 1) && (dev->accel.sx < mach->accel.width)) || ((mono_src == 1) && count)) { - if (dev->bpp) { - WRITE((mach->accel.ge_offset << 1) + ((dev->accel.dy) * (dev->pitch)) + (dev->accel.dx), dest_dat); - } else { - WRITE((mach->accel.ge_offset << 2) + ((dev->accel.dy) * (dev->pitch)) + (dev->accel.dx), dest_dat); - } + WRITE(mach->accel.dst_ge_offset + (dev->accel.dy * mach->accel.dst_pitch) + dev->accel.dx, dest_dat); } } else { - if (dev->bpp) { - WRITE((mach->accel.ge_offset << 1) + ((dev->accel.dy) * (dev->pitch)) + (dev->accel.dx), dest_dat); - } else { - WRITE((mach->accel.ge_offset << 2) + ((dev->accel.dy) * (dev->pitch)) + (dev->accel.dx), dest_dat); - } + WRITE(mach->accel.dst_ge_offset + (dev->accel.dy * mach->accel.dst_pitch) + dev->accel.dx, dest_dat); } } } } if ((mono_src == 1) && !count) { + if (cpu_input) { + mach->force_busy = 0; + dev->force_busy = 0; + dev->force_busy2 = 0; + } + dev->fifo_idx = 0; dev->accel.cmd_back = 1; break; } else if ((mono_src != 1) && (dev->accel.sx >= mach->accel.width)) { + if (cpu_input) { + mach->force_busy = 0; + dev->force_busy = 0; + dev->force_busy2 = 0; + } + dev->fifo_idx = 0; dev->accel.cmd_back = 1; break; } @@ -554,10 +551,7 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 else cpu_dat >>= 8; - if (dev->bpp) - mach->accel.color_pattern_idx += 2; - else - mach->accel.color_pattern_idx++; + mach->accel.color_pattern_idx++; if (mach->accel.color_pattern_idx > mach->accel.patt_len) mach->accel.color_pattern_idx = 0; @@ -642,11 +636,7 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } break; case 3: - if (dev->bpp) { - READ((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), mix); - } else { - READ((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), mix); - } + READ(mach->accel.src_ge_offset + (dev->accel.cy * mach->accel.src_pitch) + dev->accel.cx, mix); mix = (mix & rd_mask) == rd_mask; break; @@ -658,12 +648,13 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 (dev->accel.dx <= clip_r) && (dev->accel.dy >= clip_t) && (dev->accel.dy <= clip_b)) { + dev->subsys_stat |= INT_GE_BSY; switch (mix ? frgd_sel : bkgd_sel) { case 0: - src_dat = dev->accel.bkgd_color; + src_dat = bkgd_color; break; case 1: - src_dat = dev->accel.frgd_color; + src_dat = frgd_color; break; case 2: src_dat = cpu_dat; @@ -672,20 +663,17 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 if (mach_pixel_read(mach)) src_dat = cpu_dat; else { - if (dev->bpp) { - READ((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), src_dat); - } else { - READ((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), src_dat); - } + READ(mach->accel.src_ge_offset + (dev->accel.cy * mach->accel.src_pitch) + dev->accel.cx, src_dat); if (mono_src == 3) { src_dat = (src_dat & rd_mask) == rd_mask; } } break; case 5: - src_dat = mach->accel.color_pattern[mach->accel.color_pattern_idx]; if (dev->bpp) - src_dat |= (mach->accel.color_pattern[mach->accel.color_pattern_idx + 1] << 8); + src_dat = mach->accel.color_pattern_hicol[mach->accel.color_pattern_idx]; + else + src_dat = mach->accel.color_pattern[mach->accel.color_pattern_idx]; break; default: @@ -693,22 +681,14 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } if (mach->accel.linedraw_opt & 0x02) { - if (dev->bpp) { - READ((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), poly_src); - } else { - READ((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), poly_src); - } + READ(mach->accel.src_ge_offset + (dev->accel.cy * mach->accel.src_pitch) + dev->accel.cx, poly_src); 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)) { - if (dev->bpp) { - READ((mach->accel.ge_offset << 1) + ((dev->accel.dy) * (dev->pitch)) + (dev->accel.dx), dest_dat); - } else { - READ((mach->accel.ge_offset << 2) + ((dev->accel.dy) * (dev->pitch)) + (dev->accel.dx), dest_dat); - } + READ(mach->accel.dst_ge_offset + (dev->accel.dy * mach->accel.dst_pitch) + dev->accel.dx, dest_dat); switch (compare_mode) { case 1: @@ -748,27 +728,31 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 if (mach->accel.dp_config & 0x10) { if (mach->accel.linedraw_opt & 0x04) { if (((mono_src != 1) && (dev->accel.sx < mach->accel.width)) || ((mono_src == 1) && count)) { - if (dev->bpp) { - WRITE((mach->accel.ge_offset << 1) + ((dev->accel.dy) * (dev->pitch)) + (dev->accel.dx), dest_dat); - } else { - WRITE((mach->accel.ge_offset << 2) + ((dev->accel.dy) * (dev->pitch)) + (dev->accel.dx), dest_dat); - } + WRITE(mach->accel.dst_ge_offset + (dev->accel.dy * mach->accel.dst_pitch) + dev->accel.dx, dest_dat); } } else { - if (dev->bpp) { - WRITE((mach->accel.ge_offset << 1) + ((dev->accel.dy) * (dev->pitch)) + (dev->accel.dx), dest_dat); - } else { - WRITE((mach->accel.ge_offset << 2) + ((dev->accel.dy) * (dev->pitch)) + (dev->accel.dx), dest_dat); - } + WRITE(mach->accel.dst_ge_offset + (dev->accel.dy * mach->accel.dst_pitch) + dev->accel.dx, dest_dat); } } } } if ((mono_src == 1) && !count) { + if (cpu_input) { + dev->force_busy = 0; + dev->force_busy2 = 0; + mach->force_busy = 0; + } + dev->fifo_idx = 0; dev->accel.cmd_back = 1; break; } else if ((mono_src != 1) && (dev->accel.sx >= mach->accel.width)) { + if (cpu_input) { + dev->force_busy = 0; + dev->force_busy2 = 0; + mach->force_busy = 0; + } + dev->fifo_idx = 0; dev->accel.cmd_back = 1; break; } @@ -778,10 +762,7 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 else cpu_dat >>= 8; - if (dev->bpp) - mach->accel.color_pattern_idx += 2; - else - mach->accel.color_pattern_idx++; + mach->accel.color_pattern_idx++; if (mach->accel.color_pattern_idx > mach->accel.patt_len) mach->accel.color_pattern_idx = 0; @@ -836,11 +817,14 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 dev->accel.dy |= ~0x5ff; /*Destination Width*/ + mach->accel.dx_first_row_start = dev->accel.cur_x; + if (dev->accel.cur_x >= 0x600) + mach->accel.dx_first_row_start |= ~0x5ff; + mach->accel.dx_start = mach->accel.dest_x_start; if (mach->accel.dest_x_start >= 0x600) mach->accel.dx_start |= ~0x5ff; - mach_log("DXStart=%d, CURX=%d.\n", mach->accel.dx_start, dev->accel.dx); mach->accel.dx_end = mach->accel.dest_x_end; if (mach->accel.dest_x_end >= 0x600) mach->accel.dx_end |= ~0x5ff; @@ -851,13 +835,9 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } 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; @@ -883,16 +863,30 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 mach->accel.stepy = 1; } - dev->accel.sy = 0; - if (mach->accel.dp_config & 0x02) - dev->accel.dest = (dev->accel.dy * dev->pitch); - else { - if (dev->bpp) - 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.dp_config == 0x4011) + mach->accel.height++; + + if (mach->accel.height == 1) { + if (mach->accel.dx_end > mach->accel.dx_first_row_start) { + mach->accel.width = (mach->accel.dx_end - mach->accel.dx_first_row_start); + mach->accel.stepx = 1; + } else if (mach->accel.dx_end < mach->accel.dx_first_row_start) { + mach->accel.width = (mach->accel.dx_first_row_start - mach->accel.dx_end); + mach->accel.stepx = -1; + } else { + mach->accel.stepx = 1; + mach->accel.width = 0; + } } + if (mach->accel.stepx == -1) { + if (dev->accel.dx > 0) + dev->accel.dx--; + } + + dev->accel.sy = 0; + dev->accel.dest = mach->accel.dst_ge_offset + (dev->accel.dy * mach->accel.dst_pitch); + mach->accel.src_stepx = 0; /*Source Width*/ dev->accel.cx = mach->accel.src_x; @@ -914,28 +908,31 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 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); + 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); + 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_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 (mach->accel.patt_data_idx < 16) + if (mach->accel.patt_data_idx < 0x10) mach->accel.color_pattern_idx = mach->accel.patt_idx; else mach->accel.color_pattern_idx = 0; - if (dev->bpp) - 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.src = mach->accel.src_ge_offset + (dev->accel.cy * mach->accel.src_pitch); if (mono_src == 1) { if (mach->accel.mono_pattern_enable || mach->accel.block_write_mono_pattern_enable) { @@ -948,7 +945,7 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 mono_dat1 |= (mach->accel.mono_pattern_normal[6] << 16); mono_dat1 |= (mach->accel.mono_pattern_normal[7] << 24); - mach_log("MonoData0=%x, MonoData1=%x.\n", mono_dat0, mono_dat1); + mach_log("MonoData0=%x, MonoData1=%x, enable mono pattern=%x, dpconfig=%04x.\n", mono_dat0, mono_dat1, mach->accel.mono_pattern_enable, mach->accel.dp_config); 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; @@ -958,12 +955,20 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } } - if ((mono_src == 2) || (bkgd_sel == 2) || (frgd_sel == 2) || mach_pixel_read(mach)) { + if (!dev->accel.cmd_back) { if (mach_pixel_write(mach)) { + mach_log("Non-Conforming BitBLT Write pixtrans.\n"); + dev->force_busy = 1; + dev->force_busy2 = 1; + mach->force_busy = 1; dev->data_available = 0; dev->data_available2 = 0; return; } else if (mach_pixel_read(mach)) { + mach_log("Non-Conforming BitBLT Read pixtrans.\n"); + dev->force_busy = 1; + dev->force_busy2 = 1; + mach->force_busy = 1; dev->data_available = 1; dev->data_available2 = 1; return; @@ -982,13 +987,25 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 if (mach->accel.dy_end == mach->accel.dy_start) { mach_log("No DEST.\n"); + if (cpu_input) { + dev->force_busy = 0; + dev->force_busy2 = 0; + mach->force_busy = 0; + } + dev->fifo_idx = 0; dev->accel.cmd_back = 1; return; } if ((mono_src == 3) || (bkgd_sel == 3) || (frgd_sel == 3)) { if (mach->accel.sx_end == mach->accel.sx_start) { + if (cpu_input) { + dev->force_busy = 0; + dev->force_busy2 = 0; + mach->force_busy = 0; + } mach_log("No SRC.\n"); + dev->fifo_idx = 0; dev->accel.cmd_back = 1; return; } @@ -996,9 +1013,14 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 if (cpu_input) { if (mach->accel.dp_config == 0x3251) { - mach_log("DPCONFIG 3251: monosrc=%d, frgdsel=%d, bkgdsel=%d, pitch=%d.\n", mono_src, frgd_sel, bkgd_sel, dev->pitch); + mach_log("DPCONFIG 3251: monosrc=%d, frgdsel=%d, bkgdsel=%d, pitch=%d.\n", + mono_src, frgd_sel, bkgd_sel, dev->pitch); if (dev->accel.sy == mach->accel.height) { mach_log("No Blit on DPCONFIG=3251.\n"); + dev->force_busy = 0; + dev->force_busy2 = 0; + mach->force_busy = 0; + dev->fifo_idx = 0; dev->accel.cmd_back = 1; return; } @@ -1027,7 +1049,7 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } break; case 2: - if (mach->accel.dp_config & 0x1000) { + if ((mach->accel.dp_config & 0x1000) || (mach->accel.dp_config & 0x04)) { mix = mix_dat >> 0x1f; mix_dat <<= 1; } else { @@ -1054,6 +1076,7 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 (dev->accel.dx <= clip_r) && (dev->accel.dy >= clip_t) && (dev->accel.dy <= clip_b)) { + dev->subsys_stat |= INT_GE_BSY; if (mach->accel.dp_config & 0x02) { READ(dev->accel.src + dev->accel.cx, poly_src); poly_src = ((poly_src & rd_mask) == rd_mask); @@ -1064,10 +1087,10 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 if (mach->accel.poly_fill || !(mach->accel.dp_config & 0x02)) { switch (mix ? frgd_sel : bkgd_sel) { case 0: - src_dat = dev->accel.bkgd_color; + src_dat = bkgd_color; break; case 1: - src_dat = dev->accel.frgd_color; + src_dat = frgd_color; break; case 2: src_dat = cpu_dat; @@ -1082,9 +1105,10 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } break; case 5: - src_dat = mach->accel.color_pattern[mach->accel.color_pattern_idx]; if (dev->bpp) - src_dat |= (mach->accel.color_pattern[mach->accel.color_pattern_idx + 1] << 8); + src_dat = mach->accel.color_pattern_hicol[mach->accel.color_pattern_idx]; + else + src_dat = mach->accel.color_pattern[mach->accel.color_pattern_idx]; break; default: @@ -1093,7 +1117,7 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 if ((dev->accel_bpp == 24) && (mono_src == 1) && (frgd_sel == 5) && !mach->accel.mono_pattern_enable) { if (dev->accel.sy & 1) { - READ(dev->accel.dest + dev->accel.dx - dev->pitch, dest_dat); + READ(dev->accel.dest + dev->accel.dx - mach->accel.dst_pitch, dest_dat); } else { READ(dev->accel.dest + dev->accel.dx, dest_dat); } @@ -1139,7 +1163,7 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 if (mach->accel.dp_config & 0x10) { if ((dev->accel_bpp == 24) && (mono_src == 1) && (frgd_sel == 5) && !mach->accel.mono_pattern_enable) { if (dev->accel.sy & 1) { - WRITE(dev->accel.dest + dev->accel.dx - dev->pitch, dest_dat); + WRITE(dev->accel.dest + dev->accel.dx - mach->accel.dst_pitch, dest_dat); } else { WRITE(dev->accel.dest + dev->accel.dx, dest_dat); } @@ -1155,31 +1179,28 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 else cpu_dat >>= 8; - if (mach->accel.dp_config == 0x2071 || (mach->accel.dp_config == 0x2011)) - mach_log("FontBlit: SX=%d, C(%d,%d), SRCWidth=%d, frgdmix=%d, bkgdmix=%d, rdmask=%04x, D(%d,%d), geoffset=%x, addr=%08x,.\n", mach->accel.sx, dev->accel.cx, dev->accel.cy, mach->accel.src_width, dev->accel.frgd_mix & 0x1f, dev->accel.bkgd_mix & 0x1f, rd_mask, dev->accel.dx, dev->accel.dy, dev->accel.ge_offset, (dev->accel.src + dev->accel.cx) & dev->vram_mask); + if (mach->accel.dp_config == 0x2071) + mach_log("FontBlit: SX=%d, C(%d,%d), SRCWidth=%d, frgdmix=%d, bkgdmix=%d, rdmask=%04x, D(%d,%d), geoffset=%x, addr=%08x, 8bppdata=%02x, 16bppdata=%04x, vgabase=%06x.\n", + mach->accel.sx, dev->accel.cx, dev->accel.cy, mach->accel.src_width, dev->accel.frgd_mix & 0x1f, + dev->accel.bkgd_mix & 0x1f, rd_mask, dev->accel.dx, dev->accel.dy, dev->accel.ge_offset, + (dev->accel.src + dev->accel.cx) & dev->vram_mask, dev->vram[(dev->accel.src + dev->accel.cx) & dev->vram_mask], vram_w[(dev->accel.src + dev->accel.cx) & (dev->vram_mask >> 1)], svga->mapping.base); if ((mono_src == 3) || (frgd_sel == 3) || (bkgd_sel == 3) || (mach->accel.dp_config & 0x02)) { 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 < 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 (dev->bpp) - 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.src = mach->accel.src_ge_offset + (dev->accel.cy * mach->accel.src_pitch); } } - if (dev->bpp) - mach->accel.color_pattern_idx += 2; - else - mach->accel.color_pattern_idx++; + mach->accel.color_pattern_idx++; if ((mono_src == 1) && !mach->accel.mono_pattern_enable && !mach->accel.block_write_mono_pattern_enable && (frgd_sel == 5) && (dev->accel_bpp == 24)) { if (mach->accel.color_pattern_idx > 2) @@ -1193,7 +1214,7 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 dev->accel.sx++; if ((dev->accel.sx >= mach->accel.width) || (dev->accel.dx >= 0x600)) { dev->accel.sx = 0; - if (mach->accel.stepx < 0) + if (mach->accel.stepx == -1) dev->accel.dx += mach->accel.width; else dev->accel.dx -= mach->accel.width; @@ -1202,16 +1223,15 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 dev->accel.sy++; mach->accel.poly_fill = 0; - if (mach->accel.dp_config & 0x02) - dev->accel.dest = (dev->accel.dy * dev->pitch); - else { - if (dev->bpp) - 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); - } + dev->accel.dest = mach->accel.dst_ge_offset + (dev->accel.dy * mach->accel.dst_pitch); if (dev->accel.sy >= mach->accel.height) { + if (cpu_input) { + dev->force_busy = 0; + dev->force_busy2 = 0; + mach->force_busy = 0; + } + dev->fifo_idx = 0; dev->accel.cmd_back = 1; if ((mono_src == 2) || (mono_src == 3) || (frgd_sel == 3) || (bkgd_sel == 3) || (mach->accel.dp_config & 0x02)) return; @@ -1248,16 +1268,24 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 dev->accel.sx = 0; - mach_log("Linedraw: c(%d,%d), d(%d,%d), cend(%d,%d), bounds: l=%d, r=%d, t=%d, b=%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, mach->accel.bleft, mach->accel.bright, mach->accel.btop, mach->accel.bbottom); + mach_log("Linedraw: c(%d,%d), d(%d,%d), cend(%d,%d), bounds: l=%d, r=%d, t=%d, b=%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, mach->accel.bleft, mach->accel.bright, mach->accel.btop, mach->accel.bbottom); - if ((mono_src == 2) || (bkgd_sel == 2) || (frgd_sel == 2) || mach_pixel_read(mach)) { + if (!dev->accel.cmd_back) { if (mach_pixel_write(mach)) { - mach_log("Write PIXTRANS.\n"); + mach_log("Direct Linedraw Write pixtrans.\n"); + dev->force_busy = 1; + dev->force_busy2 = 1; + mach->force_busy = 1; dev->data_available = 0; dev->data_available2 = 0; return; } else if (mach_pixel_read(mach)) { - mach_log("Read PIXTRANS.\n"); + mach_log("Direct Linedraw Read pixtrans.\n"); + dev->force_busy = 1; + dev->force_busy2 = 1; + mach->force_busy = 1; dev->data_available = 1; dev->data_available2 = 1; return; @@ -1290,13 +1318,14 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 (dev->accel.cx <= clip_r) && (dev->accel.cy >= clip_t) && (dev->accel.cy <= clip_b)) { + dev->subsys_stat |= INT_GE_BSY; mach->accel.clip_overrun = 0; switch (mix ? frgd_sel : bkgd_sel) { case 0: - src_dat = dev->accel.bkgd_color; + src_dat = bkgd_color; break; case 1: - src_dat = dev->accel.frgd_color; + src_dat = frgd_color; break; case 2: src_dat = cpu_dat; @@ -1308,20 +1337,17 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 src_dat = 0; break; case 5: - src_dat = mach->accel.color_pattern[mach->accel.color_pattern_idx]; if (dev->bpp) - src_dat |= (mach->accel.color_pattern[mach->accel.color_pattern_idx + 1] << 8); + src_dat = mach->accel.color_pattern_hicol[mach->accel.color_pattern_idx]; + else + src_dat = mach->accel.color_pattern[mach->accel.color_pattern_idx]; break; default: break; } - if (dev->bpp) { - READ((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat); - } else { - READ((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat); - } + READ(mach->accel.dst_ge_offset + (dev->accel.cy * mach->accel.dst_pitch) + dev->accel.cx, dest_dat); switch (compare_mode) { case 1: @@ -1358,16 +1384,18 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } } if ((mach->accel.dp_config & 0x10) && (cmd_type == 3)) { - if (dev->bpp) { - WRITE((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat); - } else { - WRITE((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat); - } + WRITE(mach->accel.dst_ge_offset + (dev->accel.cy * mach->accel.dst_pitch) + dev->accel.cx, dest_dat); } } else mach->accel.clip_overrun = ((mach->accel.clip_overrun + 1) & 0x0f); if (!count) { + if (cpu_input) { + dev->force_busy = 0; + dev->force_busy2 = 0; + mach->force_busy = 0; + } + dev->fifo_idx = 0; dev->accel.cmd_back = 1; break; } @@ -1377,10 +1405,7 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 else cpu_dat >>= 8; - if (dev->bpp) - mach->accel.color_pattern_idx += 2; - else - mach->accel.color_pattern_idx++; + mach->accel.color_pattern_idx++; if (mach->accel.color_pattern_idx > mach->accel.patt_len) mach->accel.color_pattern_idx = 0; @@ -1423,23 +1448,20 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 (dev->accel.cx <= clip_r) && (dev->accel.cy >= clip_t) && (dev->accel.cy <= clip_b)) { + dev->subsys_stat |= INT_GE_BSY; mach->accel.clip_overrun = 0; if (mach->accel.linedraw_opt & 0x02) { - if (dev->bpp) { - READ((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), poly_src); - } else { - READ((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), poly_src); - } + READ(mach->accel.src_ge_offset + (dev->accel.cy * mach->accel.src_pitch) + dev->accel.cx, poly_src); if (poly_src) mach->accel.poly_fill ^= 1; } switch (mix ? frgd_sel : bkgd_sel) { case 0: - src_dat = dev->accel.bkgd_color; + src_dat = bkgd_color; break; case 1: - src_dat = dev->accel.frgd_color; + src_dat = frgd_color; break; case 2: src_dat = cpu_dat; @@ -1452,24 +1474,17 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } break; case 5: - src_dat = mach->accel.color_pattern[mach->accel.color_pattern_idx]; if (dev->bpp) - src_dat |= (mach->accel.color_pattern[mach->accel.color_pattern_idx + 1] << 8); + src_dat = mach->accel.color_pattern_hicol[mach->accel.color_pattern_idx]; + else + src_dat = mach->accel.color_pattern[mach->accel.color_pattern_idx]; break; default: break; } - if (mach->accel.linedraw_opt & 0x02) { - if (dev->bpp) { - READ((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat); - } else { - READ((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat); - } - } else { - READ(((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat); - } + READ(mach->accel.dst_ge_offset + (dev->accel.cy * mach->accel.dst_pitch) + dev->accel.cx, dest_dat); switch (compare_mode) { case 1: @@ -1511,32 +1526,22 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 if ((mach->accel.dp_config & 0x10) && (cmd_type == 3)) { if (mach->accel.linedraw_opt & 0x04) { if (dev->accel.sx < mach->accel.width) { - if (mach->accel.linedraw_opt & 0x02) { - if (dev->bpp) { - WRITE((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat); - } else { - WRITE((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat); - } - } else { - WRITE(((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat); - } + WRITE(mach->accel.dst_ge_offset + (dev->accel.cy * mach->accel.dst_pitch) + dev->accel.cx, dest_dat); } } else { - if (mach->accel.linedraw_opt & 0x02) { - if (dev->bpp) { - WRITE((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat); - } else { - WRITE((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat); - } - } else { - WRITE(((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat); - } + WRITE(mach->accel.dst_ge_offset + (dev->accel.cy * mach->accel.dst_pitch) + dev->accel.cx, dest_dat); } } } else mach->accel.clip_overrun = ((mach->accel.clip_overrun + 1) & 0x0f); if (dev->accel.sx >= mach->accel.width) { + if (cpu_input) { + dev->force_busy = 0; + dev->force_busy2 = 0; + mach->force_busy = 0; + } + dev->fifo_idx = 0; dev->accel.cmd_back = 1; break; } @@ -1546,10 +1551,7 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 else cpu_dat >>= 8; - if (dev->bpp) - mach->accel.color_pattern_idx += 2; - else - mach->accel.color_pattern_idx++; + mach->accel.color_pattern_idx++; if (mach->accel.color_pattern_idx > mach->accel.patt_len) mach->accel.color_pattern_idx = 0; @@ -1581,13 +1583,14 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 (dev->accel.cx <= clip_r) && (dev->accel.cy >= clip_t) && (dev->accel.cy <= clip_b)) { + dev->subsys_stat |= INT_GE_BSY; mach->accel.clip_overrun = 0; switch (mix ? frgd_sel : bkgd_sel) { case 0: - src_dat = dev->accel.bkgd_color; + src_dat = bkgd_color; break; case 1: - src_dat = dev->accel.frgd_color; + src_dat = frgd_color; break; case 2: src_dat = cpu_dat; @@ -1600,20 +1603,18 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } break; case 5: - src_dat = mach->accel.color_pattern[mach->accel.color_pattern_idx]; if (dev->bpp) - src_dat |= (mach->accel.color_pattern[mach->accel.color_pattern_idx + 1] << 8); + src_dat = mach->accel.color_pattern_hicol[mach->accel.color_pattern_idx]; + else + src_dat = mach->accel.color_pattern[mach->accel.color_pattern_idx]; break; default: break; } - if (dev->bpp) { - READ((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat); - } else { - READ((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat); - } + READ(mach->accel.dst_ge_offset + (dev->accel.cy * mach->accel.dst_pitch) + dev->accel.cx, dest_dat); + switch (compare_mode) { case 1: compare = 1; @@ -1650,16 +1651,18 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } if ((mach->accel.dp_config & 0x10) && (cmd_type == 3)) { - if (dev->bpp) { - WRITE((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat); - } else { - WRITE((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat); - } + WRITE(mach->accel.dst_ge_offset + (dev->accel.cy * mach->accel.dst_pitch) + dev->accel.cx, dest_dat); } } else mach->accel.clip_overrun = ((mach->accel.clip_overrun + 1) & 0x0f); if (!count) { + if (cpu_input) { + dev->force_busy = 0; + dev->force_busy2 = 0; + mach->force_busy = 0; + } + dev->fifo_idx = 0; dev->accel.cmd_back = 1; break; } @@ -1669,10 +1672,7 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 else cpu_dat >>= 8; - if (dev->bpp) - mach->accel.color_pattern_idx += 2; - else - mach->accel.color_pattern_idx++; + mach->accel.color_pattern_idx++; if (mach->accel.color_pattern_idx > mach->accel.patt_len) mach->accel.color_pattern_idx = 0; @@ -1715,13 +1715,14 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 (dev->accel.cx <= clip_r) && (dev->accel.cy >= clip_t) && (dev->accel.cy <= clip_b)) { + dev->subsys_stat |= INT_GE_BSY; mach->accel.clip_overrun = 0; switch (mix ? frgd_sel : bkgd_sel) { case 0: - src_dat = dev->accel.bkgd_color; + src_dat = bkgd_color; break; case 1: - src_dat = dev->accel.frgd_color; + src_dat = frgd_color; break; case 2: src_dat = cpu_dat; @@ -1734,24 +1735,17 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } break; case 5: - src_dat = mach->accel.color_pattern[mach->accel.color_pattern_idx]; if (dev->bpp) - src_dat |= (mach->accel.color_pattern[mach->accel.color_pattern_idx + 1] << 8); + src_dat = mach->accel.color_pattern_hicol[mach->accel.color_pattern_idx]; + else + src_dat = mach->accel.color_pattern[mach->accel.color_pattern_idx]; break; default: break; } - if (mach->accel.linedraw_opt & 0x02) { - if (dev->bpp) { - READ((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat); - } else { - READ((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat); - } - } else { - READ(((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat); - } + READ(mach->accel.dst_ge_offset + (dev->accel.cy * mach->accel.dst_pitch) + dev->accel.cx, dest_dat); switch (compare_mode) { case 1: @@ -1791,32 +1785,22 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 if ((mach->accel.dp_config & 0x10) && (cmd_type == 3)) { if (mach->accel.linedraw_opt & 0x04) { if (dev->accel.sx < mach->accel.width) { - if (mach->accel.linedraw_opt & 0x02) { - if (dev->bpp) { - WRITE((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat); - } else { - WRITE((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat); - } - } else { - WRITE((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); - } + WRITE(mach->accel.dst_ge_offset + (dev->accel.cy * mach->accel.dst_pitch) + dev->accel.cx, dest_dat); } } else { - if (mach->accel.linedraw_opt & 0x02) { - if (dev->bpp) { - WRITE((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat); - } else { - WRITE((mach->accel.ge_offset << 2) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat); - } - } else { - WRITE(((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), dest_dat); - } + WRITE(mach->accel.dst_ge_offset + (dev->accel.cy * mach->accel.dst_pitch) + dev->accel.cx, dest_dat); } } } else mach->accel.clip_overrun = ((mach->accel.clip_overrun + 1) & 0x0f); if (dev->accel.sx >= mach->accel.width) { + if (cpu_input) { + dev->force_busy = 0; + dev->force_busy2 = 0; + mach->force_busy = 0; + } + dev->fifo_idx = 0; dev->accel.cmd_back = 1; break; } @@ -1826,10 +1810,7 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 else cpu_dat >>= 8; - if (dev->bpp) - mach->accel.color_pattern_idx += 2; - else - mach->accel.color_pattern_idx++; + mach->accel.color_pattern_idx++; if (mach->accel.color_pattern_idx > mach->accel.patt_len) mach->accel.color_pattern_idx = 0; @@ -1848,8 +1829,9 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 mach->accel.poly_fill = 0; 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]; + dev->accel.cur_x = dev->accel.cx; + dev->accel.cur_y = dev->accel.cy; + mach_log("Done: %i, %i\n", dev->accel.cur_x, dev->accel.cur_y); break; case 5: /*Horizontal Raster Draw from scan_to_x register (0xcaee)*/ @@ -1895,18 +1877,18 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 if (mach->accel.dest_y_end >= 0x600) mach->accel.dy_end |= ~0x5ff; - if (mach->accel.dy_end > mach->accel.dy_start) + if (mach->accel.dy_end > mach->accel.dy_start) { + dev->accel.sy = (mach->accel.dy_end - mach->accel.dy_start); mach->accel.stepy = 1; - else if (mach->accel.dy_end < mach->accel.dy_start) + } else if (mach->accel.dy_end < mach->accel.dy_start) { + dev->accel.sy = (mach->accel.dy_start - mach->accel.dy_end); mach->accel.stepy = -1; - else + } else { mach->accel.stepy = 0; + dev->accel.sy = 0; + } - if (dev->bpp) - 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)); - + dev->accel.dest = mach->accel.dst_ge_offset + (dev->accel.dy * mach->accel.dst_pitch); mach->accel.src_stepx = 0; /*Source Width*/ @@ -1939,19 +1921,25 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } mach->accel.sx = 0; - if (dev->bpp) - 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.src = mach->accel.src_ge_offset + (dev->accel.cy * mach->accel.src_pitch); - mach_log("ScanToX=%04x, MonoSRC=%d, FrgdSel=%d, BkgdSel=%d, Pitch=%d, C(%d,%d), SRCWidth=%d, WH(%d,%d), colorpattidx=%d, pattlen=%d.\n", mach->accel.dp_config, mono_src, frgd_sel, bkgd_sel, dev->ext_pitch, dev->accel.cx, dev->accel.cy, mach->accel.src_width, mach->accel.width, mach->accel.height, mach->accel.color_pattern_idx, mach->accel.patt_len); + mach_log("ScanToX: Parameters=%04x: xbit=%d, ybit=%d, widthbit=%d, DX=%d, DY=%d, CX=%d, CY=%d, dstwidth=%d, srcwidth=%d, height=%d, frmix=%02x, colpatidx=%d, srcpitch=%d, dstpitch=%d, scantox=%d.\n", + mach->accel.dp_config, dev->accel.dx & 1, dev->accel.dy & 1, mach->accel.width & 1, dev->accel.dx, dev->accel.dy, dev->accel.cx, dev->accel.cy, mach->accel.width, mach->accel.src_width, dev->accel.sy, dev->accel.frgd_mix & 0x1f, mach->accel.color_pattern_idx, mach->accel.src_pitch, mach->accel.dst_pitch, mach->accel.scan_to_x); - if ((mono_src == 2) || (bkgd_sel == 2) || (frgd_sel == 2) || mach_pixel_read(mach)) { + if (!dev->accel.cmd_back) { if (mach_pixel_write(mach)) { + mach_log("Scan To X Write pixtrans.\n"); + dev->force_busy = 1; + dev->force_busy2 = 1; + mach->force_busy = 1; dev->data_available = 0; dev->data_available2 = 0; return; } else if (mach_pixel_read(mach)) { + mach_log("Scan To X Read pixtrans.\n"); + dev->force_busy = 1; + dev->force_busy2 = 1; + mach->force_busy = 1; dev->data_available = 1; dev->data_available2 = 1; return; @@ -1959,6 +1947,110 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } } + if ((dev->accel_bpp == 24) && (mach->accel.dp_config == 0x6211)) { + int64_t cx; + int64_t cy; + + cx = mach->accel.src_x_scan; + cy = mach->accel.src_y_scan; + + if (mach->accel.src_stepx == -1) { + if (cx > 0) + cx--; + } + + dev->accel.src = mach->accel.src_ge_offset + (cy * mach->accel.src_pitch); + + while (1) { + mix = 1; + + if ((dev->accel.dx >= clip_l) && + (dev->accel.dx <= clip_r) && + (dev->accel.dy >= clip_t) && + (dev->accel.dy <= clip_b)) { + dev->subsys_stat |= INT_GE_BSY; + READ(dev->accel.src + cx, src_dat); + READ(dev->accel.dest + dev->accel.dx, dest_dat); + + 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) { + old_dest_dat = dest_dat; + MIX(mix, dest_dat, src_dat); + dest_dat = (dest_dat & wrt_mask) | (old_dest_dat & ~wrt_mask); + } + + WRITE(dev->accel.dest + dev->accel.dx, dest_dat); + } + + cx += mach->accel.src_stepx; + mach->accel.sx++; + if (mach->accel.sx >= mach->accel.src_width) { + mach->accel.sx = 0; + cx = mach->accel.src_x_scan; + if (mach->accel.src_stepx == -1) { + if (cx > 0) + cx--; + } + + cy += (mach->accel.src_y_dir ? 1 : -1); + dev->accel.src = mach->accel.src_ge_offset + (cy * mach->accel.src_pitch); + } + + dev->accel.dx += mach->accel.stepx; + dev->accel.sx++; + if (dev->accel.sx >= mach->accel.width) { + dev->accel.sx = 0; + dev->accel.dy += mach->accel.stepy; + dev->accel.dest = mach->accel.dst_ge_offset + (dev->accel.dy * mach->accel.dst_pitch); + + if (mach->accel.line_idx == 2) { + mach->accel.line_array[0] = dev->accel.dx; + mach->accel.line_array[4] = dev->accel.dx; + } + if (dev->accel.sy >= 0) + dev->accel.sy--; + + dev->fifo_idx = 0; + dev->force_busy = 0; + dev->force_busy2 = 0; + mach->force_busy = 0; + dev->accel.cmd_back = 1; + dev->accel.cur_x = dev->accel.dx; + dev->accel.cur_y = dev->accel.dy; + mach->accel.src_x_scan = cx; + mach->accel.src_y_scan = cy; + return; + } + } + return; + } + if (mono_src == 1) { count = mach->accel.width; mix_dat = mach->accel.mono_pattern_normal[0]; @@ -1996,7 +2088,7 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } break; case 3: - READ(dev->accel.src + (dev->accel.cx), mix); + READ(dev->accel.src + dev->accel.cx, mix); mix = (mix & rd_mask) == rd_mask; break; @@ -2008,12 +2100,13 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 (dev->accel.dx <= clip_r) && (dev->accel.dy >= clip_t) && (dev->accel.dy <= clip_b)) { + dev->subsys_stat |= INT_GE_BSY; switch (mix ? frgd_sel : bkgd_sel) { case 0: - src_dat = dev->accel.bkgd_color; + src_dat = bkgd_color; break; case 1: - src_dat = dev->accel.frgd_color; + src_dat = frgd_color; break; case 2: src_dat = cpu_dat; @@ -2028,9 +2121,10 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } break; case 5: - src_dat = mach->accel.color_pattern[mach->accel.color_pattern_idx]; if (dev->bpp) - src_dat |= (mach->accel.color_pattern[mach->accel.color_pattern_idx + 1] << 8); + src_dat = mach->accel.color_pattern_hicol[mach->accel.color_pattern_idx]; + else + src_dat = mach->accel.color_pattern[mach->accel.color_pattern_idx]; break; default: @@ -2088,21 +2182,16 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 mach->accel.sx++; if (mach->accel.sx >= mach->accel.src_width) { mach->accel.sx = 0; - if (mach->accel.src_stepx == -1) { + 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 (dev->bpp) - 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.cx -= mach->accel.src_width; + + dev->accel.cy += (mach->accel.src_y_dir ? 1 : -1); + dev->accel.src = mach->accel.src_ge_offset + (dev->accel.cy * mach->accel.src_pitch); } - if (dev->bpp) - mach->accel.color_pattern_idx += 2; - else - mach->accel.color_pattern_idx++; + mach->accel.color_pattern_idx++; if (mach->accel.color_pattern_idx > mach->accel.patt_len) mach->accel.color_pattern_idx = 0; @@ -2112,14 +2201,19 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 if (dev->accel.sx >= mach->accel.width) { dev->accel.sx = 0; dev->accel.dy += mach->accel.stepy; - if (dev->bpp) - 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); + dev->accel.dest = mach->accel.dst_ge_offset + (dev->accel.dy * mach->accel.dst_pitch); + if (mach->accel.line_idx == 2) { mach->accel.line_array[0] = dev->accel.dx; mach->accel.line_array[4] = dev->accel.dx; } + if (dev->accel.sy >= 0) + dev->accel.sy--; + + dev->fifo_idx = 0; + dev->force_busy = 0; + dev->force_busy2 = 0; + mach->force_busy = 0; dev->accel.cmd_back = 1; return; } @@ -2166,7 +2260,7 @@ mach_accel_out_pixtrans(svga_t *svga, mach_t *mach, ibm8514_t *dev, uint16_t val case 0x200: /*16-bit size*/ if (mono_src == 2) { if ((frgd_sel != 2) && (bkgd_sel != 2)) { - if ((mach->accel.dp_config & 0x1000) && !swap) { + if (((mach->accel.dp_config & 0x1000) && !swap) || (!(mach->accel.dp_config & 0x1000) && swap)) { mach_log("16-bit bus size swap.\n"); val = (val >> 8) | (val << 8); } @@ -2195,11 +2289,12 @@ mach_out(uint16_t addr, uint8_t val, void *priv) if (((addr & 0xFFF0) == 0x3D0 || (addr & 0xFFF0) == 0x3B0) && !(svga->miscout & 1)) addr ^= 0x60; - if (((dev->disp_cntl & 0x60) == 0x20) && ((dev->local & 0xff) >= 0x02)) { - if ((addr >= 0x3c6) && (addr <= 0x3c9)) { - mach_log("VGA DAC write regs=%03x, on=%d, display control=%02x, on1=%x, clocksel=%02x.\n", addr, dev->on, dev->disp_cntl & 0x60, dev->accel.advfunc_cntl & 0x01, mach->accel.clock_sel & 0x01); - } else if ((addr >= 0x2ea) && (addr <= 0x2ed)) - mach_log("8514/A DAC write regs=%03x, on=%d, display control=%02x, on1=%x, clocksel=%02x.\n", addr, dev->on, dev->disp_cntl & 0x60, dev->accel.advfunc_cntl & 0x01, mach->accel.clock_sel & 0x01); + if ((addr >= 0x3c6) && (addr <= 0x3c9)) { + mach_log("VGA DAC write regs=%03x, on=%d, display control=%02x, on1=%x, clocksel=%02x.\n", + addr, dev->on, dev->disp_cntl & 0x60, dev->accel.advfunc_cntl & 0x01, mach->accel.clock_sel & 0x01); + } else if ((addr >= 0x2ea) && (addr <= 0x2ed)) { + mach_log("8514/A DAC write regs=%03x, on=%d, display control=%02x, on1=%x, clocksel=%02x.\n", + addr, dev->on, dev->disp_cntl & 0x60, dev->accel.advfunc_cntl & 0x01, mach->accel.clock_sel & 0x01); } switch (addr) { @@ -2209,7 +2304,7 @@ mach_out(uint16_t addr, uint8_t val, void *priv) case 0x1cf: old = mach->regs[mach->index]; mach->regs[mach->index] = val; - mach_log("ATI VGA write reg=%02x, val=%02x.\n", mach->index, val); + mach_log("ATI VGA write reg=%02x, val=%02x, old=%02x.\n", mach->index, val, old); switch (mach->index) { case 0xa3: if ((old ^ val) & 0x10) { @@ -2224,7 +2319,7 @@ mach_out(uint16_t addr, uint8_t val, void *priv) } break; case 0xad: - if ((dev->local & 0xff) >= 0x02) { + if (ATI_MACH32) { if ((old ^ val) & 0x0c) { mach_log("ATI AD bits 2-3.\n"); svga_recalctimings(svga); @@ -2233,8 +2328,25 @@ mach_out(uint16_t addr, uint8_t val, void *priv) break; case 0xb0: if ((old ^ val) & 0x60) { - mach_log("ATI B0 bits 5-6: old=%02x, val=%02x.\n", old & 0x60, val & 0x60); - svga_recalctimings(svga); + if (dev->_8514crt) { + if (!(mach->accel.clock_sel & 0x01)) { + if ((val & 0x20) && !(old & 0x20)) { + dev->on = 1; + dev->vendor_mode = !!(ATI_MACH32); + mach_set_resolution(mach, svga); + mach32_updatemapping(mach, svga); + } else if (!(val & 0x20) && (old & 0x20)) { + dev->on = 0; + dev->vendor_mode = 0; + mach_set_resolution(mach, svga); + mach32_updatemapping(mach, svga); + } + } + } else + svga_recalctimings(svga); + + mach_log("ATI B0 bits 5-6: old=%02x, val=%02x, on=%d, bpp=%d, hires=%x, vgahires=%02x, base=%05x.\n", + old & 0x60, val & 0x60, dev->on, dev->accel_bpp, dev->accel.advfunc_cntl & 0x04, svga->gdcreg[5] & 0x60, svga->mapping.base); } break; case 0xae: @@ -2244,20 +2356,18 @@ mach_out(uint16_t addr, uint8_t val, void *priv) 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 & 0xff) >= 0x02) { + if (ATI_MACH32) { mach->bank_r |= ((mach->regs[0xae] & 0x0c) << 2); mach->bank_w |= ((mach->regs[0xae] & 3) << 4); } - if (dev->on) - mach_log("Separate B2Bank = %02x, AEbank = %02x.\n", mach->regs[0xb2], mach->regs[0xae]); + 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 & 0xff) >= 0x02) + if (ATI_MACH32) mach->bank_w |= ((mach->regs[0xae] & 3) << 4); mach->bank_r = mach->bank_w; - if (dev->on) - mach_log("Single B2Bank = %02x, AEbank = %02x.\n", mach->regs[0xb2], mach->regs[0xae]); + 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; @@ -2283,7 +2393,7 @@ mach_out(uint16_t addr, uint8_t val, void *priv) } break; case 0xb8: - if ((dev->local & 0xff) >= 0x02) { + if (ATI_MACH32) { if ((old ^ val) & 0x40) { mach_log("ATI B8 bit 6.\n"); svga_recalctimings(svga); @@ -2311,18 +2421,12 @@ mach_out(uint16_t addr, uint8_t val, void *priv) case 0x2ed: rs2 = !!(mach->accel.ext_ge_config & 0x1000); rs3 = !!(mach->accel.ext_ge_config & 0x2000); - if ((dev->local & 0xff) >= 0x02) { - if (mach->regs[0xb0] & 0x20) { /*ATI extended 8514/A mode.*/ - mach_log("Extended 8514/A mode.\n"); - dev->vendor_mode = 1; - dev->on |= 0x01; - svga_recalctimings(svga); - mach32_updatemapping(mach, svga); - } - if (mach->pci_bus && !mach->ramdac_type) - ati68860_ramdac_out((addr & 0x03) | (rs2 << 2) | (rs3 << 3), val, svga->ramdac, svga); + mach_log("8514/A Extended mode=%02x.\n", mach->regs[0xb0] & 0x20); + if (ATI_MACH32) { + if (mach->pci_bus && (mach->ramdac_type == ATI_68860)) + ati68860_ramdac_out((addr & 0x03) | (rs2 << 2) | (rs3 << 3), val, 1, svga->ramdac, svga); else - ati68875_ramdac_out(addr, rs2, rs3, val, svga->ramdac, svga); + ati68875_ramdac_out(addr, rs2, rs3, val, 1, svga->ramdac, svga); } else svga_out(addr, val, svga); return; @@ -2333,18 +2437,12 @@ mach_out(uint16_t addr, uint8_t val, void *priv) case 0x3C9: rs2 = !!(mach->regs[0xa0] & 0x20); rs3 = !!(mach->regs[0xa0] & 0x40); - if ((dev->local & 0xff) >= 0x02) { - if (svga->attrregs[0x10] & 0x40) { - mach_log("VGA mode.\n"); - dev->vendor_mode = 0; - dev->on &= ~0x01; - svga_recalctimings(svga); - mach32_updatemapping(mach, svga); - } - if (mach->pci_bus && !mach->ramdac_type) - ati68860_ramdac_out((addr & 0x03) | (rs2 << 2) | (rs3 << 3), val, svga->ramdac, svga); + mach_log("VGA Extended mode=%02x.\n", mach->regs[0xb0] & 0x20); + if (ATI_MACH32) { + if (mach->pci_bus && (mach->ramdac_type == ATI_68860)) + ati68860_ramdac_out((addr & 0x03) | (rs2 << 2) | (rs3 << 3), val, 0, svga->ramdac, svga); else - ati68875_ramdac_out(addr, rs2, rs3, val, svga->ramdac, svga); + ati68875_ramdac_out(addr, rs2, rs3, val, 0, svga->ramdac, svga); } else svga_out(addr, val, svga); return; @@ -2378,9 +2476,9 @@ mach_out(uint16_t addr, uint8_t val, void *priv) 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); + svga->memaddr_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5); } else { - svga->fullchange = changeframecount; + svga->fullchange = svga->monitor->mon_changeframecount; svga_recalctimings(svga); } } @@ -2427,10 +2525,16 @@ mach_in(uint16_t addr, void *priv) case 0xa9: temp = svga->vc & 0xff; break; + case 0xaa: + if (ATI_GRAPHICS_ULTRA) + temp = 0x06; + else + temp = 0x00; + break; case 0xb0: temp = mach->regs[0xb0] | 0x80; temp &= ~0x18; - if ((dev->local & 0xff) >= 0x02) { /*Mach32 VGA 1MB memory*/ + if (ATI_MACH32) { /*Mach32 VGA 1MB memory*/ temp |= 0x08; } else { /*ATI 28800 VGA 512kB memory*/ temp |= 0x10; @@ -2450,6 +2554,7 @@ mach_in(uint16_t addr, void *priv) temp = mach->regs[mach->index]; break; } + mach_log("ATI VGA read reg=%02x, val=%02x.\n", mach->index, temp); break; case 0x2ea: @@ -2458,11 +2563,11 @@ mach_in(uint16_t addr, void *priv) case 0x2ed: rs2 = !!(mach->accel.ext_ge_config & 0x1000); rs3 = !!(mach->accel.ext_ge_config & 0x2000); - if ((dev->local & 0xff) >= 0x02) { - if (mach->pci_bus && !mach->ramdac_type) - temp = ati68860_ramdac_in((addr & 3) | (rs2 << 2) | (rs3 << 3), svga->ramdac, svga); + if (ATI_MACH32) { + if (mach->pci_bus && (mach->ramdac_type == ATI_68860)) + temp = ati68860_ramdac_in((addr & 3) | (rs2 << 2) | (rs3 << 3), 1, svga->ramdac, svga); else - temp = ati68875_ramdac_in(addr, rs2, rs3, svga->ramdac, svga); + temp = ati68875_ramdac_in(addr, rs2, rs3, 1, svga->ramdac, svga); } else temp = svga_in(addr, svga); break; @@ -2503,6 +2608,186 @@ ati8514_in(uint16_t addr, void *priv) return temp; } +static void +ati_render_24bpp(svga_t *svga) +{ + mach_t *mach = (mach_t *) svga->priv; + ibm8514_t *dev = (ibm8514_t *) svga->dev8514; + uint32_t *p; + uint32_t dat; + + if ((dev->displine + svga->y_add) < 0) + return; + + if (dev->changedvram[dev->memaddr >> 12] || dev->changedvram[(dev->memaddr >> 12) + 1] || svga->fullchange) { + p = &buffer32->line[dev->displine + svga->y_add][svga->x_add]; + + if (dev->firstline_draw == 2000) + dev->firstline_draw = dev->displine; + dev->lastline_draw = dev->displine; + + if (mach->accel.ext_ge_config & 0x400) { /*BGR, Blue-(23:16), Green-(15:8), Red-(7:0)*/ + for (int x = 0; x <= dev->h_disp; x += 4) { + dat = *(uint32_t *) (&dev->vram[dev->memaddr & dev->vram_mask]); + p[x] = ((dat & 0xff0000) >> 16) | (dat & 0x00ff00) | ((dat & 0x0000ff) << 16); + + dat = *(uint32_t *) (&dev->vram[(dev->memaddr + 3) & dev->vram_mask]); + p[x + 1] = ((dat & 0xff0000) >> 16) | (dat & 0x00ff00) | ((dat & 0x0000ff) << 16); + + dat = *(uint32_t *) (&dev->vram[(dev->memaddr + 6) & dev->vram_mask]); + p[x + 2] = ((dat & 0xff0000) >> 16) | (dat & 0x00ff00) | ((dat & 0x0000ff) << 16); + + dat = *(uint32_t *) (&dev->vram[(dev->memaddr + 9) & dev->vram_mask]); + p[x + 3] = ((dat & 0xff0000) >> 16) | (dat & 0x00ff00) | ((dat & 0x0000ff) << 16); + + dev->memaddr += 12; + } + } else { /*RGB, Red-(23:16), Green-(15:8), Blue-(7:0)*/ + for (int x = 0; x <= dev->h_disp; x += 4) { + dat = *(uint32_t *) (&dev->vram[dev->memaddr & dev->vram_mask]); + p[x] = dat & 0xffffff; + + dat = *(uint32_t *) (&dev->vram[(dev->memaddr + 3) & dev->vram_mask]); + p[x + 1] = dat & 0xffffff; + + dat = *(uint32_t *) (&dev->vram[(dev->memaddr + 6) & dev->vram_mask]); + p[x + 2] = dat & 0xffffff; + + dat = *(uint32_t *) (&dev->vram[(dev->memaddr + 9) & dev->vram_mask]); + p[x + 3] = dat & 0xffffff; + + dev->memaddr += 12; + } + } + dev->memaddr &= dev->vram_mask; + } +} + +static void +ati_render_32bpp(svga_t *svga) +{ + mach_t *mach = (mach_t *) svga->priv; + ibm8514_t *dev = (ibm8514_t *) svga->dev8514; + int x; + uint32_t *p; + uint32_t dat; + + if ((dev->displine + svga->y_add) < 0) + return; + + if (dev->changedvram[dev->memaddr >> 12] || dev->changedvram[(dev->memaddr >> 12) + 1] || dev->changedvram[(dev->memaddr >> 12) + 2] || svga->fullchange) { + p = &buffer32->line[dev->displine + svga->y_add][svga->x_add]; + + if (dev->firstline_draw == 2000) + dev->firstline_draw = dev->displine; + dev->lastline_draw = dev->displine; + + if (mach->accel.ext_ge_config & 0x400) { /*BGR, Blue-(23:16), Green-(15:8), Red-(7:0)*/ + for (x = 0; x <= dev->h_disp; x++) { + dat = *(uint32_t *) (&dev->vram[(dev->memaddr + (x << 2)) & dev->vram_mask]); + *p++ = ((dat & 0x00ff0000) >> 16) | (dat & 0x0000ff00) | ((dat & 0x000000ff) << 16); + } + } else { /*RGB, Red-(31:24), Green-(23:16), Blue-(15:8)*/ + for (x = 0; x <= dev->h_disp; x++) { + dat = *(uint32_t *) (&dev->vram[(dev->memaddr + (x << 2)) & dev->vram_mask]); + *p++ = ((dat & 0xffffff00) >> 8); + } + } + dev->memaddr += (x * 4); + dev->memaddr &= dev->vram_mask; + } +} + +/*The situation is the following: + When ATI mode is selected, allow complete auto-detection. + But when 8514/A mode is selected, allow detection based on the shadow register sets. +*/ +static void +mach_set_resolution(mach_t *mach, svga_t *svga) +{ + ibm8514_t *dev = (ibm8514_t *) svga->dev8514; + int ret = 0; + + dev->h_total = dev->htotal + 1; + + if (dev->h_total == 1) /*Default to 1024x768 87hz 8514/A htotal timings if it goes to 0.*/ + dev->h_total = 0x9e; + + dev->hdisp = (dev->hdisped + 1) << 3; + + dev->vdisp = (dev->v_disp + 1) >> 1; + if ((dev->vdisp == 478) || (dev->vdisp == 598) || (dev->vdisp == 766) || (dev->vdisp == 1022)) + dev->vdisp += 2; + + dev->v_total = dev->v_total_reg + 1; + + dev->v_syncstart = dev->v_sync_start + 1; + + mach_log("VSYNCSTART=%d, VTOTAL=%d, interlace=%02x, vdisp=%d.\n", dev->v_syncstart, dev->v_total, dev->interlace, dev->vdisp); + + if (!ATI_MACH32) { + if ((mach->accel.clock_sel & 0x01) && + !(dev->accel.advfunc_cntl & 0x01)) + ret = 2; + else if ((dev->accel.advfunc_cntl & 0x01) && + !(mach->accel.clock_sel & 0x01)) + ret = 1; + else if ((!(dev->accel.advfunc_cntl & 0x01) && (mach->old_on1 & 0x01)) || + (!(mach->accel.clock_sel & 0x01) && (mach->old_on2 & 0x01))) + ret = 0; + } else { + if ((mach->accel.clock_sel & 0x01) && !(mach->old_on2 & 0x01) && + !(dev->accel.advfunc_cntl & 0x01)) + ret = 2; + else if ((dev->accel.advfunc_cntl & 0x01) && !(mach->old_on1 & 0x01) && + !(mach->accel.clock_sel & 0x01)) + ret = 1; + else if ((!(dev->accel.advfunc_cntl & 0x01) && (mach->old_on1 & 0x01)) || + (!(mach->accel.clock_sel & 0x01) && (mach->old_on2 & 0x01))) + ret = 0; + } + + if (ret) { + if (ret == 2) + svga_recalctimings(svga); + else { + switch (mach->shadow_set & 0x03) { + case 0x00: + if (mach->crt_resolution) + svga_recalctimings(svga); + else { + if (dev->accel.advfunc_cntl & 0x04) { + if (dev->hdisp == 640) { + dev->hdisp = 1024; + dev->vdisp = 768; + mach_log("1024x768.\n"); + } + } else { + if (dev->hdisp == 1024) { + dev->hdisp = 640; + dev->vdisp = 480; + mach_log("640x480.\n"); + } + } + svga_recalctimings(svga); + } + break; + case 0x01: + mach->crt_resolution = 0x01; + break; + case 0x02: + mach->crt_resolution = 0x02; + break; + default: + break; + } + } + } else + svga_recalctimings(svga); + + mach_log("Shadow set ATI=%x, shadow set 8514/A and on1=%x, on2=%x, resolution h=%d, v=%d, vtotal=%d, vsyncstart=%d, crtres=%d, ret=%d, actual passthrough=%x.\n", mach->shadow_set & 0x03, dev->accel.advfunc_cntl & 0x05, mach->accel.clock_sel & 0x01, dev->hdisp, dev->vdisp, dev->v_total, dev->v_syncstart, mach->crt_resolution, ret, dev->on); +} + void ati8514_recalctimings(svga_t *svga) { @@ -2511,55 +2796,56 @@ ati8514_recalctimings(svga_t *svga) mach_log("ON=%d, vgahdisp=%d.\n", dev->on, svga->hdisp); if (dev->on) { - mach_log("8514/A ON.\n"); + dev->interlace = !!(dev->disp_cntl & 0x10); dev->pitch = dev->ext_pitch; dev->rowoffset = dev->ext_crt_pitch; - dev->h_total = dev->htotal + 1; dev->rowcount = !!(dev->disp_cntl & 0x08); - dev->accel.ge_offset = (mach->accel.ge_offset_lo | (mach->accel.ge_offset_hi << 16)); - mach->accel.ge_offset = dev->accel.ge_offset; + dev->accel.ge_offset = (mach->accel.ge_offset_lo | (mach->accel.ge_offset_hi << 16)) << 2; + mach->accel.crt_offset = (mach->accel.crt_offset_lo | (mach->accel.crt_offset_hi << 16)) << 2; - mach_log("HDISP=%d, VDISP=%d, shadowset=%x, 8514/A mode=%x, clocksel=%02x.\n", dev->hdisp, dev->vdisp, mach->shadow_set & 0x03, dev->accel.advfunc_cntl & 0x05, mach->accel.clock_sel & 0x01); + dev->accel.ge_offset -= mach->accel.crt_offset; - if (mach->accel.clock_sel & 0x01) { - dev->h_disp = dev->hdisp; - dev->dispend = dev->vdisp; - } else { - if (dev->accel.advfunc_cntl & 0x04) { - if (dev->hdisp == 640) { - dev->h_disp = 1024; - dev->dispend = 768; - } else { - dev->h_disp = dev->hdisp; - dev->dispend = dev->vdisp; - } - } else { - dev->h_disp = 640; - dev->dispend = 480; - } - } + mach_log("HDISP=%d, VDISP=%d, shadowset=%x, 8514/A mode=%x, clocksel=%02x.\n", + dev->hdisp, dev->vdisp, mach->shadow_set & 0x03, dev->accel.advfunc_cntl & 0x05, mach->accel.clock_sel & 0x01); + + mach->accel.src_pitch = dev->pitch; + mach->accel.dst_pitch = dev->pitch; + mach->accel.src_ge_offset = (mach->accel.ge_offset_lo | (mach->accel.ge_offset_hi << 16)) << 2; + mach->accel.dst_ge_offset = (mach->accel.ge_offset_lo | (mach->accel.ge_offset_hi << 16)) << 2; + mach->accel.src_ge_offset -= mach->accel.crt_offset; + mach->accel.dst_ge_offset -= mach->accel.crt_offset; + + mach_log("8514/A ON, pitch=%d, GE offset=%08x.\n", ((mach->accel.ge_pitch & 0xff) << 3), dev->accel.ge_offset); + + dev->h_disp = dev->hdisp; + dev->dispend = dev->vdisp; + if (dev->dispend == 600) + dev->h_disp = 800; + else if (dev->h_disp == 640) + dev->dispend = 480; if (dev->accel.advfunc_cntl & 0x04) - svga->clock8514 = (cpuclock * (double) (1ULL << 32)) / 44900000.0; + svga->clock_8514 = (cpuclock * (double) (1ULL << 32)) / 44900000.0; else - svga->clock8514 = (cpuclock * (double) (1ULL << 32)) / 25175000.0; + svga->clock_8514 = (cpuclock * (double) (1ULL << 32)) / 25175000.0; if (dev->interlace) dev->dispend >>= 1; - mach_log("cntl=%d, hv(%d,%d), pitch=%d, rowoffset=%d, gextconfig=%03x, shadow=%x interlace=%d.\n", dev->accel.advfunc_cntl & 0x04, dev->h_disp, dev->dispend, dev->pitch, dev->rowoffset, mach->accel.ext_ge_config & 0xcec0, mach->shadow_set & 3, dev->interlace); + mach_log("cntl=%d, hv(%d,%d), pitch=%d, rowoffset=%d, gextconfig=%03x, shadow=%x interlace=%d.\n", + dev->accel.advfunc_cntl & 0x04, dev->h_disp, dev->dispend, dev->pitch, dev->rowoffset, + mach->accel.ext_ge_config & 0xcec0, mach->shadow_set & 3, dev->interlace); if (dev->vram_512k_8514) { - if (dev->h_disp == 640) { - dev->ext_pitch = 640; - dev->pitch = dev->ext_pitch; - } else { - dev->ext_pitch = 1024; - dev->pitch = dev->ext_pitch; - } + if (dev->h_disp == 640) + dev->pitch = 640; + else + dev->pitch = 1024; } dev->accel_bpp = 8; svga->render8514 = ibm8514_render_8bpp; - } + + } else + mach->crt_resolution = 0; } static void @@ -2574,19 +2860,19 @@ mach_recalctimings(svga_t *svga) clock_sel = ((svga->miscout >> 2) & 3) | ((mach->regs[0xbe] & 0x10) >> 1) | ((mach->regs[0xb9] & 2) << 1); - if ((dev->local & 0xff) >= 0x02) { + if (ATI_MACH32) { if (mach->regs[0xad] & 0x04) - svga->ma_latch |= 0x40000; + svga->memaddr_latch |= 0x40000; if (mach->regs[0xad] & 0x08) - svga->ma_latch |= 0x80000; + svga->memaddr_latch |= 0x80000; } if (mach->regs[0xa3] & 0x10) - svga->ma_latch |= 0x10000; + svga->memaddr_latch |= 0x10000; if (mach->regs[0xb0] & 0x40) - svga->ma_latch |= 0x20000; + svga->memaddr_latch |= 0x20000; if ((mach->regs[0xb6] & 0x18) >= 0x10) { svga->hdisp <<= 1; @@ -2603,7 +2889,7 @@ mach_recalctimings(svga_t *svga) } else svga->packed_4bpp = 0; - if ((dev->local & 0xff) < 0x02) { + if (!ATI_MACH32) { if ((mach->regs[0xb6] & 0x18) == 0x08) { svga->hdisp <<= 1; svga->htotal <<= 1; @@ -2613,94 +2899,130 @@ mach_recalctimings(svga_t *svga) svga->ati_4color = 0; } - mach_log("ON?=%d, override=%d.\n", dev->on, svga->override); + mach_log("ON=%d, override=%d, gelo=%04x, gehi=%04x, vgahdisp=%d.\n", dev->on, svga->override, mach->accel.ge_offset_lo, mach->accel.ge_offset_hi, svga->hdisp); if (dev->on) { - mach_log("8514/A ON, extpitch=%d, devma=%x, vgamalatch=%x.\n", dev->ext_pitch, dev->ma, svga->ma_latch); + dev->memaddr_latch = 0; /*(mach->accel.crt_offset_lo | (mach->accel.crt_offset_hi << 16)) << 2;*/ + dev->interlace = !!(dev->disp_cntl & 0x10); dev->pitch = dev->ext_pitch; dev->rowoffset = dev->ext_crt_pitch; - dev->h_total = dev->htotal + 1; dev->rowcount = !!(dev->disp_cntl & 0x08); dev->accel.ge_offset = (mach->accel.ge_offset_lo | (mach->accel.ge_offset_hi << 16)); - mach->accel.ge_offset = dev->accel.ge_offset; + mach->accel.crt_offset = (mach->accel.crt_offset_lo | (mach->accel.crt_offset_hi << 16)); - mach_log("HDISP=%d, VDISP=%d, shadowset=%x, 8514/A mode=%x, clocksel=%02x, interlace=%x.\n", dev->hdisp, dev->vdisp, mach->shadow_set & 0x03, dev->accel.advfunc_cntl & 0x04, mach->accel.clock_sel & 0xfe, dev->interlace); - if ((dev->local & 0xff) >= 0x02) { - if (dev->bpp || ((mach->accel.ext_ge_config & 0x30) == 0x30) || (mach->accel.clock_sel & 0x01)) { - dev->h_disp = dev->hdisp; - dev->dispend = dev->vdisp; - } else { - if (dev->interlace) { /*Interlaced displays are only for 800x600 and up.*/ - if (dev->accel.advfunc_cntl & 0x04) { - dev->h_disp = dev->hdisp; - dev->dispend = dev->vdisp; - } else { - dev->h_disp = 640; - dev->dispend = 480; - } - } else { - if (((mach->shadow_set & 0x03) == 0x00) && ((dev->hdisp2 == 640) || (dev->hdisp2 == 1280)) && (dev->hdisp != 800)) { - dev->h_disp = dev->hdisp2; - dev->dispend = dev->vdisp2; - } else { - dev->h_disp = dev->hdisp; - dev->dispend = dev->vdisp; - } - } - } + if (dev->bpp) { + dev->accel.ge_offset <<= 1; + mach->accel.crt_offset <<= 1; } else { - if (mach->accel.clock_sel & 0x01) { - dev->h_disp = dev->hdisp; - dev->dispend = dev->vdisp; - } else { - if (dev->accel.advfunc_cntl & 0x04) { - dev->h_disp = dev->hdisp; - dev->dispend = dev->vdisp; - } else { - dev->h_disp = 640; - dev->dispend = 480; - } - } + dev->accel.ge_offset <<= 2; + mach->accel.crt_offset <<= 2; } - svga->clock8514 = (cpuclock * (double) (1ULL << 32)) / svga->getclock((mach->accel.clock_sel >> 2) & 0x0f, svga->clock_gen); + if (ATI_MACH32 && !dev->vram_512k_8514 && ((mach->accel.ext_ge_config & 0x30) == 0x00)) { + dev->accel.ge_offset <<= 1; + mach->accel.crt_offset <<= 1; + } + + dev->accel.ge_offset -= mach->accel.crt_offset; + + mach_log("RowCount=%x, rowoffset=%x, pitch=%d, geoffset=%x, crtoffset=%x.\n", dev->rowcount, dev->rowoffset, dev->pitch, dev->accel.ge_offset, mach->accel.crt_offset); + mach_log("HDISP=%d, VDISP=%d, shadowset=%x, 8514/A mode=%x, clocksel=%02x, interlace=%x.\n", + dev->hdisp, dev->vdisp, mach->shadow_set & 0x03, dev->accel.advfunc_cntl & 0x04, + mach->accel.clock_sel & 0xfe, dev->interlace); + + dev->h_disp = dev->hdisp; + dev->dispend = dev->vdisp; + if (dev->dispend == 959) { /*FIXME: vertical resolution mess on EEPROM tests on Mach8*/ + dev->dispend >>= 1; + dev->dispend++; + } else if (dev->dispend == 600) + dev->h_disp = 800; + else if (dev->h_disp == 640) + dev->dispend = 480; + + svga->clock_8514 = (cpuclock * (double) (1ULL << 32)) / svga->getclock((mach->accel.clock_sel >> 2) & 0x0f, svga->clock_gen); if (mach->accel.clock_sel & 0x40) - svga->clock8514 *= 2; + svga->clock_8514 *= 2; if (dev->interlace) dev->dispend >>= 1; - if ((dev->local & 0xff) >= 0x02) { - mach_log("HDISP=%d, mask=%02x.\n", dev->h_disp, dev->dac_mask); - if ((mach->accel.ext_ge_config & 0x800) || (!(mach->accel.ext_ge_config & 0x8000) && !(mach->accel.ext_ge_config & 0x800))) { - if ((mach->accel.ext_ge_config & 0x30) == 0x20) { - if ((mach->accel.ext_ge_config & 0xc0) == 0x40) - dev->accel_bpp = 16; - else - dev->accel_bpp = 15; - } else if ((mach->accel.ext_ge_config & 0x30) == 0x30) { - if (mach->accel.ext_ge_config & 0x200) - dev->accel_bpp = 32; - else - dev->accel_bpp = 24; - } else if ((mach->accel.ext_ge_config & 0x30) == 0x10) - dev->accel_bpp = 8; - else { - if (dev->vram_512k_8514) { - if (dev->h_disp == 640) { - dev->ext_pitch = 640; - dev->pitch = dev->ext_pitch; - } else { - dev->ext_pitch = 1024; - dev->pitch = dev->ext_pitch; - } + if (ATI_MACH32) { + switch ((mach->shadow_set >> 8) & 0x03) { + case 0x00: + mach->accel.src_pitch = ((mach->accel.ge_pitch & 0xff) << 3); + mach->accel.dst_pitch = ((mach->accel.ge_pitch & 0xff) << 3); + mach->accel.src_ge_offset = (mach->accel.ge_offset_lo | (mach->accel.ge_offset_hi << 16)); + mach->accel.dst_ge_offset = (mach->accel.ge_offset_lo | (mach->accel.ge_offset_hi << 16)); + if (dev->bpp) { + mach->accel.src_ge_offset <<= 1; + mach->accel.dst_ge_offset <<= 1; + } else { + mach->accel.src_ge_offset <<= 2; + mach->accel.dst_ge_offset <<= 2; } - dev->accel_bpp = 8; - } + if (!dev->vram_512k_8514 && ((mach->accel.ext_ge_config & 0x30) == 0x00)) { + mach->accel.src_ge_offset <<= 1; + mach->accel.dst_ge_offset <<= 1; + } + mach->accel.src_ge_offset -= mach->accel.crt_offset; + mach->accel.dst_ge_offset -= mach->accel.crt_offset; + dev->accel.src_pitch = mach->accel.src_pitch; + dev->accel.dst_pitch = mach->accel.dst_pitch; + dev->accel.src_ge_offset = mach->accel.src_ge_offset; + dev->accel.dst_ge_offset = mach->accel.dst_ge_offset; + break; + case 0x01: + mach->accel.dst_pitch = ((mach->accel.ge_pitch & 0xff) << 3); + mach->accel.dst_ge_offset = (mach->accel.ge_offset_lo | (mach->accel.ge_offset_hi << 16)); + if (dev->bpp) + mach->accel.dst_ge_offset <<= 1; + else + mach->accel.dst_ge_offset <<= 2; + + if (!dev->vram_512k_8514 && ((mach->accel.ext_ge_config & 0x30) == 0x00)) + mach->accel.dst_ge_offset <<= 1; + + mach->accel.dst_ge_offset -= mach->accel.crt_offset; + dev->accel.dst_pitch = mach->accel.dst_pitch; + dev->accel.dst_ge_offset = mach->accel.dst_ge_offset; + break; + case 0x02: + mach->accel.src_pitch = ((mach->accel.ge_pitch & 0xff) << 3); + mach->accel.src_ge_offset = (mach->accel.ge_offset_lo | (mach->accel.ge_offset_hi << 16)); + if (dev->bpp) + mach->accel.src_ge_offset <<= 1; + else + mach->accel.src_ge_offset <<= 2; + + if (!dev->vram_512k_8514 && ((mach->accel.ext_ge_config & 0x30) == 0x00)) + mach->accel.src_ge_offset <<= 1; + + mach->accel.src_ge_offset -= mach->accel.crt_offset; + dev->accel.src_pitch = mach->accel.src_pitch; + dev->accel.src_ge_offset = mach->accel.src_ge_offset; + break; + default: + break; + } + mach_log("cntl=%d, clksel=%x, hv(%d,%d), pitch=%d, rowoffset=%d, gextconfig=%03x, shadow=%x interlace=%d, vgahdisp=%d.\n", + dev->accel.advfunc_cntl & 0x04, mach->accel.clock_sel & 0x01, dev->h_disp, dev->dispend, dev->pitch, dev->rowoffset, + mach->accel.ext_ge_config & 0xcec0, mach->shadow_set & 3, dev->interlace, svga->hdisp); + mach_log("EXTGECONFIG bits 11-15=%04x.\n", mach->accel.ext_ge_config & 0x8800); + if ((mach->accel.ext_ge_config & 0x800) || (!(mach->accel.ext_ge_config & 0x8000) && !(mach->accel.ext_ge_config & 0x800))) { + mach_log("hv=%d,%d, pitch=%d, rowoffset=%d, gextconfig=%03x, bpp=%d, shadow=%x, vgahdisp=%d.\n", + dev->h_disp, dev->dispend, dev->pitch, dev->ext_crt_pitch, mach->accel.ext_ge_config & 0xcec0, + dev->accel_bpp, mach->shadow_set & 0x03, svga->hdisp); - svga->render8514 = ibm8514_render_blank; - mach_log("hv(%d,%d), pitch=%d, rowoffset=%d, gextconfig=%03x, bpp=%d, shadow=%x, vgahdisp=%d.\n", dev->h_disp, dev->dispend, dev->pitch, dev->ext_crt_pitch, mach->accel.ext_ge_config & 0xcec0, dev->accel_bpp, mach->shadow_set & 3, svga->hdisp); switch (dev->accel_bpp) { case 8: + if ((mach->accel.ext_ge_config & 0x30) == 0x00) { + if (dev->vram_512k_8514) { + if (dev->h_disp == 640) + dev->pitch = 640; + else + dev->pitch = 1024; + } + } svga->render8514 = ibm8514_render_8bpp; break; case 15: @@ -2711,17 +3033,11 @@ mach_recalctimings(svga_t *svga) break; case 24: mach_log("GEConfig24bpp: %03x.\n", mach->accel.ext_ge_config & 0x600); - if (mach->accel.ext_ge_config & 0x400) - svga->render8514 = ibm8514_render_BGR; - else - svga->render8514 = ibm8514_render_24bpp; + svga->render8514 = ati_render_24bpp; break; case 32: mach_log("GEConfig32bpp: %03x.\n", mach->accel.ext_ge_config & 0x600); - if (mach->accel.ext_ge_config & 0x400) - svga->render8514 = ibm8514_render_ABGR8888; - else - svga->render8514 = ibm8514_render_32bpp; + svga->render8514 = ati_render_32bpp; break; default: @@ -2729,28 +3045,37 @@ mach_recalctimings(svga_t *svga) } } } else { - svga->render8514 = ibm8514_render_blank; - mach_log("cntl=%d, hv(%d,%d), pitch=%d, rowoffset=%d, gextconfig=%03x, shadow=%x interlace=%d.\n", dev->accel.advfunc_cntl & 0x04, dev->h_disp, dev->dispend, dev->pitch, dev->rowoffset, mach->accel.ext_ge_config & 0xcec0, mach->shadow_set & 3, dev->interlace); + mach->accel.src_pitch = dev->pitch; + mach->accel.dst_pitch = dev->pitch; + mach->accel.src_ge_offset = (mach->accel.ge_offset_lo | (mach->accel.ge_offset_hi << 16)); + mach->accel.dst_ge_offset = (mach->accel.ge_offset_lo | (mach->accel.ge_offset_hi << 16)); + mach->accel.src_ge_offset <<= 2; + mach->accel.dst_ge_offset <<= 2; + mach->accel.src_ge_offset -= mach->accel.crt_offset; + mach->accel.dst_ge_offset -= mach->accel.crt_offset; + + mach_log("cntl=%d, clksel=%x, hv(%d,%d), pitch=%d, rowoffset=%d, gextconfig=%03x, shadow=%x interlace=%d, vgahdisp=%d.\n", + dev->accel.advfunc_cntl & 0x04, mach->accel.clock_sel & 0x01, dev->h_disp, dev->dispend, dev->pitch, dev->rowoffset, + mach->accel.ext_ge_config & 0xcec0, mach->shadow_set & 0x03, dev->interlace, svga->hdisp); if (dev->vram_512k_8514) { - if (dev->h_disp == 640) { - dev->ext_pitch = 640; - dev->pitch = dev->ext_pitch; - } else { - dev->ext_pitch = 1024; - dev->pitch = dev->ext_pitch; - } + if (dev->h_disp == 640) + dev->pitch = 640; + else + dev->pitch = 1024; } dev->accel_bpp = 8; svga->render8514 = ibm8514_render_8bpp; } } else { + mach->crt_resolution = 0; if (!svga->scrblank && (svga->crtc[0x17] & 0x80) && svga->attr_palette_enable) { - mach_log("GDCREG5=%02x, ATTR10=%02x, ATI B0 bit 5=%02x, ON=%d.\n", svga->gdcreg[5] & 0x60, svga->attrregs[0x10] & 0x40, mach->regs[0xb0] & 0x20, dev->on); + mach_log("GDCREG5=%02x, ATTR10=%02x, ATI B0 bit 5=%02x, ON=%d.\n", + svga->gdcreg[5] & 0x60, svga->attrregs[0x10] & 0x40, mach->regs[0xb0] & 0x20, dev->on); if ((svga->gdcreg[6] & 0x01) || (svga->attrregs[0x10] & 0x01)) { if ((svga->gdcreg[5] & 0x40) || (svga->attrregs[0x10] & 0x40) || (mach->regs[0xb0] & 0x20)) { svga->clock = (cpuclock * (double) (1ULL << 32)) / svga->getclock(clock_sel, svga->clock_gen); mach_log("VGA clock=%02x.\n", mach->regs[0xa7] & 0x80); - if ((dev->local & 0xff) >= 0x02) { + if (ATI_MACH32) { if (mach->regs[0xb8] & 0x40) svga->clock *= 2; } else { @@ -2776,7 +3101,7 @@ mach_recalctimings(svga_t *svga) else { svga->render = svga_render_8bpp_highres; if (!svga->packed_4bpp) { - svga->ma_latch <<= 1; + svga->memaddr_latch <<= 1; svga->rowoffset <<= 1; } } @@ -2793,173 +3118,417 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u int bkgd_sel; int mono_src; + if (port & 0x8000) { + if ((port & 0x06) != 0x06) { + if ((port != 0xe2e8) && (port != 0xe2e9) && (port != 0xe6e8) && (port != 0xe6e9)) { + if (port & 0x4000) + port &= ~0x4000; + } + } + } + mach_log("[%04X:%08X]: Port FIFO OUT=%04x, val=%04x, len=%d.\n", CS, cpu_state.pc, port, val, len); switch (port) { - case 0x82e8: - case 0x86e8: - case 0xc2e8: - case 0xc6e8: - dev->ext_fifo_idx++; - ibm8514_accel_out_fifo(svga, port, val, len); + case 0x2e8: + if ((mach->accel.clock_sel & 0x01) || (!(mach->accel.clock_sel & 0x01) && (mach->shadow_set & 0x03))) { /*For 8514/A mode, take the shadow sets into account.*/ + if (!(mach->shadow_cntl & 0x04)) + dev->htotal = val; + } + svga_recalctimings(svga); break; - case 0xf6ee: - dev->ext_fifo_idx++; + + case 0xae8: + if ((mach->accel.clock_sel & 0x01) || (!(mach->accel.clock_sel & 0x01) && (mach->shadow_set & 0x03))) { /*For 8514/A mode, take the shadow sets into account.*/ + if (!(mach->shadow_cntl & 0x04)) { + WRITE8(port, dev->hsync_start, val); + } + } + svga_recalctimings(svga); + break; + + case 0xee8: + if ((mach->accel.clock_sel & 0x01) || (!(mach->accel.clock_sel & 0x01) && (mach->shadow_set & 0x03))) { /*For 8514/A mode, take the shadow sets into account.*/ + if (!(mach->shadow_cntl & 0x04)) { + WRITE8(port, dev->hsync_width, val); + } + } + svga_recalctimings(svga); + break; + + case 0x6e8: + if (len == 2) { + mach_log("HDISP and HTOTAL=%04x, len=%d, set=%x, ATI mode bit=%x.\n", val, len, mach->shadow_set & 0x03, mach->accel.clock_sel & 0x01); + if ((mach->accel.clock_sel & 0x01) || (!(mach->accel.clock_sel & 0x01) && (mach->shadow_set & 0x03))) { /*For 8514/A mode, take the shadow sets into account.*/ + if (!(mach->shadow_cntl & 0x04)) + dev->htotal = (val >> 8) & 0xff; + + if (!(mach->shadow_cntl & 0x08)) { + if ((dev->htotal || (mach->accel.clock_sel & 0x01)) && (val & 0xff)) { + WRITE8(port, dev->hdisped, val); + } + } + } + } else { + mach_log("HDISP and HTOTAL=%02x, len=%d, set=%x, ATI mode bit=%x.\n", val, len, mach->shadow_set & 0x03, mach->accel.clock_sel & 0x01); + if ((mach->accel.clock_sel & 0x01) || (!(mach->accel.clock_sel & 0x01) && (mach->shadow_set & 0x03))) { /*For 8514/A mode, take the shadow sets into account.*/ + if (!(mach->shadow_cntl & 0x08)) { + if ((dev->htotal || (mach->accel.clock_sel & 0x01)) && (val & 0xff)) { + WRITE8(port, dev->hdisped, val); + } + } + } + } + mach_log("[%04X:%08X]: ATI 8514/A: (0x%04x): hdisp=0x%02x, shadowcntl=%02x, shadowset=%02x.\n", + CS, cpu_state.pc, port, val, mach->shadow_cntl & 0x08, mach->shadow_set & 0x03); + svga_recalctimings(svga); + break; + + case 0x6e9: + if (len == 1) { + mach_log("HDISP and HTOTAL+1=%02x, len=%d, set=%x, ATI mode bit=%x.\n", val, len, mach->shadow_set & 0x03, mach->accel.clock_sel & 0x01); + if ((mach->accel.clock_sel & 0x01) || (!(mach->accel.clock_sel & 0x01) && (mach->shadow_set & 0x03))) { /*For 8514/A mode, take the shadow sets into account.*/ + if (!(mach->shadow_cntl & 0x04)) { + dev->htotal = val; + } + } + } + svga_recalctimings(svga); + break; + + case 0x12e8: + if (len == 2) { + if ((mach->accel.clock_sel & 0x01) || (!(mach->accel.clock_sel & 0x01) && (mach->shadow_set & 0x03))) { /*For 8514/A mode, take the shadow sets into account.*/ + if (!(mach->shadow_cntl & 0x10) && val) { + dev->v_total_reg = val; + dev->v_total_reg &= 0x1fff; + } + } + } else { + if ((mach->accel.clock_sel & 0x01) || (!(mach->accel.clock_sel & 0x01) && (mach->shadow_set & 0x03))) { /*For 8514/A mode, take the shadow sets into account.*/ + if (!(mach->shadow_cntl & 0x10)) { + WRITE8(port, dev->v_total_reg, val); + dev->v_total_reg &= 0x1fff; + } + } + } + mach_log("[%04X:%08X]: ATI 8514/A: (0x%04x): hdisp=0x%02x.\n", CS, cpu_state.pc, port, val); + svga_recalctimings(svga); + break; + + case 0x12e9: + if (len == 1) { + if ((mach->accel.clock_sel & 0x01) || (!(mach->accel.clock_sel & 0x01) && (mach->shadow_set & 0x03))) { + if (!(mach->shadow_cntl & 0x10)) { /*For 8514/A mode, take the shadow sets into account.*/ + WRITE8(port, dev->v_total_reg, val >> 8); + dev->v_total_reg &= 0x1fff; + } + } + mach_log("[%04X:%08X]: ATI 8514/A: (0x%04x): hdisp=0x%02x.\n", CS, cpu_state.pc, port, val); + } + svga_recalctimings(svga); + break; + + case 0x16e8: + if (len == 2) { + if ((mach->accel.clock_sel & 0x01) || (!(mach->accel.clock_sel & 0x01) && (mach->shadow_set & 0x03))) { /*For 8514/A mode, take the shadow sets into account.*/ + if (!(mach->shadow_cntl & 0x20) && val) { + dev->v_disp = val; + dev->v_disp &= 0x1fff; + } + } + mach_log("ATI 8514/A: V_DISP write 16E8=%d, vdisp2=%d.\n", dev->v_disp, dev->v_disp2); + mach_log("ATI 8514/A: (0x%04x): vdisp=0x%02x.\n", port, val); + } else { + if ((mach->accel.clock_sel & 0x01) || (!(mach->accel.clock_sel & 0x01) && (mach->shadow_set & 0x03))) { /*For 8514/A mode, take the shadow sets into account.*/ + if (!(mach->shadow_cntl & 0x20)) { + WRITE8(port, dev->v_disp, val); + dev->v_disp &= 0x1fff; + } + } + } + svga_recalctimings(svga); + break; + case 0x16e9: + if (len == 1) { + if ((mach->accel.clock_sel & 0x01) || (!(mach->accel.clock_sel & 0x01) && (mach->shadow_set & 0x03))) { /*For 8514/A mode, take the shadow sets into account.*/ + if (!(mach->shadow_cntl & 0x20)) { + WRITE8(port, dev->v_disp, val >> 8); + dev->v_disp &= 0x1fff; + } + } + mach_log("ATI 8514/A: V_DISP write 16E8=%d, vdisp2=%d.\n", dev->v_disp, dev->v_disp2); + mach_log("ATI 8514/A: (0x%04x): vdisp=0x%02x.\n", port, val); + } + svga_recalctimings(svga); + break; + + case 0x1ae8: + if (len == 2) { + if ((mach->accel.clock_sel & 0x01) || (!(mach->accel.clock_sel & 0x01) && (mach->shadow_set & 0x03))) { /*For 8514/A mode, take the shadow sets into account.*/ + if (!(mach->shadow_cntl & 0x10) && val) { + dev->v_sync_start = val; + dev->v_sync_start &= 0x1fff; + } + } + mach_log("ATI 8514/A: V_SYNCSTART write 1AE8 = %d\n", dev->v_syncstart); + mach_log("ATI 8514/A: (0x%04x): vsyncstart=0x%02x.\n", port, val); + } else { + if ((mach->accel.clock_sel & 0x01) || (!(mach->accel.clock_sel & 0x01) && (mach->shadow_set & 0x03))) { /*For 8514/A mode, take the shadow sets into account.*/ + if (!(mach->shadow_cntl & 0x10)) { + WRITE8(port, dev->v_sync_start, val); + dev->v_sync_start &= 0x1fff; + } + } + } + svga_recalctimings(svga); + break; + case 0x1ae9: + if (len == 1) { + if ((mach->accel.clock_sel & 0x01) || (!(mach->accel.clock_sel & 0x01) && (mach->shadow_set & 0x03))) { /*For 8514/A mode, take the shadow sets into account.*/ + if (!(mach->shadow_cntl & 0x10)) { + WRITE8(port, dev->v_sync_start, val >> 8); + dev->v_sync_start &= 0x1fff; + } + } + mach_log("ATI 8514/A: V_SYNCSTART write 1AE8 = %d\n", dev->v_syncstart); + mach_log("ATI 8514/A: (0x%04x): vsyncstart=0x%02x.\n", port, val); + } + svga_recalctimings(svga); + break; + + case 0x1ee8: + case 0x1ee9: + svga_recalctimings(svga); + break; + + case 0x22e8: + if ((mach->shadow_cntl & 0x03) == 0x00) + dev->disp_cntl = val; + + mach_log("ATI 8514/A: DISP_CNTL write %04x=%02x, written=%02x, interlace=%d.\n", + port, val & 0x70, dev->disp_cntl & 0x70, dev->interlace); + svga_recalctimings(svga); + break; + + case 0x42e8: + case 0x42e9: + mach_log("VBLANK status=%02x, val=%02x.\n", dev->subsys_stat, val); if (len == 2) - dev->accel.cur_y = val & 0x7ff; + dev->subsys_cntl = val; + else { + WRITE8(port, dev->subsys_cntl, val); + } + dev->subsys_stat &= ~val; + if ((dev->subsys_cntl & 0xc000) == 0x8000) { + mach->force_busy = 0; + dev->force_busy = 0; + dev->force_busy2 = 0; + } + break; + + case 0x46e8: + case 0x46e9: + mach_log("0x%04x write: VGA subsystem enable add-on=%02x.\n", port, val); + break; + + case 0x4ae8: + case 0x4ae9: + mach->old_on1 = dev->accel.advfunc_cntl & 0x01; + WRITE8(port, dev->accel.advfunc_cntl, val); + if (len == 2) { + WRITE8(port + 1, dev->accel.advfunc_cntl, val >> 8); + } + dev->on = dev->accel.advfunc_cntl & 0x01; + dev->vendor_mode = 0; + if (dev->_8514crt) { + if (mach->regs[0xb0] & 0x20) { + dev->on = 1; + dev->vendor_mode = !!(ATI_MACH32); + } + } + + mach_log("[%04X:%08X]: ATI 8514/A: (0x%04x): ON=%d, valxor=%x, shadow crt=%x, hdisp=%d, vdisp=%d, extmode=%02x, accelbpp=%d, crt=%d, crtres=%d.\n", + CS, cpu_state.pc, port, val & 0x01, dev->on, dev->accel.advfunc_cntl & 0x04, dev->hdisp, dev->vdisp, mach->regs[0xb0] & 0x20, dev->accel_bpp, dev->_8514crt, mach->crt_resolution); + + if (ATI_MACH32) { + mach_set_resolution(mach, svga); + mach32_updatemapping(mach, svga); + } else { + dev->ext_pitch = 1024; + dev->ext_crt_pitch = 128; + mach_set_resolution(mach, svga); + } + mach_log("Vendor IBM mode set %s resolution.\n", (dev->accel.advfunc_cntl & 0x04) ? "2: 1024x768" : "1: 640x480"); + break; + + case 0x82e8: + ibm8514_accel_out_fifo(svga, port, val, len); + mach_log("DSTY=%04x, len=%d.\n", val & 0x07ff, len); + break; + + case 0x86e8: + ibm8514_accel_out_fifo(svga, port, val, len); + mach_log("DSTX=%04x, len=%d.\n", val & 0x07ff, len); break; case 0x8ae8: - case 0xcae8: - dev->ext_fifo_idx++; ibm8514_accel_out_fifo(svga, port, val, len); + mach_log("SRCY=%04x, len=%d.\n", val & 0x07ff, len); if (len == 2) { - mach_log("SRCY=%d.\n", val & 0x07ff); mach->accel.src_y = val & 0x07ff; + mach->accel.src_y_scan = ((int64_t)(val & 0x07ff)); } break; case 0x8ee8: - case 0xcee8: - dev->ext_fifo_idx++; ibm8514_accel_out_fifo(svga, port, val, len); + mach_log("SRCX=%04x, len=%d.\n", val & 0x07ff, len); if (len == 2) { - mach_log("SRCX=%d.\n", val & 0x07ff); mach->accel.src_x = val & 0x07ff; + mach->accel.src_x_scan = ((int64_t)(val & 0x07ff)); } break; case 0x92e8: - case 0xd2e8: - dev->ext_fifo_idx++; ibm8514_accel_out_fifo(svga, port, val, len); break; case 0x96e8: - case 0xd6e8: - dev->ext_fifo_idx++; ibm8514_accel_out_fifo(svga, port, val, len); if (len == 2) mach->accel.test = val & 0x1fff; break; case 0x9ae8: - case 0xdae8: - dev->ext_fifo_idx++; mach->accel.cmd_type = -1; ibm8514_accel_out_fifo(svga, port, val, len); break; case 0x9ee8: - case 0xdee8: - dev->ext_fifo_idx++; ibm8514_accel_out_fifo(svga, port, val, len); break; case 0xa2e8: case 0xe2e8: - dev->ext_fifo_idx++; - dev->fifo_idx++; if (port == 0xe2e8) { + mach_log("%04X: Background Color=%04x, pix=%d, len=%d.\n", port, val, dev->accel.cmd_back, len); if (len == 2) { - if (dev->accel.cmd_back) { - dev->accel.bkgd_color = val; - mach_log("CMDBack BKGDCOLOR, sy=%d, height=%d, val=%04x.\n", dev->accel.sy, mach->accel.height, val); - } else { + if (!dev->accel.cmd_back) { if (mach->accel.cmd_type >= 0) { if (mach_pixel_read(mach)) break; + + mach_log("ATI transfer.\n"); mach_accel_out_pixtrans(svga, mach, dev, val); } else { if (ibm8514_cpu_dest(svga)) break; + + mach_log("IBM transfer.\n"); ibm8514_accel_out_pixtrans(svga, port, val, len); } + } else { + dev->accel.bkgd_color = val; + mach_log("%04X: CMDBack BKGDCOLOR, sy=%d, height=%d, cmdtype=%d, val=%04x.\n", port, dev->accel.sy, mach->accel.height, mach->accel.cmd_type, val); } } else { - if (mach->accel.cmd_type >= 0) { - if (mach_pixel_read(mach)) - break; - mach->accel.pix_trans[1] = val; + if (!dev->accel.cmd_back) { + if (mach->accel.cmd_type >= 0) { + if (mach_pixel_read(mach)) + break; + + mach->accel.pix_trans[1] = val; + } } } } else { if (len == 2) dev->accel.bkgd_color = val; + + mach_log("%04X: Background Color=%04x.\n", port, val); } break; case 0xa6e8: case 0xe6e8: - dev->ext_fifo_idx++; - dev->fifo_idx++; if (port == 0xe6e8) { + mach_log("%04X: Foreground Color=%04x, pix=%d, len=%d.\n", port, val, dev->accel.cmd_back, len); if (len == 2) { - if (dev->accel.cmd_back) - dev->accel.frgd_color = val; - else { + if (!dev->accel.cmd_back) { if (mach->accel.cmd_type >= 0) { if (mach_pixel_read(mach)) break; + + mach_log("ATI transfer.\n"); mach_accel_out_pixtrans(svga, mach, dev, val); } else { if (ibm8514_cpu_dest(svga)) break; + + mach_log("IBM transfer.\n"); ibm8514_accel_out_pixtrans(svga, port, val, len); } - } + } else + dev->accel.frgd_color = val; } else { - if (mach->accel.cmd_type >= 0) { - if (mach_pixel_read(mach)) - break; - mach->accel.pix_trans[1] = val; + if (!dev->accel.cmd_back) { + if (mach->accel.cmd_type >= 0) { + if (mach_pixel_read(mach)) + break; + + mach->accel.pix_trans[1] = val; + } } } } else { if (len == 2) dev->accel.frgd_color = val; + + mach_log("%04X: Foreground Color=%04x.\n", port, val); } break; case 0xe2e9: case 0xe6e9: - dev->ext_fifo_idx++; - dev->fifo_idx++; - mach_log("Write PORT=%04x, 8514/A=%x, val=%04x, len=%d.\n", port, dev->accel.cmd_back, val, len); + mach_log("Write PORT=%04x, 8514/A=%x, val0=%02x, sy=%d, len=%d, dx=%d, dy=%d.\n", port, dev->accel.cmd_back, val, dev->accel.sy, len, dev->accel.dx, dev->accel.dy); 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; + if (!dev->accel.cmd_back) { + if (mach->accel.cmd_type >= 0) { + if (mach_pixel_read(mach)) + break; - 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, svga, mach, dev); + 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, svga, mach, dev); + } else + mach_accel_start(mach->accel.cmd_type, 1, 1, -1, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), svga, mach, dev); } else mach_accel_start(mach->accel.cmd_type, 1, 1, -1, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), svga, mach, dev); - } else - mach_accel_start(mach->accel.cmd_type, 1, 1, -1, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), svga, mach, dev); - 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, svga, mach, dev); - else - mach_accel_start(mach->accel.cmd_type, 1, 16, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), 0, svga, mach, dev); + 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, svga, mach, dev); + else + mach_accel_start(mach->accel.cmd_type, 1, 16, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), 0, svga, mach, dev); + } else + mach_accel_start(mach->accel.cmd_type, 1, 2, -1, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), svga, mach, dev); } else mach_accel_start(mach->accel.cmd_type, 1, 2, -1, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), svga, mach, dev); - } else - mach_accel_start(mach->accel.cmd_type, 1, 2, -1, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), svga, mach, dev); - break; + break; - default: - break; + default: + break; + } } } } @@ -2967,63 +3536,462 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u break; case 0xaae8: + if (len == 2) + mach->accel.dst_clr_cmp_mask = val; + fallthrough; case 0xaee8: case 0xb2e8: case 0xb6e8: case 0xbae8: - case 0xeae8: - case 0xeee8: - case 0xf2e8: - case 0xf6e8: - case 0xfae8: - dev->ext_fifo_idx++; ibm8514_accel_out_fifo(svga, port, val, len); break; case 0xbee8: - case 0xfee8: - dev->ext_fifo_idx++; ibm8514_accel_out_fifo(svga, port, val, len); if (len == 2) { if ((dev->accel.multifunc_cntl >> 12) == 5) { - if ((dev->local & 0xff) < 0x02) + if (!ATI_MACH32) { + dev->ext_pitch = 1024; dev->ext_crt_pitch = 128; + svga_recalctimings(svga); + } } } break; /*ATI Mach8/32 specific registers*/ + case 0x2ee: + case 0x2ef: + if (len == 2) { + mach->overscan_col_8 = val & 0xff; + mach->overscan_b_col_24 = (val >> 8) & 0xff; + } else { + if (port & 1) + mach->overscan_b_col_24 = val; + else + mach->overscan_col_8 = val; + } + svga_recalctimings(svga); + break; + case 0x6ee: + case 0x6ef: + if (len == 2) { + mach->overscan_g_col_24 = val & 0xff; + mach->overscan_r_col_24 = (val >> 8) & 0xff; + } else { + if (port & 1) + mach->overscan_r_col_24 = val; + else + mach->overscan_g_col_24 = val; + } + svga_recalctimings(svga); + break; + + case 0xaee: + case 0xaef: + WRITE8(port, mach->cursor_offset_lo_reg, val); + if (len == 2) { + WRITE8(port + 1, mach->cursor_offset_lo_reg, val >> 8); + } + mach->cursor_offset_lo = mach->cursor_offset_lo_reg; + dev->hwcursor.addr = ((mach->cursor_offset_lo | (mach->cursor_offset_hi << 16)) << 2); + if (!dev->vram_512k_8514 && ((mach->accel.ext_ge_config & 0x30) == 0x00)) + dev->hwcursor.addr <<= 1; + break; + + case 0xeee: + case 0xeef: + WRITE8(port, mach->cursor_offset_hi_reg, val); + if (len == 2) { + WRITE8(port + 1, mach->cursor_offset_hi_reg, val >> 8); + } + dev->hwcursor.ena = !!(mach->cursor_offset_hi_reg & 0x8000); + mach->cursor_offset_hi = mach->cursor_offset_hi_reg & 0x0f; + dev->hwcursor.addr = ((mach->cursor_offset_lo | (mach->cursor_offset_hi << 16)) << 2); + if (!dev->vram_512k_8514 && ((mach->accel.ext_ge_config & 0x30) == 0x00)) + dev->hwcursor.addr <<= 1; + break; + + case 0x12ee: + case 0x12ef: + WRITE8(port, mach->cursor_x, val); + if (len == 2) { + WRITE8(port + 1, mach->cursor_x, val >> 8); + } + dev->hwcursor.x = mach->cursor_x & 0x7ff; + break; + + case 0x16ee: + case 0x16ef: + WRITE8(port, mach->cursor_y, val); + if (len == 2) { + WRITE8(port + 1, mach->cursor_y, val >> 8); + } + dev->hwcursor.y = mach->cursor_y & 0xfff; + break; + + case 0x1aee: + case 0x1aef: + WRITE8(port, mach->cursor_col_b, val); + if (len == 2) { + WRITE8(port + 1, mach->cursor_col_b, val >> 8); + } + mach->cursor_col_0 = mach->cursor_col_b & 0xff; + mach->cursor_col_1 = (mach->cursor_col_b >> 8) & 0xff; + mach_log("ATI 8514/A: (0x%04x) Cursor Color B, val=0x%02x, len=%d, extended 8514/A mode bpp=%d.\n", port, val, len, dev->accel_bpp); + break; + + case 0x1eee: + case 0x1eef: + WRITE8(port, mach->cursor_vh_offset, val); + if (len == 2) { + WRITE8(port + 1, mach->cursor_vh_offset, val >> 8); + } + dev->hwcursor.xoff = mach->cursor_vh_offset & 0x3f; + dev->hwcursor.yoff = (mach->cursor_vh_offset >> 8) & 0x3f; + break; + + case 0x22ee: + if (mach->pci_bus) { + mach->pci_cntl_reg = val; + mach_log("PCI Control Reg=%02x.\n", val); + mach32_updatemapping(mach, svga); + } + break; + + case 0x26ee: + case 0x26ef: + WRITE8(port, mach->accel.crt_pitch, val); + if (len == 2) { + WRITE8(port + 1, mach->accel.crt_pitch, val >> 8); + } + + dev->ext_crt_pitch = mach->accel.crt_pitch & 0xff; + + if (dev->accel_bpp > 8) { + if (dev->accel_bpp == 24) { + dev->ext_crt_pitch *= 3; + } else if (dev->accel_bpp == 32) + dev->ext_crt_pitch <<= 2; + else + dev->ext_crt_pitch <<= 1; + } + + if (len == 2) { + dev->_8514crt = 0; + if (!(dev->accel.advfunc_cntl & 0x01) && ATI_MACH32) { + dev->on = 1; + dev->vendor_mode = 1; + } + } else + dev->_8514crt = 1; + + mach_set_resolution(mach, svga); + if (ATI_GRAPHICS_ULTRA || ATI_MACH32) + mach32_updatemapping(mach, svga); + + mach_log("ATI 8514/A: (0x%04x) CRT Pitch, val=0x%02x, crtpitch=%x, len=%d, extended 8514/A mode bpp=%d, enable_on=%d.\n", port, val, dev->ext_crt_pitch, len, dev->accel_bpp, dev->on); + break; + + case 0x2aee: + case 0x2aef: + if (len == 2) + mach->accel.crt_offset_lo = val; + else { + WRITE8(port, mach->accel.crt_offset_lo, val); + } + mach_log("ATI 8514/A: (0x%04x) CRT Offset Low val=0x%02x, len=%d.\n", port, val, len); + break; + + case 0x2eee: + case 0x2eef: + mach->accel.crt_offset_hi = val & 0x0f; + mach_log("ATI 8514/A: (0x%04x) CRT Offset High val=0x%02x, len=%d.\n", port, val, len); + break; + + case 0x32ee: + case 0x32ef: + if (len == 2) + mach->local_cntl = val; + else { + WRITE8(port, mach->local_cntl, val); + } + if (ATI_GRAPHICS_ULTRA || ATI_MACH32) + mach32_updatemapping(mach, svga); + break; + + case 0x36ee: + case 0x36ef: + if (len == 2) { + if (ATI_MACH32) + mach->misc = val; + } else { + if (ATI_MACH32) + WRITE8(port, mach->misc, val); + } + mach->misc &= 0xfff0; + break; + + case 0x3aee: + case 0x3aef: + if (len == 2) + mach->cursor_col_0_rg = val; + else { + WRITE8(port, mach->cursor_col_0_rg, val); + } + mach->ext_cur_col_0_g = mach->cursor_col_0_rg & 0xff; + mach->ext_cur_col_0_r = (mach->cursor_col_0_rg >> 8) & 0xff; + mach_log("ATI 8514/A: (0x%04x) Cursor Color 0 RG, val=0x%02x, len=%d, extended 8514/A mode bpp=%d.\n", port, val, len, dev->accel_bpp); + break; + + case 0x3eee: + case 0x3eef: + if (len == 2) + mach->cursor_col_1_rg = val; + else { + WRITE8(port, mach->cursor_col_1_rg, val); + } + mach->ext_cur_col_1_g = mach->cursor_col_1_rg & 0xff; + mach->ext_cur_col_1_r = (mach->cursor_col_1_rg >> 8) & 0xff; + mach_log("ATI 8514/A: (0x%04x) Cursor Color 1 RG, val=0x%02x, len=%d, extended 8514/A mode bpp=%d.\n", port, val, len, dev->accel_bpp); + break; + + case 0x42ee: + case 0x42ef: + if (len == 2) + mach->accel.test2 = val; + else { + WRITE8(port, mach->accel.test2, val); + } + mach_log("ATI 8514/A: (0x%04x) MEM_BNDRY val=%04x, memory part=%06x, gdcreg6=%02x.\n", port, val, (mach->accel.test2 & 0x0f) << 18, svga->gdcreg[6] & 0x0c); + mach32_updatemapping(mach, svga); + break; + + case 0x46ee: + case 0x46ef: + if (len == 2) + mach->shadow_cntl = val; + else { + WRITE8(port, mach->shadow_cntl, val); + } + mach_log("ATI 8514/A: (0x%04x) val=%02x.\n", port, val); + break; + + case 0x4aee: + case 0x4aef: + mach->old_on2 = mach->accel.clock_sel & 0x01; + WRITE8(port, mach->accel.clock_sel, val); + if (len == 2) { + WRITE8(port + 1, mach->accel.clock_sel, val >> 8); + } + dev->on = mach->accel.clock_sel & 0x01; + dev->vendor_mode = 1; + + mach_log("[%04X:%08X]: ATI 8514/A: (0x%04x): ON=%d, val=%04x, xor=%d, hdisp=%d, vdisp=%d, accelbpp=%d.\n", + CS, cpu_state.pc, port, mach->accel.clock_sel & 0x01, val, dev->on, dev->hdisp, dev->vdisp, dev->accel_bpp); + mach_log("Vendor ATI mode set %s resolution.\n", + (dev->accel.advfunc_cntl & 0x04) ? "2: 1024x768" : "1: 640x480"); + + mach_set_resolution(mach, svga); + if (ATI_GRAPHICS_ULTRA || ATI_MACH32) + mach32_updatemapping(mach, svga); + break; + + case 0x52ee: + case 0x52ef: + mach_log("ATI 8514/A: (0x%04x) ScratchPad0 val=%04x.\n", port, val); + if (len == 2) + mach->accel.scratch0 = val; + else { + WRITE8(port, mach->accel.scratch0, val); + } + break; + + case 0x56ee: + case 0x56ef: + mach_log("ATI 8514/A: (0x%04x) ScratchPad1 val=%04x.\n", port, val); + if (len == 2) + mach->accel.scratch1 = val; + else { + WRITE8(port, mach->accel.scratch1, val); + } + break; + + case 0x5aee: + case 0x5aef: + WRITE8(port, mach->shadow_set, val); + if (len == 2) { + WRITE8(port + 1, mach->shadow_set, val >> 8); + } + mach_log("ATI 8514/A: (0x%04x) val=0x%02x, len=%d.\n", port, val, len); + if ((mach->shadow_set & 0x03) == 0x00) + mach_log("Primary CRT register set.\n"); + else if ((mach->shadow_set & 0x03) == 0x01) + mach_log("CRT Shadow Set 1: 640x480.\n"); + else if ((mach->shadow_set & 0x03) == 0x02) + mach_log("CRT Shadow Set 2: 1024x768.\n"); + break; + + case 0x5eee: + case 0x5eef: + if (len == 2) + mach->memory_aperture = val; + else { + WRITE8(port, mach->memory_aperture, val); + } + mach_log("Memory Aperture = %04x.\n", mach->memory_aperture); + if (!mach->pci_bus) + mach->linear_base = (mach->memory_aperture & 0xff00) << 12; + + if (ATI_GRAPHICS_ULTRA || ATI_MACH32) + mach32_updatemapping(mach, svga); + break; + + case 0x6aee: + case 0x6aef: + if (len == 2) + mach->accel.max_waitstates = val; + else { + WRITE8(port, mach->accel.max_waitstates, val); + } + break; + + case 0x6eee: + case 0x6eef: + if (len == 2) + mach->accel.ge_offset_lo = val; + else { + WRITE8(port, mach->accel.ge_offset_lo, val); + } + mach_log("ATI 8514/A: (0x%04x) GE Offset Low val=0x%02x, geoffset=%04x, len=%d.\n", port, val, dev->accel.ge_offset, len); + svga_recalctimings(svga); + break; + + case 0x72ee: + case 0x72ef: + if (len == 2) + mach->accel.ge_offset_hi = val; + else { + WRITE8(port, mach->accel.ge_offset_hi, val); + } + mach_log("ATI 8514/A: (0x%04x) GE Offset High val=0x%02x, geoffset=%04x, len=%d.\n", port, val, dev->accel.ge_offset, len); + svga_recalctimings(svga); + break; + + case 0x76ee: + case 0x76ef: + if (len == 2) + mach->accel.ge_pitch = val; + else { + WRITE8(port, mach->accel.ge_pitch, val); + } + dev->ext_pitch = ((mach->accel.ge_pitch & 0xff) << 3); + mach_log("ATI 8514/A: (0x%04x) GE Pitch val=0x%02x.\n", port, val); + svga_recalctimings(svga); + break; + + case 0x7aee: + case 0x7aef: + WRITE8(port, mach->accel.ext_ge_config, val); + if (len == 2) { + WRITE8(port + 1, mach->accel.ext_ge_config, val >> 8); + } + + if (ATI_MACH32) { + if (mach->accel.crt_pitch & 0xff) + dev->ext_crt_pitch = mach->accel.crt_pitch & 0xff; + + switch (mach->accel.ext_ge_config & 0x30) { + case 0x00: + case 0x10: + dev->bpp = 0; + dev->accel_bpp = 8; + break; + case 0x20: + dev->bpp = 1; + dev->ext_crt_pitch <<= 1; + switch (mach->accel.ext_ge_config & 0xc0) { + case 0x00: + dev->accel_bpp = 15; + break; + case 0x40: + dev->accel_bpp = 16; + break; + default: /*TODO: 655RGB and 664RGB*/ + break; + } + break; + case 0x30: + dev->bpp = 0; + if (mach->accel.ext_ge_config & 0x200) { + dev->ext_crt_pitch <<= 2; + dev->accel_bpp = 32; + } else { + dev->ext_crt_pitch *= 3; + dev->accel_bpp = 24; + } + break; + + default: + break; + } + svga_set_ramdac_type(svga, !!(mach->accel.ext_ge_config & 0x4000)); + mach_log("ATI 8514/A: (0x%04x) Extended Configuration=%04x, val=%04x.\n", port, mach->accel.ext_ge_config, val); + mach_set_resolution(mach, svga); + mach32_updatemapping(mach, svga); + } else + ati_eeprom_write(&mach->eeprom, !!(mach->accel.ext_ge_config & 0x04), !!(mach->accel.ext_ge_config & 0x02), !!(mach->accel.ext_ge_config & 0x01)); + break; + + case 0x7eee: + case 0x7eef: + if (len == 2) + mach->accel.eeprom_control = val; + else { + WRITE8(port, mach->accel.eeprom_control, val); + } + mach_log("%04X write val=%04x, actual=%04x, len=%d.\n", port, mach->accel.eeprom_control, val, len); + break; + case 0x82ee: - dev->ext_fifo_idx++; mach->accel.patt_data_idx_reg = val & 0x1f; mach->accel.patt_data_idx = mach->accel.patt_data_idx_reg; + mach_log("Write Port 82ee: Pattern Data Index=%d, idx for color=%d.\n", val & 0x1f, mach->accel.color_pattern_idx); + if (mach->accel.patt_data_idx_reg < 0x10) mach->accel.color_pattern_idx = mach->accel.patt_idx; else mach->accel.color_pattern_idx = 0; - - mach_log("Write Port 82ee: Pattern Data Index=%d.\n", val & 0x1f); break; case 0x8eee: - dev->ext_fifo_idx++; if (len == 2) { if (mach->accel.patt_data_idx_reg < 0x10) { - mach->accel.color_pattern[mach->accel.patt_data_idx] = val & 0xff; - mach->accel.color_pattern[mach->accel.patt_data_idx + 1] = (val >> 8) & 0xff; - mach_log("Write Port 8eee: Color Pattern Word Data[%d]=%04x.\n", mach->accel.patt_data_idx, val); + if (dev->bpp) { + mach->accel.color_pattern_hicol[mach->accel.patt_data_idx] = val; + mach_log("Write Port 8eee: Color Pattern Word Data[%d]=%04x.\n", mach->accel.patt_data_idx, val); + mach->accel.patt_data_idx++; + } else { + mach->accel.color_pattern[mach->accel.patt_data_idx] = val & 0xff; + mach->accel.color_pattern[mach->accel.patt_data_idx + 1] = (val >> 8) & 0xff; + mach_log("Write Port 8eee: Color Pattern Word Data[%d]=%04x.\n", mach->accel.patt_data_idx, val); + mach->accel.patt_data_idx += 2; + } } else { mach->accel.mono_pattern_normal[mach->accel.patt_data_idx - 0x10] = val & 0xff; mach->accel.mono_pattern_normal[(mach->accel.patt_data_idx + 1) - 0x10] = (val >> 8) & 0xff; mach_log("Write Port 8eee: Mono Pattern Word Data[%d]=%04x.\n", mach->accel.patt_data_idx - 0x10, val); + mach->accel.patt_data_idx += 2; } - mach->accel.patt_data_idx += 2; } break; + case 0x92ee: + mach_log("Write port 92ee, malatch=%08x.\n", svga->memaddr_latch); + break; + case 0x96ee: - dev->ext_fifo_idx++; if (len == 2) { mach->accel.bres_count = val & 0x7ff; mach_log("BresenhamDraw=%04x.\n", mach->accel.dp_config); @@ -3043,12 +4011,10 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u break; case 0x9aee: - dev->ext_fifo_idx++; mach->accel.line_idx = val & 0x07; break; case 0xa2ee: - dev->ext_fifo_idx++; mach_log("Line OPT=%04x.\n", val); if (len == 2) { mach->accel.linedraw_opt = val; @@ -3066,19 +4032,16 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u break; case 0xa6ee: - dev->ext_fifo_idx++; if (len == 2) mach->accel.dest_x_start = val & 0x7ff; break; case 0xaaee: - dev->ext_fifo_idx++; if (len == 2) mach->accel.dest_x_end = val & 0x7ff; break; case 0xaeee: - dev->ext_fifo_idx++; if (len == 2) { mach->accel.dest_y_end = val & 0x7ff; if ((val + 1) == 0x10000) { @@ -3087,7 +4050,7 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u } dev->data_available = 0; dev->data_available2 = 0; - mach_log("BitBLT=%04x.\n", mach->accel.dp_config); + mach_log("BitBLT=%04x, pattidx=%d.\n", mach->accel.dp_config, mach->accel.patt_idx); mach_log(".\n"); mach->accel.cmd_type = 2; /*Non-conforming BitBLT from dest_y_end register (0xaeee)*/ @@ -3104,34 +4067,30 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u break; case 0xb2ee: - dev->ext_fifo_idx++; if (len == 2) mach->accel.src_x_start = val & 0x7ff; break; case 0xb6ee: - dev->ext_fifo_idx++; - dev->accel.bkgd_mix = val & 0xff; + dev->accel.bkgd_mix = val & 0x1f; + dev->accel.bkgd_sel = (mach->accel.dp_config >> 7) & 3; break; case 0xbaee: - dev->ext_fifo_idx++; - dev->accel.frgd_mix = val & 0xff; + dev->accel.frgd_mix = val & 0x1f; + dev->accel.frgd_sel = (mach->accel.dp_config >> 13) & 3; break; case 0xbeee: - dev->ext_fifo_idx++; if (len == 2) mach->accel.src_x_end = val & 0x7ff; break; case 0xc2ee: - dev->ext_fifo_idx++; mach->accel.src_y_dir = val & 1; break; case 0xc6ee: - dev->ext_fifo_idx++; if (len == 2) { mach->accel.cmd_type = 0; mach_log("TODO: Short Stroke.\n"); @@ -3146,7 +4105,6 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u break; case 0xcaee: - dev->ext_fifo_idx++; if (len == 2) { mach->accel.scan_to_x = (val & 0x7ff); if ((val + 1) == 0x10000) { @@ -3156,7 +4114,7 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u 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_log("ScanToX len=%d.\n", val); mach_log(".\n"); frgd_sel = (mach->accel.dp_config >> 13) & 7; @@ -3167,13 +4125,13 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u if ((mono_src == 2) || (bkgd_sel == 2) || (frgd_sel == 2) || mach_pixel_read(mach)) dev->accel.cmd_back = 0; + mach_log("ScanToX=%04x, mono_src=%d, bkgd_sel=%d, frgd_sel=%d, pixread=%x.\n", mach->accel.dp_config, mono_src, bkgd_sel, frgd_sel, mach_pixel_read(mach)); mach_accel_start(mach->accel.cmd_type, 0, -1, -1, 0, svga, mach, dev); } break; case 0xceee: - dev->ext_fifo_idx++; - mach_log("CEEE write val = %04x.\n", val); + mach_log("Data Path Configuration (%04x) write val=%04x, len=%d.\n", port, val, len); if (len == 2) { dev->data_available = 0; dev->data_available2 = 0; @@ -3182,7 +4140,6 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u break; case 0xd2ee: - dev->ext_fifo_idx++; mach->accel.patt_len = val & 0x1f; mach_log("Write Port d2ee: Pattern Length=%d, val=%04x.\n", val & 0x1f, val); mach->accel.mono_pattern_enable = !!(val & 0x80); @@ -3193,13 +4150,16 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u break; case 0xd6ee: - dev->ext_fifo_idx++; mach->accel.patt_idx = val & 0x1f; + frgd_sel = (mach->accel.dp_config >> 13) & 7; + + if ((frgd_sel == 5) && (dev->accel_bpp >= 24) && (mach->accel.patt_len == 0x17)) + mach->accel.color_pattern_idx = 0; + mach_log("Write Port d6ee: Pattern Index=%d.\n", val & 0x1f); break; case 0xdaee: - dev->ext_fifo_idx++; if (len == 2) { dev->accel.multifunc[2] = val & 0x7ff; dev->accel.clip_left = dev->accel.multifunc[2]; @@ -3210,7 +4170,6 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u break; case 0xdeee: - dev->ext_fifo_idx++; if (len == 2) { dev->accel.multifunc[1] = val & 0x7ff; dev->accel.clip_top = dev->accel.multifunc[1]; @@ -3222,7 +4181,6 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u break; case 0xe2ee: - dev->ext_fifo_idx++; if (len == 2) { dev->accel.multifunc[4] = val & 0x7ff; dev->accel.clip_right = dev->accel.multifunc[4]; @@ -3233,7 +4191,6 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u break; case 0xe6ee: - dev->ext_fifo_idx++; if (len == 2) { dev->accel.multifunc[3] = val & 0x7ff; dev->accel.clip_bottom = dev->accel.multifunc[3]; @@ -3244,23 +4201,21 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u break; case 0xeeee: - dev->ext_fifo_idx++; + mach_log("EEEE val=%04x, len=%d.\n", val, len); if (len == 2) mach->accel.dest_cmp_fn = val; break; case 0xf2ee: - dev->ext_fifo_idx++; - mach_log("F2EE.\n"); + mach_log("F2EE val=%04x, len=%d.\n", val, len); if (len == 2) mach->accel.dst_clr_cmp_mask = val; break; case 0xfeee: - dev->ext_fifo_idx++; - mach_log("LineDraw=%04x.\n", mach->accel.dp_config); if (len == 2) { mach->accel.line_array[mach->accel.line_idx] = val; + mach_log("mach->accel.line_array[%02X] = %04X\n", 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]; @@ -3275,6 +4230,10 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u if ((mono_src == 2) || (bkgd_sel == 2) || (frgd_sel == 2) || mach_pixel_read(mach)) dev->accel.cmd_back = 0; + if ((mach->accel.cmd_type == 3) && !dev->accel.cmd_back && (mach->accel.dp_config == 0x0000)) /*Avoid a hang with a dummy command.*/ + dev->accel.cmd_back = 1; + + mach_log("LineDraw type=%x, dpconfig=%04x.\n", mach->accel.cmd_type, mach->accel.dp_config); mach_accel_start(mach->accel.cmd_type, 0, -1, -1, 0, svga, mach, dev); mach->accel.line_idx = (mach->accel.line_idx == 5) ? 4 : 2; break; @@ -3284,389 +4243,11 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u break; default: + mach_log("Unknown or reserved write to %04x, val=%04x, len=%d, latch=%08x.\n", port, val, len, svga->memaddr_latch); break; } } -static void -mach_accel_out_call(uint16_t port, uint8_t val, mach_t *mach, svga_t *svga, ibm8514_t *dev) -{ - if (port != 0x42e8 && port != 0x42e9) - mach_log("[%04X:%08X]: Port CALL OUT=%04x, val=%02x.\n", CS, cpu_state.pc, port, val); - - switch (port) { - case 0x2e8: - case 0x6e9: - case 0xae8: - case 0xee8: - case 0x1ee8: - case 0x1ee9: - case 0x42e8: - ibm8514_accel_out(port, val, svga, 2); - break; - case 0x42e9: - ibm8514_accel_out(port, val, svga, 2); - if ((val & 0xc0) == 0xc0) { - dev->ext_fifo_idx = 0; - mach->force_busy = 0; - } - break; - - case 0x6e8: - /*In preparation to switch from VGA to 8514/A mode*/ - if (!(mach->shadow_cntl & 0x08)) { - if ((mach->shadow_set & 0x03) || (mach->accel.clock_sel & 0x01)) { - dev->hdisped = val; - dev->hdisp = (val + 1) << 3; - } else if (((mach->shadow_set & 0x03) == 0x00) && !(mach->accel.clock_sel & 0x01)) - dev->hdisp2 = (val + 1) << 3; - } - mach_log("[%04X:%08X]: ATI 8514/A: (0x%04x): hdisp=0x%02x, shadowcntl=%02x, shadowset=%02x.\n", CS, cpu_state.pc, port, val, mach->shadow_cntl & 0x08, mach->shadow_set & 0x03); - svga_recalctimings(svga); - break; - - case 0x12e8: - case 0x12e9: - /*In preparation to switch from VGA to 8514/A mode*/ - if (!(mach->shadow_cntl & 0x10)) { - if ((mach->shadow_set & 0x03) || (mach->accel.clock_sel & 0x01) || - (((mach->shadow_set & 0x03) == 0x00) && !(mach->accel.clock_sel & 0x01))) { - WRITE8(port, dev->v_total_reg, val); - dev->v_total_reg &= 0x1fff; - dev->v_total = dev->v_total_reg + 1; - if (dev->interlace) - dev->v_total >>= 1; - } - } - mach_log("[%04X:%08X]: ATI 8514/A: (0x%04x): hdisp=0x%02x.\n", CS, cpu_state.pc, port, val); - svga_recalctimings(svga); - break; - - case 0x16e8: - case 0x16e9: - /*In preparation to switch from VGA to 8514/A mode*/ - if (!(mach->shadow_cntl & 0x20)) { - if ((mach->shadow_set & 0x03) || (mach->accel.clock_sel & 0x01)) { - WRITE8(port, dev->v_disp, val); - dev->v_disp &= 0x1fff; - dev->vdisp = (dev->v_disp + 1) >> 1; - if ((dev->vdisp == 478) || (dev->vdisp == 598) || (dev->vdisp == 766) || (dev->vdisp == 1022)) - dev->vdisp += 2; - } else if (((mach->shadow_set & 0x03) == 0x00) && !(mach->accel.clock_sel & 0x01)) { - WRITE8(port, dev->v_disp2, val); - dev->v_disp2 &= 0x1fff; - dev->vdisp2 = (dev->v_disp2 + 1) >> 1; - if ((dev->vdisp2 == 478) || (dev->vdisp2 == 598) || (dev->vdisp2 == 766) || (dev->vdisp2 == 1022)) - dev->vdisp2 += 2; - } - } - mach_log("ATI 8514/A: V_DISP write 16E8=%d, vdisp2=%d.\n", dev->v_disp, dev->v_disp2); - mach_log("ATI 8514/A: (0x%04x): vdisp=0x%02x.\n", port, val); - svga_recalctimings(svga); - break; - - case 0x1ae8: - case 0x1ae9: - /*In preparation to switch from VGA to 8514/A mode*/ - if (!(mach->shadow_cntl & 0x10)) { - if ((mach->shadow_set & 0x03) || (mach->accel.clock_sel & 0x01) || - (((mach->shadow_set & 0x03) == 0x00) && !(mach->accel.clock_sel & 0x01))) { - WRITE8(port, dev->v_sync_start, val); - dev->v_sync_start &= 0x1fff; - dev->v_syncstart = dev->v_sync_start + 1; - if (dev->interlace) - dev->v_syncstart >>= 1; - } - } - mach_log("ATI 8514/A: V_SYNCSTART write 1AE8 = %d\n", dev->v_syncstart); - mach_log("ATI 8514/A: (0x%04x): vsyncstart=0x%02x.\n", port, val); - svga_recalctimings(svga); - break; - - case 0x22e8: - if (!(mach->shadow_cntl & 0x03)) { - if ((mach->shadow_set & 0x03) || (mach->accel.clock_sel & 0x01) || - (((mach->shadow_set & 0x03) == 0x00) && !(mach->accel.clock_sel & 0x01))) { - dev->disp_cntl = val; - dev->interlace = !!(dev->disp_cntl & 0x10); - } - } - mach_log("ATI 8514/A: DISP_CNTL write %04x=%02x, written=%02x, interlace=%d.\n", port, val & 0x70, dev->disp_cntl & 0x70, dev->interlace); - svga_recalctimings(svga); - break; - - case 0x4ae8: - dev->accel.advfunc_cntl = val; - dev->on = dev->accel.advfunc_cntl & 0x01; - dev->vendor_mode = 0; - mach_log("[%04X:%08X]: ATI 8514/A: (0x%04x): ON=%d, shadow crt=%x, hdisp=%d, vdisp=%d.\n", CS, cpu_state.pc, port, val & 0x01, dev->accel.advfunc_cntl & 0x04, dev->hdisp, dev->vdisp); - - if ((dev->local & 0xff) < 0x02) { - dev->ext_crt_pitch = 128; - svga_recalctimings(svga); - } else { - svga_recalctimings(svga); - mach32_updatemapping(mach, svga); - } - mach_log("Vendor IBM mode set %s resolution.\n", (dev->accel.advfunc_cntl & 0x04) ? "2: 1024x768" : "1: 640x480"); - break; - - /*ATI Mach8/32 specific registers*/ - case 0x2ee: - mach_log("2EE write val = %02x.\n", val); - break; - case 0x2ef: - mach_log("2EF write val = %02x.\n", val); - break; - - case 0x6ee: - mach_log("6EE write val = %02x.\n", val); - break; - case 0x6ef: - mach_log("6EF write val = %02x.\n", val); - break; - - case 0xaee: - case 0xaef: - WRITE8(port, mach->cursor_offset_lo_reg, val); - mach->cursor_offset_lo = mach->cursor_offset_lo_reg; - dev->hwcursor.addr = ((mach->cursor_offset_lo | (mach->cursor_offset_hi << 16)) << 2); - break; - - case 0xeee: - case 0xeef: - WRITE8(port, mach->cursor_offset_hi_reg, val); - mach->cursor_offset_hi = mach->cursor_offset_hi_reg & 0x0f; - dev->hwcursor.addr = ((mach->cursor_offset_lo | (mach->cursor_offset_hi << 16)) << 2); - dev->hwcursor.ena = !!(mach->cursor_offset_hi_reg & 0x8000); - mach_log("HWCursorEnabled=%x.\n", dev->hwcursor.ena); - break; - - case 0x12ee: - case 0x12ef: - WRITE8(port, mach->cursor_x, val); - dev->hwcursor.x = mach->cursor_x & 0x7ff; - break; - - case 0x16ee: - case 0x16ef: - WRITE8(port, mach->cursor_y, val); - dev->hwcursor.y = mach->cursor_y & 0xfff; - break; - - case 0x1aee: - case 0x1aef: - WRITE8(port, mach->cursor_col_b, val); - mach->cursor_col_0 = mach->cursor_col_b & 0xff; - mach->cursor_col_1 = (mach->cursor_col_b >> 8) & 0xff; - break; - - case 0x1eee: - case 0x1eef: - WRITE8(port, mach->cursor_vh_offset, val); - dev->hwcursor.xoff = mach->cursor_vh_offset & 0x3f; - dev->hwcursor.yoff = (mach->cursor_vh_offset >> 8) & 0x3f; - break; - - case 0x22ee: - if (mach->pci_bus) { - mach->pci_cntl_reg = val; - mach_log("PCI Control Reg=%02x.\n", val); - mach32_updatemapping(mach, svga); - } - break; - - case 0x26ee: - case 0x26ef: - WRITE8(port, mach->accel.crt_pitch, val); - dev->ext_crt_pitch = mach->accel.crt_pitch & 0xff; - if (dev->accel_bpp > 8) { - if (dev->accel_bpp == 24) - dev->ext_crt_pitch *= 3; - else if (dev->accel_bpp == 32) - dev->ext_crt_pitch <<= 2; - else - dev->ext_crt_pitch <<= 1; - } - if ((dev->local & 0xff) >= 0x02) { - dev->on |= 0x01; - dev->vendor_mode = 1; - } - svga_recalctimings(svga); - mach32_updatemapping(mach, svga); - mach_log("ATI 8514/A: (0x%04x) val=0x%02x, extended 8514/A mode=%02x.\n", port, val, mach->regs[0xb0] & 0x20); - break; - - case 0x32ee: - case 0x32ef: - WRITE8(port, mach->local_cntl, val); - mach32_updatemapping(mach, svga); - break; - - case 0x36ee: - case 0x36ef: - mach_log("ATI 8514/A: (0x%04x) val = %04x.\n", port, val); - if ((dev->local & 0xff) >= 0x02) { - WRITE8(port, mach->misc, val); - mach->misc &= 0xfff0; - } - break; - - case 0x3aee: - case 0x3aef: - WRITE8(port, mach->cursor_col_0_rg, val); - mach->ext_cur_col_0_g = mach->cursor_col_0_rg & 0xff; - mach->ext_cur_col_0_r = (mach->cursor_col_0_rg >> 8) & 0xff; - break; - - case 0x3eee: - case 0x3eef: - WRITE8(port, mach->cursor_col_1_rg, val); - mach->ext_cur_col_1_g = mach->cursor_col_1_rg & 0xff; - mach->ext_cur_col_1_r = (mach->cursor_col_1_rg >> 8) & 0xff; - break; - - case 0x42ee: - case 0x42ef: - mach_log("ATI 8514/A: (0x%04x) val=%04x.\n", port, val); - WRITE8(port, mach->accel.test2, val); - break; - - case 0x46ee: - case 0x46ef: - WRITE8(port, mach->shadow_cntl, val); - mach_log("ATI 8514/A: (0x%04x) val=%02x.\n", port, val); - break; - - case 0x4aee: - case 0x4aef: - WRITE8(port, mach->accel.clock_sel, val); - dev->on = mach->accel.clock_sel & 0x01; - dev->vendor_mode = 1; - mach_log("ATI 8514/A: (0x%04x): ON=%d, val=%04x, hdisp=%d, vdisp=%d.\n", port, mach->accel.clock_sel & 0x01, val, dev->hdisp, dev->vdisp); - mach_log("Vendor ATI mode set %s resolution.\n", (dev->accel.advfunc_cntl & 0x04) ? "2: 1024x768" : "1: 640x480"); - svga_recalctimings(svga); - mach32_updatemapping(mach, svga); - break; - - case 0x52ee: - case 0x52ef: - mach_log("ATI 8514/A: (0x%04x) val=%04x.\n", port, val); - WRITE8(port, mach->accel.scratch0, val); - break; - - case 0x56ee: - case 0x56ef: - mach_log("ATI 8514/A: (0x%04x) val=%04x.\n", port, val); - WRITE8(port, mach->accel.scratch1, val); - break; - - case 0x5aee: - case 0x5aef: - WRITE8(port, mach->shadow_set, val); - mach_log("ATI 8514/A: (0x%04x) val=0x%02x.\n", port, val); - if ((mach->shadow_set & 0x03) == 0x00) - mach_log("Primary CRT register set.\n"); - else if ((mach->shadow_set & 0x03) == 0x01) - mach_log("CRT Shadow Set 1: 640x480.\n"); - else if ((mach->shadow_set & 0x03) == 0x02) - mach_log("CRT Shadow Set 2: 1024x768.\n"); - break; - - case 0x5eee: - case 0x5eef: - WRITE8(port, mach->memory_aperture, val); - mach_log("Memory Aperture = %04x.\n", mach->memory_aperture); - if (!mach->pci_bus) - mach->linear_base = (mach->memory_aperture & 0xff00) << 12; - - mach32_updatemapping(mach, svga); - 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: - case 0x6aef: - WRITE8(port, mach->accel.max_waitstates, val); - break; - - case 0x6eee: - case 0x6eef: - WRITE8(port, mach->accel.ge_offset_lo, val); - svga_recalctimings(svga); - mach_log("ATI 8514/A: (0x%04x) val=0x%02x, geoffset=%04x.\n", port, val, dev->accel.ge_offset); - break; - - case 0x72ee: - case 0x72ef: - WRITE8(port, mach->accel.ge_offset_hi, val); - svga_recalctimings(svga); - mach_log("ATI 8514/A: (0x%04x) val=0x%02x, geoffset=%04x.\n", port, val, dev->accel.ge_offset); - break; - - case 0x76ee: - case 0x76ef: - WRITE8(port, mach->accel.ge_pitch, val); - dev->ext_pitch = ((mach->accel.ge_pitch & 0xff) << 3); - mach_log("ATI 8514/A: (0x%04x) val=0x%02x, extpitch=%d.\n", port, val, dev->ext_pitch); - svga_recalctimings(svga); - break; - - case 0x7aee: - case 0x7aef: - WRITE8(port, mach->accel.ext_ge_config, val); - if ((dev->local & 0xff) >= 0x02) { - if (mach->accel.crt_pitch & 0xff) - dev->ext_crt_pitch = mach->accel.crt_pitch & 0xff; - - switch (mach->accel.ext_ge_config & 0x30) { - case 0x00: - case 0x10: - dev->bpp = 0; - break; - case 0x20: - dev->bpp = 1; - dev->ext_crt_pitch <<= 1; - break; - case 0x30: - dev->bpp = 0; - if (mach->accel.ext_ge_config & 0x200) - dev->ext_crt_pitch <<= 2; - else - dev->ext_crt_pitch *= 3; - break; - - default: - break; - } - svga_set_ramdac_type(svga, !!(mach->accel.ext_ge_config & 0x4000)); - mach_log("ATI 8514/A: (0x%04x) val=%02x.\n", port, val); - svga_recalctimings(svga); - } else - ati_eeprom_write(&mach->eeprom, !!(mach->accel.ext_ge_config & 0x4000), !!(mach->accel.ext_ge_config & 0x2000), !!(mach->accel.ext_ge_config & 0x1000)); - break; - - default: - break; - } -} - -static void -mach_accel_out(uint16_t port, uint8_t val, mach_t *mach) -{ - svga_t *svga = &mach->svga; - - mach_log("[%04X:%08X]: Port NORMAL OUT=%04x, val=%04x.\n", CS, cpu_state.pc, port, val); - - mach_accel_out_call(port, val, mach, svga, (ibm8514_t *) svga->dev8514); -} - static uint16_t mach_accel_in_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, int len) { @@ -3679,7 +4260,19 @@ mach_accel_in_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, in switch (port) { case 0x82e8: + if ((mach->accel.cmd_type == 3) || (mach->accel.cmd_type == 4)) + temp = mach->accel.cy_end_line; + else + temp = ibm8514_accel_in_fifo(svga, port, len); + break; + case 0x86e8: + if ((mach->accel.cmd_type == 3) || (mach->accel.cmd_type == 4)) + temp = mach->accel.cx_end_line; + else + temp = ibm8514_accel_in_fifo(svga, port, len); + break; + case 0x92e8: case 0x96e8: case 0xc2e8: @@ -3689,18 +4282,57 @@ mach_accel_in_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, in case 0x9ae8: case 0xdae8: - if ((dev->fifo_idx >= 1) && (dev->fifo_idx <= 8)) { - temp |= (1 << (dev->fifo_idx - 1)); - dev->fifo_idx = 0; - } - if (len == 2) { - if (dev->force_busy) - temp |= 0x200; /*Hardware busy*/ + if (dev->fifo_idx <= 8) { + for (int i = 1; i <= dev->fifo_idx; i++) + temp |= (1 << (7 - (i - 1))); + } else + temp = 0x00ff; + + if (dev->fifo_idx > 0) + dev->fifo_idx--; + + if (dev->force_busy) { + temp |= 0x0200; /*Hardware busy*/ + if (mach->accel.cmd_type >= 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.cmd_type) { + case 2: + if (dev->accel.sy >= mach->accel.height) + dev->force_busy = 0; + else if ((mono_src == 2) || (frgd_sel == 2) || (bkgd_sel == 2)) + dev->force_busy = 0; + break; + case 5: + if (dev->accel.sx >= mach->accel.width) + dev->force_busy = 0; + break; + default: + if (dev->accel.sy < 0) + dev->force_busy = 0; + break; + } + } else { + switch (dev->accel.cmd >> 13) { + case 2: + case 3: + case 4: + case 6: + if (dev->accel.sy < 0) + dev->force_busy = 0; + break; + default: + if (!dev->accel.sy) + dev->force_busy = 0; + break; + } + } + } - dev->force_busy = 0; if (dev->data_available) { - temp |= 0x100; /*Read Data available*/ + temp |= 0x0100; /*Read Data available*/ if (mach->accel.cmd_type >= 0) { switch (mach->accel.cmd_type) { case 2: @@ -3738,10 +4370,13 @@ mach_accel_in_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, in case 0x9ae9: case 0xdae9: if (len == 1) { + dev->fifo_idx = 0; + if (dev->force_busy2) temp |= 0x02; /*Hardware busy*/ dev->force_busy2 = 0; + if (dev->data_available2) { temp |= 0x01; /*Read Data available*/ if (mach->accel.cmd_type >= 0) { @@ -3760,8 +4395,19 @@ mach_accel_in_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, in break; } } else { - if (dev->accel.sy < 0) - dev->data_available2 = 0; + switch (dev->accel.cmd >> 13) { + case 2: + case 3: + case 4: + case 6: + if (dev->accel.sy < 0) + dev->data_available2 = 0; + break; + default: + if (!dev->accel.sy) + dev->data_available2 = 0; + break; + } } } } @@ -3777,7 +4423,7 @@ mach_accel_in_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, in READ_PIXTRANS_BYTE_IO(dev->accel.dx, 1) temp = mach->accel.pix_trans[1]; } else { - if (mach->accel.cmd_type == 3) { + if ((mach->accel.cmd_type == 3) || (mach->accel.cmd_type == 4)) { READ_PIXTRANS_WORD(dev->accel.cx, 0) } else { READ_PIXTRANS_WORD(dev->accel.dx, 0) @@ -3790,7 +4436,7 @@ mach_accel_in_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, in cmd = (dev->accel.cmd >> 13); if (len == 2) { READ_PIXTRANS_WORD(dev->accel.cx, 0) - if (dev->subsys_stat & 0x01) { + if (dev->subsys_stat & INT_VSY) { dev->force_busy = 1; dev->data_available = 1; } @@ -3864,10 +4510,10 @@ mach_accel_in_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, in break; case 0x8eee: - if (len == 1) - temp = mach->accel.ext_ge_config & 0xff; - else + if (len == 2) temp = mach->accel.ext_ge_config; + else + temp = mach->accel.ext_ge_config & 0xff; mach_log("ExtGE Read = %04x, len=%d.\n", temp, len); break; @@ -3877,10 +4523,10 @@ mach_accel_in_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, in break; case 0x92ee: - if (len == 1) - temp = mach->accel.eeprom_control & 0xff; - else + if (len == 2) temp = mach->accel.eeprom_control; + else + temp = mach->accel.eeprom_control & 0xff; mach_log("EEPROM cntl read=%04x, len=%d.\n", temp, len); break; @@ -3892,10 +4538,10 @@ mach_accel_in_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, in break; case 0x96ee: - if (len == 1) - temp = mach->accel.test & 0xff; - else + if (len == 2) temp = mach->accel.test; + else + temp = mach->accel.test & 0xff; break; case 0x96ef: if (len == 1) @@ -3904,18 +4550,22 @@ mach_accel_in_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, in case 0x9aee: if (len == 2) { - if ((dev->ext_fifo_idx >= 1) && (dev->ext_fifo_idx <= 16)) { - temp |= (1 << (dev->ext_fifo_idx - 1)); - dev->ext_fifo_idx = 0; - } + if (dev->fifo_idx <= 16) { + for (int i = 1; i <= dev->fifo_idx; i++) + temp |= (1 << (15 - (i - 1))); + } else + temp = 0xffff; + + if (dev->fifo_idx > 0) + dev->fifo_idx--; } break; case 0xa2ee: - if (len == 1) - temp = mach->accel.linedraw_opt & 0xff; - else + if (len == 2) temp = mach->accel.linedraw_opt; + else + temp = mach->accel.linedraw_opt & 0xff; break; case 0xa2ef: if (len == 1) @@ -3923,11 +4573,11 @@ mach_accel_in_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, in break; case 0xb2ee: - if (len == 1) - temp = dev->hdisped; - else { + if (len == 2) { temp = dev->hdisped & 0xff; temp |= (dev->htotal << 8); + } else { + temp = dev->hdisped; } mach_log("B2EE read=%02x.\n", temp & 0xff); break; @@ -3945,12 +4595,10 @@ mach_accel_in_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, in break; case 0xc2ee: - if (len == 1) - temp = dev->v_total_reg & 0xff; - else { + if (len == 2) temp = dev->v_total_reg; - mach_log("VTOTAL read=%d.\n", temp); - } + else + temp = dev->v_total_reg & 0xff; break; case 0xc2ef: if (len == 1) @@ -3958,12 +4606,10 @@ mach_accel_in_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, in break; case 0xc6ee: - if (len == 1) - temp = dev->v_disp & 0xff; - else { + if (len == 2) temp = dev->v_disp; - mach_log("VDISP read=%d.\n", temp); - } + else + temp = dev->v_disp & 0xff; break; case 0xc6ef: if (len == 1) @@ -3971,10 +4617,10 @@ mach_accel_in_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, in break; case 0xcaee: - if (len == 1) - temp = dev->v_sync_start & 0xff; - else + if (len == 2) temp = dev->v_sync_start; + else + temp = dev->v_sync_start & 0xff; break; case 0xcaef: if (len == 1) @@ -3983,10 +4629,10 @@ mach_accel_in_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, in case 0xceee: mach_log("CEEE read=%d.\n", len); - if (len == 1) - temp = dev->vc & 0xff; - else + if (len == 2) temp = dev->vc & 0x7ff; + else + temp = dev->vc & 0xff; break; case 0xceef: mach_log("CEEF read=%d.\n", len); @@ -3996,44 +4642,46 @@ mach_accel_in_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, in case 0xdaee: if (len == 2) { - if ((dev->local & 0xff) >= 0x02) + if (ATI_MACH32) temp = mach->accel.src_x; } else { - if ((dev->local & 0xff) >= 0x02) + if (ATI_MACH32) temp = mach->accel.src_x & 0xff; } break; case 0xdaef: if (len == 1) { - if ((dev->local & 0xff) >= 0x02) + if (ATI_MACH32) temp = mach->accel.src_x >> 8; } break; case 0xdeee: if (len == 2) { - if ((dev->local & 0xff) >= 0x02) + if (ATI_MACH32) temp = mach->accel.src_y; - } else - temp = mach->accel.src_y & 0xff; + } else { + if (ATI_MACH32) + temp = mach->accel.src_y & 0xff; + } break; case 0xdeef: if (len == 1) { - if ((dev->local & 0xff) >= 0x02) + if (ATI_MACH32) temp = mach->accel.src_y >> 8; } break; case 0xfaee: if (len == 2) { - if ((dev->local & 0xff) >= 0x02) { + if (ATI_MACH32) { if (mach->pci_bus) temp = 0x0017; else temp = 0x22f7; } } else { - if ((dev->local & 0xff) >= 0x02) { + if (ATI_MACH32) { if (mach->pci_bus) temp = 0x17; else @@ -4043,7 +4691,7 @@ mach_accel_in_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, in break; case 0xfaef: if (len == 1) { - if ((dev->local & 0xff) >= 0x02) { + if (ATI_MACH32) { if (mach->pci_bus) temp = 0x00; else @@ -4065,6 +4713,7 @@ static uint8_t mach_accel_in_call(uint16_t port, mach_t *mach, svga_t *svga, ibm8514_t *dev) { uint8_t temp = 0; + uint8_t fifo_test_tag[16] = { 0x7c, 0x64, 0x60, 0x5c, 0x58, 0x54, 0x50, 0x68, 0x38, 0x24, 0x10, 0x0c, 0x08, 0x04, 0x00, 0x4c}; int16_t clip_t = dev->accel.clip_top; int16_t clip_l = dev->accel.clip_left; int16_t clip_b = dev->accel.clip_bottom; @@ -4075,6 +4724,7 @@ mach_accel_in_call(uint16_t port, mach_t *mach, svga_t *svga, ibm8514_t *dev) switch (port) { case 0x2e8: + case 0x2e9: case 0x6e8: case 0x22e8: case 0x26e8: @@ -4086,61 +4736,73 @@ mach_accel_in_call(uint16_t port, mach_t *mach, svga_t *svga, ibm8514_t *dev) case 0x42e8: case 0x42e9: - if (dev->vc == dev->v_syncstart) - temp |= 0x01; + if (!(port & 1)) { + if ((dev->subsys_cntl & INT_VSY) && !(dev->subsys_stat & INT_VSY) && (dev->vc == dev->dispend)) + temp |= INT_VSY; - if (mach->accel.cmd_type == -1) { - if (cmd == 6) { - if ((dev->accel.dx >= clip_l) && - (dev->accel.dx <= clip_r_ibm) && - (dev->accel.dy >= clip_t) && - (dev->accel.dy <= clip_b_ibm)) - temp |= 0x02; - } else { - if ((dev->accel.cx >= clip_l) && - (dev->accel.cx <= clip_r_ibm) && - (dev->accel.cy >= clip_t) && - (dev->accel.cy <= clip_b_ibm)) - temp |= 0x02; - } - } else { - switch (mach->accel.cmd_type) { - case 1: - case 2: - case 5: - if ((dev->accel.dx >= clip_l) && - (dev->accel.dx <= clip_r) && + if (mach->accel.cmd_type == -1) { + if (cmd == 6) { + if ((dev->subsys_cntl & INT_GE_BSY) && + !(dev->subsys_stat & INT_GE_BSY) && + (dev->accel.dx >= clip_l) && + (dev->accel.dx <= clip_r_ibm) && (dev->accel.dy >= clip_t) && - (dev->accel.dy <= clip_b)) - temp |= 0x02; - break; - case 3: - case 4: - if ((dev->accel.cx >= clip_l) && - (dev->accel.cx <= clip_r) && + (dev->accel.dy <= clip_b_ibm)) + temp |= INT_GE_BSY; + } else { + if ((dev->subsys_cntl & INT_GE_BSY) && + !(dev->subsys_stat & INT_GE_BSY) && + (dev->accel.cx >= clip_l) && + (dev->accel.cx <= clip_r_ibm) && (dev->accel.cy >= clip_t) && - (dev->accel.cy <= clip_b)) - temp |= 0x02; - break; - default: - break; + (dev->accel.cy <= clip_b_ibm)) + temp |= INT_GE_BSY; + } + } else { + switch (mach->accel.cmd_type) { + case 2: + case 5: + if ((dev->subsys_cntl & INT_GE_BSY) && + !(dev->subsys_stat & INT_GE_BSY) && + (dev->accel.dx >= clip_l) && + (dev->accel.dx <= clip_r) && + (dev->accel.dy >= clip_t) && + (dev->accel.dy <= clip_b)) + temp |= INT_GE_BSY; + break; + case 1: + case 3: + case 4: + if ((dev->subsys_cntl & INT_GE_BSY) && + !(dev->subsys_stat & INT_GE_BSY) && + (dev->accel.cx >= clip_l) && + (dev->accel.cx <= clip_r) && + (dev->accel.cy >= clip_t) && + (dev->accel.cy <= clip_b)) + temp |= INT_GE_BSY; + break; + default: + break; + } } - } - if ((!dev->fifo_idx || !dev->ext_fifo_idx)) { - if ((!dev->force_busy && !dev->force_busy2) || !mach->force_busy) - temp |= 0x08; - } - if (port & 1) - temp = dev->vram_512k_8514 ? 0x00 : 0x80; - else { + if (!dev->fifo_idx && !dev->on) { + dev->force_busy = 0; + dev->force_busy2 = 0; + mach->force_busy = 0; + dev->data_available = 0; + dev->data_available2 = 0; + temp |= INT_FIFO_EMP; + mach_log("Fifo Empty.\n"); + } temp |= (dev->subsys_stat | (dev->vram_512k_8514 ? 0x00 : 0x80)); if (mach->accel.ext_ge_config & 0x08) temp |= ((mach->accel.ext_ge_config & 0x07) << 4); else temp |= 0x20; + + mach_log("0x%04x read: Subsystem Status=%02x, monitoralias=%02x.\n", port, temp, mach->accel.ext_ge_config & 0x07); } - mach_log("0x%04x read: Subsystem Status=%02x.\n", port, temp); break; /*ATI Mach8/32 specific registers*/ @@ -4155,8 +4817,16 @@ mach_accel_in_call(uint16_t port, mach_t *mach, svga_t *svga, ibm8514_t *dev) break; case 0x1aee: + if (dev->fifo_idx > 0) + dev->fifo_idx--; + if (mach->fifo_test_idx > 0) + mach->fifo_test_idx--; + fallthrough; case 0x1aef: - temp = 0x00; + mach_log("FIFO Test IDX=%d, Data=%04x.\n", mach->fifo_test_idx, mach->fifo_test_data[mach->fifo_test_idx]); + READ8(port, mach->fifo_test_data[mach->fifo_test_idx]); + if (!mach->fifo_test_idx && ((mach->accel.dp_config == 0xaaaa) || (mach->accel.dp_config == 0x5555))) + mach->accel.dp_config = 0x2011; break; case 0x22ee: @@ -4171,9 +4841,8 @@ mach_accel_in_call(uint16_t port, mach_t *mach, svga_t *svga, ibm8514_t *dev) case 0x36ee: case 0x36ef: - if ((dev->local & 0xff) >= 0x02) { + if (ATI_MACH32) { READ8(port, mach->misc); - if (!(port & 1)) { temp &= ~0x0c; switch (dev->vram_amount) { @@ -4194,6 +4863,14 @@ mach_accel_in_call(uint16_t port, mach_t *mach, svga_t *svga, ibm8514_t *dev) } break; + case 0x3aee: + case 0x3aef: + if (port & 1) + temp = 0x01; + else + temp = fifo_test_tag[dev->fifo_idx]; + break; + case 0x42ee: case 0x42ef: READ8(port, mach->accel.test2); @@ -4217,13 +4894,21 @@ mach_accel_in_call(uint16_t port, mach_t *mach, svga_t *svga, ibm8514_t *dev) temp = (((dev->bios_rom.mapping.base >> 7) - 0x1000) >> 4); if (port & 1) temp |= 0x01; + } else { + if (mach->accel.scratch0 == 0x1234) + temp = 0x0000; } + } else { + mach_log("ScratchPad0=%x.\n", mach->accel.scratch0); + if (mach->accel.scratch0 == 0x1234) + temp = 0x0000; } break; case 0x56ee: case 0x56ef: READ8(port, mach->accel.scratch1); + mach_log("ScratchPad1=%x.\n", mach->accel.scratch1); break; case 0x5eee: @@ -4243,6 +4928,7 @@ mach_accel_in_call(uint16_t port, mach_t *mach, svga_t *svga, ibm8514_t *dev) temp |= 0x20; mach->force_busy = 0; + if (ati_eeprom_read(&mach->eeprom)) temp |= 0x40; @@ -4282,24 +4968,25 @@ mach_accel_in_call(uint16_t port, mach_t *mach, svga_t *svga, ibm8514_t *dev) return temp; } -static void -ati8514_accel_out(uint16_t port, uint8_t val, svga_t *svga) -{ - mach_log("[%04X:%08X]: Port NORMAL OUT=%04x, val=%04x.\n", CS, cpu_state.pc, port, val); - - mach_accel_out_call(port, val, (mach_t *)svga->ext8514, svga, (ibm8514_t *) svga->dev8514); -} - static void ati8514_accel_outb(uint16_t port, uint8_t val, void *priv) { svga_t *svga = (svga_t *)priv; mach_t *mach = (mach_t *)svga->ext8514; + ibm8514_t *dev = (ibm8514_t *) svga->dev8514; - if (port & 0x8000) - mach_accel_out_fifo(mach, svga, (ibm8514_t *) svga->dev8514, port, val, 1); - else - ati8514_accel_out(port, val, svga); + if (port & 0x8000) { /*Command FIFO*/ + if (dev->accel.cmd_back) { + mach->fifo_test_data[dev->fifo_idx] = val; + dev->fifo_idx++; + if (dev->fifo_idx > 16) + dev->fifo_idx = 16; + + mach->fifo_test_idx = dev->fifo_idx; + } + } + dev->accel_out_fifo(svga, port, val, 1); + mach_log("%04X:%08X: OUTB port=%04x, val=%02x, fifo idx=%d.\n", CS, cpu_state.pc, port, val, dev->fifo_idx); } static void @@ -4307,13 +4994,23 @@ ati8514_accel_outw(uint16_t port, uint16_t val, void *priv) { svga_t *svga = (svga_t *)priv; mach_t *mach = (mach_t *)svga->ext8514; + ibm8514_t *dev = (ibm8514_t *) svga->dev8514; - if (port & 0x8000) - mach_accel_out_fifo(mach, svga, (ibm8514_t *) svga->dev8514, port, val, 2); - else { - ati8514_accel_out(port, val, svga); - ati8514_accel_out(port + 1, (val >> 8), svga); + if (port == 0xf6ee) + port = 0x82e8; + + if (port & 0x8000) { /*Command FIFO*/ + if (dev->accel.cmd_back) { + mach->fifo_test_data[dev->fifo_idx] = val; + dev->fifo_idx++; + if (dev->fifo_idx > 16) + dev->fifo_idx = 16; + + mach->fifo_test_idx = dev->fifo_idx; + } } + dev->accel_out_fifo(svga, port, val, 2); + mach_log("%04X:%08X: OUTW port=%04x, val=%04x, fifo idx=%d.\n", CS, cpu_state.pc, port, val, dev->fifo_idx); } static void @@ -4321,16 +5018,23 @@ ati8514_accel_outl(uint16_t port, uint32_t val, void *priv) { svga_t *svga = (svga_t *)priv; mach_t *mach = (mach_t *)svga->ext8514; + ibm8514_t *dev = (ibm8514_t *) svga->dev8514; - if (port & 0x8000) { - mach_accel_out_fifo(mach, svga, (ibm8514_t *) svga->dev8514, port, val & 0xffff, 2); - mach_accel_out_fifo(mach, svga, (ibm8514_t *) svga->dev8514, port + 2, val >> 16, 2); - } else { - ati8514_accel_out(port, val, svga); - ati8514_accel_out(port + 1, (val >> 8), svga); - ati8514_accel_out(port + 2, (val >> 16), svga); - ati8514_accel_out(port + 3, (val >> 24), svga); + if (port == 0xf6ee) + port = 0x82e8; + + if (port & 0x8000) { /*Command FIFO*/ + if (dev->accel.cmd_back) { + mach->fifo_test_data[dev->fifo_idx] = val; + dev->fifo_idx++; + if (dev->fifo_idx > 16) + dev->fifo_idx = 16; + + mach->fifo_test_idx = dev->fifo_idx; + } } + dev->accel_out_fifo(svga, port, val, 2); + mach_log("OUTL port=%04x, val=%08x, fifo idx=%d.\n", port, val, dev->fifo_idx); } static void @@ -4338,11 +5042,20 @@ mach_accel_outb(uint16_t port, uint8_t val, void *priv) { mach_t *mach = (mach_t *) priv; svga_t *svga = &mach->svga; + ibm8514_t *dev = (ibm8514_t *) svga->dev8514; - if (port & 0x8000) - mach_accel_out_fifo(mach, svga, (ibm8514_t *) svga->dev8514, port, val, 1); - else - mach_accel_out(port, val, mach); + if (port & 0x8000) { /*Command FIFO*/ + if (dev->accel.cmd_back) { + mach->fifo_test_data[dev->fifo_idx] = val; + dev->fifo_idx++; + if (dev->fifo_idx > 16) + dev->fifo_idx = 16; + + mach->fifo_test_idx = dev->fifo_idx; + } + } + dev->accel_out_fifo(mach, port, val, 1); + mach_log("%04X:%08X: OUTB port=%04x, val=%02x, fifo idx=%d.\n", CS, cpu_state.pc, port, val, dev->fifo_idx); } static void @@ -4350,13 +5063,23 @@ mach_accel_outw(uint16_t port, uint16_t val, void *priv) { mach_t *mach = (mach_t *) priv; svga_t *svga = &mach->svga; + ibm8514_t *dev = (ibm8514_t *) svga->dev8514; - if (port & 0x8000) - mach_accel_out_fifo(mach, svga, (ibm8514_t *) svga->dev8514, port, val, 2); - else { - mach_accel_out(port, val, mach); - mach_accel_out(port + 1, (val >> 8), mach); + if (port == 0xf6ee) + port = 0x82e8; + + if (port & 0x8000) { /*Command FIFO*/ + if (dev->accel.cmd_back) { + mach->fifo_test_data[dev->fifo_idx] = val; + dev->fifo_idx++; + if (dev->fifo_idx > 16) + dev->fifo_idx = 16; + + mach->fifo_test_idx = dev->fifo_idx; + } } + dev->accel_out_fifo(mach, port, val, 2); + mach_log("%04X:%08X: OUTW port=%04x, val=%04x, fifo idx=%d.\n", CS, cpu_state.pc, port, val, dev->fifo_idx); } static void @@ -4364,16 +5087,23 @@ mach_accel_outl(uint16_t port, uint32_t val, void *priv) { mach_t *mach = (mach_t *) priv; svga_t *svga = &mach->svga; + ibm8514_t *dev = (ibm8514_t *) svga->dev8514; - if (port & 0x8000) { - mach_accel_out_fifo(mach, svga, (ibm8514_t *) svga->dev8514, port, val & 0xffff, 2); - mach_accel_out_fifo(mach, svga, (ibm8514_t *) svga->dev8514, port + 2, val >> 16, 2); - } else { - mach_accel_out(port, val, mach); - mach_accel_out(port + 1, (val >> 8), mach); - mach_accel_out(port + 2, (val >> 16), mach); - mach_accel_out(port + 3, (val >> 24), mach); + if (port == 0xf6ee) + port = 0x82e8; + + if (port & 0x8000) { /*Command FIFO*/ + if (dev->accel.cmd_back) { + mach->fifo_test_data[dev->fifo_idx] = val; + dev->fifo_idx++; + if (dev->fifo_idx > 16) + dev->fifo_idx = 16; + + mach->fifo_test_idx = dev->fifo_idx; + } } + dev->accel_out_fifo(mach, port, val, 2); + mach_log("OUTL port=%04x, val=%08x, fifo idx=%d.\n", port, val, dev->fifo_idx); } static uint8_t @@ -4394,6 +5124,7 @@ ati8514_accel_inb(uint16_t port, void *priv) else temp = ati8514_accel_in(port, svga); + mach_log("%04X:%08X: INB port=%04x, temp=%02x.\n", CS, cpu_state.pc, port, temp); return temp; } @@ -4410,6 +5141,8 @@ ati8514_accel_inw(uint16_t port, void *priv) temp = ati8514_accel_in(port, svga); temp |= (ati8514_accel_in(port + 1, svga) << 8); } + + mach_log("%04X:%08X: INW port=%04x, temp=%04x.\n", CS, cpu_state.pc, port, temp); return temp; } @@ -4420,14 +5153,11 @@ ati8514_accel_inl(uint16_t port, void *priv) mach_t *mach = (mach_t *)svga->ext8514; uint32_t temp; - if (port & 0x8000) { + if (port & 0x8000) temp = mach_accel_in_fifo(mach, svga, (ibm8514_t *) svga->dev8514, port, 2); - temp = (mach_accel_in_fifo(mach, svga, (ibm8514_t *) svga->dev8514, port + 2, 2) << 16); - } else { + else { temp = ati8514_accel_in(port, svga); temp |= (ati8514_accel_in(port + 1, svga) << 8); - temp |= (ati8514_accel_in(port + 2, svga) << 16); - temp |= (ati8514_accel_in(port + 3, svga) << 24); } return temp; } @@ -4451,6 +5181,7 @@ mach_accel_inb(uint16_t port, void *priv) else temp = mach_accel_in(port, mach); + mach_log("%04X:%08X: INB port=%04x, temp=%02x.\n", CS, cpu_state.pc, port, temp); return temp; } @@ -4467,6 +5198,8 @@ mach_accel_inw(uint16_t port, void *priv) temp = mach_accel_in(port, mach); temp |= (mach_accel_in(port + 1, mach) << 8); } + + mach_log("%04X:%08X: INW port=%04x, temp=%04x.\n", CS, cpu_state.pc, port, temp); return temp; } @@ -4477,14 +5210,11 @@ mach_accel_inl(uint16_t port, void *priv) svga_t *svga = &mach->svga; uint32_t temp; - if (port & 0x8000) { + if (port & 0x8000) temp = mach_accel_in_fifo(mach, svga, (ibm8514_t *) svga->dev8514, port, 2); - temp = (mach_accel_in_fifo(mach, svga, (ibm8514_t *) svga->dev8514, port + 2, 2) << 16); - } else { + else { temp = mach_accel_in(port, mach); temp |= (mach_accel_in(port + 1, mach) << 8); - temp |= (mach_accel_in(port + 2, mach) << 16); - temp |= (mach_accel_in(port + 3, mach) << 24); } return temp; } @@ -4653,7 +5383,12 @@ mach32_write(uint32_t addr, uint8_t val, void *priv) xga_write_test(addr, val, svga); addr = (addr & svga->banked_mask) + svga->write_bank; - if ((((dev->local & 0xff) >= 0x02) && !dev->vram_512k_8514) && ((mach->accel.ext_ge_config & 0x30) == 0x00)) { + if (mach->accel.test2 & 0x10) { + if (addr < ((mach->accel.test2 & 0x0f) << 18)) + return; + } + + if ((ATI_MACH32 && !dev->vram_512k_8514) && ((mach->accel.ext_ge_config & 0x30) == 0x00)) { addr <<= 1; switch (addr & 0x06) { case 0x00: @@ -4674,6 +5409,8 @@ mach32_write(uint32_t addr, uint8_t val, void *priv) } } else mach32_write_common(addr, val, 0, mach, svga); + + mach_log("Writeb banked=%08x.\n", addr); } static void @@ -4686,7 +5423,12 @@ mach32_writew(uint32_t addr, uint16_t val, void *priv) xga_write_test(addr, val, svga); addr = (addr & svga->banked_mask) + svga->write_bank; - if ((((dev->local & 0xff) >= 0x02) && !dev->vram_512k_8514) && ((mach->accel.ext_ge_config & 0x30) == 0x00)) { + if (mach->accel.test2 & 0x10) { + if (addr < ((mach->accel.test2 & 0x0f) << 18)) + return; + } + + if ((ATI_MACH32 && !dev->vram_512k_8514) && ((mach->accel.ext_ge_config & 0x30) == 0x00)) { addr <<= 1; if (addr & 0x04) { mach32_write_common(addr - 2, val & 0x0f, 0, mach, svga); @@ -4703,6 +5445,7 @@ mach32_writew(uint32_t addr, uint16_t val, void *priv) mach32_write_common(addr, val & 0xff, 0, mach, svga); mach32_write_common(addr + 1, val >> 8, 0, mach, svga); } + mach_log("Writew banked=%08x.\n", addr); } static void @@ -4715,7 +5458,12 @@ mach32_writel(uint32_t addr, uint32_t val, void *priv) xga_write_test(addr, val, svga); addr = (addr & svga->banked_mask) + svga->write_bank; - if ((((dev->local & 0xff) >= 0x02) && !dev->vram_512k_8514) && ((mach->accel.ext_ge_config & 0x30) == 0x00)) { + if (mach->accel.test2 & 0x10) { + if (addr < ((mach->accel.test2 & 0x0f) << 18)) + return; + } + + if ((ATI_MACH32 && !dev->vram_512k_8514) && ((mach->accel.ext_ge_config & 0x30) == 0x00)) { addr <<= 1; mach32_write_common(addr, val & 0x0f, 0, mach, svga); mach32_write_common(addr + 1, (val >> 4) & 0x0f, 0, mach, svga); @@ -4731,6 +5479,224 @@ mach32_writel(uint32_t addr, uint32_t val, void *priv) mach32_write_common(addr + 2, val >> 16, 0, mach, svga); mach32_write_common(addr + 3, val >> 24, 0, mach, svga); } + + mach_log("Writel banked=%08x.\n", addr); +} + +static __inline void +mach32_svga_write(uint32_t addr, uint8_t val, void *priv) +{ + svga_t *svga = (svga_t *) priv; + mach_t *mach = (mach_t *) svga->priv; + int writemask2 = svga->writemask; + int reset_wm = 0; + latch_t vall; + uint8_t wm = svga->writemask; + uint8_t count; + uint8_t i; + + cycles -= svga->monitor->mon_video_timing_write_b; + + xga_write_test(addr, val, svga); + addr = svga_decode_addr(svga, addr, 1); + + if (addr == 0xffffffff) { + mach_log("WriteCommon Over.\n"); + return; + } + + if (mach->accel.test2 & 0x10) { + if (addr >= ((mach->accel.test2 & 0x0f) << 18)) + return; + } + + if (!(svga->gdcreg[6] & 1)) + svga->fullchange = 2; + + if (((svga->chain4 && (svga->packed_chain4 || svga->force_old_addr)) || svga->fb_only) && (svga->writemode < 4)) { + writemask2 = 1 << (addr & 3); + addr &= ~3; + } else if (svga->chain4 && (svga->writemode < 4)) { + writemask2 = 1 << (addr & 3); + addr = ((addr & 0xfffc) << 2) | ((addr & 0x30000) >> 14) | (addr & ~0x3ffff); + } else if (svga->chain2_write) { + writemask2 &= ~0xa; + if (addr & 1) + writemask2 <<= 1; + addr &= ~1; + addr <<= 2; + } else + addr <<= 2; + + addr &= svga->decode_mask; + + if (addr >= svga->vram_max) { + mach_log("WriteBankedOver=%08x, val=%02x.\n", addr & svga->vram_mask, val); + return; + } + + addr &= svga->vram_mask; + svga->changedvram[addr >> 12] = svga->monitor->mon_changeframecount; + + count = 4; + + switch (svga->writemode) { + case 0: + val = ((val >> (svga->gdcreg[3] & 7)) | (val << (8 - (svga->gdcreg[3] & 7)))); + if ((svga->gdcreg[8] == 0xff) && !(svga->gdcreg[3] & 0x18) && (!svga->gdcreg[1] || svga->set_reset_disabled)) { + for (i = 0; i < count; i++) { + if (writemask2 & (1 << i)) + svga->vram[addr | i] = val; + } + return; + } else { + for (i = 0; i < count; i++) { + if (svga->gdcreg[1] & (1 << i)) + vall.b[i] = !!(svga->gdcreg[0] & (1 << i)) * 0xff; + else + vall.b[i] = val; + } + } + break; + case 1: + for (i = 0; i < count; i++) { + if (writemask2 & (1 << i)) + svga->vram[addr | i] = svga->latch.b[i]; + } + return; + case 2: + for (i = 0; i < count; i++) + vall.b[i] = !!(val & (1 << i)) * 0xff; + + if (!(svga->gdcreg[3] & 0x18) && (!svga->gdcreg[1] || svga->set_reset_disabled)) { + for (i = 0; i < count; i++) { + if (writemask2 & (1 << i)) + svga->vram[addr | i] = (vall.b[i] & svga->gdcreg[8]) | (svga->latch.b[i] & ~svga->gdcreg[8]); + } + return; + } + break; + case 3: + val = ((val >> (svga->gdcreg[3] & 7)) | (val << (8 - (svga->gdcreg[3] & 7)))); + wm = svga->gdcreg[8]; + svga->gdcreg[8] &= val; + + for (i = 0; i < count; i++) + vall.b[i] = !!(svga->gdcreg[0] & (1 << i)) * 0xff; + + reset_wm = 1; + break; + default: + return; + } + + switch (svga->gdcreg[3] & 0x18) { + case 0x00: /* Set */ + for (i = 0; i < count; i++) { + if (writemask2 & (1 << i)) + svga->vram[addr | i] = (vall.b[i] & svga->gdcreg[8]) | (svga->latch.b[i] & ~svga->gdcreg[8]); + } + break; + case 0x08: /* AND */ + for (i = 0; i < count; i++) { + if (writemask2 & (1 << i)) + svga->vram[addr | i] = (vall.b[i] | ~svga->gdcreg[8]) & svga->latch.b[i]; + } + break; + case 0x10: /* OR */ + for (i = 0; i < count; i++) { + if (writemask2 & (1 << i)) + svga->vram[addr | i] = (vall.b[i] & svga->gdcreg[8]) | svga->latch.b[i]; + } + break; + case 0x18: /* XOR */ + for (i = 0; i < count; i++) { + if (writemask2 & (1 << i)) + svga->vram[addr | i] = (vall.b[i] & svga->gdcreg[8]) ^ svga->latch.b[i]; + } + break; + + default: + break; + } + + if (reset_wm) + svga->gdcreg[8] = wm; +} + +static __inline void +mach32_svga_writew(uint32_t addr, uint16_t val, void *priv) +{ + svga_t *svga = (svga_t *) priv; + mach_t *mach = (mach_t *) svga->priv; + + if (!svga->fast) { + mach32_svga_write(addr, val, priv); + mach32_svga_write(addr + 1, val >> 8, priv); + return; + } + + cycles -= svga->monitor->mon_video_timing_write_w; + + xga_write_test(addr, val & 0xff, svga); + xga_write_test(addr + 1, val >> 8, svga); + addr = svga_decode_addr(svga, addr, 1); + + if (addr == 0xffffffff) + return; + + if (mach->accel.test2 & 0x10) { + if (addr >= ((mach->accel.test2 & 0x0f) << 18)) + return; + } + + addr &= svga->decode_mask; + if (addr >= svga->vram_max) + return; + addr &= svga->vram_mask; + + svga->changedvram[addr >> 12] = svga->monitor->mon_changeframecount; + *(uint16_t *) &svga->vram[addr] = val; +} + +static __inline void +mach32_svga_writel(uint32_t addr, uint32_t val, void *priv) +{ + svga_t *svga = (svga_t *) priv; + mach_t *mach = (mach_t *) svga->priv; + + if (!svga->fast) { + mach32_svga_write(addr, val, priv); + mach32_svga_write(addr + 1, val >> 8, priv); + mach32_svga_write(addr + 2, val >> 16, priv); + mach32_svga_write(addr + 3, val >> 24, priv); + return; + } + + cycles -= svga->monitor->mon_video_timing_write_l; + + xga_write_test(addr, val & 0xff, svga); + xga_write_test(addr + 1, (val >> 8) & 0xff, svga); + xga_write_test(addr + 2, (val >> 16) & 0xff, svga); + xga_write_test(addr + 3, (val >> 24) & 0xff, svga); + addr = svga_decode_addr(svga, addr, 1); + + if (addr == 0xffffffff) + return; + + if (mach->accel.test2 & 0x10) { + if (addr >= ((mach->accel.test2 & 0x0f) << 18)) + return; + } + + addr &= svga->decode_mask; + if (addr >= svga->vram_max) + return; + + addr &= svga->vram_mask; + + svga->changedvram[addr >> 12] = svga->monitor->mon_changeframecount; + *(uint32_t *) &svga->vram[addr] = val; } static __inline void @@ -4805,17 +5771,17 @@ mach32_read_common(uint32_t addr, int linear, mach_t *mach, svga_t *svga) addr &= dev->vram_mask; if (!dev->vram_512k_8514 && ((mach->accel.ext_ge_config & 0x30) == 0x00)) { - switch (addr & 0x06) { + switch ((addr & 0x06) >> 1) { case 0x00: - case 0x06: + case 0x03: ret = dev->vram[addr] & 0x0f; ret |= (dev->vram[addr + 1] << 4); break; - case 0x02: + case 0x01: ret = dev->vram[addr + 2] & 0x0f; ret |= (dev->vram[addr + 3] << 4); break; - case 0x04: + case 0x02: ret = dev->vram[addr - 2] & 0x0f; ret |= (dev->vram[addr - 1] << 4); break; @@ -4914,19 +5880,19 @@ mach32_read(uint32_t addr, void *priv) (void) xga_read_test(addr, svga); addr = (addr & svga->banked_mask) + svga->read_bank; - if ((((dev->local & 0xff) >= 0x02) && !dev->vram_512k_8514) && ((mach->accel.ext_ge_config & 0x30) == 0x00)) { + if ((ATI_MACH32 && !dev->vram_512k_8514) && ((mach->accel.ext_ge_config & 0x30) == 0x00)) { addr <<= 1; - switch (addr & 0x06) { + switch ((addr & 0x06) >> 1) { case 0x00: - case 0x06: + case 0x03: ret = mach32_read_common(addr, 0, mach, svga) & 0x0f; ret |= (mach32_read_common(addr + 1, 0, mach, svga) << 4); break; - case 0x02: + case 0x01: ret = mach32_read_common(addr + 2, 0, mach, svga) & 0x0f; ret |= (mach32_read_common(addr + 3, 0, mach, svga) << 4); break; - case 0x04: + case 0x02: ret = mach32_read_common(addr - 2, 0, mach, svga) & 0x0f; ret |= (mach32_read_common(addr - 1, 0, mach, svga) << 4); break; @@ -4936,6 +5902,7 @@ mach32_read(uint32_t addr, void *priv) } else ret = mach32_read_common(addr, 0, mach, svga); + mach_log("Readb banked=%08x.\n", addr); return ret; } @@ -4950,7 +5917,7 @@ mach32_readw(uint32_t addr, void *priv) (void) xga_read_test(addr, svga); addr = (addr & svga->banked_mask) + svga->read_bank; - if ((((dev->local & 0xff) >= 0x02) && !dev->vram_512k_8514) && ((mach->accel.ext_ge_config & 0x30) == 0x00)) { + if ((ATI_MACH32 && !dev->vram_512k_8514) && ((mach->accel.ext_ge_config & 0x30) == 0x00)) { addr <<= 1; if (addr & 0x04) { ret = mach32_read_common(addr - 2, 0, mach, svga) & 0x0f; @@ -4967,6 +5934,7 @@ mach32_readw(uint32_t addr, void *priv) ret = mach32_read_common(addr, 0, mach, svga); ret |= (mach32_read_common(addr + 1, 0, mach, svga) << 8); } + mach_log("Readw banked=%08x.\n", addr); return ret; } @@ -4981,7 +5949,7 @@ mach32_readl(uint32_t addr, void *priv) (void) xga_read_test(addr, svga); addr = (addr & svga->banked_mask) + svga->read_bank; - if ((((dev->local & 0xff) >= 0x02) && !dev->vram_512k_8514) && ((mach->accel.ext_ge_config & 0x30) == 0x00)) { + if ((ATI_MACH32 && !dev->vram_512k_8514) && ((mach->accel.ext_ge_config & 0x30) == 0x00)) { addr <<= 1; ret = mach32_read_common(addr, 0, mach, svga) & 0x0f; ret |= (mach32_read_common(addr + 1, 0, mach, svga) << 4); @@ -4997,6 +5965,7 @@ mach32_readl(uint32_t addr, void *priv) ret |= (mach32_read_common(addr + 2, 0, mach, svga) << 16); ret |= (mach32_read_common(addr + 3, 0, mach, svga) << 24); } + mach_log("Readl banked=%08x.\n", addr); return ret; } @@ -5060,18 +6029,23 @@ mach32_ap_writeb(uint32_t addr, uint8_t val, void *priv) svga_t *svga = &mach->svga; const ibm8514_t *dev = (ibm8514_t *) svga->dev8514; uint8_t port_dword = addr & 0xfc; + uint16_t actual_port = 0x02e8 + (addr & 1) + (port_dword << 8); + uint16_t actual_port_ext = 0x02ee + (addr & 1) + (port_dword << 8); if (((mach->local_cntl & 0x20) || (mach->pci_cntl_reg & 0x80)) && - ((addr >= ((mach->ap_size << 20) - 0x200)) && (addr < (mach->ap_size << 20)))) { + (((addr - mach->linear_base) >= ((mach->ap_size << 20) - 0x200)) && ((addr - mach->linear_base) < (mach->ap_size << 20))) && + (svga->mapping.base == 0xa0000)) { 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); + mach_log("Port WORDB Write=%04x.\n", actual_port_ext); + mach_accel_outb(actual_port_ext, 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); + mach_log("Port WORDB Write=%04x.\n", actual_port); + mach_accel_outb(actual_port, val, mach); } } else { - mach_log("Linear WORDB Write=%08x, val=%02x, ON=%x, dpconfig=%04x, apsize=%08x.\n", addr & dev->vram_mask, val, dev->on, mach->accel.dp_config, mach->ap_size << 20); + mach_log("Linear WORDB Write=%08x, val=%02x, ON=%x, dpconfig=%04x, apsize=%08x, addr=%08x.\n", + addr - mach->linear_base, val, dev->on, mach->accel.dp_config, mach->ap_size << 20, addr); + if (dev->on) mach32_write_common(addr, val, 1, mach, svga); else @@ -5086,18 +6060,23 @@ mach32_ap_writew(uint32_t addr, uint16_t val, void *priv) svga_t *svga = &mach->svga; const ibm8514_t *dev = (ibm8514_t *) svga->dev8514; uint8_t port_dword = addr & 0xfc; + uint16_t actual_port = 0x02e8 + (port_dword << 8); + uint16_t actual_port_ext = 0x02ee + (port_dword << 8); if (((mach->local_cntl & 0x20) || (mach->pci_cntl_reg & 0x80)) && - ((addr >= ((mach->ap_size << 20) - 0x200)) && (addr < (mach->ap_size << 20)))) { + (((addr - mach->linear_base) >= ((mach->ap_size << 20) - 0x200)) && ((addr - mach->linear_base) < (mach->ap_size << 20))) && + (svga->mapping.base == 0xa0000)) { if (addr & 0x100) { - mach_log("Port WORDW Write=%04x.\n", 0x02ee + (port_dword << 8)); - mach_accel_outw(0x02ee + (port_dword << 8), val, mach); + mach_log("Port WORDW Write=%04x, localcntl=%02x, pcicntl=%02x, actual addr=%08x, val=%04x.\n", actual_port_ext, mach->local_cntl & 0x20, mach->pci_cntl_reg & 0x80, addr, val); + mach_accel_outw(actual_port_ext, val, mach); } else { - mach_log("Port WORDW Write=%04x.\n", 0x02e8 + (port_dword << 8)); - mach_accel_outw(0x02e8 + (port_dword << 8), val, mach); + mach_log("Port WORDW Write=%04x, localcntl=%02x, pcicntl=%02x, actual addr=%08x, val=%04x.\n", actual_port, mach->local_cntl & 0x20, mach->pci_cntl_reg & 0x80, addr, val); + mach_accel_outw(actual_port, val, mach); } } else { - mach_log("Linear WORDW Write=%08x, val=%04x, ON=%x, dpconfig=%04x, apsize=%08x.\n", addr & dev->vram_mask, val, dev->on, mach->accel.dp_config, mach->ap_size << 20); + mach_log("Linear WORDW Write=%08x, val=%04x, ON=%x, dpconfig=%04x, apsize=%08x, addr=%08x.\n", + addr - mach->linear_base, val, dev->on, mach->accel.dp_config, mach->ap_size << 20, addr); + if (dev->on) mach32_writew_linear(addr, val, mach); else @@ -5112,20 +6091,23 @@ mach32_ap_writel(uint32_t addr, uint32_t val, void *priv) svga_t *svga = &mach->svga; const ibm8514_t *dev = (ibm8514_t *) svga->dev8514; uint8_t port_dword = addr & 0xfc; + uint16_t actual_port = 0x02e8 + (port_dword << 8); + uint16_t actual_port_ext = 0x02ee + (port_dword << 8); if (((mach->local_cntl & 0x20) || (mach->pci_cntl_reg & 0x80)) && - ((addr >= ((mach->ap_size << 20) - 0x200)) && (addr < (mach->ap_size << 20)))) { + (((addr - mach->linear_base) >= ((mach->ap_size << 20) - 0x200)) && ((addr - mach->linear_base) < (mach->ap_size << 20))) && + (svga->mapping.base == 0xa0000)) { 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); + mach_log("Port WORDL Write=%04x, localcntl=%02x, pcicntl=%02x.\n", actual_port_ext, mach->local_cntl & 0x20, mach->pci_cntl_reg & 0x80); + mach_accel_outl(actual_port_ext, val, 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); + mach_log("Port WORDL Write=%04x, localcntl=%02x, pcicntl=%02x.\n", actual_port, mach->local_cntl & 0x20, mach->pci_cntl_reg & 0x80); + mach_accel_outl(actual_port, val, mach); } } else { - mach_log("Linear WORDL Write=%08x, val=%08x, ON=%x, dpconfig=%04x, apsize=%08x.\n", addr & dev->vram_mask, val, dev->on, mach->accel.dp_config, mach->ap_size << 20); + mach_log("Linear WORDL Write=%08x, val=%08x, ON=%x, dpconfig=%04x, apsize=%08x, addr=%08x.\n", + addr - mach->linear_base, val, dev->on, mach->accel.dp_config, mach->ap_size << 20, addr); + if (dev->on) mach32_writel_linear(addr, val, mach); else @@ -5141,13 +6123,16 @@ mach32_ap_readb(uint32_t addr, void *priv) const ibm8514_t *dev = (ibm8514_t *) svga->dev8514; uint8_t temp; uint8_t port_dword = addr & 0xfc; + uint16_t actual_port = 0x02e8 + (addr & 1) + (port_dword << 8); + uint16_t actual_port_ext = 0x02ee + (addr & 1) + (port_dword << 8); if (((mach->local_cntl & 0x20) || (mach->pci_cntl_reg & 0x80)) && - ((addr >= ((mach->ap_size << 20) - 0x200)) && (addr < (mach->ap_size << 20)))) { + (((addr - mach->linear_base) >= ((mach->ap_size << 20) - 0x200)) && ((addr - mach->linear_base) < (mach->ap_size << 20))) && + (svga->mapping.base == 0xa0000)) { if (addr & 0x100) - temp = mach_accel_inb(0x02ee + (addr & 1) + (port_dword << 8), mach); + temp = mach_accel_inb(actual_port_ext, mach); else - temp = mach_accel_inb(0x02e8 + (addr & 1) + (port_dword << 8), mach); + temp = mach_accel_inb(actual_port, mach); } else { if (dev->on) temp = mach32_read_common(addr, 1, mach, svga); @@ -5168,13 +6153,19 @@ mach32_ap_readw(uint32_t addr, void *priv) const ibm8514_t *dev = (ibm8514_t *) svga->dev8514; uint16_t temp; uint8_t port_dword = addr & 0xfc; + uint16_t actual_port = 0x02e8 + (port_dword << 8); + uint16_t actual_port_ext = 0x02ee + (port_dword << 8); if (((mach->local_cntl & 0x20) || (mach->pci_cntl_reg & 0x80)) && - ((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); + (((addr - mach->linear_base) >= ((mach->ap_size << 20) - 0x200)) && ((addr - mach->linear_base) < (mach->ap_size << 20))) && + (svga->mapping.base == 0xa0000)) { + if (addr & 0x100) { + temp = mach_accel_inw(actual_port_ext, mach); + mach_log("Port WORDW Read=%04x.\n", actual_port_ext); + } else { + temp = mach_accel_inw(actual_port, mach); + mach_log("Port WORDW Read=%04x.\n", actual_port); + } } else { if (dev->on) temp = mach32_readw_linear(addr, mach); @@ -5195,15 +6186,18 @@ mach32_ap_readl(uint32_t addr, void *priv) const ibm8514_t *dev = (ibm8514_t *) svga->dev8514; uint32_t temp; uint8_t port_dword = addr & 0xfc; + uint16_t actual_port = 0x02e8 + (port_dword << 8); + uint16_t actual_port_ext = 0x02ee + (port_dword << 8); if (((mach->local_cntl & 0x20) || (mach->pci_cntl_reg & 0x80)) && - ((addr >= ((mach->ap_size << 20) - 0x200)) && (addr < (mach->ap_size << 20)))) { + (((addr - mach->linear_base) >= ((mach->ap_size << 20) - 0x200)) && ((addr - mach->linear_base) < (mach->ap_size << 20))) && + (svga->mapping.base == 0xa0000)) { if (addr & 0x100) { - temp = mach_accel_inw(0x02ee + (port_dword << 8), mach); - temp |= (mach_accel_inw(0x02ee + (port_dword << 8) + 4, mach) << 8); + temp = mach_accel_inl(actual_port_ext, mach); + mach_log("Port WORDL Read=%04x.\n", actual_port_ext); } else { - temp = mach_accel_inw(0x02e8 + (port_dword << 8), mach); - temp |= (mach_accel_inw(0x02e8 + (port_dword << 8) + 4, mach) << 8); + temp = mach_accel_inl(actual_port, mach); + mach_log("Port WORDL Read=%04x.\n", actual_port); } } else { if (dev->on) @@ -5249,15 +6243,6 @@ mach32_updatemapping(mach_t *mach, svga_t *svga) case 0xC: /*32k at B8000*/ mem_mapping_set_addr(&svga->mapping, 0xb8000, 0x08000); svga->banked_mask = 0x7fff; - if (((dev->local & 0xff) >= 0x02) && !(dev->accel.advfunc_cntl & 0x01) && !(mach->accel.clock_sel & 0x01)) { - if ((svga->gdcreg[6] & 0x01) || (svga->attrregs[0x10] & 0x01)) { - if (svga->attrregs[0x10] & 0x40) { - dev->vendor_mode = 0; - dev->on &= ~0x01; - svga_recalctimings(svga); - } - } - } break; default: @@ -5265,7 +6250,8 @@ mach32_updatemapping(mach_t *mach, svga_t *svga) } } - 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); + 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*/ @@ -5283,18 +6269,18 @@ mach32_updatemapping(mach_t *mach, svga_t *svga) mach_log("Linear Disabled APSIZE=4.\n"); mem_mapping_disable(&mach->mmio_linear_mapping); } - if ((dev->local & 0xff) >= 0x02) { + + if (ATI_MACH32) { if (dev->on && dev->vendor_mode) { mach_log("Mach32 banked mapping.\n"); mem_mapping_set_handler(&svga->mapping, mach32_read, mach32_readw, mach32_readl, mach32_write, mach32_writew, mach32_writel); mem_mapping_set_p(&svga->mapping, mach); } else { mach_log("IBM compatible banked mapping.\n"); - mem_mapping_set_handler(&svga->mapping, svga_read, svga_readw, svga_readl, svga_write, svga_writew, svga_writel); + mem_mapping_set_handler(&svga->mapping, svga_read, svga_readw, svga_readl, mach32_svga_write, mach32_svga_writew, mach32_svga_writel); mem_mapping_set_p(&svga->mapping, svga); } } else { - mach_log("IBM compatible banked mapping.\n"); 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); } @@ -5313,8 +6299,11 @@ mach32_hwcursor_draw(svga_t *svga, int displine) uint32_t *p; int x_pos; int y_pos; + int shift = 0; offset = dev->hwcursor_latch.x - dev->hwcursor_latch.xoff; + if (!dev->vram_512k_8514 && ((mach->accel.ext_ge_config & 0x30) == 0x00)) + shift = 1; mach_log("BPP=%d, displine=%d.\n", dev->accel_bpp, displine); switch (dev->accel_bpp) { @@ -5336,16 +6325,26 @@ mach32_hwcursor_draw(svga_t *svga, int displine) case 32: 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("24/32BPP: Color0=%08x, Color1=%08x.\n", color0, color1); break; } if (dev->interlace && dev->hwcursor_oddeven) - dev->hwcursor_latch.addr += 16; + dev->hwcursor_latch.addr += (16 >> shift); - for (int x = 0; x < 64; x += 8) { - dat = dev->vram[dev->hwcursor_latch.addr & dev->vram_mask] | (dev->vram[(dev->hwcursor_latch.addr + 1) & dev->vram_mask] << 8); - - for (int xx = 0; xx < 8; xx++) { + for (int x = 0; x < 64; x += (8 >> shift)) { + if (shift) { + dat = dev->vram[(dev->hwcursor_latch.addr) & dev->vram_mask] & 0x0f; + dat |= (dev->vram[(dev->hwcursor_latch.addr + 1) & dev->vram_mask] << 4); + dat |= (dev->vram[(dev->hwcursor_latch.addr + 2) & dev->vram_mask] << 8); + dat |= (dev->vram[(dev->hwcursor_latch.addr + 3) & dev->vram_mask] << 12); + mach_log("4bpp Data=%04x.\n", dat); + } else { + dat = dev->vram[dev->hwcursor_latch.addr & dev->vram_mask]; + dat |= (dev->vram[(dev->hwcursor_latch.addr + 1) & dev->vram_mask] << 8); + mach_log("8bppplus Data=%04x.\n", dat); + } + for (int xx = 0; xx < (8 >> shift); xx++) { comb = (dat >> (xx << 1)) & 0x03; y_pos = displine; @@ -5375,7 +6374,7 @@ mach32_hwcursor_draw(svga_t *svga, int displine) } if (dev->interlace && !dev->hwcursor_oddeven) - dev->hwcursor_latch.addr += 16; + dev->hwcursor_latch.addr += (16 >> shift); } static void @@ -5465,6 +6464,7 @@ ati8514_io_set(svga_t *svga) io_sethandler(0x7eee, 0x0002, ati8514_accel_inb, ati8514_accel_inw, ati8514_accel_inl, ati8514_accel_outb, ati8514_accel_outw, ati8514_accel_outl, svga); io_sethandler(0x82ee, 0x0002, ati8514_accel_inb, ati8514_accel_inw, ati8514_accel_inl, ati8514_accel_outb, ati8514_accel_outw, ati8514_accel_outl, svga); io_sethandler(0x86ee, 0x0002, ati8514_accel_inb, ati8514_accel_inw, ati8514_accel_inl, ati8514_accel_outb, ati8514_accel_outw, ati8514_accel_outl, svga); + io_sethandler(0x8aee, 0x0002, ati8514_accel_inb, ati8514_accel_inw, ati8514_accel_inl, ati8514_accel_outb, ati8514_accel_outw, ati8514_accel_outl, svga); io_sethandler(0x8eee, 0x0002, ati8514_accel_inb, ati8514_accel_inw, ati8514_accel_inl, ati8514_accel_outb, ati8514_accel_outw, ati8514_accel_outl, svga); io_sethandler(0x92ee, 0x0002, ati8514_accel_inb, ati8514_accel_inw, ati8514_accel_inl, ati8514_accel_outb, ati8514_accel_outw, ati8514_accel_outl, svga); io_sethandler(0x96ee, 0x0002, ati8514_accel_inb, ati8514_accel_inw, ati8514_accel_inl, ati8514_accel_outb, ati8514_accel_outw, ati8514_accel_outl, svga); @@ -5487,9 +6487,11 @@ ati8514_io_set(svga_t *svga) io_sethandler(0xdeee, 0x0002, ati8514_accel_inb, ati8514_accel_inw, ati8514_accel_inl, ati8514_accel_outb, ati8514_accel_outw, ati8514_accel_outl, svga); io_sethandler(0xe2ee, 0x0002, ati8514_accel_inb, ati8514_accel_inw, ati8514_accel_inl, ati8514_accel_outb, ati8514_accel_outw, ati8514_accel_outl, svga); io_sethandler(0xe6ee, 0x0002, ati8514_accel_inb, ati8514_accel_inw, ati8514_accel_inl, ati8514_accel_outb, ati8514_accel_outw, ati8514_accel_outl, svga); + io_sethandler(0xeaee, 0x0002, ati8514_accel_inb, ati8514_accel_inw, ati8514_accel_inl, ati8514_accel_outb, ati8514_accel_outw, ati8514_accel_outl, svga); io_sethandler(0xeeee, 0x0002, ati8514_accel_inb, ati8514_accel_inw, ati8514_accel_inl, ati8514_accel_outb, ati8514_accel_outw, ati8514_accel_outl, svga); io_sethandler(0xf2ee, 0x0002, ati8514_accel_inb, ati8514_accel_inw, ati8514_accel_inl, ati8514_accel_outb, ati8514_accel_outw, ati8514_accel_outl, svga); io_sethandler(0xf6ee, 0x0002, ati8514_accel_inb, ati8514_accel_inw, ati8514_accel_inl, ati8514_accel_outb, ati8514_accel_outw, ati8514_accel_outl, svga); + io_sethandler(0xfaee, 0x0002, ati8514_accel_inb, ati8514_accel_inw, ati8514_accel_inl, ati8514_accel_outb, ati8514_accel_outw, ati8514_accel_outl, svga); io_sethandler(0xfeee, 0x0002, ati8514_accel_inb, ati8514_accel_inw, ati8514_accel_inl, ati8514_accel_outb, ati8514_accel_outw, ati8514_accel_outl, svga); } @@ -5580,6 +6582,7 @@ mach_io_remove(mach_t *mach) io_removehandler(0x7eee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); io_removehandler(0x82ee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); io_removehandler(0x86ee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); + io_removehandler(0x8aee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); io_removehandler(0x8eee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); io_removehandler(0x92ee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); io_removehandler(0x96ee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); @@ -5602,6 +6605,7 @@ mach_io_remove(mach_t *mach) io_removehandler(0xdeee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); io_removehandler(0xe2ee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); io_removehandler(0xe6ee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); + io_removehandler(0xeaee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); io_removehandler(0xeeee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); io_removehandler(0xf2ee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); io_removehandler(0xf6ee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); @@ -5696,6 +6700,7 @@ mach_io_set(mach_t *mach) io_sethandler(0x7eee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); io_sethandler(0x82ee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); io_sethandler(0x86ee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); + io_sethandler(0x8aee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); io_sethandler(0x8eee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); io_sethandler(0x92ee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); io_sethandler(0x96ee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); @@ -5718,6 +6723,7 @@ mach_io_set(mach_t *mach) io_sethandler(0xdeee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); io_sethandler(0xe2ee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); io_sethandler(0xe6ee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); + io_sethandler(0xeaee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); io_sethandler(0xeeee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); io_sethandler(0xf2ee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); io_sethandler(0xf6ee, 0x0002, mach_accel_inb, mach_accel_inw, mach_accel_inl, mach_accel_outb, mach_accel_outw, mach_accel_outl, mach); @@ -5743,7 +6749,8 @@ mach_mca_write(int port, uint8_t val, void *priv) return; mach->pos_regs[port & 7] = val; - mach_log("[%04X]: MCA write port = %x, val = %02x, biosaddr = %05x.\n", CS, port & 7, mach->pos_regs[port & 7], (((mach->pos_regs[3] & 0x3e) << 0x0c) >> 1) + 0xc0000); + mach_log("[%04X]: MCA write port = %x, val = %02x, biosaddr = %05x.\n", + CS, port & 7, mach->pos_regs[port & 7], (((mach->pos_regs[3] & 0x3e) << 0x0c) >> 1) + 0xc0000); mem_mapping_disable(&mach->bios_rom.mapping); mem_mapping_disable(&mach->bios_rom2.mapping); if (mach->pos_regs[2] & 0x01) { @@ -5771,7 +6778,7 @@ mach_mca_reset(void *priv) mach_log("MCA reset.\n"); dev->on = 0; mach_mca_write(0x102, 0, mach); - timer_set_callback(&svga->timer, svga_poll); + svga_set_poll(svga); } uint8_t @@ -5793,7 +6800,8 @@ ati8514_mca_write(int port, uint8_t val, void *priv) return; dev->pos_regs[port & 7] = val; - mach_log("[%04X]: MCA write port = %x, val = %02x, biosaddr = %05x.\n", CS, port & 7, dev->pos_regs[port & 7], (((dev->pos_regs[3] & 0x3e) << 0x0c) >> 1) + 0xc0000); + mach_log("[%04X]: MCA write port = %x, val = %02x, biosaddr = %05x.\n", + CS, port & 7, dev->pos_regs[port & 7], (((dev->pos_regs[3] & 0x3e) << 0x0c) >> 1) + 0xc0000); mem_mapping_disable(&dev->bios_rom.mapping); if (dev->pos_regs[2] & 0x01) @@ -5947,6 +6955,99 @@ mach32_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) } } +static void +mach_vblank_start(mach_t *mach, svga_t *svga) +{ + ibm8514_t *dev = (ibm8514_t *) svga->dev8514; + + dev->subsys_stat |= INT_VSY; +} + +static void +mach_combo_vblank_start(void *priv) +{ + svga_t *svga = (svga_t *) priv; + mach_t *mach = (mach_t *) svga->priv; + + mach_vblank_start(mach, svga); +} + +static void +ati8514_vblank_start(void *priv) +{ + svga_t *svga = (svga_t *) priv; + mach_t *mach = (mach_t *) svga->ext8514; + + mach_vblank_start(mach, svga); +} + +static void +mach_combo_accel_out_fifo(void *priv, uint16_t port, uint16_t val, int len) +{ + mach_t *mach = (mach_t *) priv; + svga_t *svga = &mach->svga; + ibm8514_t *dev = (ibm8514_t *) svga->dev8514; + + mach_log("Accel OUT Combo=%04x, val=%04x, len=%d.\n", port, val, len); + mach_accel_out_fifo(mach, svga, dev, port, val, len); +} + +static void +ati8514_accel_out_fifo(void *priv, uint16_t port, uint16_t val, int len) +{ + svga_t *svga = (svga_t *) priv; + mach_t *mach = (mach_t *) svga->ext8514; + ibm8514_t *dev = (ibm8514_t *) svga->dev8514; + + mach_accel_out_fifo(mach, svga, dev, port, val, len); +} + +static void +mach_disable_handlers(mach_t *mach) +{ + if (mach->pci_bus) { + io_removehandler(0x01ce, 2, mach_in, NULL, NULL, mach_out, NULL, NULL, mach); + io_removehandler(0x02ea, 4, mach_in, NULL, NULL, mach_out, NULL, NULL, mach); + io_removehandler(0x03c0, 32, mach_in, NULL, NULL, mach_out, NULL, NULL, mach); + mach_io_remove(mach); + } + + mem_mapping_disable(&mach->mmio_linear_mapping); + mem_mapping_disable(&mach->svga.mapping); + if (mach->pci_bus && mach->has_bios) + mem_mapping_disable(&mach->bios_rom.mapping); + + /* Save all the mappings and the timers because they are part of linked lists. */ + reset_state->mmio_linear_mapping = mach->mmio_linear_mapping; + reset_state->svga.mapping = mach->svga.mapping; + reset_state->bios_rom.mapping = mach->bios_rom.mapping; + + reset_state->svga.timer = mach->svga.timer; +} + +static void +mach_reset(void *priv) +{ + mach_t *mach = (mach_t *) priv; + svga_t *svga = &mach->svga; + ibm8514_t *dev = (ibm8514_t *) svga->dev8514; + + if (reset_state != NULL) { + dev->on = 0; + dev->vendor_mode = 0; + dev->_8514on = 0; + dev->_8514crt = 0; + mach_disable_handlers(mach); + mach->force_busy = 0; + dev->force_busy = 0; + dev->force_busy2 = 0; + if (mach->pci_bus) + reset_state->pci_slot = mach->pci_slot; + + *mach = *reset_state; + } +} + static void * mach8_init(const device_t *info) { @@ -5955,6 +7056,7 @@ mach8_init(const device_t *info) ibm8514_t *dev; mach = calloc(1, sizeof(mach_t)); + reset_state = calloc(1, sizeof(mach_t)); svga = &mach->svga; dev = (ibm8514_t *) calloc(1, sizeof(ibm8514_t)); @@ -5967,11 +7069,11 @@ mach8_init(const device_t *info) dev->type = info->flags; dev->local = info->local & 0xff; mach->has_bios = !(info->local & 0xff00); - mach->ramdac_type = mach->pci_bus ? device_get_config_int("ramdac") : 1; + mach->ramdac_type = mach->pci_bus ? device_get_config_int("ramdac") : ATI_68875; dev->vram_amount = device_get_config_int("memory"); dev->vram_512k_8514 = dev->vram_amount == 512; - if ((dev->local & 0xff) >= 0x02) { + if (ATI_MACH32) { if (mach->pci_bus) { if (mach->has_bios) { rom_init(&mach->bios_rom, @@ -6006,7 +7108,7 @@ mach8_init(const device_t *info) 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); - if ((dev->local & 0xff) >= 0x02) { + if (ATI_MACH32) { svga_init(info, svga, mach, dev->vram_amount << 10, /*default: 2MB for Mach32*/ mach_recalctimings, mach_in, mach_out, @@ -6018,7 +7120,7 @@ mach8_init(const device_t *info) dev->vram_mask = dev->vram_size - 1; dev->hwcursor.cur_ysize = 64; mach->config1 = 0x20; - if (mach->pci_bus && !mach->ramdac_type) + if (mach->pci_bus && (mach->ramdac_type == ATI_68860)) svga->ramdac = device_add(&ati68860_ramdac_device); else svga->ramdac = device_add(&ati68875_ramdac_device); @@ -6041,7 +7143,7 @@ mach8_init(const device_t *info) } else if (mach->pci_bus) { video_inform(VIDEO_FLAG_TYPE_8514, &timing_mach32_pci); mach->config1 |= 0x0e; - if (mach->ramdac_type) + if (mach->ramdac_type == ATI_68860) mach->config1 |= 0x0400; else mach->config1 |= 0x0a00; @@ -6054,6 +7156,8 @@ mach8_init(const device_t *info) } 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); + + mem_mapping_set_handler(&svga->mapping, svga_read, svga_readw, svga_readl, mach32_svga_write, mach32_svga_writew, mach32_svga_writel); } else { svga_init(info, svga, mach, (512 << 10), /*default: 512kB VGA for 28800-6 + 1MB for Mach8*/ mach_recalctimings, @@ -6065,7 +7169,7 @@ mach8_init(const device_t *info) dev->changedvram = calloc((dev->vram_size >> 12) + 1, 1); dev->vram_mask = dev->vram_size - 1; video_inform(VIDEO_FLAG_TYPE_8514, &timing_gfxultra_isa); - mach->config1 = 0x01 | 0x02 | 0x08 | 0x80; + mach->config1 = 0x01 | 0x08 | 0x80; if (dev->vram_amount >= 1024) mach->config1 |= 0x20; @@ -6076,6 +7180,7 @@ mach8_init(const device_t *info) svga->getclock = ics2494_getclock; dev->on = 0; + dev->pitch = 1024; dev->ext_pitch = 1024; dev->ext_crt_pitch = 0x80; dev->accel_bpp = 8; @@ -6089,8 +7194,9 @@ mach8_init(const device_t *info) io_sethandler(0x02ea, 4, mach_in, NULL, NULL, mach_out, NULL, NULL, mach); mach_io_set(mach); mach->accel.cmd_type = -2; + dev->accel.cmd_back = 1; - if ((dev->local & 0xff) >= 0x02) { + if (ATI_MACH32) { svga->decode_mask = (4 << 20) - 1; mach->cursor_col_1 = 0xff; mach->ext_cur_col_1_r = 0xff; @@ -6121,6 +7227,11 @@ mach8_init(const device_t *info) } else ati_eeprom_load_mach8_vga(&mach->eeprom, "mach8.nvr"); + dev->accel_out_fifo = mach_combo_accel_out_fifo; + dev->vblank_start = mach_combo_vblank_start; + + *reset_state = *mach; + return mach; } @@ -6130,19 +7241,28 @@ ati8514_init(svga_t *svga, void *ext8514, void *dev8514) mach_t *mach = (mach_t *) ext8514; ibm8514_t *dev = (ibm8514_t *) dev8514; + /*Init as 1024x768 87hz interlaced first, per 8514/A.*/ dev->on = 0; + dev->pitch = 1024; dev->ext_pitch = 1024; dev->ext_crt_pitch = 0x80; dev->accel_bpp = 8; dev->rowoffset = 0x80; - dev->hdisp = 1024; - dev->vdisp = 768; + dev->hdisped = 0x7f; + dev->v_disp = 0x05ff; + dev->htotal = 0x9d; + dev->v_total_reg = 0x0668; + dev->v_sync_start = 0x0600; + dev->disp_cntl = 0x33; + mach->accel.clock_sel = 0x1c; + dev->accel.cmd_back = 1; io_sethandler(0x02ea, 4, ati8514_in, NULL, NULL, ati8514_out, NULL, NULL, svga); ati8514_io_set(svga); + mach->accel.cmd_type = -2; mach->mca_bus = !!(dev->type & DEVICE_MCA); - mach->config1 = 0x02 | 0x08 | 0x80; + mach->config1 = 0x08 | 0x80; if (mach->mca_bus) mach->config1 |= 0x04; @@ -6150,7 +7270,10 @@ ati8514_init(svga_t *svga, void *ext8514, void *dev8514) if (dev->vram_amount >= 1024) mach->config1 |= 0x20; - mach->config2 = 0x02; + mach->config2 = 0x01 | 0x02; + + dev->accel_out_fifo = ati8514_accel_out_fifo; + dev->vblank_start = ati8514_vblank_start; } static int @@ -6198,6 +7321,10 @@ mach_close(void *priv) } svga_close(svga); + + free(reset_state); + reset_state = NULL; + free(mach); } @@ -6222,197 +7349,161 @@ mach_force_redraw(void *priv) // clang-format off static const device_config_t mach8_config[] = { { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 1024, - .selection = { - { - .description = "512 KB", - .value = 512 - }, - { - .description = "1 MB", - .value = 1024 - }, - { - .description = "" - } - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 1024, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "512 KB", .value = 512 }, + { .description = "1 MB", .value = 1024 }, + { .description = "" } + }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; -// 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 = "" - } - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2048, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "512 KB", .value = 512 }, + { .description = "1 MB", .value = 1024 }, + { .description = "2 MB", .value = 2048 }, + { .description = "4 MB", .value = 4096 }, + { .description = "" } + }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; -// clang-format off static const device_config_t mach32_pci_config[] = { { - .name = "ramdac", - .description = "RAMDAC type", - .type = CONFIG_SELECTION, - .default_int = 0, - .selection = { - { - .description = "ATI 68860", - .value = 0 - }, - { - .description = "ATI 68875", - .value = 1 - }, - { - .description = "" - } - } + .name = "ramdac", + .description = "RAMDAC type", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = ATI_68860, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "ATI 68860", .value = ATI_68860 }, + { .description = "ATI 68875", .value = ATI_68875 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .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 = "" - } - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2048, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "512 KB", .value = 512 }, + { .description = "1 MB", .value = 1024 }, + { .description = "2 MB", .value = 2048 }, + { .description = "4 MB", .value = 4096 }, + { .description = "" } + }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; +// clang-format on const device_t mach8_vga_isa_device = { - .name = "ATI Mach8 (ATI Graphics Ultra) (ISA)", + .name = "ATI Mach8 (ATI Graphics Ultra) (ISA)", .internal_name = "mach8_vga_isa", - .flags = DEVICE_ISA, - .local = 1, - .init = mach8_init, - .close = mach_close, - .reset = NULL, - { .available = mach8_vga_available }, + .flags = DEVICE_ISA, + .local = ATI_38800_TYPE, + .init = mach8_init, + .close = mach_close, + .reset = mach_reset, + .available = mach8_vga_available, .speed_changed = mach_speed_changed, - .force_redraw = mach_force_redraw, - .config = mach8_config + .force_redraw = mach_force_redraw, + .config = mach8_config }; const device_t mach32_isa_device = { - .name = "ATI Mach32 (ISA)", + .name = "ATI Mach32 (ISA)", .internal_name = "mach32_isa", - .flags = DEVICE_ISA, - .local = 2, - .init = mach8_init, - .close = mach_close, - .reset = NULL, - { .available = mach32_isa_available }, + .flags = DEVICE_ISA, + .local = ATI_68800_TYPE, + .init = mach8_init, + .close = mach_close, + .reset = mach_reset, + .available = mach32_isa_available, .speed_changed = mach_speed_changed, - .force_redraw = mach_force_redraw, - .config = mach32_config + .force_redraw = mach_force_redraw, + .config = mach32_config }; const device_t mach32_vlb_device = { - .name = "ATI Mach32 (VLB)", + .name = "ATI Mach32 (VLB)", .internal_name = "mach32_vlb", - .flags = DEVICE_VLB, - .local = 2, - .init = mach8_init, - .close = mach_close, - .reset = NULL, - { .available = mach32_vlb_available }, + .flags = DEVICE_VLB, + .local = ATI_68800_TYPE, + .init = mach8_init, + .close = mach_close, + .reset = mach_reset, + .available = mach32_vlb_available, .speed_changed = mach_speed_changed, - .force_redraw = mach_force_redraw, - .config = mach32_config + .force_redraw = mach_force_redraw, + .config = mach32_config }; const device_t mach32_mca_device = { - .name = "ATI Mach32 (MCA)", + .name = "ATI Mach32 (MCA)", .internal_name = "mach32_mca", - .flags = DEVICE_MCA, - .local = 2, - .init = mach8_init, - .close = mach_close, - .reset = NULL, - { .available = mach32_mca_available }, + .flags = DEVICE_MCA, + .local = ATI_68800_TYPE, + .init = mach8_init, + .close = mach_close, + .reset = mach_reset, + .available = mach32_mca_available, .speed_changed = mach_speed_changed, - .force_redraw = mach_force_redraw, - .config = mach32_config + .force_redraw = mach_force_redraw, + .config = mach32_config }; const device_t mach32_pci_device = { - .name = "ATI Mach32 (PCI)", + .name = "ATI Mach32 (PCI)", .internal_name = "mach32_pci", - .flags = DEVICE_PCI, - .local = 2, - .init = mach8_init, - .close = mach_close, - .reset = NULL, - { .available = mach32_pci_available }, + .flags = DEVICE_PCI, + .local = ATI_68800_TYPE, + .init = mach8_init, + .close = mach_close, + .reset = mach_reset, + .available = mach32_pci_available, .speed_changed = mach_speed_changed, - .force_redraw = mach_force_redraw, - .config = mach32_pci_config + .force_redraw = mach_force_redraw, + .config = mach32_pci_config }; const device_t mach32_onboard_pci_device = { - .name = "ATI Mach32 (PCI) On-Board", + .name = "ATI Mach32 (PCI) On-Board", .internal_name = "mach32_pci_onboard", - .flags = DEVICE_PCI, - .local = 2 | 0x100, - .init = mach8_init, - .close = mach_close, - .reset = NULL, - { .available = NULL }, + .flags = DEVICE_PCI, + .local = ATI_68800_TYPE | 0x100, + .init = mach8_init, + .close = mach_close, + .reset = mach_reset, + .available = NULL, .speed_changed = mach_speed_changed, - .force_redraw = mach_force_redraw, - .config = mach32_pci_config + .force_redraw = mach_force_redraw, + .config = mach32_pci_config }; - diff --git a/src/video/vid_bochs_vbe.c b/src/video/vid_bochs_vbe.c index a4459ce4c..fd5772b19 100644 --- a/src/video/vid_bochs_vbe.c +++ b/src/video/vid_bochs_vbe.c @@ -336,22 +336,15 @@ bochs_vbe_recalctimings(svga_t* svga) if (svga->bpp == 4) { svga->rowoffset = (dev->vbe_regs[VBE_DISPI_INDEX_VIRT_WIDTH] / 2) >> 3; - svga->ma_latch = (dev->vbe_regs[VBE_DISPI_INDEX_Y_OFFSET] * svga->rowoffset) + + svga->memaddr_latch = (dev->vbe_regs[VBE_DISPI_INDEX_Y_OFFSET] * svga->rowoffset) + (dev->vbe_regs[VBE_DISPI_INDEX_X_OFFSET] >> 3); + + svga->fullchange = 3; } else { svga->rowoffset = dev->vbe_regs[VBE_DISPI_INDEX_VIRT_WIDTH] * ((svga->bpp == 15) ? 2 : (svga->bpp / 8)); - svga->ma_latch = (dev->vbe_regs[VBE_DISPI_INDEX_Y_OFFSET] * svga->rowoffset) + - (dev->vbe_regs[VBE_DISPI_INDEX_X_OFFSET] * ((svga->bpp == 15) ? 2 : (svga->bpp / 8))); - } - if (svga->ma_latch != dev->ma_latch_old) { - if (svga->bpp == 4) { - svga->maback = (svga->maback - (dev->ma_latch_old << 2)) + - (svga->ma_latch << 2); - } else { - svga->maback = (svga->maback - (dev->ma_latch_old)) + - (svga->ma_latch); - dev->ma_latch_old = svga->ma_latch; - } + svga->memaddr_latch = (dev->vbe_regs[VBE_DISPI_INDEX_Y_OFFSET] * svga->rowoffset) + + (dev->vbe_regs[VBE_DISPI_INDEX_X_OFFSET] * ((svga->bpp == 15) ? 2 : (svga->bpp / 8))); + svga->fullchange = 3; } if (svga->bpp == 4) @@ -477,23 +470,15 @@ bochs_vbe_outw(const uint16_t addr, const uint16_t val, void *priv) svga_t *svga = &dev->svga; if (svga->bpp == 4) { svga->rowoffset = (dev->vbe_regs[VBE_DISPI_INDEX_VIRT_WIDTH] / 2) >> 3; - svga->ma_latch = (dev->vbe_regs[VBE_DISPI_INDEX_Y_OFFSET] * svga->rowoffset) + + svga->memaddr_latch = (dev->vbe_regs[VBE_DISPI_INDEX_Y_OFFSET] * svga->rowoffset) + (dev->vbe_regs[VBE_DISPI_INDEX_X_OFFSET] >> 3); } else { svga->rowoffset = dev->vbe_regs[VBE_DISPI_INDEX_VIRT_WIDTH] * ((svga->bpp == 15) ? 2 : (svga->bpp / 8)); - svga->ma_latch = (dev->vbe_regs[VBE_DISPI_INDEX_Y_OFFSET] * svga->rowoffset) + - (dev->vbe_regs[VBE_DISPI_INDEX_X_OFFSET] * ((svga->bpp == 15) ? 2 : (svga->bpp / 8))); - } - if (svga->ma_latch != dev->ma_latch_old) { - if (svga->bpp == 4) { - svga->maback = (svga->maback - (dev->ma_latch_old << 2)) + - (svga->ma_latch << 2); - } else { - svga->maback = (svga->maback - (dev->ma_latch_old)) + - (svga->ma_latch); - dev->ma_latch_old = svga->ma_latch; - } + svga->memaddr_latch = (dev->vbe_regs[VBE_DISPI_INDEX_Y_OFFSET] * svga->rowoffset) + + (dev->vbe_regs[VBE_DISPI_INDEX_X_OFFSET] * ((svga->bpp == 15) ? 2 : (svga->bpp / 8))); } + + svga->fullchange = 3; } else svga_recalctimings(&dev->svga); @@ -590,7 +575,7 @@ bochs_vbe_out(uint16_t addr, uint8_t val, void *priv) 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); + svga->memaddr_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5); } else { svga->fullchange = changeframecount; svga_recalctimings(svga); @@ -686,7 +671,7 @@ bochs_vbe_pci_read(const int func, const int addr, void *priv) ret = dev->pci_rom_enable & 0x01; break; case 0x32: - ret = dev->rom_addr & 0xff; + ret = dev->rom_addr & 0xfc; break; case 0x33: ret = (dev->rom_addr & 0xff00) >> 8; @@ -723,7 +708,7 @@ bochs_vbe_disable_handlers(bochs_vbe_t *dev) reset_state->bios_rom.mapping = dev->bios_rom.mapping; reset_state->svga.timer = dev->svga.timer; - reset_state->svga.timer8514 = dev->svga.timer8514; + reset_state->svga.timer_8514 = dev->svga.timer_8514; } static void @@ -743,6 +728,7 @@ bochs_vbe_pci_write(const int func, const int addr, const uint8_t val, void *pri mem_mapping_disable(&dev->linear_mapping_2); mem_mapping_disable(&dev->linear_mapping); mem_mapping_disable(&dev->svga.mapping); + mem_mapping_disable(&dev->bios_rom.mapping); if (dev->pci_conf_status & PCI_COMMAND_IO) { io_sethandler(0x03c0, 0x0020, bochs_vbe_in, NULL, NULL, bochs_vbe_out, NULL, NULL, dev); @@ -751,11 +737,13 @@ bochs_vbe_pci_write(const int func, const int addr, const uint8_t val, void *pri } if (dev->pci_conf_status & PCI_COMMAND_MEM) { mem_mapping_enable(&dev->svga.mapping); - if (dev->pci_regs[0x13] != 0x00) { + if ((dev->pci_regs[0x13] != 0x00) && (dev->pci_regs[0x13] != 0xff)) { mem_mapping_enable(&dev->linear_mapping); if (dev->pci_regs[0x13] != 0xe0) mem_mapping_enable(&dev->linear_mapping_2); } + if (dev->pci_rom_enable && (dev->rom_addr != 0x0000) && (dev->rom_addr < 0xfff8)) + mem_mapping_set_addr(&dev->bios_rom.mapping, dev->rom_addr << 16, 0x10000); } break; case 0x13: @@ -764,7 +752,7 @@ bochs_vbe_pci_write(const int func, const int addr, const uint8_t val, void *pri mem_mapping_disable(&dev->linear_mapping_2); mem_mapping_disable(&dev->linear_mapping); - if ((dev->pci_conf_status & PCI_COMMAND_MEM) && (val != 0x00)) { + if ((dev->pci_conf_status & PCI_COMMAND_MEM) && (val != 0x00) && (val != 0xff)) { mem_mapping_set_addr(&dev->linear_mapping, val << 24, 0x01000000); if (val != 0xe0) mem_mapping_set_addr(&dev->linear_mapping_2, 0xe0000000, 0x01000000); @@ -776,18 +764,26 @@ bochs_vbe_pci_write(const int func, const int addr, const uint8_t val, void *pri case 0x30: dev->pci_rom_enable = val & 0x01; mem_mapping_disable(&dev->bios_rom.mapping); - if (dev->pci_rom_enable) + if (dev->pci_rom_enable && (dev->pci_conf_status & PCI_COMMAND_MEM) && + (dev->rom_addr != 0x0000) && (dev->rom_addr < 0xfff8)) { mem_mapping_set_addr(&dev->bios_rom.mapping, dev->rom_addr << 16, 0x10000); + } break; case 0x32: dev->rom_addr = (dev->rom_addr & 0xff00) | (val & 0xfc); - if (dev->pci_rom_enable) + mem_mapping_disable(&dev->bios_rom.mapping); + if (dev->pci_rom_enable && (dev->pci_conf_status & PCI_COMMAND_MEM) && + (dev->rom_addr != 0x0000) && (dev->rom_addr < 0xfff8)) { mem_mapping_set_addr(&dev->bios_rom.mapping, dev->rom_addr << 16, 0x10000); + } break; case 0x33: dev->rom_addr = (dev->rom_addr & 0x00ff) | (val << 8); - if (dev->pci_rom_enable) + mem_mapping_disable(&dev->bios_rom.mapping); + if (dev->pci_rom_enable && (dev->pci_conf_status & PCI_COMMAND_MEM) && + (dev->rom_addr != 0x0000) && (dev->rom_addr < 0xfff8)) { mem_mapping_set_addr(&dev->bios_rom.mapping, dev->rom_addr << 16, 0x10000); + } break; } } @@ -815,22 +811,22 @@ bochs_vbe_init(const device_t *info) dev->vram_size = device_get_config_int("memory") * (1 << 20); rom_init(&dev->bios_rom, "roms/video/bochs/VGABIOS-lgpl-latest.bin", - 0xc0000, 0x10000, 0xffff, 0x0000, + 0xc0000, 0x8000, 0x7fff, 0x0000, MEM_MAPPING_EXTERNAL); if (dev->id5_val == VBE_DISPI_ID4) { /* Patch the BIOS to match the PCI ID. */ dev->bios_rom.rom[0x010c] = 0xee; - dev->bios_rom.rom[0x8dff] -= (0xee - 0x34); + dev->bios_rom.rom[0x7fff] -= (0xee - 0x34); dev->bios_rom.rom[0x010d] = 0x80; - dev->bios_rom.rom[0x8dff] -= (0x80 - 0x12); + dev->bios_rom.rom[0x7fff] -= (0x80 - 0x12); dev->bios_rom.rom[0x010e] = 0xef; - dev->bios_rom.rom[0x8dff] -= (0xef - 0x11); + dev->bios_rom.rom[0x7fff] -= (0xef - 0x11); dev->bios_rom.rom[0x010f] = 0xbe; - dev->bios_rom.rom[0x8dff] -= (0xbe - 0x11); + dev->bios_rom.rom[0x7fff] -= (0xbe - 0x11); } video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_bochs); @@ -921,50 +917,37 @@ bochs_vbe_force_redraw(void *priv) static const device_config_t bochs_vbe_config[] = { // clang-format off { - .name = "revision", - .description = "Revision", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "VirtualBox", - .value = VBE_DISPI_ID4 - }, - { - .description = "Bochs latest", - .value = VBE_DISPI_ID5 - }, - { - .description = "" - } + .name = "revision", + .description = "Revision", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = VBE_DISPI_ID5, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "VirtualBox", .value = VBE_DISPI_ID4 }, + { .description = "Bochs latest", .value = VBE_DISPI_ID5 }, + { .description = "" } }, - .default_int = VBE_DISPI_ID5 + .bios = { { 0 } } }, { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "4 MB", - .value = 4 - }, - { - .description = "8 MB", - .value = 8 - }, - { - .description = "16 MB", - .value = 16 - }, - { - .description = "" - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 16, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "4 MB", .value = 4 }, + { .description = "8 MB", .value = 8 }, + { .description = "16 MB", .value = 16 }, + { .description = "" } }, - .default_int = 16 + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -976,7 +959,7 @@ const device_t bochs_svga_device = { .init = bochs_vbe_init, .close = bochs_vbe_close, .reset = bochs_vbe_reset, - { .available = bochs_vbe_available }, + .available = bochs_vbe_available, .speed_changed = bochs_vbe_speed_changed, .force_redraw = bochs_vbe_force_redraw, .config = bochs_vbe_config diff --git a/src/video/vid_cga.c b/src/video/vid_cga.c index c58c319df..79b9360f5 100644 --- a/src/video/vid_cga.c +++ b/src/video/vid_cga.c @@ -73,10 +73,10 @@ void cga_recalctimings(cga_t *cga); static void cga_update_latch(cga_t *cga) { - uint32_t lp_latch = cga->displine * cga->crtc[1]; + uint32_t lp_latch = cga->displine * cga->crtc[CGA_CRTC_HDISP]; - cga->crtc[0x10] = (lp_latch >> 8) & 0x3f; - cga->crtc[0x11] = lp_latch & 0xff; + cga->crtc[CGA_CRTC_LIGHT_PEN_ADDR_HIGH] = (lp_latch >> 8) & 0x3f; + cga->crtc[CGA_CRTC_LIGHT_PEN_ADDR_LOW] = lp_latch & 0xff; } void @@ -89,20 +89,22 @@ cga_out(uint16_t addr, uint8_t val, void *priv) addr = (addr & 0xff9) | 0x004; switch (addr) { - case 0x3D4: + case CGA_REGISTER_CRTC_INDEX: cga->crtcreg = val & 31; return; - case 0x3D5: + case CGA_REGISTER_CRTC_DATA: old = cga->crtc[cga->crtcreg]; cga->crtc[cga->crtcreg] = val & crtcmask[cga->crtcreg]; if (old != val) { + // Recalc the timings if we are writing any invalid CRTC register or a valid CRTC register + // except the CURSOR and LIGHT PEN registers if ((cga->crtcreg < 0xe) || (cga->crtcreg > 0x11)) { cga->fullchange = changeframecount; cga_recalctimings(cga); } } return; - case 0x3D8: + case CGA_REGISTER_MODE_CONTROL: old = cga->cgamode; cga->cgamode = val; @@ -113,18 +115,18 @@ cga_out(uint16_t addr, uint8_t val, void *priv) cga_recalctimings(cga); } return; - case 0x3D9: + case CGA_REGISTER_COLOR_SELECT: old = cga->cgacol; cga->cgacol = val; if (old ^ val) cga_recalctimings(cga); return; - case 0x3DB: + case CGA_REGISTER_CLEAR_LIGHT_PEN_LATCH: if (cga->lp_strobe == 1) cga->lp_strobe = 0; return; - case 0x3DC: + case CGA_REGISTER_SET_LIGHT_PEN_LATCH: if (cga->lp_strobe == 0) { cga->lp_strobe = 1; cga_update_latch(cga); @@ -146,21 +148,20 @@ cga_in(uint16_t addr, void *priv) addr = (addr & 0xff9) | 0x004; switch (addr) { - case 0x3D4: + case CGA_REGISTER_CRTC_INDEX: ret = cga->crtcreg; break; - case 0x3D5: + case CGA_REGISTER_CRTC_DATA: ret = cga->crtc[cga->crtcreg]; break; - case 0x3DA: + case CGA_REGISTER_STATUS: ret = cga->cgastat; break; - - case 0x3DB: + case CGA_REGISTER_CLEAR_LIGHT_PEN_LATCH: if (cga->lp_strobe == 1) cga->lp_strobe = 0; break; - case 0x3DC: + case CGA_REGISTER_SET_LIGHT_PEN_LATCH: if (cga->lp_strobe == 0) { cga->lp_strobe = 1; cga_update_latch(cga); @@ -235,12 +236,12 @@ cga_recalctimings(cga_t *cga) double _dispontime; double _dispofftime; - if (cga->cgamode & 1) { - disptime = (double) (cga->crtc[0] + 1); - _dispontime = (double) cga->crtc[1]; + if (cga->cgamode & CGA_MODE_FLAG_HIGHRES) { + disptime = (double) (cga->crtc[CGA_CRTC_HTOTAL] + 1); + _dispontime = (double) cga->crtc[CGA_CRTC_HDISP]; } else { - disptime = (double) ((cga->crtc[0] + 1) << 1); - _dispontime = (double) (cga->crtc[1] << 1); + disptime = (double) ((cga->crtc[CGA_CRTC_HTOTAL] + 1) << 1); + _dispontime = (double) (cga->crtc[CGA_CRTC_HDISP] << 1); } _dispofftime = disptime - _dispontime; _dispontime = _dispontime * CGACONST; @@ -252,95 +253,97 @@ cga_recalctimings(cga_t *cga) static void cga_render(cga_t *cga, int line) { - uint16_t ca = (cga->crtc[15] | (cga->crtc[14] << 8)) & 0x3fff; + uint16_t cursoraddr = (cga->crtc[CGA_CRTC_CURSOR_ADDR_LOW] | (cga->crtc[CGA_CRTC_CURSOR_ADDR_HIGH] << 8)) & 0x3fff; int drawcursor; int x; - int c; + int column; uint8_t chr; uint8_t attr; uint16_t dat; int cols[4]; int col; - if ((cga->cgamode & 0x12) == 0x12) { - for (c = 0; c < 8; ++c) { - buffer32->line[line][c] = 0; - if (cga->cgamode & 1) - buffer32->line[line][c + (cga->crtc[1] << 3) + 8] = 0; + int32_t highres_graphics_flag = (CGA_MODE_FLAG_HIGHRES_GRAPHICS | CGA_MODE_FLAG_GRAPHICS); + + if (((cga->cgamode & highres_graphics_flag) == highres_graphics_flag)) { + for (column = 0; column < 8; ++column) { + buffer32->line[line][column] = 0; + if (cga->cgamode & CGA_MODE_FLAG_HIGHRES) + buffer32->line[line][column + (cga->crtc[CGA_CRTC_HDISP] << 3) + 8] = 0; else - buffer32->line[line][c + (cga->crtc[1] << 4) + 8] = 0; + buffer32->line[line][column + (cga->crtc[CGA_CRTC_HDISP] << 4) + 8] = 0; } } else { - for (c = 0; c < 8; ++c) { - buffer32->line[line][c] = (cga->cgacol & 15) + 16; - if (cga->cgamode & 1) - buffer32->line[line][c + (cga->crtc[1] << 3) + 8] = (cga->cgacol & 15) + 16; + for (column = 0; column < 8; ++column) { + buffer32->line[line][column] = (cga->cgacol & 15) + 16; + if (cga->cgamode & CGA_MODE_FLAG_HIGHRES) + buffer32->line[line][column + (cga->crtc[CGA_CRTC_HDISP] << 3) + 8] = (cga->cgacol & 15) + 16; else - buffer32->line[line][c + (cga->crtc[1] << 4) + 8] = (cga->cgacol & 15) + 16; + buffer32->line[line][column + (cga->crtc[CGA_CRTC_HDISP] << 4) + 8] = (cga->cgacol & 15) + 16; } } - if (cga->cgamode & 1) { - for (x = 0; x < cga->crtc[1]; x++) { - if (cga->cgamode & 8) { + if (cga->cgamode & CGA_MODE_FLAG_HIGHRES) { + for (x = 0; x < cga->crtc[CGA_CRTC_HDISP]; x++) { + if (cga->cgamode & CGA_MODE_FLAG_VIDEO_ENABLE) { chr = cga->charbuffer[x << 1]; attr = cga->charbuffer[(x << 1) + 1]; } else chr = attr = 0; - drawcursor = ((cga->ma == ca) && cga->con && cga->cursoron); + drawcursor = ((cga->memaddr == cursoraddr) && cga->cursorvisible && cga->cursoron); cols[1] = (attr & 15) + 16; - if (cga->cgamode & 0x20) { + if (cga->cgamode & CGA_MODE_FLAG_BLINK) { cols[0] = ((attr >> 4) & 7) + 16; if ((cga->cgablink & 8) && (attr & 0x80) && !cga->drawcursor) cols[1] = cols[0]; } else cols[0] = (attr >> 4) + 16; if (drawcursor) { - for (c = 0; c < 8; c++) { - buffer32->line[line][(x << 3) + c + 8] - = cols[(fontdat[chr + cga->fontbase][cga->sc & 7] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; + for (column = 0; column < 8; column++) { + buffer32->line[line][(x << 3) + column + 8] + = cols[(fontdat[chr + cga->fontbase][cga->scanline & 7] & (1 << (column ^ 7))) ? 1 : 0] ^ 15; } } else { - for (c = 0; c < 8; c++) { - buffer32->line[line][(x << 3) + c + 8] - = cols[(fontdat[chr + cga->fontbase][cga->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; + for (column = 0; column < 8; column++) { + buffer32->line[line][(x << 3) + column + 8] + = cols[(fontdat[chr + cga->fontbase][cga->scanline & 7] & (1 << (column ^ 7))) ? 1 : 0]; } } - cga->ma++; + cga->memaddr++; } - } 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]; + } else if (!(cga->cgamode & CGA_MODE_FLAG_GRAPHICS)) { + for (x = 0; x < cga->crtc[CGA_CRTC_HDISP]; x++) { + if (cga->cgamode & CGA_MODE_FLAG_VIDEO_ENABLE) { + chr = cga->vram[(cga->memaddr << 1) & 0x3fff]; + attr = cga->vram[((cga->memaddr << 1) + 1) & 0x3fff]; } else chr = attr = 0; - drawcursor = ((cga->ma == ca) && cga->con && cga->cursoron); + drawcursor = ((cga->memaddr == cursoraddr) && cga->cursorvisible && cga->cursoron); cols[1] = (attr & 15) + 16; - if (cga->cgamode & 0x20) { + if (cga->cgamode & CGA_MODE_FLAG_BLINK) { cols[0] = ((attr >> 4) & 7) + 16; if ((cga->cgablink & 8) && (attr & 0x80)) cols[1] = cols[0]; } else cols[0] = (attr >> 4) + 16; - cga->ma++; + cga->memaddr++; if (drawcursor) { - for (c = 0; c < 8; c++) { - buffer32->line[line][(x << 4) + (c << 1) + 8] - = buffer32->line[line][(x << 4) + (c << 1) + 9] - = cols[(fontdat[chr + cga->fontbase][cga->sc & 7] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; + for (column = 0; column < 8; column++) { + buffer32->line[line][(x << 4) + (column << 1) + 8] + = buffer32->line[line][(x << 4) + (column << 1) + 9] + = cols[(fontdat[chr + cga->fontbase][cga->scanline & 7] & (1 << (column ^ 7))) ? 1 : 0] ^ 15; } } else { - for (c = 0; c < 8; c++) { - buffer32->line[line][(x << 4) + (c << 1) + 8] - = buffer32->line[line][(x << 4) + (c << 1) + 9] - = cols[(fontdat[chr + cga->fontbase][cga->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; + for (column = 0; column < 8; column++) { + buffer32->line[line][(x << 4) + (column << 1) + 8] + = buffer32->line[line][(x << 4) + (column << 1) + 9] + = cols[(fontdat[chr + cga->fontbase][cga->scanline & 7] & (1 << (column ^ 7))) ? 1 : 0]; } } } - } else if (!(cga->cgamode & 16)) { + } else if (!(cga->cgamode & CGA_MODE_FLAG_HIGHRES_GRAPHICS)) { cols[0] = (cga->cgacol & 15) | 16; col = (cga->cgacol & 16) ? 24 : 16; - if (cga->cgamode & 4) { + if (cga->cgamode & CGA_MODE_FLAG_BW) { cols[1] = col | 3; /* Cyan */ cols[2] = col | 4; /* Red */ cols[3] = col | 7; /* White */ @@ -353,16 +356,16 @@ cga_render(cga_t *cga, int line) cols[2] = col | 4; /* Red */ cols[3] = col | 6; /* Yellow */ } - for (x = 0; x < cga->crtc[1]; x++) { - if (cga->cgamode & 8) - dat = (cga->vram[((cga->ma << 1) & 0x1fff) + ((cga->sc & 1) * 0x2000)] << 8) | - cga->vram[((cga->ma << 1) & 0x1fff) + ((cga->sc & 1) * 0x2000) + 1]; + for (x = 0; x < cga->crtc[CGA_CRTC_HDISP]; x++) { + if (cga->cgamode & CGA_MODE_FLAG_VIDEO_ENABLE) + dat = (cga->vram[((cga->memaddr << 1) & 0x1fff) + ((cga->scanline & 1) * 0x2000)] << 8) | + cga->vram[((cga->memaddr << 1) & 0x1fff) + ((cga->scanline & 1) * 0x2000) + 1]; else dat = 0; - cga->ma++; - for (c = 0; c < 8; c++) { - buffer32->line[line][(x << 4) + (c << 1) + 8] - = buffer32->line[line][(x << 4) + (c << 1) + 9] + cga->memaddr++; + for (column = 0; column < 8; column++) { + buffer32->line[line][(x << 4) + (column << 1) + 8] + = buffer32->line[line][(x << 4) + (column << 1) + 9] = cols[dat >> 14]; dat <<= 2; } @@ -370,15 +373,15 @@ cga_render(cga_t *cga, int line) } else { cols[0] = 0; cols[1] = (cga->cgacol & 15) + 16; - for (x = 0; x < cga->crtc[1]; x++) { - if (cga->cgamode & 8) - dat = (cga->vram[((cga->ma << 1) & 0x1fff) + ((cga->sc & 1) * 0x2000)] << 8) | - cga->vram[((cga->ma << 1) & 0x1fff) + ((cga->sc & 1) * 0x2000) + 1]; + for (x = 0; x < cga->crtc[CGA_CRTC_HDISP]; x++) { + if (cga->cgamode & CGA_MODE_FLAG_VIDEO_ENABLE) + dat = (cga->vram[((cga->memaddr << 1) & 0x1fff) + ((cga->scanline & 1) * 0x2000)] << 8) | + cga->vram[((cga->memaddr << 1) & 0x1fff) + ((cga->scanline & 1) * 0x2000) + 1]; else dat = 0; - cga->ma++; - for (c = 0; c < 16; c++) { - buffer32->line[line][(x << 4) + c + 8] = cols[dat >> 15]; + cga->memaddr++; + for (column = 0; column < 16; column++) { + buffer32->line[line][(x << 4) + column + 8] = cols[dat >> 15]; dat <<= 1; } } @@ -388,12 +391,14 @@ cga_render(cga_t *cga, int line) static void cga_render_blank(cga_t *cga, int line) { - int col = ((cga->cgamode & 0x12) == 0x12) ? 0 : (cga->cgacol & 15) + 16; + int32_t highres_graphics_flag = (CGA_MODE_FLAG_HIGHRES_GRAPHICS | CGA_MODE_FLAG_GRAPHICS); - if (cga->cgamode & 1) - hline(buffer32, 0, line, (cga->crtc[1] << 3) + 16, col); + int col = ((cga->cgamode & highres_graphics_flag) == highres_graphics_flag) ? 0 : (cga->cgacol & 15) + 16; + + if (cga->cgamode & CGA_MODE_FLAG_HIGHRES) + hline(buffer32, 0, line, (cga->crtc[CGA_CRTC_HDISP] << 3) + 16, col); else - hline(buffer32, 0, line, (cga->crtc[1] << 4) + 16, col); + hline(buffer32, 0, line, (cga->crtc[CGA_CRTC_HDISP] << 4) + 16, col); } static void @@ -401,14 +406,15 @@ cga_render_process(cga_t *cga, int line) { int x; uint8_t border; + int32_t highres_graphics_flag = (CGA_MODE_FLAG_HIGHRES_GRAPHICS | CGA_MODE_FLAG_GRAPHICS); - if (cga->cgamode & 1) - x = (cga->crtc[1] << 3) + 16; + if (cga->cgamode & CGA_MODE_FLAG_HIGHRES) + x = (cga->crtc[CGA_CRTC_HDISP] << 3) + 16; else - x = (cga->crtc[1] << 4) + 16; + x = (cga->crtc[CGA_CRTC_HDISP] << 4) + 16; if (cga->composite) { - border = ((cga->cgamode & 0x12) == 0x12) ? 0 : (cga->cgacol & 15); + border = ((cga->cgamode & highres_graphics_flag) == highres_graphics_flag) ? 0 : (cga->cgacol & 15); Composite_Process(cga->cgamode, border, x >> 2, buffer32->line[line]); } else @@ -442,13 +448,13 @@ cga_interpolate_linear(uint8_t co1, uint8_t co2, double fraction) r2 = pow((r1 >= 0.0) ? r1 : -r1, 1.0 / 2.19921875); if (r1 <= 0.0) r2 = -r2; - ret = (uint8_t) (r2 * 255.0); + ret = (uint8_t) round(r2 * 255.0); return ret; } static color_t -cga_interpolate_lookup(cga_t *cga, color_t color1, color_t color2, double fraction) +cga_interpolate_lookup(cga_t *cga, color_t color1, color_t color2, UNUSED(double fraction)) { color_t ret; uint8_t dt = cga->double_type - DOUBLE_INTERPOLATE_SRGB; @@ -513,7 +519,7 @@ cga_poll(void *priv) { cga_t *cga = (cga_t *) priv; int x; - int oldsc; + int scanline_old; int oldvc; int xs_temp; int ys_temp; @@ -523,9 +529,9 @@ cga_poll(void *priv) timer_advance_u64(&cga->timer, cga->dispofftime); cga->cgastat |= 1; cga->linepos = 1; - oldsc = cga->sc; - if ((cga->crtc[8] & 3) == 3) - cga->sc = ((cga->sc << 1) + cga->oddeven) & 7; + scanline_old = cga->scanline; + if ((cga->crtc[CGA_CRTC_INTERLACE] & 3) == 3) + cga->scanline = ((cga->scanline << 1) + cga->oddeven) & 7; if (cga->cgadispon) { if (cga->displine < cga->firstline) { cga->firstline = cga->displine; @@ -541,9 +547,9 @@ cga_poll(void *priv) cga_render(cga, cga->displine); break; case DOUBLE_SIMPLE: - old_ma = cga->ma; + old_ma = cga->memaddr; cga_render(cga, cga->displine << 1); - cga->ma = old_ma; + cga->memaddr = old_ma; cga_render(cga, (cga->displine << 1) + 1); break; } @@ -572,8 +578,8 @@ cga_poll(void *priv) break; } - cga->sc = oldsc; - if (cga->vc == cga->crtc[7] && !cga->sc) + cga->scanline = scanline_old; + if (cga->vc == cga->crtc[CGA_CRTC_VSYNC] && !cga->scanline) cga->cgastat |= 8; cga->displine++; if (cga->displine >= 360) @@ -586,41 +592,41 @@ cga_poll(void *priv) if (!cga->vsynctime) cga->cgastat &= ~8; } - if (cga->sc == (cga->crtc[11] & 31) || ((cga->crtc[8] & 3) == 3 && - cga->sc == ((cga->crtc[11] & 31) >> 1))) { - cga->con = 0; - cga->coff = 1; + if (cga->scanline == (cga->crtc[CGA_CRTC_CURSOR_END] & 31) || ((cga->crtc[CGA_CRTC_INTERLACE] & 3) == 3 && + cga->scanline == ((cga->crtc[CGA_CRTC_CURSOR_END] & 31) >> 1))) { + cga->cursorvisible = 0; } - if ((cga->crtc[8] & 3) == 3 && cga->sc == (cga->crtc[9] >> 1)) - cga->maback = cga->ma; + if ((cga->crtc[CGA_CRTC_INTERLACE] & 3) == 3 && cga->scanline == (cga->crtc[CGA_CRTC_MAX_SCANLINE_ADDR] >> 1)) + cga->memaddr_backup = cga->memaddr; if (cga->vadj) { - cga->sc++; - cga->sc &= 31; - cga->ma = cga->maback; + cga->scanline++; + cga->scanline &= 31; + cga->memaddr = cga->memaddr_backup; cga->vadj--; if (!cga->vadj) { cga->cgadispon = 1; - cga->ma = cga->maback = (cga->crtc[13] | (cga->crtc[12] << 8)) & 0x3fff; - cga->sc = 0; + cga->memaddr = cga->memaddr_backup = (cga->crtc[CGA_CRTC_START_ADDR_LOW] | (cga->crtc[CGA_CRTC_START_ADDR_HIGH] << 8)) & 0x3fff; + cga->scanline = 0; } - } else if (cga->sc == cga->crtc[9]) { - cga->maback = cga->ma; - cga->sc = 0; + } else if (cga->scanline == cga->crtc[CGA_CRTC_MAX_SCANLINE_ADDR]) { + cga->memaddr_backup = cga->memaddr; + cga->scanline = 0; oldvc = cga->vc; cga->vc++; cga->vc &= 127; - if (cga->vc == cga->crtc[6]) + if (cga->vc == cga->crtc[CGA_CRTC_VDISP]) cga->cgadispon = 0; - if (oldvc == cga->crtc[4]) { + if (oldvc == cga->crtc[CGA_CRTC_VTOTAL]) { cga->vc = 0; - cga->vadj = cga->crtc[5]; + cga->vadj = cga->crtc[CGA_CRTC_VTOTAL_ADJUST]; if (!cga->vadj) { cga->cgadispon = 1; - cga->ma = cga->maback = (cga->crtc[13] | (cga->crtc[12] << 8)) & 0x3fff; + cga->memaddr = cga->memaddr_backup = (cga->crtc[CGA_CRTC_START_ADDR_LOW] | (cga->crtc[CGA_CRTC_START_ADDR_HIGH] << 8)) & 0x3fff; } - switch (cga->crtc[10] & 0x60) { + + switch (cga->crtc[CGA_CRTC_CURSOR_START] & 0x60) { case 0x20: cga->cursoron = 0; break; @@ -633,15 +639,15 @@ cga_poll(void *priv) } } - if (cga->vc == cga->crtc[7]) { + if (cga->vc == cga->crtc[CGA_CRTC_VSYNC]) { cga->cgadispon = 0; cga->displine = 0; cga->vsynctime = 16; - if (cga->crtc[7]) { - if (cga->cgamode & 1) - x = (cga->crtc[1] << 3) + 16; + if (cga->crtc[CGA_CRTC_VSYNC]) { + if (cga->cgamode & CGA_MODE_FLAG_HIGHRES) + x = (cga->crtc[CGA_CRTC_HDISP] << 3) + 16; else - x = (cga->crtc[1] << 4) + 16; + x = (cga->crtc[CGA_CRTC_HDISP] << 4) + 16; cga->lastline++; xs_temp = x; @@ -657,7 +663,7 @@ cga_poll(void *priv) if (!enable_overscan) xs_temp -= 16; - if ((cga->cgamode & 8) && ((xs_temp != xsize) || + if ((cga->cgamode & CGA_MODE_FLAG_VIDEO_ENABLE) && ((xs_temp != xsize) || (ys_temp != ysize) || video_force_resize_get())) { xsize = xs_temp; ysize = ys_temp; @@ -691,15 +697,15 @@ cga_poll(void *priv) video_res_x = xsize; video_res_y = ysize; - if (cga->cgamode & 1) { + if (cga->cgamode & CGA_MODE_FLAG_HIGHRES) { video_res_x /= 8; - video_res_y /= cga->crtc[9] + 1; + video_res_y /= cga->crtc[CGA_CRTC_MAX_SCANLINE_ADDR] + 1; video_bpp = 0; - } else if (!(cga->cgamode & 2)) { + } else if (!(cga->cgamode & CGA_MODE_FLAG_GRAPHICS)) { video_res_x /= 16; - video_res_y /= cga->crtc[9] + 1; + video_res_y /= cga->crtc[CGA_CRTC_MAX_SCANLINE_ADDR] + 1; video_bpp = 0; - } else if (!(cga->cgamode & 16)) { + } else if (!(cga->cgamode & CGA_MODE_FLAG_HIGHRES_GRAPHICS)) { video_res_x /= 2; video_bpp = 2; } else @@ -711,18 +717,18 @@ cga_poll(void *priv) cga->oddeven ^= 1; } } else { - cga->sc++; - cga->sc &= 31; - cga->ma = cga->maback; + cga->scanline++; + cga->scanline &= 31; + cga->memaddr = cga->memaddr_backup; } 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))) - 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]; + if (cga->scanline == (cga->crtc[CGA_CRTC_CURSOR_START] & 31) || ((cga->crtc[CGA_CRTC_INTERLACE] & 3) == 3 && + cga->scanline == ((cga->crtc[CGA_CRTC_CURSOR_START] & 31) >> 1))) + cga->cursorvisible = 1; + if (cga->cgadispon && (cga->cgamode & CGA_MODE_FLAG_HIGHRES)) { + for (x = 0; x < (cga->crtc[CGA_CRTC_HDISP] << 1); x++) + cga->charbuffer[x] = cga->vram[((cga->memaddr << 1) + x) & 0x3fff]; } } } @@ -771,6 +777,18 @@ cga_standalone_init(UNUSED(const device_t *info)) } } + switch(device_get_config_int("font")) { + case 0: + loadfont(FONT_IBM_MDA_437_PATH, 0); + break; + case 1: + loadfont(FONT_IBM_MDA_437_NORDIC_PATH, 0); + break; + case 4: + loadfont(FONT_TULIP_DGA_PATH, 0); + break; + } + return cga; } @@ -809,114 +827,99 @@ cga_speed_changed(void *priv) // clang-format off const device_config_t cga_config[] = { { - .name = "display_type", - .description = "Display type", - .type = CONFIG_SELECTION, - .default_int = CGA_RGB, - .selection = { - { - .description = "RGB", - .value = CGA_RGB - }, - { - .description = "Composite", - .value = CGA_COMPOSITE - }, - { - .description = "" - } - } + .name = "display_type", + .description = "Display type", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = CGA_RGB, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "RGB", .value = CGA_RGB }, + { .description = "Composite", .value = CGA_COMPOSITE }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "composite_type", - .description = "Composite type", - .type = CONFIG_SELECTION, - .default_int = COMPOSITE_OLD, - .selection = { - { - .description = "Old", - .value = COMPOSITE_OLD - }, - { - .description = "New", - .value = COMPOSITE_NEW - }, - { - .description = "" - } - } + .name = "composite_type", + .description = "Composite type", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = COMPOSITE_OLD, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Old", .value = COMPOSITE_OLD }, + { .description = "New", .value = COMPOSITE_NEW }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "rgb_type", - .description = "RGB type", - .type = CONFIG_SELECTION, - .default_int = 5, - .selection = { - { - .description = "Color (generic)", - .value = 0 - }, - { - .description = "Green Monochrome", - .value = 1 - }, - { - .description = "Amber Monochrome", - .value = 2 - }, - { - .description = "Gray Monochrome", - .value = 3 - }, - { - .description = "Color (no brown)", - .value = 4 - }, - { - .description = "Color (IBM 5153)", - .value = 5 - }, - { - .description = "" - } - } + .name = "rgb_type", + .description = "RGB type", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 5, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Color (generic)", .value = 0 }, + { .description = "Green Monochrome", .value = 1 }, + { .description = "Amber Monochrome", .value = 2 }, + { .description = "Gray Monochrome", .value = 3 }, + { .description = "Color (no brown)", .value = 4 }, + { .description = "Color (IBM 5153)", .value = 5 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "double_type", - .description = "Line doubling type", - .type = CONFIG_SELECTION, - .default_int = DOUBLE_NONE, - .selection = { - { - .description = "None", - .value = DOUBLE_NONE - }, - { - .description = "Simple doubling", - .value = DOUBLE_SIMPLE - }, - { - .description = "sRGB interpolation", - .value = DOUBLE_INTERPOLATE_SRGB - }, - { - .description = "Linear interpolation", - .value = DOUBLE_INTERPOLATE_LINEAR - }, - { - .description = "" - } - } + .name = "double_type", + .description = "Line doubling type", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = DOUBLE_NONE, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "None", .value = DOUBLE_NONE }, + { .description = "Simple doubling", .value = DOUBLE_SIMPLE }, + { .description = "sRGB interpolation", .value = DOUBLE_INTERPOLATE_SRGB }, + { .description = "Linear interpolation", .value = DOUBLE_INTERPOLATE_LINEAR }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "snow_enabled", - .description = "Snow emulation", - .type = CONFIG_BINARY, - .default_int = 1 + .name = "font", + .description = "Font", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "US (CP 437)", .value = 0 }, + { .description = "IBM Nordic (CP 437-Nordic)", .value = 1 }, + { .description = "Tulip DGA", .value = 4 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .type = CONFIG_END - } + .name = "snow_enabled", + .description = "Snow emulation", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } }; // clang-format on @@ -928,7 +931,7 @@ const device_t cga_device = { .init = cga_standalone_init, .close = cga_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = cga_speed_changed, .force_redraw = NULL, .config = cga_config @@ -942,7 +945,7 @@ const device_t cga_pravetz_device = { .init = cga_pravetz_init, .close = cga_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = cga_speed_changed, .force_redraw = NULL, .config = cga_config diff --git a/src/video/vid_colorplus.c b/src/video/vid_cga_colorplus.c similarity index 61% rename from src/video/vid_colorplus.c rename to src/video/vid_cga_colorplus.c index dcc72a76b..af8fd6d99 100644 --- a/src/video/vid_colorplus.c +++ b/src/video/vid_cga_colorplus.c @@ -14,7 +14,7 @@ * Miran Grca, * * Copyright 2008-2018 Sarah Walker. - * Copyright 2016-2018 Miran Grca. + * Copyright 2016-2025 Miran Grca. */ #include #include @@ -37,19 +37,19 @@ #include <86box/plat_unused.h> /* Bits in the colorplus control register: */ -#define COLORPLUS_PLANE_SWAP 0x40 /* Swap planes at 0000h and 4000h */ -#define COLORPLUS_640x200_MODE 0x20 /* 640x200x4 mode active */ -#define COLORPLUS_320x200_MODE 0x10 /* 320x200x16 mode active */ -#define COLORPLUS_EITHER_MODE 0x30 /* Either mode active */ +#define COLORPLUS_PLANE_SWAP 0x40 /* Swap planes at 0000h and 4000h */ +#define COLORPLUS_640x200_MODE 0x20 /* 640x200x4 mode active */ +#define COLORPLUS_320x200_MODE 0x10 /* 320x200x16 mode active */ +#define COLORPLUS_EITHER_MODE 0x30 /* Either mode active */ -/* Bits in the CGA graphics mode register */ -#define CGA_GRAPHICS_MODE 0x02 /* CGA graphics mode selected? */ +#define CGA_RGB 0 +#define CGA_COMPOSITE 1 -#define CGA_RGB 0 -#define CGA_COMPOSITE 1 +#define COMPOSITE_OLD 0 +#define COMPOSITE_NEW 1 -#define COMPOSITE_OLD 0 -#define COMPOSITE_NEW 1 +// Plantronics specific registers +#define COLORPLUS_CONTROL 0x3DD video_timings_t timing_colorplus = { .type = VIDEO_ISA, .write_b = 8, .write_w = 16, .write_l = 32, .read_b = 8, .read_w = 16, .read_l = 32 }; @@ -60,7 +60,7 @@ colorplus_out(uint16_t addr, uint8_t val, void *priv) { colorplus_t *colorplus = (colorplus_t *) priv; - if (addr == 0x3DD) { + if (addr == COLORPLUS_CONTROL) { colorplus->control = val & 0x70; } else { cga_out(addr, val, &colorplus->cga); @@ -80,7 +80,7 @@ colorplus_write(uint32_t addr, uint8_t val, void *priv) { colorplus_t *colorplus = (colorplus_t *) priv; - if ((colorplus->control & COLORPLUS_PLANE_SWAP) && (colorplus->control & COLORPLUS_EITHER_MODE) && (colorplus->cga.cgamode & CGA_GRAPHICS_MODE)) { + if ((colorplus->control & COLORPLUS_PLANE_SWAP) && (colorplus->control & COLORPLUS_EITHER_MODE) && (colorplus->cga.cgamode & CGA_MODE_FLAG_GRAPHICS)) { addr ^= 0x4000; } else if (!(colorplus->control & COLORPLUS_EITHER_MODE)) { addr &= 0x3FFF; @@ -99,7 +99,7 @@ colorplus_read(uint32_t addr, void *priv) { colorplus_t *colorplus = (colorplus_t *) priv; - if ((colorplus->control & COLORPLUS_PLANE_SWAP) && (colorplus->control & COLORPLUS_EITHER_MODE) && (colorplus->cga.cgamode & CGA_GRAPHICS_MODE)) { + if ((colorplus->control & COLORPLUS_PLANE_SWAP) && (colorplus->control & COLORPLUS_EITHER_MODE) && (colorplus->cga.cgamode & CGA_MODE_FLAG_GRAPHICS)) { addr ^= 0x4000; } else if (!(colorplus->control & COLORPLUS_EITHER_MODE)) { addr &= 0x3FFF; @@ -130,7 +130,7 @@ colorplus_poll(void *priv) uint16_t dat1; int cols[4]; int col; - int oldsc; + int scanline_old; static const int cols16[16] = { 0x10, 0x12, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x1E, 0x11, 0x13, 0x15, 0x17, @@ -140,7 +140,7 @@ colorplus_poll(void *priv) /* If one of the extra modes is not selected, drop down to the CGA * drawing code. */ - if (!((colorplus->control & COLORPLUS_EITHER_MODE) && (colorplus->cga.cgamode & CGA_GRAPHICS_MODE))) { + if (!((colorplus->control & COLORPLUS_EITHER_MODE) && (colorplus->cga.cgamode & CGA_MODE_FLAG_GRAPHICS))) { cga_poll(&colorplus->cga); return; } @@ -149,9 +149,9 @@ colorplus_poll(void *priv) timer_advance_u64(&colorplus->cga.timer, colorplus->cga.dispofftime); colorplus->cga.cgastat |= 1; colorplus->cga.linepos = 1; - oldsc = colorplus->cga.sc; - if ((colorplus->cga.crtc[8] & 3) == 3) - colorplus->cga.sc = ((colorplus->cga.sc << 1) + colorplus->cga.oddeven) & 7; + scanline_old = colorplus->cga.scanline; + if ((colorplus->cga.crtc[CGA_CRTC_INTERLACE] & 3) == 3) + colorplus->cga.scanline = ((colorplus->cga.scanline << 1) + colorplus->cga.oddeven) & 7; if (colorplus->cga.cgadispon) { if (colorplus->cga.displine < colorplus->cga.firstline) { colorplus->cga.firstline = colorplus->cga.displine; @@ -160,13 +160,13 @@ colorplus_poll(void *priv) colorplus->cga.lastline = colorplus->cga.displine; /* Left / right border */ for (c = 0; c < 8; c++) { - buffer32->line[colorplus->cga.displine][c] = buffer32->line[colorplus->cga.displine][c + (colorplus->cga.crtc[1] << 4) + 8] = (colorplus->cga.cgacol & 15) + 16; + buffer32->line[colorplus->cga.displine][c] = buffer32->line[colorplus->cga.displine][c + (colorplus->cga.crtc[CGA_CRTC_HDISP] << 4) + 8] = (colorplus->cga.cgacol & 15) + 16; } if (colorplus->control & COLORPLUS_320x200_MODE) { - for (x = 0; x < colorplus->cga.crtc[1]; x++) { - dat0 = (plane0[((colorplus->cga.ma << 1) & 0x1fff) + ((colorplus->cga.sc & 1) * 0x2000)] << 8) | plane0[((colorplus->cga.ma << 1) & 0x1fff) + ((colorplus->cga.sc & 1) * 0x2000) + 1]; - dat1 = (plane1[((colorplus->cga.ma << 1) & 0x1fff) + ((colorplus->cga.sc & 1) * 0x2000)] << 8) | plane1[((colorplus->cga.ma << 1) & 0x1fff) + ((colorplus->cga.sc & 1) * 0x2000) + 1]; - colorplus->cga.ma++; + for (x = 0; x < colorplus->cga.crtc[CGA_CRTC_HDISP]; x++) { + dat0 = (plane0[((colorplus->cga.memaddr << 1) & 0x1fff) + ((colorplus->cga.scanline & 1) * 0x2000)] << 8) | plane0[((colorplus->cga.memaddr << 1) & 0x1fff) + ((colorplus->cga.scanline & 1) * 0x2000) + 1]; + dat1 = (plane1[((colorplus->cga.memaddr << 1) & 0x1fff) + ((colorplus->cga.scanline & 1) * 0x2000)] << 8) | plane1[((colorplus->cga.memaddr << 1) & 0x1fff) + ((colorplus->cga.scanline & 1) * 0x2000) + 1]; + colorplus->cga.memaddr++; for (c = 0; c < 8; c++) { buffer32->line[colorplus->cga.displine][(x << 4) + (c << 1) + 8] = buffer32->line[colorplus->cga.displine][(x << 4) + (c << 1) + 1 + 8] = cols16[(dat0 >> 14) | ((dat1 >> 14) << 2)]; dat0 <<= 2; @@ -176,7 +176,7 @@ colorplus_poll(void *priv) } else if (colorplus->control & COLORPLUS_640x200_MODE) { cols[0] = (colorplus->cga.cgacol & 15) | 16; col = (colorplus->cga.cgacol & 16) ? 24 : 16; - if (colorplus->cga.cgamode & 4) { + if (colorplus->cga.cgamode & CGA_MODE_FLAG_BW) { cols[1] = col | 3; cols[2] = col | 4; cols[3] = col | 7; @@ -189,10 +189,10 @@ colorplus_poll(void *priv) cols[2] = col | 4; cols[3] = col | 6; } - for (x = 0; x < colorplus->cga.crtc[1]; x++) { - dat0 = (plane0[((colorplus->cga.ma << 1) & 0x1fff) + ((colorplus->cga.sc & 1) * 0x2000)] << 8) | plane0[((colorplus->cga.ma << 1) & 0x1fff) + ((colorplus->cga.sc & 1) * 0x2000) + 1]; - dat1 = (plane1[((colorplus->cga.ma << 1) & 0x1fff) + ((colorplus->cga.sc & 1) * 0x2000)] << 8) | plane1[((colorplus->cga.ma << 1) & 0x1fff) + ((colorplus->cga.sc & 1) * 0x2000) + 1]; - colorplus->cga.ma++; + for (x = 0; x < colorplus->cga.crtc[CGA_CRTC_HDISP]; x++) { + dat0 = (plane0[((colorplus->cga.memaddr << 1) & 0x1fff) + ((colorplus->cga.scanline & 1) * 0x2000)] << 8) | plane0[((colorplus->cga.memaddr << 1) & 0x1fff) + ((colorplus->cga.scanline & 1) * 0x2000) + 1]; + dat1 = (plane1[((colorplus->cga.memaddr << 1) & 0x1fff) + ((colorplus->cga.scanline & 1) * 0x2000)] << 8) | plane1[((colorplus->cga.memaddr << 1) & 0x1fff) + ((colorplus->cga.scanline & 1) * 0x2000) + 1]; + colorplus->cga.memaddr++; for (c = 0; c < 16; c++) { buffer32->line[colorplus->cga.displine][(x << 4) + c + 8] = cols[(dat0 >> 15) | ((dat1 >> 15) << 1)]; dat0 <<= 1; @@ -203,18 +203,18 @@ colorplus_poll(void *priv) } else /* Top / bottom border */ { cols[0] = (colorplus->cga.cgacol & 15) + 16; - hline(buffer32, 0, colorplus->cga.displine, (colorplus->cga.crtc[1] << 4) + 16, cols[0]); + hline(buffer32, 0, colorplus->cga.displine, (colorplus->cga.crtc[CGA_CRTC_HDISP] << 4) + 16, cols[0]); } - x = (colorplus->cga.crtc[1] << 4) + 16; + x = (colorplus->cga.crtc[CGA_CRTC_HDISP] << 4) + 16; if (colorplus->cga.composite) Composite_Process(colorplus->cga.cgamode, 0, x >> 2, buffer32->line[colorplus->cga.displine]); else video_process_8(x, colorplus->cga.displine); - colorplus->cga.sc = oldsc; - if (colorplus->cga.vc == colorplus->cga.crtc[7] && !colorplus->cga.sc) + colorplus->cga.scanline = scanline_old; + if (colorplus->cga.vc == colorplus->cga.crtc[CGA_CRTC_VSYNC] && !colorplus->cga.scanline) colorplus->cga.cgastat |= 8; colorplus->cga.displine++; if (colorplus->cga.displine >= 360) @@ -227,54 +227,54 @@ colorplus_poll(void *priv) if (!colorplus->cga.vsynctime) colorplus->cga.cgastat &= ~8; } - if (colorplus->cga.sc == (colorplus->cga.crtc[11] & 31) || ((colorplus->cga.crtc[8] & 3) == 3 && colorplus->cga.sc == ((colorplus->cga.crtc[11] & 31) >> 1))) { - colorplus->cga.con = 0; - colorplus->cga.coff = 1; + if (colorplus->cga.scanline == (colorplus->cga.crtc[CGA_CRTC_CURSOR_END] & 31) + || ((colorplus->cga.crtc[CGA_CRTC_INTERLACE] & 3) == 3 && colorplus->cga.scanline == ((colorplus->cga.crtc[CGA_CRTC_CURSOR_END] & 31) >> 1))) { + colorplus->cga.cursorvisible = 0; } - if ((colorplus->cga.crtc[8] & 3) == 3 && colorplus->cga.sc == (colorplus->cga.crtc[9] >> 1)) - colorplus->cga.maback = colorplus->cga.ma; + if ((colorplus->cga.crtc[CGA_CRTC_INTERLACE] & 3) == 3 && colorplus->cga.scanline == (colorplus->cga.crtc[CGA_CRTC_MAX_SCANLINE_ADDR] >> 1)) + colorplus->cga.memaddr_backup = colorplus->cga.memaddr; if (colorplus->cga.vadj) { - colorplus->cga.sc++; - colorplus->cga.sc &= 31; - colorplus->cga.ma = colorplus->cga.maback; + colorplus->cga.scanline++; + colorplus->cga.scanline &= 31; + colorplus->cga.memaddr = colorplus->cga.memaddr_backup; colorplus->cga.vadj--; if (!colorplus->cga.vadj) { colorplus->cga.cgadispon = 1; - colorplus->cga.ma = colorplus->cga.maback = (colorplus->cga.crtc[13] | (colorplus->cga.crtc[12] << 8)) & 0x3fff; - colorplus->cga.sc = 0; + colorplus->cga.memaddr = colorplus->cga.memaddr_backup = (colorplus->cga.crtc[CGA_CRTC_START_ADDR_LOW] | (colorplus->cga.crtc[CGA_CRTC_START_ADDR_HIGH] << 8)) & 0x3fff; + colorplus->cga.scanline = 0; } - } else if (colorplus->cga.sc == colorplus->cga.crtc[9]) { - colorplus->cga.maback = colorplus->cga.ma; - colorplus->cga.sc = 0; + } else if (colorplus->cga.scanline == colorplus->cga.crtc[CGA_CRTC_MAX_SCANLINE_ADDR]) { + colorplus->cga.memaddr_backup = colorplus->cga.memaddr; + colorplus->cga.scanline = 0; oldvc = colorplus->cga.vc; colorplus->cga.vc++; colorplus->cga.vc &= 127; - if (colorplus->cga.vc == colorplus->cga.crtc[6]) + if (colorplus->cga.vc == colorplus->cga.crtc[CGA_CRTC_VDISP]) colorplus->cga.cgadispon = 0; - if (oldvc == colorplus->cga.crtc[4]) { + if (oldvc == colorplus->cga.crtc[CGA_CRTC_VTOTAL]) { colorplus->cga.vc = 0; - colorplus->cga.vadj = colorplus->cga.crtc[5]; + colorplus->cga.vadj = colorplus->cga.crtc[CGA_CRTC_VTOTAL_ADJUST]; if (!colorplus->cga.vadj) colorplus->cga.cgadispon = 1; if (!colorplus->cga.vadj) - colorplus->cga.ma = colorplus->cga.maback = (colorplus->cga.crtc[13] | (colorplus->cga.crtc[12] << 8)) & 0x3fff; - if ((colorplus->cga.crtc[10] & 0x60) == 0x20) + colorplus->cga.memaddr = colorplus->cga.memaddr_backup = (colorplus->cga.crtc[CGA_CRTC_START_ADDR_LOW] | (colorplus->cga.crtc[CGA_CRTC_START_ADDR_HIGH] << 8)) & 0x3fff; + if ((colorplus->cga.crtc[CGA_CRTC_CURSOR_START] & 0x60) == 0x20) colorplus->cga.cursoron = 0; else colorplus->cga.cursoron = colorplus->cga.cgablink & 8; } - if (colorplus->cga.vc == colorplus->cga.crtc[7]) { + if (colorplus->cga.vc == colorplus->cga.crtc[CGA_CRTC_VSYNC]) { colorplus->cga.cgadispon = 0; colorplus->cga.displine = 0; colorplus->cga.vsynctime = 16; - if (colorplus->cga.crtc[7]) { - if (colorplus->cga.cgamode & 1) - x = (colorplus->cga.crtc[1] << 3) + 16; + if (colorplus->cga.crtc[CGA_CRTC_VSYNC]) { + if (colorplus->cga.cgamode & CGA_MODE_FLAG_HIGHRES) + x = (colorplus->cga.crtc[CGA_CRTC_HDISP] << 3) + 16; else - x = (colorplus->cga.crtc[1] << 4) + 16; + x = (colorplus->cga.crtc[CGA_CRTC_HDISP] << 4) + 16; colorplus->cga.lastline++; if (x != xsize || (colorplus->cga.lastline - colorplus->cga.firstline) != ysize) { xsize = x; @@ -291,15 +291,15 @@ colorplus_poll(void *priv) video_res_x = xsize - 16; video_res_y = ysize; - if (colorplus->cga.cgamode & 1) { + if (colorplus->cga.cgamode & CGA_MODE_FLAG_HIGHRES) { video_res_x /= 8; - video_res_y /= colorplus->cga.crtc[9] + 1; + video_res_y /= colorplus->cga.crtc[CGA_CRTC_MAX_SCANLINE_ADDR] + 1; video_bpp = 0; - } else if (!(colorplus->cga.cgamode & 2)) { + } else if (!(colorplus->cga.cgamode & CGA_MODE_FLAG_GRAPHICS)) { video_res_x /= 16; - video_res_y /= colorplus->cga.crtc[9] + 1; + video_res_y /= colorplus->cga.crtc[CGA_CRTC_MAX_SCANLINE_ADDR] + 1; video_bpp = 0; - } else if (!(colorplus->cga.cgamode & 16)) { + } else if (!(colorplus->cga.cgamode & CGA_MODE_FLAG_HIGHRES_GRAPHICS)) { video_res_x /= 2; video_bpp = 2; } else { @@ -312,17 +312,17 @@ colorplus_poll(void *priv) colorplus->cga.oddeven ^= 1; } } else { - colorplus->cga.sc++; - colorplus->cga.sc &= 31; - colorplus->cga.ma = colorplus->cga.maback; + colorplus->cga.scanline++; + colorplus->cga.scanline &= 31; + colorplus->cga.memaddr = colorplus->cga.memaddr_backup; } 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))) - 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]; + if (colorplus->cga.scanline == (colorplus->cga.crtc[CGA_CRTC_CURSOR_START] & 31) || ((colorplus->cga.crtc[CGA_CRTC_INTERLACE] & 3) == 3 && colorplus->cga.scanline == ((colorplus->cga.crtc[CGA_CRTC_CURSOR_START] & 31) >> 1))) + colorplus->cga.cursorvisible = 1; + if (colorplus->cga.cgadispon && (colorplus->cga.cgamode & CGA_MODE_FLAG_HIGHRES)) { + for (x = 0; x < (colorplus->cga.crtc[CGA_CRTC_HDISP] << 1); x++) + colorplus->cga.charbuffer[x] = colorplus->cga.vram[((colorplus->cga.memaddr << 1) + x) & 0x3fff]; } } } @@ -357,7 +357,7 @@ colorplus_standalone_init(UNUSED(const device_t *info)) mem_mapping_add(&colorplus->cga.mapping, 0xb8000, 0x08000, colorplus_read, NULL, NULL, colorplus_write, NULL, NULL, NULL, MEM_MAPPING_EXTERNAL, colorplus); io_sethandler(0x03d0, 0x0010, colorplus_in, NULL, NULL, colorplus_out, NULL, NULL, colorplus); - lpt3_init(0x3BC); + lpt3_setup(LPT_MDA_ADDR); return colorplus; } @@ -382,52 +382,47 @@ colorplus_speed_changed(void *priv) static const device_config_t colorplus_config[] = { // clang-format off { - .name = "display_type", - .description = "Display type", - .type = CONFIG_SELECTION, - .default_int = CGA_RGB, - .selection = { - { - .description = "RGB", - .value = CGA_RGB - }, - { - .description = "Composite", - .value = CGA_COMPOSITE - }, - { - .description = "" - } - } + .name = "display_type", + .description = "Display type", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = CGA_RGB, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "RGB", .value = CGA_RGB }, + { .description = "Composite", .value = CGA_COMPOSITE }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "composite_type", - .description = "Composite type", - .type = CONFIG_SELECTION, - .default_int = COMPOSITE_OLD, - .selection = { - { - .description = "Old", - .value = COMPOSITE_OLD - }, - { - .description = "New", - .value = COMPOSITE_NEW - }, - { - .description = "" - } - } + .name = "composite_type", + .description = "Composite type", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = COMPOSITE_OLD, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Old", .value = COMPOSITE_OLD }, + { .description = "New", .value = COMPOSITE_NEW }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "snow_enabled", - .description = "Snow emulation", - .type = CONFIG_BINARY, - .default_int = 1 + .name = "snow_enabled", + .description = "Snow emulation", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -439,7 +434,7 @@ const device_t colorplus_device = { .init = colorplus_standalone_init, .close = colorplus_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = colorplus_speed_changed, .force_redraw = NULL, .config = colorplus_config diff --git a/src/video/vid_cga_comp.c b/src/video/vid_cga_comp.c index d580f0c06..ca9c2c9df 100644 --- a/src/video/vid_cga_comp.c +++ b/src/video/vid_cga_comp.c @@ -44,22 +44,22 @@ static const double tau = 6.28318531; /* == 2*pi */ static unsigned char chroma_multiplexer[256] = { // clang-format off - 2, 2, 2, 2, 114,174, 4, 3, 2, 1,133,135, 2,113,150, 4, - 133, 2, 1, 99, 151,152, 2, 1, 3, 2, 96,136, 151,152,151,152, - 2, 56, 62, 4, 111,250,118, 4, 0, 51,207,137, 1,171,209, 5, - 140, 50, 54,100, 133,202, 57, 4, 2, 50,153,149, 128,198,198,135, - 32, 1, 36, 81, 147,158, 1, 42, 33, 1,210,254, 34,109,169, 77, - 177, 2, 0,165, 189,154, 3, 44, 33, 0, 91,197, 178,142,144,192, - 4, 2, 61, 67, 117,151,112, 83, 4, 0,249,255, 3,107,249,117, - 147, 1, 50,162, 143,141, 52, 54, 3, 0,145,206, 124,123,192,193, - 72, 78, 2, 0, 159,208, 4, 0, 53, 58,164,159, 37,159,171, 1, - 248,117, 4, 98, 212,218, 5, 2, 54, 59, 93,121, 176,181,134,130, - 1, 61, 31, 0, 160,255, 34, 1, 1, 58,197,166, 0,177,194, 2, - 162,111, 34, 96, 205,253, 32, 1, 1, 57,123,125, 119,188,150,112, - 78, 4, 0, 75, 166,180, 20, 38, 78, 1,143,246, 42,113,156, 37, - 252, 4, 1,188, 175,129, 1, 37, 118, 4, 88,249, 202,150,145,200, - 61, 59, 60, 60, 228,252,117, 77, 60, 58,248,251, 81,212,254,107, - 198, 59, 58,169, 250,251, 81, 80, 100, 58,154,250, 251,252,252,252 + 2, 2, 2, 2, 114, 174, 4, 3, 2, 1, 133, 135, 2, 113, 150, 4, + 133, 2, 1, 99, 151, 152, 2, 1, 3, 2, 96, 136, 151, 152, 151, 152, + 2, 56, 62, 4, 111, 250, 118, 4, 0, 51, 207, 137, 1, 171, 209, 5, + 140, 50, 54, 100, 133, 202, 57, 4, 2, 50, 153, 149, 128, 198, 198, 135, + 32, 1, 36, 81, 147, 158, 1, 42, 33, 1, 210, 254, 34, 109, 169, 77, + 177, 2, 0, 165, 189, 154, 3, 44, 33, 0, 91, 197, 178, 142, 144, 192, + 4, 2, 61, 67, 117, 151, 112, 83, 4, 0, 249, 255, 3, 107, 249, 117, + 147, 1, 50, 162, 143, 141, 52, 54, 3, 0, 145, 206, 124, 123, 192, 193, + 72, 78, 2, 0, 159, 208, 4, 0, 53, 58, 164, 159, 37, 159, 171, 1, + 248, 117, 4, 98, 212, 218, 5, 2, 54, 59, 93, 121, 176, 181, 134, 130, + 1, 61, 31, 0, 160, 255, 34, 1, 1, 58, 197, 166, 0, 177, 194, 2, + 162, 111, 34, 96, 205, 253, 32, 1, 1, 57, 123, 125, 119, 188, 150, 112, + 78, 4, 0, 75, 166, 180, 20, 38, 78, 1, 143, 246, 42, 113, 156, 37, + 252, 4, 1, 188, 175, 129, 1, 37, 118, 4, 88, 249, 202, 150, 145, 200, + 61, 59, 60, 60, 228, 252, 117, 77, 60, 58, 248, 251, 81, 212, 254, 107, + 198, 59, 58, 169, 250, 251, 81, 80, 100, 58, 154, 250, 251, 252, 252, 252 // clang-format on }; @@ -135,7 +135,7 @@ update_cga16_color(uint8_t cgamode) int left = (x >> 6) & 15; int rc = right; int lc = left; - if ((cgamode & 4) != 0) { + if ((cgamode & CGA_MODE_FLAG_BW) != 0) { rc = (right & 8) | ((right & 7) != 0 ? 7 : 0); lc = (left & 8) | ((left & 7) != 0 ? 7 : 0); } @@ -240,7 +240,7 @@ Composite_Process(uint8_t cgamode, uint8_t border, uint32_t blocks /*, bool doub for (uint8_t x = 0; x < 5; ++x) OUT(b[x & 3]); - if ((cgamode & 4) != 0) { + if ((cgamode & CGA_MODE_FLAG_BW) != 0) { /* Decode */ i = temp + 5; srgb = TempLine; diff --git a/src/video/vid_cga_compaq.c b/src/video/vid_cga_compaq.c new file mode 100644 index 000000000..1e21d63c1 --- /dev/null +++ b/src/video/vid_cga_compaq.c @@ -0,0 +1,511 @@ +/* + * 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 Compaq CGA graphics cards. + * + * + * + * Authors: John Elliott, + * Sarah Walker, + * Miran Grca, + * + * Copyright 2016-2019 John Elliott. + * Copyright 2008-2019 Sarah Walker. + * Copyright 2016-2019 Miran Grca. + */ +#include +#include +#include +#include +#include +#include +#include +#define HAVE_STDARG_H +#include <86box/86box.h> +#include "cpu.h" +#include <86box/io.h> +#include <86box/timer.h> +#include <86box/pit.h> +#include <86box/mem.h> +#include <86box/rom.h> +#include <86box/device.h> +#include <86box/video.h> +#include <86box/vid_cga.h> +#include <86box/vid_cga_comp.h> + +#define CGA_RGB 0 +#define CGA_COMPOSITE 1 + +static uint32_t vflags; +static uint8_t mdaattr[256][2][2]; + +#ifdef ENABLE_COMPAQ_CGA_LOG +int compaq_cga_do_log = ENABLE_COMPAQ_CGA_LOG; + +static void +compaq_cga_log(const char *fmt, ...) +{ + va_list ap; + + if (compaq_cga_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define compaq_cga_log(fmt, ...) +#endif + +static void +compaq_cga_recalctimings(cga_t *dev) +{ + double _dispontime; + double _dispofftime; + double disptime; + disptime = dev->crtc[CGA_CRTC_HTOTAL] + 1; + + _dispontime = dev->crtc[CGA_CRTC_HDISP]; + _dispofftime = disptime - _dispontime; + _dispontime *= MDACONST; + _dispofftime *= MDACONST; + dev->dispontime = (uint64_t) (_dispontime); + dev->dispofftime = (uint64_t) (_dispofftime); +} + +static void +compaq_cga_poll(void *priv) +{ + cga_t *dev = (cga_t *) priv; + uint16_t cursoraddr = (dev->crtc[CGA_CRTC_CURSOR_ADDR_LOW] | (dev->crtc[CGA_CRTC_CURSOR_ADDR_HIGH] << 8)) & 0x3fff; + int drawcursor; + int x; + int c; + int xs_temp; + int ys_temp; + int oldvc; + uint8_t chr; + uint8_t attr; + uint8_t border; + uint8_t cols[4]; + int scanline_old; + int underline = 0; + int blink = 0; + + int32_t highres_graphics_flag = (CGA_MODE_FLAG_HIGHRES_GRAPHICS | CGA_MODE_FLAG_GRAPHICS); + + /* If in graphics mode or character height is not 13, behave as CGA */ + if ((dev->cgamode & highres_graphics_flag) || (dev->crtc[CGA_CRTC_MAX_SCANLINE_ADDR] != 13)) { + overscan_x = overscan_y = 16; + cga_poll(dev); + return; + } else + overscan_x = overscan_y = 0; + + /* We are in Compaq 350-line CGA territory */ + if (!dev->linepos) { + timer_advance_u64(&dev->timer, dev->dispofftime); + dev->cgastat |= 1; + dev->linepos = 1; + scanline_old = dev->scanline; + if ((dev->crtc[CGA_CRTC_INTERLACE] & 3) == 3) + dev->scanline = ((dev->scanline << 1) + dev->oddeven) & 7; + if (dev->cgadispon) { + if (dev->displine < dev->firstline) { + dev->firstline = dev->displine; + video_wait_for_buffer(); + compaq_cga_log("Firstline %i\n", dev->firstline); + } + dev->lastline = dev->displine; + + cols[0] = (dev->cgacol & 15) + 16; + + for (c = 0; c < 8; c++) { + buffer32->line[dev->displine][c] = cols[0]; + if (dev->cgamode & CGA_MODE_FLAG_HIGHRES) + buffer32->line[dev->displine][c + (dev->crtc[CGA_CRTC_HDISP] << 3) + 8] = cols[0]; + else + buffer32->line[dev->displine][c + (dev->crtc[CGA_CRTC_HDISP] << 4) + 8] = cols[0]; + } + + if (dev->cgamode & CGA_MODE_FLAG_HIGHRES) { + for (x = 0; x < dev->crtc[CGA_CRTC_HDISP]; x++) { + chr = dev->charbuffer[x << 1]; + attr = dev->charbuffer[(x << 1) + 1]; + drawcursor = ((dev->memaddr == cursoraddr) && dev->cursorvisible && dev->cursoron); + + if (vflags) { + underline = 0; + blink = ((dev->cgablink & 8) && (dev->cgamode & CGA_MODE_FLAG_BLINK) && (attr & 0x80) && !drawcursor); + } + + if (vflags && (dev->cgamode & 0x80)) { + cols[0] = mdaattr[attr][blink][0]; + cols[1] = mdaattr[attr][blink][1]; + + if ((dev->scanline == 12) && ((attr & 7) == 1)) + underline = 1; + } else if (dev->cgamode & CGA_MODE_FLAG_BLINK) { + cols[1] = (attr & 15) + 16; + cols[0] = ((attr >> 4) & 7) + 16; + + if (vflags) { + if (blink) + cols[1] = cols[0]; + } else { + if ((dev->cgablink & 8) && (attr & 0x80) && !dev->drawcursor) + cols[1] = cols[0]; + } + } else { + cols[1] = (attr & 15) + 16; + cols[0] = (attr >> 4) + 16; + } + + if (vflags && underline) { + for (c = 0; c < 8; c++) + buffer32->line[dev->displine][(x << 3) + c + 8] = mdaattr[attr][blink][1]; + } else if (drawcursor) { + for (c = 0; c < 8; c++) + buffer32->line[dev->displine][(x << 3) + c + 8] = + cols[(fontdatm[chr + dev->fontbase][dev->scanline & 15] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; + } else { + for (c = 0; c < 8; c++) + buffer32->line[dev->displine][(x << 3) + c + 8] = + cols[(fontdatm[chr + dev->fontbase][dev->scanline & 15] & (1 << (c ^ 7))) ? 1 : 0]; + } + dev->memaddr++; + } + } else { + for (x = 0; x < dev->crtc[CGA_CRTC_HDISP]; x++) { + chr = dev->vram[(dev->memaddr << 1) & 0x3fff]; + attr = dev->vram[((dev->memaddr << 1) + 1) & 0x3fff]; + drawcursor = ((dev->memaddr == cursoraddr) && dev->cursorvisible && dev->cursoron); + + if (vflags) { + underline = 0; + blink = ((dev->cgablink & 8) && (dev->cgamode & CGA_MODE_FLAG_BLINK) && (attr & 0x80) && !drawcursor); + } + + if (vflags && (dev->cgamode & 0x80)) { + cols[0] = mdaattr[attr][blink][0]; + cols[1] = mdaattr[attr][blink][1]; + if (dev->scanline == 12 && (attr & 7) == 1) + underline = 1; + } else if (dev->cgamode & CGA_MODE_FLAG_BLINK) { + cols[1] = (attr & 15) + 16; + cols[0] = ((attr >> 4) & 7) + 16; + + if (vflags) { + if (blink) + cols[1] = cols[0]; + } else { + if ((dev->cgablink & 8) && (attr & 0x80) && !dev->drawcursor) + cols[1] = cols[0]; + } + } else { + cols[1] = (attr & 15) + 16; + cols[0] = (attr >> 4) + 16; + } + dev->memaddr++; + + if (vflags && underline) { + for (c = 0; c < 8; c++) + buffer32->line[dev->displine][(x << 4) + (c << 1) + 8] = + buffer32->line[dev->displine][(x << 4) + (c << 1) + 9] = mdaattr[attr][blink][1]; + } else if (drawcursor) { + for (c = 0; c < 8; c++) + buffer32->line[dev->displine][(x << 4) + (c << 1) + 8] = + buffer32->line[dev->displine][(x << 4) + (c << 1) + 1 + 8] = + cols[(fontdatm[chr + dev->fontbase][dev->scanline & 15] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; + } else { + for (c = 0; c < 8; c++) + buffer32->line[dev->displine][(x << 4) + (c << 1) + 8] = + buffer32->line[dev->displine][(x << 4) + (c << 1) + 1 + 8] = + cols[(fontdatm[chr + dev->fontbase][dev->scanline & 15] & (1 << (c ^ 7))) ? 1 : 0]; + } + } + } + } else { + cols[0] = (dev->cgacol & 15) + 16; + + if (dev->cgamode & CGA_MODE_FLAG_HIGHRES) + hline(buffer32, 0, dev->displine, (dev->crtc[CGA_CRTC_HDISP] << 3) + 16, cols[0]); + else + hline(buffer32, 0, dev->displine, (dev->crtc[CGA_CRTC_HDISP] << 4) + 16, cols[0]); + } + + if (dev->cgamode & CGA_MODE_FLAG_HIGHRES) + x = (dev->crtc[CGA_CRTC_HDISP] << 3) + 16; + else + x = (dev->crtc[CGA_CRTC_HDISP] << 4) + 16; + + if (dev->composite) { + if (dev->cgamode & CGA_MODE_FLAG_HIGHRES_GRAPHICS) + border = 0x00; + else + border = dev->cgacol & 0x0f; + + if (vflags) + Composite_Process(dev->cgamode & 0x7f, border, x >> 2, buffer32->line[dev->displine]); + else + Composite_Process(dev->cgamode, border, x >> 2, buffer32->line[dev->displine]); + } else + video_process_8(x, dev->displine); + + dev->scanline = scanline_old; + if (dev->vc == dev->crtc[CGA_CRTC_VSYNC] && !dev->scanline) + dev->cgastat |= 8; + dev->displine++; + if (dev->displine >= 500) + dev->displine = 0; + } else { + timer_advance_u64(&dev->timer, dev->dispontime); + dev->linepos = 0; + if (dev->vsynctime) { + dev->vsynctime--; + if (!dev->vsynctime) + dev->cgastat &= ~8; + } + + if (dev->scanline == (dev->crtc[11] & 31) || ((dev->crtc[8] & 3) == 3 && dev->scanline == ((dev->crtc[11] & 31) >> 1))) { + dev->cursorvisible = 0; + } + if ((dev->crtc[8] & 3) == 3 && dev->scanline == (dev->crtc[9] >> 1)) + dev->memaddr_backup = dev->memaddr; + if (dev->vadj) { + dev->scanline++; + dev->scanline &= 31; + dev->memaddr = dev->memaddr_backup; + dev->vadj--; + if (!dev->vadj) { + dev->cgadispon = 1; + dev->memaddr = dev->memaddr_backup = (dev->crtc[13] | (dev->crtc[12] << 8)) & 0x3fff; + dev->scanline = 0; + } + } else if (dev->scanline == dev->crtc[9]) { + dev->memaddr_backup = dev->memaddr; + dev->scanline = 0; + oldvc = dev->vc; + dev->vc++; + dev->vc &= 127; + + if (dev->vc == dev->crtc[6]) + dev->cgadispon = 0; + + if (oldvc == dev->crtc[4]) { + dev->vc = 0; + dev->vadj = dev->crtc[5]; + + if (!dev->vadj) + dev->cgadispon = 1; + + if (!dev->vadj) + dev->memaddr = dev->memaddr_backup = (dev->crtc[13] | (dev->crtc[12] << 8)) & 0x3fff; + + if ((dev->crtc[10] & 0x60) == 0x20) + dev->cursoron = 0; + else + dev->cursoron = dev->cgablink & 8; + } + + if (dev->vc == dev->crtc[7]) { + dev->cgadispon = 0; + dev->displine = 0; + dev->vsynctime = 16; + + if (dev->crtc[7]) { + compaq_cga_log("Lastline %i Firstline %i %i\n", dev->lastline, + dev->firstline, dev->lastline - dev->firstline); + + if (dev->cgamode & CGA_MODE_FLAG_HIGHRES) + x = (dev->crtc[CGA_CRTC_HDISP] << 3) + 16; + else + x = (dev->crtc[CGA_CRTC_HDISP] << 4) + 16; + + dev->lastline++; + + xs_temp = x; + ys_temp = (dev->lastline - dev->firstline); + + if ((xs_temp > 0) && (ys_temp > 0)) { + if (xs_temp < 64) + xs_temp = 656; + if (ys_temp < 32) + ys_temp = 400; + if (!enable_overscan) + xs_temp -= 16; + + if ((dev->cgamode & 8) && ((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)); + + if (video_force_resize_get()) + video_force_resize_set(0); + } + + if (enable_overscan) + video_blit_memtoscreen(0, dev->firstline - 8, xsize, (dev->lastline - dev->firstline) + 16); + else + video_blit_memtoscreen(8, dev->firstline, xsize, dev->lastline - dev->firstline); + } + + frames++; + + video_res_x = xsize; + if (enable_overscan) + xsize -= 16; + video_res_y = ysize; + if (dev->cgamode & CGA_MODE_FLAG_HIGHRES) { + video_res_x /= 8; + video_res_y /= dev->crtc[9] + 1; + video_bpp = 0; + } else if (!(dev->cgamode & 2)) { + video_res_x /= 16; + video_res_y /= dev->crtc[9] + 1; + video_bpp = 0; + } else if (!(dev->cgamode & 16)) { + video_res_x /= 2; + video_bpp = 2; + } else + video_bpp = 1; + } + + dev->firstline = 1000; + dev->lastline = 0; + dev->cgablink++; + dev->oddeven ^= 1; + } + } else { + dev->scanline++; + dev->scanline &= 31; + dev->memaddr = dev->memaddr_backup; + } + + if (dev->cgadispon) + dev->cgastat &= ~1; + + if (dev->scanline == (dev->crtc[10] & 31) || ((dev->crtc[8] & 3) == 3 && dev->scanline == ((dev->crtc[10] & 31) >> 1))) + dev->cursorvisible = 1; + + if (dev->cgadispon && (dev->cgamode & CGA_MODE_FLAG_HIGHRES)) { + for (x = 0; x < (dev->crtc[CGA_CRTC_HDISP] << 1); x++) + dev->charbuffer[x] = dev->vram[((dev->memaddr << 1) + x) & 0x3fff]; + } + } +} + +static void * +compaq_cga_init(const device_t *info) +{ + int display_type; + cga_t *dev = calloc(1, sizeof(cga_t)); + + display_type = device_get_config_int("display_type"); + dev->composite = (display_type != CGA_RGB); + dev->revision = device_get_config_int("composite_type"); + dev->snow_enabled = device_get_config_int("snow_enabled"); + + dev->vram = malloc(0x4000); + + cga_comp_init(dev->revision); + timer_add(&dev->timer, compaq_cga_poll, dev, 1); + mem_mapping_add(&dev->mapping, 0xb8000, 0x08000, + cga_read, NULL, NULL, + cga_write, NULL, NULL, + NULL, MEM_MAPPING_EXTERNAL, dev); + io_sethandler(0x03d0, 0x0010, + cga_in, NULL, NULL, + cga_out, NULL, NULL, + dev); + + if (info->local) { + 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; + } + + vflags = info->local; + + overscan_x = overscan_y = 16; + + dev->rgb_type = device_get_config_int("rgb_type"); + cga_palette = (dev->rgb_type << 1); + cgapal_rebuild(); + + dev->crtc[9] = 13; + + return dev; +} + +static void +compaq_cga_close(void *priv) +{ + cga_t *dev = (cga_t *) priv; + + free(dev->vram); + free(dev); +} + +static void +compaq_cga_speed_changed(void *priv) +{ + cga_t *dev = (cga_t *) priv; + + if (dev->crtc[9] == 13) /* Character height */ + compaq_cga_recalctimings(dev); + else + cga_recalctimings(dev); +} + +extern const device_config_t cga_config[]; + +const device_t compaq_cga_device = { + .name = "Compaq CGA", + .internal_name = "compaq_cga", + .flags = DEVICE_ISA, + .local = 0, + .init = compaq_cga_init, + .close = compaq_cga_close, + .reset = NULL, + .available = NULL, + .speed_changed = compaq_cga_speed_changed, + .force_redraw = NULL, + .config = cga_config +}; + +const device_t compaq_cga_2_device = { + .name = "Compaq CGA 2", + .internal_name = "compaq_cga_2", + .flags = DEVICE_ISA, + .local = 1, + .init = compaq_cga_init, + .close = compaq_cga_close, + .reset = NULL, + .available = NULL, + .speed_changed = compaq_cga_speed_changed, + .force_redraw = NULL, + .config = cga_config +}; diff --git a/src/video/vid_cga_compaq_plasma.c b/src/video/vid_cga_compaq_plasma.c new file mode 100644 index 000000000..b281cf93f --- /dev/null +++ b/src/video/vid_cga_compaq_plasma.c @@ -0,0 +1,843 @@ +/* + * 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 plasma displays on early Compaq Portables and laptops. + * + * + * + * Authors: Sarah Walker, + * Miran Grca, + * + * Copyright 2008-2020 Sarah Walker. + * Copyright 2016-2020 Miran Grca. + * Copyright 2025 starfrost + */ +#include +#include +#include +#include +#include +#include +#include +#define HAVE_STDARG_H +#include <86box/86box.h> +#include "cpu.h" +#include <86box/io.h> +#include <86box/timer.h> +#include <86box/pit.h> +#include <86box/mem.h> +#include <86box/rom.h> +#include <86box/device.h> +#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 }; + +#define CGA_RGB 0 +#define CGA_COMPOSITE 1 + +/*Very rough estimate*/ +#define VID_CLOCK (double) (651 * 416 * 60) + +/* Mapping of attributes to colours */ +static uint32_t amber; +static uint32_t black; +static uint32_t blinkcols[256][2]; +static uint32_t normcols[256][2]; + +/* Video options set by the motherboard; they will be picked up by the card + * on the next poll. + * + * Bit 3: Disable built-in video (for add-on card) + * Bit 2: Thin font + * Bits 0,1: Font set (not currently implemented) + */ +static int8_t cpq_st_display_internal = -1; + +static uint8_t mdaattr[256][2][2]; + +static void +compaq_plasma_display_set(uint8_t internal) +{ + cpq_st_display_internal = internal; +} + +typedef struct compaq_plasma_t { + cga_t cga; + mem_mapping_t font_ram_mapping; + uint8_t *font_ram; + uint8_t port_13c6; + uint8_t port_23c6; + uint8_t port_27c6; + uint8_t internal_monitor; +} compaq_plasma_t; + + +static void compaq_plasma_recalcattrs(compaq_plasma_t *self); + +static void +compaq_plasma_recalctimings(compaq_plasma_t *self) +{ + double _dispontime; + double _dispofftime; + double disptime; + + if (!self->internal_monitor && !(self->port_23c6 & 0x01)) { + cga_recalctimings(&self->cga); + return; + } + + disptime = 651; + _dispontime = 640; + _dispofftime = disptime - _dispontime; + 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 +compaq_plasma_write(uint32_t addr, uint8_t val, void *priv) +{ + compaq_plasma_t *self = (compaq_plasma_t *) priv; + + if (self->port_23c6 & 0x08) + self->font_ram[addr & 0x1fff] = val; + else + self->cga.vram[addr & 0x7fff] = val; + + compaq_plasma_waitstates(&self->cga); +} +static uint8_t +compaq_plasma_read(uint32_t addr, void *priv) +{ + compaq_plasma_t *self = (compaq_plasma_t *) priv; + uint8_t ret; + + compaq_plasma_waitstates(&self->cga); + + if (self->port_23c6 & 0x08) + ret = (self->font_ram[addr & 0x1fff]); + else + ret = (self->cga.vram[addr & 0x7fff]); + + return ret; +} + +static void +compaq_plasma_out(uint16_t addr, uint8_t val, void *priv) +{ + compaq_plasma_t *self = (compaq_plasma_t *) priv; + + switch (addr) { + /* Emulated CRTC, register select */ + case 0x3d0: + case 0x3d2: + case 0x3d4: + case 0x3d6: + cga_out(addr, val, &self->cga); + break; + + /* Emulated CRTC, value */ + case 0x3d1: + case 0x3d3: + case 0x3d5: + case 0x3d7: + cga_out(addr, val, &self->cga); + compaq_plasma_recalctimings(self); + break; + case 0x3d8: + case 0x3d9: + cga_out(addr, val, &self->cga); + break; + + case 0x13c6: + self->port_13c6 = val; + compaq_plasma_display_set((self->port_13c6 & 0x08) ? 1 : 0); + /* + For bits 2-0, John gives 0 = CGA, 1 = EGA, 3 = MDA; + Another source (Ralf Brown?) gives 4 = CGA, 5 = EGA, 7 = MDA; + This leads me to believe bit 2 is not relevant to the mode. + */ + if ((val & 0x07) == 0x03) + mem_mapping_set_addr(&self->cga.mapping, 0xb0000, 0x08000); + else + mem_mapping_set_addr(&self->cga.mapping, 0xb8000, 0x08000); + break; + + case 0x23c6: + self->port_23c6 = val; + break; + + case 0x27c6: + self->port_27c6 = val; + break; + + default: + break; + } +} + +static uint8_t +compaq_plasma_in(uint16_t addr, void *priv) +{ + compaq_plasma_t *self = (compaq_plasma_t *) priv; + uint8_t ret = 0xff; + + switch (addr) { + case 0x3d4: + case 0x3da: + case 0x3db: + case 0x3dc: + ret = cga_in(addr, &self->cga); + break; + + case 0x3d1: + case 0x3d3: + case 0x3d5: + case 0x3d7: + ret = cga_in(addr, &self->cga); + break; + + case 0x3d8: + ret = self->cga.cgamode; + break; + + case 0x13c6: + ret = self->port_13c6; + break; + + case 0x17c6: + ret = 0xe6; + break; + + case 0x1bc6: + ret = 0x40; + break; + + case 0x23c6: + ret = self->port_23c6; + break; + + case 0x27c6: + ret = self->port_27c6 & 0x3f; + break; + + default: + break; + } + + return ret; +} + +static void +compaq_plasma_poll(void *priv) +{ + compaq_plasma_t *self = (compaq_plasma_t *) priv; + uint8_t chr; + uint8_t attr; + uint8_t scanline; + uint16_t memaddr = (self->cga.crtc[CGA_CRTC_START_ADDR_LOW] | (self->cga.crtc[CGA_CRTC_START_ADDR_HIGH] << 8)) & 0x7fff; + uint16_t cursoraddr = (self->cga.crtc[CGA_CRTC_CURSOR_ADDR_LOW] | (self->cga.crtc[CGA_CRTC_CURSOR_ADDR_HIGH] << 8)) & 0x7fff; + uint16_t addr; + int drawcursor; + int cursorline; + int blink = 0; + int underline = 0; + int cursorvisible = 0; + int cursorinvisible = 0; + int c; + int x; + uint32_t ink = 0; + uint32_t fg = (self->cga.cgacol & 0x0f) ? amber : black; + uint32_t bg = black; + uint32_t black_half = black; + uint32_t amber_half = amber; + uint32_t cols[2]; + uint8_t dat; + 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)) { + self->internal_monitor = cpq_st_display_internal; + compaq_plasma_recalctimings(self); + } + + /* graphic mode and not mode 40h */ + if (!self->internal_monitor && !(self->port_23c6 & 0x01)) { + /* standard cga mode */ + cga_poll(&self->cga); + return; + } else { + /* mode 40h or text mode */ + if (!self->cga.linepos) { + timer_advance_u64(&self->cga.timer, self->cga.dispofftime); + self->cga.cgastat |= 1; + self->cga.linepos = 1; + if (self->cga.cgadispon) { + if (self->cga.displine == 0) + video_wait_for_buffer(); + + /* 80-col */ + if (self->cga.cgamode & 0x01) { + scanline = self->cga.displine & 0x0f; + addr = ((memaddr & ~1) + (self->cga.displine >> 4) * 80) << 1; + memaddr += (self->cga.displine >> 4) * 80; + + if ((self->cga.crtc[CGA_CRTC_CURSOR_START] & 0x60) == 0x20) + cursorline = 0; + else { + if ((self->cga.crtc[CGA_CRTC_CURSOR_START] & 0x0f) > 0x07) + cursorvisible = (self->cga.crtc[CGA_CRTC_CURSOR_START] & 0x0f) + 1; + else + cursorvisible = ((self->cga.crtc[CGA_CRTC_CURSOR_START] & 0x0f) << 1); + + if ((self->cga.crtc[CGA_CRTC_CURSOR_END] & 0x0f) > 0x07) + cursorinvisible = (self->cga.crtc[CGA_CRTC_CURSOR_END] & 0x0f) + 2; + else + cursorinvisible = ((self->cga.crtc[CGA_CRTC_CURSOR_END] & 0x0f) << 1); + + cursorline = (cursorvisible <= scanline) && (cursorinvisible >= scanline); + } + + /* for each text column */ + for (x = 0; x < 80; x++) { + /* video output enabled */ + if (self->cga.cgamode & 0x08) { + /* character */ + chr = self->cga.vram[(addr + (x << 1)) & 0x7fff]; + /* text attributes */ + attr = self->cga.vram[(addr + ((x << 1) + 1)) & 0x7fff]; + } else { + chr = 0x00; + attr = 0x00; + } + + uint8_t hi_bit = attr & 0x08; + /* check if cursor has to be drawn */ + drawcursor = ((memaddr == cursoraddr) && cursorline && (self->cga.cgamode & 0x08) && (self->cga.cgablink & 0x10)); + /* check if character underline mode should be set */ + underline = ((attr & 0x07) == 0x01); + underline = underline || (((self->port_23c6 >> 5) == 1) && hi_bit); + if (underline) { + /* set forecolor to white */ + attr = attr | 0x7; + } + blink = 0; + /* set foreground */ + cols[1] = blinkcols[attr][1]; + /* blink active */ + if (self->cga.cgamode & CGA_MODE_FLAG_BLINK) { + cols[0] = blinkcols[attr][0]; + /* attribute 7 active and not cursor */ + if ((self->cga.cgablink & 0x08) && (attr & 0x80) && !drawcursor) { + /* set blinking */ + cols[1] = cols[0]; + blink = 1; + } + } else { + /* Set intensity bit */ + cols[1] = normcols[attr][1]; + cols[0] = normcols[attr][0]; + } + + /* character address */ + uint16_t chr_addr = ((chr * 16) + scanline) & 0x0fff; + if (((self->port_23c6 >> 5) == 3) && hi_bit) + chr_addr |= 0x1000; + + /* character underline active and 7th row of pixels in character height being drawn */ + if (underline) { + /* for each pixel in character width */ + for (c = 0; c < 8; c++) + buffer32->line[self->cga.displine][(x << 3) + c] = mdaattr[attr][blink][1]; + } else if (drawcursor) { + for (c = 0; c < 8; c++) + buffer32->line[self->cga.displine][(x << 3) + c] = cols[(self->font_ram[chr_addr] & (1 << (c ^ 7))) ? 1 : 0] ^ (amber ^ black); + } else { + for (c = 0; c < 8; c++) + buffer32->line[self->cga.displine][(x << 3) + c] = cols[(self->font_ram[chr_addr] & (1 << (c ^ 7))) ? 1 : 0]; + } + + if (hi_bit) { + if ((self->port_23c6 >> 5) == 4) { + uint8_t b = (cols[1] & 0xff) >> 1; + uint8_t g = ((cols[1] >> 8) & 0xff) >> 1; + uint8_t r = ((cols[1] >> 16) & 0xff) >> 1; + cols[1] = b | (g << 8) | (r << 16); + b = (cols[0] & 0xff) >> 1; + g = ((cols[0] >> 8) & 0xff) >> 1; + r = ((cols[0] >> 16) & 0xff) >> 1; + cols[0] = b | (g << 8) | (r << 16); + if (drawcursor) { + black_half = black; + amber_half = amber; + uint8_t bB = (black & 0xff) >> 1; + uint8_t gB = ((black >> 8) & 0xff) >> 1; + uint8_t rB = ((black >> 16) & 0xff) >> 1; + black_half = bB | (gB << 8) | (rB << 16); + uint8_t bA = (amber & 0xff) >> 1; + uint8_t gA = ((amber >> 8) & 0xff) >> 1; + uint8_t rA = ((amber >> 16) & 0xff) >> 1; + amber_half = bA | (gA << 8) | (rA << 16); + for (c = 0; c < 8; c++) + buffer32->line[self->cga.displine][(x << 3) + c] = cols[(self->font_ram[chr_addr] & (1 << (c ^ 7))) ? 1 : 0] ^ (amber_half ^ black_half); + } else { + for (c = 0; c < 8; c++) + buffer32->line[self->cga.displine][(x << 3) + c] = cols[(self->font_ram[chr_addr] & (1 << (c ^ 7))) ? 1 : 0]; + } + } else if ((self->port_23c6 >> 5) == 2) { + if (drawcursor) { + for (c = 0; c < 8; c++) + buffer32->line[self->cga.displine][(x << 3) + c] = cols[(self->font_ram[chr_addr] & (1 << (c ^ 7))) ? 0 : 1] ^ (amber ^ black); + } else { + for (c = 0; c < 8; c++) + buffer32->line[self->cga.displine][(x << 3) + c] = cols[(self->font_ram[chr_addr] & (1 << (c ^ 7))) ? 0 : 1]; + } + } + } + memaddr++; + } + } + /* 40-col */ + else if (!(self->cga.cgamode & 0x02)) { + scanline = self->cga.displine & 0x0f; + addr = ((memaddr & ~1) + (self->cga.displine >> 4) * 40) << 1; + memaddr += (self->cga.displine >> 4) * 40; + + if ((self->cga.crtc[CGA_CRTC_CURSOR_START] & 0x60) == 0x20) + cursorline = 0; + else { + if ((self->cga.crtc[CGA_CRTC_CURSOR_START] & 0x0f) > 0x07) + cursorvisible = (self->cga.crtc[CGA_CRTC_CURSOR_START] & 0x0f) + 1; + else + cursorvisible = ((self->cga.crtc[CGA_CRTC_CURSOR_START] & 0x0f) << 1); + + if ((self->cga.crtc[CGA_CRTC_CURSOR_END] & 0x0f) > 0x07) + cursorinvisible = (self->cga.crtc[CGA_CRTC_CURSOR_END] & 0x0f) + 2; + else + cursorinvisible = ((self->cga.crtc[CGA_CRTC_CURSOR_END] & 0x0f) << 1); + + cursorline = (cursorvisible <= scanline) && (cursorinvisible >= scanline); + } + + for (x = 0; x < 40; x++) { + /* video output enabled */ + if (self->cga.cgamode & 0x08) { + /* character */ + chr = self->cga.vram[(addr + (x << 1)) & 0x7fff]; + /* text attributes */ + attr = self->cga.vram[(addr + ((x << 1) + 1)) & 0x7fff]; + } else { + chr = 0x00; + attr = 0x00; + } + + uint8_t hi_bit = attr & 0x08; + /* check if cursor has to be drawn */ + drawcursor = ((memaddr == cursoraddr) && cursorline && (self->cga.cgamode & 0x08) && (self->cga.cgablink & 0x10)); + /* check if character underline mode should be set */ + underline = ((attr & 0x07) == 0x01); + underline = underline || (((self->port_23c6 >> 5) == 1) && hi_bit); + if (underline) { + /* set forecolor to white */ + attr = attr | 0x7; + } + blink = 0; + /* set foreground */ + cols[1] = blinkcols[attr][1]; + /* blink active */ + if (self->cga.cgamode & CGA_MODE_FLAG_BLINK) { + cols[0] = blinkcols[attr][0]; + /* attribute 7 active and not cursor */ + if ((self->cga.cgablink & 0x08) && (attr & 0x80) && !drawcursor) { + /* set blinking */ + cols[1] = cols[0]; + blink = 1; + } + } else { + /* Set intensity bit */ + cols[1] = normcols[attr][1]; + cols[0] = normcols[attr][0]; + } + + /* character address */ + uint16_t chr_addr = ((chr * 16) + scanline) & 0x0fff; + if (((self->port_23c6 >> 5) == 3) && hi_bit) + chr_addr |= 0x1000; + + /* character underline active and 7th row of pixels in character height being drawn */ + if (underline && (scanline == 7)) { + /* for each pixel in character width */ + for (c = 0; c < 8; c++) + buffer32->line[self->cga.displine][(x << 4) + (c << 1)] = buffer32->line[self->cga.displine][(x << 4) + (c << 1) + 1] = mdaattr[attr][blink][1]; + } else if (drawcursor) { + for (c = 0; c < 8; c++) + buffer32->line[self->cga.displine][(x << 4) + (c << 1)] = buffer32->line[self->cga.displine][(x << 4) + (c << 1) + 1] = cols[(self->font_ram[chr_addr] & (1 << (c ^ 7))) ? 1 : 0] ^ (amber ^ black); + } else { + for (c = 0; c < 8; c++) + buffer32->line[self->cga.displine][(x << 4) + (c << 1)] = buffer32->line[self->cga.displine][(x << 4) + (c << 1) + 1] = cols[(self->font_ram[chr_addr] & (1 << (c ^ 7))) ? 1 : 0]; + } + + if (hi_bit) { + if ((self->port_23c6 >> 5) == 4) { + uint8_t b = (cols[1] & 0xff) >> 1; + uint8_t g = ((cols[1] >> 8) & 0xff) >> 1; + uint8_t r = ((cols[1] >> 16) & 0xff) >> 1; + cols[1] = b | (g << 8) | (r << 16); + b = (cols[0] & 0xff) >> 1; + g = ((cols[0] >> 8) & 0xff) >> 1; + r = ((cols[0] >> 16) & 0xff) >> 1; + cols[0] = b | (g << 8) | (r << 16); + if (drawcursor) { + black_half = black; + amber_half = amber; + uint8_t bB = (black & 0xff) >> 1; + uint8_t gB = ((black >> 8) & 0xff) >> 1; + uint8_t rB = ((black >> 16) & 0xff) >> 1; + black_half = bB | (gB << 8) | (rB << 16); + uint8_t bA = (amber & 0xff) >> 1; + uint8_t gA = ((amber >> 8) & 0xff) >> 1; + uint8_t rA = ((amber >> 16) & 0xff) >> 1; + amber_half = bA | (gA << 8) | (rA << 16); + for (c = 0; c < 8; c++) + buffer32->line[self->cga.displine][(x << 4) + (c << 1)] = buffer32->line[self->cga.displine][(x << 4) + (c << 1) + 1] = cols[(self->font_ram[chr_addr] & (1 << (c ^ 7))) ? 1 : 0] ^ (amber_half ^ black_half); + } else { + for (c = 0; c < 8; c++) + buffer32->line[self->cga.displine][(x << 4) + (c << 1)] = buffer32->line[self->cga.displine][(x << 4) + (c << 1) + 1] = cols[(self->font_ram[chr_addr] & (1 << (c ^ 7))) ? 1 : 0]; + } + } else if ((self->port_23c6 >> 5) == 2) { + if (drawcursor) { + for (c = 0; c < 8; c++) + buffer32->line[self->cga.displine][(x << 4) + (c << 1)] = buffer32->line[self->cga.displine][(x << 4) + (c << 1) + 1] = cols[(self->font_ram[chr_addr] & (1 << (c ^ 7))) ? 0 : 1] ^ (amber ^ black); + } else { + for (c = 0; c < 8; c++) + buffer32->line[self->cga.displine][(x << 4) + (c << 1)] = buffer32->line[self->cga.displine][(x << 4) + (c << 1) + 1] = cols[(self->font_ram[chr_addr] & (1 << (c ^ 7))) ? 0 : 1]; + } + } + } + memaddr++; + } + } else { + if (self->cga.cgamode & CGA_MODE_FLAG_HIGHRES_GRAPHICS) { + /* 640x400 mode */ + if (self->port_23c6 & 0x01) /* 640*400 */ { + addr = ((self->cga.displine) & 1) * 0x2000 + ((self->cga.displine >> 1) & 1) * 0x4000 + (self->cga.displine >> 2) * 80 + ((memaddr & ~1) << 1); + } else { + addr = ((self->cga.displine >> 1) & 1) * 0x2000 + (self->cga.displine >> 2) * 80 + ((memaddr & ~1) << 1); + } + for (uint8_t x = 0; x < 80; x++) { + dat = self->cga.vram[addr & 0x7fff]; + addr++; + + for (uint8_t c = 0; c < 8; c++) { + ink = (dat & 0x80) ? fg : bg; + if (!(self->cga.cgamode & 0x08)) + ink = black; + buffer32->line[self->cga.displine][(x << 3) + c] = ink; + dat <<= 1; + } + } + } else { + addr = ((self->cga.displine >> 1) & 1) * 0x2000 + (self->cga.displine >> 2) * 80 + ((memaddr & ~1) << 1); + for (uint8_t x = 0; x < 80; x++) { + dat = self->cga.vram[addr & 0x7fff]; + addr++; + + for (uint8_t c = 0; c < 4; c++) { + pattern = (dat & 0xC0) >> 6; + if (!(self->cga.cgamode & 0x08)) + pattern = 0; + + switch (pattern & 3) { + case 0: + ink0 = ink1 = black; + break; + case 1: + if (self->cga.displine & 0x01) { + ink0 = black; + ink1 = black; + } else { + ink0 = amber; + ink1 = black; + } + break; + case 2: + if (self->cga.displine & 0x01) { + ink0 = black; + ink1 = amber; + } else { + ink0 = amber; + ink1 = black; + } + break; + case 3: + ink0 = ink1 = amber; + break; + + default: + break; + } + buffer32->line[self->cga.displine][(x << 3) + (c << 1)] = ink0; + buffer32->line[self->cga.displine][(x << 3) + (c << 1) + 1] = ink1; + dat <<= 2; + } + } + } + } + } + self->cga.displine++; + /* Hardcode a fixed refresh rate and VSYNC timing */ + if (self->cga.displine == 400) { /* Start of VSYNC */ + self->cga.cgastat |= 8; + self->cga.cgadispon = 0; + } + if (self->cga.displine == 416) { /* End of VSYNC */ + self->cga.displine = 0; + self->cga.cgastat &= ~8; + self->cga.cgadispon = 1; + } + } else { + timer_advance_u64(&self->cga.timer, self->cga.dispontime); + if (self->cga.cgadispon) + self->cga.cgastat &= ~1; + + self->cga.linepos = 0; + + if (self->cga.displine == 400) { + xsize = 640; + ysize = 400; + + if ((self->cga.cgamode & 0x08) || video_force_resize_get()) { + set_screen_size(xsize, ysize); + + if (video_force_resize_get()) + video_force_resize_set(0); + } + /* Plasma specific */ + video_blit_memtoscreen(0, 0, xsize, ysize); + frames++; + + /* Fixed 640x400 resolution */ + video_res_x = 640; + video_res_y = 400; + + if (self->cga.cgamode & 0x02) { + if (self->cga.cgamode & CGA_MODE_FLAG_HIGHRES_GRAPHICS) + 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) +{ + int n; + + /* val behaves as follows: + * Bit 0: Attributes 01-06, 08-0E are inverse video + * Bit 1: Attributes 01-06, 08-0E are bold + * Bit 2: Attributes 11-16, 18-1F, 21-26, 28-2F ... F1-F6, F8-FF + * are inverse video + * Bit 3: Attributes 11-16, 18-1F, 21-26, 28-2F ... F1-F6, F8-FF + * are bold */ + + /* Set up colours */ + amber = makecol(0xff, 0x7d, 0x00); + black = makecol(0x64, 0x19, 0x00); + + /* 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; + blinkcols[n][1] = normcols[n][1] = black; + } + + /* Colours 0x11-0xFF are controlled by bits 2 and 3 of the + * passed value. Exclude x0 and x8, which are always black on + * amber. */ + for (n = 0x11; n <= 0xFF; n++) { + if ((n & 7) == 0) + continue; + blinkcols[n][0] = normcols[n][0] = black; + blinkcols[n][1] = normcols[n][1] = amber; + } + /* Set up the 01-0E range, controlled by bits 0 and 1 of the + * passed value. When blinking is enabled this also affects 81-8E. */ + for (n = 0x01; n <= 0x0E; n++) { + if (n == 7) + continue; + blinkcols[n][0] = normcols[n][0] = black; + blinkcols[n][1] = normcols[n][1] = amber; + blinkcols[n + 128][0] = black; + blinkcols[n + 128][1] = amber; + } + /* Colours 07 and 0F are always amber on black. If blinking is + * enabled so are 87 and 8F. */ + for (n = 0x07; n <= 0x0F; n += 8) { + blinkcols[n][0] = normcols[n][0] = black; + blinkcols[n][1] = normcols[n][1] = amber; + blinkcols[n + 128][0] = black; + blinkcols[n + 128][1] = amber; + } + /* When not blinking, colours 81-8F are always amber on black. */ + for (n = 0x81; n <= 0x8F; n++) { + normcols[n][0] = black; + normcols[n][1] = amber; + } + + /* Finally do the ones which are solid black. These differ between + * the normal and blinking mappings */ + for (n = 0; n <= 0xFF; n += 0x11) + normcols[n][0] = normcols[n][1] = black; + + /* In the blinking range, 00 11 22 .. 77 and 80 91 A2 .. F7 are black */ + for (n = 0; n <= 0x77; n += 0x11) { + blinkcols[n][0] = blinkcols[n][1] = black; + blinkcols[n + 128][0] = blinkcols[n + 128][1] = black; + } +} + +static void * +compaq_plasma_init(UNUSED(const device_t *info)) +{ + compaq_plasma_t *self = calloc(1, sizeof(compaq_plasma_t)); + + cga_init(&self->cga); + video_inform(VIDEO_FLAG_TYPE_CGA, &timing_compaq_plasma); + + self->cga.composite = 0; + self->cga.revision = 0; + + self->cga.vram = malloc(0x8000); + self->internal_monitor = 1; + self->font_ram = malloc(0x2000); + + cga_comp_init(self->cga.revision); + timer_set_callback(&self->cga.timer, compaq_plasma_poll); + timer_set_p(&self->cga.timer, self); + + mem_mapping_add(&self->cga.mapping, 0xb8000, 0x08000, + compaq_plasma_read, NULL, NULL, + compaq_plasma_write, NULL, NULL, + NULL, MEM_MAPPING_EXTERNAL, self); + for (int i = 1; i <= 2; i++) { + io_sethandler(0x03c6 + (i << 12), 0x0001, compaq_plasma_in, NULL, NULL, compaq_plasma_out, NULL, NULL, self); + io_sethandler(0x07c6 + (i << 12), 0x0001, compaq_plasma_in, NULL, NULL, compaq_plasma_out, NULL, NULL, self); + io_sethandler(0x0bc6 + (i << 12), 0x0001, compaq_plasma_in, NULL, NULL, compaq_plasma_out, NULL, NULL, self); + } + io_sethandler(0x03d0, 0x0010, compaq_plasma_in, NULL, NULL, compaq_plasma_out, NULL, NULL, self); + + overscan_x = overscan_y = 16; + compaq_plasma_recalcattrs(self); + + 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 *priv) +{ + compaq_plasma_t *self = (compaq_plasma_t *) priv; + + free(self->cga.vram); + free(self->font_ram); + free(self); +} + +static void +compaq_plasma_speed_changed(void *priv) +{ + compaq_plasma_t *self = (compaq_plasma_t *) priv; + + compaq_plasma_recalctimings(self); +} + +const device_config_t compaq_plasma_config[] = { + // clang-format off + { + .name = "rgb_type", + .description = "RGB type", + .type = CONFIG_SELECTION, + .default_string = "", + .default_int = 0, + .file_filter = "", + .spinner = { 0 }, + .selection = { + { .description = "Color", .value = 0 }, + { .description = "Green Monochrome", .value = 1 }, + { .description = "Amber Monochrome", .value = 2 }, + { .description = "Gray Monochrome", .value = 3 }, + { .description = "" } + } + }, + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on +}; + +const device_t compaq_plasma_device = { + .name = "Compaq Plasma", + .internal_name = "compaq_plasma", + .flags = 0, + .local = 0, + .init = compaq_plasma_init, + .close = compaq_plasma_close, + .reset = NULL, + .available = NULL, + .speed_changed = compaq_plasma_speed_changed, + .force_redraw = NULL, + .config = compaq_plasma_config +}; diff --git a/src/video/vid_nga.c b/src/video/vid_cga_ncr.c similarity index 67% rename from src/video/vid_nga.c rename to src/video/vid_cga_ncr.c index 32c103a8b..eb4474a40 100644 --- a/src/video/vid_nga.c +++ b/src/video/vid_cga_ncr.c @@ -30,6 +30,7 @@ #include <86box/io.h> #include <86box/video.h> #include <86box/86box.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/mem.h> #include <86box/pit.h> @@ -55,12 +56,12 @@ nga_recalctimings(nga_t *nga) double _dispofftime; double disptime; - if (nga->cga.cgamode & 1) { - disptime = nga->cga.crtc[0] + 1; - _dispontime = nga->cga.crtc[1]; + if (nga->cga.cgamode & CGA_MODE_FLAG_HIGHRES) { + disptime = nga->cga.crtc[CGA_CRTC_HTOTAL] + 1; + _dispontime = nga->cga.crtc[CGA_CRTC_HDISP]; } else { - disptime = (nga->cga.crtc[0] + 1) << 1; - _dispontime = nga->cga.crtc[1] << 1; + disptime = (nga->cga.crtc[CGA_CRTC_HTOTAL] + 1) << 1; + _dispontime = nga->cga.crtc[CGA_CRTC_HDISP] << 1; } _dispofftime = disptime - _dispontime; @@ -147,7 +148,7 @@ nga_poll(void *priv) { nga_t *nga = (nga_t *) priv; /* set cursor position in memory */ - uint16_t ca = (nga->cga.crtc[15] | (nga->cga.crtc[14] << 8)) & 0x3fff; + uint16_t cursoraddr = (nga->cga.crtc[CGA_CRTC_CURSOR_ADDR_LOW] | (nga->cga.crtc[CGA_CRTC_CURSOR_ADDR_HIGH] << 8)) & 0x3fff; int drawcursor; int x; int c; @@ -160,10 +161,10 @@ nga_poll(void *priv) uint16_t dat2; int cols[4]; int col; - int oldsc; + int scanline_old; /* graphic mode and not high-res modes */ - if ((nga->cga.cgamode & 2) && !(nga->cga.cgamode & 0x40)) { + if ((nga->cga.cgamode & CGA_MODE_FLAG_GRAPHICS) && !(nga->cga.cgamode & 0x40)) { /* standard cga mode */ cga_poll(&nga->cga); return; @@ -173,10 +174,10 @@ nga_poll(void *priv) timer_advance_u64(&nga->cga.timer, nga->cga.dispofftime); nga->cga.cgastat |= 1; nga->cga.linepos = 1; - oldsc = nga->cga.sc; + scanline_old = nga->cga.scanline; /* if interlaced */ - if ((nga->cga.crtc[8] & 3) == 3) - nga->cga.sc = ((nga->cga.sc << 1) + nga->cga.oddeven) & 7; + if ((nga->cga.crtc[CGA_CRTC_INTERLACE] & 3) == 3) + nga->cga.scanline = ((nga->cga.scanline << 1) + nga->cga.oddeven) & 7; if (nga->cga.cgadispon) { if (nga->cga.displine < nga->cga.firstline) { nga->cga.firstline = nga->cga.displine; @@ -184,11 +185,11 @@ nga_poll(void *priv) } nga->cga.lastline = nga->cga.displine; /* 80-col */ - if ((nga->cga.cgamode & 1) && !(nga->cga.cgamode & 2)) { + if ((nga->cga.cgamode & CGA_MODE_FLAG_HIGHRES) && !(nga->cga.cgamode & CGA_MODE_FLAG_GRAPHICS)) { /* for each text column */ - for (x = 0; x < nga->cga.crtc[1]; x++) { + for (x = 0; x < nga->cga.crtc[CGA_CRTC_HDISP]; x++) { /* video output enabled */ - if (nga->cga.cgamode & 8) { + if (nga->cga.cgamode & CGA_MODE_FLAG_VIDEO_ENABLE) { /* character */ chr = nga->cga.charbuffer[x << 1]; /* text attributes */ @@ -196,11 +197,11 @@ nga_poll(void *priv) } else chr = attr = 0; /* check if cursor has to be drawn */ - drawcursor = ((nga->cga.ma == ca) && nga->cga.con && nga->cga.cursoron); + drawcursor = ((nga->cga.memaddr == cursoraddr) && nga->cga.cursorvisible && nga->cga.cursoron); /* set foreground */ cols[1] = (attr & 15) + 16; /* blink active */ - if (nga->cga.cgamode & 0x20) { + if (nga->cga.cgamode & CGA_MODE_FLAG_BLINK) { cols[0] = ((attr >> 4) & 7) + 16; /* attribute 7 active and not cursor */ if ((nga->cga.cgablink & 8) && (attr & 0x80) && !nga->cga.drawcursor) { @@ -213,30 +214,30 @@ nga_poll(void *priv) } if (drawcursor) { for (c = 0; c < 8; c++) - buffer32->line[nga->cga.displine][(x << 3) + c + 8] = cols[(fontdatm[chr][((nga->cga.sc & 7) << 1) | nga->lineff] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; + buffer32->line[nga->cga.displine][(x << 3) + c + 8] = cols[(fontdatm[chr][((nga->cga.scanline & 7) << 1) | nga->lineff] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; } else { for (c = 0; c < 8; c++) - buffer32->line[nga->cga.displine][(x << 3) + c + 8] = cols[(fontdatm[chr][((nga->cga.sc & 7) << 1) | nga->lineff] & (1 << (c ^ 7))) ? 1 : 0]; + buffer32->line[nga->cga.displine][(x << 3) + c + 8] = cols[(fontdatm[chr][((nga->cga.scanline & 7) << 1) | nga->lineff] & (1 << (c ^ 7))) ? 1 : 0]; } - nga->cga.ma++; + nga->cga.memaddr++; } } /* 40-col */ - else if (!(nga->cga.cgamode & 2)) { + else if (!(nga->cga.cgamode & CGA_MODE_FLAG_GRAPHICS)) { /* for each text column */ - for (x = 0; x < nga->cga.crtc[1]; x++) { - if (nga->cga.cgamode & 8) { - chr = nga->cga.vram[((nga->cga.ma << 1) & 0x3fff) + nga->base]; - attr = nga->cga.vram[(((nga->cga.ma << 1) + 1) & 0x3fff) + nga->base]; + for (x = 0; x < nga->cga.crtc[CGA_CRTC_HDISP]; x++) { + if (nga->cga.cgamode & CGA_MODE_FLAG_VIDEO_ENABLE) { + chr = nga->cga.vram[((nga->cga.memaddr << 1) & 0x3fff) + nga->base]; + attr = nga->cga.vram[(((nga->cga.memaddr << 1) + 1) & 0x3fff) + nga->base]; } else { chr = attr = 0; } - drawcursor = ((nga->cga.ma == ca) && nga->cga.con && nga->cga.cursoron); + drawcursor = ((nga->cga.memaddr == cursoraddr) && nga->cga.cursorvisible && nga->cga.cursoron); /* set foreground */ cols[1] = (attr & 15) + 16; /* blink active */ - if (nga->cga.cgamode & 0x20) { + if (nga->cga.cgamode & CGA_MODE_FLAG_BLINK) { cols[0] = ((attr >> 4) & 7) + 16; if ((nga->cga.cgablink & 8) && (attr & 0x80) && !nga->cga.drawcursor) { /* set blinking */ @@ -249,19 +250,19 @@ nga_poll(void *priv) if (drawcursor) { for (c = 0; c < 8; c++) - buffer32->line[nga->cga.displine][(x << 4) + (c << 1) + 8] = buffer32->line[nga->cga.displine][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdatm[chr][((nga->cga.sc & 7) << 1) | nga->lineff] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; + buffer32->line[nga->cga.displine][(x << 4) + (c << 1) + 8] = buffer32->line[nga->cga.displine][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdatm[chr][((nga->cga.scanline & 7) << 1) | nga->lineff] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; } else { for (c = 0; c < 8; c++) - buffer32->line[nga->cga.displine][(x << 4) + (c << 1) + 8] = buffer32->line[nga->cga.displine][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdatm[chr][((nga->cga.sc & 7) << 1) | nga->lineff] & (1 << (c ^ 7))) ? 1 : 0]; + buffer32->line[nga->cga.displine][(x << 4) + (c << 1) + 8] = buffer32->line[nga->cga.displine][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdatm[chr][((nga->cga.scanline & 7) << 1) | nga->lineff] & (1 << (c ^ 7))) ? 1 : 0]; } - nga->cga.ma++; + nga->cga.memaddr++; } } else { /* high res modes */ if (nga->cga.cgamode & 0x40) { /* 640x400x2 mode */ - if (nga->cga.cgamode & 0x4 || nga->cga.cgamode & 0x10) { + if (nga->cga.cgamode & 0x4 || nga->cga.cgamode & CGA_MODE_FLAG_HIGHRES_GRAPHICS) { /* * Scanlines are read in the following order: * 0b8000-0b9f3f even scans (0,4,...) @@ -269,14 +270,14 @@ nga_poll(void *priv) * 0bc000-0bdf3f even scans (1,5,...) * 0be000-0bff3f odd scans (3,7,...) */ - dat2 = ((nga->cga.sc & 1) * 0x2000) | (nga->lineff * 0x4000); + dat2 = ((nga->cga.scanline & 1) * 0x2000) | (nga->lineff * 0x4000); cols[0] = 0; cols[1] = 15 + 16; /* 640x400x4 mode */ } else { cols[0] = (nga->cga.cgacol & 15) | 16; col = (nga->cga.cgacol & 16) ? 24 : 16; - if (nga->cga.cgamode & 4) { + if (nga->cga.cgamode & CGA_MODE_FLAG_BW) { cols[1] = col | 3; /* Cyan */ cols[2] = col | 4; /* Red */ cols[3] = col | 7; /* White */ @@ -296,22 +297,22 @@ nga_poll(void *priv) * 0a8000-0abf3f even scans (2,6,...) * 0ac000-0aff3f odd scans (3,7,...) */ - dat2 = (nga->cga.sc & 1) * 0x4000; + dat2 = (nga->cga.scanline & 1) * 0x4000; } } else { - dat2 = (nga->cga.sc & 1) * 0x2000; + dat2 = (nga->cga.scanline & 1) * 0x2000; cols[0] = 0; cols[1] = (nga->cga.cgacol & 15) + 16; } /* for each text column */ - for (x = 0; x < nga->cga.crtc[1]; x++) { + for (x = 0; x < nga->cga.crtc[CGA_CRTC_HDISP]; x++) { /* video out */ - if (nga->cga.cgamode & 8) { + if (nga->cga.cgamode & CGA_MODE_FLAG_VIDEO_ENABLE) { /* 640x400x2 */ - if (nga->cga.cgamode & 0x4 || nga->cga.cgamode & 0x10) { + if (nga->cga.cgamode & 0x4 || nga->cga.cgamode & CGA_MODE_FLAG_HIGHRES_GRAPHICS) { /* read two bytes at a time */ - dat = (nga->cga.vram[((nga->cga.ma << 1) & 0x1fff) + dat2] << 8) | nga->cga.vram[((nga->cga.ma << 1) & 0x1fff) + dat2 + 1]; + dat = (nga->cga.vram[((nga->cga.memaddr << 1) & 0x1fff) + dat2] << 8) | nga->cga.vram[((nga->cga.memaddr << 1) & 0x1fff) + dat2 + 1]; /* each pixel is represented by one bit, so draw 16 pixels at a time */ /* crtc[1] is 40 column, so 40x16=640 pixels */ for (c = 0; c < 16; c++) { @@ -321,13 +322,13 @@ nga_poll(void *priv) /* 640x400x4 */ } else { /* lines 2,3,6,7,etc. */ - if (nga->cga.sc & 2) + if (nga->cga.scanline & 2) /* read two bytes at a time */ - dat = (nga->vram_64k[((nga->cga.ma << 1) & 0x7fff) + dat2] << 8) | nga->vram_64k[((nga->cga.ma << 1) & 0x7fff) + dat2 + 1]; + dat = (nga->vram_64k[((nga->cga.memaddr << 1) & 0x7fff) + dat2] << 8) | nga->vram_64k[((nga->cga.memaddr << 1) & 0x7fff) + dat2 + 1]; /* lines 0,1,4,5,etc. */ else /* read two bytes at a time */ - dat = (nga->cga.vram[((nga->cga.ma << 1) & 0x7fff) + dat2] << 8) | nga->cga.vram[((nga->cga.ma << 1) & 0x7fff) + dat2 + 1]; + dat = (nga->cga.vram[((nga->cga.memaddr << 1) & 0x7fff) + dat2] << 8) | nga->cga.vram[((nga->cga.memaddr << 1) & 0x7fff) + dat2 + 1]; /* each pixel is represented by two bits, so draw 8 pixels at a time */ /* crtc[1] is 80 column, so 80x8=640 pixels */ for (c = 0; c < 8; c++) { @@ -338,7 +339,7 @@ nga_poll(void *priv) } else { dat = 0; } - nga->cga.ma++; + nga->cga.memaddr++; } } } else { @@ -346,26 +347,26 @@ 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) { - 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]); + if (nga->cga.cgamode & CGA_MODE_FLAG_HIGHRES) { + hline(buffer32, 0, (nga->cga.displine << 1), ((nga->cga.crtc[CGA_CRTC_HDISP] << 3) + 16) << 2, cols[0]); + hline(buffer32, 0, (nga->cga.displine << 1) + 1, ((nga->cga.crtc[CGA_CRTC_HDISP] << 3) + 16) << 2, cols[0]); } else { - hline(buffer32, 0, (nga->cga.displine << 1), ((nga->cga.crtc[1] << 4) + 16) << 2, cols[0]); - hline(buffer32, 0, (nga->cga.displine << 1) + 1, ((nga->cga.crtc[1] << 4) + 16) << 2, cols[0]); + hline(buffer32, 0, (nga->cga.displine << 1), ((nga->cga.crtc[CGA_CRTC_HDISP] << 4) + 16) << 2, cols[0]); + hline(buffer32, 0, (nga->cga.displine << 1) + 1, ((nga->cga.crtc[CGA_CRTC_HDISP] << 4) + 16) << 2, cols[0]); } } - if (nga->cga.cgamode & 1) + if (nga->cga.cgamode & CGA_MODE_FLAG_HIGHRES) /* set screen width */ - x = (nga->cga.crtc[1] << 3) + 16; + x = (nga->cga.crtc[CGA_CRTC_HDISP] << 3) + 16; else - x = (nga->cga.crtc[1] << 4) + 16; + x = (nga->cga.crtc[CGA_CRTC_HDISP] << 4) + 16; video_process_8(x, nga->cga.displine); - nga->cga.sc = oldsc; + nga->cga.scanline = scanline_old; /* vertical sync */ - if (nga->cga.vc == nga->cga.crtc[7] && !nga->cga.sc) + if (nga->cga.vc == nga->cga.crtc[CGA_CRTC_VSYNC] && !nga->cga.scanline) nga->cga.cgastat |= 8; nga->cga.displine++; if (nga->cga.displine >= 720) @@ -379,8 +380,8 @@ nga_poll(void *priv) nga->lineff ^= 1; /* text mode or 640x400x2 */ - if (nga->lineff && !((nga->cga.cgamode & 1) && (nga->cga.cgamode & 0x40))) { - nga->cga.ma = nga->cga.maback; + if (nga->lineff && !((nga->cga.cgamode & CGA_MODE_FLAG_HIGHRES) && (nga->cga.cgamode & 0x40))) { + nga->cga.memaddr = nga->cga.memaddr_backup; /* 640x400x4 */ } else { if (nga->cga.vsynctime) { @@ -389,50 +390,49 @@ nga_poll(void *priv) nga->cga.cgastat &= ~8; } /* cursor stop scanline */ - if (nga->cga.sc == (nga->cga.crtc[11] & 31) || ((nga->cga.crtc[8] & 3) == 3 && nga->cga.sc == ((nga->cga.crtc[11] & 31) >> 1))) { - nga->cga.con = 0; - nga->cga.coff = 1; + if (nga->cga.scanline == (nga->cga.crtc[CGA_CRTC_CURSOR_END] & 31) || ((nga->cga.crtc[CGA_CRTC_INTERLACE] & 3) == 3 && nga->cga.scanline == ((nga->cga.crtc[CGA_CRTC_CURSOR_END] & 31) >> 1))) { + nga->cga.cursorvisible = 0; } /* interlaced and max scanline per char reached */ - if ((nga->cga.crtc[8] & 3) == 3 && nga->cga.sc == (nga->cga.crtc[9] >> 1)) - nga->cga.maback = nga->cga.ma; + if ((nga->cga.crtc[CGA_CRTC_INTERLACE] & 3) == 3 && nga->cga.scanline == (nga->cga.crtc[CGA_CRTC_MAX_SCANLINE_ADDR] >> 1)) + nga->cga.memaddr_backup = nga->cga.memaddr; if (nga->cga.vadj) { - nga->cga.sc++; - nga->cga.sc &= 31; - nga->cga.ma = nga->cga.maback; + nga->cga.scanline++; + nga->cga.scanline &= 31; + nga->cga.memaddr = nga->cga.memaddr_backup; nga->cga.vadj--; if (!nga->cga.vadj) { nga->cga.cgadispon = 1; /* change start of displayed page (crtc 12-13) */ - nga->cga.ma = nga->cga.maback = (nga->cga.crtc[13] | (nga->cga.crtc[12] << 8)) & 0x7fff; - nga->cga.sc = 0; + nga->cga.memaddr = nga->cga.memaddr_backup = (nga->cga.crtc[CGA_CRTC_START_ADDR_LOW] | (nga->cga.crtc[CGA_CRTC_START_ADDR_HIGH] << 8)) & 0x7fff; + nga->cga.scanline = 0; } /* nga specific */ /* end of character line reached */ - } else if (nga->cga.sc == nga->cga.crtc[9] || ((nga->cga.crtc[8] & 3) == 3 && nga->cga.sc == (nga->cga.crtc[9] >> 1))) { - nga->cga.maback = nga->cga.ma; - nga->cga.sc = 0; + } else if (nga->cga.scanline == nga->cga.crtc[CGA_CRTC_MAX_SCANLINE_ADDR] || ((nga->cga.crtc[CGA_CRTC_INTERLACE] & 3) == 3 && nga->cga.scanline == (nga->cga.crtc[CGA_CRTC_MAX_SCANLINE_ADDR] >> 1))) { + nga->cga.memaddr_backup = nga->cga.memaddr; + nga->cga.scanline = 0; oldvc = nga->cga.vc; nga->cga.vc++; nga->cga.vc &= 127; /* lines of character displayed */ - if (nga->cga.vc == nga->cga.crtc[6]) + if (nga->cga.vc == nga->cga.crtc[CGA_CRTC_VDISP]) nga->cga.cgadispon = 0; /* total vertical lines */ - if (oldvc == nga->cga.crtc[4]) { + if (oldvc == nga->cga.crtc[CGA_CRTC_VTOTAL]) { nga->cga.vc = 0; /* adjust vertical lines */ - nga->cga.vadj = nga->cga.crtc[5]; + nga->cga.vadj = nga->cga.crtc[CGA_CRTC_VTOTAL_ADJUST]; if (!nga->cga.vadj) { nga->cga.cgadispon = 1; /* change start of displayed page (crtc 12-13) */ - nga->cga.ma = nga->cga.maback = (nga->cga.crtc[13] | (nga->cga.crtc[12] << 8)) & 0x7fff; + nga->cga.memaddr = nga->cga.memaddr_backup = (nga->cga.crtc[CGA_CRTC_START_ADDR_LOW] | (nga->cga.crtc[CGA_CRTC_START_ADDR_HIGH] << 8)) & 0x7fff; } /* cursor start */ - switch (nga->cga.crtc[10] & 0x60) { + switch (nga->cga.crtc[CGA_CRTC_CURSOR_START] & 0x60) { case 0x20: nga->cga.cursoron = 0; break; @@ -445,18 +445,18 @@ nga_poll(void *priv) } } /* vertical line position */ - if (nga->cga.vc == nga->cga.crtc[7]) { + if (nga->cga.vc == nga->cga.crtc[CGA_CRTC_VSYNC]) { nga->cga.cgadispon = 0; nga->cga.displine = 0; /* nga specific */ nga->cga.vsynctime = 16; /* vsync pos */ - if (nga->cga.crtc[7]) { - if (nga->cga.cgamode & 1) + if (nga->cga.crtc[CGA_CRTC_VSYNC]) { + if (nga->cga.cgamode & CGA_MODE_FLAG_HIGHRES) /* set screen width */ - x = (nga->cga.crtc[1] << 3) + 16; + x = (nga->cga.crtc[CGA_CRTC_HDISP] << 3) + 16; else - x = (nga->cga.crtc[1] << 4) + 16; + x = (nga->cga.crtc[CGA_CRTC_HDISP] << 4) + 16; nga->cga.lastline++; xs_temp = x; @@ -471,7 +471,7 @@ nga_poll(void *priv) if (!enable_overscan) xs_temp -= 16; - if ((nga->cga.cgamode & 8) && ((xs_temp != xsize) || (ys_temp != ysize) || video_force_resize_get())) { + if ((nga->cga.cgamode & CGA_MODE_FLAG_VIDEO_ENABLE) && ((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)); @@ -493,14 +493,14 @@ nga_poll(void *priv) video_res_x = xsize; video_res_y = ysize; /* 80-col */ - if ((nga->cga.cgamode & 1) && !(nga->cga.cgamode & 0x40)) { + if ((nga->cga.cgamode & CGA_MODE_FLAG_HIGHRES) && !(nga->cga.cgamode & 0x40)) { video_res_x /= 8; - video_res_y /= (nga->cga.crtc[9] + 1) * 2; + video_res_y /= (nga->cga.crtc[CGA_CRTC_MAX_SCANLINE_ADDR] + 1) * 2; video_bpp = 0; /* 40-col */ - } else if (!(nga->cga.cgamode & 2)) { + } else if (!(nga->cga.cgamode & CGA_MODE_FLAG_GRAPHICS)) { video_res_x /= 16; - video_res_y /= (nga->cga.crtc[9] + 1) * 2; + video_res_y /= (nga->cga.crtc[CGA_CRTC_MAX_SCANLINE_ADDR] + 1) * 2; video_bpp = 0; } else if (nga->cga.cgamode & 0x40) { video_res_x /= 8; @@ -514,23 +514,23 @@ nga_poll(void *priv) nga->cga.oddeven ^= 1; } } else { - nga->cga.sc++; - nga->cga.sc &= 31; - nga->cga.ma = nga->cga.maback; + nga->cga.scanline++; + nga->cga.scanline &= 31; + nga->cga.memaddr = nga->cga.memaddr_backup; } if (nga->cga.cgadispon) 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))) - nga->cga.con = 1; + if (nga->cga.scanline == (nga->cga.crtc[CGA_CRTC_CURSOR_START] & 31) || ((nga->cga.crtc[CGA_CRTC_INTERLACE] & 3) == 3 && nga->cga.scanline == ((nga->cga.crtc[CGA_CRTC_CURSOR_START] & 31) >> 1))) + nga->cga.cursorvisible = 1; } /* 80-columns */ - if (nga->cga.cgadispon && (nga->cga.cgamode & 1)) { + if (nga->cga.cgadispon && (nga->cga.cgamode & CGA_MODE_FLAG_HIGHRES)) { /* for each character per line */ - for (x = 0; x < (nga->cga.crtc[1] << 1); x++) - nga->cga.charbuffer[x] = nga->cga.vram[(((nga->cga.ma << 1) + x) & 0x3fff) + nga->base]; + for (x = 0; x < (nga->cga.crtc[CGA_CRTC_HDISP] << 1); x++) + nga->cga.charbuffer[x] = nga->cga.vram[(((nga->cga.memaddr << 1) + x) & 0x3fff) + nga->base]; } } } @@ -600,91 +600,67 @@ nga_init(UNUSED(const device_t *info)) const device_config_t nga_config[] = { // clang-format off { - .name = "rgb_type", - .description = "RGB type", - .type = CONFIG_SELECTION, - .default_int = 0, - .selection = { - { - .description = "Color", - .value = 0 - }, - { - .description = "Green Monochrome", - .value = 1 - }, - { - .description = "Amber Monochrome", - .value = 2 - }, - { - .description = "Gray Monochrome", - .value = 3 - }, - { - .description = "Color (no brown)", - .value = 4 - }, - { - .description = "" - } - } + .name = "rgb_type", + .description = "RGB type", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Color", .value = 0 }, + { .description = "Green Monochrome", .value = 1 }, + { .description = "Amber Monochrome", .value = 2 }, + { .description = "Gray Monochrome", .value = 3 }, + { .description = "Color (no brown)", .value = 4 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "snow_enabled", - .description = "Snow emulation", - .type = CONFIG_BINARY, - .default_int = 1 + .name = "snow_enabled", + .description = "Snow emulation", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 64, - .selection = { - { - .description = "32 KB", - .value = 32 - }, - { - .description = "64 KB", - .value = 64 - }, - { - .description = "" - } - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 64, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "32 KB", .value = 32 }, + { .description = "64 KB", .value = 64 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "charset", - .description = "Character set", - .type = CONFIG_SELECTION, - .default_int = 0, - .selection = { - { - .description = "U.S. English", - .value = 0 - }, - { - .description = "Scandinavian", - .value = 1 - }, - { - .description = "Other languages", - .value = 2 - }, - { - .description = "E.F. Hutton", - .value = 3 - }, - { - .description = "" - } - } + .name = "charset", + .description = "Character set", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "U.S. English", .value = 0 }, + { .description = "Scandinavian", .value = 1 }, + { .description = "Other languages", .value = 2 }, + { .description = "E.F. Hutton", .value = 3 }, + { .description = "" } + }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -696,7 +672,7 @@ const device_t nga_device = { .init = nga_init, .close = nga_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = nga_speed_changed, .force_redraw = NULL, .config = nga_config diff --git a/src/video/vid_ogc.c b/src/video/vid_cga_olivetti.c similarity index 71% rename from src/video/vid_ogc.c rename to src/video/vid_cga_olivetti.c index 9ac94169c..8be40ee2e 100644 --- a/src/video/vid_ogc.c +++ b/src/video/vid_cga_olivetti.c @@ -31,6 +31,7 @@ #include <86box/io.h> #include <86box/video.h> #include <86box/86box.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/mem.h> #include <86box/pit.h> @@ -64,12 +65,12 @@ ogc_recalctimings(ogc_t *ogc) double _dispofftime; double disptime; - if (ogc->cga.cgamode & 1) { - disptime = ogc->cga.crtc[0] + 1; - _dispontime = ogc->cga.crtc[1]; + if (ogc->cga.cgamode & CGA_MODE_FLAG_HIGHRES) { + disptime = ogc->cga.crtc[CGA_CRTC_HTOTAL] + 1; + _dispontime = ogc->cga.crtc[CGA_CRTC_HDISP]; } else { - disptime = (ogc->cga.crtc[0] + 1) << 1; - _dispontime = ogc->cga.crtc[1] << 1; + disptime = (ogc->cga.crtc[CGA_CRTC_HTOTAL] + 1) << 1; + _dispontime = ogc->cga.crtc[CGA_CRTC_HDISP] << 1; } _dispofftime = disptime - _dispontime; @@ -200,7 +201,7 @@ void ogc_poll(void *priv) { ogc_t *ogc = (ogc_t *) priv; - uint16_t ca = (ogc->cga.crtc[15] | (ogc->cga.crtc[14] << 8)) & 0x3fff; + uint16_t cursoraddr = (ogc->cga.crtc[CGA_CRTC_CURSOR_ADDR_LOW] | (ogc->cga.crtc[CGA_CRTC_CURSOR_ADDR_HIGH] << 8)) & 0x3fff; int drawcursor; int x; int c; @@ -212,14 +213,14 @@ ogc_poll(void *priv) uint16_t dat; uint16_t dat2; int cols[4]; - int oldsc; + int scanline_old; int blink = 0; int underline = 0; - // composito colore appare blu scuro + // Composite color appears dark blue /* graphic mode and not mode 40h */ - if (!(ogc->ctrl_3de & 0x1 || !(ogc->cga.cgamode & 2))) { + if (!(ogc->ctrl_3de & 0x1 || !(ogc->cga.cgamode & CGA_MODE_FLAG_GRAPHICS))) { /* standard cga mode */ cga_poll(&ogc->cga); return; @@ -229,9 +230,9 @@ ogc_poll(void *priv) timer_advance_u64(&ogc->cga.timer, ogc->cga.dispofftime); ogc->cga.cgastat |= 1; ogc->cga.linepos = 1; - oldsc = ogc->cga.sc; - if ((ogc->cga.crtc[8] & 3) == 3) - ogc->cga.sc = ((ogc->cga.sc << 1) + ogc->cga.oddeven) & 7; + scanline_old = ogc->cga.scanline; + if ((ogc->cga.crtc[CGA_CRTC_INTERLACE] & 3) == 3) + ogc->cga.scanline = ((ogc->cga.scanline << 1) + ogc->cga.oddeven) & 7; if (ogc->cga.cgadispon) { if (ogc->cga.displine < ogc->cga.firstline) { ogc->cga.firstline = ogc->cga.displine; @@ -239,11 +240,11 @@ ogc_poll(void *priv) } ogc->cga.lastline = ogc->cga.displine; /* 80-col */ - if (ogc->cga.cgamode & 1) { + if (ogc->cga.cgamode & CGA_MODE_FLAG_HIGHRES) { /* for each text column */ - for (x = 0; x < ogc->cga.crtc[1]; x++) { + for (x = 0; x < ogc->cga.crtc[CGA_CRTC_HDISP]; x++) { /* video output enabled */ - if (ogc->cga.cgamode & 8) { + if (ogc->cga.cgamode & CGA_MODE_FLAG_VIDEO_ENABLE) { /* character */ chr = ogc->cga.charbuffer[x << 1]; /* text attributes */ @@ -251,7 +252,7 @@ ogc_poll(void *priv) } else chr = attr = 0; /* check if cursor has to be drawn */ - drawcursor = ((ogc->cga.ma == ca) && ogc->cga.con && ogc->cga.cursoron); + drawcursor = ((ogc->cga.memaddr == cursoraddr) && ogc->cga.cursorvisible && ogc->cga.cursoron); /* check if character underline mode should be set */ underline = ((ogc->ctrl_3de & 0x40) && (attr & 0x1) && !(attr & 0x6)); if (underline) { @@ -262,7 +263,7 @@ ogc_poll(void *priv) /* set foreground */ cols[1] = (attr & 15) + 16; /* blink active */ - if (ogc->cga.cgamode & 0x20) { + if (ogc->cga.cgamode & CGA_MODE_FLAG_BLINK) { cols[0] = ((attr >> 4) & 7) + 16; /* attribute 7 active and not cursor */ if ((ogc->cga.cgablink & 8) && (attr & 0x80) && !ogc->cga.drawcursor) { @@ -276,31 +277,31 @@ ogc_poll(void *priv) blink = (attr & 0x80) * 8 + 7 + 16; } /* character underline active and 7th row of pixels in character height being drawn */ - if (underline && (ogc->cga.sc == 7)) { + if (underline && (ogc->cga.scanline == 7)) { /* for each pixel in character width */ for (c = 0; c < 8; c++) buffer32->line[ogc->cga.displine][(x << 3) + c + 8] = mdaattr[attr][blink][1]; } else if (drawcursor) { for (c = 0; c < 8; c++) - buffer32->line[ogc->cga.displine][(x << 3) + c + 8] = cols[(fontdatm[chr][((ogc->cga.sc & 7) << 1) | ogc->lineff] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; + buffer32->line[ogc->cga.displine][(x << 3) + c + 8] = cols[(fontdatm[chr][((ogc->cga.scanline & 7) << 1) | ogc->lineff] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; } else { for (c = 0; c < 8; c++) - buffer32->line[ogc->cga.displine][(x << 3) + c + 8] = cols[(fontdatm[chr][((ogc->cga.sc & 7) << 1) | ogc->lineff] & (1 << (c ^ 7))) ? 1 : 0]; + buffer32->line[ogc->cga.displine][(x << 3) + c + 8] = cols[(fontdatm[chr][((ogc->cga.scanline & 7) << 1) | ogc->lineff] & (1 << (c ^ 7))) ? 1 : 0]; } - ogc->cga.ma++; + ogc->cga.memaddr++; } } /* 40-col */ - else if (!(ogc->cga.cgamode & 2)) { - for (x = 0; x < ogc->cga.crtc[1]; x++) { - if (ogc->cga.cgamode & 8) { - chr = ogc->cga.vram[((ogc->cga.ma << 1) & 0x3fff) + ogc->base]; - attr = ogc->cga.vram[(((ogc->cga.ma << 1) + 1) & 0x3fff) + ogc->base]; + else if (!(ogc->cga.cgamode & CGA_MODE_FLAG_GRAPHICS)) { + for (x = 0; x < ogc->cga.crtc[CGA_CRTC_HDISP]; x++) { + if (ogc->cga.cgamode & CGA_MODE_FLAG_VIDEO_ENABLE) { + chr = ogc->cga.vram[((ogc->cga.memaddr << 1) & 0x3fff) + ogc->base]; + attr = ogc->cga.vram[(((ogc->cga.memaddr << 1) + 1) & 0x3fff) + ogc->base]; } else { chr = attr = 0; } - drawcursor = ((ogc->cga.ma == ca) && ogc->cga.con && ogc->cga.cursoron); + drawcursor = ((ogc->cga.memaddr == cursoraddr) && ogc->cga.cursorvisible && ogc->cga.cursoron); /* check if character underline mode should be set */ underline = ((ogc->ctrl_3de & 0x40) && (attr & 0x1) && !(attr & 0x6)); if (underline) { @@ -311,7 +312,7 @@ ogc_poll(void *priv) /* set foreground */ cols[1] = (attr & 15) + 16; /* blink active */ - if (ogc->cga.cgamode & 0x20) { + if (ogc->cga.cgamode & CGA_MODE_FLAG_BLINK) { cols[0] = ((attr >> 4) & 7) + 16; if ((ogc->cga.cgablink & 8) && (attr & 0x80) && !ogc->cga.drawcursor) { /* set blinking */ @@ -325,40 +326,40 @@ ogc_poll(void *priv) } /* character underline active and 7th row of pixels in character height being drawn */ - if (underline && (ogc->cga.sc == 7)) { + if (underline && (ogc->cga.scanline == 7)) { /* for each pixel in character width */ for (c = 0; c < 8; c++) buffer32->line[ogc->cga.displine][(x << 4) + (c << 1) + 8] = buffer32->line[ogc->cga.displine][(x << 4) + (c << 1) + 1 + 8] = mdaattr[attr][blink][1]; } else if (drawcursor) { for (c = 0; c < 8; c++) - buffer32->line[ogc->cga.displine][(x << 4) + (c << 1) + 8] = buffer32->line[ogc->cga.displine][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdatm[chr][((ogc->cga.sc & 7) << 1) | ogc->lineff] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; + buffer32->line[ogc->cga.displine][(x << 4) + (c << 1) + 8] = buffer32->line[ogc->cga.displine][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdatm[chr][((ogc->cga.scanline & 7) << 1) | ogc->lineff] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; } else { for (c = 0; c < 8; c++) - buffer32->line[ogc->cga.displine][(x << 4) + (c << 1) + 8] = buffer32->line[ogc->cga.displine][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdatm[chr][((ogc->cga.sc & 7) << 1) | ogc->lineff] & (1 << (c ^ 7))) ? 1 : 0]; + buffer32->line[ogc->cga.displine][(x << 4) + (c << 1) + 8] = buffer32->line[ogc->cga.displine][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdatm[chr][((ogc->cga.scanline & 7) << 1) | ogc->lineff] & (1 << (c ^ 7))) ? 1 : 0]; } - ogc->cga.ma++; + ogc->cga.memaddr++; } } else { /* 640x400 mode */ if (ogc->ctrl_3de & 1) { - dat2 = ((ogc->cga.sc & 1) * 0x4000) | (ogc->lineff * 0x2000); + dat2 = ((ogc->cga.scanline & 1) * 0x4000) | (ogc->lineff * 0x2000); cols[0] = 0; cols[1] = 15 + 16; } else { - dat2 = (ogc->cga.sc & 1) * 0x2000; + dat2 = (ogc->cga.scanline & 1) * 0x2000; cols[0] = 0; cols[1] = (ogc->cga.cgacol & 15) + 16; } - for (x = 0; x < ogc->cga.crtc[1]; x++) { + for (x = 0; x < ogc->cga.crtc[CGA_CRTC_HDISP]; x++) { /* video out */ - if (ogc->cga.cgamode & 8) { - dat = (ogc->cga.vram[((ogc->cga.ma << 1) & 0x1fff) + dat2] << 8) | ogc->cga.vram[((ogc->cga.ma << 1) & 0x1fff) + dat2 + 1]; + if (ogc->cga.cgamode & CGA_MODE_FLAG_VIDEO_ENABLE) { + dat = (ogc->cga.vram[((ogc->cga.memaddr << 1) & 0x1fff) + dat2] << 8) | ogc->cga.vram[((ogc->cga.memaddr << 1) & 0x1fff) + dat2 + 1]; } else { dat = 0; } - ogc->cga.ma++; + ogc->cga.memaddr++; for (c = 0; c < 16; c++) { buffer32->line[ogc->cga.displine][(x << 4) + c + 8] = cols[dat >> 15]; @@ -369,22 +370,22 @@ ogc_poll(void *priv) } else { /* ogc specific */ cols[0] = ((ogc->cga.cgamode & 0x12) == 0x12) ? 0 : (ogc->cga.cgacol & 15) + 16; - if (ogc->cga.cgamode & 1) - hline(buffer32, 0, ogc->cga.displine, ((ogc->cga.crtc[1] << 3) + 16) << 2, cols[0]); + if (ogc->cga.cgamode & CGA_MODE_FLAG_HIGHRES) + hline(buffer32, 0, ogc->cga.displine, ((ogc->cga.crtc[CGA_CRTC_HDISP] << 3) + 16) << 2, cols[0]); else - hline(buffer32, 0, ogc->cga.displine, ((ogc->cga.crtc[1] << 4) + 16) << 2, cols[0]); + hline(buffer32, 0, ogc->cga.displine, ((ogc->cga.crtc[CGA_CRTC_HDISP] << 4) + 16) << 2, cols[0]); } /* 80 columns */ - if (ogc->cga.cgamode & 1) - x = (ogc->cga.crtc[1] << 3) + 16; + if (ogc->cga.cgamode & CGA_MODE_FLAG_HIGHRES) + x = (ogc->cga.crtc[CGA_CRTC_HDISP] << 3) + 16; else - x = (ogc->cga.crtc[1] << 4) + 16; + x = (ogc->cga.crtc[CGA_CRTC_HDISP] << 4) + 16; video_process_8(x, ogc->cga.displine); - ogc->cga.sc = oldsc; - if (ogc->cga.vc == ogc->cga.crtc[7] && !ogc->cga.sc) + ogc->cga.scanline = scanline_old; + if (ogc->cga.vc == ogc->cga.crtc[CGA_CRTC_VSYNC] && !ogc->cga.scanline) ogc->cga.cgastat |= 8; ogc->cga.displine++; if (ogc->cga.displine >= 720) @@ -397,48 +398,47 @@ ogc_poll(void *priv) /* ogc specific */ ogc->lineff ^= 1; if (ogc->lineff) { - ogc->cga.ma = ogc->cga.maback; + ogc->cga.memaddr = ogc->cga.memaddr_backup; } else { if (ogc->cga.vsynctime) { ogc->cga.vsynctime--; if (!ogc->cga.vsynctime) ogc->cga.cgastat &= ~8; } - if (ogc->cga.sc == (ogc->cga.crtc[11] & 31) || ((ogc->cga.crtc[8] & 3) == 3 && ogc->cga.sc == ((ogc->cga.crtc[11] & 31) >> 1))) { - ogc->cga.con = 0; - ogc->cga.coff = 1; + if (ogc->cga.scanline == (ogc->cga.crtc[CGA_CRTC_CURSOR_END] & 31) || ((ogc->cga.crtc[CGA_CRTC_INTERLACE] & 3) == 3 && ogc->cga.scanline == ((ogc->cga.crtc[CGA_CRTC_CURSOR_END] & 31) >> 1))) { + ogc->cga.cursorvisible = 0; } - if ((ogc->cga.crtc[8] & 3) == 3 && ogc->cga.sc == (ogc->cga.crtc[9] >> 1)) - ogc->cga.maback = ogc->cga.ma; + if ((ogc->cga.crtc[CGA_CRTC_INTERLACE] & 3) == 3 && ogc->cga.scanline == (ogc->cga.crtc[CGA_CRTC_MAX_SCANLINE_ADDR] >> 1)) + ogc->cga.memaddr_backup = ogc->cga.memaddr; if (ogc->cga.vadj) { - ogc->cga.sc++; - ogc->cga.sc &= 31; - ogc->cga.ma = ogc->cga.maback; + ogc->cga.scanline++; + ogc->cga.scanline &= 31; + ogc->cga.memaddr = ogc->cga.memaddr_backup; ogc->cga.vadj--; if (!ogc->cga.vadj) { ogc->cga.cgadispon = 1; - ogc->cga.ma = ogc->cga.maback = (ogc->cga.crtc[13] | (ogc->cga.crtc[12] << 8)) & 0x3fff; - ogc->cga.sc = 0; + ogc->cga.memaddr = ogc->cga.memaddr_backup = (ogc->cga.crtc[CGA_CRTC_START_ADDR_LOW] | (ogc->cga.crtc[CGA_CRTC_START_ADDR_HIGH] << 8)) & 0x3fff; + ogc->cga.scanline = 0; } - // potrebbe dare problemi con composito - } else if (ogc->cga.sc == ogc->cga.crtc[9] || ((ogc->cga.crtc[8] & 3) == 3 && ogc->cga.sc == (ogc->cga.crtc[9] >> 1))) { - ogc->cga.maback = ogc->cga.ma; - ogc->cga.sc = 0; + // may cause problems with composite + } else if (ogc->cga.scanline == ogc->cga.crtc[CGA_CRTC_MAX_SCANLINE_ADDR] || ((ogc->cga.crtc[CGA_CRTC_INTERLACE] & 3) == 3 && ogc->cga.scanline == (ogc->cga.crtc[CGA_CRTC_MAX_SCANLINE_ADDR] >> 1))) { + ogc->cga.memaddr_backup = ogc->cga.memaddr; + ogc->cga.scanline = 0; oldvc = ogc->cga.vc; ogc->cga.vc++; ogc->cga.vc &= 127; - if (ogc->cga.vc == ogc->cga.crtc[6]) + if (ogc->cga.vc == ogc->cga.crtc[CGA_CRTC_VDISP]) ogc->cga.cgadispon = 0; - if (oldvc == ogc->cga.crtc[4]) { + if (oldvc == ogc->cga.crtc[CGA_CRTC_VTOTAL]) { ogc->cga.vc = 0; - ogc->cga.vadj = ogc->cga.crtc[5]; + ogc->cga.vadj = ogc->cga.crtc[CGA_CRTC_VTOTAL_ADJUST]; if (!ogc->cga.vadj) { ogc->cga.cgadispon = 1; - ogc->cga.ma = ogc->cga.maback = (ogc->cga.crtc[13] | (ogc->cga.crtc[12] << 8)) & 0x3fff; + ogc->cga.memaddr = ogc->cga.memaddr_backup = (ogc->cga.crtc[CGA_CRTC_START_ADDR_LOW] | (ogc->cga.crtc[CGA_CRTC_START_ADDR_HIGH] << 8)) & 0x3fff; } - switch (ogc->cga.crtc[10] & 0x60) { + switch (ogc->cga.crtc[CGA_CRTC_CURSOR_START] & 0x60) { case 0x20: ogc->cga.cursoron = 0; break; @@ -450,16 +450,16 @@ ogc_poll(void *priv) break; } } - if (ogc->cga.vc == ogc->cga.crtc[7]) { + if (ogc->cga.vc == ogc->cga.crtc[CGA_CRTC_VSYNC]) { ogc->cga.cgadispon = 0; ogc->cga.displine = 0; /* ogc specific */ - ogc->cga.vsynctime = (ogc->cga.crtc[3] >> 4) + 1; - if (ogc->cga.crtc[7]) { - if (ogc->cga.cgamode & 1) - x = (ogc->cga.crtc[1] << 3) + 16; + ogc->cga.vsynctime = (ogc->cga.crtc[CGA_CRTC_HSYNC_WIDTH] >> 4) + 1; + if (ogc->cga.crtc[CGA_CRTC_VSYNC]) { + if (ogc->cga.cgamode & CGA_MODE_FLAG_HIGHRES) + x = (ogc->cga.crtc[CGA_CRTC_HDISP] << 3) + 16; else - x = (ogc->cga.crtc[1] << 4) + 16; + x = (ogc->cga.crtc[CGA_CRTC_HDISP] << 4) + 16; ogc->cga.lastline++; xs_temp = x; @@ -474,7 +474,7 @@ ogc_poll(void *priv) if (!enable_overscan) xs_temp -= 16; - if ((ogc->cga.cgamode & 8) && ((xs_temp != xsize) || (ys_temp != ysize) || video_force_resize_get())) { + if ((ogc->cga.cgamode & CGA_MODE_FLAG_VIDEO_ENABLE) && ((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)); @@ -496,14 +496,14 @@ ogc_poll(void *priv) video_res_x = xsize; video_res_y = ysize; /* 80-col */ - if (ogc->cga.cgamode & 1) { + if (ogc->cga.cgamode & CGA_MODE_FLAG_HIGHRES) { video_res_x /= 8; - video_res_y /= (ogc->cga.crtc[9] + 1) * 2; + video_res_y /= (ogc->cga.crtc[CGA_CRTC_MAX_SCANLINE_ADDR] + 1) * 2; video_bpp = 0; /* 40-col */ - } else if (!(ogc->cga.cgamode & 2)) { + } else if (!(ogc->cga.cgamode & CGA_MODE_FLAG_GRAPHICS)) { video_res_x /= 16; - video_res_y /= (ogc->cga.crtc[9] + 1) * 2; + video_res_y /= (ogc->cga.crtc[CGA_CRTC_MAX_SCANLINE_ADDR] + 1) * 2; video_bpp = 0; } else if (!(ogc->ctrl_3de & 1)) { video_res_y /= 2; @@ -516,21 +516,21 @@ ogc_poll(void *priv) ogc->cga.oddeven ^= 1; } } else { - ogc->cga.sc++; - ogc->cga.sc &= 31; - ogc->cga.ma = ogc->cga.maback; + ogc->cga.scanline++; + ogc->cga.scanline &= 31; + ogc->cga.memaddr = ogc->cga.memaddr_backup; } if (ogc->cga.cgadispon) ogc->cga.cgastat &= ~1; - if (ogc->cga.sc == (ogc->cga.crtc[10] & 31) || ((ogc->cga.crtc[8] & 3) == 3 && ogc->cga.sc == ((ogc->cga.crtc[10] & 31) >> 1))) - ogc->cga.con = 1; + if (ogc->cga.scanline == (ogc->cga.crtc[CGA_CRTC_CURSOR_START] & 31) || ((ogc->cga.crtc[CGA_CRTC_INTERLACE] & 3) == 3 && ogc->cga.scanline == ((ogc->cga.crtc[CGA_CRTC_CURSOR_START] & 31) >> 1))) + ogc->cga.cursorvisible = 1; } /* 80-columns */ - if (ogc->cga.cgadispon && (ogc->cga.cgamode & 1)) { - for (x = 0; x < (ogc->cga.crtc[1] << 1); x++) - ogc->cga.charbuffer[x] = ogc->cga.vram[(((ogc->cga.ma << 1) + x) & 0x3fff) + ogc->base]; + if (ogc->cga.cgadispon && (ogc->cga.cgamode & CGA_MODE_FLAG_HIGHRES)) { + for (x = 0; x < (ogc->cga.crtc[CGA_CRTC_HDISP] << 1); x++) + ogc->cga.charbuffer[x] = ogc->cga.vram[(((ogc->cga.memaddr << 1) + x) & 0x3fff) + ogc->base]; } } } @@ -634,41 +634,34 @@ const device_config_t ogc_m24_config[] = { // clang-format off { /* Olivetti / ATT compatible displays */ - .name = "rgb_type", - .description = "RGB type", - .type = CONFIG_SELECTION, - .default_int = CGA_RGB, - .selection = { - { - .description = "Color", - .value = 0 - }, - { - .description = "Green Monochrome", - .value = 1 - }, - { - .description = "Amber Monochrome", - .value = 2 - }, - { - .description = "Gray Monochrome", - .value = 3 - }, - { - .description = "" - } - } + .name = "rgb_type", + .description = "RGB type", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = CGA_RGB, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Color", .value = 0 }, + { .description = "Green Monochrome", .value = 1 }, + { .description = "Amber Monochrome", .value = 2 }, + { .description = "Gray Monochrome", .value = 3 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "snow_enabled", - .description = "Snow emulation", - .type = CONFIG_BINARY, - .default_int = 1, + .name = "snow_enabled", + .description = "Snow emulation", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -680,7 +673,7 @@ const device_t ogc_m24_device = { .init = ogc_init, .close = ogc_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = ogc_speed_changed, .force_redraw = NULL, .config = ogc_m24_config @@ -694,7 +687,7 @@ const device_t ogc_device = { .init = ogc_init, .close = ogc_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = ogc_speed_changed, .force_redraw = NULL, .config = cga_config diff --git a/src/machine/m_xt_t1000_vid.c b/src/video/vid_cga_toshiba_t1000.c similarity index 87% rename from src/machine/m_xt_t1000_vid.c rename to src/video/vid_cga_toshiba_t1000.c index 4ec13b5c4..2fd382272 100644 --- a/src/machine/m_xt_t1000_vid.c +++ b/src/video/vid_cga_toshiba_t1000.c @@ -245,25 +245,25 @@ t1000_text_row80(t1000_t *t1000) int bold; int blink; uint16_t addr; - uint8_t sc; - uint16_t ma = (t1000->cga.crtc[13] | (t1000->cga.crtc[12] << 8)) & 0x3fff; - uint16_t ca = (t1000->cga.crtc[15] | (t1000->cga.crtc[14] << 8)) & 0x3fff; + uint8_t scanline; + uint16_t memaddr = (t1000->cga.crtc[CGA_CRTC_START_ADDR_LOW] | (t1000->cga.crtc[CGA_CRTC_START_ADDR_HIGH] << 8)) & 0x3fff; + uint16_t cursoraddr = (t1000->cga.crtc[CGA_CRTC_CURSOR_ADDR_LOW] | (t1000->cga.crtc[CGA_CRTC_CURSOR_ADDR_HIGH] << 8)) & 0x3fff; - sc = (t1000->displine) & 7; - addr = ((ma & ~1) + (t1000->displine >> 3) * 80) * 2; - ma += (t1000->displine >> 3) * 80; + scanline = (t1000->displine) & 7; + addr = ((memaddr & ~1) + (t1000->displine >> 3) * 80) * 2; + memaddr += (t1000->displine >> 3) * 80; - if ((t1000->cga.crtc[10] & 0x60) == 0x20) { + if ((t1000->cga.crtc[CGA_CRTC_CURSOR_START] & 0x60) == 0x20) { cursorline = 0; } else { - cursorline = ((t1000->cga.crtc[10] & 0x0F) <= sc) && ((t1000->cga.crtc[11] & 0x0F) >= sc); + cursorline = ((t1000->cga.crtc[CGA_CRTC_CURSOR_START] & 0x0F) <= scanline) && ((t1000->cga.crtc[CGA_CRTC_CURSOR_END] & 0x0F) >= scanline); } 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)); + drawcursor = ((memaddr == cursoraddr) && cursorline && (t1000->cga.cgamode & CGA_MODE_FLAG_VIDEO_ENABLE) && (t1000->cga.cgablink & 16)); - blink = ((t1000->cga.cgablink & 16) && (t1000->cga.cgamode & 0x20) && (attr & 0x80) && !drawcursor); + blink = ((t1000->cga.cgablink & 16) && (t1000->cga.cgamode & CGA_MODE_FLAG_BLINK) && (attr & 0x80) && !drawcursor); if (t1000->video_options & 1) bold = boldcols[attr] ? chr : chr + 256; @@ -272,7 +272,7 @@ t1000_text_row80(t1000_t *t1000) if (t1000->video_options & 2) bold += 512; - if (t1000->cga.cgamode & 0x20) /* Blink */ + if (t1000->cga.cgamode & CGA_MODE_FLAG_BLINK) /* Blink */ { cols[1] = blinkcols[attr][1]; cols[0] = blinkcols[attr][0]; @@ -284,13 +284,13 @@ t1000_text_row80(t1000_t *t1000) } if (drawcursor) { 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); + (buffer32->line[t1000->displine])[(x << 3) + c] = cols[(fontdat[bold][scanline] & (1 << (c ^ 7))) ? 1 : 0] ^ (blue ^ grey); } } else { for (uint8_t c = 0; c < 8; c++) - (buffer32->line[t1000->displine])[(x << 3) + c] = cols[(fontdat[bold][sc] & (1 << (c ^ 7))) ? 1 : 0]; + (buffer32->line[t1000->displine])[(x << 3) + c] = cols[(fontdat[bold][scanline] & (1 << (c ^ 7))) ? 1 : 0]; } - ++ma; + ++memaddr; } } @@ -306,25 +306,25 @@ t1000_text_row40(t1000_t *t1000) int bold; int blink; uint16_t addr; - uint8_t sc; - uint16_t ma = (t1000->cga.crtc[13] | (t1000->cga.crtc[12] << 8)) & 0x3fff; - uint16_t ca = (t1000->cga.crtc[15] | (t1000->cga.crtc[14] << 8)) & 0x3fff; + uint8_t scanline; + uint16_t memaddr = (t1000->cga.crtc[CGA_CRTC_START_ADDR_LOW] | (t1000->cga.crtc[CGA_CRTC_START_ADDR_HIGH] << 8)) & 0x3fff; + uint16_t cursoraddr = (t1000->cga.crtc[CGA_CRTC_CURSOR_ADDR_LOW] | (t1000->cga.crtc[CGA_CRTC_CURSOR_ADDR_HIGH] << 8)) & 0x3fff; - sc = (t1000->displine) & 7; - addr = ((ma & ~1) + (t1000->displine >> 3) * 40) * 2; - ma += (t1000->displine >> 3) * 40; + scanline = (t1000->displine) & 7; + addr = ((memaddr & ~1) + (t1000->displine >> 3) * 40) * 2; + memaddr += (t1000->displine >> 3) * 40; - if ((t1000->cga.crtc[10] & 0x60) == 0x20) { + if ((t1000->cga.crtc[CGA_CRTC_CURSOR_START] & 0x60) == 0x20) { cursorline = 0; } else { - cursorline = ((t1000->cga.crtc[10] & 0x0F) <= sc) && ((t1000->cga.crtc[11] & 0x0F) >= sc); + cursorline = ((t1000->cga.crtc[CGA_CRTC_CURSOR_START] & 0x0F) <= scanline) && ((t1000->cga.crtc[CGA_CRTC_CURSOR_END] & 0x0F) >= scanline); } 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)); + drawcursor = ((memaddr == cursoraddr) && cursorline && (t1000->cga.cgamode & CGA_MODE_FLAG_VIDEO_ENABLE) && (t1000->cga.cgablink & 16)); - blink = ((t1000->cga.cgablink & 16) && (t1000->cga.cgamode & 0x20) && (attr & 0x80) && !drawcursor); + blink = ((t1000->cga.cgablink & 16) && (t1000->cga.cgamode & CGA_MODE_FLAG_BLINK) && (attr & 0x80) && !drawcursor); if (t1000->video_options & 1) bold = boldcols[attr] ? chr : chr + 256; @@ -333,7 +333,7 @@ t1000_text_row40(t1000_t *t1000) if (t1000->video_options & 2) bold += 512; - if (t1000->cga.cgamode & 0x20) /* Blink */ + if (t1000->cga.cgamode & CGA_MODE_FLAG_BLINK) /* Blink */ { cols[1] = blinkcols[attr][1]; cols[0] = blinkcols[attr][0]; @@ -345,14 +345,14 @@ t1000_text_row40(t1000_t *t1000) } if (drawcursor) { 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); + (buffer32->line[t1000->displine])[(x << 4) + c * 2] = (buffer32->line[t1000->displine])[(x << 4) + c * 2 + 1] = cols[(fontdat[bold][scanline] & (1 << (c ^ 7))) ? 1 : 0] ^ (blue ^ grey); } } else { 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]; + (buffer32->line[t1000->displine])[(x << 4) + c * 2] = (buffer32->line[t1000->displine])[(x << 4) + c * 2 + 1] = cols[(fontdat[bold][scanline] & (1 << (c ^ 7))) ? 1 : 0]; } } - ++ma; + ++memaddr; } } @@ -366,9 +366,9 @@ t1000_cgaline6(t1000_t *t1000) uint32_t fg = (t1000->cga.cgacol & 0x0F) ? blue : grey; uint32_t bg = grey; - uint16_t ma = (t1000->cga.crtc[13] | (t1000->cga.crtc[12] << 8)) & 0x3fff; + uint16_t memaddr = (t1000->cga.crtc[CGA_CRTC_START_ADDR_LOW] | (t1000->cga.crtc[CGA_CRTC_START_ADDR_HIGH] << 8)) & 0x3fff; - addr = ((t1000->displine) & 1) * 0x2000 + (t1000->displine >> 1) * 80 + ((ma & ~1) << 1); + addr = ((t1000->displine) & 1) * 0x2000 + (t1000->displine >> 1) * 80 + ((memaddr & ~1) << 1); for (uint8_t x = 0; x < 80; x++) { dat = t1000->vram[addr & 0x3FFF]; @@ -376,7 +376,7 @@ t1000_cgaline6(t1000_t *t1000) for (uint8_t c = 0; c < 8; c++) { ink = (dat & 0x80) ? fg : bg; - if (!(t1000->cga.cgamode & 8)) + if (!(t1000->cga.cgamode & CGA_MODE_FLAG_VIDEO_ENABLE)) ink = grey; (buffer32->line[t1000->displine])[x * 8 + c] = ink; dat = dat << 1; @@ -395,8 +395,8 @@ t1000_cgaline4(t1000_t *t1000) 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); + uint16_t memaddr = (t1000->cga.crtc[CGA_CRTC_START_ADDR_LOW] | (t1000->cga.crtc[CGA_CRTC_START_ADDR_HIGH] << 8)) & 0x3fff; + addr = ((t1000->displine) & 1) * 0x2000 + (t1000->displine >> 1) * 80 + ((memaddr & ~1) << 1); for (uint8_t x = 0; x < 80; x++) { dat = t1000->vram[addr & 0x3FFF]; @@ -404,7 +404,7 @@ t1000_cgaline4(t1000_t *t1000) for (uint8_t c = 0; c < 4; c++) { pattern = (dat & 0xC0) >> 6; - if (!(t1000->cga.cgamode & 8)) + if (!(t1000->cga.cgamode & CGA_MODE_FLAG_VIDEO_ENABLE)) pattern = 0; switch (pattern & 3) { @@ -479,7 +479,7 @@ t1000_poll(void *priv) /* Graphics */ if (t1000->cga.cgamode & 0x02) { - if (t1000->cga.cgamode & 0x10) + if (t1000->cga.cgamode & CGA_MODE_FLAG_HIGHRES_GRAPHICS) t1000_cgaline6(t1000); else t1000_cgaline4(t1000); @@ -532,7 +532,7 @@ t1000_poll(void *priv) video_res_y = T1000_YSIZE; if (t1000->cga.cgamode & 0x02) { - if (t1000->cga.cgamode & 0x10) + if (t1000->cga.cgamode & CGA_MODE_FLAG_HIGHRES_GRAPHICS) video_bpp = 1; else video_bpp = 2; @@ -651,8 +651,7 @@ t1000_recalcattrs(t1000_t *t1000) static void * t1000_init(UNUSED(const device_t *info)) { - t1000_t *t1000 = malloc(sizeof(t1000_t)); - memset(t1000, 0, sizeof(t1000_t)); + t1000_t *t1000 = calloc(1, sizeof(t1000_t)); loadfont("roms/machines/t1000/t1000font.bin", 8); cga_init(&t1000->cga); video_inform(VIDEO_FLAG_TYPE_CGA, &timing_t1000); @@ -741,7 +740,7 @@ const device_t t1000_video_device = { .init = t1000_init, .close = t1000_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = t1000_speed_changed, .force_redraw = NULL, .config = t1000_config @@ -755,7 +754,7 @@ const device_t t1200_video_device = { .init = t1000_init, .close = t1000_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = t1000_speed_changed, .force_redraw = NULL, .config = t1000_config diff --git a/src/machine/m_at_t3100e_vid.c b/src/video/vid_cga_toshiba_t3100e.c similarity index 84% rename from src/machine/m_at_t3100e_vid.c rename to src/video/vid_cga_toshiba_t3100e.c index 50c9ec05a..e3eb673c8 100644 --- a/src/machine/m_at_t3100e_vid.c +++ b/src/video/vid_cga_toshiba_t3100e.c @@ -169,8 +169,8 @@ t3100e_out(uint16_t addr, uint8_t val, void *priv) t3100e_recalctimings(t3100e); return; - case 0x3D8: /* CGA control register */ - case 0x3D9: /* CGA colour register */ + case CGA_REGISTER_MODE_CONTROL: /* CGA control register */ + case CGA_REGISTER_COLOR_SELECT: /* CGA colour register */ cga_out(addr, val, &t3100e->cga); return; @@ -254,25 +254,25 @@ t3100e_text_row80(t3100e_t *t3100e) int bold; int blink; uint16_t addr; - uint8_t sc; - uint16_t ma = (t3100e->cga.crtc[13] | (t3100e->cga.crtc[12] << 8)) & 0x7fff; - uint16_t ca = (t3100e->cga.crtc[15] | (t3100e->cga.crtc[14] << 8)) & 0x7fff; + uint8_t scanline; + uint16_t memaddr = (t3100e->cga.crtc[CGA_CRTC_START_ADDR_LOW] | (t3100e->cga.crtc[CGA_CRTC_START_ADDR_HIGH] << 8)) & 0x7fff; + uint16_t cursoraddr = (t3100e->cga.crtc[CGA_CRTC_CURSOR_ADDR_LOW] | (t3100e->cga.crtc[CGA_CRTC_CURSOR_ADDR_HIGH] << 8)) & 0x7fff; - sc = (t3100e->displine) & 15; - addr = ((ma & ~1) + (t3100e->displine >> 4) * 80) * 2; - ma += (t3100e->displine >> 4) * 80; + scanline = (t3100e->displine) & 15; + addr = ((memaddr & ~1) + (t3100e->displine >> 4) * 80) * 2; + memaddr += (t3100e->displine >> 4) * 80; - if ((t3100e->cga.crtc[10] & 0x60) == 0x20) { + if ((t3100e->cga.crtc[CGA_CRTC_CURSOR_START] & 0x60) == 0x20) { cursorline = 0; } else { - cursorline = ((t3100e->cga.crtc[10] & 0x0F) * 2 <= sc) && ((t3100e->cga.crtc[11] & 0x0F) * 2 >= sc); + cursorline = ((t3100e->cga.crtc[CGA_CRTC_CURSOR_START] & 0x0F) * 2 <= scanline) && ((t3100e->cga.crtc[CGA_CRTC_CURSOR_END] & 0x0F) * 2 >= scanline); } 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)); + drawcursor = ((memaddr == cursoraddr) && cursorline && (t3100e->cga.cgamode & CGA_MODE_FLAG_VIDEO_ENABLE) && (t3100e->cga.cgablink & 16)); - blink = ((t3100e->cga.cgablink & 16) && (t3100e->cga.cgamode & 0x20) && (attr & 0x80) && !drawcursor); + blink = ((t3100e->cga.cgablink & 16) && (t3100e->cga.cgamode & CGA_MODE_FLAG_BLINK) && (attr & 0x80) && !drawcursor); if (t3100e->video_options & 4) bold = boldcols[attr] ? chr + 256 : chr; @@ -280,7 +280,7 @@ t3100e_text_row80(t3100e_t *t3100e) bold = boldcols[attr] ? chr : chr + 256; bold += 512 * (t3100e->video_options & 3); - if (t3100e->cga.cgamode & 0x20) /* Blink */ + if (t3100e->cga.cgamode & CGA_MODE_FLAG_BLINK) /* Blink */ { cols[1] = blinkcols[attr][1]; cols[0] = blinkcols[attr][0]; @@ -292,13 +292,13 @@ t3100e_text_row80(t3100e_t *t3100e) } if (drawcursor) { 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); + (buffer32->line[t3100e->displine])[(x << 3) + c] = cols[(fontdatm[bold][scanline] & (1 << (c ^ 7))) ? 1 : 0] ^ (amber ^ black); } } else { for (uint8_t c = 0; c < 8; c++) - (buffer32->line[t3100e->displine])[(x << 3) + c] = cols[(fontdatm[bold][sc] & (1 << (c ^ 7))) ? 1 : 0]; + (buffer32->line[t3100e->displine])[(x << 3) + c] = cols[(fontdatm[bold][scanline] & (1 << (c ^ 7))) ? 1 : 0]; } - ++ma; + ++memaddr; } } @@ -315,25 +315,25 @@ t3100e_text_row40(t3100e_t *t3100e) int bold; int blink; uint16_t addr; - uint8_t sc; - uint16_t ma = (t3100e->cga.crtc[13] | (t3100e->cga.crtc[12] << 8)) & 0x7fff; - uint16_t ca = (t3100e->cga.crtc[15] | (t3100e->cga.crtc[14] << 8)) & 0x7fff; + uint8_t scanline; + uint16_t memaddr = (t3100e->cga.crtc[CGA_CRTC_START_ADDR_LOW] | (t3100e->cga.crtc[CGA_CRTC_START_ADDR_HIGH] << 8)) & 0x7fff; + uint16_t cursoraddr = (t3100e->cga.crtc[CGA_CRTC_CURSOR_ADDR_LOW] | (t3100e->cga.crtc[CGA_CRTC_CURSOR_ADDR_HIGH] << 8)) & 0x7fff; - sc = (t3100e->displine) & 15; - addr = ((ma & ~1) + (t3100e->displine >> 4) * 40) * 2; - ma += (t3100e->displine >> 4) * 40; + scanline = (t3100e->displine) & 15; + addr = ((memaddr & ~1) + (t3100e->displine >> 4) * 40) * 2; + memaddr += (t3100e->displine >> 4) * 40; - if ((t3100e->cga.crtc[10] & 0x60) == 0x20) { + if ((t3100e->cga.crtc[CGA_CRTC_CURSOR_START] & 0x60) == 0x20) { cursorline = 0; } else { - cursorline = ((t3100e->cga.crtc[10] & 0x0F) * 2 <= sc) && ((t3100e->cga.crtc[11] & 0x0F) * 2 >= sc); + cursorline = ((t3100e->cga.crtc[CGA_CRTC_CURSOR_START] & 0x0F) * 2 <= scanline) && ((t3100e->cga.crtc[CGA_CRTC_CURSOR_END] & 0x0F) * 2 >= scanline); } 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)); + drawcursor = ((memaddr == cursoraddr) && cursorline && (t3100e->cga.cgamode & CGA_MODE_FLAG_VIDEO_ENABLE) && (t3100e->cga.cgablink & 16)); - blink = ((t3100e->cga.cgablink & 16) && (t3100e->cga.cgamode & 0x20) && (attr & 0x80) && !drawcursor); + blink = ((t3100e->cga.cgablink & 16) && (t3100e->cga.cgamode & CGA_MODE_FLAG_BLINK) && (attr & 0x80) && !drawcursor); if (t3100e->video_options & 4) bold = boldcols[attr] ? chr + 256 : chr; @@ -341,7 +341,7 @@ t3100e_text_row40(t3100e_t *t3100e) bold = boldcols[attr] ? chr : chr + 256; bold += 512 * (t3100e->video_options & 3); - if (t3100e->cga.cgamode & 0x20) /* Blink */ + if (t3100e->cga.cgamode & CGA_MODE_FLAG_BLINK) /* Blink */ { cols[1] = blinkcols[attr][1]; cols[0] = blinkcols[attr][0]; @@ -353,14 +353,14 @@ t3100e_text_row40(t3100e_t *t3100e) } if (drawcursor) { for (c = 0; c < 8; c++) { - (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); + (buffer32->line[t3100e->displine])[(x << 4) + c * 2] = (buffer32->line[t3100e->displine])[(x << 4) + c * 2 + 1] = cols[(fontdatm[bold][scanline] & (1 << (c ^ 7))) ? 1 : 0] ^ (amber ^ black); } } else { for (c = 0; c < 8; c++) { - (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]; + (buffer32->line[t3100e->displine])[(x << 4) + c * 2] = (buffer32->line[t3100e->displine])[(x << 4) + c * 2 + 1] = cols[(fontdatm[bold][scanline] & (1 << (c ^ 7))) ? 1 : 0]; } } - ++ma; + ++memaddr; } } @@ -374,13 +374,13 @@ t3100e_cgaline6(t3100e_t *t3100e) uint32_t fg = (t3100e->cga.cgacol & 0x0F) ? amber : black; uint32_t bg = black; - uint16_t ma = (t3100e->cga.crtc[13] | (t3100e->cga.crtc[12] << 8)) & 0x7fff; + uint16_t memaddr = (t3100e->cga.crtc[CGA_CRTC_START_ADDR_LOW] | (t3100e->cga.crtc[CGA_CRTC_START_ADDR_HIGH] << 8)) & 0x7fff; - if (t3100e->cga.crtc[9] == 3) /* 640*400 */ + if (t3100e->cga.crtc[CGA_CRTC_MAX_SCANLINE_ADDR] == 3) /* 640*400 */ { - addr = ((t3100e->displine) & 1) * 0x2000 + ((t3100e->displine >> 1) & 1) * 0x4000 + (t3100e->displine >> 2) * 80 + ((ma & ~1) << 1); + addr = ((t3100e->displine) & 1) * 0x2000 + ((t3100e->displine >> 1) & 1) * 0x4000 + (t3100e->displine >> 2) * 80 + ((memaddr & ~1) << 1); } else { - addr = ((t3100e->displine >> 1) & 1) * 0x2000 + (t3100e->displine >> 2) * 80 + ((ma & ~1) << 1); + addr = ((t3100e->displine >> 1) & 1) * 0x2000 + (t3100e->displine >> 2) * 80 + ((memaddr & ~1) << 1); } for (uint8_t x = 0; x < 80; x++) { dat = t3100e->vram[addr & 0x7FFF]; @@ -388,7 +388,7 @@ t3100e_cgaline6(t3100e_t *t3100e) for (uint8_t c = 0; c < 8; c++) { ink = (dat & 0x80) ? fg : bg; - if (!(t3100e->cga.cgamode & 8)) + if (!(t3100e->cga.cgamode & CGA_MODE_FLAG_VIDEO_ENABLE)) ink = black; (buffer32->line[t3100e->displine])[x * 8 + c] = ink; dat = dat << 1; @@ -407,13 +407,13 @@ t3100e_cgaline4(t3100e_t *t3100e) uint32_t ink1 = 0; uint16_t addr; - uint16_t ma = (t3100e->cga.crtc[13] | (t3100e->cga.crtc[12] << 8)) & 0x7fff; - if (t3100e->cga.crtc[9] == 3) /* 320*400 undocumented */ + uint16_t memaddr = (t3100e->cga.crtc[CGA_CRTC_START_ADDR_LOW] | (t3100e->cga.crtc[CGA_CRTC_START_ADDR_HIGH] << 8)) & 0x7fff; + if (t3100e->cga.crtc[CGA_CRTC_MAX_SCANLINE_ADDR] == 3) /* 320*400 undocumented */ { - addr = ((t3100e->displine) & 1) * 0x2000 + ((t3100e->displine >> 1) & 1) * 0x4000 + (t3100e->displine >> 2) * 80 + ((ma & ~1) << 1); + addr = ((t3100e->displine) & 1) * 0x2000 + ((t3100e->displine >> 1) & 1) * 0x4000 + (t3100e->displine >> 2) * 80 + ((memaddr & ~1) << 1); } else /* 320*200 */ { - addr = ((t3100e->displine >> 1) & 1) * 0x2000 + (t3100e->displine >> 2) * 80 + ((ma & ~1) << 1); + addr = ((t3100e->displine >> 1) & 1) * 0x2000 + (t3100e->displine >> 2) * 80 + ((memaddr & ~1) << 1); } for (uint8_t x = 0; x < 80; x++) { dat = t3100e->vram[addr & 0x7FFF]; @@ -421,7 +421,7 @@ t3100e_cgaline4(t3100e_t *t3100e) for (uint8_t c = 0; c < 4; c++) { pattern = (dat & 0xC0) >> 6; - if (!(t3100e->cga.cgamode & 8)) + if (!(t3100e->cga.cgamode & CGA_MODE_FLAG_VIDEO_ENABLE)) pattern = 0; switch (pattern & 3) { @@ -497,12 +497,12 @@ t3100e_poll(void *priv) } /* Graphics */ - if (t3100e->cga.cgamode & 0x02) { - if (t3100e->cga.cgamode & 0x10) + if (t3100e->cga.cgamode & CGA_MODE_FLAG_GRAPHICS) { + if (t3100e->cga.cgamode & CGA_MODE_FLAG_HIGHRES_GRAPHICS) t3100e_cgaline6(t3100e); else t3100e_cgaline4(t3100e); - } else if (t3100e->cga.cgamode & 0x01) /* High-res text */ + } else if (t3100e->cga.cgamode & CGA_MODE_FLAG_HIGHRES) /* High-res text */ { t3100e_text_row80(t3100e); } else { @@ -550,8 +550,8 @@ t3100e_poll(void *priv) video_res_x = T3100E_XSIZE; video_res_y = T3100E_YSIZE; - if (t3100e->cga.cgamode & 0x02) { - if (t3100e->cga.cgamode & 0x10) + if (t3100e->cga.cgamode & CGA_MODE_FLAG_GRAPHICS) { + if (t3100e->cga.cgamode & CGA_MODE_FLAG_HIGHRES_GRAPHICS) video_bpp = 1; else video_bpp = 2; @@ -655,8 +655,7 @@ t3100e_recalcattrs(t3100e_t *t3100e) void * t3100e_init(UNUSED(const device_t *info)) { - t3100e_t *t3100e = malloc(sizeof(t3100e_t)); - memset(t3100e, 0, sizeof(t3100e_t)); + t3100e_t *t3100e = calloc(1, sizeof(t3100e_t)); loadfont("roms/machines/t3100e/t3100e_font.bin", 5); cga_init(&t3100e->cga); video_inform(VIDEO_FLAG_TYPE_CGA, &timing_t3100e); @@ -711,7 +710,7 @@ const device_t t3100e_device = { .init = t3100e_init, .close = t3100e_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = t3100e_speed_changed, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_chips_69000.c b/src/video/vid_chips_69000.c index 5d41dc4a7..70b2b9e16 100644 --- a/src/video/vid_chips_69000.c +++ b/src/video/vid_chips_69000.c @@ -27,6 +27,7 @@ #include <86box/mem.h> #include <86box/rom.h> #include <86box/device.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/video.h> #include <86box/vid_svga.h> @@ -106,6 +107,7 @@ typedef struct chips_69000_t { uint8_t mm_regs[256], mm_index; uint8_t flat_panel_regs[256], flat_panel_index; uint8_t ext_regs[256], ext_index; + uint8_t pci_regs[256]; union { uint32_t mem_regs[4]; @@ -166,12 +168,12 @@ static chips_69000_t *reset_state = NULL; /* TODO: Probe timings on real hardware. */ static video_timings_t timing_chips = { .type = VIDEO_PCI, .write_b = 2, .write_w = 2, .write_l = 1, .read_b = 10, .read_w = 10, .read_l = 10 }; -uint8_t chips_69000_readb_linear(uint32_t addr, void *p); -uint16_t chips_69000_readw_linear(uint32_t addr, void *p); -uint32_t chips_69000_readl_linear(uint32_t addr, void *p); -void chips_69000_writeb_linear(uint32_t addr, uint8_t val, void *p); -void chips_69000_writew_linear(uint32_t addr, uint16_t val, void *p); -void chips_69000_writel_linear(uint32_t addr, uint32_t val, void *p); +uint8_t chips_69000_readb_linear(uint32_t addr, void *priv); +uint16_t chips_69000_readw_linear(uint32_t addr, void *priv); +uint32_t chips_69000_readl_linear(uint32_t addr, void *priv); +void chips_69000_writeb_linear(uint32_t addr, uint8_t val, void *priv); +void chips_69000_writew_linear(uint32_t addr, uint16_t val, void *priv); +void chips_69000_writel_linear(uint32_t addr, uint32_t val, void *priv); /* Multimedia handling. */ uint8_t @@ -238,7 +240,7 @@ chips_69000_write_flat_panel(chips_69000_t* chips, uint8_t val) void chips_69000_interrupt(chips_69000_t* chips) { - pci_irq(chips->slot, PCI_INTA, 0, !!((chips->mem_regs[0] & chips->mem_regs[1]) & 0x80004040), &chips->irq_state); + pci_irq(chips->slot, PCI_INTA, 0, !!(chips->mem_regs[0] & chips->mem_regs[1] & 0x80004040), &chips->irq_state); } void @@ -250,378 +252,790 @@ chips_69000_bitblt_interrupt(chips_69000_t* chips) chips_69000_interrupt(chips); } -void -chips_69000_do_rop_8bpp(uint8_t *dst, uint8_t src, uint8_t rop) -{ - switch (rop) { - case 0x00: - *dst = 0; - break; - case 0x11: - *dst = ~(*dst) & ~src; - break; - case 0x22: - *dst &= ~src; - break; - case 0x33: - *dst = ~src; - break; - case 0x44: - *dst = src & ~(*dst); - break; - case 0x55: - *dst = ~*dst; - break; - case 0x66: - *dst ^= src; - break; - case 0x77: - *dst = ~src | ~(*dst); - break; - case 0x88: - *dst &= src; - break; - case 0x99: - *dst ^= ~src; - break; - case 0xAA: - break; /* No-op. */ - case 0xBB: - *dst |= ~src; - break; - case 0xCC: - *dst = src; - break; - case 0xDD: - *dst = src | ~(*dst); - break; - case 0xEE: - *dst |= src; - break; - case 0xFF: - *dst = 0xFF; - break; +#define ROPMIX(R, D, P, S, out) \ + { \ + switch (R) { \ + case 0x00: \ + out = 0; \ + break; \ + case 0x01: \ + out = ~(D | (P | S)); \ + break; \ + case 0x02: \ + out = D & ~(P | S); \ + break; \ + case 0x03: \ + out = ~(P | S); \ + break; \ + case 0x04: \ + out = S & ~(D | P); \ + break; \ + case 0x05: \ + out = ~(D | P); \ + break; \ + case 0x06: \ + out = ~(P | ~(D ^ S)); \ + break; \ + case 0x07: \ + out = ~(P | (D & S)); \ + break; \ + case 0x08: \ + out = S & (D & ~P); \ + break; \ + case 0x09: \ + out = ~(P | (D ^ S)); \ + break; \ + case 0x0a: \ + out = D & ~P; \ + break; \ + case 0x0b: \ + out = ~(P | (S & ~D)); \ + break; \ + case 0x0c: \ + out = S & ~P; \ + break; \ + case 0x0d: \ + out = ~(P | (D & ~S)); \ + break; \ + case 0x0e: \ + out = ~(P | ~(D | S)); \ + break; \ + case 0x0f: \ + out = ~P; \ + break; \ + case 0x10: \ + out = P & ~(D | S); \ + break; \ + case 0x11: \ + out = ~(D | S); \ + break; \ + case 0x12: \ + out = ~(S | ~(D ^ P)); \ + break; \ + case 0x13: \ + out = ~(S | (D & P)); \ + break; \ + case 0x14: \ + out = ~(D | ~(P ^ S)); \ + break; \ + case 0x15: \ + out = ~(D | (P & S)); \ + break; \ + case 0x16: \ + out = P ^ (S ^ (D & ~(P & S))); \ + break; \ + case 0x17: \ + out = ~(S ^ ((S ^ P) & (D ^ S))); \ + break; \ + case 0x18: \ + out = (S ^ P) & (P ^ D); \ + break; \ + case 0x19: \ + out = ~(S ^ (D & ~(P & S))); \ + break; \ + case 0x1a: \ + out = P ^ (D | (S & P)); \ + break; \ + case 0x1b: \ + out = ~(S ^ (D & (P ^ S))); \ + break; \ + case 0x1c: \ + out = P ^ (S | (D & P)); \ + break; \ + case 0x1d: \ + out = ~(D ^ (S & (P ^ D))); \ + break; \ + case 0x1e: \ + out = P ^ (D | S); \ + break; \ + case 0x1f: \ + out = ~(P & (D | S)); \ + break; \ + case 0x20: \ + out = D & (P & ~S); \ + break; \ + case 0x21: \ + out = ~(S | (D ^ P)); \ + break; \ + case 0x22: \ + out = D & ~S; \ + break; \ + case 0x23: \ + out = ~(S | (P & ~D)); \ + break; \ + case 0x24: \ + out = (S ^ P) & (D ^ S); \ + break; \ + case 0x25: \ + out = ~(P ^ (D & ~(S & P))); \ + break; \ + case 0x26: \ + out = S ^ (D | (P & S)); \ + break; \ + case 0x27: \ + out = S ^ (D | ~(P ^ S)); \ + break; \ + case 0x28: \ + out = D & (P ^ S); \ + break; \ + case 0x29: \ + out = ~(P ^ (S ^ (D | (P & S)))); \ + break; \ + case 0x2a: \ + out = D & ~(P & S); \ + break; \ + case 0x2b: \ + out = ~(S ^ ((S ^ P) & (P ^ D))); \ + break; \ + case 0x2c: \ + out = S ^ (P & (D | S)); \ + break; \ + case 0x2d: \ + out = P ^ (S | ~D); \ + break; \ + case 0x2e: \ + out = P ^ (S | (D ^ P)); \ + break; \ + case 0x2f: \ + out = ~(P & (S | ~D)); \ + break; \ + case 0x30: \ + out = P & ~S; \ + break; \ + case 0x31: \ + out = ~(S | (D & ~P)); \ + break; \ + case 0x32: \ + out = S ^ (D | (P | S)); \ + break; \ + case 0x33: \ + out = ~S; \ + break; \ + case 0x34: \ + out = S ^ (P | (D & S)); \ + break; \ + case 0x35: \ + out = S ^ (P | ~(D ^ S)); \ + break; \ + case 0x36: \ + out = S ^ (D | P); \ + break; \ + case 0x37: \ + out = ~(S & (D | P)); \ + break; \ + case 0x38: \ + out = P ^ (S & (D | P)); \ + break; \ + case 0x39: \ + out = S ^ (P | ~D); \ + break; \ + case 0x3a: \ + out = S ^ (P | (D ^ S)); \ + break; \ + case 0x3b: \ + out = ~(S & (P | ~D)); \ + break; \ + case 0x3c: \ + out = P ^ S; \ + break; \ + case 0x3d: \ + out = S ^ (P | ~(D | S)); \ + break; \ + case 0x3e: \ + out = S ^ (P | (D & ~S)); \ + break; \ + case 0x3f: \ + out = ~(P & S); \ + break; \ + case 0x40: \ + out = P & (S & ~D); \ + break; \ + case 0x41: \ + out = ~(D | (P ^ S)); \ + break; \ + case 0x42: \ + out = (S ^ D) & (P ^ D); \ + break; \ + case 0x43: \ + out = ~(S ^ (P & ~(D & S))); \ + break; \ + case 0x44: \ + out = S & ~D; \ + break; \ + case 0x45: \ + out = ~(D | (P & ~S)); \ + break; \ + case 0x46: \ + out = D ^ (S | (P & D)); \ + break; \ + case 0x47: \ + out = ~(P ^ (S & (D ^ P))); \ + break; \ + case 0x48: \ + out = S & (D ^ P); \ + break; \ + case 0x49: \ + out = ~(P ^ (D ^ (S | (P & D)))); \ + break; \ + case 0x4a: \ + out = D ^ (P & (S | D)); \ + break; \ + case 0x4b: \ + out = P ^ (D | ~S); \ + break; \ + case 0x4c: \ + out = S & ~(D & P); \ + break; \ + case 0x4d: \ + out = ~(S ^ ((S ^ P) | (D ^ S))); \ + break; \ + case 0x4e: \ + out = P ^ (D | (S ^ P)); \ + break; \ + case 0x4f: \ + out = ~(P & (D | ~S)); \ + break; \ + case 0x50: \ + out = P & ~D; \ + break; \ + case 0x51: \ + out = ~(D | (S & ~P)); \ + break; \ + case 0x52: \ + out = D ^ (P | (S & D)); \ + break; \ + case 0x53: \ + out = ~(S ^ (P & (D ^ S))); \ + break; \ + case 0x54: \ + out = ~(D | ~(P | S)); \ + break; \ + case 0x55: \ + out = ~D; \ + break; \ + case 0x56: \ + out = D ^ (P | S); \ + break; \ + case 0x57: \ + out = ~(D & (P | S)); \ + break; \ + case 0x58: \ + out = P ^ (D & (S | P)); \ + break; \ + case 0x59: \ + out = D ^ (P | ~S); \ + break; \ + case 0x5a: \ + out = D ^ P; \ + break; \ + case 0x5b: \ + out = D ^ (P | ~(S | D)); \ + break; \ + case 0x5c: \ + out = D ^ (P | (S ^ D)); \ + break; \ + case 0x5d: \ + out = ~(D & (P | ~S)); \ + break; \ + case 0x5e: \ + out = D ^ (P | (S & ~D)); \ + break; \ + case 0x5f: \ + out = ~(D & P); \ + break; \ + case 0x60: \ + out = P & (D ^ S); \ + break; \ + case 0x61: \ + out = ~(D ^ (S ^ (P | (D & S)))); \ + break; \ + case 0x62: \ + out = D ^ (S & (P | D)); \ + break; \ + case 0x63: \ + out = S ^ (D | ~P); \ + break; \ + case 0x64: \ + out = S ^ (D & (P | S)); \ + break; \ + case 0x65: \ + out = D ^ (S | ~P); \ + break; \ + case 0x66: \ + out = D ^ S; \ + break; \ + case 0x67: \ + out = S ^ (D | ~(P | S)); \ + break; \ + case 0x68: \ + out = ~(D ^ (S ^ (P | ~(D | S)))); \ + break; \ + case 0x69: \ + out = ~(P ^ (D ^ S)); \ + break; \ + case 0x6a: \ + out = D ^ (P & S); \ + break; \ + case 0x6b: \ + out = ~(P ^ (S ^ (D & (P | S)))); \ + break; \ + case 0x6c: \ + out = S ^ (D & P); \ + break; \ + case 0x6d: \ + out = ~(P ^ (D ^ (S & (P | D)))); \ + break; \ + case 0x6e: \ + out = S ^ (D & (P | ~S)); \ + break; \ + case 0x6f: \ + out = ~(P & ~(D ^ S)); \ + break; \ + case 0x70: \ + out = P & ~(D & S); \ + break; \ + case 0x71: \ + out = ~(S ^ ((S ^ D) & (P ^ D))); \ + break; \ + case 0x72: \ + out = S ^ (D | (P ^ S)); \ + break; \ + case 0x73: \ + out = ~(S & (D | ~P)); \ + break; \ + case 0x74: \ + out = D ^ (S | (P ^ D)); \ + break; \ + case 0x75: \ + out = ~(D & (S | ~P)); \ + break; \ + case 0x76: \ + out = S ^ (D | (P & ~S)); \ + break; \ + case 0x77: \ + out = ~(D & S); \ + break; \ + case 0x78: \ + out = P ^ (D & S); \ + break; \ + case 0x79: \ + out = ~(D ^ (S ^ (P & (D | S)))); \ + break; \ + case 0x7a: \ + out = D ^ (P & (S | ~D)); \ + break; \ + case 0x7b: \ + out = ~(S & ~(D ^ P)); \ + break; \ + case 0x7c: \ + out = S ^ (P & (D | ~S)); \ + break; \ + case 0x7d: \ + out = ~(D & ~(P ^ S)); \ + break; \ + case 0x7e: \ + out = (S ^ P) | (D ^ S); \ + break; \ + case 0x7f: \ + out = ~(D & (P & S)); \ + break; \ + case 0x80: \ + out = D & (P & S); \ + break; \ + case 0x81: \ + out = ~((S ^ P) | (D ^ S)); \ + break; \ + case 0x82: \ + out = D & ~(P ^ S); \ + break; \ + case 0x83: \ + out = ~(S ^ (P & (D | ~S))); \ + break; \ + case 0x84: \ + out = S & ~(D ^ P); \ + break; \ + case 0x85: \ + out = ~(P ^ (D & (S | ~P))); \ + break; \ + case 0x86: \ + out = D ^ (S ^ (P & (D | S))); \ + break; \ + case 0x87: \ + out = ~(P ^ (D & S)); \ + break; \ + case 0x88: \ + out = D & S; \ + break; \ + case 0x89: \ + out = ~(S ^ (D | (P & ~S))); \ + break; \ + case 0x8a: \ + out = D & (S | ~P); \ + break; \ + case 0x8b: \ + out = ~(D ^ (S | (P ^ D))); \ + break; \ + case 0x8c: \ + out = S & (D | ~P); \ + break; \ + case 0x8d: \ + out = ~(S ^ (D | (P ^ S))); \ + break; \ + case 0x8e: \ + out = S ^ ((S ^ D) & (P ^ D)); \ + break; \ + case 0x8f: \ + out = ~(P & ~(D & S)); \ + break; \ + case 0x90: \ + out = P & ~(D ^ S); \ + break; \ + case 0x91: \ + out = ~(S ^ (D & (P | ~S))); \ + break; \ + case 0x92: \ + out = D ^ (P ^ (S & (D | P))); \ + break; \ + case 0x93: \ + out = ~(S ^ (P & D)); \ + break; \ + case 0x94: \ + out = P ^ (S ^ (D & (P | S))); \ + break; \ + case 0x95: \ + out = ~(D ^ (P & S)); \ + break; \ + case 0x96: \ + out = D ^ (P ^ S); \ + break; \ + case 0x97: \ + out = P ^ (S ^ (D | ~(P | S))); \ + break; \ + case 0x98: \ + out = ~(S ^ (D | ~(P | S))); \ + break; \ + case 0x99: \ + out = ~(D ^ S); \ + break; \ + case 0x9a: \ + out = D ^ (P & ~S); \ + break; \ + case 0x9b: \ + out = ~(S ^ (D & (P | S))); \ + break; \ + case 0x9c: \ + out = S ^ (P & ~D); \ + break; \ + case 0x9d: \ + out = ~(D ^ (S & (P | D))); \ + break; \ + case 0x9e: \ + out = D ^ (S ^ (P | (D & S))); \ + break; \ + case 0x9f: \ + out = ~(P & (D ^ S)); \ + break; \ + case 0xa0: \ + out = D & P; \ + break; \ + case 0xa1: \ + out = ~(P ^ (D | (S & ~P))); \ + break; \ + case 0xa2: \ + out = D & (P | ~S); \ + break; \ + case 0xa3: \ + out = ~(D ^ (P | (S ^ D))); \ + break; \ + case 0xa4: \ + out = ~(P ^ (D | ~(S | P))); \ + break; \ + case 0xa5: \ + out = ~(P ^ D); \ + break; \ + case 0xa6: \ + out = D ^ (S & ~P); \ + break; \ + case 0xa7: \ + out = ~(P ^ (D & (S | P))); \ + break; \ + case 0xa8: \ + out = D & (P | S); \ + break; \ + case 0xa9: \ + out = ~(D ^ (P | S)); \ + break; \ + case 0xaa: \ + out = D; \ + break; \ + case 0xab: \ + out = D | ~(P | S); \ + break; \ + case 0xac: \ + out = S ^ (P & (D ^ S)); \ + break; \ + case 0xad: \ + out = ~(D ^ (P | (S & D))); \ + break; \ + case 0xae: \ + out = D | (S & ~P); \ + break; \ + case 0xaf: \ + out = D | ~P; \ + break; \ + case 0xb0: \ + out = P & (D | ~S); \ + break; \ + case 0xb1: \ + out = ~(P ^ (D | (S ^ P))); \ + break; \ + case 0xb2: \ + out = S ^ ((S ^ P) | (D ^ S)); \ + break; \ + case 0xb3: \ + out = ~(S & ~(D & P)); \ + break; \ + case 0xb4: \ + out = P ^ (S & ~D); \ + break; \ + case 0xb5: \ + out = ~(D ^ (P & (S | D))); \ + break; \ + case 0xb6: \ + out = D ^ (P ^ (S | (D & P))); \ + break; \ + case 0xb7: \ + out = ~(S & (D ^ P)); \ + break; \ + case 0xb8: \ + out = P ^ (S & (D ^ P)); \ + break; \ + case 0xb9: \ + out = ~(D ^ (S | (P & D))); \ + break; \ + case 0xba: \ + out = D | (P & ~S); \ + break; \ + case 0xbb: \ + out = D | ~S; \ + break; \ + case 0xbc: \ + out = S ^ (P & ~(D & S)); \ + break; \ + case 0xbd: \ + out = ~((S ^ D) & (P ^ D)); \ + break; \ + case 0xbe: \ + out = D | (P ^ S); \ + break; \ + case 0xbf: \ + out = D | ~(P & S); \ + break; \ + case 0xc0: \ + out = P & S; \ + break; \ + case 0xc1: \ + out = ~(S ^ (P | (D & ~S))); \ + break; \ + case 0xc2: \ + out = ~(S ^ (P | ~(D | S))); \ + break; \ + case 0xc3: \ + out = ~(P ^ S); \ + break; \ + case 0xc4: \ + out = S & (P | ~D); \ + break; \ + case 0xc5: \ + out = ~(S ^ (P | (D ^ S))); \ + break; \ + case 0xc6: \ + out = S ^ (D & ~P); \ + break; \ + case 0xc7: \ + out = ~(P ^ (S & (D | P))); \ + break; \ + case 0xc8: \ + out = S & (D | P); \ + break; \ + case 0xc9: \ + out = ~(S ^ (P | D)); \ + break; \ + case 0xca: \ + out = D ^ (P & (S ^ D)); \ + break; \ + case 0xcb: \ + out = ~(S ^ (P | (D & S))); \ + break; \ + case 0xcc: \ + out = S; \ + break; \ + case 0xcd: \ + out = S | ~(D | P); \ + break; \ + case 0xce: \ + out = S | (D & ~P); \ + break; \ + case 0xcf: \ + out = S | ~P; \ + break; \ + case 0xd0: \ + out = P & (S | ~D); \ + break; \ + case 0xd1: \ + out = ~(P ^ (S | (D ^ P))); \ + break; \ + case 0xd2: \ + out = P ^ (D & ~S); \ + break; \ + case 0xd3: \ + out = ~(S ^ (P & (D | S))); \ + break; \ + case 0xd4: \ + out = S ^ ((S ^ P) & (P ^ D)); \ + break; \ + case 0xd5: \ + out = ~(D & ~(P & S)); \ + break; \ + case 0xd6: \ + out = P ^ (S ^ (D | (P & S))); \ + break; \ + case 0xd7: \ + out = ~(D & (P ^ S)); \ + break; \ + case 0xd8: \ + out = P ^ (D & (S ^ P)); \ + break; \ + case 0xd9: \ + out = ~(S ^ (D | (P & S))); \ + break; \ + case 0xda: \ + out = D ^ (P & ~(S & D)); \ + break; \ + case 0xdb: \ + out = ~((S ^ P) & (D ^ S)); \ + break; \ + case 0xdc: \ + out = S | (P & ~D); \ + break; \ + case 0xdd: \ + out = S | ~D; \ + break; \ + case 0xde: \ + out = S | (D ^ P); \ + break; \ + case 0xdf: \ + out = S | ~(D & P); \ + break; \ + case 0xe0: \ + out = P & (D | S); \ + break; \ + case 0xe1: \ + out = ~(P ^ (D | S)); \ + break; \ + case 0xe2: \ + out = D ^ (S & (P ^ D)); \ + break; \ + case 0xe3: \ + out = ~(P ^ (S | (D & P))); \ + break; \ + case 0xe4: \ + out = S ^ (D & (P ^ S)); \ + break; \ + case 0xe5: \ + out = ~(P ^ (D | (S & P))); \ + break; \ + case 0xe6: \ + out = S ^ (D & ~(P & S)); \ + break; \ + case 0xe7: \ + out = ~((S ^ P) & (P ^ D)); \ + break; \ + case 0xe8: \ + out = S ^ ((S ^ P) & (D ^ S)); \ + break; \ + case 0xe9: \ + out = ~(D ^ (S ^ (P & ~(D & S)))); \ + break; \ + case 0xea: \ + out = D | (P & S); \ + break; \ + case 0xeb: \ + out = D | ~(P ^ S); \ + break; \ + case 0xec: \ + out = S | (D & P); \ + break; \ + case 0xed: \ + out = S | ~(D ^ P); \ + break; \ + case 0xee: \ + out = D | S; \ + break; \ + case 0xef: \ + out = S | (D | ~P); \ + break; \ + case 0xf0: \ + out = P; \ + break; \ + case 0xf1: \ + out = P | ~(D | S); \ + break; \ + case 0xf2: \ + out = P | (D & ~S); \ + break; \ + case 0xf3: \ + out = P | ~S; \ + break; \ + case 0xf4: \ + out = P | (S & ~D); \ + break; \ + case 0xf5: \ + out = P | ~D; \ + break; \ + case 0xf6: \ + out = P | (D ^ S); \ + break; \ + case 0xf7: \ + out = P | ~(D & S); \ + break; \ + case 0xf8: \ + out = P | (D & S); \ + break; \ + case 0xf9: \ + out = P | ~(D ^ S); \ + break; \ + case 0xfa: \ + out = D | P; \ + break; \ + case 0xfb: \ + out = D | (P | ~S); \ + break; \ + case 0xfc: \ + out = P | S; \ + break; \ + case 0xfd: \ + out = P | (S | ~D); \ + break; \ + case 0xfe: \ + out = D | (P | S); \ + break; \ + case 0xff: \ + out = ~0; \ + break; \ + } \ } -} - -void -chips_69000_do_rop_16bpp(uint16_t *dst, uint16_t src, uint8_t rop) -{ - switch (rop) { - case 0x00: - *dst = 0; - break; - case 0x11: - *dst = ~(*dst) & ~src; - break; - case 0x22: - *dst &= ~src; - break; - case 0x33: - *dst = ~src; - break; - case 0x44: - *dst = src & ~(*dst); - break; - case 0x55: - *dst = ~*dst; - break; - case 0x66: - *dst ^= src; - break; - case 0x77: - *dst = ~src | ~(*dst); - break; - case 0x88: - *dst &= src; - break; - case 0x99: - *dst ^= ~src; - break; - case 0xAA: - break; /* No-op. */ - case 0xBB: - *dst |= ~src; - break; - case 0xCC: - *dst = src; - break; - case 0xDD: - *dst = src | ~(*dst); - break; - case 0xEE: - *dst |= src; - break; - case 0xFF: - *dst = 0xFFFF; - break; - } -} - -void -chips_69000_do_rop_24bpp(uint32_t *dst, uint32_t src, uint8_t rop) -{ - switch (rop) { - case 0x00: - *dst = 0; - break; - case 0x11: - *dst = ~(*dst) & ~src; - break; - case 0x22: - *dst &= ~src; - break; - case 0x33: - *dst = ~src; - break; - case 0x44: - *dst = src & ~(*dst); - break; - case 0x55: - *dst = ~*dst; - break; - case 0x66: - *dst ^= src; - break; - case 0x77: - *dst = ~src | ~(*dst); - break; - case 0x88: - *dst &= src; - break; - case 0x99: - *dst ^= ~src; - break; - case 0xAA: - break; /* No-op. */ - case 0xBB: - *dst |= ~src; - break; - case 0xCC: - *dst = src; - break; - case 0xDD: - *dst = src | ~(*dst); - break; - case 0xEE: - *dst |= src; - break; - case 0xFF: - *dst = 0xFFFFFF; - break; - } -} void chips_69000_do_rop_8bpp_patterned(uint8_t *dst, uint8_t pattern, uint8_t src, uint8_t rop) { - if ((rop & 0xF) == ((rop >> 4) & 0xF)) { - return chips_69000_do_rop_8bpp(dst, src, rop); - } - - switch (rop) { - case 0x00: - *dst = 0; - break; - case 0x05: - *dst = ~(*dst) & ~pattern; - break; - case 0x0A: - *dst &= ~pattern; - break; - case 0x0F: - *dst = ~pattern; - break; - case 0x1A: - *dst = pattern ^ (*dst | (pattern & src)); - break; - case 0x2A: - *dst = *dst & (~(src & pattern)); - break; - case 0x3A: - *dst = src ^ (pattern | (*dst ^ src)); - break; - case 0x4A: - *dst = *dst ^ (pattern & (src | *dst)); - break; - case 0x50: - *dst = pattern & ~(*dst); - break; - case 0x55: - *dst = ~*dst; - break; - case 0x5A: - *dst ^= pattern; - break; - case 0x5F: - *dst = ~pattern | ~(*dst); - break; - case 0x6A: - *dst = *dst ^ (pattern & src); - break; - case 0x7A: - *dst = *dst ^ (pattern & (src | (~*dst))); - break; - case 0x8A: - *dst = *dst & (src | (~pattern)); - break; - case 0x9A: - *dst = *dst ^ (pattern & (~src)); - break; - case 0xB8: - *dst = (((pattern ^ *dst) & src) ^ pattern); - break; - case 0xA0: - *dst &= pattern; - break; - case 0xA5: - *dst ^= ~pattern; - break; - case 0xAA: - break; /* No-op. */ - case 0xAC: - *dst = src ^ (pattern & (*dst ^ src)); - break; - case 0xAF: - *dst |= ~pattern; - break; - case 0xBA: - *dst |= (pattern & ~src); - break; - case 0xCA: - *dst ^= (pattern & (src ^ *dst)); - break; - case 0xE2: - *dst ^= (src & (pattern ^ *dst)); - break; - case 0xDA: - *dst ^= pattern & (~(src & *dst)); - break; - case 0xEA: - *dst |= pattern & src; - break; - case 0xF0: - *dst = pattern; - break; - case 0xF5: - *dst = pattern | ~(*dst); - break; - case 0xFA: - *dst |= pattern; - break; - case 0xFF: - *dst = 0xFF; - break; - default: - pclog("Unknown ROP 0x%X\n", rop); - break; - } + ROPMIX(rop, *dst, pattern, src, *dst); } void chips_69000_do_rop_16bpp_patterned(uint16_t *dst, uint16_t pattern, uint16_t src, uint8_t rop) { - if ((rop & 0xF) == ((rop >> 4) & 0xF)) { - return chips_69000_do_rop_16bpp(dst, src, rop); - } - - switch (rop) { - default: - pclog("Unknown ROP 0x%X\n", rop); - break; - case 0x00: - *dst = 0; - break; - case 0x05: - *dst = ~(*dst) & ~pattern; - break; - case 0x0A: - *dst &= ~pattern; - break; - case 0x0F: - *dst = ~pattern; - break; - case 0x1A: - *dst = pattern ^ (*dst | (pattern & src)); - break; - case 0x2A: - *dst = *dst & (~(src & pattern)); - break; - case 0x3A: - *dst = src ^ (pattern | (*dst ^ src)); - break; - case 0x4A: - *dst = *dst ^ (pattern & (src | *dst)); - break; - case 0x50: - *dst = pattern & ~(*dst); - break; - case 0x55: - *dst = ~*dst; - break; - case 0x5A: - *dst ^= pattern; - break; - case 0x5F: - *dst = ~pattern | ~(*dst); - break; - case 0x6A: - *dst = *dst ^ (pattern & src); - break; - case 0x7A: - *dst = *dst ^ (pattern & (src | (~*dst))); - break; - case 0x8A: - *dst = *dst & (src | (~pattern)); - break; - case 0x9A: - *dst = *dst ^ (pattern & (~src)); - break; - case 0xB8: - *dst = (((pattern ^ *dst) & src) ^ pattern); - break; - case 0xA0: - *dst &= pattern; - break; - case 0xA5: - *dst ^= ~pattern; - break; - case 0xAA: - break; /* No-op. */ - case 0xAC: - *dst = src ^ (pattern & (*dst ^ src)); - break; - case 0xAF: - *dst |= ~pattern; - break; - case 0xBA: - *dst |= (pattern & ~src); - break; - case 0xCA: - *dst ^= (pattern & (src ^ *dst)); - break; - case 0xE2: - *dst ^= (src & (pattern ^ *dst)); - break; - case 0xDA: - *dst ^= pattern & (~(src & *dst)); - break; - case 0xEA: - *dst |= pattern & src; - break; - case 0xF0: - *dst = pattern; - break; - case 0xF5: - *dst = pattern | ~(*dst); - break; - case 0xFA: - *dst |= pattern; - break; - case 0xFF: - *dst = 0xFF; - break; - } + ROPMIX(rop, *dst, pattern, src, *dst); } void @@ -629,107 +1043,8 @@ chips_69000_do_rop_24bpp_patterned(uint32_t *dst, uint32_t pattern, uint32_t src { uint32_t orig_dst = *dst & 0xFF000000; - if ((rop & 0xF) == ((rop >> 4) & 0xF)) { - return chips_69000_do_rop_24bpp(dst, src, rop); - } + ROPMIX(rop, *dst, pattern, src, *dst); - switch (rop) { - default: - pclog("Unknown ROP 0x%X\n", rop); - break; - case 0x00: - *dst = 0; - break; - case 0x05: - *dst = ~(*dst) & ~pattern; - break; - case 0x0A: - *dst &= ~pattern; - break; - case 0x0F: - *dst = ~pattern; - break; - case 0x1A: - *dst = pattern ^ (*dst | (pattern & src)); - break; - case 0x2A: - *dst = *dst & (~(src & pattern)); - break; - case 0x3A: - *dst = src ^ (pattern | (*dst ^ src)); - break; - case 0x4A: - *dst = *dst ^ (pattern & (src | *dst)); - break; - case 0x50: - *dst = pattern & ~(*dst); - break; - case 0x55: - *dst = ~*dst; - break; - case 0x5A: - *dst ^= pattern; - break; - case 0x5F: - *dst = ~pattern | ~(*dst); - break; - case 0x6A: - *dst = *dst ^ (pattern & src); - break; - case 0x7A: - *dst = *dst ^ (pattern & (src | (~*dst))); - break; - case 0x8A: - *dst = *dst & (src | (~pattern)); - break; - case 0x9A: - *dst = *dst ^ (pattern & (~src)); - break; - case 0xB8: - *dst = (((pattern ^ *dst) & src) ^ pattern); - break; - case 0xA0: - *dst &= pattern; - break; - case 0xA5: - *dst ^= ~pattern; - break; - case 0xAA: - break; /* No-op. */ - case 0xAC: - *dst = src ^ (pattern & (*dst ^ src)); - break; - case 0xAF: - *dst |= ~pattern; - break; - case 0xBA: - *dst |= (pattern & ~src); - break; - case 0xCA: - *dst ^= (pattern & (src ^ *dst)); - break; - case 0xDA: - *dst ^= pattern & (~(src & *dst)); - break; - case 0xE2: - *dst ^= (src & (pattern ^ *dst)); - break; - case 0xEA: - *dst |= pattern & src; - break; - case 0xF0: - *dst = pattern; - break; - case 0xF5: - *dst = pattern | ~(*dst); - break; - case 0xFA: - *dst |= pattern; - break; - case 0xFF: - *dst = 0xFF; - break; - } *dst &= 0xFFFFFF; *dst |= orig_dst; } @@ -783,7 +1098,7 @@ chips_69000_recalctimings(svga_t *svga) svga->hblank_end_val = ((svga->crtc[3] & 0x1f) | ((svga->crtc[5] & 0x80) ? 0x20 : 0x00)) | (svga->crtc[0x3c] & 0b11000000); svga->hblank_end_mask = 0xff; - svga->ma_latch |= (svga->crtc[0x40] & 0xF) << 16; + svga->memaddr_latch |= (svga->crtc[0x40] & 0xF) << 16; svga->rowoffset |= (svga->crtc[0x41] & 0xF) << 8; svga->interlace = !!(svga->crtc[0x70] & 0x80); @@ -953,15 +1268,15 @@ chips_69000_process_pixel(chips_69000_t* chips, uint32_t pixel) if (chips->bitblt_running.bytes_per_pixel == 3) { pattern_pixel = chips_69000_readb_linear(chips->bitblt_running.bitblt.pat_addr + (4 * 8 * ((vert_pat_alignment + chips->bitblt_running.y) & 7)) - + (3 * (((chips->bitblt_running.bitblt.destination_addr & 7) + chips->bitblt_running.x) & 7)), chips); + + (3 * ((((chips->bitblt_running.bitblt.destination_addr / 3) & 7) + chips->bitblt_running.x) & 7)), chips); pattern_pixel |= chips_69000_readb_linear(chips->bitblt_running.bitblt.pat_addr + (4 * 8 * ((vert_pat_alignment + chips->bitblt_running.y) & 7)) - + (3 * (((chips->bitblt_running.bitblt.destination_addr & 7) + chips->bitblt_running.x) & 7)) + 1, chips) << 8; + + (3 * ((((chips->bitblt_running.bitblt.destination_addr / 3) & 7) + chips->bitblt_running.x) & 7)) + 1, chips) << 8; pattern_pixel |= chips_69000_readb_linear(chips->bitblt_running.bitblt.pat_addr + (4 * 8 * ((vert_pat_alignment + chips->bitblt_running.y) & 7)) - + (3 * (((chips->bitblt_running.bitblt.destination_addr & 7) + chips->bitblt_running.x) & 7)) + 2, chips) << 16; + + (3 * ((((chips->bitblt_running.bitblt.destination_addr / 3) & 7) + chips->bitblt_running.x) & 7)) + 2, chips) << 16; } } if (chips->bitblt_running.bytes_per_pixel == 2) { @@ -979,7 +1294,7 @@ chips_69000_process_pixel(chips_69000_t* chips, uint32_t pixel) : chips->bitblt_running.bitblt.pattern_source_key_bg; color_key &= (1 << (8 * (chips->bitblt_running.bytes_per_pixel))) - 1; - if (!!(color_key == dest_pixel) == !!(chips->bitblt_running.bitblt.bitblt_control & (1 << 16))) { + if (!!(color_key == dest_pixel) == !(chips->bitblt_running.bitblt.bitblt_control & (1 << 16))) { return; } @@ -1017,7 +1332,7 @@ chips_69000_process_pixel(chips_69000_t* chips, uint32_t pixel) color_key &= (1 << (8 * (chips->bitblt_running.bytes_per_pixel))) - 1; dest_pixel &= (1 << (8 * (chips->bitblt_running.bytes_per_pixel))) - 1; - if (!!(color_key == dest_pixel) == !!(chips->bitblt_running.bitblt.bitblt_control & (1 << 16))) { + if (!!(color_key == dest_pixel) == !(chips->bitblt_running.bitblt.bitblt_control & (1 << 16))) { return; } @@ -1643,9 +1958,9 @@ chips_69000_write_ext_reg(chips_69000_t* chips, uint8_t val) } void -chips_69000_out(uint16_t addr, uint8_t val, void *p) +chips_69000_out(uint16_t addr, uint8_t val, void *priv) { - chips_69000_t *chips = (chips_69000_t *) p; + chips_69000_t *chips = (chips_69000_t *) priv; svga_t *svga = &chips->svga; uint8_t old, index; @@ -1729,7 +2044,7 @@ chips_69000_out(uint16_t addr, uint8_t val, void *p) 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); + svga->memaddr_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5); } else { svga->fullchange = changeframecount; svga_recalctimings(svga); @@ -1750,9 +2065,9 @@ chips_69000_out(uint16_t addr, uint8_t val, void *p) } uint8_t -chips_69000_in(uint16_t addr, void *p) +chips_69000_in(uint16_t addr, void *priv) { - chips_69000_t *chips = (chips_69000_t *) p; + chips_69000_t *chips = (chips_69000_t *) priv; svga_t *svga = &chips->svga; uint8_t temp = 0, index; @@ -1828,128 +2143,155 @@ chips_69000_in(uint16_t addr, void *p) } static uint8_t -chips_69000_pci_read(int func, int addr, void *p) +chips_69000_pci_read(UNUSED(int func), int addr, void *priv) { - chips_69000_t *chips = (chips_69000_t *) p; + chips_69000_t *chips = (chips_69000_t *) priv; + uint8_t ret = 0x00; - { - switch (addr) { - case 0x00: - return 0x2C; - case 0x01: - return 0x10; - case 0x02: - return 0xC0; - case 0x03: - return 0x00; - case 0x04: - return (chips->pci_conf_status & 0b11100011) | 0x80; - case 0x06: - return 0x80; - case 0x07: - return 0x02; - case 0x08: - case 0x09: - case 0x0a: - return 0x00; - case 0x0b: - return 0x03; - case 0x13: - return chips->linear_mapping.base >> 24; - case 0x30: - return chips->pci_rom_enable & 0x1; - case 0x31: - return 0x0; - case 0x32: - return chips->rom_addr & 0xFF; - case 0x33: - return (chips->rom_addr & 0xFF00) >> 8; - case 0x3c: - return chips->pci_line_interrupt; - case 0x3d: - return 0x01; - case 0x2C: - case 0x2D: - case 0x6C: - case 0x6D: - return (chips->subsys_vid >> ((addr & 1) * 8)) & 0xFF; - case 0x2E: - case 0x2F: - case 0x6E: - case 0x6F: - return (chips->subsys_pid >> ((addr & 1) * 8)) & 0xFF; - default: - return 0x00; - } + switch (addr) { + case 0x00: + ret = 0x2c; + break; + case 0x01: + ret = 0x10; + break; + case 0x02: + ret = 0xc0; + break; + case 0x03: + ret = 0x00; + break; + + case 0x04: + ret = (chips->pci_conf_status & 0x73) | 0x80; + break; + case 0x05: + ret = chips->pci_regs[addr] & 0x01; + break; + case 0x06: + ret = 0x80; + break; + case 0x07: + ret = chips->pci_regs[addr] | 0x02; + break; + + case 0x0b: + ret = 0x03; + break; + + case 0x13: + ret = chips->linear_mapping.base >> 24; + break; + + case 0x2c ... 0x2d: + case 0x6c ... 0x6d: + ret = chips->subsys_vid_b[addr & 1]; + break; + case 0x2e ... 0x2f: + case 0x6e ... 0x6f: + ret = chips->subsys_pid_b[addr & 1]; + break; + + case 0x30: + ret = chips->pci_rom_enable & 0x1; + break; + case 0x32: + ret = chips->rom_addr & 0xff; + break; + case 0x33: + ret = (chips->rom_addr & 0xff00) >> 8; + break; + + case 0x3c: + ret = chips->pci_line_interrupt; + break; + case 0x3d: + ret = 0x01; + break; + + default: + break; } + + return ret; } static void -chips_69000_pci_write(int func, int addr, uint8_t val, void *p) +chips_69000_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) { - chips_69000_t *chips = (chips_69000_t *) p; + chips_69000_t *chips = (chips_69000_t *) priv; - { - switch (addr) { - case 0x04: - { - chips->pci_conf_status = val; - io_removehandler(0x03c0, 0x0020, chips_69000_in, NULL, NULL, chips_69000_out, NULL, NULL, chips); - mem_mapping_disable(&chips->linear_mapping); - mem_mapping_disable(&chips->svga.mapping); - if (chips->pci_conf_status & PCI_COMMAND_IO) { - io_sethandler(0x03c0, 0x0020, chips_69000_in, NULL, NULL, chips_69000_out, NULL, NULL, chips); - } - if (chips->pci_conf_status & PCI_COMMAND_MEM) { - mem_mapping_enable(&chips->svga.mapping); - if (chips->linear_mapping.base) - mem_mapping_set_addr(&chips->linear_mapping, chips->linear_mapping.base, (1 << 24)); - } - break; - } - case 0x13: - { - chips->linear_mapping.base = val << 24; - if (chips->linear_mapping.base) - mem_mapping_set_addr(&chips->linear_mapping, chips->linear_mapping.base, (1 << 24)); - break; - } - case 0x3c: - chips->pci_line_interrupt = val; - break; - case 0x30: - if (chips->on_board) break; + switch (addr) { + case 0x04: + chips->pci_conf_status = val; + io_removehandler(0x03c0, 0x0020, chips_69000_in, NULL, NULL, chips_69000_out, NULL, NULL, chips); + mem_mapping_disable(&chips->linear_mapping); + mem_mapping_disable(&chips->svga.mapping); + if (!chips->on_board) + mem_mapping_disable(&chips->bios_rom.mapping); + if (val & PCI_COMMAND_IO) + io_sethandler(0x03c0, 0x0020, chips_69000_in, NULL, NULL, chips_69000_out, NULL, NULL, chips); + if (val & PCI_COMMAND_MEM) { + if (!chips->on_board && (chips->pci_rom_enable & 1)) + mem_mapping_set_addr(&chips->bios_rom.mapping, chips->rom_addr << 16, 0x10000); + mem_mapping_enable(&chips->svga.mapping); + if (chips->linear_mapping.base > 0x00000000) + mem_mapping_set_addr(&chips->linear_mapping, chips->linear_mapping.base, (1 << 24)); + } + break; + case 0x05: + chips->pci_regs[addr] = val & 0x01; + break; + case 0x07: + chips->pci_regs[addr] &= ~(val & 0xc8); + break; + + case 0x13: + mem_mapping_disable(&chips->linear_mapping); + chips->linear_mapping.base = val << 24; + if ((chips->pci_conf_status & PCI_COMMAND_MEM) && + (chips->linear_mapping.base > 0x00000000)) + mem_mapping_set_addr(&chips->linear_mapping, chips->linear_mapping.base, (1 << 24)); + break; + + case 0x30: + if (!chips->on_board) { chips->pci_rom_enable = val & 0x1; mem_mapping_disable(&chips->bios_rom.mapping); - if (chips->pci_rom_enable & 1) { + if ((chips->pci_conf_status & PCI_COMMAND_MEM) && + (chips->pci_rom_enable & 1)) mem_mapping_set_addr(&chips->bios_rom.mapping, chips->rom_addr << 16, 0x10000); - } - break; - case 0x32: - if (chips->on_board) break; - chips->rom_addr &= ~0xFF; - chips->rom_addr |= val & 0xFC; - if (chips->pci_rom_enable & 1) { + } + break; + case 0x32: + if (!chips->on_board) { + chips->rom_addr &= ~0xff; + chips->rom_addr |= val & 0xfc; + if ((chips->pci_conf_status & PCI_COMMAND_MEM) && + (chips->pci_rom_enable & 1)) mem_mapping_set_addr(&chips->bios_rom.mapping, chips->rom_addr << 16, 0x10000); - } - break; - case 0x33: - if (chips->on_board) break; - chips->rom_addr &= ~0xFF00; + } + break; + case 0x33: + if (!chips->on_board) { + chips->rom_addr &= ~0xff00; chips->rom_addr |= (val << 8); - if (chips->pci_rom_enable & 1) { + if ((chips->pci_conf_status & PCI_COMMAND_MEM) && + (chips->pci_rom_enable & 1)) mem_mapping_set_addr(&chips->bios_rom.mapping, chips->rom_addr << 16, 0x10000); - } - break; - case 0x6C: - case 0x6D: - chips->subsys_vid_b[addr & 1] = val; - break; - case 0x6E: - case 0x6F: - chips->subsys_pid_b[addr & 1] = val; - break; - } + } + break; + + case 0x3c: + chips->pci_line_interrupt = val; + break; + + case 0x6c ... 0x6d: + chips->subsys_vid_b[addr & 1] = val; + break; + case 0x6e ... 0x6f: + chips->subsys_pid_b[addr & 1] = val; + break; } } @@ -2074,7 +2416,7 @@ chips_69000_writeb_mmio(uint32_t addr, uint8_t val, chips_69000_t* chips) { chips->mem_regs_b[addr & 0xF] = val; chips->mem_regs[(addr >> 2) & 0x3] &= 0x80004040; - if (addr == 0x605 || addr == 0x607) + if (addr == 0x601 || addr == 0x603) chips_69000_interrupt(chips); break; } @@ -2193,71 +2535,71 @@ chips_69000_writel_mmio(uint32_t addr, uint32_t val, chips_69000_t* chips) } uint8_t -chips_69000_readb_linear(uint32_t addr, void *p) +chips_69000_readb_linear(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; chips_69000_t *chips = (chips_69000_t *) svga->priv; if (addr & 0x400000) return chips_69000_readb_mmio(addr, chips); - return svga_readb_linear(addr & 0x1FFFFF, p); + return svga_readb_linear(addr & 0x1FFFFF, priv); } uint16_t -chips_69000_readw_linear(uint32_t addr, void *p) +chips_69000_readw_linear(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; chips_69000_t *chips = (chips_69000_t *) svga->priv; if (addr & 0x800000) { if (addr & 0x400000) return bswap16(chips_69000_readw_mmio(addr, chips)); - return bswap16(svga_readw_linear(addr & 0x1FFFFF, p)); + return bswap16(svga_readw_linear(addr & 0x1FFFFF, priv)); } if (addr & 0x400000) return chips_69000_readw_mmio(addr, chips); - return svga_readw_linear(addr & 0x1FFFFF, p); + return svga_readw_linear(addr & 0x1FFFFF, priv); } uint32_t -chips_69000_readl_linear(uint32_t addr, void *p) +chips_69000_readl_linear(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; chips_69000_t *chips = (chips_69000_t *) svga->priv; if (addr & 0x800000) { if (addr & 0x400000) return bswap32(chips_69000_readl_mmio(addr, chips)); - return bswap32(svga_readl_linear(addr & 0x1FFFFF, p)); + return bswap32(svga_readl_linear(addr & 0x1FFFFF, priv)); } if (addr & 0x400000) return chips_69000_readl_mmio(addr, chips); - return svga_readl_linear(addr & 0x1FFFFF, p); + return svga_readl_linear(addr & 0x1FFFFF, priv); } void -chips_69000_writeb_linear(uint32_t addr, uint8_t val, void *p) +chips_69000_writeb_linear(uint32_t addr, uint8_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; chips_69000_t *chips = (chips_69000_t *) svga->priv; if (addr & 0x400000) return chips_69000_writeb_mmio(addr, val, chips); - svga_writeb_linear(addr & 0x1FFFFF, val, p); + svga_writeb_linear(addr & 0x1FFFFF, val, priv); } void -chips_69000_writew_linear(uint32_t addr, uint16_t val, void *p) +chips_69000_writew_linear(uint32_t addr, uint16_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; chips_69000_t *chips = (chips_69000_t *) svga->priv; if (addr & 0x800000) @@ -2266,13 +2608,13 @@ chips_69000_writew_linear(uint32_t addr, uint16_t val, void *p) if (addr & 0x400000) return chips_69000_writew_mmio(addr, val, chips); - svga_writew_linear(addr & 0x1FFFFF, val, p); + svga_writew_linear(addr & 0x1FFFFF, val, priv); } void -chips_69000_writel_linear(uint32_t addr, uint32_t val, void *p) +chips_69000_writel_linear(uint32_t addr, uint32_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; chips_69000_t *chips = (chips_69000_t *) svga->priv; if (addr & 0x800000) @@ -2281,7 +2623,7 @@ chips_69000_writel_linear(uint32_t addr, uint32_t val, void *p) if (addr & 0x400000) return chips_69000_writel_mmio(addr, val, chips); - svga_writel_linear(addr & 0x1FFFFF, val, p); + svga_writel_linear(addr & 0x1FFFFF, val, priv); } void @@ -2393,7 +2735,7 @@ chips_69000_getclock(int clock, void *priv) int pl = ((chips->ext_regs[0xcb] >> 4) & 7); float fvco = 14318181.0 * ((float)(m + 2) / (float)(n + 2)); - if (chips->ext_regs[0xcb] & 4) + if (!(chips->ext_regs[0xcb] & 4)) fvco *= 4.0; float fo = fvco / (float)(1 << pl); @@ -2444,6 +2786,8 @@ chips_69000_disable_handlers(chips_69000_t *chips) if (!chips->on_board) mem_mapping_disable(&chips->bios_rom.mapping); + chips->linear_mapping.base = 0; + /* Save all the mappings and the timers because they are part of linked lists. */ reset_state->linear_mapping = chips->linear_mapping; reset_state->svga.mapping = chips->svga.mapping; @@ -2451,7 +2795,8 @@ chips_69000_disable_handlers(chips_69000_t *chips) reset_state->decrement_timer = chips->decrement_timer; reset_state->svga.timer = chips->svga.timer; - reset_state->svga.timer8514 = chips->svga.timer8514; + reset_state->svga.timer_8514 = chips->svga.timer_8514; + reset_state->svga.timer_xga = chips->svga.timer_xga; } static void @@ -2493,7 +2838,7 @@ chips_69000_init(const device_t *info) chips->svga.bpp = 8; chips->svga.miscout = 1; - chips->svga.vblank_start = chips_69000_vblank_start; + chips->svga.vsync_callback = chips_69000_vblank_start; chips->svga.getclock = chips_69000_getclock; chips->svga.conv_16to32 = chips_69000_conv_16to32; chips->svga.line_compare = chips_69000_line_compare; @@ -2514,6 +2859,18 @@ chips_69000_init(const device_t *info) chips->flat_panel_regs[0x01] = 1; + chips->pci_conf_status = 0x00; + chips->pci_rom_enable = 0x00; + chips->rom_addr = 0x0000; + chips->subsys_vid = 0x102c; + chips->subsys_pid = 0x00c0; + + io_removehandler(0x03c0, 0x0020, chips_69000_in, NULL, NULL, chips_69000_out, NULL, NULL, chips); + mem_mapping_disable(&chips->linear_mapping); + mem_mapping_disable(&chips->svga.mapping); + if (!chips->on_board) + mem_mapping_disable(&chips->bios_rom.mapping); + *reset_state = *chips; return chips; @@ -2526,9 +2883,9 @@ chips_69000_available(void) } void -chips_69000_close(void *p) +chips_69000_close(void *priv) { - chips_69000_t *chips = (chips_69000_t *) p; + chips_69000_t *chips = (chips_69000_t *) priv; chips->quit = 1; // thread_set_event(chips->fifo_event); @@ -2544,17 +2901,17 @@ chips_69000_close(void *p) } void -chips_69000_speed_changed(void *p) +chips_69000_speed_changed(void *priv) { - chips_69000_t *chips = (chips_69000_t *) p; + chips_69000_t *chips = (chips_69000_t *) priv; svga_recalctimings(&chips->svga); } void -chips_69000_force_redraw(void *p) +chips_69000_force_redraw(void *priv) { - chips_69000_t *chips = (chips_69000_t *) p; + chips_69000_t *chips = (chips_69000_t *) priv; chips->svga.fullchange = chips->svga.monitor->mon_changeframecount; } @@ -2567,7 +2924,7 @@ const device_t chips_69000_device = { .init = chips_69000_init, .close = chips_69000_close, .reset = chips_69000_reset, - { .available = chips_69000_available }, + .available = chips_69000_available, .speed_changed = chips_69000_speed_changed, .force_redraw = chips_69000_force_redraw, .config = NULL @@ -2581,7 +2938,7 @@ const device_t chips_69000_onboard_device = { .init = chips_69000_init, .close = chips_69000_close, .reset = chips_69000_reset, - { .available = chips_69000_available }, + .available = chips_69000_available, .speed_changed = chips_69000_speed_changed, .force_redraw = chips_69000_force_redraw, .config = NULL diff --git a/src/video/vid_cl54xx.c b/src/video/vid_cl54xx.c index bc54d0d7c..b2a221e20 100644 --- a/src/video/vid_cl54xx.c +++ b/src/video/vid_cl54xx.c @@ -33,6 +33,7 @@ #include <86box/pci.h> #include <86box/rom.h> #include <86box/device.h> +#include <86box/machine.h> #include <86box/timer.h> #include <86box/video.h> #include <86box/i2c.h> @@ -260,6 +261,8 @@ typedef struct gd54xx_t { uint8_t pos_regs[8]; + uint32_t vlb_lfb_base; + uint32_t lfb_base; uint32_t vgablt_base; @@ -572,7 +575,7 @@ gd54xx_overlay_draw(svga_t *svga, int displine) 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]; + uint8_t *src2 = &svga->vram[(svga->memaddr - (svga->hdisp * bytesperpix)) & svga->vram_display_mask]; int occl; int ckval; @@ -1252,7 +1255,7 @@ gd54xx_out(uint16_t addr, uint8_t val, void *priv) 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->memaddr_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5); } else { svga->fullchange = changeframecount; @@ -1750,7 +1753,8 @@ gd543x_recalc_mapping(gd54xx_t *gd54xx) } else mem_mapping_disable(&gd54xx->mmio_mapping); } else { - if ((svga->crtc[0x27] <= CIRRUS_ID_CLGD5429) || (!gd54xx->pci && !gd54xx->vlb)) { + if ((svga->crtc[0x27] <= CIRRUS_ID_CLGD5429) || + (!gd54xx->pci && !gd54xx->vlb)) { if (svga->gdcreg[0x0b] & CIRRUS_BANKING_GRANULARITY_16K) { base = (svga->seqregs[0x07] & 0xf0) << 16; size = 1 * 1024 * 1024; @@ -1770,7 +1774,10 @@ gd543x_recalc_mapping(gd54xx_t *gd54xx) else size = 4 * 1024 * 1024; } else { /*VLB/ISA/MCA*/ - base = 128 * 1024 * 1024; + if (gd54xx->vlb_lfb_base != 0x00000000) + base = gd54xx->vlb_lfb_base; + else + base = 128 * 1024 * 1024; if (svga->crtc[0x27] >= CIRRUS_ID_CLGD5436) size = 16 * 1024 * 1024; else @@ -1868,7 +1875,7 @@ gd54xx_recalctimings(svga_t *svga) } else if (svga->gdcreg[5] & 0x40) svga->render = svga_render_8bpp_lowres; - svga->ma_latch |= ((svga->crtc[0x1b] & 0x01) << 16) | ((svga->crtc[0x1b] & 0xc) << 15); + svga->memaddr_latch |= ((svga->crtc[0x1b] & 0x01) << 16) | ((svga->crtc[0x1b] & 0xc) << 15); svga->bpp = 8; @@ -2257,8 +2264,8 @@ gd54xx_mem_sys_src_write(gd54xx_t *gd54xx, uint8_t val, uint8_t ap) static void gd54xx_write(uint32_t addr, uint8_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) priv; - svga_t *svga = &gd54xx->svga; + svga_t *svga = (svga_t *) priv; + gd54xx_t *gd54xx = (gd54xx_t *) svga->local; if (gd54xx->countminusone && !gd54xx->blt.ms_is_dest && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { @@ -2276,16 +2283,16 @@ gd54xx_write(uint32_t addr, uint8_t val, void *priv) static void gd54xx_writew(uint32_t addr, uint16_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) priv; - svga_t *svga = &gd54xx->svga; + svga_t *svga = (svga_t *) priv; + gd54xx_t *gd54xx = (gd54xx_t *) svga->local; if (gd54xx->countminusone && !gd54xx->blt.ms_is_dest && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { if ((gd54xx->blt.mode & CIRRUS_BLTMODE_COLOREXPAND) && (gd54xx->blt.modeext & CIRRUS_BLTMODEEXT_DWORDGRANULARITY)) val = (val >> 8) | (val << 8); - gd54xx_write(addr, val, gd54xx); - gd54xx_write(addr + 1, val >> 8, gd54xx); + gd54xx_write(addr, val, svga); + gd54xx_write(addr + 1, val >> 8, svga); return; } @@ -2306,18 +2313,18 @@ gd54xx_writew(uint32_t addr, uint16_t val, void *priv) static void gd54xx_writel(uint32_t addr, uint32_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) priv; - svga_t *svga = &gd54xx->svga; + svga_t *svga = (svga_t *) priv; + gd54xx_t *gd54xx = (gd54xx_t *) svga->local; if (gd54xx->countminusone && !gd54xx->blt.ms_is_dest && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { if ((gd54xx->blt.mode & CIRRUS_BLTMODE_COLOREXPAND) && (gd54xx->blt.modeext & CIRRUS_BLTMODEEXT_DWORDGRANULARITY)) val = ((val & 0xff000000) >> 24) | ((val & 0x00ff0000) >> 8) | ((val & 0x0000ff00) << 8) | ((val & 0x000000ff) << 24); - gd54xx_write(addr, val, gd54xx); - gd54xx_write(addr + 1, val >> 8, gd54xx); - gd54xx_write(addr + 2, val >> 16, gd54xx); - gd54xx_write(addr + 3, val >> 24, gd54xx); + gd54xx_write(addr, val, svga); + gd54xx_write(addr + 1, val >> 8, svga); + gd54xx_write(addr + 2, val >> 16, svga); + gd54xx_write(addr + 3, val >> 24, svga); return; } @@ -2875,8 +2882,8 @@ gd54xx_writel_linear(uint32_t addr, uint32_t val, void *priv) static uint8_t gd54xx_read(uint32_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) priv; - svga_t *svga = &gd54xx->svga; + svga_t *svga = (svga_t *) priv; + gd54xx_t *gd54xx = (gd54xx_t *) svga->local; if (gd54xx->countminusone && gd54xx->blt.ms_is_dest && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) @@ -2892,14 +2899,14 @@ gd54xx_read(uint32_t addr, void *priv) static uint16_t gd54xx_readw(uint32_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) priv; - svga_t *svga = &gd54xx->svga; + svga_t *svga = (svga_t *) priv; + gd54xx_t *gd54xx = (gd54xx_t *) svga->local; uint16_t ret; if (gd54xx->countminusone && gd54xx->blt.ms_is_dest && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { - ret = gd54xx_read(addr, priv); - ret |= gd54xx_read(addr + 1, priv) << 8; + ret = gd54xx_read(addr, svga); + ret |= gd54xx_read(addr + 1, svga) << 8; return ret; } @@ -2914,16 +2921,16 @@ gd54xx_readw(uint32_t addr, void *priv) static uint32_t gd54xx_readl(uint32_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) priv; - svga_t *svga = &gd54xx->svga; + svga_t *svga = (svga_t *) priv; + gd54xx_t *gd54xx = (gd54xx_t *) svga->local; uint32_t ret; if (gd54xx->countminusone && gd54xx->blt.ms_is_dest && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { - 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; + ret = gd54xx_read(addr, svga); + ret |= gd54xx_read(addr + 1, svga) << 8; + ret |= gd54xx_read(addr + 2, svga) << 16; + ret |= gd54xx_read(addr + 3, svga) << 24; return ret; } @@ -3114,7 +3121,7 @@ gd543x_mmio_write(uint32_t addr, uint8_t val, void *priv) break; } } else if (gd54xx->mmio_vram_overlap) - gd54xx_write(addr, val, gd54xx); + gd54xx_write(addr, val, svga); } static void @@ -3147,8 +3154,8 @@ gd543x_mmio_writew(uint32_t addr, uint16_t val, void *priv) gd543x_mmio_write(addr, val & 0xff, gd54xx); gd543x_mmio_write(addr + 1, val >> 8, gd54xx); } else { - gd54xx_write(addr, val, gd54xx); - gd54xx_write(addr + 1, val >> 8, gd54xx); + gd54xx_write(addr, val, svga); + gd54xx_write(addr + 1, val >> 8, svga); } } } @@ -3172,10 +3179,10 @@ gd543x_mmio_writel(uint32_t addr, uint32_t val, void *priv) gd543x_mmio_write(addr + 2, val >> 16, gd54xx); gd543x_mmio_write(addr + 3, val >> 24, gd54xx); } else { - gd54xx_write(addr, val, gd54xx); - gd54xx_write(addr + 1, val >> 8, gd54xx); - gd54xx_write(addr + 2, val >> 16, gd54xx); - gd54xx_write(addr + 3, val >> 24, gd54xx); + gd54xx_write(addr, val, svga); + gd54xx_write(addr + 1, val >> 8, svga); + gd54xx_write(addr + 2, val >> 16, svga); + gd54xx_write(addr + 3, val >> 24, svga); } } } @@ -3314,7 +3321,7 @@ gd543x_mmio_read(uint32_t addr, void *priv) break; } } else if (gd54xx->mmio_vram_overlap) - ret = gd54xx_read(addr, gd54xx); + ret = gd54xx_read(addr, svga); else if (gd54xx->countminusone && gd54xx->blt.ms_is_dest && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) ret = gd54xx_mem_sys_dest_read(gd54xx, 0); @@ -3332,7 +3339,7 @@ gd543x_mmio_readw(uint32_t addr, void *priv) if (gd543x_do_mmio(svga, addr)) ret = gd543x_mmio_read(addr, gd54xx) | (gd543x_mmio_read(addr + 1, gd54xx) << 8); else if (gd54xx->mmio_vram_overlap) - ret = gd54xx_read(addr, gd54xx) | (gd54xx_read(addr + 1, gd54xx) << 8); + ret = gd54xx_read(addr, svga) | (gd54xx_read(addr + 1, svga) << 8); else if (gd54xx->countminusone && gd54xx->blt.ms_is_dest && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { ret = gd543x_mmio_read(addr, priv); @@ -3355,7 +3362,7 @@ gd543x_mmio_readl(uint32_t addr, void *priv) (gd543x_mmio_read(addr + 2, gd54xx) << 16) | (gd543x_mmio_read(addr + 3, gd54xx) << 24); else if (gd54xx->mmio_vram_overlap) - ret = gd54xx_read(addr, gd54xx) | (gd54xx_read(addr + 1, gd54xx) << 8) | + ret = gd54xx_read(addr, svga) | (gd54xx_read(addr + 1, svga) << 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)) { @@ -4153,7 +4160,6 @@ gd54xx_reset(void *priv) memset(gd54xx->pci_regs, 0x00, 256); - mem_mapping_set_p(&svga->mapping, gd54xx); mem_mapping_disable(&gd54xx->mmio_mapping); mem_mapping_disable(&gd54xx->linear_mapping); mem_mapping_disable(&gd54xx->aperture2_mapping); @@ -4204,7 +4210,7 @@ gd54xx_reset(void *priv) static void * gd54xx_init(const device_t *info) { - gd54xx_t *gd54xx = malloc(sizeof(gd54xx_t)); + gd54xx_t *gd54xx = calloc(1, sizeof(gd54xx_t)); svga_t *svga = &gd54xx->svga; int id = info->local & 0xff; int vram; @@ -4212,8 +4218,6 @@ gd54xx_init(const device_t *info) const char *romfn1 = NULL; const char *romfn2 = NULL; - memset(gd54xx, 0, sizeof(gd54xx_t)); - gd54xx->pci = !!(info->flags & DEVICE_PCI); gd54xx->vlb = !!(info->flags & DEVICE_VLB); gd54xx->mca = !!(info->flags & DEVICE_MCA); @@ -4224,6 +4228,12 @@ gd54xx_init(const device_t *info) gd54xx->id = id; + if (gd54xx->vlb && ((gd54xx->id == CIRRUS_ID_CLGD5430) || + (gd54xx->id == CIRRUS_ID_CLGD5434) || + (gd54xx->id == CIRRUS_ID_CLGD5434_4) || + (gd54xx->id == CIRRUS_ID_CLGD5440))) + gd54xx->vlb_lfb_base = device_get_config_int("lfb_base") << 20; + switch (id) { case CIRRUS_ID_CLGD5401: romfn = BIOS_GD5401_PATH; @@ -4237,14 +4247,23 @@ gd54xx_init(const device_t *info) break; case CIRRUS_ID_CLGD5420: - romfn = BIOS_GD5420_PATH; + if (info->local & 0x200) + romfn = NULL; + else + romfn = BIOS_GD5420_PATH; break; case CIRRUS_ID_CLGD5422: - case CIRRUS_ID_CLGD5424: romfn = BIOS_GD5422_PATH; break; + case CIRRUS_ID_CLGD5424: + if (info->local & 0x200) + romfn = /*NULL*/ "roms/machines/advantage40xxd/AST101.09A"; + else + romfn = BIOS_GD5422_PATH; + break; + case CIRRUS_ID_CLGD5426: if (info->local & 0x200) romfn = NULL; @@ -4263,7 +4282,10 @@ gd54xx_init(const device_t *info) break; case CIRRUS_ID_CLGD5428: - if (info->local & 0x100) + if (info->local & 0x200) { + romfn = NULL; + gd54xx->has_bios = 0; + } else if (info->local & 0x100) if (gd54xx->vlb) romfn = BIOS_GD5428_DIAMOND_B1_VLB_PATH; else { @@ -4307,7 +4329,8 @@ gd54xx_init(const device_t *info) break; case CIRRUS_ID_CLGD5436: - if (info->local & 0x200) { + if ((info->local & 0x200) && + !strstr(machine_get_internal_name(), "sb486pv")) { romfn = NULL; gd54xx->has_bios = 0; } else @@ -4382,7 +4405,7 @@ gd54xx_init(const device_t *info) rom_init_interleaved(&gd54xx->bios_rom, BIOS_GD5428_BOCA_ISA_PATH_1, BIOS_GD5428_BOCA_ISA_PATH_2, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); - if (info->flags & DEVICE_ISA) + if ((info->flags & DEVICE_ISA) || (info->flags & DEVICE_ISA16)) video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_gd54xx_isa); else if (info->flags & DEVICE_PCI) video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_gd54xx_pci); @@ -4403,7 +4426,13 @@ gd54xx_init(const device_t *info) if ((vram == 1) || (vram >= 256 && vram <= 1024)) svga->decode_mask = gd54xx->vram_mask; + svga->read = gd54xx_read; + svga->readw = gd54xx_readw; + svga->write = gd54xx_write; + svga->writew = gd54xx_writew; if (gd54xx->bit32) { + svga->readl = gd54xx_readl; + svga->writel = gd54xx_writel; mem_mapping_set_handler(&svga->mapping, gd54xx_read, gd54xx_readw, gd54xx_readl, gd54xx_write, gd54xx_writew, gd54xx_writel); mem_mapping_add(&gd54xx->mmio_mapping, 0, 0, @@ -4423,6 +4452,8 @@ gd54xx_init(const device_t *info) gd5480_vgablt_write, gd5480_vgablt_writew, gd5480_vgablt_writel, NULL, MEM_MAPPING_EXTERNAL, gd54xx); } else { + svga->readl = NULL; + svga->writel = NULL; mem_mapping_set_handler(&svga->mapping, gd54xx_read, gd54xx_readw, NULL, gd54xx_write, gd54xx_writew, NULL); mem_mapping_add(&gd54xx->mmio_mapping, 0, 0, @@ -4444,8 +4475,8 @@ gd54xx_init(const device_t *info) } io_sethandler(0x03c0, 0x0020, gd54xx_in, NULL, NULL, gd54xx_out, NULL, NULL, gd54xx); - if (gd54xx->pci && id >= CIRRUS_ID_CLGD5430) { - if (romfn == NULL) + if (gd54xx->pci && (id >= CIRRUS_ID_CLGD5430)) { + if (info->local & 0x200) pci_add_card(PCI_ADD_VIDEO, cl_pci_read, cl_pci_write, gd54xx, &gd54xx->pci_slot); else pci_add_card(PCI_ADD_NORMAL, cl_pci_read, cl_pci_write, gd54xx, &gd54xx->pci_slot); @@ -4455,7 +4486,6 @@ gd54xx_init(const device_t *info) if ((id <= CIRRUS_ID_CLGD5429) || (!gd54xx->pci && !gd54xx->vlb)) mem_mapping_set_base_ignore(&gd54xx->linear_mapping, 0xff000000); - mem_mapping_set_p(&svga->mapping, gd54xx); mem_mapping_disable(&gd54xx->mmio_mapping); mem_mapping_disable(&gd54xx->linear_mapping); mem_mapping_disable(&gd54xx->aperture2_mapping); @@ -4518,6 +4548,8 @@ gd54xx_init(const device_t *info) gd54xx->overlay.colorkeycompare = 0xff; + svga->local = gd54xx; + return gd54xx; } @@ -4693,218 +4725,209 @@ gd54xx_force_redraw(void *priv) // clang-format off static const device_config_t gd542x_config[] = { { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "512 KB", - .value = 512 - }, - { - .description = "1 MB", - .value = 1024 - }, - { - .description = "" - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 512, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "512 KB", .value = 512 }, + { .description = "1 MB", .value = 1024 }, + { .description = "" } }, - .default_int = 512 + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t gd5426_config[] = { { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "512 KB", - .value = 512 - }, - { - .description = "1 MB", - .value = 1024 - }, - { - .description = "2 MB", - .value = 2048 - }, - { - .description = "" - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2048, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "512 KB", .value = 512 }, + { .description = "1 MB", .value = 1024 }, + { .description = "2 MB", .value = 2048 }, + { .description = "" } }, - .default_int = 2048 + .bios = { { 0 } } }, - { - .type = CONFIG_END - } -}; - -static const device_config_t gd5428_onboard_config[] = { - { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "512 KB", - .value = 512 - }, - { - .description = "1 MB", - .value = 1024 - }, - { - .description = "2 MB", - .value = 2048 - }, - { - .description = "" - } - }, - .default_int = 2048 - }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t gd5429_config[] = { { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "1 MB", - .value = 1 - }, - { - .description = "2 MB", - .value = 2 - }, - { - .description = "" - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "1 MB", .value = 1 }, + { .description = "2 MB", .value = 2 }, + { .description = "" } }, - .default_int = 2 + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } +}; + +static const device_config_t gd5430_vlb_config[] = { + { + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "1 MB", .value = 1 }, + { .description = "2 MB", .value = 2 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .type = CONFIG_END - } + .name = "lfb_base", + .description = "Linear framebuffer base", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2048, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "32 MB", .value = 32 }, + { .description = "64 MB", .value = 64 }, + { .description = "2048 MB", .value = 2048 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t gd5440_onboard_config[] = { { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "1 MB", - .value = 1 - }, - { - .description = "2 MB", - .value = 2 - }, - { - .description = "" - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "1 MB", .value = 1 }, + { .description = "2 MB", .value = 2 }, + { .description = "" } }, - .default_int = 2 + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t gd5434_config[] = { { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "1 MB", - .value = 1 - }, - { - .description = "2 MB", - .value = 2 - }, - { - .description = "4 MB", - .value = 4 - }, - { - .description = "" - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 4, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "1 MB", .value = 1 }, + { .description = "2 MB", .value = 2 }, + { .description = "4 MB", .value = 4 }, + { .description = "" } }, - .default_int = 4 + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } +}; + +static const device_config_t gd5434_vlb_config[] = { + { + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 4, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "1 MB", .value = 1 }, + { .description = "2 MB", .value = 2 }, + { .description = "4 MB", .value = 4 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .type = CONFIG_END - } + .name = "lfb_base", + .description = "Linear framebuffer base", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2048, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "32 MB", .value = 32 }, + { .description = "64 MB", .value = 64 }, + { .description = "2048 MB", .value = 2048 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t gd5434_onboard_config[] = { { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "1 MB", - .value = 1 - }, - { - .description = "2 MB", - .value = 2 - }, - { - .description = "4 MB", - .value = 4 - }, - { - .description = "" - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 4, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "1 MB", .value = 1 }, + { .description = "2 MB", .value = 2 }, + { .description = "4 MB", .value = 4 }, + { .description = "" } }, - .default_int = 4 + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t gd5480_config[] = { { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "2 MB", - .value = 2 - }, - { - .description = "4 MB", - .value = 4 - }, - { - .description = "" - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 4, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "2 MB", .value = 2 }, + { .description = "4 MB", .value = 4 }, + { .description = "" } }, - .default_int = 4 + .bios = { { 0 } } }, - { - .type = -1 - } + { .name = "", .description = "", .type = CONFIG_END } }; // clang-format on @@ -4916,7 +4939,7 @@ const device_t gd5401_isa_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5401_available }, + .available = gd5401_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = NULL, @@ -4930,7 +4953,7 @@ const device_t gd5402_isa_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5402_available }, + .available = gd5402_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = NULL, @@ -4939,12 +4962,12 @@ const device_t gd5402_isa_device = { const device_t gd5402_onboard_device = { .name = "Cirrus Logic GD5402 (ISA) (ACUMOS AVGA2) (On-Board)", .internal_name = "cl_gd5402_onboard", - .flags = DEVICE_AT | DEVICE_ISA, + .flags = DEVICE_ISA16, .local = CIRRUS_ID_CLGD5402 | 0x200, .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = NULL }, + .available = NULL, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = NULL, @@ -4953,12 +4976,26 @@ const device_t gd5402_onboard_device = { const device_t gd5420_isa_device = { .name = "Cirrus Logic GD5420 (ISA)", .internal_name = "cl_gd5420_isa", - .flags = DEVICE_AT | DEVICE_ISA, + .flags = DEVICE_ISA16, .local = CIRRUS_ID_CLGD5420, .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5420_available }, + .available = gd5420_available, + .speed_changed = gd54xx_speed_changed, + .force_redraw = gd54xx_force_redraw, + .config = gd542x_config, +}; + +const device_t gd5420_onboard_device = { + .name = "Cirrus Logic GD5420 (ISA) (On-Board)", + .internal_name = "cl_gd5420_onboard", + .flags = DEVICE_ISA16, + .local = CIRRUS_ID_CLGD5420 | 0x200, + .init = gd54xx_init, + .close = gd54xx_close, + .reset = gd54xx_reset, + .available = NULL, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd542x_config, @@ -4967,12 +5004,12 @@ const device_t gd5420_isa_device = { const device_t gd5422_isa_device = { .name = "Cirrus Logic GD5422 (ISA)", .internal_name = "cl_gd5422_isa", - .flags = DEVICE_AT | DEVICE_ISA, + .flags = DEVICE_ISA16, .local = CIRRUS_ID_CLGD5422, .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5422_available }, /* Common BIOS between 5422 and 5424 */ + .available = gd5422_available, /* Common BIOS between 5422 and 5424 */ .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd542x_config, @@ -4986,7 +5023,21 @@ const device_t gd5424_vlb_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5422_available }, /* Common BIOS between 5422 and 5424 */ + .available = gd5422_available, /* Common BIOS between 5422 and 5424 */ + .speed_changed = gd54xx_speed_changed, + .force_redraw = gd54xx_force_redraw, + .config = gd542x_config, +}; + +const device_t gd5424_onboard_device = { + .name = "Cirrus Logic GD5424 (VLB) (On-Board)", + .internal_name = "cl_gd5424_onboard", + .flags = DEVICE_VLB, + .local = CIRRUS_ID_CLGD5424 | 0x200, + .init = gd54xx_init, + .close = gd54xx_close, + .reset = gd54xx_reset, + .available = NULL, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd542x_config, @@ -4995,12 +5046,12 @@ const device_t gd5424_vlb_device = { const device_t gd5426_isa_device = { .name = "Cirrus Logic GD5426 (ISA)", .internal_name = "cl_gd5426_isa", - .flags = DEVICE_AT | DEVICE_ISA, + .flags = DEVICE_ISA16, .local = CIRRUS_ID_CLGD5426, .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5428_isa_available }, + .available = gd5428_isa_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5426_config @@ -5010,12 +5061,12 @@ const device_t gd5426_isa_device = { const device_t gd5426_diamond_speedstar_pro_a1_isa_device = { .name = "Cirrus Logic GD5426 (ISA) (Diamond SpeedStar Pro Rev. A1)", .internal_name = "cl_gd5426_diamond_a1_isa", - .flags = DEVICE_AT | DEVICE_ISA, + .flags = DEVICE_ISA16, .local = CIRRUS_ID_CLGD5426 | 0x100, .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5426_diamond_a1_available }, + .available = gd5426_diamond_a1_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5426_config @@ -5029,7 +5080,7 @@ const device_t gd5426_vlb_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5428_available }, + .available = gd5428_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5426_config @@ -5043,7 +5094,7 @@ const device_t gd5426_onboard_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = NULL }, + .available = NULL, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = NULL @@ -5052,12 +5103,12 @@ const device_t gd5426_onboard_device = { const device_t gd5428_isa_device = { .name = "Cirrus Logic GD5428 (ISA)", .internal_name = "cl_gd5428_isa", - .flags = DEVICE_AT | DEVICE_ISA, + .flags = DEVICE_ISA16, .local = CIRRUS_ID_CLGD5428, .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5428_isa_available }, + .available = gd5428_isa_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5426_config @@ -5071,7 +5122,7 @@ const device_t gd5428_vlb_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5428_available }, + .available = gd5428_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5426_config @@ -5086,7 +5137,7 @@ const device_t gd5428_diamond_speedstar_pro_b1_vlb_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5428_diamond_b1_available }, + .available = gd5428_diamond_b1_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5426_config @@ -5095,12 +5146,12 @@ const device_t gd5428_diamond_speedstar_pro_b1_vlb_device = { const device_t gd5428_boca_isa_device = { .name = "Cirrus Logic GD5428 (ISA) (BOCA Research 4610)", .internal_name = "cl_gd5428_boca_isa", - .flags = DEVICE_AT | DEVICE_ISA, + .flags = DEVICE_ISA16, .local = CIRRUS_ID_CLGD5428 | 0x100, .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5428_boca_isa_available }, + .available = gd5428_boca_isa_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5426_config @@ -5114,7 +5165,7 @@ const device_t gd5428_mca_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5428_mca_available }, + .available = gd5428_mca_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = NULL @@ -5128,7 +5179,7 @@ const device_t gd5426_mca_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5426_mca_available }, + .available = gd5426_mca_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5426_config @@ -5137,15 +5188,15 @@ const device_t gd5426_mca_device = { const device_t gd5428_onboard_device = { .name = "Cirrus Logic GD5428 (ISA) (On-Board)", .internal_name = "cl_gd5428_onboard", - .flags = DEVICE_AT | DEVICE_ISA, + .flags = DEVICE_ISA16, .local = CIRRUS_ID_CLGD5428, .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5428_isa_available }, + .available = gd5428_isa_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, - .config = gd5428_onboard_config + .config = gd5426_config }; const device_t gd5428_vlb_onboard_device = { @@ -5156,21 +5207,35 @@ const device_t gd5428_vlb_onboard_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = NULL }, + .available = NULL, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, - .config = gd5428_onboard_config + .config = gd5426_config +}; + +const device_t gd5428_onboard_vlb_device = { + .name = "Cirrus Logic GD5428 (VLB) (On-Board) (Dell)", + .internal_name = "cl_gd5428_onboard_vlb", + .flags = DEVICE_VLB, + .local = CIRRUS_ID_CLGD5428 | 0x200, + .init = gd54xx_init, + .close = gd54xx_close, + .reset = gd54xx_reset, + .available = NULL, + .speed_changed = gd54xx_speed_changed, + .force_redraw = gd54xx_force_redraw, + .config = gd542x_config }; const device_t gd5429_isa_device = { .name = "Cirrus Logic GD5429 (ISA)", .internal_name = "cl_gd5429_isa", - .flags = DEVICE_AT | DEVICE_ISA, + .flags = DEVICE_ISA16, .local = CIRRUS_ID_CLGD5429, .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5429_available }, + .available = gd5429_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5429_config @@ -5184,7 +5249,7 @@ const device_t gd5429_vlb_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5429_available }, + .available = gd5429_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5429_config @@ -5199,10 +5264,10 @@ const device_t gd5430_diamond_speedstar_pro_se_a8_vlb_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5430_diamond_a8_available }, + .available = gd5430_diamond_a8_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, - .config = gd5429_config + .config = gd5430_vlb_config }; const device_t gd5430_vlb_device = { @@ -5213,10 +5278,10 @@ const device_t gd5430_vlb_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5430_orchid_vlb_available }, + .available = gd5430_orchid_vlb_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, - .config = gd5429_config + .config = gd5430_vlb_config }; const device_t gd5430_onboard_vlb_device = { @@ -5227,10 +5292,10 @@ const device_t gd5430_onboard_vlb_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = NULL }, + .available = NULL, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, - .config = gd5429_config + .config = gd5430_vlb_config }; const device_t gd5430_pci_device = { @@ -5241,7 +5306,7 @@ const device_t gd5430_pci_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5430_available }, + .available = gd5430_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5429_config @@ -5255,7 +5320,7 @@ const device_t gd5430_onboard_pci_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = NULL }, + .available = NULL, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5429_config @@ -5264,12 +5329,12 @@ const device_t gd5430_onboard_pci_device = { const device_t gd5434_isa_device = { .name = "Cirrus Logic GD5434 (ISA)", .internal_name = "cl_gd5434_isa", - .flags = DEVICE_AT | DEVICE_ISA, + .flags = DEVICE_ISA16, .local = CIRRUS_ID_CLGD5434, .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5434_isa_available }, + .available = gd5434_isa_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5434_config @@ -5279,12 +5344,12 @@ const device_t gd5434_isa_device = { const device_t gd5434_diamond_speedstar_64_a3_isa_device = { .name = "Cirrus Logic GD5434 (ISA) (Diamond SpeedStar 64 Rev. A3)", .internal_name = "cl_gd5434_diamond_a3_isa", - .flags = DEVICE_AT | DEVICE_ISA, + .flags = DEVICE_ISA16, .local = CIRRUS_ID_CLGD5434 | 0x100, .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5434_diamond_a3_available }, + .available = gd5434_diamond_a3_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5429_config @@ -5298,7 +5363,7 @@ const device_t gd5434_onboard_pci_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = NULL }, + .available = NULL, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5434_onboard_config @@ -5312,10 +5377,10 @@ const device_t gd5434_vlb_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5430_orchid_vlb_available }, + .available = gd5430_orchid_vlb_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, - .config = gd5434_config + .config = gd5434_vlb_config }; const device_t gd5434_pci_device = { @@ -5326,7 +5391,7 @@ const device_t gd5434_pci_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5434_available }, + .available = gd5434_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5434_config @@ -5340,7 +5405,7 @@ const device_t gd5436_onboard_pci_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = NULL }, + .available = NULL, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5434_config @@ -5354,7 +5419,7 @@ const device_t gd5436_pci_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5436_available }, + .available = gd5436_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5434_config @@ -5368,7 +5433,7 @@ const device_t gd5440_onboard_pci_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = NULL }, + .available = NULL, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5440_onboard_config @@ -5382,7 +5447,7 @@ const device_t gd5440_pci_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5440_available }, + .available = gd5440_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5429_config @@ -5396,7 +5461,7 @@ const device_t gd5446_pci_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5446_available }, + .available = gd5446_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5434_config @@ -5410,7 +5475,7 @@ const device_t gd5446_stb_pci_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5446_stb_available }, + .available = gd5446_stb_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5434_config @@ -5424,7 +5489,7 @@ const device_t gd5480_pci_device = { .init = gd54xx_init, .close = gd54xx_close, .reset = gd54xx_reset, - { .available = gd5480_available }, + .available = gd5480_available, .speed_changed = gd54xx_speed_changed, .force_redraw = gd54xx_force_redraw, .config = gd5480_config diff --git a/src/video/vid_compaq_cga.c b/src/video/vid_compaq_cga.c deleted file mode 100644 index 430c7a64d..000000000 --- a/src/video/vid_compaq_cga.c +++ /dev/null @@ -1,502 +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. - * - * Emulation of the Compaq CGA graphics cards. - * - * - * - * Authors: John Elliott, - * Sarah Walker, - * Miran Grca, - * - * Copyright 2016-2019 John Elliott. - * Copyright 2008-2019 Sarah Walker. - * Copyright 2016-2019 Miran Grca. - */ -#include -#include -#include -#include -#include -#include -#include -#define HAVE_STDARG_H -#include <86box/86box.h> -#include "cpu.h" -#include <86box/io.h> -#include <86box/timer.h> -#include <86box/pit.h> -#include <86box/mem.h> -#include <86box/rom.h> -#include <86box/device.h> -#include <86box/video.h> -#include <86box/vid_cga.h> -#include <86box/vid_cga_comp.h> - -#define CGA_RGB 0 -#define CGA_COMPOSITE 1 - -static uint32_t vflags; -static uint8_t mdaattr[256][2][2]; - -typedef struct compaq_cga_t { - cga_t cga; -} compaq_cga_t; - -#ifdef ENABLE_COMPAQ_CGA_LOG -int compaq_cga_do_log = ENABLE_COMPAQ_CGA_LOG; - -static void -compaq_cga_log(const char *fmt, ...) -{ - va_list ap; - - if (compaq_cga_do_log) { - va_start(ap, fmt); - pclog_ex(fmt, ap); - va_end(ap); - } -} -#else -# define compaq_cga_log(fmt, ...) -#endif - -void -compaq_cga_recalctimings(compaq_cga_t *self) -{ - double _dispontime; - double _dispofftime; - double disptime; - disptime = self->cga.crtc[0] + 1; - - _dispontime = self->cga.crtc[1]; - _dispofftime = disptime - _dispontime; - _dispontime *= MDACONST; - _dispofftime *= MDACONST; - self->cga.dispontime = (uint64_t) (_dispontime); - self->cga.dispofftime = (uint64_t) (_dispofftime); -} - -void -compaq_cga_poll(void *priv) -{ - 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; - int c; - int xs_temp; - int ys_temp; - int oldvc; - uint8_t chr; - uint8_t attr; - uint8_t border; - uint8_t cols[4]; - int oldsc; - int underline = 0; - int blink = 0; - - /* If in graphics mode or character height is not 13, behave as CGA */ - if ((self->cga.cgamode & 0x12) || (self->cga.crtc[9] != 13)) { - overscan_x = overscan_y = 16; - cga_poll(&self->cga); - return; - } else - overscan_x = overscan_y = 0; - - /* We are in Compaq 350-line CGA territory */ - if (!self->cga.linepos) { - timer_advance_u64(&self->cga.timer, self->cga.dispofftime); - self->cga.cgastat |= 1; - self->cga.linepos = 1; - oldsc = self->cga.sc; - if ((self->cga.crtc[8] & 3) == 3) - self->cga.sc = ((self->cga.sc << 1) + self->cga.oddeven) & 7; - if (self->cga.cgadispon) { - if (self->cga.displine < self->cga.firstline) { - self->cga.firstline = self->cga.displine; - video_wait_for_buffer(); - compaq_cga_log("Firstline %i\n", self->cga.firstline); - } - self->cga.lastline = self->cga.displine; - - cols[0] = (self->cga.cgacol & 15) + 16; - - for (c = 0; c < 8; c++) { - buffer32->line[self->cga.displine][c] = cols[0]; - if (self->cga.cgamode & 1) - buffer32->line[self->cga.displine][c + (self->cga.crtc[1] << 3) + 8] = cols[0]; - else - buffer32->line[self->cga.displine][c + (self->cga.crtc[1] << 4) + 8] = cols[0]; - } - - if (self->cga.cgamode & 1) { - for (x = 0; x < self->cga.crtc[1]; x++) { - chr = self->cga.charbuffer[x << 1]; - attr = self->cga.charbuffer[(x << 1) + 1]; - drawcursor = ((self->cga.ma == ca) && self->cga.con && self->cga.cursoron); - - if (vflags) { - underline = 0; - blink = ((self->cga.cgablink & 8) && (self->cga.cgamode & 0x20) && (attr & 0x80) && !drawcursor); - } - - if (vflags && (self->cga.cgamode & 0x80)) { - cols[0] = mdaattr[attr][blink][0]; - cols[1] = mdaattr[attr][blink][1]; - - if ((self->cga.sc == 12) && ((attr & 7) == 1)) - underline = 1; - } else if (self->cga.cgamode & 0x20) { - cols[1] = (attr & 15) + 16; - cols[0] = ((attr >> 4) & 7) + 16; - - if (vflags) { - if (blink) - cols[1] = cols[0]; - } else { - if ((self->cga.cgablink & 8) && (attr & 0x80) && !self->cga.drawcursor) - cols[1] = cols[0]; - } - } else { - cols[1] = (attr & 15) + 16; - cols[0] = (attr >> 4) + 16; - } - - if (vflags && underline) { - for (c = 0; c < 8; c++) - buffer32->line[self->cga.displine][(x << 3) + c + 8] = mdaattr[attr][blink][1]; - } else if (drawcursor) { - for (c = 0; c < 8; c++) - buffer32->line[self->cga.displine][(x << 3) + c + 8] = cols[(fontdatm[chr + self->cga.fontbase][self->cga.sc & 15] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; - } else { - for (c = 0; c < 8; c++) - buffer32->line[self->cga.displine][(x << 3) + c + 8] = cols[(fontdatm[chr + self->cga.fontbase][self->cga.sc & 15] & (1 << (c ^ 7))) ? 1 : 0]; - } - self->cga.ma++; - } - } 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]; - drawcursor = ((self->cga.ma == ca) && self->cga.con && self->cga.cursoron); - - if (vflags) { - underline = 0; - blink = ((self->cga.cgablink & 8) && (self->cga.cgamode & 0x20) && (attr & 0x80) && !drawcursor); - } - - if (vflags && (self->cga.cgamode & 0x80)) { - cols[0] = mdaattr[attr][blink][0]; - cols[1] = mdaattr[attr][blink][1]; - if (self->cga.sc == 12 && (attr & 7) == 1) - underline = 1; - } else if (self->cga.cgamode & 0x20) { - cols[1] = (attr & 15) + 16; - cols[0] = ((attr >> 4) & 7) + 16; - - if (vflags) { - if (blink) - cols[1] = cols[0]; - } else { - if ((self->cga.cgablink & 8) && (attr & 0x80) && !self->cga.drawcursor) - cols[1] = cols[0]; - } - } else { - cols[1] = (attr & 15) + 16; - cols[0] = (attr >> 4) + 16; - } - self->cga.ma++; - - if (vflags && underline) { - for (c = 0; c < 8; c++) - buffer32->line[self->cga.displine][(x << 4) + (c << 1) + 8] = buffer32->line[self->cga.displine][(x << 4) + (c << 1) + 9] = mdaattr[attr][blink][1]; - } else if (drawcursor) { - for (c = 0; c < 8; c++) - buffer32->line[self->cga.displine][(x << 4) + (c << 1) + 8] = buffer32->line[self->cga.displine][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdatm[chr + self->cga.fontbase][self->cga.sc & 15] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; - } else { - for (c = 0; c < 8; c++) - buffer32->line[self->cga.displine][(x << 4) + (c << 1) + 8] = buffer32->line[self->cga.displine][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdatm[chr + self->cga.fontbase][self->cga.sc & 15] & (1 << (c ^ 7))) ? 1 : 0]; - } - } - } - } else { - cols[0] = (self->cga.cgacol & 15) + 16; - - if (self->cga.cgamode & 1) - hline(buffer32, 0, self->cga.displine, (self->cga.crtc[1] << 3) + 16, cols[0]); - else - hline(buffer32, 0, self->cga.displine, (self->cga.crtc[1] << 4) + 16, cols[0]); - } - - if (self->cga.cgamode & 1) - x = (self->cga.crtc[1] << 3) + 16; - else - x = (self->cga.crtc[1] << 4) + 16; - - if (self->cga.composite) { - if (self->cga.cgamode & 0x10) - border = 0x00; - else - border = self->cga.cgacol & 0x0f; - - if (vflags) - Composite_Process(self->cga.cgamode & 0x7f, border, x >> 2, buffer32->line[self->cga.displine]); - else - Composite_Process(self->cga.cgamode, border, x >> 2, buffer32->line[self->cga.displine]); - } else - video_process_8(x, self->cga.displine); - - self->cga.sc = oldsc; - if (self->cga.vc == self->cga.crtc[7] && !self->cga.sc) - self->cga.cgastat |= 8; - self->cga.displine++; - if (self->cga.displine >= 500) - self->cga.displine = 0; - } else { - timer_advance_u64(&self->cga.timer, self->cga.dispontime); - self->cga.linepos = 0; - if (self->cga.vsynctime) { - self->cga.vsynctime--; - if (!self->cga.vsynctime) - self->cga.cgastat &= ~8; - } - - if (self->cga.sc == (self->cga.crtc[11] & 31) || ((self->cga.crtc[8] & 3) == 3 && self->cga.sc == ((self->cga.crtc[11] & 31) >> 1))) { - self->cga.con = 0; - self->cga.coff = 1; - } - if ((self->cga.crtc[8] & 3) == 3 && self->cga.sc == (self->cga.crtc[9] >> 1)) - self->cga.maback = self->cga.ma; - if (self->cga.vadj) { - self->cga.sc++; - self->cga.sc &= 31; - self->cga.ma = self->cga.maback; - self->cga.vadj--; - if (!self->cga.vadj) { - self->cga.cgadispon = 1; - self->cga.ma = self->cga.maback = (self->cga.crtc[13] | (self->cga.crtc[12] << 8)) & 0x3fff; - self->cga.sc = 0; - } - } else if (self->cga.sc == self->cga.crtc[9]) { - self->cga.maback = self->cga.ma; - self->cga.sc = 0; - oldvc = self->cga.vc; - self->cga.vc++; - self->cga.vc &= 127; - - if (self->cga.vc == self->cga.crtc[6]) - self->cga.cgadispon = 0; - - if (oldvc == self->cga.crtc[4]) { - self->cga.vc = 0; - self->cga.vadj = self->cga.crtc[5]; - - if (!self->cga.vadj) - self->cga.cgadispon = 1; - - if (!self->cga.vadj) - self->cga.ma = self->cga.maback = (self->cga.crtc[13] | (self->cga.crtc[12] << 8)) & 0x3fff; - - if ((self->cga.crtc[10] & 0x60) == 0x20) - self->cga.cursoron = 0; - else - self->cga.cursoron = self->cga.cgablink & 8; - } - - if (self->cga.vc == self->cga.crtc[7]) { - self->cga.cgadispon = 0; - self->cga.displine = 0; - self->cga.vsynctime = 16; - - if (self->cga.crtc[7]) { - compaq_cga_log("Lastline %i Firstline %i %i\n", self->cga.lastline, - self->cga.firstline, self->cga.lastline - self->cga.firstline); - - if (self->cga.cgamode & 1) - x = (self->cga.crtc[1] << 3) + 16; - else - x = (self->cga.crtc[1] << 4) + 16; - - self->cga.lastline++; - - xs_temp = x; - ys_temp = (self->cga.lastline - self->cga.firstline); - - if ((xs_temp > 0) && (ys_temp > 0)) { - if (xs_temp < 64) - xs_temp = 656; - if (ys_temp < 32) - ys_temp = 400; - if (!enable_overscan) - xs_temp -= 16; - - if ((self->cga.cgamode & 8) && ((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)); - - if (video_force_resize_get()) - video_force_resize_set(0); - } - - if (enable_overscan) - video_blit_memtoscreen(0, self->cga.firstline - 8, xsize, (self->cga.lastline - self->cga.firstline) + 16); - else - video_blit_memtoscreen(8, self->cga.firstline, xsize, self->cga.lastline - self->cga.firstline); - } - - frames++; - - video_res_x = xsize; - if (enable_overscan) - xsize -= 16; - video_res_y = ysize; - if (self->cga.cgamode & 1) { - video_res_x /= 8; - video_res_y /= self->cga.crtc[9] + 1; - video_bpp = 0; - } else if (!(self->cga.cgamode & 2)) { - video_res_x /= 16; - video_res_y /= self->cga.crtc[9] + 1; - video_bpp = 0; - } else if (!(self->cga.cgamode & 16)) { - video_res_x /= 2; - video_bpp = 2; - } else - video_bpp = 1; - } - - self->cga.firstline = 1000; - self->cga.lastline = 0; - self->cga.cgablink++; - self->cga.oddeven ^= 1; - } - } else { - self->cga.sc++; - self->cga.sc &= 31; - self->cga.ma = self->cga.maback; - } - - 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))) - 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]; - } - } -} - -void * -compaq_cga_init(const device_t *info) -{ - int display_type; - compaq_cga_t *self = malloc(sizeof(compaq_cga_t)); - memset(self, 0, sizeof(compaq_cga_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"); - self->cga.snow_enabled = device_get_config_int("snow_enabled"); - - self->cga.vram = malloc(0x4000); - - cga_comp_init(self->cga.revision); - timer_add(&self->cga.timer, compaq_cga_poll, self, 1); - mem_mapping_add(&self->cga.mapping, 0xb8000, 0x08000, cga_read, NULL, NULL, cga_write, NULL, NULL, NULL /*self->cga.vram*/, MEM_MAPPING_EXTERNAL, self); - io_sethandler(0x03d0, 0x0010, cga_in, NULL, NULL, cga_out, NULL, NULL, self); - - if (info->local) { - 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; - } - - vflags = info->local; - - overscan_x = overscan_y = 16; - - self->cga.rgb_type = device_get_config_int("rgb_type"); - cga_palette = (self->cga.rgb_type << 1); - cgapal_rebuild(); - - self->cga.crtc[9] = 13; - - return self; -} - -void -compaq_cga_close(void *priv) -{ - compaq_cga_t *self = (compaq_cga_t *) priv; - - free(self->cga.vram); - free(self); -} - -void -compaq_cga_speed_changed(void *priv) -{ - compaq_cga_t *self = (compaq_cga_t *) priv; - - if (self->cga.crtc[9] == 13) /* Character height */ - compaq_cga_recalctimings(self); - else - cga_recalctimings(&self->cga); -} - -extern const device_config_t cga_config[]; - -const device_t compaq_cga_device = { - .name = "Compaq CGA", - .internal_name = "compaq_cga", - .flags = DEVICE_ISA, - .local = 0, - .init = compaq_cga_init, - .close = compaq_cga_close, - .reset = NULL, - { .available = NULL }, - .speed_changed = compaq_cga_speed_changed, - .force_redraw = NULL, - .config = cga_config -}; - -const device_t compaq_cga_2_device = { - .name = "Compaq CGA 2", - .internal_name = "compaq_cga_2", - .flags = DEVICE_ISA, - .local = 1, - .init = compaq_cga_init, - .close = compaq_cga_close, - .reset = NULL, - { .available = NULL }, - .speed_changed = compaq_cga_speed_changed, - .force_redraw = NULL, - .config = cga_config -}; diff --git a/src/video/vid_ega.c b/src/video/vid_ega.c index fccd4f629..21671f4b3 100644 --- a/src/video/vid_ega.c +++ b/src/video/vid_ega.c @@ -45,26 +45,11 @@ void ega_doblit(int wx, int wy, ega_t *ega); #define BIOS_ISKRA_PATH "roms/video/ega/143-02.bin", "roms/video/ega/143-03.bin" #define BIOS_TSENG_PATH "roms/video/ega/EGA ET2000.BIN" -enum { - EGA_IBM = 0, - EGA_COMPAQ, - EGA_SUPEREGA, - EGA_ATI800P, - EGA_ISKRA, - EGA_TSENG -}; - -enum { - EGA_TYPE_IBM = 0, - EGA_TYPE_OTHER = 1, - EGA_TYPE_COMPAQ = 2 -}; - 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 int active = 0; -static uint32_t pallook16[256]; -static uint32_t pallook64[256]; +uint32_t pallook16[256]; +uint32_t pallook64[256]; static int ega_type = EGA_TYPE_IBM; static int old_overscan_color = 0; @@ -82,8 +67,12 @@ ega_out(uint16_t addr, uint8_t val, void *priv) ega_t *ega = (ega_t *) priv; uint8_t o; uint8_t old; + int type = ega_type; + int atype = ega->actual_type; + uint8_t gdcmask = (ega_type == EGA_SUPEREGA) ? 0xff : 0x0f; + uint8_t crtcmask = (atype == EGA_SUPEREGA) ? 0xff : 0x1f; - if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(ega->miscout & 1)) + if (((((addr & 0xfff0) == 0x3d0) || ((addr & 0xfff0) == 0x2d0)) || (((addr & 0xfff0) == 0x3b0) || ((addr & 0xfff0) == 0x2b0))) && !(ega->miscout & 1)) addr ^= 0x60; switch (addr) { @@ -105,8 +94,12 @@ ega_out(uint16_t addr, uint8_t val, void *priv) } break; + case 0x2c0: case 0x3c0: + case 0x2c1: case 0x3c1: + if (atype == EGA_SUPEREGA) + val &= 0x7f; /* Bit 7 indicates the flipflop status (read only) */ if (!ega->attrff) { ega->attraddr = val & 31; if ((val & 0x20) != ega->attr_palette_enable) { @@ -117,16 +110,21 @@ ega_out(uint16_t addr, uint8_t val, void *priv) } else { if ((ega->attraddr == 0x13) && (ega->attrregs[0x13] != val)) ega->fullchange = changeframecount; - o = ega->attrregs[ega->attraddr & 31]; - ega->attrregs[ega->attraddr & 31] = val; + uint8_t aidx = ega->attraddr & 31; + o = ega->attrregs[aidx]; + ega->attrregs[aidx] = val; if (ega->attraddr < 16) ega->fullchange = changeframecount; - if (ega->attraddr == 0x10 || ega->attraddr == 0x14 || ega->attraddr < 0x10) { + int is_attr14 = ega->chipset && (ega->attraddr == 0x14); + if ((ega->attraddr == 0x10) || is_attr14 || (ega->attraddr < 0x10)) { 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 - ega->egapal[c] = (ega->attrregs[c] & 0x3f) | ((ega->attrregs[0x14] & 0xc) << 4); + if (ega->chipset) { + if (ega->attrregs[0x10] & 0x80) + ega->egapal[c] = (ega->attrregs[c] & 0xf) | ((ega->attrregs[0x14] & 0xf) << 4); + else + ega->egapal[c] = (ega->attrregs[c] & 0x3f) | ((ega->attrregs[0x14] & 0xc) << 4); + } else + ega->egapal[c] = ega->attrregs[c] & 0x3f; } ega->fullchange = changeframecount; } @@ -144,6 +142,7 @@ ega_out(uint16_t addr, uint8_t val, void *priv) } ega->attrff ^= 1; break; + case 0x2c2: case 0x3c2: o = ega->miscout; egaswitchread = (val & 0xc) >> 2; @@ -151,14 +150,23 @@ ega_out(uint16_t addr, uint8_t val, void *priv) ega->pallook = ega->vres ? pallook16 : pallook64; ega->vidclock = val & 4; ega->miscout = val; - ega->overscan_color = ega->vres ? pallook16[ega->attrregs[0x11] & 0x0f] : pallook64[ega->attrregs[0x11] & 0x3f]; - io_removehandler(0x03a0, 0x0020, ega_in, NULL, NULL, ega_out, NULL, NULL, ega); - if (!(val & 1)) - io_sethandler(0x03a0, 0x0020, ega_in, NULL, NULL, ega_out, NULL, NULL, ega); + ega->overscan_color = ega->vres ? pallook16[ega->attrregs[0x11] & 0x0f] : + pallook64[ega->attrregs[0x11] & 0x3f]; + + uint16_t base_addr = 0x03a0; +#ifdef EGA_ALT_ADDR_SUPPORT + if (ega->alt_addr == 1) + base_addr = 0x02a0; +#endif + if (ega->priv_parent == NULL) { + io_removehandler(base_addr, 0x0020, ega_in, NULL, NULL, ega_out, NULL, NULL, ega); + if (!(val & 1)) + io_sethandler(base_addr, 0x0020, ega_in, NULL, NULL, ega_out, NULL, NULL, ega); + } ega_recalctimings(ega); - if ((ega_type == EGA_TYPE_COMPAQ) && !(val & 0x02)) + if ((type == EGA_TYPE_COMPAQ) && !(val & 0x02)) mem_mapping_disable(&ega->mapping); - else switch (ega->gdcreg[6] & 0xc) { + else switch (ega->gdcreg[6] & 0xc) { case 0x0: /*128k at A0000*/ mem_mapping_set_addr(&ega->mapping, 0xa0000, 0x20000); break; @@ -176,9 +184,11 @@ ega_out(uint16_t addr, uint8_t val, void *priv) break; } break; + case 0x2c4: case 0x3c4: ega->seqaddr = val; break; + case 0x2c5: case 0x3c5: o = ega->seqregs[ega->seqaddr & 0xf]; ega->seqregs[ega->seqaddr & 0xf] = val; @@ -205,16 +215,20 @@ ega_out(uint16_t addr, uint8_t val, void *priv) break; } break; + case 0x2c6: case 0x3c6: - if (ega_type == EGA_TYPE_COMPAQ) + if (type == EGA_TYPE_COMPAQ) ega->ctl_mode = val; break; + case 0x2ce: case 0x3ce: ega->gdcaddr = val; break; - case 0x3cf: - ega->gdcreg[ega->gdcaddr & 15] = val; - switch (ega->gdcaddr & 15) { + case 0x2cf: + case 0x3cf: { + uint8_t reg = ega->gdcaddr & gdcmask; + ega->gdcreg[reg] = val; + switch (reg) { case 2: ega->colourcompare = val; break; @@ -227,9 +241,9 @@ ega_out(uint16_t addr, uint8_t val, void *priv) ega->chain2_read = val & 0x10; break; case 6: - if ((ega_type == EGA_TYPE_COMPAQ) && !(ega->miscout & 0x02)) + if ((type == EGA_TYPE_COMPAQ) && !(ega->miscout & 0x02)) mem_mapping_disable(&ega->mapping); - else switch (val & 0xc) { + else switch (val & 0xc) { case 0x0: /*128k at A0000*/ mem_mapping_set_addr(&ega->mapping, 0xa0000, 0x20000); break; @@ -251,37 +265,58 @@ ega_out(uint16_t addr, uint8_t val, void *priv) ega->colournocare = val; break; + case 0xf8: + ega->la = val; + break; + case 0xf9: + ega->lb = val; + break; + case 0xfa: + ega->lc = val; + break; + case 0xfb: + ega->ld = val; + break; + default: break; } break; + } + case 0x2d0: case 0x3d0: + case 0x2d4: case 0x3d4: - if (ega->chipset) - ega->crtcreg = val & 0x3f; - else - ega->crtcreg = val & 0x1f; + ega->crtcreg = ega->chipset ? (val & 0x3f) : val; return; + case 0x2d1: case 0x3d1: - case 0x3d5: + case 0x2d5: + case 0x3d5: { + int idx = ega->crtcreg; + if (ega->chipset) { - if ((ega->crtcreg < 7) && (ega->crtc[0x11] & 0x80) && !(ega->regs[0xb4] & 0x80)) + if ((idx < 7) && (ega->crtc[0x11] & 0x80) && !(ega->regs[0xb4] & 0x80)) return; - if ((ega->crtcreg == 7) && (ega->crtc[0x11] & 0x80) && !(ega->regs[0xb4] & 0x80)) + if ((idx == 7) && (ega->crtc[0x11] & 0x80) && !(ega->regs[0xb4] & 0x80)) val = (ega->crtc[7] & ~0x10) | (val & 0x10); } else { - if ((ega->crtcreg < 7) && (ega->crtc[0x11] & 0x80)) + idx &= crtcmask; + if ((idx >= 0x19) && (idx <= 0xf6)) return; - if ((ega->crtcreg == 7) && (ega->crtc[0x11] & 0x80)) + if ((idx < 7) && (ega->crtc[0x11] & 0x80)) + return; + if ((idx == 7) && (ega->crtc[0x11] & 0x80)) val = (ega->crtc[7] & ~0x10) | (val & 0x10); } - old = ega->crtc[ega->crtcreg]; - ega->crtc[ega->crtcreg] = val; + old = ega->crtc[idx]; + ega->crtc[idx] = val; if (old != val) { - if (ega->crtcreg < 0xe || ega->crtcreg > 0x10) { - if ((ega->crtcreg == 0xc) || (ega->crtcreg == 0xd)) { + if ((idx < 0xe) || (idx > 0x10)) { + if ((idx == 0xc) || (idx == 0xd)) { ega->fullchange = 3; - ega->ma_latch = ((ega->crtc[0xc] << 8) | ega->crtc[0xd]) + ((ega->crtc[8] & 0x60) >> 5); + ega->memaddr_latch = ((ega->crtc[0xc] << 8) | ega->crtc[0xd]) + + ((ega->crtc[8] & 0x60) >> 5); } else { ega->fullchange = changeframecount; ega_recalctimings(ega); @@ -290,6 +325,8 @@ ega_out(uint16_t addr, uint8_t val, void *priv) } break; + } + default: break; } @@ -298,10 +335,14 @@ ega_out(uint16_t addr, uint8_t val, void *priv) uint8_t ega_in(uint16_t addr, void *priv) { - ega_t *ega = (ega_t *) priv; - uint8_t ret = 0xff; + ega_t *ega = (ega_t *) priv; + uint8_t ret = 0xff; + int type = ega_type; + int atype = ega->actual_type; + uint8_t gdcmask = (atype == EGA_SUPEREGA) ? 0xff : 0x0f; + uint8_t crtcmask = (atype == EGA_SUPEREGA) ? 0xff : 0x1f; - if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(ega->miscout & 1)) + if (((((addr & 0xfff0) == 0x3d0) || ((addr & 0xfff0) == 0x2d0)) || (((addr & 0xfff0) == 0x3b0) || ((addr & 0xfff0) == 0x2b0))) && !(ega->miscout & 1)) addr ^= 0x60; switch (addr) { @@ -322,53 +363,114 @@ ega_in(uint16_t addr, void *priv) } break; + case 0x2c0: case 0x3c0: - if (ega_type == EGA_TYPE_OTHER) - ret = ega->attraddr | ega->attr_palette_enable; - break; + case 0x2c1: case 0x3c1: - if (ega_type == EGA_TYPE_OTHER) - ret = ega->attrregs[ega->attraddr]; + if (type == EGA_TYPE_OTHER) { + int data = (atype == EGA_SUPEREGA) ? (ega->attrff & 1) : (addr & 1); + if (data) + ret = ega->attrregs[ega->attraddr]; + else + ret = ega->attraddr | ega->attr_palette_enable; + if (atype == EGA_SUPEREGA) + /* Bit 7 indicates the flipflop status (read only) */ + ret = (ret & 0x3f) | (ega->attrff ? 0x80 : 0x00); + } break; + case 0x2c2: case 0x3c2: ret = (egaswitches & (8 >> egaswitchread)) ? 0x10 : 0x00; break; + case 0x2c4: case 0x3c4: - if (ega_type == EGA_TYPE_OTHER) - ret = ega->seqaddr; + if (type == EGA_TYPE_OTHER) { + if (atype == EGA_SUPEREGA) + ret = 0x1f | ((ega->miscout & 0x01) << 5); + else + ret = ega->seqaddr; + } break; + case 0x2c5: case 0x3c5: - if (ega_type == EGA_TYPE_OTHER) - ret = ega->seqregs[ega->seqaddr & 0xf]; + if (type == EGA_TYPE_OTHER) { + uint8_t idx = ega->seqaddr & 0xf; + if (idx > 0x04) + ret = ega->chipset ? ega->seqregs[idx] : 0xff; + else + ret = ega->seqregs[idx]; + } break; + case 0x2c6: case 0x3c6: - if (ega_type == EGA_TYPE_COMPAQ) + if (type == EGA_TYPE_COMPAQ) ret = ega->ctl_mode; break; + case 0x2c8: case 0x3c8: - if (ega_type == EGA_TYPE_OTHER) + if (type == EGA_TYPE_OTHER) ret = 2; break; + case 0x2cc: case 0x3cc: - if (ega_type == EGA_TYPE_OTHER) + if (type == EGA_TYPE_OTHER) ret = ega->miscout; break; + case 0x2ce: case 0x3ce: - if (ega_type == EGA_TYPE_OTHER) + if (type == EGA_TYPE_OTHER) { ret = ega->gdcaddr; + if (atype == EGA_SUPEREGA) { + ret = (ret & 0x0f) | 0xe0; + if ((ega->gdcaddr & 0xe0) == 0xe0) + ret |= 0x10; + } + } break; + case 0x2cf: case 0x3cf: - if (ega_type == EGA_TYPE_OTHER) - ret = ega->gdcreg[ega->gdcaddr & 0xf]; + if (type == EGA_TYPE_OTHER) { + uint8_t gidx = ega->gdcaddr & gdcmask; + switch (gidx) { + default: + ret = ega->gdcreg[gidx]; + break; + case 0x09 ... 0xf7: + ret = ega->chipset ? ega->gdcreg[gidx] : 0xff; + break; + case 0xf8: + ret = ega->la; + break; + case 0xf9: + ret = ega->lb; + break; + case 0xfa: + ret = ega->lc; + break; + case 0xfb: + ret = ega->ld; + break; + } + } break; + case 0x2d0: case 0x3d0: + case 0x2d4: case 0x3d4: - if (ega_type == EGA_TYPE_OTHER) + if (type == EGA_TYPE_OTHER) { ret = ega->crtcreg; + if (atype == EGA_SUPEREGA) { + ret = (ret & 0x1f) | 0xc0; + if ((ega->crtcreg & 0xc0) == 0xc0) + ret |= 0x20; + } + } break; + case 0x2d1: case 0x3d1: + case 0x2d5: case 0x3d5: - switch (ega->crtcreg) { + switch (ega->crtcreg & crtcmask) { case 0xc: case 0xd: case 0xe: @@ -377,29 +479,35 @@ ega_in(uint16_t addr, void *priv) break; case 0x10: - if (ega_type == EGA_TYPE_OTHER) + if (type == EGA_TYPE_OTHER) ret = ega->crtc[ega->crtcreg]; else ret = ega->light_pen >> 8; break; case 0x11: - if (ega_type == EGA_TYPE_OTHER) + if (type == EGA_TYPE_OTHER) ret = ega->crtc[ega->crtcreg]; else ret = ega->light_pen & 0xff; break; + case 0x19 ... 0xf6: + if (type == EGA_TYPE_OTHER) + ret = ega->chipset ? ega->crtc[ega->crtcreg] : 0xff; + break; + default: - if (ega_type == EGA_TYPE_OTHER) + if (type == EGA_TYPE_OTHER) ret = ega->crtc[ega->crtcreg]; break; } break; + case 0x2da: case 0x3da: ega->attrff = 0; - if (ega_type == EGA_TYPE_COMPAQ) { - ret = ega->stat & 0xcf; + if (type == EGA_TYPE_COMPAQ) { + ret = ega->status & 0xcf; switch ((ega->attrregs[0x12] >> 4) & 0x03) { case 0x00: /* 00 = Pri. Red (5), Pri. Blue (4) */ @@ -420,12 +528,12 @@ ega_in(uint16_t addr, void *priv) break; } } else { - ega->stat ^= 0x30; /* Fools IBM EGA video BIOS self-test. */ - ret = ega->stat; + ega->status ^= 0x30; /* Fools IBM EGA video BIOS self-test. */ + ret = ega->status; } break; case 0x7c6: - ret = 0xfd; /* EGA mode supported. */ + ret = 0xfd; /* EGA mode supported. */ break; case 0xbc6: /* 0000 = None; @@ -456,6 +564,7 @@ ega_recalctimings(ega_t *ega) double _dispofftime; double disptime; double crtcconst; + double mdiv = (ega->seqregs[1] & 1) ? 8.0 : 9.0; ega->vtotal = ega->crtc[6]; ega->dispend = ega->crtc[0x12]; @@ -464,19 +573,19 @@ ega_recalctimings(ega_t *ega) if (ega->crtc[7] & 1) ega->vtotal |= 0x100; - if (ega->crtc[7] & 32) + if ((ega->actual_type != EGA_SUPEREGA) && (ega->crtc[7] & 32)) ega->vtotal |= 0x200; ega->vtotal += 2; if (ega->crtc[7] & 2) ega->dispend |= 0x100; - if (ega->crtc[7] & 64) + if ((ega->actual_type != EGA_SUPEREGA) && (ega->crtc[7] & 64)) ega->dispend |= 0x200; ega->dispend++; if (ega->crtc[7] & 4) ega->vsyncstart |= 0x100; - if (ega->crtc[7] & 128) + if ((ega->actual_type != EGA_SUPEREGA) && (ega->crtc[7] & 128)) ega->vsyncstart |= 0x200; ega->vsyncstart++; @@ -509,10 +618,7 @@ ega_recalctimings(ega_t *ega) else crtcconst = (cpuclock / 16872000.0 * (double) (1ULL << 32)); } - if (!(ega->seqregs[1] & 1)) - crtcconst *= 9.0; - else - crtcconst *= 8.0; + crtcconst *= mdiv; } else if (ega->eeprom) { clksel = ((ega->miscout & 0xc) >> 2) | ((ega->regs[0xbe] & 0x10) ? 4 : 0); @@ -534,24 +640,18 @@ ega_recalctimings(ega_t *ega) crtcconst = (cpuclock / 36000000.0 * (double) (1ULL << 32)); break; } - if (!(ega->seqregs[1] & 1)) - crtcconst *= 9.0; - else - crtcconst *= 8.0; + crtcconst *= mdiv; } else { if (ega->vidclock) crtcconst = (ega->seqregs[1] & 1) ? MDACONST : (MDACONST * (9.0 / 8.0)); else crtcconst = (ega->seqregs[1] & 1) ? CGACONST : (CGACONST * (9.0 / 8.0)); } - if (!(ega->seqregs[1] & 1)) - ega->dot_clock = crtcconst / 9.0; - else - ega->dot_clock = crtcconst / 8.0; + ega->dot_clock = crtcconst / mdiv; ega->interlace = 0; - ega->ma_latch = (ega->crtc[0xc] << 8) | ega->crtc[0xd]; + ega->memaddr_latch = (ega->crtc[0xc] << 8) | ega->crtc[0xd]; ega->render = ega_render_blank; if (!ega->scrblank && ega->attr_palette_enable) { @@ -560,17 +660,16 @@ ega_recalctimings(ega_t *ega) ega->hdisp *= (ega->seqregs[1] & 1) ? 16 : 18; else ega->hdisp *= (ega->seqregs[1] & 1) ? 8 : 9; - ega->render = ega_render_text; - ega->hdisp_old = ega->hdisp; + ega->render = ega_render_text; } else { ega->hdisp *= (ega->seqregs[1] & 8) ? 16 : 8; - ega->render = ega_render_graphics; - ega->hdisp_old = ega->hdisp; + ega->render = ega_render_graphics; } + ega->hdisp_old = ega->hdisp; } if (ega->chipset) { - if (ega->hdisp > 640) { + if (ega->hdisp >= 800) { ega->dispend <<= 1; ega->vtotal <<= 1; ega->split <<= 1; @@ -598,11 +697,16 @@ ega_recalctimings(ega_t *ega) ega->y_add >>= 1; if (ega->seqregs[1] & 8) { - disptime = (double) ((ega->crtc[0] + 2) << 1); - _dispontime = (double) ((ega->crtc[1] + 1) << 1); + disptime = (double) ((ega->crtc[0] + 2) << 1); + _dispontime = (double) ((ega->crtc[1] + 1) << 1); } else { - disptime = (double) (ega->crtc[0] + 2); - _dispontime = (double) (ega->crtc[1] + 1); + disptime = (double) (ega->crtc[0] + 2); + _dispontime = (double) (ega->crtc[1] + 1); + } + if ((ega->actual_type == EGA_SUPEREGA) && (ega->crtc[0x17] & 0x10) && + (ega->crtc[0xf9] & 0x01)) { + disptime *= 2.0; + _dispontime *= 2.0; } _dispofftime = disptime - _dispontime; _dispontime *= crtcconst; @@ -622,7 +726,7 @@ ega_recalctimings(ega_t *ega) timer_disable(&ega->dot_timer); timer_set_delay_u64(&ega->dot_timer, ega->dot_time); ega->cca = 0; - active = 1; + active = 1; ega->dot = 0; } @@ -634,30 +738,30 @@ ega_recalctimings(ega_t *ega) void ega_dot_poll(void *priv) { - ega_t *ega = (ega_t *) priv; - static uint8_t chr; - static uint8_t attr; - 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 bool blinked = ega->blink & 0x10; - const int dwshift = doublewidth ? 1 : 0; - const int dotwidth = 1 << dwshift; - const int charwidth = dotwidth * (seq9dot ? 9 : 8); - const int cursoron = (ega->sc == (ega->crtc[10] & 31)); - const int cursoraddr = (ega->crtc[0xe] << 8) | ega->crtc[0xf]; - uint32_t addr; - int drawcursor; - uint32_t charaddr; - static int fg = 0; - static int bg = 0; - static uint32_t dat = 0x00000000; - static int cclock = 0; - static int disptime; - static int _dispontime; - static int _dispofftime; + ega_t *ega = (ega_t *) priv; + static uint8_t chr; + static uint8_t attr; + 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 bool blinked = ega->blink & 0x10; + const int dwshift = doublewidth ? 1 : 0; + const int dotwidth = 1 << dwshift; + const int charwidth = dotwidth * (seq9dot ? 9 : 8); + const int cursoron = (ega->scanline == (ega->crtc[10] & 31)); + const int cursoraddr = (ega->crtc[0xe] << 8) | ega->crtc[0xf]; + uint32_t addr; + int drawcursor; + uint32_t charaddr; + static int fg = 0; + static int bg = 0; + static uint32_t dat = 0x00000000; + static int cclock = 0; + static int disptime; + static int _dispontime; + static int _dispofftime; if (ega->seqregs[1] & 8) { disptime = ((ega->crtc[0] + 2) << 1); @@ -690,7 +794,7 @@ ega_dot_poll(void *priv) else charaddr = ega->charseta + (chr * 0x80); - dat = ega->vram[charaddr + (ega->sc << 2)]; + dat = ega->vram[charaddr + (ega->scanline << 2)]; dat <<= 1; if ((chr & ~0x1F) == 0xC0 && attrlinechars) dat |= (dat >> 1) & 1; @@ -729,30 +833,28 @@ void ega_poll(void *priv) { ega_t *ega = (ega_t *) priv; - int x, y; int old_ma; int wx = 640; int wy = 350; - uint32_t blink_delay; if (!ega->linepos) { timer_advance_u64(&ega->timer, ega->dispofftime); - ega->stat |= 1; + ega->status |= 1; ega->linepos = 1; if (ega->dispon) { ega->hdisp_on = 1; - ega->ma &= ega->vrammask; + ega->memaddr &= ega->vrammask; if (ega->firstline == 2000) { ega->firstline = ega->displine; video_wait_for_buffer(); } - old_ma = ega->ma; + old_ma = ega->memaddr; ega->displine *= ega->vres + 1; ega->y_add *= ega->vres + 1; - for (y = 0; y <= ega->vres; y++) { + for (int y = 0; y <= ega->vres; y++) { /* Render scanline */ ega->render(ega); @@ -763,7 +865,7 @@ ega_poll(void *priv) ega->x_add = (overscan_x >> 1) - ega->scrollcache; if (y != ega->vres) { - ega->ma = old_ma; + ega->memaddr = old_ma; ega->displine++; } } @@ -777,11 +879,11 @@ ega_poll(void *priv) ega->displine++; if (ega->interlace) ega->displine++; - if ((ega->stat & 8) && ((ega->displine & 15) == (ega->crtc[0x11] & 15)) && ega->vslines) - ega->stat &= ~8; + if ((ega->status & 8) && ((ega->displine & 15) == (ega->crtc[0x11] & 15)) && ega->vslines) + ega->status &= ~8; ega->vslines++; if (ega->chipset) { - if (ega->hdisp > 640) { + if (ega->hdisp >= 800) { if (ega->displine > 2000) ega->displine = 0; } else { @@ -796,40 +898,43 @@ ega_poll(void *priv) timer_advance_u64(&ega->timer, ega->dispontime); if (ega->dispon) - ega->stat &= ~1; + ega->status &= ~1; ega->hdisp_on = 0; ega->linepos = 0; - if ((ega->sc == (ega->crtc[11] & 31)) || (ega->sc == ega->rowcount)) - ega->con = 0; + if ((ega->scanline == (ega->crtc[11] & 31)) || (ega->scanline == ega->rowcount)) + ega->cursorvisible = 0; if (ega->dispon) { /* TODO: Verify real hardware behaviour for out-of-range fine vertical scroll */ if (ega->linedbl && !ega->linecountff) { ega->linecountff = 1; - ega->ma = ega->maback; - ega->cca = ega->maback; + ega->memaddr = ega->memaddr_backup; + ega->cca = ega->memaddr_backup; } - if (ega->sc == (ega->crtc[9] & 31)) { + if (ega->scanline == (ega->crtc[9] & 31)) { ega->linecountff = 0; - ega->sc = 0; + ega->scanline = 0; - ega->maback += (ega->rowoffset << 3); + ega->memaddr_backup += (ega->rowoffset << 3); if (ega->interlace) - ega->maback += (ega->rowoffset << 3); - ega->maback &= ega->vrammask; - ega->ma = ega->maback; - ega->cca = ega->maback; + ega->memaddr_backup += (ega->rowoffset << 3); + ega->memaddr_backup &= ega->vrammask; + ega->memaddr = ega->memaddr_backup; + ega->cca = ega->memaddr_backup; } else { ega->linecountff = 0; - ega->sc++; - ega->sc &= 31; - ega->ma = ega->maback; - ega->cca = ega->maback; + ega->scanline++; + ega->scanline &= 31; + ega->memaddr = ega->memaddr_backup; + ega->cca = ega->memaddr_backup; } } - ega->vc++; + ega->real_vc++; + if ((ega->actual_type != EGA_SUPEREGA) || !(ega->crtc[0xf9] & 0x02) || + !(ega->real_vc & 1)) + ega->vc++; if (ega->chipset) { - if (ega->hdisp > 640) + if (ega->hdisp >= 800) ega->vc &= 1023; else ega->vc &= 511; @@ -838,17 +943,17 @@ ega_poll(void *priv) 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->rowoffset << 1; + ega->memaddr = ega->memaddr_backup = ega->rowoffset << 1; else - ega->ma = ega->maback = 0; - ega->ma <<= 2; - ega->cca = ega->ma; - ega->maback <<= 2; - ega->sc = 0; + ega->memaddr = ega->memaddr_backup = 0; + ega->memaddr <<= 2; + ega->cca = ega->memaddr; + ega->memaddr_backup <<= 2; + ega->scanline = 0; } if (ega->vc == ega->dispend) { ega->dispon = 0; - blink_delay = (ega->crtc[11] & 0x60) >> 5; + uint32_t blink_delay = (ega->crtc[11] & 0x60) >> 5; if (ega->crtc[10] & 0x20) ega->cursoron = 0; else if (blink_delay == 2) @@ -865,24 +970,28 @@ ega_poll(void *priv) } if (ega->vc == ega->vsyncstart) { ega->dispon = 0; - ega->stat |= 8; + ega->status |= 8; #if 0 picint(1 << 2); #endif - x = ega->hdisp; +// x = ega->hdisp; if (ega->interlace && !ega->oddeven) ega->lastline++; if (ega->interlace && ega->oddeven) ega->firstline--; - wx = x; + wx = ega->hdisp; if (ega->vres) { wy = (ega->lastline - ega->firstline) << 1; + if ((ega->actual_type == EGA_SUPEREGA) && (ega->crtc[0xf9] & 0x02)) + wy >>= 1; ega_doblit(wx, wy, ega); } else { wy = ega->lastline - ega->firstline; + if ((ega->actual_type == EGA_SUPEREGA) && (ega->crtc[0xf9] & 0x02)) + wy >>= 1; ega_doblit(wx, wy, ega); } @@ -900,19 +1009,19 @@ ega_poll(void *priv) ega->vslines = 0; if (ega->interlace && ega->oddeven) - ega->ma = ega->maback = ega->ma_latch + (ega->rowoffset << 1); + ega->memaddr = ega->memaddr_backup = ega->memaddr_latch + (ega->rowoffset << 1); else - ega->ma = ega->maback = ega->ma_latch; - ega->ca = (ega->crtc[0xe] << 8) | ega->crtc[0xf]; + ega->memaddr = ega->memaddr_backup = ega->memaddr_latch; + ega->cursoraddr = (ega->crtc[0xe] << 8) | ega->crtc[0xf]; - ega->ma <<= 2; - ega->maback <<= 2; - ega->ca <<= 2; - ega->cca = ega->ma; + ega->memaddr <<= 2; + ega->memaddr_backup <<= 2; + ega->cursoraddr <<= 2; + ega->cca = ega->memaddr; } if (ega->vc == ega->vtotal) { ega->vc = 0; - ega->sc = (ega->crtc[0x8] & 0x1f); + ega->scanline = (ega->crtc[0x8] & 0x1f); ega->dispon = 1; ega->displine = (ega->interlace && ega->oddeven) ? 1 : 0; @@ -929,8 +1038,8 @@ ega_poll(void *priv) ega->linecountff = 0; } - if (ega->sc == (ega->crtc[10] & 31)) - ega->con = 1; + if (ega->scanline == (ega->crtc[10] & 31)) + ega->cursorvisible = 1; } } @@ -943,9 +1052,6 @@ ega_doblit(int wx, int wy, ega_t *ega) int y_start = enable_overscan ? 0 : (unscaled_overscan_y >> 1); int x_start = enable_overscan ? 0 : (overscan_x >> 1); int bottom = (unscaled_overscan_y >> 1); - uint32_t *p; - int i; - int j; int xs_temp; int ys_temp; @@ -992,17 +1098,17 @@ ega_doblit(int wx, int wy, ega_t *ega) if ((wx >= 160) && ((wy + 1) >= 120)) { /* Draw (overscan_size - scroll size) lines of overscan on top and bottom. */ - for (i = 0; i < ega->y_add; i++) { - p = &buffer32->line[i & 0x7ff][0]; + for (int i = 0; i < ega->y_add; i++) { + uint32_t *p = &buffer32->line[i & 0x7ff][0]; - for (j = 0; j < (xsize + x_add); j++) + for (int j = 0; j < (xsize + x_add); j++) p[j] = ega->overscan_color; } - for (i = 0; i < bottom; i++) { - p = &buffer32->line[(ysize + ega->y_add + i) & 0x7ff][0]; + for (int i = 0; i < bottom; i++) { + uint32_t *p = &buffer32->line[(ysize + ega->y_add + i) & 0x7ff][0]; - for (j = 0; j < (xsize + x_add); j++) + for (int j = 0; j < (xsize + x_add); j++) p[j] = ega->overscan_color; } } @@ -1026,12 +1132,11 @@ ega_remap_cpu_addr(uint32_t inaddr, ega_t *ega) // bit 2: 1 = 128K mapping, 0 = other mapping (from memory decode PROM) a0mux = 0; - if (ega->gdcreg[6] & 2) { + if (ega->gdcreg[6] & 2) a0mux |= 2; - } - if (ega->vram_limit <= 64 * 1024) { + + if (ega->vram_limit <= 64 * 1024) a0mux |= 1; - } switch (ega->gdcreg[6] & 0xC) { case 0x0: // 128K A000 @@ -1098,11 +1203,8 @@ ega_write(uint32_t addr, uint8_t val, void *priv) cycles -= video_timing_write_b; - if (ega->chain2_write) { - writemask2 &= ~0xa; - if (addr & 1) - writemask2 <<= 1; - } + if (ega->chain2_write) + writemask2 &= 0x5 << (addr & 1); addr = ega_remap_cpu_addr(addr, ega); @@ -1282,9 +1384,8 @@ ega_read(uint32_t addr, void *priv) cycles -= video_timing_read_b; - if (ega->chain2_read) { + if (ega->chain2_read) readplane = (readplane & 2) | (addr & 1); - } addr = ega_remap_cpu_addr(addr, ega); @@ -1322,23 +1423,19 @@ ega_read(uint32_t addr, void *priv) void ega_init(ega_t *ega, int monitor_type, int is_mono) { - int c; - int d; - int e; - ega->vram = malloc(0x40000); ega->vrammask = 0x3ffff; - for (c = 0; c < 256; c++) { - e = c; - for (d = 0; d < 8; d++) { + for (uint16_t c = 0; c < 256; c++) { + int e = c; + for (uint8_t d = 0; d < 8; d++) { ega_rotate[d][c] = e; e = (e >> 1) | ((e & 1) ? 0x80 : 0); } } if (is_mono) { - for (c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { if (((c >> 3) & 3) == 0) pallook64[c] = pallook16[c] = makecol32(0, 0, 0); else @@ -1395,9 +1492,14 @@ ega_init(ega_t *ega, int monitor_type, int is_mono) } } - io_sethandler(0x03a0, 0x0020, ega_in, NULL, NULL, ega_out, NULL, NULL, ega); + uint16_t base_addr = 0x03a0; +#ifdef EGA_ALT_ADDR_SUPPORT + if (ega->alt_addr == 1) + base_addr = 0x02a0; +#endif + io_sethandler(base_addr, 0x0020, ega_in, NULL, NULL, ega_out, NULL, NULL, ega); } else { - for (c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { pallook64[c] = makecol32(((c >> 2) & 1) * 0xaa, ((c >> 1) & 1) * 0xaa, (c & 1) * 0xaa); pallook64[c] += makecol32(((c >> 5) & 1) * 0x55, ((c >> 4) & 1) * 0x55, ((c >> 3) & 1) * 0x55); pallook16[c] = makecol32(((c >> 2) & 1) * 0xaa, ((c >> 1) & 1) * 0xaa, (c & 1) * 0xaa); @@ -1411,6 +1513,26 @@ ega_init(ega_t *ega, int monitor_type, int is_mono) ega->pallook = pallook16; + for (uint16_t c = 0; c < 256; c++) { + ega->mda_attr_to_color_table[c][0][0] = ega->mda_attr_to_color_table[c][1][0] = ega->mda_attr_to_color_table[c][1][1] = 16; + if (c & 8) + ega->mda_attr_to_color_table[c][0][1] = 15 + 16; + else + ega->mda_attr_to_color_table[c][0][1] = 7 + 16; + } + ega->mda_attr_to_color_table[0x70][0][1] = 16; + ega->mda_attr_to_color_table[0x70][0][0] = ega->mda_attr_to_color_table[0x70][1][0] = ega->mda_attr_to_color_table[0x70][1][1] = 16 + 15; + ega->mda_attr_to_color_table[0xF0][0][1] = 16; + ega->mda_attr_to_color_table[0xF0][0][0] = ega->mda_attr_to_color_table[0xF0][1][0] = ega->mda_attr_to_color_table[0xF0][1][1] = 16 + 15; + ega->mda_attr_to_color_table[0x78][0][1] = 16 + 7; + ega->mda_attr_to_color_table[0x78][0][0] = ega->mda_attr_to_color_table[0x78][1][0] = ega->mda_attr_to_color_table[0x78][1][1] = 16 + 15; + ega->mda_attr_to_color_table[0xF8][0][1] = 16 + 7; + ega->mda_attr_to_color_table[0xF8][0][0] = ega->mda_attr_to_color_table[0xF8][1][0] = ega->mda_attr_to_color_table[0xF8][1][1] = 16 + 15; + ega->mda_attr_to_color_table[0x00][0][1] = ega->mda_attr_to_color_table[0x00][1][1] = 16; + ega->mda_attr_to_color_table[0x08][0][1] = ega->mda_attr_to_color_table[0x08][1][1] = 16; + ega->mda_attr_to_color_table[0x80][0][1] = ega->mda_attr_to_color_table[0x80][1][1] = 16; + ega->mda_attr_to_color_table[0x88][0][1] = ega->mda_attr_to_color_table[0x88][1][1] = 16; + egaswitches = monitor_type & 0xf; ega->vram_limit = 256 * 1024; @@ -1429,19 +1551,43 @@ ega_init(ega_t *ega, int monitor_type, int is_mono) ega->crtc[0] = 63; ega->crtc[6] = 255; + ega->render_override = NULL; + timer_add(&ega->timer, ega_poll, ega, 1); if (ega_type == EGA_TYPE_COMPAQ) timer_add(&ega->dot_timer, ega_dot_poll, ega, 1); } +void +ega_set_type(void *priv, uint32_t local) +{ + ega_t *ega = (ega_t *) priv; + + if ((local == EGA_IBM) || (local == EGA_ISKRA) || (local == EGA_TSENG)) + ega_type = EGA_TYPE_IBM; + else if (local == EGA_COMPAQ) + ega_type = EGA_TYPE_COMPAQ; + else + ega_type = EGA_TYPE_OTHER; + + ega->actual_type = local; + ega->chipset = 0; + + switch (local) { + default: + break; + case EGA_ATI800P: + ega->chipset = 1; + break; + } +} + static void * ega_standalone_init(const device_t *info) { - ega_t *ega = malloc(sizeof(ega_t)); + ega_t *ega = calloc(1, sizeof(ega_t)); int monitor_type; - memset(ega, 0x00, sizeof(ega_t)); - video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_ega); overscan_x = 16; @@ -1497,7 +1643,7 @@ ega_standalone_init(const device_t *info) } } - monitor_type = device_get_config_int("monitor_type"); + monitor_type = ega->chipset ? 0x09 : device_get_config_int("monitor_type"); ega_init(ega, monitor_type, (monitor_type & 0x0F) == 0x0B); ega->vram_limit = device_get_config_int("memory") * 1024; @@ -1506,12 +1652,19 @@ ega_standalone_init(const device_t *info) mem_mapping_add(&ega->mapping, 0xa0000, 0x20000, ega_read, NULL, NULL, ega_write, NULL, NULL, NULL, MEM_MAPPING_EXTERNAL, ega); if (ega_type == EGA_TYPE_COMPAQ) mem_mapping_disable(&ega->mapping); - io_sethandler(0x03c0, 0x0020, ega_in, NULL, NULL, ega_out, NULL, NULL, ega); + uint16_t addr = 0x03c0; +#ifdef EGA_ALT_ADDR_SUPPORT + if (ega_type == EGA_TYPE_IBM) { + addr = device_get_config_hex16("base"); + if (addr == 0x02c0) + ega->alt_addr = 1; + } +#endif + io_sethandler(addr, 0x0020, ega_in, NULL, NULL, ega_out, NULL, NULL, ega); if (ega->chipset) { io_sethandler(0x01ce, 0x0002, ega_in, NULL, NULL, ega_out, NULL, NULL, ega); - ega->eeprom = malloc(sizeof(ati_eeprom_t)); - memset(ega->eeprom, 0, sizeof(ati_eeprom_t)); + ega->eeprom = calloc(1, sizeof(ati_eeprom_t)); ati_eeprom_load((ati_eeprom_t *) ega->eeprom, "egawonder800p.nvr", 0); } else if (info->local == EGA_COMPAQ) { io_sethandler(0x0084, 0x0001, ega_in, NULL, NULL, ega_out, NULL, NULL, ega); @@ -1587,77 +1740,129 @@ ega_speed_changed(void *priv) 0 = Switch closed (ON); 1 = Switch open (OFF). */ +static const device_config_t ega_ibm_config[] = { + // clang-format off + { + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 256, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "32 KB", .value = 32 }, + { .description = "64 KB", .value = 64 }, + { .description = "128 KB", .value = 128 }, + { .description = "256 KB", .value = 256 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { + .name = "monitor_type", + .description = "Monitor type", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 9, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Monochrome (5151/MDA) (white)", .value = 0x0B | (DISPLAY_WHITE << 4) }, + { .description = "Monochrome (5151/MDA) (green)", .value = 0x0B | (DISPLAY_GREEN << 4) }, + { .description = "Monochrome (5151/MDA) (amber)", .value = 0x0B | (DISPLAY_AMBER << 4) }, + { .description = "Color 40x25 (5153/CGA)", .value = 0x06 }, + { .description = "Color 80x25 (5153/CGA)", .value = 0x07 }, + { .description = "Enhanced Color - Normal Mode (5154/ECD)", .value = 0x08 }, + { .description = "Enhanced Color - Enhanced Mode (5154/ECD)", .value = 0x09 }, + { .description = "" } + }, + .bios = { { 0 } } + }, +#ifdef EGA_ALT_ADDR_SUPPORT + { + .name = "base", + .description = "Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x03c0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "0x3C0", .value = 0x03c0 }, + { .description = "0x2C0", .value = 0x02c0 }, + { .description = "" } + }, + .bios = { { 0 } } + }, +#endif + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on +}; + static const device_config_t ega_config[] = { // clang-format off { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 256, - .selection = { - { - .description = "32 KB", - .value = 32 - }, - { - .description = "64 KB", - .value = 64 - }, - { - .description = "128 KB", - .value = 128 - }, - { - .description = "256 KB", - .value = 256 - }, - { - .description = "" - } - } - }, - { - .name = "monitor_type", - .description = "Monitor type", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "Monochrome (5151/MDA) (white)", - .value = 0x0B | (DISPLAY_WHITE << 4) - }, - { - .description = "Monochrome (5151/MDA) (green)", - .value = 0x0B | (DISPLAY_GREEN << 4) - }, - { - .description = "Monochrome (5151/MDA) (amber)", - .value = 0x0B | (DISPLAY_AMBER << 4) - }, - { - .description = "Color 40x25 (5153/CGA)", - .value = 0x06 - }, - { - .description = "Color 80x25 (5153/CGA)", - .value = 0x07 - }, - { - .description = "Enhanced Color - Normal Mode (5154/ECD)", - .value = 0x08 - }, - { - .description = "Enhanced Color - Enhanced Mode (5154/ECD)", - .value = 0x09 - }, - { - .description = "" - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 256, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "32 KB", .value = 32 }, + { .description = "64 KB", .value = 64 }, + { .description = "128 KB", .value = 128 }, + { .description = "256 KB", .value = 256 }, + { .description = "" } }, - .default_int = 9 + .bios = { { 0 } } }, { - .type = CONFIG_END - } + .name = "monitor_type", + .description = "Monitor type", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 9, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Monochrome (5151/MDA) (white)", .value = 0x0B | (DISPLAY_WHITE << 4) }, + { .description = "Monochrome (5151/MDA) (green)", .value = 0x0B | (DISPLAY_GREEN << 4) }, + { .description = "Monochrome (5151/MDA) (amber)", .value = 0x0B | (DISPLAY_AMBER << 4) }, + { .description = "Color 40x25 (5153/CGA)", .value = 0x06 }, + { .description = "Color 80x25 (5153/CGA)", .value = 0x07 }, + { .description = "Enhanced Color - Normal Mode (5154/ECD)", .value = 0x08 }, + { .description = "Enhanced Color - Enhanced Mode (5154/ECD)", .value = 0x09 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on +}; + +static const device_config_t atiega800p_config[] = { + // clang-format off + { + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 256, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "32 KB", .value = 32 }, + { .description = "64 KB", .value = 64 }, + { .description = "128 KB", .value = 128 }, + { .description = "256 KB", .value = 256 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -1669,10 +1874,10 @@ const device_t ega_device = { .init = ega_standalone_init, .close = ega_close, .reset = NULL, - { .available = ega_standalone_available }, + .available = ega_standalone_available, .speed_changed = ega_speed_changed, .force_redraw = NULL, - .config = ega_config + .config = ega_ibm_config }; const device_t cpqega_device = { @@ -1683,7 +1888,7 @@ const device_t cpqega_device = { .init = ega_standalone_init, .close = ega_close, .reset = NULL, - { .available = cpqega_standalone_available }, + .available = cpqega_standalone_available, .speed_changed = ega_speed_changed, .force_redraw = NULL, .config = ega_config @@ -1697,7 +1902,7 @@ const device_t sega_device = { .init = ega_standalone_init, .close = ega_close, .reset = NULL, - { .available = sega_standalone_available }, + .available = sega_standalone_available, .speed_changed = ega_speed_changed, .force_redraw = NULL, .config = ega_config @@ -1711,10 +1916,10 @@ const device_t atiega800p_device = { .init = ega_standalone_init, .close = ega_close, .reset = NULL, - { .available = atiega800p_standalone_available }, + .available = atiega800p_standalone_available, .speed_changed = ega_speed_changed, .force_redraw = NULL, - .config = ega_config + .config = atiega800p_config }; const device_t iskra_ega_device = { @@ -1725,7 +1930,7 @@ const device_t iskra_ega_device = { .init = ega_standalone_init, .close = ega_close, .reset = NULL, - { .available = iskra_ega_standalone_available }, + .available = iskra_ega_standalone_available, .speed_changed = ega_speed_changed, .force_redraw = NULL, .config = ega_config @@ -1739,7 +1944,7 @@ const device_t et2000_device = { .init = ega_standalone_init, .close = ega_close, .reset = NULL, - { .available = et2000_standalone_available }, + .available = et2000_standalone_available, .speed_changed = ega_speed_changed, .force_redraw = NULL, .config = ega_config diff --git a/src/video/vid_ega_render.c b/src/video/vid_ega_render.c index fe2632574..c1c44dfdb 100644 --- a/src/video/vid_ega_render.c +++ b/src/video/vid_ega_render.c @@ -107,6 +107,11 @@ ega_render_overscan_right(ega_t *ega) void ega_render_text(ega_t *ega) { + if (ega->render_override) { + ega->render_override(ega->priv_parent); + return; + } + if ((ega->displine + ega->y_add) < 0) return; @@ -118,6 +123,7 @@ ega_render_text(ega_t *ega) 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 monoattrs = (ega->attrregs[0x10] & 2); const bool crtcreset = ((ega->crtc[0x17] & 0x80) == 0); const bool seq9dot = ((ega->seqregs[1] & 1) == 0); const int dwshift = doublewidth ? 1 : 0; @@ -135,9 +141,9 @@ ega_render_text(ega_t *ega) } for (int x = 0; x < (ega->hdisp + ega->scrollcache); x += charwidth) { - uint32_t addr = ega->remap_func(ega, ega->ma) & ega->vrammask; + uint32_t addr = ega->remap_func(ega, ega->memaddr) & ega->vrammask; - int drawcursor = ((ega->ma == ega->ca) && ega->con && ega->cursoron); + int drawcursor = ((ega->memaddr == ega->cursoraddr) && ega->cursorvisible && ega->cursoron); uint32_t chr; uint32_t attr; @@ -169,18 +175,30 @@ ega_render_text(ega_t *ega) } } - uint32_t dat = ega->vram[charaddr + (ega->sc << 2)]; + uint32_t dat = ega->vram[charaddr + (ega->scanline << 2)]; dat <<= 1; - if ((chr & ~0x1F) == 0xC0 && attrlinechars) + if (((chr & ~0x1f) == 0xc0) && attrlinechars) dat |= (dat >> 1) & 1; - for (int xx = 0; xx < charwidth; xx++) - p[xx] = (dat & (0x100 >> (xx >> dwshift))) ? fg : bg; + for (int xx = 0; xx < charwidth; xx++) { + if (monoattrs) { + int bit = (dat & (0x100 >> (xx >> dwshift))) ? 1 : 0; + int blink = (!drawcursor && (attr & 0x80) && attrblink && blinked); + if ((ega->scanline == ega->crtc[0x14]) && ((attr & 7) == 1)) + p[xx] = ega->mda_attr_to_color_table[attr][blink][1]; + else + p[xx] = ega->mda_attr_to_color_table[attr][blink][bit]; + if (drawcursor) + p[xx] ^= ega->mda_attr_to_color_table[attr][0][1]; + p[xx] = ega->pallook[ega->egapal[p[xx] & 0x0f]]; + } else + p[xx] = (dat & (0x100 >> (xx >> dwshift))) ? fg : bg; + } - ega->ma += 4; + ega->memaddr += 4; p += charwidth; } - ega->ma &= 0x3ffff; + ega->memaddr &= 0x3ffff; } } @@ -218,7 +236,7 @@ ega_render_graphics(ega_t *ega) } for (int x = 0; x <= (ega->hdisp + ega->scrollcache); x += charwidth) { - uint32_t addr = ega->remap_func(ega, ega->ma) & ega->vrammask; + uint32_t addr = ega->remap_func(ega, ega->memaddr) & ega->vrammask; uint8_t edat[4]; if (seqoddeven) { @@ -229,12 +247,12 @@ ega_render_graphics(ega_t *ega) edat[3] = ega->vram[(addr | 3) ^ secondcclk]; secondcclk = (secondcclk + 1) & 1; if (secondcclk == 0) - ega->ma += 4; + ega->memaddr += 4; } else { *(uint32_t *) (&edat[0]) = *(uint32_t *) (&ega->vram[addr]); - ega->ma += 4; + ega->memaddr += 4; } - ega->ma &= 0x3ffff; + ega->memaddr &= 0x3ffff; if (cga2bpp) { // Remap CGA 2bpp-chunky data into fully planar data diff --git a/src/video/vid_et3000.c b/src/video/vid_et3000.c index a7d2a749f..a82f93385 100644 --- a/src/video/vid_et3000.c +++ b/src/video/vid_et3000.c @@ -424,7 +424,7 @@ et3000_out(uint16_t addr, uint8_t val, void *priv) static void et3000_recalctimings(svga_t *svga) { - svga->ma_latch |= (svga->crtc[0x23] & 2) << 15; + svga->memaddr_latch |= (svga->crtc[0x23] & 2) << 15; if (svga->crtc[0x25] & 1) svga->vblankstart |= 0x400; if (svga->crtc[0x25] & 2) @@ -439,7 +439,7 @@ et3000_recalctimings(svga_t *svga) svga->interlace = !!(svga->crtc[0x25] & 0x80); if (svga->attrregs[0x16] & 0x10) { - svga->ma_latch <<= (1 << 0); + svga->memaddr_latch <<= (1 << 0); svga->rowoffset <<= (1 << 0); switch (svga->gdcreg[5] & 0x60) { case 0x00: @@ -548,17 +548,24 @@ et3000_available(void) } static const device_config_t et3000_config[] = { - { .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 512, - .selection = { - { .description = "256 KB", - .value = 256 }, - { .description = "512 KB", - .value = 512 }, - { .description = "" } } }, - { .type = CONFIG_END } + // clang-format off + { + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 512, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "256 KB", .value = 256 }, + { .description = "512 KB", .value = 512 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on }; const device_t et3000_isa_device = { @@ -569,7 +576,7 @@ const device_t et3000_isa_device = { .init = et3000_init, .close = et3000_close, .reset = NULL, - { .available = et3000_available }, + .available = et3000_available, .speed_changed = et3000_speed_changed, .force_redraw = et3000_force_redraw, .config = et3000_config diff --git a/src/video/vid_et4000.c b/src/video/vid_et4000.c index caf8d03c7..a99cb8872 100644 --- a/src/video/vid_et4000.c +++ b/src/video/vid_et4000.c @@ -82,8 +82,8 @@ typedef struct { rom_t bios_rom; uint8_t banking; - uint32_t vram_size, - vram_mask; + uint32_t vram_size; + uint32_t vram_mask; uint8_t port_22cb_val; uint8_t port_32cb_val; @@ -378,7 +378,7 @@ et4000_out(uint16_t addr, uint8_t val, void *priv) 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); + svga->memaddr_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5); } else { svga->fullchange = changeframecount; svga_recalctimings(svga); @@ -642,7 +642,7 @@ et4000_recalctimings(svga_t *svga) { const et4000_t *dev = (et4000_t *) svga->priv; - svga->ma_latch |= (svga->crtc[0x33] & 3) << 16; + svga->memaddr_latch |= (svga->crtc[0x33] & 3) << 16; svga->hblankstart = (((svga->crtc[0x3f] & 0x4) >> 2) << 8) + svga->crtc[2]; @@ -701,7 +701,7 @@ et4000_recalctimings(svga_t *svga) if (dev->type == ET4000_TYPE_KOREAN || dev->type == ET4000_TYPE_TRIGEM || dev->type == ET4000_TYPE_KASAN) { if ((svga->render == svga_render_text_80) && ((svga->crtc[0x37] & 0x0A) == 0x0A)) { if (dev->port_32cb_val & 0x80) { - svga->ma_latch -= 2; + svga->memaddr_latch -= 2; svga->ca_adj = -2; } if ((dev->port_32cb_val & 0xB4) == ((svga->crtc[0x37] & 3) == 2 ? 0xB4 : 0xB0)) { @@ -719,7 +719,7 @@ et4000_recalctimings(svga_t *svga) } if ((svga->seqregs[0x0e] & 0x02) && ((svga->gdcreg[5] & 0x60) >= 0x40) && svga->lowres) { - svga->ma_latch <<= 1; + svga->memaddr_latch <<= 1; svga->rowoffset <<= 1; svga->render = svga_render_8bpp_highres; } @@ -734,7 +734,7 @@ et4000_kasan_recalctimings(svga_t *svga) if (svga->render == svga_render_text_80 && (et4000->kasan_cfg_regs[0] & 8)) { svga->hdisp += svga->dots_per_clock; - svga->ma_latch -= 4; + svga->memaddr_latch -= 4; svga->ca_adj = (et4000->kasan_cfg_regs[0] >> 6) - 3; svga->ksc5601_sbyte_mask = (et4000->kasan_cfg_regs[0] & 4) << 5; if ((et4000->kasan_cfg_regs[0] & 0x23) == 0x20 && (et4000->kasan_cfg_regs[4] & 0x80) && ((svga->crtc[0x37] & 0x0B) == 0x0A)) @@ -943,125 +943,128 @@ et4000_kasan_available(void) static const device_config_t et4000_tc6058af_config[] = { // clang-format off { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 512, - .selection = { + .name = "bios_ver", + .description = "BIOS Revision", + .type = CONFIG_BIOS, + .default_string = "v1_10", + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { - .description = "256 KB", - .value = 256 + .name = "Version 1.10", + .internal_name = "v1_10", + .bios_type = BIOS_NORMAL, + .files_no = 1, + .local = 0, + .size = 32768, + .files = { TC6058AF_BIOS_ROM_PATH, "" } }, { - .description = "512 KB", - .value = 512 + .name = "Version 1.21", + .internal_name = "v1_21", + .bios_type = BIOS_NORMAL, + .files_no = 1, + .local = 0, + .size = 32768, + .files = { V1_21_BIOS_ROM_PATH, "" } }, - { - .description = "1 MB", - .value = 1024 - }, - { - .description = "" - } + { .files_no = 0 } } }, { - .name = "bios_ver", - .description = "BIOS Revision", - .type = CONFIG_BIOS, - .default_string = "v1_10", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, /*W1*/ - .bios = { - { .name = "Version 1.10", .internal_name = "v1_10", .bios_type = BIOS_NORMAL, - .files_no = 1, .local = 0, .size = 32768, .files = { TC6058AF_BIOS_ROM_PATH, "" } }, - { .name = "Version 1.21", .internal_name = "v1_21", .bios_type = BIOS_NORMAL, - .files_no = 1, .local = 0, .size = 32768, .files = { V1_21_BIOS_ROM_PATH, "" } }, - { .files_no = 0 } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 512, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "256 KB", .value = 256 }, + { .description = "512 KB", .value = 512 }, + { .description = "1 MB", .value = 1024 }, + { .description = "" } }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; static const device_config_t et4000_bios_config[] = { // clang-format off { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 1024, - .selection = { + .name = "bios_ver", + .description = "BIOS Revision", + .type = CONFIG_BIOS, + .default_string = "v8_01", + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { - .description = "256 KB", - .value = 256 + .name = "Version 8.01", + .internal_name = "v8_01", + .bios_type = BIOS_NORMAL, + .files_no = 1, + .local = 0, + .size = 32768, + .files = { BIOS_ROM_PATH, "" } }, { - .description = "512 KB", - .value = 512 + .name = "Version 8.06", + .internal_name = "v8_06", + .bios_type = BIOS_NORMAL, + .files_no = 1, + .local = 0, + .size = 32768, + .files = { V8_06_BIOS_ROM_PATH, "" } }, - { - .description = "1 MB", - .value = 1024 - }, - { - .description = "" - } + { .files_no = 0 } } }, { - .name = "bios_ver", - .description = "BIOS Revision", - .type = CONFIG_BIOS, - .default_string = "v8_01", - .default_int = 0, - .file_filter = "", - .spinner = { 0 }, /*W1*/ - .bios = { - { .name = "Version 8.01", .internal_name = "v8_01", .bios_type = BIOS_NORMAL, - .files_no = 1, .local = 0, .size = 32768, .files = { BIOS_ROM_PATH, "" } }, - { .name = "Version 8.06", .internal_name = "v8_06", .bios_type = BIOS_NORMAL, - .files_no = 1, .local = 0, .size = 32768, .files = { V8_06_BIOS_ROM_PATH, "" } }, - { .files_no = 0 } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 1024, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "256 KB", .value = 256 }, + { .description = "512 KB", .value = 512 }, + { .description = "1 MB", .value = 1024 }, + { .description = "" } }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; static const device_config_t et4000_config[] = { // clang-format off { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 1024, - .selection = { - { - .description = "256 KB", - .value = 256 - }, - { - .description = "512 KB", - .value = 512 - }, - { - .description = "1 MB", - .value = 1024 - }, - { - .description = "" - } - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 1024, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "256 KB", .value = 256 }, + { .description = "512 KB", .value = 512 }, + { .description = "1 MB", .value = 1024 }, + { .description = "" } + }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -1073,7 +1076,7 @@ const device_t et4000_tc6058af_isa_device = { .init = et4000_init, .close = et4000_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = et4000_speed_changed, .force_redraw = et4000_force_redraw, .config = et4000_tc6058af_config @@ -1087,7 +1090,7 @@ const device_t et4000_isa_device = { .init = et4000_init, .close = et4000_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = et4000_speed_changed, .force_redraw = et4000_force_redraw, .config = et4000_bios_config @@ -1101,7 +1104,7 @@ const device_t et4000_mca_device = { .init = et4000_init, .close = et4000_close, .reset = NULL, - { .available = et4000_available }, + .available = et4000_available, .speed_changed = et4000_speed_changed, .force_redraw = et4000_force_redraw, .config = et4000_config @@ -1115,7 +1118,7 @@ const device_t et4000k_isa_device = { .init = et4000_init, .close = et4000_close, .reset = NULL, - { .available = et4000k_available }, + .available = et4000k_available, .speed_changed = et4000_speed_changed, .force_redraw = et4000_force_redraw, .config = et4000_config @@ -1129,7 +1132,7 @@ const device_t et4000k_tg286_isa_device = { .init = et4000_init, .close = et4000_close, .reset = NULL, - { .available = et4000k_available }, + .available = et4000k_available, .speed_changed = et4000_speed_changed, .force_redraw = et4000_force_redraw, .config = et4000_config @@ -1143,7 +1146,7 @@ const device_t et4000_kasan_isa_device = { .init = et4000_init, .close = et4000_close, .reset = NULL, - { .available = et4000_kasan_available }, + .available = et4000_kasan_available, .speed_changed = et4000_speed_changed, .force_redraw = et4000_force_redraw, .config = et4000_config diff --git a/src/video/vid_et4000w32.c b/src/video/vid_et4000w32.c index 2f086f3c7..533bd1f28 100644 --- a/src/video/vid_et4000w32.c +++ b/src/video/vid_et4000w32.c @@ -238,7 +238,7 @@ et4000w32p_out(uint16_t addr, uint8_t val, void *priv) 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); + svga->memaddr_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5); } else { svga->fullchange = changeframecount; svga_recalctimings(svga); @@ -430,7 +430,7 @@ et4000w32p_recalctimings(svga_t *svga) { et4000w32p_t *et4000 = (et4000w32p_t *) svga->priv; - svga->ma_latch |= (svga->crtc[0x33] & 0x7) << 16; + svga->memaddr_latch |= (svga->crtc[0x33] & 0x7) << 16; svga->hblankstart = (((svga->crtc[0x3f] & 0x4) >> 2) << 8) + svga->crtc[2]; @@ -2943,39 +2943,33 @@ et4000w32p_force_redraw(void *priv) static const device_config_t et4000w32p_config[] = { // clang-format off { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 2, - .selection = { - { - .description = "1 MB", - .value = 1 - }, - { - .description = "2 MB", - .value = 2 - }, - { - .description = "" - } - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "1 MB", .value = 1 }, + { .description = "2 MB", .value = 2 }, + { .description = "" } + }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; const device_t et4000w32_device = { .name = "Tseng Labs ET4000/w32 ISA", .internal_name = "et4000w32", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = ET4000W32, .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32_available }, + .available = et4000w32_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = NULL @@ -2984,12 +2978,12 @@ const device_t et4000w32_device = { const device_t et4000w32_onboard_device = { .name = "Tseng Labs ET4000/w32 (ISA) (On-Board)", .internal_name = "et4000w32_onboard", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = ET4000W32, .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32_available }, + .available = et4000w32_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = NULL @@ -2998,12 +2992,12 @@ const device_t et4000w32_onboard_device = { const device_t et4000w32i_isa_device = { .name = "Tseng Labs ET4000/w32i Rev. B ISA", .internal_name = "et4000w32i", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = ET4000W32I, .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32i_isa_available }, + .available = et4000w32i_isa_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = NULL @@ -3017,7 +3011,7 @@ const device_t et4000w32i_vlb_device = { .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32i_vlb_available }, + .available = et4000w32i_vlb_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = et4000w32p_config @@ -3031,7 +3025,7 @@ const device_t et4000w32p_videomagic_revb_vlb_device = { .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32p_videomagic_revb_vlb_available }, + .available = et4000w32p_videomagic_revb_vlb_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = et4000w32p_config @@ -3045,7 +3039,7 @@ const device_t et4000w32p_videomagic_revb_pci_device = { .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32p_videomagic_revb_vlb_available }, + .available = et4000w32p_videomagic_revb_vlb_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = et4000w32p_config @@ -3059,7 +3053,7 @@ const device_t et4000w32p_revc_vlb_device = { .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32p_revc_available }, + .available = et4000w32p_revc_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = et4000w32p_config @@ -3073,7 +3067,7 @@ const device_t et4000w32p_revc_pci_device = { .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32p_revc_available }, + .available = et4000w32p_revc_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = et4000w32p_config @@ -3087,7 +3081,7 @@ const device_t et4000w32p_noncardex_vlb_device = { .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32p_noncardex_available }, + .available = et4000w32p_noncardex_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = et4000w32p_config @@ -3101,7 +3095,7 @@ const device_t et4000w32p_noncardex_pci_device = { .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32p_noncardex_available }, + .available = et4000w32p_noncardex_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = et4000w32p_config @@ -3115,7 +3109,7 @@ const device_t et4000w32p_cardex_vlb_device = { .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32p_cardex_available }, + .available = et4000w32p_cardex_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = et4000w32p_config @@ -3129,7 +3123,7 @@ const device_t et4000w32p_cardex_pci_device = { .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32p_cardex_available }, + .available = et4000w32p_cardex_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = et4000w32p_config @@ -3143,7 +3137,7 @@ const device_t et4000w32p_vlb_device = { .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32p_available }, + .available = et4000w32p_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = et4000w32p_config @@ -3157,7 +3151,7 @@ const device_t et4000w32p_pci_device = { .init = et4000w32p_init, .close = et4000w32p_close, .reset = NULL, - { .available = et4000w32p_available }, + .available = et4000w32p_available, .speed_changed = et4000w32p_speed_changed, .force_redraw = et4000w32p_force_redraw, .config = et4000w32p_config diff --git a/src/video/vid_f82c425.c b/src/video/vid_f82c425.c index 772926e1e..078e0f3df 100644 --- a/src/video/vid_f82c425.c +++ b/src/video/vid_f82c425.c @@ -361,28 +361,28 @@ f82c425_text_row(f82c425_t *f82c425) int cursorline; int blink; uint16_t addr; - uint8_t sc; - uint16_t ma = (f82c425->cga.crtc[0x0d] | (f82c425->cga.crtc[0x0c] << 8)) & 0x3fff; - uint16_t ca = (f82c425->cga.crtc[0x0f] | (f82c425->cga.crtc[0x0e] << 8)) & 0x3fff; - uint8_t sl = f82c425->cga.crtc[9] + 1; - int columns = f82c425->cga.crtc[1]; + uint8_t scanline; + uint16_t memaddr = (f82c425->cga.crtc[CGA_CRTC_START_ADDR_LOW] | (f82c425->cga.crtc[CGA_CRTC_START_ADDR_HIGH] << 8)) & 0x3fff; + uint16_t cursoraddr = (f82c425->cga.crtc[0x0f] | (f82c425->cga.crtc[0x0e] << 8)) & 0x3fff; + uint8_t sl = f82c425->cga.crtc[CGA_CRTC_MAX_SCANLINE_ADDR] + 1; + int columns = f82c425->cga.crtc[CGA_CRTC_HDISP]; - sc = (f82c425->displine) & 7; - addr = ((ma & ~1) + (f82c425->displine >> 3) * columns) * 2; - ma += (f82c425->displine >> 3) * columns; + scanline = (f82c425->displine) & 7; + addr = ((memaddr & ~1) + (f82c425->displine >> 3) * columns) * 2; + memaddr += (f82c425->displine >> 3) * columns; - if ((f82c425->cga.crtc[0x0a] & 0x60) == 0x20) { + if ((f82c425->cga.crtc[CGA_CRTC_CURSOR_START] & 0x60) == 0x20) { cursorline = 0; } else { - cursorline = ((f82c425->cga.crtc[0x0a] & 0x0F) <= sc) && ((f82c425->cga.crtc[0x0b] & 0x0F) >= sc); + cursorline = ((f82c425->cga.crtc[CGA_CRTC_CURSOR_START] & 0x0F) <= scanline) && ((f82c425->cga.crtc[CGA_CRTC_CURSOR_END] & 0x0F) >= scanline); } 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)); + drawcursor = ((memaddr == cursoraddr) && cursorline && (f82c425->cga.cgamode & CGA_MODE_FLAG_VIDEO_ENABLE) && (f82c425->cga.cgablink & 0x10)); - blink = ((f82c425->cga.cgablink & 0x10) && (f82c425->cga.cgamode & 0x20) && (attr & 0x80) && !drawcursor); + blink = ((f82c425->cga.cgablink & 0x10) && (f82c425->cga.cgamode & CGA_MODE_FLAG_BLINK) && (attr & 0x80) && !drawcursor); if (drawcursor) { colors[0] = smartmap[~attr & 0xff][0]; @@ -398,16 +398,16 @@ f82c425_text_row(f82c425_t *f82c425) if (f82c425->cga.cgamode & 0x01) { /* High resolution (80 cols) */ for (c = 0; c < sl; c++) { - (buffer32->line[f82c425->displine])[(x << 3) + c] = colors[(fontdat[chr][sc] & (1 << (c ^ 7))) ? 1 : 0]; + (buffer32->line[f82c425->displine])[(x << 3) + c] = colors[(fontdat[chr][scanline] & (1 << (c ^ 7))) ? 1 : 0]; } } else { /* Low resolution (40 columns, stretch pixels horizontally) */ for (c = 0; c < sl; c++) { - (buffer32->line[f82c425->displine])[(x << 4) + c * 2] = (buffer32->line[f82c425->displine])[(x << 4) + c * 2 + 1] = colors[(fontdat[chr][sc] & (1 << (c ^ 7))) ? 1 : 0]; + (buffer32->line[f82c425->displine])[(x << 4) + c * 2] = (buffer32->line[f82c425->displine])[(x << 4) + c * 2 + 1] = colors[(fontdat[chr][scanline] & (1 << (c ^ 7))) ? 1 : 0]; } } - ++ma; + ++memaddr; } } @@ -418,9 +418,9 @@ f82c425_cgaline6(f82c425_t *f82c425) uint8_t dat; uint16_t addr; - uint16_t ma = (f82c425->cga.crtc[0x0d] | (f82c425->cga.crtc[0x0c] << 8)) & 0x3fff; + uint16_t memaddr = (f82c425->cga.crtc[CGA_CRTC_START_ADDR_LOW] | (f82c425->cga.crtc[CGA_CRTC_START_ADDR_HIGH] << 8)) & 0x3fff; - addr = ((f82c425->displine) & 1) * 0x2000 + (f82c425->displine >> 1) * 80 + ((ma & ~1) << 1); + addr = ((f82c425->displine) & 1) * 0x2000 + (f82c425->displine >> 1) * 80 + ((memaddr & ~1) << 1); for (uint8_t x = 0; x < 80; x++) { dat = f82c425->vram[addr & 0x3FFF]; @@ -442,8 +442,8 @@ f82c425_cgaline4(f82c425_t *f82c425) 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); + uint16_t memaddr = (f82c425->cga.crtc[CGA_CRTC_START_ADDR_LOW] | (f82c425->cga.crtc[CGA_CRTC_START_ADDR_HIGH] << 8)) & 0x3fff; + addr = ((f82c425->displine) & 1) * 0x2000 + (f82c425->displine >> 1) * 80 + ((memaddr & ~1) << 1); for (uint8_t x = 0; x < 80; x++) { dat = f82c425->vram[addr & 0x3FFF]; @@ -526,7 +526,7 @@ f82c425_poll(void *priv) f82c425->displine = 0; f82c425->cga.cgastat &= ~8; f82c425->dispon = 1; - } else if (f82c425->displine == (f82c425->cga.crtc[9] + 1) * f82c425->cga.crtc[6]) { + } else if (f82c425->displine == (f82c425->cga.crtc[CGA_CRTC_MAX_SCANLINE_ADDR] + 1) * f82c425->cga.crtc[CGA_CRTC_VDISP]) { /* Start of VSYNC */ f82c425->cga.cgastat |= 8; f82c425->dispon = 0; @@ -631,7 +631,7 @@ const device_t f82c425_video_device = { .init = f82c425_init, .close = f82c425_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = f82c425_speed_changed, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_genius.c b/src/video/vid_genius.c index 4ae8e6fd1..366fa25e1 100644 --- a/src/video/vid_genius.c +++ b/src/video/vid_genius.c @@ -387,7 +387,7 @@ genius_textline(genius_t *genius, uint8_t background, int mda, int cols80) int cw = 9; /* Each character is 9 pixels wide */ uint8_t chr; uint8_t attr; - uint8_t sc; + uint8_t scanline; uint8_t ctrl; const uint8_t *crtc; uint8_t bitmap[2]; @@ -398,8 +398,8 @@ genius_textline(genius_t *genius, uint8_t background, int mda, int cols80) 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; + uint16_t memaddr = (genius->mda_crtc[13] | (genius->mda_crtc[12] << 8)) & 0x3fff; + uint16_t cursoraddr = (genius->mda_crtc[15] | (genius->mda_crtc[14] << 8)) & 0x3fff; const uint8_t *framebuf = genius->vram + 0x10000; uint32_t col; uint32_t dl = genius->displine; @@ -416,14 +416,14 @@ genius_textline(genius_t *genius, uint8_t background, int mda, int cols80) #if 0 if (genius->genius_charh & 0x10) { row = ((dl >> 1) / charh); - sc = ((dl >> 1) % charh); + scanline = ((dl >> 1) % charh); } else { row = (dl / charh); - sc = (dl % charh); + scanline = (dl % charh); } #else row = (dl / charh); - sc = (dl % charh); + scanline = (dl % charh); #endif } else { if ((genius->displine < 512) || (genius->displine >= 912)) @@ -439,23 +439,23 @@ genius_textline(genius_t *genius, uint8_t background, int mda, int cols80) charh = crtc[9] + 1; row = ((dl >> 1) / charh); - sc = ((dl >> 1) % charh); + scanline = ((dl >> 1) % charh); } - ma = (crtc[13] | (crtc[12] << 8)) & 0x3fff; - ca = (crtc[15] | (crtc[14] << 8)) & 0x3fff; + memaddr = (crtc[13] | (crtc[12] << 8)) & 0x3fff; + cursoraddr = (crtc[15] | (crtc[14] << 8)) & 0x3fff; - addr = ((ma & ~1) + row * w) * 2; + addr = ((memaddr & ~1) + row * w) * 2; if (!mda) dl += 512; - ma += (row * w); + memaddr += (row * w); if ((crtc[10] & 0x60) == 0x20) cursorline = 0; else - cursorline = ((crtc[10] & 0x1F) <= sc) && ((crtc[11] & 0x1F) >= sc); + cursorline = ((crtc[10] & 0x1F) <= scanline) && ((crtc[11] & 0x1F) >= scanline); for (int x = 0; x < w; x++) { #if 0 @@ -467,7 +467,7 @@ genius_textline(genius_t *genius, uint8_t background, int mda, int cols80) chr = framebuf[(addr + 2 * x) & 0x3FFF]; attr = framebuf[(addr + 2 * x + 1) & 0x3FFF]; - drawcursor = ((ma == ca) && cursorline && genius->enabled && (ctrl & 8)); + drawcursor = ((memaddr == cursoraddr) && cursorline && genius->enabled && (ctrl & 8)); switch (crtc[10] & 0x60) { case 0x00: @@ -487,7 +487,7 @@ genius_textline(genius_t *genius, uint8_t background, int mda, int cols80) attr &= 0x7F; /* MDA underline */ - if (mda && (sc == charh) && ((attr & 7) == 1)) { + if (mda && (scanline == charh) && ((attr & 7) == 1)) { col = mdaattr[attr][blink][1]; if (genius->genius_control & 0x20) @@ -504,9 +504,9 @@ genius_textline(genius_t *genius, uint8_t background, int mda, int cols80) } } else { /* Draw 8 pixels of character */ if (mda) - bitmap[0] = fontdat8x12[chr][sc]; + bitmap[0] = fontdat8x12[chr][scanline]; else - bitmap[0] = fontdat[chr][sc]; + bitmap[0] = fontdat[chr][scanline]; for (c = 0; c < 8; c++) { col = mdaattr[attr][blink][(bitmap[0] & (1 << (c ^ 7))) ? 1 : 0]; @@ -563,7 +563,7 @@ genius_textline(genius_t *genius, uint8_t background, int mda, int cols80) } } } - ++ma; + ++memaddr; } } } @@ -826,7 +826,7 @@ const device_t genius_device = { .init = genius_init, .close = genius_close, .reset = NULL, - { .available = genius_available }, + .available = genius_available, .speed_changed = genius_speed_changed, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_hercules.c b/src/video/vid_hercules.c index 2a725488d..229ddcca8 100644 --- a/src/video/vid_hercules.c +++ b/src/video/vid_hercules.c @@ -14,7 +14,7 @@ * Miran Grca, * * Copyright 2008-2019 Sarah Walker. - * Copyright 2016-2019 Miran Grca. + * Copyright 2016-2025 Miran Grca. */ #include #include @@ -168,9 +168,9 @@ hercules_in(uint16_t addr, void *priv) case 0x03b5: case 0x03b7: if (dev->crtcreg == 0x0c) - ret = (dev->ma >> 8) & 0x3f; + ret = (dev->memaddr >> 8) & 0x3f; else if (dev->crtcreg == 0x0d) - ret = dev->ma & 0xff; + ret = dev->memaddr & 0xff; else ret = dev->crtc[dev->crtcreg]; break; @@ -178,8 +178,8 @@ hercules_in(uint16_t addr, void *priv) case 0x03ba: ret = 0x70; /* Hercules ident */ ret |= (dev->lp_ff ? 2 : 0); - ret |= (dev->stat & 0x01); - if (dev->stat & 0x08) + ret |= (dev->status & 0x01); + if (dev->status & 0x08) ret |= 0x80; if ((ret & 0x81) == 0x80) ret |= 0x08; @@ -281,10 +281,10 @@ hercules_poll(void *priv) hercules_t *dev = (hercules_t *) priv; uint8_t chr; uint8_t attr; - uint16_t ca; + uint16_t cursoraddr; uint16_t dat; uint16_t pa; - int oldsc; + int scanline_old; int blink; int x; int xx; @@ -296,16 +296,16 @@ hercules_poll(void *priv) uint32_t *p; VIDEO_MONITOR_PROLOGUE() - ca = (dev->crtc[15] | (dev->crtc[14] << 8)) & 0x3fff; + cursoraddr = (dev->crtc[15] | (dev->crtc[14] << 8)) & 0x3fff; if (!dev->linepos) { timer_advance_u64(&dev->timer, dev->dispofftime); - dev->stat |= 1; + dev->status |= 1; dev->linepos = 1; - oldsc = dev->sc; + scanline_old = dev->scanline; if ((dev->crtc[8] & 3) == 3) - dev->sc = (dev->sc << 1) & 7; + dev->scanline = (dev->scanline << 1) & 7; if (dev->dispon) { if (dev->displine < dev->firstline) { @@ -317,16 +317,16 @@ hercules_poll(void *priv) hercules_render_overscan_left(dev); if (dev->ctrl & 0x02) { - ca = (dev->sc & 3) * 0x2000; + cursoraddr = (dev->scanline & 3) * 0x2000; if (dev->ctrl & 0x80) - ca += 0x8000; + cursoraddr += 0x8000; for (x = 0; x < dev->crtc[1]; x++) { if (dev->ctrl & 8) - dat = (dev->vram[((dev->ma << 1) & 0x1fff) + ca] << 8) | dev->vram[((dev->ma << 1) & 0x1fff) + ca + 1]; + dat = (dev->vram[((dev->memaddr << 1) & 0x1fff) + cursoraddr] << 8) | dev->vram[((dev->memaddr << 1) & 0x1fff) + cursoraddr + 1]; else dat = 0; - dev->ma++; + dev->memaddr++; for (c = 0; c < 16; c++) buffer32->line[dev->displine + 14][(x << 4) + c + 8] = (dat & (32768 >> c)) ? 7 : 0; for (c = 0; c < 16; c += 8) @@ -341,25 +341,25 @@ hercules_poll(void *priv) attr = dev->charbuffer[(x << 1) + 1]; } else chr = attr = 0; - drawcursor = ((dev->ma == ca) && dev->con && dev->cursoron); + drawcursor = ((dev->memaddr == cursoraddr) && dev->cursorvisible && dev->cursoron); blink = ((dev->blink & 16) && (dev->ctrl & 0x20) && (attr & 0x80) && !drawcursor); - if (dev->sc == 12 && ((attr & 7) == 1)) { + if (dev->scanline == 12 && ((attr & 7) == 1)) { for (c = 0; c < 9; c++) buffer32->line[dev->displine + 14][(x * 9) + c + 8] = dev->cols[attr][blink][1]; } else { for (c = 0; c < 8; c++) - buffer32->line[dev->displine + 14][(x * 9) + c + 8] = dev->cols[attr][blink][(fontdatm[chr][dev->sc] & (1 << (c ^ 7))) ? 1 : 0]; + buffer32->line[dev->displine + 14][(x * 9) + c + 8] = dev->cols[attr][blink][(fontdatm[chr][dev->scanline] & (1 << (c ^ 7))) ? 1 : 0]; if ((chr & ~0x1f) == 0xc0) - buffer32->line[dev->displine + 14][(x * 9) + 8 + 8] = dev->cols[attr][blink][fontdatm[chr][dev->sc] & 1]; + buffer32->line[dev->displine + 14][(x * 9) + 8 + 8] = dev->cols[attr][blink][fontdatm[chr][dev->scanline] & 1]; else buffer32->line[dev->displine + 14][(x * 9) + 8 + 8] = dev->cols[attr][blink][0]; } if (dev->ctrl2 & 0x01) - dev->ma = (dev->ma + 1) & 0x3fff; + dev->memaddr = (dev->memaddr + 1) & 0x3fff; else - dev->ma = (dev->ma + 1) & 0x7ff; + dev->memaddr = (dev->memaddr + 1) & 0x7ff; if (drawcursor) { for (c = 0; c < 9; c++) @@ -377,10 +377,10 @@ hercules_poll(void *priv) video_process_8(x + 16, dev->displine + 14); } - dev->sc = oldsc; + dev->scanline = scanline_old; - if (dev->vc == dev->crtc[7] && !dev->sc) - dev->stat |= 8; + if (dev->vc == dev->crtc[7] && !dev->scanline) + dev->status |= 8; dev->displine++; if (dev->displine >= 500) dev->displine = 0; @@ -388,33 +388,32 @@ hercules_poll(void *priv) timer_advance_u64(&dev->timer, dev->dispontime); if (dev->dispon) - dev->stat &= ~1; + dev->status &= ~1; dev->linepos = 0; if (dev->vsynctime) { dev->vsynctime--; if (!dev->vsynctime) - dev->stat &= ~8; + dev->status &= ~8; } - if (dev->sc == (dev->crtc[11] & 31) || ((dev->crtc[8] & 3) == 3 && dev->sc == ((dev->crtc[11] & 31) >> 1))) { - dev->con = 0; - dev->coff = 1; + if (dev->scanline == (dev->crtc[11] & 31) || ((dev->crtc[8] & 3) == 3 && dev->scanline == ((dev->crtc[11] & 31) >> 1))) { + dev->cursorvisible = 0; } if (dev->vadj) { - dev->sc++; - dev->sc &= 31; - dev->ma = dev->maback; + dev->scanline++; + dev->scanline &= 31; + dev->memaddr = dev->memaddr_backup; dev->vadj--; if (!dev->vadj) { dev->dispon = 1; - dev->ma = dev->maback = (dev->crtc[13] | (dev->crtc[12] << 8)) & 0x3fff; - dev->sc = 0; + dev->memaddr = dev->memaddr_backup = (dev->crtc[13] | (dev->crtc[12] << 8)) & 0x3fff; + dev->scanline = 0; } - } else if (((dev->crtc[8] & 3) != 3 && dev->sc == dev->crtc[9]) || ((dev->crtc[8] & 3) == 3 && dev->sc == (dev->crtc[9] >> 1))) { - dev->maback = dev->ma; - dev->sc = 0; + } else if (((dev->crtc[8] & 3) != 3 && dev->scanline == dev->crtc[9]) || ((dev->crtc[8] & 3) == 3 && dev->scanline == (dev->crtc[9] >> 1))) { + dev->memaddr_backup = dev->memaddr; + dev->scanline = 0; oldvc = dev->vc; dev->vc++; dev->vc &= 127; @@ -427,7 +426,7 @@ hercules_poll(void *priv) dev->vadj = dev->crtc[5]; if (!dev->vadj) { dev->dispon = 1; - dev->ma = dev->maback = (dev->crtc[13] | (dev->crtc[12] << 8)) & 0x3fff; + dev->memaddr = dev->memaddr_backup = (dev->crtc[13] | (dev->crtc[12] << 8)) & 0x3fff; } switch (dev->crtc[10] & 0x60) { case 0x20: @@ -512,17 +511,17 @@ hercules_poll(void *priv) dev->blink++; } } else { - dev->sc++; - dev->sc &= 31; - dev->ma = dev->maback; + dev->scanline++; + dev->scanline &= 31; + dev->memaddr = dev->memaddr_backup; } - if (dev->sc == (dev->crtc[10] & 31) || ((dev->crtc[8] & 3) == 3 && dev->sc == ((dev->crtc[10] & 31) >> 1))) - dev->con = 1; + if (dev->scanline == (dev->crtc[10] & 31) || ((dev->crtc[8] & 3) == 3 && dev->scanline == ((dev->crtc[10] & 31) >> 1))) + dev->cursorvisible = 1; if (dev->dispon && !(dev->ctrl & 0x02)) { for (x = 0; x < (dev->crtc[1] << 1); x++) { pa = (dev->ctrl & 0x80) ? ((x & 1) ? 0x0000 : 0x8000) : 0x0000; - dev->charbuffer[x] = dev->vram[(((dev->ma << 1) + x) & 0x3fff) + pa]; + dev->charbuffer[x] = dev->vram[(((dev->memaddr << 1) + x) & 0x3fff) + pa]; } } } @@ -543,14 +542,36 @@ hercules_init(UNUSED(const device_t *info)) dev->vram = (uint8_t *) malloc(0x10000); + switch(device_get_config_int("font")) { + case 0: + loadfont(FONT_IBM_MDA_437_PATH, 0); + break; + case 1: + loadfont(FONT_IBM_MDA_437_NORDIC_PATH, 0); + break; + case 2: + loadfont(FONT_KAM_PATH, 0); + break; + case 3: + loadfont(FONT_KAMCL16_PATH, 0); + break; + case 4: + loadfont(FONT_TULIP_DGA_PATH, 0); + break; + } + timer_add(&dev->timer, hercules_poll, dev, 1); mem_mapping_add(&dev->mapping, 0xb0000, 0x08000, - hercules_read, NULL, NULL, hercules_write, NULL, NULL, - NULL /*dev->vram*/, MEM_MAPPING_EXTERNAL, dev); + hercules_read, NULL, NULL, + hercules_write, NULL, NULL, + NULL /*dev->vram*/, MEM_MAPPING_EXTERNAL, + dev); - io_sethandler(0x03b0, 16, - hercules_in, NULL, NULL, hercules_out, NULL, NULL, dev); + io_sethandler(0x03b0, 0x0010, + hercules_in, NULL, NULL, + hercules_out, NULL, NULL, + dev); for (uint16_t c = 0; c < 256; c++) { dev->cols[c][0][0] = dev->cols[c][1][0] = dev->cols[c][1][1] = 16; @@ -585,7 +606,7 @@ hercules_init(UNUSED(const device_t *info)) video_inform(VIDEO_FLAG_TYPE_MDA, &timing_hercules); /* Force the LPT3 port to be enabled. */ - lpt3_init(0x3BC); + lpt3_setup(LPT_MDA_ADDR); return dev; } @@ -615,41 +636,52 @@ speed_changed(void *priv) static const device_config_t hercules_config[] = { // clang-format off { - .name = "rgb_type", - .description = "Display type", - .type = CONFIG_SELECTION, - .default_int = 0, - .selection = { - { - .description = "Default", - .value = 0 - }, - { - .description = "Green", - .value = 1 - }, - { - .description = "Amber", - .value = 2 - }, - { - .description = "Gray", - .value = 3 - }, - { - .description = "" - } - } + .name = "rgb_type", + .description = "Display type", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Default", .value = 0 }, + { .description = "Green", .value = 1 }, + { .description = "Amber", .value = 2 }, + { .description = "Gray", .value = 3 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "blend", - .description = "Blend", - .type = CONFIG_BINARY, - .default_int = 1 + .name = "font", + .description = "Font", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "US (CP 437)", .value = 0 }, + { .description = "IBM Nordic (CP 437-Nordic)", .value = 1 }, + { .description = "Czech Kamenicky (CP 895) #1", .value = 2 }, + { .description = "Czech Kamenicky (CP 895) #2", .value = 3 }, + { .description = "Tulip DGA", .value = 4 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .type = CONFIG_END - } + .name = "blend", + .description = "Blend", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -661,7 +693,7 @@ const device_t hercules_device = { .init = hercules_init, .close = hercules_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = speed_changed, .force_redraw = NULL, .config = hercules_config diff --git a/src/video/vid_incolor.c b/src/video/vid_hercules_incolor.c similarity index 87% rename from src/video/vid_incolor.c rename to src/video/vid_hercules_incolor.c index e3f37ec65..eceb440f9 100644 --- a/src/video/vid_incolor.c +++ b/src/video/vid_hercules_incolor.c @@ -14,7 +14,7 @@ * Miran Grca, * * Copyright 2008-2018 Sarah Walker. - * Copyright 2016-2018 Miran Grca. + * Copyright 2016-2025 Miran Grca. */ #include #include @@ -157,7 +157,7 @@ typedef struct { uint8_t crtc[32]; int crtcreg; - uint8_t ctrl, ctrl2, stat; + uint8_t ctrl, ctrl2, status; uint64_t dispontime, dispofftime; pc_timer_t timer; @@ -165,9 +165,9 @@ typedef struct { int firstline, lastline; int linepos, displine; - int vc, sc; - uint16_t ma, maback; - int con, coff, cursoron; + int vc, scanline; + uint16_t memaddr, memaddr_backup; + int cursorvisible, cursoron; int dispon, blink; int vsynctime; int vadj; @@ -285,7 +285,7 @@ incolor_in(uint16_t port, void *priv) case 0x3ba: /* 0x50: InColor card identity */ - ret = (dev->stat & 0xf) | ((dev->stat & 8) << 4) | 0x50; + ret = (dev->status & 0xf) | ((dev->status & 8) << 4) | 0x50; break; default: @@ -483,11 +483,11 @@ draw_char_rom(incolor_t *dev, int x, uint8_t chr, uint8_t attr) elg = ((chr >= 0xc0) && (chr <= 0xdf)); } - fnt = &(fontdatm[chr][dev->sc]); + fnt = &(fontdatm[chr][dev->scanline]); if (blk) { val = 0x000; /* Blinking, draw all background */ - } else if (dev->sc == ull) { + } else if (dev->scanline == ull) { val = 0x1ff; /* Underscore, draw all foreground */ } else { val = fnt[0] << 1; @@ -559,12 +559,12 @@ draw_char_ram4(incolor_t *dev, int x, uint8_t chr, uint8_t attr) } else { elg = ((chr >= 0xc0) && (chr <= 0xdf)); } - fnt = dev->vram + 0x4000 + 16 * chr + dev->sc; + fnt = dev->vram + 0x4000 + 16 * chr + dev->scanline; if (blk) { /* Blinking, draw all background */ val[0] = val[1] = val[2] = val[3] = 0x000; - } else if (dev->sc == ull) { + } else if (dev->scanline == ull) { /* Underscore, draw all foreground */ val[0] = val[1] = val[2] = val[3] = 0x1ff; } else { @@ -685,12 +685,12 @@ draw_char_ram48(incolor_t *dev, int x, uint8_t chr, uint8_t attr) } else { elg = ((chr >= 0xc0) && (chr <= 0xdf)); } - fnt = dev->vram + 0x4000 + 16 * chr + 4096 * font + dev->sc; + fnt = dev->vram + 0x4000 + 16 * chr + 4096 * font + dev->scanline; if (blk) { /* Blinking, draw all background */ val[0] = val[1] = val[2] = val[3] = 0x000; - } else if (dev->sc == ull) { + } else if (dev->scanline == ull) { /* Underscore, draw all foreground */ val[0] = val[1] = val[2] = val[3] = 0x1ff; } else { @@ -716,9 +716,9 @@ draw_char_ram48(incolor_t *dev, int x, uint8_t chr, uint8_t attr) /* Generate pixel colour */ cfg = 0; pmask = 1; - if (dev->sc == oll) { + if (dev->scanline == oll) { cfg = olc ^ ibg; /* Strikethrough */ - } else if (dev->sc == ull) { + } else if (dev->scanline == ull) { cfg = ulc ^ ibg; /* Underline */ } else { for (uint8_t plane = 0; plane < 4; plane++, pmask = pmask << 1) { @@ -746,7 +746,7 @@ draw_char_ram48(incolor_t *dev, int x, uint8_t chr, uint8_t attr) } static void -text_line(incolor_t *dev, uint16_t ca) +text_line(incolor_t *dev, uint16_t cursoraddr) { int drawcursor; uint8_t chr; @@ -755,12 +755,12 @@ text_line(incolor_t *dev, uint16_t ca) for (uint8_t x = 0; x < dev->crtc[1]; x++) { if (dev->ctrl & 8) { - chr = dev->vram[(dev->ma << 1) & 0x3fff]; - attr = dev->vram[((dev->ma << 1) + 1) & 0x3fff]; + chr = dev->vram[(dev->memaddr << 1) & 0x3fff]; + attr = dev->vram[((dev->memaddr << 1) + 1) & 0x3fff]; } else chr = attr = 0; - drawcursor = ((dev->ma == ca) && dev->con && dev->cursoron); + drawcursor = ((dev->memaddr == cursoraddr) && dev->cursorvisible && dev->cursoron); switch (dev->crtc[INCOLOR_CRTC_XMODE] & 5) { case 0: @@ -779,7 +779,7 @@ text_line(incolor_t *dev, uint16_t ca) default: break; } - ++dev->ma; + ++dev->memaddr; if (drawcursor) { int cw = INCOLOR_CW; @@ -808,29 +808,29 @@ static void graphics_line(incolor_t *dev) { uint8_t mask; - uint16_t ca; + uint16_t cursoraddr; int plane; int col; uint8_t ink; uint16_t val[4]; /* Graphics mode. */ - ca = (dev->sc & 3) * 0x2000; + cursoraddr = (dev->scanline & 3) * 0x2000; if ((dev->ctrl & INCOLOR_CTRL_PAGE1) && (dev->ctrl2 & INCOLOR_CTRL2_PAGE1)) - ca += 0x8000; + cursoraddr += 0x8000; 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) { if (mask & 1) - val[plane] = (dev->vram[((dev->ma << 1) & 0x1fff) + ca + 0x10000 * plane] << 8) | dev->vram[((dev->ma << 1) & 0x1fff) + ca + 0x10000 * plane + 1]; + val[plane] = (dev->vram[((dev->memaddr << 1) & 0x1fff) + cursoraddr + 0x10000 * plane] << 8) | dev->vram[((dev->memaddr << 1) & 0x1fff) + cursoraddr + 0x10000 * plane + 1]; else val[plane] = 0; } else val[plane] = 0; } - dev->ma++; + dev->memaddr++; for (uint8_t c = 0; c < 16; c++) { ink = 0; @@ -855,19 +855,19 @@ static void incolor_poll(void *priv) { incolor_t *dev = (incolor_t *) priv; - uint16_t ca = (dev->crtc[15] | (dev->crtc[14] << 8)) & 0x3fff; + uint16_t cursoraddr = (dev->crtc[15] | (dev->crtc[14] << 8)) & 0x3fff; int x; int oldvc; - int oldsc; + int scanline_old; int cw = INCOLOR_CW; if (!dev->linepos) { timer_advance_u64(&dev->timer, dev->dispofftime); - dev->stat |= 1; + dev->status |= 1; dev->linepos = 1; - oldsc = dev->sc; + scanline_old = dev->scanline; if ((dev->crtc[8] & 3) == 3) - dev->sc = (dev->sc << 1) & 7; + dev->scanline = (dev->scanline << 1) & 7; if (dev->dispon) { if (dev->displine < dev->firstline) { @@ -878,44 +878,43 @@ incolor_poll(void *priv) if ((dev->ctrl & INCOLOR_CTRL_GRAPH) && (dev->ctrl2 & INCOLOR_CTRL2_GRAPH)) graphics_line(dev); else - text_line(dev, ca); + text_line(dev, cursoraddr); } - dev->sc = oldsc; - if (dev->vc == dev->crtc[7] && !dev->sc) - dev->stat |= 8; + dev->scanline = scanline_old; + if (dev->vc == dev->crtc[7] && !dev->scanline) + dev->status |= 8; dev->displine++; if (dev->displine >= 500) dev->displine = 0; } else { timer_advance_u64(&dev->timer, dev->dispontime); if (dev->dispon) - dev->stat &= ~1; + dev->status &= ~1; dev->linepos = 0; if (dev->vsynctime) { dev->vsynctime--; if (!dev->vsynctime) - dev->stat &= ~8; + dev->status &= ~8; } - if (dev->sc == (dev->crtc[11] & 31) || ((dev->crtc[8] & 3) == 3 && dev->sc == ((dev->crtc[11] & 31) >> 1))) { - dev->con = 0; - dev->coff = 1; + if (dev->scanline == (dev->crtc[11] & 31) || ((dev->crtc[8] & 3) == 3 && dev->scanline == ((dev->crtc[11] & 31) >> 1))) { + dev->cursorvisible = 0; } if (dev->vadj) { - dev->sc++; - dev->sc &= 31; - dev->ma = dev->maback; + dev->scanline++; + dev->scanline &= 31; + dev->memaddr = dev->memaddr_backup; dev->vadj--; if (!dev->vadj) { dev->dispon = 1; - dev->ma = dev->maback = (dev->crtc[13] | (dev->crtc[12] << 8)) & 0x3fff; - dev->sc = 0; + dev->memaddr = dev->memaddr_backup = (dev->crtc[13] | (dev->crtc[12] << 8)) & 0x3fff; + dev->scanline = 0; } - } else if (dev->sc == dev->crtc[9] || ((dev->crtc[8] & 3) == 3 && dev->sc == (dev->crtc[9] >> 1))) { - dev->maback = dev->ma; - dev->sc = 0; - oldvc = dev->vc; + } else if (dev->scanline == dev->crtc[9] || ((dev->crtc[8] & 3) == 3 && dev->scanline == (dev->crtc[9] >> 1))) { + dev->memaddr_backup = dev->memaddr; + dev->scanline = 0; + oldvc = dev->vc; dev->vc++; dev->vc &= 127; if (dev->vc == dev->crtc[6]) @@ -926,7 +925,7 @@ incolor_poll(void *priv) if (!dev->vadj) dev->dispon = 1; if (!dev->vadj) - dev->ma = dev->maback = (dev->crtc[13] | (dev->crtc[12] << 8)) & 0x3fff; + dev->memaddr = dev->memaddr_backup = (dev->crtc[13] | (dev->crtc[12] << 8)) & 0x3fff; if ((dev->crtc[10] & 0x60) == 0x20) dev->cursoron = 0; else @@ -972,13 +971,13 @@ incolor_poll(void *priv) dev->blink++; } } else { - dev->sc++; - dev->sc &= 31; - dev->ma = dev->maback; + dev->scanline++; + dev->scanline &= 31; + dev->memaddr = dev->memaddr_backup; } - if (dev->sc == (dev->crtc[10] & 31) || ((dev->crtc[8] & 3) == 3 && dev->sc == ((dev->crtc[10] & 31) >> 1))) - dev->con = 1; + if (dev->scanline == (dev->crtc[10] & 31) || ((dev->crtc[8] & 3) == 3 && dev->scanline == ((dev->crtc[10] & 31) >> 1))) + dev->cursorvisible = 1; } } @@ -993,6 +992,24 @@ incolor_init(UNUSED(const device_t *info)) dev->vram = (uint8_t *) malloc(0x40000); /* 4 planes of 64k */ + switch(device_get_config_int("font")) { + case 0: + loadfont(FONT_IBM_MDA_437_PATH, 0); + break; + case 1: + loadfont(FONT_IBM_MDA_437_NORDIC_PATH, 0); + break; + case 2: + loadfont(FONT_KAM_PATH, 0); + break; + case 3: + loadfont(FONT_KAMCL16_PATH, 0); + break; + case 4: + loadfont(FONT_TULIP_DGA_PATH, 0); + break; + } + timer_add(&dev->timer, incolor_poll, dev, 1); mem_mapping_add(&dev->mapping, 0xb0000, 0x08000, @@ -1018,7 +1035,7 @@ incolor_init(UNUSED(const device_t *info)) video_inform(VIDEO_FLAG_TYPE_MDA, &timing_incolor); /* Force the LPT3 port to be enabled. */ - lpt3_init(0x3BC); + lpt3_setup(LPT_MDA_ADDR); return dev; } @@ -1045,6 +1062,30 @@ speed_changed(void *priv) recalc_timings(dev); } +static const device_config_t incolor_config[] = { + // clang-format off + { + .name = "font", + .description = "Font", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "US (CP 437)", .value = 0 }, + { .description = "IBM Nordic (CP 437-Nordic)", .value = 1 }, + { .description = "Czech Kamenicky (CP 895) #1", .value = 2 }, + { .description = "Czech Kamenicky (CP 895) #2", .value = 3 }, + { .description = "Tulip DGA", .value = 4 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on +}; + const device_t incolor_device = { .name = "Hercules InColor", .internal_name = "incolor", @@ -1053,8 +1094,8 @@ const device_t incolor_device = { .init = incolor_init, .close = incolor_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = speed_changed, .force_redraw = NULL, - .config = NULL + .config = incolor_config }; diff --git a/src/video/vid_herculesplus.c b/src/video/vid_hercules_plus.c similarity index 78% rename from src/video/vid_herculesplus.c rename to src/video/vid_hercules_plus.c index 429632f19..7e1aec943 100644 --- a/src/video/vid_herculesplus.c +++ b/src/video/vid_hercules_plus.c @@ -14,7 +14,7 @@ * Miran Grca, * * Copyright 2008-2018 Sarah Walker. - * Copyright 2016-2018 Miran Grca. + * Copyright 2016-2025 Miran Grca. */ #include #include @@ -23,8 +23,8 @@ #include #include <86box/86box.h> #include <86box/io.h> -#include <86box/lpt.h> #include <86box/timer.h> +#include <86box/lpt.h> #include <86box/pit.h> #include <86box/mem.h> #include <86box/rom.h> @@ -67,7 +67,7 @@ typedef struct { uint8_t crtc[32]; int crtcreg; - uint8_t ctrl, ctrl2, stat; + uint8_t ctrl, ctrl2, status; uint64_t dispontime, dispofftime; pc_timer_t timer; @@ -75,9 +75,9 @@ typedef struct { int firstline, lastline; int linepos, displine; - int vc, sc; - uint16_t ma, maback; - int con, coff, cursoron; + int vc, scanline; + uint16_t memaddr, memaddr_backup; + int cursorvisible, cursoron; int dispon, blink; int vsynctime; int vadj; @@ -194,7 +194,7 @@ herculesplus_in(uint16_t port, void *priv) case 0x3ba: /* 0x10: Hercules Plus card identity */ - ret = (dev->stat & 0xf) | ((dev->stat & 8) << 4) | 0x10; + ret = (dev->status & 0xf) | ((dev->status & 8) << 4) | 0x10; break; default: @@ -260,11 +260,11 @@ draw_char_rom(herculesplus_t *dev, int x, uint8_t chr, uint8_t attr) else elg = ((chr >= 0xc0) && (chr <= 0xdf)); - fnt = &(fontdatm[chr][dev->sc]); + fnt = &(fontdatm[chr][dev->scanline]); if (blk) { val = 0x000; /* Blinking, draw all background */ - } else if (dev->sc == ull) { + } else if (dev->scanline == ull) { val = 0x1ff; /* Underscore, draw all foreground */ } else { val = fnt[0] << 1; @@ -319,11 +319,11 @@ draw_char_ram4(herculesplus_t *dev, int x, uint8_t chr, uint8_t attr) else elg = ((chr >= 0xc0) && (chr <= 0xdf)); - fnt = dev->vram + 0x4000 + 16 * chr + dev->sc; + fnt = dev->vram + 0x4000 + 16 * chr + dev->scanline; if (blk) { val = 0x000; /* Blinking, draw all background */ - } else if (dev->sc == ull) { + } else if (dev->scanline == ull) { val = 0x1ff; /* Underscore, draw all foreground */ } else { val = fnt[0] << 1; @@ -384,11 +384,11 @@ draw_char_ram48(herculesplus_t *dev, int x, uint8_t chr, uint8_t attr) else elg = ((chr >= 0xc0) && (chr <= 0xdf)); - fnt = dev->vram + 0x4000 + 16 * chr + 4096 * font + dev->sc; + fnt = dev->vram + 0x4000 + 16 * chr + 4096 * font + dev->scanline; if (blk) { val = 0x000; /* Blinking, draw all background */ - } else if (dev->sc == ull) { + } else if (dev->scanline == ull) { val = 0x1ff; /* Underscore, draw all foreground */ } else { val = fnt[0] << 1; @@ -404,7 +404,7 @@ draw_char_ram48(herculesplus_t *dev, int x, uint8_t chr, uint8_t attr) } static void -text_line(herculesplus_t *dev, uint16_t ca) +text_line(herculesplus_t *dev, uint16_t cursoraddr) { int drawcursor; uint8_t chr; @@ -413,12 +413,12 @@ text_line(herculesplus_t *dev, uint16_t ca) for (uint8_t x = 0; x < dev->crtc[1]; x++) { if (dev->ctrl & 8) { - chr = dev->vram[(dev->ma << 1) & 0x3fff]; - attr = dev->vram[((dev->ma << 1) + 1) & 0x3fff]; + chr = dev->vram[(dev->memaddr << 1) & 0x3fff]; + attr = dev->vram[((dev->memaddr << 1) + 1) & 0x3fff]; } else chr = attr = 0; - drawcursor = ((dev->ma == ca) && dev->con && dev->cursoron); + drawcursor = ((dev->memaddr == cursoraddr) && dev->cursorvisible && dev->cursoron); switch (dev->crtc[HERCULESPLUS_CRTC_XMODE] & 5) { case 0: @@ -437,7 +437,7 @@ text_line(herculesplus_t *dev, uint16_t ca) default: break; } - ++dev->ma; + ++dev->memaddr; if (drawcursor) { int cw = HERCULESPLUS_CW; @@ -452,24 +452,24 @@ text_line(herculesplus_t *dev, uint16_t ca) static void graphics_line(herculesplus_t *dev) { - uint16_t ca; + uint16_t cursoraddr; int c; int plane = 0; uint16_t val; /* Graphics mode. */ - ca = (dev->sc & 3) * 0x2000; + cursoraddr = (dev->scanline & 3) * 0x2000; if ((dev->ctrl & HERCULESPLUS_CTRL_PAGE1) && (dev->ctrl2 & HERCULESPLUS_CTRL2_PAGE1)) - ca += 0x8000; + cursoraddr += 0x8000; 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]; + val = (dev->vram[((dev->memaddr << 1) & 0x1fff) + cursoraddr + 0x10000 * plane] << 8) + | dev->vram[((dev->memaddr << 1) & 0x1fff) + cursoraddr + 0x10000 * plane + 1]; else val = 0; - dev->ma++; + dev->memaddr++; for (c = 0; c < 16; c++) { buffer32->line[dev->displine][(x << 4) + c] = (val & 0x8000) ? 7 : 0; @@ -485,20 +485,20 @@ static void herculesplus_poll(void *priv) { herculesplus_t *dev = (herculesplus_t *) priv; - uint16_t ca = (dev->crtc[15] | (dev->crtc[14] << 8)) & 0x3fff; + uint16_t cursoraddr = (dev->crtc[15] | (dev->crtc[14] << 8)) & 0x3fff; int x; int oldvc; - int oldsc; + int scanline_old; int cw = HERCULESPLUS_CW; VIDEO_MONITOR_PROLOGUE(); if (!dev->linepos) { timer_advance_u64(&dev->timer, dev->dispofftime); - dev->stat |= 1; + dev->status |= 1; dev->linepos = 1; - oldsc = dev->sc; + scanline_old = dev->scanline; if ((dev->crtc[8] & 3) == 3) - dev->sc = (dev->sc << 1) & 7; + dev->scanline = (dev->scanline << 1) & 7; if (dev->dispon) { if (dev->displine < dev->firstline) { dev->firstline = dev->displine; @@ -508,7 +508,7 @@ herculesplus_poll(void *priv) if ((dev->ctrl & HERCULESPLUS_CTRL_GRAPH) && (dev->ctrl2 & HERCULESPLUS_CTRL2_GRAPH)) graphics_line(dev); else - text_line(dev, ca); + text_line(dev, cursoraddr); if ((dev->ctrl & HERCULESPLUS_CTRL_GRAPH) && (dev->ctrl2 & HERCULESPLUS_CTRL2_GRAPH)) x = dev->crtc[1] << 4; @@ -517,40 +517,39 @@ herculesplus_poll(void *priv) video_process_8(x, dev->displine); } - dev->sc = oldsc; - if (dev->vc == dev->crtc[7] && !dev->sc) - dev->stat |= 8; + dev->scanline = scanline_old; + if (dev->vc == dev->crtc[7] && !dev->scanline) + dev->status |= 8; dev->displine++; if (dev->displine >= 500) dev->displine = 0; } else { timer_advance_u64(&dev->timer, dev->dispontime); if (dev->dispon) - dev->stat &= ~1; + dev->status &= ~1; dev->linepos = 0; if (dev->vsynctime) { dev->vsynctime--; if (!dev->vsynctime) - dev->stat &= ~8; + dev->status &= ~8; } - if (dev->sc == (dev->crtc[11] & 31) || ((dev->crtc[8] & 3) == 3 && dev->sc == ((dev->crtc[11] & 31) >> 1))) { - dev->con = 0; - dev->coff = 1; + if (dev->scanline == (dev->crtc[11] & 31) || ((dev->crtc[8] & 3) == 3 && dev->scanline == ((dev->crtc[11] & 31) >> 1))) { + dev->cursorvisible = 0; } if (dev->vadj) { - dev->sc++; - dev->sc &= 31; - dev->ma = dev->maback; + dev->scanline++; + dev->scanline &= 31; + dev->memaddr = dev->memaddr_backup; dev->vadj--; if (!dev->vadj) { dev->dispon = 1; - dev->ma = dev->maback = (dev->crtc[13] | (dev->crtc[12] << 8)) & 0x3fff; - dev->sc = 0; + dev->memaddr = dev->memaddr_backup = (dev->crtc[13] | (dev->crtc[12] << 8)) & 0x3fff; + dev->scanline = 0; } - } else if (dev->sc == dev->crtc[9] || ((dev->crtc[8] & 3) == 3 && dev->sc == (dev->crtc[9] >> 1))) { - dev->maback = dev->ma; - dev->sc = 0; + } else if (dev->scanline == dev->crtc[9] || ((dev->crtc[8] & 3) == 3 && dev->scanline == (dev->crtc[9] >> 1))) { + dev->memaddr_backup = dev->memaddr; + dev->scanline = 0; oldvc = dev->vc; dev->vc++; dev->vc &= 127; @@ -562,7 +561,7 @@ herculesplus_poll(void *priv) if (!dev->vadj) dev->dispon = 1; if (!dev->vadj) - dev->ma = dev->maback = (dev->crtc[13] | (dev->crtc[12] << 8)) & 0x3fff; + dev->memaddr = dev->memaddr_backup = (dev->crtc[13] | (dev->crtc[12] << 8)) & 0x3fff; if ((dev->crtc[10] & 0x60) == 0x20) dev->cursoron = 0; else @@ -607,13 +606,13 @@ herculesplus_poll(void *priv) dev->blink++; } } else { - dev->sc++; - dev->sc &= 31; - dev->ma = dev->maback; + dev->scanline++; + dev->scanline &= 31; + dev->memaddr = dev->memaddr_backup; } - if (dev->sc == (dev->crtc[10] & 31) || ((dev->crtc[8] & 3) == 3 && dev->sc == ((dev->crtc[10] & 31) >> 1))) - dev->con = 1; + if (dev->scanline == (dev->crtc[10] & 31) || ((dev->crtc[8] & 3) == 3 && dev->scanline == ((dev->crtc[10] & 31) >> 1))) + dev->cursorvisible = 1; } VIDEO_MONITOR_EPILOGUE(); @@ -630,6 +629,24 @@ herculesplus_init(UNUSED(const device_t *info)) dev->vram = (uint8_t *) malloc(0x10000); /* 64k VRAM */ dev->monitor_index = monitor_index_global; + switch(device_get_config_int("font")) { + case 0: + loadfont(FONT_IBM_MDA_437_PATH, 0); + break; + case 1: + loadfont(FONT_IBM_MDA_437_NORDIC_PATH, 0); + break; + case 2: + loadfont(FONT_KAM_PATH, 0); + break; + case 3: + loadfont(FONT_KAMCL16_PATH, 0); + break; + case 4: + loadfont(FONT_TULIP_DGA_PATH, 0); + break; + } + timer_add(&dev->timer, herculesplus_poll, dev, 1); mem_mapping_add(&dev->mapping, 0xb0000, 0x08000, @@ -670,7 +687,7 @@ herculesplus_init(UNUSED(const device_t *info)) video_inform(VIDEO_FLAG_TYPE_MDA, &timing_herculesplus); /* Force the LPT3 port to be enabled. */ - lpt3_init(0x3BC); + lpt3_setup(LPT_MDA_ADDR); return dev; } @@ -700,41 +717,52 @@ speed_changed(void *priv) static const device_config_t herculesplus_config[] = { // clang-format off { - .name = "rgb_type", - .description = "Display type", - .type = CONFIG_SELECTION, - .default_int = 0, - .selection = { - { - .description = "Default", - .value = 0 - }, - { - .description = "Green", - .value = 1 - }, - { - .description = "Amber", - .value = 2 - }, - { - .description = "Gray", - .value = 3 - }, - { - .description = "" - } - } + .name = "rgb_type", + .description = "Display type", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Default", .value = 0 }, + { .description = "Green", .value = 1 }, + { .description = "Amber", .value = 2 }, + { .description = "Gray", .value = 3 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "blend", - .description = "Blend", - .type = CONFIG_BINARY, - .default_int = 1 + .name = "font", + .description = "Font", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "US (CP 437)", .value = 0 }, + { .description = "IBM Nordic (CP 437-Nordic)", .value = 1 }, + { .description = "Czech Kamenicky (CP 895) #1", .value = 2 }, + { .description = "Czech Kamenicky (CP 895) #2", .value = 3 }, + { .description = "Tulip DGA", .value = 4 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .type = CONFIG_END - } + .name = "blend", + .description = "Blend", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -746,7 +774,7 @@ const device_t herculesplus_device = { .init = herculesplus_init, .close = herculesplus_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = speed_changed, .force_redraw = NULL, .config = herculesplus_config diff --git a/src/video/vid_ht216.c b/src/video/vid_ht216.c index c1f5cbeaf..3089ae26d 100644 --- a/src/video/vid_ht216.c +++ b/src/video/vid_ht216.c @@ -33,9 +33,12 @@ #include <86box/rom.h> #include <86box/device.h> #include <86box/video.h> +#include <86box/vid_8514a.h> #include <86box/vid_xga.h> #include <86box/vid_svga.h> #include <86box/vid_svga_render.h> +#include <86box/vid_ati_eeprom.h> +#include <86box/vid_ati_mach8.h> #include <86box/plat_fallthrough.h> #include <86box/plat_unused.h> @@ -425,9 +428,8 @@ ht216_out(uint16_t addr, uint8_t val, void *priv) svga->banked_mask = 0xffff; } - if (svga->gdcaddr <= 8) { + if (svga->gdcaddr <= 8) svga->fast = (svga->gdcreg[8] == 0xff && !(svga->gdcreg[3] & 0x18) && !svga->gdcreg[1]) && svga->chain4 && svga->packed_chain4; - } break; case 0x3D4: @@ -446,7 +448,7 @@ ht216_out(uint16_t addr, uint8_t val, void *priv) 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); + svga->memaddr_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5); } else { svga->fullchange = changeframecount; svga_recalctimings(svga); @@ -625,7 +627,9 @@ ht216_remap(ht216_t *ht216) void ht216_recalctimings(svga_t *svga) { - ht216_t *ht216 = (ht216_t *) svga->priv; + ht216_t *ht216 = (ht216_t *) svga->priv; + ibm8514_t *dev = (ibm8514_t *) svga->dev8514; + mach_t *mach = (mach_t *) svga->ext8514; int high_res_256 = 0; @@ -656,10 +660,10 @@ ht216_recalctimings(svga_t *svga) break; } - svga->ma_latch |= ((ht216->ht_regs[0xf6] & 0x30) << 12); + svga->memaddr_latch |= ((ht216->ht_regs[0xf6] & 0x30) << 12); if (ht216->ht_regs[0xf6] & 0x80) - svga->ma_latch = ((ht216->ht_regs[0xf6] & 0x30) << 12); + svga->memaddr_latch = ((ht216->ht_regs[0xf6] & 0x30) << 12); svga->interlace = ht216->ht_regs[0xe0] & 0x01; @@ -672,10 +676,16 @@ ht216_recalctimings(svga_t *svga) if (!svga->scrblank && svga->attr_palette_enable) { if (!(svga->gdcreg[6] & 1) && !(svga->attrregs[0x10] & 1)) { /*Text mode*/ - if (svga->seqregs[1] & 8) /*40 column*/ { + if (svga->seqregs[1] & 8) /*40 column*/ svga->render = svga_render_text_40; - } else { + else svga->render = svga_render_text_80; + + if (ibm8514_active && (svga->dev8514 != NULL)) { + if (svga->ext8514 != NULL) { + if (!(dev->accel.advfunc_cntl & 0x01) && !(mach->accel.clock_sel & 0x01)) /*FIXME: Possibly a BIOS bug within the V7 chips when it's used with a 8514/A card?*/ + dev->on &= ~0x01; + } } } else { if (svga->crtc[0x17] == 0xeb) { @@ -1576,10 +1586,17 @@ ht216_init(const device_t *info, uint32_t mem_size, int has_rom) if (has_rom == 4) svga->ramdac = device_add(&sc11484_nors2_ramdac_device); + svga->read = ht216_read; + svga->readw = NULL; + svga->readl = NULL; + svga->write = ht216_write; + svga->writew = ht216_writew; if ((info->flags & DEVICE_VLB) || (info->flags & DEVICE_MCA)) { + svga->writel = ht216_writel; mem_mapping_set_handler(&svga->mapping, ht216_read, NULL, NULL, ht216_write, ht216_writew, ht216_writel); mem_mapping_add(&ht216->linear_mapping, 0, 0, ht216_read_linear, NULL, NULL, ht216_write_linear, ht216_writew_linear, ht216_writel_linear, NULL, MEM_MAPPING_EXTERNAL, svga); } else { + svga->writel = NULL; mem_mapping_set_handler(&svga->mapping, ht216_read, NULL, NULL, ht216_write, ht216_writew, NULL); mem_mapping_add(&ht216->linear_mapping, 0, 0, ht216_read_linear, NULL, NULL, ht216_write_linear, ht216_writew_linear, NULL, NULL, MEM_MAPPING_EXTERNAL, svga); } @@ -1587,7 +1604,7 @@ ht216_init(const device_t *info, uint32_t mem_size, int has_rom) mem_mapping_disable(&ht216->linear_mapping); ht216->id = info->local; - ht216->isabus = (info->flags & DEVICE_ISA); + ht216->isabus = (info->flags & DEVICE_ISA) || (info->flags & DEVICE_ISA16); ht216->mca = (info->flags & DEVICE_MCA); io_sethandler(0x03c0, 0x0020, ht216_in, NULL, NULL, ht216_out, NULL, NULL, ht216); @@ -1701,52 +1718,45 @@ ht216_force_redraw(void *priv) ht216->svga.fullchange = changeframecount; } +// clang-format off static const device_config_t v7_vga_1024i_config[] = { - { .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 512, - .selection = { - { .description = "256 KB", - .value = 256 }, - { .description = "512 KB", - .value = 512 }, - { .description = "" } } }, - { .type = CONFIG_END } + { + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 512, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "256 KB", .value = 256 }, + { .description = "512 KB", .value = 512 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } }; -// clang-format off static const device_config_t ht216_32_standalone_config[] = { { - .name = "monitor_type", - .description = "Monitor type", - .type = CONFIG_SELECTION, - .default_int = 0x18, - .selection = { - { - .description = "Mono Interlaced", - .value = 0x00 - }, - { - .description = "Mono Non-Interlaced", - .value = 0x08 - }, - { - .description = "Color Interlaced", - .value = 0x10 - }, - { - .description = "Color Non-Interlaced", - .value = 0x18 - }, - { - .description = "" - } - } + .name = "monitor_type", + .description = "Monitor type", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0x18, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Mono Interlaced", .value = 0x00 }, + { .description = "Mono Non-Interlaced", .value = 0x08 }, + { .description = "Color Interlaced", .value = 0x10 }, + { .description = "Color Non-Interlaced", .value = 0x18 }, + { .description = "" } + }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; // clang-format on @@ -1758,7 +1768,7 @@ const device_t g2_gc205_device = { .init = g2_gc205_init, .close = ht216_close, .reset = NULL, - { .available = g2_gc205_available }, + .available = g2_gc205_available, .speed_changed = ht216_speed_changed, .force_redraw = ht216_force_redraw, .config = NULL @@ -1772,7 +1782,7 @@ const device_t v7_vga_1024i_device = { .init = v7_vga_1024i_init, .close = ht216_close, .reset = NULL, - { .available = v7_vga_1024i_available }, + .available = v7_vga_1024i_available, .speed_changed = ht216_speed_changed, .force_redraw = ht216_force_redraw, .config = v7_vga_1024i_config @@ -1786,7 +1796,7 @@ const device_t ht216_32_pb410a_device = { .init = ht216_pb410a_init, .close = ht216_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = ht216_speed_changed, .force_redraw = ht216_force_redraw, .config = NULL @@ -1800,7 +1810,7 @@ const device_t ht216_32_standalone_device = { .init = ht216_standalone_init, .close = ht216_close, .reset = NULL, - { .available = ht216_standalone_available }, + .available = ht216_standalone_available, .speed_changed = ht216_speed_changed, .force_redraw = ht216_force_redraw, .config = ht216_32_standalone_config @@ -1809,12 +1819,12 @@ const device_t ht216_32_standalone_device = { const device_t radius_svga_multiview_isa_device = { .name = "Radius SVGA Multiview ISA (HT209)", .internal_name = "radius_isa", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0x7152, /*HT209*/ .init = radius_svga_multiview_init, .close = ht216_close, .reset = NULL, - { .available = radius_svga_multiview_available }, + .available = radius_svga_multiview_available, .speed_changed = ht216_speed_changed, .force_redraw = ht216_force_redraw, .config = NULL @@ -1828,7 +1838,7 @@ const device_t radius_svga_multiview_mca_device = { .init = radius_svga_multiview_init, .close = ht216_close, .reset = NULL, - { .available = radius_svga_multiview_available }, + .available = radius_svga_multiview_available, .speed_changed = ht216_speed_changed, .force_redraw = ht216_force_redraw, .config = NULL diff --git a/src/video/vid_im1024.c b/src/video/vid_im1024.c index c7602ffd0..a77ad09c3 100644 --- a/src/video/vid_im1024.c +++ b/src/video/vid_im1024.c @@ -1090,7 +1090,7 @@ const device_t im1024_device = { .init = im1024_init, .close = im1024_close, .reset = NULL, - { .available = im1024_available }, + .available = im1024_available, .speed_changed = im1024_speed_changed, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_jega.c b/src/video/vid_jega.c new file mode 100644 index 000000000..f49c92e64 --- /dev/null +++ b/src/video/vid_jega.c @@ -0,0 +1,1054 @@ +/* + * 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 JEGA (Japanese EGA), a part of the AX architecture. + * + * It's an extension of the SuperEGA. Superimposing text (AX-2) is not available. + * + * Authors: Akamaki + * + * Copyright 2025 Akamaki + */ +#include +#include +#include +#include +#include +#include +#include +#define HAVE_STDARG_H +#include <86box/86box.h> +#include "cpu.h" +#include <86box/io.h> +#include <86box/timer.h> +#include <86box/pic.h> +#include <86box/pit.h> +#include <86box/plat.h> +#include <86box/plat_fallthrough.h> +#include <86box/mem.h> +#include <86box/rom.h> +#include <86box/device.h> +#include <86box/video.h> +#include <86box/vid_ega.h> +#include <86box/vid_svga.h> +#include <86box/vid_vga.h> + +/* JEGA internal registers */ +#define RPESL 0x09 /* End Scan Line */ +#define RCCSL 0x0A /* Cursor Start Line */ +#define RCCEL 0x0B /* Cursor End Line */ +#define RCCLH 0x0E /* Cursor Location High */ +#define RCCLL 0x0F /* Cursor Location Low */ +#define RPULP 0x14 /* Under Line Position */ +/* + 0xB8 - 0x20 */ +#define RMOD1 0x21 /* Display out, EGA through, Superimpose, Sync with EGA, Master EGA, Slave EGA, n/a, Test */ +#define RMOD2 0x22 /* 1st Attr, 2nd Attr, Blink/Int, n/a, Font access mode (b3-2), Font map sel (b1-0)*/ +#define RDAGS 0x23 /* ANK Group Select */ +#define RDFFB 0x24 /* Font Access First Byte */ +#define RDFSB 0x25 /* Font Access Second Byte */ +#define RDFAP 0x26 /* Font Access Pattern */ +#define RSTAT 0x27 /* Font Status Register */ +/* + 0xD0 - 0x20 */ +#define RPSSU 0x29 /* Start Scan Upper */ +#define RPSSL 0x2A /* Start Scan Lower */ +#define RPSSC 0x2B /* Start Scan Count */ +#define RPPAJ 0x2C /* Phase Adjust Count */ +#define RCMOD 0x2D /* Cursor Mode */ +#define RCSKW 0x2E /* Cursor Skew Control */ +#define ROMSL 0x2F /* ? */ +#define RINVALID_INDEX 0x30 + +#define JEGA_PATH_BIOS "roms/video/jega/JEGABIOS.BIN" +#define JEGA_PATH_FONTDBCS "roms/video/jega/JPNZN16X.FNT" +#define IF386_PATH_VBIOS "roms/machines/if386sx/OKI_IF386SX_VBIOS.bin" +#define JVGA_PATH_BIOS "roms/video/jega/OKI_JVGT(AXVGAH)_BIOS_011993.BIN" +#define JVGA_PATH_FONTDBCS "roms/video/jega/JWPCE.FNT" +#define SBCS19_FILESIZE (256 * 19 * 2) /* 8 x 19 x 256 chr x 2 pages */ +#define DBCS16_CHARS 0x2c10 +#define DBCS16_FILESIZE (DBCS16_CHARS * 16 * 2) + +#define INVALIDACCESS8 0xffu +#define INVALIDACCESS16 0xffffu +#define INVALIDACCESS32 0xffffffffu + +#ifndef RELEASE_BUILD +// # define ENABLE_JEGA_LOG 1 +#endif + +#ifdef ENABLE_JEGA_LOG +int jega_do_log = ENABLE_JEGA_LOG; + +static void +jega_log(const char *fmt, ...) +{ + va_list ap; + + if (jega_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define jega_log(fmt, ...) +#endif + +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 }; + +typedef struct jega_t { + rom_t bios_rom; + ega_t ega; + vga_t vga; + uint8_t regs_index; /* 3D4/3D5 index B9-BF, D9-DF */ + uint8_t regs[0x31]; + uint8_t egapal[16]; + uint8_t attrregs[32]; + uint8_t attraddr; + uint8_t attrff; + uint8_t attr_palette_enable; + uint32_t *pallook; + int is_vga; + int cursorvisible; + int cursoron; + int cursorblink_disable; + int cursoraddr; + int font_index; + int sbcsbank_inv; + int attr3_sbcsbank; + int start_scan_lower; + int start_scan_upper; + int start_scan_count; + uint8_t * vram; + uint8_t jfont_sbcs_19[SBCS19_FILESIZE]; /* 8 x 19 font */ + uint8_t jfont_dbcs_16[DBCS16_FILESIZE]; /* 16 x 16 font. Use dbcs_read/write to access it. */ +} jega_t; + +static void jega_recalctimings(void *priv); + +#define FONTX_LEN_ID 6 +#define FONTX_LEN_FN 8 + +typedef struct { + char id[FONTX_LEN_ID]; + char name[FONTX_LEN_FN]; + uint8_t width; + uint8_t height; + uint8_t type; +} fontx_h; + +typedef struct { + uint16_t start; + uint16_t end; +} fontx_tbl; + +extern uint32_t pallook16[256]; +extern uint32_t pallook64[256]; +static bool is_SJIS_1(uint8_t chr) { return (chr >= 0x81 && chr <= 0x9f) || (chr >= 0xe0 && chr <= 0xfc); } +static bool is_SJIS_2(uint8_t chr) { return (chr >= 0x40 && chr <= 0x7e) || (chr >= 0x80 && chr <= 0xfc); } + +static uint8_t jega_in(uint16_t addr, void *priv); + +static uint16_t +SJIS_to_SEQ(uint16_t sjis) +{ + uint32_t chr1 = (sjis >> 8) & 0xff; + uint32_t chr2 = sjis & 0xff; + + if (!is_SJIS_1(chr1) || !is_SJIS_2(chr2)) + return INVALIDACCESS16; + + chr1 -= 0x81; + + if (chr1 > 0x5e) + chr1 -= 0x40; + + chr2 -= 0x40; + + if (chr2 > 0x3f) + chr2--; + + chr1 *= 0xbc; + + return (chr1 + chr2); +} + +static uint8_t +dbcs_read(uint16_t sjis, int index, void *priv) { + jega_t *jega = (jega_t *) priv; + int seq = SJIS_to_SEQ(sjis); + if ((seq >= DBCS16_CHARS) || (index >= 32)) + return INVALIDACCESS8; + return jega->jfont_dbcs_16[seq * 32 + index]; +} + +static void +dbcs_write(uint16_t sjis, int index, uint8_t val, void *priv) { + jega_t *jega = (jega_t *) priv; + int seq = SJIS_to_SEQ(sjis); + if ((seq >= DBCS16_CHARS) || (index >= 32)) + return; + jega->jfont_dbcs_16[seq * 32 + index] = val; +} + +/* Display Adapter Mode 3 Drawing */ +void +jega_render_text(void *priv) +{ + jega_t * jega = (jega_t *) priv; +#ifdef USE_DOUBLE_WIDTH_AND_LINE_CHARS + uint8_t * seqregs = jega->is_vga ? jega->vga.svga.seqregs : + jega->ega.seqregs; + uint8_t * attrregs = jega->is_vga ? jega->vga.svga.attrregs : + jega->ega.attrregs; +#endif + uint8_t * crtc = jega->is_vga ? jega->vga.svga.crtc : + jega->ega.crtc; + uint8_t * vram = jega->is_vga ? jega->vga.svga.vram : + jega->ega.vram; + int * firstline_draw = jega->is_vga ? &jega->vga.svga.firstline_draw : + &jega->ega.firstline_draw; + int * lastline_draw = jega->is_vga ? &jega->vga.svga.lastline_draw : + &jega->ega.lastline_draw; + int * displine = jega->is_vga ? &jega->vga.svga.displine : + &jega->ega.displine; + int * fullchange = jega->is_vga ? &jega->vga.svga.fullchange : + &jega->ega.fullchange; + int * blink = jega->is_vga ? &jega->vga.svga.blink : + &jega->ega.blink; + int * x_add = jega->is_vga ? &jega->vga.svga.x_add : + &jega->ega.x_add; + int * y_add = jega->is_vga ? &jega->vga.svga.y_add : + &jega->ega.y_add; + int * sc = jega->is_vga ? &jega->vga.svga.scanline : + &jega->ega.scanline; + int * hdisp = jega->is_vga ? &jega->vga.svga.hdisp : + &jega->ega.hdisp; + int * scrollcache = jega->is_vga ? &jega->vga.svga.scrollcache : + &jega->ega.scrollcache; + uint32_t *memaddr = jega->is_vga ? &jega->vga.svga.memaddr : + &jega->ega.memaddr; + uint8_t mask = jega->is_vga ? jega->vga.svga.dac_mask : 0xff; + + if (*firstline_draw == 2000) + *firstline_draw = *displine; + *lastline_draw = *displine; + + if (*fullchange) { +#ifdef USE_DOUBLE_WIDTH_AND_LINE_CHARS + const bool doublewidth = ((seqregs[1] & 8) != 0); + const bool attrlinechars = (attrregs[0x10] & 4); +#endif + const bool attrblink = ((jega->regs[RMOD2] & 0x20) == 0); /* JEGA specific */ + const bool crtcreset = ((crtc[0x17] & 0x80) == 0) || ((jega->regs[RMOD1] & 0x80) == 0); + const int charwidth = 8; + const bool blinked = *blink & 0x10; + uint32_t *p = &buffer32->line[*displine + *y_add][*x_add]; + bool chr_wide = false; + int sc_wide = *sc - jega->start_scan_count; + const bool cursoron = (blinked || jega->cursorblink_disable) && + (*sc >= jega->regs[RCCSL]) && (*sc <= jega->regs[RCCEL]); + uint32_t attr_basic = 0; + uint32_t chr_first; + int fg = 0; + int bg; + + for (int x = 0; x < (*hdisp + *scrollcache); x += charwidth) { + uint32_t addr = 0; + + if (jega->is_vga) { + if (!jega->vga.svga.force_old_addr) + addr = jega->vga.svga.remap_func(&jega->vga.svga, jega->vga.svga.memaddr) & + jega->vga.svga.vram_display_mask; + } else + addr = jega->ega.remap_func(&jega->ega, *memaddr) & jega->ega.vrammask; + + int drawcursor = ((*memaddr == jega->cursoraddr) && cursoron); + + uint32_t chr; + uint32_t attr; + if (!crtcreset) { + chr = vram[addr]; + attr = vram[addr + 1]; + } else + chr = attr = 0; + if (chr_wide) { + uint8_t attr_ext = 0; + /* the code may be in DBCS */ + if (jega->regs[RMOD2] & 0x40) { + /* Parse JEGA extended attribute */ + /* Bold | 2x width | 2x height | U/L select | R/L select | - | - | - */ + attr_ext = attr; + if ((attr_ext & 0x30) == 0x30) + sc_wide = *sc - jega->start_scan_lower; /* Set top padding of lower 2x character */ + else if ((attr_ext & 0x30) == 0x20) + sc_wide = *sc - jega->start_scan_upper; /* Set top padding of upper 2x character */ + else + sc_wide = *sc - jega->start_scan_count; + } + if (is_SJIS_2(chr) && sc_wide >= 0 && sc_wide < 16 && *sc <= jega->regs[RPESL]) { + chr_first <<= 8; + chr |= chr_first; + /* Vertical wide font (Extended Attribute) */ + if (attr_ext & 0x20) { + if (attr_ext & 0x10) + sc_wide = (sc_wide >> 1) + 8; + else + sc_wide = sc_wide >> 1; + } + /* Horizontal wide font (Extended Attribute) */ + if (attr_ext & 0x40) { + uint32_t dat = dbcs_read(chr, sc_wide, jega); + if (!(attr_ext & 0x08)) { /* right half of character */ + dat = dbcs_read(chr, sc_wide + 16, jega); + } + for (int xx = 0; xx < charwidth; xx++) { + p[xx * 2] = (dat & (0x80 >> xx)) ? fg : bg; + p[xx * 2 + 1] = (dat & (0x80 >> xx)) ? fg : bg; + } + } else { + uint32_t dat = dbcs_read(chr, sc_wide, jega); + dat <<= 8; + dat |= dbcs_read(chr, sc_wide + 16, jega); + /* Bold (Extended Attribute) */ + if (attr_ext &= 0x80) { + uint32_t dat2 = dat; + dat2 >>= 1; + dat |= dat2; + } + for (int xx = 0; xx < charwidth * 2; xx++) + p[xx] = (dat & (0x8000 >> xx)) ? fg : bg; + } + } else { + /* invalid DBCS code or line space then put blank */ + for (int xx = 0; xx < charwidth * 2; xx++) + p[xx] = bg; + } + if (attr_basic & 0x20) { /* vertical line */ + p[0] = fg; + } + if ((*sc == jega->regs[RPULP]) && (attr_basic & 0x10)) { /* underline */ + for (int xx = 0; xx < charwidth * 2; xx++) + p[xx] = fg; + } + chr_wide = false; + p += (charwidth * 2); + } else { + /* SBCS or invalid second byte of DBCS */ + if (jega->regs[RMOD2] & 0x80) { + /* Parse attribute as JEGA */ + /* Blink | Reverse | V line | U line | (Bit 3-0 is the same as EGA) */ + /* The background color is always black (transparent in AX-2) */ + if (drawcursor || attr & 0x40) { + bg = jega->pallook[jega->egapal[attr & 0x0f]]; + fg = 0; + } else { + fg = jega->pallook[jega->egapal[attr & 0x0f]]; + bg = 0; + if (attr & 0x80) { + bg = 0; + if (blinked) + fg = bg; + } + } + attr_basic = attr; + } else { + /* Parse attribute as EGA */ + /* BInt/Blink | BR | BG | BB | Int/Group | R | G | B */ + if (drawcursor) { + bg = jega->pallook[jega->egapal[attr & 0x0f] & mask]; + fg = jega->pallook[jega->egapal[attr >> 4] & mask]; + } else { + fg = jega->pallook[jega->egapal[attr & 0x0f] & mask]; + bg = jega->pallook[jega->egapal[attr >> 4] & mask]; + if ((attr & 0x80) && attrblink) { + bg = jega->pallook[jega->egapal[(attr >> 4) & 7] & mask]; + if (blinked) + fg = bg; + } + } + attr_basic = 0; + } + + if (is_SJIS_1(chr)) { + /* the char code maybe in DBCS */ + chr_first = chr; + chr_wide = true; + } else { + /* the char code is in SBCS */ + uint32_t charaddr = chr; + // if (jega->attr3_sbcsbank && (attr & 8)) + // charaddr |= 0x100; + // if (jega->sbcsbank_inv) + // charaddr ^= 0x100; + charaddr *= 19; + + uint32_t dat = jega->jfont_sbcs_19[charaddr + *sc]; + for (int xx = 0; xx < charwidth; xx++) + p[xx] = (dat & (0x80 >> xx)) ? fg : bg; + + if (attr_basic & 0x20) { /* vertical line */ + p[0] = fg; + } + if ((*sc == jega->regs[RPULP]) && (attr_basic & 0x10)) { /* underline */ + for (int xx = 0; xx < charwidth; xx++) + p[xx] = fg; + } + p += charwidth; + } + } + *memaddr += 4; + } + *memaddr &= 0x3ffff; + } +} + +static void +jega_out(uint16_t addr, uint8_t val, void *priv) +{ + jega_t *jega = (jega_t *) priv; + uint8_t pal4to16[16] = { 0, 7, 0x38, 0x3f, 0, 3, 4, 0x3f, 0, 2, 4, 0x3e, 0, 3, 5, 0x3f }; + uint16_t chr; + + // jega_log("JEGA Out %04X %02X(%d) %04X:%04X\n", addr, val, val, cs >> 4, cpu_state.pc); + + switch (addr) { + case 0x3c0: + case 0x3c1: + jega_log("Palette %02X %02X(%d) %04X:%04X\n", jega->attraddr, val, val, cs >> 4, cpu_state.pc); + /* Palette (write only) */ + if (!jega->attrff) { + jega->attraddr = val & 31; + if ((val & 0x20) != jega->attr_palette_enable) { + if (jega->is_vga) + jega->vga.svga.fullchange = 3; + else + jega->ega.fullchange = 3; + jega->attr_palette_enable = val & 0x20; + jega_recalctimings(jega); + } + } else { + jega->attrregs[jega->attraddr & 31] = val; + int is_attr14 = jega->is_vga ? (jega->attraddr == 0x14) : 0; + if (is_attr14 || (jega->attraddr < 0x10)) { + for (uint8_t c = 0; c < 16; c++) { + if (jega->is_vga) { + if (jega->attrregs[0x10] & 0x80) + jega->egapal[c] = (jega->attrregs[c] & 0xf) | ((jega->attrregs[0x14] & 0xf) << 4); + else if (jega->vga.svga.ati_4color) + jega->egapal[c] = pal4to16[(c & 0x03) | ((val >> 2) & 0xc)]; + else + jega->egapal[c] = (jega->attrregs[c] & 0x3f) | ((jega->attrregs[0x14] & 0xc) << 4); + } else + jega->egapal[c] = jega->attrregs[c] & 0x3f; + } + if (jega->is_vga) + jega->vga.svga.fullchange = changeframecount; + else + jega->ega.fullchange = changeframecount; + } + } + jega->attrff ^= 1; + break; + case 0x3c2: + if (jega->regs[RMOD1] & 0x0c) { + io_removehandler(0x03a0, 0x0020, jega_in, NULL, NULL, jega_out, NULL, NULL, jega); + if (!(val & 1)) + io_sethandler(0x03a0, 0x0020, jega_in, NULL, NULL, jega_out, NULL, NULL, jega); + } + break; + case 0x3b4: + case 0x3d4: + /* Index 0x00-0x1F (write only), 0xB8-0xDF (write and read) */ + if (val >= 0xB8 && val <= 0xBF) + jega->regs_index = val - 0xB8 + 0x20; + else if (val >= 0xD8 && val <= 0xDF) + jega->regs_index = val - 0xD0 + 0x20; + else if (val <= 0x1F) + jega->regs_index = val; + else + jega->regs_index = RINVALID_INDEX; + break; + case 0x3b5: + case 0x3d5: + /* Data */ + if (jega->regs_index != RINVALID_INDEX) { + if ((jega->regs_index < 7) && (jega->regs[0x11] & 0x80)) + return; + if ((jega->regs_index == 7) && (jega->regs[0x11] & 0x80)) + val = (jega->regs[7] & ~0x10) | (val & 0x10); + /* + Do not allow cursor updates if neither master nor slave is + active - the AX Windows 3.0 386 Enhanced Mode DOS grabber + relies on this for the cursor position to behave correctly. + */ + if ((jega->regs_index >= 0x0e) && (jega->regs_index <= 0x0f) && !(jega->regs[RMOD1] & 0x0c)) + return; + jega->regs[jega->regs_index] = val; + jega_log("JEGA Out %04X(%02X) %02Xh(%d) %04X:%04X\n", addr, jega->regs_index, val, val, cs >> 4, cpu_state.pc); + switch (jega->regs_index) { + case RMOD1: + /* if the value is changed */ + /* + Do not allow override toggling unless it's on master and + only override the text renderer - the AX Windows 3.0 386 + Enhanced Mode DOS grabber relies on this for the grabbing + to behave correctly. + */ + if (val & 0x08) { + if (jega->is_vga) { + if (val & 0x40) + jega->vga.svga.render_override = NULL; + else + jega->vga.svga.render_override = jega_render_text; + } else { + if (val & 0x40) + jega->ega.render_override = NULL; + else + jega->ega.render_override = jega_render_text; + } + } + break; + case RDAGS: + switch (val & 0x03) { + case 0x00: + jega->attr3_sbcsbank = false; + jega->sbcsbank_inv = false; + break; + case 0x01: + jega->attr3_sbcsbank = true; + jega->sbcsbank_inv = false; + break; + case 0x02: + jega->attr3_sbcsbank = true; + jega->sbcsbank_inv = true; + break; + case 0x03: + jega->attr3_sbcsbank = false; + jega->sbcsbank_inv = true; + break; + } + break; + case RCCLH: + case RCCLL: + jega->cursoraddr = jega->regs[RCCLH] << 10 | jega->regs[RCCLL] << 2; + break; + case RCMOD: + jega->cursoron = (val & 0x80); + jega->cursorblink_disable = (~val & 0x20); + break; + case RDFFB: + case RDFSB: + /* reset the line number */ + jega->font_index = 0; + break; + case RPSSC: + if (val <= 17) + jega->start_scan_count = val + 1; + else + jega->start_scan_count = (val - 32) + 1; + break; + case RPSSL: + jega->start_scan_lower = val - 15; + break; + case RPSSU: + if (val <= 33) + jega->start_scan_upper = val + 4; + else + jega->start_scan_upper = (val - 64) + 4; + break; + case RDFAP: + chr = jega->regs[RDFFB]; + if (is_SJIS_1(chr) && chr >= 0xf0 && chr <= 0xf3) { + chr <<= 8; + chr |= jega->regs[RDFSB]; + if (jega->font_index < 32) + dbcs_write(chr, jega->font_index, val, jega); + } else { + if (jega->font_index <19) + jega->jfont_sbcs_19[chr * 19 + jega->font_index] = val; + } + jega_log("JEGA Font W %X %d %02Xh(%d) %04X:%04X\n", chr, jega->font_index, val, val, cs >> 4, cpu_state.pc); + jega->font_index++; + break; + } + } + break; + default: + break; + } + + /* Accessing to Slave EGA is redirected to Master in AX-1. */ + if (jega->regs[RMOD1] & 0x0c) { + if (jega->is_vga) + vga_out(addr, val, &jega->vga); + else + ega_out(addr, val, &jega->ega); + } +} + +static uint8_t +jega_in(uint16_t addr, void *priv) +{ + jega_t *jega = (jega_t *) priv; + uint8_t ret = INVALIDACCESS8; + uint16_t chr; + + switch (addr) { + case 0x3b5: + case 0x3d5: + if (jega->regs_index >= 0x20 && jega->regs_index <= 0x2F) { + switch (jega->regs_index) { + case RDFAP: + chr = jega->regs[RDFFB]; + /* DBCS or SBCS */ + if (is_SJIS_1(chr)) { + chr <<= 8; + chr |= jega->regs[RDFSB]; + if (jega->font_index < 32) + ret = dbcs_read(chr, jega->font_index, jega); + } else { + if (jega->font_index < 19) + ret = jega->jfont_sbcs_19[chr * 19 + jega->font_index]; + } + jega_log("JEGA Font R %X %d %02Xh(%d) %04X:%04X\n", chr, jega->font_index, ret, ret, cs >> 4, cpu_state.pc); + jega->font_index++; + break; + case RSTAT: + ret = 0x03; + break; + default: + ret = jega->regs[jega->regs_index]; + break; + } + jega_log("JEGA In %04X(%02X) %02X %04X:%04X\n", addr, jega->regs_index, ret, cs >> 4, cpu_state.pc); + } else if (jega->regs[RMOD1] & 0x0c) { + /* Accessing to Slave EGA is redirected to Master in AX-1. */ + if (jega->is_vga) + ret = vga_in(addr, &jega->vga); + else + ret = ega_in(addr, &jega->ega); + } + break; + case 0x3ba: + case 0x3da: + jega->attrff = 0; + fallthrough; + default: + /* Accessing to Slave is redirected to Master in AX-1. */ + if (jega->regs[RMOD1] & 0x0c) { + if (jega->is_vga) + ret = vga_in(addr, &jega->vga); + else + ret = ega_in(addr, &jega->ega); + } + break; + } + // jega_log("JEGA In %04X(%02X) %02X %04X:%04X\n", addr, jega->regs_index, ret, cs >> 4, cpu_state.pc); + return ret; +} + +static int +getfontx2header(FILE *fp, fontx_h *header) +{ + fread(header->id, FONTX_LEN_ID, 1, fp); + if (strncmp(header->id, "FONTX2", FONTX_LEN_ID) != 0) { + return 1; + } + fread(header->name, FONTX_LEN_FN, 1, fp); + header->width = (uint8_t) getc(fp); + header->height = (uint8_t) getc(fp); + header->type = (uint8_t) getc(fp); + return 0; +} + +static uint16_t +chrtosht(FILE *fp) +{ + uint16_t i, j; + i = (uint16_t) getc(fp); + j = (uint16_t) getc(fp) << 8; + return (i | j); +} + +static void +readfontxtbl(fontx_tbl *table, int size, FILE *fp) +{ + while (size > 0) { + table->start = chrtosht(fp); + table->end = chrtosht(fp); + ++table; + --size; + } +} + +static int +LoadFontxFile(const char *fn, void *priv) +{ + fontx_h fhead; + fontx_tbl *ftbl; + uint16_t code; + uint16_t scode; + uint8_t size; + uint8_t buf; + int line; + jega_t *jega = (jega_t *) priv; + FILE *fp = rom_fopen(fn, "rb"); + jega_log("JEGA: Loading font\n"); + if (fp == NULL) { + jega_log("JEGA: font file '%s' not found.\n", fn); + return 0; + } + if (getfontx2header(fp, &fhead) != 0) { + fclose(fp); + jega_log("JEGA: FONTX2 header is incorrect.\n"); + return 1; + } + /* DBCS or SBCS */ + if (fhead.type == 1) { + if (fhead.width == 16 && fhead.height == 16) { + size = getc(fp); + ftbl = (fontx_tbl *) calloc(size, sizeof(fontx_tbl)); + readfontxtbl(ftbl, size, fp); + for (int i = 0; i < size; i++) { + for (code = ftbl[i].start; code <= ftbl[i].end; code++) { + scode = SJIS_to_SEQ(code); + if (scode != INVALIDACCESS16) { + for (line = 0; line < 16; line++) { + fread(&buf, sizeof(uint8_t), 1, fp); + jega->jfont_dbcs_16[(int) (scode * 32) + line] = buf; + fread(&buf, sizeof(uint8_t), 1, fp); + jega->jfont_dbcs_16[(int) (scode * 32) + line + 16] = buf; + } + } else { + fseek(fp, 32, SEEK_CUR); + } + } + } + } else { + fclose(fp); + jega_log("JEGA: Width or height of DBCS font doesn't match.\n"); + return 1; + } + } else { + if (fhead.width == 8 && fhead.height == 19) { + fread(jega->jfont_sbcs_19, sizeof(uint8_t), SBCS19_FILESIZE, fp); + } else { + fclose(fp); + jega_log("JEGA: Width or height of SBCS font doesn't match.\n"); + return 1; + } + } + fclose(fp); + return 0; +} + +static void +jega_commoninit(const device_t *info, void *priv, int vga) +{ + jega_t *jega = (jega_t *) priv; + jega->is_vga = vga; + if (vga) { + video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_vga); + svga_init(info, &jega->vga.svga, &jega->vga, 1 << 18, /*256kb*/ + NULL, + jega_in, jega_out, + NULL, + NULL); + + jega->vga.svga.bpp = 8; + jega->vga.svga.miscout = 1; + + jega->vga.svga.vga_enabled = 0; + jega->vga.svga.priv_parent = jega; + jega->pallook = jega->vga.svga.pallook; + io_sethandler(0x03c0, 0x0020, jega_in, NULL, NULL, jega_out, NULL, NULL, jega); + } else { + for (int c = 0; c < 256; c++) { + pallook64[c] = makecol32(((c >> 2) & 1) * 0xaa, ((c >> 1) & 1) * 0xaa, (c & 1) * 0xaa); + pallook64[c] += makecol32(((c >> 5) & 1) * 0x55, ((c >> 4) & 1) * 0x55, ((c >> 3) & 1) * 0x55); + } + video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_ega); + jega->pallook = pallook64; + ega_init(&jega->ega, 9, 0); + ega_set_type(&jega->ega, EGA_SUPEREGA); + jega->ega.priv_parent = jega; + mem_mapping_add(&jega->ega.mapping, 0xa0000, 0x20000, + ega_read, NULL, NULL, ega_write, NULL, NULL, + NULL, MEM_MAPPING_EXTERNAL, &jega->ega); + /* I/O 3DD and 3DE are used by Oki if386 */ + io_sethandler(0x03c0, 0x001c, jega_in, NULL, NULL, jega_out, NULL, NULL, jega); + } + /* I/O 3DD and 3DE are used by Oki if386 */ + // io_sethandler(0x03b0, 0x002c, jega_in, NULL, NULL, jega_out, NULL, NULL, jega); + jega->regs[RMOD1] = 0x48; +} + +static void * +jega_standalone_init(const device_t *info) +{ + jega_t *jega = calloc(1, sizeof(jega_t)); + + rom_init(&jega->bios_rom, JEGA_PATH_BIOS, 0xc0000, 0x8000, 0x7fff, 0, 0); + memset(&jega->jfont_dbcs_16, 0, DBCS16_FILESIZE); + LoadFontxFile(JEGA_PATH_FONTDBCS, jega); + + jega_commoninit(info, jega, 0); + + return jega; +} + +static void * +jvga_standalone_init(const device_t *info) +{ + jega_t *jega = calloc(1, sizeof(jega_t)); + + rom_init(&jega->bios_rom, JVGA_PATH_BIOS, 0xc0000, 0x8000, 0x7fff, 0, 0); + memset(&jega->jfont_dbcs_16, 0, DBCS16_FILESIZE); + LoadFontxFile(JVGA_PATH_FONTDBCS, jega); + + jega_commoninit(info, jega, 1); + + return jega; +} + +static void +jega_close(void *priv) +{ + jega_t *jega = (jega_t *) priv; +#ifdef ENABLE_JEGA_LOG + FILE *f; + // f = fopen("jega_font16.dmp", "wb"); + // if (f != NULL) { + // fwrite(jega->jfont_dbcs_16, DBCS16_FILESIZE, 1, f); + // fclose(f); + // } + // f = fopen("jega_font19.dmp", "wb"); + // if (f != NULL) { + // fwrite(jega->jfont_sbcs_19, SBCS19_FILESIZE, 1, f); + // fclose(f); + // } + f = fopen("jega_regs.txt", "wb"); + if (f != NULL) { + for (int i = 0; i < 49; i++) + fprintf(f, "Regs %02X: %4X\n", i, jega->regs[i]); + for (int i = 0; i < 32; i++) + fprintf(f, "Attr %02X: %4X\n", i, jega->attrregs[i]); + for (int i = 0; i < 16; i++) + fprintf(f, "JEGAPal %02X: %4X\n", i, jega->egapal[i]); + for (int i = 0; i < 16; i++) + fprintf(f, "EGAPal %02X: %4X\n", i, jega->ega.egapal[i]); + for (int i = 0; i < 64; i++) + fprintf(f, "RealPal %02X: %4X\n", i, jega->pallook[i]); + fclose(f); + } + // f = fopen("ega_vram.dmp", "wb"); + // if (f != NULL) { + // fwrite(jega->ega.vram, 256 * 1024, 1, f); + // fclose(f); + // } + f = fopen("ram_bda.dmp", "wb"); + if (f != NULL) { + fwrite(&ram[0x0], 0x500, 1, f); + fclose(f); + } + pclog("jeclosed %04X:%04X DS %04X\n", cs >> 4, cpu_state.pc, DS); +#endif + + if (jega->is_vga) + svga_close(&jega->vga.svga); + else { + if (jega->ega.eeprom) + free(jega->ega.eeprom); + free(jega->ega.vram); + } + + free(jega); +} + +static void +jega_recalctimings(void *priv) +{ + jega_t *jega = (jega_t *) priv; + + if (jega->is_vga) + svga_recalctimings(&jega->vga.svga); + else + ega_recalctimings(&jega->ega); +} + +static void +jega_speed_changed(void *priv) +{ + jega_t *jega = (jega_t *) priv; + + jega_recalctimings(jega); +} + +static int +jega_standalone_available(void) +{ + return (rom_present(JEGA_PATH_BIOS) && rom_present(JEGA_PATH_FONTDBCS)); +} + +const device_t jega_device = { + .name = "JEGA", + .internal_name = "jega", + .flags = DEVICE_ISA, + .local = 0, + .init = jega_standalone_init, + .close = jega_close, + .reset = NULL, + .available = jega_standalone_available, + .speed_changed = jega_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t jvga_device = { + .name = "OKIVGA/H-2 (JVGA/H)", + .internal_name = "jvga", + .flags = DEVICE_ISA, + .local = 0, + .init = jvga_standalone_init, + .close = jega_close, + .reset = NULL, + .available = jega_standalone_available, + .speed_changed = jega_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +static uint8_t p65idx = 0; +// static uint8_t p3de_idx = 0; +static uint8_t p65[6]; +// static uint8_t p3de[0x30]; + + +static uint8_t +if386_p6x_read(uint16_t port, void *priv) +{ + uint8_t ret = INVALIDACCESS8; + if (port == 0x63) { + ret = p65idx; + } else if (port == 0x65) { + ret = p65[p65idx]; + } + // pclog("p%x_r: [%04x:%04x] [%02x]%02x\n", port, cs >> 4, cpu_state.pc , p65idx, ret); + return ret; +} + +/* + OKi if386AX/SX Power management and Miscellaneous + I/O 63h: Index 0-5, I/O 65h: Data + Index 2: + Bit 3: Caps Lock enabled + Bit 2: Num Lock enabled + Bit 1: Scrl Lock enabled + Bit 0: Kana Lock enabled + Index 3 + Bit 2: External monitor output enabled + Bit 1: Floppy drive 1 active + Bit 0: Floppy drive 0 active + Index 5 + Bit 8: ? (1=Disabled, 0=Enabled) + Bit 7: Screen Off? (enabled by Ctrl + Alt + [1] and disabled by any key) + Bit 4: Shutdown? (caused by POST rebooting and POWER OFF command in DOS 3.21) + Bit 3: ? +*/ +static uint32_t lcd_cols[8] = { 0x001024, 0x747d8a, 0x8c96a4, 0xa0abbb, + 0xb1bece, 0xc0cee0, 0xceddf0, 0xdbebff }; +static void +if386_p6x_write(uint16_t port, uint8_t val, void *priv) +{ + jega_t *jega = (jega_t *) priv; + // pclog("p%x_w: [%04x:%04x] val=%02x\n", port, cs >> 4, cpu_state.pc, val); + if (port == 0x63 && val < 6) + p65idx = val; + if (port == 0x65) { + // pclog("p65_w: [%04x:%04x] idx=%02x, val=%02x\n", cs >> 4, cpu_state.pc, p65idx, val); + p65[p65idx] = val; + if (p65idx == 0x03) { + if (val & 0x04) { /* Color monitor */ + for (int c = 0; c < 256; c++) { + pallook64[c] = makecol32(((c >> 2) & 1) * 0xaa, ((c >> 1) & 1) * 0xaa, (c & 1) * 0xaa); + pallook64[c] += makecol32(((c >> 5) & 1) * 0x55, ((c >> 4) & 1) * 0x55, ((c >> 3) & 1) * 0x55); + pallook16[c] = makecol32(((c >> 2) & 1) * 0xaa, ((c >> 1) & 1) * 0xaa, (c & 1) * 0xaa); + pallook16[c] += makecol32(((c >> 4) & 1) * 0x55, ((c >> 4) & 1) * 0x55, ((c >> 4) & 1) * 0x55); + if ((c & 0x17) == 6) + pallook16[c] = makecol32(0xaa, 0x55, 0); + } + } else { /* Monochrome LCD */ + for (int c = 0; c < 256; c++) { + int cval = 0; +#ifdef SIMPLE_BW + if (c & 0x0f) + cval = ((c & 0x0e) * 0x10) + 0x1f; + pallook64[c] = makecol32(cval, cval, cval); + pallook16[c] = makecol32(cval, cval, cval); +#else + if (c & 0x3f) { + cval = (c & 0x10) >> 2; + cval |= (c & 0x06) >> 1; + } + pallook64[c] = lcd_cols[cval]; + cval = 0; + if (c & 0x0f) + cval = (c & 0x0e) >> 1; + pallook16[c] = lcd_cols[cval]; +#endif + } + } + jega_recalctimings(jega); + } else if (p65idx == 0x05) { + if (val & 0x10) { + /* Power off (instead this call hardware reset here) */ + device_reset_all(DEVICE_ALL); + resetx86(); + } + } + } + return; +} + +static void * +if386jega_init(const device_t *info) +{ + jega_t *jega = calloc(1, sizeof(jega_t)); + + rom_init(&jega->bios_rom, IF386_PATH_VBIOS, 0xc0000, 0x8000, 0x7fff, 0, 0); + memset(&jega->jfont_dbcs_16, 0, DBCS16_FILESIZE); + LoadFontxFile(JEGA_PATH_FONTDBCS, jega); + + jega_commoninit(info, jega, 0); + + io_sethandler(0x0063, 1, if386_p6x_read, NULL, NULL, if386_p6x_write, NULL, NULL, jega); + io_sethandler(0x0065, 1, if386_p6x_read, NULL, NULL, if386_p6x_write, NULL, NULL, jega); + // io_sethandler(0x03dd, 2, if386_p6x_read, NULL, NULL, if386_p6x_write, NULL, NULL, jega); + + return jega; +} + +static int +if386jega_available(void) +{ + return (rom_present(IF386_PATH_VBIOS) && rom_present(JEGA_PATH_FONTDBCS)); +} + +const device_t if386jega_device = { + .name = "JEGA (if386AX)", + .internal_name = "if386jega", + .flags = DEVICE_ISA, + .local = 0, + .init = if386jega_init, + .close = jega_close, + .reset = NULL, + .available = if386jega_available, + .speed_changed = jega_speed_changed, + .force_redraw = NULL, + .config = NULL +}; diff --git a/src/video/vid_mda.c b/src/video/vid_mda.c index 702fb7e32..5330e2ab3 100644 --- a/src/video/vid_mda.c +++ b/src/video/vid_mda.c @@ -6,16 +6,19 @@ * * This file is part of the 86Box distribution. * - * MDA emulation. + * IBM Monochrome Display and Printer Adapter emulation. * * * * Authors: Sarah Walker, * Miran Grca, + * Connor Hyde, * * Copyright 2008-2019 Sarah Walker. - * Copyright 2016-2019 Miran Grca. + * Copyright 2016-2025 Miran Grca. + * Copyright 2025 starfrost / Connor Hyde */ +#include #include #include #include @@ -33,7 +36,17 @@ #include <86box/vid_mda.h> #include <86box/plat_unused.h> -static int mdacols[256][2][2]; +// Enumerates MDA monitor types +enum mda_monitor_type_e { + MDA_MONITOR_TYPE_DEFAULT = 0, // Default MDA monitor type. + MDA_MONITOR_TYPE_GREEN = 1, // Green phosphor + MDA_MONITOR_TYPE_AMBER = 2, // Amber phosphor + MDA_MONITOR_TYPE_GRAY = 3, // Gray phosphor + MDA_MONITOR_TYPE_RGBI = 4, // RGBI colour monitor with modified rev1 or rev0 MDA card for colour support +} mda_monitor_type; + +// [attr][blink][fg] +static int mda_attr_to_color_table[256][2][2]; static video_timings_t timing_mda = { .type = VIDEO_ISA, .write_b = 8, .write_w = 16, .write_l = 32, .read_b = 8, .read_w = 16, .read_l = 32 }; @@ -44,32 +57,31 @@ mda_out(uint16_t addr, uint8_t val, void *priv) { mda_t *mda = (mda_t *) priv; - switch (addr) { - case 0x3b0: - case 0x3b2: - case 0x3b4: - case 0x3b6: - mda->crtcreg = val & 31; - return; - case 0x3b1: - case 0x3b3: - case 0x3b5: - case 0x3b7: - mda->crtc[mda->crtcreg] = val; - if (mda->crtc[10] == 6 && mda->crtc[11] == 7) /*Fix for Generic Turbo XT BIOS, which sets up cursor registers wrong*/ - { - mda->crtc[10] = 0xb; - mda->crtc[11] = 0xc; - } - mda_recalctimings(mda); - return; - case 0x3b8: - mda->ctrl = val; - return; + if (addr < MDA_REGISTER_START + || addr > MDA_REGISTER_CRT_STATUS) // Maintain old behaviour for printer registers, just in case + return; + switch (addr) { + case MDA_REGISTER_MODE_CONTROL: + mda->mode = val; + return; default: break; } + + // addr & 1 == 1 = MDA_REGISTER_CRTC_DATA + // otherwise MDA_REGISTER_CRTC_INDEX + if (addr & 1) { + mda->crtc[mda->crtcreg] = val; + if (mda->crtc[MDA_CRTC_CURSOR_START] == 6 + && mda->crtc[MDA_CRTC_CURSOR_END] == 7) /*Fix for Generic Turbo XT BIOS, which sets up cursor registers wrong*/ + { + mda->crtc[MDA_CRTC_CURSOR_START] = 0xb; + mda->crtc[MDA_CRTC_CURSOR_END] = 0xc; + } + mda_recalctimings(mda); + } else + mda->crtcreg = val & 31; } uint8_t @@ -78,23 +90,23 @@ mda_in(uint16_t addr, void *priv) const mda_t *mda = (mda_t *) priv; switch (addr) { - case 0x3b0: - case 0x3b2: - case 0x3b4: - case 0x3b6: - return mda->crtcreg; - case 0x3b1: - case 0x3b3: - case 0x3b5: - case 0x3b7: - return mda->crtc[mda->crtcreg]; - case 0x3ba: - return mda->stat | 0xF0; - + case MDA_REGISTER_CRT_STATUS: + return mda->status | 0xF0; default: + if (addr < MDA_REGISTER_START + || addr > MDA_REGISTER_CRT_STATUS) // Maintain old behaviour for printer registers, just in case + return 0xFF; + + // MDA_REGISTER_CRTC_DATA + if (addr & 1) + return mda->crtc[mda->crtcreg]; + else + return mda->crtcreg; + break; } - return 0xff; + + return 0xFF; } void @@ -118,8 +130,8 @@ mda_recalctimings(mda_t *mda) double _dispontime; double _dispofftime; double disptime; - disptime = mda->crtc[0] + 1; - _dispontime = mda->crtc[1]; + disptime = mda->crtc[MDA_CRTC_HTOTAL] + 1; + _dispontime = mda->crtc[MDA_CRTC_HDISP]; _dispofftime = disptime - _dispontime; _dispontime *= MDACONST; _dispofftime *= MDACONST; @@ -130,59 +142,141 @@ mda_recalctimings(mda_t *mda) void mda_poll(void *priv) { - mda_t *mda = (mda_t *) priv; - uint16_t ca = (mda->crtc[15] | (mda->crtc[14] << 8)) & 0x3fff; - int drawcursor; - int x; - int c; - int oldvc; + mda_t *mda = (mda_t *) priv; + uint16_t cursoraddr = (mda->crtc[MDA_CRTC_CURSOR_ADDR_LOW] | (mda->crtc[MDA_CRTC_CURSOR_ADDR_HIGH] << 8)) & 0x3fff; + bool drawcursor; + int32_t oldvc; uint8_t chr; uint8_t attr; - int oldsc; - int blink; + int32_t scanline_old; + int32_t blink; VIDEO_MONITOR_PROLOGUE() + if (!mda->linepos) { timer_advance_u64(&mda->timer, mda->dispofftime); - mda->stat |= 1; + mda->status |= 1; mda->linepos = 1; - oldsc = mda->sc; - if ((mda->crtc[8] & 3) == 3) - mda->sc = (mda->sc << 1) & 7; + scanline_old = mda->scanline; + if ((mda->crtc[MDA_CRTC_INTERLACE] & 3) == 3) + mda->scanline = (mda->scanline << 1) & 7; + if (mda->dispon) { if (mda->displine < mda->firstline) { mda->firstline = mda->displine; video_wait_for_buffer(); } mda->lastline = mda->displine; - for (x = 0; x < mda->crtc[1]; x++) { - chr = mda->vram[(mda->ma << 1) & 0xfff]; - attr = mda->vram[((mda->ma << 1) + 1) & 0xfff]; - drawcursor = ((mda->ma == ca) && mda->con && mda->cursoron); - blink = ((mda->blink & 16) && (mda->ctrl & 0x20) && (attr & 0x80) && !drawcursor); - if (mda->sc == 12 && ((attr & 7) == 1)) { - for (c = 0; c < 9; c++) - buffer32->line[mda->displine][(x * 9) + c] = mdacols[attr][blink][1]; - } else { - for (c = 0; c < 8; c++) - buffer32->line[mda->displine][(x * 9) + c] = mdacols[attr][blink][(fontdatm[chr + mda->fontbase][mda->sc] & (1 << (c ^ 7))) ? 1 : 0]; - if ((chr & ~0x1f) == 0xc0) - buffer32->line[mda->displine][(x * 9) + 8] = mdacols[attr][blink][fontdatm[chr + mda->fontbase][mda->sc] & 1]; - else - buffer32->line[mda->displine][(x * 9) + 8] = mdacols[attr][blink][0]; + + for (uint32_t x = 0; x < mda->crtc[MDA_CRTC_HDISP]; x++) { + chr = mda->vram[(mda->memaddr << 1) & 0xfff]; + attr = mda->vram[((mda->memaddr << 1) + 1) & 0xfff]; + drawcursor = ((mda->memaddr == cursoraddr) && mda->cursorvisible && mda->cursoron); + blink = ((mda->blink & 16) && (mda->mode & MDA_MODE_BLINK) && (attr & 0x80) && !drawcursor); + + // Colours that will be used + int32_t color_bg = 0, color_fg = 0; + + // If we are using an RGBI monitor allow colour + if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI + && !(mda->mode & MDA_MODE_BW)) { + color_bg = (attr >> 4) & 0x0F; + color_fg = (attr & 0x0F); + + // turn off bright bg colours in blink mode + if ((mda->mode & MDA_MODE_BLINK) + && (color_bg & 0x8)) + color_bg &= ~(0x8); + + // black-on-non black or white colours forced to white + // grey-on-colours forced to bright white + + bool special_treatment = (color_bg != 0 && color_bg != 7); + + if (color_fg == MDA_COLOR_GREY + && special_treatment) + color_fg = MDA_COLOR_BRIGHT_WHITE; + + if (color_fg == 0 + && special_treatment) + color_fg = MDA_COLOR_GREY; + + // gray is black + if (color_fg == MDA_COLOR_GREY + && (color_bg == MDA_COLOR_GREY || color_bg == MDA_COLOR_BLACK)) + color_fg = MDA_COLOR_BLACK; } - mda->ma++; + + if (mda->scanline == 12 + && ((attr & 7) == 1)) { // underline + for (uint32_t column = 0; column < 9; column++) { + if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI + && !(mda->mode & MDA_MODE_BW)) { + buffer32->line[mda->displine][(x * 9) + column] = CGAPAL_CGA_START + color_fg; + } else + buffer32->line[mda->displine][(x * 9) + column] = mda_attr_to_color_table[attr][blink][1]; + } + } else { // character + for (uint32_t column = 0; column < 8; column++) { + // bg=0, fg=1 + bool is_fg = (fontdatm[chr + mda->fontbase][mda->scanline] & (1 << (column ^ 7))) ? 1 : 0; + + uint32_t font_char = mda_attr_to_color_table[attr][blink][is_fg]; + + if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI + && !(mda->mode & MDA_MODE_BW)) { + if (!is_fg) + font_char = CGAPAL_CGA_START + color_bg; + else + font_char = CGAPAL_CGA_START + color_fg; + } + + buffer32->line[mda->displine][(x * 9) + column] = font_char; + } + + // these characters (C0-DF) have their background extended to their 9th column + if ((chr & ~0x1f) == 0xc0) { + bool is_fg = fontdatm[chr + mda->fontbase][mda->scanline] & 1; + uint32_t final_result = mda_attr_to_color_table[attr][blink][is_fg]; + + if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI + && !(mda->mode & MDA_MODE_BW)) { + if (!is_fg) + final_result = CGAPAL_CGA_START + color_bg; + else + final_result = CGAPAL_CGA_START + color_fg; + } + + buffer32->line[mda->displine][(x * 9) + 8] = final_result; + + } else { + if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI + && !(mda->mode & MDA_MODE_BW)) { + buffer32->line[mda->displine][(x * 9) + 8] = CGAPAL_CGA_START + color_bg; + + } else + buffer32->line[mda->displine][(x * 9) + 8] = mda_attr_to_color_table[attr][blink][0]; + } + } + + mda->memaddr++; + if (drawcursor) { - for (c = 0; c < 9; c++) - buffer32->line[mda->displine][(x * 9) + c] ^= mdacols[attr][0][1]; + for (uint32_t column = 0; column < 9; column++) { + if (mda->monitor_type == MDA_MONITOR_TYPE_RGBI + && !(mda->mode & MDA_MODE_BW)) { + buffer32->line[mda->displine][(x * 9) + column] ^= CGAPAL_CGA_START + color_fg; + } else + buffer32->line[mda->displine][(x * 9) + column] ^= mda_attr_to_color_table[attr][0][1]; + } } } - video_process_8(mda->crtc[1] * 9, mda->displine); + video_process_8(mda->crtc[MDA_CRTC_HDISP] * 9, mda->displine); } - mda->sc = oldsc; - if (mda->vc == mda->crtc[7] && !mda->sc) { - mda->stat |= 8; + mda->scanline = scanline_old; + if (mda->vc == mda->crtc[MDA_CRTC_VSYNC] && !mda->scanline) { + mda->status |= 8; } mda->displine++; if (mda->displine >= 500) @@ -190,54 +284,60 @@ mda_poll(void *priv) } else { timer_advance_u64(&mda->timer, mda->dispontime); if (mda->dispon) - mda->stat &= ~1; + mda->status &= ~1; mda->linepos = 0; + if (mda->vsynctime) { mda->vsynctime--; if (!mda->vsynctime) { - mda->stat &= ~8; + mda->status &= ~8; } } - if (mda->sc == (mda->crtc[11] & 31) || ((mda->crtc[8] & 3) == 3 && mda->sc == ((mda->crtc[11] & 31) >> 1))) { - mda->con = 0; - mda->coff = 1; + if (mda->scanline == (mda->crtc[MDA_CRTC_CURSOR_END] & 31) + || ((mda->crtc[MDA_CRTC_INTERLACE] & 3) == 3 + && mda->scanline == ((mda->crtc[MDA_CRTC_CURSOR_END] & 31) >> 1))) { + mda->cursorvisible = 0; } + if (mda->vadj) { - mda->sc++; - mda->sc &= 31; - mda->ma = mda->maback; + mda->scanline++; + mda->scanline &= 31; + mda->memaddr = mda->memaddr_backup; mda->vadj--; if (!mda->vadj) { - mda->dispon = 1; - mda->ma = mda->maback = (mda->crtc[13] | (mda->crtc[12] << 8)) & 0x3fff; - mda->sc = 0; + mda->dispon = 1; + mda->memaddr = mda->memaddr_backup = (mda->crtc[MDA_CRTC_START_ADDR_LOW] | (mda->crtc[MDA_CRTC_START_ADDR_HIGH] << 8)) & 0x3fff; + mda->scanline = 0; } - } else if (mda->sc == mda->crtc[9] || ((mda->crtc[8] & 3) == 3 && mda->sc == (mda->crtc[9] >> 1))) { - mda->maback = mda->ma; - mda->sc = 0; - oldvc = mda->vc; + } else if (mda->scanline == mda->crtc[MDA_CRTC_MAX_SCANLINE_ADDR] + || ((mda->crtc[MDA_CRTC_INTERLACE] & 3) == 3 + && mda->scanline == (mda->crtc[MDA_CRTC_MAX_SCANLINE_ADDR] >> 1))) { + mda->memaddr_backup = mda->memaddr; + mda->scanline = 0; + oldvc = mda->vc; mda->vc++; mda->vc &= 127; - if (mda->vc == mda->crtc[6]) + if (mda->vc == mda->crtc[MDA_CRTC_VDISP]) mda->dispon = 0; - if (oldvc == mda->crtc[4]) { + if (oldvc == mda->crtc[MDA_CRTC_VTOTAL]) { mda->vc = 0; - mda->vadj = mda->crtc[5]; + mda->vadj = mda->crtc[MDA_CRTC_VTOTAL_ADJUST]; if (!mda->vadj) mda->dispon = 1; if (!mda->vadj) - mda->ma = mda->maback = (mda->crtc[13] | (mda->crtc[12] << 8)) & 0x3fff; - if ((mda->crtc[10] & 0x60) == 0x20) + mda->memaddr = mda->memaddr_backup = (mda->crtc[MDA_CRTC_START_ADDR_LOW] | (mda->crtc[MDA_CRTC_START_ADDR_HIGH] << 8)) & 0x3fff; + if ((mda->crtc[MDA_CRTC_CURSOR_START] & 0x60) == 0x20) mda->cursoron = 0; else mda->cursoron = mda->blink & 16; } - if (mda->vc == mda->crtc[7]) { + + if (mda->vc == mda->crtc[MDA_CRTC_VSYNC]) { mda->dispon = 0; mda->displine = 0; mda->vsynctime = 16; - if (mda->crtc[7]) { - x = mda->crtc[1] * 9; + if (mda->crtc[MDA_CRTC_VSYNC]) { + uint32_t x = mda->crtc[MDA_CRTC_HDISP] * 9; mda->lastline++; if ((x != xsize) || ((mda->lastline - mda->firstline) != ysize) || video_force_resize_get()) { xsize = x; @@ -253,8 +353,8 @@ mda_poll(void *priv) } video_blit_memtoscreen(0, mda->firstline, xsize, ysize); frames++; - video_res_x = mda->crtc[1]; - video_res_y = mda->crtc[6]; + video_res_x = mda->crtc[MDA_CRTC_HDISP]; + video_res_y = mda->crtc[MDA_CRTC_VDISP]; video_bpp = 0; } mda->firstline = 1000; @@ -262,12 +362,15 @@ mda_poll(void *priv) mda->blink++; } } else { - mda->sc++; - mda->sc &= 31; - mda->ma = mda->maback; + mda->scanline++; + mda->scanline &= 31; + mda->memaddr = mda->memaddr_backup; } - if (mda->sc == (mda->crtc[10] & 31) || ((mda->crtc[8] & 3) == 3 && mda->sc == ((mda->crtc[10] & 31) >> 1))) { - mda->con = 1; + + if (mda->scanline == (mda->crtc[MDA_CRTC_CURSOR_START] & 31) + || ((mda->crtc[MDA_CRTC_INTERLACE] & 3) == 3 + && mda->scanline == ((mda->crtc[MDA_CRTC_CURSOR_START] & 31) >> 1))) { + mda->cursorvisible = 1; } } VIDEO_MONITOR_EPILOGUE(); @@ -276,30 +379,32 @@ mda_poll(void *priv) void mda_init(mda_t *mda) { - 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; + + for (uint16_t attr = 0; attr < 256; attr++) { + mda_attr_to_color_table[attr][0][0] = mda_attr_to_color_table[attr][1][0] = mda_attr_to_color_table[attr][1][1] = 16; + if (attr & 8) + mda_attr_to_color_table[attr][0][1] = 15 + 16; else - mdacols[c][0][1] = 7 + 16; + mda_attr_to_color_table[attr][0][1] = 7 + 16; } - mdacols[0x70][0][1] = 16; - mdacols[0x70][0][0] = mdacols[0x70][1][0] = mdacols[0x70][1][1] = 16 + 15; - mdacols[0xF0][0][1] = 16; - mdacols[0xF0][0][0] = mdacols[0xF0][1][0] = mdacols[0xF0][1][1] = 16 + 15; - mdacols[0x78][0][1] = 16 + 7; - mdacols[0x78][0][0] = mdacols[0x78][1][0] = mdacols[0x78][1][1] = 16 + 15; - mdacols[0xF8][0][1] = 16 + 7; - mdacols[0xF8][0][0] = mdacols[0xF8][1][0] = mdacols[0xF8][1][1] = 16 + 15; - mdacols[0x00][0][1] = mdacols[0x00][1][1] = 16; - mdacols[0x08][0][1] = mdacols[0x08][1][1] = 16; - mdacols[0x80][0][1] = mdacols[0x80][1][1] = 16; - mdacols[0x88][0][1] = mdacols[0x88][1][1] = 16; + mda_attr_to_color_table[0x70][0][1] = 16; + mda_attr_to_color_table[0x70][0][0] = mda_attr_to_color_table[0x70][1][0] = mda_attr_to_color_table[0x70][1][1] = CGAPAL_CGA_START + 15; + mda_attr_to_color_table[0xF0][0][1] = 16; + mda_attr_to_color_table[0xF0][0][0] = mda_attr_to_color_table[0xF0][1][0] = mda_attr_to_color_table[0xF0][1][1] = CGAPAL_CGA_START + 15; + mda_attr_to_color_table[0x78][0][1] = CGAPAL_CGA_START + 7; + mda_attr_to_color_table[0x78][0][0] = mda_attr_to_color_table[0x78][1][0] = mda_attr_to_color_table[0x78][1][1] = CGAPAL_CGA_START + 15; + mda_attr_to_color_table[0xF8][0][1] = CGAPAL_CGA_START + 7; + mda_attr_to_color_table[0xF8][0][0] = mda_attr_to_color_table[0xF8][1][0] = mda_attr_to_color_table[0xF8][1][1] = CGAPAL_CGA_START + 15; + mda_attr_to_color_table[0x00][0][1] = mda_attr_to_color_table[0x00][1][1] = 16; + mda_attr_to_color_table[0x08][0][1] = mda_attr_to_color_table[0x08][1][1] = 16; + mda_attr_to_color_table[0x80][0][1] = mda_attr_to_color_table[0x80][1][1] = 16; + mda_attr_to_color_table[0x88][0][1] = mda_attr_to_color_table[0x88][1][1] = 16; overscan_x = overscan_y = 0; mda->monitor_index = monitor_index_global; - cga_palette = device_get_config_int("rgb_type") << 1; + mda->monitor_type = device_get_config_int("rgb_type"); + cga_palette = mda->monitor_type << 1; if (cga_palette > 6) { cga_palette = 0; } @@ -317,12 +422,38 @@ mda_standalone_init(UNUSED(const device_t *info)) mda->vram = malloc(0x1000); - mem_mapping_add(&mda->mapping, 0xb0000, 0x08000, mda_read, NULL, NULL, mda_write, NULL, NULL, NULL, MEM_MAPPING_EXTERNAL, mda); - io_sethandler(0x03b0, 0x0010, mda_in, NULL, NULL, mda_out, NULL, NULL, mda); + switch (device_get_config_int("font")) { + case 0: + loadfont(FONT_IBM_MDA_437_PATH, 0); + break; + case 1: + loadfont(FONT_IBM_MDA_437_NORDIC_PATH, 0); + break; + case 2: + loadfont(FONT_KAM_PATH, 0); + break; + case 3: + loadfont(FONT_KAMCL16_PATH, 0); + break; + case 4: + loadfont(FONT_TULIP_DGA_PATH, 0); + break; + } + + mem_mapping_add(&mda->mapping, 0xb0000, 0x08000, + mda_read, NULL, NULL, + mda_write, NULL, NULL, + NULL, MEM_MAPPING_EXTERNAL, + mda); + + io_sethandler(0x03b0, 0x0010, + mda_in, NULL, NULL, + mda_out, NULL, NULL, + mda); mda_init(mda); - lpt3_init(0x3BC); + lpt3_setup(LPT_MDA_ADDR); return mda; } @@ -330,7 +461,7 @@ mda_standalone_init(UNUSED(const device_t *info)) void mda_setcol(int chr, int blink, int fg, uint8_t cga_ink) { - mdacols[chr][blink][fg] = 16 + cga_ink; + mda_attr_to_color_table[chr][blink][fg] = CGAPAL_CGA_START + cga_ink; } void @@ -351,38 +482,47 @@ mda_speed_changed(void *priv) } static const device_config_t mda_config[] = { - // clang-format off + // clang-format off { - .name = "rgb_type", - .description = "Display type", - .type = CONFIG_SELECTION, - .default_int = 0, - .selection = { - { - .description = "Default", - .value = 0 - }, - { - .description = "Green", - .value = 1 - }, - { - .description = "Amber", - .value = 2 - }, - { - .description = "Gray", - .value = 3 - }, - { - .description = "" - } - } + .name = "rgb_type", + .description = "Display type", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = + { + { .description = "Default", .value = MDA_MONITOR_TYPE_DEFAULT }, + { .description = "Green", .value = MDA_MONITOR_TYPE_GREEN }, + { .description = "Amber", .value = MDA_MONITOR_TYPE_AMBER }, + { .description = "Gray", .value = MDA_MONITOR_TYPE_GRAY }, + { .description = "Generic RGBI color monitor", .value = MDA_MONITOR_TYPE_RGBI }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .type = CONFIG_END - } - // clang-format on + .name = "font", + .description = "Font", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = + { + { .description = "US (CP 437)", .value = 0 }, + { .description = "IBM Nordic (CP 437-Nordic)", .value = 1 }, + { .description = "Czech Kamenicky (CP 895) #1", .value = 2 }, + { .description = "Czech Kamenicky (CP 895) #2", .value = 3 }, + { .description = "Tulip DGA", .value = 4 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on }; const device_t mda_device = { @@ -393,8 +533,9 @@ const device_t mda_device = { .init = mda_standalone_init, .close = mda_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = mda_speed_changed, .force_redraw = NULL, .config = mda_config }; + diff --git a/src/video/vid_mga.c b/src/video/vid_mga.c index 1bdbecdf6..294e6ce75 100644 --- a/src/video/vid_mga.c +++ b/src/video/vid_mga.c @@ -23,6 +23,7 @@ #include #include <86box/86box.h> #include <86box/io.h> +#include "cpu.h" #include <86box/timer.h> #include <86box/mem.h> #include <86box/pci.h> @@ -427,8 +428,7 @@ enum { DMA_STATE_SEC }; -typedef struct -{ +typedef struct { uint32_t addr_type; uint32_t val; } fifo_entry_t; @@ -484,13 +484,11 @@ typedef struct mystique_t { event_t *wake_fifo_thread, *fifo_not_full_event; - struct - { + struct { int m, n, p, s; } xpixpll[3]; - struct - { + struct { uint8_t funcnt : 7, stylelen, dmamod; @@ -521,27 +519,23 @@ typedef struct mystique_t { uint64_t extended_dr[4]; - struct - { + struct { int sdydxl, scanleft, sdxl, sdy, sdxr; } sgn; } dwgreg; - struct - { + struct { uint8_t r, g, b; } lut[256]; - struct - { + struct { uint16_t pos_x, pos_y, addr; uint32_t col[3]; } cursor; - struct - { + struct { atomic_int pri_state, sec_state, iload_state, state; atomic_uint primaddress, primend, secaddress, secend, @@ -742,7 +736,7 @@ mystique_out(uint16_t addr, uint8_t val, void *priv) if ((svga->crtcreg & 0x3f) < 0xE || (svga->crtcreg & 0x3f) > 0x10) { if (((svga->crtcreg & 0x3f) == 0xc) || ((svga->crtcreg & 0x3f) == 0xd)) { svga->fullchange = 3; - svga->ma_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5); + svga->memaddr_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5); } else { svga->fullchange = changeframecount; svga_recalctimings(svga); @@ -774,24 +768,24 @@ mystique_out(uint16_t addr, uint8_t val, void *priv) if (!(mystique->type >= MGA_2164W)) svga->rowoffset <<= 1; - svga->ma_latch = ((mystique->crtcext_regs[0] & CRTCX_R0_STARTADD_MASK) << 16) | + svga->memaddr_latch = ((mystique->crtcext_regs[0] & CRTCX_R0_STARTADD_MASK) << 16) | (svga->crtc[0xc] << 8) | svga->crtc[0xd]; if ((mystique->pci_regs[0x41] & (OPTION_INTERLEAVE >> 8))) { svga->rowoffset <<= 1; - svga->ma_latch <<= 1; + svga->memaddr_latch <<= 1; } if (!(mystique->type >= MGA_2164W)) - svga->ma_latch <<= 1; + svga->memaddr_latch <<= 1; - if (svga->ma_latch != mystique->ma_latch_old) { + if (svga->memaddr_latch != mystique->ma_latch_old) { if (svga->interlace && svga->oddeven) - svga->maback = (svga->maback - (mystique->ma_latch_old << 2)) + - (svga->ma_latch << 2) + (svga->rowoffset << 1); + svga->memaddr_backup = (svga->memaddr_backup - (mystique->ma_latch_old << 2)) + + (svga->memaddr_latch << 2) + (svga->rowoffset << 1); else - svga->maback = (svga->maback - (mystique->ma_latch_old << 2)) + - (svga->ma_latch << 2); - mystique->ma_latch_old = svga->ma_latch; + svga->memaddr_backup = (svga->memaddr_backup - (mystique->ma_latch_old << 2)) + + (svga->memaddr_latch << 2); + mystique->ma_latch_old = svga->memaddr_latch; } } @@ -901,9 +895,9 @@ mystique_vblank_start(svga_t *svga) mystique_t *mystique = (mystique_t *) svga->priv; if (mystique->crtcext_regs[3] & CRTCX_R3_MGAMODE) { - svga->ma_latch = ((mystique->crtcext_regs[0] & CRTCX_R0_STARTADD_MASK) << 16) | (svga->crtc[0xc] << 8) | svga->crtc[0xd]; + svga->memaddr_latch = ((mystique->crtcext_regs[0] & CRTCX_R0_STARTADD_MASK) << 16) | (svga->crtc[0xc] << 8) | svga->crtc[0xd]; if (mystique->pci_regs[0x41] & (OPTION_INTERLEAVE >> 8)) - svga->ma_latch <<= 1; + svga->memaddr_latch <<= 1; } } @@ -990,29 +984,29 @@ mystique_recalctimings(svga_t *svga) svga->lut_map = !!(mystique->xmiscctrl & XMISCCTRL_RAMCS); if (mystique->type >= MGA_1064SG) - svga->ma_latch = ((mystique->crtcext_regs[0] & CRTCX_R0_STARTADD_MASK) << 16) | (svga->crtc[0xc] << 8) | svga->crtc[0xd]; + svga->memaddr_latch = ((mystique->crtcext_regs[0] & CRTCX_R0_STARTADD_MASK) << 16) | (svga->crtc[0xc] << 8) | svga->crtc[0xd]; if ((mystique->pci_regs[0x41] & (OPTION_INTERLEAVE >> 8))) { svga->rowoffset <<= 1; if (mystique->type >= MGA_1064SG) - svga->ma_latch <<= 1; + svga->memaddr_latch <<= 1; } if (mystique->type >= MGA_1064SG) { /*Mystique and later, unlike most SVGA cards, allows display start to take effect mid-screen*/ if (!(mystique->type >= MGA_2164W)) - svga->ma_latch <<= 1; - /* Only change maback so the new display start will take effect on the next + svga->memaddr_latch <<= 1; + /* Only change memaddr_backup so the new display start will take effect on the next horizontal retrace. */ - if (svga->ma_latch != mystique->ma_latch_old) { + if (svga->memaddr_latch != mystique->ma_latch_old) { if (svga->interlace && svga->oddeven) - svga->maback = (svga->maback - (mystique->ma_latch_old << 2)) + - (svga->ma_latch << 2) + (svga->rowoffset << 1); + svga->memaddr_backup = (svga->memaddr_backup - (mystique->ma_latch_old << 2)) + + (svga->memaddr_latch << 2) + (svga->rowoffset << 1); else - svga->maback = (svga->maback - (mystique->ma_latch_old << 2)) + - (svga->ma_latch << 2); - mystique->ma_latch_old = svga->ma_latch; + svga->memaddr_backup = (svga->memaddr_backup - (mystique->ma_latch_old << 2)) + + (svga->memaddr_latch << 2); + mystique->ma_latch_old = svga->memaddr_latch; } if (!(mystique->type >= MGA_2164W)) @@ -4684,6 +4678,7 @@ blit_trap(mystique_t *mystique) int err_l = (int32_t)mystique->dwgreg.ar[1]; int err_r = (int32_t)mystique->dwgreg.ar[4]; const int trans_sel = (mystique->dwgreg.dwgctrl_running & DWGCTRL_TRANS_MASK) >> DWGCTRL_TRANS_SHIFT; + bool transc = !!(mystique->dwgreg.dwgctrl_running & DWGCTRL_TRANSC); switch (mystique->dwgreg.dwgctrl_running & DWGCTRL_ATYPE_MASK) { case DWGCTRL_ATYPE_BLK: @@ -4706,6 +4701,7 @@ blit_trap(mystique_t *mystique) int pattern = mystique->dwgreg.pattern[yoff][xoff]; uint32_t dst; + if (!transc || (transc && pattern)) switch (mystique->maccess_running & MACCESS_PWIDTH_MASK) { case MACCESS_PWIDTH_8: svga->vram[(mystique->dwgreg.ydst_lin + x_l) & mystique->vram_mask] = (pattern ? mystique->dwgreg.fcol : mystique->dwgreg.bcol) & 0xff; @@ -4777,6 +4773,7 @@ blit_trap(mystique_t *mystique) uint32_t dst; uint32_t old_dst; + if (!transc || (transc && pattern)) switch (mystique->maccess_running & MACCESS_PWIDTH_MASK) { case MACCESS_PWIDTH_8: dst = svga->vram[(mystique->dwgreg.ydst_lin + x_l) & mystique->vram_mask]; @@ -5558,6 +5555,7 @@ blit_bitblt(mystique_t *mystique) mystique->dwgreg.ar[0] += mystique->dwgreg.ar[5]; mystique->dwgreg.ar[3] += mystique->dwgreg.ar[5]; src_addr = mystique->dwgreg.ar[3]; + break; } else src_addr += x_dir; @@ -5670,6 +5668,7 @@ blit_bitblt(mystique_t *mystique) mystique->dwgreg.ar[0] += mystique->dwgreg.ar[5]; mystique->dwgreg.ar[3] += mystique->dwgreg.ar[5]; src_addr = mystique->dwgreg.ar[3]; + break; } else src_addr += x_dir; @@ -5756,6 +5755,7 @@ blit_bitblt(mystique_t *mystique) mystique->dwgreg.ar[0] += mystique->dwgreg.ar[5]; mystique->dwgreg.ar[3] += mystique->dwgreg.ar[5]; src_addr = mystique->dwgreg.ar[3]; + break; } else src_addr += x_dir; @@ -5852,6 +5852,7 @@ blit_bitblt(mystique_t *mystique) mystique->dwgreg.ar[0] += mystique->dwgreg.ar[5]; mystique->dwgreg.ar[3] += mystique->dwgreg.ar[5]; src_addr = mystique->dwgreg.ar[3]; + break; } else src_addr += x_dir; @@ -6170,7 +6171,7 @@ mystique_hwcursor_draw(svga_t *svga, int displine) } static uint8_t -mystique_tvp3026_gpio_read(uint8_t cntl, void *priv) +mystique_tvp3026_gpio_read(UNUSED(uint8_t cntl), void *priv) { mystique_t *mystique = (mystique_t *) priv; @@ -6521,6 +6522,7 @@ mystique_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) mystique->pci_regs[addr] = val; if (addr == 0x30) mystique->pci_regs[addr] &= 1; + if (mystique->pci_regs[0x30] & 0x01) { uint32_t biosaddr = (mystique->pci_regs[0x32] << 16) | (mystique->pci_regs[0x33] << 24); mem_mapping_set_addr(&mystique->bios_rom.mapping, biosaddr, (mystique->type == MGA_G100) ? 0x10000 : 0x8000); @@ -6533,26 +6535,24 @@ mystique_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) return; case 0x40: - mystique->pci_regs[addr] = val & 0x3f; + mystique->pci_regs[0x40] = val & 0x3f; break; case 0x41: - mystique->pci_regs[addr] = val; + mystique->pci_regs[0x41] = val; break; case 0x42: - mystique->pci_regs[addr] = val & 0x1f; + mystique->pci_regs[0x42] = val & 0x1f; break; case 0x43: - mystique->pci_regs[addr] = val; - if (addr == 0x43) { - if (val & 0x40) { - if (mystique->pci_regs[0x30] & 0x01) { - uint32_t biosaddr = (mystique->pci_regs[0x32] << 16) | (mystique->pci_regs[0x33] << 24); - mem_mapping_set_addr(&mystique->bios_rom.mapping, biosaddr, (mystique->type == MGA_G100) ? 0x10000 : 0x8000); - } else - mem_mapping_disable(&mystique->bios_rom.mapping); + mystique->pci_regs[0x43] = val; + if (val & 0x40) { + if (mystique->pci_regs[0x30] & 0x01) { + uint32_t biosaddr = (mystique->pci_regs[0x32] << 16) | (mystique->pci_regs[0x33] << 24); + mem_mapping_set_addr(&mystique->bios_rom.mapping, biosaddr, (mystique->type == MGA_G100) ? 0x10000 : 0x8000); } else - mem_mapping_set_addr(&mystique->bios_rom.mapping, 0x000c0000, (mystique->type == MGA_G100) ? 0x10000 : 0x8000); - } + mem_mapping_disable(&mystique->bios_rom.mapping); + } else + mem_mapping_set_addr(&mystique->bios_rom.mapping, 0x000c0000, (mystique->type == MGA_G100) ? 0x10000 : 0x8000); break; case 0x4c: @@ -6580,17 +6580,17 @@ mystique_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) mystique_ctrl_write_b(addr, val, mystique); break; - case 0xf8: - mystique->pci_regs[0xf8] = val & 0x7; - break; + case 0xf8: + mystique->pci_regs[0xf8] = val & 0x7; + break; - case 0xf9: - mystique->pci_regs[0xf9] = val & 0x3; - break; + case 0xf9: + mystique->pci_regs[0xf9] = val & 0x3; + break; - case 0xfb: - mystique->pci_regs[0xfb] = val; - break; + case 0xfb: + mystique->pci_regs[0xfb] = val; + break; default: break; @@ -6677,6 +6677,7 @@ mystique_init(const device_t *info) mystique->svga.conv_16to32 = tvp3026_conv_16to32; if (mystique->type == MGA_2164W) mystique->svga.decode_mask = 0xffffff; + tvp3026_gpio(mystique_tvp3026_gpio_read, mystique_tvp3026_gpio_write, mystique, mystique->svga.ramdac); } else { video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_matrox_mystique); @@ -6848,64 +6849,44 @@ mystique_force_redraw(void *priv) static const device_config_t mystique_config[] = { // clang-format off { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .selection = - { - { - .description = "2 MB", - .value = 2 - }, - { - .description = "4 MB", - .value = 4 - }, - { - .description = "8 MB", - .value = 8 - }, - { - .description = "" - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 8, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "2 MB", .value = 2 }, + { .description = "4 MB", .value = 4 }, + { .description = "8 MB", .value = 8 }, + { .description = "" } }, - .default_int = 8 + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; static const device_config_t millennium_ii_config[] = { // clang-format off { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .selection = - { - { - .description = "4 MB", - .value = 4 - }, - { - .description = "8 MB", - .value = 8 - }, - { - .description = "16 MB", - .value = 16 - }, - { - .description = "" - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 8, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "4 MB", .value = 4 }, + { .description = "8 MB", .value = 8 }, + { .description = "16 MB", .value = 16 }, + { .description = "" } }, - .default_int = 8 + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -6917,7 +6898,7 @@ const device_t millennium_device = { .init = mystique_init, .close = mystique_close, .reset = NULL, - { .available = millennium_available }, + .available = millennium_available, .speed_changed = mystique_speed_changed, .force_redraw = mystique_force_redraw, .config = mystique_config @@ -6931,7 +6912,7 @@ const device_t mystique_device = { .init = mystique_init, .close = mystique_close, .reset = NULL, - { .available = mystique_available }, + .available = mystique_available, .speed_changed = mystique_speed_changed, .force_redraw = mystique_force_redraw, .config = mystique_config @@ -6945,7 +6926,7 @@ const device_t mystique_220_device = { .init = mystique_init, .close = mystique_close, .reset = NULL, - { .available = mystique_220_available }, + .available = mystique_220_available, .speed_changed = mystique_speed_changed, .force_redraw = mystique_force_redraw, .config = mystique_config @@ -6959,7 +6940,7 @@ const device_t millennium_ii_device = { .init = mystique_init, .close = mystique_close, .reset = NULL, - { .available = millennium_ii_available }, + .available = millennium_ii_available, .speed_changed = mystique_speed_changed, .force_redraw = mystique_force_redraw, .config = millennium_ii_config @@ -6974,7 +6955,7 @@ const device_t productiva_g100_device = { .init = mystique_init, .close = mystique_close, .reset = NULL, - { .available = matrox_g100_available }, + .available = matrox_g100_available, .speed_changed = mystique_speed_changed, .force_redraw = mystique_force_redraw, .config = millennium_ii_config diff --git a/src/video/vid_oak_oti.c b/src/video/vid_oak_oti.c index 715ba0df3..3ea935b06 100644 --- a/src/video/vid_oak_oti.c +++ b/src/video/vid_oak_oti.c @@ -30,6 +30,7 @@ #include <86box/vid_svga.h> #include <86box/vid_svga_render.h> #include <86box/plat_unused.h> +#include "cpu.h" #define BIOS_037C_PATH "roms/video/oti/bios.bin" #define BIOS_067_AMA932J_PATH "roms/machines/ama932j/OTI067.BIN" @@ -38,13 +39,13 @@ #define BIOS_077_PATH "roms/video/oti/oti077.vbi" #define BIOS_077_ACER100T_PATH "roms/machines/acer100t/oti077_acer100t.BIN" - enum { - OTI_037C = 0, - OTI_067 = 2, - OTI_067_AMA932J = 3, - OTI_067_M300 = 4, - OTI_077 = 5, + OTI_037C = 0, + OTI_037_PBL300SX = 1, + OTI_067 = 2, + OTI_067_AMA932J = 3, + OTI_067_M300 = 4, + OTI_077 = 5, OTI_077_ACER100T = 6 }; @@ -54,6 +55,7 @@ typedef struct { rom_t bios_rom; int index; + int en_map; uint8_t regs[32]; uint8_t chip_id; @@ -76,16 +78,23 @@ oti_out(uint16_t addr, uint8_t val, void *priv) uint8_t idx; uint8_t enable; - if (!oti->chip_id && !(oti->enable_register & 1) && (addr != 0x3C3)) + if (!oti->chip_id && !(oti->enable_register & 1) && (addr != 0x3c3)) return; - if ((((addr & 0xFFF0) == 0x3D0 || (addr & 0xFFF0) == 0x3B0) && addr < 0x3de) && !(svga->miscout & 1)) + if (((((addr & 0xfff0) == 0x3d0) || ((addr & 0xfff0) == 0x3b0)) && (addr < 0x3de)) && + !(svga->miscout & 1)) addr ^= 0x60; switch (addr) { - case 0x3C3: + case 0x3c3: if (!oti->chip_id) { oti->enable_register = val & 1; + if ((val & 0x01) && oti->en_map) + mem_mapping_enable(&svga->mapping); + else if (!(val & 0x01)) { + oti->en_map = svga->mapping.enable; + mem_mapping_disable(&svga->mapping); + } return; } svga_out(addr, val, svga); @@ -95,20 +104,20 @@ oti_out(uint16_t addr, uint8_t val, void *priv) case 0x3c7: case 0x3c8: case 0x3c9: - if (oti->chip_id == OTI_077 || oti->chip_id == OTI_077_ACER100T) + if ((oti->chip_id == OTI_077) || (oti->chip_id == OTI_077_ACER100T)) sc1148x_ramdac_out(addr, 0, val, svga->ramdac, svga); else svga_out(addr, val, svga); return; - case 0x3D4: + case 0x3d4: if (oti->chip_id) svga->crtcreg = val & 0x3f; else svga->crtcreg = val; /* FIXME: The BIOS wants to set the test bit? */ return; - case 0x3D5: + case 0x3d5: if (oti->chip_id && (svga->crtcreg & 0x20)) return; idx = svga->crtcreg; @@ -124,7 +133,8 @@ oti_out(uint16_t addr, uint8_t val, void *priv) if ((idx < 0x0e) || (idx > 0x10)) { if (idx == 0x0c || idx == 0x0d) { svga->fullchange = 3; - svga->ma_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5); + svga->memaddr_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + + ((svga->crtc[8] & 0x60) >> 5); } else { svga->fullchange = changeframecount; svga_recalctimings(svga); @@ -133,14 +143,14 @@ oti_out(uint16_t addr, uint8_t val, void *priv) } break; - case 0x3DE: + case 0x3de: if (oti->chip_id) oti->index = val & 0x1f; else oti->index = val; return; - case 0x3DF: + case 0x3df: idx = oti->index; if (!oti->chip_id) idx &= 0x1f; @@ -223,14 +233,14 @@ oti_in(uint16_t addr, void *priv) addr ^= 0x60; switch (addr) { - case 0x3C2: + case 0x3c2: if ((svga->vgapal[0].r + svga->vgapal[0].g + svga->vgapal[0].b) >= 0x50) temp = 0; else temp = 0x10; break; - case 0x3C3: + case 0x3c3: if (oti->chip_id) temp = svga_in(addr, svga); else @@ -242,17 +252,20 @@ oti_in(uint16_t addr, void *priv) case 0x3c8: case 0x3c9: if (oti->chip_id == OTI_077 || oti->chip_id == OTI_077_ACER100T) - return sc1148x_ramdac_in(addr, 0, svga->ramdac, svga); - return svga_in(addr, svga); + temp = sc1148x_ramdac_in(addr, 0, svga->ramdac, svga); + else + temp = svga_in(addr, svga); + break; case 0x3CF: - return svga->gdcreg[svga->gdcaddr & 0xf]; + temp = svga->gdcreg[svga->gdcaddr & 0xf]; + break; - case 0x3D4: + case 0x3d4: temp = svga->crtcreg; break; - case 0x3D5: + case 0x3d5: if (oti->chip_id) { if (svga->crtcreg & 0x20) temp = 0xff; @@ -262,17 +275,19 @@ oti_in(uint16_t addr, void *priv) temp = svga->crtc[svga->crtcreg & 0x1f]; break; - case 0x3DA: + case 0x3da: if (oti->chip_id) { temp = svga_in(addr, svga); break; } svga->attrff = 0; - /*The OTI-037C BIOS waits for bits 0 and 3 in 0x3da to go low, then reads 0x3da again - and expects the diagnostic bits to equal the current border colour. As I understand - it, the 0x3da active enable status does not include the border time, so this may be - an area where OTI-037C is not entirely VGA compatible.*/ + /* + The OTI-037C BIOS waits for bits 0 and 3 in 0x3da to go low, then reads 0x3da again + and expects the diagnostic bits to equal the current border colour. As I understand + it, the 0x3da active enable status does not include the border time, so this may be + an area where OTI-037C is not entirely VGA compatible. + */ svga->cgastat &= ~0x30; /* copy color diagnostic info from the overscan color register */ switch (svga->attrregs[0x12] & 0x30) { @@ -307,13 +322,13 @@ oti_in(uint16_t addr, void *priv) temp = svga->cgastat; break; - case 0x3DE: + case 0x3de: temp = oti->index; if (oti->chip_id) temp |= (oti->chip_id << 5); break; - case 0x3DF: + case 0x3df: idx = oti->index; if (!oti->chip_id) idx &= 0x1f; @@ -393,9 +408,9 @@ oti_recalctimings(svga_t *svga) if (oti->chip_id > 0) { if (oti->regs[0x14] & 0x08) - svga->ma_latch |= 0x10000; + svga->memaddr_latch |= 0x10000; if (oti->regs[0x16] & 0x08) - svga->ma_latch |= 0x20000; + svga->memaddr_latch |= 0x20000; if (oti->regs[0x14] & 0x01) svga->vtotal += 0x400; @@ -441,6 +456,13 @@ oti_init(const device_t *info) #endif break; + case OTI_037_PBL300SX: + romfn = NULL; + oti->chip_id = 0; + oti->vram_size = 256; + oti->regs[0] = 0x08; /* FIXME: The BIOS wants to read this at index 0? This index is undocumented. */ + break; + case OTI_067_AMA932J: romfn = BIOS_067_AMA932J_PATH; oti->chip_id = 2; @@ -478,26 +500,25 @@ oti_init(const device_t *info) break; } - if (romfn != NULL) { + if (romfn != NULL) rom_init(&oti->bios_rom, romfn, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); - } oti->vram_mask = (oti->vram_size << 10) - 1; - if (oti->chip_id == OTI_077_ACER100T){ - /* josephillips: Required to show all BIOS - information on Acer 100T only + if (oti->chip_id == OTI_077_ACER100T) { + /* + josephillips: Required to show all BIOS + information on Acer 100T only */ - video_inform(0x1,&timing_oti); - }else{ + video_inform(0x1, &timing_oti); + } else video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_oti); - } svga_init(info, &oti->svga, oti, oti->vram_size << 10, oti_recalctimings, oti_in, oti_out, NULL, NULL); - if (oti->chip_id == OTI_077 || oti->chip_id == OTI_077_ACER100T) + if ((oti->chip_id == OTI_077) || (oti->chip_id == OTI_077_ACER100T)) oti->svga.ramdac = device_add(&sc11487_ramdac_device); /*Actually a 82c487, probably a clone.*/ io_sethandler(0x03c0, 32, @@ -571,110 +592,80 @@ oti067_m300_available(void) // clang-format off static const device_config_t oti067_config[] = { { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 512, - .selection = { - { - .description = "256 KB", - .value = 256 - }, - { - .description = "512 KB", - .value = 512 - }, - { - .description = "" - } - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 512, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "256 KB", .value = 256 }, + { .description = "512 KB", .value = 512 }, + { .description = "" } + }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t oti067_ama932j_config[] = { { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 256, - .selection = { - { - .description = "256 KB", - .value = 256 - }, - { - .description = "512 KB", - .value = 512 - }, - { - .description = "" - } - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 256, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "256 KB", .value = 256 }, + { .description = "512 KB", .value = 512 }, + { .description = "" } + }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t oti077_acer100t_config[] = { { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 512, - .selection = { - { - .description = "256 KB", - .value = 256 - }, - { - .description = "512 KB", - .value = 512 - }, - { - .description = "1 MB", - .value = 1024 - }, - { - .description = "" - } - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 512, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "256 KB", .value = 256 }, + { .description = "512 KB", .value = 512 }, + { .description = "1 MB", .value = 1024 }, + { .description = "" } + }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t oti077_config[] = { { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 1024, - .selection = { - { - .description = "256 KB", - .value = 256 - }, - { - .description = "512 KB", - .value = 512 - }, - { - .description = "1 MB", - .value = 1024 - }, - { - .description = "" - } - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 1024, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "256 KB", .value = 256 }, + { .description = "512 KB", .value = 512 }, + { .description = "1 MB", .value = 1024 }, + { .description = "" } + }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; // clang-format on @@ -686,7 +677,21 @@ const device_t oti037c_device = { .init = oti_init, .close = oti_close, .reset = NULL, - { .available = oti037c_available }, + .available = oti037c_available, + .speed_changed = oti_speed_changed, + .force_redraw = oti_force_redraw, + .config = NULL +}; + +const device_t oti037_pbl300sx_device = { + .name = "Oak OTI-037 (Packard Bell Legend 300SX)", + .internal_name = "oti037_pbl300sx", + .flags = DEVICE_ISA, + .local = 1, + .init = oti_init, + .close = oti_close, + .reset = NULL, + .available = NULL, .speed_changed = oti_speed_changed, .force_redraw = oti_force_redraw, .config = NULL @@ -700,21 +705,7 @@ const device_t oti067_device = { .init = oti_init, .close = oti_close, .reset = NULL, - { .available = oti067_077_available }, - .speed_changed = oti_speed_changed, - .force_redraw = oti_force_redraw, - .config = oti067_config -}; - -const device_t oti067_m300_device = { - .name = "Oak OTI-067 (Olivetti M300-08/15)", - .internal_name = "oti067_m300", - .flags = DEVICE_ISA, - .local = 4, - .init = oti_init, - .close = oti_close, - .reset = NULL, - { .available = oti067_m300_available }, + .available = oti067_077_available, .speed_changed = oti_speed_changed, .force_redraw = oti_force_redraw, .config = oti067_config @@ -728,12 +719,40 @@ const device_t oti067_ama932j_device = { .init = oti_init, .close = oti_close, .reset = NULL, - { .available = oti067_ama932j_available }, + .available = oti067_ama932j_available, .speed_changed = oti_speed_changed, .force_redraw = oti_force_redraw, .config = oti067_ama932j_config }; +const device_t oti067_m300_device = { + .name = "Oak OTI-067 (Olivetti M300-08/15)", + .internal_name = "oti067_m300", + .flags = DEVICE_ISA, + .local = 4, + .init = oti_init, + .close = oti_close, + .reset = NULL, + .available = oti067_m300_available, + .speed_changed = oti_speed_changed, + .force_redraw = oti_force_redraw, + .config = oti067_config +}; + +const device_t oti077_device = { + .name = "Oak OTI-077", + .internal_name = "oti077", + .flags = DEVICE_ISA, + .local = 5, + .init = oti_init, + .close = oti_close, + .reset = NULL, + .available = oti067_077_available, + .speed_changed = oti_speed_changed, + .force_redraw = oti_force_redraw, + .config = oti077_config +}; + const device_t oti077_acer100t_device = { .name = "Oak OTI-077 (Acer 100T)", .internal_name = "oti077_acer100t", @@ -742,23 +761,8 @@ const device_t oti077_acer100t_device = { .init = oti_init, .close = oti_close, .reset = NULL, - { .available = oti077_acer100t_available }, + .available = oti077_acer100t_available, .speed_changed = oti_speed_changed, .force_redraw = oti_force_redraw, .config = oti077_acer100t_config }; - - -const device_t oti077_device = { - .name = "Oak OTI-077", - .internal_name = "oti077", - .flags = DEVICE_ISA, - .local = 5, - .init = oti_init, - .close = oti_close, - .reset = NULL, - { .available = oti067_077_available }, - .speed_changed = oti_speed_changed, - .force_redraw = oti_force_redraw, - .config = oti077_config -}; diff --git a/src/video/vid_paradise.c b/src/video/vid_paradise.c index bf038eb32..a9b0c65a5 100644 --- a/src/video/vid_paradise.c +++ b/src/video/vid_paradise.c @@ -68,7 +68,7 @@ typedef struct paradise_t { } paradise_t; static video_timings_t timing_paradise_pvga1a = { .type = VIDEO_ISA, .write_b = 6, .write_w = 8, .write_l = 16, .read_b = 6, .read_w = 8, .read_l = 16 }; -static video_timings_t timing_paradise_wd90c = { .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_paradise_wd90c = { .type = VIDEO_ISA, .write_b = 3, .write_w = 3, .write_l = 6, .read_b = 5, .read_w = 5, .read_l = 10 }; void paradise_remap(paradise_t *paradise); @@ -245,7 +245,7 @@ paradise_out(uint16_t addr, uint8_t val, void *priv) 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); + svga->memaddr_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5); } else { svga->fullchange = changeframecount; svga_recalctimings(svga); @@ -362,11 +362,6 @@ paradise_write(uint32_t addr, uint8_t val, void *priv) uint32_t prev_addr; uint32_t prev_addr2; - if (!(svga->attrregs[0x10] & 0x40)) { - svga_write(addr, val, svga); - return; - } - addr = (addr & 0x7fff) + paradise->write_bank[(addr >> 15) & 3]; /*Could be done in a better way but it works.*/ @@ -400,11 +395,6 @@ paradise_writew(uint32_t addr, uint16_t val, void *priv) uint32_t prev_addr; uint32_t prev_addr2; - if (!(svga->attrregs[0x10] & 0x40)) { - svga_writew(addr, val, svga); - return; - } - addr = (addr & 0x7fff) + paradise->write_bank[(addr >> 15) & 3]; /*Could be done in a better way but it works.*/ @@ -438,9 +428,6 @@ paradise_read(uint32_t addr, void *priv) uint32_t prev_addr; uint32_t prev_addr2; - if (!(svga->attrregs[0x10] & 0x40)) - return svga_read(addr, svga); - addr = (addr & 0x7fff) + paradise->read_bank[(addr >> 15) & 3]; /*Could be done in a better way but it works.*/ @@ -474,9 +461,6 @@ paradise_readw(uint32_t addr, void *priv) uint32_t prev_addr; uint32_t prev_addr2; - if (!(svga->attrregs[0x10] & 0x40)) - return svga_readw(addr, svga); - addr = (addr & 0x7fff) + paradise->read_bank[(addr >> 15) & 3]; /*Could be done in a better way but it works.*/ @@ -550,6 +534,12 @@ paradise_init(const device_t *info, uint32_t memory) break; } + svga->read = paradise_read; + svga->readw = paradise_readw; + svga->readl = NULL; + svga->write = paradise_write; + svga->writew = paradise_writew; + svga->writel = NULL; mem_mapping_set_handler(&svga->mapping, paradise_read, paradise_readw, NULL, paradise_write, paradise_writew, NULL); mem_mapping_set_p(&svga->mapping, paradise); @@ -581,6 +571,8 @@ paradise_init(const device_t *info, uint32_t memory) paradise->type = info->local; + svga->hoverride = 1; + return paradise; } @@ -722,7 +714,7 @@ const device_t paradise_pvga1a_pc2086_device = { .init = paradise_pvga1a_pc2086_init, .close = paradise_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = paradise_speed_changed, .force_redraw = paradise_force_redraw, .config = NULL @@ -736,7 +728,7 @@ const device_t paradise_pvga1a_pc3086_device = { .init = paradise_pvga1a_pc3086_init, .close = paradise_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = paradise_speed_changed, .force_redraw = paradise_force_redraw, .config = NULL @@ -745,27 +737,21 @@ const device_t paradise_pvga1a_pc3086_device = { static const device_config_t paradise_pvga1a_config[] = { // clang-format off { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 512, - .selection = { - { - .description = "256 KB", - .value = 256 - }, - { - .description = "512 KB", - .value = 512 - }, - { - .description = "" - } - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 512, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "256 KB", .value = 256 }, + { .description = "512 KB", .value = 512 }, + { .description = "" } + }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -777,7 +763,7 @@ const device_t paradise_pvga1a_ncr3302_device = { .init = paradise_pvga1a_ncr3302_init, .close = paradise_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = paradise_speed_changed, .force_redraw = paradise_force_redraw, .config = paradise_pvga1a_config @@ -791,7 +777,7 @@ const device_t paradise_pvga1a_device = { .init = paradise_pvga1a_standalone_init, .close = paradise_close, .reset = NULL, - { .available = paradise_pvga1a_standalone_available }, + .available = paradise_pvga1a_standalone_available, .speed_changed = paradise_speed_changed, .force_redraw = paradise_force_redraw, .config = paradise_pvga1a_config @@ -805,7 +791,7 @@ const device_t paradise_wd90c11_megapc_device = { .init = paradise_wd90c11_megapc_init, .close = paradise_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = paradise_speed_changed, .force_redraw = paradise_force_redraw, .config = NULL @@ -819,7 +805,7 @@ const device_t paradise_wd90c11_device = { .init = paradise_wd90c11_standalone_init, .close = paradise_close, .reset = NULL, - { .available = paradise_wd90c11_standalone_available }, + .available = paradise_wd90c11_standalone_available, .speed_changed = paradise_speed_changed, .force_redraw = paradise_force_redraw, .config = NULL @@ -828,31 +814,22 @@ const device_t paradise_wd90c11_device = { static const device_config_t paradise_wd90c30_config[] = { // clang-format off { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 1024, - .selection = { - { - .description = "256 KB", - .value = 256 - }, - { - .description = "512 KB", - .value = 512 - }, - { - .description = "1 MB", - .value = 1024 - }, - { - .description = "" - } - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 1024, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "256 KB", .value = 256 }, + { .description = "512 KB", .value = 512 }, + { .description = "1 MB", .value = 1024 }, + { .description = "" } + }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -864,7 +841,7 @@ const device_t paradise_wd90c30_device = { .init = paradise_wd90c30_standalone_init, .close = paradise_close, .reset = NULL, - { .available = paradise_wd90c30_standalone_available }, + .available = paradise_wd90c30_standalone_available, .speed_changed = paradise_speed_changed, .force_redraw = paradise_force_redraw, .config = paradise_wd90c30_config diff --git a/src/video/vid_pcjr.c b/src/video/vid_pcjr.c new file mode 100644 index 000000000..2b3eb730a --- /dev/null +++ b/src/video/vid_pcjr.c @@ -0,0 +1,706 @@ +/* + * 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. + * + * IBM PCjr video subsystem emulation + * + * + * Authors: Sarah Walker, + * Miran Grca, + * Connor Hyde / starfrost + * + * Copyright 2008-2019 Sarah Walker. + * Copyright 2016-2019 Miran Grca. + * Copyright 2017-2019 Fred N. van Kempen. + * Copyright 2025 starfrost + */ + +#include +#include +#include +#include +#include +#include <86box/86box.h> +#include <86box/io.h> +#include <86box/timer.h> +#include <86box/mem.h> +#include <86box/pic.h> +#include <86box/pit.h> +#include <86box/rom.h> +#include <86box/device.h> +#include <86box/video.h> +#include <86box/vid_cga.h> +#include <86box/vid_cga_comp.h> + +#include <86box/m_pcjr.h> + +static video_timings_t timing_dram = { VIDEO_BUS, 0, 0, 0, 0, 0, 0 }; /*No additional waitstates*/ + +static uint8_t 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 void +recalc_address(pcjr_t *pcjr) +{ + uint8_t masked_memctrl = pcjr->memctrl; + + /* According to the Technical Reference, bits 2 and 5 are + ignored if there is only 64k of RAM and there are only + 4 pages. */ + if (mem_size < 128) + masked_memctrl &= ~0x24; + + if ((pcjr->memctrl & 0xc0) == 0xc0) { + pcjr->vram = &ram[(masked_memctrl & 0x06) << 14]; + pcjr->b8000 = &ram[(masked_memctrl & 0x30) << 11]; + } else { + pcjr->vram = &ram[(masked_memctrl & 0x07) << 14]; + pcjr->b8000 = &ram[(masked_memctrl & 0x38) << 11]; + } +} + +void +pcjr_recalc_timings(pcjr_t *pcjr) +{ + double _dispontime; + double _dispofftime; + double disptime; + + if (pcjr->array[0] & 1) { + disptime = pcjr->crtc[0] + 1; + _dispontime = pcjr->crtc[1]; + } else { + disptime = (pcjr->crtc[0] + 1) << 1; + _dispontime = pcjr->crtc[1] << 1; + } + + _dispofftime = disptime - _dispontime; + _dispontime *= CGACONST; + _dispofftime *= CGACONST; + pcjr->dispontime = (uint64_t) (_dispontime); + pcjr->dispofftime = (uint64_t) (_dispofftime); +} + +static int +vid_get_h_overscan_size(pcjr_t *pcjr) +{ + int ret; + + if (pcjr->array[0] & 1) + ret = 128; + else + ret = 256; + + return ret; +} + +static void +vid_out(uint16_t addr, uint8_t val, void *priv) +{ + pcjr_t *pcjr = (pcjr_t *) priv; + uint8_t old; + + switch (addr) { + case 0x3d0: + case 0x3d2: + case 0x3d4: + case 0x3d6: + pcjr->crtcreg = val & 0x1f; + return; + + case 0x3d1: + case 0x3d3: + case 0x3d5: + case 0x3d7: + old = pcjr->crtc[pcjr->crtcreg]; + pcjr->crtc[pcjr->crtcreg] = val & crtcmask[pcjr->crtcreg]; + if (pcjr->crtcreg == 2) + overscan_x = vid_get_h_overscan_size(pcjr); + if (old != val) { + if (pcjr->crtcreg < 0xe || pcjr->crtcreg > 0x10) { + pcjr->fullchange = changeframecount; + pcjr_recalc_timings(pcjr); + } + } + return; + + case 0x3da: + if (!pcjr->array_ff) + pcjr->array_index = val & 0x1f; + else { + if (pcjr->array_index & 0x10) + val &= 0x0f; + pcjr->array[pcjr->array_index & 0x1f] = val; + if (!(pcjr->array_index & 0x1f)) + update_cga16_color(val); + } + pcjr->array_ff = !pcjr->array_ff; + break; + + case 0x3df: + pcjr->memctrl = val; + pcjr->pa = val; /* The PCjr BIOS expects the value written to 3DF to + then be readable from port 60, others it errors out + with only 64k RAM set (but somehow, still works with + 128k or more RAM). */ + pcjr->addr_mode = val >> 6; + recalc_address(pcjr); + break; + + default: + break; + } +} + +static uint8_t +vid_in(uint16_t addr, void *priv) +{ + pcjr_t *pcjr = (pcjr_t *) priv; + uint8_t ret = 0xff; + + switch (addr) { + case 0x3d0: + case 0x3d2: + case 0x3d4: + case 0x3d6: + ret = pcjr->crtcreg; + break; + + case 0x3d1: + case 0x3d3: + case 0x3d5: + case 0x3d7: + ret = pcjr->crtc[pcjr->crtcreg]; + break; + + case 0x3da: + pcjr->array_ff = 0; + pcjr->status ^= 0x10; + ret = pcjr->status; + break; + + default: + break; + } + + return ret; +} + +static void +vid_write(uint32_t addr, uint8_t val, void *priv) +{ + pcjr_t *pcjr = (pcjr_t *) priv; + + if (pcjr->memctrl == -1) + return; + + pcjr->b8000[addr & 0x3fff] = val; +} + +static uint8_t +vid_read(uint32_t addr, void *priv) +{ + const pcjr_t *pcjr = (pcjr_t *) priv; + + if (pcjr->memctrl == -1) + return 0xff; + + return (pcjr->b8000[addr & 0x3fff]); +} + +static int +vid_get_h_overscan_delta(pcjr_t *pcjr) +{ + int def; + int coef; + int ret; + + switch ((pcjr->array[0] & 0x13) | ((pcjr->array[3] & 0x08) << 5)) { + case 0x13: /*320x200x16*/ + def = 0x56; + coef = 8; + break; + case 0x12: /*160x200x16*/ + def = 0x2c; /* I'm going to assume a datasheet erratum here. */ + coef = 16; + break; + case 0x03: /*640x200x4*/ + def = 0x56; + coef = 8; + break; + case 0x01: /*80 column text*/ + def = 0x5a; + coef = 8; + break; + case 0x00: /*40 column text*/ + default: + def = 0x2c; + coef = 16; + break; + case 0x02: /*320x200x4*/ + def = 0x2b; + coef = 16; + break; + case 0x102: /*640x200x2*/ + def = 0x2b; + coef = 16; + break; + } + + ret = pcjr->crtc[0x02] - def; + + if (ret < -8) + ret = -8; + + if (ret > 8) + ret = 8; + + return ret * coef; +} + +static void +vid_blit_h_overscan(pcjr_t *pcjr) +{ + int cols = (pcjr->array[2] & 0xf) + 16;; + int y0 = pcjr->firstline << 1; + int y = (pcjr->lastline << 1) + 16; + int ho_s = vid_get_h_overscan_size(pcjr); + int i; + int x; + + if (pcjr->array[0] & 1) + x = (pcjr->crtc[1] << 3) + ho_s; + else + x = (pcjr->crtc[1] << 4) + ho_s; + + for (i = 0; i < 16; i++) { + hline(buffer32, 0, y0 + i, x, cols); + hline(buffer32, 0, y + i, x, cols); + + if (pcjr->composite) { + Composite_Process(pcjr->array[0], 0, x >> 2, buffer32->line[y0 + i]); + Composite_Process(pcjr->array[0], 0, x >> 2, buffer32->line[y + i]); + } else { + video_process_8(x, y0 + i); + video_process_8(x, y + i); + } + } +} + +static void +vid_poll(void *priv) +{ + pcjr_t *pcjr = (pcjr_t *) priv; + uint16_t cursoraddr = (pcjr->crtc[15] | (pcjr->crtc[14] << 8)) & 0x3fff; + int drawcursor; + int x; + int xs_temp; + int ys_temp; + int oldvc; + uint8_t chr; + uint8_t attr; + uint16_t dat; + int cols[4]; + int scanline_old; + int l = (pcjr->displine << 1) + 16; + int ho_s = vid_get_h_overscan_size(pcjr); + int ho_d = vid_get_h_overscan_delta(pcjr) + (ho_s / 2); + + if (!pcjr->linepos) { + timer_advance_u64(&pcjr->timer, pcjr->dispofftime); + pcjr->status &= ~1; + pcjr->linepos = 1; + scanline_old = pcjr->scanline; + if ((pcjr->crtc[8] & 3) == 3) + pcjr->scanline = (pcjr->scanline << 1) & 7; + if (pcjr->dispon) { + uint16_t offset = 0; + uint16_t mask = 0x1fff; + + if (pcjr->displine < pcjr->firstline) { + pcjr->firstline = pcjr->displine; + video_wait_for_buffer(); + } + pcjr->lastline = pcjr->displine; + cols[0] = (pcjr->array[2] & 0xf) + 16; + + if (pcjr->array[0] & 1) { + hline(buffer32, 0, l, (pcjr->crtc[1] << 3) + ho_s, cols[0]); + hline(buffer32, 0, l + 1, (pcjr->crtc[1] << 3) + ho_s, cols[0]); + } else { + hline(buffer32, 0, l, (pcjr->crtc[1] << 4) + ho_s, cols[0]); + hline(buffer32, 0, l + 1, (pcjr->crtc[1] << 4) + ho_s, cols[0]); + } + + switch (pcjr->addr_mode) { + case 0: /*Alpha*/ + offset = 0; + mask = 0x3fff; + break; + case 1: /*Low resolution graphics*/ + offset = (pcjr->scanline & 1) * 0x2000; + break; + case 3: /*High resolution graphics*/ + offset = (pcjr->scanline & 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++) { + int ef_x = (x << 3) + ho_d; + dat = (pcjr->vram[((pcjr->memaddr << 1) & mask) + offset] << 8) | + pcjr->vram[((pcjr->memaddr << 1) & mask) + offset + 1]; + pcjr->memaddr++; + buffer32->line[l][ef_x] = buffer32->line[l][ef_x + 1] = + buffer32->line[l + 1][ef_x] = buffer32->line[l + 1][ef_x + 1] = + pcjr->array[((dat >> 12) & pcjr->array[1] & 0x0f) + 16] + 16; + buffer32->line[l][ef_x + 2] = buffer32->line[l][ef_x + 3] = + buffer32->line[l + 1][ef_x + 2] = buffer32->line[l + 1][ef_x + 3] = + pcjr->array[((dat >> 8) & pcjr->array[1] & 0x0f) + 16] + 16; + buffer32->line[l][ef_x + 4] = buffer32->line[l][ef_x + 5] = + buffer32->line[l + 1][ef_x + 4] = buffer32->line[l + 1][ef_x + 5] = + pcjr->array[((dat >> 4) & pcjr->array[1] & 0x0f) + 16] + 16; + buffer32->line[l][ef_x + 6] = buffer32->line[l][ef_x + 7] = + buffer32->line[l + 1][ef_x + 6] = buffer32->line[l + 1][ef_x + 7] = + pcjr->array[(dat & pcjr->array[1] & 0x0f) + 16] + 16; + } + break; + case 0x12: /*160x200x16*/ + for (x = 0; x < pcjr->crtc[1]; x++) { + int ef_x = (x << 4) + ho_d; + dat = (pcjr->vram[((pcjr->memaddr << 1) & mask) + offset] << 8) | + pcjr->vram[((pcjr->memaddr << 1) & mask) + offset + 1]; + pcjr->memaddr++; + buffer32->line[l][ef_x] = buffer32->line[l][ef_x + 1] = + buffer32->line[l][ef_x + 2] = buffer32->line[l][ef_x + 3] = + buffer32->line[l + 1][ef_x] = buffer32->line[l + 1][ef_x + 1] = + buffer32->line[l + 1][ef_x + 2] = buffer32->line[l + 1][ef_x + 3] = + pcjr->array[((dat >> 12) & pcjr->array[1] & 0x0f) + 16] + 16; + buffer32->line[l][ef_x + 4] = buffer32->line[l][ef_x + 5] = + buffer32->line[l][ef_x + 6] = buffer32->line[l][ef_x + 7] = + buffer32->line[l + 1][ef_x + 4] = buffer32->line[l + 1][ef_x + 5] = + buffer32->line[l + 1][ef_x + 6] = buffer32->line[l + 1][ef_x + 7] = + pcjr->array[((dat >> 8) & pcjr->array[1] & 0x0f) + 16] + 16; + buffer32->line[l][ef_x + 8] = buffer32->line[l][ef_x + 9] = + buffer32->line[l][ef_x + 10] = buffer32->line[l][ef_x + 11] = + buffer32->line[l + 1][ef_x + 8] = buffer32->line[l + 1][ef_x + 9] = + buffer32->line[l + 1][ef_x + 10] = buffer32->line[l + 1][ef_x + 11] = + pcjr->array[((dat >> 4) & pcjr->array[1] & 0x0f) + 16] + 16; + buffer32->line[l][ef_x + 12] = buffer32->line[l][ef_x + 13] = + buffer32->line[l][ef_x + 14] = buffer32->line[l][ef_x + 15] = + buffer32->line[l + 1][ef_x + 12] = buffer32->line[l + 1][ef_x + 13] = + buffer32->line[l + 1][ef_x + 14] = buffer32->line[l + 1][ef_x + 15] = + pcjr->array[(dat & pcjr->array[1] & 0x0f) + 16] + 16; + } + break; + case 0x03: /*640x200x4*/ + for (x = 0; x < pcjr->crtc[1]; x++) { + int ef_x = (x << 3) + ho_d; + dat = (pcjr->vram[((pcjr->memaddr << 1) & mask) + offset + 1] << 8) | + pcjr->vram[((pcjr->memaddr << 1) & mask) + offset]; + pcjr->memaddr++; + for (uint8_t c = 0; c < 8; c++) { + chr = (dat >> 7) & 1; + chr |= ((dat >> 14) & 2); + buffer32->line[l][ef_x + c] = buffer32->line[l + 1][ef_x + c] = + pcjr->array[(chr & pcjr->array[1] & 0x0f) + 16] + 16; + dat <<= 1; + } + } + break; + case 0x01: /*80 column text*/ + for (x = 0; x < pcjr->crtc[1]; x++) { + int ef_x = (x << 3) + ho_d; + chr = pcjr->vram[((pcjr->memaddr << 1) & mask) + offset]; + attr = pcjr->vram[((pcjr->memaddr << 1) & mask) + offset + 1]; + drawcursor = ((pcjr->memaddr == cursoraddr) && pcjr->cursorvisible && pcjr->cursoron); + if (pcjr->array[3] & 4) { + cols[1] = pcjr->array[((attr & 15) & pcjr->array[1] & 0x0f) + 16] + 16; + cols[0] = pcjr->array[(((attr >> 4) & 7) & pcjr->array[1] & 0x0f) + 16] + 16; + if ((pcjr->blink & 16) && (attr & 0x80) && !drawcursor) + cols[1] = cols[0]; + } else { + cols[1] = pcjr->array[((attr & 15) & pcjr->array[1] & 0x0f) + 16] + 16; + cols[0] = pcjr->array[((attr >> 4) & pcjr->array[1] & 0x0f) + 16] + 16; + } + if (pcjr->scanline & 8) + for (uint8_t c = 0; c < 8; c++) + buffer32->line[l][ef_x + c] = + buffer32->line[l + 1][ef_x + c] = cols[0]; + else + for (uint8_t c = 0; c < 8; c++) + buffer32->line[l][ef_x + c] = + buffer32->line[l + 1][ef_x + c] = + cols[(fontdat[chr][pcjr->scanline & 7] & (1 << (c ^ 7))) ? 1 : 0]; + if (drawcursor) + for (uint8_t c = 0; c < 8; c++) { + buffer32->line[l][ef_x + c] ^= 15; + buffer32->line[l + 1][ef_x + c] ^= 15; + } + pcjr->memaddr++; + } + break; + case 0x00: /*40 column text*/ + for (x = 0; x < pcjr->crtc[1]; x++) { + int ef_x = (x << 4) + ho_d; + chr = pcjr->vram[((pcjr->memaddr << 1) & mask) + offset]; + attr = pcjr->vram[((pcjr->memaddr << 1) & mask) + offset + 1]; + drawcursor = ((pcjr->memaddr == cursoraddr) && pcjr->cursorvisible && pcjr->cursoron); + if (pcjr->array[3] & 4) { + cols[1] = pcjr->array[((attr & 15) & pcjr->array[1] & 0x0f) + 16] + 16; + cols[0] = pcjr->array[(((attr >> 4) & 7) & pcjr->array[1] & 0x0f) + 16] + 16; + if ((pcjr->blink & 16) && (attr & 0x80) && !drawcursor) + cols[1] = cols[0]; + } else { + cols[1] = pcjr->array[((attr & 15) & pcjr->array[1] & 0x0f) + 16] + 16; + cols[0] = pcjr->array[((attr >> 4) & pcjr->array[1] & 0x0f) + 16] + 16; + } + pcjr->memaddr++; + if (pcjr->scanline & 8) + for (uint8_t c = 0; c < 8; c++) + buffer32->line[l][ef_x + (c << 1)] = + buffer32->line[l][ef_x + (c << 1) + 1] = + buffer32->line[l + 1][ef_x + (c << 1)] = + buffer32->line[l + 1][ef_x + (c << 1) + 1] = cols[0]; + else + for (uint8_t c = 0; c < 8; c++) + buffer32->line[l][ef_x + (c << 1)] = + buffer32->line[l][ef_x + (c << 1) + 1] = + buffer32->line[l + 1][ef_x + (c << 1)] = + buffer32->line[l + 1][ef_x + (c << 1) + 1] = + cols[(fontdat[chr][pcjr->scanline & 7] & (1 << (c ^ 7))) ? 1 : 0]; + if (drawcursor) + for (uint8_t c = 0; c < 16; c++) { + buffer32->line[l][ef_x + c] ^= 15; + buffer32->line[l + 1][ef_x + c] ^= 15; + } + } + break; + case 0x02: /*320x200x4*/ + cols[0] = pcjr->array[0 + 16] + 16; + cols[1] = pcjr->array[1 + 16] + 16; + cols[2] = pcjr->array[2 + 16] + 16; + cols[3] = pcjr->array[3 + 16] + 16; + for (x = 0; x < pcjr->crtc[1]; x++) { + int ef_x = (x << 4) + ho_d; + dat = (pcjr->vram[((pcjr->memaddr << 1) & mask) + offset] << 8) | + pcjr->vram[((pcjr->memaddr << 1) & mask) + offset + 1]; + pcjr->memaddr++; + for (uint8_t c = 0; c < 8; c++) { + buffer32->line[l][ef_x + (c << 1)] = + buffer32->line[l][ef_x + (c << 1) + 1] = + buffer32->line[l + 1][ef_x + (c << 1)] = + buffer32->line[l + 1][ef_x + (c << 1) + 1] = cols[dat >> 14]; + dat <<= 2; + } + } + break; + case 0x102: /*640x200x2*/ + cols[0] = pcjr->array[0 + 16] + 16; + cols[1] = pcjr->array[1 + 16] + 16; + for (x = 0; x < pcjr->crtc[1]; x++) { + int ef_x = (x << 4) + ho_d; + dat = (pcjr->vram[((pcjr->memaddr << 1) & mask) + offset] << 8) | + pcjr->vram[((pcjr->memaddr << 1) & mask) + offset + 1]; + pcjr->memaddr++; + for (uint8_t c = 0; c < 16; c++) { + buffer32->line[l][ef_x + c] = buffer32->line[l + 1][ef_x + c] = + cols[dat >> 15]; + dat <<= 1; + } + } + break; + + default: + break; + } + } else { + if (pcjr->array[3] & 4) { + if (pcjr->array[0] & 1) { + hline(buffer32, 0, l, (pcjr->crtc[1] << 3) + ho_s, (pcjr->array[2] & 0xf) + 16); + hline(buffer32, 0, l + 1, (pcjr->crtc[1] << 3) + ho_s, (pcjr->array[2] & 0xf) + 16); + } else { + hline(buffer32, 0, l, (pcjr->crtc[1] << 4) + ho_s, (pcjr->array[2] & 0xf) + 16); + hline(buffer32, 0, l + 1, (pcjr->crtc[1] << 4) + ho_s, (pcjr->array[2] & 0xf) + 16); + } + } else { + cols[0] = pcjr->array[0 + 16] + 16; + if (pcjr->array[0] & 1) { + hline(buffer32, 0, l, (pcjr->crtc[1] << 3) + ho_s, cols[0]); + hline(buffer32, 0, l + 1, (pcjr->crtc[1] << 3) + ho_s, cols[0]); + } else { + hline(buffer32, 0, l, (pcjr->crtc[1] << 4) + ho_s, cols[0]); + hline(buffer32, 0, l + 1, (pcjr->crtc[1] << 4) + ho_s, cols[0]); + } + } + } + if (pcjr->array[0] & 1) + x = (pcjr->crtc[1] << 3) + ho_s; + else + x = (pcjr->crtc[1] << 4) + ho_s; + if (pcjr->composite) { + Composite_Process(pcjr->array[0], 0, x >> 2, buffer32->line[l]); + Composite_Process(pcjr->array[0], 0, x >> 2, buffer32->line[l + 1]); + } else { + video_process_8(x, l); + video_process_8(x, l + 1); + } + pcjr->scanline = scanline_old; + if (pcjr->vc == pcjr->crtc[7] && !pcjr->scanline) { + pcjr->status |= 8; + } + pcjr->displine++; + if (pcjr->displine >= 360) + pcjr->displine = 0; + } else { + timer_advance_u64(&pcjr->timer, pcjr->dispontime); + if (pcjr->dispon) + pcjr->status |= 1; + pcjr->linepos = 0; + if (pcjr->vsynctime) { + pcjr->vsynctime--; + if (!pcjr->vsynctime) { + pcjr->status &= ~8; + } + } + if (pcjr->scanline == (pcjr->crtc[11] & 31) || ((pcjr->crtc[8] & 3) == 3 && pcjr->scanline == ((pcjr->crtc[11] & 31) >> 1))) { + pcjr->cursorvisible = 0; + } + if (pcjr->vadj) { + pcjr->scanline++; + pcjr->scanline &= 31; + pcjr->memaddr = pcjr->memaddr_backup; + pcjr->vadj--; + if (!pcjr->vadj) { + pcjr->dispon = 1; + pcjr->memaddr = pcjr->memaddr_backup = (pcjr->crtc[13] | (pcjr->crtc[12] << 8)) & 0x3fff; + pcjr->scanline = 0; + } + } else if (pcjr->scanline == pcjr->crtc[9] || ((pcjr->crtc[8] & 3) == 3 && pcjr->scanline == (pcjr->crtc[9] >> 1))) { + pcjr->memaddr_backup = pcjr->memaddr; + pcjr->scanline = 0; + oldvc = pcjr->vc; + pcjr->vc++; + pcjr->vc &= 127; + if (pcjr->vc == pcjr->crtc[6]) + pcjr->dispon = 0; + if (oldvc == pcjr->crtc[4]) { + pcjr->vc = 0; + pcjr->vadj = pcjr->crtc[5]; + if (!pcjr->vadj) + pcjr->dispon = 1; + if (!pcjr->vadj) + pcjr->memaddr = pcjr->memaddr_backup = (pcjr->crtc[13] | (pcjr->crtc[12] << 8)) & 0x3fff; + if ((pcjr->crtc[10] & 0x60) == 0x20) + pcjr->cursoron = 0; + else + pcjr->cursoron = pcjr->blink & 16; + } + if (pcjr->vc == pcjr->crtc[7]) { + pcjr->dispon = 0; + pcjr->displine = 0; + pcjr->vsynctime = 16; + picint(1 << 5); + if (pcjr->crtc[7]) { + if (pcjr->array[0] & 1) + x = (pcjr->crtc[1] << 3) + ho_s; + else + x = (pcjr->crtc[1] << 4) + ho_s; + pcjr->lastline++; + + xs_temp = x; + ys_temp = (pcjr->lastline - pcjr->firstline) << 1; + + if ((xs_temp > 0) && (ys_temp > 0)) { + int actual_ys = ys_temp; + + if (xs_temp < 64) + xs_temp = 656; + if (ys_temp < 32) + ys_temp = 400; + if (!enable_overscan) + xs_temp -= ho_s; + + if ((xs_temp != xsize) || (ys_temp != ysize) || video_force_resize_get()) { + xsize = xs_temp; + ysize = ys_temp; + + set_screen_size(xsize, ysize + (enable_overscan ? 32 : 0)); + + if (video_force_resize_get()) + video_force_resize_set(0); + } + + vid_blit_h_overscan(pcjr); + + if (enable_overscan) { + video_blit_memtoscreen(0, pcjr->firstline << 1, + xsize, actual_ys + 32); + } else if (pcjr->apply_hd) { + video_blit_memtoscreen(ho_s / 2, (pcjr->firstline << 1) + 16, + xsize, actual_ys); + } else { + video_blit_memtoscreen(ho_d, (pcjr->firstline << 1) + 16, + xsize, actual_ys); + } + } + + frames++; + video_res_x = xsize; + video_res_y = ysize; + } + pcjr->firstline = 1000; + pcjr->lastline = 0; + pcjr->blink++; + } + } else { + pcjr->scanline++; + pcjr->scanline &= 31; + pcjr->memaddr = pcjr->memaddr_backup; + } + if (pcjr->scanline == (pcjr->crtc[10] & 31) || ((pcjr->crtc[8] & 3) == 3 && pcjr->scanline == ((pcjr->crtc[10] & 31) >> 1))) + pcjr->cursorvisible = 1; + } +} + + +void +pcjr_vid_init(pcjr_t *pcjr) +{ + int display_type; + + video_inform(VIDEO_FLAG_TYPE_CGA, &timing_dram); + + pcjr->memctrl = -1; + if (mem_size < 128) + pcjr->memctrl &= ~0x24; + + display_type = device_get_config_int("display_type"); + pcjr->composite = (display_type == PCJR_COMPOSITE); + pcjr->apply_hd = device_get_config_int("apply_hd"); + overscan_x = 256; + overscan_y = 32; + + mem_mapping_add(&pcjr->mapping, 0xb8000, 0x08000, + vid_read, NULL, NULL, + vid_write, NULL, NULL, NULL, 0, pcjr); + io_sethandler(0x03d0, 16, + vid_in, NULL, NULL, vid_out, NULL, NULL, pcjr); + timer_add(&pcjr->timer, vid_poll, pcjr, 1); + + if (pcjr->composite) + cga_palette = 0; + else + cga_palette = (display_type << 1); + cgapal_rebuild(); +} diff --git a/src/video/vid_pgc.c b/src/video/vid_pgc.c index 354c7e265..63126955c 100644 --- a/src/video/vid_pgc.c +++ b/src/video/vid_pgc.c @@ -2342,23 +2342,23 @@ pgc_cga_text(pgc_t *dev, int w) int drawcursor = 0; uint32_t cols[2]; int pitch = (dev->mapram[0x3e9] + 1) * 2; - uint16_t sc = (dev->displine & 0x0f) % pitch; - uint16_t ma = (dev->mapram[0x3ed] | (dev->mapram[0x3ec] << 8)) & 0x3fff; - uint16_t ca = (dev->mapram[0x3ef] | (dev->mapram[0x3ee] << 8)) & 0x3fff; + uint16_t scanline = (dev->displine & 0x0f) % pitch; + uint16_t memaddr = (dev->mapram[0x3ed] | (dev->mapram[0x3ec] << 8)) & 0x3fff; + uint16_t cursoraddr = (dev->mapram[0x3ef] | (dev->mapram[0x3ee] << 8)) & 0x3fff; const uint8_t *addr; uint32_t val; int cw = (w == 80) ? 8 : 16; - addr = &dev->cga_vram[((ma + ((dev->displine / pitch) * w)) * 2) & 0x3ffe]; - ma += (dev->displine / pitch) * w; + addr = &dev->cga_vram[((memaddr + ((dev->displine / pitch) * w)) * 2) & 0x3ffe]; + memaddr += (dev->displine / pitch) * w; for (int x = 0; x < w; x++) { chr = *addr++; attr = *addr++; /* Cursor enabled? */ - if (ma == ca && (dev->cgablink & 8) && (dev->mapram[0x3ea] & 0x60) != 0x20) { - drawcursor = ((dev->mapram[0x3ea] & 0x1f) <= (sc >> 1)) && ((dev->mapram[0x3eb] & 0x1f) >= (sc >> 1)); + if (memaddr == cursoraddr && (dev->cgablink & 8) && (dev->mapram[0x3ea] & 0x60) != 0x20) { + drawcursor = ((dev->mapram[0x3ea] & 0x1f) <= (scanline >> 1)) && ((dev->mapram[0x3eb] & 0x1f) >= (scanline >> 1)); } else drawcursor = 0; @@ -2374,9 +2374,9 @@ pgc_cga_text(pgc_t *dev, int w) for (int c = 0; c < cw; c++) { if (drawcursor) - val = cols[(fontdatm[chr + dev->fontbase][sc] & (1 << (c ^ 7))) ? 1 : 0] ^ 0x0f; + val = cols[(fontdatm[chr + dev->fontbase][scanline] & (1 << (c ^ 7))) ? 1 : 0] ^ 0x0f; else - val = cols[(fontdatm[chr + dev->fontbase][sc] & (1 << (c ^ 7))) ? 1 : 0]; + val = cols[(fontdatm[chr + dev->fontbase][scanline] & (1 << (c ^ 7))) ? 1 : 0]; if (cw == 8) /* 80x25 CGA text screen. */ buffer32->line[dev->displine][(x * cw) + c] = val; else { /* 40x25 CGA text screen. */ @@ -2385,7 +2385,7 @@ pgc_cga_text(pgc_t *dev, int w) } } - ma++; + memaddr++; } } @@ -2395,7 +2395,7 @@ pgc_cga_gfx40(pgc_t *dev) { uint32_t cols[4]; int col; - uint16_t ma = (dev->mapram[0x3ed] | (dev->mapram[0x3ec] << 8)) & 0x3fff; + uint16_t memaddr = (dev->mapram[0x3ed] | (dev->mapram[0x3ec] << 8)) & 0x3fff; const uint8_t *addr; uint16_t dat; @@ -2422,9 +2422,9 @@ pgc_cga_gfx40(pgc_t *dev) } 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]; + addr = &dev->cga_vram[(memaddr + 2 * x + 80 * (dev->displine >> 2) + 0x2000 * ((dev->displine >> 1) & 1)) & 0x3fff]; dat = (addr[0] << 8) | addr[1]; - dev->ma++; + dev->memaddr++; 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; @@ -2437,7 +2437,7 @@ void pgc_cga_gfx80(pgc_t *dev) { uint32_t cols[2]; - uint16_t ma = (dev->mapram[0x3ed] | (dev->mapram[0x3ec] << 8)) & 0x3fff; + uint16_t memaddr = (dev->mapram[0x3ed] | (dev->mapram[0x3ec] << 8)) & 0x3fff; const uint8_t *addr; uint16_t dat; @@ -2445,9 +2445,9 @@ pgc_cga_gfx80(pgc_t *dev) cols[1] = (dev->mapram[0x3d9] & 15) + 16; 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]; + addr = &dev->cga_vram[(memaddr + 2 * x + 80 * (dev->displine >> 2) + 0x2000 * ((dev->displine >> 1) & 1)) & 0x3fff]; dat = (addr[0] << 8) | addr[1]; - dev->ma++; + dev->memaddr++; for (uint8_t c = 0; c < 16; c++) { buffer32->line[dev->displine][(x << 4) + c] = cols[dat >> 15]; dat <<= 1; @@ -2743,7 +2743,7 @@ const device_t pgc_device = { .init = pgc_standalone_init, .close = pgc_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = pgc_speed_changed, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_ps55da2.c b/src/video/vid_ps55da2.c new file mode 100644 index 000000000..938e4bf6b --- /dev/null +++ b/src/video/vid_ps55da2.c @@ -0,0 +1,3508 @@ +/* + * 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. + * + * IBM PS/55 Display Adapter II (and its successors) emulation. + * + * Notes: There are some known issues that should be corrected. + * - Incorrect foreground text color appears on an active window in OS/2 J1.3. + * - Glitches some part of graphics on the Control Panel in OS/2 J2.1 beta. + * + * The code should be tested with following cases. + * - Execute MODE 0, 1, 3 and 4 commands in DOS K3.3 to test various video modes. + * - Run SAMPLE program with the BASIC interpreter in DOS K3.3. + * - Run DOS J4.0 install program to test video mode 03. + * - Run Win 3.1 (IBM-J OEM) and OS/2 J1.3 with 16 and 256 color driver to test BilBlt operations. + * + * Authors: Akamaki. + * + * Copyright 2024-2025 Akamaki. + */ + +#include +#include +#include +#include +#include +#include +#define HAVE_STDARG_H +#include <86box/86box.h> +#include <86box/device.h> +#include <86box/io.h> +#include <86box/machine.h> +#include <86box/mem.h> +#include <86box/timer.h> +#include <86box/mca.h> +#include <86box/rom.h> +#include <86box/plat.h> +#include <86box/video.h> +#include <86box/vid_ps55da2.h> +#include <86box/vid_svga.h> +#include <86box/vid_svga_render.h> +#include "cpu.h" + +#define DA2_FONTROM_PATH_JPAN "roms/video/da2/94X1320.BIN" +#define DA2_FONTROM_PATH_HANT "roms/video/da2/23F2698.BIN" +#define DA2_FONTROM_SIZE (1536 * 1024) +#define DA2_FONTROM_BASESBCS 0x98000 +#define DA2_GAIJIRAM_SBCS 0x34000 +#define DA2_GAIJIRAM_SBEX 0x3c000 +#define DA2_VM03_BASECHR 0x18000 +#define DA2_VM03_BASEEXATTR 0x10000 +#define DA2_INVALIDACCESS8 0xffu +#define DA2_INVALIDACCESS16 0xffffu +#define DA2_INVALIDACCESS32 0xffffffffu +#define DA2_MASK_MMIO 0x1ffff +#define DA2_SIZE_VRAM (1024 * 1024) /* 0x100000 */ +#define DA2_SIZE_CRAM (4 * 1024) /* 0x1000 */ +#define DA2_SIZE_GAIJIRAM (256 * 1024) /* 0x40000 */ +#define DA2_MASK_A000 0x1ffff /* 0x1FFFF */ +#define DA2_MASK_CRAM 0xfff /* 0xFFF */ +#define DA2_MASK_GAIJIRAM 0x3ffff /* 0x3FFFF */ +#define DA2_MASK_VRAM 0xfffff /* 0xFFFFF */ +#define DA2_MASK_VRAMPLANE 0x1ffff /* 0x1FFFF */ +#define DA2_PIXELCLOCK 29000000.0 /* 58 MHz interlaced */ +#define DA2_BLT_MEMSIZE 0x10 +#define DA2_BLT_REGSIZE 0x40 +#define DA2_DEBUG_BLTLOG_SIZE (DA2_BLT_REGSIZE + 1) +#define DA2_DEBUG_BLTLOG_MAX (256 * 1024) +#define DA2_DEBUG_BLT_NEVERUSED 0xfefefefe +#define DA2_DEBUG_BLT_USEDRESET 0xfefefe +#define DA2_DCONFIG_CHARSET_JPAN 0 /* for Code page 932 Japanese */ +// #define DA2_DCONFIG_CHARSET_HANG 1 /* for Code page 934 Hangul */ +// #define DA2_DCONFIG_CHARSET_HANS 2 /* for Code page 936 Simplified Chinese */ +/* These ROMs are currently not found. + At least, IBM-J released a Korean and PRC version of PS/55 for each market. */ +#define DA2_DCONFIG_CHARSET_HANT 3 /* for Code page 938 Traditional Chinese */ +#define DA2_DCONFIG_MONTYPE_COLOR 0x0A +#define DA2_DCONFIG_MONTYPE_8515 0x0B +#define DA2_DCONFIG_MONTYPE_MONO 0x09 + +#define DA2_BLT_CIDLE 0 +#define DA2_BLT_CFILLRECT 1 +#define DA2_BLT_CFILLTILE 2 +#define DA2_BLT_CCOPYF 3 +#define DA2_BLT_CCOPYR 4 +#define DA2_BLT_CPUTCHAR 5 +#define DA2_BLT_CLINE 6 +#define DA2_BLT_CDONE 7 +#define DA2_BLT_CLOAD 8 +/* POS ID = 0xeffe : Display Adapter II, III, V */ +#define DA2_POSID_H 0xef +#define DA2_POSID_L 0xfe +/* + [Identification] + POS ID SYS ID + EFFFh * Display Adapter (PS/55 Model 5571-S0A) [Toledo] + E013h * Layout Display Terminal (PS/55-5571 RPQ model) [LDT] + EFFEh * Display Adapter II (I/O 3E0:0A = xx0x xxxx) [Atlas] + |- FFF2h Display Adapter B2 (I/O 3E0:0A = xx1x xxxx) (PS/55 Model 5530Z-SX) + |- FDFEh Display Adapter B2 (I/O 3E0:0A = xx1x xxxx) (PS/55 Model 5550-V2) + |- * Display Adapter III,V (I/O 3E0:0A = xx1x xxxx) + ECECh FF4Fh Display Adapter B1 (PS/55 Model 5531Z-SX) [Atlas-KENT] + |- * Display Adapter IV + ECCEh * Display Adapter IV + 901Fh * Display Adapter A2 + 901Dh * Display Adapter A1 [Atlas II] + 901Eh * Plasma Display Adapter + EFD8h * Display Adapter/J [Atlas-SP2] + + [Japanese DOS and Display Adapter compatibility] + | | | 5605JBK | 5605PAA | 5605PCA | 5605PDE | 5605PAW | 5605PXB | + | POS ID | Adapter Name | K3.31 | J4.05 | J4.08 | J1.33 | 3.02 | 2.0 | + |------------|-----------------------------|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:| + | EFFFh | Display Adapter | X | | | | | | + | FFEDh | ? [Atlas EVT] | X | | | | | | + | FFFDh | ? [LDT EVT] | X | | | | | | + | EFFEh | Display Adapter II,III,V,B2 | X | X | X | X | X | X | + | E013h | ? [LDT] | X | X | X | X | | X | + | ECCEh | Display Adapter IV | | X | X | X | | X | + | ECECh | Display Adapter IV,B1 | | X | X | X | X | X | + | 9000-901Fh | Display Adapter A1,A2 | | X | X | | X | X | + | EFD8h | Display Adapter /J | | | X | X | X | X | + + - 5605JBK : Japanese DOS K3.3, K3.4 (for PS/55 model 55xx-S, T, V, Z) + - 5605PAA : DOS J4.0 + - 5605PCA : DOS J4.0 (with MKK) + - 5605PDE : OS/2 Extended Edition J1.3 + - 5605PAW : Japanese Microsoft Windows 3.0 (IBMJ OEM) + - 5605PXB : DOS/V Extension V2.0 + */ +/* IO 3E0/3E1:0Ah Hardware Configuration Value L (imported from OS/2 DDK) */ +#define OldLSI 0x20 /* 1 = DA-2, 0 = DA-3 */ +// #define Mon_ID3 0x10 +#define FontCard 0x08 /* ? */ +#define Page_One 0x06 /* 80000h 110b */ +#define Page_Two 0x05 /* 100000h 101b */ +#define Page_Four 0x03 /* 200000h 011b */ +/* Page Number Mask : Memory Size? = (110b and 111b): vram size is 512k (256 color mode unsupported). */ + +/* IO 3E0/3E1:0Bh Hardware Configuration Value H (imported from OS/2 DDK) */ +#define AddPage 0x08 /* ? */ +// #define Mon_ID2 0x04 +// #define Mon_ID1 0x02 +// #define Mon_ID0 0x01 + +/* Monitor ID (imported from OS/2 DDK 1.2) +#define StarbuckC 0x0A // 1 010b IBM 8514, 9518 color 1040x768 +#define StarbuckM 0x09 // 1 001b IBM 8507, 8604 grayscale +#define Lark_B 0x02 // 0 010b IBM 9517 color 1040x768 but 4bpp +#define Dallas 0x0B // 1 011b IBM 8515, 9515 color 1040x740 another palette +*/ + +/* DA2 Registers (imported from OS/2 DDK) */ +#define AC_REG 0x3EE +#define AC_DMAE 0x80 +#define AC_FONT_SEL 0x40 +#define FONT_BANK 0x3EF +#define LS_INDEX 0x3E0 +#define LS_DATA 0x3E1 +#define LS_RESET 0x00 +#define LS_MODE 0x02 +#define LS_STATUS 0x03 /* added */ +#define LS_MMIO 0x08 /* added */ +#define LS_CONFIG1 0x0a +#define LS_CONFIG2 0x0b /* added */ +#define LF_INDEX 0x3e2 +#define LF_DATA 0x3e3 +#define LF_MMIO_SEL 0x08 /* added */ +#define LF_MMIO_09 0x09 /* added */ +#define LF_MMIO_ADDR 0x0A /* added */ +#define LF_MMIO_MODE 0x0B /* added */ +#define LF_PD_RESET 0x18 /* added */ +#define LC_INDEX 0x3E4 +#define LC_DATA 0x3E5 +#define LC_HORIZONTAL_TOTAL 0x00 +#define LC_H_DISPLAY_ENABLE_END 0x01 +#define LC_START_H_BLANKING 0x02 +#define LC_END_H_BLANKING 0x03 +#define LC_START_HSYNC_PULSE 0x04 +#define LC_END_HSYNC_PULSE 0x05 +#define LC_VERTICAL_TOTALJ 0x06 +#define LC_CRTC_OVERFLOW 0x07 +#define LC_PRESET_ROW_SCANJ 0x08 +#define LC_MAXIMUM_SCAN_LINE 0x09 +#define LC_CURSOR_ROW_START 0x0A +#define LC_CURSOR_ROW_END 0x0B +#define LC_START_ADDRESS_HIGH 0x0C +#define LC_START_ADDRESS_LOW 0x0D +#define LC_CURSOR_LOC_HIGH 0x0E +#define LC_ROW_CURSOR_LOC 0x0E +#define LC_CURSOR_LOC_LOWJ 0x0F +#define LC_COLUMN_CURSOR_LOC 0x0F +#define LC_VERTICAL_SYNC_START 0x10 +#define LC_LIGHT_PEN_HIGH 0x10 +#define LC_VERTICAL_SYNC_END 0x11 +#define LC_LIGHT_PEN_LOW 0x11 +#define LC_V_DISPLAY_ENABLE_END 0x12 +#define LC_OFFSET 0x13 +#define LC_UNDERLINE_LOCATION 0x14 +#define LC_START_VERTICAL_BLANK 0x15 +#define LC_END_VERTICAL_BLANK 0x16 +#define LC_LC_MODE_CONTROL 0x17 +#define LC_LINE_COMPAREJ 0x18 +#define LC_START_H_DISPLAY_ENAB 0x19 +#define LC_START_V_DISPLAY_ENAB 0x1A +#define LC_VIEWPORT_COMMAND 0x1B +#define LC_VIEWPORT_SELECT 0x1C +#define LC_VIEWPORT_PRIORITY 0x1D +#define LC_COMMAND 0x1E +#define LC_COMPATIBILITY 0x1F +#define LC_VIEWPORT_NUMBER 0x1F +#define LV_PORT 0x3E8 +#define LV_PALETTE_0 0x00 +#define LV_MODE_CONTROL 0x10 +#define LV_OVERSCAN_COLOR 0x11 +#define LV_COLOR_PLANE_ENAB 0x12 +#define LV_PANNING 0x13 +#define LV_VIEWPORT1_BG 0x14 +#define LV_VIEWPORT2_BG 0x15 +#define LV_VIEWPORT3_BG 0x16 +#define LV_BLINK_COLOR 0x17 +#define LV_BLINK_CODE 0x18 +#define LV_GR_CURSOR_ROTATION 0x19 +#define LV_GR_CURSOR_COLOR 0x1A +#define LV_GR_CURSOR_CONTROL 0x1B +#define LV_COMMAND 0x1C +#define LV_VP_BORDER_LINE 0x1D +#define LV_SYNC_POLARITY 0x1F +#define LV_CURSOR_CODE_0 0x20 +#define LV_GRID_COLOR_0 0x34 +#define LV_GRID_COLOR_1 0x35 +#define LV_GRID_COLOR_2 0x36 +#define LV_GRID_COLOR_3 0x37 +#define LV_ATTRIBUTE_CNTL 0x38 +#define LV_CURSOR_COLOR 0x3A +#define LV_CURSOR_CONTROL 0x3B +#define LV_RAS_STATUS_VIDEO 0x3C +#define LV_PAS_STATUS_CNTRL 0x3D +#define LV_IDENTIFICATION 0x3E +#define LV_OUTPUT 0x3E +#define LV_COMPATIBILITY 0x3F +#define LG_INDEX 0x3EA +#define LG_DATA 0x3EB +#define LG_SET_RESETJ 0x00 +#define LG_ENABLE_SRJ 0x01 +#define LG_COLOR_COMPAREJ 0x02 +#define LG_DATA_ROTATION 0x03 +#define LG_READ_MAP_SELECT 0x04 +#define LG_MODE 0x05 +#define LG_COMPLEMENT 0x06 +#define LG_COLOR_DONT_CARE 0x07 +#define LG_BIT_MASK_LOW 0x08 +#define LG_BIT_MASK_HIGH 0x09 +#define LG_MAP_MASKJ 0x0A +#define LG_COMMAND 0x0B +#define LG_SET_RESET_2 0x10 + +#ifndef RELEASE_BUILD +// #define ENABLE_DA2_LOG 1 +#endif + +#ifdef ENABLE_DA2_LOG +# define ENABLE_DA2_DEBUGIO 1 +# define ENABLE_DA2_DEBUGBLT 1 +// # define ENABLE_DA2_DEBUGVRAM 1 +// # define ENABLE_DA2_DEBUGFULLSCREEN 1 +// # define ENABLE_DA2_DEBUGMONWAIT 1 +int da2_do_log = ENABLE_DA2_LOG; + +static void +da2_log(const char *fmt, ...) +{ + va_list ap; + + if (da2_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define da2_log(fmt, ...) +#endif +#ifdef ENABLE_DA2_DEBUGIO +# define da2_iolog da2_log +#else +# define da2_iolog(fmt, ...) +#endif +#ifdef ENABLE_DA2_DEBUGBLT +# define da2_bltlog da2_log +# define ENABLE_DA2_DEBUGBLT_DETAIL 1 +# ifdef ENABLE_DA2_DEBUGBLT_DETAIL +# define da2_bltreglog da2_log +# else +# define da2_bltreglog(fmt, ...) +# endif +#else +# define da2_bltlog(fmt, ...) +# define da2_bltreglog(fmt, ...) +#endif + +typedef struct da2_t { + mem_mapping_t cmapping; + + uint8_t ioctl[16]; + uint8_t fctl[32]; + uint16_t crtc[32]; + uint16_t crtc_vpreg[128]; + uint8_t crtc_vpsel; + uint8_t gdcreg[64]; + uint8_t reg3ee[16]; + int gdcaddr; + uint8_t attrc[0x40]; + int attraddr, attrff; + int attr_palette_enable; + int outflipflop; + int inflipflop; + int iolatch; + + int ioctladdr; + int fctladdr; + int crtcaddr; + + uint32_t gdcla[8]; + uint32_t gdcinput[8]; + uint32_t gdcsrc[8]; + + uint8_t dac_mask, dac_status; + int dac_read, dac_write, dac_pos; + int dac_r, dac_g; + + uint8_t cgastat; + + uint8_t plane_mask; + + int writemode, readplane; + uint8_t planemask; + + uint8_t egapal[16]; + uint32_t pallook[512]; + PALETTE vgapal; + + int vtotal, dispend, vsyncstart, split, vblankstart; + int hdisp, htotal, hdisp_time, rowoffset; + int lowres; + int rowcount; + double clock; + uint32_t memaddr_latch, ca_adj; + + uint64_t dispontime, dispofftime; + pc_timer_t timer; + uint64_t da2const; + + int dispon; + int hdisp_on; + + uint32_t memaddr, memaddr_backup, cursoraddr; + int vc; + int scanline; + int linepos, vslines, linecountff; + int cursorvisible, cursoron, blink, blinkconf; + int scrollcache; + int char_width; + + int firstline, lastline; + int firstline_draw, lastline_draw; + int displine; + + /* Attribute Buffer E0000-E0FFFh (4 KB) */ + uint8_t *cram; + /* APA Buffer A0000-BFFFFh (128 KB) */ + uint8_t *vram; + uint8_t *changedvram; + uint32_t vram_display_mask; + + int fullchange; + + void (*render)(struct da2_t *da2); + + /*If set then another device is driving the monitor output and the SVGA + card should not attempt to display anything */ + int override; + + struct { + int enable; + mem_mapping_t mapping; + uint8_t ram[DA2_SIZE_GAIJIRAM]; + uint8_t *font; + int charset; + } mmio; + + struct { + int bitshift_destr; + int raster_op; + uint8_t payload[DA2_BLT_MEMSIZE]; + int payload_addr; + int payload_opsize; + int32_t reg[DA2_BLT_REGSIZE]; // must be signed int +#ifdef ENABLE_DA2_DEBUGBLT + int32_t *debug_reg; // for debug + int debug_reg_ip; // for debug + int debug_exesteps; +#endif + pc_timer_t timer; + int64_t timerspeed; + int exec; + int indata; + int32_t destaddr; + int32_t srcaddr; + int16_t size_x; + int16_t tile_w; + int16_t size_y; + int16_t dest_x; + int16_t dest_y; + int16_t destpitch; + int16_t srcpitch; + int32_t fcolor; + int32_t maskl, maskr; + int32_t count; + int32_t d; + int8_t destoption; + int octdir; + int x, y, wx1, wx2, wy1, wy2; + } bitblt; + +#ifdef ENABLE_DA2_DEBUGVRAM + FILE *mmdbg_fp; + FILE *mmrdbg_fp; + uint32_t mmdbg_vidaddr; + uint32_t mmrdbg_vidaddr; +#endif + + uint8_t pos_regs[8]; + svga_t *mb_vga; + uint8_t monitorid; + pc_timer_t timer_vidupd; + + int old_pos2; +} da2_t; + +static void da2_recalctimings(da2_t *da2); +static void da2_mmio_gc_writeW(uint32_t addr, uint16_t val, void *p); +static void da2_bitblt_exec(void *p); +static void da2_updatevidselector(da2_t *da2); +static void da2_reset_ioctl(da2_t *da2); +static void da2_reset(void *priv); +static uint16_t da2_rightrotate(uint16_t data, uint8_t count); + +typedef union { + uint32_t d; + uint8_t b[4]; +} vidseq32; + +typedef struct { + uint32_t p8[8]; +} pixel32; + +/* safety read for internal functions */ +static uint32_t +da2_vram_r(uint32_t addr, da2_t *da2) +{ + if (addr & ~DA2_MASK_VRAM) + return DA2_INVALIDACCESS32; + return da2->vram[addr]; +} +/* safety write for internal functions */ +static void +da2_vram_w(uint32_t addr, uint8_t val, da2_t *da2) +{ + if (addr & ~DA2_MASK_VRAM) + return; + da2->vram[addr] = val; + return; +} + +/* +Param Desc +01 Color +03 Bit Shift +04 Select plane? +05 Direction (1000h or 1100h) + Command? (40 or 48) +08 Mask Left +09 Mask Right +0A Plane Mask? +0B ROP + 2000 NOT Source + 200 Source / Pattern + 20 NOT Dest + 10 NOT Pattern + 8 ? + 0-3 Bit op (0 None, 1 AND, 2 OR, 3 XOR) +0D +20 Exec (1) or Exec without reset regs? (21h) +21 Dest Pitch +22 Src Pitch +23 Tile W +28 Tile H +29 Dest Addr +2A Src Addr +2B Tile Addr +2D Octant for line drawing +2F Dest Write Option +32 wx1, Dest X +33 wx2, Size W +34 wy1, Dest Y +35 wy2, Size H +*/ +/* write pixel data with rop (Note: bitmask must be in big endian) */ +static void +da2_WritePlaneDataWithBitmask(uint32_t destaddr, const uint16_t mask, pixel32 *srcpx, da2_t *da2) +{ + uint32_t writepx[8]; + destaddr &= 0xfffffffe; /* align to word address to work bit shift correctly */ + // da2_log("DA2_WPDWB addr %x mask %x rop %x shift %d\n", destaddr, mask, da2->bitblt.raster_op, da2->bitblt.bitshift_destr); + da2->changedvram[(DA2_MASK_VRAMPLANE & destaddr) >> 9] = changeframecount; + destaddr <<= 3; + /* read destination data with big endian order */ + for (uint8_t i = 0; i < 8; i++) + writepx[i] = da2_vram_r((destaddr + 24) | i, da2) + | (da2_vram_r((destaddr + 16) | i, da2) << 8) + | (da2_vram_r((destaddr + 8) | i, da2) << 16) + | (da2_vram_r((destaddr + 0) | i, da2) << 24); + + vidseq32 mask32in; + mask32in.d = (uint32_t) mask; + vidseq32 mask32; + mask32.b[3] = mask32in.b[0]; + mask32.b[2] = mask32in.b[1]; + mask32.d &= 0xffff0000; + for (uint8_t i = 0; i < 8; i++) { + if (da2->bitblt.bitshift_destr > 0) + srcpx->p8[i] <<= 16 - da2->bitblt.bitshift_destr; +// #ifdef ENABLE_DA2_DEBUGBLT +// if (i == 0) { +// pclog("writeplane: src %08X mask %08X dest %08X\n", srcpx->p8[i], mask32.d, writepx[i]); +// } +// #endif + if (da2->bitblt.raster_op & 0x2010) /* NOT Src or NOT Pattern */ + srcpx->p8[i] = ~srcpx->p8[i] & mask32.d; + if (da2->bitblt.raster_op & 0x20) /* Dest NOT */ + writepx[i] = (~writepx[i] & mask32.d) | (writepx[i] & ~mask32.d); + switch (da2->bitblt.raster_op & 0x03) { + case 0x00: /* None */ + writepx[i] &= ~mask32.d; + writepx[i] |= srcpx->p8[i] & mask32.d; + break; + case 0x01: /* AND */ + writepx[i] &= srcpx->p8[i] | ~mask32.d; + break; + case 0x02: /* OR */ + writepx[i] |= srcpx->p8[i] & mask32.d; + break; + case 0x03: /* XOR */ + writepx[i] ^= srcpx->p8[i] & mask32.d; + break; + } + } + for (uint8_t i = 0; i < 8; i++) { + da2_vram_w(destaddr | i, (writepx[i] >> 24) & 0xff, da2); + da2_vram_w((destaddr + 8) | i, (writepx[i] >> 16) & 0xff, da2); + } +} + +static void +da2_DrawColorWithBitmask(uint32_t destaddr, uint8_t color, uint16_t mask, da2_t *da2) +{ + pixel32 srcpx; + /* fill data with input color */ + for (uint8_t i = 0; i < 8; i++) + srcpx.p8[i] = (color & (1 << i)) ? 0xffffffff : 0; /* read in word */ + + da2_WritePlaneDataWithBitmask(destaddr, mask, &srcpx, da2); +} +static void +da2_CopyPlaneDataWithBitmask(uint32_t srcaddr, uint32_t destaddr, uint16_t mask, da2_t *da2) +{ + pixel32 srcpx; + srcaddr &= 0xfffffffe; + srcaddr <<= 3; + for (uint8_t i = 0; i < 8; i++) + srcpx.p8[i] = da2_vram_r((srcaddr + 24) | i, da2) + | (da2_vram_r((srcaddr + 16) | i, da2) << 8) + | (da2_vram_r((srcaddr + 8) | i, da2) << 16) + | (da2_vram_r((srcaddr + 0) | i, da2) << 24); + + da2_WritePlaneDataWithBitmask(destaddr, mask, &srcpx, da2); +} +/* get font data for bitblt operation */ +static uint32_t +getRAMFont(int32_t code, int line, int x, void *priv) +{ + da2_t *da2 = (da2_t *) priv; + uint32_t font = 0; +#ifdef RESERVED_FOR_FUTURE_USE + int fline = line - 2; /* Start line of drawing character (line >= 1 AND line < 24 + 1 ) */ +#endif + if (code < 0x100) { /* SBCS 13x29 */ + code *= 0x40; + code += DA2_GAIJIRAM_SBCS + (line * 2) + x; + font = da2->mmio.ram[code]; + font <<= 8; + font |= da2->mmio.ram[code + 1]; + font <<= 16; + } else if ((code >= 0xb000) && (code <= 0xb75f)) { /* DBCS 26x29 */ + /* convert code->address in gaiji memory */ + code -= 0xb000; + code = (code * 0x80) + (line * 4) + x; + font = da2->mmio.ram[code]; + font <<= 8; + font |= da2->mmio.ram[code + 1]; + font <<= 8; + font |= da2->mmio.ram[code + 2]; + font <<= 8; + font |= da2->mmio.ram[code + 3]; + } else + font = 0; + return font; +} +#ifdef RESERVED_FOR_FUTURE_USE +/* Reverse the bit order of attribute code IBGR to IRGB(used in Mode 3 and Cursor Color) */ +static int8_t +IBGRtoIRGB(uint8_t attr) +{ + attr = ((attr & 0x01) << 6) | ((attr & 0x02) << 4) | ((attr & 0x04) << 2) | ((attr & 0x08) << 4); + return attr >>= 4; +} +#endif +static void +da2_PutcharWithBitmask(uint32_t codeIBMJ, int width, uint16_t attr, int line, uint32_t destaddr, uint16_t maskl, uint16_t maskr, da2_t *da2) +{ + pixel32 srcpx; + uint8_t fg = (~attr >> 8) & 0x0f; + uint8_t bg = (~attr >> 12) & 0x0f; + uint32_t font = getRAMFont(codeIBMJ, line, 0, da2); + uint32_t fontinv; + if (width <= 2) { + fontinv = ~font; + for (uint8_t i = 0; i < 8; i++) { + srcpx.p8[i] = (fg & (1 << i)) ? font >> 16 : 0; + srcpx.p8[i] |= (bg & (1 << i)) ? fontinv >> 16 : 0; + } + da2_WritePlaneDataWithBitmask(destaddr, maskl, &srcpx, da2); + for (uint8_t i = 0; i < 8; i++) { + srcpx.p8[i] = (fg & (1 << i)) ? font : 0; + srcpx.p8[i] |= (bg & (1 << i)) ? fontinv : 0; + } + da2_WritePlaneDataWithBitmask(destaddr + 2, maskr, &srcpx, da2); + } else { + font = (font & 0xfff80000) | ((font & 0x0000ffff) << 3); + fontinv = ~font; + for (uint8_t i = 0; i < 8; i++) { + srcpx.p8[i] = (fg & (1 << i)) ? font >> 16 : 0; + srcpx.p8[i] |= (bg & (1 << i)) ? fontinv >> 16 : 0; + } + da2_WritePlaneDataWithBitmask(destaddr, maskl, &srcpx, da2); + for (uint8_t i = 0; i < 8; i++) { + srcpx.p8[i] = (fg & (1 << i)) ? font : 0; + srcpx.p8[i] |= (bg & (1 << i)) ? fontinv : 0; + } + if (da2->bitblt.destoption & 0x20) { + da2_WritePlaneDataWithBitmask(destaddr + 2, maskr, &srcpx, da2); + } else { + da2_WritePlaneDataWithBitmask(destaddr + 2, 0xffff, &srcpx, da2); + for (uint8_t i = 0; i < 8; i++) { + srcpx.p8[i] = (fg & (1 << i)) ? font << 16 : 0; + srcpx.p8[i] |= (bg & (1 << i)) ? fontinv << 16 : 0; + } + da2_WritePlaneDataWithBitmask(destaddr + 4, maskr, &srcpx, da2); + } + } +} +#ifdef ENABLE_DA2_DEBUGBLT +static uint8_t +pixel1tohex(uint32_t addr, int index, da2_t *da2) +{ + uint8_t pixeldata = 0; + for (uint8_t i = 0; i < 8; j++) { + if (da2_vram_r(((addr << 3) | i) & (1 << (7 - index)), da2)) + pixeldata++; + } + return pixeldata; +} +static void +print_pixelbyte(uint32_t addr, da2_t *da2) +{ + for (uint8_t i = 0; i < 8; i++) { + pclog("%X", pixel1tohex(addr, i, da2)); + } +} +static void +print_bytetobin(uint8_t b) +{ + for (uint8_t i = 0; i < 8; i++) { + if (b & 0x80) + pclog("1"); + else + pclog("0"); + b <<= 1; + } +} +/* Convert internal char code to Shift JIS code */ +static int +isKanji1(uint8_t chr) +{ + return (chr >= 0x81 && chr <= 0x9f) || (chr >= 0xe0 && chr <= 0xfc); +} +static int +isKanji2(uint8_t chr) +{ + return (chr >= 0x40 && chr <= 0x7e) || (chr >= 0x80 && chr <= 0xfc); +} +static uint16_t +IBMJtoSJIS(uint16_t knj) +{ + if (knj < 0x100) + return 0xffff; + knj -= 0x100; + if (knj <= 0x1f7d) + ; /* do nothing */ + else if (knj >= 0xb700 && knj <= 0xb75f) + knj -= 0x90ec; + else if (knj >= 0xb3f0 && knj <= 0xb67f) + knj -= 0x906c; + else if (knj >= 0x8000 && knj <= 0x8183) + knj -= 0x5524; + else + return 0xffff; + uint32_t knj1 = knj / 0xBC; + uint32_t knj2 = knj - (knj1 * 0xBC); + knj1 += 0x81; + if (knj1 > 0x9F) + knj1 += 0x40; + knj2 += 0x40; + if (knj2 > 0x7E) + knj2++; + // if (!isKanji1(knj1)) return 0xffff; + // if (!isKanji2(knj2)) return 0xffff; + knj = knj1 << 8; + knj |= knj2; + return knj; +} +#endif + +static void +da2_bitblt_parse(da2_t *da2) +{ + uint32_t value32; + uint64_t value64; + switch (da2->bitblt.payload[0]) { + case 0x88: + case 0x89: + case 0x95: + value32 = da2->bitblt.payload[3]; + value32 <<= 8; + value32 |= da2->bitblt.payload[2]; + da2_bltreglog("[%02x] %02x: %04x (%d)\n", da2->bitblt.payload[0], da2->bitblt.payload[1], value32, value32); + da2->bitblt.reg[da2->bitblt.payload[1]] = value32; + break; + case 0x91: + value32 = da2->bitblt.payload[5]; + value32 <<= 8; + value32 |= da2->bitblt.payload[4]; + value32 <<= 8; + value32 |= da2->bitblt.payload[3]; + value32 <<= 8; + value32 |= da2->bitblt.payload[2]; + da2_bltreglog("[%02x] %02x: %08x (%d)\n", da2->bitblt.payload[0], da2->bitblt.payload[1], value32, value32); + da2->bitblt.reg[da2->bitblt.payload[1]] = value32; + break; + case 0x99: + value64 = da2->bitblt.payload[7]; + value64 <<= 8; + value64 = da2->bitblt.payload[6]; + value64 <<= 8; + value64 = da2->bitblt.payload[5]; + value64 <<= 8; + value64 |= da2->bitblt.payload[4]; + value64 <<= 8; + value64 |= da2->bitblt.payload[3]; + value64 <<= 8; + value64 |= da2->bitblt.payload[2]; + da2_bltreglog("[%02x] %02x: %02x %02x %02x %02x %02x %02x\n", da2->bitblt.payload[0], da2->bitblt.payload[1], da2->bitblt.payload[2], da2->bitblt.payload[3], + da2->bitblt.payload[4], da2->bitblt.payload[5], da2->bitblt.payload[6], da2->bitblt.payload[7]); + da2->bitblt.reg[da2->bitblt.payload[1]] = value64; + break; + case 0xa1: + value64 = da2->bitblt.payload[9]; + value64 <<= 8; + value64 |= da2->bitblt.payload[8]; + value64 <<= 8; + value64 |= da2->bitblt.payload[7]; + value64 <<= 8; + value64 |= da2->bitblt.payload[6]; + value64 <<= 8; + value64 |= da2->bitblt.payload[5]; + value64 <<= 8; + value64 |= da2->bitblt.payload[4]; + value64 <<= 8; + value64 |= da2->bitblt.payload[3]; + value64 <<= 8; + value64 |= da2->bitblt.payload[2]; + da2_bltreglog("[%02x] %02x: %02x %02x %02x %02x %02x %02x %02x %02x\n", da2->bitblt.payload[0], da2->bitblt.payload[1], da2->bitblt.payload[2], da2->bitblt.payload[3], + da2->bitblt.payload[4], da2->bitblt.payload[5], da2->bitblt.payload[6], da2->bitblt.payload[7], da2->bitblt.payload[8], da2->bitblt.payload[9]); + da2->bitblt.reg[da2->bitblt.payload[1]] = value64; + break; + case 0x00: /* Win 3.0 Clock writes invalid zero data. */ + break; + default: + da2_log("bltload: Unknown PreOP!\n"); + break; + } + if (da2->bitblt.reg[0x20] & 0x01) { /* Execute Bitblt immediately (for OS/2 J1.3) */ + da2->bitblt.exec = DA2_BLT_CLOAD; + da2_bitblt_exec(da2); + } + /* clear payload memory */ + memset(da2->bitblt.payload, 0x00, DA2_BLT_MEMSIZE); + da2->bitblt.payload_addr = 0; + da2->bitblt.indata = 0; +} + +static void +da2_bitblt_load(da2_t *da2) +{ + da2->bitblt.reg[0x20] = 0; /* need to stop execution */ +#ifdef ENABLE_DA2_DEBUGBLT + for (int i = 0; i < DA2_DEBUG_BLTLOG_SIZE; i++) { + da2->bitblt.debug_reg[DA2_DEBUG_BLTLOG_SIZE * da2->bitblt.debug_reg_ip + i] = da2->bitblt.reg[i]; + } + da2->bitblt.debug_reg[DA2_DEBUG_BLTLOG_SIZE * (da2->bitblt.debug_reg_ip + 1) - 1] = 0; + da2->bitblt.debug_reg_ip++; + if ((DA2_DEBUG_BLTLOG_SIZE * da2->bitblt.debug_reg_ip) >= DA2_DEBUG_BLTLOG_MAX) + da2->bitblt.debug_reg_ip = 0; + da2->bitblt.debug_exesteps = 0; +#endif + da2->bitblt.bitshift_destr = ((da2->bitblt.reg[0x03] >> 4) & 0x0f); /* set bit shift */ + da2->bitblt.raster_op = da2->bitblt.reg[0x0b]; + da2->bitblt.destaddr = da2->bitblt.reg[0x29]; + da2->bitblt.size_x = da2->bitblt.reg[0x33]; + da2->bitblt.size_y = da2->bitblt.reg[0x35]; + da2->bitblt.destpitch = da2->bitblt.reg[0x21]; + da2->bitblt.srcpitch = da2->bitblt.reg[0x22]; + /* + DOS/V Extension 1040x725 some DBCS uses 0xB0 others 0x90 + */ + da2->bitblt.destoption = da2->bitblt.reg[0x2F]; + if (da2->bitblt.destoption & 0x10) { /* destaddr -= 2, length += 1; */ + da2->bitblt.destaddr -= 2; + da2->bitblt.size_x += 1; + da2->bitblt.destpitch -= 2; + da2->bitblt.srcpitch -= 2; + } + da2->bitblt.fcolor = da2->bitblt.reg[0x0]; + da2->bitblt.maskl = da2->bitblt.reg[0x8]; + da2->bitblt.maskr = da2->bitblt.reg[0x9]; + da2->bitblt.x = 0; + da2->bitblt.y = 0; + da2->bitblt.exec = DA2_BLT_CDONE; + + /* Put DBCS char used by OS/2 and DOS/V Extension */ + if (!(da2->bitblt.reg[0xb] & 0x08)) { + da2->bitblt.exec = DA2_BLT_CPUTCHAR; + da2->bitblt.fcolor = da2->bitblt.reg[0x1]; + da2->bitblt.srcaddr = da2->bitblt.reg[0x12]; + da2->bitblt.destaddr += 2; +#ifdef ENABLE_DA2_DEBUGBLT + uint8_t sjis_h = IBMJtoSJIS(da2->bitblt.reg[0x12]) >> 8; + uint8_t sjis_l = IBMJtoSJIS(da2->bitblt.reg[0x12]) & 0xff; + if (da2->bitblt.reg[0x12] < 0x100) { + sjis_h = 0x20; + sjis_l = da2->bitblt.reg[0x12]; + } else { + if (!(isKanji1(sjis_h))) + sjis_h = 0x3f; + if (!(isKanji2(sjis_l))) + sjis_l = 0x3f; + } + da2_log("put char src=%x, dest=%x, x=%d, y=%d, w=%d, h=%d, c=%c%c\n", + da2->bitblt.srcaddr, da2->bitblt.destaddr, + da2->bitblt.reg[0x29] % (da2->rowoffset * 2), da2->bitblt.reg[0x29] / (da2->rowoffset * 2), + da2->bitblt.size_x, da2->bitblt.size_y, sjis_h, sjis_l); +#else + da2_log("put char src=%x, dest=%x, x=%d, y=%d, w=%d, h=%d\n", + da2->bitblt.srcaddr, da2->bitblt.destaddr, + da2->bitblt.reg[0x29] % (da2->rowoffset * 2), da2->bitblt.reg[0x29] / (da2->rowoffset * 2), + da2->bitblt.size_x, da2->bitblt.size_y); +#endif + + /* Draw a line */ + } else if (da2->bitblt.reg[0x5] == 0x43) { + da2->bitblt.exec = DA2_BLT_CLINE; + da2->bitblt.dest_x = (da2->bitblt.reg[0x32] & 0xffff); + da2->bitblt.dest_y = (da2->bitblt.reg[0x34] & 0xffff); + da2->bitblt.wx1 = (da2->bitblt.reg[0x32]) >> 16; + da2->bitblt.wx2 = (da2->bitblt.reg[0x33]) >> 16; + da2->bitblt.wy1 = (da2->bitblt.reg[0x34]) >> 16; + da2->bitblt.wy2 = (da2->bitblt.reg[0x35]) >> 16; + da2->bitblt.size_x = abs((int16_t) (da2->bitblt.reg[0x33] & 0xffff) - da2->bitblt.dest_x); + da2->bitblt.size_y = abs((int16_t) (da2->bitblt.reg[0x35] & 0xffff) - da2->bitblt.dest_y); + da2->bitblt.count = 0; + da2->bitblt.octdir = da2->bitblt.reg[0x2D]; + da2->bitblt.bitshift_destr = 0; + if (da2->bitblt.octdir & 0x04) /* dX > dY */ + da2->bitblt.d = 2 * da2->bitblt.size_y - da2->bitblt.size_x; + else + da2->bitblt.d = 2 * da2->bitblt.size_x - da2->bitblt.size_y; + da2->bitblt.x = da2->bitblt.dest_x; + da2->bitblt.y = da2->bitblt.dest_y; + da2_log("drawline x=%d, y=%d, dx=%d, dy=%d, oct=%dn", + da2->bitblt.dest_x, da2->bitblt.dest_y, + da2->bitblt.size_x, da2->bitblt.size_y, da2->bitblt.octdir); + da2_log(" x1=%d, x2=%d, y1=%d, y2=%d\n", + da2->bitblt.reg[0x32] & 0x7ff, da2->bitblt.reg[0x33] & 0x7ff, + da2->bitblt.reg[0x34] & 0x7ff, da2->bitblt.reg[0x35] & 0x7ff); + da2_log(" ux1=%d,ux2=%d,uy1=%d,uy2=%d\n", + (da2->bitblt.reg[0x32] >> 16) & 0x7ff, (da2->bitblt.reg[0x33] >> 16) & 0x7ff, + (da2->bitblt.reg[0x34] >> 16) & 0x7ff, (da2->bitblt.reg[0x35] >> 16) & 0x7ff); + + /* Fill a rectangle (or draw a horizontal / vertical line) */ + } else if ((da2->bitblt.reg[0x5] & 0xfff0) == 0x40 && da2->bitblt.reg[0x3D] == 0) { + da2_log("fillrect x=%d, y=%d, w=%d, h=%d, c=%d, 2f=%x, rowcount=%x\n", + da2->bitblt.reg[0x29] % (da2->rowoffset * 2), da2->bitblt.reg[0x29] / (da2->rowoffset * 2), + da2->bitblt.size_x, da2->bitblt.size_y, da2->bitblt.reg[0x0], da2->bitblt.reg[0x2F], da2->rowoffset * 2); + da2->bitblt.exec = DA2_BLT_CFILLRECT; + da2->bitblt.destaddr += 2; + + /* Tiling a rectangle ??(transfer tile data multiple times) os/2 only */ + } else if ((da2->bitblt.reg[0x5] & 0xfff0) == 0x0040 && da2->bitblt.reg[0x3D] == 0x40) { + da2->bitblt.exec = DA2_BLT_CFILLTILE; + da2->bitblt.destaddr += 2; + da2->bitblt.srcaddr = da2->bitblt.reg[0x2B]; + da2->bitblt.tile_w = da2->bitblt.reg[0x28]; + da2_log("copy tile src=%x, dest=%x, x1=%d, y1=%d, x2=%d, y2=%d, w=%d, h=%d\n", + da2->bitblt.srcaddr, da2->bitblt.destaddr, + da2->bitblt.reg[0x2B] % (da2->rowoffset * 2), da2->bitblt.reg[0x2B] / (da2->rowoffset * 2), + da2->bitblt.reg[0x29] % (da2->rowoffset * 2), da2->bitblt.reg[0x29] / (da2->rowoffset * 2), + da2->bitblt.size_x, da2->bitblt.size_y); + + /* Tiling a rectangle (transfer tile data multiple times) */ + } else if ((da2->bitblt.reg[0x5] & 0xfff0) == 0x1040 && da2->bitblt.reg[0x3D] == 0x40) { + da2->bitblt.exec = DA2_BLT_CFILLTILE; + da2->bitblt.destaddr += 2; + da2->bitblt.srcaddr = da2->bitblt.reg[0x2B]; + da2->bitblt.tile_w = da2->bitblt.reg[0x28]; + da2_log("copy tile src=%x, dest=%x, x1=%d, y1=%d, x2=%d, y2=%d, w=%d, h=%d\n", + da2->bitblt.srcaddr, da2->bitblt.destaddr, + da2->bitblt.reg[0x2B] % (da2->rowoffset * 2), da2->bitblt.reg[0x2B] / (da2->rowoffset * 2), + da2->bitblt.reg[0x29] % (da2->rowoffset * 2), da2->bitblt.reg[0x29] / (da2->rowoffset * 2), + da2->bitblt.size_x, da2->bitblt.size_y); + + /* Block copy */ + } else if ((da2->bitblt.reg[0x5] & 0xfff0) == 0x1040 && da2->bitblt.reg[0x3D] == 0x00) { + da2->bitblt.exec = DA2_BLT_CCOPYF; + da2->bitblt.srcaddr = da2->bitblt.reg[0x2A]; + da2->bitblt.destaddr += 2; + da2_log("copy block src=%x, dest=%x, x1=%d, y1=%d, x2=%d, y2=%d, w=%d, h=%d\n", + da2->bitblt.srcaddr, da2->bitblt.destaddr, + da2->bitblt.reg[0x2A] % (da2->rowoffset * 2), da2->bitblt.reg[0x2A] / (da2->rowoffset * 2), + da2->bitblt.reg[0x29] % (da2->rowoffset * 2), da2->bitblt.reg[0x29] / (da2->rowoffset * 2), + da2->bitblt.size_x, da2->bitblt.size_y); + + /* Block copy but reversed direction */ + } else if ((da2->bitblt.reg[0x5] & 0xfff0) == 0x1140 && da2->bitblt.reg[0x3D] == 0x00) { + da2->bitblt.exec = DA2_BLT_CCOPYR; + da2->bitblt.srcaddr = da2->bitblt.reg[0x2A]; + da2->bitblt.destaddr -= 2; + da2->bitblt.srcaddr -= 2; + da2_log("copy blockR src=%x, dest=%x, x1=%d, y1=%d, x2=%d, y2=%d, w=%d, h=%d\n", + da2->bitblt.srcaddr, da2->bitblt.destaddr, + da2->bitblt.reg[0x2A] % (da2->rowoffset * 2), da2->bitblt.reg[0x2A] / (da2->rowoffset * 2), + da2->bitblt.reg[0x29] % (da2->rowoffset * 2), da2->bitblt.reg[0x29] / (da2->rowoffset * 2), + da2->bitblt.size_x, da2->bitblt.size_y); + } +} +static void +da2_bitblt_exec(void *priv) +{ + da2_t *da2 = (da2_t *) priv; + // timer_set_delay_u64(&da2->bitblt.timer, da2->bitblt.timerspeed); +#ifdef ENABLE_DA2_DEBUGBLT_DETAIL + if (!(da2->bitblt.debug_exesteps & 0xff)) + da2_log("bitblt_exec: %d %d\n", da2->bitblt.exec, da2->bitblt.debug_exesteps); + da2->bitblt.debug_exesteps++; +#else + da2_log("bltload_exec: %x, CS:PC=%4x:%4x\n", da2->bitblt.exec, CS, cpu_state.pc); +#endif + switch (da2->bitblt.exec) { + case DA2_BLT_CIDLE: + // timer_disable(&da2->bitblt.timer); + break; + case DA2_BLT_CLOAD: + da2_bitblt_load(da2); + // da2->bitblt.indata = 0; + break; + case DA2_BLT_CLINE: + { + /* Draw a dot */ + da2_bltlog("point: %d %d %d %d %d\n", da2->bitblt.x, da2->bitblt.y, da2->bitblt.d, da2->bitblt.x, da2->bitblt.y); + int destaddr = da2->bitblt.y * (da2->rowoffset * 2) + da2->bitblt.x / 8; + int pixelmask = da2->bitblt.x % 16; + if (pixelmask >= 8) + pixelmask = (0x8000 >> (pixelmask - 8)); + else + pixelmask = (0x80 >> pixelmask); + + /* check the current position is inside the window */ + if (da2->bitblt.x < da2->bitblt.wx1 || da2->bitblt.x > da2->bitblt.wx2 + || da2->bitblt.y < da2->bitblt.wy1 || da2->bitblt.y > da2->bitblt.wy2) + ; + else + da2_DrawColorWithBitmask(destaddr, da2->bitblt.fcolor, pixelmask, da2); + da2->bitblt.count++; + + /* calculate the next position with Bresenham's line algorithm */ + if (da2->bitblt.octdir & 0x04) { /* dX > dY */ + if (da2->bitblt.octdir & 0x02) { + da2->bitblt.x++; + } else { + da2->bitblt.x--; + } + if (da2->bitblt.d >= 0) { + da2->bitblt.d -= (2 * da2->bitblt.size_x); + if (da2->bitblt.octdir & 0x01) { + da2->bitblt.y++; + } else { + da2->bitblt.y--; + } + } + da2->bitblt.d += (2 * da2->bitblt.size_y); + if (da2->bitblt.count >= da2->bitblt.size_x) + da2->bitblt.exec = DA2_BLT_CDONE; + } else { + if (da2->bitblt.octdir & 0x01) { + da2->bitblt.y++; + } else { + da2->bitblt.y--; + } + if (da2->bitblt.d >= 0) { + da2->bitblt.d -= (2 * da2->bitblt.size_y); + if (da2->bitblt.octdir & 0x02) { + da2->bitblt.x++; + } else { + da2->bitblt.x--; + } + } + da2->bitblt.d += (2 * da2->bitblt.size_x); + if (da2->bitblt.count >= da2->bitblt.size_y) + da2->bitblt.exec = DA2_BLT_CDONE; + } + break; + } + case DA2_BLT_CFILLRECT: + // da2_log("%x %x %x\n", da2->bitblt.destaddr, da2->bitblt.x, da2->bitblt.y); + if (da2->bitblt.x >= da2->bitblt.size_x - 1) { + da2_DrawColorWithBitmask(da2->bitblt.destaddr, da2->bitblt.fcolor, da2->bitblt.maskr, da2); + if (da2->bitblt.y >= da2->bitblt.size_y - 1) { + da2->bitblt.exec = DA2_BLT_CDONE; + } + da2->bitblt.x = 0; + da2->bitblt.y++; + da2->bitblt.destaddr += da2->bitblt.destpitch + 2; + } else if (da2->bitblt.x == 0) { + da2_DrawColorWithBitmask(da2->bitblt.destaddr, da2->bitblt.fcolor, da2->bitblt.maskl, da2); + da2->bitblt.x++; + } else { + da2_DrawColorWithBitmask(da2->bitblt.destaddr, da2->bitblt.fcolor, 0xffff, da2); + da2->bitblt.x++; + } + da2->bitblt.destaddr += 2; + break; + case DA2_BLT_CFILLTILE: + { + int32_t tileaddr = da2->bitblt.srcaddr + (da2->bitblt.y % da2->bitblt.tile_w) * 2; + if (da2->bitblt.x >= da2->bitblt.size_x - 1) { + da2_CopyPlaneDataWithBitmask(tileaddr, da2->bitblt.destaddr, da2->bitblt.maskr, da2); + if (da2->bitblt.y >= da2->bitblt.size_y - 1) { + da2->bitblt.exec = DA2_BLT_CDONE; + } + da2->bitblt.x = 0; + da2->bitblt.y++; + da2->bitblt.destaddr += da2->bitblt.destpitch + 2; + } else if (da2->bitblt.x == 0) { + da2_CopyPlaneDataWithBitmask(tileaddr, da2->bitblt.destaddr, da2->bitblt.maskl, da2); + da2->bitblt.x++; + } else { + da2_CopyPlaneDataWithBitmask(tileaddr, da2->bitblt.destaddr, 0xffff, da2); + da2->bitblt.x++; + } + da2->bitblt.destaddr += 2; + break; + } + case DA2_BLT_CCOPYF: + if (da2->bitblt.x >= da2->bitblt.size_x - 1) { + da2_CopyPlaneDataWithBitmask(da2->bitblt.srcaddr, da2->bitblt.destaddr, da2->bitblt.maskr, da2); + if (da2->bitblt.y >= da2->bitblt.size_y - 1) { + da2->bitblt.exec = DA2_BLT_CDONE; + } + da2->bitblt.x = 0; + da2->bitblt.y++; + da2->bitblt.destaddr += da2->bitblt.destpitch + 2; + da2->bitblt.srcaddr += da2->bitblt.srcpitch + 2; + } else if (da2->bitblt.x == 0) { + da2_CopyPlaneDataWithBitmask(da2->bitblt.srcaddr, da2->bitblt.destaddr, da2->bitblt.maskl, da2); + da2->bitblt.x++; + } else { + da2_CopyPlaneDataWithBitmask(da2->bitblt.srcaddr, da2->bitblt.destaddr, 0xffff, da2); + da2->bitblt.x++; + } + da2->bitblt.destaddr += 2; + da2->bitblt.srcaddr += 2; + break; + case DA2_BLT_CCOPYR: + if (da2->bitblt.x >= da2->bitblt.size_x - 1) { + da2_CopyPlaneDataWithBitmask(da2->bitblt.srcaddr, da2->bitblt.destaddr, da2->bitblt.maskr, da2); + if (da2->bitblt.y >= da2->bitblt.size_y - 1) { + da2->bitblt.exec = DA2_BLT_CDONE; + } + da2->bitblt.x = 0; + da2->bitblt.y++; + da2->bitblt.destaddr -= da2->bitblt.destpitch; + da2->bitblt.srcaddr -= da2->bitblt.srcpitch; + da2->bitblt.destaddr -= 2; + da2->bitblt.srcaddr -= 2; + } else if (da2->bitblt.x == 0) { + da2_CopyPlaneDataWithBitmask(da2->bitblt.srcaddr, da2->bitblt.destaddr, da2->bitblt.maskl, da2); + da2->bitblt.x++; + } else { + da2_CopyPlaneDataWithBitmask(da2->bitblt.srcaddr, da2->bitblt.destaddr, 0xffff, da2); + da2->bitblt.x++; + } + da2->bitblt.destaddr -= 2; + da2->bitblt.srcaddr -= 2; + break; + case DA2_BLT_CPUTCHAR: /* used in OS/2 J1.3 wo ROM patch. TODO: still not work */ + // pclog("scr %x dest %x x %x y %x\n", da2->bitblt.srcaddr, da2->bitblt.destaddr, da2->bitblt.x, da2->bitblt.y); + if (da2->bitblt.y >= da2->bitblt.size_y) { + da2->bitblt.exec = DA2_BLT_CDONE; + } else { + da2_PutcharWithBitmask(da2->bitblt.srcaddr, da2->bitblt.size_x, da2->bitblt.fcolor, da2->bitblt.y, da2->bitblt.destaddr, da2->bitblt.maskl, da2->bitblt.maskr, da2); + } + da2->bitblt.y++; + da2->bitblt.destaddr += da2->bitblt.size_x * 2 + da2->bitblt.destpitch + 2; + break; + case DA2_BLT_CDONE: + // if (!(da2->bitblt.reg[0x20] & 0x20)) { + // /* initialize regs and set magic value for debug dump */ + // for (int i = 0; i < DA2_BLT_REGSIZE; i++) { + // if (da2->bitblt.reg[i] != DA2_DEBUG_BLT_NEVERUSED) + // da2->bitblt.reg[i] = DA2_DEBUG_BLT_USEDRESET; + // } + // } else /* without init regs */ + // if (da2->bitblt.indata) + // da2->bitblt.exec = DA2_BLT_CLOAD; + // else + da2->bitblt.exec = DA2_BLT_CIDLE; + break; + } +} +static void +da2_bitblt_dopayload(void *priv) +{ + da2_t *da2 = (da2_t *) priv; + timer_set_delay_u64(&da2->bitblt.timer, da2->bitblt.timerspeed); + /* do async operation but it causes the scrolling text glitch in OS/2 J1.3 Command Prompt (TODO) */ + if (da2->bitblt.exec != DA2_BLT_CIDLE) { + while (da2->bitblt.exec != DA2_BLT_CIDLE) /* this disables async operation */ + da2_bitblt_exec(da2); + } else if ((da2->bitblt.reg[0x20] & 0x01) && (da2->bitblt.exec == DA2_BLT_CIDLE)) { + da2->bitblt.exec = DA2_BLT_CLOAD; + da2_bitblt_exec(da2); + } else { + // timer_disable(&da2->bitblt.timer); + } +} +static void +da2_bitblt_addpayload(uint8_t val, void *priv) +{ + da2_t *da2 = (da2_t *) priv; + da2->bitblt.indata = 1; + if (da2->bitblt.payload_addr >= DA2_BLT_MEMSIZE) + da2_log("da2_mmio_write payload overflow! addr %x, val %x\n", da2->bitblt.payload_addr, val); + else { + if (da2->bitblt.payload_addr == 0) { + da2->bitblt.payload[da2->bitblt.payload_addr] = val; + da2->bitblt.payload_addr++; + switch (val) { + case 0x88: + case 0x89: + case 0x95: + da2->bitblt.payload_opsize = 3; + break; + case 0x91: + da2->bitblt.payload_opsize = 5; + break; + case 0x99: + da2->bitblt.payload_opsize = 7; + break; + case 0xa1: + da2->bitblt.payload_opsize = 9; + break; + default: + da2_log("addpayload: Unknown PreOP! %x\n", val); + da2->bitblt.payload_addr = 0; /* ignore input */ + break; + } + } else if (da2->bitblt.payload_addr < da2->bitblt.payload_opsize) { + da2->bitblt.payload[da2->bitblt.payload_addr] = val; + da2->bitblt.payload_addr++; + } else if (da2->bitblt.payload_addr == da2->bitblt.payload_opsize) { + da2->bitblt.payload[da2->bitblt.payload_addr] = val; + da2->bitblt.payload_opsize = 0; /* reset */ + da2_bitblt_parse(da2); + } + } +} + +static void +da2_out(uint16_t addr, uint16_t val, void *priv) +{ + da2_t *da2 = (da2_t *) priv; + int oldval; + /* + 3E0 3E1 Sequencer Registers (undoc) + 3E2 3E3 Font Registers (undoc) + 3E4 3E5 CRT Control Registers (undoc) + 3E8 3E9 Attribute Controller Registers (undoc) + 3EA 3EB 3EC Graphics Contoller Registers + */ + switch (addr) { + case 0x3c6: /* PEL Mask */ + da2->dac_mask = val; + break; + case 0x3C7: /* Read Address */ + da2->dac_read = val; + da2->dac_pos = 0; + break; + case 0x3C8: /* Write Address */ + da2->dac_write = val; + da2->dac_read = val - 1; + da2->dac_pos = 0; + break; + case 0x3C9: /* Data */ + // da2_iolog("DA2 Out addr %03X idx %d:%d val %02X %04X:%04X esdi %04X:%04X\n", addr, da2->dac_write, da2->dac_pos, val, cs >> 4, cpu_state.pc, ES, DI); + da2->dac_status = 0; + da2->fullchange = changeframecount; + switch (da2->dac_pos) { + case 0: + da2->dac_r = val; + da2->dac_pos++; + break; + case 1: + da2->dac_g = val; + da2->dac_pos++; + break; + case 2: + da2->vgapal[da2->dac_write].r = da2->dac_r; + da2->vgapal[da2->dac_write].g = da2->dac_g; + da2->vgapal[da2->dac_write].b = val; + // if (da2->ramdac_type == RAMDAC_8BIT) + // da2->pallook[da2->dac_write] = makecol32(da2->vgapal[da2->dac_write].r, da2->vgapal[da2->dac_write].g, da2->vgapal[da2->dac_write].b); + // else + da2->pallook[da2->dac_write] = makecol32((da2->vgapal[da2->dac_write].r & 0x3f) * 4, (da2->vgapal[da2->dac_write].g & 0x3f) * 4, (da2->vgapal[da2->dac_write].b & 0x3f) * 4); + da2->dac_pos = 0; + da2->dac_write = (da2->dac_write + 1) & 255; + break; + } + break; + case LS_INDEX: + da2->ioctladdr = val; + break; + case LS_DATA: + // da2_iolog("DA2 Out addr %03X idx %02X val %02X %04X:%04X\n", addr, da2->ioctladdr, val, cs >> 4, cpu_state.pc); + if (da2->ioctladdr > 0xf) + return; + if (da2->ioctl[da2->ioctladdr & 15] != val) + da2_iolog("ioctl changed %x: %x -> %x %04X:%04X\n", da2->ioctladdr & 15, da2->ioctl[da2->ioctladdr & 15], val, cs >> 4, cpu_state.pc); + oldval = da2->ioctl[da2->ioctladdr]; + da2->ioctl[da2->ioctladdr] = val; + if (oldval != val) { + if (da2->ioctladdr == LS_RESET && val & 0x01) /* Reset register */ + da2_reset_ioctl(da2); + else if (da2->ioctladdr == LS_MODE && ((oldval ^ val) & 0x03)) { /* Mode register */ + da2->fullchange = changeframecount; + da2_recalctimings(da2); + da2_updatevidselector(da2); + } + } + break; + case LF_INDEX: + da2->fctladdr = val; + break; + case LF_DATA: + // da2_iolog("DA2 Out addr %03X idx %02X val %02X %04X:%04X\n", addr, da2->fctladdr, val, cs >> 4, cpu_state.pc); + if (da2->fctladdr > 0x1f) + return; + if (da2->fctl[da2->fctladdr & 0x1f] != val) + da2_iolog("fctl changed %x: %x -> %x %04X:%04X\n", da2->fctladdr & 0x1f, da2->fctl[da2->fctladdr & 0x1f], val, cs >> 4, cpu_state.pc); + oldval = da2->fctl[da2->fctladdr]; + da2->fctl[da2->fctladdr] = val; + if (da2->fctladdr == 0 && oldval != val) { + da2_iolog("DA2 Out FCTL addr %03X idx %02X val %02X %04X:%04X\n", addr, da2->fctladdr, val, cs >> 4, cpu_state.pc); + } else if ((da2->fctladdr == LF_PD_RESET) && ((val & 0x7) == 7)) { + /* Reset Bitblt busy */ + da2->bitblt.indata = 0; + da2->bitblt.exec = DA2_BLT_CIDLE; + } + break; + case LC_INDEX: + da2->crtcaddr = val; + break; + case LC_DATA: + if (da2->crtcaddr > 0x1f) + return; + if (!(da2->crtcaddr == LC_CURSOR_LOC_HIGH || da2->crtcaddr == LC_CURSOR_LOC_LOWJ)) + da2_iolog("DA2 Out addr %03X idx %02X val %02X %04X:%04X\n", addr, da2->crtcaddr, val, cs >> 4, cpu_state.pc); + if (!(da2->crtc[da2->crtcaddr] ^ val)) + return; + switch (da2->crtcaddr) { + case LC_CRTC_OVERFLOW: + // return; + break; + case LC_MAXIMUM_SCAN_LINE: + if (!(da2->ioctl[LS_MODE] & 0x01)) /* 16 or 256 color graphics mode */ + val = 0; + break; + case LC_VERTICAL_TOTALJ: /* Vertical Total */ + case LC_VERTICAL_SYNC_START: /* Vertical Retrace Start Register */ + case LC_V_DISPLAY_ENABLE_END: /* Vertical Display End Register */ + case LC_START_VERTICAL_BLANK: /* Start Vertical Blank Register */ +#ifdef ENABLE_DA2_DEBUGFULLSCREEN + val = 0x400; /* for debugging bitblt in Win 3.x */ +#endif + break; + } + da2->crtc[da2->crtcaddr] = val; + switch (da2->crtcaddr) { + // case LC_START_ADDRESS_HIGH: + // case LC_START_ADDRESS_LOW: + /* The DOS J4.0 MODE 4 command and OS/2 driver write 0xFF00. + OS/2 DOS MODE 1 setup reads this to set the base line, but it causes the screen glitch. */ + // outb(0x680, da2->crtc[LC_START_ADDRESS_LOW]); + // outb(0x680, da2->crtc[LC_START_ADDRESS_HIGH]); + // break; + case LC_VIEWPORT_SELECT: + /* backup some current crtc regs */ + for (int i = LC_START_ADDRESS_HIGH; i <= LC_START_ADDRESS_LOW; i++) { + da2->crtc_vpreg[(da2->crtc_vpsel * 0x20) + i] = da2->crtc[i]; + } + da2->crtc_vpsel = (val >> 6) & 3; + /* restore crtc regs */ + for (int i = LC_START_ADDRESS_HIGH; i <= LC_START_ADDRESS_LOW; i++) { + da2->crtc[i] = da2->crtc_vpreg[(da2->crtc_vpsel * 0x20) + i]; + } + break; + default: + break; + } + switch (da2->crtcaddr) { + case LC_H_DISPLAY_ENABLE_END: + case LC_VERTICAL_TOTALJ: + case LC_MAXIMUM_SCAN_LINE: + case LC_START_ADDRESS_HIGH: + case LC_START_ADDRESS_LOW: + case LC_VERTICAL_SYNC_START: + case LC_V_DISPLAY_ENABLE_END: + case LC_START_VERTICAL_BLANK: + case LC_LINE_COMPAREJ: + case LC_START_H_DISPLAY_ENAB: + case LC_START_V_DISPLAY_ENAB: + case LC_VIEWPORT_SELECT: + case LC_VIEWPORT_PRIORITY: + da2->fullchange = changeframecount; + da2_recalctimings(da2); + break; + default: + break; + } + break; + case LV_PORT: + // da2_iolog("DA2 Out addr %03X val %02X ff %d %04X:%04X\n", addr, val, da2->attrff,cs >> 4, cpu_state.pc); + if (!da2->attrff) { + da2->attraddr = val & 0x3f; + if ((val & 0x20) != (da2->attr_palette_enable & 0x20)) { + da2->fullchange = 3; + da2->attr_palette_enable = val & 0x20; + da2_recalctimings(da2); + } + // da2_iolog("set attraddr: %X\n", da2->attraddr); + } else { + if ((da2->attraddr == LV_PANNING) && (da2->attrc[LV_PANNING] != val)) + da2->fullchange = changeframecount; + if (da2->attrc[da2->attraddr & 0x3f] != val) + da2_iolog("attr changed %x: %x -> %x\n", da2->attraddr & 0x3f, da2->attrc[da2->attraddr & 0x3f], val); + da2->attrc[da2->attraddr & 0x3f] = val; + // da2_iolog("set attrc %x: %x\n", da2->attraddr & 31, val); + if (da2->attraddr < 16) + da2->fullchange = changeframecount; + if (da2->attraddr == LV_MODE_CONTROL || da2->attraddr < 0x10) { + for (uint8_t c = 0; c < 16; c++) { + // if (da2->attrc[LV_MODE_CONTROL] & 0x80) da2->egapal[c] = (da2->attrc[c] & 0xf) | ((da2->attrc[0x14] & 0xf) << 4); + // else da2->egapal[c] = (da2->attrc[c] & 0x3f) | ((da2->attrc[0x14] & 0xc) << 4); + if (da2->attrc[LV_MODE_CONTROL] & 0x80) + da2->egapal[c] = da2->attrc[c] & 0xf; + else + da2->egapal[c] = da2->attrc[c] & 0x3f; + } + } + switch (da2->attraddr) { + case LV_COLOR_PLANE_ENAB: + if ((val & 0xff) != da2->plane_mask) + da2->fullchange = changeframecount; + da2->plane_mask = val & 0xff; + break; + case LV_CURSOR_CONTROL: + switch (val & 0x18) { + case 0x08: /* fast blink */ + da2->blinkconf = 0x10; + break; + case 0x18: /* slow blink */ + da2->blinkconf = 0x20; + break; + default: /* no blink */ + da2->blinkconf = 0xff; + break; + } + break; + case LV_MODE_CONTROL: + case LV_ATTRIBUTE_CNTL: + case LV_COMPATIBILITY: + da2_recalctimings(da2); + break; + default: + break; + } + } + da2->attrff ^= 1; + break; + case 0x3E9: + /* VZ Editor's CURSOR.COM writes data via this port */ + da2->attrc[da2->attraddr & 0x3f] = val; + break; + case LG_INDEX: + da2_iolog("DA2 Out addr %03X val %02X\n", addr, val); + da2->gdcaddr = val; + break; + case LG_DATA: + // if(da2->gdcaddr != 8 && da2->gdcaddr != 9) da2_iolog("DA2 GCOut idx %X val %02X %04X:%04X esdi %04X:%04X\n", da2->gdcaddr, val, cs >> 4, cpu_state.pc, ES, DI); + da2_iolog("DA2 Out addr %03X idx %02X val %02X\n", addr, da2->gdcaddr, val); + da2->gdcreg[da2->gdcaddr & 0x0f] = val & 0xff; + switch (da2->gdcaddr & 0x1f) { + case LG_READ_MAP_SELECT: + da2->readplane = val & 0x7; + break; + case LG_MODE: + da2->writemode = val & 3; + /* Resettting masks here gliches chart drawing in IBM Multitool Chart K3.1 */ + // da2->gdcreg[LG_BIT_MASK_LOW] = 0xff; + // da2->gdcreg[LG_BIT_MASK_HIGH] = 0xff; + // da2->planemask = 0xff; + // da2->gdcreg[LG_MAP_MASKJ] = 0xff; + break; + case LG_MAP_MASKJ: + da2->planemask = val & 0xff; + break; + case LG_COMMAND: + break; + case LG_SET_RESET_2: + da2_iolog("!!!DA2 GC Out addr %03X idx 10 val %02X\n", addr, val); + return; + } + break; + // case 0x3ed: /* used by Windows 3.1 display driver */ + // da2->gdcreg[5] = val & 0xff; + // break; + default: + da2_iolog("DA2? Out addr %03X val %02X\n", addr, val); + break; + } +} + +static uint16_t +da2_in(uint16_t addr, void *priv) +{ + da2_t *da2 = (da2_t *) priv; + uint16_t temp = 0xff; + + switch (addr) { + case 0x3c3: + temp = 0; + break; + case 0x3c6: + temp = da2->dac_mask; + break; + case 0x3c7: + temp = da2->dac_status; + break; + case 0x3c8: + temp = da2->dac_write; + break; + case 0x3c9: + da2->dac_status = 3; + switch (da2->dac_pos) { + case 0: + da2->dac_pos++; + temp = da2->vgapal[da2->dac_read].r & 0x3f; + break; + case 1: + da2->dac_pos++; + temp = da2->vgapal[da2->dac_read].g & 0x3f; + break; + case 2: + da2->dac_pos = 0; + da2->dac_read = (da2->dac_read + 1) & 255; + temp = da2->vgapal[(da2->dac_read - 1) & 255].b & 0x3f; + break; + } + break; + case LS_INDEX: + temp = da2->ioctladdr; + break; + case LS_DATA: + // da2->ioctl[3] = 0x80; /* 3E1h:3 bit 7 color monitor, bit 3 busy(GC) bit 0 busy (IO?) */ + if (da2->ioctladdr > 0xf) + return DA2_INVALIDACCESS16; + temp = da2->ioctl[da2->ioctladdr]; + if (da2->ioctladdr == LS_STATUS) { /* Status register */ + if (da2->attrc[LV_COMPATIBILITY] & 0x08) { /* for detecting monitor type and cable wiring */ + if (da2->monitorid == DA2_DCONFIG_MONTYPE_MONO) { + /* grayscale monitor */ + if ((da2->vgapal[0].r >= 10) || (da2->vgapal[0].g >= 40) || (da2->vgapal[0].b >= 10)) + temp &= 0x7F; /* Inactive when the RGB output voltage is high (or the cable is not connected to a color monitor). */ + else + temp |= 0x80; /* Active when the RGB output voltage is low and the cable is connected to a color monitor. + If the cable or the monitor is wrong, it becomes inactive. */ + } else { + /* color monitor */ + if ((da2->vgapal[0].r + da2->vgapal[0].g + da2->vgapal[0].b) >= 80) + temp &= 0x7F; + else + temp |= 0x80; + } + } else { + temp |= 0x80; + } + temp &= 0xf6; /* clear busy bit */ + // if (da2->bitblt.indata) /* for OS/2 J1.3 command prompt scrolling */ + // da2_bitblt_dopayload(da2); + if (da2->bitblt.exec != DA2_BLT_CIDLE) { + temp |= 0x09; /* wait (bit 3 + bit 0) ? need verify */ + } + // if (da2->bitblt.indata) temp |= 0x08; +#ifdef ENABLE_DA2_DEBUGMONWAIT + da2_iolog("DA2 In %04X(%02X) %04X %04X:%04X\n", addr, da2->ioctladdr, temp, cs >> 4, cpu_state.pc); +#endif + } + break; + case LF_INDEX: + temp = da2->fctladdr; + break; + case LF_DATA: + if (da2->fctladdr > 0x1f) + return DA2_INVALIDACCESS16; + temp = da2->fctl[da2->fctladdr]; + break; + case LC_INDEX: + temp = da2->crtcaddr; + break; + case LC_DATA: + if (da2->crtcaddr > 0x1f) + return DA2_INVALIDACCESS16; + temp = da2->crtc[da2->crtcaddr]; + break; + case LV_PORT: + temp = da2->attraddr | da2->attr_palette_enable; + break; + case 0x3E9: + if (da2->attraddr == LV_RAS_STATUS_VIDEO) /* this maybe equivalent to 3ba / 3da ISR1 */ + { + if (da2->cgastat & 0x01) + da2->cgastat &= ~0x30; + else + da2->cgastat ^= 0x30; /* toggle */ + if (da2->cgastat & 0x08) + da2->cgastat &= ~0x08; + else + da2->cgastat ^= 0x08; /* toggle */ + temp = da2->cgastat; + } else + temp = da2->attrc[da2->attraddr]; + // da2_iolog("DA2 In %04X(%02X) %04X %04X:%04X\n", addr, da2->attraddr, temp, cs >> 4, cpu_state.pc); + da2->attrff = 0; /* reset flipflop (VGA does not reset flipflop) */ + break; + case LG_INDEX: + temp = da2->gdcaddr; + break; + case LG_DATA: + temp = da2->gdcreg[da2->gdcaddr & 0x1f]; + // da2_iolog("DA2 In %04X(%02X) %04X %04X:%04X\n", addr, da2->gdcaddr, temp, cs >> 4, cpu_state.pc); + break; + } + // da2_iolog("DA2 In %04X %04X %04X:%04X\n", addr, temp, cs >> 4, cpu_state.pc); + return temp; +} +/* + * Write I/O + * out b(idx), out b(data), out b(data) + * out b(idx), out w(data) + * out b(idx), out w(data), out b(data) + * out w(idx) + * Read I/O + * out b(idx), in b(data) + * out b(idx), in b, in b(data) + * out b(idx), in w(data) + */ +static void +da2_outb(uint16_t addr, uint8_t val, void *priv) +{ + da2_t *da2 = (da2_t *) priv; + da2_iolog("DA2 Outb addr %03X val %02X %04X:%04X es:di=%x:%x ds:si=%x:%x\n", addr, val, cs >> 4, cpu_state.pc, ES, DI, DS, SI); + da2->inflipflop = 0; + switch (addr) { + case LS_DATA: + case LF_DATA: + case LC_DATA: + case LG_DATA: + if (da2->outflipflop) { + /* out b(idx), out b(data), out b(data) */ + da2->iolatch |= (uint16_t) val << 8; + da2->outflipflop = 0; + } else { // + da2->iolatch = val; + da2->outflipflop = 1; + } + break; + case LS_INDEX: + case LF_INDEX: + case LC_INDEX: + case LG_INDEX: + default: + da2->iolatch = val; + da2->outflipflop = 0; + break; + } + da2_out(addr, da2->iolatch, da2); +} +void +da2_outw(uint16_t addr, uint16_t val, void *priv) +{ + da2_iolog("DA2 Outw addr %03X val %04X\n", addr, val); + da2_t *da2 = (da2_t *) priv; + da2->inflipflop = 0; + switch (addr) { + case LS_INDEX: + case LF_INDEX: + case LC_INDEX: + case LG_INDEX: + da2_out(addr, val & 0xff, da2); + da2->iolatch = val >> 8; + da2_out(addr + 1, da2->iolatch, da2); + da2->outflipflop = 1; + break; + case LV_PORT: + da2->attrff = 0; + da2_out(addr, val & 0xff, da2); + da2_out(addr, val >> 8, da2); + da2->outflipflop = 0; + break; + case 0x3EC: + // da2_iolog("DA2 Outw addr %03X val %04X %04X:%04X\n", addr, val, cs >> 4, cpu_state.pc); + da2_out(LG_DATA, val >> 8, da2); + /* reset masks for compatibility with Win 3.1 solitaire */ + if (da2->gdcaddr == LG_MODE) { + da2->gdcreg[LG_BIT_MASK_LOW] = 0xff; + da2->gdcreg[LG_BIT_MASK_HIGH] = 0xff; + da2->planemask = 0xff; + da2->gdcreg[LG_MAP_MASKJ] = 0xff; + } + break; + case 0x3ED: + da2->gdcaddr = LG_MODE; + da2_out(LG_DATA, val, da2); + break; + case LS_DATA: + case LF_DATA: + case LC_DATA: + case LG_DATA: + default: + da2_out(addr, val, da2); + da2->outflipflop = 0; + break; + case AC_REG: + /* no register is revealed */ + da2_iolog("DA2 Outw addr %03X val %04X %04X:%04X\n", addr, val, cs >> 4, cpu_state.pc); + da2->reg3ee[val & 0x0f] = val >> 8; + break; + } +} +static uint8_t +da2_inb(uint16_t addr, void *priv) +{ + uint8_t temp; + da2_t *da2 = (da2_t *) priv; + da2->outflipflop = 0; + switch (addr) { + case LC_DATA: + if (da2->inflipflop) { + /* out b(idx), in b(low data), in b(high data) */ + temp = da2->iolatch >> 8; + da2->inflipflop = 0; + } else { // + da2->iolatch = da2_in(addr, da2); + temp = da2->iolatch & 0xff; + da2->inflipflop = 1; + } + break; + case LS_INDEX: + case LF_INDEX: + case LC_INDEX: + case LG_INDEX: + case LS_DATA: + case LF_DATA: + case LG_DATA: + default: + temp = da2_in(addr, da2) & 0xff; + da2->inflipflop = 0; + break; + } + // da2_iolog("DA2 Inb %04X %02X %04X:%04X\n", addr, temp, cs >> 4, cpu_state.pc); + return temp; +} +static uint16_t +da2_inw(uint16_t addr, void *priv) +{ + uint16_t temp; + da2_t *da2 = (da2_t *) priv; + da2->inflipflop = 0; + da2->outflipflop = 0; + temp = da2_in(addr, da2); + da2_iolog("DA2 Inw addr %03X val %04X\n", addr, temp); + return temp; +} +/* IO 03DAh : Input Status Register 2 for DOSSHELL used by DOS J4.0 */ +static uint8_t +da2_in_ISR(uint16_t addr, void *priv) +{ + da2_t *da2 = (da2_t *) priv; + uint8_t temp = 0; + if (addr == 0x3da) { + if (da2->cgastat & 0x01) + da2->cgastat &= ~0x30; + else + da2->cgastat ^= 0x30; + temp = da2->cgastat; + } + // da2_iolog("DA2D In %04X %04X %04X:%04X\n", addr, temp, cs >> 4, cpu_state.pc); + return temp; +} + +static void +da2_out_ISR(uint16_t addr, uint8_t val, void *priv) +{ + // da2_t* da2 = (da2_t*) priv; + da2_iolog("DA2D Out %04X %04X %04X:%04X\n", addr, val, cs >> 4, cpu_state.pc); +} + +/* +The IBM 5550 character mode addresses video memory between E0000h and E0FFFh. + [Character drawing] + SBCS: + 1 2 ... 13 + 1 | H.Grid + |---------------- + 2 | Space + 3 V| + .| + G| Font Pattern + r| (12x24 pixels) + i| + d| +26 |________________ +27 Space + ---------------- +28 Underscore ] + ---------------- >Cursor Position +29 ] + + DBCS: + 1 2 ... 13 1 2 ... 12 13 + 1 | H.Grid | H.Grid | + -|--------------------------|- + 2 | Space | Space | + -|--------------------------|- + 3 V| | |S + .| | |p + G| Font Pattern |a + r| (24x24 pixels) |c + i| | |e + d| | | +26 |_____________|____________| +27 | Space | Space + ------------------------------ +28 | Underscore | Underscore ] + ------------------------------ >Cursor Position +29 | | ] + + [Attributes] + Video mode 08h: + 7 6 5 4 3 2 1 0 + Blink |Under |HGrid |VGrid |Bright|Revers|FntSet|DBCS/SBCS| + + Video mode 0Eh: + -Blue |-Green|HGrid |VGrid |-Red |Revers|FntSet|DBCS/SBCS| + + Bit 1 switches the font bank to the Extended SBCS. DOS K3.x loads APL characters from $SYSEX24.FNT into it. + DOS Bunsho Program transfers 1/2 and 1/4 fonts fron the font ROM to the Extended SBCS. + This bit is not used for DBCS, but some apps set it as that column is right half of DBCS. + +[Font ROM Map (DA2, Japanese)] +The Font ROM can be accessed via 128 KB memory window located at A0000-BFFFFh. + + Bank 0 + 4800- * + Bank 1, 2, 3 + * - * + Bank 4 + * -0DB6Fh ( 4800-8DB6Fh) : JIS X 0208 DBCS (24 x 24) (IBMJ code: 100-1F7Dh) + 10000-16D1Fh (90000-96D1Fh) : IBM Extended Characters (IBMJ code: 2ADC-2C5Fh) + 18000-1BFCFh (98000-9BFCFh) : JIS X 0201 SBCS (13 x 30) + 1C000-1FFFFh (9C000-9FFFFh) : Codepage 437 characters (13 x 30) + Bank 5 + 00000-0C68Fh (A0000-AC68Fh) : Gaiji used by DOS Bunsho + 10000-13FFFh (B0000-B3FFFh) : Extended SBCS (13 x 30) + 14000-1477Fh (B4000-B477Fh) : Half-width box drawing characters used by DOS Bunsho + 16000-17FFFh (B6000-B7FFFh) : Codepage 850 characters (13 x 30) + 18000-1A3FFh (B8000-BA3FFh) : CAD control icons and box drawing characters (32 x 32) + + Some models have the signature 80h, 01h placed at Bank 0:1AFFEh. It disables Bitblt text drawing in OS/2 J1.3. + +[Font ROM Map (DA3, Traditional Chinese)] + Bank 0 - 11 : Valid Font ROM data + Bank 12 : Alias of bank 11 (At least, DOS T5.0 uses this on purpose to obtain the SBCS font.) + Bank 13 : Filled by 0xFFh + +[Gaiji RAM Map (DA2)] + Bank 0 00000-1FFFFh placed between A0000h-BFFFFh + 00000-1F7FFh(A0000-BF7FFh): Gaiji Non-resident (Kuten 103-114 ku,IBM: 2674-2ADBh) 1008 chs 128 bytes + 1F800-1FFFFh(BF800-BFFFFh): Gaiji Resident (SJIS: F040-F04Fh, IBM: 2384-2393h) 16 chs + + Bank 1 20000-3FFFFh placed between A0000h-BFFFFh + 20000-33FFFh(A0000-B3FFFh): Gaiji Resident (SJIS: F050-F39Ch, IBM: 2394-2613h) 640 chs + 34000-37FFFh(B4000-B7FFFh): Basic SBCS(00-FFh, ATTR bit 1 = off) + 38000-3AFFFh(B8000-BAFFFh): Gaiji Resident (SJIS: F39D-F3FCh, IBM: 2614-2673h) 96 chs + 3C000-3FFFFh(BC000-BFFFFh): Extended SBCS(00-FFh, ATTR bit 1 = on) + +[IBMJ code to Gaiji address conv tbl from DOS K3.3] + A B C + 2ADC, 2C5F, +5524 --> 8000 + 2614, 2673, +90EC --> B700 + 2384, 2613, +906C --> B3F0 + 0682, 1F7D, +0000 + + 8000 - 8183h 184h(388 characters) IBM Extended Characters + B3F0 - B75Fh 370h(880 characters) User-defined Characters +*/ + +/* Get character line pattern from jfont rom or gaiji volatile memory */ +static uint32_t +getfont_ps55dbcs(int32_t code, int32_t line, void *priv) +{ + da2_t *da2 = (da2_t *) priv; + uint32_t font = 0; + int32_t fline = line - 2; /* Start line of drawing character (line >= 1 AND line < 24 + 1 ) */ + if (code >= 0x8000 && code <= 0x8183) + code -= 0x6000; /* shift for IBM extended characters (I don't know how the real card works.) */ + if (code < DA2_FONTROM_SIZE / 72 && fline >= 0 && fline < 24) { + font = da2->mmio.font[code * 72 + fline * 3]; /* 0000 0000 0000 0000 0000 0000 1111 1111 */ + font <<= 8; /* 0000 0000 0000 0000 1111 1111 0000 0000 */ + font |= da2->mmio.font[code * 72 + fline * 3 + 1] & 0xf0; /* 0000 0000 0000 0000 1111 1111 2222 0000 */ + font <<= 3; /* 0000 0000 0000 0111 1111 1222 2000 0000 */ + font |= da2->mmio.font[code * 72 + fline * 3 + 1] & 0x0f; /* 0000 0000 0000 0111 1111 1222 2000 2222 */ + font <<= 8; /* 0000 0111 1111 1222 2000 2222 0000 0000 */ + font |= da2->mmio.font[code * 72 + fline * 3 + 2]; /* 0000 0111 1111 1222 2000 2222 3333 3333 */ + font <<= 4; /* 0111 1111 1222 2000 2222 3333 3333 0000 */ + /* font >>= 1;//put blank at column 1 (and 26) */ + } else if (code >= 0xb000 && code <= 0xb75f) { + /* convert code->address in gaiji memory */ + code -= 0xb000; + code *= 0x80; + // code += 0xf800; + font = da2->mmio.ram[code + line * 4]; + font <<= 8; + font |= da2->mmio.ram[code + line * 4 + 1]; + font <<= 8; + font |= da2->mmio.ram[code + line * 4 + 2]; + font <<= 8; + font |= da2->mmio.ram[code + line * 4 + 3]; + } else if (code > DA2_FONTROM_SIZE) + font = 0xffffffff; + else + font = 0; + return font; +} + +/* Reverse the bit order of attribute code IRGB to BGRI(used in Mode 3 and Cursor Color) */ +static int8_t +IRGBtoBGRI(uint8_t attr) +{ + attr = ((attr & 0x01) << 7) | ((attr & 0x02) << 5) | ((attr & 0x04) << 3) | ((attr & 0x08) << 1); + return attr >>= 4; +} +/* Get the foreground color from the attribute byte */ +static uint8_t +getPS55ForeColor(uint8_t attr, da2_t *da2) +{ + uint8_t foreground = ~attr & 0x08; /* 0000 1000 */ + foreground <<= 2; /* 0010 0000 */ + foreground |= ~attr & 0xc0; /* 1110 0000 */ + foreground >>= 4; /* 0000 1110 */ + if (da2->attrc[LV_PAS_STATUS_CNTRL] & 0x40) + foreground |= 0x01; /* bright color palette */ + return foreground; +} + +static void +da2_render_blank(da2_t *da2) +{ + int x, xx; + int cwidth; + if (da2->ioctl[LS_MODE] & 0x01) cwidth = 13; /* in character mode */ + else cwidth = 16; + + if (da2->firstline_draw == 2000) + da2->firstline_draw = da2->displine; + da2->lastline_draw = da2->displine; + + for (x = 0; x < da2->hdisp; x++) { + for (xx = 0; xx < cwidth; xx++) + ((uint32_t *) buffer32->line[da2->displine])[(x * cwidth) + xx + 32] = 0; + } +} +/* Display Adapter Mode 8, E Drawing */ +static void +da2_render_text(da2_t *da2) +{ + if (da2->firstline_draw == 2000) + da2->firstline_draw = da2->displine; + da2->lastline_draw = da2->displine; + + if (da2->fullchange) { + int offset = (8 - da2->scrollcache) + 24; + uint32_t *p = &((uint32_t *) buffer32->line[da2->displine])[offset]; + int x; + int drawcursor; + uint8_t chr, attr; + int fg, bg; + uint32_t chr_dbcs; + int chr_wide = 0; + int colormode = ((da2->attrc[LV_PAS_STATUS_CNTRL] & 0x80) == 0x80); + // da2_log("\nda2ma: %x, da2sc: %x\n", da2->memaddr, da2->scanline); + for (x = 0; x < da2->hdisp; x += 13) { + chr = da2->cram[(da2->memaddr) & DA2_MASK_CRAM]; + attr = da2->cram[(da2->memaddr + 1) & DA2_MASK_CRAM]; + // if(chr!=0x20) da2_log("chr: %x, attr: %x ", chr, attr); + if (colormode) /* IO 3E8h, Index 1Dh */ + { /* --Parse attribute byte in color mode-- */ + bg = 0; /* bg color is always black (the only way to change background color is programming PAL) */ + fg = getPS55ForeColor(attr, da2); + if (attr & 0x04) { /* reverse 0000 0100 */ + bg = fg; + fg = 0; + } + } else { /* --Parse attribute byte in monochrome mode-- */ + if (attr & 0x08) + fg = 3; /* Highlight 0000 1000 */ + else + fg = 2; + bg = 0; /* Background is always color #0 (default is black) */ + if (!(~attr & 0xCC)) /* Invisible 11xx 11xx -> 00xx 00xx */ + { + fg = bg; + attr &= 0x33; /* disable blinkking, underscore, highlight and reverse */ + } + if (attr & 0x04) { /* reverse 0000 0100 */ + bg = fg; + fg = 0; + } + /* Blinking 1000 0000 */ + fg = ((da2->blink & 0x20) || (!(attr & 0x80))) ? fg : bg; + // if(chr!=0x20) da2_log("chr: %x, %x, %x, %x, %x ", chr, attr, fg, da2->egapal[fg], da2->pallook[da2->egapal[fg]]); + } + /* Draw character */ + for (uint32_t n = 0; n < 13; n++) + p[n] = da2->pallook[da2->egapal[bg]]; /* draw blank */ + /* SBCS or DBCS left half */ + if (chr_wide == 0) { + if (attr & 0x01) + chr_wide = 1; + // chr_wide = 0; + /* Stay drawing If the char code is DBCS and not at last column. */ + if (chr_wide) { + /* Get high DBCS code from the next video address */ + chr_dbcs = da2->cram[(da2->memaddr + 2) & DA2_MASK_CRAM]; + chr_dbcs <<= 8; + chr_dbcs |= chr; + /* Get the font pattern */ + uint32_t font = getfont_ps55dbcs(chr_dbcs, da2->scanline, da2); + /* Draw 13 dots */ + for (uint32_t n = 0; n < 13; n++) { + p[n] = da2->pallook[da2->egapal[(font & 0x80000000) ? fg : bg]]; + font <<= 1; + } + } else { + /* the char code is SBCS (ANK) */ + uint32_t fontbase; + if (attr & 0x02) /* second map of SBCS font */ + fontbase = DA2_GAIJIRAM_SBEX; + else + fontbase = DA2_GAIJIRAM_SBCS; + uint16_t font = da2->mmio.ram[fontbase + chr * 0x40 + da2->scanline * 2]; /* w13xh29 font */ + font <<= 8; + font |= da2->mmio.ram[fontbase + chr * 0x40 + da2->scanline * 2 + 1]; /* w13xh29 font */ + // if(chr!=0x20) da2_log("memaddr: %x, scanline: %x, chr: %x, font: %x ", da2->memaddr, da2->scanline, chr, font); + /* Draw 13 dots */ + for (uint32_t n = 0; n < 13; n++) { + p[n] = da2->pallook[da2->egapal[(font & 0x8000) ? fg : bg]]; + font <<= 1; + } + } + } + /* right half of DBCS */ + else { + uint32_t font = getfont_ps55dbcs(chr_dbcs, da2->scanline, da2); + /* Draw 13 dots */ + for (uint32_t n = 0; n < 13; n++) { + p[n] = da2->pallook[da2->egapal[(font & 0x8000) ? fg : bg]]; + font <<= 1; + } + chr_wide = 0; + } + /* Line 28 (Underscore) Note: Draw this first to display blink + vertical + underline correctly. */ + if (da2->scanline == da2->crtc[LC_UNDERLINE_LOCATION] && attr & 0x40 && !colormode) { /* Underscore only in monochrome mode */ + for (uint32_t n = 0; n < 13; n++) + p[n] = da2->pallook[da2->egapal[fg]]; /* under line (white) */ + } + /* Column 1 (Vertical Line) */ + if (attr & 0x10) { + p[0] = da2->pallook[da2->egapal[(colormode) ? IRGBtoBGRI(da2->attrc[LV_GRID_COLOR_0]) : 2]]; /* vertical line (white) */ + } + if (da2->scanline == 0 && attr & 0x20 && ~da2->attrc[LV_PAS_STATUS_CNTRL]) { /* HGrid */ + for (uint32_t n = 0; n < 13; n++) + p[n] = da2->pallook[da2->egapal[(colormode) ? IRGBtoBGRI(da2->attrc[LV_GRID_COLOR_0]) : 2]]; /* horizontal line (white) */ + } + /* Drawing text cursor */ + drawcursor = ((da2->memaddr == da2->cursoraddr) && da2->cursorvisible && da2->cursoron); + if (drawcursor && da2->scanline >= da2->crtc[LC_CURSOR_ROW_START] && da2->scanline <= da2->crtc[LC_CURSOR_ROW_END]) { + int cursorwidth = (da2->crtc[LC_COMPATIBILITY] & 0x20 ? 26 : 13); + int cursorcolor = (colormode) ? IRGBtoBGRI(da2->attrc[LV_CURSOR_COLOR]) : 2; /* Choose color 2 if mode 8 */ + fg = (colormode) ? getPS55ForeColor(attr, da2) : ((attr & 0x08) ? 3 : 2); + bg = 0; + if (attr & 0x04) { /* Color 0 if reverse */ + bg = fg; + fg = 0; + } + for (uint32_t n = 0; n < cursorwidth; n++) + if (p[n] == da2->pallook[da2->egapal[cursorcolor]] || da2->egapal[bg] == da2->egapal[cursorcolor]) + p[n] = (p[n] == da2->pallook[da2->egapal[bg]]) ? da2->pallook[da2->egapal[fg]] : da2->pallook[da2->egapal[bg]]; + else + p[n] = (p[n] == da2->pallook[da2->egapal[bg]]) ? da2->pallook[da2->egapal[cursorcolor]] : p[n]; + } + da2->memaddr += 2; + p += 13; + } + // da2->memaddr &= DA2_MASK_CRAM; + // da2->writelines++; + } +} + +/* Display Adapter Mode 3 Drawing */ +static void +da2_render_textm3(da2_t *da2) +{ + if (da2->firstline_draw == 2000) + da2->firstline_draw = da2->displine; + da2->lastline_draw = da2->displine; + + if (da2->fullchange) { + int offset = (8 - da2->scrollcache) + 24; + uint32_t *p = &((uint32_t *) buffer32->line[da2->displine])[offset]; + int x; + int drawcursor; + uint8_t chr, attr, extattr; + int fg, bg; + uint32_t chr_dbcs; + int chr_wide = 0; + // da2_log("\nda2ma: %x, da2sc: %x\n", da2->memaddr, da2->scanline); + for (x = 0; x < da2->hdisp; x += 13) { + chr = da2_vram_r(DA2_VM03_BASECHR + da2->memaddr, da2); + attr = da2_vram_r(DA2_VM03_BASECHR + da2->memaddr + 1, da2); + extattr = da2_vram_r(DA2_VM03_BASEEXATTR + da2->memaddr + 1, da2); + // if(chr!=0x20) da2_log("addr: %x, chr: %x, attr: %x ", (DA2_VM03_BASECHR + da2->memaddr << 1) & da2->vram_mask, chr, attr); + bg = attr >> 4; + // if (da2->blink) bg &= ~0x8; + // fg = (da2->blink || (!(attr & 0x80))) ? (attr & 0xf) : bg; + fg = attr & 0xf; + fg = IRGBtoBGRI(fg); + bg = IRGBtoBGRI(bg); + /* Draw character */ + for (uint32_t n = 0; n < 13; n++) + p[n] = da2->pallook[da2->egapal[bg]]; /* draw blank */ + /* BCS or DBCS left half */ + if (chr_wide == 0) { + if (extattr & 0x01) + chr_wide = 1; + /* Stay drawing if the char code is DBCS and not at last column. */ + if (chr_wide) { + /* Get high DBCS code from the next video address */ + chr_dbcs = da2_vram_r(DA2_VM03_BASECHR + da2->memaddr + 2, da2); + chr_dbcs <<= 8; + chr_dbcs |= chr; + /* Get the font pattern */ + uint32_t font = getfont_ps55dbcs(chr_dbcs, da2->scanline, da2); + /* Draw 13 dots */ + for (uint32_t n = 0; n < 13; n++) { + p[n] = da2->pallook[da2->egapal[(font & 0x80000000) ? fg : bg]]; + font <<= 1; + } + } else { + /* the char code is SBCS (ANK) */ + uint32_t fontbase; + if (extattr & 0x80) /* second map of SBCS font */ + fontbase = DA2_GAIJIRAM_SBEX; + else + fontbase = DA2_GAIJIRAM_SBCS; + uint16_t font = da2->mmio.ram[fontbase+ chr * 0x40 + da2->scanline * 2]; /* w13xh29 font */ + font <<= 8; + font |= da2->mmio.ram[fontbase + chr * 0x40 + da2->scanline * 2 + 1]; /* w13xh29 font */ + // if(chr!=0x20) da2_log("memaddr: %x, scanline: %x, chr: %x, font: %x ", da2->memaddr, da2->scanline, chr, font); + for (uint32_t n = 0; n < 13; n++) { + p[n] = da2->pallook[da2->egapal[(font & 0x8000) ? fg : bg]]; + font <<= 1; + } + } + } + /* right half of DBCS */ + else { + uint32_t font = getfont_ps55dbcs(chr_dbcs, da2->scanline, da2); + /* Draw 13 dots */ + for (uint32_t n = 0; n < 13; n++) { + p[n] = da2->pallook[da2->egapal[(font & 0x8000) ? fg : bg]]; + font <<= 1; + } + chr_wide = 0; + } + drawcursor = ((da2->memaddr == da2->cursoraddr) && da2->cursorvisible && da2->cursoron); + if (drawcursor && da2->scanline >= da2->crtc[LC_CURSOR_ROW_START] && da2->scanline <= da2->crtc[LC_CURSOR_ROW_END]) { + // int cursorwidth = (da2->crtc[0x1f] & 0x20 ? 26 : 13); + // int cursorcolor = (colormode) ? IRGBtoBGRI(da2->attrc[0x1a]) : 2;/* Choose color 2 if mode 8 */ + // fg = (colormode) ? getPS55ForeColor(attr, da2) : (attr & 0x08) ? 3 : 2; + // bg = 0; + // if (attr & 0x04) {/* Color 0 if reverse */ + // bg = fg; + // fg = 0; + // } + for (uint32_t n = 0; n < 13; n++) + p[n] = da2->pallook[da2->egapal[fg]]; + } + da2->memaddr += 2; + p += 13; + } + // da2->memaddr &= DA2_MASK_CRAM; + // da2->writelines++; + } +} + +static void +da2_render_color_4bpp(da2_t *da2) +{ + int changed_offset = da2->memaddr >> 9; + // da2_log("memaddr %x cf %x\n", da2->memaddr, changed_offset); + da2->plane_mask &= 0x0f; /*safety */ + + if (da2->changedvram[changed_offset] || da2->changedvram[changed_offset + 1] || da2->fullchange) { + int x; + int offset = (8 - da2->scrollcache) + 24; + uint32_t *p = &((uint32_t *) buffer32->line[da2->displine])[offset]; + + if (da2->firstline_draw == 2000) + da2->firstline_draw = da2->displine; + da2->lastline_draw = da2->displine; + // da2_log("d %X\n", da2->memaddr); + + for (x = 0; x <= da2->hdisp; x += 8) /* hdisp = 1024 */ + { + uint8_t edat[8]; + uint8_t dat; + + /* get 8 pixels from vram */ + da2->memaddr &= da2->vram_display_mask; + *(uint32_t *) (&edat[0]) = *(uint32_t *) (&da2->vram[da2->memaddr << 3]); + da2->memaddr += 1; + + dat = ((edat[0] >> 7) & (1 << 0)) | ((edat[1] >> 6) & (1 << 1)) | ((edat[2] >> 5) & (1 << 2)) | ((edat[3] >> 4) & (1 << 3)); + p[0] = da2->pallook[da2->egapal[dat & da2->plane_mask]]; + dat = ((edat[0] >> 6) & (1 << 0)) | ((edat[1] >> 5) & (1 << 1)) | ((edat[2] >> 4) & (1 << 2)) | ((edat[3] >> 3) & (1 << 3)); + p[1] = da2->pallook[da2->egapal[dat & da2->plane_mask]]; + dat = ((edat[0] >> 5) & (1 << 0)) | ((edat[1] >> 4) & (1 << 1)) | ((edat[2] >> 3) & (1 << 2)) | ((edat[3] >> 2) & (1 << 3)); + p[2] = da2->pallook[da2->egapal[dat & da2->plane_mask]]; + dat = ((edat[0] >> 4) & (1 << 0)) | ((edat[1] >> 3) & (1 << 1)) | ((edat[2] >> 2) & (1 << 2)) | ((edat[3] >> 1) & (1 << 3)); + p[3] = da2->pallook[da2->egapal[dat & da2->plane_mask]]; + dat = ((edat[0] >> 3) & (1 << 0)) | ((edat[1] >> 2) & (1 << 1)) | ((edat[2] >> 1) & (1 << 2)) | ((edat[3] >> 0) & (1 << 3)); + p[4] = da2->pallook[da2->egapal[dat & da2->plane_mask]]; + dat = ((edat[0] >> 2) & (1 << 0)) | ((edat[1] >> 1) & (1 << 1)) | ((edat[2] >> 0) & (1 << 2)) | ((edat[3] << 1) & (1 << 3)); + p[5] = da2->pallook[da2->egapal[dat & da2->plane_mask]]; + dat = ((edat[0] >> 1) & (1 << 0)) | ((edat[1] >> 0) & (1 << 1)) | ((edat[2] << 1) & (1 << 2)) | ((edat[3] << 2) & (1 << 3)); + p[6] = da2->pallook[da2->egapal[dat & da2->plane_mask]]; + dat = ((edat[0] >> 0) & (1 << 0)) | ((edat[1] << 1) & (1 << 1)) | ((edat[2] << 2) & (1 << 2)) | ((edat[3] << 3) & (1 << 3)); + p[7] = da2->pallook[da2->egapal[dat & da2->plane_mask]]; + p += 8; + } + // da2->writelines++; + } +} + +static void +da2_render_color_8bpp(da2_t *da2) +{ + int changed_offset = da2->memaddr >> 9; + // da2_log("memaddr %x cf %x\n", da2->memaddr, changed_offset); + + if (da2->changedvram[changed_offset] || da2->changedvram[changed_offset + 1] || da2->fullchange) { + int x; + int offset = (8 - da2->scrollcache) + 24; + uint32_t *p = &((uint32_t *) buffer32->line[da2->displine])[offset]; + + if (da2->firstline_draw == 2000) + da2->firstline_draw = da2->displine; + da2->lastline_draw = da2->displine; + // da2_log("d %X\n", da2->memaddr); + + for (x = 0; x <= da2->hdisp; x += 8) /* hdisp = 1024 */ + { + uint8_t edat[8]; + uint8_t dat; + + /* get 8 pixels from vram */ + da2->memaddr &= da2->vram_display_mask; + *(uint32_t *) (&edat[0]) = *(uint32_t *) (&da2->vram[da2->memaddr << 3]); + *(uint32_t *) (&edat[4]) = *(uint32_t *) (&da2->vram[(da2->memaddr << 3) + 4]); + da2->memaddr += 1; + + dat = ((edat[0] >> 7) & (1 << 0)) | ((edat[1] >> 6) & (1 << 1)) | ((edat[2] >> 5) & (1 << 2)) | ((edat[3] >> 4) & (1 << 3)) | ((edat[4] >> 3) & (1 << 4)) | ((edat[5] >> 2) & (1 << 5)) | ((edat[6] >> 1) & (1 << 6)) | ((edat[7] >> 0) & (1 << 7)); + p[0] = da2->pallook[dat]; + dat = ((edat[0] >> 6) & (1 << 0)) | ((edat[1] >> 5) & (1 << 1)) | ((edat[2] >> 4) & (1 << 2)) | ((edat[3] >> 3) & (1 << 3)) | ((edat[4] >> 2) & (1 << 4)) | ((edat[5] >> 1) & (1 << 5)) | ((edat[6] >> 0) & (1 << 6)) | ((edat[7] << 1) & (1 << 7)); + p[1] = da2->pallook[dat]; + dat = ((edat[0] >> 5) & (1 << 0)) | ((edat[1] >> 4) & (1 << 1)) | ((edat[2] >> 3) & (1 << 2)) | ((edat[3] >> 2) & (1 << 3)) | ((edat[4] >> 1) & (1 << 4)) | ((edat[5] >> 0) & (1 << 5)) | ((edat[6] << 1) & (1 << 6)) | ((edat[7] << 2) & (1 << 7)); + p[2] = da2->pallook[dat]; + dat = ((edat[0] >> 4) & (1 << 0)) | ((edat[1] >> 3) & (1 << 1)) | ((edat[2] >> 2) & (1 << 2)) | ((edat[3] >> 1) & (1 << 3)) | ((edat[4] >> 0) & (1 << 4)) | ((edat[5] << 1) & (1 << 5)) | ((edat[6] << 2) & (1 << 6)) | ((edat[7] << 3) & (1 << 7)); + p[3] = da2->pallook[dat]; + dat = ((edat[0] >> 3) & (1 << 0)) | ((edat[1] >> 2) & (1 << 1)) | ((edat[2] >> 1) & (1 << 2)) | ((edat[3] >> 0) & (1 << 3)) | ((edat[4] << 1) & (1 << 4)) | ((edat[5] << 2) & (1 << 5)) | ((edat[6] << 3) & (1 << 6)) | ((edat[7] << 4) & (1 << 7)); + p[4] = da2->pallook[dat]; + dat = ((edat[0] >> 2) & (1 << 0)) | ((edat[1] >> 1) & (1 << 1)) | ((edat[2] >> 0) & (1 << 2)) | ((edat[3] << 1) & (1 << 3)) | ((edat[4] << 2) & (1 << 4)) | ((edat[5] << 3) & (1 << 5)) | ((edat[6] << 4) & (1 << 6)) | ((edat[7] << 5) & (1 << 7)); + p[5] = da2->pallook[dat]; + dat = ((edat[0] >> 1) & (1 << 0)) | ((edat[1] >> 0) & (1 << 1)) | ((edat[2] << 1) & (1 << 2)) | ((edat[3] << 2) & (1 << 3)) | ((edat[4] << 3) & (1 << 4)) | ((edat[5] << 4) & (1 << 5)) | ((edat[6] << 5) & (1 << 6)) | ((edat[7] << 6) & (1 << 7)); + p[6] = da2->pallook[dat]; + dat = ((edat[0] >> 0) & (1 << 0)) | ((edat[1] << 1) & (1 << 1)) | ((edat[2] << 2) & (1 << 2)) | ((edat[3] << 3) & (1 << 3)) | ((edat[4] << 4) & (1 << 4)) | ((edat[5] << 5) & (1 << 5)) | ((edat[6] << 6) & (1 << 6)) | ((edat[7] << 7) & (1 << 7)); + p[7] = da2->pallook[dat]; + p += 8; + } + // da2->writelines++; + } +} + +static void +da2_updatevidselector_tick(void *priv) +{ + da2_t *da2 = (da2_t *) priv; + if (da2->ioctl[LS_MODE] & 0x02) { + /* VGA passthrough mode */ + da2->override = 1; + timer_disable(&da2->timer); + svga_set_override(da2->mb_vga, 0); + da2_log("DA2 selector: VGA\n"); + } else { + svga_set_override(da2->mb_vga, 1); + timer_enable(&da2->timer); + da2->override = 0; + da2_log("DA2 selector: DA2\n"); + } +} + +static void +da2_updatevidselector(da2_t *da2) +{ + timer_set_delay_u64(&da2->timer_vidupd, 100000ull * TIMER_USEC); +} + +/* + INT 10h video modes supported in DOS J4.0 (The DA-2 doesn't have a video BIOS on its card.) + Mode Type Colors Text Base Address PELs Render + 3 A/N/K 16 80 x 25 B0000h/B8000h 1040 x 754 textm3 + 8 A/N/K 2 80 x 25 E0000h 1040 x 725 text + Ah APA 1 78 x 25 A0000h 1024 x 768 color_4bpp + Dh APA 16 78 x 25 A0000h 1024 x 768 color_4bpp + Eh A/N/K 16 80 x 25 E0000h 1040 x 725 text + Fh APA 256 NA A0000h 1024 x 768 color_8bpp + 45h(undoc) APA 16 NA A0000h 1040 x 768 color_4bpp + 46h(undoc) APA 16 ? A0000h 1040 x 768 color_4bpp +*/ +static void +da2_recalctimings(da2_t *da2) +{ + double crtcconst; + double _dispontime, _dispofftime, disptime; + + da2->vtotal = da2->crtc[LC_VERTICAL_TOTALJ] & 0xfff; + da2->dispend = da2->crtc[LC_V_DISPLAY_ENABLE_END] & 0xfff; + da2->vsyncstart = da2->crtc[LC_VERTICAL_SYNC_START] & 0xfff; + da2->split = da2->crtc[LC_LINE_COMPAREJ] & 0xfff; + da2->split -= 1; + da2->vblankstart = da2->crtc[LC_START_VERTICAL_BLANK] & 0xfff; + da2->hdisp = da2->crtc[LC_H_DISPLAY_ENABLE_END]; + + /* In the video mode 3, you'll see a blank below the screen. It's NOT a bug. */ + da2->hdisp -= da2->crtc[LC_START_H_DISPLAY_ENAB]; + da2->dispend -= da2->crtc[LC_START_V_DISPLAY_ENAB]; + da2->dispend += 1; + + da2->htotal = da2->crtc[LC_HORIZONTAL_TOTAL]; + da2->htotal += 1; + + da2->rowoffset = da2->crtc[LC_OFFSET]; /* number of bytes in a scanline */ + + da2->clock = da2->da2const; + + if (da2->vtotal == 0) + da2->vtotal = da2->vsyncstart = da2->vblankstart = 256; + if (da2->htotal == 0) + da2->htotal = da2->dispend = da2->hdisp = 64; + if (da2->rowoffset == 0) + da2->rowoffset = 64 * 2; /* To avoid causing a DBZ error */ + if (da2->split == 0) /* To avoid a glitch in MODE 1 of OS/2 J1.3 DOSBox. */ + da2->memaddr_latch = 0; + else + da2->memaddr_latch = ((da2->crtc[LC_START_ADDRESS_HIGH] & 0x3ff) << 8) | da2->crtc[LC_START_ADDRESS_LOW]; + + da2->ca_adj = 0; + da2->rowcount = da2->crtc[LC_MAXIMUM_SCAN_LINE]; + da2->hdisp_time = da2->hdisp; + da2->render = da2_render_blank; + /* determine display mode */ + // if (da2->attr_palette_enable && (da2->attrc[0x1f] & 0x08)) + /* if output disabled or VGA passthrough */ + if (da2->ioctl[LS_MODE] & 0x02 || !(da2->attrc[LV_COMPATIBILITY] & 0x08)) { + da2->render = da2_render_blank; + // return; + /* 16 color graphics mode */ + } else if (!(da2->ioctl[LS_MODE] & 0x01)) { + da2->hdisp *= 16; + da2->char_width = 13; + if (da2->crtc[LC_VIEWPORT_PRIORITY] & 0x80) { + da2_log("Set videomode to PS/55 8 bpp graphics.\n"); + da2->render = da2_render_color_8bpp; + da2->vram_display_mask = DA2_MASK_A000; + } else { /* PS/55 8-color */ + da2_log("Set videomode to PS/55 4 bpp graphics.\n"); + da2->render = da2_render_color_4bpp; + da2->vram_display_mask = DA2_MASK_A000; + } + } else { + /* text mode */ + if (da2->attrc[LV_ATTRIBUTE_CNTL] & 1) { + da2_log("Set videomode to PS/55 Mode 03 text.\n"); + da2->render = da2_render_textm3; + da2->vram_display_mask = DA2_MASK_CRAM; + } else { /* PS/55 text(color/mono) */ + da2_log("Set videomode to PS/55 Mode 8/E text.\n"); + da2->render = da2_render_text; + da2->vram_display_mask = DA2_MASK_CRAM; + } + da2->hdisp *= 13; + da2->char_width = 13; + } + + if (da2->vblankstart < da2->dispend) + da2->dispend = da2->vblankstart; + + crtcconst = da2->clock * da2->char_width; + + disptime = da2->htotal; + _dispontime = da2->hdisp_time; + + da2_log("Disptime %f dispontime %f hdisp %i\n", disptime, _dispontime, da2->hdisp); + + _dispofftime = disptime - _dispontime; + _dispontime *= crtcconst; + _dispofftime *= crtcconst; + + da2->dispontime = (uint64_t) _dispontime; + da2->dispofftime = (uint64_t) _dispofftime; + if (da2->dispontime < TIMER_USEC) + da2->dispontime = TIMER_USEC; + if (da2->dispofftime < TIMER_USEC) + da2->dispofftime = TIMER_USEC; + da2_log("da2 horiz total %i display end %i vidclock %f\n", da2->crtc[0], da2->crtc[1], da2->clock); + da2_log("da2 vert total %i display end %i max row %i vsync %i\n",da2->vtotal,da2->dispend,(da2->crtc[9]&31)+1,da2->vsyncstart); + da2_log("da2 dispon %lu dispoff %lu on(us) %f off(us) %f\n",da2->dispontime, da2->dispofftime, (double)da2->dispontime / (double)cpuclock / (double) (1ULL << 32) * 1000000.0, (double)da2->dispofftime / (double)cpuclock / (double) (1ULL << 32) * 1000000.0); + da2_log("da2 linecompare %d\n", da2->split); +} + +static void +da2_mapping_update(da2_t *da2) +{ + /* Has the CardEnable bit been changed? */ + if (!((da2->pos_regs[2] ^ da2->old_pos2) & 1)) + return; + da2->old_pos2 = da2->pos_regs[2]; + // da2_recalc_mapping(da2); + if (da2->pos_regs[2] & 0x01) { + da2_log("DA2 enable registers\n"); + for (uint8_t i = 0; i < 8; i++) + da2_log("DA2 POS[%d]: %x\n", i, da2->pos_regs[i]); + io_sethandler(0x03c0, 0x000a, da2_inb, da2_inw, NULL, da2_outb, da2_outw, NULL, da2); + io_sethandler(0x03e0, 0x0010, da2_inb, da2_inw, NULL, da2_outb, da2_outw, NULL, da2); + io_sethandler(0x03d0, 0x000b, da2_in_ISR, NULL, NULL, da2_out_ISR, NULL, NULL, da2); + mem_mapping_enable(&da2->cmapping); + mem_mapping_enable(&da2->mmio.mapping); + timer_enable(&da2->bitblt.timer); + } else { + da2_log("DA2 disable registers\n"); + timer_disable(&da2->bitblt.timer); + mem_mapping_disable(&da2->cmapping); + mem_mapping_disable(&da2->mmio.mapping); + io_removehandler(0x03c0, 0x000a, da2_inb, da2_inw, NULL, da2_outb, da2_outw, NULL, da2); + io_removehandler(0x03e0, 0x0010, da2_inb, da2_inw, NULL, da2_outb, da2_outw, NULL, da2); + io_removehandler(0x03d0, 0x000b, da2_in_ISR, NULL, NULL, da2_out_ISR, NULL, NULL, da2); + } +} + +static uint8_t +da2_mca_read(int port, void *priv) +{ + da2_t *da2 = (da2_t *) priv; + return da2->pos_regs[port & 7]; +} + +static void +da2_mca_write(int port, uint8_t val, void *priv) +{ + da2_t *da2 = (da2_t *) priv; + + da2_log("da2_mca_write: port=%04x val=%02x\n", port, val); + + if (port < 0x102) + return; + da2->pos_regs[port & 7] = val; + + da2_mapping_update(da2); +} + +static uint8_t +da2_mca_feedb(void *priv) +{ + const da2_t *da2 = (da2_t *) priv; + + return da2->pos_regs[2] & 0x01; +} + +static void +da2_mca_reset(void *priv) +{ + da2_t *da2 = (da2_t *) priv; + da2_log("da2_mca_reset called.\n"); + da2_reset(da2); + da2_mca_write(0x102, 0, da2); +} + +/* ROP gdcinput and gdcsrc, and write the result with bitmask at addr (byte) */ +static void +da2_gdcropB(uint32_t addr,uint8_t bitmask, da2_t *da2) +{ + for (uint8_t i = 0; i < 8; i++) { + if (da2->planemask & (1 << i)) { + // da2_log("da2_gdcropB o%x a%x d%x p%d m%x\n", da2->gdcreg[LG_COMMAND] & 0x03, addr, da2->gdcinput[i], i, bitmask); + switch (da2->gdcreg[LG_COMMAND] & 0x03) { + case 0: /*Set*/ + // da2->vram[addr | i] = (da2->gdcinput[i] & bitmask) | (da2->gdcsrc[i] & ~bitmask); + // da2->vram[addr | i] = (da2->gdcinput[i] & bitmask) | (da2->vram[addr | i] & ~bitmask); + da2_vram_w(addr | i, (da2->gdcinput[i] & bitmask) | (da2->vram[addr | i] & ~bitmask), da2); + break; + case 1: /*AND*/ + // da2->vram[addr | i] = (da2->gdcinput[i] | ~bitmask) & da2->gdcsrc[i]; + da2_vram_w(addr | i, ((da2->gdcinput[i] & da2->gdcsrc[i]) & bitmask) | (da2->vram[addr | i] & ~bitmask), da2); + break; + case 2: /*OR*/ + // da2->vram[addr | i] = (da2->gdcinput[i] & bitmask) | da2->gdcsrc[i]; + da2_vram_w(addr | i, ((da2->gdcinput[i] | da2->gdcsrc[i]) & bitmask) | (da2->vram[addr | i] & ~bitmask), da2); + break; + case 3: /*XOR*/ + // da2->vram[addr | i] = (da2->gdcinput[i] & bitmask) ^ da2->gdcsrc[i]; + da2_vram_w(addr | i, ((da2->gdcinput[i] ^ da2->gdcsrc[i]) & bitmask) | (da2->vram[addr | i] & ~bitmask), da2); + break; + } + } + } +} +/* ROP gdcinput and gdcsrc, and write the result with bitmask at addr (word) */ +static void +da2_gdcropW(uint32_t addr, uint16_t bitmask, da2_t *da2) +{ + if((addr & 8) && !(da2->gdcreg[LG_COMMAND] & 0x08)) bitmask = da2_rightrotate(bitmask, 8); + // if((addr & 8)) bitmask = da2_rightrotate(bitmask, 8); + uint8_t bitmask_l = bitmask & 0xff; + uint8_t bitmask_h = bitmask >> 8; + for (uint8_t i = 0; i < 8; i++) { + if (da2->planemask & (1 << i)) { + // da2_log("da2_gdcropW m%x a%x d%x i%d ml%x mh%x\n", da2->gdcreg[LG_COMMAND] & 0x03, addr, da2->gdcinput[i], i, da2->gdcreg[LG_BIT_MASK_LOW], da2->gdcreg[LG_BIT_MASK_HIGH]); + switch (da2->gdcreg[LG_COMMAND] & 0x03) { + case 0: /*Set*/ + // da2->vram[addr | i] = (da2->gdcinput[i] & bitmask_l) | (da2->gdcsrc[i] & ~bitmask_l); + // da2->vram[(addr + 8) | i] = ((da2->gdcinput[i] >> 8) & bitmask_h) | ((da2->gdcsrc[i] >> 8) & ~bitmask_h); + da2_vram_w(addr | i, (da2->gdcinput[i] & bitmask_l) | (da2->vram[addr | i] & ~bitmask_l), da2); + da2_vram_w((addr + 8) | i, ((da2->gdcinput[i] >> 8) & bitmask_h) + | (da2->vram[(addr + 8) | i] & ~bitmask_h), da2); + break; + case 1: /*AND*/ + // da2->vram[addr | i] = (da2->gdcinput[i] | ~bitmask_l) & da2->gdcsrc[i]; + // da2->vram[(addr + 8) | i] = ((da2->gdcinput[i] >> 8) | ~bitmask_h) & (da2->gdcsrc[i] >> 8); + da2_vram_w(addr | i, ((da2->gdcinput[i] & da2->gdcsrc[i]) & bitmask_l) | (da2->vram[addr | i] & ~bitmask_l), da2); + da2_vram_w((addr + 8) | i, (((da2->gdcinput[i] >> 8) & (da2->gdcsrc[i] >> 8)) & bitmask_h) + | (da2->vram[(addr + 8) | i] & ~bitmask_h), da2); + break; + case 2: /*OR*/ + // da2->vram[addr | i] = (da2->gdcinput[i] & bitmask_l) | da2->gdcsrc[i]; + // da2->vram[(addr + 8) | i] = ((da2->gdcinput[i] >> 8) & bitmask_h) | (da2->gdcsrc[i] >> 8); + da2_vram_w(addr | i, ((da2->gdcinput[i] | da2->gdcsrc[i]) & bitmask_l) | (da2->vram[addr | i] & ~bitmask_l), da2); + da2_vram_w((addr + 8) | i, (((da2->gdcinput[i] >> 8) | (da2->gdcsrc[i] >> 8)) & bitmask_h) + | (da2->vram[(addr + 8) | i] & ~bitmask_h), da2); + break; + case 3: /*XOR*/ + // da2->vram[addr | i] = (da2->gdcinput[i] & bitmask_l) ^ da2->gdcsrc[i]; + // da2->vram[(addr + 8) | i] = ((da2->gdcinput[i] >> 8) & bitmask_h) ^ (da2->gdcsrc[i] >> 8); + da2_vram_w(addr | i, ((da2->gdcinput[i] ^ da2->gdcsrc[i]) & bitmask_l) | (da2->vram[addr | i] & ~bitmask_l), da2); + da2_vram_w((addr + 8) | i, (((da2->gdcinput[i] >> 8) ^ (da2->gdcsrc[i] >> 8)) & bitmask_h) + | (da2->vram[(addr + 8) | i] & ~bitmask_h), da2); + break; + } + } + } +} + +static uint8_t +da2_mmio_read(uint32_t addr, void *priv) +{ + da2_t *da2 = (da2_t *) priv; + uint32_t index = 0; + addr &= DA2_MASK_MMIO; + if (da2->ioctl[LS_MMIO] & 0x10) { + if (da2->fctl[LF_MMIO_SEL] == 0x80) + /* linear access */ + addr |= ((uint32_t) da2->fctl[LF_MMIO_ADDR] << 17); + else { + /* 64k bank switch access */ + index = da2->fctl[LF_MMIO_MODE] & 0x0f; + index <<= 8; + index |= da2->fctl[LF_MMIO_ADDR]; + } + // da2_log("PS55_MemHnd: Read from mem %x, bank %x, addr %x\n", da2->fctl[LF_MMIO_MODE], da2->fctl[LF_MMIO_ADDR], addr); + switch (da2->fctl[LF_MMIO_MODE] & 0xf0) { + case 0xb0: /* Gaiji RAM */ + addr += index * 0x80; + addr &= DA2_MASK_GAIJIRAM; /* safety access */ + // da2_log("PS55_MemHnd_G: Read from mem %x, bank %x, chr %x (%x), val %x\n", da2->fctl[LF_MMIO_MODE], da2->fctl[LF_MMIO_ADDR], addr / 128, addr, da2->mmio.font[addr]); + return da2->mmio.ram[addr]; + break; + case 0x10: /* Font ROM */ + if (da2->mmio.charset == DA2_DCONFIG_CHARSET_HANT) { + if (addr >= 0x1a0000) + return DA2_INVALIDACCESS8; + if (addr >= 0x180000) + addr -= 0x40000; /* The bank 12 (180000h-19ffffh) is beyond the available ROM address range, + but the Chinese font sub card actually has this alias, and is used by DOS T5.0. */ + } + if (addr >= DA2_FONTROM_SIZE) + return DA2_INVALIDACCESS8; + // da2_log("PS55_MemHnd: Read from mem %x, bank %x, chr %x (%x), val %x\n", da2->fctl[LF_MMIO_MODE], da2->fctl[LF_MMIO_ADDR], addr / 72, addr, da2->mmio.font[addr]); + return da2->mmio.font[addr]; + break; + case 0x00: /* SBCS in Gaiji RAM (used in the downward writing mode of DOS/V Extension) */ + addr += DA2_GAIJIRAM_SBCS + index * 0x40; + addr &= DA2_MASK_GAIJIRAM; + return da2->mmio.ram[addr]; + break; + default: + da2_log("PS55_MemHnd: Invalid read mem %x, bank %x, chr %x (%x), val %x\n", da2->fctl[LF_MMIO_MODE], da2->fctl[LF_MMIO_ADDR], addr / 72, addr, da2->mmio.font[addr]); + return DA2_INVALIDACCESS8; /* invalid memory access */ + break; + } + } else if (!(da2->ioctl[LS_MODE] & 1)) { /* 16 or 256 color mode */ + cycles -= video_timing_read_b; + for (uint8_t i = 0; i < 8; i++) + da2->gdcla[i] = da2->vram[(addr << 3) | i]; /* read in byte */ +#ifdef ENABLE_DA2_DEBUGVRAM + da2_log("da2_Rb: %05x=%02x\n", addr, da2->gdcla[da2->readplane]); +#endif + if (da2->gdcreg[LG_MODE] & 0x08) { /* compare data across planes if the read mode bit (3EB 05, bit 3) is 1 */ + uint8_t ret = 0; + for (uint8_t i = 0; i < 8; i++) { + if (~da2->gdcreg[LG_COLOR_DONT_CARE] & (1 << i)) /* color don't care register */ + ret |= da2->gdcla[i] ^ ((da2->gdcreg[LG_COLOR_COMPAREJ] & (1 << i)) ? 0xff : 0); + } + return ~ret; + } else + return da2->gdcla[da2->readplane]; + } else { /* text mode 3 */ + cycles -= video_timing_read_b; + return da2->vram[addr]; + } +} +static uint16_t +da2_mmio_readw(uint32_t addr, void *priv) +{ + da2_t *da2 = (da2_t *) priv; + // da2_log("da2_readW: %x %x %x %x %x\n", da2->ioctl[LS_MMIO], da2->fctl[LF_MMIO_SEL], da2->fctl[LF_MMIO_MODE], da2->fctl[LF_MMIO_ADDR], addr); + // da2_log("da2_readW: %x %x %x %x %x CS:PC=%4x:%4x\n", da2->ioctl[LS_MMIO], da2->fctl[LF_MMIO_SEL], da2->fctl[LF_MMIO_MODE], da2->fctl[LF_MMIO_ADDR], addr, CS, cpu_state.pc); + + if (da2->ioctl[LS_MMIO] & 0x10) { + return (uint16_t) da2_mmio_read(addr, da2) | (uint16_t) (da2_mmio_read(addr + 1, da2) << 8); + } else if (!(da2->ioctl[LS_MODE] & 1)) {/* 16 color or 256 color mode */ + cycles -= video_timing_read_w; + addr &= DA2_MASK_MMIO; + for (uint8_t i = 0; i < 8; i++) + da2->gdcla[i] = (uint16_t) (da2->vram[(addr << 3) | i]) | ((uint16_t) (da2->vram[((addr << 3) + 8) | i]) << 8); /* read vram into latch */ + +#ifdef ENABLE_DA2_DEBUGVRAM + ////debug + // if (((int)addr - (int)da2->mmrdbg_vidaddr) > 2 || (((int)da2->mmrdbg_vidaddr - (int)addr) > 2) || da2->mmrdbg_vidaddr == addr) + //{ + // fprintf(da2->mmrdbg_fp, "\nR %x ", addr); + // for (uint8_t i = 0; i <= 0xb; i++) + // fprintf(da2->mmrdbg_fp, "%02x ", da2->gdcreg[i]); + // } + // for (uint8_t i = 0; i < 16; i++) + //{ + // int pixeldata = 0; + // if (da2->gdcla[da2->readplane] & (1 << (15 - i))) pixeldata = 1; + // fprintf(da2->mmrdbg_fp, "%X", pixeldata); + // } + // da2->mmrdbg_vidaddr = addr; +#endif + + if (da2->gdcreg[LG_MODE] & 0x08) { /* compare data across planes if the read mode bit (3EB 05, bit 3) is 1 */ + uint16_t ret = 0; + + for (uint8_t i = 0; i < 8; i++) { + if (~da2->gdcreg[LG_COLOR_DONT_CARE] & (1 << i)) /* color don't care register */ + ret |= da2->gdcla[i] ^ ((da2->gdcreg[LG_COLOR_COMPAREJ] & (1 << i)) ? 0xffff : 0); + } + return ~ret; + } else { +#ifdef ENABLE_DA2_DEBUGVRAM + da2_log("da2_Rw: %05x(%d) = %04x\n", addr, da2->readplane, da2->gdcla[da2->readplane]); +#endif + return da2->gdcla[da2->readplane]; + } + } else { + return (uint16_t) da2_mmio_read(addr, da2) | (uint16_t) (da2_mmio_read(addr + 1, da2) << 8); + } +} +static void +da2_mmio_write(uint32_t addr, uint8_t val, void *priv) +{ + da2_t *da2 = (da2_t *) priv; + uint32_t index = 0; + // da2_log("da2_mmio_write %x %x\n", addr, val); + // if ((addr & ~DA2_MASK_MMIO) != 0xA0000) + // return; + addr &= DA2_MASK_MMIO; + + if (da2->ioctl[LS_MMIO] == 0x1f) {/* write bitblt fifo data */ + da2_bitblt_addpayload(val, da2); + } + else if (da2->ioctl[LS_MMIO] & 0x10) { /* access to gaiji ram */ + // if(da2->ioctl[LS_MMIO] == 0x1f) da2_log("mw mem %x, addr %x, val %x, ESDI %x:%x DSSI %x:%x\n", da2->fctl[LF_MMIO_MODE], addr, val, ES, DI, DS, SI); + /* Gaiji RAM */ + if (da2->fctl[LF_MMIO_SEL] == 0x80) + addr |= ((uint32_t) da2->fctl[LF_MMIO_ADDR] << 17); /* xxxy yyyy yyyy yyyy yyyy */ + else { + index = da2->fctl[LF_MMIO_MODE] & 0x0f; + index <<= 8; + index |= da2->fctl[LF_MMIO_ADDR]; + // da2_log("da2_mmio_w io %x, sl %x, 09 %x, ad %x, mm %x, addr %x, val %x\n", da2->ioctl[LS_MMIO],da2->fctl[LF_MMIO_SEL], + // da2->fctl[LF_MMIO_09],da2->fctl[LF_MMIO_ADDR], da2->fctl[LF_MMIO_MODE], addr, val); + } + switch (da2->fctl[LF_MMIO_MODE] & 0xf0) { + case 0xb0: /* Gaiji RAM 1011 0000 */ + addr += index * 0x80; + da2->mmio.ram[addr & DA2_MASK_GAIJIRAM] = val; + break; + case 0x10: /* Font ROM 0001 0000 */ + /* Read-Only */ + break; + case 0x00: /* SBCS in Gaiji RAM (used by DOS/V Extension DSPXDA2 driver) */ + addr += index * 0x40; + da2->mmio.ram[(DA2_GAIJIRAM_SBCS + addr) & DA2_MASK_GAIJIRAM] = val; + // da2_log("da2_mmio_write %x %x %04X:%04X\n", addr, val, CS, cpu_state.pc); + break; + default: + da2_log("da2_mmio_write failed io %x, mm %x, addr %x, val %x\n", da2->ioctl[LS_MMIO] ,da2->fctl[LF_MMIO_MODE], addr, val); + break; + } + } else if (!(da2->ioctl[LS_MODE] & 1)) { /* 16 color or 256 color mode */ + uint8_t bitmask; + /* Align bitmask with even address */ + /* With byte align: Win 3.1 (Window) - ok, Solitaire 3.1 - ok, A-Train IV (splash): bad, OS/2 J2.0(cmd) - ok */ + // if ((addr & 1) && !(da2->gdcreg[LG_COMMAND] & 0x08)) bitmask = da2->gdcreg[LG_BIT_MASK_HIGH]; + /* Without byte align: Win 3.1 (Window) - bad, Solitaire 3.1 - ok, A-Train IV (splash): ok, OS/2 J2.0(cmd) - ok */ + /* With byte align: Win 3.1 (Window) - ok, Solitaire 3.1 - ok, A-Train IV (splash): ok, OS/2 J2.0(cmd) - ok */ + if ((addr & 1)) bitmask = da2->gdcreg[LG_BIT_MASK_HIGH]; + else + /* No align: Win 3.1 (Window Title) - ok, Solitaire 3.1 - ok, A-Train IV (splash): bad, OS/2 J2.0(cmd) - bad */ + bitmask = da2->gdcreg[LG_BIT_MASK_LOW]; + +#ifdef ENABLE_DA2_DEBUGVRAM + // da2_log("da2_wB %x %02x\n", addr, val); + da2_log("da2_wB %x %d %d %02x\n", addr, + addr % (da2->rowoffset * 2) * 8, addr / (da2->rowoffset * 2), val); + // if (!(da2->gdcreg[LG_COMMAND] & 0x08)) + //{ + if (((int) addr - (int) da2->mmdbg_vidaddr) > 2 || (((int) da2->mmdbg_vidaddr - (int) addr) > 2) || da2->mmdbg_vidaddr == addr) { + fprintf(da2->mmdbg_fp, "\nB %x %02x ", addr, val); + for (uint8_t i = 0; i <= 0xb; i++) + fprintf(da2->mmdbg_fp, "%02x ", da2->gdcreg[i]); + } + for (uint8_t i = 0; i < 8; i++) { + int pixeldata = 0; + if (val & (1 << (7 - i))) + pixeldata = (da2->planemask & 0xf); + fprintf(da2->mmdbg_fp, "%X", pixeldata); + } + da2->mmdbg_vidaddr = addr; + //} +#endif + cycles -= video_timing_write_b; + da2->changedvram[addr >> 9] = changeframecount;/* 0x1FFFF -> 0x1F */ + addr <<= 3; + + for (uint8_t i = 0; i < 8; i++) + da2->gdcsrc[i] = da2->gdcla[i]; /* use latch */ + + // da2_log("da2_Wb m%02x r%02x %05x:%02x %x:%x\n", da2->gdcreg[0x5], da2->gdcreg[LG_COMMAND], addr >> 3, val, cs >> 4, cpu_state.pc); + // da2_log("da2_Wb m%02x r%02x %05x:%02x=%02x%02x%02x%02x->", da2->gdcreg[0x5], da2->gdcreg[LG_COMMAND], addr >> 3, val, da2->vram[addr + 0], da2->vram[addr + 1], da2->vram[addr + 2], da2->vram[addr + 3]); + + if (!(da2->gdcreg[LG_COMMAND] & 0x08)) { + for (uint8_t i = 0; i < 8; i++) + if (da2->gdcreg[LG_ENABLE_SRJ] & (1 << i)) + da2->gdcinput[i] = (da2->gdcreg[LG_SET_RESETJ] & (1 << i)) ? 0xff : 0; + else if (da2->gdcreg[LG_SET_RESETJ] & (1 << i)) + da2->gdcinput[i] = ~val; + else + da2->gdcinput[i] = val; + da2_gdcropB(addr, bitmask, da2); + return; + } + + switch (da2->writemode) { + case 2: /* equiv to vga write mode 1 */ + for (uint8_t i = 0; i < 8; i++) + if (da2->planemask & (1 << i)) + da2_vram_w(addr | i, da2->gdcsrc[i], da2); + break; + case 0:/* equiv to vga write mode 0 */ + if (da2->gdcreg[LG_DATA_ROTATION] & 7) + val = svga_rotate[da2->gdcreg[LG_DATA_ROTATION] & 7][val]; + if (bitmask == 0xff && !(da2->gdcreg[LG_COMMAND] & 0x03) && (!da2->gdcreg[LG_ENABLE_SRJ])) { + for (uint8_t i = 0; i < 8; i++) + if (da2->planemask & (1 << i)) + da2_vram_w(addr | i, val, da2); + } else { + for (uint8_t i = 0; i < 8; i++) + if (da2->gdcreg[LG_ENABLE_SRJ] & (1 << i)) + da2->gdcinput[i] = (da2->gdcreg[LG_SET_RESETJ] & (1 << i)) ? 0xff : 0; + else + da2->gdcinput[i] = val; + da2_gdcropB(addr, bitmask, da2); + } + break; + case 1:/* equiv to vga write mode 2 */ + for (uint8_t i = 0; i < 8; i++) + da2->gdcinput[i] = ((val & (1 << i)) ? 0xff : 0); + da2_gdcropB(addr, bitmask, da2); + break; + case 3:/* equiv to vga write mode 3 */ + if (da2->gdcreg[LG_DATA_ROTATION] & 7) + val = svga_rotate[da2->gdcreg[LG_DATA_ROTATION] & 7][val]; + bitmask &= val; + + for (uint8_t i = 0; i < 8; i++) + da2->gdcinput[i] = (da2->gdcreg[LG_SET_RESETJ] & (1 << i)) ? 0xff : 0; + da2_gdcropB(addr, bitmask, da2); + break; + } + } else { /* mode 3h text */ + cycles -= video_timing_write_b; + da2_vram_w(addr, val, da2); + da2->fullchange = 2; + } +} +static uint16_t +da2_rightrotate(uint16_t data, uint8_t count) +{ + return (data >> count) | (data << (sizeof(data) * 8 - count)); +} +static void +da2_mmio_gc_writeW(uint32_t addr, uint16_t val, void *priv) +{ + da2_t *da2 = (da2_t *) priv; + uint16_t bitmask; + addr &= DA2_MASK_MMIO; + bitmask = da2->gdcreg[LG_BIT_MASK_HIGH]; + bitmask <<= 8; + bitmask |= (uint16_t) da2->gdcreg[LG_BIT_MASK_LOW]; +#ifdef ENABLE_DA2_DEBUGVRAM + da2_log("da2_wW %x %d %d %02x\n", addr, + addr % (da2->rowoffset * 2) * 8, addr / (da2->rowoffset * 2), val); + + if (((int) addr - (int) da2->mmdbg_vidaddr) > 2 || (((int) da2->mmdbg_vidaddr - (int) addr) > 2) || da2->mmdbg_vidaddr == addr) { + fprintf(da2->mmdbg_fp, "\nW %x %x ", addr, val); + for (uint8_t i = 0; i <= 0xb; i++) + fprintf(da2->mmdbg_fp, "%02x ", da2->gdcreg[i]); + } + for (uint8_t i = 0; i < 16; i++) { + int pixeldata = 0; + if (val & (1 << (15 - i))) + pixeldata = (da2->planemask & 0xf); + fprintf(da2->mmdbg_fp, "%X", pixeldata); + } + da2->mmdbg_vidaddr = addr; +#endif + cycles -= video_timing_write_w; + + // da2_log("da2_gcW m%d a%x d%x\n", da2->writemode, addr, val); + // da2_log("da2_gcW %05X %02X %04X:%04X esdi %04X:%04X dssi %04X:%04X\n", addr, val, cs >> 4, cpu_state.pc, ES, DI, DS, SI); + + da2->changedvram[addr >> 9] = changeframecount; + addr <<= 3; + + for (uint8_t i = 0; i < 8; i++) + da2->gdcsrc[i] = da2->gdcla[i]; /* use latch */ + + if (!(da2->gdcreg[LG_COMMAND] & 0x08)) { + for (uint8_t i = 0; i < 8; i++) + if (da2->gdcreg[LG_ENABLE_SRJ] & (1 << i)) + da2->gdcinput[i] = (da2->gdcreg[LG_SET_RESETJ] & (1 << i)) ? 0xffff : 0; + else if (da2->gdcreg[LG_SET_RESETJ] & (1 << i)) + da2->gdcinput[i] = ~val; + else + da2->gdcinput[i] = val; + da2_gdcropW(addr, bitmask, da2); + return; + } + // da2_log("da2_Ww m%02x r%02x %05x:%04x=%02x%02x%02x%02x,%02x%02x%02x%02x->", da2->gdcreg[0x5], da2->gdcreg[LG_COMMAND], addr >> 3, val, da2->vram[addr + 0], da2->vram[addr + 1], da2->vram[addr + 2], da2->vram[addr + 3] + // , da2->vram[addr + 8], da2->vram[addr + 9], da2->vram[addr + 10], da2->vram[addr + 11]); + switch (da2->writemode) { + case 2: + for (uint8_t i = 0; i < 8; i++) + if (da2->planemask & (1 << i)) { + da2_vram_w(addr | i, da2->gdcsrc[i] & 0xff, da2); + da2_vram_w((addr + 8) | i, da2->gdcsrc[i] >> 8, da2); + } + break; + case 0: + if (da2->gdcreg[LG_DATA_ROTATION] & 15) + val = da2_rightrotate(val, da2->gdcreg[LG_DATA_ROTATION] & 15); + if (bitmask == 0xffff && !(da2->gdcreg[LG_COMMAND] & 0x03) && (!da2->gdcreg[LG_ENABLE_SRJ])) { + for (uint8_t i = 0; i < 8; i++) + if (da2->planemask & (1 << i)) { + da2_vram_w(addr | i, val & 0xff, da2); + da2_vram_w((addr + 8) | i, val >> 8, da2); + } + } else { + for (uint8_t i = 0; i < 8; i++) + if (da2->gdcreg[LG_ENABLE_SRJ] & (1 << i)) + da2->gdcinput[i] = (da2->gdcreg[LG_SET_RESETJ] & (1 << i)) ? 0xffff : 0; + else + da2->gdcinput[i] = val; + da2_gdcropW(addr, bitmask, da2); + // da2_log("- %02X %02X %02X %02X %08X\n",vram[addr],vram[addr|0x1],vram[addr|0x2],vram[addr|0x3],addr); + } + break; + case 1: + for (uint8_t i = 0; i < 8; i++) + da2->gdcinput[i] = ((val & (1 << i)) ? 0xffff : 0); + da2_gdcropW(addr, bitmask, da2); + break; + case 3: + if (da2->gdcreg[LG_DATA_ROTATION] & 15) + val = da2_rightrotate(val, da2->gdcreg[LG_DATA_ROTATION] & 15); + bitmask &= val; + + for (uint8_t i = 0; i < 8; i++) + da2->gdcinput[i] = (da2->gdcreg[LG_SET_RESETJ] & (1 << i)) ? 0xffff : 0; + da2_gdcropW(addr, bitmask, da2); + break; + } + // da2_log("%02x%02x%02x%02x,%02x%02x%02x%02x\n", da2->vram[addr + 0], da2->vram[addr + 1], da2->vram[addr + 2], da2->vram[addr + 3] + // , da2->vram[addr + 8], da2->vram[addr + 9], da2->vram[addr + 10], da2->vram[addr + 11]); +} +static void +da2_mmio_writew(uint32_t addr, uint16_t val, void *priv) +{ + da2_t *da2 = (da2_t *) priv; + // if (da2->bitblt.exec != DA2_BLT_CIDLE) /* Bitblt is in operation. */ + // return; + // if ((addr & ~0x1ffff) != 0xA0000) return; + if (da2->ioctl[LS_MMIO] & 0x10) { +#ifdef ENABLE_DA2_DEBUGVRAM + da2_log("da2_mmio_writeW %x %x %x %x %x %x\n", da2->ioctl[LS_MMIO], da2->fctl[LF_MMIO_SEL], da2->fctl[LF_MMIO_MODE], da2->fctl[LF_MMIO_ADDR], addr, val); +#endif + da2_mmio_write(addr, val & 0xff, da2); + da2_mmio_write(addr + 1, val >> 8, da2); + } else if (!(da2->ioctl[LS_MODE] & 1)) { /* 16 color or 256 color mode */ +#ifdef ENABLE_DA2_DEBUGVRAM + da2_log("da2_mmio_writeGW %x %x %x %x %x %x\n", da2->ioctl[LS_MMIO], da2->fctl[LF_MMIO_SEL], da2->fctl[LF_MMIO_MODE], da2->fctl[LF_MMIO_ADDR], addr, val); +#endif + da2_mmio_gc_writeW(addr, val, da2); + } else { /* mode 3h text */ +#ifdef ENABLE_DA2_DEBUGVRAM + // if (addr & 0xff00 == 0) da2_log("da2_mmio_write %x %x %04X:%04X\n", addr, val, CS, cpu_state.pc); + da2_log("da2_mmio_write3W %x %x %x %x %x %x\n", da2->ioctl[LS_MMIO], da2->fctl[LF_MMIO_SEL], da2->fctl[LF_MMIO_MODE], da2->fctl[LF_MMIO_ADDR], addr, val); +#endif + da2_mmio_write(addr, val & 0xff, da2); + da2_mmio_write(addr + 1, val >> 8, da2); + } +} + +static void +da2_code_write(uint32_t addr, uint8_t val, void *priv) +{ + da2_t *da2 = (da2_t *) priv; + // if ((addr & ~0xfff) != 0xE0000) return; + addr &= DA2_MASK_CRAM; + da2->cram[addr] = val; + da2->fullchange = 2; +} +static void +da2_code_writeb(uint32_t addr, uint8_t val, void *priv) +{ + da2_t *da2 = (da2_t *) priv; + // da2_log("DA2_code_writeb: Write to %x, val %x\n", addr, val); + cycles -= video_timing_write_b; + da2_code_write(addr, val, da2); +} +static void +da2_code_writew(uint32_t addr, uint16_t val, void *priv) +{ + // da2_log("DA2_code_writ ew: Write to %x, val %x\n", addr, val); + da2_t *da2 = (da2_t *) priv; + cycles -= video_timing_write_w; + da2_code_write(addr, val & 0xff, da2); + da2_code_write(addr + 1, val >> 8, da2); +} + +static uint8_t +da2_code_read(uint32_t addr, void *priv) +{ + da2_t *da2 = (da2_t *) priv; + // if ((addr & ~DA2_MASK_CRAM) != 0xE0000) + // return DA2_INVALIDACCESS8; + addr &= DA2_MASK_CRAM; + return da2->cram[addr]; +} +static uint8_t +da2_code_readb(uint32_t addr, void *priv) +{ + da2_t *da2 = (da2_t *) priv; + cycles -= video_timing_read_b; + return da2_code_read(addr, da2); +} +static uint16_t +da2_code_readw(uint32_t addr, void *priv) +{ + da2_t *da2 = (da2_t *) priv; + cycles -= video_timing_read_w; + return da2_code_read(addr, da2) | (da2_code_read(addr + 1, da2) << 8); +} + +static void +da2_doblit(int y1, int y2, int wx, int wy, da2_t *da2) +{ + if (wx != xsize || wy != ysize) { + xsize = wx; + ysize = wy; + set_screen_size(xsize, ysize); + + if (video_force_resize_get()) + video_force_resize_set(0); + } + video_blit_memtoscreen(32, 0, xsize, ysize); + frames++; + + video_res_x = wx; + video_res_y = wy; + video_bpp = 8; +} + +static void +da2_poll(void *priv) +{ + da2_t *da2 = (da2_t *) priv; + int x; + + if (!da2->linepos) { + timer_advance_u64(&da2->timer, da2->dispofftime); + // if (output) printf("Display off %f\n",vidtime); + da2->cgastat |= 1; + da2->linepos = 1; + + if (da2->dispon) { + da2->hdisp_on = 1; + + da2->memaddr &= da2->vram_display_mask; + if (da2->firstline == 2000) { + da2->firstline = da2->displine; + video_wait_for_buffer(); + } + + if (!da2->override) + da2->render(da2); + + if (da2->lastline < da2->displine) + da2->lastline = da2->displine; + } + + // da2_log("%03i %06X %06X\n", da2->displine, da2->memaddr,da2->vram_display_mask); + da2->displine++; + if ((da2->cgastat & 8) && ((da2->displine & 0xf) == (da2->crtc[LC_VERTICAL_SYNC_END] & 0xf)) && da2->vslines) { + // da2_log("Vsync off at line %i\n",displine); + da2->cgastat &= ~8; + } + da2->vslines++; + if (da2->displine > 1200) + da2->displine = 0; + // da2_log("Col is %08X %08X %08X %i %i %08X\n",((uint32_t *)buffer32->line[displine])[320],((uint32_t *)buffer32->line[displine])[321],((uint32_t *)buffer32->line[displine])[322], + // displine, vc, memaddr); + } else { + // da2_log("VC %i memaddr %05X\n", da2->vc, da2->memaddr); + timer_advance_u64(&da2->timer, da2->dispontime); + + if (da2->dispon) + da2->cgastat &= ~1; + da2->hdisp_on = 0; + + da2->linepos = 0; + if (da2->scanline == (da2->crtc[LC_CURSOR_ROW_END] & 31)) + da2->cursorvisible = 0; + if (da2->dispon) { + if (da2->scanline == da2->rowcount) { + da2->linecountff = 0; + da2->scanline = 0; + + da2->memaddr_backup += (da2->rowoffset << 1); /* color = 0x50(80), mono = 0x40(64) */ + da2->memaddr_backup &= da2->vram_display_mask; + da2->memaddr = da2->memaddr_backup; + } else { + da2->scanline++; + da2->scanline &= 31; + da2->memaddr = da2->memaddr_backup; + } + } + + da2->vc++; + da2->vc &= 2047; + + if (da2->vc == da2->split) { + // da2->memaddr = da2->memaddr_backup = da2->hblank_sub; + da2->memaddr = da2->memaddr_backup = 0; + da2->scanline = 0; + // da2->displine = 0; + } + + if (da2->vc == da2->dispend) { + da2->dispon = 0; + // if (da2->crtc[10] & 0x20) da2->cursoron = 0; + // else da2->cursoron = da2->blink & 16; + if (da2->ioctl[LS_MODE] & 1) { /* in text mode */ + if (da2->attrc[LV_CURSOR_CONTROL] & 0x01) /* cursor blinking */ + { + da2->cursoron = (da2->blink | 1) & da2->blinkconf; + } else { + da2->cursoron = 0; + } + if (!(da2->blink & (0x10 - 1))) /* force redrawing for cursor and blink attribute */ + da2->fullchange = 2; + } + da2->blink++; + + for (x = 0; x <= (DA2_MASK_VRAMPLANE >> 9); x++) { + if (da2->changedvram[x]) + da2->changedvram[x]--; + } + // memset(changedvram,0,2048); del + if (da2->fullchange) { + da2->fullchange--; + } + } + if (da2->vc == da2->vsyncstart) { + int wx, wy; + // da2_log("VC vsync %i %i\n", da2->firstline_draw, da2->lastline_draw); + da2->dispon = 0; + da2->cgastat |= 8; + x = da2->hdisp; + + wx = x; + wy = da2->lastline - da2->firstline; + + da2_doblit(da2->firstline_draw, da2->lastline_draw + 1, wx, wy, da2); + + da2->firstline = 2000; + da2->lastline = 0; + + da2->firstline_draw = 2000; + da2->lastline_draw = 0; + + changeframecount = 2; + da2->vslines = 0; + + da2->memaddr + = da2->memaddr_backup = da2->memaddr_latch << 1; + da2->cursoraddr = ((da2->crtc[LC_CURSOR_LOC_HIGH] << 8) | da2->crtc[LC_CURSOR_LOC_LOWJ]) + da2->ca_adj; + da2->cursoraddr <<= 1; + + // da2_log("Addr %08X vson %03X vsoff %01X\n",da2->memaddr,da2->vsyncstart,da2->crtc[0x11]&0xF); + } + if (da2->vc == da2->vtotal) { + // da2_log("VC vtotal\n"); + // printf("Frame over at line %i %i %i %i\n",displine,vc,da2_vsyncstart,da2_dispend); + da2->vc = 0; + da2->scanline = da2->crtc[LC_PRESET_ROW_SCANJ] & 0x1f; + da2->dispon = 1; + da2->displine = 0; + da2->scrollcache = da2->attrc[LV_PANNING] & 7; + } + if (da2->scanline == (da2->crtc[LC_CURSOR_ROW_START] & 31)) + da2->cursorvisible = 1; + } +} + +static void +da2_loadfont(char *fname, void *priv) +{ + da2_t *da2 = (da2_t *) priv; + uint8_t buf; + uint64_t fsize; + if (!fname) + return; + if (*fname == '\0') + return; + FILE *mfile = rom_fopen(fname, "rb"); + if (!mfile) { + // da2_log("MSG: Can't open binary ROM font file: %s\n", fname); + return; + } + fseek(mfile, 0, SEEK_END); + fsize = ftell(mfile); /* get filesize */ + fseek(mfile, 0, SEEK_SET); + if (fsize > DA2_FONTROM_SIZE) { + fsize = DA2_FONTROM_SIZE; /* truncate read data */ + // da2_log("MSG: The binary ROM font is truncated: %s\n", fname); + // fclose(mfile); + // return 1; + } + uint32_t j = 0; + while (ftell(mfile) < fsize) { + (void) !fread(&buf, sizeof(uint8_t), 1, mfile); + da2->mmio.font[j] = buf; + j++; + } + fclose(mfile); + return; +} + +/* 12-bit DAC color palette for IBMJ Display Adapter with color monitor */ +static uint8_t ps55_palette_color[64][3] = { + { 0x00, 0x00, 0x00 }, { 0x00, 0x00, 0x2A }, { 0x00, 0x2A, 0x00 }, { 0x00, 0x2A, 0x2A }, + { 0x2A, 0x00, 0x00 }, { 0x2A, 0x00, 0x2A }, { 0x2A, 0x2A, 0x00 }, { 0x2A, 0x2A, 0x2A }, + { 0x00, 0x00, 0x15 }, { 0x00, 0x00, 0x3F }, { 0x00, 0x2A, 0x15 }, { 0x00, 0x2A, 0x3F }, + { 0x2A, 0x00, 0x15 }, { 0x2A, 0x00, 0x3F }, { 0x2A, 0x2A, 0x15 }, { 0x2A, 0x2A, 0x3F }, + { 0x00, 0x15, 0x00 }, { 0x00, 0x15, 0x2A }, { 0x00, 0x3F, 0x00 }, { 0x00, 0x3F, 0x2A }, + { 0x2A, 0x15, 0x00 }, { 0x2A, 0x15, 0x2A }, { 0x2A, 0x3F, 0x00 }, { 0x2A, 0x3F, 0x2A }, + { 0x00, 0x15, 0x15 }, { 0x00, 0x15, 0x3F }, { 0x00, 0x3F, 0x15 }, { 0x00, 0x3F, 0x3F }, + { 0x2A, 0x15, 0x15 }, { 0x2A, 0x15, 0x3F }, { 0x2A, 0x3F, 0x15 }, { 0x2A, 0x3F, 0x3F }, + { 0x15, 0x00, 0x00 }, { 0x15, 0x00, 0x2A }, { 0x15, 0x2A, 0x00 }, { 0x15, 0x2A, 0x2A }, + { 0x3F, 0x00, 0x00 }, { 0x3F, 0x00, 0x2A }, { 0x3F, 0x2A, 0x00 }, { 0x3F, 0x2A, 0x2A }, + { 0x15, 0x00, 0x15 }, { 0x15, 0x00, 0x3F }, { 0x15, 0x2A, 0x15 }, { 0x15, 0x2A, 0x3F }, + { 0x3F, 0x00, 0x15 }, { 0x3F, 0x00, 0x3F }, { 0x3F, 0x2A, 0x15 }, { 0x3F, 0x2A, 0x3F }, + { 0x15, 0x15, 0x00 }, { 0x15, 0x15, 0x2A }, { 0x15, 0x3F, 0x00 }, { 0x15, 0x3F, 0x2A }, + { 0x3F, 0x15, 0x00 }, { 0x3F, 0x15, 0x2A }, { 0x3F, 0x3F, 0x00 }, { 0x3F, 0x3F, 0x2A }, + { 0x15, 0x15, 0x15 }, { 0x15, 0x15, 0x3F }, { 0x15, 0x3F, 0x15 }, { 0x15, 0x3F, 0x3F }, + { 0x3F, 0x15, 0x15 }, { 0x3F, 0x15, 0x3F }, { 0x3F, 0x3F, 0x15 }, { 0x3F, 0x3F, 0x3F } +}; + +static void +da2_reset_ioctl(da2_t *da2) +{ + da2->ioctl[LS_RESET] = 0x00; /* Bit 0: Reset sequencer */ + da2_outw(LS_INDEX, 0x0302, da2); /* Index 02, Bit 1: VGA passthrough, Bit 0: Character Mode */ + da2_outw(LS_INDEX, 0x0008, da2); /* Index 08, Bit 0: Enable MMIO */ +} + +static void +da2_reset(void *priv) +{ + da2_t *da2 = (da2_t *) priv; + + /* Initialize drawing */ + da2->bitblt.exec = DA2_BLT_CIDLE; + da2_reset_ioctl(da2); + + da2->pos_regs[0] = DA2_POSID_L; /* Adapter Identification Byte (Low byte) */ + da2->pos_regs[1] = DA2_POSID_H; /* Adapter Identification Byte (High byte) */ + da2->pos_regs[2] = 0x40; /* Bit 7-5: 010=Mono, 100=Color, Bit 0 : Card Enable (set by reference diskette) */ + da2->ioctl[LS_CONFIG1] = OldLSI | Page_Two; /* Configuration 1 : DA-II, 1024 KB */ + da2->ioctl[LS_CONFIG1] |= ((da2->monitorid & 0x8) << 1); /* Configuration 1 : Monitor ID 3 */ + da2->ioctl[LS_CONFIG2] = (da2->monitorid & 0x7); /* Configuration 2: Monitor ID 0-2 */ + da2->fctl[0] = 0x2b; /* 3E3h:0 */ + da2->fctl[LF_MMIO_MODE] = 0xb0; /* 3E3h:0bh */ + da2->attrc[LV_CURSOR_COLOR] = 0x0f; /* cursor color */ + da2->crtc[LC_HORIZONTAL_TOTAL] = 63; /* Horizontal Total */ + da2->crtc[LC_VERTICAL_TOTALJ] = 255; /* Vertical Total (These two must be set before the timer starts.) */ + da2->memaddr_latch = 0; + da2->attrc[LV_CURSOR_CONTROL] = 0x13; /* cursor options */ + da2->attr_palette_enable = 0; /* disable attribute generator */ + + /* Set default color palette (Windows 3.1 display driver won't reset palette) */ + for (uint16_t i = 0; i < 256; i++) { + da2->vgapal[i].r = ps55_palette_color[i & 0x3F][0]; + da2->vgapal[i].g = ps55_palette_color[i & 0x3F][1]; + da2->vgapal[i].b = ps55_palette_color[i & 0x3F][2]; + da2->pallook[i] = makecol32((da2->vgapal[i].r & 0x3f) * 4, (da2->vgapal[i].g & 0x3f) * 4, (da2->vgapal[i].b & 0x3f) * 4); + } + da2_log("da2_reset done.\n"); +} + +static void * +da2_init(UNUSED(const device_t *info)) +{ + if (svga_get_pri() == NULL) + return NULL; + svga_t *mb_vga = svga_get_pri(); + mb_vga->cable_connected = 0; + + da2_t *da2 = calloc(1, sizeof(da2_t)); + da2->mb_vga = mb_vga; + + da2->dispontime = 1000ull << 32; + da2->dispofftime = 1000ull << 32; + da2->vram = calloc(1, DA2_SIZE_VRAM); + da2->cram = calloc(1, DA2_SIZE_CRAM); + da2->vram_display_mask = DA2_MASK_CRAM; + da2->monitorid = device_get_config_int("montype"); + da2->changedvram = calloc(1, (DA2_MASK_VRAMPLANE + 1) >> 9); /* XX000h */ + + da2->mmio.charset = device_get_config_int("charset"); + da2->mmio.font = malloc(DA2_FONTROM_SIZE); + switch (da2->mmio.charset) { + case DA2_DCONFIG_CHARSET_HANT: + da2_loadfont(DA2_FONTROM_PATH_HANT, da2); + break; + case DA2_DCONFIG_CHARSET_JPAN: + da2_loadfont(DA2_FONTROM_PATH_JPAN, da2); + /* Add magic code for OS/2 J1.3. This disables BitBlt's text drawing function. */ + da2->mmio.font[0x1AFFE] = 0x80; + da2->mmio.font[0x1AFFF] = 0x01; + break; + } + + mca_add(da2_mca_read, da2_mca_write, da2_mca_feedb, da2_mca_reset, da2); + da2->da2const = (uint64_t) ((cpuclock / DA2_PIXELCLOCK) * (double) (1ull << 32)); + memset(da2->bitblt.payload, 0x00, DA2_BLT_MEMSIZE); + memset(da2->bitblt.reg, 0xfe, DA2_BLT_REGSIZE * sizeof(uint32_t)); /* clear memory */ +#ifdef ENABLE_DA2_DEBUGBLT + da2->bitblt.debug_reg = malloc(DA2_DEBUG_BLTLOG_MAX * DA2_DEBUG_BLTLOG_SIZE); + da2->bitblt.debug_reg_ip = 0; +#endif +#ifdef ENABLE_DA2_DEBUGVRAM + da2->mmdbg_fp = fopen("da2_mmiowdat.txt", "w"); + da2->mmrdbg_fp = fopen("da2_mmiordat.txt", "w"); +#endif + da2->bitblt.payload_addr = 0; + + timer_add(&da2->timer_vidupd, da2_updatevidselector_tick, da2, 0);/* Init timer before executing reset */ + da2_reset(da2); + + mem_mapping_add(&da2->mmio.mapping, 0xA0000, 0x20000, da2_mmio_read, da2_mmio_readw, NULL, da2_mmio_write, da2_mmio_writew, NULL, NULL, MEM_MAPPING_EXTERNAL, da2); + // da2_log("DA2mmio new mapping: %X, base: %x, size: %x\n", &da2->mmio.mapping, da2->mmio.mapping.base, da2->mmio.mapping.size); + + mem_mapping_disable(&da2->mmio.mapping); + + mem_mapping_add(&da2->cmapping, 0xE0000, 0x1000, da2_code_readb, da2_code_readw, NULL, da2_code_writeb, da2_code_writew, NULL, NULL, MEM_MAPPING_EXTERNAL, da2); + + mem_mapping_disable(&da2->cmapping); + + timer_add(&da2->timer, da2_poll, da2, 0); + da2->bitblt.timerspeed = 5ull * TIMER_USEC; /* Bitblt execution speed */ + timer_add(&da2->bitblt.timer, da2_bitblt_dopayload, da2, 0); + + return da2; +} +static int +da2_available(void) +{ + return (rom_present(DA2_FONTROM_PATH_HANT) || rom_present(DA2_FONTROM_PATH_JPAN)); +} + +static void +da2_close(void *priv) +{ + da2_t *da2 = (da2_t *) priv; + + /* dump mem for debug */ +#ifdef ENABLE_DA2_LOG + FILE *fp; + fp = fopen("da2_cram.dmp", "wb"); + if (fp != NULL) { + fwrite(da2->cram, DA2_SIZE_CRAM, 1, fp); + fclose(fp); + } + fp = fopen("da2_vram.dmp", "wb"); + if (fp != NULL) { + fwrite(da2->vram, DA2_SIZE_VRAM, 1, fp); + fclose(fp); + } + fp = fopen("da2_gram.dmp", "wb"); + if (fp != NULL) { + fwrite(da2->mmio.ram, DA2_SIZE_GAIJIRAM, 1, fp); + fclose(fp); + } + fp = fopen("da2_attrpal.dmp", "wb"); + if (fp != NULL) { + fwrite(da2->attrc, 32, 1, fp); + fclose(fp); + } + fp = fopen("da2_dacrgb.dmp", "wb"); + if (fp != NULL) { + fwrite(da2->vgapal, 3 * 256, 1, fp); + fclose(fp); + } + fp = fopen("da2_daregs.txt", "w"); + if (fp != NULL) { + for (uint8_t i = 0; i < 0x10; i++) + fprintf(fp, "3e1(ioctl) %02X: %4X\n", i, da2->ioctl[i]); + for (uint8_t i = 0; i < 0x20; i++) + fprintf(fp, "3e3(fctl) %02X: %4X\n", i, da2->fctl[i]); + for (uint8_t i = 0; i < 0x20; i++) + fprintf(fp, "3e5(crtc) %02X: %4X\n", i, da2->crtc[i]); + for (uint8_t i = 0; i < 0x40; i++) + fprintf(fp, "3e8(attr) %02X: %4X\n", i, da2->attrc[i]); + for (uint8_t i = 0; i < 0x10; i++) + fprintf(fp, "3eb(gcr) %02X: %4X\n", i, da2->gdcreg[i]); + for (uint8_t i = 0; i < 0x10; i++) + fprintf(fp, "3ee(?) %02X: %4X\n", i, da2->reg3ee[i]); + for (uint8_t i = 0; i < 0x20; i++) { + fprintf(fp, "vp %02X: %4X %4X %4X %4X\n", i, + da2->crtc_vpreg[0 + i], da2->crtc_vpreg[0x20 + i], da2->crtc_vpreg[0x40 + i], da2->crtc_vpreg[0x60 + i]); + } + fclose(fp); + } + fp = fopen("ram_low.dmp", "wb"); + if (fp != NULL) { + fwrite(&ram[0x0], 0x100000, 1, fp); + fclose(fp); + } + pclog("closed %04X:%04X DS %04X\n", cs >> 4, cpu_state.pc, DS); +#endif +#ifdef ENABLE_DA2_DEBUGBLT + fp = fopen("da2_bltdump.csv", "w"); + if (fp != NULL && da2->bitblt.debug_reg_ip > 0) { + /* print header */ + for (int y = 0; y < DA2_DEBUG_BLTLOG_SIZE; y++) { + if (da2->bitblt.debug_reg[(da2->bitblt.debug_reg_ip - 1) * DA2_DEBUG_BLTLOG_SIZE + y] != DA2_DEBUG_BLT_NEVERUSED) + fprintf(fp, "\"%02X\"\t", y); + } + fprintf(fp, "\n"); + /* print data */ + for (int x = 0; x < da2->bitblt.debug_reg_ip; x++) { + for (int y = 0; y < DA2_DEBUG_BLTLOG_SIZE; y++) { + if (da2->bitblt.debug_reg[x * DA2_DEBUG_BLTLOG_SIZE + y] == DA2_DEBUG_BLT_NEVERUSED) + ; + else if (da2->bitblt.debug_reg[x * DA2_DEBUG_BLTLOG_SIZE + y] == DA2_DEBUG_BLT_USEDRESET) + fprintf(fp, "\"\"\t"); + else { + fprintf(fp, "\"%X\"\t", da2->bitblt.debug_reg[x * DA2_DEBUG_BLTLOG_SIZE + y]); + if (y == 0x12) { + int chr = da2->bitblt.debug_reg[x * DA2_DEBUG_BLTLOG_SIZE + 0x12]; + if ((chr >= 0x20) && (chr < 0x7f)) + fprintf(fp, "\"%c\"\t", chr); + else + fprintf(fp, "\"\"\t"); + } + } + } + fprintf(fp, "\n"); + } + fclose(fp); + } + free(da2->bitblt.debug_reg); +#endif +#ifdef ENABLE_DA2_DEBUGVRAM + if (da2->mmdbg_fp != NULL) + fclose(da2->mmdbg_fp); + if (da2->mmrdbg_fp != NULL) + fclose(da2->mmrdbg_fp); +#endif + free(da2->cram); + free(da2->vram); + free(da2->changedvram); + free(da2->mmio.font); + free(da2); +} + +static void +da2_speed_changed(void *priv) +{ + da2_t *da2 = (da2_t *) priv; + da2->da2const = (uint64_t) ((cpuclock / DA2_PIXELCLOCK) * (double) (1ull << 32)); + da2_recalctimings(da2); +} + +static void +da2_force_redraw(void *priv) +{ + da2_t *da2 = (da2_t *) priv; + da2->fullchange = changeframecount; +} + +static const device_config_t da2_configuration[] = { + // clang-format off + { + .name = "charset", + .description = "Character set", + .type = CONFIG_SELECTION, + .default_int = DA2_DCONFIG_CHARSET_JPAN, + .selection = { + { + .description = "932 (Japanese)", + .value = DA2_DCONFIG_CHARSET_JPAN + }, + { + .description = "938 (Traditional Chinese)", + .value = DA2_DCONFIG_CHARSET_HANT + }, + { .description = "" } + } + }, + { + .name = "montype", + .description = "Monitor type", + .type = CONFIG_SELECTION, + .default_int = DA2_DCONFIG_MONTYPE_COLOR, + .selection = { + { + .description = "Color", + .value = DA2_DCONFIG_MONTYPE_COLOR + }, + { + .description = "IBM 8515", + .value = DA2_DCONFIG_MONTYPE_8515 + }, + { + .description = "Grayscale", + .value = DA2_DCONFIG_MONTYPE_MONO + }, + { .description = "" } + } + }, + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on +}; + +const device_t ps55da2_device = { + .name = "IBM Display Adapter II (MCA)", + .internal_name = "ps55da2", + .flags = DEVICE_MCA, + .local = 0, + .init = da2_init, + .close = da2_close, + .reset = da2_reset, + .available = da2_available, + .speed_changed = da2_speed_changed, + .force_redraw = da2_force_redraw, + .config = da2_configuration +}; + +void +da2_device_add(void) +{ + if (!da2_standalone_enabled) + return; + + if (machine_has_bus(machine, MACHINE_BUS_MCA)) + device_add(&ps55da2_device); + else + return; +} diff --git a/src/video/vid_rtg310x.c b/src/video/vid_rtg310x.c index e82763d15..813d30bf3 100644 --- a/src/video/vid_rtg310x.c +++ b/src/video/vid_rtg310x.c @@ -180,7 +180,7 @@ rtg_out(uint16_t addr, uint8_t val, void *priv) 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); + svga->memaddr_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5); } else { svga->fullchange = changeframecount; svga_recalctimings(svga); @@ -211,7 +211,7 @@ rtg_recalctimings(svga_t *svga) { const rtg_t *dev = (rtg_t *) svga->priv; - svga->ma_latch |= ((svga->crtc[0x19] & 0x10) << 16) | ((svga->crtc[0x19] & 0x40) << 17); + svga->memaddr_latch |= ((svga->crtc[0x19] & 0x10) << 16) | ((svga->crtc[0x19] & 0x40) << 17); svga->interlace = (svga->crtc[0x19] & 1); @@ -387,58 +387,43 @@ rtg3106_available(void) static const device_config_t rtg3105_config[] = { // clang-format off { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 512, - .selection = { - { - .description = "256 KB", - .value = 256 - }, - { - .description = "512 KB", - .value = 512 - }, - { - .description = "" - } - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 512, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "256 KB", .value = 256 }, + { .description = "512 KB", .value = 512 }, + { .description = "" } + }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; static const device_config_t rtg3106_config[] = { // clang-format off { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 1024, - .selection = { - { - .description = "256 KB", - .value = 256 - }, - { - .description = "512 KB", - .value = 512 - }, - { - .description = "1 MB", - .value = 1024 - }, - { - .description = "" - } - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 1024, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "256 KB", .value = 256 }, + { .description = "512 KB", .value = 512 }, + { .description = "1 MB", .value = 1024 }, + { .description = "" } + }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -450,7 +435,7 @@ const device_t realtek_rtg3105_device = { .init = rtg_init, .close = rtg_close, .reset = NULL, - { .available = rtg3105_available }, + .available = rtg3105_available, .speed_changed = rtg_speed_changed, .force_redraw = rtg_force_redraw, .config = rtg3105_config @@ -464,7 +449,7 @@ const device_t realtek_rtg3106_device = { .init = rtg_init, .close = rtg_close, .reset = NULL, - { .available = rtg3106_available }, + .available = rtg3106_available, .speed_changed = rtg_speed_changed, .force_redraw = rtg_force_redraw, .config = rtg3106_config diff --git a/src/video/vid_s3.c b/src/video/vid_s3.c index bb5c283ad..d0495dca0 100644 --- a/src/video/vid_s3.c +++ b/src/video/vid_s3.c @@ -54,6 +54,7 @@ #define ROM_MIROCRYSTAL20SV_964_PCI "roms/video/s3/mirocrystal.VBI" #define ROM_MIROCRYSTAL20SD_864_VLB "roms/video/s3/Miro20SD.BIN" #define ROM_PHOENIX_86C80X "roms/video/s3/805.VBI" +#define ROM_WINNER1000_805 "roms/video/s3/v01_05_00-C.BIN" #define ROM_PARADISE_BAHAMAS64 "roms/video/s3/bahamas64.bin" #define ROM_PHOENIX_VISION864 "roms/video/s3/86c864p.bin" #define ROM_DIAMOND_STEALTH64_964 "roms/video/s3/964_107h.rom" @@ -117,7 +118,8 @@ enum { S3_NUMBER9_9FX_771, S3_SPEA_MERCURY_LITE_PCI, S3_86C805_ONBOARD, - S3_DIAMOND_STEALTH64_968 + S3_DIAMOND_STEALTH64_968, + S3_WINNER1000_805 }; enum { @@ -234,6 +236,8 @@ typedef struct s3_t { uint8_t advfunc_cntl; uint16_t cur_y, cur_y2; uint16_t cur_x, cur_x2; + uint16_t cur_x_overflow; + uint16_t destx_overflow; uint16_t x2, ropmix; uint16_t pat_x, pat_y; int16_t desty_axstp, desty_axstp2; @@ -245,6 +249,8 @@ typedef struct s3_t { uint32_t pat_bg_color, pat_fg_color; uint32_t bkgd_color; uint32_t frgd_color; + uint16_t bkgd_color_back; + uint16_t frgd_color_back; uint32_t wrt_mask; uint32_t rd_mask; uint32_t color_cmp; @@ -253,7 +259,8 @@ typedef struct s3_t { uint16_t multifunc_cntl; uint16_t multifunc[16]; uint8_t pix_trans[4]; - uint16_t pix_trans_val; + uint8_t pix_trans_val[2048][2048]; + int pix_trans_inc; int ssv_state; int16_t cx, cy; @@ -281,7 +288,13 @@ typedef struct s3_t { uint8_t bkgd_color_actual[2]; uint8_t wrt_mask_actual[2]; int color_16bit_check; + int color_16bit_check_pixtrans; int16_t minus; + int16_t minus_src_24bpp; + int rd_mask_16bit_check; + int start; + int mix_dat_upper; + int overflow; /*For non-threaded FIFO*/ int setup_fifo_slot; @@ -537,15 +550,15 @@ static void s3_visionx68_video_engine_op(uint32_t cpu_dat, s3_t *s3); #define READ_PIXTRANS_BYTE_MM \ 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) { \ - 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 \ +#define READ_PIXTRANS_WORD \ + 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 \ temp = vram_w[dword_remap_w(svga, (s3->accel.dest + s3->accel.cx - s3->accel.minus)) & (s3->vram_mask >> 1)]; #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); \ @@ -611,18 +624,34 @@ s3_accel_out_pixtrans_w(s3_t *s3, uint16_t val) if (((s3->accel.frgd_mix & 0x60) != 0x40) || ((s3->accel.bkgd_mix & 0x60) != 0x40)) { if (s3->accel.cmd & 0x1000) val = (val >> 8) | (val << 8); + s3->accel_start(8, 1, val | (val << 16), 0, s3); } else { - if ((s3->bpp == 0) && s3->color_16bit) + if ((s3->bpp == 0) && s3->color_16bit) { + if (s3->accel.rd_mask_16bit_check) { + if (s3->accel.cur_x & 0x400) + val = (val >> 8) | (val << 8); + } else { + if (s3->accel.cur_x & 0x400) + s3->accel.color_16bit_check_pixtrans = 1; + else + s3->accel.color_16bit_check_pixtrans = 0; + } s3->accel_start(2, 1, 0xffffffff, val | (val << 16), s3); - else + } else s3->accel_start(1, 1, 0xffffffff, val | (val << 16), s3); } } else { if ((s3->bpp == 0) && s3->color_16bit) { - if (s3->accel.cur_x & 0x400) - val = (val >> 8) | (val << 8); - + if (s3->accel.rd_mask_16bit_check) { + if (s3->accel.cur_x & 0x400) + val = (val >> 8) | (val << 8); + } else { + if (s3->accel.cur_x & 0x400) + s3->accel.color_16bit_check_pixtrans = 1; + else + s3->accel.color_16bit_check_pixtrans = 0; + } s3->accel_start(2, 1, 0xffffffff, val | (val << 16), s3); } else s3->accel_start(1, 1, 0xffffffff, val | (val << 16), s3); @@ -635,12 +664,29 @@ s3_accel_out_pixtrans_w(s3_t *s3, uint16_t val) val = (val >> 8) | (val << 8); s3->accel_start(16, 1, val | (val << 16), 0, s3); - } else + } else { + if (s3->accel.rd_mask_16bit_check) { + if ((s3->accel.cmd == 0x53f1) || (s3->accel.cmd == 0x53b1)) { + if (s3->accel.cur_x & 0x400) + val = (val >> 8) | (val << 8); + + s3->accel_start(2, 1, 0xffffffff, val | (val << 16), s3); + + val = (val >> 8) | (val << 8); + } + } s3->accel_start(2, 1, 0xffffffff, val | (val << 16), s3); + } } else { - if ((s3->bpp == 0) && s3->color_16bit) { - if (s3->accel.cur_x & 0x400) + if (s3->accel.rd_mask_16bit_check) { + if ((s3->accel.cmd == 0x53f1) || (s3->accel.cmd == 0x53b1)) { + if (s3->accel.cur_x & 0x400) + val = (val >> 8) | (val << 8); + + s3->accel_start(2, 1, 0xffffffff, val | (val << 16), s3); + val = (val >> 8) | (val << 8); + } } s3->accel_start(2, 1, 0xffffffff, val | (val << 16), s3); } @@ -763,6 +809,7 @@ s3_accel_out_fifo(s3_t *s3, uint16_t port, uint8_t val) case 0x82e9: s3->accel.cur_y = (s3->accel.cur_y & 0xff) | ((val & 0x0f) << 8); s3->accel.poly_cy = s3->accel.cur_y; + s3_log("[%04X:%08X] OUT PORTB=%04x, valy=%d.\n", CS, cpu_state.pc, port - 1, s3->accel.cur_y); break; case 0x814a: case 0x82ea: @@ -778,15 +825,17 @@ s3_accel_out_fifo(s3_t *s3, uint16_t port, uint8_t val) case 0x8548: case 0x86e8: s3->accel.cur_x = (s3->accel.cur_x & 0xf00) | val; + s3->accel.cur_x_overflow = (s3->accel.cur_x_overflow & 0xff00) | val; s3->accel.poly_cx = s3->accel.cur_x << 20; s3->accel.poly_x = s3->accel.poly_cx >> 20; break; case 0x8549: case 0x86e9: s3->accel.cur_x = (s3->accel.cur_x & 0xff) | ((val & 0x0f) << 8); + s3->accel.cur_x_overflow = (s3->accel.cur_x_overflow & 0xff) | (val << 8); s3->accel.poly_cx = s3->accel.poly_x = s3->accel.cur_x << 20; s3->accel.poly_x = s3->accel.poly_cx >> 20; - s3_log("[%04X:%08X] OUT PORTB=%04x, val=%04x.\n", CS, cpu_state.pc, port - 1, s3->accel.cur_x); + s3_log("[%04X:%08X] OUT PORTB=%04x, valx=%d, valxover=%d.\n", CS, cpu_state.pc, port - 1, s3->accel.cur_x, s3->accel.cur_x_overflow); break; case 0x854a: case 0x86ea: @@ -829,11 +878,13 @@ s3_accel_out_fifo(s3_t *s3, uint16_t port, uint8_t val) case 0x8d48: case 0x8ee8: s3->accel.destx_distp = (s3->accel.destx_distp & 0x3f00) | val; + s3->accel.destx_overflow = (s3->accel.destx_overflow & 0xff00) | val; s3->accel.point_1_updated = 1; break; case 0x8d49: case 0x8ee9: s3->accel.destx_distp = (s3->accel.destx_distp & 0xff) | ((val & 0x3f) << 8); + s3->accel.destx_overflow = (s3->accel.destx_overflow & 0xff) | (val << 8); if (val & 0x20) s3->accel.destx_distp |= ~0x3fff; s3->accel.point_1_updated = 1; @@ -877,6 +928,7 @@ s3_accel_out_fifo(s3_t *s3, uint16_t port, uint8_t val) case 0x9459: case 0x96e9: s3->accel.maj_axis_pcnt = (s3->accel.maj_axis_pcnt & 0xff) | ((val & 0x0f) << 8); + s3_log("[%04X:%08X] OUT PORTB=%04x, valmajx=%d.\n", CS, cpu_state.pc, port - 1, s3->accel.maj_axis_pcnt); break; case 0x954a: case 0x96ea: @@ -923,6 +975,9 @@ s3_accel_out_fifo(s3_t *s3, uint16_t port, uint8_t val) s3->accel.short_stroke = (s3->accel.short_stroke & 0xff) | (val << 8); s3->accel.ssv_state = 1; + s3->accel.cx = s3->accel.cur_x & 0xfff; + s3->accel.cy = s3->accel.cur_y & 0xfff; + if (s3->accel.cmd & 0x1000) { s3_short_stroke_start(s3, s3->accel.short_stroke & 0xff); s3_short_stroke_start(s3, s3->accel.short_stroke >> 8); @@ -1034,7 +1089,6 @@ s3_accel_out_fifo(s3_t *s3, uint16_t port, uint8_t val) break; case 0xa549: case 0xa6e9: - s3_log("[%04X:%08X] OUT PORTB=%04x (Foreground Color), val=%02x.\n", CS, cpu_state.pc, port, val); if (s3->bpp == 3) { if ((s3->chip >= S3_86C928) && (s3->chip < S3_VISION964)) { if (s3->accel.multifunc[0xe] & 0x10) @@ -1257,7 +1311,7 @@ s3_accel_out_fifo(s3_t *s3, uint16_t port, uint8_t val) case 0xb148: case 0xb2e8: s3_log("[%04X:%08X] OUT PORTB=%04x, val=%02x, CMD=%04x, C(%d,%d).\n", CS, cpu_state.pc, port, val, s3->accel.cmd, s3->accel.cur_x, s3->accel.cur_y); - if (s3->accel.multifunc[0xe] & 0x100) { + if ((s3->accel.multifunc[0xe] & 0x100) || (s3->chip >= S3_VISION964)) { s3->accel.b2e8_pix = 0; if (s3->bpp == 3) { if ((s3->chip >= S3_86C928) && (s3->chip < S3_VISION964)) { @@ -1299,7 +1353,7 @@ s3_accel_out_fifo(s3_t *s3, uint16_t port, uint8_t val) case 0xb149: case 0xb2e9: s3_log("[%04X:%08X] OUT PORTB=%04x, val=%02x, CMD=%04x, C(%d,%d).\n", CS, cpu_state.pc, port, val, s3->accel.cmd, s3->accel.cur_x, s3->accel.cur_y); - if (s3->accel.multifunc[0xe] & 0x100) { + if ((s3->accel.multifunc[0xe] & 0x100) || (s3->chip >= S3_VISION964)) { s3->accel.b2e8_pix = 0; if (s3->bpp == 3) { if ((s3->chip >= S3_86C928) && (s3->chip < S3_VISION964)) { @@ -1447,6 +1501,8 @@ s3_accel_out_fifo(s3_t *s3, uint16_t port, uint8_t val) case 0xbee9: s3->accel.multifunc_cntl = (s3->accel.multifunc_cntl & 0xff) | (val << 8); s3->accel.multifunc[s3->accel.multifunc_cntl >> 12] = s3->accel.multifunc_cntl & 0xfff; + if ((s3->accel.multifunc_cntl >> 12) == 5) + s3_log("S3 multifunc_cntl = %d, val = %03x.\n", s3->accel.multifunc_cntl >> 12, s3->accel.multifunc_cntl & 0xfff); break; case 0xd148: @@ -1586,13 +1642,36 @@ s3_accel_out_fifo(s3_t *s3, uint16_t port, uint8_t val) s3->accel_start(1, 1, 0xffffffff, s3->accel.pix_trans[0], s3); } else { if ((s3->bpp == 0) && s3->color_16bit) { - s3->accel.pix_trans[1] = svga->vram[dword_remap(svga, (s3->accel.dest + s3->accel.cx - s3->accel.minus)) & s3->vram_mask]; - if (s3->accel.cur_x & 0x400) { - s3_log("Last Pixel Written=%02x (1024).\n", s3->accel.pix_trans[1]); - s3->accel_start(2, 1, 0xffffffff, s3->accel.pix_trans[1] | (s3->accel.pix_trans[0] << 8), s3); + if (s3->accel.rd_mask_16bit_check) { + s3->accel.pix_trans[1] = svga->vram[dword_remap(svga, (s3->accel.dest + s3->accel.cx - s3->accel.minus)) & s3->vram_mask]; + if (s3->accel.cmd & 0x1000) { + if (s3->accel.cur_x & 0x400) { + s3_log("Last Pixel Written=%02x (1024) reverse.\n", s3->accel.pix_trans[1]); + s3->accel_start(2, 1, 0xffffffff, s3->accel.pix_trans[0] | (s3->accel.pix_trans[1] << 8), s3); + } else { + s3_log("Last Pixel Written=%02x (0) reverse, cx=%d.\n", s3->accel.pix_trans[1], s3->accel.cx, s3->accel.cur_x); + s3->accel_start(2, 1, 0xffffffff, s3->accel.pix_trans[1] | (s3->accel.pix_trans[0] << 8), s3); + } + } else { + if (s3->accel.cur_x & 0x400) { + s3_log("Last Pixel Written=%02x (1024) normal, cx=%d, curx=%d.\n", s3->accel.pix_trans[1], s3->accel.cx, s3->accel.cur_x); + s3->accel_start(2, 1, 0xffffffff, s3->accel.pix_trans[1] | (s3->accel.pix_trans[0] << 8), s3); + } else { + s3_log("Last Pixel Written=%02x (0) normal, cx=%d, curx=%d.\n", s3->accel.pix_trans[1], s3->accel.cx, s3->accel.cur_x); + s3->accel_start(2, 1, 0xffffffff, s3->accel.pix_trans[0] | (s3->accel.pix_trans[1] << 8), s3); + } + } } else { - s3_log("Last Pixel Written=%02x (0).\n", s3->accel.pix_trans[1]); - s3->accel_start(2, 1, 0xffffffff, s3->accel.pix_trans[0] | (s3->accel.pix_trans[1] << 8), s3); + s3->accel.pix_trans_val[s3->accel.cy][s3->accel.cx] = val; + + if (s3->accel.cur_x & 0x400) { + s3->accel.color_16bit_check_pixtrans = 0; + s3_log("%04X:%08X: Last Pixel Written=%04x (1024) normal, cx=%d, cy=%d.\n", CS, cpu_state.pc, s3->accel.pix_trans_val[s3->accel.cy][s3->accel.cx - s3->accel.minus] | (s3->accel.pix_trans_val[s3->accel.cy][s3->accel.cx] << 8), s3->accel.cx, s3->accel.cy); + s3->accel_start(2, 1, 0xffffffff, s3->accel.pix_trans_val[s3->accel.cy][s3->accel.cx - s3->accel.minus] | (s3->accel.pix_trans_val[s3->accel.cy][s3->accel.cx] << 8), s3); + } else { + s3->accel.color_16bit_check_pixtrans = 1; + s3->accel_start(2, 1, 0xffffffff, s3->accel.pix_trans[0], s3); + } } } else s3->accel_start(1, 1, 0xffffffff, s3->accel.pix_trans[0], s3); @@ -1785,6 +1864,9 @@ s3_accel_out_fifo_w(s3_t *s3, uint16_t port, uint16_t val) s3->accel.short_stroke = val; s3->accel.ssv_state = 1; + s3->accel.cx = s3->accel.cur_x & 0xfff; + s3->accel.cy = s3->accel.cur_y & 0xfff; + if (s3->accel.cmd & 0x1000) { s3_short_stroke_start(s3, s3->accel.short_stroke & 0xff); s3_short_stroke_start(s3, s3->accel.short_stroke >> 8); @@ -2158,7 +2240,7 @@ s3_hwcursor_draw(svga_t *svga, int displine) const s3_t *s3 = (s3_t *) svga->priv; int shift = 1; int width = 16; - uint16_t dat[2] = { 0, 0 }; + uint16_t dat[4] = { 0, 0, 0, 0 }; int xx; int offset = svga->hwcursor_latch.x - svga->hwcursor_latch.xoff; uint32_t fg; @@ -2170,30 +2252,53 @@ s3_hwcursor_draw(svga_t *svga, int displine) case 15: fg = video_15to32[s3->hwc_fg_col & 0xffff]; bg = video_15to32[s3->hwc_bg_col & 0xffff]; - if (s3->chip >= S3_86C928 && s3->chip <= S3_86C805) { - if (s3->card_type != S3_MIROCRYSTAL10SD_805 && s3->card_type != S3_MIROCRYSTAL8S_805) { - if (!(svga->crtc[0x45] & 0x04)) { - shift = 2; - width = 8; + if ((s3->chip >= S3_86C928) && (s3->chip <= S3_86C805)) { + if (!s3->color_16bit) { + if ((s3->card_type != S3_MIROCRYSTAL10SD_805) && (s3->card_type != S3_MIROCRYSTAL8S_805)) { + if (!(svga->crtc[0x45] & 0x04)) { + shift = 2; + width = 8; + } } + } else { + shift = 2; + width = 8; + fg = svga->pallook[svga->crtc[0xe]]; + bg = svga->pallook[svga->crtc[0xf]]; } + } else if (s3->chip <= S3_86C924) { + shift = 2; + width = 8; + fg = svga->pallook[svga->crtc[0xe]]; + bg = svga->pallook[svga->crtc[0xf]]; } break; case 16: fg = video_16to32[s3->hwc_fg_col & 0xffff]; bg = video_16to32[s3->hwc_bg_col & 0xffff]; - if (s3->chip >= S3_86C928 && s3->chip <= S3_86C805) { - if ((s3->card_type != S3_MIROCRYSTAL10SD_805) && (s3->card_type != S3_MIROCRYSTAL8S_805)) { - if (!(svga->crtc[0x45] & 0x04)) { - shift = 2; - width = 8; - } - } else if (s3->card_type == S3_MIROCRYSTAL10SD_805) { - if (!(svga->crtc[0x45] & 0x04)) { - offset <<= 1; + if ((s3->chip >= S3_86C928) && (s3->chip <= S3_86C805)) { + if (!s3->color_16bit) { + if ((s3->card_type != S3_MIROCRYSTAL10SD_805) && (s3->card_type != S3_MIROCRYSTAL8S_805)) { + if (!(svga->crtc[0x45] & 0x04)) { + shift = 2; + width = 8; + } + } else if (s3->card_type == S3_MIROCRYSTAL10SD_805) { + if (!(svga->crtc[0x45] & 0x04)) + offset <<= 1; } + } else { + shift = 2; + width = 8; + fg = svga->pallook[svga->crtc[0xe]]; + bg = svga->pallook[svga->crtc[0xf]]; } + } else if (s3->chip <= S3_86C924) { + shift = 2; + width = 8; + fg = svga->pallook[svga->crtc[0xe]]; + bg = svga->pallook[svga->crtc[0xf]]; } break; @@ -2230,40 +2335,62 @@ s3_hwcursor_draw(svga_t *svga, int displine) for (uint8_t x = 0; x < 64; x += 16) { remapped_addr = dword_remap(svga, real_addr); + if (((svga->bpp == 15) || (svga->bpp == 16)) && s3->color_16bit) { + dat[0] = svga->vram[remapped_addr & s3->vram_mask]; + dat[1] = svga->vram[(remapped_addr + 1) & s3->vram_mask]; + dat[2] = svga->vram[(remapped_addr + 2) & s3->vram_mask]; + dat[3] = svga->vram[(remapped_addr + 3) & s3->vram_mask]; - dat[0] = (svga->vram[remapped_addr & s3->vram_mask] << 8) | svga->vram[(remapped_addr + 1) & s3->vram_mask]; - dat[1] = (svga->vram[(remapped_addr + 2) & s3->vram_mask] << 8) | svga->vram[(remapped_addr + 3) & s3->vram_mask]; - - if (svga->crtc[0x55] & 0x10) { - /*X11*/ - for (xx = 0; xx < 16; xx++) { - if (offset >= 0) { - if (dat[0] & 0x8000) - buffer32->line[displine][offset + svga->x_add] = (dat[1] & 0x8000) ? fg : bg; - } - - offset++; - dat[0] <<= shift; - dat[1] <<= shift; - } - } else { /*Windows*/ - for (xx = 0; xx < width; xx++) { + for (xx = 0; xx < 8; xx++) { if (offset >= 0) { - if (!(dat[0] & 0x8000)) - buffer32->line[displine][offset + svga->x_add] = (dat[1] & 0x8000) ? fg : bg; - else if (dat[1] & 0x8000) + if (!(dat[(xx & 4) ? 2 : 0] & 0x80)) + buffer32->line[displine][offset + svga->x_add] = (dat[(xx & 4) ? 3 : 1] & 0x80) ? fg : bg; + else if (dat[(xx & 4) ? 3 : 1] & 0x80) buffer32->line[displine][offset + svga->x_add] ^= 0xffffff; } offset++; - dat[0] <<= shift; - dat[1] <<= shift; + s3_log("Up: Data0=%04x, Data1=%04x, Data2=%04x, Data3=%04x, xx=%d addr=%06x.\n", dat[0], dat[1], dat[2], dat[3], xx, remapped_addr); + dat[(xx & 4) ? 2 : 0] <<= 2; + dat[(xx & 4) ? 3 : 1] <<= 2; + } + } else { + dat[0] = (svga->vram[remapped_addr & s3->vram_mask] << 8) | svga->vram[(remapped_addr + 1) & s3->vram_mask]; + dat[1] = (svga->vram[(remapped_addr + 2) & s3->vram_mask] << 8) | svga->vram[(remapped_addr + 3) & s3->vram_mask]; + + if (svga->crtc[0x55] & 0x10) { + /*X11*/ + for (xx = 0; xx < 16; xx++) { + if (offset >= 0) { + if (dat[0] & 0x8000) + buffer32->line[displine][offset + svga->x_add] = (dat[1] & 0x8000) ? fg : bg; + } + + offset++; + dat[0] <<= shift; + dat[1] <<= shift; + } + } else { + /*Windows*/ + for (xx = 0; xx < width; xx++) { + if (offset >= 0) { + if (!(dat[0] & 0x8000)) + buffer32->line[displine][offset + svga->x_add] = (dat[1] & 0x8000) ? fg : bg; + else if (dat[1] & 0x8000) + buffer32->line[displine][offset + svga->x_add] ^= 0xffffff; + } + + offset++; + dat[0] <<= shift; + dat[1] <<= shift; + } } } svga->hwcursor_latch.addr += 4; real_addr = s3_hwcursor_convert_addr(svga); } + if (svga->interlace && !svga->hwcursor_oddeven) svga->hwcursor_latch.addr += 16; } @@ -2806,10 +2933,10 @@ s3_out(uint16_t addr, uint8_t val, void *priv) 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->chip == S3_86C924)) && + } else if (((s3->chip == S3_86C801) || (s3->chip == S3_86C805)) && ((s3->card_type != S3_MIROCRYSTAL10SD_805) && (s3->card_type != S3_MIROCRYSTAL8S_805))) att49x_ramdac_out(addr, rs2, val, svga->ramdac, svga); - else if (s3->chip == S3_86C911) { + else if (s3->chip <= S3_86C924) { sc1148x_ramdac_out(addr, rs2, val, svga->ramdac, svga); } else if (s3->card_type == S3_NUMBER9_9FX_531) att498_ramdac_out(addr, rs2, val, svga->ramdac, svga); @@ -2846,7 +2973,7 @@ s3_out(uint16_t addr, uint8_t val, void *priv) break; case 0x40: - s3->enable_8514 = (val & 0x01); + s3->enable_8514 = val & 0x01; break; case 0x50: @@ -2910,7 +3037,7 @@ s3_out(uint16_t addr, uint8_t val, void *priv) break; case 0x45: - if (s3->chip == S3_VISION964 || s3->chip == S3_VISION968) + if ((s3->chip == S3_VISION964) || (s3->chip == S3_VISION968)) break; svga->hwcursor.ena = val & 1; break; @@ -2922,7 +3049,7 @@ s3_out(uint16_t addr, uint8_t val, void *priv) case 0x4d: case 0x4e: case 0x4f: - if (s3->chip == S3_VISION964 || s3->chip == S3_VISION968) + if ((s3->chip == S3_VISION964) || (s3->chip == S3_VISION968)) break; svga->hwcursor.x = ((svga->crtc[0x46] << 8) | svga->crtc[0x47]) & 0x7ff; if (svga->bpp == 32) @@ -2931,14 +3058,14 @@ s3_out(uint16_t addr, uint8_t val, void *priv) svga->hwcursor.xoff = svga->crtc[0x4e] & 0x3f; svga->hwcursor.yoff = svga->crtc[0x4f] & 0x3f; svga->hwcursor.addr = ((((svga->crtc[0x4c] << 8) | svga->crtc[0x4d]) & 0xfff) * 1024) + (svga->hwcursor.yoff * 16); - if ((s3->chip >= S3_TRIO32) && svga->bpp == 32) + if ((s3->chip >= S3_TRIO32) && (svga->bpp == 32)) svga->hwcursor.x <<= 1; - else if ((s3->chip >= S3_86C928 && s3->chip <= S3_86C805) && (svga->bpp == 15 || svga->bpp == 16)) { - if ((s3->card_type == S3_MIROCRYSTAL10SD_805) && !(svga->crtc[0x45] & 0x04) && svga->bpp == 16) + else if ((s3->chip >= S3_86C928 && s3->chip <= S3_86C805) && ((svga->bpp == 15) || (svga->bpp == 16))) { + if ((s3->card_type == S3_MIROCRYSTAL10SD_805) && !(svga->crtc[0x45] & 0x04) && (svga->bpp == 16)) svga->hwcursor.x >>= 2; else svga->hwcursor.x >>= 1; - } else if ((s3->chip >= S3_86C928 && s3->chip <= S3_86C805) && (svga->bpp == 24)) + } else if ((s3->chip >= S3_86C928) && (s3->chip <= S3_86C805) && (svga->bpp == 24)) svga->hwcursor.x /= 3; else if ((s3->chip <= S3_86C805) && s3->color_16bit) svga->hwcursor.x >>= 1; @@ -3052,9 +3179,9 @@ s3_out(uint16_t addr, uint8_t val, void *priv) 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); + svga->memaddr_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5); if ((((svga->crtc[0x67] & 0xc) != 0xc) && (s3->chip >= S3_TRIO64V)) || (s3->chip < S3_TRIO64V)) - svga->ma_latch |= (s3->ma_ext << 16); + svga->memaddr_latch |= (s3->ma_ext << 16); } else { svga->fullchange = svga->monitor->mon_changeframecount; svga_recalctimings(svga); @@ -3131,10 +3258,10 @@ s3_in(uint16_t addr, void *priv) 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); return tvp3026_ramdac_in(addr, rs2, rs3, svga->ramdac, svga); - } else if (((s3->chip == S3_86C801) || (s3->chip == S3_86C805) || (s3->chip == S3_86C924)) && + } else if (((s3->chip == S3_86C801) || (s3->chip == S3_86C805)) && ((s3->card_type != S3_MIROCRYSTAL10SD_805) && (s3->card_type != S3_MIROCRYSTAL8S_805))) return att49x_ramdac_in(addr, rs2, svga->ramdac, svga); - else if (s3->chip == S3_86C911) + else if (s3->chip <= S3_86C924) return sc1148x_ramdac_in(addr, rs2, svga->ramdac, svga); else if (s3->card_type == S3_NUMBER9_9FX_531) return att498_ramdac_in(addr, rs2, svga->ramdac, svga); @@ -3376,7 +3503,7 @@ s3_recalctimings(svga_t *svga) } svga->hdisp = svga->hdisp_old; - svga->ma_latch |= (s3->ma_ext << 16); + svga->memaddr_latch |= (s3->ma_ext << 16); svga->lowres = (!!(svga->attrregs[0x10] & 0x40) && !(svga->crtc[0x3a] & 0x10)); @@ -3443,7 +3570,8 @@ s3_recalctimings(svga_t *svga) if (s3->chip <= S3_86C805) { s3->color_16bit = !!(svga->crtc[0x43] & 0x08); - if (svga->bpp == 24) + s3_log("Color 16bit=%x, bpp=%d, 256color=%x.\n", s3->color_16bit, svga->bpp, (svga->attrregs[0x10] & 0x40)); + if ((svga->bpp == 24) || (svga->bpp == 8)) s3->color_16bit = 0; if (s3->color_16bit) @@ -3513,34 +3641,6 @@ s3_recalctimings(svga_t *svga) } } -#ifdef OLD_CODE_REFERENCE - if (s3->card_type == S3_MIROCRYSTAL10SD_805 || s3->card_type == S3_MIROCRYSTAL20SD_864 || s3->card_type == S3_MIROCRYSTAL20SV_964 || s3->card_type == S3_SPEA_MIRAGE_86C801 || s3->card_type == S3_SPEA_MIRAGE_86C805 || s3->card_type == S3_MIROCRYSTAL8S_805 || s3->card_type == S3_NUMBER9_9FX_531 || s3->card_type == S3_SPEA_MERCURY_LITE_PCI) { - if (!(svga->crtc[0x5e] & 0x04)) - svga->vblankstart = svga->dispend; - if (svga->bpp != 32) { - if (svga->crtc[0x31] & 2) - s3->width = 2048; - else { - if (s3->card_type == S3_MIROCRYSTAL10SD_805) { - if (svga->hdisp == 1280 && s3->width == 1024) { - s3->width = 1280; - } - } - } - } else { - if (s3->card_type == S3_NUMBER9_9FX_531) { - if ((svga->hdisp == 1600) && (s3->width == 1600)) - s3->width = 800; - } - } - } else if (s3->chip == S3_86C928) { - if (svga->bpp == 15) { - if (s3->width == 800) - s3->width = 1024; - } - } -#endif - if ((svga->crtc[0x3a] & 0x10) && !svga->lowres) { s3_log("BPP=%d, pitch=%d, width=%02x, double?=%x, 16bit?=%d, highres?=%d, " "attr=%02x, hdisp=%d.\n", svga->bpp, s3->width, svga->crtc[0x50], @@ -3659,29 +3759,6 @@ s3_recalctimings(svga_t *svga) default: break; } -#ifdef OLD_CODE_REFERENCE - if (s3->chip != S3_VISION868) { - if (s3->chip == S3_86C928) { - if (s3->width == 2048 || s3->width == 1280 || s3->width == 1600) { - if ((s3->width != 1600) && (svga->dispend == 1024) && (svga->hdisp != 1280)) - svga->hdisp <<= 2; - else - svga->hdisp <<= 1; - } - } else if ((s3->chip != S3_86C801) && (s3->chip != S3_86C805) && (s3->chip != S3_TRIO32) && (s3->chip != S3_TRIO64) && (s3->chip != S3_VISION964) && (s3->chip != S3_VISION968)) { - if (s3->width == 1280 || s3->width == 1600) - svga->hdisp <<= 1; - } else if ((s3->card_type == S3_ELSAWIN2KPROX_964) || (s3->card_type == S3_ELSAWIN2KPROX)) { - if (s3->width == 1280 || s3->width == 1600) - svga->hdisp <<= 1; - } else if (s3->card_type == S3_SPEA_MERCURY_P64V) { - if (s3->width == 1280 || s3->width == 1600) - svga->hdisp <<= 1; - } - } else if (s3->card_type == S3_NUMBER9_9FX_771) - svga->hdisp <<= 1; - } -#endif break; case 15: svga->render = svga_render_15bpp_highres; @@ -3707,6 +3784,7 @@ s3_recalctimings(svga_t *svga) switch (s3->card_type) { case S3_MIROCRYSTAL8S_805: case S3_MIROCRYSTAL10SD_805: + case S3_WINNER1000_805: case S3_PHOENIX_86C805: case S3_86C805_ONBOARD: svga->hdisp >>= 1; @@ -3850,29 +3928,6 @@ s3_recalctimings(svga_t *svga) default: break; } -#ifdef OLD_CODE_REFERENCE - if ((s3->chip != S3_VISION964) && (s3->card_type != S3_SPEA_MIRAGE_86C801) && (s3->card_type != S3_SPEA_MIRAGE_86C805)) { - if (s3->chip == S3_86C928) - svga->hdisp <<= 1; - else if (s3->chip != S3_VISION968) - svga->hdisp >>= 1; - } - if ((s3->chip != S3_VISION868) && (s3->chip != S3_TRIO32) && (s3->chip != S3_TRIO64) && (s3->chip != S3_VISION964)) { - if (s3->width == 1280 || s3->width == 1600) - svga->hdisp <<= 1; - else if (s3->card_type == S3_NUMBER9_9FX_771) - svga->hdisp <<= 1; - } - if (s3->card_type == S3_MIROVIDEO40SV_ERGO_968 || s3->card_type == S3_PHOENIX_VISION968 || s3->card_type == S3_SPEA_MERCURY_P64V) { - if (svga->hdisp == (1408 * 2)) - svga->hdisp >>= 1; - else - svga->hdisp = s3->width; - } - - if (s3->card_type == S3_SPEA_MIRAGE_86C801 || s3->card_type == S3_SPEA_MIRAGE_86C805 || s3->card_type == S3_SPEA_MERCURY_LITE_PCI) - svga->hdisp = s3->width; -#endif break; case 16: svga->render = svga_render_16bpp_highres; @@ -3898,6 +3953,7 @@ s3_recalctimings(svga_t *svga) switch (s3->card_type) { case S3_MIROCRYSTAL8S_805: case S3_MIROCRYSTAL10SD_805: + case S3_WINNER1000_805: case S3_PHOENIX_86C805: case S3_86C805_ONBOARD: svga->hdisp >>= 1; @@ -4038,35 +4094,6 @@ s3_recalctimings(svga_t *svga) default: break; } - -#ifdef OLD_CODE_REFERENCE - if ((s3->card_type == S3_ELSAWIN2KPROX_964) || (s3->card_type == S3_ELSAWIN2KPROX)) { - if (s3->width == 1280 || s3->width == 1600) - svga->hdisp <<= 1; - } - if ((s3->chip != S3_VISION964) && (s3->card_type != S3_SPEA_MIRAGE_86C801) && (s3->card_type != S3_SPEA_MIRAGE_86C805)) { - if (s3->chip == S3_86C928) - svga->hdisp <<= 1; - else if (s3->chip != S3_VISION968) - svga->hdisp >>= 1; - } else if ((s3->card_type == S3_SPEA_MIRAGE_86C801) || (s3->card_type == S3_SPEA_MIRAGE_86C805)) - svga->hdisp >>= 1; - if ((s3->chip != S3_VISION868) && (s3->chip != S3_TRIO32) && (s3->chip != S3_TRIO64) && (s3->chip != S3_VISION964)) { - if (s3->width == 1280 || s3->width == 1600) - svga->hdisp <<= 1; - else if (s3->card_type == S3_NUMBER9_9FX_771) - svga->hdisp <<= 1; - } - if (s3->card_type == S3_MIROVIDEO40SV_ERGO_968 || s3->card_type == S3_PHOENIX_VISION968 || s3->card_type == S3_SPEA_MERCURY_P64V) { - if (svga->hdisp == (1408 << 1)) - svga->hdisp >>= 1; - else - svga->hdisp = s3->width; - } - - if (s3->card_type == S3_SPEA_MIRAGE_86C801 || s3->card_type == S3_SPEA_MIRAGE_86C805 || s3->card_type == S3_SPEA_MERCURY_LITE_PCI) - svga->hdisp = s3->width; -#endif break; case 24: svga->render = svga_render_24bpp_highres; @@ -4099,6 +4126,7 @@ s3_recalctimings(svga_t *svga) switch (s3->card_type) { case S3_MIROCRYSTAL8S_805: case S3_MIROCRYSTAL10SD_805: + case S3_WINNER1000_805: case S3_PHOENIX_86C805: case S3_SPEA_MIRAGE_86C805: case S3_86C805_ONBOARD: @@ -4144,34 +4172,6 @@ s3_recalctimings(svga_t *svga) default: break; } -#ifdef OLD_CODE_REFERENCE - if (s3->chip != S3_VISION968) { - if (s3->chip != S3_86C928 && s3->chip != S3_86C801 && s3->chip != S3_86C805) - svga->hdisp /= 3; - else - svga->hdisp = (svga->hdisp * 2) / 3; - - if (s3->card_type == S3_SPEA_MERCURY_LITE_PCI) { - if (s3->width == 2048) { - switch (svga->dispend) { - case 480: - svga->hdisp = 640; - break; - - default: - break; - } - } - } else if (s3->chip == S3_86C924) { - if (svga->dispend == 480) - svga->hdisp = 640; - } - } else { - if ((s3->card_type == S3_MIROVIDEO40SV_ERGO_968) || - (s3->card_type == S3_PHOENIX_VISION968) || (s3->card_type == S3_SPEA_MERCURY_P64V)) - svga->hdisp = s3->width; - } -#endif break; case 32: svga->render = svga_render_32bpp_highres; @@ -4256,48 +4256,6 @@ s3_recalctimings(svga_t *svga) default: break; } -#ifdef OLD_CODE_REFERENCE - if ((s3->chip < S3_TRIO32) && (s3->chip != S3_VISION964) && (s3->chip != S3_VISION968) && (s3->chip != S3_86C928)) { - if (s3->chip == S3_VISION868) - svga->hdisp >>= 1; - else - svga->hdisp >>= 2; - } - if (s3->width == 1280 || s3->width == 1600 || (s3->card_type == S3_SPEA_MERCURY_P64V || s3->card_type == S3_NUMBER9_9FX_771)) - svga->hdisp <<= 1; - if (s3->card_type == S3_NUMBER9_9FX_771) { - if (svga->hdisp == 832) - svga->hdisp -= 32; - } - if (s3->card_type == S3_MIROVIDEO40SV_ERGO_968 || s3->card_type == S3_MIROCRYSTAL20SV_964 || s3->card_type == S3_MIROCRYSTAL20SD_864 || s3->card_type == S3_PHOENIX_VISION968 || s3->card_type == S3_SPEA_MERCURY_P64V) { - svga->hdisp = s3->width; - if (s3->card_type == S3_MIROCRYSTAL20SD_864 || s3->card_type == S3_MIROCRYSTAL20SV_964) { - if (s3->width == 800 || s3->width == 1024 || s3->width == 1600) { - switch (svga->dispend) { - case 400: - case 480: - svga->hdisp = 640; - break; - - case 576: - if (s3->width == 1600) - s3->width = 800; - svga->hdisp = 768; - break; - - case 600: - if (s3->width == 1600) - s3->width = 800; - svga->hdisp = 800; - break; - - default: - break; - } - } - } - } -#endif break; default: @@ -4356,7 +4314,7 @@ s3_trio64v_recalctimings(svga_t *svga) svga->htotal |= 0x100; if (svga->crtc[0x5d] & 0x02) { svga->hdisp_time |= 0x100; - svga->hdisp |= 0x100 * svga->dots_per_clock; + svga->hdisp |= (0x100 * svga->dots_per_clock); } if (svga->crtc[0x5e] & 0x01) svga->vtotal |= 0x400; @@ -4421,7 +4379,7 @@ s3_trio64v_recalctimings(svga_t *svga) if ((svga->crtc[0x67] & 0xc) != 0xc) /*VGA mode*/ { - svga->ma_latch |= (s3->ma_ext << 16); + svga->memaddr_latch |= (s3->ma_ext << 16); if (svga->crtc[0x51] & 0x30) svga->rowoffset |= (svga->crtc[0x51] & 0x30) << 4; else if (svga->crtc[0x43] & 0x04) @@ -4469,9 +4427,9 @@ s3_trio64v_recalctimings(svga_t *svga) } else /*Streams mode*/ { if (s3->streams.buffer_ctrl & 1) - svga->ma_latch = s3->streams.pri_fb1 >> 2; + svga->memaddr_latch = s3->streams.pri_fb1 >> 2; else - svga->ma_latch = s3->streams.pri_fb0 >> 2; + svga->memaddr_latch = s3->streams.pri_fb0 >> 2; svga->hdisp = s3->streams.pri_w + 1; if (s3->streams.pri_h < svga->dispend) @@ -4675,6 +4633,7 @@ s3_trio64_getclock(int clock, void *priv) return 25175000.0; if (clock == 1) return 28322000.0; + m = svga->seqregs[0x13] + 2; n1 = (svga->seqregs[0x12] & 0x1f) + 2; n2 = ((svga->seqregs[0x12] >> 5) & 0x07); @@ -5829,6 +5788,8 @@ s3_accel_in_w(uint16_t port, void *priv) s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; uint16_t temp = 0x0000; + uint16_t temp1 = 0x0000; + uint16_t temp2 = 0x0000; const uint16_t *vram_w = (uint16_t *) svga->vram; if (!s3->enable_8514) @@ -5840,37 +5801,59 @@ s3_accel_in_w(uint16_t port, void *priv) switch (s3->accel.cmd & 0x600) { case 0x000: - if (((s3->accel.multifunc[0xa] & 0xc0) == 0x80) || (s3->accel.cmd & 2)) { + if (((s3->accel.multifunc[0xa] & 0xc0) == 0x80) || (s3->accel.cmd & 0x02)) { if (((s3->accel.frgd_mix & 0x60) != 0x40) || ((s3->accel.bkgd_mix & 0x60) != 0x40)) { if (s3->accel.cmd & 0x1000) temp = (temp >> 8) | (temp << 8); + s3->accel_start(8, 1, temp | (temp << 16), 0, s3); } else { - if ((s3->bpp == 0) && s3->color_16bit) + if ((s3->bpp == 0) && s3->color_16bit) { + if (s3->accel.rd_mask_16bit_check) { + if (s3->accel.cur_x & 0x400) + temp = (temp >> 8) | (temp << 8); + } s3->accel_start(2, 1, 0xffffffff, temp | (temp << 16), s3); - else + } else s3->accel_start(1, 1, 0xffffffff, temp | (temp << 16), s3); } } else { if ((s3->bpp == 0) && s3->color_16bit) { - if (s3->accel.cur_x & 0x400) - temp = ((temp >> 8) | (temp << 8)) & 0xffff; - + if (s3->accel.rd_mask_16bit_check) { + if (s3->accel.cur_x & 0x400) + temp = (temp >> 8) | (temp << 8); + } s3->accel_start(2, 1, 0xffffffff, temp | (temp << 16), s3); } else s3->accel_start(1, 1, 0xffffffff, temp | (temp << 16), s3); } break; case 0x200: - if (((s3->accel.multifunc[0xa] & 0xc0) == 0x80) || (s3->accel.cmd & 2)) { + if (((s3->accel.multifunc[0xa] & 0xc0) == 0x80) || (s3->accel.cmd & 0x02)) { if (((s3->accel.frgd_mix & 0x60) != 0x40) || ((s3->accel.bkgd_mix & 0x60) != 0x40)) { if (s3->accel.cmd & 0x1000) temp = (temp >> 8) | (temp << 8); + s3->accel_start(16, 1, temp | (temp << 16), 0, s3); } else s3->accel_start(2, 1, 0xffffffff, temp | (temp << 16), s3); } else { - s3->accel_start(2, 1, 0xffffffff, temp | (temp << 16), s3); + if (s3->accel.rd_mask_16bit_check) { + if (s3->accel.cmd == 0x53b0) { + temp1 = vram_w[dword_remap_w(svga, s3->accel.dest + s3->accel.cx - s3->accel.minus) & (s3->vram_mask >> 1)]; + temp2 = vram_w[dword_remap_w(svga, s3->accel.dest + s3->accel.cx - s3->accel.minus + 1) & (s3->vram_mask >> 1)]; + if (s3->accel.cur_x & 0x400) { + temp = temp1 >> 8; + temp |= (temp2 >> 8) << 8; + } else { + temp = temp1 & 0xff; + temp |= ((temp2 & 0xff) << 8); + } + s3->accel_start(4, 1, 0xffffffff, temp | (temp << 16), s3); + } else + s3->accel_start(2, 1, 0xffffffff, temp | (temp << 16), s3); + } else + s3->accel_start(2, 1, 0xffffffff, temp | (temp << 16), s3); } break; @@ -5881,6 +5864,7 @@ s3_accel_in_w(uint16_t port, void *priv) } else { if (s3_enable_fifo(s3)) s3_wait_fifo_idle(s3); + temp = s3->accel.short_stroke; } @@ -6577,9 +6561,9 @@ polygon_setup(s3_t *s3) #define READ(addr, dat) \ if (((s3->bpp == 0) && !s3->color_16bit) || (s3->bpp == 2)) \ 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 \ + else \ dat = vram_l[dword_remap_l(svga, addr) & (s3->vram_mask >> 2)]; #define MIX_READ \ @@ -6636,11 +6620,10 @@ polygon_setup(s3_t *s3) } \ } -#define MIX \ - { \ - old_dest_dat = dest_dat; \ - MIX_READ \ - dest_dat = (dest_dat & wrt_mask) | (old_dest_dat & ~wrt_mask); \ +#define MIX \ + { \ + MIX_READ \ + dest_dat = (dest_dat & wrt_mask) | (old_dest_dat & ~wrt_mask); \ } #define ROPMIX_READ(D, P, S) \ @@ -7425,14 +7408,14 @@ polygon_setup(s3_t *s3) } #define WRITE(addr, dat) \ - if (((s3->bpp == 0) && !s3->color_16bit) || (s3->bpp == 2)) { \ - svga->vram[dword_remap(svga, addr) & s3->vram_mask] = dat; \ + if (((s3->bpp == 0) && !s3->color_16bit) || (s3->bpp == 2)) { \ + 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 { \ - vram_l[dword_remap_l(svga, addr) & (s3->vram_mask >> 2)] = dat; \ + vram_l[dword_remap_l(svga, addr) & (s3->vram_mask >> 2)] = dat; \ svga->changedvram[(dword_remap_l(svga, addr) & (s3->vram_mask >> 2)) >> 10] = svga->monitor->mon_changeframecount; \ } @@ -7861,7 +7844,10 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi uint32_t srcbase; uint32_t dstbase; - if ((s3->chip >= S3_TRIO64 || s3->chip == S3_VISION968 || s3->chip == S3_VISION868) && (s3->accel.cmd & (1 << 11))) + frgd_mix = (s3->accel.frgd_mix >> 5) & 3; + bkgd_mix = (s3->accel.bkgd_mix >> 5) & 3; + + if (((s3->chip >= S3_TRIO64) || (s3->chip == S3_VISION968) || (s3->chip == S3_VISION868)) && (s3->accel.cmd & (1 << 11))) cmd |= 0x08; // SRC-BASE/DST-BASE @@ -7886,32 +7872,6 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi if ((s3->accel.cmd & 0x100) && (s3_cpu_src(s3) || (s3_cpu_dest(s3))) && (!cpu_input || (s3_enable_fifo(s3) == 0))) s3->force_busy = 1; - if ((s3->bpp == 0) && s3->color_16bit && !s3->accel.b2e8_pix) { - if (cmd <= 2) { - if (s3->accel.cur_x & 0x400) { - if (s3->accel.cmd != 0x41b3) - wrt_mask = (wrt_mask << 8) & 0xff00; - else - wrt_mask &= 0xff; - - frgd_color = (frgd_color << 8) & 0xff00; - bkgd_color = (bkgd_color << 8) & 0xff00; - } else { - if (clip_r >= 0x400) { - wrt_mask &= 0xff; - frgd_color &= 0xff; - bkgd_color &= 0xff; - } - } - } else if (cmd == 6) { - if (s3->accel.destx_distp & 0x400) { - wrt_mask = (wrt_mask << 8) & 0xff00; - frgd_color = (frgd_color << 8) & 0xff00; - bkgd_color = (bkgd_color << 8) & 0xff00; - } - } - } - if (!cpu_input) s3->accel.dat_count = 0; @@ -7960,21 +7920,15 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi break; } - frgd_mix = (s3->accel.frgd_mix >> 5) & 3; - bkgd_mix = (s3->accel.bkgd_mix >> 5) & 3; - /*Bit 4 of the Command register is the draw yes bit, which enables writing to memory/reading from memory when enabled. When this bit is disabled, no writing to memory/reading from memory is allowed. (This bit is almost meaningless on the NOP command)*/ - s3_log("CMD=%d, full=%04x, s3bpp=%x, multifuncE=%03x, sourcedisplay=%x, mmio=%02x, srcbase=%08x, dstbase=%08x, cpu=%04x, mix=%04x, count=%d, rd_mask=%04x, wrt_mask=%04x, width=%d, s=%d,%d, c=%d,%d, d=%d,%d, 16bitcolor=%x, frgdcolor=%04x, bkgdcolor=%04x, frgdsel=%d, bkgdsel=%d, frgdmix=%02x, svgabpp=%d.\n", cmd, s3->accel.cmd, s3->bpp, s3->accel.multifunc[0x0e], vram_mask, svga->crtc[0x53] & 0x18, srcbase, dstbase, cpu_dat & 0xffff, mix_dat & 0xffff, count, rd_mask, wrt_mask, s3->width, s3->accel.sx, s3->accel.sy, s3->accel.cx, s3->accel.cy, s3->accel.dx, s3->accel.dy, s3->color_16bit, frgd_color, bkgd_color, frgd_mix, bkgd_mix, s3->accel.frgd_mix & 0x0f, svga->bpp); + s3_log("CMD=%d, full=%04x, s3bpp=%x, clr=%d, clb=%d, sourcedisplay=%02x, mmio=%02x, srcbase=%08x, dstbase=%08x, cpu=%04x, mix=%04x, count=%d, rd_mask=%04x, wrt_mask=%04x, width=%d, s=%d,%d, c=%d,%d, d=%d,%d, 16bitcolor=%x, frgdcolor=%04x, bkgdcolor=%04x, frgdsel=%d, bkgdsel=%d, frgdmix=%02x, curx=%d, cury=%d, cll=%d, b2e8pix=%x.\n", cmd, s3->accel.cmd, s3->bpp, clip_r, clip_b, s3->accel.multifunc[0x0a] & 0xc4, svga->crtc[0x53] & 0x18, srcbase, dstbase, cpu_dat & 0xffff, mix_dat & 0xffff, count, rd_mask, wrt_mask, s3->width, s3->accel.sx, s3->accel.sy, s3->accel.cx, s3->accel.cy, s3->accel.dx, s3->accel.dy, s3->color_16bit, frgd_color, bkgd_color, frgd_mix, bkgd_mix, s3->accel.frgd_mix & 0x0f, s3->accel.cur_x, s3->accel.cur_y, clip_l, s3->accel.b2e8_pix); switch (cmd) { case 0: /*NOP (Short Stroke Vectors)*/ - if (s3->accel.ssv_state == 0) { - s3->accel.cx = s3->accel.cur_x & 0xfff; - s3->accel.cy = s3->accel.cur_y & 0xfff; + if (s3->accel.ssv_state == 0) break; - } if (s3->accel.cmd & 0x08) { /*Radial*/ while (count-- && s3->accel.ssv_len >= 0) { @@ -8015,6 +7969,7 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi if (update) { READ((s3->accel.cy * s3->width) + s3->accel.cx, dest_dat); + old_dest_dat = dest_dat; MIX if (s3->accel.ssv_draw) { @@ -8079,18 +8034,52 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi case 1: /*Draw line*/ if (!cpu_input) { + s3->accel.rd_mask_16bit_check = 0; s3->accel.minus = 0; + s3->accel.color_16bit_check_pixtrans = 0; s3->accel.cx = s3->accel.cur_x & 0xfff; s3->accel.cy = s3->accel.cur_y & 0xfff; + s3->accel.sy = s3->accel.maj_axis_pcnt; - if ((s3->bpp == 0) && s3->color_16bit && (s3->accel.cur_x & 0x400)) - s3->accel.minus = 0x400; + if ((s3->bpp == 0) && s3->color_16bit) { + s3->accel.rd_mask_16bit_check = ((rd_mask & 0xff00) != 0xff00) && rd_mask; + if (s3->accel.rd_mask_16bit_check) { + if ((s3->accel.cur_x_overflow & 0xc00) == 0xc00) + s3->accel.start = 1; + else { + if (s3->accel.start) { + s3->accel.start = 0; + s3->accel.minus = 0x400; + } else { + s3->accel.start = 0; + if (s3->accel.cur_x_overflow & 0x400) + s3->accel.minus = 0x400; + } + } + } + } if (s3_cpu_src(s3)) return; /*Wait for data from CPU*/ } if (s3->accel.cmd & 0x08) { /*Radial*/ + if ((s3->bpp == 0) && s3->color_16bit) { + if (s3->accel.rd_mask_16bit_check) { + if (s3->accel.minus) { + wrt_mask = (s3->accel.wrt_mask_actual[1] << 8); + frgd_color = (s3->accel.frgd_color_actual[1] << 8); + bkgd_color = (s3->accel.bkgd_color_actual[1] << 8); + } else { + wrt_mask = s3->accel.wrt_mask_actual[0]; + frgd_color = s3->accel.frgd_color_actual[0]; + bkgd_color = s3->accel.bkgd_color_actual[0]; + } + rd_mask &= 0x00ff; + } else if (!s3->accel.rd_mask_16bit_check && (s3->accel.cur_x & 0x400)) + break; + } + while (count-- && s3->accel.sy >= 0) { 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) { switch ((mix_dat & mix_mask) ? frgd_mix : bkgd_mix) { @@ -8129,6 +8118,7 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi if (update) { READ((s3->accel.cy * s3->width) + s3->accel.cx - s3->accel.minus, dest_dat); + old_dest_dat = dest_dat; MIX WRITE((s3->accel.cy * s3->width) + s3->accel.cx - s3->accel.minus, dest_dat); @@ -8142,8 +8132,15 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi else cpu_dat >>= 16; - if (!s3->accel.sy) + if (!s3->accel.sy) { + if (s3->accel.rd_mask_16bit_check) { + if (s3->accel.minus) + s3->accel.color_16bit_check = 0; + else + s3->accel.color_16bit_check = 1; + } break; + } switch (s3->accel.cmd & 0xe0) { case 0x00: @@ -8185,17 +8182,54 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi s3->accel.cur_x = s3->accel.cx & 0xfff; s3->accel.cur_y = s3->accel.cy & 0xfff; } 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)) { /*Pattern on pixtrans (911/924)*/ count = s3->accel.maj_axis_pcnt + 1; s3->accel.temp_cnt = 16; + if ((s3->bpp == 0) && s3->color_16bit) { + if (s3->accel.rd_mask_16bit_check) { + if (s3->accel.minus) { + wrt_mask = (s3->accel.wrt_mask_actual[1] << 8); + frgd_color = (s3->accel.frgd_color_actual[1] << 8); + bkgd_color = (s3->accel.bkgd_color_actual[1] << 8); + } else { + wrt_mask = s3->accel.wrt_mask_actual[0]; + frgd_color = s3->accel.frgd_color_actual[0]; + bkgd_color = s3->accel.bkgd_color_actual[0]; + } + rd_mask &= 0x00ff; + } else if (!s3->accel.rd_mask_16bit_check && (s3->accel.cur_x & 0x400)) + break; + } + } else { + if ((s3->bpp == 0) && s3->color_16bit) { + if (s3->accel.rd_mask_16bit_check) { + if (s3->accel.minus) { + wrt_mask = (s3->accel.wrt_mask_actual[1] << 8); + frgd_color = (s3->accel.frgd_color_actual[1] << 8); + bkgd_color = (s3->accel.bkgd_color_actual[1] << 8); + } else { + wrt_mask = s3->accel.wrt_mask_actual[0]; + frgd_color = s3->accel.frgd_color_actual[0]; + bkgd_color = s3->accel.bkgd_color_actual[0]; + } + rd_mask &= 0x00ff; + } else if (!s3->accel.rd_mask_16bit_check && (s3->accel.cur_x & 0x400)) + break; + } } - while (count-- && s3->accel.sy >= 0) { + if (!s3->accel.b2e8_pix) + s3_log("CMDFULL=%04x, FRGDMIX=%x, FRGDCOLR=%04x, RDMASK=%04x, MINUS=%d, WRTMASK=%04X, MIX=%04x, CX=%d, CY=%d, SX=%d, SY=%d, PIXCNTL=%02x, 16BITCOLOR=%x, RDCHECK=%x, CLIPL=%d, CLIPR=%d, CLIPT=%d, CLIPB=%d.\n", s3->accel.cmd, frgd_mix, s3->accel.frgd_color, rd_mask, s3->accel.minus, wrt_mask, mix_dat & 0xffff, s3->accel.cx, s3->accel.cy, s3->accel.sx, s3->accel.sy, s3->accel.multifunc[0x0a] & 0xc4, s3->accel.color_16bit_check, s3->accel.rd_mask_16bit_check, clip_l, clip_r, clip_t, clip_b); + + while (count-- && (s3->accel.sy >= 0)) { if (s3->accel.b2e8_pix && s3_cpu_src(s3) && !s3->accel.temp_cnt) { mix_dat >>= 16; s3->accel.temp_cnt = 16; } + if (s3->accel.minus) + s3_log("Total pixel cx=%d, cy=%d.\n", s3->accel.cx - s3->accel.minus, s3->accel.cy); + 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) { switch ((mix_dat & mix_mask) ? frgd_mix : bkgd_mix) { case 0: @@ -8233,6 +8267,7 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi if (update) { READ((s3->accel.cy * s3->width) + s3->accel.cx - s3->accel.minus, dest_dat); + old_dest_dat = dest_dat; MIX WRITE((s3->accel.cy * s3->width) + s3->accel.cx - s3->accel.minus, dest_dat); @@ -8255,8 +8290,15 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi else cpu_dat >>= 16; - if (!s3->accel.sy) + if (!s3->accel.sy) { + if (s3->accel.rd_mask_16bit_check) { + if (s3->accel.minus) + s3->accel.color_16bit_check = 0; + else + s3->accel.color_16bit_check = 1; + } break; + } if (s3->accel.cmd & 0x40) { if (s3->accel.cmd & 0x80) @@ -8301,20 +8343,68 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi if (!cpu_input) /*!cpu_input is trigger to start operation*/ { s3->accel.minus = 0; + s3->accel.mix_dat_upper = 0; + s3->accel.color_16bit_check_pixtrans = 0; s3->accel.sx = s3->accel.maj_axis_pcnt & 0xfff; s3->accel.sy = s3->accel.multifunc[0] & 0xfff; s3->accel.cx = s3->accel.cur_x & 0xfff; s3->accel.cy = s3->accel.cur_y & 0xfff; - if ((s3->bpp == 0) && s3->color_16bit && (s3->accel.cur_x & 0x400)) - s3->accel.minus = 0x400; - - if (s3->accel.cur_x & 0x400) - s3_log("Rectangle Fill + 1024 FULLCMD=%04x: frgdcolor=%04x, s(%d,%d), c(%d,%d).\n", s3->accel.cmd, frgd_color, s3->accel.sx, s3->accel.sy, s3->accel.cx, s3->accel.cy); - else - s3_log("Rectangle Fill + 0 FULLCMD=%04x: frgdcolor=%04x, s(%d,%d), c(%d,%d).\n", s3->accel.cmd, frgd_color, s3->accel.sx, s3->accel.sy, s3->accel.cx, s3->accel.cy); s3->accel.dest = dstbase + s3->accel.cy * s3->width; + if ((s3->bpp == 0) && s3->color_16bit) { + s3->accel.rd_mask_16bit_check = ((rd_mask & 0xff00) != 0xff00) && rd_mask; + if (s3->accel.rd_mask_16bit_check) { + if (s3->accel.cmd == 0x41b3) { + if (frgd_mix == 0) { + if (!(s3->accel.cur_x & 0x400)) + s3->accel.color_16bit_check = 0; + } else { + if ((s3->accel.cur_x_overflow & 0xc00) == 0xc00) + s3->accel.start = 1; + else { + if (s3->accel.start) { + s3->accel.start = 0; + s3->accel.minus = 0x400; + } else { + s3->accel.start = 0; + if (s3->accel.cur_x_overflow & 0x400) + s3->accel.minus = 0x400; + } + } + } + } else { + if ((s3->accel.cur_x_overflow & 0xc00) == 0xc00) + s3->accel.start = 1; + else { + if (s3->accel.start) { + s3->accel.start = 0; + s3->accel.minus = 0x400; + } else { + s3->accel.start = 0; + if (s3->accel.cur_x_overflow & 0x400) + s3->accel.minus = 0x400; + } + } + } + } else { + if (s3->accel.cmd & 0x100) { + if (mix_mask == 0x80) { + if (s3->accel.cur_x & 0x400) + s3->accel.minus = 0x400; + else + s3->accel.minus = 0; + } + } + } + } else + s3->accel.rd_mask_16bit_check = 0; + + if (s3->accel.cur_x & 0x400) + s3_log("Rectangle Fill + 1024 FULLCMD=%04x: frgdcolor=%04x, s=%d,%d, c=%d,%d, frmix=%x, bkmix=%x, pixcntl=%02x, m2=%d, m4=%d.\n", s3->accel.cmd, s3->accel.frgd_color_actual[1] << 8, s3->accel.sx, s3->accel.sy, s3->accel.cx, s3->accel.cy, frgd_mix, bkgd_mix, s3->accel.multifunc[0xa] & 0xc0, s3->accel.multifunc[2], s3->accel.multifunc[4]); + else + s3_log("Rectangle Fill + 0 FULLCMD=%04x: frgdcolor=%04x, s=%d,%d, c=%d,%d, frmix=%x, bkmix=%x, pixcntl=%02x, m2=%d, m4=%d.\n", s3->accel.cmd, s3->accel.frgd_color_actual[0], s3->accel.sx, s3->accel.sy, s3->accel.cx, s3->accel.cy, frgd_mix, bkgd_mix, s3->accel.multifunc[0xa] & 0xc0, s3->accel.multifunc[2], s3->accel.multifunc[4]); + if (s3_cpu_src(s3)) { s3->data_available = 0; return; /*Wait for data from CPU*/ @@ -8324,11 +8414,83 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi } } - 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)) { /*Pattern on pixtrans (911/924)*/ count = s3->accel.maj_axis_pcnt + 1; s3->accel.temp_cnt = 16; + if (s3->accel.rd_mask_16bit_check) { + if (s3->accel.minus) { + wrt_mask = (s3->accel.wrt_mask_actual[1] << 8); + frgd_color = (s3->accel.frgd_color_actual[1] << 8); + bkgd_color = (s3->accel.bkgd_color_actual[1] << 8); + } else { + wrt_mask = s3->accel.wrt_mask_actual[0]; + frgd_color = s3->accel.frgd_color_actual[0]; + bkgd_color = s3->accel.bkgd_color_actual[0]; + } + rd_mask &= 0x00ff; + } else if (!s3->accel.rd_mask_16bit_check && (s3->accel.cur_x & 0x400)) + break; + } else { + if ((s3->bpp == 0) && s3->color_16bit) { + if (s3->accel.cmd == 0x41b3) { + if (frgd_mix != 0) { + if (s3->accel.rd_mask_16bit_check) { + if (s3->accel.minus) { + wrt_mask = (s3->accel.wrt_mask_actual[1] << 8); + frgd_color = (s3->accel.frgd_color_actual[1] << 8); + bkgd_color = (s3->accel.bkgd_color_actual[1] << 8); + } else { + wrt_mask = s3->accel.wrt_mask_actual[0]; + frgd_color = s3->accel.frgd_color_actual[0]; + bkgd_color = s3->accel.bkgd_color_actual[0]; + } + rd_mask &= 0x00ff; + } else if (!s3->accel.rd_mask_16bit_check && (s3->accel.cur_x & 0x400)) + break; + } else { + if (s3->accel.rd_mask_16bit_check) { + if (s3->accel.minus) { + wrt_mask = (s3->accel.wrt_mask_actual[1] << 8); + frgd_color = (s3->accel.frgd_color_actual[1] << 8); + bkgd_color = (s3->accel.bkgd_color_actual[1] << 8); + } else { + wrt_mask = s3->accel.wrt_mask_actual[0]; + frgd_color = s3->accel.frgd_color_actual[0]; + bkgd_color = s3->accel.bkgd_color_actual[0]; + s3->accel.mix_dat_upper = !!(mix_dat & 0xff00); + } + rd_mask &= 0x00ff; + } + } + } else { + if (s3->accel.rd_mask_16bit_check) { + if (s3->accel.minus) { + wrt_mask = (s3->accel.wrt_mask_actual[1] << 8); + frgd_color = (s3->accel.frgd_color_actual[1] << 8); + bkgd_color = (s3->accel.bkgd_color_actual[1] << 8); + } else { + wrt_mask = s3->accel.wrt_mask_actual[0]; + frgd_color = s3->accel.frgd_color_actual[0]; + bkgd_color = s3->accel.bkgd_color_actual[0]; + } + rd_mask &= 0x00ff; + } else { + if ((s3_cpu_src(s3)) && !(s3->accel.cmd & 0x200)) { + s3_log("FIXME: S3 911/924 15/16bpp documentation needed.\n"); + } else { + if (!cpu_input && (s3->accel.cur_x & 0x400)) { + s3_log("No Input.\n"); + break; + } else if (cpu_input && (s3->accel.cmd == 0x53b3) && (s3->accel.cur_x & 0x400)) + break; + } + } + } + } } + s3_log("CMDFULL=%04x, FRGDSEL=%x, BKGDSEL=%x, FRGDMIX=%02x, BKGDMIX=%02x, MASKCHECK=%x, RDMASK=%04x, MINUS=%d, WRTMASK=%04X, MIX=%04x, CX=%d, CY=%d, DX=%d, DY=%d, SX=%d, SY=%d, PIXCNTL=%02x, 16BITCOLOR=%x, RDCHECK=%x, CLIPL=%d, CLIPR=%d, OVERFLOW=%d, pitch=%d.\n", s3->accel.cmd, frgd_mix, bkgd_mix, s3->accel.frgd_mix & 0x0f, s3->accel.bkgd_mix & 0x0f, s3->accel.rd_mask_16bit_check, rd_mask, s3->accel.minus, wrt_mask, mix_dat & 0xffff, s3->accel.cx, s3->accel.cy, s3->accel.dx, s3->accel.dy, s3->accel.sx, s3->accel.sy, s3->accel.multifunc[0x0a] & 0xc4, s3->accel.color_16bit_check, s3->accel.rd_mask_16bit_check, clip_l, clip_r, (s3->accel.destx_overflow & 0xc00) == 0xc00, s3->width); + while (count-- && (s3->accel.sy >= 0)) { if (s3->accel.b2e8_pix && s3_cpu_src(s3) && !s3->accel.temp_cnt) { mix_dat >>= 16; @@ -8346,7 +8508,7 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi mix_dat = mix_dat ? mix_mask : 0; } - if (s3_cpu_dest(s3) || ((s3_cpu_src(s3)) && s3->color_16bit && (s3->bpp == 0) && (s3->accel.cmd == 0x41b3))) { + if (s3_cpu_dest(s3)) { READ(s3->accel.dest + s3->accel.cx - s3->accel.minus, src_dat); if (vram_mask) src_dat = ((src_dat & rd_mask) == rd_mask); @@ -8390,17 +8552,18 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi if (s3_cpu_dest(s3)) { if (vram_mask) { + old_dest_dat = dest_dat; MIX } } else { + old_dest_dat = dest_dat; MIX } if (s3->accel.cmd & 0x10) { - if (s3->accel.cmd == 0x41b3) - s3_log("Full=%04x: Destination=%04x, OldDest=%04x, c=%d,%d.\n", s3->accel.cmd, dest_dat, old_dest_dat, s3->accel.cx, s3->accel.cy); - - WRITE(s3->accel.dest + s3->accel.cx - s3->accel.minus, dest_dat); + if (!s3->accel.color_16bit_check_pixtrans) { + WRITE(s3->accel.dest + s3->accel.cx - s3->accel.minus, dest_dat); + } } } } @@ -8443,9 +8606,23 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi s3->accel.cy &= 0xfff; s3->accel.dest = dstbase + s3->accel.cy * s3->width; + s3->accel.sy--; if (cpu_input) { + if (s3->accel.sy < 0) { + if ((s3->bpp == 0) && s3->color_16bit) { + if (s3->accel.rd_mask_16bit_check) { + if (s3->accel.minus) + s3->accel.color_16bit_check = 0; + else + s3->accel.color_16bit_check = 1; + + if ((s3->accel.cmd == 0x41b3) && (frgd_mix == 0)) + s3->accel.color_16bit_check = 0; + } + } + } if (s3->accel.b2e8_pix) { s3->accel.cur_x = s3->accel.cx; s3->accel.cur_y = s3->accel.cy; @@ -8453,6 +8630,14 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi return; } if (s3->accel.sy < 0) { + if ((s3->bpp == 0) && s3->color_16bit) { + if (s3->accel.rd_mask_16bit_check) { + if (s3->accel.minus) + s3->accel.color_16bit_check = 0; + else + s3->accel.color_16bit_check = 1; + } + } s3->accel.cur_x = s3->accel.cx; s3->accel.cur_y = s3->accel.cy; return; @@ -8521,6 +8706,7 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi if (update) { READ(s3->accel.dest + s3->accel.poly_x, dest_dat); + old_dest_dat = dest_dat; MIX if (s3->accel.cmd & 0x10) { @@ -8560,18 +8746,39 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi case 6: /*BitBlt*/ if (!cpu_input) { /*!cpu_input is trigger to start operation*/ s3->accel.minus = 0; + s3->accel.minus_src_24bpp = 0; s3->accel.sx = s3->accel.maj_axis_pcnt & 0xfff; s3->accel.sy = s3->accel.multifunc[0] & 0xfff; s3->accel.dx = s3->accel.destx_distp & 0xfff; s3->accel.dy = s3->accel.desty_axstp & 0xfff; - if ((s3->bpp == 0) && s3->color_16bit && (clip_r > 0x3ff) && (s3->accel.destx_distp & 0x400)) - s3->accel.minus = 0x400; - s3->accel.cx = s3->accel.cur_x & 0xfff; s3->accel.cy = s3->accel.cur_y & 0xfff; + if ((s3->bpp == 0) && s3->color_16bit) { + s3->accel.rd_mask_16bit_check = ((rd_mask & 0xff00) != 0xff00) && rd_mask; + if (s3->accel.rd_mask_16bit_check) { + if (!(clip_r & 0x400)) + s3->accel.start = 1; + else { + if (s3->accel.start) { + s3->accel.start = 0; + s3->accel.minus = 0x400; + } else { + s3->accel.start = 0; + if (s3->accel.destx_distp & 0x400) + s3->accel.minus = 0x400; + } + } + } + } + + if (s3->accel.destx_distp & 0x400) { + s3_log("BitBLT + 1024 FULLCMD=%04x: frgdcolor=%04x, s=%d,%d, d=%d,%d, frmix=%x, bkmix=%x, pixcntl=%02x.\n", s3->accel.cmd, frgd_color, s3->accel.sx, s3->accel.sy, s3->accel.dx, s3->accel.dy, frgd_mix, bkgd_mix, s3->accel.multifunc[0xa] & 0xc0); + } else { + s3_log("BitBLT + 0 FULLCMD=%04x: frgdcolor=%04x, s=%d,%d, d=%d,%d, frmix=%x, bkmix=%x, pixcntl=%02x.\n", s3->accel.cmd, frgd_color, s3->accel.sx, s3->accel.sy, s3->accel.dx, s3->accel.dy, frgd_mix, bkgd_mix, s3->accel.multifunc[0xa] & 0xc0); + } s3->accel.src = srcbase + s3->accel.cy * s3->width; s3->accel.dest = dstbase + s3->accel.dy * s3->width; s3_log("BitBLT: D(%d,%d).\n", s3->accel.dx, s3->accel.dy); @@ -8580,7 +8787,26 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi if ((s3->accel.cmd & 0x100) && !cpu_input) return; /*Wait for data from CPU*/ + if ((s3->bpp == 0) && s3->color_16bit) { + if (s3->accel.rd_mask_16bit_check) { + if (s3->accel.minus) { + wrt_mask = (s3->accel.wrt_mask_actual[1] << 8); + frgd_color = (s3->accel.frgd_color_actual[1] << 8); + bkgd_color = (s3->accel.bkgd_color_actual[1] << 8); + } else { + wrt_mask = s3->accel.wrt_mask_actual[0]; + frgd_color = s3->accel.frgd_color_actual[0]; + bkgd_color = s3->accel.bkgd_color_actual[0]; + } + rd_mask &= 0x00ff; + } else if (!s3->accel.rd_mask_16bit_check && (s3->accel.destx_distp & 0x400)) + break; + } + + s3_log("CMDFULL=%04x, FRGDSEL=%x, BKGDSEL=%x, FRGDMIX=%02x, BKGDMIX=%02x, MASKCHECK=%x, RDMASK=%04x, MINUS=%d, WRTMASK=%04X, MIX=%04x, CX=%d, CY=%d, DX=%d, DY=%d, SX=%d, SY=%d, PIXCNTL=%02x, 16BITCOLOR=%x, RDCHECK=%x, CLIPL=%d, CLIPR=%d, OVERFLOW=%d, pitch=%d.\n", s3->accel.cmd, frgd_mix, bkgd_mix, s3->accel.frgd_mix & 0x0f, s3->accel.bkgd_mix & 0x0f, s3->accel.rd_mask_16bit_check, rd_mask, s3->accel.minus, wrt_mask, mix_dat & 0xffff, s3->accel.cx, s3->accel.cy, s3->accel.dx, s3->accel.dy, s3->accel.sx, s3->accel.sy, s3->accel.multifunc[0x0a] & 0xc4, s3->accel.color_16bit_check, s3->accel.rd_mask_16bit_check, clip_l, clip_r, (s3->accel.destx_overflow & 0xc00) == 0xc00, s3->width); + if (!cpu_input && (frgd_mix == 3) && !vram_mask && !(s3->accel.multifunc[0xe] & 0x100) && ((s3->accel.cmd & 0xa0) == 0xa0) && ((s3->accel.frgd_mix & 0xf) == 7) && ((s3->accel.bkgd_mix & 0xf) == 7)) { + s3_log("Special BitBLT.\n"); while (1) { if ((s3->accel.dx >= clip_l) && (s3->accel.dx <= clip_r) && (s3->accel.dy >= clip_t) && (s3->accel.dy <= clip_b)) { READ(s3->accel.src + s3->accel.cx - s3->accel.minus, src_dat); @@ -8596,6 +8822,7 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi s3->accel.dx++; s3->accel.sx--; s3->accel.dx &= 0xfff; + if (s3->accel.sx < 0) { s3->accel.cx -= (s3->accel.maj_axis_pcnt & 0xfff) + 1; s3->accel.dx -= (s3->accel.maj_axis_pcnt & 0xfff) + 1; @@ -8610,6 +8837,12 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi s3->accel.sy--; if (s3->accel.sy < 0) { + if (s3->accel.rd_mask_16bit_check) { + if (s3->accel.minus) + s3->accel.color_16bit_check = 0; + else + s3->accel.color_16bit_check = 1; + } s3->accel.destx_distp = s3->accel.dx; s3->accel.desty_axstp = s3->accel.dy; return; @@ -8617,6 +8850,7 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi } } } else { + s3_log("Normal blit, srcbase=%08x, dstbase=%08x, full=%04x, wrt_mask=%08x, extmultifunc0e=%03x, frgdmixval=%02x.\n", srcbase, dstbase, s3->accel.cmd, wrt_mask, s3->accel.multifunc[0x0e] & 0x180, s3->accel.frgd_mix); while (count-- && (s3->accel.sy >= 0)) { if ((s3->accel.dx >= clip_l) && (s3->accel.dx <= clip_r) && (s3->accel.dy >= clip_t) && (s3->accel.dy <= clip_b)) { if (vram_mask && (s3->accel.cmd & 0x10)) { @@ -8662,6 +8896,7 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi if (update) { READ(s3->accel.dest + s3->accel.dx - s3->accel.minus, dest_dat); + old_dest_dat = dest_dat; MIX if ((!(s3->accel.cmd & 0x10) && vram_mask) || (s3->accel.cmd & 0x10)) { @@ -8685,7 +8920,11 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi s3->accel.cx--; s3->accel.dx--; } - s3->accel.dx &= 0xfff; + if (s3->accel.rd_mask_16bit_check) + s3->accel.dx &= 0x7ff; + else + s3->accel.dx &= 0xfff; + s3->accel.sx--; if (s3->accel.sx < 0) { if (s3->accel.cmd & 0x20) { @@ -8704,15 +8943,34 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi s3->accel.cy--; s3->accel.dy--; } + s3->accel.src = srcbase + s3->accel.cy * s3->width; s3->accel.dest = dstbase + s3->accel.dy * s3->width; s3->accel.sy--; - if (cpu_input) + if (cpu_input) { + if (s3->accel.sy < 0) { + if (s3->accel.rd_mask_16bit_check) { + if (s3->accel.minus) + s3->accel.color_16bit_check = 0; + else + s3->accel.color_16bit_check = 1; + } + } return; + } if (s3->accel.sy < 0) { + if (s3->accel.rd_mask_16bit_check) { + if (s3->accel.minus) + s3->accel.color_16bit_check = 0; + else + s3->accel.color_16bit_check = 1; + + if (s3->accel.mix_dat_upper && !vram_mask && (frgd_mix == 3)) + s3->accel.color_16bit_check = 0; + } s3->accel.destx_distp = s3->accel.dx; s3->accel.desty_axstp = s3->accel.dy; return; @@ -8792,6 +9050,7 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi if (update) { READ(s3->accel.dest + s3->accel.dx, dest_dat); + old_dest_dat = dest_dat; MIX if (s3->accel.cmd & 0x10) { @@ -8897,6 +9156,7 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi if (update) { READ((s3->accel.cy * s3->width) + s3->accel.cx, dest_dat); + old_dest_dat = dest_dat; MIX if (s3->accel.cmd & 0x10) { @@ -8946,6 +9206,7 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi if (update) { READ((s3->accel.cy * s3->width) + s3->accel.cx, dest_dat); + old_dest_dat = dest_dat; MIX if (s3->accel.cmd & 0x10) { @@ -9047,6 +9308,7 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, voi if (update) { READ(s3->accel.dest + s3->accel.poly_x, dest_dat); + old_dest_dat = dest_dat; MIX if (s3->accel.cmd & 0x10) { @@ -9520,7 +9782,6 @@ s3_disable_handlers(s3_t *s3) reset_state->bios_rom.mapping = s3->bios_rom.mapping; reset_state->svga.timer = s3->svga.timer; - reset_state->svga.timer8514 = s3->svga.timer8514; memset(s3->svga.vram, 0x00, s3->svga.vram_max + 8); memset(s3->svga.changedvram, 0x00, (s3->svga.vram_max >> 12) + 1); @@ -9578,6 +9839,11 @@ s3_init(const device_t *info) chip = S3_86C801; video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_s3_86c801); break; + case S3_WINNER1000_805: + bios_fn = ROM_WINNER1000_805; + chip = S3_86C801; + video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_s3_86c801); + break; case S3_86C805_ONBOARD: bios_fn = NULL; chip = S3_86C805; @@ -10008,7 +10274,7 @@ s3_init(const device_t *info) s3->id_ext_pci = 0; s3->packed_mmio = 0; - svga->ramdac = device_add(&att490_ramdac_device); + svga->ramdac = device_add(&sc11483_ramdac_device); svga->clock_gen = device_add(&ics2494an_305_device); svga->getclock = ics2494_getclock; break; @@ -10030,6 +10296,7 @@ s3_init(const device_t *info) case S3_SPEA_MIRAGE_86C801: case S3_SPEA_MIRAGE_86C805: + case S3_WINNER1000_805: svga->decode_mask = (2 << 20) - 1; stepping = 0xa2; /*86C801/86C805*/ s3->id = stepping; @@ -10328,6 +10595,12 @@ s3_phoenix_86c80x_available(void) return rom_present(ROM_PHOENIX_86C80X); } +static int +s3_winner1000_805_available(void) +{ + return rom_present(ROM_WINNER1000_805); +} + static int s3_mirocrystal_8s_805_available(void) { @@ -10540,109 +10813,136 @@ s3_force_redraw(void *priv) s3->svga.fullchange = s3->svga.monitor->mon_changeframecount; } +// clang-format off static const device_config_t s3_orchid_86c911_config[] = { - { .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 1, - .selection = { - { .description = "512 KB", - .value = 0 }, - { .description = "1 MB", - .value = 1 }, - { .description = "" } } }, - { .type = CONFIG_END } + { + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "512 KB", .value = 0 }, + { .description = "1 MB", .value = 1 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t s3_9fx_config[] = { - { .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 2, - .selection = { - { .description = "1 MB", - .value = 1 }, - { .description = "2 MB", - .value = 2 }, - /*Trio64 also supports 4 MB, however the Number Nine BIOS does not*/ - { - .description = "" } } }, - { .type = CONFIG_END } + { + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "1 MB", .value = 1 }, + { .description = "2 MB", .value = 2 }, + /* Trio64 also supports 4 MB, however the Number Nine BIOS does not */ + { .description = "" } + }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t s3_phoenix_trio32_config[] = { - { .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 2, - .selection = { - { .description = "512 KB", - .value = 0 }, - { .description = "1 MB", - .value = 1 }, - { .description = "2 MB", - .value = 2 }, - { .description = "" } } }, - { .type = CONFIG_END } + { + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "512 KB", .value = 0 }, + { .description = "1 MB", .value = 1 }, + { .description = "2 MB", .value = 2 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t s3_standard_config[] = { - { .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 4, - .selection = { - { .description = "1 MB", - .value = 1 }, - { .description = "2 MB", - .value = 2 }, - { .description = "4 MB", - .value = 4 }, - { .description = "" } } }, - { .type = CONFIG_END } + { + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 4, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "1 MB", .value = 1 }, + { .description = "2 MB", .value = 2 }, + { .description = "4 MB", .value = 4 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t s3_968_config[] = { - { .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 4, - .selection = { - { .description = "1 MB", - .value = 1 }, - { .description = "2 MB", - .value = 2 }, - { .description = "4 MB", - .value = 4 }, - { .description = "8 MB", - .value = 8 }, - { .description = "" } } }, - { .type = CONFIG_END } + { + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 4, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "1 MB", .value = 1 }, + { .description = "2 MB", .value = 2 }, + { .description = "4 MB", .value = 4 }, + { .description = "8 MB", .value = 8 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t s3_standard_config2[] = { - { .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 4, - .selection = { - { .description = "2 MB", - .value = 2 }, - { .description = "4 MB", - .value = 4 }, - { .description = "" } } }, - { .type = CONFIG_END } + { + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 4, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "2 MB", .value = 2 }, + { .description = "4 MB", .value = 4 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } }; +// clang-format on const device_t s3_orchid_86c911_isa_device = { .name = "S3 86c911 ISA (Orchid Fahrenheit 1280)", .internal_name = "orchid_s3_911", - .flags = DEVICE_AT | DEVICE_ISA, + .flags = DEVICE_ISA16, .local = S3_ORCHID_86C911, .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_orchid_86c911_available }, + .available = s3_orchid_86c911_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_orchid_86c911_config @@ -10651,12 +10951,12 @@ const device_t s3_orchid_86c911_isa_device = { const device_t s3_diamond_stealth_vram_isa_device = { .name = "S3 86c911 ISA (Diamond Stealth VRAM)", .internal_name = "stealthvram_isa", - .flags = DEVICE_AT | DEVICE_ISA, + .flags = DEVICE_ISA16, .local = S3_DIAMOND_STEALTH_VRAM, .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_diamond_stealth_vram_available }, + .available = s3_diamond_stealth_vram_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_orchid_86c911_config @@ -10665,12 +10965,12 @@ const device_t s3_diamond_stealth_vram_isa_device = { const device_t s3_ami_86c924_isa_device = { .name = "S3 86c924 ISA (AMI)", .internal_name = "ami_s3_924", - .flags = DEVICE_AT | DEVICE_ISA, + .flags = DEVICE_ISA16, .local = S3_AMI_86C924, .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_ami_86c924_available }, + .available = s3_ami_86c924_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_orchid_86c911_config @@ -10679,12 +10979,26 @@ const device_t s3_ami_86c924_isa_device = { const device_t s3_spea_mirage_86c801_isa_device = { .name = "S3 86c801 ISA (SPEA Mirage ISA)", .internal_name = "px_s3_v7_801_isa", - .flags = DEVICE_AT | DEVICE_ISA, + .flags = DEVICE_ISA16, .local = S3_SPEA_MIRAGE_86C801, .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_spea_mirage_86c801_available }, + .available = s3_spea_mirage_86c801_available, + .speed_changed = s3_speed_changed, + .force_redraw = s3_force_redraw, + .config = s3_9fx_config +}; + +const device_t s3_winner1000_805_isa_device = { + .name = "S3 86c805 ISA (ELSA Winner 1000)", + .internal_name = "winner1000_805_isa", + .flags = DEVICE_ISA16, + .local = S3_WINNER1000_805, + .init = s3_init, + .close = s3_close, + .reset = s3_reset, + .available = s3_winner1000_805_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -10698,7 +11012,7 @@ const device_t s3_86c805_onboard_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = NULL }, + .available = NULL, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -10712,7 +11026,7 @@ const device_t s3_spea_mirage_86c805_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_spea_mirage_86c805_available }, + .available = s3_spea_mirage_86c805_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -10726,7 +11040,7 @@ const device_t s3_mirocrystal_8s_805_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_mirocrystal_8s_805_available }, + .available = s3_mirocrystal_8s_805_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -10740,7 +11054,7 @@ const device_t s3_mirocrystal_10sd_805_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_mirocrystal_10sd_805_available }, + .available = s3_mirocrystal_10sd_805_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -10749,12 +11063,12 @@ const device_t s3_mirocrystal_10sd_805_vlb_device = { const device_t s3_phoenix_86c801_isa_device = { .name = "S3 86c801 ISA (Phoenix)", .internal_name = "px_86c801_isa", - .flags = DEVICE_AT | DEVICE_ISA, + .flags = DEVICE_ISA16, .local = S3_PHOENIX_86C801, .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_phoenix_86c80x_available }, + .available = s3_phoenix_86c80x_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -10768,7 +11082,7 @@ const device_t s3_phoenix_86c805_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_phoenix_86c80x_available }, + .available = s3_phoenix_86c80x_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -10777,12 +11091,12 @@ const device_t s3_phoenix_86c805_vlb_device = { const device_t s3_metheus_86c928_isa_device = { .name = "S3 86c928 ISA (Metheus Premier 928)", .internal_name = "metheus928_isa", - .flags = DEVICE_AT | DEVICE_ISA, + .flags = DEVICE_ISA16, .local = S3_METHEUS_86C928, .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_metheus_86c928_available }, + .available = s3_metheus_86c928_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -10796,7 +11110,7 @@ const device_t s3_metheus_86c928_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_metheus_86c928_available }, + .available = s3_metheus_86c928_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -10810,7 +11124,7 @@ const device_t s3_spea_mercury_lite_86c928_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_spea_mercury_lite_pci_available }, + .available = s3_spea_mercury_lite_pci_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_orchid_86c911_config @@ -10824,7 +11138,7 @@ const device_t s3_mirocrystal_20sd_864_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_mirocrystal_20sd_864_vlb_available }, + .available = s3_mirocrystal_20sd_864_vlb_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -10838,7 +11152,7 @@ const device_t s3_bahamas64_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_bahamas64_available }, + .available = s3_bahamas64_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -10852,7 +11166,7 @@ const device_t s3_bahamas64_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_bahamas64_available }, + .available = s3_bahamas64_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -10866,7 +11180,7 @@ const device_t s3_mirocrystal_20sv_964_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_mirocrystal_20sv_964_vlb_available }, + .available = s3_mirocrystal_20sv_964_vlb_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -10880,7 +11194,7 @@ const device_t s3_mirocrystal_20sv_964_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_mirocrystal_20sv_964_pci_available }, + .available = s3_mirocrystal_20sv_964_pci_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -10894,7 +11208,7 @@ const device_t s3_diamond_stealth64_964_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_diamond_stealth64_964_available }, + .available = s3_diamond_stealth64_964_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -10908,7 +11222,7 @@ const device_t s3_diamond_stealth64_964_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_diamond_stealth64_964_available }, + .available = s3_diamond_stealth64_964_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -10922,7 +11236,7 @@ const device_t s3_diamond_stealth64_968_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_diamond_stealth64_968_available }, + .available = s3_diamond_stealth64_968_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config2 @@ -10936,7 +11250,7 @@ const device_t s3_diamond_stealth64_968_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_diamond_stealth64_968_available }, + .available = s3_diamond_stealth64_968_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config2 @@ -10950,7 +11264,7 @@ const device_t s3_9fx_771_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_9fx_771_available }, + .available = s3_9fx_771_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_968_config @@ -10964,7 +11278,7 @@ const device_t s3_phoenix_vision968_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_phoenix_vision968_available }, + .available = s3_phoenix_vision968_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -10978,7 +11292,7 @@ const device_t s3_mirovideo_40sv_ergo_968_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_mirovideo_40sv_ergo_968_pci_available }, + .available = s3_mirovideo_40sv_ergo_968_pci_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -10992,7 +11306,7 @@ const device_t s3_spea_mercury_p64v_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_spea_mercury_p64v_pci_available }, + .available = s3_spea_mercury_p64v_pci_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -11006,7 +11320,7 @@ const device_t s3_9fx_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_9fx_available }, + .available = s3_9fx_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -11020,7 +11334,7 @@ const device_t s3_9fx_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_9fx_available }, + .available = s3_9fx_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -11034,7 +11348,7 @@ const device_t s3_phoenix_trio32_onboard_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = NULL }, + .available = NULL, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_phoenix_trio32_config @@ -11048,7 +11362,7 @@ const device_t s3_phoenix_trio32_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_phoenix_trio32_available }, + .available = s3_phoenix_trio32_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_phoenix_trio32_config @@ -11062,7 +11376,7 @@ const device_t s3_phoenix_trio32_onboard_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = NULL }, + .available = NULL, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_phoenix_trio32_config @@ -11076,7 +11390,7 @@ const device_t s3_phoenix_trio32_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_phoenix_trio32_available }, + .available = s3_phoenix_trio32_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_phoenix_trio32_config @@ -11090,7 +11404,7 @@ const device_t s3_diamond_stealth_se_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_diamond_stealth_se_available }, + .available = s3_diamond_stealth_se_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_phoenix_trio32_config @@ -11104,7 +11418,7 @@ const device_t s3_diamond_stealth_se_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_diamond_stealth_se_available }, + .available = s3_diamond_stealth_se_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_phoenix_trio32_config @@ -11118,7 +11432,7 @@ const device_t s3_phoenix_trio64_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_phoenix_trio64_available }, + .available = s3_phoenix_trio64_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -11132,7 +11446,7 @@ const device_t s3_phoenix_trio64_onboard_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = NULL }, + .available = NULL, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -11146,7 +11460,7 @@ const device_t s3_phoenix_trio64_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_phoenix_trio64_available }, + .available = s3_phoenix_trio64_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -11160,7 +11474,7 @@ const device_t s3_stb_powergraph_64_video_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_stb_powergraph_64_video_available }, + .available = s3_stb_powergraph_64_video_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_phoenix_trio32_config @@ -11174,7 +11488,7 @@ const device_t s3_phoenix_trio64vplus_onboard_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = NULL }, + .available = NULL, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -11188,7 +11502,7 @@ const device_t s3_phoenix_trio64vplus_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_phoenix_trio64vplus_available }, + .available = s3_phoenix_trio64vplus_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -11202,7 +11516,7 @@ const device_t s3_cardex_trio64vplus_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_cardex_trio64vplus_available }, + .available = s3_cardex_trio64vplus_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -11216,7 +11530,7 @@ const device_t s3_phoenix_vision864_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_phoenix_vision864_available }, + .available = s3_phoenix_vision864_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -11230,7 +11544,7 @@ const device_t s3_phoenix_vision864_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_phoenix_vision864_available }, + .available = s3_phoenix_vision864_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -11244,7 +11558,7 @@ const device_t s3_9fx_531_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_9fx_531_available }, + .available = s3_9fx_531_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -11258,7 +11572,7 @@ const device_t s3_phoenix_vision868_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_phoenix_vision868_available }, + .available = s3_phoenix_vision868_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -11272,7 +11586,7 @@ const device_t s3_diamond_stealth64_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_diamond_stealth64_764_available }, + .available = s3_diamond_stealth64_764_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -11286,7 +11600,7 @@ const device_t s3_diamond_stealth64_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_diamond_stealth64_764_available }, + .available = s3_diamond_stealth64_764_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -11300,7 +11614,7 @@ const device_t s3_spea_mirage_p64_vlb_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_spea_mirage_p64_vlb_available }, + .available = s3_spea_mirage_p64_vlb_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_9fx_config @@ -11314,7 +11628,7 @@ const device_t s3_elsa_winner2000_pro_x_964_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_elsa_winner2000_pro_x_964_available }, + .available = s3_elsa_winner2000_pro_x_964_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_968_config @@ -11328,7 +11642,7 @@ const device_t s3_elsa_winner2000_pro_x_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_elsa_winner2000_pro_x_available }, + .available = s3_elsa_winner2000_pro_x_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_968_config @@ -11342,7 +11656,7 @@ const device_t s3_trio64v2_dx_pci_device = { .init = s3_init, .close = s3_close, .reset = s3_reset, - { .available = s3_trio64v2_dx_available }, + .available = s3_trio64v2_dx_available, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config @@ -11356,7 +11670,7 @@ const device_t s3_trio64v2_dx_onboard_pci_device = { .init = s3_init, .close = s3_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = s3_speed_changed, .force_redraw = s3_force_redraw, .config = s3_standard_config diff --git a/src/video/vid_s3_virge.c b/src/video/vid_s3_virge.c index 08a01dbd6..774b0d4b7 100644 --- a/src/video/vid_s3_virge.c +++ b/src/video/vid_s3_virge.c @@ -53,10 +53,10 @@ static uint64_t virge_time = 0; static int dither[4][4] = { - {0, 4, 1, 5}, - {6, 2, 7, 3}, - {1, 5, 0, 4}, - {7, 3, 6, 2} + { 0, 4, 1, 5 }, + { 6, 2, 7, 3 }, + { 1, 5, 0, 4 }, + { 7, 3, 6, 2 } }; #define ROM_VIRGE_325 "roms/video/s3virge/86c325.bin" @@ -112,80 +112,80 @@ enum { }; enum { - FIFO_INVALID = (0x00 << 24), - FIFO_WRITE_BYTE = (0x01 << 24), - FIFO_WRITE_WORD = (0x02 << 24), + FIFO_INVALID = (0x00 << 24), + FIFO_WRITE_BYTE = (0x01 << 24), + FIFO_WRITE_WORD = (0x02 << 24), FIFO_WRITE_DWORD = (0x03 << 24) }; typedef struct { - uint32_t addr_type; - uint32_t val; + uint32_t addr_type; + uint32_t val; } fifo_entry_t; typedef struct s3d_t { - uint32_t cmd_set; - int clip_l; - int clip_r; - int clip_t; - int clip_b; + uint32_t cmd_set; + int clip_l; + int clip_r; + int clip_t; + int clip_b; - uint32_t dest_base; - uint32_t dest_str; + uint32_t dest_base; + uint32_t dest_str; - uint32_t z_base; - uint32_t z_str; + uint32_t z_base; + uint32_t z_str; - uint32_t tex_base; - uint32_t tex_bdr_clr; - uint32_t tbv; - uint32_t tbu; - int32_t TdVdX; - int32_t TdUdX; - int32_t TdVdY; - int32_t TdUdY; - uint32_t tus; - uint32_t tvs; + uint32_t tex_base; + uint32_t tex_bdr_clr; + uint32_t tbv; + uint32_t tbu; + int32_t TdVdX; + int32_t TdUdX; + int32_t TdVdY; + int32_t TdUdY; + uint32_t tus; + uint32_t tvs; - int32_t TdZdX; - int32_t TdZdY; - uint32_t tzs; + int32_t TdZdX; + int32_t TdZdY; + uint32_t tzs; - int32_t TdWdX; - int32_t TdWdY; - uint32_t tws; + int32_t TdWdX; + int32_t TdWdY; + uint32_t tws; - int32_t TdDdX; - int32_t TdDdY; - uint32_t tds; + int32_t TdDdX; + int32_t TdDdY; + uint32_t tds; - int16_t TdGdX; - int16_t TdBdX; - int16_t TdRdX; - int16_t TdAdX; - int16_t TdGdY; - int16_t TdBdY; - int16_t TdRdY; - int16_t TdAdY; - uint32_t tgs; - uint32_t tbs; - uint32_t trs; - uint32_t tas; + int16_t TdGdX; + int16_t TdBdX; + int16_t TdRdX; + int16_t TdAdX; + int16_t TdGdY; + int16_t TdBdY; + int16_t TdRdY; + int16_t TdAdY; + uint32_t tgs; + uint32_t tbs; + uint32_t trs; + uint32_t tas; - uint32_t TdXdY12; - uint32_t txend12; - uint32_t TdXdY01; - uint32_t txend01; - uint32_t TdXdY02; - uint32_t txs; - uint32_t tys; - int ty01; - int ty12; - int tlr; + uint32_t TdXdY12; + uint32_t txend12; + uint32_t TdXdY01; + uint32_t txend01; + uint32_t TdXdY02; + uint32_t txs; + uint32_t tys; + int ty01; + int ty12; + int tlr; - uint8_t fog_r; - uint8_t fog_g; - uint8_t fog_b; + uint8_t fog_r; + uint8_t fog_g; + uint8_t fog_b; } s3d_t; typedef struct virge_t { @@ -193,41 +193,42 @@ typedef struct virge_t { mem_mapping_t mmio_mapping; mem_mapping_t new_mmio_mapping; - rom_t bios_rom; + rom_t bios_rom; - svga_t svga; + svga_t svga; - uint8_t bank; - uint8_t ma_ext; + uint8_t bank; + uint8_t ma_ext; - uint8_t virge_id; - uint8_t virge_id_high; - uint8_t virge_id_low; - uint8_t virge_rev; + uint8_t virge_id; + uint8_t virge_id_high; + uint8_t virge_id_low; + uint8_t virge_rev; - uint32_t linear_base; - uint32_t linear_size; + uint32_t linear_base; + uint32_t linear_size; - uint8_t pci_regs[256]; - uint8_t pci_slot; + uint8_t pci_regs[256]; + uint8_t pci_slot; - int chip; + uint8_t type; + int chip; - int bilinear_enabled; - int dithering_enabled; - int memory_size; + int bilinear_enabled; + int dithering_enabled; + int memory_size; - int pixel_count; - int tri_count; + int pixel_count; + int tri_count; - thread_t * render_thread; - event_t * wake_render_thread; - event_t * wake_main_thread; - event_t * not_full_event; + thread_t *render_thread; + event_t *wake_render_thread; + event_t *wake_main_thread; + event_t *not_full_event; - uint32_t hwc_fg_col; - uint32_t hwc_bg_col; - int hwc_col_stack_pos; + uint32_t hwc_fg_col; + uint32_t hwc_bg_col; + int hwc_col_stack_pos; struct { uint32_t src_base; @@ -260,13 +261,13 @@ typedef struct virge_t { int lycnt; int line_dir; - int src_x; - int src_y; - int dest_x; - int dest_y; - int w; - int h; - uint8_t rop; + int src_x; + int src_y; + int dest_x; + int dest_y; + int w; + int h; + uint8_t rop; int data_left_count; uint32_t data_left; @@ -282,15 +283,16 @@ typedef struct virge_t { uint32_t plxstart; uint32_t pystart; uint32_t pycnt; - uint32_t dest_l, dest_r; + uint32_t dest_l; + uint32_t dest_r; } s3d; - s3d_t s3d_tri; + s3d_t s3d_tri; - s3d_t s3d_buffer[RB_SIZE]; - atomic_int s3d_read_idx; - atomic_int s3d_write_idx; - atomic_int s3d_busy; + s3d_t s3d_buffer[RB_SIZE]; + atomic_int s3d_read_idx; + atomic_int s3d_write_idx; + atomic_int s3d_busy; struct { uint32_t pri_ctrl; @@ -317,85 +319,89 @@ typedef struct virge_t { uint32_t sec_start; uint32_t sec_size; - int sdif; + int sdif; - int pri_x; - int pri_y; - int pri_w; - int pri_h; - int sec_x; - int sec_y; - int sec_w; - int sec_h; + int pri_x; + int pri_y; + int pri_w; + int pri_h; + int sec_x; + int sec_y; + int sec_w; + int sec_h; } streams; fifo_entry_t fifo[FIFO_SIZE]; atomic_int fifo_read_idx, fifo_write_idx; atomic_int fifo_thread_run, render_thread_run; - thread_t * fifo_thread; - event_t *wake_fifo_thread; - event_t * fifo_not_full_event; + thread_t *fifo_thread; + event_t *wake_fifo_thread; + event_t *fifo_not_full_event; - atomic_int virge_busy; + atomic_int virge_busy; + atomic_uint irq_pending; - uint8_t subsys_stat; - uint8_t subsys_cntl; + uint8_t subsys_stat; + uint8_t subsys_cntl; - int local; + int local; - uint8_t serialport; + uint8_t serialport; - uint8_t irq_state; - uint8_t advfunc_cntl; + uint8_t irq_state; + uint8_t advfunc_cntl; - void *i2c, *ddc; + void *i2c, *ddc; - int onboard; - int fifo_slots_num; + int onboard; + int fifo_slots_num; - uint32_t vram_mask; + uint32_t vram_mask; - uint8_t reg6b; - uint8_t lfb_bios; - uint8_t int_line; - uint8_t cmd_dma; + uint8_t reg6b; + uint8_t lfb_bios; + uint8_t int_line; + uint8_t cmd_dma; - uint32_t cmd_dma_base; - uint32_t cmd_dma_buf_size; - uint32_t cmd_dma_buf_size_mask; - uint32_t cmd_base_addr; - uint32_t cmd_dma_write_ptr_reg; - uint32_t cmd_dma_write_ptr_update; - uint32_t cmd_dma_read_ptr_reg; - uint32_t dma_val; - uint32_t dma_dbl_words; - uint32_t dma_mmio_addr; - uint32_t dma_data_type; + uint32_t cmd_dma_base; + uint32_t cmd_dma_buf_size; + uint32_t cmd_dma_buf_size_mask; + uint32_t cmd_base_addr; + uint32_t cmd_dma_write_ptr_reg; + uint32_t cmd_dma_write_ptr_update; + uint32_t cmd_dma_read_ptr_reg; + uint32_t dma_val; + uint32_t dma_dbl_words; + uint32_t dma_mmio_addr; + uint32_t dma_data_type; - int pci; - int is_agp; + int pci; + int is_agp; + + pc_timer_t irq_timer; } virge_t; static __inline void -wake_fifo_thread(virge_t *virge) { +wake_fifo_thread(virge_t *virge) +{ /* Wake up FIFO thread if moving from idle */ thread_set_event(virge->wake_fifo_thread); } -static virge_t *reset_state = NULL; +static virge_t *reset_state = NULL; static video_timings_t timing_diamond_stealth3d_2000_pci = { .type = VIDEO_PCI, .write_b = 2, .write_w = 2, .write_l = 3, .read_b = 28, .read_w = 28, .read_l = 45 }; static video_timings_t timing_diamond_stealth3d_3000_pci = { .type = VIDEO_PCI, .write_b = 2, .write_w = 2, .write_l = 4, .read_b = 26, .read_w = 26, .read_l = 42 }; static video_timings_t timing_virge_dx_pci = { .type = VIDEO_PCI, .write_b = 2, .write_w = 2, .write_l = 3, .read_b = 28, .read_w = 28, .read_l = 45 }; static video_timings_t timing_virge_agp = { .type = VIDEO_AGP, .write_b = 2, .write_w = 2, .write_l = 3, .read_b = 28, .read_w = 28, .read_l = 45 }; -static void queue_triangle(virge_t *virge); +static void queue_triangle(virge_t *virge); -static void s3_virge_recalctimings(svga_t *svga); -static void s3_virge_updatemapping(virge_t *virge); +static void s3_virge_recalctimings(svga_t *svga); +static void s3_virge_updatemapping(virge_t *virge); -static void s3_virge_bitblt(virge_t *virge, int count, uint32_t cpu_dat); +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 *priv); static uint16_t s3_virge_mmio_read_w(uint32_t addr, void *priv); @@ -404,33 +410,33 @@ 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); -static void s3_virge_queue(virge_t *virge, uint32_t addr, uint32_t val, uint32_t type); +static void s3_virge_queue(virge_t *virge, uint32_t addr, uint32_t val, uint32_t type); enum { - CMD_SET_AE = 1, - CMD_SET_HC = (1 << 1), + CMD_SET_AE = 1, + CMD_SET_HC = (1 << 1), - CMD_SET_FORMAT_MASK = (7 << 2), - CMD_SET_FORMAT_8 = (0 << 2), - CMD_SET_FORMAT_16 = (1 << 2), - CMD_SET_FORMAT_24 = (2 << 2), + CMD_SET_FORMAT_MASK = (7 << 2), + CMD_SET_FORMAT_8 = (0 << 2), + CMD_SET_FORMAT_16 = (1 << 2), + CMD_SET_FORMAT_24 = (2 << 2), - CMD_SET_MS = (1 << 6), - CMD_SET_IDS = (1 << 7), - CMD_SET_MP = (1 << 8), - CMD_SET_TP = (1 << 9), + CMD_SET_MS = (1 << 6), + CMD_SET_IDS = (1 << 7), + CMD_SET_MP = (1 << 8), + CMD_SET_TP = (1 << 9), - CMD_SET_ITA_MASK = (3 << 10), - CMD_SET_ITA_BYTE = (0 << 10), - CMD_SET_ITA_WORD = (1 << 10), - CMD_SET_ITA_DWORD = (2 << 10), + CMD_SET_ITA_MASK = (3 << 10), + CMD_SET_ITA_BYTE = (0 << 10), + CMD_SET_ITA_WORD = (1 << 10), + CMD_SET_ITA_DWORD = (2 << 10), - CMD_SET_ZUP = (1 << 23), + CMD_SET_ZUP = (1 << 23), - CMD_SET_ZB_MODE = (3 << 24), + CMD_SET_ZB_MODE = (3 << 24), - CMD_SET_XP = (1 << 25), - CMD_SET_YP = (1 << 26), + CMD_SET_XP = (1 << 25), + CMD_SET_YP = (1 << 26), CMD_SET_COMMAND_MASK = (15 << 27) }; @@ -441,11 +447,11 @@ enum { #define CMD_SET_TWE (1 << 26) enum { - CMD_SET_COMMAND_BITBLT = (0 << 27), - CMD_SET_COMMAND_RECTFILL = (2 << 27), - CMD_SET_COMMAND_LINE = (3 << 27), - CMD_SET_COMMAND_POLY = (5 << 27), - CMD_SET_COMMAND_NOP = (15 << 27) + CMD_SET_COMMAND_BITBLT = (0 << 27), + CMD_SET_COMMAND_RECTFILL = (2 << 27), + CMD_SET_COMMAND_LINE = (3 << 27), + CMD_SET_COMMAND_POLY = (5 << 27), + CMD_SET_COMMAND_NOP = (15 << 27) }; #define INT_VSY (1 << 0) @@ -471,11 +477,24 @@ s3_virge_update_irqs(virge_t *virge) pci_clear_irq(virge->pci_slot, PCI_INTA, &virge->irq_state); } +static void +s3_virge_update_irq_timer(void *priv) +{ + virge_t *virge = (virge_t *) priv; + + if (virge->irq_pending) { + virge->irq_pending--; + s3_virge_update_irqs(virge); + } + + timer_on_auto(&virge->irq_timer, 100.); +} + static void s3_virge_out(uint16_t addr, uint8_t val, void *priv) { virge_t *virge = (virge_t *) priv; - svga_t * svga = &virge->svga; + svga_t *svga = &virge->svga; uint8_t old; uint32_t cursoraddr; @@ -522,7 +541,7 @@ s3_virge_out(uint16_t addr, uint8_t val, void *priv) if ((svga->crtcreg == 0x36) && (svga->crtc[0x39] != 0xa5)) return; - old = svga->crtc[svga->crtcreg]; + old = svga->crtc[svga->crtcreg]; svga->crtc[svga->crtcreg] = val; switch (svga->crtcreg) { @@ -606,7 +625,7 @@ s3_virge_out(uint16_t addr, uint8_t val, void *priv) switch (virge->hwc_col_stack_pos) { case 0: virge->hwc_bg_col = (virge->hwc_bg_col & 0xffff00) | val; - break; + break; case 1: virge->hwc_bg_col = (virge->hwc_bg_col & 0xff00ff) | (val << 8); break; @@ -670,10 +689,10 @@ s3_virge_out(uint16_t addr, uint8_t val, void *priv) 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->memaddr_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5); if ((svga->crtc[0x67] & 0xc) != 0xc) - svga->ma_latch |= (virge->ma_ext << 16); + svga->memaddr_latch |= (virge->ma_ext << 16); } else { svga->fullchange = changeframecount; svga_recalctimings(svga); @@ -689,9 +708,10 @@ s3_virge_out(uint16_t addr, uint8_t val, void *priv) } static uint8_t -s3_virge_in(uint16_t addr, void *priv) { +s3_virge_in(uint16_t addr, void *priv) +{ virge_t *virge = (virge_t *) priv; - svga_t * svga = &virge->svga; + svga_t *svga = &virge->svga; uint8_t ret; if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(svga->miscout & 1)) @@ -742,7 +762,7 @@ s3_virge_in(uint16_t addr, void *priv) { break; case 0x45: virge->hwc_col_stack_pos = 0; - ret = svga->crtc[0x45]; + ret = svga->crtc[0x45]; break; case 0x51: ret = (svga->crtc[0x51] & 0xf0) | ((virge->bank >> 2) & 0xc) | ((virge->ma_ext >> 2) & 3); @@ -796,8 +816,10 @@ s3_virge_in(uint16_t addr, void *priv) { static void s3_virge_recalctimings(svga_t *svga) { - int n, r, m; - double freq; + int n; + int r; + int m; + double freq; virge_t *virge = (virge_t *) svga->priv; svga->hdisp = svga->hdisp_old; @@ -841,7 +863,7 @@ s3_virge_recalctimings(svga_t *svga) else r = (svga->seqregs[0x12] >> 5) & 0x03; - m = svga->seqregs[0x13] & 0x7f; + m = svga->seqregs[0x13] & 0x7f; freq = (((double) m + 2) / (((double) n + 2) * (double) (1 << r))) * 14318184.0; svga->clock = (cpuclock * (float) (1ULL << 32)) / freq; @@ -860,7 +882,7 @@ s3_virge_recalctimings(svga_t *svga) svga->vblankstart = svga->dispend; video_force_resize_set_monitor(1, svga->monitor_index); } else { - svga->hblankstart = (((svga->crtc[0x5d] & 0x04) >> 2) << 8) + svga->crtc[2]; + svga->hblankstart = (((svga->crtc[0x5d] & 0x04) >> 2) << 8) + svga->crtc[2]; svga->hblank_end_val = (svga->crtc[3] & 0x1f) | (((svga->crtc[5] & 0x80) >> 7) << 5) | (((svga->crtc[0x5d] & 0x08) >> 3) << 6); @@ -869,7 +891,7 @@ s3_virge_recalctimings(svga_t *svga) } if ((svga->crtc[0x67] & 0xc) != 0xc) { /*VGA mode*/ - svga->ma_latch |= (virge->ma_ext << 16); + svga->memaddr_latch |= (virge->ma_ext << 16); if (svga->crtc[0x51] & 0x30) svga->rowoffset |= (svga->crtc[0x51] & 0x30) << 4; else if (svga->crtc[0x43] & 0x04) @@ -878,45 +900,45 @@ s3_virge_recalctimings(svga_t *svga) svga->rowoffset = 256; svga->lowres = !((svga->gdcreg[5] & 0x40) && (svga->crtc[0x3a] & 0x10)); - if ((svga->gdcreg[5] & 0x40) && (svga->crtc[0x3a] & 0x10)) switch (svga->bpp) { - case 8: - svga->render = svga_render_8bpp_highres; - break; - case 15: - svga->render = svga_render_15bpp_highres; - if ((virge->chip != S3_VIRGEVX) && (virge->chip < S3_VIRGEGX2)) { - svga->hdisp >>= 1; - svga->dots_per_clock >>= 1; - } - break; - case 16: - svga->render = svga_render_16bpp_highres; - if ((virge->chip != S3_VIRGEVX) && (virge->chip < S3_VIRGEGX2)) { - svga->hdisp >>= 1; - svga->dots_per_clock >>= 1; - } - break; - case 24: - svga->render = svga_render_24bpp_highres; - if ((virge->chip != S3_VIRGEVX) && (virge->chip < S3_VIRGEGX2)) - svga->rowoffset = (svga->rowoffset * 3) >> 2; /*Hack*/ - break; - case 32: - svga->render = svga_render_32bpp_highres; - break; + if ((svga->gdcreg[5] & 0x40) && (svga->crtc[0x3a] & 0x10)) + switch (svga->bpp) { + case 8: + svga->render = svga_render_8bpp_highres; + break; + case 15: + svga->render = svga_render_15bpp_highres; + if ((virge->chip != S3_VIRGEVX) && (virge->chip < S3_VIRGEGX2)) { + svga->hdisp >>= 1; + svga->dots_per_clock >>= 1; + } + break; + case 16: + svga->render = svga_render_16bpp_highres; + if ((virge->chip != S3_VIRGEVX) && (virge->chip < S3_VIRGEGX2)) { + svga->hdisp >>= 1; + svga->dots_per_clock >>= 1; + } + break; + case 24: + svga->render = svga_render_24bpp_highres; + if ((virge->chip != S3_VIRGEVX) && (virge->chip < S3_VIRGEGX2)) + svga->rowoffset = (svga->rowoffset * 3) >> 2; /*Hack*/ + break; + case 32: + svga->render = svga_render_32bpp_highres; + break; - default: - break; - } + default: + break; + } - svga->vram_display_mask = (!(svga->crtc[0x31] & 0x08) && - (svga->crtc[0x32] & 0x40)) ? 0x3ffff : virge->vram_mask; + svga->vram_display_mask = (!(svga->crtc[0x31] & 0x08) && (svga->crtc[0x32] & 0x40)) ? 0x3ffff : virge->vram_mask; } else { /*Streams mode*/ if (virge->chip < S3_VIRGEGX2) { if (virge->streams.buffer_ctrl & 1) - svga->ma_latch = virge->streams.pri_fb1 >> 2; + svga->memaddr_latch = virge->streams.pri_fb1 >> 2; else - svga->ma_latch = virge->streams.pri_fb0 >> 2; + svga->memaddr_latch = virge->streams.pri_fb0 >> 2; svga->hdisp = virge->streams.pri_w + 1; if (virge->streams.pri_h < svga->dispend) @@ -925,7 +947,7 @@ s3_virge_recalctimings(svga_t *svga) svga->overlay.x = virge->streams.sec_x - virge->streams.pri_x; svga->overlay.y = virge->streams.sec_y - virge->streams.pri_y; } else { - svga->ma_latch |= (virge->ma_ext << 16); + svga->memaddr_latch |= (virge->ma_ext << 16); if (svga->crtc[0x51] & 0x30) svga->rowoffset |= (svga->crtc[0x51] & 0x30) << 4; else if (svga->crtc[0x43] & 0x04) @@ -944,7 +966,7 @@ s3_virge_recalctimings(svga_t *svga) else svga->overlay.addr = virge->streams.sec_fb0; - svga->overlay.ena = (svga->overlay.x >= 0); + svga->overlay.ena = (svga->overlay.x >= 0); svga->overlay.h_acc = virge->streams.dda_horiz_accumulator; svga->overlay.v_acc = virge->streams.dda_vert_accumulator; @@ -952,8 +974,7 @@ s3_virge_recalctimings(svga_t *svga) svga->rowoffset = virge->streams.pri_stride >> 3; if (virge->chip <= S3_VIRGEDX && svga->overlay.ena) { - svga->overlay.ena = (((virge->streams.blend_ctrl >> 24) & 7) == 0b000) || - (((virge->streams.blend_ctrl >> 24) & 7) == 0b101); + svga->overlay.ena = (((virge->streams.blend_ctrl >> 24) & 7) == 0b000) || (((virge->streams.blend_ctrl >> 24) & 7) == 0b101); } else if (virge->chip >= S3_VIRGEGX2 && svga->overlay.ena) { /* 0x20 = Secondary Stream enabled */ /* 0x2000 = Primary Stream enabled */ @@ -1012,7 +1033,8 @@ s3_virge_recalctimings(svga_t *svga) } static void -s3_virge_updatemapping(virge_t *virge) { +s3_virge_updatemapping(virge_t *virge) +{ svga_t *svga = &virge->svga; if (!(virge->pci_regs[PCI_REG_COMMAND] & PCI_COMMAND_MEM)) { @@ -1024,7 +1046,7 @@ s3_virge_updatemapping(virge_t *virge) { } switch (svga->gdcreg[6] & 0xc) { /*Banked framebuffer*/ - case 0x0: /*128k at A0000*/ + case 0x0: /*128k at A0000*/ mem_mapping_set_addr(&svga->mapping, 0xa0000, 0x20000); svga->banked_mask = 0xffff; break; @@ -1098,15 +1120,19 @@ s3_virge_updatemapping(virge_t *virge) { } static void -s3_virge_vblank_start(svga_t *svga) { +s3_virge_vblank_start(svga_t *svga) +{ virge_t *virge = (virge_t *) svga->priv; + if (virge->irq_pending) + virge->irq_pending--; virge->subsys_stat |= INT_VSY; s3_virge_update_irqs(virge); } static void -s3_virge_wait_fifo_idle(virge_t *virge) { +s3_virge_wait_fifo_idle(virge_t *virge) +{ while (!FIFO_EMPTY) { wake_fifo_thread(virge); thread_wait_event(virge->fifo_not_full_event, 1); @@ -1117,7 +1143,7 @@ static uint8_t s3_virge_mmio_read(uint32_t addr, void *priv) { virge_t *virge = (virge_t *) priv; - uint8_t ret; + uint8_t ret; switch (addr & 0xffff) { case 0x8504: @@ -1198,9 +1224,10 @@ s3_virge_mmio_read_w(uint32_t addr, void *priv) } static uint32_t -s3_virge_mmio_read_l(uint32_t addr, void *priv) { +s3_virge_mmio_read_l(uint32_t addr, void *priv) +{ virge_t *virge = (virge_t *) priv; - uint32_t ret = 0xffffffff; + uint32_t ret = 0xffffffff; switch (addr & 0xfffc) { case 0x8180: @@ -1429,7 +1456,7 @@ s3_virge_mmio_read_l(uint32_t addr, void *priv) { break; } - //pclog("MMIO ReadL=%04x, ret=%08x.\n", addr & 0xfffc, ret); + // pclog("MMIO ReadL=%04x, ret=%08x.\n", addr & 0xfffc, ret); return ret; } @@ -1443,15 +1470,15 @@ s3_virge_mmio_write_fifo_l(virge_t *virge, uint32_t addr, uint32_t val) int y = (addr >> 3) & 7; int color; int byte; - uint32_t newaddr = addr; - virge->s3d.pattern_8[y * 8 + x] = val & 0xff; + uint32_t newaddr = addr; + virge->s3d.pattern_8[y * 8 + x] = val & 0xff; virge->s3d.pattern_8[y * 8 + x + 1] = val >> 8; virge->s3d.pattern_8[y * 8 + x + 2] = val >> 16; virge->s3d.pattern_8[y * 8 + x + 3] = val >> 24; - x = (addr >> 1) & 6; - y = (addr >> 4) & 7; - virge->s3d.pattern_16[y * 8 + x] = val & 0xffff; + x = (addr >> 1) & 6; + y = (addr >> 4) & 7; + virge->s3d.pattern_16[y * 8 + x] = val & 0xffff; virge->s3d.pattern_16[y * 8 + x + 1] = val >> 16; newaddr &= 0x00ff; @@ -1464,22 +1491,21 @@ s3_virge_mmio_write_fifo_l(virge_t *virge, uint32_t addr, uint32_t val) virge->s3d.pattern_24[y * 8 + x] |= ((val >> byte) & 0xff) << color; } - x = (addr >> 2) & 7; - y = (addr >> 5) & 7; + x = (addr >> 2) & 7; + y = (addr >> 5) & 7; virge->s3d.pattern_32[y * 8 + x] = val & 0xffffff; - } break; + } + break; case 0xa4d4: case 0xa8d4: case 0xacd4: - virge->s3d.src_base = val & ((virge->memory_size == 8) ? - (val & 0x7ffff8) : (val & 0x3ffff8)); + virge->s3d.src_base = val & ((virge->memory_size == 8) ? (val & 0x7ffff8) : (val & 0x3ffff8)); break; case 0xa4d8: case 0xa8d8: case 0xacd8: - virge->s3d.dest_base = val & ((virge->memory_size == 8) ? - (val & 0x7ffff8) : (val & 0x3ffff8)); + virge->s3d.dest_base = val & ((virge->memory_size == 8) ? (val & 0x7ffff8) : (val & 0x3ffff8)); break; case 0xa4dc: case 0xa8dc: @@ -1497,7 +1523,7 @@ s3_virge_mmio_write_fifo_l(virge_t *virge, uint32_t addr, uint32_t val) case 0xa8e4: case 0xace4: virge->s3d.dest_str = (val >> 16) & 0xff8; - virge->s3d.src_str = val & 0xff8; + virge->s3d.src_str = val & 0xff8; break; case 0xa4e8: case 0xace8: @@ -1530,7 +1556,7 @@ s3_virge_mmio_write_fifo_l(virge_t *virge, uint32_t addr, uint32_t val) s3_virge_bitblt(virge, -1, 0); break; case 0xa504: - virge->s3d.r_width = (val >> 16) & 0x7ff; + virge->s3d.r_width = (val >> 16) & 0x7ff; virge->s3d.r_height = val & 0x7ff; break; case 0xa508: @@ -1548,7 +1574,7 @@ s3_virge_mmio_write_fifo_l(virge_t *virge, uint32_t addr, uint32_t val) virge->s3d.lxend1 = val & 0x7ff; break; case 0xa970: - virge->s3d.ldx = (int32_t)val; + virge->s3d.ldx = (int32_t) val; break; case 0xa974: virge->s3d.lxstart = val; @@ -1557,7 +1583,7 @@ s3_virge_mmio_write_fifo_l(virge_t *virge, uint32_t addr, uint32_t val) virge->s3d.lystart = val & 0x7ff; break; case 0xa97c: - virge->s3d.lycnt = val & 0x7ff; + virge->s3d.lycnt = val & 0x7ff; virge->s3d.line_dir = val >> 31; if (virge->s3d.cmd_set & CMD_SET_AE) s3_virge_bitblt(virge, -1, 0); @@ -1586,13 +1612,11 @@ s3_virge_mmio_write_fifo_l(virge_t *virge, uint32_t addr, uint32_t val) case 0xb0d4: case 0xb4d4: - virge->s3d_tri.z_base = val & ((virge->memory_size == 8) ? - (val & 0x7ffff8) : (val & 0x3ffff8)); + virge->s3d_tri.z_base = val & ((virge->memory_size == 8) ? (val & 0x7ffff8) : (val & 0x3ffff8)); break; case 0xb0d8: case 0xb4d8: - virge->s3d_tri.dest_base = val & ((virge->memory_size == 8) ? - (val & 0x7ffff8) : (val & 0x3ffff8)); + virge->s3d_tri.dest_base = val & ((virge->memory_size == 8) ? (val & 0x7ffff8) : (val & 0x3ffff8)); break; case 0xb0dc: case 0xb4dc: @@ -1607,15 +1631,14 @@ s3_virge_mmio_write_fifo_l(virge_t *virge, uint32_t addr, uint32_t val) case 0xb0e4: case 0xb4e4: virge->s3d_tri.dest_str = (val >> 16) & 0xff8; - virge->s3d.src_str = val & 0xff8; + virge->s3d.src_str = val & 0xff8; break; case 0xb0e8: case 0xb4e8: virge->s3d_tri.z_str = val & 0xff8; break; case 0xb4ec: - virge->s3d_tri.tex_base = val & ((virge->memory_size == 8) ? - (val & 0x7ffff8) : (val & 0x3ffff8)); + virge->s3d_tri.tex_base = val & ((virge->memory_size == 8) ? (val & 0x7ffff8) : (val & 0x3ffff8)); break; case 0xb4f0: virge->s3d_tri.tex_bdr_clr = val & 0xffffff; @@ -1732,17 +1755,17 @@ s3_virge_mmio_write_fifo_l(virge_t *virge, uint32_t addr, uint32_t val) case 0xb57c: virge->s3d_tri.ty01 = (val >> 16) & 0x7ff; virge->s3d_tri.ty12 = val & 0x7ff; - virge->s3d_tri.tlr = val >> 31; + virge->s3d_tri.tlr = val >> 31; if (virge->s3d_tri.cmd_set & CMD_SET_AE) queue_triangle(virge); - break; + break; } } static void fifo_thread(void *param) { - virge_t *virge = (virge_t *)param; + virge_t *virge = (virge_t *) param; while (virge->fifo_thread_run) { thread_set_event(virge->fifo_not_full_event); @@ -1750,10 +1773,10 @@ fifo_thread(void *param) thread_reset_event(virge->wake_fifo_thread); virge->virge_busy = 1; while (!FIFO_EMPTY) { - uint64_t start_time = plat_timer_read(); - uint64_t end_time; + uint64_t start_time = plat_timer_read(); + uint64_t end_time; fifo_entry_t *fifo = &virge->fifo[virge->fifo_read_idx & FIFO_MASK]; - uint32_t val = fifo->val; + uint32_t val = fifo->val; switch (fifo->addr_type & FIFO_TYPE) { case FIFO_WRITE_BYTE: @@ -1784,26 +1807,26 @@ fifo_thread(void *param) virge->fifo_read_idx++; fifo->addr_type = FIFO_INVALID; - if (FIFO_ENTRIES > 0xe000) - thread_set_event(virge->fifo_not_full_event); + if (FIFO_ENTRIES > 0xe000) + thread_set_event(virge->fifo_not_full_event); - end_time = plat_timer_read(); - virge_time += end_time - start_time; - } - virge->virge_busy = 0; - virge->subsys_stat |= (INT_FIFO_EMP | INT_3DF_EMP); - if (virge->cmd_dma) + end_time = plat_timer_read(); + virge_time += end_time - start_time; + } + virge->virge_busy = 0; + virge->subsys_stat |= (INT_FIFO_EMP | INT_3DF_EMP); + if (virge->cmd_dma) virge->subsys_stat |= (INT_HOST_DONE | INT_CMD_DONE); - s3_virge_update_irqs(virge); + virge->irq_pending++; } } static void s3_virge_queue(virge_t *virge, uint32_t addr, uint32_t val, uint32_t type) { - fifo_entry_t *fifo = &virge->fifo[virge->fifo_write_idx & FIFO_MASK]; - int limit = 0; + fifo_entry_t *fifo = &virge->fifo[virge->fifo_write_idx & FIFO_MASK]; + int limit = 0; if (type == FIFO_WRITE_DWORD) { switch (addr & 0xfffc) { @@ -1830,7 +1853,7 @@ s3_virge_queue(virge_t *virge, uint32_t addr, uint32_t val, uint32_t type) } } - fifo->val = val; + fifo->val = val; fifo->addr_type = (addr & FIFO_ADDR) | type; virge->fifo_write_idx++; @@ -1906,7 +1929,7 @@ s3_virge_mmio_write_l(uint32_t addr, uint32_t val, void *priv) virge->streams.chroma_ctrl = val; break; case 0x8190: - virge->streams.sec_ctrl = val; + virge->streams.sec_ctrl = val; virge->streams.dda_horiz_accumulator = val & 0xfff; if (val & 0x1000) virge->streams.dda_horiz_accumulator |= ~0xfff; @@ -1917,7 +1940,7 @@ s3_virge_mmio_write_l(uint32_t addr, uint32_t val, void *priv) virge->streams.chroma_upper_bound = val; break; case 0x8198: - virge->streams.sec_filter = val; + virge->streams.sec_filter = val; virge->streams.k1_horiz_scale = val & 0x7ff; if (val & 0x800) virge->streams.k1_horiz_scale |= ~0x7ff; @@ -1997,29 +2020,29 @@ s3_virge_mmio_write_l(uint32_t addr, uint32_t val, void *priv) break; case 0x81f0: virge->streams.pri_start = val; - virge->streams.pri_x = (val >> 16) & 0x7ff; - virge->streams.pri_y = val & 0x7ff; + virge->streams.pri_x = (val >> 16) & 0x7ff; + virge->streams.pri_y = val & 0x7ff; svga_recalctimings(svga); svga->fullchange = changeframecount; break; case 0x81f4: virge->streams.pri_size = val; - virge->streams.pri_w = (val >> 16) & 0x7ff; - virge->streams.pri_h = val & 0x7ff; + virge->streams.pri_w = (val >> 16) & 0x7ff; + virge->streams.pri_h = val & 0x7ff; svga_recalctimings(svga); svga->fullchange = changeframecount; break; case 0x81f8: virge->streams.sec_start = val; - virge->streams.sec_x = (val >> 16) & 0x7ff; - virge->streams.sec_y = val & 0x7ff; + virge->streams.sec_x = (val >> 16) & 0x7ff; + virge->streams.sec_y = val & 0x7ff; svga_recalctimings(svga); svga->fullchange = changeframecount; break; case 0x81fc: virge->streams.sec_size = val; - virge->streams.sec_w = (val >> 16) & 0x7ff; - virge->streams.sec_h = val & 0x7ff; + virge->streams.sec_w = (val >> 16) & 0x7ff; + virge->streams.sec_h = val & 0x7ff; svga_recalctimings(svga); svga->fullchange = changeframecount; break; @@ -2036,23 +2059,23 @@ s3_virge_mmio_write_l(uint32_t addr, uint32_t val, void *priv) break; case 0x8590: - virge->cmd_dma_base = val; - virge->cmd_dma_buf_size = (val & 2) ? 0x10000 : 0x1000; + virge->cmd_dma_base = val; + virge->cmd_dma_buf_size = (val & 2) ? 0x10000 : 0x1000; virge->cmd_dma_buf_size_mask = virge->cmd_dma_buf_size - 1; - virge->cmd_base_addr = (val & 2) ? (val & 0xffff0000) : (val & 0xfffff000); + virge->cmd_base_addr = (val & 2) ? (val & 0xffff0000) : (val & 0xfffff000); break; case 0x8594: virge->cmd_dma_write_ptr_update = val & (1 << 16); if (virge->cmd_dma_write_ptr_update) { virge->cmd_dma_write_ptr_reg = (virge->cmd_dma_buf_size == 0x10000) ? (val & 0xffff) : (val & 0xfff); - virge->dma_dbl_words = 0; - virge->dma_data_type = 0; - virge->dma_val = 0; + virge->dma_dbl_words = 0; + virge->dma_data_type = 0; + virge->dma_val = 0; if (virge->cmd_dma) { while (virge->cmd_dma_read_ptr_reg != virge->cmd_dma_write_ptr_reg) { virge->cmd_dma_write_ptr_update = 0; - dma_bm_read(virge->cmd_base_addr + virge->cmd_dma_read_ptr_reg, (uint8_t *)&virge->dma_val, 4, 4); + dma_bm_read(virge->cmd_base_addr + virge->cmd_dma_read_ptr_reg, (uint8_t *) &virge->dma_val, 4, 4); if (!virge->dma_dbl_words) { virge->dma_dbl_words = (virge->dma_val & 0xffff); virge->dma_data_type = !!(virge->dma_val & (1 << 31)); @@ -2076,9 +2099,9 @@ s3_virge_mmio_write_l(uint32_t addr, uint32_t val, void *priv) break; case 0x859c: - virge->cmd_dma = val & 1; + virge->cmd_dma = val & 1; virge->cmd_dma_write_ptr_reg = 0; - virge->cmd_dma_read_ptr_reg = 0; + virge->cmd_dma_read_ptr_reg = 0; break; case 0xff20: @@ -2088,133 +2111,899 @@ s3_virge_mmio_write_l(uint32_t addr, uint32_t val, void *priv) } } -#define READ(addr, val) \ - do { \ - switch (bpp) { \ - case 0: /*8 bpp*/ \ - val = vram[addr & virge->vram_mask]; \ - break; \ - case 1: /*16 bpp*/ \ - val = *(uint16_t *)&vram[addr & virge->vram_mask]; \ - break; \ - case 2: /*24 bpp*/ \ - val = (*(uint32_t *)&vram[addr & virge->vram_mask]) & 0xffffff; \ - break; \ - } \ +#define READ(addr, val) \ + do { \ + switch (bpp) { \ + case 0: /*8 bpp*/ \ + val = vram[addr & virge->vram_mask]; \ + break; \ + case 1: /*16 bpp*/ \ + val = *(uint16_t *) &vram[addr & virge->vram_mask]; \ + break; \ + case 2: /*24 bpp*/ \ + val = (*(uint32_t *) &vram[addr & virge->vram_mask]) & 0xffffff; \ + break; \ + } \ } while (0) -#define Z_READ(addr) *(uint16_t *)&vram[addr & virge->vram_mask] +#define Z_READ(addr) *(uint16_t *) &vram[addr & virge->vram_mask] -#define Z_WRITE(addr, val) \ - if (!(s3d_tri->cmd_set & CMD_SET_ZB_MODE)) \ - *(uint16_t *)&vram[addr & virge->vram_mask] = val +#define Z_WRITE(addr, val) \ + if (!(s3d_tri->cmd_set & CMD_SET_ZB_MODE)) \ + *(uint16_t *) &vram[addr & virge->vram_mask] = val -#define CLIP(x, y) \ - do { \ - if ((virge->s3d.cmd_set & CMD_SET_HC) && \ - (x < virge->s3d.clip_l || x > virge->s3d.clip_r || \ - y < virge->s3d.clip_t || y > virge->s3d.clip_b)) \ - update = 0; \ +#define CLIP(x, y) \ + do { \ + if ((virge->s3d.cmd_set & CMD_SET_HC) && \ + (x < virge->s3d.clip_l || x > virge->s3d.clip_r || \ + y < virge->s3d.clip_t || y > virge->s3d.clip_b)) \ + update = 0; \ } while (0) -#define CLIP_3D(x, y) \ - do { \ - if ((s3d_tri->cmd_set & CMD_SET_HC) && (x < s3d_tri->clip_l || \ - x > s3d_tri->clip_r || y < s3d_tri->clip_t || \ - y > s3d_tri->clip_b)) \ - update = 0; \ +#define CLIP_3D(x, y) \ + do { \ + if ((s3d_tri->cmd_set & CMD_SET_HC) && (x < s3d_tri->clip_l || \ + x > s3d_tri->clip_r || y < s3d_tri->clip_t || \ + y > s3d_tri->clip_b)) \ + update = 0; \ } while (0) -#define Z_CLIP(Zzb, Zs) \ - do { \ - if (!(s3d_tri->cmd_set & CMD_SET_ZB_MODE)) \ - switch ((s3d_tri->cmd_set >> 20) & 7) { \ - case 0: \ - update = 0; \ - break; \ - case 1: \ - if (Zs <= Zzb) \ - update = 0; \ - else \ - Zzb = Zs; \ - break; \ - case 2: \ - if (Zs != Zzb) \ - update = 0; \ - else \ - Zzb = Zs; \ - break; \ - case 3: \ - if (Zs < Zzb) \ - update = 0; \ - else \ - Zzb = Zs; \ - break; \ - case 4: \ - if (Zs >= Zzb) \ - update = 0; \ - else \ - Zzb = Zs; \ - break; \ - case 5: \ - if (Zs == Zzb) \ - update = 0; \ - else \ - Zzb = Zs; \ - break; \ - case 6: \ - if (Zs > Zzb) \ - update = 0; \ - else \ - Zzb = Zs; \ - break; \ - case 7: \ - update = 1; \ - Zzb = Zs; \ - break; \ - } \ - } while (0) - -#define MIX() \ - do { \ - int c; \ - for (c = 0; c < 24; c++) { \ - int d = (dest & (1 << c)) ? 1 : 0; \ - if (source & (1 << c)) \ - d |= 2; \ - if (pattern & (1 << c)) \ - d |= 4; \ - if (virge->s3d.rop & (1 << d)) \ - out |= (1 << c); \ - } \ +#define Z_CLIP(Zzb, Zs) \ + do { \ + if (!(s3d_tri->cmd_set & CMD_SET_ZB_MODE)) \ + switch ((s3d_tri->cmd_set >> 20) & 7) { \ + case 0: \ + update = 0; \ + break; \ + case 1: \ + if (Zs <= Zzb) \ + update = 0; \ + else \ + Zzb = Zs; \ + break; \ + case 2: \ + if (Zs != Zzb) \ + update = 0; \ + else \ + Zzb = Zs; \ + break; \ + case 3: \ + if (Zs < Zzb) \ + update = 0; \ + else \ + Zzb = Zs; \ + break; \ + case 4: \ + if (Zs >= Zzb) \ + update = 0; \ + else \ + Zzb = Zs; \ + break; \ + case 5: \ + if (Zs == Zzb) \ + update = 0; \ + else \ + Zzb = Zs; \ + break; \ + case 6: \ + if (Zs > Zzb) \ + update = 0; \ + else \ + Zzb = Zs; \ + break; \ + case 7: \ + update = 1; \ + Zzb = Zs; \ + break; \ + } \ } while (0) -#define WRITE(addr, val) \ - do { \ - switch (bpp) { \ - case 0: /*8 bpp*/ \ - vram[addr & virge->vram_mask] = val; \ - virge->svga.changedvram[(addr & virge->vram_mask) >> 12] = \ - changeframecount; \ - break; \ - case 1: /*16 bpp*/ \ - *(uint16_t *)&vram[addr & virge->vram_mask] = val; \ - virge->svga.changedvram[(addr & virge->vram_mask) >> 12] = \ - changeframecount; \ - break; \ - case 2: /*24 bpp*/ \ - *(uint32_t *)&vram[addr & virge->vram_mask] = (val & 0xffffff) |\ - (vram[(addr + 3) & virge->vram_mask] << 24); \ - virge->svga.changedvram[(addr & virge->vram_mask) >> 12] = \ - changeframecount; \ - break; \ - } \ +#define ROPMIX(R, D, P, S, out) \ + { \ + switch (R) { \ + case 0x00: \ + out = 0; \ + break; \ + case 0x01: \ + out = ~(D | (P | S)); \ + break; \ + case 0x02: \ + out = D & ~(P | S); \ + break; \ + case 0x03: \ + out = ~(P | S); \ + break; \ + case 0x04: \ + out = S & ~(D | P); \ + break; \ + case 0x05: \ + out = ~(D | P); \ + break; \ + case 0x06: \ + out = ~(P | ~(D ^ S)); \ + break; \ + case 0x07: \ + out = ~(P | (D & S)); \ + break; \ + case 0x08: \ + out = S & (D & ~P); \ + break; \ + case 0x09: \ + out = ~(P | (D ^ S)); \ + break; \ + case 0x0a: \ + out = D & ~P; \ + break; \ + case 0x0b: \ + out = ~(P | (S & ~D)); \ + break; \ + case 0x0c: \ + out = S & ~P; \ + break; \ + case 0x0d: \ + out = ~(P | (D & ~S)); \ + break; \ + case 0x0e: \ + out = ~(P | ~(D | S)); \ + break; \ + case 0x0f: \ + out = ~P; \ + break; \ + case 0x10: \ + out = P & ~(D | S); \ + break; \ + case 0x11: \ + out = ~(D | S); \ + break; \ + case 0x12: \ + out = ~(S | ~(D ^ P)); \ + break; \ + case 0x13: \ + out = ~(S | (D & P)); \ + break; \ + case 0x14: \ + out = ~(D | ~(P ^ S)); \ + break; \ + case 0x15: \ + out = ~(D | (P & S)); \ + break; \ + case 0x16: \ + out = P ^ (S ^ (D & ~(P & S))); \ + break; \ + case 0x17: \ + out = ~(S ^ ((S ^ P) & (D ^ S))); \ + break; \ + case 0x18: \ + out = (S ^ P) & (P ^ D); \ + break; \ + case 0x19: \ + out = ~(S ^ (D & ~(P & S))); \ + break; \ + case 0x1a: \ + out = P ^ (D | (S & P)); \ + break; \ + case 0x1b: \ + out = ~(S ^ (D & (P ^ S))); \ + break; \ + case 0x1c: \ + out = P ^ (S | (D & P)); \ + break; \ + case 0x1d: \ + out = ~(D ^ (S & (P ^ D))); \ + break; \ + case 0x1e: \ + out = P ^ (D | S); \ + break; \ + case 0x1f: \ + out = ~(P & (D | S)); \ + break; \ + case 0x20: \ + out = D & (P & ~S); \ + break; \ + case 0x21: \ + out = ~(S | (D ^ P)); \ + break; \ + case 0x22: \ + out = D & ~S; \ + break; \ + case 0x23: \ + out = ~(S | (P & ~D)); \ + break; \ + case 0x24: \ + out = (S ^ P) & (D ^ S); \ + break; \ + case 0x25: \ + out = ~(P ^ (D & ~(S & P))); \ + break; \ + case 0x26: \ + out = S ^ (D | (P & S)); \ + break; \ + case 0x27: \ + out = S ^ (D | ~(P ^ S)); \ + break; \ + case 0x28: \ + out = D & (P ^ S); \ + break; \ + case 0x29: \ + out = ~(P ^ (S ^ (D | (P & S)))); \ + break; \ + case 0x2a: \ + out = D & ~(P & S); \ + break; \ + case 0x2b: \ + out = ~(S ^ ((S ^ P) & (P ^ D))); \ + break; \ + case 0x2c: \ + out = S ^ (P & (D | S)); \ + break; \ + case 0x2d: \ + out = P ^ (S | ~D); \ + break; \ + case 0x2e: \ + out = P ^ (S | (D ^ P)); \ + break; \ + case 0x2f: \ + out = ~(P & (S | ~D)); \ + break; \ + case 0x30: \ + out = P & ~S; \ + break; \ + case 0x31: \ + out = ~(S | (D & ~P)); \ + break; \ + case 0x32: \ + out = S ^ (D | (P | S)); \ + break; \ + case 0x33: \ + out = ~S; \ + break; \ + case 0x34: \ + out = S ^ (P | (D & S)); \ + break; \ + case 0x35: \ + out = S ^ (P | ~(D ^ S)); \ + break; \ + case 0x36: \ + out = S ^ (D | P); \ + break; \ + case 0x37: \ + out = ~(S & (D | P)); \ + break; \ + case 0x38: \ + out = P ^ (S & (D | P)); \ + break; \ + case 0x39: \ + out = S ^ (P | ~D); \ + break; \ + case 0x3a: \ + out = S ^ (P | (D ^ S)); \ + break; \ + case 0x3b: \ + out = ~(S & (P | ~D)); \ + break; \ + case 0x3c: \ + out = P ^ S; \ + break; \ + case 0x3d: \ + out = S ^ (P | ~(D | S)); \ + break; \ + case 0x3e: \ + out = S ^ (P | (D & ~S)); \ + break; \ + case 0x3f: \ + out = ~(P & S); \ + break; \ + case 0x40: \ + out = P & (S & ~D); \ + break; \ + case 0x41: \ + out = ~(D | (P ^ S)); \ + break; \ + case 0x42: \ + out = (S ^ D) & (P ^ D); \ + break; \ + case 0x43: \ + out = ~(S ^ (P & ~(D & S))); \ + break; \ + case 0x44: \ + out = S & ~D; \ + break; \ + case 0x45: \ + out = ~(D | (P & ~S)); \ + break; \ + case 0x46: \ + out = D ^ (S | (P & D)); \ + break; \ + case 0x47: \ + out = ~(P ^ (S & (D ^ P))); \ + break; \ + case 0x48: \ + out = S & (D ^ P); \ + break; \ + case 0x49: \ + out = ~(P ^ (D ^ (S | (P & D)))); \ + break; \ + case 0x4a: \ + out = D ^ (P & (S | D)); \ + break; \ + case 0x4b: \ + out = P ^ (D | ~S); \ + break; \ + case 0x4c: \ + out = S & ~(D & P); \ + break; \ + case 0x4d: \ + out = ~(S ^ ((S ^ P) | (D ^ S))); \ + break; \ + case 0x4e: \ + out = P ^ (D | (S ^ P)); \ + break; \ + case 0x4f: \ + out = ~(P & (D | ~S)); \ + break; \ + case 0x50: \ + out = P & ~D; \ + break; \ + case 0x51: \ + out = ~(D | (S & ~P)); \ + break; \ + case 0x52: \ + out = D ^ (P | (S & D)); \ + break; \ + case 0x53: \ + out = ~(S ^ (P & (D ^ S))); \ + break; \ + case 0x54: \ + out = ~(D | ~(P | S)); \ + break; \ + case 0x55: \ + out = ~D; \ + break; \ + case 0x56: \ + out = D ^ (P | S); \ + break; \ + case 0x57: \ + out = ~(D & (P | S)); \ + break; \ + case 0x58: \ + out = P ^ (D & (S | P)); \ + break; \ + case 0x59: \ + out = D ^ (P | ~S); \ + break; \ + case 0x5a: \ + out = D ^ P; \ + break; \ + case 0x5b: \ + out = D ^ (P | ~(S | D)); \ + break; \ + case 0x5c: \ + out = D ^ (P | (S ^ D)); \ + break; \ + case 0x5d: \ + out = ~(D & (P | ~S)); \ + break; \ + case 0x5e: \ + out = D ^ (P | (S & ~D)); \ + break; \ + case 0x5f: \ + out = ~(D & P); \ + break; \ + case 0x60: \ + out = P & (D ^ S); \ + break; \ + case 0x61: \ + out = ~(D ^ (S ^ (P | (D & S)))); \ + break; \ + case 0x62: \ + out = D ^ (S & (P | D)); \ + break; \ + case 0x63: \ + out = S ^ (D | ~P); \ + break; \ + case 0x64: \ + out = S ^ (D & (P | S)); \ + break; \ + case 0x65: \ + out = D ^ (S | ~P); \ + break; \ + case 0x66: \ + out = D ^ S; \ + break; \ + case 0x67: \ + out = S ^ (D | ~(P | S)); \ + break; \ + case 0x68: \ + out = ~(D ^ (S ^ (P | ~(D | S)))); \ + break; \ + case 0x69: \ + out = ~(P ^ (D ^ S)); \ + break; \ + case 0x6a: \ + out = D ^ (P & S); \ + break; \ + case 0x6b: \ + out = ~(P ^ (S ^ (D & (P | S)))); \ + break; \ + case 0x6c: \ + out = S ^ (D & P); \ + break; \ + case 0x6d: \ + out = ~(P ^ (D ^ (S & (P | D)))); \ + break; \ + case 0x6e: \ + out = S ^ (D & (P | ~S)); \ + break; \ + case 0x6f: \ + out = ~(P & ~(D ^ S)); \ + break; \ + case 0x70: \ + out = P & ~(D & S); \ + break; \ + case 0x71: \ + out = ~(S ^ ((S ^ D) & (P ^ D))); \ + break; \ + case 0x72: \ + out = S ^ (D | (P ^ S)); \ + break; \ + case 0x73: \ + out = ~(S & (D | ~P)); \ + break; \ + case 0x74: \ + out = D ^ (S | (P ^ D)); \ + break; \ + case 0x75: \ + out = ~(D & (S | ~P)); \ + break; \ + case 0x76: \ + out = S ^ (D | (P & ~S)); \ + break; \ + case 0x77: \ + out = ~(D & S); \ + break; \ + case 0x78: \ + out = P ^ (D & S); \ + break; \ + case 0x79: \ + out = ~(D ^ (S ^ (P & (D | S)))); \ + break; \ + case 0x7a: \ + out = D ^ (P & (S | ~D)); \ + break; \ + case 0x7b: \ + out = ~(S & ~(D ^ P)); \ + break; \ + case 0x7c: \ + out = S ^ (P & (D | ~S)); \ + break; \ + case 0x7d: \ + out = ~(D & ~(P ^ S)); \ + break; \ + case 0x7e: \ + out = (S ^ P) | (D ^ S); \ + break; \ + case 0x7f: \ + out = ~(D & (P & S)); \ + break; \ + case 0x80: \ + out = D & (P & S); \ + break; \ + case 0x81: \ + out = ~((S ^ P) | (D ^ S)); \ + break; \ + case 0x82: \ + out = D & ~(P ^ S); \ + break; \ + case 0x83: \ + out = ~(S ^ (P & (D | ~S))); \ + break; \ + case 0x84: \ + out = S & ~(D ^ P); \ + break; \ + case 0x85: \ + out = ~(P ^ (D & (S | ~P))); \ + break; \ + case 0x86: \ + out = D ^ (S ^ (P & (D | S))); \ + break; \ + case 0x87: \ + out = ~(P ^ (D & S)); \ + break; \ + case 0x88: \ + out = D & S; \ + break; \ + case 0x89: \ + out = ~(S ^ (D | (P & ~S))); \ + break; \ + case 0x8a: \ + out = D & (S | ~P); \ + break; \ + case 0x8b: \ + out = ~(D ^ (S | (P ^ D))); \ + break; \ + case 0x8c: \ + out = S & (D | ~P); \ + break; \ + case 0x8d: \ + out = ~(S ^ (D | (P ^ S))); \ + break; \ + case 0x8e: \ + out = S ^ ((S ^ D) & (P ^ D)); \ + break; \ + case 0x8f: \ + out = ~(P & ~(D & S)); \ + break; \ + case 0x90: \ + out = P & ~(D ^ S); \ + break; \ + case 0x91: \ + out = ~(S ^ (D & (P | ~S))); \ + break; \ + case 0x92: \ + out = D ^ (P ^ (S & (D | P))); \ + break; \ + case 0x93: \ + out = ~(S ^ (P & D)); \ + break; \ + case 0x94: \ + out = P ^ (S ^ (D & (P | S))); \ + break; \ + case 0x95: \ + out = ~(D ^ (P & S)); \ + break; \ + case 0x96: \ + out = D ^ (P ^ S); \ + break; \ + case 0x97: \ + out = P ^ (S ^ (D | ~(P | S))); \ + break; \ + case 0x98: \ + out = ~(S ^ (D | ~(P | S))); \ + break; \ + case 0x99: \ + out = ~(D ^ S); \ + break; \ + case 0x9a: \ + out = D ^ (P & ~S); \ + break; \ + case 0x9b: \ + out = ~(S ^ (D & (P | S))); \ + break; \ + case 0x9c: \ + out = S ^ (P & ~D); \ + break; \ + case 0x9d: \ + out = ~(D ^ (S & (P | D))); \ + break; \ + case 0x9e: \ + out = D ^ (S ^ (P | (D & S))); \ + break; \ + case 0x9f: \ + out = ~(P & (D ^ S)); \ + break; \ + case 0xa0: \ + out = D & P; \ + break; \ + case 0xa1: \ + out = ~(P ^ (D | (S & ~P))); \ + break; \ + case 0xa2: \ + out = D & (P | ~S); \ + break; \ + case 0xa3: \ + out = ~(D ^ (P | (S ^ D))); \ + break; \ + case 0xa4: \ + out = ~(P ^ (D | ~(S | P))); \ + break; \ + case 0xa5: \ + out = ~(P ^ D); \ + break; \ + case 0xa6: \ + out = D ^ (S & ~P); \ + break; \ + case 0xa7: \ + out = ~(P ^ (D & (S | P))); \ + break; \ + case 0xa8: \ + out = D & (P | S); \ + break; \ + case 0xa9: \ + out = ~(D ^ (P | S)); \ + break; \ + case 0xaa: \ + out = D; \ + break; \ + case 0xab: \ + out = D | ~(P | S); \ + break; \ + case 0xac: \ + out = S ^ (P & (D ^ S)); \ + break; \ + case 0xad: \ + out = ~(D ^ (P | (S & D))); \ + break; \ + case 0xae: \ + out = D | (S & ~P); \ + break; \ + case 0xaf: \ + out = D | ~P; \ + break; \ + case 0xb0: \ + out = P & (D | ~S); \ + break; \ + case 0xb1: \ + out = ~(P ^ (D | (S ^ P))); \ + break; \ + case 0xb2: \ + out = S ^ ((S ^ P) | (D ^ S)); \ + break; \ + case 0xb3: \ + out = ~(S & ~(D & P)); \ + break; \ + case 0xb4: \ + out = P ^ (S & ~D); \ + break; \ + case 0xb5: \ + out = ~(D ^ (P & (S | D))); \ + break; \ + case 0xb6: \ + out = D ^ (P ^ (S | (D & P))); \ + break; \ + case 0xb7: \ + out = ~(S & (D ^ P)); \ + break; \ + case 0xb8: \ + out = P ^ (S & (D ^ P)); \ + break; \ + case 0xb9: \ + out = ~(D ^ (S | (P & D))); \ + break; \ + case 0xba: \ + out = D | (P & ~S); \ + break; \ + case 0xbb: \ + out = D | ~S; \ + break; \ + case 0xbc: \ + out = S ^ (P & ~(D & S)); \ + break; \ + case 0xbd: \ + out = ~((S ^ D) & (P ^ D)); \ + break; \ + case 0xbe: \ + out = D | (P ^ S); \ + break; \ + case 0xbf: \ + out = D | ~(P & S); \ + break; \ + case 0xc0: \ + out = P & S; \ + break; \ + case 0xc1: \ + out = ~(S ^ (P | (D & ~S))); \ + break; \ + case 0xc2: \ + out = ~(S ^ (P | ~(D | S))); \ + break; \ + case 0xc3: \ + out = ~(P ^ S); \ + break; \ + case 0xc4: \ + out = S & (P | ~D); \ + break; \ + case 0xc5: \ + out = ~(S ^ (P | (D ^ S))); \ + break; \ + case 0xc6: \ + out = S ^ (D & ~P); \ + break; \ + case 0xc7: \ + out = ~(P ^ (S & (D | P))); \ + break; \ + case 0xc8: \ + out = S & (D | P); \ + break; \ + case 0xc9: \ + out = ~(S ^ (P | D)); \ + break; \ + case 0xca: \ + out = D ^ (P & (S ^ D)); \ + break; \ + case 0xcb: \ + out = ~(S ^ (P | (D & S))); \ + break; \ + case 0xcc: \ + out = S; \ + break; \ + case 0xcd: \ + out = S | ~(D | P); \ + break; \ + case 0xce: \ + out = S | (D & ~P); \ + break; \ + case 0xcf: \ + out = S | ~P; \ + break; \ + case 0xd0: \ + out = P & (S | ~D); \ + break; \ + case 0xd1: \ + out = ~(P ^ (S | (D ^ P))); \ + break; \ + case 0xd2: \ + out = P ^ (D & ~S); \ + break; \ + case 0xd3: \ + out = ~(S ^ (P & (D | S))); \ + break; \ + case 0xd4: \ + out = S ^ ((S ^ P) & (P ^ D)); \ + break; \ + case 0xd5: \ + out = ~(D & ~(P & S)); \ + break; \ + case 0xd6: \ + out = P ^ (S ^ (D | (P & S))); \ + break; \ + case 0xd7: \ + out = ~(D & (P ^ S)); \ + break; \ + case 0xd8: \ + out = P ^ (D & (S ^ P)); \ + break; \ + case 0xd9: \ + out = ~(S ^ (D | (P & S))); \ + break; \ + case 0xda: \ + out = D ^ (P & ~(S & D)); \ + break; \ + case 0xdb: \ + out = ~((S ^ P) & (D ^ S)); \ + break; \ + case 0xdc: \ + out = S | (P & ~D); \ + break; \ + case 0xdd: \ + out = S | ~D; \ + break; \ + case 0xde: \ + out = S | (D ^ P); \ + break; \ + case 0xdf: \ + out = S | ~(D & P); \ + break; \ + case 0xe0: \ + out = P & (D | S); \ + break; \ + case 0xe1: \ + out = ~(P ^ (D | S)); \ + break; \ + case 0xe2: \ + out = D ^ (S & (P ^ D)); \ + break; \ + case 0xe3: \ + out = ~(P ^ (S | (D & P))); \ + break; \ + case 0xe4: \ + out = S ^ (D & (P ^ S)); \ + break; \ + case 0xe5: \ + out = ~(P ^ (D | (S & P))); \ + break; \ + case 0xe6: \ + out = S ^ (D & ~(P & S)); \ + break; \ + case 0xe7: \ + out = ~((S ^ P) & (P ^ D)); \ + break; \ + case 0xe8: \ + out = S ^ ((S ^ P) & (D ^ S)); \ + break; \ + case 0xe9: \ + out = ~(D ^ (S ^ (P & ~(D & S)))); \ + break; \ + case 0xea: \ + out = D | (P & S); \ + break; \ + case 0xeb: \ + out = D | ~(P ^ S); \ + break; \ + case 0xec: \ + out = S | (D & P); \ + break; \ + case 0xed: \ + out = S | ~(D ^ P); \ + break; \ + case 0xee: \ + out = D | S; \ + break; \ + case 0xef: \ + out = S | (D | ~P); \ + break; \ + case 0xf0: \ + out = P; \ + break; \ + case 0xf1: \ + out = P | ~(D | S); \ + break; \ + case 0xf2: \ + out = P | (D & ~S); \ + break; \ + case 0xf3: \ + out = P | ~S; \ + break; \ + case 0xf4: \ + out = P | (S & ~D); \ + break; \ + case 0xf5: \ + out = P | ~D; \ + break; \ + case 0xf6: \ + out = P | (D ^ S); \ + break; \ + case 0xf7: \ + out = P | ~(D & S); \ + break; \ + case 0xf8: \ + out = P | (D & S); \ + break; \ + case 0xf9: \ + out = P | ~(D ^ S); \ + break; \ + case 0xfa: \ + out = D | P; \ + break; \ + case 0xfb: \ + out = D | (P | ~S); \ + break; \ + case 0xfc: \ + out = P | S; \ + break; \ + case 0xfd: \ + out = P | (S | ~D); \ + break; \ + case 0xfe: \ + out = D | (P | S); \ + break; \ + case 0xff: \ + out = ~0; \ + break; \ + } \ + } + +#define MIX() \ + do { \ + ROPMIX(virge->s3d.rop & 0xFF, dest, pattern, source, out); \ + out &= 0xFFFFFF; \ + } while (0) + +#define WRITE(addr, val) \ + do { \ + switch (bpp) { \ + case 0: /*8 bpp*/ \ + vram[addr & virge->vram_mask] = val; \ + virge->svga.changedvram[(addr & virge->vram_mask) >> 12] = \ + changeframecount; \ + break; \ + case 1: /*16 bpp*/ \ + *(uint16_t *)&vram[addr & virge->vram_mask] = val; \ + virge->svga.changedvram[(addr & virge->vram_mask) >> 12] = \ + changeframecount; \ + break; \ + case 2: /*24 bpp*/ \ + *(uint32_t *)&vram[addr & virge->vram_mask] = (val & 0xffffff) | \ + (vram[(addr + 3) & virge->vram_mask] << 24); \ + virge->svga.changedvram[(addr & virge->vram_mask) >> 12] = \ + changeframecount; \ + break; \ + } \ } while (0) static void s3_virge_bitblt(virge_t *virge, int count, uint32_t cpu_dat) { - uint8_t *vram = virge->svga.vram; + uint8_t *vram = virge->svga.vram; uint32_t mono_pattern[64]; int count_mask; int x_inc = (virge->s3d.cmd_set & CMD_SET_XP) ? 1 : -1; @@ -2228,33 +3017,33 @@ s3_virge_bitblt(virge_t *virge, int count, uint32_t cpu_dat) switch (virge->s3d.cmd_set & CMD_SET_FORMAT_MASK) { case CMD_SET_FORMAT_8: - bpp = 0; - x_mul = 1; + bpp = 0; + x_mul = 1; cpu_dat_shift = 8; - pattern_data = virge->s3d.pattern_8; - src_fg_clr = virge->s3d.src_fg_clr & 0xff; - src_bg_clr = virge->s3d.src_bg_clr & 0xff; + pattern_data = virge->s3d.pattern_8; + src_fg_clr = virge->s3d.src_fg_clr & 0xff; + src_bg_clr = virge->s3d.src_bg_clr & 0xff; break; case CMD_SET_FORMAT_16: - bpp = 1; - x_mul = 2; + bpp = 1; + x_mul = 2; cpu_dat_shift = 16; - pattern_data = virge->s3d.pattern_16; - src_fg_clr = virge->s3d.src_fg_clr & 0xffff; - src_bg_clr = virge->s3d.src_bg_clr & 0xffff; + pattern_data = virge->s3d.pattern_16; + src_fg_clr = virge->s3d.src_fg_clr & 0xffff; + src_bg_clr = virge->s3d.src_bg_clr & 0xffff; break; case CMD_SET_FORMAT_24: default: - bpp = 2; - x_mul = 3; + bpp = 2; + x_mul = 3; cpu_dat_shift = 24; - pattern_data = virge->s3d.pattern_24; - src_fg_clr = virge->s3d.src_fg_clr; - src_bg_clr = virge->s3d.src_bg_clr; + pattern_data = virge->s3d.pattern_24; + src_fg_clr = virge->s3d.src_fg_clr; + src_bg_clr = virge->s3d.src_bg_clr; break; - } - if (virge->s3d.cmd_set & CMD_SET_MP) - pattern_data = mono_pattern; + } + if (virge->s3d.cmd_set & CMD_SET_MP) + pattern_data = mono_pattern; switch (virge->s3d.cmd_set & CMD_SET_ITA_MASK) { case CMD_SET_ITA_BYTE: @@ -2272,16 +3061,16 @@ s3_virge_bitblt(virge_t *virge, int count, uint32_t cpu_dat) int x; int y; for (y = 0; y < 4; y++) { - for (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 - mono_pattern[y * 8 + (7 - x)] = virge->s3d.pat_bg_clr; - if (virge->s3d.mono_pat_1 & (1 << (x + y * 8))) - mono_pattern[(y + 4) * 8 + (7 - x)] = virge->s3d.pat_fg_clr; - else - mono_pattern[(y + 4) * 8 + (7 - x)] = virge->s3d.pat_bg_clr; - } + for (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 + mono_pattern[y * 8 + (7 - x)] = virge->s3d.pat_bg_clr; + if (virge->s3d.mono_pat_1 & (1 << (x + y * 8))) + mono_pattern[(y + 4) * 8 + (7 - x)] = virge->s3d.pat_fg_clr; + else + mono_pattern[(y + 4) * 8 + (7 - x)] = virge->s3d.pat_bg_clr; + } } } switch (virge->s3d.cmd_set & CMD_SET_COMMAND_MASK) { @@ -2290,13 +3079,13 @@ s3_virge_bitblt(virge_t *virge, int count, uint32_t cpu_dat) case CMD_SET_COMMAND_BITBLT: if (count == -1) { - virge->s3d.src_x = virge->s3d.rsrc_x; - virge->s3d.src_y = virge->s3d.rsrc_y; - virge->s3d.dest_x = virge->s3d.rdest_x; - virge->s3d.dest_y = virge->s3d.rdest_y; - virge->s3d.w = virge->s3d.r_width; - virge->s3d.h = virge->s3d.r_height; - virge->s3d.rop = (virge->s3d.cmd_set >> 17) & 0xff; + virge->s3d.src_x = virge->s3d.rsrc_x; + virge->s3d.src_y = virge->s3d.rsrc_y; + virge->s3d.dest_x = virge->s3d.rdest_x; + virge->s3d.dest_y = virge->s3d.rdest_y; + virge->s3d.w = virge->s3d.r_width; + virge->s3d.h = virge->s3d.r_height; + virge->s3d.rop = (virge->s3d.cmd_set >> 17) & 0xff; virge->s3d.data_left_count = 0; if (virge->s3d.cmd_set & CMD_SET_IDS) @@ -2312,8 +3101,8 @@ s3_virge_bitblt(virge_t *virge, int count, uint32_t cpu_dat) uint32_t source = 0; uint32_t dest = 0; uint32_t pattern; - uint32_t out = 0; - int update = 1; + uint32_t out = 0; + int update = 1; switch (virge->s3d.cmd_set & (CMD_SET_MS | CMD_SET_IDS)) { case 0: @@ -2331,18 +3120,18 @@ s3_virge_bitblt(virge_t *virge, int count, uint32_t cpu_dat) count -= (cpu_dat_shift - virge->s3d.data_left_count); virge->s3d.data_left_count = 0; if (count < cpu_dat_shift) { - virge->s3d.data_left = cpu_dat; + virge->s3d.data_left = cpu_dat; virge->s3d.data_left_count = count; - count = 0; + count = 0; } } else { source = cpu_dat; cpu_dat >>= cpu_dat_shift; count -= cpu_dat_shift; if (count < cpu_dat_shift) { - virge->s3d.data_left = cpu_dat; + virge->s3d.data_left = cpu_dat; virge->s3d.data_left_count = count; - count = 0; + count = 0; } } if ((virge->s3d.cmd_set & CMD_SET_TP) && source == src_fg_clr) @@ -2372,9 +3161,9 @@ s3_virge_bitblt(virge_t *virge, int count, uint32_t cpu_dat) virge->s3d.dest_x += x_inc; virge->s3d.dest_x &= 0x7ff; if (!virge->s3d.w) { - virge->s3d.src_x = virge->s3d.rsrc_x; + virge->s3d.src_x = virge->s3d.rsrc_x; virge->s3d.dest_x = virge->s3d.rdest_x; - virge->s3d.w = virge->s3d.r_width; + virge->s3d.w = virge->s3d.r_width; virge->s3d.src_y += y_inc; virge->s3d.dest_y += y_inc; @@ -2402,23 +3191,22 @@ s3_virge_bitblt(virge_t *virge, int count, uint32_t cpu_dat) case CMD_SET_COMMAND_RECTFILL: /*No source, pattern = pat_fg_clr*/ if (count == -1) { - virge->s3d.src_x = virge->s3d.rsrc_x; - virge->s3d.src_y = virge->s3d.rsrc_y; + virge->s3d.src_x = virge->s3d.rsrc_x; + virge->s3d.src_y = virge->s3d.rsrc_y; virge->s3d.dest_x = virge->s3d.rdest_x; virge->s3d.dest_y = virge->s3d.rdest_y; - virge->s3d.w = virge->s3d.r_width; - virge->s3d.h = virge->s3d.r_height; - virge->s3d.rop = (virge->s3d.cmd_set >> 17) & 0xff; + virge->s3d.w = virge->s3d.r_width; + virge->s3d.h = virge->s3d.r_height; + virge->s3d.rop = (virge->s3d.cmd_set >> 17) & 0xff; } while (count && virge->s3d.h) { - uint32_t dest_addr = virge->s3d.dest_base + (virge->s3d.dest_x * x_mul) + - (virge->s3d.dest_y * virge->s3d.dest_str); + uint32_t dest_addr = virge->s3d.dest_base + (virge->s3d.dest_x * x_mul) + (virge->s3d.dest_y * virge->s3d.dest_str); uint32_t source = 0; uint32_t dest = 0; uint32_t pattern = virge->s3d.pat_fg_clr; uint32_t out = 0; - int update = 1; + int update = 1; CLIP(virge->s3d.dest_x, virge->s3d.dest_y); @@ -2435,9 +3223,9 @@ s3_virge_bitblt(virge_t *virge, int count, uint32_t cpu_dat) virge->s3d.dest_x += x_inc; virge->s3d.dest_x &= 0x7ff; if (!virge->s3d.w) { - virge->s3d.src_x = virge->s3d.rsrc_x; + virge->s3d.src_x = virge->s3d.rsrc_x; virge->s3d.dest_x = virge->s3d.rdest_x; - virge->s3d.w = virge->s3d.r_width; + virge->s3d.w = virge->s3d.r_width; virge->s3d.src_y += y_inc; virge->s3d.dest_y += y_inc; @@ -2445,7 +3233,7 @@ s3_virge_bitblt(virge_t *virge, int count, uint32_t cpu_dat) if (!virge->s3d.h) return; } else - virge->s3d.w--; + virge->s3d.w--; count--; } break; @@ -2454,8 +3242,8 @@ s3_virge_bitblt(virge_t *virge, int count, uint32_t cpu_dat) if (count == -1) { virge->s3d.dest_x = virge->s3d.lxstart; virge->s3d.dest_y = virge->s3d.lystart; - virge->s3d.h = virge->s3d.lycnt; - virge->s3d.rop = (virge->s3d.cmd_set >> 17) & 0xff; + virge->s3d.h = virge->s3d.lycnt; + virge->s3d.rop = (virge->s3d.cmd_set >> 17) & 0xff; } while (virge->s3d.h) { int x; @@ -2482,8 +3270,8 @@ s3_virge_bitblt(virge_t *virge, int count, uint32_t cpu_dat) uint32_t source = 0; uint32_t dest = 0; uint32_t pattern; - uint32_t out = 0; - int update = 1; + uint32_t out = 0; + int update = 1; if ((virge->s3d.h == virge->s3d.lycnt || !first_pixel) && ((virge->s3d.line_dir && x < virge->s3d.lxend0) || @@ -2526,39 +3314,39 @@ skip_line: virge->s3d.dest_r = virge->s3d.prxstart; if (virge->s3d.pycnt & (1 << 29)) virge->s3d.dest_l = virge->s3d.plxstart; - virge->s3d.h = virge->s3d.pycnt & 0x7ff; + virge->s3d.h = virge->s3d.pycnt & 0x7ff; virge->s3d.rop = (virge->s3d.cmd_set >> 17) & 0xff; while (virge->s3d.h) { - int x = virge->s3d.dest_l >> 20; - int xend = virge->s3d.dest_r >> 20; - int y = virge->s3d.pystart & 0x7ff; - 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; - uint32_t dest = 0; - uint32_t pattern; - uint32_t out = 0; - int update = 1; + int x = virge->s3d.dest_l >> 20; + int xend = virge->s3d.dest_r >> 20; + int y = virge->s3d.pystart & 0x7ff; + 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; + uint32_t dest = 0; + uint32_t pattern; + uint32_t out = 0; + int update = 1; - CLIP(x, y); + CLIP(x, y); - if (update) { - READ(dest_addr, dest); - pattern = pattern_data[(y & 7) * 8 + (x & 7)]; + if (update) { + READ(dest_addr, dest); + pattern = pattern_data[(y & 7) * 8 + (x & 7)]; - MIX(); + MIX(); - WRITE(dest_addr, out); - } + WRITE(dest_addr, out); + } - x = (x + xdir) & 0x7ff; - } while (x != (xend + xdir)); + x = (x + xdir) & 0x7ff; + } while (x != (xend + xdir)); - virge->s3d.dest_l += virge->s3d.pldx; - virge->s3d.dest_r += virge->s3d.prdx; - virge->s3d.h--; - virge->s3d.pystart = (virge->s3d.pystart - 1) & 0x7ff; + virge->s3d.dest_l += virge->s3d.pldx; + virge->s3d.dest_r += virge->s3d.prdx; + virge->s3d.h--; + virge->s3d.pystart = (virge->s3d.pystart - 1) & 0x7ff; } break; @@ -2573,76 +3361,79 @@ skip_line: g = ((val & 0x03e0) >> 2) | ((val & 0x03e0) >> 7); \ r = ((val & 0x7c00) >> 7) | ((val & 0x7c00) >> 12); -#define RGB24_TO_24(val, r, g, b) \ - b = val & 0xff; \ - g = (val & 0xff00) >> 8; \ +#define RGB24_TO_24(val, r, g, b) \ + b = val & 0xff; \ + g = (val & 0xff00) >> 8; \ r = (val & 0xff0000) >> 16 -#define RGB15(r, g, b, dest) \ - if (virge->dithering_enabled) { \ - int add = dither[_y & 3][_x & 3]; \ - int _r = (r > 248) ? 248 : r + add; \ - int _g = (g > 248) ? 248 : g + add; \ - int _b = (b > 248) ? 248 : b + add; \ - dest = ((_b >> 3) & 0x1f) | \ - (((_g >> 3) & 0x1f) << 5) | \ - (((_r >> 3) & 0x1f) << 10); \ - } else \ - dest = ((b >> 3) & 0x1f) | \ - (((g >> 3) & 0x1f) << 5) | \ +#define RGB15(r, g, b, dest) \ + if (virge->dithering_enabled) { \ + int add = dither[_y & 3][_x & 3]; \ + int _r = (r > 248) ? 248 : r + add; \ + int _g = (g > 248) ? 248 : g + add; \ + int _b = (b > 248) ? 248 : b + add; \ + dest = ((_b >> 3) & 0x1f) | \ + (((_g >> 3) & 0x1f) << 5) | \ + (((_r >> 3) & 0x1f) << 10); \ + } else \ + dest = ((b >> 3) & 0x1f) | \ + (((g >> 3) & 0x1f) << 5) | \ (((r >> 3) & 0x1f) << 10) #define RGB24(r, g, b) ((b) | ((g) << 8) | ((r) << 16)) typedef struct rgba_t { - int r, g, b, a; + int r; + int g; + int b; + int a; } rgba_t; typedef struct s3d_state_t { - int32_t r; - int32_t g; - int32_t b; - int32_t a; - int32_t u; - int32_t v; - int32_t d; - int32_t w; + int32_t r; + int32_t g; + int32_t b; + int32_t a; + int32_t u; + int32_t v; + int32_t d; + int32_t w; - int32_t base_r; - int32_t base_g; - int32_t base_b; - int32_t base_a; - int32_t base_u; - int32_t base_v; - int32_t base_d; - int32_t base_w; + int32_t base_r; + int32_t base_g; + int32_t base_b; + int32_t base_a; + int32_t base_u; + int32_t base_v; + int32_t base_d; + int32_t base_w; - uint32_t base_z; + uint32_t base_z; - uint32_t tbu; - uint32_t tbv; + uint32_t tbu; + uint32_t tbv; - uint32_t cmd_set; - int max_d; + uint32_t cmd_set; + int max_d; uint16_t *texture[10]; - uint32_t tex_bdr_clr; + uint32_t tex_bdr_clr; - int32_t x1; - int32_t x2; + int32_t x1; + int32_t x2; - int y; + int y; - rgba_t dest_rgba; + rgba_t dest_rgba; } s3d_state_t; typedef struct s3d_texture_state_t { - int level; - int texture_shift; + int level; + int texture_shift; - int32_t u; - int32_t v; + int32_t u; + int32_t v; } s3d_texture_state_t; static void (*tex_read)(s3d_state_t *state, s3d_texture_state_t *texture_state, rgba_t *out); @@ -2656,7 +3447,8 @@ static int _x; static int _y; static void -tex_ARGB1555(s3d_state_t *state, s3d_texture_state_t *texture_state, rgba_t *out) { +tex_ARGB1555(s3d_state_t *state, s3d_texture_state_t *texture_state, rgba_t *out) +{ int offset = ((texture_state->u & 0x7fc0000) >> texture_state->texture_shift) + (((texture_state->v & 0x7fc0000) >> texture_state->texture_shift) << texture_state->level); uint16_t val = state->texture[texture_state->level][offset]; @@ -2668,7 +3460,8 @@ tex_ARGB1555(s3d_state_t *state, s3d_texture_state_t *texture_state, rgba_t *out } static void -tex_ARGB1555_nowrap(s3d_state_t *state, s3d_texture_state_t *texture_state, rgba_t *out) { +tex_ARGB1555_nowrap(s3d_state_t *state, s3d_texture_state_t *texture_state, rgba_t *out) +{ int offset = ((texture_state->u & 0x7fc0000) >> texture_state->texture_shift) + (((texture_state->v & 0x7fc0000) >> texture_state->texture_shift) << texture_state->level); uint16_t val = state->texture[texture_state->level][offset]; @@ -2683,7 +3476,8 @@ tex_ARGB1555_nowrap(s3d_state_t *state, s3d_texture_state_t *texture_state, rgba } static void -tex_ARGB4444(s3d_state_t *state, s3d_texture_state_t *texture_state, rgba_t *out) { +tex_ARGB4444(s3d_state_t *state, s3d_texture_state_t *texture_state, rgba_t *out) +{ int offset = ((texture_state->u & 0x7fc0000) >> texture_state->texture_shift) + (((texture_state->v & 0x7fc0000) >> texture_state->texture_shift) << texture_state->level); uint16_t val = state->texture[texture_state->level][offset]; @@ -2695,7 +3489,8 @@ tex_ARGB4444(s3d_state_t *state, s3d_texture_state_t *texture_state, rgba_t *out } static void -tex_ARGB4444_nowrap(s3d_state_t *state, s3d_texture_state_t *texture_state, rgba_t *out) { +tex_ARGB4444_nowrap(s3d_state_t *state, s3d_texture_state_t *texture_state, rgba_t *out) +{ int offset = ((texture_state->u & 0x7fc0000) >> texture_state->texture_shift) + (((texture_state->v & 0x7fc0000) >> texture_state->texture_shift) << texture_state->level); uint16_t val = state->texture[texture_state->level][offset]; @@ -2710,7 +3505,8 @@ tex_ARGB4444_nowrap(s3d_state_t *state, s3d_texture_state_t *texture_state, rgba } static void -tex_ARGB8888(s3d_state_t *state, s3d_texture_state_t *texture_state, rgba_t *out) { +tex_ARGB8888(s3d_state_t *state, s3d_texture_state_t *texture_state, rgba_t *out) +{ int offset = ((texture_state->u & 0x7fc0000) >> texture_state->texture_shift) + (((texture_state->v & 0x7fc0000) >> texture_state->texture_shift) << texture_state->level); uint32_t val = ((uint32_t *)state->texture[texture_state->level])[offset]; @@ -2722,7 +3518,8 @@ tex_ARGB8888(s3d_state_t *state, s3d_texture_state_t *texture_state, rgba_t *out } static void -tex_ARGB8888_nowrap(s3d_state_t *state, s3d_texture_state_t *texture_state, rgba_t *out) { +tex_ARGB8888_nowrap(s3d_state_t *state, s3d_texture_state_t *texture_state, rgba_t *out) +{ int offset = ((texture_state->u & 0x7fc0000) >> texture_state->texture_shift) + (((texture_state->v & 0x7fc0000) >> texture_state->texture_shift) << texture_state->level); uint32_t val = ((uint32_t *)state->texture[texture_state->level])[offset]; @@ -2737,19 +3534,21 @@ tex_ARGB8888_nowrap(s3d_state_t *state, s3d_texture_state_t *texture_state, rgba } static void -tex_sample_normal(s3d_state_t *state) { +tex_sample_normal(s3d_state_t *state) +{ s3d_texture_state_t texture_state; - texture_state.level = state->max_d; + texture_state.level = state->max_d; texture_state.texture_shift = 18 + (9 - texture_state.level); - texture_state.u = state->u + state->tbu; - texture_state.v = state->v + state->tbv; + texture_state.u = state->u + state->tbu; + texture_state.v = state->v + state->tbv; tex_read(state, &texture_state, &state->dest_rgba); } static void -tex_sample_normal_filter(s3d_state_t *state) { +tex_sample_normal_filter(s3d_state_t *state) +{ s3d_texture_state_t texture_state; int tex_offset; rgba_t tex_samples[4]; @@ -2757,9 +3556,9 @@ tex_sample_normal_filter(s3d_state_t *state) { int dv; int d[4]; - texture_state.level = state->max_d; + texture_state.level = state->max_d; texture_state.texture_shift = 18 + (9 - texture_state.level); - tex_offset = 1 << texture_state.texture_shift; + tex_offset = 1 << texture_state.texture_shift; texture_state.u = state->u + state->tbu; texture_state.v = state->v + state->tbv; @@ -2795,21 +3594,23 @@ tex_sample_normal_filter(s3d_state_t *state) { } static void -tex_sample_mipmap(s3d_state_t *state) { +tex_sample_mipmap(s3d_state_t *state) +{ s3d_texture_state_t texture_state; texture_state.level = (state->d < 0) ? state->max_d : state->max_d - ((state->d >> 27) & 0xf); if (texture_state.level < 0) texture_state.level = 0; texture_state.texture_shift = 18 + (9 - texture_state.level); - texture_state.u = state->u + state->tbu; - texture_state.v = state->v + state->tbv; + texture_state.u = state->u + state->tbu; + texture_state.v = state->v + state->tbv; tex_read(state, &texture_state, &state->dest_rgba); } static void -tex_sample_mipmap_filter(s3d_state_t *state) { +tex_sample_mipmap_filter(s3d_state_t *state) +{ s3d_texture_state_t texture_state; int tex_offset; rgba_t tex_samples[4]; @@ -2821,7 +3622,7 @@ tex_sample_mipmap_filter(s3d_state_t *state) { if (texture_state.level < 0) texture_state.level = 0; texture_state.texture_shift = 18 + (9 - texture_state.level); - tex_offset = 1 << texture_state.texture_shift; + tex_offset = 1 << texture_state.texture_shift; texture_state.u = state->u + state->tbu; texture_state.v = state->v + state->tbv; @@ -2857,25 +3658,27 @@ tex_sample_mipmap_filter(s3d_state_t *state) { } static void -tex_sample_persp_normal(s3d_state_t *state) { +tex_sample_persp_normal(s3d_state_t *state) +{ s3d_texture_state_t texture_state; - int32_t w = 0; + int32_t w = 0; if (state->w) - w = (int32_t)(((1ULL << 27) << 19) / (int64_t)state->w); + w = (int32_t) (((1ULL << 27) << 19) / (int64_t) state->w); - texture_state.level = state->max_d; + texture_state.level = state->max_d; texture_state.texture_shift = 18 + (9 - texture_state.level); - texture_state.u = (int32_t)(((int64_t)state->u * (int64_t)w) >> (12 + state->max_d)) + state->tbu; - texture_state.v = (int32_t)(((int64_t)state->v * (int64_t)w) >> (12 + state->max_d)) + state->tbv; + texture_state.u = (int32_t) (((int64_t) state->u * (int64_t) w) >> (12 + state->max_d)) + state->tbu; + texture_state.v = (int32_t) (((int64_t) state->v * (int64_t) w) >> (12 + state->max_d)) + state->tbv; tex_read(state, &texture_state, &state->dest_rgba); } static void -tex_sample_persp_normal_filter(s3d_state_t *state) { +tex_sample_persp_normal_filter(s3d_state_t *state) +{ s3d_texture_state_t texture_state; - int32_t w = 0; + int32_t w = 0; int32_t u; int32_t v; int tex_offset; @@ -2885,14 +3688,14 @@ tex_sample_persp_normal_filter(s3d_state_t *state) { int d[4]; if (state->w) - w = (int32_t)(((1ULL << 27) << 19) / (int64_t)state->w); + w = (int32_t) (((1ULL << 27) << 19) / (int64_t) state->w); - u = (int32_t)(((int64_t)state->u * (int64_t)w) >> (12 + state->max_d)) + state->tbu; - v = (int32_t)(((int64_t)state->v * (int64_t)w) >> (12 + state->max_d)) + state->tbv; + u = (int32_t) (((int64_t) state->u * (int64_t) w) >> (12 + state->max_d)) + state->tbu; + v = (int32_t) (((int64_t) state->v * (int64_t) w) >> (12 + state->max_d)) + state->tbv; - texture_state.level = state->max_d; + texture_state.level = state->max_d; texture_state.texture_shift = 18 + (9 - texture_state.level); - tex_offset = 1 << texture_state.texture_shift; + tex_offset = 1 << texture_state.texture_shift; texture_state.u = u; texture_state.v = v; @@ -2928,25 +3731,27 @@ tex_sample_persp_normal_filter(s3d_state_t *state) { } static void -tex_sample_persp_normal_375(s3d_state_t *state) { +tex_sample_persp_normal_375(s3d_state_t *state) +{ s3d_texture_state_t texture_state; - int32_t w = 0; + int32_t w = 0; if (state->w) - w = (int32_t)(((1ULL << 27) << 19) / (int64_t)state->w); + w = (int32_t) (((1ULL << 27) << 19) / (int64_t) state->w); - texture_state.level = state->max_d; + texture_state.level = state->max_d; texture_state.texture_shift = 18 + (9 - texture_state.level); - texture_state.u = (int32_t)(((int64_t)state->u * (int64_t)w) >> (8 + state->max_d)) + state->tbu; - texture_state.v = (int32_t)(((int64_t)state->v * (int64_t)w) >> (8 + state->max_d)) + state->tbv; + texture_state.u = (int32_t) (((int64_t) state->u * (int64_t) w) >> (8 + state->max_d)) + state->tbu; + texture_state.v = (int32_t) (((int64_t) state->v * (int64_t) w) >> (8 + state->max_d)) + state->tbv; tex_read(state, &texture_state, &state->dest_rgba); } static void -tex_sample_persp_normal_filter_375(s3d_state_t *state) { +tex_sample_persp_normal_filter_375(s3d_state_t *state) +{ s3d_texture_state_t texture_state; - int32_t w = 0; + int32_t w = 0; int32_t u; int32_t v; int tex_offset; @@ -2956,14 +3761,14 @@ tex_sample_persp_normal_filter_375(s3d_state_t *state) { int d[4]; if (state->w) - w = (int32_t)(((1ULL << 27) << 19) / (int64_t)state->w); + w = (int32_t) (((1ULL << 27) << 19) / (int64_t) state->w); - u = (int32_t)(((int64_t)state->u * (int64_t)w) >> (8 + state->max_d)) + state->tbu; - v = (int32_t)(((int64_t)state->v * (int64_t)w) >> (8 + state->max_d)) + state->tbv; + u = (int32_t) (((int64_t) state->u * (int64_t) w) >> (8 + state->max_d)) + state->tbu; + v = (int32_t) (((int64_t) state->v * (int64_t) w) >> (8 + state->max_d)) + state->tbv; - texture_state.level = state->max_d; + texture_state.level = state->max_d; texture_state.texture_shift = 18 + (9 - texture_state.level); - tex_offset = 1 << texture_state.texture_shift; + tex_offset = 1 << texture_state.texture_shift; texture_state.u = u; texture_state.v = v; @@ -2999,27 +3804,29 @@ tex_sample_persp_normal_filter_375(s3d_state_t *state) { } static void -tex_sample_persp_mipmap(s3d_state_t *state) { +tex_sample_persp_mipmap(s3d_state_t *state) +{ s3d_texture_state_t texture_state; - int32_t w = 0; + int32_t w = 0; if (state->w) - w = (int32_t)(((1ULL << 27) << 19) / (int64_t)state->w); + w = (int32_t) (((1ULL << 27) << 19) / (int64_t) state->w); texture_state.level = (state->d < 0) ? state->max_d : state->max_d - ((state->d >> 27) & 0xf); if (texture_state.level < 0) texture_state.level = 0; texture_state.texture_shift = 18 + (9 - texture_state.level); - texture_state.u = (int32_t)(((int64_t)state->u * (int64_t)w) >> (12 + state->max_d)) + state->tbu; - texture_state.v = (int32_t)(((int64_t)state->v * (int64_t)w) >> (12 + state->max_d)) + state->tbv; + texture_state.u = (int32_t) (((int64_t) state->u * (int64_t) w) >> (12 + state->max_d)) + state->tbu; + texture_state.v = (int32_t) (((int64_t) state->v * (int64_t) w) >> (12 + state->max_d)) + state->tbv; tex_read(state, &texture_state, &state->dest_rgba); } static void -tex_sample_persp_mipmap_filter(s3d_state_t *state) { +tex_sample_persp_mipmap_filter(s3d_state_t *state) +{ s3d_texture_state_t texture_state; - int32_t w = 0; + int32_t w = 0; int32_t u; int32_t v; int tex_offset; @@ -3029,16 +3836,16 @@ tex_sample_persp_mipmap_filter(s3d_state_t *state) { int d[4]; if (state->w) - w = (int32_t)(((1ULL << 27) << 19) / (int64_t)state->w); + w = (int32_t) (((1ULL << 27) << 19) / (int64_t) state->w); - u = (int32_t)(((int64_t)state->u * (int64_t)w) >> (12 + state->max_d)) + state->tbu; - v = (int32_t)(((int64_t)state->v * (int64_t)w) >> (12 + state->max_d)) + state->tbv; + u = (int32_t) (((int64_t) state->u * (int64_t) w) >> (12 + state->max_d)) + state->tbu; + v = (int32_t) (((int64_t) state->v * (int64_t) w) >> (12 + state->max_d)) + state->tbv; texture_state.level = (state->d < 0) ? state->max_d : state->max_d - ((state->d >> 27) & 0xf); if (texture_state.level < 0) texture_state.level = 0; texture_state.texture_shift = 18 + (9 - texture_state.level); - tex_offset = 1 << texture_state.texture_shift; + tex_offset = 1 << texture_state.texture_shift; texture_state.u = u; texture_state.v = v; @@ -3074,27 +3881,29 @@ tex_sample_persp_mipmap_filter(s3d_state_t *state) { } static void -tex_sample_persp_mipmap_375(s3d_state_t *state) { +tex_sample_persp_mipmap_375(s3d_state_t *state) +{ s3d_texture_state_t texture_state; - int32_t w = 0; + int32_t w = 0; if (state->w) - w = (int32_t)(((1ULL << 27) << 19) / (int64_t)state->w); + w = (int32_t) (((1ULL << 27) << 19) / (int64_t) state->w); texture_state.level = (state->d < 0) ? state->max_d : state->max_d - ((state->d >> 27) & 0xf); if (texture_state.level < 0) texture_state.level = 0; texture_state.texture_shift = 18 + (9 - texture_state.level); - texture_state.u = (int32_t)(((int64_t)state->u * (int64_t)w) >> (8 + state->max_d)) + state->tbu; - texture_state.v = (int32_t)(((int64_t)state->v * (int64_t)w) >> (8 + state->max_d)) + state->tbv; + texture_state.u = (int32_t) (((int64_t) state->u * (int64_t) w) >> (8 + state->max_d)) + state->tbu; + texture_state.v = (int32_t) (((int64_t) state->v * (int64_t) w) >> (8 + state->max_d)) + state->tbv; tex_read(state, &texture_state, &state->dest_rgba); } static void -tex_sample_persp_mipmap_filter_375(s3d_state_t *state) { +tex_sample_persp_mipmap_filter_375(s3d_state_t *state) +{ s3d_texture_state_t texture_state; - int32_t w = 0; + int32_t w = 0; int32_t u; int32_t v; int tex_offset; @@ -3104,16 +3913,16 @@ tex_sample_persp_mipmap_filter_375(s3d_state_t *state) { int d[4]; if (state->w) - w = (int32_t)(((1ULL << 27) << 19) / (int64_t)state->w); + w = (int32_t) (((1ULL << 27) << 19) / (int64_t) state->w); - u = (int32_t)(((int64_t)state->u * (int64_t)w) >> (8 + state->max_d)) + state->tbu; - v = (int32_t)(((int64_t)state->v * (int64_t)w) >> (8 + state->max_d)) + state->tbv; + u = (int32_t) (((int64_t) state->u * (int64_t) w) >> (8 + state->max_d)) + state->tbu; + v = (int32_t) (((int64_t) state->v * (int64_t) w) >> (8 + state->max_d)) + state->tbv; texture_state.level = (state->d < 0) ? state->max_d : state->max_d - ((state->d >> 27) & 0xf); if (texture_state.level < 0) texture_state.level = 0; texture_state.texture_shift = 18 + (9 - texture_state.level); - tex_offset = 1 << texture_state.texture_shift; + tex_offset = 1 << texture_state.texture_shift; texture_state.u = u; texture_state.v = v; @@ -3148,40 +3957,41 @@ tex_sample_persp_mipmap_filter_375(s3d_state_t *state) { tex_samples[2].a * d[2] + tex_samples[3].a * d[3]) >> 16; } -#define CLAMP(x) \ - do { \ - if ((x) & ~0xff) \ - x = ((x) < 0) ? 0 : 0xff; \ +#define CLAMP(x) \ + do { \ + if ((x) & ~0xff) \ + x = ((x) < 0) ? 0 : 0xff; \ } while (0) -#define CLAMP_RGBA(r, g, b, a) \ - if ((r) & ~0xff) \ - r = ((r) < 0) ? 0 : 0xff; \ - if ((g) & ~0xff) \ - g = ((g) < 0) ? 0 : 0xff; \ - if ((b) & ~0xff) \ - b = ((b) < 0) ? 0 : 0xff; \ - if ((a) & ~0xff) \ - a = ((a) < 0) ? 0 : 0xff; +#define CLAMP_RGBA(r, g, b, a) \ + if ((r) & ~0xff) \ + r = ((r) < 0) ? 0 : 0xff; \ + if ((g) & ~0xff) \ + g = ((g) < 0) ? 0 : 0xff; \ + if ((b) & ~0xff) \ + b = ((b) < 0) ? 0 : 0xff; \ + if ((a) & ~0xff) \ + a = ((a) < 0) ? 0 : 0xff; -#define CLAMP_RGB(r, g, b) \ - do { \ - if ((r) < 0) \ - r = 0; \ - if ((r) > 0xff) \ - r = 0xff; \ - if ((g) < 0) \ - g = 0; \ - if ((g) > 0xff) \ - g = 0xff; \ - if ((b) < 0) \ - b = 0; \ - if ((b) > 0xff) \ - b = 0xff; \ +#define CLAMP_RGB(r, g, b) \ + do { \ + if ((r) < 0) \ + r = 0; \ + if ((r) > 0xff) \ + r = 0xff; \ + if ((g) < 0) \ + g = 0; \ + if ((g) > 0xff) \ + g = 0xff; \ + if ((b) < 0) \ + b = 0; \ + if ((b) > 0xff) \ + b = 0xff; \ } while (0) static void -dest_pixel_gouraud_shaded_triangle(s3d_state_t *state) { +dest_pixel_gouraud_shaded_triangle(s3d_state_t *state) +{ state->dest_rgba.r = state->r >> 7; CLAMP(state->dest_rgba.r); @@ -3196,7 +4006,8 @@ dest_pixel_gouraud_shaded_triangle(s3d_state_t *state) { } static void -dest_pixel_unlit_texture_triangle(s3d_state_t *state) { +dest_pixel_unlit_texture_triangle(s3d_state_t *state) +{ tex_sample(state); if (state->cmd_set & CMD_SET_ABC_SRC) @@ -3204,7 +4015,8 @@ dest_pixel_unlit_texture_triangle(s3d_state_t *state) { } static void -dest_pixel_lit_texture_decal(s3d_state_t *state) { +dest_pixel_lit_texture_decal(s3d_state_t *state) +{ tex_sample(state); if (state->cmd_set & CMD_SET_ABC_SRC) @@ -3212,7 +4024,8 @@ dest_pixel_lit_texture_decal(s3d_state_t *state) { } static void -dest_pixel_lit_texture_reflection(s3d_state_t *state) { +dest_pixel_lit_texture_reflection(s3d_state_t *state) +{ tex_sample(state); state->dest_rgba.r += (state->r >> 7); @@ -3225,7 +4038,8 @@ dest_pixel_lit_texture_reflection(s3d_state_t *state) { } static void -dest_pixel_lit_texture_modulate(s3d_state_t *state) { +dest_pixel_lit_texture_modulate(s3d_state_t *state) +{ int r = state->r >> 7; int g = state->g >> 7; int b = state->b >> 7; @@ -3244,17 +4058,18 @@ dest_pixel_lit_texture_modulate(s3d_state_t *state) { } static void -tri(virge_t *virge, s3d_t *s3d_tri, s3d_state_t *state, int yc, int32_t dx1, int32_t dx2) { - uint8_t *vram = virge->svga.vram; - int x_dir = s3d_tri->tlr ? 1 : -1; - int use_z = !(s3d_tri->cmd_set & CMD_SET_ZB_MODE); - int y_count = yc; - int bpp = (s3d_tri->cmd_set >> 2) & 7; - uint32_t dest_offset; - uint32_t z_offset; +tri(virge_t *virge, s3d_t *s3d_tri, s3d_state_t *state, int yc, int32_t dx1, int32_t dx2) +{ + uint8_t *vram = virge->svga.vram; + int x_dir = s3d_tri->tlr ? 1 : -1; + int use_z = !(s3d_tri->cmd_set & CMD_SET_ZB_MODE); + int y_count = yc; + int bpp = (s3d_tri->cmd_set >> 2) & 7; + uint32_t dest_offset; + uint32_t z_offset; dest_offset = s3d_tri->dest_base + (state->y * s3d_tri->dest_str); - z_offset = s3d_tri->z_base + (state->y * s3d_tri->z_str); + z_offset = s3d_tri->z_base + (state->y * s3d_tri->z_str); if (s3d_tri->cmd_set & CMD_SET_HC) { if (state->y < s3d_tri->clip_t) @@ -3274,195 +4089,190 @@ tri(virge_t *virge, s3d_t *s3d_tri, s3d_state_t *state, int yc, int32_t dx1, int state->base_a += (s3d_tri->TdAdY * diff_y); state->base_d += (s3d_tri->TdDdY * diff_y); state->base_w += (s3d_tri->TdWdY * diff_y); - state->x1 += (dx1 * diff_y); - state->x2 += (dx2 * diff_y); - state->y -= diff_y; - dest_offset -= s3d_tri->dest_str; - z_offset -= s3d_tri->z_str; - y_count -= diff_y; + state->x1 += (dx1 * diff_y); + state->x2 += (dx2 * diff_y); + state->y -= diff_y; + dest_offset -= s3d_tri->dest_str; + z_offset -= s3d_tri->z_str; + y_count -= diff_y; } if ((state->y - y_count) < s3d_tri->clip_t) y_count = (state->y - s3d_tri->clip_t) + 1; } for (; y_count > 0; y_count--) { - int x = (state->x1 + ((1 << 20) - 1)) >> 20; - int xe = (state->x2 + ((1 << 20) - 1)) >> 20; - uint32_t z = (state->base_z > 0) ? (state->base_z << 1) : 0; + int x = (state->x1 + ((1 << 20) - 1)) >> 20; + int xe = (state->x2 + ((1 << 20) - 1)) >> 20; + uint32_t z = (state->base_z > 0) ? (state->base_z << 1) : 0; - if (x_dir < 0) { - x--; - xe--; - } + if (x_dir < 0) { + x--; + xe--; + } - if (x != xe && ((x_dir > 0 && x < xe) || (x_dir < 0 && x > xe))) { - uint32_t dest_addr; - uint32_t z_addr; - int dx = (x_dir > 0) ? ((31 - ((state->x1 - 1) >> 15)) & 0x1f) : - (((state->x1 - 1) >> 15) & 0x1f); - int x_offset = x_dir * (bpp + 1); - int xz_offset = x_dir << 1; + if (x != xe && ((x_dir > 0 && x < xe) || (x_dir < 0 && x > xe))) { + uint32_t dest_addr; + uint32_t z_addr; + int dx = (x_dir > 0) ? ((31 - ((state->x1 - 1) >> 15)) & 0x1f) : (((state->x1 - 1) >> 15) & 0x1f); + int x_offset = x_dir * (bpp + 1); + int xz_offset = x_dir << 1; - if (x_dir > 0) - dx += 1; + if (x_dir > 0) + dx += 1; - state->r = state->base_r + ((s3d_tri->TdRdX * dx) >> 5); - state->g = state->base_g + ((s3d_tri->TdGdX * dx) >> 5); - state->b = state->base_b + ((s3d_tri->TdBdX * dx) >> 5); - state->a = state->base_a + ((s3d_tri->TdAdX * dx) >> 5); - state->u = state->base_u + ((s3d_tri->TdUdX * dx) >> 5); - state->v = state->base_v + ((s3d_tri->TdVdX * dx) >> 5); - state->w = state->base_w + ((s3d_tri->TdWdX * dx) >> 5); - state->d = state->base_d + ((s3d_tri->TdDdX * dx) >> 5); - z += ((s3d_tri->TdZdX * dx) >> 5); + state->r = state->base_r + ((s3d_tri->TdRdX * dx) >> 5); + state->g = state->base_g + ((s3d_tri->TdGdX * dx) >> 5); + state->b = state->base_b + ((s3d_tri->TdBdX * dx) >> 5); + state->a = state->base_a + ((s3d_tri->TdAdX * dx) >> 5); + state->u = state->base_u + ((s3d_tri->TdUdX * dx) >> 5); + state->v = state->base_v + ((s3d_tri->TdVdX * dx) >> 5); + state->w = state->base_w + ((s3d_tri->TdWdX * dx) >> 5); + state->d = state->base_d + ((s3d_tri->TdDdX * dx) >> 5); + z += ((s3d_tri->TdZdX * dx) >> 5); - if (s3d_tri->cmd_set & CMD_SET_HC) { - if (x_dir > 0) { - if (x > s3d_tri->clip_r) - goto tri_skip_line; - if (xe < s3d_tri->clip_l) - goto tri_skip_line; - if (xe > s3d_tri->clip_r) - xe = s3d_tri->clip_r + 1; - if (x < s3d_tri->clip_l) { - int diff_x = s3d_tri->clip_l - x; + if (s3d_tri->cmd_set & CMD_SET_HC) { + if (x_dir > 0) { + if (x > s3d_tri->clip_r) + goto tri_skip_line; + if (xe < s3d_tri->clip_l) + goto tri_skip_line; + if (xe > s3d_tri->clip_r) + xe = s3d_tri->clip_r + 1; + if (x < s3d_tri->clip_l) { + int diff_x = s3d_tri->clip_l - x; - z += (s3d_tri->TdZdX * diff_x); - state->u += (s3d_tri->TdUdX * diff_x); - state->v += (s3d_tri->TdVdX * diff_x); - state->r += (s3d_tri->TdRdX * diff_x); - state->g += (s3d_tri->TdGdX * diff_x); - state->b += (s3d_tri->TdBdX * diff_x); - state->a += (s3d_tri->TdAdX * diff_x); - state->d += (s3d_tri->TdDdX * diff_x); - state->w += (s3d_tri->TdWdX * diff_x); + z += (s3d_tri->TdZdX * diff_x); + state->u += (s3d_tri->TdUdX * diff_x); + state->v += (s3d_tri->TdVdX * diff_x); + state->r += (s3d_tri->TdRdX * diff_x); + state->g += (s3d_tri->TdGdX * diff_x); + state->b += (s3d_tri->TdBdX * diff_x); + state->a += (s3d_tri->TdAdX * diff_x); + state->d += (s3d_tri->TdDdX * diff_x); + state->w += (s3d_tri->TdWdX * diff_x); - x = s3d_tri->clip_l; - } - } else { - if (x < s3d_tri->clip_l) - goto tri_skip_line; - if (xe > s3d_tri->clip_r) - goto tri_skip_line; - if (xe < s3d_tri->clip_l) - xe = s3d_tri->clip_l - 1; - if (x > s3d_tri->clip_r) { - int diff_x = x - s3d_tri->clip_r; + x = s3d_tri->clip_l; + } + } else { + if (x < s3d_tri->clip_l) + goto tri_skip_line; + if (xe > s3d_tri->clip_r) + goto tri_skip_line; + if (xe < s3d_tri->clip_l) + xe = s3d_tri->clip_l - 1; + if (x > s3d_tri->clip_r) { + int diff_x = x - s3d_tri->clip_r; - z += (s3d_tri->TdZdX * diff_x); - state->u += (s3d_tri->TdUdX * diff_x); - state->v += (s3d_tri->TdVdX * diff_x); - state->r += (s3d_tri->TdRdX * diff_x); - state->g += (s3d_tri->TdGdX * diff_x); - state->b += (s3d_tri->TdBdX * diff_x); - state->a += (s3d_tri->TdAdX * diff_x); - state->d += (s3d_tri->TdDdX * diff_x); - state->w += (s3d_tri->TdWdX * diff_x); + z += (s3d_tri->TdZdX * diff_x); + state->u += (s3d_tri->TdUdX * diff_x); + state->v += (s3d_tri->TdVdX * diff_x); + state->r += (s3d_tri->TdRdX * diff_x); + state->g += (s3d_tri->TdGdX * diff_x); + state->b += (s3d_tri->TdBdX * diff_x); + state->a += (s3d_tri->TdAdX * diff_x); + state->d += (s3d_tri->TdDdX * diff_x); + state->w += (s3d_tri->TdWdX * diff_x); - x = s3d_tri->clip_r; - } - } - } + x = s3d_tri->clip_r; + } + } + } - virge->svga.changedvram[(dest_offset & virge->vram_mask) >> 12] = changeframecount; + virge->svga.changedvram[(dest_offset & virge->vram_mask) >> 12] = changeframecount; - dest_addr = dest_offset + (x * (bpp + 1)); - z_addr = z_offset + (x << 1); + dest_addr = dest_offset + (x * (bpp + 1)); + z_addr = z_offset + (x << 1); - x &= 0xfff; - xe &= 0xfff; + x &= 0xfff; + xe &= 0xfff; - for (; x != xe; x = (x + x_dir) & 0xfff) { - int update = 1; - uint16_t src_z = 0; + for (; x != xe; x = (x + x_dir) & 0xfff) { + int update = 1; + uint16_t src_z = 0; - _x = x; - _y = state->y; + _x = x; + _y = state->y; - if (use_z) { - src_z = Z_READ(z_addr); - Z_CLIP(src_z, z >> 16); - } + if (use_z) { + src_z = Z_READ(z_addr); + Z_CLIP(src_z, z >> 16); + } - if (update) { - uint32_t dest_col; + if (update) { + uint32_t dest_col; - dest_pixel(state); + dest_pixel(state); - if (s3d_tri->cmd_set & CMD_SET_FE) { - int a = state->a >> 7; - state->dest_rgba.r = ((state->dest_rgba.r * a) + (s3d_tri->fog_r * (255 - a))) / 255; - state->dest_rgba.g = ((state->dest_rgba.g * a) + (s3d_tri->fog_g * (255 - a))) / 255; - state->dest_rgba.b = ((state->dest_rgba.b * a) + (s3d_tri->fog_b * (255 - a))) / 255; - } + if (s3d_tri->cmd_set & CMD_SET_FE) { + int a = state->a >> 7; + state->dest_rgba.r = ((state->dest_rgba.r * a) + (s3d_tri->fog_r * (255 - a))) / 255; + state->dest_rgba.g = ((state->dest_rgba.g * a) + (s3d_tri->fog_g * (255 - a))) / 255; + state->dest_rgba.b = ((state->dest_rgba.b * a) + (s3d_tri->fog_b * (255 - a))) / 255; + } - if (s3d_tri->cmd_set & CMD_SET_ABC_ENABLE) { - uint32_t src_col; - int src_r = 0; - uint32_t src_g = 0; - uint32_t src_b = 0; + if (s3d_tri->cmd_set & CMD_SET_ABC_ENABLE) { + uint32_t src_col; + int src_r = 0; + uint32_t src_g = 0; + uint32_t src_b = 0; + switch (bpp) { + case 0: /*8 bpp*/ + /*Not implemented yet*/ + break; + case 1: /*16 bpp*/ + src_col = *(uint16_t *) &vram[dest_addr & virge->vram_mask]; + RGB15_TO_24(src_col, src_r, src_g, src_b); + break; + case 2: /*24 bpp*/ + src_col = (*(uint32_t *) &vram[dest_addr & virge->vram_mask]) & 0xffffff; + RGB24_TO_24(src_col, src_r, src_g, src_b); + break; + } - switch (bpp) { - case 0: /*8 bpp*/ - /*Not implemented yet*/ - break; - case 1: /*16 bpp*/ - src_col = *(uint16_t *)&vram[dest_addr & virge->vram_mask]; - RGB15_TO_24(src_col, src_r, src_g, src_b); - break; - case 2: /*24 bpp*/ - src_col = (*(uint32_t *)&vram[dest_addr & virge->vram_mask]) & 0xffffff; - RGB24_TO_24(src_col, src_r, src_g, src_b); - break; - } + state->dest_rgba.r = ((state->dest_rgba.r * state->dest_rgba.a) + (src_r * (255 - state->dest_rgba.a))) / 255; + state->dest_rgba.g = ((state->dest_rgba.g * state->dest_rgba.a) + (src_g * (255 - state->dest_rgba.a))) / 255; + state->dest_rgba.b = ((state->dest_rgba.b * state->dest_rgba.a) + (src_b * (255 - state->dest_rgba.a))) / 255; + } - state->dest_rgba.r = ((state->dest_rgba.r * state->dest_rgba.a) + - (src_r * (255 - state->dest_rgba.a))) / 255; - state->dest_rgba.g = ((state->dest_rgba.g * state->dest_rgba.a) + - (src_g * (255 - state->dest_rgba.a))) / 255; - state->dest_rgba.b = ((state->dest_rgba.b * state->dest_rgba.a) + - (src_b * (255 - state->dest_rgba.a))) / 255; - } + switch (bpp) { + case 0: /*8 bpp*/ + /*Not implemented yet*/ + break; + case 1: /*16 bpp*/ + RGB15(state->dest_rgba.r, state->dest_rgba.g, state->dest_rgba.b, dest_col); + *(uint16_t *) &vram[dest_addr] = dest_col; + break; + case 2: /*24 bpp*/ + dest_col = RGB24(state->dest_rgba.r, state->dest_rgba.g, state->dest_rgba.b); + *(uint8_t *) &vram[dest_addr] = dest_col & 0xff; + *(uint8_t *) &vram[dest_addr + 1] = (dest_col >> 8) & 0xff; + *(uint8_t *) &vram[dest_addr + 2] = (dest_col >> 16) & 0xff; + break; + } - switch (bpp) { - case 0: /*8 bpp*/ - /*Not implemented yet*/ - break; - case 1: /*16 bpp*/ - RGB15(state->dest_rgba.r, state->dest_rgba.g, state->dest_rgba.b, dest_col); - *(uint16_t *)&vram[dest_addr] = dest_col; - break; - case 2: /*24 bpp*/ - dest_col = RGB24(state->dest_rgba.r, state->dest_rgba.g, state->dest_rgba.b); - *(uint8_t *)&vram[dest_addr] = dest_col & 0xff; - *(uint8_t *)&vram[dest_addr + 1] = (dest_col >> 8) & 0xff; - *(uint8_t *)&vram[dest_addr + 2] = (dest_col >> 16) & 0xff; - break; - } + if (use_z && (s3d_tri->cmd_set & CMD_SET_ZUP)) + Z_WRITE(z_addr, src_z); + } - if (use_z && (s3d_tri->cmd_set & CMD_SET_ZUP)) - Z_WRITE(z_addr, src_z); - } - - z += s3d_tri->TdZdX; - state->u += s3d_tri->TdUdX; - state->v += s3d_tri->TdVdX; - state->r += s3d_tri->TdRdX; - state->g += s3d_tri->TdGdX; - state->b += s3d_tri->TdBdX; - state->a += s3d_tri->TdAdX; - state->d += s3d_tri->TdDdX; - state->w += s3d_tri->TdWdX; - dest_addr += x_offset; - z_addr += xz_offset; - virge->pixel_count++; - } + z += s3d_tri->TdZdX; + state->u += s3d_tri->TdUdX; + state->v += s3d_tri->TdVdX; + state->r += s3d_tri->TdRdX; + state->g += s3d_tri->TdGdX; + state->b += s3d_tri->TdBdX; + state->a += s3d_tri->TdAdX; + state->d += s3d_tri->TdDdX; + state->w += s3d_tri->TdWdX; + dest_addr += x_offset; + z_addr += xz_offset; + virge->pixel_count++; + } } tri_skip_line: - state->x1 += dx1; - state->x2 += dx2; + state->x1 += dx1; + state->x2 += dx2; state->base_u += s3d_tri->TdUdY; state->base_v += s3d_tri->TdVdY; state->base_z += s3d_tri->TdZdY; @@ -3473,22 +4283,23 @@ tri_skip_line: state->base_d += s3d_tri->TdDdY; state->base_w += s3d_tri->TdWdY; state->y--; - dest_offset -= s3d_tri->dest_str; - z_offset -= s3d_tri->z_str; + dest_offset -= s3d_tri->dest_str; + z_offset -= s3d_tri->z_str; } } -static int tex_size[8] = {4 * 2, 2 * 2, 2 * 2, 1 * 2, 2 / 1, 2 / 1, 1 * 2, 1 * 2}; +static int tex_size[8] = { 4 * 2, 2 * 2, 2 * 2, 1 * 2, 2 / 1, 2 / 1, 1 * 2, 1 * 2 }; static void -s3_virge_triangle(virge_t *virge, s3d_t *s3d_tri) { +s3_virge_triangle(virge_t *virge, s3d_t *s3d_tri) +{ s3d_state_t state; - uint32_t tex_base; - int c; + uint32_t tex_base; + int c; - uint64_t start_time = plat_timer_read(); - uint64_t end_time; + uint64_t start_time = plat_timer_read(); + uint64_t end_time; state.tbu = s3d_tri->tbu << 11; state.tbv = s3d_tri->tbv << 11; @@ -3502,18 +4313,18 @@ s3_virge_triangle(virge_t *virge, s3d_t *s3d_tri) { state.base_u = s3d_tri->tus; state.base_v = s3d_tri->tvs; state.base_z = s3d_tri->tzs; - state.base_r = (int32_t)s3d_tri->trs; - state.base_g = (int32_t)s3d_tri->tgs; - state.base_b = (int32_t)s3d_tri->tbs; - state.base_a = (int32_t)s3d_tri->tas; + state.base_r = (int32_t) s3d_tri->trs; + state.base_g = (int32_t) s3d_tri->tgs; + state.base_b = (int32_t) s3d_tri->tbs; + state.base_a = (int32_t) s3d_tri->tas; state.base_d = s3d_tri->tds; state.base_w = s3d_tri->tws; tex_base = s3d_tri->tex_base; for (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; + 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; } switch ((s3d_tri->cmd_set >> 27) & 0xf) { @@ -3627,7 +4438,7 @@ s3_virge_triangle(virge_t *virge, s3d_t *s3d_tri) { static void render_thread(void *param) { - virge_t *virge = (virge_t *)param; + virge_t *virge = (virge_t *) param; while (virge->render_thread_run) { thread_wait_event(virge->wake_render_thread, -1); @@ -3642,7 +4453,7 @@ render_thread(void *param) } virge->s3d_busy = 0; virge->subsys_stat |= INT_S3D_DONE; - s3_virge_update_irqs(virge); + virge->irq_pending++; } } @@ -3663,14 +4474,14 @@ queue_triangle(virge_t *virge) static void s3_virge_hwcursor_draw(svga_t *svga, int displine) { - virge_t *virge = (virge_t *) svga->priv; - int x; - uint16_t dat[2] = { 0, 0 }; - int xx; - int offset = svga->hwcursor_latch.x - svga->hwcursor_latch.xoff; - uint32_t fg; - uint32_t bg; - uint32_t vram_mask = virge->vram_mask; + virge_t *virge = (virge_t *) svga->priv; + int x; + uint16_t dat[2] = { 0, 0 }; + int xx; + int offset = svga->hwcursor_latch.x - svga->hwcursor_latch.xoff; + uint32_t fg; + uint32_t bg; + uint32_t vram_mask = virge->vram_mask; if (svga->interlace && svga->hwcursor_oddeven) svga->hwcursor_latch.addr += 16; @@ -3753,103 +4564,99 @@ s3_virge_hwcursor_draw(svga_t *svga, int displine) svga->hwcursor_latch.addr += 16; } -#define DECODE_YCbCr() \ - do { \ - int c; \ - \ - for (c = 0; c < 2; c++) { \ - uint8_t y1, y2; \ - int8_t Cr; \ - int8_t Cb; \ - int dR; \ - int dG; \ - int dB; \ - \ - y1 = src[0]; \ - Cr = src[1] - 0x80; \ - y2 = src[2]; \ - Cb = src[3] - 0x80; \ - src += 4; \ - \ - dR = (359 * Cr) >> 8; \ - dG = (88 * Cb + 183 * Cr) >> 8; \ - dB = (453 * Cb) >> 8; \ - \ - r[x_write] = y1 + dR; \ - CLAMP(r[x_write]); \ - g[x_write] = y1 - dG; \ - CLAMP(g[x_write]); \ - b[x_write] = y1 + dB; \ - CLAMP(b[x_write]); \ - \ - r[x_write + 1] = y2 + dR; \ - CLAMP(r[x_write + 1]); \ - g[x_write + 1] = y2 - dG; \ - CLAMP(g[x_write + 1]); \ - b[x_write + 1] = y2 + dB; \ - CLAMP(b[x_write + 1]); \ - \ - x_write = (x_write + 2) & 7; \ - } \ +#define DECODE_YCbCr() \ + do { \ + for (uint8_t c = 0; c < 2; c++) { \ + uint8_t y1, y2; \ + int8_t Cr; \ + int8_t Cb; \ + int dR; \ + int dG; \ + int dB; \ + \ + y1 = src[0]; \ + Cr = src[1] - 0x80; \ + y2 = src[2]; \ + Cb = src[3] - 0x80; \ + src += 4; \ + \ + dR = (359 * Cr) >> 8; \ + dG = (88 * Cb + 183 * Cr) >> 8; \ + dB = (453 * Cb) >> 8; \ + \ + r[x_write] = y1 + dR; \ + CLAMP(r[x_write]); \ + g[x_write] = y1 - dG; \ + CLAMP(g[x_write]); \ + b[x_write] = y1 + dB; \ + CLAMP(b[x_write]); \ + \ + r[x_write + 1] = y2 + dR; \ + CLAMP(r[x_write + 1]); \ + g[x_write + 1] = y2 - dG; \ + CLAMP(g[x_write + 1]); \ + b[x_write + 1] = y2 + dB; \ + CLAMP(b[x_write + 1]); \ + \ + x_write = (x_write + 2) & 7; \ + } \ } while (0) /*Both YUV formats are untested*/ -#define DECODE_YUV211() \ - do { \ - uint8_t y1, y2, y3, y4; \ - int8_t U, V; \ - int dR; \ - int dG; \ - int dB; \ - \ - U = src[0] - 0x80; \ - y1 = (298 * (src[1] - 16)) >> 8; \ - y2 = (298 * (src[2] - 16)) >> 8; \ - V = src[3] - 0x80; \ - y3 = (298 * (src[4] - 16)) >> 8; \ - y4 = (298 * (src[5] - 16)) >> 8; \ - src += 6; \ - \ - dR = (309 * V) >> 8; \ - dG = (100 * U + 208 * V) >> 8; \ - dB = (516 * U) >> 8; \ - \ - r[x_write] = y1 + dR; \ - CLAMP(r[x_write]); \ - g[x_write] = y1 - dG; \ - CLAMP(g[x_write]); \ - b[x_write] = y1 + dB; \ - CLAMP(b[x_write]); \ - \ - r[x_write + 1] = y2 + dR; \ - CLAMP(r[x_write + 1]); \ - g[x_write + 1] = y2 - dG; \ - CLAMP(g[x_write + 1]); \ - b[x_write + 1] = y2 + dB; \ - CLAMP(b[x_write + 1]); \ - \ - r[x_write + 2] = y3 + dR; \ - CLAMP(r[x_write + 2]); \ - g[x_write + 2] = y3 - dG; \ - CLAMP(g[x_write + 2]); \ - b[x_write + 2] = y3 + dB; \ - CLAMP(b[x_write + 2]); \ - \ - r[x_write + 3] = y4 + dR; \ - CLAMP(r[x_write + 3]); \ - g[x_write + 3] = y4 - dG; \ - CLAMP(g[x_write + 3]); \ - b[x_write + 3] = y4 + dB; \ - CLAMP(b[x_write + 3]); \ - \ - x_write = (x_write + 4) & 7; \ +#define DECODE_YUV211() \ + do { \ + uint8_t y1, y2, y3, y4; \ + int8_t U, V; \ + int dR; \ + int dG; \ + int dB; \ + \ + U = src[0] - 0x80; \ + y1 = (298 * (src[1] - 16)) >> 8; \ + y2 = (298 * (src[2] - 16)) >> 8; \ + V = src[3] - 0x80; \ + y3 = (298 * (src[4] - 16)) >> 8; \ + y4 = (298 * (src[5] - 16)) >> 8; \ + src += 6; \ + \ + dR = (309 * V) >> 8; \ + dG = (100 * U + 208 * V) >> 8; \ + dB = (516 * U) >> 8; \ + \ + r[x_write] = y1 + dR; \ + CLAMP(r[x_write]); \ + g[x_write] = y1 - dG; \ + CLAMP(g[x_write]); \ + b[x_write] = y1 + dB; \ + CLAMP(b[x_write]); \ + \ + r[x_write + 1] = y2 + dR; \ + CLAMP(r[x_write + 1]); \ + g[x_write + 1] = y2 - dG; \ + CLAMP(g[x_write + 1]); \ + b[x_write + 1] = y2 + dB; \ + CLAMP(b[x_write + 1]); \ + \ + r[x_write + 2] = y3 + dR; \ + CLAMP(r[x_write + 2]); \ + g[x_write + 2] = y3 - dG; \ + CLAMP(g[x_write + 2]); \ + b[x_write + 2] = y3 + dB; \ + CLAMP(b[x_write + 2]); \ + \ + r[x_write + 3] = y4 + dR; \ + CLAMP(r[x_write + 3]); \ + g[x_write + 3] = y4 - dG; \ + CLAMP(g[x_write + 3]); \ + b[x_write + 3] = y4 + dB; \ + CLAMP(b[x_write + 3]); \ + \ + x_write = (x_write + 4) & 7; \ } while (0) #define DECODE_YUV422() \ do { \ - int c; \ - \ - for (c = 0; c < 2; c++) { \ + for (uint8_t c = 0; c < 2; c++) { \ uint8_t y1; \ uint8_t y2; \ int8_t U; \ @@ -3858,9 +4665,9 @@ s3_virge_hwcursor_draw(svga_t *svga, int displine) int dG; \ int dB; \ \ - U = src[0] - 0x80; \ + U = src[0] - 0x80; \ y1 = (298 * (src[1] - 16)) >> 8; \ - V = src[2] - 0x80; \ + V = src[2] - 0x80; \ y2 = (298 * (src[3] - 16)) >> 8; \ src += 4; \ \ @@ -3886,116 +4693,108 @@ s3_virge_hwcursor_draw(svga_t *svga, int displine) } \ } while (0) -#define DECODE_RGB555() \ - do { \ - int c; \ - \ - for (c = 0; c < 4; c++) { \ - uint16_t dat; \ - \ - dat = *(uint16_t *)src; \ - src += 2; \ - \ - r[x_write + c] = \ - ((dat & 0x001f) << 3) | \ - ((dat & 0x001f) >> 2); \ - g[x_write + c] = \ - ((dat & 0x03e0) >> 2) | \ - ((dat & 0x03e0) >> 7); \ - b[x_write + c] = \ - ((dat & 0x7c00) >> 7) | \ - ((dat & 0x7c00) >> 12); \ - } \ - x_write = (x_write + 4) & 7; \ +#define DECODE_RGB555() \ + do { \ + for (uint8_t c = 0; c < 4; c++) { \ + uint16_t dat; \ + \ + dat = *(uint16_t *)src; \ + src += 2; \ + \ + r[x_write + c] = \ + ((dat & 0x001f) << 3) | \ + ((dat & 0x001f) >> 2); \ + g[x_write + c] = \ + ((dat & 0x03e0) >> 2) | \ + ((dat & 0x03e0) >> 7); \ + b[x_write + c] = \ + ((dat & 0x7c00) >> 7) | \ + ((dat & 0x7c00) >> 12); \ + } \ + x_write = (x_write + 4) & 7; \ } while (0) -#define DECODE_RGB565() \ - do { \ - int c; \ - \ - for (c = 0; c < 4; c++) { \ - uint16_t dat; \ - \ - dat = *(uint16_t *)src; \ - src += 2; \ - \ - r[x_write + c] = \ - ((dat & 0x001f) << 3) | \ - ((dat & 0x001f) >> 2); \ - g[x_write + c] = \ - ((dat & 0x07e0) >> 3) | \ - ((dat & 0x07e0) >> 9); \ - b[x_write + c] = \ - ((dat & 0xf800) >> 8) | \ - ((dat & 0xf800) >> 13); \ - } \ - x_write = (x_write + 4) & 7; \ +#define DECODE_RGB565() \ + do { \ + for (uint8_t c = 0; c < 4; c++) { \ + uint16_t dat; \ + \ + dat = *(uint16_t *)src; \ + src += 2; \ + \ + r[x_write + c] = \ + ((dat & 0x001f) << 3) | \ + ((dat & 0x001f) >> 2); \ + g[x_write + c] = \ + ((dat & 0x07e0) >> 3) | \ + ((dat & 0x07e0) >> 9); \ + b[x_write + c] = \ + ((dat & 0xf800) >> 8) | \ + ((dat & 0xf800) >> 13); \ + } \ + x_write = (x_write + 4) & 7; \ } while (0) -#define DECODE_RGB888() \ - do { \ - int c; \ - \ - for (c = 0; c < 4; c++) { \ - r[x_write + c] = src[0]; \ - g[x_write + c] = src[1]; \ - b[x_write + c] = src[2]; \ - src += 3; \ - } \ - x_write = (x_write + 4) & 7; \ +#define DECODE_RGB888() \ + do { \ + for (uint8_t c = 0; c < 4; c++) { \ + r[x_write + c] = src[0]; \ + g[x_write + c] = src[1]; \ + b[x_write + c] = src[2]; \ + src += 3; \ + } \ + x_write = (x_write + 4) & 7; \ } while (0) -#define DECODE_XRGB8888() \ - do { \ - int c; \ - \ - for (c = 0; c < 4; c++) { \ - r[x_write + c] = src[0]; \ - g[x_write + c] = src[1]; \ - b[x_write + c] = src[2]; \ - src += 4; \ - } \ - x_write = (x_write + 4) & 7; \ +#define DECODE_XRGB8888() \ + do { \ + for (uint8_t c = 0; c < 4; c++) { \ + r[x_write + c] = src[0]; \ + g[x_write + c] = src[1]; \ + b[x_write + c] = src[2]; \ + src += 4; \ + } \ + x_write = (x_write + 4) & 7; \ } while (0) -#define OVERLAY_SAMPLE() \ - do { \ - switch (virge->streams.sdif) { \ - case 1: \ - DECODE_YCbCr(); \ - break; \ - case 2: \ - DECODE_YUV422(); \ - break; \ - case 3: \ - DECODE_RGB555(); \ - break; \ - case 4: \ - DECODE_YUV211(); \ - break; \ - case 5: \ - DECODE_RGB565(); \ - break; \ - case 6: \ - DECODE_RGB888(); \ - break; \ - case 7: \ - default: \ - DECODE_XRGB8888(); \ - break; \ - } \ +#define OVERLAY_SAMPLE() \ + do { \ + switch (virge->streams.sdif) { \ + case 1: \ + DECODE_YCbCr(); \ + break; \ + case 2: \ + DECODE_YUV422(); \ + break; \ + case 3: \ + DECODE_RGB555(); \ + break; \ + case 4: \ + DECODE_YUV211(); \ + break; \ + case 5: \ + DECODE_RGB565(); \ + break; \ + case 6: \ + DECODE_RGB888(); \ + break; \ + case 7: \ + default: \ + DECODE_XRGB8888(); \ + break; \ + } \ } while (0) static void s3_virge_overlay_draw(svga_t *svga, int displine) { - virge_t *virge = (virge_t *) svga->priv; + virge_t *virge = (virge_t *) svga->priv; int offset; int r[8]; int g[8]; int b[8]; int x_size; - int x_read = 4; + int x_read = 4; int x_write = 4; int x; uint32_t *p; @@ -4006,7 +4805,7 @@ s3_virge_overlay_draw(svga_t *svga, int displine) else offset = virge->streams.sec_x + 1; - p = &((uint32_t *)buffer32->line[displine])[offset + svga->x_add]; + p = &((uint32_t *) buffer32->line[displine])[offset + svga->x_add]; if (virge->chip < S3_VIRGEGX2) { if ((offset + virge->streams.sec_w) > virge->streams.pri_w) @@ -4310,8 +5109,10 @@ s3_virge_disable_handlers(virge_t *dev) reset_state->svga.mapping = dev->svga.mapping; reset_state->bios_rom.mapping = dev->bios_rom.mapping; - reset_state->svga.timer = dev->svga.timer; - reset_state->svga.timer8514 = dev->svga.timer8514; + reset_state->svga.timer = dev->svga.timer; + reset_state->svga.timer_8514 = dev->svga.timer_8514; + reset_state->svga.timer_xga = dev->svga.timer_xga; + reset_state->irq_timer = dev->irq_timer; } static void @@ -4321,12 +5122,12 @@ s3_virge_reset(void *priv) if (reset_state != NULL) { s3_virge_disable_handlers(dev); - dev->virge_busy = 0; - dev->fifo_write_idx = 0; - dev->fifo_read_idx = 0; - dev->s3d_busy = 0; - dev->s3d_write_idx = 0; - dev->s3d_read_idx = 0; + dev->virge_busy = 0; + dev->fifo_write_idx = 0; + dev->fifo_read_idx = 0; + dev->s3d_busy = 0; + dev->s3d_write_idx = 0; + dev->s3d_read_idx = 0; reset_state->pci_slot = dev->pci_slot; *dev = *reset_state; @@ -4337,56 +5138,59 @@ static void * s3_virge_init(const device_t *info) { const char *bios_fn = NULL; - virge_t *virge = (virge_t *) calloc(1, sizeof(virge_t)); - reset_state = calloc(1, sizeof(virge_t)); + virge_t *virge = (virge_t *) calloc(1, sizeof(virge_t)); + reset_state = calloc(1, sizeof(virge_t)); + + virge->type = (info->local & 0xff); virge->bilinear_enabled = device_get_config_int("bilinear"); virge->dithering_enabled = device_get_config_int("dithering"); - if (info->local >= S3_VIRGE_GX2) + if (virge->type >= S3_VIRGE_GX2) virge->memory_size = 4; else virge->memory_size = device_get_config_int("memory"); virge->onboard = !!(info->local & 0x100); - if (!virge->onboard) switch (info->local) { - case S3_VIRGE_325: - bios_fn = ROM_VIRGE_325; - break; - case S3_DIAMOND_STEALTH3D_2000: - bios_fn = ROM_DIAMOND_STEALTH3D_2000; - break; - case S3_MIROCRYSTAL_3D: - bios_fn = ROM_MIROCRYSTAL_3D; - break; - case S3_DIAMOND_STEALTH3D_3000: - bios_fn = ROM_DIAMOND_STEALTH3D_3000; - break; - case S3_STB_VELOCITY_3D: - bios_fn = ROM_STB_VELOCITY_3D; - break; - case S3_VIRGE_DX: - bios_fn = ROM_VIRGE_DX; - break; - case S3_DIAMOND_STEALTH3D_2000PRO: - bios_fn = ROM_DIAMOND_STEALTH3D_2000PRO; - break; - case S3_VIRGE_GX: - bios_fn = ROM_VIRGE_GX; - break; - case S3_VIRGE_GX2: - bios_fn = ROM_VIRGE_GX2; - break; - case S3_DIAMOND_STEALTH3D_4000: - bios_fn = ROM_DIAMOND_STEALTH3D_4000; - break; - case S3_TRIO_3D2X: - bios_fn = ROM_TRIO3D2X; - break; - default: - free(virge); - return NULL; - } + if (!virge->onboard) + switch (virge->type) { + case S3_VIRGE_325: + bios_fn = ROM_VIRGE_325; + break; + case S3_DIAMOND_STEALTH3D_2000: + bios_fn = ROM_DIAMOND_STEALTH3D_2000; + break; + case S3_MIROCRYSTAL_3D: + bios_fn = ROM_MIROCRYSTAL_3D; + break; + case S3_DIAMOND_STEALTH3D_3000: + bios_fn = ROM_DIAMOND_STEALTH3D_3000; + break; + case S3_STB_VELOCITY_3D: + bios_fn = ROM_STB_VELOCITY_3D; + break; + case S3_VIRGE_DX: + bios_fn = ROM_VIRGE_DX; + break; + case S3_DIAMOND_STEALTH3D_2000PRO: + bios_fn = ROM_DIAMOND_STEALTH3D_2000PRO; + break; + case S3_VIRGE_GX: + bios_fn = ROM_VIRGE_GX; + break; + case S3_VIRGE_GX2: + bios_fn = ROM_VIRGE_GX2; + break; + case S3_DIAMOND_STEALTH3D_4000: + bios_fn = ROM_DIAMOND_STEALTH3D_4000; + break; + case S3_TRIO_3D2X: + bios_fn = ROM_TRIO3D2X; + break; + default: + free(virge); + return NULL; + } svga_init(info, &virge->svga, virge, virge->memory_size << 20, s3_virge_recalctimings, @@ -4396,7 +5200,7 @@ s3_virge_init(const device_t *info) virge->svga.hwcursor.cur_ysize = 64; if (bios_fn != NULL) { - if (info->local == S3_VIRGE_GX2) + if (virge->type == S3_VIRGE_GX2) rom_init(&virge->bios_rom, bios_fn, 0xc0000, 0x10000, 0xffff, 0, MEM_MAPPING_EXTERNAL); else rom_init(&virge->bios_rom, bios_fn, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); @@ -4450,11 +5254,11 @@ s3_virge_init(const device_t *info) virge->virge_id = 0xe1; virge->is_agp = !!(info->flags & DEVICE_AGP); - switch (info->local) { + switch (virge->type) { case S3_VIRGE_325: case S3_DIAMOND_STEALTH3D_2000: case S3_MIROCRYSTAL_3D: - virge->fifo_slots_num = 8; + virge->fifo_slots_num = 8; virge->svga.decode_mask = (4 << 20) - 1; virge->virge_id_high = 0x56; virge->virge_id_low = 0x31; @@ -4464,7 +5268,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->fifo_slots_num = 8; virge->svga.decode_mask = (8 << 20) - 1; virge->virge_id_high = 0x88; virge->virge_id_low = 0x3d; @@ -4474,7 +5278,7 @@ s3_virge_init(const device_t *info) break; case S3_VIRGE_GX2: case S3_DIAMOND_STEALTH3D_4000: - virge->fifo_slots_num = 16; + virge->fifo_slots_num = 16; virge->svga.decode_mask = (4 << 20) - 1; virge->virge_id_high = 0x8a; virge->virge_id_low = 0x10; @@ -4486,7 +5290,7 @@ s3_virge_init(const device_t *info) break; case S3_TRIO_3D2X: - virge->fifo_slots_num = 16; + virge->fifo_slots_num = 16; virge->svga.decode_mask = (8 << 20) - 1; virge->virge_id_high = 0x8a; virge->virge_id_low = 0x13; @@ -4503,7 +5307,7 @@ s3_virge_init(const device_t *info) fallthrough; default: - virge->fifo_slots_num = 8; + virge->fifo_slots_num = 8; virge->svga.decode_mask = (4 << 20) - 1; virge->virge_id_high = 0x8a; virge->virge_id_low = 0x01; @@ -4555,7 +5359,7 @@ s3_virge_init(const device_t *info) default: break; } - if (info->local == S3_VIRGE_GX) + if (virge->type == S3_VIRGE_GX) virge->svga.crtc[0x36] |= (1 << 2); } @@ -4572,16 +5376,18 @@ s3_virge_init(const device_t *info) virge->svga.force_old_addr = 1; - virge->render_thread_run = 1; + virge->render_thread_run = 1; virge->wake_render_thread = thread_create_event(); - virge->wake_main_thread = thread_create_event(); - virge->not_full_event = thread_create_event(); - virge->render_thread = thread_create(render_thread, virge); + virge->wake_main_thread = thread_create_event(); + virge->not_full_event = thread_create_event(); + virge->render_thread = thread_create(render_thread, virge); - virge->fifo_thread_run = 1; - virge->wake_fifo_thread = thread_create_event(); + virge->fifo_thread_run = 1; + virge->wake_fifo_thread = thread_create_event(); virge->fifo_not_full_event = thread_create_event(); - virge->fifo_thread = thread_create(fifo_thread, virge); + virge->fifo_thread = thread_create(fifo_thread, virge); + + timer_add(&virge->irq_timer, s3_virge_update_irq_timer, virge, 1); virge->local = info->local; @@ -4702,144 +5508,153 @@ s3_virge_force_redraw(void *priv) } static const device_config_t s3_virge_config[] = { - // clang-format off + // clang-format off { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 4, - .selection = { - { - .description = "2 MB", - .value = 2 - }, - { - .description = "4 MB", - .value = 4 - }, - { - .description = "" - } - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_int = 4, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "2 MB", .value = 2 }, + { .description = "4 MB", .value = 4 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "bilinear", - .description = "Bilinear filtering", - .type = CONFIG_BINARY, - .default_int = 1 + .name = "bilinear", + .description = "Bilinear filtering", + .type = CONFIG_BINARY, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "dithering", - .description = "Dithering", - .type = CONFIG_BINARY, - .default_int = 1 + .name = "dithering", + .description = "Dithering", + .type = CONFIG_BINARY, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } - // clang-format on + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on }; static const device_config_t s3_virge_stb_config[] = { - // clang-format off + // clang-format off { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 4, - .selection = { - { - .description = "2 MB", - .value = 2 - }, - { - .description = "4 MB", - .value = 4 - }, - { - .description = "8 MB", - .value = 8 - }, - { - .description = "" - } - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_int = 4, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "2 MB", .value = 2 }, + { .description = "4 MB", .value = 4 }, + { .description = "8 MB", .value = 8 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "bilinear", - .description = "Bilinear filtering", - .type = CONFIG_BINARY, - .default_int = 1 + .name = "bilinear", + .description = "Bilinear filtering", + .type = CONFIG_BINARY, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "dithering", - .description = "Dithering", - .type = CONFIG_BINARY, - .default_int = 1 + .name = "dithering", + .description = "Dithering", + .type = CONFIG_BINARY, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } - // clang-format on + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on }; static const device_config_t s3_virge_357_config[] = { - // clang-format off + // clang-format off { - .name = "bilinear", - .description = "Bilinear filtering", - .type = CONFIG_BINARY, - .default_int = 1 + .name = "bilinear", + .description = "Bilinear filtering", + .type = CONFIG_BINARY, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "dithering", - .description = "Dithering", - .type = CONFIG_BINARY, - .default_int = 1 + .name = "dithering", + .description = "Dithering", + .type = CONFIG_BINARY, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } - // clang-format on + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on }; static const device_config_t s3_trio3d2x_config[] = { - // clang-format off + // clang-format off { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 4, - .selection = { - { - .description = "4 MB", - .value = 4 - }, - { - .description = "8 MB", - .value = 8 - }, - { - .description = "" - } - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 4, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "4 MB", .value = 4 }, + { .description = "8 MB", .value = 8 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "bilinear", - .description = "Bilinear filtering", - .type = CONFIG_BINARY, - .default_int = 1 + .name = "bilinear", + .description = "Bilinear filtering", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "dithering", - .description = "Dithering", - .type = CONFIG_BINARY, - .default_int = 1 + .name = "dithering", + .description = "Dithering", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } - // clang-format on + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on }; const device_t s3_virge_325_pci_device = { @@ -4850,7 +5665,7 @@ const device_t s3_virge_325_pci_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_virge_325_available }, + .available = s3_virge_325_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_config @@ -4864,7 +5679,7 @@ const device_t s3_virge_325_onboard_pci_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = NULL }, + .available = NULL, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_config @@ -4878,7 +5693,7 @@ const device_t s3_diamond_stealth_2000_pci_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_virge_325_diamond_available }, + .available = s3_virge_325_diamond_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_config @@ -4892,7 +5707,7 @@ const device_t s3_mirocrystal_3d_pci_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_mirocrystal_3d_available }, + .available = s3_mirocrystal_3d_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_config @@ -4906,7 +5721,7 @@ const device_t s3_diamond_stealth_3000_pci_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_virge_988_diamond_available }, + .available = s3_virge_988_diamond_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_stb_config @@ -4920,7 +5735,7 @@ const device_t s3_stb_velocity_3d_pci_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_virge_988_stb_available }, + .available = s3_virge_988_stb_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_stb_config @@ -4934,7 +5749,7 @@ const device_t s3_virge_375_pci_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_virge_375_available }, + .available = s3_virge_375_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_config @@ -4948,7 +5763,7 @@ const device_t s3_virge_375_onboard_pci_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = NULL }, + .available = NULL, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_config @@ -4962,7 +5777,7 @@ const device_t s3_diamond_stealth_2000pro_pci_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_virge_375_diamond_available }, + .available = s3_virge_375_diamond_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_config @@ -4976,7 +5791,7 @@ const device_t s3_virge_385_pci_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_virge_385_available }, + .available = s3_virge_385_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_config @@ -4990,7 +5805,7 @@ const device_t s3_virge_357_pci_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_virge_357_available }, + .available = s3_virge_357_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_357_config @@ -5004,7 +5819,7 @@ const device_t s3_virge_357_agp_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_virge_357_available }, + .available = s3_virge_357_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_357_config @@ -5018,7 +5833,7 @@ const device_t s3_diamond_stealth_4000_pci_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_virge_357_diamond_available }, + .available = s3_virge_357_diamond_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_357_config @@ -5032,7 +5847,7 @@ const device_t s3_diamond_stealth_4000_agp_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_virge_357_diamond_available }, + .available = s3_virge_357_diamond_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_virge_357_config @@ -5046,7 +5861,7 @@ const device_t s3_trio3d2x_pci_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_trio3d2x_available }, + .available = s3_trio3d2x_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_trio3d2x_config @@ -5060,7 +5875,7 @@ const device_t s3_trio3d2x_agp_device = { .init = s3_virge_init, .close = s3_virge_close, .reset = s3_virge_reset, - { .available = s3_trio3d2x_available }, + .available = s3_trio3d2x_available, .speed_changed = s3_virge_speed_changed, .force_redraw = s3_virge_force_redraw, .config = s3_trio3d2x_config diff --git a/src/video/vid_sigma.c b/src/video/vid_sigma.c index 56f8b99aa..6be21ce69 100644 --- a/src/video/vid_sigma.c +++ b/src/video/vid_sigma.c @@ -151,14 +151,14 @@ typedef struct sigma_t { uint8_t sigmamode; /* Mode control register [0x2D8] */ - uint16_t ma, maback; + uint16_t memaddr, memaddr_backup; int crtcreg; /* CRTC: Real selected register */ int linepos, displine; - int sc, vc; + int scanline, vc; int cgadispon; - int con, coff, cursoron, cgablink; + int cursorvisible, cursoron, cgablink; int vsynctime, vadj; int oddeven; @@ -414,23 +414,23 @@ sigma_text80(sigma_t *sigma) { uint8_t chr; uint8_t attr; - uint16_t ca = (sigma->crtc[15] | (sigma->crtc[14] << 8)); - uint16_t ma = ((sigma->ma & 0x3FFF) << 1); + uint16_t cursoraddr = (sigma->crtc[15] | (sigma->crtc[14] << 8)); + uint16_t memaddr = ((sigma->memaddr & 0x3FFF) << 1); int drawcursor; uint32_t cols[4]; - const uint8_t *vram = sigma->vram + (ma << 1); + const uint8_t *vram = sigma->vram + (memaddr << 1); - ca = ca << 1; + cursoraddr = cursoraddr << 1; if (sigma->sigma_ctl & CTL_CURSOR) - ++ca; - ca &= 0x3fff; + ++cursoraddr; + cursoraddr &= 0x3fff; /* The Sigma 400 seems to use screen widths stated in words (40 for 80-column, 20 for 40-column) */ 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); + drawcursor = ((memaddr == cursoraddr) && sigma->cursorvisible && sigma->cursoron); if (!(sigma->sigmamode & MODE_NOBLINK)) { cols[1] = (attr & 15) | 16; @@ -445,22 +445,22 @@ sigma_text80(sigma_t *sigma) if (drawcursor) { 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; + buffer32->line[sigma->displine][(x << 3) + c + 8] = cols[(fontdatm[chr][sigma->scanline & 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; + buffer32->line[sigma->displine][(x << 3) + c + 8] = cols[(fontdat[chr][sigma->scanline & 7] & (1 << (c ^ 7))) ? 1 : 0] ^ 0xf; } } else { 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]; + buffer32->line[sigma->displine][(x << 3) + c + 8] = cols[(fontdatm[chr][sigma->scanline & 15] & (1 << (c ^ 7))) ? 1 : 0]; else - buffer32->line[sigma->displine][(x << 3) + c + 8] = cols[(fontdat[chr][sigma->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; + buffer32->line[sigma->displine][(x << 3) + c + 8] = cols[(fontdat[chr][sigma->scanline & 7] & (1 << (c ^ 7))) ? 1 : 0]; } } - ++ma; + ++memaddr; } - sigma->ma += sigma->crtc[1]; + sigma->memaddr += sigma->crtc[1]; } /* Render a line in 40-column text mode */ @@ -469,23 +469,23 @@ sigma_text40(sigma_t *sigma) { uint8_t chr; uint8_t attr; - uint16_t ca = (sigma->crtc[15] | (sigma->crtc[14] << 8)); - uint16_t ma = ((sigma->ma & 0x3FFF) << 1); + uint16_t cursoraddr = (sigma->crtc[15] | (sigma->crtc[14] << 8)); + uint16_t memaddr = ((sigma->memaddr & 0x3FFF) << 1); int drawcursor; uint32_t cols[4]; - const uint8_t *vram = sigma->vram + ((ma << 1) & 0x3FFF); + const uint8_t *vram = sigma->vram + ((memaddr << 1) & 0x3FFF); - ca = ca << 1; + cursoraddr = cursoraddr << 1; if (sigma->sigma_ctl & CTL_CURSOR) - ++ca; - ca &= 0x3fff; + ++cursoraddr; + cursoraddr &= 0x3fff; /* The Sigma 400 seems to use screen widths stated in words (40 for 80-column, 20 for 40-column) */ 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); + drawcursor = ((memaddr == cursoraddr) && sigma->cursorvisible && sigma->cursoron); if (!(sigma->sigmamode & MODE_NOBLINK)) { cols[1] = (attr & 15) | 16; @@ -499,24 +499,24 @@ sigma_text40(sigma_t *sigma) if (drawcursor) { 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; + buffer32->line[sigma->displine][(x << 4) + 2 * c + 8] = buffer32->line[sigma->displine][(x << 4) + 2 * c + 9] = cols[(fontdatm[chr][sigma->scanline & 15] & (1 << (c ^ 7))) ? 1 : 0] ^ 0xf; } } else { 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]; + buffer32->line[sigma->displine][(x << 4) + 2 * c + 8] = buffer32->line[sigma->displine][(x << 4) + 2 * c + 9] = cols[(fontdatm[chr][sigma->scanline & 15] & (1 << (c ^ 7))) ? 1 : 0]; } } - ma++; + memaddr++; } - sigma->ma += sigma->crtc[1]; + sigma->memaddr += sigma->crtc[1]; } /* Draw a line in the 640x400 graphics mode */ static void sigma_gfx400(sigma_t *sigma) { - const uint8_t *vram = &sigma->vram[((sigma->ma << 1) & 0x1FFF) + (sigma->sc & 3) * 0x2000]; + const uint8_t *vram = &sigma->vram[((sigma->memaddr << 1) & 0x1FFF) + (sigma->scanline & 3) * 0x2000]; uint8_t plane[4]; uint8_t col; @@ -532,7 +532,7 @@ sigma_gfx400(sigma_t *sigma) buffer32->line[sigma->displine][(x << 3) + c + 8] = col; } if (x & 1) - ++sigma->ma; + ++sigma->memaddr; } } @@ -544,7 +544,7 @@ sigma_gfx400(sigma_t *sigma) static void sigma_gfx200(sigma_t *sigma) { - const uint8_t *vram = &sigma->vram[((sigma->ma << 1) & 0x1FFF) + (sigma->sc & 2) * 0x1000]; + const uint8_t *vram = &sigma->vram[((sigma->memaddr << 1) & 0x1FFF) + (sigma->scanline & 2) * 0x1000]; uint8_t plane[4]; uint8_t col; @@ -561,7 +561,7 @@ sigma_gfx200(sigma_t *sigma) } if (x & 1) - ++sigma->ma; + ++sigma->memaddr; } } @@ -569,7 +569,7 @@ sigma_gfx200(sigma_t *sigma) static void sigma_gfx4col(sigma_t *sigma) { - const uint8_t *vram = &sigma->vram[((sigma->ma << 1) & 0x1FFF) + (sigma->sc & 2) * 0x1000]; + const uint8_t *vram = &sigma->vram[((sigma->memaddr << 1) & 0x1FFF) + (sigma->scanline & 2) * 0x1000]; uint8_t plane[4]; uint8_t mask; uint8_t col; @@ -592,7 +592,7 @@ sigma_gfx4col(sigma_t *sigma) } if (x & 1) - ++sigma->ma; + ++sigma->memaddr; } } @@ -604,15 +604,15 @@ sigma_poll(void *priv) int c; int oldvc; uint32_t cols[4]; - int oldsc; + int scanline_old; if (!sigma->linepos) { timer_advance_u64(&sigma->timer, sigma->dispofftime); sigma->sigmastat |= STATUS_RETR_H; sigma->linepos = 1; - oldsc = sigma->sc; + scanline_old = sigma->scanline; if ((sigma->crtc[8] & 3) == 3) - sigma->sc = ((sigma->sc << 1) + sigma->oddeven) & 7; + sigma->scanline = ((sigma->scanline << 1) + sigma->oddeven) & 7; if (sigma->cgadispon) { if (sigma->displine < sigma->firstline) { sigma->firstline = sigma->displine; @@ -660,8 +660,8 @@ sigma_poll(void *priv) video_process_8(x, sigma->displine); - sigma->sc = oldsc; - if (sigma->vc == sigma->crtc[7] && !sigma->sc) + sigma->scanline = scanline_old; + if (sigma->vc == sigma->crtc[7] && !sigma->scanline) sigma->sigmastat |= STATUS_RETR_V; sigma->displine++; if (sigma->displine >= 560) @@ -674,25 +674,24 @@ sigma_poll(void *priv) if (!sigma->vsynctime) sigma->sigmastat &= ~STATUS_RETR_V; } - if (sigma->sc == (sigma->crtc[11] & 31) || ((sigma->crtc[8] & 3) == 3 && sigma->sc == ((sigma->crtc[11] & 31) >> 1))) { - sigma->con = 0; - sigma->coff = 1; + if (sigma->scanline == (sigma->crtc[11] & 31) || ((sigma->crtc[8] & 3) == 3 && sigma->scanline == ((sigma->crtc[11] & 31) >> 1))) { + sigma->cursorvisible = 0; } - if ((sigma->crtc[8] & 3) == 3 && sigma->sc == (sigma->crtc[9] >> 1)) - sigma->maback = sigma->ma; + if ((sigma->crtc[8] & 3) == 3 && sigma->scanline == (sigma->crtc[9] >> 1)) + sigma->memaddr_backup = sigma->memaddr; if (sigma->vadj) { - sigma->sc++; - sigma->sc &= 31; - sigma->ma = sigma->maback; + sigma->scanline++; + sigma->scanline &= 31; + sigma->memaddr = sigma->memaddr_backup; sigma->vadj--; if (!sigma->vadj) { sigma->cgadispon = 1; - sigma->ma = sigma->maback = (sigma->crtc[13] | (sigma->crtc[12] << 8)) & 0x3fff; - sigma->sc = 0; + sigma->memaddr = sigma->memaddr_backup = (sigma->crtc[13] | (sigma->crtc[12] << 8)) & 0x3fff; + sigma->scanline = 0; } - } else if (sigma->sc == sigma->crtc[9]) { - sigma->maback = sigma->ma; - sigma->sc = 0; + } else if (sigma->scanline == sigma->crtc[9]) { + sigma->memaddr_backup = sigma->memaddr; + sigma->scanline = 0; oldvc = sigma->vc; sigma->vc++; sigma->vc &= 127; @@ -706,7 +705,7 @@ sigma_poll(void *priv) if (!sigma->vadj) sigma->cgadispon = 1; if (!sigma->vadj) - sigma->ma = sigma->maback = (sigma->crtc[13] | (sigma->crtc[12] << 8)) & 0x3fff; + sigma->memaddr = sigma->memaddr_backup = (sigma->crtc[13] | (sigma->crtc[12] << 8)) & 0x3fff; if ((sigma->crtc[10] & 0x60) == 0x20) sigma->cursoron = 0; else @@ -769,14 +768,14 @@ sigma_poll(void *priv) sigma->oddeven ^= 1; } } else { - sigma->sc++; - sigma->sc &= 31; - sigma->ma = sigma->maback; + sigma->scanline++; + sigma->scanline &= 31; + sigma->memaddr = sigma->memaddr_backup; } 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))) - sigma->con = 1; + if (sigma->scanline == (sigma->crtc[10] & 31) || ((sigma->crtc[8] & 3) == 3 && sigma->scanline == ((sigma->crtc[10] & 31) >> 1))) + sigma->cursorvisible = 1; } } @@ -860,100 +859,59 @@ sigma_speed_changed(void *priv) device_config_t sigma_config[] = { // clang-format off { - .name = "rgb_type", - .description = "RGB type", - .type = CONFIG_SELECTION, - .default_int = 0, - .selection = { - { - .description = "Color", - .value = 0 - }, - { - .description = "Green Monochrome", - .value = 1 - }, - { - .description = "Amber Monochrome", - .value = 2 - }, - { - .description = "Gray Monochrome", - .value = 3 - }, - { - .description = "Color (no brown)", - .value = 4 - }, - { - .description = "" - } - } - }, - { - .name = "enable_nmi", - .description = "Enable NMI for CGA emulation", - .type = CONFIG_BINARY, - .default_int = 1 - }, - { - .name = "bios_addr", - .description = "BIOS Address", - .type = CONFIG_HEX20, - .default_int = 0xc0000, - .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 = "E000H", - .value = 0xe0000 - }, - { - .description = "E400H", - .value = 0xe4000 - }, - { - .description = "E800H", - .value = 0xe8000 - }, - { - .description = "EC00H", - .value = 0xec000 - }, - { - .description = "" - } + .name = "rgb_type", + .description = "RGB type", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Color", .value = 0 }, + { .description = "Green Monochrome", .value = 1 }, + { .description = "Amber Monochrome", .value = 2 }, + { .description = "Gray Monochrome", .value = 3 }, + { .description = "Color (no brown)", .value = 4 }, + { .description = "" } }, + .bios = { { 0 } } }, { - .type = CONFIG_END - } + .name = "enable_nmi", + .description = "Enable NMI for CGA emulation", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { + .name = "bios_addr", + .description = "BIOS Address", + .type = CONFIG_HEX20, + .default_string = NULL, + .default_int = 0xc0000, + .file_filter = NULL, + .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 = "E000H", .value = 0xe0000 }, + { .description = "E400H", .value = 0xe4000 }, + { .description = "E800H", .value = 0xe8000 }, + { .description = "EC00H", .value = 0xec000 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -965,7 +923,7 @@ const device_t sigma_device = { .init = sigma_init, .close = sigma_close, .reset = NULL, - { .available = sigma_available }, + .available = sigma_available, .speed_changed = sigma_speed_changed, .force_redraw = NULL, .config = sigma_config diff --git a/src/video/vid_svga.c b/src/video/vid_svga.c index 6a91713fb..afeb7a9d6 100644 --- a/src/video/vid_svga.c +++ b/src/video/vid_svga.c @@ -83,26 +83,76 @@ svga_get_pri(void) return svga_pri; } +void +svga_set_poll(svga_t *svga) +{ + svga_log("SVGA Timer activated, enabled?=%x.\n", timer_is_enabled(&svga->timer)); + timer_set_callback(&svga->timer, svga_poll); + if (!timer_is_enabled(&svga->timer)) + timer_enable(&svga->timer); +} + void svga_set_override(svga_t *svga, int val) { ibm8514_t *dev = (ibm8514_t *) svga->dev8514; + xga_t *xga = (xga_t *) svga->xga; + uint8_t ret_poll = 0; if (svga->override && !val) svga->fullchange = svga->monitor->mon_changeframecount; + svga->override = val; svga_log("Override=%x.\n", val); - if (ibm8514_active && (svga->dev8514 != NULL)) { - if (dev->on) { - if (svga->override) - timer_set_callback(&svga->timer, svga_poll); - else - timer_set_callback(&svga->timer, ibm8514_poll); - } else - timer_set_callback(&svga->timer, svga_poll); - } else - timer_set_callback(&svga->timer, svga_poll); + if (ibm8514_active && (svga->dev8514 != NULL)) + ret_poll |= 1; + + if (xga_active && (svga->xga != NULL)) + ret_poll |= 2; + + if (svga->override) + svga_set_poll(svga); + else { + switch (ret_poll) { + case 0: + default: + svga_set_poll(svga); + break; + + case 1: + if (ibm8514_active && (svga->dev8514 != NULL)) { + if (dev->on) + ibm8514_set_poll(svga); + else + svga_set_poll(svga); + } else + svga_set_poll(svga); + break; + + case 2: + if (xga_active && (svga->xga != NULL)) { + if (xga->on) + xga_set_poll(svga); + else + svga_set_poll(svga); + } else + svga_set_poll(svga); + break; + + case 3: + if (ibm8514_active && (svga->dev8514 != NULL) && xga_active && (svga->xga != NULL)) { + if (dev->on) + ibm8514_set_poll(svga); + else if (xga->on) + xga_set_poll(svga); + else + svga_set_poll(svga); + } else + svga_set_poll(svga); + break; + } + } #ifdef OVERRIDE_OVERSCAN if (!val) { @@ -230,9 +280,11 @@ svga_out(uint16_t addr, uint8_t val, void *priv) case 0x3c2: svga->miscout = val; svga->vidclock = val & 4; - 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->priv); + if (svga->priv_parent == NULL) { + 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->priv); + } svga_recalctimings(svga); break; case 0x3c3: @@ -241,7 +293,7 @@ svga_out(uint16_t addr, uint8_t val, void *priv) if (ibm8514_active && dev) dev->on = (val & 0x01) ? 0 : 1; - svga_log("Write Port 3C3.\n"); + svga_log("Write Port 3C3=%x.\n", val & 0x01); svga_recalctimings(svga); break; case 0x3c4: @@ -452,10 +504,25 @@ svga_in(uint16_t addr, void *priv) ret = svga->attrregs[svga->attraddr]; break; case 0x3c2: - if ((svga->vgapal[0].r + svga->vgapal[0].g + svga->vgapal[0].b) >= 0x4e) - ret = 0; - else - ret = 0x10; + if (svga->cable_connected) { + if ((svga->vgapal[0].r + svga->vgapal[0].g + svga->vgapal[0].b) >= 0x4e) + ret = 0; + else + ret = 0x10; + /* Monitor is not connected to the planar VGA if the PS/55 Display Adapter is installed. */ + } else { + /* + The IBM PS/55 Display Adapter has own Monitor Type Detection bit in the different I/O port (I/O 3E0h, 3E1h). + When the monitor cable is connected to the Display Adapter, the port 3C2h returns the value as 'no cable connection'. + The POST of PS/55 has an extra code. If the monitor is not detected on the planar VGA, + it reads the POS data in NVRAM set by the reference diskette, and writes the BIOS Data Area (Mem 487h, 489h). + MONCHK.EXE in the reference diskette uses both I/O ports to determine the monitor type, updates the NVRAM and BDA. + */ + if (svga->vgapal[0].r >= 10 || svga->vgapal[0].g >= 10 || svga->vgapal[0].b >= 10) + ret = 0; + else + ret = 0x10; + } break; case 0x3c3: ret = 0x01; @@ -612,6 +679,8 @@ void svga_recalctimings(svga_t *svga) { ibm8514_t *dev = (ibm8514_t *) svga->dev8514; + xga_t *xga = (xga_t *) svga->xga; + uint8_t set_timer = 0; double crtcconst; double _dispontime; double _dispofftime; @@ -620,11 +689,14 @@ svga_recalctimings(svga_t *svga) double _dispontime8514 = 0.0; double _dispofftime8514 = 0.0; double disptime8514 = 0.0; + double crtcconst_xga = 0.0; + double _dispontime_xga = 0.0; + double _dispofftime_xga = 0.0; + double disptime_xga = 0.0; #ifdef ENABLE_SVGA_LOG int vsyncend; - int vblankend; - int hdispstart; int hdispend; + int hdispstart; int hsyncstart; int hsyncend; #endif @@ -668,7 +740,8 @@ svga_recalctimings(svga_t *svga) svga->vblankstart++; svga->hdisp = svga->crtc[1]; - svga->hdisp++; + if (svga->crtc[1] & 1) + svga->hdisp++; svga->htotal = svga->crtc[0]; /* +5 has been verified by Sergi to be correct - +6 must have been an off by one error. */ @@ -682,7 +755,7 @@ svga_recalctimings(svga_t *svga) svga->interlace = 0; - svga->ma_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5); + svga->memaddr_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5); svga->ca_adj = 0; svga->rowcount = svga->crtc[9] & 0x1f; @@ -704,11 +777,18 @@ svga_recalctimings(svga_t *svga) } if (!(svga->gdcreg[6] & 1) && !(svga->attrregs[0x10] & 1)) { /*Text mode*/ - if (svga->seqregs[1] & 8) { /*40 column*/ + if (svga->seqregs[1] & 8) /*40 column*/ svga->render = svga_render_text_40; - } else + else svga->render = svga_render_text_80; + if (xga_active && (svga->xga != NULL)) { + if (xga->on) { + svga_log("XGA on=%d, base=%05x, ap=%x.\n", xga->on, svga->mapping.base, xga->aperture_cntl); + if ((svga->mapping.base == 0xb8000) && (xga->aperture_cntl >= 1)) /*Some operating systems reset themselves with ctrl-alt-del by going into text mode.*/ + xga->on = 0; + } + } svga->hdisp_old = svga->hdisp; } else { svga->hdisp_old = svga->hdisp; @@ -825,14 +905,24 @@ svga_recalctimings(svga_t *svga) svga->recalctimings_ex(svga); if (ibm8514_active && (svga->dev8514 != NULL)) { - if ((dev->local & 0xff) == 0x00) + if (IBM_8514A || ATI_8514A_ULTRA) ibm8514_recalctimings(svga); } if (xga_active && (svga->xga != NULL)) xga_recalctimings(svga); - if (!svga->hoverride) { + svga->vblankend = (svga->vblankstart & 0xffffff80) | (svga->crtc[0x16] & 0x7f); + if (svga->vblankend <= svga->vblankstart) + svga->vblankend += 0x00000080; + + if (svga->hoverride || svga->override) { + if (svga->hdisp >= 2048) + svga->monitor->mon_overscan_x = 0; + + svga->y_add = (svga->monitor->mon_overscan_y >> 1); + svga->left_overscan = svga->x_add = (svga->monitor->mon_overscan_x >> 1); + } else { uint32_t dot = svga->hblankstart; uint32_t adj_dot = svga->hblankstart; /* Verified with both the Voodoo 3 and the S3 cards: compare 7 bits if bit 7 is set, @@ -840,7 +930,9 @@ svga_recalctimings(svga_t *svga) uint32_t eff_mask = (svga->hblank_end_val & ~0x0000003f) ? svga->hblank_end_mask : 0x0000003f; svga->hblank_sub = 0; - svga_log("HDISP=%d, CRTC1+1=%d, Blank: %04i-%04i, Total: %04i, Mask: %02X, ADJ_DOT=%04i.\n", svga->hdisp, svga->crtc[1] + 1, svga->hblankstart, svga->hblank_end_val, + svga_log("HDISP=%d, CRTC1+1=%d, Blank: %04i-%04i, Total: %04i, " + "Mask: %02X, ADJ_DOT=%04i.\n", svga->hdisp, svga->crtc[1] + 1, + svga->hblankstart, svga->hblank_end_val, svga->htotal, eff_mask, adj_dot); while (adj_dot < (svga->htotal << 1)) { @@ -850,7 +942,10 @@ svga_recalctimings(svga_t *svga) if (adj_dot >= svga->htotal) svga->hblank_sub++; - svga_log("Loop: adjdot=%d, htotal=%d, dotmask=%02x, hblankendvalmask=%02x, blankendval=%02x.\n", adj_dot, svga->htotal, dot & eff_mask, svga->hblank_end_val & eff_mask, svga->hblank_end_val); + svga_log("Loop: adjdot=%d, htotal=%d, dotmask=%02x, " + "hblankendvalmask=%02x, blankendval=%02x.\n", adj_dot, + svga->htotal, dot & eff_mask, svga->hblank_end_val & eff_mask, + svga->hblank_end_val); if ((dot & eff_mask) == (svga->hblank_end_val & eff_mask)) break; @@ -858,7 +953,28 @@ svga_recalctimings(svga_t *svga) adj_dot++; } + uint32_t hd = svga->hdisp; svga->hdisp -= (svga->hblank_sub * svga->dots_per_clock); + + svga->left_overscan = svga->x_add = (svga->htotal - adj_dot - 1) * svga->dots_per_clock; + svga->monitor->mon_overscan_x = svga->x_add + (svga->hblankstart * svga->dots_per_clock) - hd + svga->dots_per_clock; + /* Compensate for the HDISP code above. */ + if (svga->crtc[1] & 1) + svga->monitor->mon_overscan_x++; + + if ((svga->hdisp >= 2048) || (svga->left_overscan < 0)) { + svga->left_overscan = svga->x_add = 0; + svga->monitor->mon_overscan_x = 0; + } + + /* - 1 because + 1 but also - 2 to compensate for the + 2 added to vtotal above. */ + svga->y_add = svga->vtotal - svga->vblankend - 1; + svga->monitor->mon_overscan_y = svga->y_add + abs(svga->vblankstart - svga->dispend); + + if ((svga->dispend >= 2048) || (svga->y_add < 0)) { + svga->y_add = 0; + svga->monitor->mon_overscan_y = 0; + } } #ifdef TBD @@ -866,7 +982,7 @@ svga_recalctimings(svga_t *svga) if (dev->on) { uint32_t dot8514 = dev->h_blankstart; uint32_t adj_dot8514 = dev->h_blankstart; - uint32_t eff_mask8514 = 0x0000003f; + uint32_t eff_mask8514 = 0x0000001f; dev->hblank_sub = 0; while (adj_dot8514 < (dev->h_total << 1)) { @@ -888,12 +1004,6 @@ svga_recalctimings(svga_t *svga) } #endif - if (svga->hdisp >= 2048) - svga->monitor->mon_overscan_x = 0; - - svga->y_add = (svga->monitor->mon_overscan_y >> 1); - svga->x_add = (svga->monitor->mon_overscan_x >> 1); - if (svga->vblankstart < svga->dispend) { svga_log("DISPEND > VBLANKSTART.\n"); svga->dispend = svga->vblankstart; @@ -902,19 +1012,20 @@ svga_recalctimings(svga_t *svga) crtcconst = svga->clock * svga->char_width; if (ibm8514_active && (svga->dev8514 != NULL)) { if (dev->on) - crtcconst8514 = svga->clock8514; + crtcconst8514 = svga->clock_8514; + } + if (xga_active && (svga->xga != NULL)) { + if (xga->on) + crtcconst_xga = svga->clock_xga; } #ifdef ENABLE_SVGA_LOG vsyncend = (svga->vsyncstart & 0xfffffff0) | (svga->crtc[0x11] & 0x0f); if (vsyncend <= svga->vsyncstart) vsyncend += 0x00000010; - vblankend = (svga->vblankstart & 0xffffff80) | (svga->crtc[0x16] & 0x7f); - if (vblankend <= svga->vblankstart) - vblankend += 0x00000080; - hdispstart = ((svga->crtc[3] >> 5) & 3); hdispend = svga->crtc[1] + 1; + hdispstart = ((svga->crtc[3] >> 5) & 3); hsyncstart = svga->crtc[4] + ((svga->crtc[5] >> 5) & 3) + 1; hsyncend = (hsyncstart & 0xffffffe0) | (svga->crtc[5] & 0x1f); if (hsyncend <= hsyncstart) @@ -938,7 +1049,7 @@ svga_recalctimings(svga_t *svga) "\n" "\n", svga->vtotal, svga->dispend, svga->vsyncstart, vsyncend, - svga->vblankstart, vblankend, + svga->vblankstart, svga->vblankend, svga->htotal, hdispstart, hdispend, hsyncstart, hsyncend, svga->hblankstart, svga->hblankend); @@ -947,8 +1058,16 @@ svga_recalctimings(svga_t *svga) if (ibm8514_active && (svga->dev8514 != NULL)) { if (dev->on) { - disptime8514 = dev->h_total ? dev->h_total : TIMER_USEC; - _dispontime8514 = dev->hdisped; + disptime8514 = dev->h_total; + _dispontime8514 = dev->h_disp; + svga_log("HTOTAL=%d, HDISP=%d.\n", dev->h_total, dev->h_disp); + } + } + + if (xga_active && (svga->xga != NULL)) { + if (xga->on) { + disptime_xga = xga->h_total ? xga->h_total : TIMER_USEC; + _dispontime_xga = xga->h_disp; } } @@ -968,25 +1087,84 @@ svga_recalctimings(svga_t *svga) if (svga->dispofftime < TIMER_USEC) svga->dispofftime = TIMER_USEC; - if (ibm8514_active && (svga->dev8514 != NULL)) { - if (dev->on) { - _dispofftime8514 = disptime8514 - _dispontime8514; - _dispontime8514 *= crtcconst8514; - _dispofftime8514 *= crtcconst8514; + if (ibm8514_active && (svga->dev8514 != NULL)) + set_timer |= 1; - dev->dispontime = (uint64_t) (_dispontime8514); - dev->dispofftime = (uint64_t) (_dispofftime8514); - if (dev->dispontime < TIMER_USEC) - dev->dispontime = TIMER_USEC; - if (dev->dispofftime < TIMER_USEC) - dev->dispofftime = TIMER_USEC; + if (xga_active && (svga->xga != NULL)) + set_timer |= 2; - svga_log("IBM 8514/A poll.\n"); - timer_set_callback(&svga->timer, ibm8514_poll); - } else { - svga_log("SVGA Poll.\n"); - timer_set_callback(&svga->timer, svga_poll); - } + switch (set_timer) { + default: + case 0: /*VGA only*/ + svga_set_poll(svga); + break; + + case 1: /*Plus 8514/A*/ + if (dev->on) { + _dispofftime8514 = disptime8514 - _dispontime8514; + _dispontime8514 *= crtcconst8514; + _dispofftime8514 *= crtcconst8514; + + dev->dispontime = (uint64_t) (_dispontime8514); + dev->dispofftime = (uint64_t) (_dispofftime8514); + if (dev->dispontime < TIMER_USEC) + dev->dispontime = TIMER_USEC; + if (dev->dispofftime < TIMER_USEC) + dev->dispofftime = TIMER_USEC; + + ibm8514_set_poll(svga); + } else + svga_set_poll(svga); + break; + + case 2: /*Plus XGA*/ + if (xga->on) { + _dispofftime_xga = disptime_xga - _dispontime_xga; + _dispontime_xga *= crtcconst_xga; + _dispofftime_xga *= crtcconst_xga; + + xga->dispontime = (uint64_t) (_dispontime_xga); + xga->dispofftime = (uint64_t) (_dispofftime_xga); + if (xga->dispontime < TIMER_USEC) + xga->dispontime = TIMER_USEC; + if (xga->dispofftime < TIMER_USEC) + xga->dispofftime = TIMER_USEC; + + xga_set_poll(svga); + } else + svga_set_poll(svga); + break; + + case 3: /*Plus 8514/A and XGA*/ + if (dev->on) { + _dispofftime8514 = disptime8514 - _dispontime8514; + _dispontime8514 *= crtcconst8514; + _dispofftime8514 *= crtcconst8514; + + dev->dispontime = (uint64_t) (_dispontime8514); + dev->dispofftime = (uint64_t) (_dispofftime8514); + if (dev->dispontime < TIMER_USEC) + dev->dispontime = TIMER_USEC; + if (dev->dispofftime < TIMER_USEC) + dev->dispofftime = TIMER_USEC; + + ibm8514_set_poll(svga); + } else if (xga->on) { + _dispofftime_xga = disptime_xga - _dispontime_xga; + _dispontime_xga *= crtcconst_xga; + _dispofftime_xga *= crtcconst_xga; + + xga->dispontime = (uint64_t) (_dispontime_xga); + xga->dispofftime = (uint64_t) (_dispofftime_xga); + if (xga->dispontime < TIMER_USEC) + xga->dispontime = TIMER_USEC; + if (xga->dispofftime < TIMER_USEC) + xga->dispofftime = TIMER_USEC; + + xga_set_poll(svga); + } else + svga_set_poll(svga); + break; } if (!svga->force_old_addr) @@ -1028,10 +1206,10 @@ svga_do_render(svga_t *svga) if (!svga->override) { svga->render(svga); - svga->x_add = (svga->monitor->mon_overscan_x >> 1); + svga->x_add = svga->left_overscan; svga_render_overscan_left(svga); svga_render_overscan_right(svga); - svga->x_add = (svga->monitor->mon_overscan_x >> 1) - svga->scrollcache; + svga->x_add = svga->left_overscan - svga->scrollcache; } if (svga->overlay_on) { @@ -1064,7 +1242,6 @@ void svga_poll(void *priv) { svga_t *svga = (svga_t *) priv; - xga_t *xga = (xga_t *) svga->xga; uint32_t x; uint32_t blink_delay; int wx; @@ -1072,15 +1249,7 @@ svga_poll(void *priv) int ret; int old_ma; - if (!svga->override) { - if (xga_active && xga && xga->on) { - if ((xga->disp_cntl_2 & 7) >= 2) { - xga_poll(svga); - return; - } - } - } - + svga_log("SVGA Poll.\n"); if (!svga->linepos) { if (svga->displine == ((svga->hwcursor_latch.y < 0) ? 0 : svga->hwcursor_latch.y) && svga->hwcursor_latch.ena) { svga->hwcursor_on = svga->hwcursor_latch.cur_ysize - svga->hwcursor_latch.yoff; @@ -1119,17 +1288,17 @@ svga_poll(void *priv) if (svga->dispon) { svga->hdisp_on = 1; - svga->ma &= svga->vram_display_mask; + svga->memaddr &= svga->vram_display_mask; if (svga->firstline == 2000) { svga->firstline = svga->displine; video_wait_for_buffer_monitor(svga->monitor_index); } if (svga->hwcursor_on || svga->dac_hwcursor_on || svga->overlay_on) - svga->changedvram[svga->ma >> 12] = svga->changedvram[(svga->ma >> 12) + 1] = svga->interlace ? 3 : 2; + svga->changedvram[svga->memaddr >> 12] = svga->changedvram[(svga->memaddr >> 12) + 1] = svga->interlace ? 3 : 2; if (svga->vertical_linedbl) { - old_ma = svga->ma; + old_ma = svga->memaddr; svga->displine <<= 1; svga->y_add <<= 1; @@ -1138,7 +1307,7 @@ svga_poll(void *priv) svga->displine++; - svga->ma = old_ma; + svga->memaddr = old_ma; svga_do_render(svga); @@ -1167,29 +1336,29 @@ svga_poll(void *priv) svga->hdisp_on = 0; svga->linepos = 0; - if ((svga->sc == (svga->crtc[11] & 31)) || (svga->sc == svga->rowcount)) - svga->con = 0; + if ((svga->scanline == (svga->crtc[11] & 31)) || (svga->scanline == svga->rowcount)) + svga->cursorvisible = 0; if (svga->dispon) { /* TODO: Verify real hardware behaviour for out-of-range fine vertical scroll - - S3 Trio64V2/DX: sc == rowcount, wrapping 5-bit counter. */ + - S3 Trio64V2/DX: scanline == rowcount, wrapping 5-bit counter. */ if (svga->linedbl && !svga->linecountff) { svga->linecountff = 1; - svga->ma = svga->maback; - } else if (svga->sc == svga->rowcount) { + svga->memaddr = svga->memaddr_backup; + } else if (svga->scanline == svga->rowcount) { svga->linecountff = 0; - svga->sc = 0; + svga->scanline = 0; - svga->maback += (svga->adv_flags & FLAG_NO_SHIFT3) ? svga->rowoffset : (svga->rowoffset << 3); + svga->memaddr_backup += (svga->adv_flags & FLAG_NO_SHIFT3) ? svga->rowoffset : (svga->rowoffset << 3); if (svga->interlace) - svga->maback += (svga->adv_flags & FLAG_NO_SHIFT3) ? svga->rowoffset : (svga->rowoffset << 3); + svga->memaddr_backup += (svga->adv_flags & FLAG_NO_SHIFT3) ? svga->rowoffset : (svga->rowoffset << 3); - svga->maback &= svga->vram_display_mask; - svga->ma = svga->maback; + svga->memaddr_backup &= svga->vram_display_mask; + svga->memaddr = svga->memaddr_backup; } else { svga->linecountff = 0; - svga->sc++; - svga->sc &= 0x1f; - svga->ma = svga->maback; + svga->scanline++; + svga->scanline &= 0x1f; + svga->memaddr = svga->memaddr_backup; } } @@ -1209,17 +1378,17 @@ svga_poll(void *priv) if (ret) { if (svga->interlace && svga->oddeven) - svga->ma = svga->maback = (svga->rowoffset << 1) + svga->hblank_sub; + svga->memaddr = svga->memaddr_backup = (svga->rowoffset << 1) + svga->hblank_sub; else - svga->ma = svga->maback = svga->hblank_sub; + svga->memaddr = svga->memaddr_backup = svga->hblank_sub; - svga->ma = (svga->ma << 2); - svga->maback = (svga->maback << 2); + svga->memaddr = (svga->memaddr << 2); + svga->memaddr_backup = (svga->memaddr_backup << 2); - svga->sc = 0; + svga->scanline = 0; if (svga->attrregs[0x10] & 0x20) { svga->scrollcache = 0; - svga->x_add = (svga->monitor->mon_overscan_x >> 1); + svga->x_add = svga->left_overscan; } } } @@ -1285,16 +1454,16 @@ svga_poll(void *priv) svga->vslines = 0; if (svga->interlace && svga->oddeven) - svga->ma = svga->maback = svga->ma_latch + (svga->rowoffset << 1) + svga->hblank_sub; + svga->memaddr = svga->memaddr_backup = svga->memaddr_latch + (svga->rowoffset << 1) + svga->hblank_sub; else - svga->ma = svga->maback = svga->ma_latch + svga->hblank_sub; + svga->memaddr = svga->memaddr_backup = svga->memaddr_latch + svga->hblank_sub; - svga->ca = ((svga->crtc[0xe] << 8) | svga->crtc[0xf]) + ((svga->crtc[0xb] & 0x60) >> 5) + svga->ca_adj; + svga->cursoraddr = ((svga->crtc[0xe] << 8) | svga->crtc[0xf]) + ((svga->crtc[0xb] & 0x60) >> 5) + svga->ca_adj; if (!(svga->adv_flags & FLAG_NO_SHIFT3)) { - svga->ma = (svga->ma << 2); - svga->maback = (svga->maback << 2); + svga->memaddr = (svga->memaddr << 2); + svga->memaddr_backup = (svga->memaddr_backup << 2); } - svga->ca = (svga->ca << 2); + svga->cursoraddr = (svga->cursoraddr << 2); if (svga->vsync_callback) svga->vsync_callback(svga); @@ -1304,7 +1473,7 @@ svga_poll(void *priv) #endif if (svga->vc == svga->vtotal) { svga->vc = 0; - svga->sc = (svga->crtc[0x8] & 0x1f); + svga->scanline = (svga->crtc[0x8] & 0x1f); svga->dispon = 1; svga->displine = (svga->interlace && svga->oddeven) ? 1 : 0; @@ -1325,7 +1494,7 @@ svga_poll(void *priv) 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; + svga->x_add = svga->left_overscan - svga->scrollcache; svga->linecountff = 0; @@ -1338,13 +1507,13 @@ svga_poll(void *priv) svga->overlay_on = 0; svga->overlay_latch = svga->overlay; } - if (svga->sc == (svga->crtc[10] & 31)) - svga->con = 1; + if (svga->scanline == (svga->crtc[10] & 31)) + svga->cursorvisible = 1; } } uint32_t -svga_conv_16to32(struct svga_t *svga, uint16_t color, uint8_t bpp) +svga_conv_16to32(UNUSED(struct svga_t *svga), uint16_t color, uint8_t bpp) { return (bpp == 15) ? video_15to32[color] : video_16to32[color]; } @@ -1375,6 +1544,7 @@ svga_init(const device_t *info, svga_t *svga, void *priv, int memsize, svga->attrregs[0x11] = 0; svga->overscan_color = 0x000000; + svga->left_overscan = 8; svga->monitor->mon_overscan_x = 16; svga->monitor->mon_overscan_y = 32; svga->x_add = 8; @@ -1403,19 +1573,44 @@ svga_init(const device_t *info, svga_t *svga, void *priv, int memsize, svga->dac_hwcursor.cur_xsize = svga->dac_hwcursor.cur_ysize = 32; svga->translate_address = NULL; + + svga->cable_connected = 1; svga->ksc5601_english_font_type = 0; - if ((info->flags & DEVICE_PCI) || (info->flags & DEVICE_VLB) || (info->flags & DEVICE_MCA)) { + /* TODO: Move DEVICE_MCA to 16-bit once the device flags have been appropriately corrected. */ + if ((info->flags & DEVICE_MCA) || (info->flags & DEVICE_MCA32) || + (info->flags & DEVICE_EISA) || (info->flags & DEVICE_AT32) || + (info->flags & DEVICE_OLB) || (info->flags & DEVICE_VLB) || + (info->flags & DEVICE_PCI) || (info->flags & DEVICE_AGP)) { + svga->read = svga_read; + svga->readw = svga_readw; + svga->readl = svga_readl; + svga->write = svga_write; + svga->writew = svga_writew; + svga->writel = svga_writel; mem_mapping_add(&svga->mapping, 0xa0000, 0x20000, svga_read, svga_readw, svga_readl, svga_write, svga_writew, svga_writel, NULL, MEM_MAPPING_EXTERNAL, svga); - } else if ((info->flags & DEVICE_ISA) && (info->flags & DEVICE_AT)) { + /* The chances of ever seeing a C-BUS (S)VGA card are approximately zero, but you never know. */ + } else if ((info->flags & DEVICE_CBUS) || (info->flags & DEVICE_ISA16)) { + svga->read = svga_read; + svga->readw = svga_readw; + svga->readl = NULL; + svga->write = svga_write; + svga->writew = svga_writew; + svga->writel = NULL; mem_mapping_add(&svga->mapping, 0xa0000, 0x20000, svga_read, svga_readw, NULL, svga_write, svga_writew, NULL, NULL, MEM_MAPPING_EXTERNAL, svga); } else { + svga->read = svga_read; + svga->readw = NULL; + svga->readl = NULL; + svga->write = svga_write; + svga->writew = NULL; + svga->writel = NULL; mem_mapping_add(&svga->mapping, 0xa0000, 0x20000, svga_read, NULL, NULL, svga_write, NULL, NULL, @@ -1523,9 +1718,7 @@ svga_write_common(uint32_t addr, uint8_t val, uint8_t linear, void *priv) addr &= ~3; addr = ((addr & 0xfffc) << 2) | ((addr & 0x30000) >> 14) | (addr & ~0x3ffff); } else if (svga->chain2_write) { - writemask2 &= ~0xa; - if (addr & 1) - writemask2 <<= 1; + writemask2 &= 0x5 << (addr & 1); addr &= ~1; addr <<= 2; } else @@ -1809,9 +2002,15 @@ svga_doblit(int wx, int wy, svga_t *svga) y_add = enable_overscan ? svga->monitor->mon_overscan_y : 0; x_add = enable_overscan ? svga->monitor->mon_overscan_x : 0; +#ifdef USE_OLD_CALCULATION 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); +#else + y_start = enable_overscan ? 0 : svga->y_add; + x_start = enable_overscan ? 0 : svga->left_overscan; + bottom = svga->monitor->mon_overscan_y - svga->y_add; +#endif if (svga->vertical_linedbl) { y_add <<= 1; @@ -2051,6 +2250,8 @@ svga_readw_common(uint32_t addr, uint8_t linear, void *priv) cycles -= svga->monitor->mon_video_timing_read_w; if (!linear) { + (void) xga_read_test(addr, svga); + (void) xga_read_test(addr + 1, svga); addr = svga_decode_addr(svga, addr, 0); if (addr == 0xffffffff) return 0xffff; @@ -2097,6 +2298,10 @@ svga_readl_common(uint32_t addr, uint8_t linear, void *priv) cycles -= svga->monitor->mon_video_timing_read_l; if (!linear) { + (void) xga_read_test(addr, svga); + (void) xga_read_test(addr + 1, svga); + (void) xga_read_test(addr + 2, svga); + (void) xga_read_test(addr + 3, svga); addr = svga_decode_addr(svga, addr, 0); if (addr == 0xffffffff) return 0xffffffff; diff --git a/src/video/vid_svga_render.c b/src/video/vid_svga_render.c index c05d308fa..5cfcc8889 100644 --- a/src/video/vid_svga_render.c +++ b/src/video/vid_svga_render.c @@ -85,18 +85,9 @@ svga_render_blank(svga_t *svga) break; } -#if 0 - pclog("svga->displine = %i, svga->y_add = %i, svga->x_add = %i\n", svga->displine, svga->y_add, svga->x_add); -#endif uint32_t *line_ptr = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; -#if 0 - pclog("svga->hdisp = %i, svga->scrollcache = %i, char_width = %i, sizeof(uint32_t) = %i\n", svga->hdisp, svga->scrollcache, char_width, sizeof(uint32_t)); -#endif uint32_t line_width = (uint32_t) (svga->hdisp + svga->scrollcache) * char_width * sizeof(uint32_t); -#if 0 - pclog("line_width = %i\n", line_width); -#endif if ((svga->hdisp + svga->scrollcache) > 0) memset(line_ptr, 0, line_width); } @@ -127,7 +118,7 @@ svga_render_overscan_right(svga_t *svga) return; uint32_t *line_ptr = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add + svga->hdisp]; - right = (overscan_x >> 1); + right = overscan_x - svga->left_overscan; for (int i = 0; i < right; i++) *line_ptr++ = svga->overscan_color; } @@ -147,6 +138,11 @@ svga_render_text_40(svga_t *svga) int bg; uint32_t addr = 0; + if (svga->render_override) { + svga->render_override(svga->priv_parent); + return; + } + if ((svga->displine + svga->y_add) < 0) return; @@ -160,13 +156,13 @@ svga_render_text_40(svga_t *svga) 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; + addr = svga->remap_func(svga, svga->memaddr) & svga->vram_display_mask; - drawcursor = ((svga->ma == svga->ca) && svga->con && svga->cursoron); + drawcursor = ((svga->memaddr == svga->cursoraddr) && svga->cursorvisible && svga->cursoron); if (svga->force_old_addr) { - chr = svga->vram[(svga->ma << 1) & svga->vram_display_mask]; - attr = svga->vram[((svga->ma << 1) + 1) & svga->vram_display_mask]; + chr = svga->vram[(svga->memaddr << 1) & svga->vram_display_mask]; + attr = svga->vram[((svga->memaddr << 1) + 1) & svga->vram_display_mask]; } else { chr = svga->vram[addr]; attr = svga->vram[addr + 1]; @@ -191,7 +187,7 @@ svga_render_text_40(svga_t *svga) } } - dat = svga->vram[charaddr + (svga->sc << 2)]; + dat = svga->vram[charaddr + (svga->scanline << 2)]; if (svga->seqregs[1] & 1) { for (xx = 0; xx < 16; xx += 2) p[xx] = p[xx + 1] = (dat & (0x80 >> (xx >> 1))) ? fg : bg; @@ -203,10 +199,10 @@ svga_render_text_40(svga_t *svga) else p[16] = p[17] = (dat & 1) ? fg : bg; } - svga->ma += 4; + svga->memaddr += 4; p += xinc; } - svga->ma &= svga->vram_display_mask; + svga->memaddr &= svga->vram_display_mask; } } @@ -225,6 +221,11 @@ svga_render_text_80(svga_t *svga) int bg; uint32_t addr = 0; + if (svga->render_override) { + svga->render_override(svga->priv_parent); + return; + } + if ((svga->displine + svga->y_add) < 0) return; @@ -238,13 +239,13 @@ svga_render_text_80(svga_t *svga) 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; + addr = svga->remap_func(svga, svga->memaddr) & svga->vram_display_mask; - drawcursor = ((svga->ma == svga->ca) && svga->con && svga->cursoron); + drawcursor = ((svga->memaddr == svga->cursoraddr) && svga->cursorvisible && svga->cursoron); if (svga->force_old_addr) { - chr = svga->vram[(svga->ma << 1) & svga->vram_display_mask]; - attr = svga->vram[((svga->ma << 1) + 1) & svga->vram_display_mask]; + chr = svga->vram[(svga->memaddr << 1) & svga->vram_display_mask]; + attr = svga->vram[((svga->memaddr << 1) + 1) & svga->vram_display_mask]; } else { chr = svga->vram[addr]; attr = svga->vram[addr + 1]; @@ -268,7 +269,7 @@ svga_render_text_80(svga_t *svga) } } - dat = svga->vram[charaddr + (svga->sc << 2)]; + dat = svga->vram[charaddr + (svga->scanline << 2)]; if (svga->seqregs[1] & 1) { for (xx = 0; xx < 8; xx++) p[xx] = (dat & (0x80 >> xx)) ? fg : bg; @@ -280,10 +281,10 @@ svga_render_text_80(svga_t *svga) else p[8] = (dat & 1) ? fg : bg; } - svga->ma += 4; + svga->memaddr += 4; p += xinc; } - svga->ma &= svga->vram_display_mask; + svga->memaddr &= svga->vram_display_mask; } } @@ -316,8 +317,8 @@ svga_render_text_80_ksc5601(svga_t *svga) xinc = (svga->seqregs[1] & 1) ? 8 : 9; 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); + uint32_t addr = svga->remap_func(svga, svga->memaddr) & svga->vram_display_mask; + drawcursor = ((svga->memaddr == svga->cursoraddr) && svga->cursorvisible && svga->cursoron); chr = svga->vram[addr]; nextchr = svga->vram[addr + 8]; attr = svga->vram[addr + 1]; @@ -337,7 +338,7 @@ svga_render_text_80_ksc5601(svga_t *svga) if ((x + xinc) < svga->hdisp && (chr & (nextchr | svga->ksc5601_sbyte_mask) & 0x80)) { if ((chr == svga->ksc5601_udc_area_msb[0] || chr == svga->ksc5601_udc_area_msb[1]) && (nextchr > 0xa0 && nextchr < 0xff)) - dat = fontdatksc5601_user[(chr == svga->ksc5601_udc_area_msb[1] ? 96 : 0) + (nextchr & 0x7F) - 0x20].chr[svga->sc]; + dat = fontdatksc5601_user[(chr == svga->ksc5601_udc_area_msb[1] ? 96 : 0) + (nextchr & 0x7F) - 0x20].chr[svga->scanline]; else if (nextchr & 0x80) { if (svga->ksc5601_swap_mode == 1 && (nextchr > 0xa0 && nextchr < 0xff)) { if (chr >= 0x80 && chr < 0x99) @@ -345,7 +346,7 @@ svga_render_text_80_ksc5601(svga_t *svga) else if (chr >= 0xB0 && chr < 0xC9) chr -= 0x30; } - dat = fontdatksc5601[((chr & 0x7F) << 7) | (nextchr & 0x7F)].chr[svga->sc]; + dat = fontdatksc5601[((chr & 0x7F) << 7) | (nextchr & 0x7F)].chr[svga->scanline]; } else dat = 0xff; } else { @@ -355,9 +356,9 @@ svga_render_text_80_ksc5601(svga_t *svga) charaddr = svga->charseta + (chr * 128); if ((svga->ksc5601_english_font_type >> 8) == 1) - dat = fontdatksc5601[((svga->ksc5601_english_font_type & 0x7F) << 7) | (chr >> 1)].chr[((chr & 1) << 4) | svga->sc]; + dat = fontdatksc5601[((svga->ksc5601_english_font_type & 0x7F) << 7) | (chr >> 1)].chr[((chr & 1) << 4) | svga->scanline]; else - dat = svga->vram[charaddr + (svga->sc << 2)]; + dat = svga->vram[charaddr + (svga->scanline << 2)]; } if (svga->seqregs[1] & 1) { @@ -371,11 +372,11 @@ svga_render_text_80_ksc5601(svga_t *svga) else p[8] = (dat & 1) ? fg : bg; } - svga->ma += 4; + svga->memaddr += 4; p += xinc; if ((x + xinc) < svga->hdisp && (chr & (nextchr | svga->ksc5601_sbyte_mask) & 0x80)) { - attr = svga->vram[((svga->ma << 1) + 1) & svga->vram_display_mask]; + attr = svga->vram[((svga->memaddr << 1) + 1) & svga->vram_display_mask]; if (drawcursor) { bg = svga->pallook[svga->egapal[attr & 15] & svga->dac_mask]; @@ -391,9 +392,9 @@ svga_render_text_80_ksc5601(svga_t *svga) } if ((chr == svga->ksc5601_udc_area_msb[0] || chr == svga->ksc5601_udc_area_msb[1]) && (nextchr > 0xa0 && nextchr < 0xff)) - dat = fontdatksc5601_user[(chr == svga->ksc5601_udc_area_msb[1] ? 96 : 0) + (nextchr & 0x7F) - 0x20].chr[svga->sc + 16]; + dat = fontdatksc5601_user[(chr == svga->ksc5601_udc_area_msb[1] ? 96 : 0) + (nextchr & 0x7F) - 0x20].chr[svga->scanline + 16]; else if (nextchr & 0x80) - dat = fontdatksc5601[((chr & 0x7f) << 7) | (nextchr & 0x7F)].chr[svga->sc + 16]; + dat = fontdatksc5601[((chr & 0x7f) << 7) | (nextchr & 0x7F)].chr[svga->scanline + 16]; else dat = 0xff; @@ -409,12 +410,12 @@ svga_render_text_80_ksc5601(svga_t *svga) p[8] = (dat & 1) ? fg : bg; } - svga->ma += 4; + svga->memaddr += 4; p += xinc; x += xinc; } } - svga->ma &= svga->vram_display_mask; + svga->memaddr &= svga->vram_display_mask; } } @@ -432,7 +433,7 @@ svga_render_2bpp_s3_lowres(svga_t *svga) return; if (svga->force_old_addr) { - changed_offset = ((svga->ma << 1) + (svga->sc & ~svga->crtc[0x17] & 3) * 0x8000) >> 12; + changed_offset = ((svga->memaddr << 1) + (svga->scanline & ~svga->crtc[0x17] & 3) * 0x8000) >> 12; if (svga->changedvram[changed_offset] || svga->changedvram[changed_offset + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; @@ -442,32 +443,32 @@ svga_render_2bpp_s3_lowres(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 16) { - addr = svga->ma; + addr = svga->memaddr; if (!(svga->crtc[0x17] & 0x40)) { addr = (addr << 1) & svga->vram_mask; addr &= ~7; - if ((svga->crtc[0x17] & 0x20) && (svga->ma & 0x20000)) + if ((svga->crtc[0x17] & 0x20) && (svga->memaddr & 0x20000)) addr |= 4; - if (!(svga->crtc[0x17] & 0x20) && (svga->ma & 0x8000)) + if (!(svga->crtc[0x17] & 0x20) && (svga->memaddr & 0x8000)) addr |= 4; } if (!(svga->crtc[0x17] & 0x01)) - addr = (addr & ~0x8000) | ((svga->sc & 1) ? 0x8000 : 0); + addr = (addr & ~0x8000) | ((svga->scanline & 1) ? 0x8000 : 0); if (!(svga->crtc[0x17] & 0x02)) - addr = (addr & ~0x10000) | ((svga->sc & 2) ? 0x10000 : 0); + addr = (addr & ~0x10000) | ((svga->scanline & 2) ? 0x10000 : 0); dat[0] = svga->vram[addr]; dat[1] = svga->vram[addr | 0x1]; if (svga->seqregs[1] & 4) - svga->ma += 2; + svga->memaddr += 2; else - svga->ma += 4; - svga->ma &= svga->vram_mask; + svga->memaddr += 4; + svga->memaddr &= svga->vram_mask; p[0] = p[1] = svga->pallook[svga->egapal[(dat[0] >> 6) & 3] & svga->dac_mask]; p[2] = p[3] = svga->pallook[svga->egapal[(dat[0] >> 4) & 3] & svga->dac_mask]; p[4] = p[5] = svga->pallook[svga->egapal[(dat[0] >> 2) & 3] & svga->dac_mask]; @@ -480,7 +481,7 @@ svga_render_2bpp_s3_lowres(svga_t *svga) } } } else { - changed_addr = svga->remap_func(svga, svga->ma); + changed_addr = svga->remap_func(svga, svga->memaddr); if (svga->changedvram[changed_addr >> 12] || svga->changedvram[(changed_addr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; @@ -490,16 +491,16 @@ svga_render_2bpp_s3_lowres(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 16) { - addr = svga->remap_func(svga, svga->ma); + addr = svga->remap_func(svga, svga->memaddr); dat[0] = svga->vram[addr]; dat[1] = svga->vram[addr | 0x1]; if (svga->seqregs[1] & 4) - svga->ma += 2; + svga->memaddr += 2; else - svga->ma += 4; + svga->memaddr += 4; - svga->ma &= svga->vram_mask; + svga->memaddr &= svga->vram_mask; p[0] = p[1] = svga->pallook[svga->egapal[(dat[0] >> 6) & 3] & svga->dac_mask]; p[2] = p[3] = svga->pallook[svga->egapal[(dat[0] >> 4) & 3] & svga->dac_mask]; @@ -530,7 +531,7 @@ svga_render_2bpp_s3_highres(svga_t *svga) return; if (svga->force_old_addr) { - changed_offset = ((svga->ma << 1) + (svga->sc & ~svga->crtc[0x17] & 3) * 0x8000) >> 12; + changed_offset = ((svga->memaddr << 1) + (svga->scanline & ~svga->crtc[0x17] & 3) * 0x8000) >> 12; if (svga->changedvram[changed_offset] || svga->changedvram[changed_offset + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; @@ -540,32 +541,32 @@ svga_render_2bpp_s3_highres(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 8) { - addr = svga->ma; + addr = svga->memaddr; if (!(svga->crtc[0x17] & 0x40)) { addr = (addr << 1) & svga->vram_mask; addr &= ~7; - if ((svga->crtc[0x17] & 0x20) && (svga->ma & 0x20000)) + if ((svga->crtc[0x17] & 0x20) && (svga->memaddr & 0x20000)) addr |= 4; - if (!(svga->crtc[0x17] & 0x20) && (svga->ma & 0x8000)) + if (!(svga->crtc[0x17] & 0x20) && (svga->memaddr & 0x8000)) addr |= 4; } if (!(svga->crtc[0x17] & 0x01)) - addr = (addr & ~0x8000) | ((svga->sc & 1) ? 0x8000 : 0); + addr = (addr & ~0x8000) | ((svga->scanline & 1) ? 0x8000 : 0); if (!(svga->crtc[0x17] & 0x02)) - addr = (addr & ~0x10000) | ((svga->sc & 2) ? 0x10000 : 0); + addr = (addr & ~0x10000) | ((svga->scanline & 2) ? 0x10000 : 0); dat[0] = svga->vram[addr]; dat[1] = svga->vram[addr | 0x1]; if (svga->seqregs[1] & 4) - svga->ma += 2; + svga->memaddr += 2; else - svga->ma += 4; - svga->ma &= svga->vram_mask; + svga->memaddr += 4; + svga->memaddr &= svga->vram_mask; p[0] = svga->pallook[svga->egapal[(dat[0] >> 6) & 3] & svga->dac_mask]; p[1] = svga->pallook[svga->egapal[(dat[0] >> 4) & 3] & svga->dac_mask]; p[2] = svga->pallook[svga->egapal[(dat[0] >> 2) & 3] & svga->dac_mask]; @@ -578,7 +579,7 @@ svga_render_2bpp_s3_highres(svga_t *svga) } } } else { - changed_addr = svga->remap_func(svga, svga->ma); + changed_addr = svga->remap_func(svga, svga->memaddr); if (svga->changedvram[changed_addr >> 12] || svga->changedvram[(changed_addr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; @@ -588,16 +589,16 @@ svga_render_2bpp_s3_highres(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 8) { - addr = svga->remap_func(svga, svga->ma); + addr = svga->remap_func(svga, svga->memaddr); dat[0] = svga->vram[addr]; dat[1] = svga->vram[addr | 0x1]; if (svga->seqregs[1] & 4) - svga->ma += 2; + svga->memaddr += 2; else - svga->ma += 4; + svga->memaddr += 4; - svga->ma &= svga->vram_mask; + svga->memaddr &= svga->vram_mask; p[0] = svga->pallook[svga->egapal[(dat[0] >> 6) & 3] & svga->dac_mask]; p[1] = svga->pallook[svga->egapal[(dat[0] >> 4) & 3] & svga->dac_mask]; @@ -627,7 +628,7 @@ svga_render_2bpp_headland_highres(svga_t *svga) if ((svga->displine + svga->y_add) < 0) return; - changed_addr = svga->remap_func(svga, svga->ma); + changed_addr = svga->remap_func(svga, svga->memaddr); if (svga->changedvram[changed_addr >> 12] || svga->changedvram[(changed_addr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; @@ -637,7 +638,7 @@ svga_render_2bpp_headland_highres(svga_t *svga) svga->lastline_draw = svga->displine; for (int x = 0; x <= (svga->hdisp + svga->scrollcache); x += 8) { - addr = svga->remap_func(svga, svga->ma); + addr = svga->remap_func(svga, svga->memaddr); oddeven = 0; if (svga->seqregs[1] & 4) { @@ -648,8 +649,8 @@ svga_render_2bpp_headland_highres(svga_t *svga) } else { *(uint32_t *) (&edat[0]) = *(uint32_t *) (&svga->vram[addr]); } - svga->ma += 4; - svga->ma &= svga->vram_mask; + svga->memaddr += 4; + svga->memaddr &= svga->vram_mask; dat = edatlookup[edat[0] >> 6][edat[1] >> 6] | (edatlookup[edat[2] >> 6][edat[3] >> 6] << 2); p[0] = svga->pallook[svga->egapal[(dat >> 4) & svga->plane_mask] & svga->dac_mask]; @@ -735,9 +736,9 @@ svga_render_indexed_gfx(svga_t *svga, bool highres, bool combine8bits) return; if (svga->force_old_addr) - changed_offset = (svga->ma + (svga->sc & ~svga->crtc[0x17] & 3) * 0x8000) >> 12; + changed_offset = (svga->memaddr + (svga->scanline & ~svga->crtc[0x17] & 3) * 0x8000) >> 12; else - changed_offset = svga->remap_func(svga, svga->ma) >> 12; + changed_offset = svga->remap_func(svga, svga->memaddr) >> 12; if (!(svga->changedvram[changed_offset] || svga->changedvram[changed_offset + 1] || svga->fullchange)) return; @@ -754,19 +755,19 @@ svga_render_indexed_gfx(svga_t *svga, bool highres, bool combine8bits) if (load_counter == 0) { /* Find our address */ if (svga->force_old_addr) { - addr = ((svga->ma & ~0x3) << incbypow2); + addr = ((svga->memaddr & ~0x3) << incbypow2); if (incbypow2 == 2) { - if (svga->ma & (4 << 15)) + if (svga->memaddr & (4 << 15)) addr |= 0x8; - if (svga->ma & (4 << 14)) + if (svga->memaddr & (4 << 14)) addr |= 0x4; } else if (incbypow2 == 1) { if ((svga->crtc[0x17] & 0x20)) { - if (svga->ma & (4 << 15)) + if (svga->memaddr & (4 << 15)) addr |= 0x4; } else { - if (svga->ma & (4 << 13)) + if (svga->memaddr & (4 << 13)) addr |= 0x4; } } else { @@ -774,13 +775,13 @@ svga_render_indexed_gfx(svga_t *svga, bool highres, bool combine8bits) } if (!(svga->crtc[0x17] & 0x01)) - addr = (addr & ~0x8000) | ((svga->sc & 1) ? 0x8000 : 0); + addr = (addr & ~0x8000) | ((svga->scanline & 1) ? 0x8000 : 0); if (!(svga->crtc[0x17] & 0x02)) - addr = (addr & ~0x10000) | ((svga->sc & 2) ? 0x10000 : 0); + addr = (addr & ~0x10000) | ((svga->scanline & 2) ? 0x10000 : 0); } else if (svga->remap_required) - addr = svga->remap_func(svga, svga->ma); + addr = svga->remap_func(svga, svga->memaddr); else - addr = svga->ma; + addr = svga->memaddr; addr &= svga->vram_display_mask; @@ -818,9 +819,9 @@ svga_render_indexed_gfx(svga_t *svga, bool highres, bool combine8bits) incr_counter += 1; if (incr_counter >= incevery) { incr_counter = 0; - svga->ma += 4; + svga->memaddr += 4; /* DISCREPANCY TODO FIXME 2/4bpp used vram_mask, 8bpp used vram_display_mask --GM */ - svga->ma &= svga->vram_display_mask; + svga->memaddr &= svga->vram_display_mask; } uint32_t current_shift = shift_values; @@ -925,7 +926,7 @@ svga_render_8bpp_clone_highres(svga_t *svga) return; if (svga->force_old_addr) { - if (svga->changedvram[svga->ma >> 12] || svga->changedvram[(svga->ma >> 12) + 1] || svga->fullchange) { + if (svga->changedvram[svga->memaddr >> 12] || svga->changedvram[(svga->memaddr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; if (svga->firstline_draw == 2000) @@ -933,25 +934,25 @@ svga_render_8bpp_clone_highres(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp /* + svga->scrollcache*/); x += 8) { - dat = *(uint32_t *) (&svga->vram[svga->ma & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[svga->memaddr & svga->vram_display_mask]); p[0] = svga->map8[dat & svga->dac_mask & 0xff]; p[1] = svga->map8[(dat >> 8) & svga->dac_mask & 0xff]; p[2] = svga->map8[(dat >> 16) & svga->dac_mask & 0xff]; p[3] = svga->map8[(dat >> 24) & svga->dac_mask & 0xff]; - dat = *(uint32_t *) (&svga->vram[(svga->ma + 4) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + 4) & svga->vram_display_mask]); p[4] = svga->map8[dat & svga->dac_mask & 0xff]; p[5] = svga->map8[(dat >> 8) & svga->dac_mask & 0xff]; p[6] = svga->map8[(dat >> 16) & svga->dac_mask & 0xff]; p[7] = svga->map8[(dat >> 24) & svga->dac_mask & 0xff]; - svga->ma += 8; + svga->memaddr += 8; p += 8; } - svga->ma &= svga->vram_display_mask; + svga->memaddr &= svga->vram_display_mask; } } else { - changed_addr = svga->remap_func(svga, svga->ma); + changed_addr = svga->remap_func(svga, svga->memaddr); if (svga->changedvram[changed_addr >> 12] || svga->changedvram[(changed_addr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; @@ -962,35 +963,35 @@ svga_render_8bpp_clone_highres(svga_t *svga) if (!svga->remap_required) { for (x = 0; x <= (svga->hdisp /* + svga->scrollcache*/); x += 8) { - dat = *(uint32_t *) (&svga->vram[svga->ma & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[svga->memaddr & svga->vram_display_mask]); p[0] = svga->map8[dat & svga->dac_mask & 0xff]; p[1] = svga->map8[(dat >> 8) & svga->dac_mask & 0xff]; p[2] = svga->map8[(dat >> 16) & svga->dac_mask & 0xff]; p[3] = svga->map8[(dat >> 24) & svga->dac_mask & 0xff]; - dat = *(uint32_t *) (&svga->vram[(svga->ma + 4) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + 4) & svga->vram_display_mask]); p[4] = svga->map8[dat & svga->dac_mask & 0xff]; p[5] = svga->map8[(dat >> 8) & svga->dac_mask & 0xff]; p[6] = svga->map8[(dat >> 16) & svga->dac_mask & 0xff]; p[7] = svga->map8[(dat >> 24) & svga->dac_mask & 0xff]; - svga->ma += 8; + svga->memaddr += 8; p += 8; } } else { for (x = 0; x <= (svga->hdisp /* + svga->scrollcache*/); x += 4) { - addr = svga->remap_func(svga, svga->ma); + addr = svga->remap_func(svga, svga->memaddr); dat = *(uint32_t *) (&svga->vram[addr & svga->vram_display_mask]); p[0] = svga->map8[dat & svga->dac_mask & 0xff]; p[1] = svga->map8[(dat >> 8) & svga->dac_mask & 0xff]; p[2] = svga->map8[(dat >> 16) & svga->dac_mask & 0xff]; p[3] = svga->map8[(dat >> 24) & svga->dac_mask & 0xff]; - svga->ma += 4; + svga->memaddr += 4; p += 4; } } - svga->ma &= svga->vram_display_mask; + svga->memaddr &= svga->vram_display_mask; } } } @@ -1010,7 +1011,7 @@ svga_render_8bpp_lowres(svga_t *svga) return; if (svga->force_old_addr) { - if (svga->changedvram[svga->ma >> 12] || svga->changedvram[(svga->ma >> 12) + 1] || svga->fullchange) { + if (svga->changedvram[svga->memaddr >> 12] || svga->changedvram[(svga->memaddr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; if (svga->firstline_draw == 2000) @@ -1018,20 +1019,20 @@ svga_render_8bpp_lowres(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 8) { - dat = *(uint32_t *) (&svga->vram[svga->ma & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[svga->memaddr & svga->vram_display_mask]); p[0] = p[1] = svga->map8[dat & 0xff]; p[2] = p[3] = svga->map8[(dat >> 8) & 0xff]; p[4] = p[5] = svga->map8[(dat >> 16) & 0xff]; p[6] = p[7] = svga->map8[(dat >> 24) & 0xff]; - svga->ma += 4; + svga->memaddr += 4; p += 8; } - svga->ma &= svga->vram_display_mask; + svga->memaddr &= svga->vram_display_mask; } } else { - changed_addr = svga->remap_func(svga, svga->ma); + changed_addr = svga->remap_func(svga, svga->memaddr); if (svga->changedvram[changed_addr >> 12] || svga->changedvram[(changed_addr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; @@ -1042,29 +1043,29 @@ svga_render_8bpp_lowres(svga_t *svga) if (!svga->remap_required) { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 8) { - dat = *(uint32_t *) (&svga->vram[svga->ma & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[svga->memaddr & svga->vram_display_mask]); p[0] = p[1] = svga->map8[dat & svga->dac_mask & 0xff]; p[2] = p[3] = svga->map8[(dat >> 8) & svga->dac_mask & 0xff]; p[4] = p[5] = svga->map8[(dat >> 16) & svga->dac_mask & 0xff]; p[6] = p[7] = svga->map8[(dat >> 24) & svga->dac_mask & 0xff]; - svga->ma += 4; + svga->memaddr += 4; p += 8; } } else { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 8) { - addr = svga->remap_func(svga, svga->ma); + addr = svga->remap_func(svga, svga->memaddr); dat = *(uint32_t *) (&svga->vram[addr & svga->vram_display_mask]); p[0] = p[1] = svga->map8[dat & svga->dac_mask & 0xff]; p[2] = p[3] = svga->map8[(dat >> 8) & svga->dac_mask & 0xff]; p[4] = p[5] = svga->map8[(dat >> 16) & svga->dac_mask & 0xff]; p[6] = p[7] = svga->map8[(dat >> 24) & svga->dac_mask & 0xff]; - svga->ma += 4; + svga->memaddr += 4; p += 8; } } - svga->ma &= svga->vram_display_mask; + svga->memaddr &= svga->vram_display_mask; } } } @@ -1082,7 +1083,7 @@ svga_render_8bpp_highres(svga_t *svga) return; if (svga->force_old_addr) { - if (svga->changedvram[svga->ma >> 12] || svga->changedvram[(svga->ma >> 12) + 1] || svga->fullchange) { + if (svga->changedvram[svga->memaddr >> 12] || svga->changedvram[(svga->memaddr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; if (svga->firstline_draw == 2000) @@ -1090,25 +1091,25 @@ svga_render_8bpp_highres(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp /* + svga->scrollcache*/); x += 8) { - dat = *(uint32_t *) (&svga->vram[svga->ma & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[svga->memaddr & svga->vram_display_mask]); p[0] = svga->map8[dat & svga->dac_mask & 0xff]; p[1] = svga->map8[(dat >> 8) & svga->dac_mask & 0xff]; p[2] = svga->map8[(dat >> 16) & svga->dac_mask & 0xff]; p[3] = svga->map8[(dat >> 24) & svga->dac_mask & 0xff]; - dat = *(uint32_t *) (&svga->vram[(svga->ma + 4) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + 4) & svga->vram_display_mask]); p[4] = svga->map8[dat & svga->dac_mask & 0xff]; p[5] = svga->map8[(dat >> 8) & svga->dac_mask & 0xff]; p[6] = svga->map8[(dat >> 16) & svga->dac_mask & 0xff]; p[7] = svga->map8[(dat >> 24) & svga->dac_mask & 0xff]; - svga->ma += 8; + svga->memaddr += 8; p += 8; } - svga->ma &= svga->vram_display_mask; + svga->memaddr &= svga->vram_display_mask; } } else { - changed_addr = svga->remap_func(svga, svga->ma); + changed_addr = svga->remap_func(svga, svga->memaddr); if (svga->changedvram[changed_addr >> 12] || svga->changedvram[(changed_addr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; @@ -1119,35 +1120,35 @@ svga_render_8bpp_highres(svga_t *svga) if (!svga->remap_required) { for (x = 0; x <= (svga->hdisp /* + svga->scrollcache*/); x += 8) { - dat = *(uint32_t *) (&svga->vram[svga->ma & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[svga->memaddr & svga->vram_display_mask]); p[0] = svga->map8[dat & svga->dac_mask & 0xff]; p[1] = svga->map8[(dat >> 8) & svga->dac_mask & 0xff]; p[2] = svga->map8[(dat >> 16) & svga->dac_mask & 0xff]; p[3] = svga->map8[(dat >> 24) & svga->dac_mask & 0xff]; - dat = *(uint32_t *) (&svga->vram[(svga->ma + 4) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + 4) & svga->vram_display_mask]); p[4] = svga->map8[dat & svga->dac_mask & 0xff]; p[5] = svga->map8[(dat >> 8) & svga->dac_mask & 0xff]; p[6] = svga->map8[(dat >> 16) & svga->dac_mask & 0xff]; p[7] = svga->map8[(dat >> 24) & svga->dac_mask & 0xff]; - svga->ma += 8; + svga->memaddr += 8; p += 8; } } else { for (x = 0; x <= (svga->hdisp /* + svga->scrollcache*/); x += 4) { - addr = svga->remap_func(svga, svga->ma); + addr = svga->remap_func(svga, svga->memaddr); dat = *(uint32_t *) (&svga->vram[addr & svga->vram_display_mask]); p[0] = svga->map8[dat & svga->dac_mask & 0xff]; p[1] = svga->map8[(dat >> 8) & svga->dac_mask & 0xff]; p[2] = svga->map8[(dat >> 16) & svga->dac_mask & 0xff]; p[3] = svga->map8[(dat >> 24) & svga->dac_mask & 0xff]; - svga->ma += 4; + svga->memaddr += 4; p += 4; } } - svga->ma &= svga->vram_display_mask; + svga->memaddr &= svga->vram_display_mask; } } } @@ -1162,7 +1163,7 @@ svga_render_8bpp_tseng_lowres(svga_t *svga) if ((svga->displine + svga->y_add) < 0) return; - if (svga->changedvram[svga->ma >> 12] || svga->changedvram[(svga->ma >> 12) + 1] || svga->fullchange) { + if (svga->changedvram[svga->memaddr >> 12] || svga->changedvram[(svga->memaddr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; if (svga->firstline_draw == 2000) @@ -1170,7 +1171,7 @@ svga_render_8bpp_tseng_lowres(svga_t *svga) svga->lastline_draw = svga->displine; for (int x = 0; x <= (svga->hdisp + svga->scrollcache); x += 8) { - dat = *(uint32_t *) (&svga->vram[svga->ma & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[svga->memaddr & svga->vram_display_mask]); if (svga->attrregs[0x10] & 0x80) dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); p[0] = p[1] = svga->map8[dat & svga->dac_mask & 0xff]; @@ -1187,10 +1188,10 @@ svga_render_8bpp_tseng_lowres(svga_t *svga) dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); p[6] = p[7] = svga->map8[dat & svga->dac_mask & 0xff]; - svga->ma += 4; + svga->memaddr += 4; p += 8; } - svga->ma &= svga->vram_display_mask; + svga->memaddr &= svga->vram_display_mask; } } @@ -1203,7 +1204,7 @@ svga_render_8bpp_tseng_highres(svga_t *svga) if ((svga->displine + svga->y_add) < 0) return; - if (svga->changedvram[svga->ma >> 12] || svga->changedvram[(svga->ma >> 12) + 1] || svga->fullchange) { + if (svga->changedvram[svga->memaddr >> 12] || svga->changedvram[(svga->memaddr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; if (svga->firstline_draw == 2000) @@ -1211,7 +1212,7 @@ svga_render_8bpp_tseng_highres(svga_t *svga) svga->lastline_draw = svga->displine; for (int x = 0; x <= (svga->hdisp /* + svga->scrollcache*/); x += 8) { - dat = *(uint32_t *) (&svga->vram[svga->ma & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[svga->memaddr & svga->vram_display_mask]); if (svga->attrregs[0x10] & 0x80) dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); p[0] = svga->map8[dat & svga->dac_mask & 0xff]; @@ -1228,7 +1229,7 @@ svga_render_8bpp_tseng_highres(svga_t *svga) dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); p[3] = svga->map8[dat & svga->dac_mask & 0xff]; - dat = *(uint32_t *) (&svga->vram[(svga->ma + 4) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + 4) & svga->vram_display_mask]); if (svga->attrregs[0x10] & 0x80) dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); p[4] = svga->map8[dat & svga->dac_mask & 0xff]; @@ -1245,10 +1246,10 @@ svga_render_8bpp_tseng_highres(svga_t *svga) dat = (dat & ~0xf0) | ((svga->attrregs[0x14] & 0x0f) << 4); p[7] = svga->map8[dat & svga->dac_mask & 0xff]; - svga->ma += 8; + svga->memaddr += 8; p += 8; } - svga->ma &= svga->vram_display_mask; + svga->memaddr &= svga->vram_display_mask; } } @@ -1265,7 +1266,7 @@ svga_render_15bpp_lowres(svga_t *svga) return; if (svga->force_old_addr) { - if (svga->changedvram[svga->ma >> 12] || svga->changedvram[(svga->ma >> 12) + 1] || svga->fullchange) { + if (svga->changedvram[svga->memaddr >> 12] || svga->changedvram[(svga->memaddr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; if (svga->firstline_draw == 2000) @@ -1273,21 +1274,21 @@ svga_render_15bpp_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]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1)) & svga->vram_display_mask]); p[x << 1] = p[(x << 1) + 1] = svga->conv_16to32(svga, dat & 0xffff, 15); p[(x << 1) + 2] = p[(x << 1) + 3] = svga->conv_16to32(svga, dat >> 16, 15); - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1) + 4) & svga->vram_display_mask]); p[(x << 1) + 4] = p[(x << 1) + 5] = svga->conv_16to32(svga, dat & 0xffff, 15); p[(x << 1) + 6] = p[(x << 1) + 7] = svga->conv_16to32(svga, dat >> 16, 15); } - svga->ma += x << 1; - svga->ma &= svga->vram_display_mask; + svga->memaddr += x << 1; + svga->memaddr &= svga->vram_display_mask; } } else { - changed_addr = svga->remap_func(svga, svga->ma); + changed_addr = svga->remap_func(svga, svga->memaddr); if (svga->changedvram[changed_addr >> 12] || svga->changedvram[(changed_addr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; @@ -1298,28 +1299,28 @@ svga_render_15bpp_lowres(svga_t *svga) if (!svga->remap_required) { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 4) { - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1)) & svga->vram_display_mask]); *p++ = svga->conv_16to32(svga, dat & 0xffff, 15); *p++ = svga->conv_16to32(svga, dat >> 16, 15); - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1) + 4) & svga->vram_display_mask]); *p++ = svga->conv_16to32(svga, dat & 0xffff, 15); *p++ = svga->conv_16to32(svga, dat >> 16, 15); } - svga->ma += x << 1; + svga->memaddr += x << 1; } else { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 2) { - addr = svga->remap_func(svga, svga->ma); + addr = svga->remap_func(svga, svga->memaddr); dat = *(uint32_t *) (&svga->vram[addr & svga->vram_display_mask]); *p++ = svga->conv_16to32(svga, dat & 0xffff, 15); *p++ = svga->conv_16to32(svga, dat >> 16, 15); - svga->ma += 4; + svga->memaddr += 4; } } - svga->ma &= svga->vram_display_mask; + svga->memaddr &= svga->vram_display_mask; } } } @@ -1337,7 +1338,7 @@ svga_render_15bpp_highres(svga_t *svga) return; if (svga->force_old_addr) { - if (svga->changedvram[svga->ma >> 12] || svga->changedvram[(svga->ma >> 12) + 1] || svga->fullchange) { + if (svga->changedvram[svga->memaddr >> 12] || svga->changedvram[(svga->memaddr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; if (svga->firstline_draw == 2000) @@ -1345,27 +1346,27 @@ svga_render_15bpp_highres(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 8) { - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1)) & svga->vram_display_mask]); p[x] = svga->conv_16to32(svga, dat & 0xffff, 15); p[x + 1] = svga->conv_16to32(svga, dat >> 16, 15); - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1) + 4) & svga->vram_display_mask]); p[x + 2] = svga->conv_16to32(svga, dat & 0xffff, 15); p[x + 3] = svga->conv_16to32(svga, dat >> 16, 15); - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1) + 8) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1) + 8) & svga->vram_display_mask]); p[x + 4] = svga->conv_16to32(svga, dat & 0xffff, 15); p[x + 5] = svga->conv_16to32(svga, dat >> 16, 15); - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1) + 12) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1) + 12) & svga->vram_display_mask]); p[x + 6] = svga->conv_16to32(svga, dat & 0xffff, 15); p[x + 7] = svga->conv_16to32(svga, dat >> 16, 15); } - svga->ma += x << 1; - svga->ma &= svga->vram_display_mask; + svga->memaddr += x << 1; + svga->memaddr &= svga->vram_display_mask; } } else { - changed_addr = svga->remap_func(svga, svga->ma); + changed_addr = svga->remap_func(svga, svga->memaddr); if (svga->changedvram[changed_addr >> 12] || svga->changedvram[(changed_addr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; @@ -1376,34 +1377,34 @@ svga_render_15bpp_highres(svga_t *svga) if (!svga->remap_required) { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 8) { - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1)) & svga->vram_display_mask]); *p++ = svga->conv_16to32(svga, dat & 0xffff, 15); *p++ = svga->conv_16to32(svga, dat >> 16, 15); - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1) + 4) & svga->vram_display_mask]); *p++ = svga->conv_16to32(svga, dat & 0xffff, 15); *p++ = svga->conv_16to32(svga, dat >> 16, 15); - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1) + 8) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1) + 8) & svga->vram_display_mask]); *p++ = svga->conv_16to32(svga, dat & 0xffff, 15); *p++ = svga->conv_16to32(svga, dat >> 16, 15); - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1) + 12) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1) + 12) & svga->vram_display_mask]); *p++ = svga->conv_16to32(svga, dat & 0xffff, 15); *p++ = svga->conv_16to32(svga, dat >> 16, 15); } - svga->ma += x << 1; + svga->memaddr += x << 1; } else { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 2) { - addr = svga->remap_func(svga, svga->ma); + addr = svga->remap_func(svga, svga->memaddr); dat = *(uint32_t *) (&svga->vram[addr & svga->vram_display_mask]); *p++ = svga->conv_16to32(svga, dat & 0xffff, 15); *p++ = svga->conv_16to32(svga, dat >> 16, 15); - svga->ma += 4; + svga->memaddr += 4; } } - svga->ma &= svga->vram_display_mask; + svga->memaddr &= svga->vram_display_mask; } } } @@ -1418,7 +1419,7 @@ svga_render_15bpp_mix_lowres(svga_t *svga) if ((svga->displine + svga->y_add) < 0) return; - if (svga->changedvram[svga->ma >> 12] || svga->changedvram[(svga->ma >> 12) + 1] || svga->fullchange) { + if (svga->changedvram[svga->memaddr >> 12] || svga->changedvram[(svga->memaddr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; if (svga->firstline_draw == 2000) @@ -1426,20 +1427,20 @@ 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]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1)) & svga->vram_display_mask]); p[x << 1] = p[(x << 1) + 1] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : svga->conv_16to32(svga, dat & 0xffff, 15); dat >>= 16; p[(x << 1) + 2] = p[(x << 1) + 3] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : svga->conv_16to32(svga, dat & 0xffff, 15); - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1) + 4) & svga->vram_display_mask]); p[(x << 1) + 4] = p[(x << 1) + 5] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : svga->conv_16to32(svga, dat & 0xffff, 15); dat >>= 16; p[(x << 1) + 6] = p[(x << 1) + 7] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : svga->conv_16to32(svga, dat & 0xffff, 15); } - svga->ma += x << 1; - svga->ma &= svga->vram_display_mask; + svga->memaddr += x << 1; + svga->memaddr &= svga->vram_display_mask; } } @@ -1453,7 +1454,7 @@ svga_render_15bpp_mix_highres(svga_t *svga) if ((svga->displine + svga->y_add) < 0) return; - if (svga->changedvram[svga->ma >> 12] || svga->changedvram[(svga->ma >> 12) + 1] || svga->fullchange) { + if (svga->changedvram[svga->memaddr >> 12] || svga->changedvram[(svga->memaddr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; if (svga->firstline_draw == 2000) @@ -1461,28 +1462,28 @@ svga_render_15bpp_mix_highres(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 8) { - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1)) & svga->vram_display_mask]); p[x] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : svga->conv_16to32(svga, dat & 0xffff, 15); dat >>= 16; p[x + 1] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : svga->conv_16to32(svga, dat & 0xffff, 15); - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1) + 4) & svga->vram_display_mask]); p[x + 2] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : svga->conv_16to32(svga, dat & 0xffff, 15); dat >>= 16; p[x + 3] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : svga->conv_16to32(svga, dat & 0xffff, 15); - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1) + 8) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1) + 8) & svga->vram_display_mask]); p[x + 4] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : svga->conv_16to32(svga, dat & 0xffff, 15); dat >>= 16; p[x + 5] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : svga->conv_16to32(svga, dat & 0xffff, 15); - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1) + 12) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1) + 12) & svga->vram_display_mask]); p[x + 6] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : svga->conv_16to32(svga, dat & 0xffff, 15); dat >>= 16; p[x + 7] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : svga->conv_16to32(svga, dat & 0xffff, 15); } - svga->ma += x << 1; - svga->ma &= svga->vram_display_mask; + svga->memaddr += x << 1; + svga->memaddr &= svga->vram_display_mask; } } @@ -1499,7 +1500,7 @@ svga_render_16bpp_lowres(svga_t *svga) return; if (svga->force_old_addr) { - if (svga->changedvram[svga->ma >> 12] || svga->changedvram[(svga->ma >> 12) + 1] || svga->fullchange) { + if (svga->changedvram[svga->memaddr >> 12] || svga->changedvram[(svga->memaddr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; if (svga->firstline_draw == 2000) @@ -1507,19 +1508,19 @@ 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]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1)) & svga->vram_display_mask]); p[x << 1] = p[(x << 1) + 1] = svga->conv_16to32(svga, dat & 0xffff, 16); p[(x << 1) + 2] = p[(x << 1) + 3] = svga->conv_16to32(svga, dat >> 16, 16); - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1) + 4) & svga->vram_display_mask]); p[(x << 1) + 4] = p[(x << 1) + 5] = svga->conv_16to32(svga, dat & 0xffff, 16); p[(x << 1) + 6] = p[(x << 1) + 7] = svga->conv_16to32(svga, dat >> 16, 16); } - svga->ma += x << 1; - svga->ma &= svga->vram_display_mask; + svga->memaddr += x << 1; + svga->memaddr &= svga->vram_display_mask; } } else { - changed_addr = svga->remap_func(svga, svga->ma); + changed_addr = svga->remap_func(svga, svga->memaddr); if (svga->changedvram[changed_addr >> 12] || svga->changedvram[(changed_addr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; @@ -1530,28 +1531,28 @@ svga_render_16bpp_lowres(svga_t *svga) if (!svga->remap_required) { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 4) { - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1)) & svga->vram_display_mask]); *p++ = svga->conv_16to32(svga, dat & 0xffff, 16); *p++ = svga->conv_16to32(svga, dat >> 16, 16); - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1) + 4) & svga->vram_display_mask]); *p++ = svga->conv_16to32(svga, dat & 0xffff, 16); *p++ = svga->conv_16to32(svga, dat >> 16, 16); } - svga->ma += x << 1; + svga->memaddr += x << 1; } else { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 2) { - addr = svga->remap_func(svga, svga->ma); + addr = svga->remap_func(svga, svga->memaddr); dat = *(uint32_t *) (&svga->vram[addr & svga->vram_display_mask]); *p++ = svga->conv_16to32(svga, dat & 0xffff, 16); *p++ = svga->conv_16to32(svga, dat >> 16, 16); } - svga->ma += 4; + svga->memaddr += 4; } - svga->ma &= svga->vram_display_mask; + svga->memaddr &= svga->vram_display_mask; } } } @@ -1569,7 +1570,7 @@ svga_render_16bpp_highres(svga_t *svga) return; if (svga->force_old_addr) { - if (svga->changedvram[svga->ma >> 12] || svga->changedvram[(svga->ma >> 12) + 1] || svga->fullchange) { + if (svga->changedvram[svga->memaddr >> 12] || svga->changedvram[(svga->memaddr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; if (svga->firstline_draw == 2000) @@ -1577,27 +1578,27 @@ svga_render_16bpp_highres(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 8) { - uint32_t dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); + uint32_t dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1)) & svga->vram_display_mask]); p[x] = svga->conv_16to32(svga, dat & 0xffff, 16); p[x + 1] = svga->conv_16to32(svga, dat >> 16, 16); - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1) + 4) & svga->vram_display_mask]); p[x + 2] = svga->conv_16to32(svga, dat & 0xffff, 16); p[x + 3] = svga->conv_16to32(svga, dat >> 16, 16); - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1) + 8) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1) + 8) & svga->vram_display_mask]); p[x + 4] = svga->conv_16to32(svga, dat & 0xffff, 16); p[x + 5] = svga->conv_16to32(svga, dat >> 16, 16); - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1) + 12) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1) + 12) & svga->vram_display_mask]); p[x + 6] = svga->conv_16to32(svga, dat & 0xffff, 16); p[x + 7] = svga->conv_16to32(svga, dat >> 16, 16); } - svga->ma += x << 1; - svga->ma &= svga->vram_display_mask; + svga->memaddr += x << 1; + svga->memaddr &= svga->vram_display_mask; } } else { - changed_addr = svga->remap_func(svga, svga->ma); + changed_addr = svga->remap_func(svga, svga->memaddr); if (svga->changedvram[changed_addr >> 12] || svga->changedvram[(changed_addr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; @@ -1608,35 +1609,35 @@ svga_render_16bpp_highres(svga_t *svga) if (!svga->remap_required) { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 8) { - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1)) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1)) & svga->vram_display_mask]); *p++ = svga->conv_16to32(svga, dat & 0xffff, 16); *p++ = svga->conv_16to32(svga, dat >> 16, 16); - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1) + 4) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1) + 4) & svga->vram_display_mask]); *p++ = svga->conv_16to32(svga, dat & 0xffff, 16); *p++ = svga->conv_16to32(svga, dat >> 16, 16); - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1) + 8) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1) + 8) & svga->vram_display_mask]); *p++ = svga->conv_16to32(svga, dat & 0xffff, 16); *p++ = svga->conv_16to32(svga, dat >> 16, 16); - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 1) + 12) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 1) + 12) & svga->vram_display_mask]); *p++ = svga->conv_16to32(svga, dat & 0xffff, 16); *p++ = svga->conv_16to32(svga, dat >> 16, 16); } - svga->ma += x << 1; + svga->memaddr += x << 1; } else { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 2) { - addr = svga->remap_func(svga, svga->ma); + addr = svga->remap_func(svga, svga->memaddr); dat = *(uint32_t *) (&svga->vram[addr & svga->vram_display_mask]); *p++ = svga->conv_16to32(svga, dat & 0xffff, 16); *p++ = svga->conv_16to32(svga, dat >> 16, 16); - svga->ma += 4; + svga->memaddr += 4; } } - svga->ma &= svga->vram_display_mask; + svga->memaddr &= svga->vram_display_mask; } } } @@ -1660,20 +1661,20 @@ svga_render_24bpp_lowres(svga_t *svga) if ((svga->displine + svga->y_add) < 0) return; - if (svga->changedvram[svga->ma >> 12] || svga->changedvram[(svga->ma >> 12) + 1] || svga->fullchange) { + if (svga->changedvram[svga->memaddr >> 12] || svga->changedvram[(svga->memaddr >> 12) + 1] || svga->fullchange) { if (svga->firstline_draw == 2000) svga->firstline_draw = svga->displine; svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - fg = svga->vram[svga->ma] | (svga->vram[svga->ma + 1] << 8) | (svga->vram[svga->ma + 2] << 16); - svga->ma += 3; - svga->ma &= svga->vram_display_mask; + fg = svga->vram[svga->memaddr] | (svga->vram[svga->memaddr + 1] << 8) | (svga->vram[svga->memaddr + 2] << 16); + svga->memaddr += 3; + svga->memaddr &= svga->vram_display_mask; svga->monitor->target_buffer->line[svga->displine + svga->y_add][(x << 1) + svga->x_add] = svga->monitor->target_buffer->line[svga->displine + svga->y_add][(x << 1) + 1 + svga->x_add] = lookup_lut(fg); } } } else { - changed_addr = svga->remap_func(svga, svga->ma); + changed_addr = svga->remap_func(svga, svga->memaddr); if (svga->changedvram[changed_addr >> 12] || svga->changedvram[(changed_addr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; @@ -1684,24 +1685,24 @@ svga_render_24bpp_lowres(svga_t *svga) if (!svga->remap_required) { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - dat0 = *(uint32_t *) (&svga->vram[svga->ma & svga->vram_display_mask]); - dat1 = *(uint32_t *) (&svga->vram[(svga->ma + 4) & svga->vram_display_mask]); - dat2 = *(uint32_t *) (&svga->vram[(svga->ma + 8) & svga->vram_display_mask]); + dat0 = *(uint32_t *) (&svga->vram[svga->memaddr & svga->vram_display_mask]); + dat1 = *(uint32_t *) (&svga->vram[(svga->memaddr + 4) & svga->vram_display_mask]); + dat2 = *(uint32_t *) (&svga->vram[(svga->memaddr + 8) & svga->vram_display_mask]); p[0] = p[1] = lookup_lut(dat0 & 0xffffff); p[2] = p[3] = lookup_lut((dat0 >> 24) | ((dat1 & 0xffff) << 8)); p[4] = p[5] = lookup_lut((dat1 >> 16) | ((dat2 & 0xff) << 16)); p[6] = p[7] = lookup_lut(dat2 >> 8); - svga->ma += 12; + svga->memaddr += 12; } } else { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 4) { - addr = svga->remap_func(svga, svga->ma); + addr = svga->remap_func(svga, svga->memaddr); dat0 = *(uint32_t *) (&svga->vram[addr & svga->vram_display_mask]); - addr = svga->remap_func(svga, svga->ma + 4); + addr = svga->remap_func(svga, svga->memaddr + 4); dat1 = *(uint32_t *) (&svga->vram[addr & svga->vram_display_mask]); - addr = svga->remap_func(svga, svga->ma + 8); + addr = svga->remap_func(svga, svga->memaddr + 8); dat2 = *(uint32_t *) (&svga->vram[addr & svga->vram_display_mask]); p[0] = p[1] = lookup_lut(dat0 & 0xffffff); @@ -1709,10 +1710,10 @@ svga_render_24bpp_lowres(svga_t *svga) p[4] = p[5] = lookup_lut((dat1 >> 16) | ((dat2 & 0xff) << 16)); p[6] = p[7] = lookup_lut(dat2 >> 8); - svga->ma += 12; + svga->memaddr += 12; } } - svga->ma &= svga->vram_display_mask; + svga->memaddr &= svga->vram_display_mask; } } } @@ -1733,7 +1734,7 @@ svga_render_24bpp_highres(svga_t *svga) return; if (svga->force_old_addr) { - if (svga->changedvram[svga->ma >> 12] || svga->changedvram[(svga->ma >> 12) + 1] || svga->fullchange) { + if (svga->changedvram[svga->memaddr >> 12] || svga->changedvram[(svga->memaddr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; if (svga->firstline_draw == 2000) @@ -1741,24 +1742,24 @@ svga_render_24bpp_highres(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 & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[svga->memaddr & svga->vram_display_mask]); p[x] = lookup_lut(dat & 0xffffff); - dat = *(uint32_t *) (&svga->vram[(svga->ma + 3) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + 3) & svga->vram_display_mask]); p[x + 1] = lookup_lut(dat & 0xffffff); - dat = *(uint32_t *) (&svga->vram[(svga->ma + 6) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + 6) & svga->vram_display_mask]); p[x + 2] = lookup_lut(dat & 0xffffff); - dat = *(uint32_t *) (&svga->vram[(svga->ma + 9) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + 9) & svga->vram_display_mask]); p[x + 3] = lookup_lut(dat & 0xffffff); - svga->ma += 12; + svga->memaddr += 12; } - svga->ma &= svga->vram_display_mask; + svga->memaddr &= svga->vram_display_mask; } } else { - changed_addr = svga->remap_func(svga, svga->ma); + changed_addr = svga->remap_func(svga, svga->memaddr); if (svga->changedvram[changed_addr >> 12] || svga->changedvram[(changed_addr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; @@ -1769,24 +1770,24 @@ svga_render_24bpp_highres(svga_t *svga) if (!svga->remap_required) { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 4) { - dat0 = *(uint32_t *) (&svga->vram[svga->ma & svga->vram_display_mask]); - dat1 = *(uint32_t *) (&svga->vram[(svga->ma + 4) & svga->vram_display_mask]); - dat2 = *(uint32_t *) (&svga->vram[(svga->ma + 8) & svga->vram_display_mask]); + dat0 = *(uint32_t *) (&svga->vram[svga->memaddr & svga->vram_display_mask]); + dat1 = *(uint32_t *) (&svga->vram[(svga->memaddr + 4) & svga->vram_display_mask]); + dat2 = *(uint32_t *) (&svga->vram[(svga->memaddr + 8) & svga->vram_display_mask]); *p++ = lookup_lut(dat0 & 0xffffff); *p++ = lookup_lut((dat0 >> 24) | ((dat1 & 0xffff) << 8)); *p++ = lookup_lut((dat1 >> 16) | ((dat2 & 0xff) << 16)); *p++ = lookup_lut(dat2 >> 8); - svga->ma += 12; + svga->memaddr += 12; } } else { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x += 4) { - addr = svga->remap_func(svga, svga->ma); + addr = svga->remap_func(svga, svga->memaddr); dat0 = *(uint32_t *) (&svga->vram[addr & svga->vram_display_mask]); - addr = svga->remap_func(svga, svga->ma + 4); + addr = svga->remap_func(svga, svga->memaddr + 4); dat1 = *(uint32_t *) (&svga->vram[addr & svga->vram_display_mask]); - addr = svga->remap_func(svga, svga->ma + 8); + addr = svga->remap_func(svga, svga->memaddr + 8); dat2 = *(uint32_t *) (&svga->vram[addr & svga->vram_display_mask]); *p++ = lookup_lut(dat0 & 0xffffff); @@ -1794,10 +1795,10 @@ svga_render_24bpp_highres(svga_t *svga) *p++ = lookup_lut((dat1 >> 16) | ((dat2 & 0xff) << 16)); *p++ = lookup_lut(dat2 >> 8); - svga->ma += 12; + svga->memaddr += 12; } } - svga->ma &= svga->vram_display_mask; + svga->memaddr &= svga->vram_display_mask; } } } @@ -1815,20 +1816,20 @@ svga_render_32bpp_lowres(svga_t *svga) return; if (svga->force_old_addr) { - if (svga->changedvram[svga->ma >> 12] || svga->changedvram[(svga->ma >> 12) + 1] || svga->fullchange) { + if (svga->changedvram[svga->memaddr >> 12] || svga->changedvram[(svga->memaddr >> 12) + 1] || svga->fullchange) { if (svga->firstline_draw == 2000) svga->firstline_draw = svga->displine; svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - dat = svga->vram[svga->ma] | (svga->vram[svga->ma + 1] << 8) | (svga->vram[svga->ma + 2] << 16); - svga->ma += 4; - svga->ma &= svga->vram_display_mask; + dat = svga->vram[svga->memaddr] | (svga->vram[svga->memaddr + 1] << 8) | (svga->vram[svga->memaddr + 2] << 16); + svga->memaddr += 4; + svga->memaddr &= svga->vram_display_mask; svga->monitor->target_buffer->line[svga->displine + svga->y_add][(x << 1) + svga->x_add] = svga->monitor->target_buffer->line[svga->displine + svga->y_add][(x << 1) + 1 + svga->x_add] = lookup_lut(dat); } } } else { - changed_addr = svga->remap_func(svga, svga->ma); + changed_addr = svga->remap_func(svga, svga->memaddr); if (svga->changedvram[changed_addr >> 12] || svga->changedvram[(changed_addr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; @@ -1839,20 +1840,20 @@ svga_render_32bpp_lowres(svga_t *svga) if (!svga->remap_required) { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 2)) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 2)) & svga->vram_display_mask]); *p++ = lookup_lut(dat & 0xffffff); *p++ = lookup_lut(dat & 0xffffff); } - svga->ma += (x * 4); + svga->memaddr += (x * 4); } else { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - addr = svga->remap_func(svga, svga->ma); + addr = svga->remap_func(svga, svga->memaddr); dat = *(uint32_t *) (&svga->vram[addr & svga->vram_display_mask]); *p++ = lookup_lut(dat & 0xffffff); *p++ = lookup_lut(dat & 0xffffff); - svga->ma += 4; + svga->memaddr += 4; } - svga->ma &= svga->vram_display_mask; + svga->memaddr &= svga->vram_display_mask; } } } @@ -1871,7 +1872,7 @@ svga_render_32bpp_highres(svga_t *svga) return; if (svga->force_old_addr) { - if (svga->changedvram[svga->ma >> 12] || svga->changedvram[(svga->ma >> 12) + 1] || svga->changedvram[(svga->ma >> 12) + 2] || svga->fullchange) { + if (svga->changedvram[svga->memaddr >> 12] || svga->changedvram[(svga->memaddr >> 12) + 1] || svga->changedvram[(svga->memaddr >> 12) + 2] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; if (svga->firstline_draw == 2000) @@ -1879,14 +1880,14 @@ svga_render_32bpp_highres(svga_t *svga) svga->lastline_draw = svga->displine; for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 2)) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 2)) & svga->vram_display_mask]); p[x] = lookup_lut(dat & 0xffffff); } - svga->ma += 4; - svga->ma &= svga->vram_display_mask; + svga->memaddr += 4; + svga->memaddr &= svga->vram_display_mask; } } else { - changed_addr = svga->remap_func(svga, svga->ma); + changed_addr = svga->remap_func(svga, svga->memaddr); if (svga->changedvram[changed_addr >> 12] || svga->changedvram[(changed_addr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; @@ -1897,20 +1898,20 @@ svga_render_32bpp_highres(svga_t *svga) if (!svga->remap_required) { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 2)) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 2)) & svga->vram_display_mask]); *p++ = lookup_lut(dat & 0xffffff); } - svga->ma += (x * 4); + svga->memaddr += (x * 4); } else { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - addr = svga->remap_func(svga, svga->ma); + addr = svga->remap_func(svga, svga->memaddr); dat = *(uint32_t *) (&svga->vram[addr & svga->vram_display_mask]); *p++ = lookup_lut(dat & 0xffffff); - svga->ma += 4; + svga->memaddr += 4; } } - svga->ma &= svga->vram_display_mask; + svga->memaddr &= svga->vram_display_mask; } } } @@ -1927,7 +1928,7 @@ svga_render_ABGR8888_highres(svga_t *svga) if ((svga->displine + svga->y_add) < 0) return; - changed_addr = svga->remap_func(svga, svga->ma); + changed_addr = svga->remap_func(svga, svga->memaddr); if (svga->changedvram[changed_addr >> 12] || svga->changedvram[(changed_addr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; @@ -1938,20 +1939,20 @@ svga_render_ABGR8888_highres(svga_t *svga) if (!svga->remap_required) { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 2)) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 2)) & svga->vram_display_mask]); *p++ = lookup_lut(((dat & 0xff0000) >> 16) | (dat & 0x00ff00) | ((dat & 0x0000ff) << 16)); } - svga->ma += x * 4; + svga->memaddr += x * 4; } else { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - addr = svga->remap_func(svga, svga->ma); + addr = svga->remap_func(svga, svga->memaddr); dat = *(uint32_t *) (&svga->vram[addr & svga->vram_display_mask]); *p++ = lookup_lut(((dat & 0xff0000) >> 16) | (dat & 0x00ff00) | ((dat & 0x0000ff) << 16)); - svga->ma += 4; + svga->memaddr += 4; } } - svga->ma &= svga->vram_display_mask; + svga->memaddr &= svga->vram_display_mask; } } @@ -1967,7 +1968,7 @@ svga_render_RGBA8888_highres(svga_t *svga) if ((svga->displine + svga->y_add) < 0) return; - changed_addr = svga->remap_func(svga, svga->ma); + changed_addr = svga->remap_func(svga, svga->memaddr); if (svga->changedvram[changed_addr >> 12] || svga->changedvram[(changed_addr >> 12) + 1] || svga->fullchange) { p = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; @@ -1978,19 +1979,19 @@ svga_render_RGBA8888_highres(svga_t *svga) if (!svga->remap_required) { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - dat = *(uint32_t *) (&svga->vram[(svga->ma + (x << 2)) & svga->vram_display_mask]); + dat = *(uint32_t *) (&svga->vram[(svga->memaddr + (x << 2)) & svga->vram_display_mask]); *p++ = lookup_lut(dat >> 8); } - svga->ma += (x * 4); + svga->memaddr += (x * 4); } else { for (x = 0; x <= (svga->hdisp + svga->scrollcache); x++) { - addr = svga->remap_func(svga, svga->ma); + addr = svga->remap_func(svga, svga->memaddr); dat = *(uint32_t *) (&svga->vram[addr & svga->vram_display_mask]); *p++ = lookup_lut(dat >> 8); - svga->ma += 4; + svga->memaddr += 4; } } - svga->ma &= svga->vram_display_mask; + svga->memaddr &= svga->vram_display_mask; } } diff --git a/src/video/vid_table.c b/src/video/vid_table.c index 859712357..b97defe8c 100644 --- a/src/video/vid_table.c +++ b/src/video/vid_table.c @@ -50,206 +50,216 @@ static int was_reset = 0; static const VIDEO_CARD video_cards[] = { // clang-format off - { &device_none }, - { &device_internal }, - { &atiega800p_device }, - { &mach8_vga_isa_device, VIDEO_FLAG_TYPE_8514 }, - { &mach32_isa_device, VIDEO_FLAG_TYPE_8514 }, - { &mach64gx_isa_device }, - { &ati28800k_device }, - { &ati18800_vga88_device }, - { &ati28800_device }, - { &compaq_ati28800_device }, - { &ati28800_wonder1024d_xl_plus_device }, + { .device = &device_none, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &device_internal, .flags = VIDEO_FLAG_TYPE_NONE }, + /* ISA */ + { .device = &atiega800p_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &mach8_vga_isa_device, .flags = VIDEO_FLAG_TYPE_8514 }, + { .device = &mach32_isa_device, .flags = VIDEO_FLAG_TYPE_8514 }, + { .device = &ati28800k_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &ati18800_vga88_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &ati28800_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &compaq_ati28800_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &ati28800_wonder1024d_xl_plus_device, .flags = VIDEO_FLAG_TYPE_NONE }, #ifdef USE_XL24 - { &ati28800_wonderxl24_device }, + { .device = &ati28800_wonderxl24_device, .flags = VIDEO_FLAG_TYPE_NONE }, #endif /* USE_XL24 */ - { &ati18800_device }, - { &ati18800_wonder_device }, - { &cga_device }, - { &sega_device }, - { &gd5401_isa_device }, - { &gd5402_isa_device }, - { &gd5420_isa_device }, - { &gd5422_isa_device }, - { &gd5426_isa_device }, - { &gd5426_diamond_speedstar_pro_a1_isa_device }, - { &gd5428_boca_isa_device }, - { &gd5428_isa_device }, - { &gd5429_isa_device }, - { &gd5434_isa_device }, - { &gd5434_diamond_speedstar_64_a3_isa_device }, - { &compaq_cga_device }, - { &compaq_cga_2_device }, - { &cpqega_device }, - { &ega_device }, - { &g2_gc205_device }, - { &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 }, - { &mda_device, VIDEO_FLAG_TYPE_MDA }, - { &genius_device }, - { &nga_device }, - { &ogc_device }, - { &oti037c_device }, - { &oti067_device }, - { &oti077_device }, - { ¶dise_pvga1a_device }, - { ¶dise_wd90c11_device }, - { ¶dise_wd90c30_device }, - { &colorplus_device }, - { &pgc_device }, - { &cga_pravetz_device }, - { &radius_svga_multiview_isa_device }, - { &realtek_rtg3105_device }, - { &realtek_rtg3106_device }, - { &s3_diamond_stealth_vram_isa_device }, - { &s3_orchid_86c911_isa_device }, - { &s3_ami_86c924_isa_device }, - { &s3_metheus_86c928_isa_device }, - { &s3_phoenix_86c801_isa_device }, - { &s3_spea_mirage_86c801_isa_device }, - { &sigma_device }, - { &tvga8900b_device }, - { &tvga8900d_device }, - { &tvga8900dr_device }, - { &tvga9000b_device }, - { &nec_sv9000_device }, - { &et4000k_isa_device }, - { &et2000_device }, - { &et3000_isa_device }, - { &et4000_tc6058af_isa_device }, - { &et4000_isa_device }, - { &et4000w32_device }, - { &et4000w32i_isa_device }, - { &vga_device }, - { &v7_vga_1024i_device }, - { &wy700_device }, - { &mach32_mca_device, VIDEO_FLAG_TYPE_8514 }, - { &gd5426_mca_device }, - { &gd5428_mca_device }, - { &et4000_mca_device }, - { &radius_svga_multiview_mca_device }, - { &mach32_pci_device, VIDEO_FLAG_TYPE_8514 }, - { &mach64gx_pci_device }, - { &mach64vt2_device }, - { &bochs_svga_device }, - { &chips_69000_device }, - { &gd5430_pci_device, }, - { &gd5434_pci_device }, - { &gd5436_pci_device, VIDEO_FLAG_TYPE_SPECIAL }, - { &gd5440_pci_device }, - { &gd5446_pci_device, VIDEO_FLAG_TYPE_SPECIAL }, - { &gd5446_stb_pci_device, VIDEO_FLAG_TYPE_SPECIAL }, - { &gd5480_pci_device }, - { &et4000w32p_videomagic_revb_pci_device }, - { &et4000w32p_revc_pci_device }, - { &et4000w32p_cardex_pci_device }, - { &et4000w32p_noncardex_pci_device }, - { &et4000w32p_pci_device }, - { &s3_spea_mercury_lite_86c928_pci_device }, - { &s3_diamond_stealth64_964_pci_device }, - { &s3_elsa_winner2000_pro_x_964_pci_device }, - { &s3_mirocrystal_20sv_964_pci_device }, - { &s3_bahamas64_pci_device }, - { &s3_phoenix_vision864_pci_device }, - { &s3_diamond_stealth_se_pci_device }, - { &s3_phoenix_trio32_pci_device }, - { &s3_diamond_stealth64_pci_device }, - { &s3_9fx_pci_device }, - { &s3_phoenix_trio64_pci_device }, - { &s3_diamond_stealth64_968_pci_device }, - { &s3_elsa_winner2000_pro_x_pci_device }, - { &s3_mirovideo_40sv_ergo_968_pci_device }, - { &s3_9fx_771_pci_device }, - { &s3_phoenix_vision968_pci_device }, - { &s3_spea_mercury_p64v_pci_device }, - { &s3_9fx_531_pci_device }, - { &s3_phoenix_vision868_pci_device }, - { &s3_cardex_trio64vplus_pci_device }, - { &s3_phoenix_trio64vplus_pci_device }, - { &s3_trio64v2_dx_pci_device }, - { &s3_virge_325_pci_device }, - { &s3_diamond_stealth_2000_pci_device }, - { &s3_mirocrystal_3d_pci_device }, - { &s3_diamond_stealth_3000_pci_device }, - { &s3_stb_velocity_3d_pci_device }, - { &s3_virge_375_pci_device }, - { &s3_diamond_stealth_2000pro_pci_device }, - { &s3_virge_385_pci_device }, - { &s3_virge_357_pci_device }, - { &s3_diamond_stealth_4000_pci_device }, - { &s3_trio3d2x_pci_device }, - { &millennium_device }, - { &millennium_ii_device }, - { &mystique_device }, - { &mystique_220_device }, - { &tgui9440_pci_device }, - { &tgui9660_pci_device }, - { &tgui9680_pci_device }, - { &voodoo_banshee_device }, - { &creative_voodoo_banshee_device }, - { &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 }, - { &et4000w32p_revc_vlb_device }, - { &et4000w32p_cardex_vlb_device }, - { &et4000w32p_vlb_device }, - { &et4000w32p_noncardex_vlb_device }, - { &gd5424_vlb_device }, - { &gd5426_vlb_device }, - { &gd5428_vlb_device }, - { &gd5428_diamond_speedstar_pro_b1_vlb_device }, - { &gd5429_vlb_device }, - { &gd5430_diamond_speedstar_pro_se_a8_vlb_device }, - { &gd5430_vlb_device }, - { &gd5434_vlb_device }, - { &s3_metheus_86c928_vlb_device }, - { &s3_mirocrystal_8s_805_vlb_device }, - { &s3_mirocrystal_10sd_805_vlb_device }, - { &s3_phoenix_86c805_vlb_device }, - { &s3_spea_mirage_86c805_vlb_device }, - { &s3_diamond_stealth64_964_vlb_device }, - { &s3_mirocrystal_20sv_964_vlb_device }, - { &s3_mirocrystal_20sd_864_vlb_device }, - { &s3_bahamas64_vlb_device }, - { &s3_phoenix_vision864_vlb_device }, - { &s3_diamond_stealth_se_vlb_device }, - { &s3_phoenix_trio32_vlb_device }, - { &s3_diamond_stealth64_vlb_device }, - { &s3_9fx_vlb_device }, - { &s3_phoenix_trio64_vlb_device }, - { &s3_spea_mirage_p64_vlb_device }, - { &s3_diamond_stealth64_968_vlb_device }, - { &s3_stb_powergraph_64_video_vlb_device }, - { &ht216_32_standalone_device }, - { &tgui9400cxi_device }, - { &tgui9440_vlb_device }, - { &s3_virge_357_agp_device }, - { &s3_diamond_stealth_4000_agp_device }, - { &s3_trio3d2x_agp_device }, + { .device = &ati18800_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &ati18800_wonder_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &cga_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &sega_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &jega_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5401_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5402_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &compaq_cga_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &compaq_cga_2_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &cpqega_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &ega_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &g2_gc205_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &hercules_device, .flags = VIDEO_FLAG_TYPE_MDA }, + { .device = &herculesplus_device, .flags = VIDEO_FLAG_TYPE_MDA }, + { .device = &incolor_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &im1024_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &iskra_ega_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000_kasan_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &mda_device, .flags = VIDEO_FLAG_TYPE_MDA }, + { .device = &genius_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &nga_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &ogc_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &jvga_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &oti037c_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &oti067_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &oti077_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = ¶dise_pvga1a_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = ¶dise_wd90c11_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = ¶dise_wd90c30_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &colorplus_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &pgc_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &cga_pravetz_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &realtek_rtg3105_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &realtek_rtg3106_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &sigma_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &tvga8900b_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &tvga8900d_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &tvga8900dr_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &tvga9000b_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &nec_sv9000_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000k_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et2000_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et3000_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000_tc6058af_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &vga_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &v7_vga_1024i_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &wy700_device, .flags = VIDEO_FLAG_TYPE_NONE }, + /* ISA16 */ + { .device = &mach64gx_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5420_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5422_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5426_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5426_diamond_speedstar_pro_a1_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5428_boca_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5428_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5429_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5434_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5434_diamond_speedstar_64_a3_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &inmos_isa_device, .flags = VIDEO_FLAG_TYPE_XGA }, + { .device = &radius_svga_multiview_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth_vram_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_orchid_86c911_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_ami_86c924_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_metheus_86c928_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_phoenix_86c801_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_spea_mirage_86c801_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_winner1000_805_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32i_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + /* MCA */ + { .device = &mach32_mca_device, .flags = VIDEO_FLAG_TYPE_8514 }, + { .device = &gd5426_mca_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5428_mca_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000_mca_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &radius_svga_multiview_mca_device, .flags = VIDEO_FLAG_TYPE_NONE }, + /* VLB */ + { .device = &mach32_vlb_device, .flags = VIDEO_FLAG_TYPE_8514 }, + { .device = &mach64gx_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32i_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32p_videomagic_revb_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32p_revc_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32p_cardex_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32p_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32p_noncardex_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5424_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5426_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5428_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5428_diamond_speedstar_pro_b1_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5429_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5430_diamond_speedstar_pro_se_a8_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5430_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5434_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_metheus_86c928_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_mirocrystal_8s_805_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_mirocrystal_10sd_805_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_phoenix_86c805_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_spea_mirage_86c805_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth64_964_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_mirocrystal_20sv_964_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_mirocrystal_20sd_864_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_bahamas64_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_phoenix_vision864_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth_se_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_phoenix_trio32_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth64_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_9fx_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_phoenix_trio64_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_spea_mirage_p64_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth64_968_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_stb_powergraph_64_video_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &ht216_32_standalone_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &tgui9400cxi_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &tgui9440_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + /* PCI */ + { .device = &mach32_pci_device, .flags = VIDEO_FLAG_TYPE_8514 }, + { .device = &mach64gx_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &mach64vt2_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &bochs_svga_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &chips_69000_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5430_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5434_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5436_pci_device, .flags = VIDEO_FLAG_TYPE_SECONDARY }, + { .device = &gd5440_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5446_pci_device, .flags = VIDEO_FLAG_TYPE_SECONDARY }, + { .device = &gd5446_stb_pci_device, .flags = VIDEO_FLAG_TYPE_SECONDARY }, + { .device = &gd5480_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32p_videomagic_revb_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32p_revc_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32p_cardex_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32p_noncardex_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32p_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_spea_mercury_lite_86c928_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth64_964_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_elsa_winner2000_pro_x_964_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_mirocrystal_20sv_964_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_bahamas64_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_phoenix_vision864_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth_se_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_phoenix_trio32_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth64_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_9fx_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_phoenix_trio64_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth64_968_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_elsa_winner2000_pro_x_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_mirovideo_40sv_ergo_968_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_9fx_771_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_phoenix_vision968_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_spea_mercury_p64v_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_9fx_531_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_phoenix_vision868_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_cardex_trio64vplus_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_phoenix_trio64vplus_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_trio64v2_dx_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_virge_325_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth_2000_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_mirocrystal_3d_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth_3000_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_stb_velocity_3d_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_virge_375_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth_2000pro_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_virge_385_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_virge_357_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth_4000_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_trio3d2x_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &millennium_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &millennium_ii_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &mystique_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &mystique_220_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &tgui9440_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &tgui9660_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &tgui9680_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &voodoo_banshee_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &creative_voodoo_banshee_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &quantum3d_raven_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &voodoo_3_1000_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &voodoo_3_2000_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &voodoo_3_3000_device, .flags = VIDEO_FLAG_TYPE_NONE }, + /* AGP */ + { .device = &s3_virge_357_agp_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth_4000_agp_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_trio3d2x_agp_device, .flags = VIDEO_FLAG_TYPE_NONE }, #ifdef USE_G100 - { &productiva_g100_device, VIDEO_FLAG_TYPE_SPECIAL }, + { .device = &productiva_g100_device, .flags = VIDEO_FLAG_TYPE_SPECIAL }, #endif /*USE_G100 */ - { &velocity_100_agp_device }, - { &velocity_200_agp_device }, - { &voodoo_3_1000_agp_device }, - { &voodoo_3_2000_agp_device }, - { &voodoo_3_3000_agp_device }, - { &voodoo_3_3500_agp_ntsc_device }, - { &voodoo_3_3500_agp_pal_device }, - { &compaq_voodoo_3_3500_agp_device }, - { &voodoo_3_3500_se_agp_device }, - { &voodoo_3_3500_si_agp_device }, - { NULL } + { .device = &velocity_100_agp_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &velocity_200_agp_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &voodoo_3_1000_agp_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &voodoo_3_2000_agp_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &voodoo_3_3000_agp_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &voodoo_3_3500_agp_ntsc_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &voodoo_3_3500_agp_pal_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &compaq_voodoo_3_3500_agp_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &voodoo_3_3500_se_agp_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &voodoo_3_3500_si_agp_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = NULL, .flags = VIDEO_FLAG_TYPE_NONE } // clang-format on }; @@ -324,7 +334,7 @@ video_reset(int card) card, machine_has_flags(machine, MACHINE_VIDEO) ? 1 : 0); monitor_index_global = 0; - loadfont("roms/video/mda/mda.rom", 0); + loadfont(FONT_IBM_MDA_437_PATH, 0); for (uint8_t i = 1; i < GFXCARD_MAX; i ++) { if ((card != VID_NONE) && !machine_has_flags(machine, MACHINE_VIDEO_ONLY) && @@ -369,6 +379,8 @@ video_post_reset(void) if (xga_standalone_enabled) xga_device_add(); + if (da2_standalone_enabled) + da2_device_add(); /* Reset the graphics card (or do nothing if it was already done by the machine's init function). */ video_reset(gfxcard[0]); diff --git a/src/video/vid_tandy.c b/src/video/vid_tandy.c new file mode 100644 index 000000000..0504fd096 --- /dev/null +++ b/src/video/vid_tandy.c @@ -0,0 +1,827 @@ +/* + * 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. + * + * Tandy 1000 video emulation + * + * + * + * Authors: Sarah Walker, + * Miran Grca, + * Connor Hyde / starfrost, + * + * Copyright 2008-2019 Sarah Walker. + * Copyright 2016-2019 Miran Grca. + * Copyright 2025 starfrost + */ +#include +#include +#include +#include +#include +#include +#include +#define HAVE_STDARG_H +#include <86box/86box.h> +#include <86box/timer.h> +#include <86box/io.h> +#include <86box/pic.h> +#include <86box/pit.h> +#include <86box/nmi.h> +#include <86box/mem.h> +#include <86box/rom.h> +#include <86box/device.h> +#include <86box/nvr.h> +#include <86box/fdd.h> +#include <86box/fdc.h> +#include <86box/fdc_ext.h> +#include <86box/gameport.h> +#include <86box/keyboard.h> +#include <86box/sound.h> +#include <86box/snd_sn76489.h> +#include <86box/video.h> +#include <86box/vid_cga_comp.h> +#include <86box/m_tandy.h> +#include <86box/machine.h> +#include <86box/plat_unused.h> + +static uint8_t 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 uint8_t crtcmask_sl[32] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, + 0xf3, 0x1f, 0x7f, 0x1f, 0x3f, 0xff, 0x3f, 0xff, + 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +enum { + TANDY_RGB = 0, + TANDY_COMPOSITE +}; + +static video_timings_t timing_dram = { VIDEO_BUS, 0, 0, 0, 0, 0, 0 }; /*No additional waitstates*/ + +static void +recalc_mapping(tandy_t *dev) +{ + t1kvid_t *vid = dev->vid; + + mem_mapping_disable(&vid->mapping); + io_removehandler(0x03d0, 16, + tandy_vid_in, NULL, NULL, tandy_vid_out, NULL, NULL, dev); + + if (vid->planar_ctrl & 4) { + mem_mapping_enable(&vid->mapping); + if (vid->array[5] & 1) + mem_mapping_set_addr(&vid->mapping, 0xa0000, 0x10000); + else + mem_mapping_set_addr(&vid->mapping, 0xb8000, 0x8000); + io_sethandler(0x03d0, 16, tandy_vid_in, NULL, NULL, tandy_vid_out, NULL, NULL, dev); + } +} + +static void +recalc_timings(tandy_t *dev) +{ + t1kvid_t *vid = dev->vid; + + double _dispontime; + double _dispofftime; + double disptime; + + if (vid->mode & 1) { + disptime = vid->crtc[0] + 1; + _dispontime = vid->crtc[1]; + } else { + disptime = (vid->crtc[0] + 1) << 1; + _dispontime = vid->crtc[1] << 1; + } + + _dispofftime = disptime - _dispontime; + _dispontime *= CGACONST; + _dispofftime *= CGACONST; + vid->dispontime = (uint64_t) (_dispontime); + vid->dispofftime = (uint64_t) (_dispofftime); +} + +static void +recalc_address(tandy_t *dev) +{ + t1kvid_t *vid = dev->vid; + + if ((vid->memctrl & 0xc0) == 0xc0) { + vid->vram = &ram[((vid->memctrl & 0x06) << 14) + dev->base]; + vid->b8000 = &ram[((vid->memctrl & 0x30) << 11) + dev->base]; + vid->b8000_mask = 0x7fff; + } else { + vid->vram = &ram[((vid->memctrl & 0x07) << 14) + dev->base]; + vid->b8000 = &ram[((vid->memctrl & 0x38) << 11) + dev->base]; + vid->b8000_mask = 0x3fff; + } +} + +void +tandy_recalc_address_sl(tandy_t *dev) +{ + t1kvid_t *vid = dev->vid; + + vid->b8000_limit = 0x8000; + + if (vid->array[5] & 1) { + vid->vram = &ram[((vid->memctrl & 0x04) << 14) + dev->base]; + vid->b8000 = &ram[((vid->memctrl & 0x20) << 11) + dev->base]; + } else if ((vid->memctrl & 0xc0) == 0xc0) { + vid->vram = &ram[((vid->memctrl & 0x06) << 14) + dev->base]; + vid->b8000 = &ram[((vid->memctrl & 0x30) << 11) + dev->base]; + } else { + vid->vram = &ram[((vid->memctrl & 0x07) << 14) + dev->base]; + vid->b8000 = &ram[((vid->memctrl & 0x38) << 11) + dev->base]; + if ((vid->memctrl & 0x38) == 0x38) + vid->b8000_limit = 0x4000; + } +} + +static void +vid_update_latch(t1kvid_t *vid) +{ + uint32_t lp_latch = vid->displine * vid->crtc[1]; + + vid->crtc[0x10] = (lp_latch >> 8) & 0x3f; + vid->crtc[0x11] = lp_latch & 0xff; +} + +void +tandy_vid_out(uint16_t addr, uint8_t val, void *priv) +{ + tandy_t *dev = (tandy_t *) priv; + t1kvid_t *vid = dev->vid; + uint8_t old; + + if ((addr >= 0x3d0) && (addr <= 0x3d7)) + addr = (addr & 0xff9) | 0x004; + + switch (addr) { + case 0x03d4: + vid->crtcreg = val & 0x1f; + break; + + case 0x03d5: + old = vid->crtc[vid->crtcreg]; + if (dev->is_sl2) + vid->crtc[vid->crtcreg] = val & crtcmask_sl[vid->crtcreg]; + else + vid->crtc[vid->crtcreg] = val & crtcmask[vid->crtcreg]; + if (old != val) { + if (vid->crtcreg < 0xe || vid->crtcreg > 0x10) { + vid->fullchange = changeframecount; + recalc_timings(dev); + } + } + break; + + case 0x03d8: + old = vid->mode; + vid->mode = val; + if ((old ^ val) & 0x01) + recalc_timings(dev); + if (!dev->is_sl2) + update_cga16_color(vid->mode); + break; + + case 0x03d9: + vid->col = val; + break; + + case 0x03da: + vid->array_index = val & 0x1f; + break; + + case 0x3db: + if (!dev->is_sl2 && (vid->lp_strobe == 1)) + vid->lp_strobe = 0; + break; + + case 0x3dc: + if (!dev->is_sl2 && (vid->lp_strobe == 0)) { + vid->lp_strobe = 1; + vid_update_latch(vid); + } + break; + + case 0x03de: + if (vid->array_index & 16) + val &= 0xf; + vid->array[vid->array_index & 0x1f] = val; + if (dev->is_sl2) { + if ((vid->array_index & 0x1f) == 5) { + recalc_mapping(dev); + tandy_recalc_address_sl(dev); + } + } + break; + + case 0x03df: + vid->memctrl = val; + if (dev->is_sl2) + tandy_recalc_address_sl(dev); + else + recalc_address(dev); + break; + + case 0x0065: + if (val == 8) + return; /*Hack*/ + vid->planar_ctrl = val; + recalc_mapping(dev); + break; + + default: + break; + } +} + +uint8_t +tandy_vid_in(uint16_t addr, void *priv) +{ + const tandy_t *dev = (tandy_t *) priv; + t1kvid_t *vid = dev->vid; + uint8_t ret = 0xff; + + if ((addr >= 0x3d0) && (addr <= 0x3d7)) + addr = (addr & 0xff9) | 0x004; + + switch (addr) { + case 0x03d4: + ret = vid->crtcreg; + break; + + case 0x03d5: + ret = vid->crtc[vid->crtcreg]; + break; + + case 0x03da: + ret = vid->status; + break; + + case 0x3db: + if (!dev->is_sl2 && (vid->lp_strobe == 1)) + vid->lp_strobe = 0; + break; + + case 0x3dc: + if (!dev->is_sl2 && (vid->lp_strobe == 0)) { + vid->lp_strobe = 1; + vid_update_latch(vid); + } + break; + + default: + break; + } + + return ret; +} + +static void +vid_write(uint32_t addr, uint8_t val, void *priv) +{ + tandy_t *dev = (tandy_t *) priv; + t1kvid_t *vid = dev->vid; + + if (vid->memctrl == -1) + return; + + if (dev->is_sl2) { + if (vid->array[5] & 1) + vid->b8000[addr & 0xffff] = val; + else { + if ((addr & 0x7fff) < vid->b8000_limit) + vid->b8000[addr & 0x7fff] = val; + } + } else { + vid->b8000[addr & vid->b8000_mask] = val; + } +} + +static uint8_t +vid_read(uint32_t addr, void *priv) +{ + const tandy_t *dev = (tandy_t *) priv; + const t1kvid_t *vid = dev->vid; + + if (vid->memctrl == -1) + return 0xff; + + if (dev->is_sl2) { + if (vid->array[5] & 1) + return (vid->b8000[addr & 0xffff]); + if ((addr & 0x7fff) < vid->b8000_limit) + return (vid->b8000[addr & 0x7fff]); + else + return 0xff; + } else { + return (vid->b8000[addr & vid->b8000_mask]); + } +} + +static void +vid_poll(void *priv) +{ + tandy_t *dev = (tandy_t *) priv; + t1kvid_t *vid = dev->vid; + uint16_t cursoraddr = (vid->crtc[15] | (vid->crtc[14] << 8)) & 0x3fff; + int drawcursor; + int x; + int c; + int xs_temp; + int ys_temp; + int oldvc; + uint8_t chr; + uint8_t attr; + uint16_t dat; + int cols[4]; + int col; + int scanline_old; + + if (!vid->linepos) { + timer_advance_u64(&vid->timer, vid->dispofftime); + vid->status |= 1; + vid->linepos = 1; + scanline_old = vid->scanline; + if ((vid->crtc[8] & 3) == 3) + vid->scanline = (vid->scanline << 1) & 7; + if (vid->dispon) { + if (vid->displine < vid->firstline) { + vid->firstline = vid->displine; + video_wait_for_buffer(); + } + vid->lastline = vid->displine; + 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]; + 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]; + } 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]; + } + } else if ((vid->mode & 0x12) == 0x12) { + 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; + } 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; + } + } else { + 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; + } 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; + } + } + } + if (dev->is_sl2 && (vid->array[5] & 1)) { /*640x200x16*/ + for (x = 0; x < vid->crtc[1] * 2; x++) { + dat = (vid->vram[(vid->memaddr << 1) & 0xffff] << 8) | vid->vram[((vid->memaddr << 1) + 1) & 0xffff]; + vid->memaddr++; + 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->memaddr << 1) & 0x1fff) + ((vid->scanline & 3) * 0x2000)] << 8) | vid->vram[((vid->memaddr << 1) & 0x1fff) + ((vid->scanline & 3) * 0x2000) + 1]; + vid->memaddr++; + 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] & 0x0f) + 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] & 0x0f) + 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] & 0x0f) + 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] & 0x0f) + 16] + 16; + } + } else if (vid->array[3] & 0x10) { /*160x200x16*/ + for (x = 0; x < vid->crtc[1]; x++) { + if (dev->is_sl2) { + dat = (vid->vram[((vid->memaddr << 1) & 0x1fff) + ((vid->scanline & 1) * 0x2000)] << 8) | vid->vram[((vid->memaddr << 1) & 0x1fff) + ((vid->scanline & 1) * 0x2000) + 1]; + } else { + dat = (vid->vram[((vid->memaddr << 1) & 0x1fff) + ((vid->scanline & 3) * 0x2000)] << 8) | vid->vram[((vid->memaddr << 1) & 0x1fff) + ((vid->scanline & 3) * 0x2000) + 1]; + } + vid->memaddr++; + 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] & 0x0f) + 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] & 0x0f) + 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] & 0x0f) + 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] & 0x0f) + 16] + 16; + } + } else if (vid->array[3] & 0x08) { /*640x200x4 - this implementation is a complete guess!*/ + for (x = 0; x < vid->crtc[1]; x++) { + dat = (vid->vram[((vid->memaddr << 1) & 0x1fff) + ((vid->scanline & 3) * 0x2000)] << 8) | vid->vram[((vid->memaddr << 1) & 0x1fff) + ((vid->scanline & 3) * 0x2000) + 1]; + vid->memaddr++; + 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; + dat <<= 1; + } + } + } else if (vid->mode & 1) { + for (x = 0; x < vid->crtc[1]; x++) { + chr = vid->vram[(vid->memaddr << 1) & 0x3fff]; + attr = vid->vram[((vid->memaddr << 1) + 1) & 0x3fff]; + drawcursor = ((vid->memaddr == cursoraddr) && vid->cursorvisible && vid->cursoron); + if (vid->mode & 0x20) { + cols[1] = vid->array[((attr & 15) & vid->array[1]) + 16] + 16; + cols[0] = vid->array[(((attr >> 4) & 7) & vid->array[1]) + 16] + 16; + if ((vid->blink & 16) && (attr & 0x80) && !drawcursor) + cols[1] = cols[0]; + } else { + cols[1] = vid->array[((attr & 15) & vid->array[1]) + 16] + 16; + cols[0] = vid->array[((attr >> 4) & vid->array[1]) + 16] + 16; + } + if (vid->scanline & 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] = ((chr & 0xf0) == 0xb0) ? cols[(fontdat[chr][7] & (1 << (c ^ 7))) ? 1 : 0] : cols[0]; + } + } else { + for (c = 0; c < 8; c++) { + if (vid->scanline == 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]; + } else { + buffer32->line[vid->displine << 1][(x << 3) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[chr][vid->scanline & 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) + 1][(x << 3) + c + 8] ^= 15; + } + } + vid->memaddr++; + } + } else if (!(vid->mode & 2)) { + for (x = 0; x < vid->crtc[1]; x++) { + chr = vid->vram[(vid->memaddr << 1) & 0x3fff]; + attr = vid->vram[((vid->memaddr << 1) + 1) & 0x3fff]; + drawcursor = ((vid->memaddr == cursoraddr) && vid->cursorvisible && vid->cursoron); + if (vid->mode & 0x20) { + cols[1] = vid->array[((attr & 15) & vid->array[1]) + 16] + 16; + cols[0] = vid->array[(((attr >> 4) & 7) & vid->array[1]) + 16] + 16; + if ((vid->blink & 16) && (attr & 0x80) && !drawcursor) + cols[1] = cols[0]; + } else { + cols[1] = vid->array[((attr & 15) & vid->array[1]) + 16] + 16; + cols[0] = vid->array[((attr >> 4) & vid->array[1]) + 16] + 16; + } + vid->memaddr++; + if (vid->scanline & 8) { + 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] = ((chr & 0xf0) == 0xb0) ? cols[(fontdat[chr][7] & (1 << (c ^ 7))) ? 1 : 0] : cols[0]; + } else { + for (c = 0; c < 8; c++) { + if (vid->scanline == 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]; + } 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->scanline & 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) + 1][(x << 4) + c + 8] ^= 15; + } + } + } + } else if (!(vid->mode & 16)) { + cols[0] = (vid->col & 15); + col = (vid->col & 16) ? 8 : 0; + if (vid->mode & 4) { + cols[1] = col | 3; + cols[2] = col | 4; + cols[3] = col | 7; + } else if (vid->col & 32) { + cols[1] = col | 3; + cols[2] = col | 5; + cols[3] = col | 7; + } else { + cols[1] = col | 2; + cols[2] = col | 4; + cols[3] = col | 6; + } + cols[0] = vid->array[(cols[0] & vid->array[1]) + 16] + 16; + cols[1] = vid->array[(cols[1] & vid->array[1]) + 16] + 16; + cols[2] = vid->array[(cols[2] & vid->array[1]) + 16] + 16; + cols[3] = vid->array[(cols[3] & vid->array[1]) + 16] + 16; + for (x = 0; x < vid->crtc[1]; x++) { + dat = (vid->vram[((vid->memaddr << 1) & 0x1fff) + ((vid->scanline & 1) * 0x2000)] << 8) | vid->vram[((vid->memaddr << 1) & 0x1fff) + ((vid->scanline & 1) * 0x2000) + 1]; + vid->memaddr++; + 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]; + dat <<= 2; + } + } + } else { + cols[0] = 0; + cols[1] = vid->array[(vid->col & vid->array[1]) + 16] + 16; + for (x = 0; x < vid->crtc[1]; x++) { + dat = (vid->vram[((vid->memaddr << 1) & 0x1fff) + ((vid->scanline & 1) * 0x2000)] << 8) | vid->vram[((vid->memaddr << 1) & 0x1fff) + ((vid->scanline & 1) * 0x2000) + 1]; + vid->memaddr++; + 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]; + dat <<= 1; + } + } + } + } else { + if (vid->array[3] & 4) { + if (vid->mode & 1) { + hline(buffer32, 0, (vid->displine << 1), (vid->crtc[1] << 3) + 16, (vid->array[2] & 0xf) + 16); + hline(buffer32, 0, (vid->displine << 1) + 1, (vid->crtc[1] << 3) + 16, (vid->array[2] & 0xf) + 16); + } else { + hline(buffer32, 0, (vid->displine << 1), (vid->crtc[1] << 4) + 16, (vid->array[2] & 0xf) + 16); + hline(buffer32, 0, (vid->displine << 1) + 1, (vid->crtc[1] << 4) + 16, (vid->array[2] & 0xf) + 16); + } + } else { + cols[0] = ((vid->mode & 0x12) == 0x12) ? 0 : (vid->col & 0xf) + 16; + if (vid->mode & 1) { + hline(buffer32, 0, (vid->displine << 1), (vid->crtc[1] << 3) + 16, cols[0]); + hline(buffer32, 0, (vid->displine << 1) + 1, (vid->crtc[1] << 3) + 16, cols[0]); + } else { + hline(buffer32, 0, (vid->displine << 1), (vid->crtc[1] << 4) + 16, cols[0]); + hline(buffer32, 0, (vid->displine << 1) + 1, (vid->crtc[1] << 4) + 16, cols[0]); + } + } + } + + if (vid->mode & 1) + x = (vid->crtc[1] << 3) + 16; + 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) + 1]); + } else { + video_process_8(x, vid->displine << 1); + video_process_8(x, (vid->displine << 1) + 1); + } + vid->scanline = scanline_old; + if (vid->vc == vid->crtc[7] && !vid->scanline) + vid->status |= 8; + vid->displine++; + if (vid->displine >= 360) + vid->displine = 0; + } else { + timer_advance_u64(&vid->timer, vid->dispontime); + if (vid->dispon) + vid->status &= ~1; + vid->linepos = 0; + if (vid->vsynctime) { + vid->vsynctime--; + if (!vid->vsynctime) + vid->status &= ~8; + } + if (vid->scanline == (vid->crtc[11] & 31) || ((vid->crtc[8] & 3) == 3 && vid->scanline == ((vid->crtc[11] & 31) >> 1))) { + vid->cursorvisible = 0; + } + if (vid->vadj) { + vid->scanline++; + vid->scanline &= 31; + vid->memaddr = vid->memaddr_backup; + vid->vadj--; + if (!vid->vadj) { + vid->dispon = 1; + if (dev->is_sl2 && (vid->array[5] & 1)) + vid->memaddr = vid->memaddr_backup = vid->crtc[13] | (vid->crtc[12] << 8); + else + vid->memaddr = vid->memaddr_backup = (vid->crtc[13] | (vid->crtc[12] << 8)) & 0x3fff; + vid->scanline = 0; + } + } else if (vid->scanline == vid->crtc[9] || ((vid->crtc[8] & 3) == 3 && vid->scanline == (vid->crtc[9] >> 1))) { + vid->memaddr_backup = vid->memaddr; + vid->scanline = 0; + oldvc = vid->vc; + vid->vc++; + if (dev->is_sl2) + vid->vc &= 255; + else + vid->vc &= 127; + if (vid->vc == vid->crtc[6]) + vid->dispon = 0; + if (oldvc == vid->crtc[4]) { + vid->vc = 0; + vid->vadj = vid->crtc[5]; + if (!vid->vadj) + vid->dispon = 1; + if (!vid->vadj) { + if (dev->is_sl2 && (vid->array[5] & 1)) + vid->memaddr = vid->memaddr_backup = vid->crtc[13] | (vid->crtc[12] << 8); + else + vid->memaddr = vid->memaddr_backup = (vid->crtc[13] | (vid->crtc[12] << 8)) & 0x3fff; + } + if ((vid->crtc[10] & 0x60) == 0x20) + vid->cursoron = 0; + else + vid->cursoron = vid->blink & 16; + } + if (vid->vc == vid->crtc[7]) { + vid->dispon = 0; + vid->displine = 0; + vid->vsynctime = 16; + picint(1 << 5); + if (vid->crtc[7]) { + if (vid->mode & 1) + x = (vid->crtc[1] << 3) + 16; + else + x = (vid->crtc[1] << 4) + 16; + vid->lastline++; + + xs_temp = x; + ys_temp = (vid->lastline - vid->firstline) << 1; + + if ((xs_temp > 0) && (ys_temp > 0)) { + if (xs_temp < 64) + xs_temp = 656; + if (ys_temp < 32) + ys_temp = 400; + if (!enable_overscan) + xs_temp -= 16; + + 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)); + + if (video_force_resize_get()) + video_force_resize_set(0); + } + + if (enable_overscan) { + video_blit_memtoscreen(0, (vid->firstline - 4) << 1, + xsize, ((vid->lastline - vid->firstline) + 8) << 1); + } else { + video_blit_memtoscreen(8, vid->firstline << 1, + xsize, (vid->lastline - vid->firstline) << 1); + } + } + + frames++; + + video_res_x = xsize; + video_res_y = ysize; + if ((vid->array[3] & 0x10) && (vid->mode & 1)) { /*320x200x16*/ + video_res_x /= 2; + video_bpp = 4; + } else if (vid->array[3] & 0x10) { /*160x200x16*/ + video_res_x /= 4; + video_bpp = 4; + } else if (vid->array[3] & 0x08) { /*640x200x4 - this implementation is a complete guess!*/ + video_bpp = 2; + } else if (vid->mode & 1) { + video_res_x /= 8; + video_res_y /= vid->crtc[9] + 1; + video_bpp = 0; + } else if (!(vid->mode & 2)) { + video_res_x /= 16; + video_res_y /= vid->crtc[9] + 1; + video_bpp = 0; + } else if (!(vid->mode & 16)) { + video_res_x /= 2; + video_bpp = 2; + } else { + video_bpp = 1; + } + } + vid->firstline = 1000; + vid->lastline = 0; + vid->blink++; + } + } else { + vid->scanline++; + vid->scanline &= 31; + vid->memaddr = vid->memaddr_backup; + } + if (vid->scanline == (vid->crtc[10] & 31) || ((vid->crtc[8] & 3) == 3 && vid->scanline == ((vid->crtc[10] & 31) >> 1))) + vid->cursorvisible = 1; + } +} + +void +tandy_vid_speed_changed(void *priv) +{ + tandy_t *dev = (tandy_t *) priv; + + recalc_timings(dev); +} + +void +tandy_vid_close(void *priv) +{ + tandy_t *dev = (tandy_t *) priv; + + free(dev->vid); + dev->vid = NULL; +} + +void +tandy_vid_init(tandy_t *dev) +{ + int display_type; + t1kvid_t *vid; + + vid = calloc(1, sizeof(t1kvid_t)); + vid->memctrl = -1; + + video_inform(VIDEO_FLAG_TYPE_CGA, &timing_dram); + + display_type = device_get_config_int("display_type"); + vid->composite = (display_type != TANDY_RGB); + + cga_comp_init(1); + + if (dev->is_sl2) { + vid->b8000_limit = 0x8000; + vid->planar_ctrl = 4; + overscan_x = overscan_y = 16; + + io_sethandler(0x0065, 1, tandy_vid_in, NULL, NULL, tandy_vid_out, NULL, NULL, dev); + } else + vid->b8000_mask = 0x3fff; + + timer_add(&vid->timer, vid_poll, dev, 1); + mem_mapping_add(&vid->mapping, 0xb8000, 0x08000, + vid_read, NULL, NULL, vid_write, NULL, NULL, NULL, 0, dev); + io_sethandler(0x03d0, 16, + tandy_vid_in, NULL, NULL, tandy_vid_out, NULL, NULL, dev); + + dev->vid = vid; +} + +const device_config_t vid_config[] = { + // clang-format off + { + .name = "display_type", + .description = "Display type", + .type = CONFIG_SELECTION, + .default_string = "", + .default_int = TANDY_RGB, + .file_filter = "", + .spinner = { 0 }, + .selection = { + { .description = "RGB", .value = TANDY_RGB }, + { .description = "Composite", .value = TANDY_COMPOSITE }, + { .description = "" } + } + }, + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on +}; + +const device_t tandy_1000_video_device = { + .name = "Tandy 1000", + .internal_name = "tandy1000_video", + .flags = 0, + .local = 0, + .init = NULL, + .close = tandy_vid_close, + .reset = NULL, + .available = NULL, + .speed_changed = tandy_vid_speed_changed, + .force_redraw = NULL, + .config = vid_config +}; + +const device_t tandy_1000hx_video_device = { + .name = "Tandy 1000 HX", + .internal_name = "tandy1000_hx_video", + .flags = 0, + .local = 0, + .init = NULL, + .close = tandy_vid_close, + .reset = NULL, + .available = NULL, + .speed_changed = tandy_vid_speed_changed, + .force_redraw = NULL, + .config = vid_config +}; + +const device_t tandy_1000sl_video_device = { + .name = "Tandy 1000SL2", + .internal_name = "tandy1000_sl_video", + .flags = 0, + .local = 1, + .init = NULL, + .close = tandy_vid_close, + .reset = NULL, + .available = NULL, + .speed_changed = tandy_vid_speed_changed, + .force_redraw = NULL, + .config = NULL +}; diff --git a/src/video/vid_tgui9440.c b/src/video/vid_tgui9440.c index 9ec7e6105..5cc3a8a78 100644 --- a/src/video/vid_tgui9440.c +++ b/src/video/vid_tgui9440.c @@ -112,8 +112,7 @@ typedef struct tgui_t { uint8_t int_line; uint8_t pci_regs[256]; - struct - { + struct { int16_t src_x, src_y; int16_t src_x_clip, src_y_clip; int16_t dst_x, dst_y; @@ -126,6 +125,7 @@ typedef struct tgui_t { uint8_t rop; uint32_t flags; uint8_t pattern[0x80]; + uint8_t pattern_32bpp[0x100]; int command; int offset; uint16_t ger22; @@ -143,6 +143,7 @@ typedef struct tgui_t { uint32_t pattern_8[8 * 8]; uint32_t pattern_16[8 * 8]; uint32_t pattern_32[8 * 8]; + int pattern_32_idx; } accel; uint8_t copy_latch[16]; /*TGUI9400CXi only*/ @@ -210,7 +211,7 @@ 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 -dword_remap(svga_t *svga, uint32_t in_addr) +dword_remap(UNUSED(svga_t *svga), uint32_t in_addr) { return ((in_addr << 2) & 0x3fff0) | ((in_addr >> 14) & 0xc) | (in_addr & ~0x3fffc); } @@ -350,7 +351,9 @@ tgui_out(uint16_t addr, uint8_t val, void *priv) if (tgui->ramdac_state == 4) { tgui->ramdac_state = 0; tgui->ramdac_ctrl = val; - //pclog("TGUI ramdac ctrl=%02x.\n", (tgui->ramdac_ctrl >> 4) & 0x0f); +#if 0 + pclog("TGUI ramdac ctrl=%02x.\n", (tgui->ramdac_ctrl >> 4) & 0x0f); +#endif svga_recalctimings(svga); return; } @@ -540,7 +543,7 @@ tgui_out(uint16_t addr, uint8_t val, void *priv) 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); + svga->memaddr_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5); } else { svga->fullchange = svga->monitor->mon_changeframecount; svga_recalctimings(svga); @@ -718,16 +721,18 @@ tgui_recalctimings(svga_t *svga) if (((svga->crtc[0x29] & 0x30) && (svga->bpp >= 15)) || !svga->rowoffset) svga->rowoffset |= 0x100; - //pclog("BPP=%d, DataWidth=%02x, CRTC29 bit 4-5=%02x, pixbusmode=%02x, rowoffset=%02x, doublerowoffset=%x.\n", svga->bpp, svga->crtc[0x2a] & 0x40, svga->crtc[0x29] & 0x30, svga->crtc[0x38], svga->rowoffset, svga->gdcreg[0x2f] & 4); +#if 0 + pclog("BPP=%d, DataWidth=%02x, CRTC29 bit 4-5=%02x, pixbusmode=%02x, rowoffset=%02x, doublerowoffset=%x.\n", svga->bpp, svga->crtc[0x2a] & 0x40, svga->crtc[0x29] & 0x30, svga->crtc[0x38], svga->rowoffset, svga->gdcreg[0x2f] & 4); +#endif if ((svga->crtc[0x1e] & 0xA0) == 0xA0) - svga->ma_latch |= 0x10000; + svga->memaddr_latch |= 0x10000; if (svga->crtc[0x27] & 0x01) - svga->ma_latch |= 0x20000; + svga->memaddr_latch |= 0x20000; if (svga->crtc[0x27] & 0x02) - svga->ma_latch |= 0x40000; + svga->memaddr_latch |= 0x40000; if (svga->crtc[0x27] & 0x04) - svga->ma_latch |= 0x80000; + svga->memaddr_latch |= 0x80000; if (svga->crtc[0x27] & 0x08) svga->split |= 0x400; @@ -753,8 +758,8 @@ tgui_recalctimings(svga_t *svga) if (svga->vdisp == 1020) svga->vdisp += 2; - if ((tgui->oldctrl2 & 0x10) || (svga->crtc[0x2a] & 0x40)) - svga->ma_latch <<= 1; + if (tgui->oldctrl2 & 0x10) + svga->memaddr_latch <<= 1; svga->lowres = !(svga->crtc[0x2a] & 0x40); @@ -1454,29 +1459,795 @@ enum { else \ dat = vram_l[(addr) & (tgui->vram_mask >> 2)]; -#define MIX() \ - do { \ - out = 0; \ - for (c = 0; c < 32; c++) { \ - d = (dst_dat & (1 << c)) ? 1 : 0; \ - if (src_dat & (1 << c)) \ - d |= 2; \ - if (pat_dat & (1 << c)) \ - d |= 4; \ - if (tgui->accel.rop & (1 << d)) \ - out |= (1 << c); \ - } \ +#define ROPMIX(R, D, P, S, out) \ + { \ + switch (R) { \ + case 0x00: \ + out = 0; \ + break; \ + case 0x01: \ + out = ~(D | (P | S)); \ + break; \ + case 0x02: \ + out = D & ~(P | S); \ + break; \ + case 0x03: \ + out = ~(P | S); \ + break; \ + case 0x04: \ + out = S & ~(D | P); \ + break; \ + case 0x05: \ + out = ~(D | P); \ + break; \ + case 0x06: \ + out = ~(P | ~(D ^ S)); \ + break; \ + case 0x07: \ + out = ~(P | (D & S)); \ + break; \ + case 0x08: \ + out = S & (D & ~P); \ + break; \ + case 0x09: \ + out = ~(P | (D ^ S)); \ + break; \ + case 0x0a: \ + out = D & ~P; \ + break; \ + case 0x0b: \ + out = ~(P | (S & ~D)); \ + break; \ + case 0x0c: \ + out = S & ~P; \ + break; \ + case 0x0d: \ + out = ~(P | (D & ~S)); \ + break; \ + case 0x0e: \ + out = ~(P | ~(D | S)); \ + break; \ + case 0x0f: \ + out = ~P; \ + break; \ + case 0x10: \ + out = P & ~(D | S); \ + break; \ + case 0x11: \ + out = ~(D | S); \ + break; \ + case 0x12: \ + out = ~(S | ~(D ^ P)); \ + break; \ + case 0x13: \ + out = ~(S | (D & P)); \ + break; \ + case 0x14: \ + out = ~(D | ~(P ^ S)); \ + break; \ + case 0x15: \ + out = ~(D | (P & S)); \ + break; \ + case 0x16: \ + out = P ^ (S ^ (D & ~(P & S))); \ + break; \ + case 0x17: \ + out = ~(S ^ ((S ^ P) & (D ^ S))); \ + break; \ + case 0x18: \ + out = (S ^ P) & (P ^ D); \ + break; \ + case 0x19: \ + out = ~(S ^ (D & ~(P & S))); \ + break; \ + case 0x1a: \ + out = P ^ (D | (S & P)); \ + break; \ + case 0x1b: \ + out = ~(S ^ (D & (P ^ S))); \ + break; \ + case 0x1c: \ + out = P ^ (S | (D & P)); \ + break; \ + case 0x1d: \ + out = ~(D ^ (S & (P ^ D))); \ + break; \ + case 0x1e: \ + out = P ^ (D | S); \ + break; \ + case 0x1f: \ + out = ~(P & (D | S)); \ + break; \ + case 0x20: \ + out = D & (P & ~S); \ + break; \ + case 0x21: \ + out = ~(S | (D ^ P)); \ + break; \ + case 0x22: \ + out = D & ~S; \ + break; \ + case 0x23: \ + out = ~(S | (P & ~D)); \ + break; \ + case 0x24: \ + out = (S ^ P) & (D ^ S); \ + break; \ + case 0x25: \ + out = ~(P ^ (D & ~(S & P))); \ + break; \ + case 0x26: \ + out = S ^ (D | (P & S)); \ + break; \ + case 0x27: \ + out = S ^ (D | ~(P ^ S)); \ + break; \ + case 0x28: \ + out = D & (P ^ S); \ + break; \ + case 0x29: \ + out = ~(P ^ (S ^ (D | (P & S)))); \ + break; \ + case 0x2a: \ + out = D & ~(P & S); \ + break; \ + case 0x2b: \ + out = ~(S ^ ((S ^ P) & (P ^ D))); \ + break; \ + case 0x2c: \ + out = S ^ (P & (D | S)); \ + break; \ + case 0x2d: \ + out = P ^ (S | ~D); \ + break; \ + case 0x2e: \ + out = P ^ (S | (D ^ P)); \ + break; \ + case 0x2f: \ + out = ~(P & (S | ~D)); \ + break; \ + case 0x30: \ + out = P & ~S; \ + break; \ + case 0x31: \ + out = ~(S | (D & ~P)); \ + break; \ + case 0x32: \ + out = S ^ (D | (P | S)); \ + break; \ + case 0x33: \ + out = ~S; \ + break; \ + case 0x34: \ + out = S ^ (P | (D & S)); \ + break; \ + case 0x35: \ + out = S ^ (P | ~(D ^ S)); \ + break; \ + case 0x36: \ + out = S ^ (D | P); \ + break; \ + case 0x37: \ + out = ~(S & (D | P)); \ + break; \ + case 0x38: \ + out = P ^ (S & (D | P)); \ + break; \ + case 0x39: \ + out = S ^ (P | ~D); \ + break; \ + case 0x3a: \ + out = S ^ (P | (D ^ S)); \ + break; \ + case 0x3b: \ + out = ~(S & (P | ~D)); \ + break; \ + case 0x3c: \ + out = P ^ S; \ + break; \ + case 0x3d: \ + out = S ^ (P | ~(D | S)); \ + break; \ + case 0x3e: \ + out = S ^ (P | (D & ~S)); \ + break; \ + case 0x3f: \ + out = ~(P & S); \ + break; \ + case 0x40: \ + out = P & (S & ~D); \ + break; \ + case 0x41: \ + out = ~(D | (P ^ S)); \ + break; \ + case 0x42: \ + out = (S ^ D) & (P ^ D); \ + break; \ + case 0x43: \ + out = ~(S ^ (P & ~(D & S))); \ + break; \ + case 0x44: \ + out = S & ~D; \ + break; \ + case 0x45: \ + out = ~(D | (P & ~S)); \ + break; \ + case 0x46: \ + out = D ^ (S | (P & D)); \ + break; \ + case 0x47: \ + out = ~(P ^ (S & (D ^ P))); \ + break; \ + case 0x48: \ + out = S & (D ^ P); \ + break; \ + case 0x49: \ + out = ~(P ^ (D ^ (S | (P & D)))); \ + break; \ + case 0x4a: \ + out = D ^ (P & (S | D)); \ + break; \ + case 0x4b: \ + out = P ^ (D | ~S); \ + break; \ + case 0x4c: \ + out = S & ~(D & P); \ + break; \ + case 0x4d: \ + out = ~(S ^ ((S ^ P) | (D ^ S))); \ + break; \ + case 0x4e: \ + out = P ^ (D | (S ^ P)); \ + break; \ + case 0x4f: \ + out = ~(P & (D | ~S)); \ + break; \ + case 0x50: \ + out = P & ~D; \ + break; \ + case 0x51: \ + out = ~(D | (S & ~P)); \ + break; \ + case 0x52: \ + out = D ^ (P | (S & D)); \ + break; \ + case 0x53: \ + out = ~(S ^ (P & (D ^ S))); \ + break; \ + case 0x54: \ + out = ~(D | ~(P | S)); \ + break; \ + case 0x55: \ + out = ~D; \ + break; \ + case 0x56: \ + out = D ^ (P | S); \ + break; \ + case 0x57: \ + out = ~(D & (P | S)); \ + break; \ + case 0x58: \ + out = P ^ (D & (S | P)); \ + break; \ + case 0x59: \ + out = D ^ (P | ~S); \ + break; \ + case 0x5a: \ + out = D ^ P; \ + break; \ + case 0x5b: \ + out = D ^ (P | ~(S | D)); \ + break; \ + case 0x5c: \ + out = D ^ (P | (S ^ D)); \ + break; \ + case 0x5d: \ + out = ~(D & (P | ~S)); \ + break; \ + case 0x5e: \ + out = D ^ (P | (S & ~D)); \ + break; \ + case 0x5f: \ + out = ~(D & P); \ + break; \ + case 0x60: \ + out = P & (D ^ S); \ + break; \ + case 0x61: \ + out = ~(D ^ (S ^ (P | (D & S)))); \ + break; \ + case 0x62: \ + out = D ^ (S & (P | D)); \ + break; \ + case 0x63: \ + out = S ^ (D | ~P); \ + break; \ + case 0x64: \ + out = S ^ (D & (P | S)); \ + break; \ + case 0x65: \ + out = D ^ (S | ~P); \ + break; \ + case 0x66: \ + out = D ^ S; \ + break; \ + case 0x67: \ + out = S ^ (D | ~(P | S)); \ + break; \ + case 0x68: \ + out = ~(D ^ (S ^ (P | ~(D | S)))); \ + break; \ + case 0x69: \ + out = ~(P ^ (D ^ S)); \ + break; \ + case 0x6a: \ + out = D ^ (P & S); \ + break; \ + case 0x6b: \ + out = ~(P ^ (S ^ (D & (P | S)))); \ + break; \ + case 0x6c: \ + out = S ^ (D & P); \ + break; \ + case 0x6d: \ + out = ~(P ^ (D ^ (S & (P | D)))); \ + break; \ + case 0x6e: \ + out = S ^ (D & (P | ~S)); \ + break; \ + case 0x6f: \ + out = ~(P & ~(D ^ S)); \ + break; \ + case 0x70: \ + out = P & ~(D & S); \ + break; \ + case 0x71: \ + out = ~(S ^ ((S ^ D) & (P ^ D))); \ + break; \ + case 0x72: \ + out = S ^ (D | (P ^ S)); \ + break; \ + case 0x73: \ + out = ~(S & (D | ~P)); \ + break; \ + case 0x74: \ + out = D ^ (S | (P ^ D)); \ + break; \ + case 0x75: \ + out = ~(D & (S | ~P)); \ + break; \ + case 0x76: \ + out = S ^ (D | (P & ~S)); \ + break; \ + case 0x77: \ + out = ~(D & S); \ + break; \ + case 0x78: \ + out = P ^ (D & S); \ + break; \ + case 0x79: \ + out = ~(D ^ (S ^ (P & (D | S)))); \ + break; \ + case 0x7a: \ + out = D ^ (P & (S | ~D)); \ + break; \ + case 0x7b: \ + out = ~(S & ~(D ^ P)); \ + break; \ + case 0x7c: \ + out = S ^ (P & (D | ~S)); \ + break; \ + case 0x7d: \ + out = ~(D & ~(P ^ S)); \ + break; \ + case 0x7e: \ + out = (S ^ P) | (D ^ S); \ + break; \ + case 0x7f: \ + out = ~(D & (P & S)); \ + break; \ + case 0x80: \ + out = D & (P & S); \ + break; \ + case 0x81: \ + out = ~((S ^ P) | (D ^ S)); \ + break; \ + case 0x82: \ + out = D & ~(P ^ S); \ + break; \ + case 0x83: \ + out = ~(S ^ (P & (D | ~S))); \ + break; \ + case 0x84: \ + out = S & ~(D ^ P); \ + break; \ + case 0x85: \ + out = ~(P ^ (D & (S | ~P))); \ + break; \ + case 0x86: \ + out = D ^ (S ^ (P & (D | S))); \ + break; \ + case 0x87: \ + out = ~(P ^ (D & S)); \ + break; \ + case 0x88: \ + out = D & S; \ + break; \ + case 0x89: \ + out = ~(S ^ (D | (P & ~S))); \ + break; \ + case 0x8a: \ + out = D & (S | ~P); \ + break; \ + case 0x8b: \ + out = ~(D ^ (S | (P ^ D))); \ + break; \ + case 0x8c: \ + out = S & (D | ~P); \ + break; \ + case 0x8d: \ + out = ~(S ^ (D | (P ^ S))); \ + break; \ + case 0x8e: \ + out = S ^ ((S ^ D) & (P ^ D)); \ + break; \ + case 0x8f: \ + out = ~(P & ~(D & S)); \ + break; \ + case 0x90: \ + out = P & ~(D ^ S); \ + break; \ + case 0x91: \ + out = ~(S ^ (D & (P | ~S))); \ + break; \ + case 0x92: \ + out = D ^ (P ^ (S & (D | P))); \ + break; \ + case 0x93: \ + out = ~(S ^ (P & D)); \ + break; \ + case 0x94: \ + out = P ^ (S ^ (D & (P | S))); \ + break; \ + case 0x95: \ + out = ~(D ^ (P & S)); \ + break; \ + case 0x96: \ + out = D ^ (P ^ S); \ + break; \ + case 0x97: \ + out = P ^ (S ^ (D | ~(P | S))); \ + break; \ + case 0x98: \ + out = ~(S ^ (D | ~(P | S))); \ + break; \ + case 0x99: \ + out = ~(D ^ S); \ + break; \ + case 0x9a: \ + out = D ^ (P & ~S); \ + break; \ + case 0x9b: \ + out = ~(S ^ (D & (P | S))); \ + break; \ + case 0x9c: \ + out = S ^ (P & ~D); \ + break; \ + case 0x9d: \ + out = ~(D ^ (S & (P | D))); \ + break; \ + case 0x9e: \ + out = D ^ (S ^ (P | (D & S))); \ + break; \ + case 0x9f: \ + out = ~(P & (D ^ S)); \ + break; \ + case 0xa0: \ + out = D & P; \ + break; \ + case 0xa1: \ + out = ~(P ^ (D | (S & ~P))); \ + break; \ + case 0xa2: \ + out = D & (P | ~S); \ + break; \ + case 0xa3: \ + out = ~(D ^ (P | (S ^ D))); \ + break; \ + case 0xa4: \ + out = ~(P ^ (D | ~(S | P))); \ + break; \ + case 0xa5: \ + out = ~(P ^ D); \ + break; \ + case 0xa6: \ + out = D ^ (S & ~P); \ + break; \ + case 0xa7: \ + out = ~(P ^ (D & (S | P))); \ + break; \ + case 0xa8: \ + out = D & (P | S); \ + break; \ + case 0xa9: \ + out = ~(D ^ (P | S)); \ + break; \ + case 0xaa: \ + out = D; \ + break; \ + case 0xab: \ + out = D | ~(P | S); \ + break; \ + case 0xac: \ + out = S ^ (P & (D ^ S)); \ + break; \ + case 0xad: \ + out = ~(D ^ (P | (S & D))); \ + break; \ + case 0xae: \ + out = D | (S & ~P); \ + break; \ + case 0xaf: \ + out = D | ~P; \ + break; \ + case 0xb0: \ + out = P & (D | ~S); \ + break; \ + case 0xb1: \ + out = ~(P ^ (D | (S ^ P))); \ + break; \ + case 0xb2: \ + out = S ^ ((S ^ P) | (D ^ S)); \ + break; \ + case 0xb3: \ + out = ~(S & ~(D & P)); \ + break; \ + case 0xb4: \ + out = P ^ (S & ~D); \ + break; \ + case 0xb5: \ + out = ~(D ^ (P & (S | D))); \ + break; \ + case 0xb6: \ + out = D ^ (P ^ (S | (D & P))); \ + break; \ + case 0xb7: \ + out = ~(S & (D ^ P)); \ + break; \ + case 0xb8: \ + out = P ^ (S & (D ^ P)); \ + break; \ + case 0xb9: \ + out = ~(D ^ (S | (P & D))); \ + break; \ + case 0xba: \ + out = D | (P & ~S); \ + break; \ + case 0xbb: \ + out = D | ~S; \ + break; \ + case 0xbc: \ + out = S ^ (P & ~(D & S)); \ + break; \ + case 0xbd: \ + out = ~((S ^ D) & (P ^ D)); \ + break; \ + case 0xbe: \ + out = D | (P ^ S); \ + break; \ + case 0xbf: \ + out = D | ~(P & S); \ + break; \ + case 0xc0: \ + out = P & S; \ + break; \ + case 0xc1: \ + out = ~(S ^ (P | (D & ~S))); \ + break; \ + case 0xc2: \ + out = ~(S ^ (P | ~(D | S))); \ + break; \ + case 0xc3: \ + out = ~(P ^ S); \ + break; \ + case 0xc4: \ + out = S & (P | ~D); \ + break; \ + case 0xc5: \ + out = ~(S ^ (P | (D ^ S))); \ + break; \ + case 0xc6: \ + out = S ^ (D & ~P); \ + break; \ + case 0xc7: \ + out = ~(P ^ (S & (D | P))); \ + break; \ + case 0xc8: \ + out = S & (D | P); \ + break; \ + case 0xc9: \ + out = ~(S ^ (P | D)); \ + break; \ + case 0xca: \ + out = D ^ (P & (S ^ D)); \ + break; \ + case 0xcb: \ + out = ~(S ^ (P | (D & S))); \ + break; \ + case 0xcc: \ + out = S; \ + break; \ + case 0xcd: \ + out = S | ~(D | P); \ + break; \ + case 0xce: \ + out = S | (D & ~P); \ + break; \ + case 0xcf: \ + out = S | ~P; \ + break; \ + case 0xd0: \ + out = P & (S | ~D); \ + break; \ + case 0xd1: \ + out = ~(P ^ (S | (D ^ P))); \ + break; \ + case 0xd2: \ + out = P ^ (D & ~S); \ + break; \ + case 0xd3: \ + out = ~(S ^ (P & (D | S))); \ + break; \ + case 0xd4: \ + out = S ^ ((S ^ P) & (P ^ D)); \ + break; \ + case 0xd5: \ + out = ~(D & ~(P & S)); \ + break; \ + case 0xd6: \ + out = P ^ (S ^ (D | (P & S))); \ + break; \ + case 0xd7: \ + out = ~(D & (P ^ S)); \ + break; \ + case 0xd8: \ + out = P ^ (D & (S ^ P)); \ + break; \ + case 0xd9: \ + out = ~(S ^ (D | (P & S))); \ + break; \ + case 0xda: \ + out = D ^ (P & ~(S & D)); \ + break; \ + case 0xdb: \ + out = ~((S ^ P) & (D ^ S)); \ + break; \ + case 0xdc: \ + out = S | (P & ~D); \ + break; \ + case 0xdd: \ + out = S | ~D; \ + break; \ + case 0xde: \ + out = S | (D ^ P); \ + break; \ + case 0xdf: \ + out = S | ~(D & P); \ + break; \ + case 0xe0: \ + out = P & (D | S); \ + break; \ + case 0xe1: \ + out = ~(P ^ (D | S)); \ + break; \ + case 0xe2: \ + out = D ^ (S & (P ^ D)); \ + break; \ + case 0xe3: \ + out = ~(P ^ (S | (D & P))); \ + break; \ + case 0xe4: \ + out = S ^ (D & (P ^ S)); \ + break; \ + case 0xe5: \ + out = ~(P ^ (D | (S & P))); \ + break; \ + case 0xe6: \ + out = S ^ (D & ~(P & S)); \ + break; \ + case 0xe7: \ + out = ~((S ^ P) & (P ^ D)); \ + break; \ + case 0xe8: \ + out = S ^ ((S ^ P) & (D ^ S)); \ + break; \ + case 0xe9: \ + out = ~(D ^ (S ^ (P & ~(D & S)))); \ + break; \ + case 0xea: \ + out = D | (P & S); \ + break; \ + case 0xeb: \ + out = D | ~(P ^ S); \ + break; \ + case 0xec: \ + out = S | (D & P); \ + break; \ + case 0xed: \ + out = S | ~(D ^ P); \ + break; \ + case 0xee: \ + out = D | S; \ + break; \ + case 0xef: \ + out = S | (D | ~P); \ + break; \ + case 0xf0: \ + out = P; \ + break; \ + case 0xf1: \ + out = P | ~(D | S); \ + break; \ + case 0xf2: \ + out = P | (D & ~S); \ + break; \ + case 0xf3: \ + out = P | ~S; \ + break; \ + case 0xf4: \ + out = P | (S & ~D); \ + break; \ + case 0xf5: \ + out = P | ~D; \ + break; \ + case 0xf6: \ + out = P | (D ^ S); \ + break; \ + case 0xf7: \ + out = P | ~(D & S); \ + break; \ + case 0xf8: \ + out = P | (D & S); \ + break; \ + case 0xf9: \ + out = P | ~(D ^ S); \ + break; \ + case 0xfa: \ + out = D | P; \ + break; \ + case 0xfb: \ + out = D | (P | ~S); \ + break; \ + case 0xfc: \ + out = P | S; \ + break; \ + case 0xfd: \ + out = P | (S | ~D); \ + break; \ + case 0xfe: \ + out = D | (P | S); \ + break; \ + case 0xff: \ + out = ~0; \ + break; \ + } \ + } + +#define MIX() \ + do { \ + out = 0; \ + ROPMIX(tgui->accel.rop, dst_dat, pat_dat, src_dat, out); \ } while (0) -#define WRITE(addr, dat) \ - if (tgui->accel.bpp == 0) { \ - svga->vram[(addr) &tgui->vram_mask] = dat; \ +#define WRITE(addr, dat) \ + if (tgui->accel.bpp == 0) { \ + svga->vram[(addr) &tgui->vram_mask] = dat; \ svga->changedvram[((addr) & (tgui->vram_mask)) >> 12] = svga->monitor->mon_changeframecount; \ - } else if (tgui->accel.bpp == 1) { \ - vram_w[(addr) & (tgui->vram_mask >> 1)] = dat; \ + } else if (tgui->accel.bpp == 1) { \ + vram_w[(addr) & (tgui->vram_mask >> 1)] = dat; \ svga->changedvram[((addr) & (tgui->vram_mask >> 1)) >> 11] = svga->monitor->mon_changeframecount; \ - } else { \ - vram_l[(addr) & (tgui->vram_mask >> 2)] = dat; \ + } else { \ + vram_l[(addr) & (tgui->vram_mask >> 2)] = dat; \ svga->changedvram[((addr) & (tgui->vram_mask >> 2)) >> 10] = svga->monitor->mon_changeframecount; \ } @@ -1487,8 +2258,6 @@ tgui_accel_command(int count, uint32_t cpu_dat, tgui_t *tgui) const uint32_t *pattern_data; int x; int y; - int c; - int d; uint32_t out; uint32_t src_dat = 0; uint32_t dst_dat; @@ -1513,6 +2282,8 @@ tgui_accel_command(int count, uint32_t cpu_dat, tgui_t *tgui) if (count == -1) tgui->accel.x = tgui->accel.y = 0; + tgui->accel.pattern_32_idx = 0; + if (tgui->accel.flags & TGUI_SOLIDFILL) { for (y = 0; y < 8; y++) { for (x = 0; x < 8; x++) { @@ -1531,22 +2302,21 @@ tgui_accel_command(int count, uint32_t cpu_dat, tgui_t *tgui) if (tgui->accel.bpp == 0) { for (y = 0; y < 8; y++) { for (x = 0; x < 8; x++) { - tgui->accel.pattern_8[(y * 8) + (7 - x)] = tgui->accel.pattern[x + y * 8]; + tgui->accel.pattern_8[(y * 8) + x] = tgui->accel.pattern[x + y * 8]; } } pattern_data = tgui->accel.pattern_8; } else if (tgui->accel.bpp == 1) { for (y = 0; y < 8; y++) { for (x = 0; x < 8; x++) { - tgui->accel.pattern_16[(y * 8) + (7 - x)] = tgui->accel.pattern[x * 2 + y * 16] | (tgui->accel.pattern[x * 2 + y * 16 + 1] << 8); + tgui->accel.pattern_16[(y * 8) + x] = tgui->accel.pattern[x * 2 + y * 16] | (tgui->accel.pattern[x * 2 + y * 16 + 1] << 8); } } pattern_data = tgui->accel.pattern_16; } else { - for (y = 0; y < 4; y++) { + for (y = 0; y < 8; y++) { for (x = 0; x < 8; x++) { - tgui->accel.pattern_32[(y * 8) + (7 - x)] = tgui->accel.pattern[x * 4 + y * 32] | (tgui->accel.pattern[x * 4 + y * 32 + 1] << 8) | (tgui->accel.pattern[x * 4 + y * 32 + 2] << 16) | (tgui->accel.pattern[x * 4 + y * 32 + 3] << 24); - tgui->accel.pattern_32[((y + 4) * 8) + (7 - x)] = tgui->accel.pattern[x * 4 + y * 32] | (tgui->accel.pattern[x * 4 + y * 32 + 1] << 8) | (tgui->accel.pattern[x * 4 + y * 32 + 2] << 16) | (tgui->accel.pattern[x * 4 + y * 32 + 3] << 24); + tgui->accel.pattern_32[(y * 8) + x] = tgui->accel.pattern_32bpp[x * 4 + y * 32] | (tgui->accel.pattern_32bpp[x * 4 + y * 32 + 1] << 8) | (tgui->accel.pattern_32bpp[x * 4 + y * 32 + 2] << 16) | (tgui->accel.pattern_32bpp[x * 4 + y * 32 + 3] << 24); } } pattern_data = tgui->accel.pattern_32; @@ -1629,6 +2399,7 @@ tgui_accel_command(int count, uint32_t cpu_dat, tgui_t *tgui) count -= 3; } + READ(tgui->accel.dst, dst_dat); pat_dat = pattern_data[((tgui->accel.pat_y & 7) * 8) + (tgui->accel.pat_x & 7)]; @@ -2115,7 +2886,9 @@ tgui_accel_out(uint16_t addr, uint8_t val, void *priv) case 0x2123: tgui->accel.ger22 = (tgui->accel.ger22 & 0xff) | (val << 8); - //pclog("Pitch IO23: val = %02x, rowoffset = %x.\n", tgui->accel.ger22, svga->crtc[0x13]); +#if 0 + pclog("Pitch IO23: val = %02x, rowoffset = %x.\n", tgui->accel.ger22, svga->crtc[0x13]); +#endif switch (svga->bpp) { case 8: case 24: @@ -2423,6 +3196,8 @@ tgui_accel_out(uint16_t addr, uint8_t val, void *priv) case 0x21fe: case 0x21ff: tgui->accel.pattern[addr & 0x7f] = val; + tgui->accel.pattern_32bpp[tgui->accel.pattern_32_idx] = val; + tgui->accel.pattern_32_idx = (tgui->accel.pattern_32_idx + 1) & 0xff; break; default: @@ -3364,56 +4139,41 @@ tgui_force_redraw(void *priv) // clang-format off static const device_config_t tgui9440_config[] = { { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "1 MB", - .value = 1 - }, - { - .description = "2 MB", - .value = 2 - }, - { - .description = "" - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "1 MB", .value = 1 }, + { .description = "2 MB", .value = 2 }, + { .description = "" } }, - .default_int = 2 + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; static const device_config_t tgui96xx_config[] = { { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "1 MB", - .value = 1 - }, - { - .description = "2 MB", - .value = 2 - }, - { - .description = "4 MB", - .value = 4 - }, - { - .description = "" - } + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 4, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "1 MB", .value = 1 }, + { .description = "2 MB", .value = 2 }, + { .description = "4 MB", .value = 4 }, + { .description = "" } }, - .default_int = 4 + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } }; // clang-format on @@ -3425,7 +4185,7 @@ const device_t tgui9400cxi_device = { .init = tgui_init, .close = tgui_close, .reset = NULL, - { .available = tgui9400cxi_available }, + .available = tgui9400cxi_available, .speed_changed = tgui_speed_changed, .force_redraw = tgui_force_redraw, .config = tgui9440_config @@ -3439,7 +4199,7 @@ const device_t tgui9440_vlb_device = { .init = tgui_init, .close = tgui_close, .reset = NULL, - { .available = tgui9440_vlb_available }, + .available = tgui9440_vlb_available, .speed_changed = tgui_speed_changed, .force_redraw = tgui_force_redraw, .config = tgui9440_config @@ -3453,7 +4213,7 @@ const device_t tgui9440_pci_device = { .init = tgui_init, .close = tgui_close, .reset = NULL, - { .available = tgui9440_pci_available }, + .available = tgui9440_pci_available, .speed_changed = tgui_speed_changed, .force_redraw = tgui_force_redraw, .config = tgui9440_config @@ -3467,7 +4227,7 @@ const device_t tgui9440_onboard_pci_device = { .init = tgui_init, .close = tgui_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = tgui_speed_changed, .force_redraw = tgui_force_redraw, .config = tgui9440_config @@ -3481,7 +4241,7 @@ const device_t tgui9660_pci_device = { .init = tgui_init, .close = tgui_close, .reset = NULL, - { .available = tgui96xx_available }, + .available = tgui96xx_available, .speed_changed = tgui_speed_changed, .force_redraw = tgui_force_redraw, .config = tgui96xx_config @@ -3495,7 +4255,7 @@ const device_t tgui9660_onboard_pci_device = { .init = tgui_init, .close = tgui_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = tgui_speed_changed, .force_redraw = tgui_force_redraw, .config = tgui96xx_config @@ -3509,7 +4269,7 @@ const device_t tgui9680_pci_device = { .init = tgui_init, .close = tgui_close, .reset = NULL, - { .available = tgui96xx_available }, + .available = tgui96xx_available, .speed_changed = tgui_speed_changed, .force_redraw = tgui_force_redraw, .config = tgui96xx_config diff --git a/src/video/vid_ti_cf62011.c b/src/video/vid_ti_cf62011.c index f23cb7396..fcc046cb4 100644 --- a/src/video/vid_ti_cf62011.c +++ b/src/video/vid_ti_cf62011.c @@ -266,7 +266,7 @@ const device_t ibm_ps1_2121_device = { .init = vid_init, .close = vid_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = vid_speed_changed, .force_redraw = vid_force_redraw, .config = NULL diff --git a/src/video/vid_tvga.c b/src/video/vid_tvga.c index eb0d1a780..51ab132ca 100644 --- a/src/video/vid_tvga.c +++ b/src/video/vid_tvga.c @@ -168,7 +168,7 @@ tvga_out(uint16_t addr, uint8_t val, void *priv) 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); + svga->memaddr_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5); } else { svga->fullchange = changeframecount; svga_recalctimings(svga); @@ -293,15 +293,15 @@ tvga_recalctimings(svga_t *svga) svga->hdisp = (svga->crtc[1] + 1) * 8; if ((svga->crtc[0x1e] & 0xA0) == 0xA0) - svga->ma_latch |= 0x10000; + svga->memaddr_latch |= 0x10000; if ((svga->crtc[0x27] & 0x01) == 0x01) - svga->ma_latch |= 0x20000; + svga->memaddr_latch |= 0x20000; if ((svga->crtc[0x27] & 0x02) == 0x02) - svga->ma_latch |= 0x40000; + svga->memaddr_latch |= 0x40000; if (tvga->oldctrl2 & 0x10) { svga->rowoffset <<= 1; - svga->ma_latch <<= 1; + svga->memaddr_latch <<= 1; } if (svga->gdcreg[0xf] & 0x08) { @@ -521,101 +521,92 @@ tvga_force_redraw(void *priv) static const device_config_t tvga_config[] = { // clang-format off { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .default_int = 1024, - .selection = { - { - .description = "256 KB", - .value = 256 - }, - { - .description = "512 KB", - .value = 512 - }, - { - .description = "1 MB", - .value = 1024 - }, + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 1024, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "256 KB", .value = 256 }, + { .description = "512 KB", .value = 512 }, + { .description = "1 MB", .value = 1024 }, /*Chip supports 2mb, but drivers are buggy*/ - { - .description = "" - } - } + { .description = "" } + }, + .bios = { { 0 } } }, - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format off }; const device_t tvga8900b_device = { - .name = "Trident TVGA 8900B", + .name = "Trident TVGA 8900B", .internal_name = "tvga8900b", - .flags = DEVICE_ISA, - .local = TVGA8900B_ID, - .init = tvga_init, - .close = tvga_close, - .reset = NULL, - { .available = tvga8900b_available }, + .flags = DEVICE_ISA, + .local = TVGA8900B_ID, + .init = tvga_init, + .close = tvga_close, + .reset = NULL, + .available = tvga8900b_available, .speed_changed = tvga_speed_changed, - .force_redraw = tvga_force_redraw, - .config = tvga_config + .force_redraw = tvga_force_redraw, + .config = tvga_config }; const device_t tvga8900d_device = { - .name = "Trident TVGA 8900D", + .name = "Trident TVGA 8900D", .internal_name = "tvga8900d", - .flags = DEVICE_ISA, - .local = TVGA8900CLD_ID, - .init = tvga_init, - .close = tvga_close, - .reset = NULL, - { .available = tvga8900d_available }, + .flags = DEVICE_ISA, + .local = TVGA8900CLD_ID, + .init = tvga_init, + .close = tvga_close, + .reset = NULL, + .available = tvga8900d_available, .speed_changed = tvga_speed_changed, - .force_redraw = tvga_force_redraw, - .config = tvga_config + .force_redraw = tvga_force_redraw, + .config = tvga_config }; const device_t tvga8900dr_device = { - .name = "Trident TVGA 8900D-R", + .name = "Trident TVGA 8900D-R", .internal_name = "tvga8900dr", - .flags = DEVICE_ISA, - .local = TVGA8900CLD_ID | 0x0100, - .init = tvga_init, - .close = tvga_close, - .reset = NULL, - { .available = tvga8900dr_available }, + .flags = DEVICE_ISA, + .local = TVGA8900CLD_ID | 0x0100, + .init = tvga_init, + .close = tvga_close, + .reset = NULL, + .available = tvga8900dr_available, .speed_changed = tvga_speed_changed, - .force_redraw = tvga_force_redraw, - .config = tvga_config + .force_redraw = tvga_force_redraw, + .config = tvga_config }; const device_t tvga9000b_device = { - .name = "Trident TVGA 9000B", + .name = "Trident TVGA 9000B", .internal_name = "tvga9000b", - .flags = DEVICE_ISA, - .local = TVGA9000B_ID, - .init = tvga_init, - .close = tvga_close, - .reset = NULL, - { .available = tvga9000b_available }, + .flags = DEVICE_ISA, + .local = TVGA9000B_ID, + .init = tvga_init, + .close = tvga_close, + .reset = NULL, + .available = tvga9000b_available, .speed_changed = tvga_speed_changed, - .force_redraw = tvga_force_redraw, - .config = NULL + .force_redraw = tvga_force_redraw, + .config = NULL }; const device_t nec_sv9000_device = { - .name = "NEC SV9000 (Trident TVGA 9000B)", + .name = "NEC SV9000 (Trident TVGA 9000B)", .internal_name = "nec_sv9000", - .flags = DEVICE_ISA, - .local = TVGA9000B_ID | 0x100, - .init = tvga_init, - .close = tvga_close, - .reset = NULL, - { .available = tvga9000b_nec_sv9000_available }, + .flags = DEVICE_ISA, + .local = TVGA9000B_ID | 0x100, + .init = tvga_init, + .close = tvga_close, + .reset = NULL, + .available = tvga9000b_nec_sv9000_available, .speed_changed = tvga_speed_changed, - .force_redraw = tvga_force_redraw, - .config = NULL + .force_redraw = tvga_force_redraw, + .config = NULL }; diff --git a/src/video/vid_vga.c b/src/video/vid_vga.c index 881a3c6fd..4cde5ba01 100644 --- a/src/video/vid_vga.c +++ b/src/video/vid_vga.c @@ -31,7 +31,8 @@ #include <86box/vid_svga.h> #include <86box/vid_vga.h> -static video_timings_t timing_vga = { .type = VIDEO_ISA, .write_b = 8, .write_w = 16, .write_l = 32, .read_b = 8, .read_w = 16, .read_l = 32 }; +video_timings_t timing_vga = { .type = VIDEO_ISA, .write_b = 8, .write_w = 16, .write_l = 32, .read_b = 8, .read_w = 16, .read_l = 32 }; + static video_timings_t timing_ps1_svga_isa = { .type = VIDEO_ISA, .write_b = 6, .write_w = 8, .write_l = 16, .read_b = 6, .read_w = 8, .read_l = 16 }; 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 }; @@ -62,7 +63,7 @@ vga_out(uint16_t addr, uint8_t val, void *priv) 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); + svga->memaddr_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5); } else { svga->fullchange = changeframecount; svga_recalctimings(svga); @@ -104,27 +105,65 @@ vga_in(uint16_t addr, void *priv) return temp; } -static void * -vga_init(const device_t *info) +void vga_disable(void* p) { - vga_t *vga = malloc(sizeof(vga_t)); - memset(vga, 0, sizeof(vga_t)); + vga_t* vga = (vga_t*)p; + svga_t* svga = &vga->svga; - rom_init(&vga->bios_rom, "roms/video/vga/ibm_vga.bin", 0xc0000, 0x8000, 0x7fff, 0x2000, MEM_MAPPING_EXTERNAL); + io_removehandler(0x03a0, 0x0040, vga_in, NULL, NULL, vga_out, NULL, NULL, vga); + mem_mapping_disable(&svga->mapping); + svga->vga_enabled = 0; +} - video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_vga); +void vga_enable(void* p) +{ + vga_t* vga = (vga_t*)p; + svga_t* svga = &vga->svga; + io_sethandler(0x03c0, 0x0020, vga_in, NULL, NULL, vga_out, NULL, NULL, vga); + if (!(svga->miscout & 1)) + io_sethandler(0x03a0, 0x0020, vga_in, NULL, NULL, vga_out, NULL, NULL, vga); + + mem_mapping_enable(&svga->mapping); + svga->vga_enabled = 1; +} + +int vga_isenabled(void* p) +{ + vga_t* vga = (vga_t*)p; + svga_t* svga = &vga->svga; + + return svga->vga_enabled; +} + +void +vga_init(const device_t *info, vga_t *vga, int enabled) +{ svga_init(info, &vga->svga, vga, 1 << 18, /*256kb*/ NULL, vga_in, vga_out, NULL, NULL); - io_sethandler(0x03c0, 0x0020, vga_in, NULL, NULL, vga_out, NULL, NULL, vga); - vga->svga.bpp = 8; vga->svga.miscout = 1; + vga->svga.vga_enabled = enabled; +} + +static void * +vga_standalone_init(const device_t *info) +{ + vga_t *vga = calloc(1, sizeof(vga_t)); + + rom_init(&vga->bios_rom, "roms/video/vga/ibm_vga.bin", 0xc0000, 0x8000, 0x7fff, 0x2000, MEM_MAPPING_EXTERNAL); + + video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_vga); + + vga_init(info, vga, 0); + + io_sethandler(0x03c0, 0x0020, vga_in, NULL, NULL, vga_out, NULL, NULL, vga); + return vga; } @@ -132,25 +171,17 @@ vga_init(const device_t *info) void * ps1vga_init(const device_t *info) { - vga_t *vga = malloc(sizeof(vga_t)); - memset(vga, 0, sizeof(vga_t)); + vga_t *vga = calloc(1, sizeof(vga_t)); if (info->flags & DEVICE_MCA) video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_ps1_svga_mca); else video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_ps1_svga_isa); - svga_init(info, &vga->svga, vga, 1 << 18, /*256kb*/ - NULL, - vga_in, vga_out, - NULL, - NULL); + vga_init(info, vga, 1); io_sethandler(0x03c0, 0x0020, vga_in, NULL, NULL, vga_out, NULL, NULL, vga); - vga->svga.bpp = 8; - vga->svga.miscout = 1; - return vga; } @@ -191,10 +222,10 @@ const device_t vga_device = { .internal_name = "vga", .flags = DEVICE_ISA, .local = 0, - .init = vga_init, + .init = vga_standalone_init, .close = vga_close, .reset = NULL, - { .available = vga_available }, + .available = vga_available, .speed_changed = vga_speed_changed, .force_redraw = vga_force_redraw, .config = NULL @@ -208,7 +239,7 @@ const device_t ps1vga_device = { .init = ps1vga_init, .close = vga_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = vga_speed_changed, .force_redraw = vga_force_redraw, .config = NULL @@ -222,7 +253,7 @@ const device_t ps1vga_mca_device = { .init = ps1vga_init, .close = vga_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = vga_speed_changed, .force_redraw = vga_force_redraw, .config = NULL diff --git a/src/video/vid_voodoo.c b/src/video/vid_voodoo.c index a9981333b..57ddbf64d 100644 --- a/src/video/vid_voodoo.c +++ b/src/video/vid_voodoo.c @@ -530,6 +530,7 @@ voodoo_writel(uint32_t addr, uint32_t val, void *priv) voodoo_recalc(voodoo); voodoo->front_offset = voodoo->params.front_offset; } + svga_recalctimings(voodoo->svga); } break; case SST_fbiInit1: @@ -1308,124 +1309,124 @@ voodoo_close(void *priv) static const device_config_t voodoo_config[] = { // clang-format off { - .name = "type", - .description = "Voodoo type", - .type = CONFIG_SELECTION, + .name = "type", + .description = "Voodoo type", + .type = CONFIG_SELECTION, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, .selection = { - { - .description = "3Dfx Voodoo Graphics", - .value = VOODOO_1 - }, - { - .description = "Obsidian SB50 + Amethyst (2 TMUs)", - .value = VOODOO_SB50 - }, - { - .description = "3Dfx Voodoo 2", - .value = VOODOO_2 - }, - { - .description = "" - } + { .description = "3Dfx Voodoo Graphics", .value = VOODOO_1 }, + { .description = "Obsidian SB50 + Amethyst (2 TMUs)", .value = VOODOO_SB50 }, + { .description = "3Dfx Voodoo 2", .value = VOODOO_2 }, + { .description = "" } }, - .default_int = 0 + .bios = { { 0 } } }, { - .name = "framebuffer_memory", - .description = "Framebuffer memory size", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "2 MB", - .value = 2 - }, - { - .description = "4 MB", - .value = 4 - }, - { - .description = "" - } + .name = "framebuffer_memory", + .description = "Framebuffer memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "2 MB", .value = 2 }, + { .description = "4 MB", .value = 4 }, + { .description = "" } }, - .default_int = 2 + .bios = { { 0 } } }, { - .name = "texture_memory", - .description = "Texture memory size", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "2 MB", - .value = 2 - }, - { - .description = "4 MB", - .value = 4 - }, - { - .description = "" - } + .name = "texture_memory", + .description = "Texture memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "2 MB", .value = 2 }, + { .description = "4 MB", .value = 4 }, + { .description = "" } }, - .default_int = 2 + .bios = { { 0 } } }, { - .name = "bilinear", - .description = "Bilinear filtering", - .type = CONFIG_BINARY, - .default_int = 1 + .name = "bilinear", + .description = "Bilinear filtering", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "dithersub", - .description = "Dither subtraction", - .type = CONFIG_BINARY, - .default_int = 1 + .name = "dithersub", + .description = "Dither subtraction", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "dacfilter", - .description = "Screen Filter", - .type = CONFIG_BINARY, - .default_int = 0 + .name = "dacfilter", + .description = "Screen Filter", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, { - .name = "render_threads", - .description = "Render threads", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "1", - .value = 1 - }, - { - .description = "2", - .value = 2 - }, - { - .description = "4", - .value = 4 - }, - { - .description = "" - } + .name = "render_threads", + .description = "Render threads", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "1", .value = 1 }, + { .description = "2", .value = 2 }, + { .description = "4", .value = 4 }, + { .description = "" } }, - .default_int = 2 + .bios = { { 0 } } }, { - .name = "sli", - .description = "SLI", - .type = CONFIG_BINARY, - .default_int = 0 + .name = "sli", + .description = "SLI", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, #ifndef NO_CODEGEN { - .name = "recompiler", - .description = "Dynamic Recompiler", - .type = CONFIG_BINARY, - .default_int = 1 + .name = "recompiler", + .description = "Dynamic Recompiler", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } }, #endif - { - .type = CONFIG_END - } + { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; @@ -1437,7 +1438,7 @@ const device_t voodoo_device = { .init = voodoo_init, .close = voodoo_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = voodoo_speed_changed, .force_redraw = voodoo_force_blit, .config = voodoo_config diff --git a/src/video/vid_voodoo_banshee.c b/src/video/vid_voodoo_banshee.c index 4fa27e2e4..4bcf8a479 100644 --- a/src/video/vid_voodoo_banshee.c +++ b/src/video/vid_voodoo_banshee.c @@ -30,6 +30,7 @@ #include <86box/device.h> #include <86box/io.h> #include <86box/mem.h> +#include <86box/dma.h> #include <86box/pci.h> #include <86box/rom.h> #include <86box/timer.h> @@ -43,12 +44,15 @@ #include <86box/vid_svga_render.h> #include <86box/vid_voodoo_common.h> #include <86box/vid_voodoo_display.h> +#include <86box/vid_voodoo_fb.h> #include <86box/vid_voodoo_fifo.h> #include <86box/vid_voodoo_regs.h> #include <86box/vid_voodoo_render.h> +#include <86box/vid_voodoo_texture.h> #define ROM_BANSHEE "roms/video/voodoo/Pci_sg.rom" #define ROM_CREATIVE_BANSHEE "roms/video/voodoo/BlasterPCI.rom" +#define ROM_QUANTUM3D_RAVEN "roms/video/voodoo/RVPD0224.rom" #define ROM_VOODOO3_1000 "roms/video/voodoo/1k11sg.rom" #define ROM_VOODOO3_2000 "roms/video/voodoo/2k11sd.rom" #define ROM_VOODOO3_3000 "roms/video/voodoo/3k12sd.rom" @@ -75,6 +79,7 @@ static uint8_t vb_filter_bx_g[256][256]; enum { TYPE_BANSHEE = 0, + TYPE_QUANTUM3D_RAVEN, TYPE_V3_1000, TYPE_V3_2000, TYPE_V3_3000, @@ -220,6 +225,7 @@ enum { Agp_agpHostAddressHigh = 0x08, Agp_agpGraphicsAddress = 0x0C, Agp_agpGraphicsStride = 0x10, + Agp_agpMoveCMD = 0x14, }; #define VGAINIT0_RAMDAC_8BIT (1 << 2) @@ -379,7 +385,7 @@ banshee_out(uint16_t addr, uint8_t val, void *priv) if (svga->crtcreg < 0xe || svga->crtcreg > 0x11 || (svga->crtcreg == 0x11 && old != val)) { 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); + svga->memaddr_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5); } else { svga->fullchange = changeframecount; svga_recalctimings(svga); @@ -441,7 +447,9 @@ banshee_updatemapping(banshee_t *banshee) svga_t *svga = &banshee->svga; if (!(banshee->pci_regs[PCI_REG_COMMAND] & PCI_COMMAND_MEM)) { - // banshee_log("Update mapping - PCI disabled\n"); +#if 0 + banshee_log("Update mapping - PCI disabled\n"); +#endif mem_mapping_disable(&svga->mapping); mem_mapping_disable(&banshee->linear_mapping); mem_mapping_disable(&banshee->reg_mapping_low); @@ -480,7 +488,7 @@ banshee_updatemapping(banshee_t *banshee) } uint32_t -banshee_conv_16to32(svga_t* svga, uint16_t color, uint8_t bpp) +banshee_conv_16to32(svga_t* svga, uint16_t color, UNUSED(uint8_t bpp)) { banshee_t *banshee = (banshee_t *) svga->priv; uint32_t ret = 0x00000000; @@ -655,7 +663,7 @@ banshee_recalctimings(svga_t *svga) svga->rowoffset = ((banshee->vidDesktopOverlayStride & 0x3fff) * 128) >> 3; else svga->rowoffset = (banshee->vidDesktopOverlayStride & 0x3fff) >> 3; - svga->ma_latch = banshee->vidDesktopStartAddr >> 2; + svga->memaddr_latch = banshee->vidDesktopStartAddr >> 2; banshee->desktop_stride_tiled = (banshee->vidDesktopOverlayStride & 0x3fff) * 128 * 32; #if 0 banshee_log("Extended shift out %i rowoffset=%i %02x\n", VIDPROCCFG_DESKTOP_PIX_FORMAT, svga->rowoffset, svga->crtc[1]); @@ -1082,7 +1090,9 @@ banshee_ext_in(uint16_t addr, void *priv) break; } - // banshee_log("banshee_ext_in: addr=%04x val=%02x\n", addr, ret); +#if 0 + banshee_log("banshee_ext_in: addr=%04x val=%02x\n", addr, ret); +#endif return ret; } @@ -1273,7 +1283,9 @@ banshee_ext_inl(uint16_t addr, void *priv) break; default: - // fatal("bad banshee_ext_inl: addr=%04x\n", addr); +#if 0 + fatal("bad banshee_ext_inl: addr=%04x\n", addr); +#endif break; } @@ -1334,17 +1346,23 @@ banshee_cmd_read(banshee_t *banshee, uint32_t addr) case cmdBaseAddr0: ret = voodoo->cmdfifo_base >> 12; - // banshee_log("Read cmdfifo_base %08x\n", ret); +#if 0 + banshee_log("Read cmdfifo_base %08x\n", ret); +#endif break; case cmdRdPtrL0: ret = voodoo->cmdfifo_rp; - // banshee_log("Read cmdfifo_rp %08x\n", ret); +#if 0 + banshee_log("Read cmdfifo_rp %08x\n", ret); +#endif break; case cmdFifoDepth0: ret = voodoo->cmdfifo_depth_wr - voodoo->cmdfifo_depth_rd; - // banshee_log("Read cmdfifo_depth %08x\n", ret); +#if 0 + banshee_log("Read cmdfifo_depth %08x\n", ret); +#endif break; case cmdStatus0: @@ -1353,21 +1371,31 @@ banshee_cmd_read(banshee_t *banshee, uint32_t addr) case cmdBaseSize0: ret = voodoo->cmdfifo_size; + if (voodoo->cmdfifo_enabled) + ret |= 0x100; + if (voodoo->cmdfifo_in_agp) + ret |= 0x200; break; case cmdBaseAddr1: ret = voodoo->cmdfifo_base_2 >> 12; - // banshee_log("Read cmdfifo_base %08x\n", ret); +#if 0 + banshee_log("Read cmdfifo_base %08x\n", ret); +#endif break; case cmdRdPtrL1: ret = voodoo->cmdfifo_rp_2; - // banshee_log("Read cmdfifo_rp %08x\n", ret); +#if 0 + banshee_log("Read cmdfifo_rp %08x\n", ret); +#endif break; case cmdFifoDepth1: ret = voodoo->cmdfifo_depth_wr_2 - voodoo->cmdfifo_depth_rd_2; - // banshee_log("Read cmdfifo_depth %08x\n", ret); +#if 0 + banshee_log("Read cmdfifo_depth %08x\n", ret); +#endif break; case cmdStatus1: @@ -1376,6 +1404,10 @@ banshee_cmd_read(banshee_t *banshee, uint32_t addr) case cmdBaseSize1: ret = voodoo->cmdfifo_size_2; + if (voodoo->cmdfifo_enabled_2) + ret |= 0x100; + if (voodoo->cmdfifo_in_agp_2) + ret |= 0x200; break; case 0x108: @@ -1595,10 +1627,11 @@ banshee_reg_writew(uint32_t addr, uint16_t val, void *priv) } } -static void -banshee_cmd_write(banshee_t *banshee, uint32_t addr, uint32_t val) +void +banshee_cmd_write(void *priv, uint32_t addr, uint32_t val) { - voodoo_t *voodoo = banshee->voodoo; + banshee_t *banshee = (banshee_t *) priv; + voodoo_t *voodoo = banshee->voodoo; #if 0 banshee_log("banshee_cmd_write: addr=%03x val=%08x\n", addr & 0x1fc, val); #endif @@ -1623,6 +1656,62 @@ banshee_cmd_write(banshee_t *banshee, uint32_t addr, uint32_t val) banshee->agpReqSize = val; break; + case Agp_agpMoveCMD: { + uint32_t src_addr = banshee->agpHostAddressLow; + uint32_t src_width = banshee->agpHostAddressHigh & 0x3fff; + uint32_t src_stride = (banshee->agpHostAddressHigh >> 14) & 0x3fff; + uint32_t src_end = src_addr + (banshee->agpReqSize & 0xfffff); /* don't know whether or not stride is accounted for! */ + uint32_t dest_addr = banshee->agpGraphicsAddress & 0x3ffffff; + uint32_t dest_stride = banshee->agpGraphicsStride & 0x7fff; +#if 0 + banshee_log("AGP: %d bytes W%d from %08x S%d to %d:%08x S%d\n", src_end - src_addr, src_width, src_addr, src_stride, (val >> 3) & 3, dest_addr, dest_stride); +#endif + switch ((val >> 3) & 3) { + case 0: /*Linear framebuffer (Banshee)*/ + case 1: /*Planar YUV*/ + if (voodoo->texture_present[0][(dest_addr & voodoo->texture_mask) >> TEX_DIRTY_SHIFT]) { +#if 0 + banshee_log("texture_present at %08x %i\n", dest_addr, (dest_addr & voodoo->texture_mask) >> TEX_DIRTY_SHIFT); +#endif + flush_texture_cache(voodoo, dest_addr & voodoo->texture_mask, 0); + } + if (voodoo->texture_present[1][(dest_addr & voodoo->texture_mask) >> TEX_DIRTY_SHIFT]) { +#if 0 + banshee_log("texture_present at %08x %i\n", dest_addr, (dest_addr & voodoo->texture_mask) >> TEX_DIRTY_SHIFT); +#endif + flush_texture_cache(voodoo, dest_addr & voodoo->texture_mask, 1); + } + while ((src_addr < src_end) && (dest_addr <= voodoo->fb_mask)) { + dma_bm_read(src_addr, &voodoo->fb_mem[dest_addr], MIN(src_width, voodoo->fb_mask - dest_addr), 4); + src_addr += src_stride; + dest_addr += dest_stride; + } + break; + case 2: /*Framebuffer*/ + src_width &= ~3; + while (src_addr < src_end) { + for (uint32_t i = 0; i < src_width; i += 4) + voodoo_fb_writel(dest_addr + i, mem_readl_phys(src_addr + i), voodoo); + src_addr += src_stride; + dest_addr += dest_stride; + } + break; + case 3: /*Texture*/ + src_width &= ~3; + while (src_addr < src_end) { + for (uint32_t i = 0; i < src_width; i += 4) + voodoo_tex_writel(dest_addr + i, mem_readl_phys(src_addr + i), voodoo); + src_addr += src_stride; + dest_addr += dest_stride; + } + break; + + default: + break; + } + break; + } + case cmdBaseAddr0: voodoo->cmdfifo_base = (val & 0xfff) << 12; voodoo->cmdfifo_end = voodoo->cmdfifo_base + (((voodoo->cmdfifo_size & 0xff) + 1) << 12); @@ -1637,6 +1726,7 @@ 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*/ + voodoo->cmdfifo_in_agp = val & 0x200; #if 0 banshee_log("cmdfifo_base=%08x cmdfifo_end=%08x\n", voodoo->cmdfifo_base, voodoo->cmdfifo_end); #endif @@ -1676,6 +1766,7 @@ banshee_cmd_write(banshee_t *banshee, uint32_t addr, uint32_t val) voodoo->cmdfifo_enabled_2 = val & 0x100; if (!voodoo->cmdfifo_enabled_2) voodoo->cmdfifo_in_sub_2 = 0; /*Not sure exactly when this should be reset*/ + voodoo->cmdfifo_in_agp_2 = val & 0x200; #if 0 banshee_log("cmdfifo_base=%08x cmdfifo_end=%08x\n", voodoo->cmdfifo_base, voodoo->cmdfifo_end); #endif @@ -2833,7 +2924,9 @@ banshee_pci_read(int func, int addr, void *priv) if (func) return 0xff; - // banshee_log("Banshee PCI read %08X ", addr); +#if 0 + banshee_log("Banshee PCI read %08X ", addr); +#endif switch (addr) { case 0x00: ret = 0x1a; @@ -3158,192 +3251,6 @@ banshee_pci_write(int func, int addr, uint8_t val, void *priv) } } -// clang-format off -static const device_config_t banshee_sgram_config[] = { - { - .name = "memory", - .description = "Memory size", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "8 MB", - .value = 8 - }, - { - .description = "16 MB", - .value = 16 - }, - { - .description = "" - } - }, - .default_int = 16 - }, - { - .name = "bilinear", - .description = "Bilinear filtering", - .type = CONFIG_BINARY, - .default_int = 1 - }, - { - .name = "dithersub", - .description = "Dither subtraction", - .type = CONFIG_BINARY, - .default_int = 1 - }, - { - .name = "dacfilter", - .description = "Screen Filter", - .type = CONFIG_BINARY, - .default_int = 0 - }, - { - .name = "render_threads", - .description = "Render threads", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "1", - .value = 1 - }, - { - .description = "2", - .value = 2 - }, - { - .description = "4", - .value = 4 - }, - { - .description = "" - } - }, - .default_int = 2 - }, -#ifndef NO_CODEGEN - { - .name = "recompiler", - .description = "Dynamic Recompiler", - .type = CONFIG_BINARY, - .default_int = 1 - }, -#endif - { - .type = CONFIG_END - } -}; - -static const device_config_t banshee_sgram_16mbonly_config[] = { - { - .name = "bilinear", - .description = "Bilinear filtering", - .type = CONFIG_BINARY, - .default_int = 1 - }, - { - .name = "dithersub", - .description = "Dither subtraction", - .type = CONFIG_BINARY, - .default_int = 1 - }, - { - .name = "dacfilter", - .description = "Screen Filter", - .type = CONFIG_BINARY, - .default_int = 0 - }, - { - .name = "render_threads", - .description = "Render threads", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "1", - .value = 1 - }, - { - .description = "2", - .value = 2 - }, - { - .description = "4", - .value = 4 - }, - { - .description = "" - } - }, - .default_int = 2 - }, -#ifndef NO_CODEGEN - { - .name = "recompiler", - .description = "Dynamic Recompiler", - .type = CONFIG_BINARY, - .default_int = 1 - }, -#endif - { - .type = CONFIG_END - } -}; - -static const device_config_t banshee_sdram_config[] = { - { - .name = "bilinear", - .description = "Bilinear filtering", - .type = CONFIG_BINARY, - .default_int = 1 - }, - { - .name = "dithersub", - .description = "Dither subtraction", - .type = CONFIG_BINARY, - .default_int = 1 - }, - { - .name = "dacfilter", - .description = "Screen Filter", - .type = CONFIG_BINARY, - .default_int = 0 - }, - { - .name = "render_threads", - .description = "Render threads", - .type = CONFIG_SELECTION, - .selection = { - { - .description = "1", - .value = 1 - }, - { - .description = "2", - .value = 2 - }, - { - .description = "4", - .value = 4 - }, - { - .description = "" - } - }, - .default_int = 2 - }, -#ifndef NO_CODEGEN - { - .name = "recompiler", - .description = "Dynamic Recompiler", - .type = CONFIG_BINARY, - .default_int = 1 - }, -#endif - { - .type = CONFIG_END - } -}; -// clang-format on - static void * banshee_init_common(const device_t *info, char *fn, int has_sgram, int type, int voodoo_type, int agp) { @@ -3469,6 +3376,16 @@ banshee_init_common(const device_t *info, char *fn, int has_sgram, int type, int } break; + case TYPE_QUANTUM3D_RAVEN: + /* This case basically exists only to set the subsystem ID correctly for SF: Rush, a vendor-locked game. */ + /* We set the type back to TYPE_BANSHEE so the card behaves as a regular Banshee (no 3D glasses emulation). */ + banshee->pci_regs[0x2c] = 0x9c; + banshee->pci_regs[0x2d] = 0x13; + banshee->pci_regs[0x2e] = banshee->agp ? 0x16 : 0x17; + banshee->pci_regs[0x2f] = 0x00; + banshee->type = TYPE_BANSHEE; + break; + case TYPE_V3_1000: banshee->pci_regs[0x2c] = 0x1a; banshee->pci_regs[0x2d] = 0x12; @@ -3546,6 +3463,12 @@ creative_banshee_init(const device_t *info) return banshee_init_common(info, ROM_CREATIVE_BANSHEE, 0, TYPE_BANSHEE, VOODOO_BANSHEE, 0); } +static void * +quantum3d_raven_init(const device_t *info) +{ + return banshee_init_common(info, ROM_QUANTUM3D_RAVEN, 0, TYPE_QUANTUM3D_RAVEN, VOODOO_BANSHEE, 0); +} + static void * v3_1000_init(const device_t *info) { @@ -3642,6 +3565,12 @@ creative_banshee_available(void) return rom_present(ROM_CREATIVE_BANSHEE); } +static int +quantum3d_raven_available(void) +{ + return rom_present(ROM_QUANTUM3D_RAVEN); +} + static int v3_1000_available(void) { @@ -3735,6 +3664,221 @@ banshee_force_redraw(void *priv) banshee->svga.fullchange = changeframecount; } +// clang-format off +static const device_config_t banshee_sgram_config[] = { + { + .name = "memory", + .description = "Memory size", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 16, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "8 MB", .value = 8 }, + { .description = "16 MB", .value = 16 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { + .name = "bilinear", + .description = "Bilinear filtering", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { + .name = "dithersub", + .description = "Dither subtraction", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { + .name = "dacfilter", + .description = "Screen Filter", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { + .name = "render_threads", + .description = "Render threads", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "1", .value = 1 }, + { .description = "2", .value = 2 }, + { .description = "4", .value = 4 }, + { .description = "" } + }, + .bios = { { 0 } } + }, +#ifndef NO_CODEGEN + { + .name = "recompiler", + .description = "Dynamic Recompiler", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, +#endif + { .name = "", .description = "", .type = CONFIG_END } +}; + +static const device_config_t banshee_sgram_16mbonly_config[] = { + { + .name = "bilinear", + .description = "Bilinear filtering", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { + .name = "dithersub", + .description = "Dither subtraction", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { + .name = "dacfilter", + .description = "Screen Filter", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { + .name = "render_threads", + .description = "Render threads", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "1", .value = 1 }, + { .description = "2", .value = 2 }, + { .description = "4", .value = 4 }, + { .description = "" } + }, + .bios = { { 0 } } + }, +#ifndef NO_CODEGEN + { + .name = "recompiler", + .description = "Dynamic Recompiler", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, +#endif + { .name = "", .description = "", .type = CONFIG_END } +}; + +static const device_config_t banshee_sdram_config[] = { + { + .name = "bilinear", + .description = "Bilinear filtering", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { + .name = "dithersub", + .description = "Dither subtraction", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { + .name = "dacfilter", + .description = "Screen Filter", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, + { + .name = "render_threads", + .description = "Render threads", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 2, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "1", .value = 1 }, + { .description = "2", .value = 2 }, + { .description = "4", .value = 4 }, + { .description = "" } + }, + .bios = { { 0 } } + }, +#ifndef NO_CODEGEN + { + .name = "recompiler", + .description = "Dynamic Recompiler", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, +#endif + { .name = "", .description = "", .type = CONFIG_END } +}; +// clang-format on + const device_t voodoo_banshee_device = { .name = "3Dfx Voodoo Banshee", .internal_name = "voodoo_banshee_pci", @@ -3743,7 +3887,7 @@ const device_t voodoo_banshee_device = { .init = banshee_init, .close = banshee_close, .reset = NULL, - { .available = banshee_available }, + .available = banshee_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sgram_config @@ -3757,7 +3901,21 @@ const device_t creative_voodoo_banshee_device = { .init = creative_banshee_init, .close = banshee_close, .reset = NULL, - { .available = creative_banshee_available }, + .available = creative_banshee_available, + .speed_changed = banshee_speed_changed, + .force_redraw = banshee_force_redraw, + .config = banshee_sdram_config +}; + +const device_t quantum3d_raven_device = { + .name = "Quantum3D Raven", + .internal_name = "q3d_raven_pci", + .flags = DEVICE_PCI, + .local = 0, + .init = quantum3d_raven_init, + .close = banshee_close, + .reset = NULL, + .available = quantum3d_raven_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sdram_config @@ -3771,7 +3929,7 @@ const device_t voodoo_3_1000_device = { .init = v3_1000_init, .close = banshee_close, .reset = NULL, - { .available = v3_1000_available }, + .available = v3_1000_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sgram_config @@ -3785,7 +3943,7 @@ const device_t voodoo_3_1000_agp_device = { .init = v3_1000_agp_init, .close = banshee_close, .reset = NULL, - { .available = v3_1000_agp_available }, + .available = v3_1000_agp_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sgram_16mbonly_config @@ -3799,7 +3957,7 @@ const device_t voodoo_3_2000_device = { .init = v3_2000_init, .close = banshee_close, .reset = NULL, - { .available = v3_2000_available }, + .available = v3_2000_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sdram_config @@ -3813,7 +3971,7 @@ const device_t voodoo_3_2000_agp_device = { .init = v3_2000_agp_init, .close = banshee_close, .reset = NULL, - { .available = v3_2000_agp_available }, + .available = v3_2000_agp_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sdram_config @@ -3827,7 +3985,7 @@ const device_t voodoo_3_2000_agp_onboard_8m_device = { .init = v3_2000_agp_onboard_init, .close = banshee_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sgram_config @@ -3841,7 +3999,7 @@ const device_t voodoo_3_3000_device = { .init = v3_3000_init, .close = banshee_close, .reset = NULL, - { .available = v3_3000_available }, + .available = v3_3000_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sdram_config @@ -3855,7 +4013,7 @@ const device_t voodoo_3_3000_agp_device = { .init = v3_3000_agp_init, .close = banshee_close, .reset = NULL, - { .available = v3_3000_agp_available }, + .available = v3_3000_agp_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sdram_config @@ -3869,7 +4027,7 @@ const device_t voodoo_3_3500_agp_ntsc_device = { .init = v3_3500_agp_ntsc_init, .close = banshee_close, .reset = NULL, - { .available = v3_3500_agp_ntsc_available }, + .available = v3_3500_agp_ntsc_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sdram_config @@ -3883,7 +4041,7 @@ const device_t voodoo_3_3500_agp_pal_device = { .init = v3_3500_agp_pal_init, .close = banshee_close, .reset = NULL, - { .available = v3_3500_agp_pal_available }, + .available = v3_3500_agp_pal_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sdram_config @@ -3897,7 +4055,7 @@ const device_t compaq_voodoo_3_3500_agp_device = { .init = compaq_v3_3500_agp_init, .close = banshee_close, .reset = NULL, - { .available = compaq_v3_3500_agp_available }, + .available = compaq_v3_3500_agp_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sdram_config @@ -3911,7 +4069,7 @@ const device_t voodoo_3_3500_se_agp_device = { .init = v3_3500_se_agp_init, .close = banshee_close, .reset = NULL, - { .available = v3_3500_se_agp_available }, + .available = v3_3500_se_agp_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sdram_config @@ -3925,7 +4083,7 @@ const device_t voodoo_3_3500_si_agp_device = { .init = v3_3500_si_agp_init, .close = banshee_close, .reset = NULL, - { .available = v3_3500_si_agp_available }, + .available = v3_3500_si_agp_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sdram_config @@ -3939,7 +4097,7 @@ const device_t velocity_100_agp_device = { .init = velocity_100_agp_init, .close = banshee_close, .reset = NULL, - { .available = velocity_100_available }, + .available = velocity_100_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sdram_config @@ -3953,7 +4111,7 @@ const device_t velocity_200_agp_device = { .init = velocity_200_agp_init, .close = banshee_close, .reset = NULL, - { .available = velocity_200_available }, + .available = velocity_200_available, .speed_changed = banshee_speed_changed, .force_redraw = banshee_force_redraw, .config = banshee_sgram_16mbonly_config diff --git a/src/video/vid_voodoo_fifo.c b/src/video/vid_voodoo_fifo.c index 54a0140f6..83be0f7bb 100644 --- a/src/video/vid_voodoo_fifo.c +++ b/src/video/vid_voodoo_fifo.c @@ -35,6 +35,7 @@ #include <86box/video.h> #include <86box/vid_svga.h> #include <86box/vid_voodoo_common.h> +#include <86box/vid_voodoo_banshee.h> #include <86box/vid_voodoo_banshee_blitter.h> #include <86box/vid_voodoo_fb.h> #include <86box/vid_voodoo_fifo.h> @@ -166,7 +167,10 @@ cmdfifo_get(voodoo_t *voodoo) } } - val = *(uint32_t *) &voodoo->fb_mem[voodoo->cmdfifo_rp & voodoo->fb_mask]; + if (voodoo->cmdfifo_in_agp) + val = mem_readl_phys(voodoo->cmdfifo_rp); + else + val = *(uint32_t *) &voodoo->fb_mem[voodoo->cmdfifo_rp & voodoo->fb_mask]; if (!voodoo->cmdfifo_in_sub) voodoo->cmdfifo_depth_rd++; @@ -200,7 +204,10 @@ cmdfifo_get_2(voodoo_t *voodoo) } } - val = *(uint32_t *) &voodoo->fb_mem[voodoo->cmdfifo_rp_2 & voodoo->fb_mask]; + if (voodoo->cmdfifo_in_agp_2) + val = mem_readl_phys(voodoo->cmdfifo_rp_2); + else + val = *(uint32_t *) &voodoo->fb_mem[voodoo->cmdfifo_rp_2 & voodoo->fb_mask]; if (!voodoo->cmdfifo_in_sub_2) voodoo->cmdfifo_depth_rd_2++; @@ -362,9 +369,21 @@ voodoo_fifo_thread(void *param) break; case 3: /*JMP local frame buffer*/ - voodoo->cmdfifo_rp = (header >> 4) & 0xfffffc; + voodoo->cmdfifo_rp = (header >> 4) & 0xfffffc; + voodoo->cmdfifo_in_agp = 0; #if 0 - voodoo_fifo_log("JMP to %08x %04x\n", voodoo->cmdfifo_rp, header); + voodoo_fifo_log("JMP LFB to %08x %04x\n", voodoo->cmdfifo_rp, header); +#endif + break; + + case 4: /*JMP AGP*/ + if (UNLIKELY(voodoo->type < VOODOO_BANSHEE)) + fatal("CMDFIFO0: Not Banshee %08x\n", header); + + voodoo->cmdfifo_rp = ((header >> 4) & 0x1fffffc) | (cmdfifo_get(voodoo) << 25); + voodoo->cmdfifo_in_agp = 1; +#if 0 + voodoo_fifo_log("JMP AGP to %08x %04x\n", voodoo->cmdfifo_rp, header); #endif break; @@ -573,6 +592,23 @@ voodoo_fifo_thread(void *param) } break; + case 6: + if (UNLIKELY(voodoo->type < VOODOO_BANSHEE)) { + fatal("CMDFIFO6: Not Banshee %08x %08x\n", header, voodoo->cmdfifo_rp); + } else { + uint32_t val = cmdfifo_get(voodoo); + banshee_cmd_write(voodoo->priv, 0x00, val >> 5); /* agpReqSize */ + banshee_cmd_write(voodoo->priv, 0x04, cmdfifo_get(voodoo)); /* agpHostAddressLow */ + banshee_cmd_write(voodoo->priv, 0x08, cmdfifo_get(voodoo)); /* agpHostAddressHigh */ + banshee_cmd_write(voodoo->priv, 0x0c, cmdfifo_get(voodoo)); /* agpGraphicsAddress */ + banshee_cmd_write(voodoo->priv, 0x10, cmdfifo_get(voodoo)); /* agpGraphicsStride */ + banshee_cmd_write(voodoo->priv, 0x14, (val & 0x18) | 0x00); /* agpMoveCMD - start transfer */ +#if 0 + voodoo_fifo_log("CMDFIFO6 addr=%08x num=%i\n", addr, banshee->agpReqSize); +#endif + } + break; + default: fatal("Bad CMDFIFO packet %08x %08x\n", header, voodoo->cmdfifo_rp); } @@ -624,9 +660,21 @@ voodoo_fifo_thread(void *param) break; case 3: /*JMP local frame buffer*/ - voodoo->cmdfifo_rp_2 = (header >> 4) & 0xfffffc; + voodoo->cmdfifo_rp_2 = (header >> 4) & 0xfffffc; + voodoo->cmdfifo_in_agp_2 = 0; #if 0 - voodoo_fifo_log("JMP to %08x %04x\n", voodoo->cmdfifo_rp, header); + voodoo_fifo_log("JMP LFB to %08x %04x\n", voodoo->cmdfifo_rp_2, header); +#endif + break; + + case 4: /*JMP AGP*/ + if (UNLIKELY(voodoo->type < VOODOO_BANSHEE)) + fatal("CMDFIFO0: Not Banshee %08x\n", header); + + voodoo->cmdfifo_rp_2 = ((header >> 4) & 0x1fffffc) | (cmdfifo_get_2(voodoo) << 25); + voodoo->cmdfifo_in_agp_2 = 1; +#if 0 + voodoo_fifo_log("JMP AGP to %08x %04x\n", voodoo->cmdfifo_rp_2, header); #endif break; @@ -835,6 +883,23 @@ voodoo_fifo_thread(void *param) } break; + case 6: + if (UNLIKELY(voodoo->type < VOODOO_BANSHEE)) { + fatal("CMDFIFO6: Not Banshee %08x %08x\n", header, voodoo->cmdfifo_rp); + } else { + uint32_t val = cmdfifo_get_2(voodoo); + banshee_cmd_write(voodoo->priv, 0x00, val >> 5); /* agpReqSize */ + banshee_cmd_write(voodoo->priv, 0x04, cmdfifo_get_2(voodoo)); /* agpHostAddressLow */ + banshee_cmd_write(voodoo->priv, 0x08, cmdfifo_get_2(voodoo)); /* agpHostAddressHigh */ + banshee_cmd_write(voodoo->priv, 0x0c, cmdfifo_get_2(voodoo)); /* agpGraphicsAddress */ + banshee_cmd_write(voodoo->priv, 0x10, cmdfifo_get_2(voodoo)); /* agpGraphicsStride */ + banshee_cmd_write(voodoo->priv, 0x14, (val & 0x18) | 0x20); /* agpMoveCMD - start transfer */ +#if 0 + voodoo_fifo_log("CMDFIFO6 addr=%08x num=%i\n", addr, banshee->agpReqSize); +#endif + } + break; + default: fatal("Bad CMDFIFO packet %08x %08x\n", header, voodoo->cmdfifo_rp); } diff --git a/src/video/vid_voodoo_render.c b/src/video/vid_voodoo_render.c index d8f812f7f..cc52fc61a 100644 --- a/src/video/vid_voodoo_render.c +++ b/src/video/vid_voodoo_render.c @@ -43,8 +43,7 @@ typedef struct voodoo_state_t { int xstart, xend, xdir; uint32_t base_r, base_g, base_b, base_a, base_z; - struct - { + struct { int64_t base_s, base_t, base_w; int lod; } tmu[2]; @@ -1424,11 +1423,14 @@ voodoo_triangle(voodoo_t *voodoo, voodoo_params_t *params, int odd_even) if ((params->vertexAy & 0xf) > 8) dy += 16; - /* voodoo_render_log("voodoo_triangle %i %i %i : vA %f, %f vB %f, %f vC %f, %f f %i,%i %08x %08x %08x,%08x tex=%i,%i fogMode=%08x\n", odd_even, voodoo->params_read_idx[odd_even], voodoo->params_read_idx[odd_even] & PARAM_MASK, (float)params->vertexAx / 16.0, (float)params->vertexAy / 16.0, - (float)params->vertexBx / 16.0, (float)params->vertexBy / 16.0, - (float)params->vertexCx / 16.0, (float)params->vertexCy / 16.0, - (params->fbzColorPath & FBZCP_TEXTURE_ENABLED) ? params->tformat[0] : 0, - (params->fbzColorPath & FBZCP_TEXTURE_ENABLED) ? params->tformat[1] : 0, params->fbzColorPath, params->alphaMode, params->textureMode[0],params->textureMode[1], params->tex_entry[0],params->tex_entry[1], params->fogMode);*/ +#if 0 +voodoo_render_log("voodoo_triangle %i %i %i : vA %f, %f vB %f, %f vC %f, %f f %i,%i %08x %08x %08x,%08x tex=%i,%i fogMode=%08x\n", + odd_even, voodoo->params_read_idx[odd_even], voodoo->params_read_idx[odd_even] & PARAM_MASK, (float)params->vertexAx / 16.0, (float)params->vertexAy / 16.0, + (float)params->vertexBx / 16.0, (float)params->vertexBy / 16.0, + (float)params->vertexCx / 16.0, (float)params->vertexCy / 16.0, + (params->fbzColorPath & FBZCP_TEXTURE_ENABLED) ? params->tformat[0] : 0, + (params->fbzColorPath & FBZCP_TEXTURE_ENABLED) ? params->tformat[1] : 0, params->fbzColorPath, params->alphaMode, params->textureMode[0],params->textureMode[1], params->tex_entry[0],params->tex_entry[1], params->fogMode); +#endif state.base_r = params->startR; state.base_g = params->startG; diff --git a/src/video/vid_voodoo_setup.c b/src/video/vid_voodoo_setup.c index e1d13ba35..11f4ff861 100644 --- a/src/video/vid_voodoo_setup.c +++ b/src/video/vid_voodoo_setup.c @@ -191,8 +191,8 @@ voodoo_triangle_setup(voodoo_t *voodoo) voodoo->params.dWdX = (int64_t) (((verts[va].sWb - verts[vb].sWb) * dyBC - (verts[vb].sWb - verts[vc].sWb) * dyAB) * 4294967296.0f); voodoo->params.dWdY = (int64_t) (((verts[vb].sWb - verts[vc].sWb) * dxAB - (verts[va].sWb - verts[vb].sWb) * dxBC) * 4294967296.0f); voodoo->params.tmu[0].startW = voodoo->params.tmu[1].startW = voodoo->params.startW; - voodoo->params.tmu[0].dWdX = voodoo->params.tmu[1].dWdX = voodoo->params.dWdX; - voodoo->params.tmu[0].dWdY = voodoo->params.tmu[1].dWdY = voodoo->params.dWdY; + voodoo->params.tmu[0].dWdX = voodoo->params.tmu[1].dWdX = voodoo->params.dWdX; + voodoo->params.tmu[0].dWdY = voodoo->params.tmu[1].dWdY = voodoo->params.dWdY; } if (voodoo->sSetupMode & SETUPMODE_W0) { voodoo->params.tmu[0].startW = (int64_t) (verts[va].sW0 * 4294967296.0f); diff --git a/src/video/vid_voodoo_texture.c b/src/video/vid_voodoo_texture.c index 3939db3cd..f6894ec0f 100644 --- a/src/video/vid_voodoo_texture.c +++ b/src/video/vid_voodoo_texture.c @@ -61,10 +61,10 @@ voodoo_texture_log(const char *fmt, ...) void voodoo_recalc_tex12(voodoo_t *voodoo, int tmu) { - int aspect = (voodoo->params.tLOD[tmu] >> 21) & 3; - int width = 256; - int height = 256; - int shift = 8; + int aspect = (voodoo->params.tLOD[tmu] >> 21) & 3; + int width = 256; + int height = 256; + int shift = 8; uint32_t base = voodoo->params.texBaseAddr[tmu]; uint32_t offset = 0; int tex_lod = 0; diff --git a/src/video/vid_wy700.c b/src/video/vid_wy700.c index 600fa21a8..c00541113 100644 --- a/src/video/vid_wy700.c +++ b/src/video/vid_wy700.c @@ -212,9 +212,9 @@ typedef struct wy700_t { } wy700_t; /* Mapping of attributes to colours, in CGA emulation... */ -static int cgacols[256][2][2]; +static int cga_attr_to_color_table[256][2][2]; /* ... and MDA emulation. */ -static int mdacols[256][2][2]; +static int mda_attr_to_color_table[256][2][2]; void wy700_recalctimings(wy700_t *wy700); void wy700_write(uint32_t addr, uint8_t val, void *priv); @@ -535,9 +535,9 @@ wy700_textline(wy700_t *wy700) int cursorline; int mda = 0; uint16_t addr; - uint8_t sc; - uint16_t ma = (wy700->cga_crtc[13] | (wy700->cga_crtc[12] << 8)) & 0x3fff; - uint16_t ca = (wy700->cga_crtc[15] | (wy700->cga_crtc[14] << 8)) & 0x3fff; + uint8_t scanline; + uint16_t memaddr = (wy700->cga_crtc[13] | (wy700->cga_crtc[12] << 8)) & 0x3fff; + uint16_t cursoraddr = (wy700->cga_crtc[15] | (wy700->cga_crtc[14] << 8)) & 0x3fff; /* The fake CRTC character height register selects whether MDA or CGA * attributes are used */ @@ -548,41 +548,41 @@ wy700_textline(wy700_t *wy700) if (wy700->font) { fontbase += 256 * 32; } - addr = ((ma & ~1) + (wy700->displine >> 5) * w) * 2; - sc = (wy700->displine >> 1) & 15; + addr = ((memaddr & ~1) + (wy700->displine >> 5) * w) * 2; + scanline = (wy700->displine >> 1) & 15; - ma += ((wy700->displine >> 5) * w); + memaddr += ((wy700->displine >> 5) * w); if ((wy700->real_crtc[10] & 0x60) == 0x20) { cursorline = 0; } else { - cursorline = ((wy700->real_crtc[10] & 0x1F) <= sc) && ((wy700->real_crtc[11] & 0x1F) >= sc); + cursorline = ((wy700->real_crtc[10] & 0x1F) <= scanline) && ((wy700->real_crtc[11] & 0x1F) >= scanline); } 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)); + drawcursor = ((memaddr == cursoraddr) && cursorline && wy700->enabled && (wy700->cga_ctrl & 8) && (wy700->blink & 16)); blink = ((wy700->blink & 16) && (wy700->cga_ctrl & 0x20) && (attr & 0x80) && !drawcursor); if (wy700->cga_ctrl & 0x20) attr &= 0x7F; /* MDA underline */ - if (sc == 14 && mda && ((attr & 7) == 1)) { + if (scanline == 14 && mda && ((attr & 7) == 1)) { for (c = 0; c < cw; c++) - buffer32->line[wy700->displine][(x * cw) + c] = mdacols[attr][blink][1]; + buffer32->line[wy700->displine][(x * cw) + c] = mda_attr_to_color_table[attr][blink][1]; } else /* Draw 16 pixels of character */ { - bitmap[0] = fontbase[chr * 32 + 2 * sc]; - bitmap[1] = fontbase[chr * 32 + 2 * sc + 1]; + bitmap[0] = fontbase[chr * 32 + 2 * scanline]; + bitmap[1] = fontbase[chr * 32 + 2 * scanline + 1]; for (c = 0; c < 16; c++) { int col; if (c < 8) - col = (mda ? mdacols : cgacols)[attr][blink][(bitmap[0] & (1 << (c ^ 7))) ? 1 : 0]; + col = (mda ? mda_attr_to_color_table : cga_attr_to_color_table)[attr][blink][(bitmap[0] & (1 << (c ^ 7))) ? 1 : 0]; else - col = (mda ? mdacols : cgacols)[attr][blink][(bitmap[1] & (1 << ((c & 7) ^ 7))) ? 1 : 0]; + col = (mda ? mda_attr_to_color_table : cga_attr_to_color_table)[attr][blink][(bitmap[1] & (1 << ((c & 7) ^ 7))) ? 1 : 0]; if (!(wy700->enabled) || !(wy700->cga_ctrl & 8)) - col = mdacols[0][0][0]; + col = mda_attr_to_color_table[0][0][0]; if (w == 40) { buffer32->line[wy700->displine][(x * cw) + 2 * c] = col; buffer32->line[wy700->displine][(x * cw) + 2 * c + 1] = col; @@ -592,9 +592,9 @@ wy700_textline(wy700_t *wy700) if (drawcursor) { for (c = 0; c < cw; c++) - buffer32->line[wy700->displine][(x * cw) + c] ^= (mda ? mdacols : cgacols)[attr][0][1]; + buffer32->line[wy700->displine][(x * cw) + c] ^= (mda ? mda_attr_to_color_table : cga_attr_to_color_table)[attr][0][1]; } - ++ma; + ++memaddr; } } } @@ -608,8 +608,8 @@ wy700_cgaline(wy700_t *wy700) uint8_t ink = 0; uint16_t addr; - uint16_t ma = (wy700->cga_crtc[13] | (wy700->cga_crtc[12] << 8)) & 0x3fff; - addr = ((wy700->displine >> 2) & 1) * 0x2000 + (wy700->displine >> 3) * 80 + ((ma & ~1) << 1); + uint16_t memaddr = (wy700->cga_crtc[13] | (wy700->cga_crtc[12] << 8)) & 0x3fff; + addr = ((wy700->displine >> 2) & 1) * 0x2000 + (wy700->displine >> 3) * 80 + ((memaddr & ~1) << 1); /* 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 */ @@ -902,74 +902,74 @@ wy700_init(UNUSED(const device_t *info)) /* Set up the emulated attributes. * CGA is done in four groups: 00-0F, 10-7F, 80-8F, 90-FF */ for (c = 0; c < 0x10; c++) { - cgacols[c][0][0] = cgacols[c][1][0] = cgacols[c][1][1] = 16; + cga_attr_to_color_table[c][0][0] = cga_attr_to_color_table[c][1][0] = cga_attr_to_color_table[c][1][1] = 16; if (c & 8) - cgacols[c][0][1] = 15 + 16; + cga_attr_to_color_table[c][0][1] = 15 + 16; else - cgacols[c][0][1] = 7 + 16; + cga_attr_to_color_table[c][0][1] = 7 + 16; } for (c = 0x10; c < 0x80; c++) { - cgacols[c][0][0] = cgacols[c][1][0] = cgacols[c][1][1] = 16 + 7; + cga_attr_to_color_table[c][0][0] = cga_attr_to_color_table[c][1][0] = cga_attr_to_color_table[c][1][1] = 16 + 7; if (c & 8) - cgacols[c][0][1] = 15 + 16; + cga_attr_to_color_table[c][0][1] = 15 + 16; else - cgacols[c][0][1] = 0 + 16; + cga_attr_to_color_table[c][0][1] = 0 + 16; if ((c & 0x0F) == 8) - cgacols[c][0][1] = 8 + 16; + cga_attr_to_color_table[c][0][1] = 8 + 16; } /* With special cases for 00, 11, 22, ... 77 */ - cgacols[0x00][0][1] = cgacols[0x00][1][1] = 16; + cga_attr_to_color_table[0x00][0][1] = cga_attr_to_color_table[0x00][1][1] = 16; for (c = 0x11; c <= 0x77; c += 0x11) { - cgacols[c][0][1] = cgacols[c][1][1] = 16 + 7; + cga_attr_to_color_table[c][0][1] = cga_attr_to_color_table[c][1][1] = 16 + 7; } for (c = 0x80; c < 0x90; c++) { - cgacols[c][0][0] = 16 + 8; + cga_attr_to_color_table[c][0][0] = 16 + 8; if (c & 8) - cgacols[c][0][1] = 15 + 16; + cga_attr_to_color_table[c][0][1] = 15 + 16; else - cgacols[c][0][1] = 7 + 16; - cgacols[c][1][0] = cgacols[c][1][1] = cgacols[c - 0x80][0][0]; + cga_attr_to_color_table[c][0][1] = 7 + 16; + cga_attr_to_color_table[c][1][0] = cga_attr_to_color_table[c][1][1] = cga_attr_to_color_table[c - 0x80][0][0]; } for (c = 0x90; c < 0x100; c++) { - cgacols[c][0][0] = 16 + 15; + cga_attr_to_color_table[c][0][0] = 16 + 15; if (c & 8) - cgacols[c][0][1] = 8 + 16; + cga_attr_to_color_table[c][0][1] = 8 + 16; else - cgacols[c][0][1] = 7 + 16; + cga_attr_to_color_table[c][0][1] = 7 + 16; if ((c & 0x0F) == 0) - cgacols[c][0][1] = 16; - cgacols[c][1][0] = cgacols[c][1][1] = cgacols[c - 0x80][0][0]; + cga_attr_to_color_table[c][0][1] = 16; + cga_attr_to_color_table[c][1][0] = cga_attr_to_color_table[c][1][1] = cga_attr_to_color_table[c - 0x80][0][0]; } /* Also special cases for 99, AA, ..., FF */ for (c = 0x99; c <= 0xFF; c += 0x11) { - cgacols[c][0][1] = 16 + 15; + cga_attr_to_color_table[c][0][1] = 16 + 15; } /* Special cases for 08, 80 and 88 */ - cgacols[0x08][0][1] = 16 + 8; - cgacols[0x80][0][1] = 16; - cgacols[0x88][0][1] = 16 + 8; + cga_attr_to_color_table[0x08][0][1] = 16 + 8; + cga_attr_to_color_table[0x80][0][1] = 16; + cga_attr_to_color_table[0x88][0][1] = 16 + 8; /* MDA attributes */ for (c = 0; c < 256; c++) { - mdacols[c][0][0] = mdacols[c][1][0] = mdacols[c][1][1] = 16; + mda_attr_to_color_table[c][0][0] = mda_attr_to_color_table[c][1][0] = mda_attr_to_color_table[c][1][1] = 16; if (c & 8) - mdacols[c][0][1] = 15 + 16; + mda_attr_to_color_table[c][0][1] = 15 + 16; else - mdacols[c][0][1] = 7 + 16; + mda_attr_to_color_table[c][0][1] = 7 + 16; } - mdacols[0x70][0][1] = 16; - mdacols[0x70][0][0] = mdacols[0x70][1][0] = mdacols[0x70][1][1] = 16 + 15; - mdacols[0xF0][0][1] = 16; - mdacols[0xF0][0][0] = mdacols[0xF0][1][0] = mdacols[0xF0][1][1] = 16 + 15; - mdacols[0x78][0][1] = 16 + 7; - mdacols[0x78][0][0] = mdacols[0x78][1][0] = mdacols[0x78][1][1] = 16 + 15; - mdacols[0xF8][0][1] = 16 + 7; - mdacols[0xF8][0][0] = mdacols[0xF8][1][0] = mdacols[0xF8][1][1] = 16 + 15; - mdacols[0x00][0][1] = mdacols[0x00][1][1] = 16; - mdacols[0x08][0][1] = mdacols[0x08][1][1] = 16; - mdacols[0x80][0][1] = mdacols[0x80][1][1] = 16; - mdacols[0x88][0][1] = mdacols[0x88][1][1] = 16; + mda_attr_to_color_table[0x70][0][1] = 16; + mda_attr_to_color_table[0x70][0][0] = mda_attr_to_color_table[0x70][1][0] = mda_attr_to_color_table[0x70][1][1] = 16 + 15; + mda_attr_to_color_table[0xF0][0][1] = 16; + mda_attr_to_color_table[0xF0][0][0] = mda_attr_to_color_table[0xF0][1][0] = mda_attr_to_color_table[0xF0][1][1] = 16 + 15; + mda_attr_to_color_table[0x78][0][1] = 16 + 7; + mda_attr_to_color_table[0x78][0][0] = mda_attr_to_color_table[0x78][1][0] = mda_attr_to_color_table[0x78][1][1] = 16 + 15; + mda_attr_to_color_table[0xF8][0][1] = 16 + 7; + mda_attr_to_color_table[0xF8][0][0] = mda_attr_to_color_table[0xF8][1][0] = mda_attr_to_color_table[0xF8][1][1] = 16 + 15; + mda_attr_to_color_table[0x00][0][1] = mda_attr_to_color_table[0x00][1][1] = 16; + mda_attr_to_color_table[0x08][0][1] = mda_attr_to_color_table[0x08][1][1] = 16; + mda_attr_to_color_table[0x80][0][1] = mda_attr_to_color_table[0x80][1][1] = 16; + mda_attr_to_color_table[0x88][0][1] = mda_attr_to_color_table[0x88][1][1] = 16; /* Start off in 80x25 text mode */ wy700->cga_stat = 0xF4; @@ -1004,7 +1004,7 @@ const device_t wy700_device = { .init = wy700_init, .close = wy700_close, .reset = NULL, - { .available = NULL }, + .available = NULL, .speed_changed = wy700_speed_changed, .force_redraw = NULL, .config = NULL diff --git a/src/video/vid_xga.c b/src/video/vid_xga.c index 3df43a29c..8f4dc0d0e 100644 --- a/src/video/vid_xga.c +++ b/src/video/vid_xga.c @@ -19,7 +19,7 @@ #include #include #include -#include <86box/bswap.h> +//#include <86box/bswap.h> #include <86box/86box.h> #include <86box/io.h> #include <86box/machine.h> @@ -41,7 +41,7 @@ #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 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_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 xga_ext_outb(uint16_t addr, uint8_t val, void *priv); @@ -107,7 +107,7 @@ svga_xga_out(uint16_t addr, uint8_t val, void *priv) 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); + svga->memaddr_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5); } else { svga->fullchange = changeframecount; svga_recalctimings(svga); @@ -188,7 +188,7 @@ xga_updatemapping(svga_t *svga) mem_mapping_disable(&xga->linear_mapping); break; default: - xga_log("XGA: Extended Graphics mode.\n"); + xga_log("XGA: Extended Graphics mode, ap=%d.\n", xga->aperture_cntl); switch (xga->aperture_cntl) { case 0: xga_log("XGA: No 64KB aperture: 1MB=%x, 4MB=%x, SVGA Mapping Base=%x.\n", xga->base_addr_1mb, xga->linear_base, svga->mapping.base); @@ -201,7 +201,7 @@ xga_updatemapping(svga_t *svga) } else mem_mapping_disable(&xga->linear_mapping); - mem_mapping_set_handler(&svga->mapping, svga_read, svga_readw, svga_readl, svga_write, svga_writew, svga_writel); + mem_mapping_set_handler(&svga->mapping, svga->read, svga->readw, svga->readl, svga->write, svga->writew, svga->writel); switch (svga->gdcreg[6] & 0xc) { case 0x0: /*128k at A0000*/ mem_mapping_set_addr(&svga->mapping, 0xa0000, 0x20000); @@ -243,6 +243,26 @@ xga_updatemapping(svga_t *svga) } } +static void +xga_render_blank(svga_t *svga) +{ + xga_t *xga = (xga_t *) svga->xga; + + if ((xga->displine + svga->y_add) < 0) + return; + + if (xga->firstline_draw == 2000) + xga->firstline_draw = xga->displine; + + xga->lastline_draw = xga->displine; + + uint32_t *line_ptr = &svga->monitor->target_buffer->line[xga->displine + svga->y_add][svga->x_add]; + uint32_t line_width = (uint32_t)(xga->h_disp) * sizeof(uint32_t); + + if (xga->h_disp > 0) + memset(line_ptr, 0, line_width); +} + void xga_recalctimings(svga_t *svga) { @@ -270,28 +290,45 @@ xga_recalctimings(svga_t *svga) xga->v_blankstart >>= 1; } - xga->ma_latch = xga->disp_start_addr; + xga->memaddr_latch = xga->disp_start_addr; + xga_log("XGA ClkSel1 = %d, ClkSel2 = %02x, dispcntl2=%02x.\n", (xga->clk_sel_1 >> 2) & 3, xga->clk_sel_2 & 0x80, xga->disp_cntl_2 & 0xc0); switch ((xga->clk_sel_1 >> 2) & 3) { case 0: xga_log("HDISP VGA0 = %d, XGA = %d.\n", svga->hdisp, xga->h_disp); if (xga->clk_sel_2 & 0x80) - svga->clock = (cpuclock * (double) (1ULL << 32)) / 41539000.0; + svga->clock_xga = (cpuclock * (double) (1ULL << 32)) / 41539000.0; else - svga->clock = (cpuclock * (double) (1ULL << 32)) / 25175000.0; + svga->clock_xga = (cpuclock * (double) (1ULL << 32)) / 25175000.0; break; case 1: xga_log("HDISP VGA1 = %d, XGA = %d.\n", svga->hdisp, xga->h_disp); - svga->clock = (cpuclock * (double) (1ULL << 32)) / 28322000.0; + svga->clock_xga = (cpuclock * (double) (1ULL << 32)) / 28322000.0; break; case 3: - svga->clock = (cpuclock * (double) (1ULL << 32)) / 44900000.0; + svga->clock_xga = (cpuclock * (double) (1ULL << 32)) / 44900000.0; break; default: break; } + + switch (xga->disp_cntl_2 & 7) { + case 2: + svga->render_xga = xga_render_4bpp; + break; + case 3: + svga->render_xga = xga_render_8bpp; + break; + case 4: + svga->render_xga = xga_render_16bpp; + break; + + default: + svga->render_xga = xga_render_blank; + break; + } } } @@ -439,9 +476,9 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) break; case 0x51: - xga_log("Reg51 write = %02x.\n", val); + xga_log("Reg51 write=%02x.\n", val & 0x07); xga->disp_cntl_2 = val; - xga->on = ((val & 7) >= 2); + xga->on = ((val & 0x07) >= 0x02); svga_recalctimings(svga); break; @@ -535,9 +572,11 @@ xga_ext_outb(uint16_t addr, uint8_t val, void *priv) xga_log("[%04X:%08X]: EXT OUTB = %02x, val = %02x\n", CS, cpu_state.pc, addr, val); switch (addr & 0x0f) { case 0: + xga_log("[%04X:%08X]: EXT OUTB = %02x, val = %02x\n", CS, cpu_state.pc, addr, val); xga->op_mode = val; break; case 1: + xga_log("[%04X:%08X]: EXT OUTB = %02x, val = %02x\n", CS, cpu_state.pc, addr, val); xga->aperture_cntl = val & 3; xga_updatemapping(svga); break; @@ -579,6 +618,7 @@ xga_ext_outb(uint16_t addr, uint8_t val, void *priv) break; default: + xga_log("[%04X:%08X]: EXT OUTB = %02x, val = %02x\n", CS, cpu_state.pc, addr, val); break; } } @@ -807,6 +847,7 @@ xga_ext_inb(uint16_t addr, void *priv) break; default: + xga_log("[%04X:%08X]: EXT INB = %02x, ret = %02x.\n\n", CS, cpu_state.pc, addr, ret); break; } @@ -815,18 +856,18 @@ xga_ext_inb(uint16_t addr, void *priv) return ret; } -#define READ(addr, dat) \ +#define READ(addr, dat) \ dat = xga->vram[(addr) & (xga->vram_mask)]; -#define WRITE(addr, dat) \ - xga->vram[((addr)) & (xga->vram_mask)] = dat; \ +#define WRITE(addr, dat) \ + xga->vram[((addr)) & (xga->vram_mask)] = dat; \ xga->changedvram[(((addr)) & (xga->vram_mask)) >> 12] = svga->monitor->mon_changeframecount; -#define READW(addr, dat) \ +#define READW(addr, dat) \ dat = *(uint16_t *) &xga->vram[(addr) & (xga->vram_mask)]; -#define WRITEW(addr, dat) \ - *(uint16_t *) &xga->vram[((addr)) & (xga->vram_mask)] = dat; \ +#define WRITEW(addr, dat) \ + *(uint16_t *) &xga->vram[((addr)) & (xga->vram_mask)] = dat; \ xga->changedvram[(((addr)) & (xga->vram_mask)) >> 12] = svga->monitor->mon_changeframecount; #define ROP(mix, d, s) \ @@ -887,7 +928,7 @@ xga_ext_inb(uint16_t addr, void *priv) d = MIN(s, d); \ break; \ case 0x12: \ - d = MIN(~0, s + d); \ + d = MIN(~0, s + d); \ break; \ case 0x13: \ d = MAX(0, d - s); \ @@ -933,6 +974,32 @@ xga_accel_read_pattern_map_pixel(svga_t *svga, int x, int y, uint32_t base, int return px; } +static uint32_t +xga_accel_read_area_map_pixel(svga_t *svga, int x, int y, uint32_t base, int width) +{ + const xga_t *xga = (xga_t *) svga->xga; + uint32_t addr = base; + int bits; + uint8_t byte; + uint8_t px; + int skip = 0; + + if ((addr < xga->linear_base) || (addr > (xga->linear_base + 0xfffff))) + skip = 1; + + addr += (y * (width >> 3)); + addr += (x >> 3); + if (!skip) { + READ(addr, byte); + } else + byte = mem_readb_phys(addr); + + 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) { @@ -971,6 +1038,7 @@ xga_accel_read_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, int } else byte = mem_readb_phys(addr); + xga_log("4bpp read: OPMODEBIG=%02x, SRC Map=%02x, DST Map=%02x, AccessMode=%02x, SRCPIX=%02x, DSTPIX=%02x, wordpix=%04x, x=%d, y=%d, skip=%d.\n", xga->op_mode & 0x08, (xga->accel.px_map_format[xga->accel.src_map] & 0x0f), (xga->accel.px_map_format[xga->accel.dst_map] & 0x0f), xga->access_mode & 0x0f, xga->accel.src_map, xga->accel.dst_map, byte, x, y, skip); return byte; case 3: /*8-bit*/ addr += (y * width); @@ -984,19 +1052,15 @@ 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 (xga->access_mode & 0x08) { - if (!skip) { - READW(addr, byte); - } else - byte = mem_readw_phys(addr); - } else { - if (!skip) { - READW(addr, byte); - } else { - byte = mem_readw_phys(addr); - if ((xga->access_mode & 0x07) == 0x04) - byte = ((byte & 0xff00) >> 8) | ((byte & 0x00ff) << 8); - } + + if (!skip) { + READW(addr, byte); + } else { + byte = mem_readw_phys(addr); + if ((xga->access_mode & 0x07) == 0x04) + byte = ((byte & 0xff00) >> 8) | ((byte & 0x00ff) << 8); + else if (xga->access_mode & 0x08) + byte = ((byte & 0xff00) >> 8) | ((byte & 0x00ff) << 8); } return byte; @@ -1081,17 +1145,14 @@ xga_accel_write_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, ui case 4: /*16-bit*/ addr += (y * width << 1); addr += (x << 1); - if (xga->access_mode & 0x08) { - if (!skip) { - WRITEW(addr, pixel); - } + + if (!skip) { + WRITEW(addr, pixel); } else { - if (!skip) { - WRITEW(addr, pixel); - } else { - if ((xga->access_mode & 0x07) == 0x04) - pixel = ((pixel & 0xff00) >> 8) | ((pixel & 0x00ff) << 8); - } + if ((xga->access_mode & 0x07) == 0x04) + pixel = ((pixel & 0xff00) >> 8) | ((pixel & 0x00ff) << 8); + else if (xga->access_mode & 0x08) + pixel = ((pixel & 0xff00) >> 8) | ((pixel & 0x00ff) << 8); } mem_writew_phys(addr, pixel); break; @@ -1237,12 +1298,11 @@ xga_line_draw_write(svga_t *svga) uint32_t srcbase = xga->accel.px_map_base[xga->accel.src_map]; int y = xga->accel.blt_width; int x = 0; + int draw_pixel = 0; int16_t dx; int16_t dy; int16_t cx; int16_t cy; - int err = xga->accel.bres_err_term; - int draw_pixel = 0; cx = xga->accel.src_map_x & 0xfff; cy = xga->accel.src_map_y & 0xfff; @@ -1256,38 +1316,57 @@ xga_line_draw_write(svga_t *svga) dy |= ~0x17ff; if ((xga->accel.command & 0x30) == 0x30) - xga_log("Line Draw Write: BLTWIDTH=%d, BLTHEIGHT=%d, FRGDCOLOR=%04x, XDIR=%i, YDIR=%i, steep=%s, ERR=%04x.\n", xga->accel.blt_width, xga->accel.blt_height, xga->accel.frgd_color & 0xffff, xdir, ydir, (xga->accel.octant & 0x01) ? "0" : "1", err); - + xga_log("Line Draw Write Fill: DX=%d, DY=%d, BLTWIDTH=%d, BLTHEIGHT=%d, FRGDCOLOR=%04x, negative XDIR=%i, negative YDIR=%i, YMAJOR=%d, ERR=%d, BRESK2=%d, BRESK1=%d, mask=%02x.\n", dx, dy, xga->accel.blt_width, xga->accel.blt_height, xga->accel.frgd_color & 0xffff, (xga->accel.octant & 0x04), (xga->accel.octant & 0x02), (xga->accel.octant & 0x01), xga->accel.bres_err_term, xga->accel.bres_k2, xga->accel.bres_k1, xga->accel.command & 0xc0); if (xga->accel.pat_src == 8) { if ((xga->accel.command & 0x30) == 0x30) { while (y >= 0) { draw_pixel = 0; - if (xga->accel.octant & 0x01) { - if (xga->accel.octant & 0x02) { /*Bottom-to-Top*/ + if (xga->accel.octant & 0x01) { /*Y Major*/ + if (xga->accel.octant & 0x02) { /*Bottom to Top*/ if (x) draw_pixel = 1; - } else { /*Top-to-Bottom*/ + } else { /*Top to Bottom*/ if (y) draw_pixel = 1; } - } else if (!(xga->accel.octant & 0x04) && (err < (xga->accel.bres_k2 + xga->accel.bres_k1))) /*X+*/ - draw_pixel = 1; - else if ((xga->accel.octant & 0x04) && (err >= 0)) /*X-*/ - draw_pixel = 1; - - 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))) { - if (draw_pixel) { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, cx, cy, 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); - - 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))) { - ROP(1, dest_dat, src_dat); - 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 { /*X Major*/ + if (xga->accel.octant & 0x04) { /*Right to Left*/ + if (xga->accel.bres_err_term >= 0) { + if (xga->accel.octant & 0x02) { /*Bottom to Top*/ + if (x) + draw_pixel = 1; + } else { /*Top to Bottom*/ + if (y) + draw_pixel = 1; } } + } else { /*Left to Right*/ + if (xga->accel.bres_err_term < (xga->accel.bres_k1 + xga->accel.bres_k2)) { + if (xga->accel.octant & 0x02) { /*Bottom to Top*/ + if (x) + draw_pixel = 1; + } else { /*Top to Bottom*/ + if (y) + draw_pixel = 1; + } + } + } + } + + xga_log("Draw Boundary: DX=%d, DY=%d, wrt_pix=%d, ymajor=%d, bottomtotop=%x, len=%d, err=%d, frgdmix=%02x.\n", dx, dy, draw_pixel, xga->accel.octant & 0x01, xga->accel.octant & 0x02, y, xga->accel.bres_err_term, xga->accel.frgd_mix & 0x1f); + 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)) && draw_pixel) { + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, cx, cy, 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); + + 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); + dest_dat = (dest_dat & plane_mask) | (old_dest_dat & ~plane_mask); + 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 { if (draw_pixel) { @@ -1295,7 +1374,9 @@ xga_line_draw_write(svga_t *svga) 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); 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); + dest_dat = (dest_dat & plane_mask) | (old_dest_dat & ~plane_mask); 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); } } @@ -1310,28 +1391,28 @@ xga_line_draw_write(svga_t *svga) else dy++; - if (err >= 0) { - err += xga->accel.bres_k2; + if (xga->accel.bres_err_term >= 0) { + xga->accel.bres_err_term += xga->accel.bres_k2; if (xga->accel.octant & 0x04) dx--; else dx++; } else - err += xga->accel.bres_k1; + xga->accel.bres_err_term += xga->accel.bres_k1; } else { if (xga->accel.octant & 0x04) dx--; else dx++; - if (err >= 0) { - err += xga->accel.bres_k2; + if (xga->accel.bres_err_term >= 0) { + xga->accel.bres_err_term += xga->accel.bres_k2; if (xga->accel.octant & 0x02) dy--; else dy++; } else - err += xga->accel.bres_k1; + xga->accel.bres_err_term += xga->accel.bres_k1; } x++; y--; @@ -1384,28 +1465,28 @@ xga_line_draw_write(svga_t *svga) else dy++; - if (err >= 0) { - err += xga->accel.bres_k2; + if (xga->accel.bres_err_term >= 0) { + xga->accel.bres_err_term += xga->accel.bres_k2; if (xga->accel.octant & 0x04) dx--; else dx++; } else - err += xga->accel.bres_k1; + xga->accel.bres_err_term += xga->accel.bres_k1; } else { if (xga->accel.octant & 0x04) dx--; else dx++; - if (err >= 0) { - err += xga->accel.bres_k2; + if (xga->accel.bres_err_term >= 0) { + xga->accel.bres_err_term += xga->accel.bres_k2; if (xga->accel.octant & 0x02) dy--; else dy++; } else - err += xga->accel.bres_k1; + xga->accel.bres_err_term += xga->accel.bres_k1; } y--; x++; @@ -1423,7 +1504,7 @@ xga_bitblt(svga_t *svga) 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]; + uint32_t patbase; uint32_t dstbase = xga->accel.px_map_base[xga->accel.dst_map]; uint32_t srcbase = xga->accel.px_map_base[xga->accel.src_map]; uint32_t patwidth = xga->accel.px_map_width[xga->accel.pat_src]; @@ -1454,20 +1535,21 @@ xga_bitblt(svga_t *svga) if (xga->accel.dst_map_y >= 0x1800) dy |= ~0x17ff; - xga_log("D(%d,%d), SWH(%d,%d), BLT(%d,%d), dstwidth=%d.\n", dx, dy, xga->accel.x, xga->accel.y, srcwidth, srcheight, dstwidth); + xga_log("D(%d,%d), SWH(%d,%d), BLT(%d,%d), dstwidth=%d, frgdcol=%04x, bkgdcol=%04x.\n", dx, dy, xga->accel.x, xga->accel.y, srcwidth, srcheight, dstwidth, frgdcol, bkgdcol); xga->accel.pattern = 0; xga->accel.filling = 0; - xga_log("XGA bitblt linear endian reverse=%d, access_mode=%x, octanty=%d, src command = %08x, " + xga_log("XGA bitblt 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, + "usesrcvramfr=%d, usevrambk=%d, frgdcol=%04x, bkgdcol=%04x, bgmix=%02x, fgmix=%02x.\n", + 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)); + xga->accel.dst_map, ((xga->accel.command >> 28) & 3), ((xga->accel.command >> 30) & 3), + frgdcol, bkgdcol, xga->accel.bkgd_mix & 0x1f, xga->accel.frgd_mix & 0x1f); if (xga->accel.pat_src == 8) { if (srcheight == 7) @@ -1550,6 +1632,8 @@ xga_bitblt(svga_t *svga) } } } else if (xga->accel.pat_src >= 1) { + patbase = xga->accel.px_map_base[xga->accel.pat_src]; + if (patheight == 7) { if (xga->accel.src_map != 1) xga->accel.pattern = 1; @@ -1593,17 +1677,19 @@ xga_bitblt(svga_t *svga) xga->accel.px_map_width[2], xga->accel.px_map_width[3], bkgdcol); xga_log("Pattern Enabled?=%d, patwidth=%d, patheight=%d, P(%d,%d).\n", xga->accel.pattern, patwidth, patheight, xga->accel.px, xga->accel.py); - if ((((xga->accel.command >> 24) & 0x0f) == 0x0a) && ((xga->accel.bkgd_mix & 0x1f) == 5)) { - while (xga->accel.y >= 0) { - mix = xga_accel_read_pattern_map_pixel(svga, xga->accel.px, xga->accel.py, patbase, patwidth + 1); - if (mix) - xga->accel.filling = !xga->accel.filling; + if (((xga->accel.command >> 24) & 0x0f) == 0x0a) { + if ((xga->accel.bkgd_mix & 0x1f) == 0x05) { + while (xga->accel.y >= 0) { + mix = xga_accel_read_area_map_pixel(svga, xga->accel.px, xga->accel.py, patbase, patwidth + 1); + if (mix) + xga->accel.filling ^= 1; - 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.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1) : frgdcol; - if (xga->accel.filling) { - dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, 1024); + xga_log("Area Fill Command: dx=%d, dy=%d, mix=%x, filling=%x.\n", dx, dy, mix, xga->accel.filling); + + 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)) && xga->accel.filling) { + 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) : frgdcol; + dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, dstwidth + 1); 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); @@ -1612,11 +1698,9 @@ xga_bitblt(svga_t *svga) xga_accel_write_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, dest_dat, dstwidth + 1); } } - } - } else { - if ((dx >= 0) && (dx <= dstwidth) && (dy >= 0) && (dy <= dstheight)) { - 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) : frgdcol; - if (xga->accel.filling) { + } else { + if ((dx >= 0) && (dx <= dstwidth) && (dy >= 0) && (dy <= dstheight) && xga->accel.filling) { + 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) : frgdcol; dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, dstwidth + 1); 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; @@ -1627,35 +1711,40 @@ xga_bitblt(svga_t *svga) } } } - } - xga->accel.sx = ((xga->accel.sx + xdir) & srcwidth) | (xga->accel.sx & ~srcwidth); - xga->accel.px++; + xga->accel.sx = ((xga->accel.sx + xdir) & srcwidth) | (xga->accel.sx & ~srcwidth); + xga->accel.px++; - dx++; - xga->accel.x--; - if (xga->accel.x < 0) { - xga->accel.y--; - xga->accel.x = xga->accel.blt_width & 0xfff; + dx++; + xga->accel.x--; + if (xga->accel.x < 0) { + xga->accel.y--; + xga->accel.x = xga->accel.blt_width & 0xfff; - dx = xga->accel.dst_map_x; - if (xga->accel.dst_map_x >= 0x1800) - dx |= ~0x17ff; + dx = xga->accel.dst_map_x; + if (xga->accel.dst_map_x >= 0x1800) + dx |= ~0x17ff; - xga->accel.sx = xga->accel.src_map_x & 0xfff; - xga->accel.px = xga->accel.pat_map_x & 0xfff; + xga->accel.sx = xga->accel.src_map_x & 0xfff; + xga->accel.px = xga->accel.pat_map_x & 0xfff; - xga->accel.sy = ((xga->accel.sy + ydir) & srcheight) | (xga->accel.sy & ~srcheight); - xga->accel.py++; + xga->accel.sy = ((xga->accel.sy + ydir) & srcheight) | (xga->accel.sy & ~srcheight); + xga->accel.py++; - dy++; - xga->accel.filling = 0; + dy++; + xga->accel.filling = 0; - if (xga->accel.y < 0) - return; + if (xga->accel.y < 0) { + xga->accel.dst_map_x = dx; + xga->accel.dst_map_y = dy; + return; + } + } } } } else { + patbase = xga->accel.px_map_base[xga->accel.pat_src]; + while (xga->accel.y >= 0) { mix = xga_accel_read_pattern_map_pixel(svga, xga->accel.px, xga->accel.py, patbase, patwidth + 1); @@ -2171,7 +2260,6 @@ exec_command: xga->accel.src_map = ((xga->accel.command >> 20) & 0x0f); xga_log("PATMAP=%x, DSTMAP=%x, SRCMAP=%x.\n", xga->accel.px_map_format[xga->accel.pat_src], xga->accel.px_map_format[xga->accel.dst_map], xga->accel.px_map_format[xga->accel.src_map]); -#ifdef ENABLE_XGA_LOG if (xga->accel.pat_src) xga_log("[%04X:%08X]: Accel Command = %02x, full = %08x, patwidth = %d, " "dstwidth = %d, srcwidth = %d, patheight = %d, dstheight = %d, " @@ -2196,7 +2284,7 @@ exec_command: xga->accel.px_map_format[xga->accel.dst_map] & 0x0f, xga->accel.px_map_format[xga->accel.src_map] & 0x0f, xga->accel.plane_mask); -#endif + switch ((xga->accel.command >> 24) & 0x0f) { case 2: /*Short Stroke Vectors Read */ xga_log("Short Stroke Vectors Read.\n"); @@ -2538,7 +2626,7 @@ xga_render_4bpp(svga_t *svga) if ((xga->displine + svga->y_add) < 0) return; - if (xga->changedvram[xga->ma >> 12] || xga->changedvram[(xga->ma >> 12) + 1] || svga->fullchange) { + if (xga->changedvram[xga->memaddr >> 12] || xga->changedvram[(xga->memaddr >> 12) + 1] || svga->fullchange) { p = &buffer32->line[xga->displine + svga->y_add][svga->x_add]; if (xga->firstline_draw == 2000) @@ -2547,22 +2635,22 @@ xga_render_4bpp(svga_t *svga) xga->lastline_draw = xga->displine; for (int x = 0; x <= xga->h_disp; x += 8) { - dat = *(uint32_t *) (&xga->vram[xga->ma & xga->vram_mask]); + dat = *(uint32_t *) (&xga->vram[xga->memaddr & xga->vram_mask]); p[0] = xga->pallook[dat & 0x0f]; p[1] = xga->pallook[(dat >> 8) & 0x0f]; p[2] = xga->pallook[(dat >> 16) & 0x0f]; p[3] = xga->pallook[(dat >> 24) & 0x0f]; - dat = *(uint32_t *) (&xga->vram[(xga->ma + 2) & xga->vram_mask]); + dat = *(uint32_t *) (&xga->vram[(xga->memaddr + 2) & xga->vram_mask]); p[4] = xga->pallook[dat & 0x0f]; p[5] = xga->pallook[(dat >> 8) & 0x0f]; p[6] = xga->pallook[(dat >> 16) & 0x0f]; p[7] = xga->pallook[(dat >> 24) & 0x0f]; - xga->ma += 8; + xga->memaddr += 8; p += 8; } - xga->ma &= xga->vram_mask; + xga->memaddr &= xga->vram_mask; } } @@ -2576,7 +2664,7 @@ xga_render_8bpp(svga_t *svga) if ((xga->displine + svga->y_add) < 0) return; - if (xga->changedvram[xga->ma >> 12] || xga->changedvram[(xga->ma >> 12) + 1] || svga->fullchange) { + if (xga->changedvram[xga->memaddr >> 12] || xga->changedvram[(xga->memaddr >> 12) + 1] || svga->fullchange) { p = &buffer32->line[xga->displine + svga->y_add][svga->x_add]; if (xga->firstline_draw == 2000) @@ -2584,22 +2672,22 @@ xga_render_8bpp(svga_t *svga) xga->lastline_draw = xga->displine; for (int x = 0; x <= xga->h_disp; x += 8) { - dat = *(uint32_t *) (&xga->vram[xga->ma & xga->vram_mask]); + dat = *(uint32_t *) (&xga->vram[xga->memaddr & xga->vram_mask]); p[0] = xga->pallook[dat & 0xff]; p[1] = xga->pallook[(dat >> 8) & 0xff]; p[2] = xga->pallook[(dat >> 16) & 0xff]; p[3] = xga->pallook[(dat >> 24) & 0xff]; - dat = *(uint32_t *) (&xga->vram[(xga->ma + 4) & xga->vram_mask]); + dat = *(uint32_t *) (&xga->vram[(xga->memaddr + 4) & xga->vram_mask]); p[4] = xga->pallook[dat & 0xff]; p[5] = xga->pallook[(dat >> 8) & 0xff]; p[6] = xga->pallook[(dat >> 16) & 0xff]; p[7] = xga->pallook[(dat >> 24) & 0xff]; - xga->ma += 8; + xga->memaddr += 8; p += 8; } - xga->ma &= xga->vram_mask; + xga->memaddr &= xga->vram_mask; } } @@ -2614,7 +2702,7 @@ xga_render_16bpp(svga_t *svga) if ((xga->displine + svga->y_add) < 0) return; - if (xga->changedvram[xga->ma >> 12] || xga->changedvram[(xga->ma >> 12) + 1] || svga->fullchange) { + if (xga->changedvram[xga->memaddr >> 12] || xga->changedvram[(xga->memaddr >> 12) + 1] || svga->fullchange) { p = &buffer32->line[xga->displine + svga->y_add][svga->x_add]; if (xga->firstline_draw == 2000) @@ -2622,24 +2710,24 @@ xga_render_16bpp(svga_t *svga) xga->lastline_draw = xga->displine; for (x = 0; x <= xga->h_disp; x += 8) { - dat = *(uint32_t *) (&xga->vram[(xga->ma + (x << 1)) & xga->vram_mask]); + dat = *(uint32_t *) (&xga->vram[(xga->memaddr + (x << 1)) & xga->vram_mask]); p[x] = video_16to32[dat & 0xffff]; p[x + 1] = video_16to32[dat >> 16]; - dat = *(uint32_t *) (&xga->vram[(xga->ma + (x << 1) + 4) & xga->vram_mask]); + dat = *(uint32_t *) (&xga->vram[(xga->memaddr + (x << 1) + 4) & xga->vram_mask]); p[x + 2] = video_16to32[dat & 0xffff]; p[x + 3] = video_16to32[dat >> 16]; - dat = *(uint32_t *) (&xga->vram[(xga->ma + (x << 1) + 8) & xga->vram_mask]); + dat = *(uint32_t *) (&xga->vram[(xga->memaddr + (x << 1) + 8) & xga->vram_mask]); p[x + 4] = video_16to32[dat & 0xffff]; p[x + 5] = video_16to32[dat >> 16]; - dat = *(uint32_t *) (&xga->vram[(xga->ma + (x << 1) + 12) & xga->vram_mask]); + dat = *(uint32_t *) (&xga->vram[(xga->memaddr + (x << 1) + 12) & xga->vram_mask]); p[x + 6] = video_16to32[dat & 0xffff]; p[x + 7] = video_16to32[dat >> 16]; } - xga->ma += x << 1; - xga->ma &= xga->vram_mask; + xga->memaddr += x << 1; + xga->memaddr &= xga->vram_mask; } } @@ -2650,7 +2738,7 @@ xga_write_test(uint32_t addr, uint8_t val, void *priv) xga_t *xga = (xga_t *) svga->xga; if (xga_active && xga) { - if (((xga->op_mode & 7) >= 1) && xga->aperture_cntl) { + if (((xga->op_mode & 7) >= 1) && xga->aperture_cntl && (svga->mapping.base == 0xb8000)) { xga_log("WriteAddr=%05x.\n", addr); if (val == 0xa5) { /*Memory size test of XGA*/ xga->test = val; @@ -2670,8 +2758,10 @@ xga_write_test(uint32_t addr, uint8_t val, void *priv) xga->vram[addr & xga->vram_mask] = val; xga_log("XGA Linear endian reverse write, val = %02x, addr = %05x, banked mask = %04x, a5test=%d.\n", val, addr, svga->banked_mask, xga->a5_test); } - } else if (xga->aperture_cntl) + } else if (xga->aperture_cntl || (!xga->aperture_cntl && (svga->mapping.base == 0xa0000))) { xga->on = 0; + xga_log("OFF XGA write.\n"); + } } } @@ -2753,7 +2843,7 @@ xga_read_test(uint32_t addr, void *priv) uint8_t ret = 0x00; if (xga_active && xga) { - if (((xga->op_mode & 7) >= 1) && xga->aperture_cntl) { + if (((xga->op_mode & 7) >= 1) && xga->aperture_cntl && (svga->mapping.base == 0xb8000)) { if (xga->test == 0xa5) { /*Memory size test of XGA*/ if (addr == 0xa0001) { ret = xga->test; @@ -2777,8 +2867,9 @@ xga_read_test(uint32_t addr, void *priv) addr += xga->read_bank; return xga->vram[addr & xga->vram_mask]; } - } else if (xga->aperture_cntl) { + } else if (xga->aperture_cntl || (!xga->aperture_cntl && (svga->mapping.base == 0xa0000))) { xga->on = 0; + xga_log("OFF XGA read.\n"); } } return ret; @@ -2874,7 +2965,7 @@ xga_write_linear(uint32_t addr, uint8_t val, void *priv) svga_t *svga = (svga_t *) priv; xga_t *xga = (xga_t *) svga->xga; - xga_log("WrtieLL XGA=%d.\n", xga->on); + xga_log("WriteLL XGA=%d.\n", xga->on); if (!xga->on) { svga_write_linear(addr, val, svga); return; @@ -2889,13 +2980,6 @@ xga_write_linear(uint32_t addr, uint8_t val, void *priv) cycles -= svga->monitor->mon_video_timing_write_b; - if (!(xga->access_mode & 0x08)) { - if ((xga->access_mode & 0x07) == 0x04) { - if ((xga->accel.px_map_format[xga->accel.dst_map] & 0x07) == 0x04) - addr ^= 1; - } - } - xga->changedvram[(addr & xga->vram_mask) >> 12] = svga->monitor->mon_changeframecount; xga->vram[addr & xga->vram_mask] = val; } @@ -2951,14 +3035,9 @@ xga_read_linear(uint32_t addr, void *priv) cycles -= svga->monitor->mon_video_timing_read_b; - if (!(xga->access_mode & 0x08)) { - if ((xga->access_mode & 0x07) == 0x04) { - if ((xga->accel.px_map_format[xga->accel.dst_map] & 0x07) == 0x04) - addr ^= 1; - } - } + ret = xga->vram[addr & xga->vram_mask]; - return xga->vram[addr & xga->vram_mask]; + return ret; } static uint16_t @@ -2995,6 +3074,12 @@ xga_readl_linear(uint32_t addr, void *priv) return ret; } +void +xga_set_poll(svga_t *svga) +{ + timer_set_callback(&svga->timer, xga_poll); +} + void xga_poll(void *priv) { @@ -3004,166 +3089,158 @@ xga_poll(void *priv) int wx; int wy; - if (!xga->linepos) { - if (xga->displine == xga->hwcursor_latch.y && xga->hwcursor_latch.ena) { - xga->hwcursor_on = xga->hwcursor_latch.cur_ysize - ((xga->hwcursor_latch.yoff & 0x20) ? 32 : 0); - xga->hwcursor_oddeven = 0; - } - - if (xga->displine == (xga->hwcursor_latch.y + 1) && xga->hwcursor_latch.ena && xga->interlace) { - xga->hwcursor_on = xga->hwcursor_latch.cur_ysize - ((xga->hwcursor_latch.yoff & 0x20) ? 33 : 1); - xga->hwcursor_oddeven = 1; - } - - timer_advance_u64(&svga->timer, svga->dispofftime); - svga->cgastat |= 1; - xga->linepos = 1; - - if (xga->dispon) { - xga->h_disp_on = 1; - - xga->ma &= xga->vram_mask; - - if (xga->firstline == 2000) { - xga->firstline = xga->displine; - video_wait_for_buffer_monitor(svga->monitor_index); + xga_log("XGA Poll=%d.\n", xga->on); + if (xga->on) { + if (!xga->linepos) { + if (xga->displine == xga->hwcursor_latch.y && xga->hwcursor_latch.ena) { + xga->hwcursor_on = xga->hwcursor_latch.cur_ysize - ((xga->hwcursor_latch.yoff & 0x20) ? 32 : 0); + xga->hwcursor_oddeven = 0; } - if (xga->hwcursor_on) - xga->changedvram[xga->ma >> 12] = xga->changedvram[(xga->ma >> 12) + 1] = xga->interlace ? 3 : 2; - - switch (xga->disp_cntl_2 & 7) { - case 2: - xga_render_4bpp(svga); - break; - case 3: - xga_render_8bpp(svga); - break; - case 4: - xga_render_16bpp(svga); - break; - default: - break; + if (xga->displine == (xga->hwcursor_latch.y + 1) && xga->hwcursor_latch.ena && xga->interlace) { + xga->hwcursor_on = xga->hwcursor_latch.cur_ysize - ((xga->hwcursor_latch.yoff & 0x20) ? 33 : 1); + xga->hwcursor_oddeven = 1; } - svga->x_add = (overscan_x >> 1); - xga_render_overscan_left(xga, svga); - xga_render_overscan_right(xga, svga); - svga->x_add = (overscan_x >> 1); + timer_advance_u64(&svga->timer, xga->dispofftime); + svga->cgastat |= 1; + xga->linepos = 1; - if (xga->hwcursor_on) { - xga_hwcursor_draw(svga, xga->displine + svga->y_add); - xga->hwcursor_on--; - if (xga->hwcursor_on && xga->interlace) + if (xga->dispon) { + xga->h_disp_on = 1; + + xga->memaddr &= xga->vram_mask; + + if (xga->firstline == 2000) { + xga->firstline = xga->displine; + video_wait_for_buffer_monitor(svga->monitor_index); + } + + if (xga->hwcursor_on) + xga->changedvram[xga->memaddr >> 12] = xga->changedvram[(xga->memaddr >> 12) + 1] = xga->interlace ? 3 : 2; + + svga->render_xga(svga); + + svga->x_add = (overscan_x >> 1); + xga_render_overscan_left(xga, svga); + xga_render_overscan_right(xga, svga); + svga->x_add = (overscan_x >> 1); + + if (xga->hwcursor_on) { + xga_hwcursor_draw(svga, xga->displine + svga->y_add); xga->hwcursor_on--; + if (xga->hwcursor_on && xga->interlace) + xga->hwcursor_on--; + } + + if (xga->lastline < xga->displine) + xga->lastline = xga->displine; } - if (xga->lastline < xga->displine) - xga->lastline = xga->displine; - } - - xga->displine++; - if (xga->interlace) xga->displine++; - if ((svga->cgastat & 8) && ((xga->displine & 0x0f) == (svga->crtc[0x11] & 0x0f)) && svga->vslines) - svga->cgastat &= ~8; - if (xga->displine > 1500) - xga->displine = 0; - } else { - timer_advance_u64(&svga->timer, svga->dispontime); - if (xga->dispon) - svga->cgastat &= ~1; + if (xga->interlace) + xga->displine++; + if ((svga->cgastat & 8) && ((xga->displine & 0x0f) == (svga->crtc[0x11] & 0x0f)) && svga->vslines) + svga->cgastat &= ~8; + if (xga->displine > 1500) + xga->displine = 0; + } else { + timer_advance_u64(&svga->timer, xga->dispontime); + if (xga->dispon) + svga->cgastat &= ~1; - xga->h_disp_on = 0; + xga->h_disp_on = 0; - xga->linepos = 0; - if (xga->dispon) { - if (xga->sc == xga->rowcount) { - xga->sc = 0; + xga->linepos = 0; + if (xga->dispon) { + if (xga->scanline == xga->rowcount) { + xga->scanline = 0; - xga_log("MA=%08x, MALATCH=%x.\n", xga->ma, xga->ma_latch); - xga->maback += (xga->rowoffset << 3); - if (xga->interlace) - xga->maback += (xga->rowoffset << 3); + xga_log("MA=%08x, MALATCH=%x.\n", xga->memaddr, xga->memaddr_latch); + xga->memaddr_backup += (xga->rowoffset << 3); + if (xga->interlace) + xga->memaddr_backup += (xga->rowoffset << 3); - xga->maback &= xga->vram_mask; - xga->ma = xga->maback; - } else { - xga->sc++; - xga->sc &= 0x1f; - xga->ma = xga->maback; + xga->memaddr_backup &= xga->vram_mask; + xga->memaddr = xga->memaddr_backup; + } else { + xga->scanline++; + xga->scanline &= 0x1f; + xga->memaddr = xga->memaddr_backup; + } + } + + xga->vc++; + xga->vc &= 0x7ff; + + if (xga->vc == xga->split) { + if (xga->interlace && xga->oddeven) + xga->memaddr = xga->memaddr_backup = (xga->rowoffset << 1); + else + xga->memaddr = xga->memaddr_backup = 0; + + xga->memaddr = (xga->memaddr << 2); + xga->memaddr_backup = (xga->memaddr_backup << 2); + + xga->scanline = 0; + } + if (xga->vc == xga->dispend) { + xga->dispon = 0; + + for (x = 0; x < ((xga->vram_mask + 1) >> 12); x++) { + if (xga->changedvram[x]) + xga->changedvram[x]--; + } + if (svga->fullchange) + svga->fullchange--; + } + if (xga->vc == xga->v_syncstart) { + xga->dispon = 0; + svga->cgastat |= 8; + x = xga->h_disp; + + if (xga->interlace && !xga->oddeven) + xga->lastline++; + if (xga->interlace && xga->oddeven) + xga->firstline--; + + wx = x; + + wy = xga->lastline - xga->firstline; + svga_doblit(wx, wy, svga); + + xga->firstline = 2000; + xga->lastline = 0; + + xga->firstline_draw = 2000; + xga->lastline_draw = 0; + + xga->oddeven ^= 1; + + svga->monitor->mon_changeframecount = xga->interlace ? 3 : 2; + + if (xga->interlace && xga->oddeven) + xga->memaddr = xga->memaddr_backup = xga->memaddr_latch + (xga->rowoffset << 1); + else + xga->memaddr = xga->memaddr_backup = xga->memaddr_latch; + + xga->memaddr = (xga->memaddr << 2); + xga->memaddr_backup = (xga->memaddr_backup << 2); + } + if (xga->vc == xga->v_total) { + xga->vc = 0; + xga->scanline = 0; + xga->dispon = 1; + xga->displine = (xga->interlace && xga->oddeven) ? 1 : 0; + + svga->x_add = (overscan_x >> 1); + + xga->hwcursor_on = 0; + xga->hwcursor_latch = xga->hwcursor; } } - - xga->vc++; - xga->vc &= 0x7ff; - - if (xga->vc == xga->split) { - if (xga->interlace && xga->oddeven) - xga->ma = xga->maback = (xga->rowoffset << 1); - else - xga->ma = xga->maback = 0; - - xga->ma = (xga->ma << 2); - xga->maback = (xga->maback << 2); - - xga->sc = 0; - } - if (xga->vc == xga->dispend) { - xga->dispon = 0; - - for (x = 0; x < ((xga->vram_mask + 1) >> 12); x++) { - if (xga->changedvram[x]) - xga->changedvram[x]--; - } - if (svga->fullchange) - svga->fullchange--; - } - if (xga->vc == xga->v_syncstart) { - xga->dispon = 0; - svga->cgastat |= 8; - x = xga->h_disp; - - if (xga->interlace && !xga->oddeven) - xga->lastline++; - if (xga->interlace && xga->oddeven) - xga->firstline--; - - wx = x; - - wy = xga->lastline - xga->firstline; - svga_doblit(wx, wy, svga); - - xga->firstline = 2000; - xga->lastline = 0; - - xga->firstline_draw = 2000; - xga->lastline_draw = 0; - - xga->oddeven ^= 1; - - svga->monitor->mon_changeframecount = xga->interlace ? 3 : 2; - - if (xga->interlace && xga->oddeven) - xga->ma = xga->maback = xga->ma_latch + (xga->rowoffset << 1); - else - xga->ma = xga->maback = xga->ma_latch; - - xga->ma = (xga->ma << 2); - xga->maback = (xga->maback << 2); - } - if (xga->vc == xga->v_total) { - xga->vc = 0; - xga->sc = 0; - xga->dispon = 1; - xga->displine = (xga->interlace && xga->oddeven) ? 1 : 0; - - svga->x_add = (overscan_x >> 1); - - xga->hwcursor_on = 0; - xga->hwcursor_latch = xga->hwcursor; - } - } + } else + svga_recalctimings(svga); } static uint8_t @@ -3234,7 +3311,7 @@ xga_mca_reset(void *priv) svga_t *svga = (svga_t *) priv; xga_log("MCA Reset.\n"); - mem_mapping_set_handler(&svga->mapping, svga_read, svga_readw, svga_readl, svga_write, svga_writew, svga_writel); + mem_mapping_set_handler(&svga->mapping, svga->read, svga->readw, svga->readl, svga->write, svga->writew, svga->writel); xga_mca_write(0x102, 0, svga); } @@ -3250,7 +3327,8 @@ xga_reset(void *priv) xga->on = 0; xga->a5_test = 0; - mem_mapping_set_handler(&svga->mapping, svga_read, svga_readw, svga_readl, svga_write, svga_writew, svga_writel); + mem_mapping_set_handler(&svga->mapping, svga->read, svga->readw, svga->readl, svga->write, svga->writew, svga->writel); + svga_set_poll(svga); } static uint8_t @@ -3582,24 +3660,19 @@ xga_force_redraw(void *priv) static const device_config_t xga_mca_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 = "type", + .description = "XGA type", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "XGA-1", .value = 0 }, + { .description = "XGA-2", .value = 1 }, + { .description = "" } + }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -3608,34 +3681,29 @@ static const device_config_t xga_mca_configuration[] = { 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 = "type", + .description = "XGA type", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "XGA-1", .value = 0 }, + { .description = "XGA-2", .value = 1 }, + { .description = "" } + }, + .bios = { { 0 } } }, { - .name = "instance", - .description = "Instance", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 6, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "instance", + .description = "Instance", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 6, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "0 (2100h-210Fh)", .value = 0 }, { .description = "1 (2110h-211Fh)", .value = 1 }, { .description = "2 (2120h-212Fh)", .value = 2 }, @@ -3644,18 +3712,19 @@ static const device_config_t xga_isa_configuration[] = { { .description = "5 (2150h-215Fh)", .value = 5 }, { .description = "6 (2160h-216Fh)", .value = 6 }, { .description = "7 (2170h-217Fh)", .value = 7 }, - { .description = "" } + { .description = "" } }, + .bios = { { 0 } } }, { - .name = "ext_mem_addr", - .description = "MMIO Address", - .type = CONFIG_HEX16, - .default_string = "", - .default_int = 0x00f0, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "ext_mem_addr", + .description = "MMIO Address", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x00f0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "C800h", .value = 0x0040 }, { .description = "CA00h", .value = 0x0050 }, { .description = "CC00h", .value = 0x0060 }, @@ -3668,23 +3737,25 @@ static const device_config_t xga_isa_configuration[] = { { .description = "DA00h", .value = 0x00d0 }, { .description = "DC00h", .value = 0x00e0 }, { .description = "DE00h", .value = 0x00f0 }, - { .description = "" } + { .description = "" } }, + .bios = { { 0 } } }, { - .name = "dma", - .description = "DMA", - .type = CONFIG_SELECTION, - .default_string = "", - .default_int = 7, - .file_filter = "", - .spinner = { 0 }, - .selection = { + .name = "dma", + .description = "DMA", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 7, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { .description = "Disabled", .value = 0 }, - { .description = "DMA 6", .value = 6 }, - { .description = "DMA 7", .value = 7 }, - { .description = "" } + { .description = "DMA 6", .value = 6 }, + { .description = "DMA 7", .value = 7 }, + { .description = "" } }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -3693,39 +3764,35 @@ static const device_config_t xga_isa_configuration[] = { static const device_config_t xga_inmos_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 = "dma", - .description = "DMA", - .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 }, + .name = "type", + .description = "XGA type", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "XGA-1", .value = 0 }, + { .description = "XGA-2", .value = 1 }, { .description = "" } }, + .bios = { { 0 } } + }, + { + .name = "dma", + .description = "DMA", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 7, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "Disabled", .value = 0 }, + { .description = "DMA 6", .value = 6 }, + { .description = "DMA 7", .value = 7 }, + { .description = "" } + }, + .bios = { { 0 } } }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on @@ -3739,7 +3806,7 @@ const device_t xga_device = { .init = xga_init, .close = xga_close, .reset = xga_reset, - { .available = xga_available }, + .available = xga_available, .speed_changed = xga_speed_changed, .force_redraw = xga_force_redraw, .config = xga_mca_configuration @@ -3748,12 +3815,12 @@ const device_t xga_device = { const device_t xga_isa_device = { .name = "XGA (ISA)", .internal_name = "xga_isa", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0, .init = xga_init, .close = xga_close, .reset = xga_reset, - { .available = xga_available }, + .available = xga_available, .speed_changed = xga_speed_changed, .force_redraw = xga_force_redraw, .config = xga_isa_configuration @@ -3762,12 +3829,12 @@ const device_t xga_isa_device = { const device_t inmos_isa_device = { .name = "INMOS XGA (ISA)", .internal_name = "inmos_xga_isa", - .flags = DEVICE_ISA | DEVICE_AT, + .flags = DEVICE_ISA16, .local = 0, .init = svga_xga_init, .close = xga_close, .reset = xga_reset, - { .available = inmos_xga_available }, + .available = inmos_xga_available, .speed_changed = xga_speed_changed, .force_redraw = xga_force_redraw, .config = xga_inmos_isa_configuration diff --git a/src/video/video.c b/src/video/video.c index 0773e61ce..785479e15 100644 --- a/src/video/video.c +++ b/src/video/video.c @@ -1006,76 +1006,73 @@ video_force_resize_set_monitor(uint8_t res, int monitor_index) } void -loadfont_common(FILE *f, int format) +loadfont_common(FILE *fp, int format) { - int c; - int d; - switch (format) { case 0: /* MDA */ - for (c = 0; c < 256; c++) - for (d = 0; d < 8; d++) - fontdatm[c][d] = fgetc(f) & 0xff; - for (c = 0; c < 256; c++) - for (d = 0; d < 8; d++) - fontdatm[c][d + 8] = fgetc(f) & 0xff; - (void) fseek(f, 4096 + 2048, SEEK_SET); - for (c = 0; c < 256; c++) - for (d = 0; d < 8; d++) - fontdat[c][d] = fgetc(f) & 0xff; + for (uint16_t c = 0; c < 256; c++) /* 8x14 MDA in 8x8 cell (lines 0-7) */ + for (uint8_t d = 0; d < 8; d++) + fontdatm[c][d] = fgetc(fp) & 0xff; + for (uint16_t c = 0; c < 256; c++) /* 8x14 MDA in 8x8 cell (lines 8-13 + padding lines) */ + for (uint8_t d = 0; d < 8; d++) + fontdatm[c][d + 8] = fgetc(fp) & 0xff; + (void) fseek(fp, 4096 + 2048, SEEK_SET); + for (uint16_t c = 0; c < 256; c++) /* 8x8 CGA (thick, primary) */ + for (uint8_t d = 0; d < 8; d++) + fontdat[c][d] = fgetc(fp) & 0xff; break; case 1: /* PC200 */ - for (d = 0; d < 4; d++) { + for (uint8_t d = 0; d < 4; d++) { /* There are 4 fonts in the ROM */ - for (c = 0; c < 256; c++) /* 8x14 MDA in 8x16 cell */ - (void) !fread(&fontdatm[256 * d + c][0], 1, 16, f); - for (c = 0; c < 256; c++) { /* 8x8 CGA in 8x16 cell */ - (void) !fread(&fontdat[256 * d + c][0], 1, 8, f); - fseek(f, 8, SEEK_CUR); + for (uint16_t c = 0; c < 256; c++) /* 8x14 MDA in 8x16 cell */ + (void) !fread(&fontdatm[256 * d + c][0], 1, 16, fp); + for (uint16_t c = 0; c < 256; c++) { /* 8x8 CGA in 8x16 cell */ + (void) !fread(&fontdat[256 * d + c][0], 1, 8, fp); + fseek(fp, 8, SEEK_CUR); } } break; default: case 2: /* CGA */ - for (c = 0; c < 256; c++) - for (d = 0; d < 8; d++) - fontdat[c][d] = fgetc(f) & 0xff; + for (uint16_t c = 0; c < 256; c++) + for (uint8_t d = 0; d < 8; d++) + fontdat[c][d] = fgetc(fp) & 0xff; break; case 3: /* Wyse 700 */ - for (c = 0; c < 512; c++) - for (d = 0; d < 32; d++) - fontdatw[c][d] = fgetc(f) & 0xff; + for (uint16_t c = 0; c < 512; c++) + for (uint8_t d = 0; d < 32; d++) + fontdatw[c][d] = fgetc(fp) & 0xff; break; case 4: /* MDSI Genius */ - for (c = 0; c < 256; c++) - for (d = 0; d < 16; d++) - fontdat8x12[c][d] = fgetc(f) & 0xff; + for (uint16_t c = 0; c < 256; c++) + for (uint8_t d = 0; d < 16; d++) + fontdat8x12[c][d] = fgetc(fp) & 0xff; break; - case 5: /* Toshiba 3100e */ - for (d = 0; d < 2048; d += 512) { /* Four languages... */ - for (c = d; c < d + 256; c++) { - (void) !fread(&fontdatm[c][8], 1, 8, f); + case 5: /* Toshiba 3100e */ + for (uint16_t d = 0; d < 2048; d += 512) { /* Four languages... */ + for (uint16_t c = d; c < d + 256; c++) { + (void) !fread(&fontdatm[c][8], 1, 8, fp); } - for (c = d + 256; c < d + 512; c++) { - (void) !fread(&fontdatm[c][8], 1, 8, f); + for (uint16_t c = d + 256; c < d + 512; c++) { + (void) !fread(&fontdatm[c][8], 1, 8, fp); } - for (c = d; c < d + 256; c++) { - (void) !fread(&fontdatm[c][0], 1, 8, f); + for (uint16_t c = d; c < d + 256; c++) { + (void) !fread(&fontdatm[c][0], 1, 8, fp); } - for (c = d + 256; c < d + 512; c++) { - (void) !fread(&fontdatm[c][0], 1, 8, f); + for (uint16_t c = d + 256; c < d + 512; c++) { + (void) !fread(&fontdatm[c][0], 1, 8, fp); } - fseek(f, 4096, SEEK_CUR); /* Skip blank section */ - for (c = d; c < d + 256; c++) { - (void) !fread(&fontdat[c][0], 1, 8, f); + fseek(fp, 4096, SEEK_CUR); /* Skip blank section */ + for (uint16_t c = d; c < d + 256; c++) { + (void) !fread(&fontdat[c][0], 1, 8, fp); } - for (c = d + 256; c < d + 512; c++) { - (void) !fread(&fontdat[c][0], 1, 8, f); + for (uint16_t c = d + 256; c < d + 512; c++) { + (void) !fread(&fontdat[c][0], 1, 8, fp); } } break; @@ -1087,65 +1084,64 @@ loadfont_common(FILE *f, int format) if (!fontdatksc5601_user) fontdatksc5601_user = malloc(192 * sizeof(dbcs_font_t)); - for (c = 0; c < 16384; c++) { - for (d = 0; d < 32; d++) - fontdatksc5601[c].chr[d] = fgetc(f) & 0xff; + for (uint32_t c = 0; c < 16384; c++) { + for (uint8_t d = 0; d < 32; d++) + fontdatksc5601[c].chr[d] = fgetc(fp) & 0xff; } break; case 7: /* Sigma Color 400 */ /* The first 4k of the character ROM holds an 8x8 font */ - for (c = 0; c < 256; c++) { - (void) !fread(&fontdat[c][0], 1, 8, f); - fseek(f, 8, SEEK_CUR); + for (uint16_t c = 0; c < 256; c++) { + (void) !fread(&fontdat[c][0], 1, 8, fp); + fseek(fp, 8, SEEK_CUR); } /* The second 4k holds an 8x16 font */ - for (c = 0; c < 256; c++) { - if (fread(&fontdatm[c][0], 1, 16, f) != 16) + for (uint16_t c = 0; c < 256; c++) { + if (fread(&fontdatm[c][0], 1, 16, fp) != 16) fatal("loadfont(): Error reading 8x16 font in Sigma Color 400 mode, c = %i\n", c); } break; - case 8: /* Amstrad PC1512, Toshiba T1000/T1200 */ - for (c = 0; c < 2048; c++) /* Allow up to 2048 chars */ - for (d = 0; d < 8; d++) - fontdat[c][d] = fgetc(f) & 0xff; + case 8: /* Amstrad PC1512, Toshiba T1000/T1200 */ + for (uint16_t c = 0; c < 2048; c++) /* Allow up to 2048 chars */ + for (uint8_t d = 0; d < 8; d++) + fontdat[c][d] = fgetc(fp) & 0xff; break; case 9: /* Image Manager 1024 native font */ - for (c = 0; c < 256; c++) - (void) !fread(&fontdat12x18[c][0], 1, 36, f); + for (uint16_t c = 0; c < 256; c++) + (void) !fread(&fontdat12x18[c][0], 1, 36, fp); break; - case 10: /* Pravetz */ - for (c = 0; c < 1024; c++) /* Allow up to 1024 chars */ - for (d = 0; d < 8; d++) - fontdat[c][d] = fgetc(f) & 0xff; + case 10: /* Pravetz */ + for (uint16_t c = 0; c < 1024; c++) /* Allow up to 1024 chars */ + for (uint8_t d = 0; d < 8; d++) + fontdat[c][d] = fgetc(fp) & 0xff; break; - case 11: /* PC200 */ - for (d = 0; d < 4; d++) { + for (uint8_t d = 0; d < 4; d++) { /* There are 4 fonts in the ROM */ - for (c = 0; c < 256; c++) /* 8x14 MDA in 8x16 cell */ - (void) !fread(&fontdatm2[256 * d + c][0], 1, 16, f); - for (c = 0; c < 256; c++) { /* 8x8 CGA in 8x16 cell */ - (void) !fread(&fontdat2[256 * d + c][0], 1, 8, f); - fseek(f, 8, SEEK_CUR); + for (uint16_t c = 0; c < 256; c++) /* 8x14 MDA in 8x16 cell */ + (void) !fread(&fontdatm2[256 * d + c][0], 1, 16, fp); + for (uint16_t c = 0; c < 256; c++) { /* 8x8 CGA in 8x16 cell */ + (void) !fread(&fontdat2[256 * d + c][0], 1, 8, fp); + fseek(fp, 8, SEEK_CUR); } } break; } - (void) fclose(f); + (void) fclose(fp); } void -loadfont_ex(char *s, int format, int offset) +loadfont_ex(char *fn, int format, int offset) { FILE *fp; - fp = rom_fopen(s, "rb"); + fp = rom_fopen(fn, "rb"); if (fp == NULL) return; @@ -1154,9 +1150,9 @@ loadfont_ex(char *s, int format, int offset) } void -loadfont(char *s, int format) +loadfont(char *fn, int format) { - loadfont_ex(s, format, 0); + loadfont_ex(fn, format, 0); } uint32_t diff --git a/vcpkg.json b/vcpkg.json index 87859869b..20b783add 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,6 +1,6 @@ { "name": "86box", - "version-string": "4.3", + "version-string": "5.0", "homepage": "https://86box.net/", "documentation": "https://86box.readthedocs.io/", "license": "GPL-2.0-or-later", diff --git a/wl_protocols/keyboard-shortcuts-inhibit-unstable-v1.xml b/wl_protocols/keyboard-shortcuts-inhibit-unstable-v1.xml new file mode 100644 index 000000000..27748764d --- /dev/null +++ b/wl_protocols/keyboard-shortcuts-inhibit-unstable-v1.xml @@ -0,0 +1,143 @@ + + + + + Copyright © 2017 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 (including the next + paragraph) 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. + + + + This protocol specifies a way for a client to request the compositor + to ignore its own keyboard shortcuts for a given seat, so that all + key events from that seat get forwarded to a surface. + + Warning! The protocol described in this file is experimental and + backward incompatible changes may be made. Backward compatible + changes may be added together with the corresponding interface + version bump. + Backward incompatible changes are done by bumping the version + number in the protocol and interface names and resetting the + interface version. Once the protocol is to be declared stable, + the 'z' prefix and the version number in the protocol and + interface names are removed and the interface version number is + reset. + + + + + A global interface used for inhibiting the compositor keyboard shortcuts. + + + + + Destroy the keyboard shortcuts inhibitor manager. + + + + + + Create a new keyboard shortcuts inhibitor object associated with + the given surface for the given seat. + + If shortcuts are already inhibited for the specified seat and surface, + a protocol error "already_inhibited" is raised by the compositor. + + + + + + + + + + + + + + A keyboard shortcuts inhibitor instructs the compositor to ignore + its own keyboard shortcuts when the associated surface has keyboard + focus. As a result, when the surface has keyboard focus on the given + seat, it will receive all key events originating from the specified + seat, even those which would normally be caught by the compositor for + its own shortcuts. + + The Wayland compositor is however under no obligation to disable + all of its shortcuts, and may keep some special key combo for its own + use, including but not limited to one allowing the user to forcibly + restore normal keyboard events routing in the case of an unwilling + client. The compositor may also use the same key combo to reactivate + an existing shortcut inhibitor that was previously deactivated on + user request. + + When the compositor restores its own keyboard shortcuts, an + "inactive" event is emitted to notify the client that the keyboard + shortcuts inhibitor is not effectively active for the surface and + seat any more, and the client should not expect to receive all + keyboard events. + + When the keyboard shortcuts inhibitor is inactive, the client has + no way to forcibly reactivate the keyboard shortcuts inhibitor. + + The user can chose to re-enable a previously deactivated keyboard + shortcuts inhibitor using any mechanism the compositor may offer, + in which case the compositor will send an "active" event to notify + the client. + + If the surface is destroyed, unmapped, or loses the seat's keyboard + focus, the keyboard shortcuts inhibitor becomes irrelevant and the + compositor will restore its own keyboard shortcuts but no "inactive" + event is emitted in this case. + + + + + Remove the keyboard shortcuts inhibitor from the associated wl_surface. + + + + + + This event indicates that the shortcut inhibitor is active. + + The compositor sends this event every time compositor shortcuts + are inhibited on behalf of the surface. When active, the client + may receive input events normally reserved by the compositor + (see zwp_keyboard_shortcuts_inhibitor_v1). + + This occurs typically when the initial request "inhibit_shortcuts" + first becomes active or when the user instructs the compositor to + re-enable and existing shortcuts inhibitor using any mechanism + offered by the compositor. + + + + + + This event indicates that the shortcuts inhibitor is inactive, + normal shortcuts processing is restored by the compositor. + + + +